From: Anatolij Gustschin <agust@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] SPI: mxc_spi: add SPI clock calculation and setup to the driver
Date: Sun, 16 Jan 2011 19:17:17 +0100 [thread overview]
Message-ID: <1295201837-26836-2-git-send-email-agust@denx.de> (raw)
In-Reply-To: <1295201837-26836-1-git-send-email-agust@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 <agust@denx.de>
---
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
next prev parent reply other threads:[~2011-01-16 18:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-16 18:17 [U-Boot] [PATCH 1/2] SPI: mxc_spi: fix swapping bug and add missing swapping in unaligned rx case Anatolij Gustschin
2011-01-16 18:17 ` Anatolij Gustschin [this message]
2011-01-17 9:00 ` [U-Boot] [PATCH 2/2] SPI: mxc_spi: add SPI clock calculation and setup to the driver Stefano Babic
2011-01-17 9:30 ` Anatolij Gustschin
2011-01-17 9:36 ` Anatolij Gustschin
2011-01-17 9:41 ` Stefano Babic
2011-01-18 11:22 ` [U-Boot] [PATCH V2 " Stefano Babic
2011-01-18 15:37 ` Sergei Shtylyov
2011-01-20 8:11 ` Stefano Babic
2011-01-18 11:20 ` [U-Boot] [PATCH 1/2] SPI: mxc_spi: fix swapping bug and add missing swapping in unaligned rx case Stefano Babic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295201837-26836-2-git-send-email-agust@denx.de \
--to=agust@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox