Skip to content

Commit 02c6959

Browse files
committed
clk: renesas: div6: Implement range checking
Consider the minimum and maximum clock rates imposed by clock users when calculating the most appropriate clock rate in the .determine_rate() callback. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/35ceb262c71f1b2e9864a39bde9dafd78b2981f4.1617281699.git.geert+renesas@glider.be
1 parent 1c924fc commit 02c6959

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/clk/renesas/clk-div6.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ static int cpg_div6_clock_determine_rate(struct clk_hw *hw,
106106
unsigned long prate, calc_rate, diff, best_rate, best_prate;
107107
unsigned int num_parents = clk_hw_get_num_parents(hw);
108108
struct clk_hw *parent, *best_parent = NULL;
109+
unsigned int i, min_div, max_div, div;
109110
unsigned long min_diff = ULONG_MAX;
110-
unsigned int i, div;
111111

112112
for (i = 0; i < num_parents; i++) {
113113
parent = clk_hw_get_parent_by_index(hw, i);
@@ -118,7 +118,13 @@ static int cpg_div6_clock_determine_rate(struct clk_hw *hw,
118118
if (!prate)
119119
continue;
120120

121+
min_div = max(DIV_ROUND_UP(prate, req->max_rate), 1UL);
122+
max_div = req->min_rate ? min(prate / req->min_rate, 64UL) : 64;
123+
if (max_div < min_div)
124+
continue;
125+
121126
div = cpg_div6_clock_calc_div(req->rate, prate);
127+
div = clamp(div, min_div, max_div);
122128
calc_rate = prate / div;
123129
diff = calc_rate > req->rate ? calc_rate - req->rate
124130
: req->rate - calc_rate;

0 commit comments

Comments
 (0)