forked from Minki/linux
clk: sunxi-ng: Use u64 for calculation of nkmp rate
When parent rate is 24MHz and multiplier N >= 180, intermediate clock rate doesn't fit in 32 bit variable anymore. Because of that, introduce function for calculating clock rate which uses 64 bit variable for intermediate result. Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
This commit is contained in:
parent
d897ef56fa
commit
a5ebc3368e
@ -20,6 +20,18 @@ struct _ccu_nkmp {
|
||||
unsigned long p, min_p, max_p;
|
||||
};
|
||||
|
||||
static unsigned long ccu_nkmp_calc_rate(unsigned long parent,
|
||||
unsigned long n, unsigned long k,
|
||||
unsigned long m, unsigned long p)
|
||||
{
|
||||
u64 rate = parent;
|
||||
|
||||
rate *= n * k;
|
||||
do_div(rate, m * p);
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
static void ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
|
||||
struct _ccu_nkmp *nkmp)
|
||||
{
|
||||
@ -33,7 +45,9 @@ static void ccu_nkmp_find_best(unsigned long parent, unsigned long rate,
|
||||
for (_p = nkmp->min_p; _p <= nkmp->max_p; _p <<= 1) {
|
||||
unsigned long tmp_rate;
|
||||
|
||||
tmp_rate = parent * _n * _k / (_m * _p);
|
||||
tmp_rate = ccu_nkmp_calc_rate(parent,
|
||||
_n, _k,
|
||||
_m, _p);
|
||||
|
||||
if (tmp_rate > rate)
|
||||
continue;
|
||||
@ -107,7 +121,7 @@ static unsigned long ccu_nkmp_recalc_rate(struct clk_hw *hw,
|
||||
p = reg >> nkmp->p.shift;
|
||||
p &= (1 << nkmp->p.width) - 1;
|
||||
|
||||
return (parent_rate * n * k >> p) / m;
|
||||
return ccu_nkmp_calc_rate(parent_rate, n, k, m, 1 << p);
|
||||
}
|
||||
|
||||
static long ccu_nkmp_round_rate(struct clk_hw *hw, unsigned long rate,
|
||||
@ -127,7 +141,8 @@ static long ccu_nkmp_round_rate(struct clk_hw *hw, unsigned long rate,
|
||||
|
||||
ccu_nkmp_find_best(*parent_rate, rate, &_nkmp);
|
||||
|
||||
return *parent_rate * _nkmp.n * _nkmp.k / (_nkmp.m * _nkmp.p);
|
||||
return ccu_nkmp_calc_rate(*parent_rate, _nkmp.n, _nkmp.k,
|
||||
_nkmp.m, _nkmp.p);
|
||||
}
|
||||
|
||||
static int ccu_nkmp_set_rate(struct clk_hw *hw, unsigned long rate,
|
||||
|
Loading…
Reference in New Issue
Block a user