Skip to content
Snippets Groups Projects
Commit c1ab8266 authored by James Yang's avatar James Yang Committed by Jon Loeliger
Browse files

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: default avatarJames Yang <James.Yang@freescale.com>
Signed-off-by: default avatarJon Loeliger <jdl@freescale.com>
parent 2e343b9a
No related branches found
No related tags found
No related merge requests found
...@@ -51,20 +51,32 @@ extern int dma_xfer(void *dest, uint count, void *src); ...@@ -51,20 +51,32 @@ extern int dma_xfer(void *dest, uint count, void *src);
#define CFG_SUPER_BANK_INTERLEAVING 0 #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 static unsigned int
picos_to_clk(int picos) picos_to_clk(unsigned int picos)
{ {
int clks; /* use unsigned long long to avoid rounding errors */
const unsigned long long ULL_2e12 = 2000000000000ULL;
clks = picos / (2000000000 / (get_bus_freq(0) / 1000)); unsigned long long clks;
if (picos % (2000000000 / (get_bus_freq(0) / 1000)) != 0) { 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++; clks++;
} }
return clks; if (clks > 0xFFFFFFFFULL) {
clks = 0xFFFFFFFFULL;
}
return (unsigned int) clks;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment