Skip to content

Commit 20fc4ea

Browse files
prabhakarladgeertu
authored andcommitted
clk: renesas: rzv2h: Refactor PLL configuration handling
Refactor PLL handling by introducing a `struct pll` to encapsulate PLL configuration parameters, ensuring consistency with the existing dynamic divider structure. Introduce the `PLL_PACK()` macro to simplify PLL structure initialization and update the `DEF_PLL()` macro to use the new `pll` structure. Modify relevant clock register functions to utilize the structured PLL data instead of raw configuration values. This refactoring improves code readability, maintainability, and alignment with the existing clock configuration approach. Signed-off-by: Lad Prabhakar <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 0af2f6b commit 20fc4ea

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

drivers/clk/renesas/r9a09g047-cpg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static const struct cpg_core_clk r9a09g047_core_clks[] __initconst = {
7979
DEF_FIXED(".pllcm33", CLK_PLLCM33, CLK_QEXTAL, 200, 3),
8080
DEF_FIXED(".pllcln", CLK_PLLCLN, CLK_QEXTAL, 200, 3),
8181
DEF_FIXED(".plldty", CLK_PLLDTY, CLK_QEXTAL, 200, 3),
82-
DEF_PLL(".pllca55", CLK_PLLCA55, CLK_QEXTAL, PLL_CONF(0x64)),
82+
DEF_PLL(".pllca55", CLK_PLLCA55, CLK_QEXTAL, PLLCA55),
8383
DEF_FIXED(".pllvdo", CLK_PLLVDO, CLK_QEXTAL, 105, 2),
8484

8585
/* Internal Core Clocks */

drivers/clk/renesas/r9a09g057-cpg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static const struct cpg_core_clk r9a09g057_core_clks[] __initconst = {
8585
DEF_FIXED(".pllcm33", CLK_PLLCM33, CLK_QEXTAL, 200, 3),
8686
DEF_FIXED(".pllcln", CLK_PLLCLN, CLK_QEXTAL, 200, 3),
8787
DEF_FIXED(".plldty", CLK_PLLDTY, CLK_QEXTAL, 200, 3),
88-
DEF_PLL(".pllca55", CLK_PLLCA55, CLK_QEXTAL, PLL_CONF(0x64)),
88+
DEF_PLL(".pllca55", CLK_PLLCA55, CLK_QEXTAL, PLLCA55),
8989
DEF_FIXED(".pllvdo", CLK_PLLVDO, CLK_QEXTAL, 105, 2),
9090

9191
/* Internal Core Clocks */

drivers/clk/renesas/rzv2h-cpg.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
#define CPG_BUS_1_MSTOP (0xd00)
4545
#define CPG_BUS_MSTOP(m) (CPG_BUS_1_MSTOP + ((m) - 1) * 4)
4646

47+
#define CPG_PLL_CLK1(x) ((x) + 0x004)
4748
#define KDIV(val) ((s16)FIELD_GET(GENMASK(31, 16), (val)))
4849
#define MDIV(val) FIELD_GET(GENMASK(15, 6), (val))
4950
#define PDIV(val) FIELD_GET(GENMASK(5, 0), (val))
51+
#define CPG_PLL_CLK2(x) ((x) + 0x008)
5052
#define SDIV(val) FIELD_GET(GENMASK(2, 0), (val))
5153

5254
#define DDIV_DIVCTL_WEN(shift) BIT((shift) + 16)
@@ -94,7 +96,7 @@ struct pll_clk {
9496
struct rzv2h_cpg_priv *priv;
9597
void __iomem *base;
9698
struct clk_hw hw;
97-
unsigned int conf;
99+
struct pll pll;
98100
unsigned int type;
99101
};
100102

@@ -145,14 +147,15 @@ static unsigned long rzv2h_cpg_pll_clk_recalc_rate(struct clk_hw *hw,
145147
{
146148
struct pll_clk *pll_clk = to_pll(hw);
147149
struct rzv2h_cpg_priv *priv = pll_clk->priv;
150+
struct pll pll = pll_clk->pll;
148151
unsigned int clk1, clk2;
149152
u64 rate;
150153

151-
if (!PLL_CLK_ACCESS(pll_clk->conf))
154+
if (!pll.has_clkn)
152155
return 0;
153156

154-
clk1 = readl(priv->base + PLL_CLK1_OFFSET(pll_clk->conf));
155-
clk2 = readl(priv->base + PLL_CLK2_OFFSET(pll_clk->conf));
157+
clk1 = readl(priv->base + CPG_PLL_CLK1(pll.offset));
158+
clk2 = readl(priv->base + CPG_PLL_CLK2(pll.offset));
156159

157160
rate = mul_u64_u32_shr(parent_rate, (MDIV(clk1) << 16) + KDIV(clk1),
158161
16 + SDIV(clk2));
@@ -193,7 +196,7 @@ rzv2h_cpg_pll_clk_register(const struct cpg_core_clk *core,
193196
init.num_parents = 1;
194197

195198
pll_clk->hw.init = &init;
196-
pll_clk->conf = core->cfg.conf;
199+
pll_clk->pll = core->cfg.pll;
197200
pll_clk->base = base;
198201
pll_clk->priv = priv;
199202
pll_clk->type = core->type;

drivers/clk/renesas/rzv2h-cpg.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@
1010

1111
#include <linux/bitfield.h>
1212

13+
/**
14+
* struct pll - Structure for PLL configuration
15+
*
16+
* @offset: STBY register offset
17+
* @has_clkn: Flag to indicate if CLK1/2 are accessible or not
18+
*/
19+
struct pll {
20+
unsigned int offset:9;
21+
unsigned int has_clkn:1;
22+
};
23+
24+
#define PLL_PACK(_offset, _has_clkn) \
25+
((struct pll){ \
26+
.offset = _offset, \
27+
.has_clkn = _has_clkn \
28+
})
29+
30+
#define PLLCA55 PLL_PACK(0x60, 1)
31+
1332
/**
1433
* struct ddiv - Structure for dynamic switching divider
1534
*
@@ -74,6 +93,7 @@ struct cpg_core_clk {
7493
union {
7594
unsigned int conf;
7695
struct ddiv ddiv;
96+
struct pll pll;
7797
} cfg;
7898
const struct clk_div_table *dtable;
7999
u32 flag;
@@ -87,18 +107,12 @@ enum clk_types {
87107
CLK_TYPE_DDIV, /* Dynamic Switching Divider */
88108
};
89109

90-
/* BIT(31) indicates if CLK1/2 are accessible or not */
91-
#define PLL_CONF(n) (BIT(31) | ((n) & ~GENMASK(31, 16)))
92-
#define PLL_CLK_ACCESS(n) ((n) & BIT(31) ? 1 : 0)
93-
#define PLL_CLK1_OFFSET(n) ((n) & ~GENMASK(31, 16))
94-
#define PLL_CLK2_OFFSET(n) (((n) & ~GENMASK(31, 16)) + (0x4))
95-
96110
#define DEF_TYPE(_name, _id, _type...) \
97111
{ .name = _name, .id = _id, .type = _type }
98112
#define DEF_BASE(_name, _id, _type, _parent...) \
99113
DEF_TYPE(_name, _id, _type, .parent = _parent)
100-
#define DEF_PLL(_name, _id, _parent, _conf) \
101-
DEF_TYPE(_name, _id, CLK_TYPE_PLL, .parent = _parent, .cfg.conf = _conf)
114+
#define DEF_PLL(_name, _id, _parent, _pll_packed) \
115+
DEF_TYPE(_name, _id, CLK_TYPE_PLL, .parent = _parent, .cfg.pll = _pll_packed)
102116
#define DEF_INPUT(_name, _id) \
103117
DEF_TYPE(_name, _id, CLK_TYPE_IN)
104118
#define DEF_FIXED(_name, _id, _parent, _mult, _div) \

0 commit comments

Comments
 (0)