summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Yang <James.Yang@freescale.com>2007-03-16 13:02:53 -0500
committerJon Loeliger <jdl@freescale.com>2007-05-01 11:36:59 -0500
commitc1ab82669d9525998c34e802a12cad662723f22a (patch)
tree804587965298fa0ac74c0d566cebee5cffda686b
parent2e343b9a57f32e1bd08c35c9976910333fb4e13d (diff)
downloadu-boot-imx-c1ab82669d9525998c34e802a12cad662723f22a.zip
u-boot-imx-c1ab82669d9525998c34e802a12cad662723f22a.tar.gz
u-boot-imx-c1ab82669d9525998c34e802a12cad662723f22a.tar.bz2
Rewrote picos_to_clk() to avoid rounding errors.
Clarified that conversion is to DRAM clocks rather than platform clocks. Made function static to spd_sdram.c. Signed-off-by: James Yang <James.Yang@freescale.com> Signed-off-by: Jon Loeliger <jdl@freescale.com>
-rw-r--r--cpu/mpc86xx/spd_sdram.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/cpu/mpc86xx/spd_sdram.c b/cpu/mpc86xx/spd_sdram.c
index ac9ff81..f37ab43 100644
--- a/cpu/mpc86xx/spd_sdram.c
+++ b/cpu/mpc86xx/spd_sdram.c
@@ -51,20 +51,32 @@ extern int dma_xfer(void *dest, uint count, void *src);
#define CFG_SUPER_BANK_INTERLEAVING 0
/*
- * Convert picoseconds into clock cycles (rounding up if needed).
+ * Convert picoseconds into DRAM clock cycles (rounding up if needed).
*/
-int
-picos_to_clk(int picos)
+static unsigned int
+picos_to_clk(unsigned int picos)
{
- int clks;
-
- clks = picos / (2000000000 / (get_bus_freq(0) / 1000));
- if (picos % (2000000000 / (get_bus_freq(0) / 1000)) != 0) {
+ /* use unsigned long long to avoid rounding errors */
+ const unsigned long long ULL_2e12 = 2000000000000ULL;
+ unsigned long long clks;
+ unsigned long long clks_temp;
+
+ if (! picos)
+ return 0;
+
+ clks = get_bus_freq(0) * (unsigned long long) picos;
+ clks_temp = clks;
+ clks = clks / ULL_2e12;
+ if (clks_temp % ULL_2e12) {
clks++;
}
- return clks;
+ if (clks > 0xFFFFFFFFULL) {
+ clks = 0xFFFFFFFFULL;
+ }
+
+ return (unsigned int) clks;
}