powerpc/mpc8xxx: Fix picos_to_mclk() and get_memory_clk_period_ps()
Reduce the calculation error to 1ps. Signed-off-by: York Sun <yorksun@freescale.com> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
This commit is contained in:
parent
639f330f5f
commit
905acde21a
|
@ -20,7 +20,8 @@
|
||||||
#define ULL_8FS 0xFFFFFFFFULL
|
#define ULL_8FS 0xFFFFFFFFULL
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Round mclk_ps to nearest 10 ps in memory controller code.
|
* Round up mclk_ps to nearest 1 ps in memory controller code
|
||||||
|
* if the error is 0.5ps or more.
|
||||||
*
|
*
|
||||||
* If an imprecise data rate is too high due to rounding error
|
* If an imprecise data rate is too high due to rounding error
|
||||||
* propagation, compute a suitably rounded mclk_ps to compute
|
* propagation, compute a suitably rounded mclk_ps to compute
|
||||||
|
@ -32,42 +33,37 @@ unsigned int get_memory_clk_period_ps(void)
|
||||||
unsigned int result;
|
unsigned int result;
|
||||||
|
|
||||||
/* Round to nearest 10ps, being careful about 64-bit multiply/divide */
|
/* Round to nearest 10ps, being careful about 64-bit multiply/divide */
|
||||||
unsigned long long mclk_ps = ULL_2E12;
|
unsigned long long rem, mclk_ps = ULL_2E12;
|
||||||
|
|
||||||
/* Add 5*data_rate, for rounding */
|
|
||||||
mclk_ps += 5*(unsigned long long)data_rate;
|
|
||||||
|
|
||||||
/* Now perform the big divide, the result fits in 32-bits */
|
/* Now perform the big divide, the result fits in 32-bits */
|
||||||
do_div(mclk_ps, data_rate);
|
rem = do_div(mclk_ps, data_rate);
|
||||||
result = mclk_ps;
|
result = (rem >= (data_rate >> 1)) ? mclk_ps + 1 : mclk_ps;
|
||||||
|
|
||||||
/* We still need to round to 10ps */
|
return result;
|
||||||
return 10 * (result/10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
|
/* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
|
||||||
unsigned int picos_to_mclk(unsigned int picos)
|
unsigned int picos_to_mclk(unsigned int picos)
|
||||||
{
|
{
|
||||||
unsigned long long clks, clks_rem;
|
unsigned long long clks, clks_rem;
|
||||||
|
unsigned long data_rate = get_ddr_freq(0);
|
||||||
|
|
||||||
/* Short circuit for zero picos */
|
/* Short circuit for zero picos */
|
||||||
if (!picos)
|
if (!picos)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* First multiply the time by the data rate (32x32 => 64) */
|
/* First multiply the time by the data rate (32x32 => 64) */
|
||||||
clks = picos * (unsigned long long)get_ddr_freq(0);
|
clks = picos * (unsigned long long)data_rate;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now divide by 5^12 and track the 32-bit remainder, then divide
|
* Now divide by 5^12 and track the 32-bit remainder, then divide
|
||||||
* by 2*(2^12) using shifts (and updating the remainder).
|
* by 2*(2^12) using shifts (and updating the remainder).
|
||||||
*/
|
*/
|
||||||
clks_rem = do_div(clks, UL_5POW12);
|
clks_rem = do_div(clks, UL_5POW12);
|
||||||
clks_rem <<= 13;
|
clks_rem += (clks & (UL_2POW13-1)) * UL_5POW12;
|
||||||
clks_rem |= clks & (UL_2POW13-1);
|
|
||||||
clks >>= 13;
|
clks >>= 13;
|
||||||
|
|
||||||
/* If we had a remainder, then round up */
|
/* If we had a remainder greater than the 1ps error, then round up */
|
||||||
if (clks_rem)
|
if (clks_rem > data_rate)
|
||||||
clks++;
|
clks++;
|
||||||
|
|
||||||
/* Clamp to the maximum representable value */
|
/* Clamp to the maximum representable value */
|
||||||
|
|
Loading…
Reference in New Issue