From: Juergen Beisert <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] i.MX23/MCI: Make the clock calculation easier to read and correct
Date: Thu, 14 Oct 2010 21:38:45 +0200 [thread overview]
Message-ID: <201010142138.45775.jbe@pengutronix.de> (raw)
From: Juergen Beisert <jbe@pengutronix.de>
Subject: Make the clock calculation easier to read and correct
Due to a wrong rounding while calculating the clock divider the requested clock
of 25 MHz resulted into a 48 MHz clock. With this patch a clock frequency
below or equal the requested one will be set.
By using 'div' and 'rate' as vars, its also easier to check against the data
sheet.
Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
drivers/mci/stm378x.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
Index: a/drivers/mci/stm378x.c
===================================================================
--- a/drivers/mci/stm378x.c
+++ b/drivers/mci/stm378x.c
@@ -474,7 +474,7 @@ static int stm_mci_adtc(struct device_d
*/
static unsigned setup_clock_speed(struct device_d *hw_dev, unsigned nc)
{
- unsigned ssp, div1, div2, reg;
+ unsigned ssp, div, rate, reg;
if (nc == 0U) {
/* TODO stop the clock */
@@ -483,21 +483,21 @@ static unsigned setup_clock_speed(struct
ssp = imx_get_sspclk(0) * 1000;
- for (div1 = 2; div1 < 255; div1 += 2) {
- div2 = ssp / nc / div1;
- if (div2 <= 0x100)
+ for (div = 2; div < 255; div += 2) {
+ rate = (((ssp + (nc >> 1) ) / nc) + (div >> 1)) / div;
+ if (rate <= 0x100)
break;
}
- if (div1 >= 255) {
+ if (div >= 255) {
pr_warning("Cannot set clock to %d Hz\n", nc);
return 0;
}
reg = readl(hw_dev->map_base + HW_SSP_TIMING) & SSP_TIMING_TIMEOUT_MASK;
- reg |= SSP_TIMING_CLOCK_DIVIDE(div1) | SSP_TIMING_CLOCK_RATE(div2 - 1);
+ reg |= SSP_TIMING_CLOCK_DIVIDE(div) | SSP_TIMING_CLOCK_RATE(rate - 1);
writel(reg, hw_dev->map_base + HW_SSP_TIMING);
- return ssp / div1 / div2;
+ return ssp / div / rate;
}
/**
--
Pengutronix e.K. | Juergen Beisert |
Linux Solutions for Science and Industry | Phone: +49-8766-939 228 |
Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2010-10-14 19:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=201010142138.45775.jbe@pengutronix.de \
--to=jbe@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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