Skip to content

Commit df98719

Browse files
committed
clk: renesas: rcar-gen3: Switch Z clocks to .determine_rate()
As the .round_rate() callback returns a long clock rate, it cannot return clock rates that do not fit in signed long, but do fit in unsigned long. Hence switch the Z clocks on R-Car Gen3 from the old .round_rate() callback to the newer .determine_rate() callback, which does not suffer from this limitation. This includes implementing range checking. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7aee839 commit df98719

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/clk/renesas/rcar-gen3-cpg.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,24 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw,
114114
32 * zclk->fixed_div);
115115
}
116116

117-
static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,
118-
unsigned long *parent_rate)
117+
static int cpg_z_clk_determine_rate(struct clk_hw *hw,
118+
struct clk_rate_request *req)
119119
{
120120
struct cpg_z_clk *zclk = to_z_clk(hw);
121+
unsigned int min_mult, max_mult, mult;
121122
unsigned long prate;
122-
unsigned int mult;
123123

124-
prate = *parent_rate / zclk->fixed_div;
125-
mult = div64_ul(rate * 32ULL, prate);
126-
mult = clamp(mult, 1U, 32U);
124+
prate = req->best_parent_rate / zclk->fixed_div;
125+
min_mult = max(div64_ul(req->min_rate * 32ULL, prate), 1ULL);
126+
max_mult = min(div64_ul(req->max_rate * 32ULL, prate), 32ULL);
127+
if (max_mult < min_mult)
128+
return -EINVAL;
127129

128-
return div_u64((u64)prate * mult, 32);
130+
mult = div64_ul(req->rate * 32ULL, prate);
131+
mult = clamp(mult, min_mult, max_mult);
132+
133+
req->rate = div_u64((u64)prate * mult, 32);
134+
return 0;
129135
}
130136

131137
static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
@@ -172,7 +178,7 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
172178

173179
static const struct clk_ops cpg_z_clk_ops = {
174180
.recalc_rate = cpg_z_clk_recalc_rate,
175-
.round_rate = cpg_z_clk_round_rate,
181+
.determine_rate = cpg_z_clk_determine_rate,
176182
.set_rate = cpg_z_clk_set_rate,
177183
};
178184

0 commit comments

Comments
 (0)