From patchwork Fri Dec 24 07:16:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Chou X-Patchwork-Id: 76626 X-Patchwork-Delegate: vapier@gentoo.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 892A7B70BA for ; Fri, 24 Dec 2010 18:57:28 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9C0C728089; Fri, 24 Dec 2010 08:57:03 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h08616OmaIbC; Fri, 24 Dec 2010 08:57:03 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 47F7F28082; Fri, 24 Dec 2010 08:56:53 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4598328082 for ; Fri, 24 Dec 2010 08:56:51 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1D+KJOrc1SfW for ; Fri, 24 Dec 2010 08:56:50 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from www.wytron.com.tw (www.wytron.com.tw [211.75.82.101]) by theia.denx.de (Postfix) with ESMTPS id 1FD8828084 for ; Fri, 24 Dec 2010 08:56:40 +0100 (CET) Received: from [192.168.1.15] (helo=darkstar.wytron.com.tw) by www.wytron.com.tw with esmtp (Exim 4.69) (envelope-from ) id 1PW1rp-00028b-3u; Fri, 24 Dec 2010 15:15:09 +0800 From: Thomas Chou To: Andy Fleming Date: Fri, 24 Dec 2010 15:16:08 +0800 Message-Id: <1293174969-18653-4-git-send-email-thomas@wytron.com.tw> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1293174969-18653-1-git-send-email-thomas@wytron.com.tw> References: <1293174969-18653-1-git-send-email-thomas@wytron.com.tw> X-SA-Exim-Connect-IP: 192.168.1.15 X-SA-Exim-Mail-From: thomas@wytron.com.tw X-SA-Exim-Scanned: No (on www.wytron.com.tw); SAEximRunCond expanded to false Cc: u-boot@lists.denx.de, nios2-dev@sopc.et.ntust.edu.tw Subject: [U-Boot] [PATCH 3/4] bfin_spi: add spi_set_speed X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de The new speed will be applied by spi_claim_bus. Signed-off-by: Thomas Chou Signed-off-by: Mike Frysinger --- drivers/spi/bfin_spi.c | 32 +++++++++++++++++++------------- 1 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c index d7e1474..bfecdaf 100644 --- a/drivers/spi/bfin_spi.c +++ b/drivers/spi/bfin_spi.c @@ -138,13 +138,29 @@ static const unsigned short cs_pins[][7] = { #endif }; +void spi_set_speed(struct spi_slave *slave, uint hz) +{ + struct bfin_spi_slave *bss = to_bfin_spi_slave(slave); + ulong sclk; + u32 baud; + + sclk = get_sclk(); + baud = sclk / (2 * hz); + /* baud should be rounded up */ + if (sclk % (2 * hz)) + baud += 1; + if (baud < 2) + baud = 2; + else if (baud > (u16)-1) + baud = -1; + bss->baud = baud; +} + struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int mode) { struct bfin_spi_slave *bss; - ulong sclk; u32 mmr_base; - u32 baud; if (!spi_cs_is_valid(bus, cs)) return NULL; @@ -166,16 +182,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, default: return NULL; } - sclk = get_sclk(); - baud = sclk / (2 * max_hz); - /* baud should be rounded up */ - if (sclk % (2 * max_hz)) - baud += 1; - if (baud < 2) - baud = 2; - else if (baud > (u16)-1) - baud = -1; - bss = malloc(sizeof(*bss)); if (!bss) return NULL; @@ -187,8 +193,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, if (mode & SPI_CPHA) bss->ctl |= CPHA; if (mode & SPI_CPOL) bss->ctl |= CPOL; if (mode & SPI_LSB_FIRST) bss->ctl |= LSBF; - bss->baud = baud; bss->flg = mode & SPI_CS_HIGH ? 1 : 0; + spi_set_speed(&bss->slave, max_hz); debug("%s: bus:%i cs:%i mmr:%x ctl:%x baud:%i flg:%i\n", __func__, bus, cs, mmr_base, bss->ctl, baud, bss->flg);