summaryrefslogtreecommitdiffstats
path: root/arch/mips/ath79
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2019-01-11 09:22:30 -0500
committerPaul Burton <paul.burton@mips.com>2019-01-22 14:17:21 -0500
commit9b56e0d0cc6353865c5bbc41a18161215063fd33 (patch)
tree2c350f5e28cb312a36655f08cd1b4bee257c5830 /arch/mips/ath79
parent7b3415f581c70ef37b4a8a7e5be37bb117caa616 (diff)
MIPS: ath79: add helpers for setting clocks and expose the ref clock
Preparation for transitioning the legacy clock setup code over to OF. Signed-off-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: John Crispin <john@phrozen.org> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: James Hogan <jhogan@kernel.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: Pengutronix Kernel Team <kernel@pengutronix.de> Cc: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: devicetree@vger.kernel.org
Diffstat (limited to 'arch/mips/ath79')
-rw-r--r--arch/mips/ath79/clock.c128
1 files changed, 66 insertions, 62 deletions
diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c
index cf9158e3c2d9..50bc3b01a4c4 100644
--- a/arch/mips/ath79/clock.c
+++ b/arch/mips/ath79/clock.c
@@ -37,20 +37,46 @@ static struct clk_onecell_data clk_data = {
37 .clk_num = ARRAY_SIZE(clks), 37 .clk_num = ARRAY_SIZE(clks),
38}; 38};
39 39
40static struct clk *__init ath79_add_sys_clkdev( 40static const char * const clk_names[ATH79_CLK_END] = {
41 const char *id, unsigned long rate) 41 [ATH79_CLK_CPU] = "cpu",
42 [ATH79_CLK_DDR] = "ddr",
43 [ATH79_CLK_AHB] = "ahb",
44 [ATH79_CLK_REF] = "ref",
45};
46
47static const char * __init ath79_clk_name(int type)
42{ 48{
43 struct clk *clk; 49 BUG_ON(type >= ARRAY_SIZE(clk_names) || !clk_names[type]);
44 int err; 50 return clk_names[type];
51}
45 52
46 clk = clk_register_fixed_rate(NULL, id, NULL, 0, rate); 53static void __init __ath79_set_clk(int type, const char *name, struct clk *clk)
54{
47 if (IS_ERR(clk)) 55 if (IS_ERR(clk))
48 panic("failed to allocate %s clock structure", id); 56 panic("failed to allocate %s clock structure", clk_names[type]);
49 57
50 err = clk_register_clkdev(clk, id, NULL); 58 clks[type] = clk;
51 if (err) 59 clk_register_clkdev(clk, name, NULL);
52 panic("unable to register %s clock device", id); 60}
53 61
62static struct clk * __init ath79_set_clk(int type, unsigned long rate)
63{
64 const char *name = ath79_clk_name(type);
65 struct clk *clk;
66
67 clk = clk_register_fixed_rate(NULL, name, NULL, 0, rate);
68 __ath79_set_clk(type, name, clk);
69 return clk;
70}
71
72static struct clk * __init ath79_set_ff_clk(int type, const char *parent,
73 unsigned int mult, unsigned int div)
74{
75 const char *name = ath79_clk_name(type);
76 struct clk *clk;
77
78 clk = clk_register_fixed_factor(NULL, name, parent, 0, mult, div);
79 __ath79_set_clk(type, name, clk);
54 return clk; 80 return clk;
55} 81}
56 82
@@ -80,27 +106,15 @@ static void __init ar71xx_clocks_init(void)
80 div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2; 106 div = (((pll >> AR71XX_AHB_DIV_SHIFT) & AR71XX_AHB_DIV_MASK) + 1) * 2;
81 ahb_rate = cpu_rate / div; 107 ahb_rate = cpu_rate / div;
82 108
83 ath79_add_sys_clkdev("ref", ref_rate); 109 ath79_set_clk(ATH79_CLK_REF, ref_rate);
84 clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate); 110 ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
85 clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate); 111 ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
86 clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate); 112 ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
87 113
88 clk_add_alias("wdt", NULL, "ahb", NULL); 114 clk_add_alias("wdt", NULL, "ahb", NULL);
89 clk_add_alias("uart", NULL, "ahb", NULL); 115 clk_add_alias("uart", NULL, "ahb", NULL);
90} 116}
91 117
92static struct clk * __init ath79_reg_ffclk(const char *name,
93 const char *parent_name, unsigned int mult, unsigned int div)
94{
95 struct clk *clk;
96
97 clk = clk_register_fixed_factor(NULL, name, parent_name, 0, mult, div);
98 if (IS_ERR(clk))
99 panic("failed to allocate %s clock structure", name);
100
101 return clk;
102}
103
104static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base) 118static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base)
105{ 119{
106 u32 pll; 120 u32 pll;
@@ -114,24 +128,19 @@ static void __init ar724x_clk_init(struct clk *ref_clk, void __iomem *pll_base)
114 ddr_div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1; 128 ddr_div = ((pll >> AR724X_DDR_DIV_SHIFT) & AR724X_DDR_DIV_MASK) + 1;
115 ahb_div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2; 129 ahb_div = (((pll >> AR724X_AHB_DIV_SHIFT) & AR724X_AHB_DIV_MASK) + 1) * 2;
116 130
117 clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref", mult, div); 131 ath79_set_ff_clk(ATH79_CLK_CPU, "ref", mult, div);
118 clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref", mult, div * ddr_div); 132 ath79_set_ff_clk(ATH79_CLK_DDR, "ref", mult, div * ddr_div);
119 clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref", mult, div * ahb_div); 133 ath79_set_ff_clk(ATH79_CLK_AHB, "ref", mult, div * ahb_div);
120} 134}
121 135
122static void __init ar724x_clocks_init(void) 136static void __init ar724x_clocks_init(void)
123{ 137{
124 struct clk *ref_clk; 138 struct clk *ref_clk;
125 139
126 ref_clk = ath79_add_sys_clkdev("ref", AR724X_BASE_FREQ); 140 ref_clk = ath79_set_clk(ATH79_CLK_REF, AR724X_BASE_FREQ);
127 141
128 ar724x_clk_init(ref_clk, ath79_pll_base); 142 ar724x_clk_init(ref_clk, ath79_pll_base);
129 143
130 /* just make happy plat_time_init() from arch/mips/ath79/setup.c */
131 clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
132 clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
133 clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
134
135 clk_add_alias("wdt", NULL, "ahb", NULL); 144 clk_add_alias("wdt", NULL, "ahb", NULL);
136 clk_add_alias("uart", NULL, "ahb", NULL); 145 clk_add_alias("uart", NULL, "ahb", NULL);
137} 146}
@@ -186,12 +195,12 @@ static void __init ar9330_clk_init(struct clk *ref_clk, void __iomem *pll_base)
186 AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1; 195 AR933X_PLL_CLOCK_CTRL_AHB_DIV_MASK) + 1;
187 } 196 }
188 197
189 clks[ATH79_CLK_CPU] = ath79_reg_ffclk("cpu", "ref", 198 ath79_set_ff_clk(ATH79_CLK_CPU, "ref", ninit_mul,
190 ninit_mul, ref_div * out_div * cpu_div); 199 ref_div * out_div * cpu_div);
191 clks[ATH79_CLK_DDR] = ath79_reg_ffclk("ddr", "ref", 200 ath79_set_ff_clk(ATH79_CLK_DDR, "ref", ninit_mul,
192 ninit_mul, ref_div * out_div * ddr_div); 201 ref_div * out_div * ddr_div);
193 clks[ATH79_CLK_AHB] = ath79_reg_ffclk("ahb", "ref", 202 ath79_set_ff_clk(ATH79_CLK_AHB, "ref", ninit_mul,
194 ninit_mul, ref_div * out_div * ahb_div); 203 ref_div * out_div * ahb_div);
195} 204}
196 205
197static void __init ar933x_clocks_init(void) 206static void __init ar933x_clocks_init(void)
@@ -206,15 +215,10 @@ static void __init ar933x_clocks_init(void)
206 else 215 else
207 ref_rate = (25 * 1000 * 1000); 216 ref_rate = (25 * 1000 * 1000);
208 217
209 ref_clk = ath79_add_sys_clkdev("ref", ref_rate); 218 ref_clk = ath79_set_clk(ATH79_CLK_REF, ref_rate);
210 219
211 ar9330_clk_init(ref_clk, ath79_pll_base); 220 ar9330_clk_init(ref_clk, ath79_pll_base);
212 221
213 /* just make happy plat_time_init() from arch/mips/ath79/setup.c */
214 clk_register_clkdev(clks[ATH79_CLK_CPU], "cpu", NULL);
215 clk_register_clkdev(clks[ATH79_CLK_DDR], "ddr", NULL);
216 clk_register_clkdev(clks[ATH79_CLK_AHB], "ahb", NULL);
217
218 clk_add_alias("wdt", NULL, "ahb", NULL); 222 clk_add_alias("wdt", NULL, "ahb", NULL);
219 clk_add_alias("uart", NULL, "ref", NULL); 223 clk_add_alias("uart", NULL, "ref", NULL);
220} 224}
@@ -344,10 +348,10 @@ static void __init ar934x_clocks_init(void)
344 else 348 else
345 ahb_rate = cpu_pll / (postdiv + 1); 349 ahb_rate = cpu_pll / (postdiv + 1);
346 350
347 ath79_add_sys_clkdev("ref", ref_rate); 351 ath79_set_clk(ATH79_CLK_REF, ref_rate);
348 clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate); 352 ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
349 clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate); 353 ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
350 clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate); 354 ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
351 355
352 clk_add_alias("wdt", NULL, "ref", NULL); 356 clk_add_alias("wdt", NULL, "ref", NULL);
353 clk_add_alias("uart", NULL, "ref", NULL); 357 clk_add_alias("uart", NULL, "ref", NULL);
@@ -431,10 +435,10 @@ static void __init qca953x_clocks_init(void)
431 else 435 else
432 ahb_rate = cpu_pll / (postdiv + 1); 436 ahb_rate = cpu_pll / (postdiv + 1);
433 437
434 ath79_add_sys_clkdev("ref", ref_rate); 438 ath79_set_clk(ATH79_CLK_REF, ref_rate);
435 ath79_add_sys_clkdev("cpu", cpu_rate); 439 ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
436 ath79_add_sys_clkdev("ddr", ddr_rate); 440 ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
437 ath79_add_sys_clkdev("ahb", ahb_rate); 441 ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
438 442
439 clk_add_alias("wdt", NULL, "ref", NULL); 443 clk_add_alias("wdt", NULL, "ref", NULL);
440 clk_add_alias("uart", NULL, "ref", NULL); 444 clk_add_alias("uart", NULL, "ref", NULL);
@@ -516,10 +520,10 @@ static void __init qca955x_clocks_init(void)
516 else 520 else
517 ahb_rate = cpu_pll / (postdiv + 1); 521 ahb_rate = cpu_pll / (postdiv + 1);
518 522
519 ath79_add_sys_clkdev("ref", ref_rate); 523 ath79_set_clk(ATH79_CLK_REF, ref_rate);
520 clks[ATH79_CLK_CPU] = ath79_add_sys_clkdev("cpu", cpu_rate); 524 ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
521 clks[ATH79_CLK_DDR] = ath79_add_sys_clkdev("ddr", ddr_rate); 525 ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
522 clks[ATH79_CLK_AHB] = ath79_add_sys_clkdev("ahb", ahb_rate); 526 ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
523 527
524 clk_add_alias("wdt", NULL, "ref", NULL); 528 clk_add_alias("wdt", NULL, "ref", NULL);
525 clk_add_alias("uart", NULL, "ref", NULL); 529 clk_add_alias("uart", NULL, "ref", NULL);
@@ -620,10 +624,10 @@ static void __init qca956x_clocks_init(void)
620 else 624 else
621 ahb_rate = cpu_pll / (postdiv + 1); 625 ahb_rate = cpu_pll / (postdiv + 1);
622 626
623 ath79_add_sys_clkdev("ref", ref_rate); 627 ath79_set_clk(ATH79_CLK_REF, ref_rate);
624 ath79_add_sys_clkdev("cpu", cpu_rate); 628 ath79_set_clk(ATH79_CLK_CPU, cpu_rate);
625 ath79_add_sys_clkdev("ddr", ddr_rate); 629 ath79_set_clk(ATH79_CLK_DDR, ddr_rate);
626 ath79_add_sys_clkdev("ahb", ahb_rate); 630 ath79_set_clk(ATH79_CLK_AHB, ahb_rate);
627 631
628 clk_add_alias("wdt", NULL, "ref", NULL); 632 clk_add_alias("wdt", NULL, "ref", NULL);
629 clk_add_alias("uart", NULL, "ref", NULL); 633 clk_add_alias("uart", NULL, "ref", NULL);