From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anatolij Gustschin Date: Sun, 16 Jan 2011 19:17:17 +0100 Subject: [U-Boot] [PATCH 2/2] SPI: mxc_spi: add SPI clock calculation and setup to the driver In-Reply-To: <1295201837-26836-1-git-send-email-agust@denx.de> References: <1295201837-26836-1-git-send-email-agust@denx.de> Message-ID: <1295201837-26836-2-git-send-email-agust@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de The MXC SPI driver didn't calculate the SPI clock up to now and just used lowest possible divider 512 for DATA RATE in the control register. This results in very low transfer rates. The patch adds code to calculate and setup the SPI clock frequency for transfers. Signed-off-by: Anatolij Gustschin --- drivers/spi/mxc_spi.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c index 9ed2891..07c62c2 100644 --- a/drivers/spi/mxc_spi.c +++ b/drivers/spi/mxc_spi.c @@ -438,12 +438,25 @@ static int decode_cs(struct mxc_spi_slave *mxcs, unsigned int cs) return cs; } +u32 get_cspi_div(u32 div) +{ + int i; + + for (i = 0; i < 8; i++) { + if (div <= (4 << i)) + return i; + } + return i; +} + struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, unsigned int max_hz, unsigned int mode) { unsigned int ctrl_reg; struct mxc_spi_slave *mxcs; int ret; + u32 clk_src; + u32 div; if (bus >= ARRAY_SIZE(spi_bases)) return NULL; @@ -477,9 +490,16 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, return NULL; } #else + clk_src = mx31_get_ipg_clk(); + div = clk_src / max_hz; + div = get_cspi_div(div); + + debug("clk %d Hz, div %d, real clk %d Hz\n", + max_hz, div, clk_src / (4 << div)); + ctrl_reg = MXC_CSPICTRL_CHIPSELECT(cs) | MXC_CSPICTRL_BITCOUNT(31) | - MXC_CSPICTRL_DATARATE(7) | /* FIXME: calculate data rate */ + MXC_CSPICTRL_DATARATE(div) | MXC_CSPICTRL_EN | MXC_CSPICTRL_MODE; -- 1.7.1