Skip to content

Commit 3a0e848

Browse files
committed
clk: renesas: rcar-gen3: Add boost support to Z clocks
Add support for switching the Z and Z2 clocks between normal and boost modes, by requesting clock rate changes to parent PLLs. Inspired by a patch in the BSP by Takeshi Kihara <[email protected]>. Signed-off-by: Geert Uytterhoeven <[email protected]> Acked-by: Stephen Boyd <[email protected]> Reviewed-by: Yoshihiro Shimoda <[email protected]> Tested-by: Yoshihiro Shimoda <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3f70795 commit 3a0e848

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct cpg_z_clk {
165165
struct clk_hw hw;
166166
void __iomem *reg;
167167
void __iomem *kick_reg;
168+
unsigned long max_rate; /* Maximum rate for normal mode */
168169
unsigned int fixed_div;
169170
u32 mask;
170171
};
@@ -190,15 +191,26 @@ static int cpg_z_clk_determine_rate(struct clk_hw *hw,
190191
{
191192
struct cpg_z_clk *zclk = to_z_clk(hw);
192193
unsigned int min_mult, max_mult, mult;
193-
unsigned long prate;
194+
unsigned long rate, prate;
195+
196+
rate = min(req->rate, req->max_rate);
197+
if (rate <= zclk->max_rate) {
198+
/* Set parent rate to initial value for normal modes */
199+
prate = zclk->max_rate;
200+
} else {
201+
/* Set increased parent rate for boost modes */
202+
prate = rate;
203+
}
204+
req->best_parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw),
205+
prate * zclk->fixed_div);
194206

195207
prate = req->best_parent_rate / zclk->fixed_div;
196208
min_mult = max(div64_ul(req->min_rate * 32ULL, prate), 1ULL);
197209
max_mult = min(div64_ul(req->max_rate * 32ULL, prate), 32ULL);
198210
if (max_mult < min_mult)
199211
return -EINVAL;
200212

201-
mult = DIV_ROUND_CLOSEST_ULL(req->rate * 32ULL, prate);
213+
mult = DIV_ROUND_CLOSEST_ULL(rate * 32ULL, prate);
202214
mult = clamp(mult, min_mult, max_mult);
203215

204216
req->rate = DIV_ROUND_CLOSEST_ULL((u64)prate * mult, 32);
@@ -268,7 +280,7 @@ static struct clk * __init cpg_z_clk_register(const char *name,
268280

269281
init.name = name;
270282
init.ops = &cpg_z_clk_ops;
271-
init.flags = 0;
283+
init.flags = CLK_SET_RATE_PARENT;
272284
init.parent_names = &parent_name;
273285
init.num_parents = 1;
274286

@@ -279,9 +291,13 @@ static struct clk * __init cpg_z_clk_register(const char *name,
279291
zclk->fixed_div = div; /* PLLVCO x 1/div x SYS-CPU divider */
280292

281293
clk = clk_register(NULL, &zclk->hw);
282-
if (IS_ERR(clk))
294+
if (IS_ERR(clk)) {
283295
kfree(zclk);
296+
return clk;
297+
}
284298

299+
zclk->max_rate = clk_hw_get_rate(clk_hw_get_parent(&zclk->hw)) /
300+
zclk->fixed_div;
285301
return clk;
286302
}
287303

0 commit comments

Comments
 (0)