mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 11:41:38 -04:00
clk: divider: fix selection of divider when rounding to closest
It's an invalid approach to assume that among two divider values
the one nearer the exact divider is the better one.
Assume a parent rate of 1000 Hz, a divider with CLK_DIVIDER_POWER_OF_TWO
and a target rate of 89 Hz. The exact divider is ~ 11.236 so 8 and 16
are the candidates to choose from yielding rates 125 Hz and 62.5 Hz
respectivly. While 8 is nearer to 11.236 than 16 is, the latter is still
the better divider as 62.5 is nearer to 89 than 125 is.
Fixes: 774b514390 (clk: divider: Add round to closest divider)
Signed-off-by: Uwe Kleine-König <[email protected]>
Acked-by: Sascha Hauer <[email protected]>
Acked-by: Maxime Coquelin <[email protected]>
Signed-off-by: Michael Turquette <[email protected]>
This commit is contained in:
parent
da321133b5
commit
26bac95aa8
1 changed files with 5 additions and 1 deletions
|
|
@ -220,6 +220,7 @@ static int _div_round_closest(const struct clk_div_table *table,
|
|||
unsigned long flags)
|
||||
{
|
||||
int up, down, div;
|
||||
unsigned long up_rate, down_rate;
|
||||
|
||||
up = down = div = DIV_ROUND_CLOSEST(parent_rate, rate);
|
||||
|
||||
|
|
@ -231,7 +232,10 @@ static int _div_round_closest(const struct clk_div_table *table,
|
|||
down = _round_down_table(table, div);
|
||||
}
|
||||
|
||||
return (up - div) <= (div - down) ? up : down;
|
||||
up_rate = DIV_ROUND_UP(parent_rate, up);
|
||||
down_rate = DIV_ROUND_UP(parent_rate, down);
|
||||
|
||||
return (rate - up_rate) <= (down_rate - rate) ? up : down;
|
||||
}
|
||||
|
||||
static int _div_round(const struct clk_div_table *table,
|
||||
|
|
|
|||
Loading…
Reference in a new issue