Atmel AT91 SD/MMC clock too fast
Due to integer truncation, the calculated divisor for the SD/MMC clock may be too low, resulting in a clock that is too fast. For example, the at91sam9g45 is typically run with a master clock at 133 MHz. There is no divisor possible that will result in a 25 or 50 MHz clock as is typically used for a SD card. The existing code will set the clock at 33 MHz or 66 MHz when 25 or 50 MHz is requested. A Kingston class 10 8G SDHC was found to not work properly at 33 MHz, but did after patching. The patch, in this case, generated a 22.1 MHz clock ( 133/6 ). This is the same frequency that this card sees after booting Linux. If a perfect integer division is possible, the patch will provide an exact clock rate. If not, the frequency will be the closest possible without exceeding the target.
The following was based on barebox 2012-07:
drivers/mci/atmel_mci.c 2012-07-15 23:14:02.203872596 -0700 renamed from drivers/mci/atmel_mci.c 2012-07-02 01:31:52.000000000 -0700 +1 -1
@@ -76,7 +76,8 @@ unsigned int clk_in = clk_get_rate(host->clk); if (clk_ios > 0) { - divider = (clk_in / clk_ios) / 2; + /* don't allow integer truncation to result in too small a
divider */
+ divider = (clk_in + 2 * clk_ios - 1) / (2 * clk_ios);
if (divider > 0)
divider -= 1;
}_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Hi George,
Quoted 22 lines · George Pontis
Due to integer truncation, the calculated divisor for the SD/MMC clock may be too low, resulting in a clock that is too fast. For example, the at91sam9g45 is typically run with a master clock at 133 MHz. There is no divisor possible that will result in a 25 or 50 MHz clock as is typically used for a SD card. The existing code will set the clock at 33 MHz or 66 MHz when 25 or 50 MHz is requested. A Kingston class 10 8G SDHC was found to not work properly at 33 MHz, but did after patching. The patch, in this case, generated a 22.1 MHz clock ( 133/6 ). This is the same frequency that this card sees after booting Linux. If a perfect integer division is possible, the patch will provide an exact clock rate. If not, the frequency will be the closest possible without exceeding the target.
The following was based on barebox 2012-07:
drivers/mci/atmel_mci.c 2012-07-15 23:14:02.203872596 -0700 renamed from drivers/mci/atmel_mci.c 2012-07-02 01:31:52.000000000 -0700 +1
-1@@ -76,7 +76,8 @@ unsigned int clk_in = clk_get_rate(host->clk); if (clk_ios > 0) { - divider = (clk_in / clk_ios) / 2; + /* don't allow integer truncation to result in too small a
Quoted 2 lines
divider */
+ divider = (clk_in+ 2 *clk_ios- 1) / (2 *clk_ios);
DIV_ROUND_UP(clk_in, clk_ios / 2) instead?
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 9 lines
-----Original Message-----
From: Sascha Hauer [mailto:[email protected]]
Sent: Monday, July 16, 2012 1:33 AM
To: George Pontis
Cc: [email protected]
Subject: Re: Atmel AT91 SD/MMC clock too fast
Quoted 4 lines
Hi George,
Quoted 1 line · George Pontis
Due to integer truncation, the calculated divisor for the SD/MMC clock
may
Quoted 3 lines
Quoted 3 lines
be too low, resulting in a clock that is too fast. For example, the at91sam9g45 is typically run with a master clock at 133 MHz. There is no divisor possible that will result in a 25 or 50 MHz clock as is
typically
Quoted 5 lines
Quoted 1 line
used for a SD card. The existing code will set the clock at 33 MHz or 66
MHz
Quoted 1 line
when 25 or 50 MHz is requested. A Kingston class 10 8G SDHC was found to
not
Quoted 1 line
work properly at 33 MHz, but did after patching. The patch, in this
case,
Quoted 1 line
Quoted 1 line
generated a 22.1 MHz clock ( 133/6 ). This is the same frequency that
this
Quoted 1 line
Quoted 1 line
card sees after booting Linux. If a perfect integer division is
possible,
Quoted 1 line
Quoted 1 line
the patch will provide an exact clock rate. If not, the frequency will
be
Quoted 4 lines
Quoted 4 lines
the closest possible without exceeding the target.
The following was based on barebox 2012-07:
Quoted 8 lines
drivers/mci/atmel_mci.c 2012-07-15 23:14:02.203872596 -0700 line 79
Quoted 8 lines
drivers/mci/atmel_mci.c 2012-07-15 23:14:02.203872596 -0700 renamed from drivers/mci/atmel_mci.c 2012-07-02 01:31:52.000000000 -0700 +1
-1@@ -76,7 +76,8 @@ unsigned int clk_in = clk_get_rate(host->clk); if (clk_ios > 0) { - divider = (clk_in / clk_ios) / 2; + /* don't allow integer truncation to result in too small
a
Quoted 7 lines
Quoted 2 lines
divider */
+ divider = (clk_in+ 2 *clk_ios- 1) / (2 *clk_ios);
DIV_ROUND_UP(clk_in, clk_ios / 2)instead?Sascha
Looks good, but it needs a divisor of 2*clk_ios. Using that macro:
drivers/mci/atmel_mci.c 2012-07-15 23:14:02.203872596 -0700 renamed from drivers/mci/atmel_mci.c 2012-07-02 01:31:52.000000000 -0700 +1 -1
@@ -76,7 +76,8 @@ unsigned int clk_in = clk_get_rate(host->clk); if (clk_ios > 0) { - divider = (clk_in / clk_ios) / 2; + /* don't allow integer truncation to result in too small a
divider */
+ divider = DIV_ROUND_UP( clk_in, (2 * clk_ios));
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox