Skip to content

Commit ed84ef1

Browse files
pcercueibebarino
authored andcommitted
clk: ingenic: Fix bugs with divided dividers
Two fixes in one: - In the "impose hardware constraints" block, the "logical" divider value (aka. not translated to the hardware) was clamped to fit in the register area, but this totally ignored the fact that the divider value can itself have a fixed divider. - The code that made sure that the divider value returned by the function was a multiple of its own fixed divider could result in a wrong value being calculated, because it was rounded down instead of rounded up. Fixes: 4afe2d1 ("clk: ingenic: Allow divider value to be divided") Co-developed-by: Artur Rojek <[email protected]> Signed-off-by: Artur Rojek <[email protected]> Signed-off-by: Paul Cercueil <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent e2ceaa8 commit ed84ef1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/clk/ingenic/cgu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,15 @@ ingenic_clk_calc_div(struct clk_hw *hw,
453453
}
454454

455455
/* Impose hardware constraints */
456-
div = min_t(unsigned, div, 1 << clk_info->div.bits);
457-
div = max_t(unsigned, div, 1);
456+
div = clamp_t(unsigned int, div, clk_info->div.div,
457+
clk_info->div.div << clk_info->div.bits);
458458

459459
/*
460460
* If the divider value itself must be divided before being written to
461461
* the divider register, we must ensure we don't have any bits set that
462462
* would be lost as a result of doing so.
463463
*/
464-
div /= clk_info->div.div;
464+
div = DIV_ROUND_UP(div, clk_info->div.div);
465465
div *= clk_info->div.div;
466466

467467
return div;

0 commit comments

Comments
 (0)