Skip to content

Commit 732a610

Browse files
committed
clk: renesas: rcar-gen4: Add support for fractional 9.24 PLLs
The custom clock driver that models the PLL clocks on R-Car Gen4 supports only fractional 8.25 PLLs, as used on R-Car V4H/V4M. R-Car S4-8 uses integer and fractional multiplication fields that are one bit larger resp. smaller, and a slightly different formula. Extend the existing support to fractional 9.24 PLL, and introduce new clock types and helper macros to describe these PLLs. Note that there is no use case for variable fractional 9.24 PLLs yet, as the Cortex-A55 cores on R-Car S4-8 do not support High Performance mode. Hence the PLL is always modeled as a fixed PLL, regardless of the description, Signed-off-by: Geert Uytterhoeven <[email protected]> Reviewed-by: Yoshihiro Shimoda <[email protected]> Link: https://lore.kernel.org/5684eda1260435c8eceabc274e0b18cb280a6341.1721648548.git.geert+renesas@glider.be
1 parent 3284ffb commit 732a610

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ static u32 cpg_mode __initdata;
5656
#define CPG_PLLxCR0_NI8 GENMASK(27, 20) /* Integer mult. factor */
5757
#define CPG_PLLxCR1_NF25 GENMASK(24, 0) /* Fractional mult. factor */
5858

59+
/* Fractional 9.24 PLL */
60+
#define CPG_PLLxCR0_NI9 GENMASK(28, 20) /* Integer mult. factor */
61+
#define CPG_PLLxCR1_NF24 GENMASK(23, 0) /* Fractional mult. factor */
62+
5963
#define CPG_PLLxCR_STC GENMASK(30, 24) /* R_Car V3U PLLxCR */
6064

6165
#define CPG_RPCCKCR 0x874 /* RPC Clock Freq. Control Register */
@@ -189,6 +193,30 @@ static const struct clk_ops cpg_pll_v8_25_clk_ops = {
189193
.set_rate = cpg_pll_8_25_clk_set_rate,
190194
};
191195

196+
static unsigned long cpg_pll_9_24_clk_recalc_rate(struct clk_hw *hw,
197+
unsigned long parent_rate)
198+
{
199+
struct cpg_pll_clk *pll_clk = to_pll_clk(hw);
200+
u32 cr0 = readl(pll_clk->pllcr0_reg);
201+
unsigned int ni, nf;
202+
unsigned long rate;
203+
204+
ni = FIELD_GET(CPG_PLLxCR0_NI9, cr0) + 1;
205+
rate = parent_rate * ni;
206+
if (cr0 & CPG_PLLxCR0_SSMODE_FM) {
207+
nf = FIELD_GET(CPG_PLLxCR1_NF24, readl(pll_clk->pllcr1_reg));
208+
rate += mul_u64_u32_shr(parent_rate, nf, 24);
209+
} else {
210+
rate *= 2;
211+
}
212+
213+
return rate;
214+
}
215+
216+
static const struct clk_ops cpg_pll_f9_24_clk_ops = {
217+
.recalc_rate = cpg_pll_9_24_clk_recalc_rate,
218+
};
219+
192220
static struct clk * __init cpg_pll_clk_register(const char *name,
193221
const char *parent_name,
194222
void __iomem *base,
@@ -461,6 +489,14 @@ struct clk * __init rcar_gen4_cpg_clk_register(struct device *dev,
461489
base, core->offset,
462490
&cpg_pll_v8_25_clk_ops);
463491

492+
case CLK_TYPE_GEN4_PLL_V9_24:
493+
/* Variable fractional 9.24 is not yet supported, using fixed */
494+
fallthrough;
495+
case CLK_TYPE_GEN4_PLL_F9_24:
496+
return cpg_pll_clk_register(core->name, __clk_get_name(parent),
497+
base, core->offset,
498+
&cpg_pll_f9_24_clk_ops);
499+
464500
case CLK_TYPE_GEN4_Z:
465501
return cpg_z_clk_register(core->name, __clk_get_name(parent),
466502
base, core->div, core->offset);

drivers/clk/renesas/rcar-gen4-cpg.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ enum rcar_gen4_clk_types {
2121
CLK_TYPE_GEN4_PLL6,
2222
CLK_TYPE_GEN4_PLL_F8_25, /* Fixed fractional 8.25 PLL */
2323
CLK_TYPE_GEN4_PLL_V8_25, /* Variable fractional 8.25 PLL */
24+
CLK_TYPE_GEN4_PLL_F9_24, /* Fixed fractional 9.24 PLL */
25+
CLK_TYPE_GEN4_PLL_V9_24, /* Variable fractional 9.24 PLL */
2426
CLK_TYPE_GEN4_SDSRC,
2527
CLK_TYPE_GEN4_SDH,
2628
CLK_TYPE_GEN4_SD,
@@ -55,6 +57,12 @@ enum rcar_gen4_clk_types {
5557
#define DEF_GEN4_PLL_V8_25(_name, _idx, _id, _parent) \
5658
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_V8_25, _parent, .offset = _idx)
5759

60+
#define DEF_GEN4_PLL_F9_24(_name, _idx, _id, _parent) \
61+
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_F9_24, _parent, .offset = _idx)
62+
63+
#define DEF_GEN4_PLL_V9_24(_name, _idx, _id, _parent) \
64+
DEF_BASE(_name, _id, CLK_TYPE_GEN4_PLL_V9_24, _parent, .offset = _idx)
65+
5866
#define DEF_GEN4_Z(_name, _id, _type, _parent, _div, _offset) \
5967
DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
6068

0 commit comments

Comments
 (0)