Skip to content

Commit 6f21d14

Browse files
Wolfram Sanggeertu
authored andcommitted
clk: renesas: cpg-lib: Move RPC clock registration to the library
We want to reuse this code for V3U soon. Because its RPCCKCR register is at a different offset, the moved functions do not use the base register as an argument anymore but the RPCCKCR register itself. Verified that an Eagle board with R-Car V3M still works. Signed-off-by: Wolfram Sang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent f294a0e commit 6f21d14

File tree

3 files changed

+92
-87
lines changed

3 files changed

+92
-87
lines changed

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,87 @@ struct clk * __init cpg_sd_clk_register(const char *name,
267267
return clk;
268268
}
269269

270+
struct rpc_clock {
271+
struct clk_divider div;
272+
struct clk_gate gate;
273+
/*
274+
* One notifier covers both RPC and RPCD2 clocks as they are both
275+
* controlled by the same RPCCKCR register...
276+
*/
277+
struct cpg_simple_notifier csn;
278+
};
279+
280+
static const struct clk_div_table cpg_rpc_div_table[] = {
281+
{ 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 0, 0 },
282+
};
283+
284+
struct clk * __init cpg_rpc_clk_register(const char *name,
285+
void __iomem *rpcckcr, const char *parent_name,
286+
struct raw_notifier_head *notifiers)
287+
{
288+
struct rpc_clock *rpc;
289+
struct clk *clk;
290+
291+
rpc = kzalloc(sizeof(*rpc), GFP_KERNEL);
292+
if (!rpc)
293+
return ERR_PTR(-ENOMEM);
294+
295+
rpc->div.reg = rpcckcr;
296+
rpc->div.width = 3;
297+
rpc->div.table = cpg_rpc_div_table;
298+
rpc->div.lock = &cpg_lock;
299+
300+
rpc->gate.reg = rpcckcr;
301+
rpc->gate.bit_idx = 8;
302+
rpc->gate.flags = CLK_GATE_SET_TO_DISABLE;
303+
rpc->gate.lock = &cpg_lock;
304+
305+
rpc->csn.reg = rpcckcr;
306+
307+
clk = clk_register_composite(NULL, name, &parent_name, 1, NULL, NULL,
308+
&rpc->div.hw, &clk_divider_ops,
309+
&rpc->gate.hw, &clk_gate_ops,
310+
CLK_SET_RATE_PARENT);
311+
if (IS_ERR(clk)) {
312+
kfree(rpc);
313+
return clk;
314+
}
315+
316+
cpg_simple_notifier_register(notifiers, &rpc->csn);
317+
return clk;
318+
}
319+
320+
struct rpcd2_clock {
321+
struct clk_fixed_factor fixed;
322+
struct clk_gate gate;
323+
};
324+
325+
struct clk * __init cpg_rpcd2_clk_register(const char *name,
326+
void __iomem *rpcckcr,
327+
const char *parent_name)
328+
{
329+
struct rpcd2_clock *rpcd2;
330+
struct clk *clk;
331+
332+
rpcd2 = kzalloc(sizeof(*rpcd2), GFP_KERNEL);
333+
if (!rpcd2)
334+
return ERR_PTR(-ENOMEM);
335+
336+
rpcd2->fixed.mult = 1;
337+
rpcd2->fixed.div = 2;
338+
339+
rpcd2->gate.reg = rpcckcr;
340+
rpcd2->gate.bit_idx = 9;
341+
rpcd2->gate.flags = CLK_GATE_SET_TO_DISABLE;
342+
rpcd2->gate.lock = &cpg_lock;
343+
344+
clk = clk_register_composite(NULL, name, &parent_name, 1, NULL, NULL,
345+
&rpcd2->fixed.hw, &clk_fixed_factor_ops,
346+
&rpcd2->gate.hw, &clk_gate_ops,
347+
CLK_SET_RATE_PARENT);
348+
if (IS_ERR(clk))
349+
kfree(rpcd2);
350+
351+
return clk;
352+
}
270353

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ struct clk * __init cpg_sd_clk_register(const char *name,
3030
void __iomem *base, unsigned int offset, const char *parent_name,
3131
struct raw_notifier_head *notifiers, bool skip_first);
3232

33+
struct clk * __init cpg_rpc_clk_register(const char *name,
34+
void __iomem *rpcckcr, const char *parent_name,
35+
struct raw_notifier_head *notifiers);
36+
37+
struct clk * __init cpg_rpcd2_clk_register(const char *name,
38+
void __iomem *rpcckcr,
39+
const char *parent_name);
3340
#endif

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

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -301,95 +301,10 @@ static struct clk * __init cpg_z_clk_register(const char *name,
301301
return clk;
302302
}
303303

304-
struct rpc_clock {
305-
struct clk_divider div;
306-
struct clk_gate gate;
307-
/*
308-
* One notifier covers both RPC and RPCD2 clocks as they are both
309-
* controlled by the same RPCCKCR register...
310-
*/
311-
struct cpg_simple_notifier csn;
312-
};
313-
314304
static const struct clk_div_table cpg_rpcsrc_div_table[] = {
315305
{ 2, 5 }, { 3, 6 }, { 0, 0 },
316306
};
317307

318-
static const struct clk_div_table cpg_rpc_div_table[] = {
319-
{ 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 0, 0 },
320-
};
321-
322-
static struct clk * __init cpg_rpc_clk_register(const char *name,
323-
void __iomem *base, const char *parent_name,
324-
struct raw_notifier_head *notifiers)
325-
{
326-
struct rpc_clock *rpc;
327-
struct clk *clk;
328-
329-
rpc = kzalloc(sizeof(*rpc), GFP_KERNEL);
330-
if (!rpc)
331-
return ERR_PTR(-ENOMEM);
332-
333-
rpc->div.reg = base + CPG_RPCCKCR;
334-
rpc->div.width = 3;
335-
rpc->div.table = cpg_rpc_div_table;
336-
rpc->div.lock = &cpg_lock;
337-
338-
rpc->gate.reg = base + CPG_RPCCKCR;
339-
rpc->gate.bit_idx = 8;
340-
rpc->gate.flags = CLK_GATE_SET_TO_DISABLE;
341-
rpc->gate.lock = &cpg_lock;
342-
343-
rpc->csn.reg = base + CPG_RPCCKCR;
344-
345-
clk = clk_register_composite(NULL, name, &parent_name, 1, NULL, NULL,
346-
&rpc->div.hw, &clk_divider_ops,
347-
&rpc->gate.hw, &clk_gate_ops,
348-
CLK_SET_RATE_PARENT);
349-
if (IS_ERR(clk)) {
350-
kfree(rpc);
351-
return clk;
352-
}
353-
354-
cpg_simple_notifier_register(notifiers, &rpc->csn);
355-
return clk;
356-
}
357-
358-
struct rpcd2_clock {
359-
struct clk_fixed_factor fixed;
360-
struct clk_gate gate;
361-
};
362-
363-
static struct clk * __init cpg_rpcd2_clk_register(const char *name,
364-
void __iomem *base,
365-
const char *parent_name)
366-
{
367-
struct rpcd2_clock *rpcd2;
368-
struct clk *clk;
369-
370-
rpcd2 = kzalloc(sizeof(*rpcd2), GFP_KERNEL);
371-
if (!rpcd2)
372-
return ERR_PTR(-ENOMEM);
373-
374-
rpcd2->fixed.mult = 1;
375-
rpcd2->fixed.div = 2;
376-
377-
rpcd2->gate.reg = base + CPG_RPCCKCR;
378-
rpcd2->gate.bit_idx = 9;
379-
rpcd2->gate.flags = CLK_GATE_SET_TO_DISABLE;
380-
rpcd2->gate.lock = &cpg_lock;
381-
382-
clk = clk_register_composite(NULL, name, &parent_name, 1, NULL, NULL,
383-
&rpcd2->fixed.hw, &clk_fixed_factor_ops,
384-
&rpcd2->gate.hw, &clk_gate_ops,
385-
CLK_SET_RATE_PARENT);
386-
if (IS_ERR(clk))
387-
kfree(rpcd2);
388-
389-
return clk;
390-
}
391-
392-
393308
static const struct rcar_gen3_cpg_pll_config *cpg_pll_config __initdata;
394309
static unsigned int cpg_clk_extalr __initdata;
395310
static u32 cpg_mode __initdata;
@@ -600,11 +515,11 @@ struct clk * __init rcar_gen3_cpg_clk_register(struct device *dev,
600515
break;
601516

602517
case CLK_TYPE_GEN3_RPC:
603-
return cpg_rpc_clk_register(core->name, base,
518+
return cpg_rpc_clk_register(core->name, base + CPG_RPCCKCR,
604519
__clk_get_name(parent), notifiers);
605520

606521
case CLK_TYPE_GEN3_RPCD2:
607-
return cpg_rpcd2_clk_register(core->name, base,
522+
return cpg_rpcd2_clk_register(core->name, base + CPG_RPCCKCR,
608523
__clk_get_name(parent));
609524

610525
default:

0 commit comments

Comments
 (0)