diff options
| author | Haavard Skinnemoen <hskinnemoen@atmel.com> | 2007-06-19 15:40:01 +0200 | 
|---|---|---|
| committer | Haavard Skinnemoen <hskinnemoen@atmel.com> | 2007-06-19 15:40:01 +0200 | 
| commit | 448f5fea4c7dd531b69e4e60eed2a72b89b4ed6d (patch) | |
| tree | 022599b68a0e72f34f3f152f4a0056b557a06a44 /cpu/mpc86xx/spd_sdram.c | |
| parent | f2134f8e9eb006bdcd729e89f309c07b2fa45180 (diff) | |
| parent | 5ffa76a032279bc6d3230b703eda32d13305ba13 (diff) | |
| download | olio-uboot-2014.01-448f5fea4c7dd531b69e4e60eed2a72b89b4ed6d.tar.xz olio-uboot-2014.01-448f5fea4c7dd531b69e4e60eed2a72b89b4ed6d.zip  | |
Merge branch 'upstream'
Diffstat (limited to 'cpu/mpc86xx/spd_sdram.c')
| -rw-r--r-- | cpu/mpc86xx/spd_sdram.c | 26 | 
1 files changed, 19 insertions, 7 deletions
diff --git a/cpu/mpc86xx/spd_sdram.c b/cpu/mpc86xx/spd_sdram.c index ac9ff81ce..f37ab430b 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; +	/* use unsigned long long to avoid rounding errors */ +	const unsigned long long ULL_2e12 = 2000000000000ULL; +	unsigned long long clks; +	unsigned long long clks_temp; -	clks = picos / (2000000000 / (get_bus_freq(0) / 1000)); -	if (picos % (2000000000 / (get_bus_freq(0) / 1000)) != 0) { +	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;  }  |