1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2013 Freescale Semiconductor, Inc.
6 * clock driver for Freescale QorIQ SoCs.
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <dt-bindings/clock/fsl,qoriq-clockgen.h>
12 #include <linux/cleanup.h>
13 #include <linux/clk.h>
14 #include <linux/clk-provider.h>
15 #include <linux/clkdev.h>
16 #include <linux/fsl/guts.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/of_address.h>
22 #include <linux/platform_device.h>
23 #include <linux/slab.h>
30 #define PLATFORM_PLL 0
34 #define CGA_PLL4 4 /* only on clockgen-1.0, which lacks CGB */
37 #define MAX_PLL_DIV 32
39 struct clockgen_pll_div
{
45 struct clockgen_pll_div div
[MAX_PLL_DIV
];
48 #define CLKSEL_VALID 1
49 #define CLKSEL_80PCT 2 /* Only allowed if PLL <= 80% of max cpu freq */
51 struct clockgen_sourceinfo
{
52 u32 flags
; /* CLKSEL_xxx */
53 int pll
; /* CGx_PLLn */
54 int div
; /* PLL_DIVn */
57 #define NUM_MUX_PARENTS 16
59 struct clockgen_muxinfo
{
60 struct clockgen_sourceinfo clksel
[NUM_MUX_PARENTS
];
69 * cmux freq must be >= platform pll.
70 * If not set, cmux freq must be >= platform pll/2
72 #define CG_CMUX_GE_PLAT 1
74 #define CG_PLL_8BIT 2 /* PLLCnGSR[CFG] is 8 bits, not 6 */
75 #define CG_VER3 4 /* version 3 cg: reg layout different */
76 #define CG_LITTLE_ENDIAN 8
78 struct clockgen_chipinfo
{
79 const char *compat
, *guts_compat
;
80 const struct clockgen_muxinfo
*cmux_groups
[2];
81 const struct clockgen_muxinfo
*hwaccel
[NUM_HWACCEL
];
82 void (*init_periph
)(struct clockgen
*cg
);
83 int cmux_to_group
[NUM_CMUX
+ 1]; /* array should be -1 terminated */
84 u32 pll_mask
; /* 1 << n bit set if PLL n is valid */
85 u32 flags
; /* CG_xxx */
89 struct device_node
*node
;
91 struct clockgen_chipinfo info
; /* mutable copy */
92 struct clk
*sysclk
, *coreclk
;
93 struct clockgen_pll pll
[6];
94 struct clk
*cmux
[NUM_CMUX
];
95 struct clk
*hwaccel
[NUM_HWACCEL
];
97 struct ccsr_guts __iomem
*guts
;
100 static struct clockgen clockgen
;
101 static bool add_cpufreq_dev __initdata
;
103 static void cg_out(struct clockgen
*cg
, u32 val
, u32 __iomem
*reg
)
105 if (cg
->info
.flags
& CG_LITTLE_ENDIAN
)
108 iowrite32be(val
, reg
);
111 static u32
cg_in(struct clockgen
*cg
, u32 __iomem
*reg
)
115 if (cg
->info
.flags
& CG_LITTLE_ENDIAN
)
118 val
= ioread32be(reg
);
123 static const struct clockgen_muxinfo p2041_cmux_grp1
= {
125 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
126 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
127 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
131 static const struct clockgen_muxinfo p2041_cmux_grp2
= {
133 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
134 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
135 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
139 static const struct clockgen_muxinfo p5020_cmux_grp1
= {
141 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
142 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
143 [4] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL2
, PLL_DIV1
},
147 static const struct clockgen_muxinfo p5020_cmux_grp2
= {
149 [0] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV1
},
150 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
151 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
155 static const struct clockgen_muxinfo p5040_cmux_grp1
= {
157 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
158 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
159 [4] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL2
, PLL_DIV1
},
160 [5] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL2
, PLL_DIV2
},
164 static const struct clockgen_muxinfo p5040_cmux_grp2
= {
166 [0] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV1
},
167 [1] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV2
},
168 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
169 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
173 static const struct clockgen_muxinfo p4080_cmux_grp1
= {
175 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
176 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
177 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
178 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
179 [8] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL3
, PLL_DIV1
},
183 static const struct clockgen_muxinfo p4080_cmux_grp2
= {
185 [0] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV1
},
186 [8] = { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV1
},
187 [9] = { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV2
},
188 [12] = { CLKSEL_VALID
, CGA_PLL4
, PLL_DIV1
},
189 [13] = { CLKSEL_VALID
, CGA_PLL4
, PLL_DIV2
},
193 static const struct clockgen_muxinfo t1023_cmux
= {
195 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
196 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
200 static const struct clockgen_muxinfo t1040_cmux
= {
202 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
203 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
204 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
205 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
210 static const struct clockgen_muxinfo clockgen2_cmux_cga
= {
212 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
213 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
214 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
216 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
217 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
218 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
220 { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV1
},
221 { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV2
},
222 { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV4
},
226 static const struct clockgen_muxinfo clockgen2_cmux_cga12
= {
228 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
229 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
230 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
232 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
233 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
234 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
238 static const struct clockgen_muxinfo clockgen2_cmux_cgb
= {
240 { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV1
},
241 { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV2
},
242 { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV4
},
244 { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV1
},
245 { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV2
},
246 { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV4
},
250 static const struct clockgen_muxinfo ls1021a_cmux
= {
252 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
253 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
254 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
258 static const struct clockgen_muxinfo ls1028a_hwa1
= {
260 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
261 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
262 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
263 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
264 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
266 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
267 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
271 static const struct clockgen_muxinfo ls1028a_hwa2
= {
273 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
274 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
275 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
276 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
277 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
279 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
280 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
284 static const struct clockgen_muxinfo ls1028a_hwa3
= {
286 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
287 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
288 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
289 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
290 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
292 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
293 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
297 static const struct clockgen_muxinfo ls1028a_hwa4
= {
299 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
300 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
301 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
302 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
303 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
305 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
306 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
310 static const struct clockgen_muxinfo ls1043a_hwa1
= {
314 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
315 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
318 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
319 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
323 static const struct clockgen_muxinfo ls1043a_hwa2
= {
326 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
328 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
332 static const struct clockgen_muxinfo ls1046a_hwa1
= {
336 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
337 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
338 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
339 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
340 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
341 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
345 static const struct clockgen_muxinfo ls1046a_hwa2
= {
348 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
349 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
350 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
353 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
357 static const struct clockgen_muxinfo ls1088a_hwa1
= {
360 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
361 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
362 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
363 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
365 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
366 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
370 static const struct clockgen_muxinfo ls1088a_hwa2
= {
373 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
374 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
375 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
376 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
378 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
379 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
383 static const struct clockgen_muxinfo ls1012a_cmux
= {
385 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
387 [2] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
391 static const struct clockgen_muxinfo t1023_hwa1
= {
394 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
395 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
396 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
400 static const struct clockgen_muxinfo t1023_hwa2
= {
402 [6] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
406 static const struct clockgen_muxinfo t2080_hwa1
= {
409 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
410 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
411 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
412 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
413 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
414 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
415 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
419 static const struct clockgen_muxinfo t2080_hwa2
= {
422 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
423 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
424 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
425 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
426 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
427 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
428 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
432 static const struct clockgen_muxinfo t4240_hwa1
= {
434 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV2
},
435 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
436 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
437 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
438 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
440 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
441 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
445 static const struct clockgen_muxinfo t4240_hwa4
= {
447 [2] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV2
},
448 [3] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV3
},
449 [4] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV4
},
450 [5] = { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
451 [6] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV2
},
455 static const struct clockgen_muxinfo t4240_hwa5
= {
457 [2] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV2
},
458 [3] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV3
},
459 [4] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV4
},
460 [5] = { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
461 [6] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV2
},
462 [7] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV3
},
466 #define RCWSR7_FM1_CLK_SEL 0x40000000
467 #define RCWSR7_FM2_CLK_SEL 0x20000000
468 #define RCWSR7_HWA_ASYNC_DIV 0x04000000
470 static void __init
p2041_init_periph(struct clockgen
*cg
)
474 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
476 if (reg
& RCWSR7_FM1_CLK_SEL
)
477 cg
->fman
[0] = cg
->pll
[CGA_PLL2
].div
[PLL_DIV2
].clk
;
479 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
482 static void __init
p4080_init_periph(struct clockgen
*cg
)
486 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
488 if (reg
& RCWSR7_FM1_CLK_SEL
)
489 cg
->fman
[0] = cg
->pll
[CGA_PLL3
].div
[PLL_DIV2
].clk
;
491 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
493 if (reg
& RCWSR7_FM2_CLK_SEL
)
494 cg
->fman
[1] = cg
->pll
[CGA_PLL3
].div
[PLL_DIV2
].clk
;
496 cg
->fman
[1] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
499 static void __init
p5020_init_periph(struct clockgen
*cg
)
504 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
505 if (reg
& RCWSR7_HWA_ASYNC_DIV
)
508 if (reg
& RCWSR7_FM1_CLK_SEL
)
509 cg
->fman
[0] = cg
->pll
[CGA_PLL2
].div
[div
].clk
;
511 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
514 static void __init
p5040_init_periph(struct clockgen
*cg
)
519 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
520 if (reg
& RCWSR7_HWA_ASYNC_DIV
)
523 if (reg
& RCWSR7_FM1_CLK_SEL
)
524 cg
->fman
[0] = cg
->pll
[CGA_PLL3
].div
[div
].clk
;
526 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
528 if (reg
& RCWSR7_FM2_CLK_SEL
)
529 cg
->fman
[1] = cg
->pll
[CGA_PLL3
].div
[div
].clk
;
531 cg
->fman
[1] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
534 static void __init
t1023_init_periph(struct clockgen
*cg
)
536 cg
->fman
[0] = cg
->hwaccel
[1];
539 static void __init
t1040_init_periph(struct clockgen
*cg
)
541 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV1
].clk
;
544 static void __init
t2080_init_periph(struct clockgen
*cg
)
546 cg
->fman
[0] = cg
->hwaccel
[0];
549 static void __init
t4240_init_periph(struct clockgen
*cg
)
551 cg
->fman
[0] = cg
->hwaccel
[3];
552 cg
->fman
[1] = cg
->hwaccel
[4];
555 static const struct clockgen_chipinfo chipinfo
[] = {
557 .compat
= "fsl,b4420-clockgen",
558 .guts_compat
= "fsl,b4860-device-config",
559 .init_periph
= t2080_init_periph
,
561 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
569 .pll_mask
= BIT(PLATFORM_PLL
) |
570 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
) |
571 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
572 .flags
= CG_PLL_8BIT
,
575 .compat
= "fsl,b4860-clockgen",
576 .guts_compat
= "fsl,b4860-device-config",
577 .init_periph
= t2080_init_periph
,
579 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
587 .pll_mask
= BIT(PLATFORM_PLL
) |
588 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
) |
589 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
590 .flags
= CG_PLL_8BIT
,
593 .compat
= "fsl,ls1021a-clockgen",
600 .pll_mask
= BIT(PLATFORM_PLL
) |
601 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
604 .compat
= "fsl,ls1028a-clockgen",
606 &clockgen2_cmux_cga12
609 &ls1028a_hwa1
, &ls1028a_hwa2
,
610 &ls1028a_hwa3
, &ls1028a_hwa4
615 .pll_mask
= BIT(PLATFORM_PLL
) |
616 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
617 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
620 .compat
= "fsl,ls1043a-clockgen",
621 .init_periph
= t2080_init_periph
,
626 &ls1043a_hwa1
, &ls1043a_hwa2
631 .pll_mask
= BIT(PLATFORM_PLL
) |
632 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
633 .flags
= CG_PLL_8BIT
,
636 .compat
= "fsl,ls1046a-clockgen",
637 .init_periph
= t2080_init_periph
,
642 &ls1046a_hwa1
, &ls1046a_hwa2
647 .pll_mask
= BIT(PLATFORM_PLL
) |
648 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
649 .flags
= CG_PLL_8BIT
,
652 .compat
= "fsl,ls1088a-clockgen",
654 &clockgen2_cmux_cga12
657 &ls1088a_hwa1
, &ls1088a_hwa2
662 .pll_mask
= BIT(PLATFORM_PLL
) |
663 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
664 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
667 .compat
= "fsl,ls1012a-clockgen",
674 .pll_mask
= BIT(PLATFORM_PLL
) | BIT(CGA_PLL1
),
677 .compat
= "fsl,ls2080a-clockgen",
679 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
684 .pll_mask
= BIT(PLATFORM_PLL
) |
685 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) |
686 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
687 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
690 .compat
= "fsl,lx2160a-clockgen",
692 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
695 0, 0, 0, 0, 1, 1, 1, 1, -1
697 .pll_mask
= BIT(PLATFORM_PLL
) |
698 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) |
699 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
700 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
703 .compat
= "fsl,p2041-clockgen",
704 .guts_compat
= "fsl,qoriq-device-config-1.0",
705 .init_periph
= p2041_init_periph
,
707 &p2041_cmux_grp1
, &p2041_cmux_grp2
712 .pll_mask
= BIT(PLATFORM_PLL
) |
713 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
716 .compat
= "fsl,p3041-clockgen",
717 .guts_compat
= "fsl,qoriq-device-config-1.0",
718 .init_periph
= p2041_init_periph
,
720 &p2041_cmux_grp1
, &p2041_cmux_grp2
725 .pll_mask
= BIT(PLATFORM_PLL
) |
726 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
729 .compat
= "fsl,p4080-clockgen",
730 .guts_compat
= "fsl,qoriq-device-config-1.0",
731 .init_periph
= p4080_init_periph
,
733 &p4080_cmux_grp1
, &p4080_cmux_grp2
736 0, 0, 0, 0, 1, 1, 1, 1, -1
738 .pll_mask
= BIT(PLATFORM_PLL
) |
739 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) |
740 BIT(CGA_PLL3
) | BIT(CGA_PLL4
),
743 .compat
= "fsl,p5020-clockgen",
744 .guts_compat
= "fsl,qoriq-device-config-1.0",
745 .init_periph
= p5020_init_periph
,
747 &p5020_cmux_grp1
, &p5020_cmux_grp2
752 .pll_mask
= BIT(PLATFORM_PLL
) |
753 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
756 .compat
= "fsl,p5040-clockgen",
757 .guts_compat
= "fsl,p5040-device-config",
758 .init_periph
= p5040_init_periph
,
760 &p5040_cmux_grp1
, &p5040_cmux_grp2
765 .pll_mask
= BIT(PLATFORM_PLL
) |
766 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
),
769 .compat
= "fsl,t1023-clockgen",
770 .guts_compat
= "fsl,t1023-device-config",
771 .init_periph
= t1023_init_periph
,
776 &t1023_hwa1
, &t1023_hwa2
781 .pll_mask
= BIT(PLATFORM_PLL
) | BIT(CGA_PLL1
),
782 .flags
= CG_PLL_8BIT
,
785 .compat
= "fsl,t1040-clockgen",
786 .guts_compat
= "fsl,t1040-device-config",
787 .init_periph
= t1040_init_periph
,
794 .pll_mask
= BIT(PLATFORM_PLL
) |
795 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
796 .flags
= CG_PLL_8BIT
,
799 .compat
= "fsl,t2080-clockgen",
800 .guts_compat
= "fsl,t2080-device-config",
801 .init_periph
= t2080_init_periph
,
803 &clockgen2_cmux_cga12
806 &t2080_hwa1
, &t2080_hwa2
811 .pll_mask
= BIT(PLATFORM_PLL
) |
812 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
813 .flags
= CG_PLL_8BIT
,
816 .compat
= "fsl,t4240-clockgen",
817 .guts_compat
= "fsl,t4240-device-config",
818 .init_periph
= t4240_init_periph
,
820 &clockgen2_cmux_cga
, &clockgen2_cmux_cgb
823 &t4240_hwa1
, NULL
, NULL
, &t4240_hwa4
, &t4240_hwa5
828 .pll_mask
= BIT(PLATFORM_PLL
) |
829 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
) |
830 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
831 .flags
= CG_PLL_8BIT
,
839 const struct clockgen_muxinfo
*info
;
841 u8 parent_to_clksel
[NUM_MUX_PARENTS
];
842 s8 clksel_to_parent
[NUM_MUX_PARENTS
];
846 #define to_mux_hwclock(p) container_of(p, struct mux_hwclock, hw)
847 #define CLKSEL_MASK 0x78000000
848 #define CLKSEL_SHIFT 27
850 static int mux_set_parent(struct clk_hw
*hw
, u8 idx
)
852 struct mux_hwclock
*hwc
= to_mux_hwclock(hw
);
855 if (idx
>= hwc
->num_parents
)
858 clksel
= hwc
->parent_to_clksel
[idx
];
859 cg_out(hwc
->cg
, (clksel
<< CLKSEL_SHIFT
) & CLKSEL_MASK
, hwc
->reg
);
864 static u8
mux_get_parent(struct clk_hw
*hw
)
866 struct mux_hwclock
*hwc
= to_mux_hwclock(hw
);
870 clksel
= (cg_in(hwc
->cg
, hwc
->reg
) & CLKSEL_MASK
) >> CLKSEL_SHIFT
;
872 ret
= hwc
->clksel_to_parent
[clksel
];
874 pr_err("%s: mux at %p has bad clksel\n", __func__
, hwc
->reg
);
881 static const struct clk_ops cmux_ops
= {
882 .determine_rate
= clk_hw_determine_rate_no_reparent
,
883 .get_parent
= mux_get_parent
,
884 .set_parent
= mux_set_parent
,
888 * Don't allow setting for now, as the clock options haven't been
889 * sanitized for additional restrictions.
891 static const struct clk_ops hwaccel_ops
= {
892 .get_parent
= mux_get_parent
,
895 static const struct clockgen_pll_div
*get_pll_div(struct clockgen
*cg
,
896 struct mux_hwclock
*hwc
,
901 if (!(hwc
->info
->clksel
[idx
].flags
& CLKSEL_VALID
))
904 pll
= hwc
->info
->clksel
[idx
].pll
;
905 div
= hwc
->info
->clksel
[idx
].div
;
907 return &cg
->pll
[pll
].div
[div
];
910 static struct clk
* __init
create_mux_common(struct clockgen
*cg
,
911 struct mux_hwclock
*hwc
,
912 const struct clk_ops
*ops
,
913 unsigned long min_rate
,
914 unsigned long max_rate
,
915 unsigned long pct80_rate
,
916 const char *fmt
, int idx
)
918 struct clk_init_data init
= {};
920 const struct clockgen_pll_div
*div
;
921 const char *parent_names
[NUM_MUX_PARENTS
];
925 snprintf(name
, sizeof(name
), fmt
, idx
);
927 for (i
= 0, j
= 0; i
< NUM_MUX_PARENTS
; i
++) {
930 hwc
->clksel_to_parent
[i
] = -1;
932 div
= get_pll_div(cg
, hwc
, i
);
936 rate
= clk_get_rate(div
->clk
);
938 if (hwc
->info
->clksel
[i
].flags
& CLKSEL_80PCT
&&
946 parent_names
[j
] = div
->name
;
947 hwc
->parent_to_clksel
[j
] = i
;
948 hwc
->clksel_to_parent
[i
] = j
;
954 init
.parent_names
= parent_names
;
955 init
.num_parents
= hwc
->num_parents
= j
;
957 hwc
->hw
.init
= &init
;
960 clk
= clk_register(NULL
, &hwc
->hw
);
962 pr_err("%s: Couldn't register %s: %ld\n", __func__
, name
,
971 static struct clk
* __init
create_one_cmux(struct clockgen
*cg
, int idx
)
973 struct mux_hwclock
*hwc
;
974 const struct clockgen_pll_div
*div
;
975 unsigned long plat_rate
, min_rate
;
976 u64 max_rate
, pct80_rate
;
979 hwc
= kzalloc(sizeof(*hwc
), GFP_KERNEL
);
983 if (cg
->info
.flags
& CG_VER3
)
984 hwc
->reg
= cg
->regs
+ 0x70000 + 0x20 * idx
;
986 hwc
->reg
= cg
->regs
+ 0x20 * idx
;
988 hwc
->info
= cg
->info
.cmux_groups
[cg
->info
.cmux_to_group
[idx
]];
991 * Find the rate for the default clksel, and treat it as the
992 * maximum rated core frequency. If this is an incorrect
993 * assumption, certain clock options (possibly including the
994 * default clksel) may be inappropriately excluded on certain
997 clksel
= (cg_in(cg
, hwc
->reg
) & CLKSEL_MASK
) >> CLKSEL_SHIFT
;
998 div
= get_pll_div(cg
, hwc
, clksel
);
1004 max_rate
= clk_get_rate(div
->clk
);
1005 pct80_rate
= max_rate
* 8;
1006 do_div(pct80_rate
, 10);
1008 plat_rate
= clk_get_rate(cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV1
].clk
);
1010 if (cg
->info
.flags
& CG_CMUX_GE_PLAT
)
1011 min_rate
= plat_rate
;
1013 min_rate
= plat_rate
/ 2;
1015 return create_mux_common(cg
, hwc
, &cmux_ops
, min_rate
, max_rate
,
1016 pct80_rate
, "cg-cmux%d", idx
);
1019 static struct clk
* __init
create_one_hwaccel(struct clockgen
*cg
, int idx
)
1021 struct mux_hwclock
*hwc
;
1023 hwc
= kzalloc(sizeof(*hwc
), GFP_KERNEL
);
1027 hwc
->reg
= cg
->regs
+ 0x20 * idx
+ 0x10;
1028 hwc
->info
= cg
->info
.hwaccel
[idx
];
1030 return create_mux_common(cg
, hwc
, &hwaccel_ops
, 0, ULONG_MAX
, 0,
1031 "cg-hwaccel%d", idx
);
1034 static void __init
create_muxes(struct clockgen
*cg
)
1038 for (i
= 0; i
< ARRAY_SIZE(cg
->cmux
); i
++) {
1039 if (cg
->info
.cmux_to_group
[i
] < 0)
1041 if (cg
->info
.cmux_to_group
[i
] >=
1042 ARRAY_SIZE(cg
->info
.cmux_groups
)) {
1047 cg
->cmux
[i
] = create_one_cmux(cg
, i
);
1050 for (i
= 0; i
< ARRAY_SIZE(cg
->hwaccel
); i
++) {
1051 if (!cg
->info
.hwaccel
[i
])
1054 cg
->hwaccel
[i
] = create_one_hwaccel(cg
, i
);
1058 static void __init
_clockgen_init(struct device_node
*np
, bool legacy
);
1061 * Legacy nodes may get probed before the parent clockgen node.
1062 * It is assumed that device trees with legacy nodes will not
1063 * contain a "clocks" property -- otherwise the input clocks may
1064 * not be initialized at this point.
1066 static void __init
legacy_init_clockgen(struct device_node
*np
)
1068 if (!clockgen
.node
) {
1069 struct device_node
*parent_np
__free(device_node
) = of_get_parent(np
);
1070 _clockgen_init(parent_np
, true);
1075 static void __init
core_mux_init(struct device_node
*np
)
1078 struct resource res
;
1081 legacy_init_clockgen(np
);
1083 if (of_address_to_resource(np
, 0, &res
))
1086 idx
= (res
.start
& 0xf0) >> 5;
1087 clk
= clockgen
.cmux
[idx
];
1089 rc
= of_clk_add_provider(np
, of_clk_src_simple_get
, clk
);
1091 pr_err("%s: Couldn't register clk provider for node %pOFn: %d\n",
1097 static struct clk __init
1098 *sysclk_from_fixed(struct device_node
*node
, const char *name
)
1102 if (of_property_read_u32(node
, "clock-frequency", &rate
))
1103 return ERR_PTR(-ENODEV
);
1105 return clk_register_fixed_rate(NULL
, name
, NULL
, 0, rate
);
1108 static struct clk __init
*input_clock(const char *name
, struct clk
*clk
)
1110 const char *input_name
;
1112 /* Register the input clock under the desired name. */
1113 input_name
= __clk_get_name(clk
);
1114 clk
= clk_register_fixed_factor(NULL
, name
, input_name
,
1117 pr_err("%s: Couldn't register %s: %ld\n", __func__
, name
,
1123 static struct clk __init
*input_clock_by_name(const char *name
,
1128 clk
= of_clk_get_by_name(clockgen
.node
, dtname
);
1132 return input_clock(name
, clk
);
1135 static struct clk __init
*input_clock_by_index(const char *name
, int idx
)
1139 clk
= of_clk_get(clockgen
.node
, 0);
1143 return input_clock(name
, clk
);
1146 static struct clk
* __init
create_sysclk(const char *name
)
1148 struct device_node
*sysclk
;
1151 clk
= sysclk_from_fixed(clockgen
.node
, name
);
1155 clk
= input_clock_by_name(name
, "sysclk");
1159 clk
= input_clock_by_index(name
, 0);
1163 sysclk
= of_get_child_by_name(clockgen
.node
, "sysclk");
1165 clk
= sysclk_from_fixed(sysclk
, name
);
1166 of_node_put(sysclk
);
1171 pr_err("%s: No input sysclk\n", __func__
);
1175 static struct clk
* __init
create_coreclk(const char *name
)
1179 clk
= input_clock_by_name(name
, "coreclk");
1184 * This indicates a mix of legacy nodes with the new coreclk
1185 * mechanism, which should never happen. If this error occurs,
1186 * don't use the wrong input clock just because coreclk isn't
1189 if (WARN_ON(PTR_ERR(clk
) == -EPROBE_DEFER
))
1196 static void __init
sysclk_init(struct device_node
*node
)
1200 legacy_init_clockgen(node
);
1202 clk
= clockgen
.sysclk
;
1204 of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
1207 #define PLL_KILL BIT(31)
1209 static void __init
create_one_pll(struct clockgen
*cg
, int idx
)
1213 struct clockgen_pll
*pll
= &cg
->pll
[idx
];
1214 const char *input
= "cg-sysclk";
1217 if (!(cg
->info
.pll_mask
& (1 << idx
)))
1220 if (cg
->coreclk
&& idx
!= PLATFORM_PLL
) {
1221 if (IS_ERR(cg
->coreclk
))
1224 input
= "cg-coreclk";
1227 if (cg
->info
.flags
& CG_VER3
) {
1230 reg
= cg
->regs
+ 0x60080;
1233 reg
= cg
->regs
+ 0x80;
1236 reg
= cg
->regs
+ 0xa0;
1239 reg
= cg
->regs
+ 0x10080;
1242 reg
= cg
->regs
+ 0x100a0;
1245 WARN_ONCE(1, "index %d\n", idx
);
1249 if (idx
== PLATFORM_PLL
)
1250 reg
= cg
->regs
+ 0xc00;
1252 reg
= cg
->regs
+ 0x800 + 0x20 * (idx
- 1);
1255 /* Get the multiple of PLL */
1256 mult
= cg_in(cg
, reg
);
1258 /* Check if this PLL is disabled */
1259 if (mult
& PLL_KILL
) {
1260 pr_debug("%s(): pll %p disabled\n", __func__
, reg
);
1264 if ((cg
->info
.flags
& CG_VER3
) ||
1265 ((cg
->info
.flags
& CG_PLL_8BIT
) && idx
!= PLATFORM_PLL
))
1266 mult
= (mult
& GENMASK(8, 1)) >> 1;
1268 mult
= (mult
& GENMASK(6, 1)) >> 1;
1270 for (i
= 0; i
< ARRAY_SIZE(pll
->div
); i
++) {
1275 * For platform PLL, there are MAX_PLL_DIV divider clocks.
1276 * For core PLL, there are 4 divider clocks at most.
1278 if (idx
!= PLATFORM_PLL
&& i
>= 4)
1281 snprintf(pll
->div
[i
].name
, sizeof(pll
->div
[i
].name
),
1282 "cg-pll%d-div%d", idx
, i
+ 1);
1284 clk
= clk_register_fixed_factor(NULL
,
1285 pll
->div
[i
].name
, input
, 0, mult
, i
+ 1);
1287 pr_err("%s: %s: register failed %ld\n",
1288 __func__
, pll
->div
[i
].name
, PTR_ERR(clk
));
1292 pll
->div
[i
].clk
= clk
;
1293 ret
= clk_register_clkdev(clk
, pll
->div
[i
].name
, NULL
);
1295 pr_err("%s: %s: register to lookup table failed %d\n",
1296 __func__
, pll
->div
[i
].name
, ret
);
1301 static void __init
create_plls(struct clockgen
*cg
)
1305 for (i
= 0; i
< ARRAY_SIZE(cg
->pll
); i
++)
1306 create_one_pll(cg
, i
);
1309 static void __init
legacy_pll_init(struct device_node
*np
, int idx
)
1311 struct clockgen_pll
*pll
;
1312 struct clk_onecell_data
*onecell_data
;
1313 struct clk
**subclks
;
1316 legacy_init_clockgen(np
);
1318 pll
= &clockgen
.pll
[idx
];
1319 count
= of_property_count_strings(np
, "clock-output-names");
1321 BUILD_BUG_ON(ARRAY_SIZE(pll
->div
) < 4);
1322 subclks
= kcalloc(4, sizeof(struct clk
*), GFP_KERNEL
);
1326 onecell_data
= kmalloc(sizeof(*onecell_data
), GFP_KERNEL
);
1331 subclks
[0] = pll
->div
[0].clk
;
1332 subclks
[1] = pll
->div
[1].clk
;
1333 subclks
[2] = pll
->div
[3].clk
;
1335 subclks
[0] = pll
->div
[0].clk
;
1336 subclks
[1] = pll
->div
[1].clk
;
1337 subclks
[2] = pll
->div
[2].clk
;
1338 subclks
[3] = pll
->div
[3].clk
;
1341 onecell_data
->clks
= subclks
;
1342 onecell_data
->clk_num
= count
;
1344 rc
= of_clk_add_provider(np
, of_clk_src_onecell_get
, onecell_data
);
1346 pr_err("%s: Couldn't register clk provider for node %pOFn: %d\n",
1353 kfree(onecell_data
);
1359 static void __init
pltfrm_pll_init(struct device_node
*np
)
1361 legacy_pll_init(np
, PLATFORM_PLL
);
1365 static void __init
core_pll_init(struct device_node
*np
)
1367 struct resource res
;
1370 if (of_address_to_resource(np
, 0, &res
))
1373 if ((res
.start
& 0xfff) == 0xc00) {
1375 * ls1021a devtree labels the platform PLL
1376 * with the core PLL compatible
1378 pltfrm_pll_init(np
);
1380 idx
= (res
.start
& 0xf0) >> 5;
1381 legacy_pll_init(np
, CGA_PLL1
+ idx
);
1385 static struct clk
*clockgen_clk_get(struct of_phandle_args
*clkspec
, void *data
)
1387 struct clockgen
*cg
= data
;
1389 struct clockgen_pll
*pll
;
1392 if (clkspec
->args_count
< 2) {
1393 pr_err("%s: insufficient phandle args\n", __func__
);
1394 return ERR_PTR(-EINVAL
);
1397 type
= clkspec
->args
[0];
1398 idx
= clkspec
->args
[1];
1401 case QORIQ_CLK_SYSCLK
:
1406 case QORIQ_CLK_CMUX
:
1407 if (idx
>= ARRAY_SIZE(cg
->cmux
))
1409 clk
= cg
->cmux
[idx
];
1411 case QORIQ_CLK_HWACCEL
:
1412 if (idx
>= ARRAY_SIZE(cg
->hwaccel
))
1414 clk
= cg
->hwaccel
[idx
];
1416 case QORIQ_CLK_FMAN
:
1417 if (idx
>= ARRAY_SIZE(cg
->fman
))
1419 clk
= cg
->fman
[idx
];
1421 case QORIQ_CLK_PLATFORM_PLL
:
1422 pll
= &cg
->pll
[PLATFORM_PLL
];
1423 if (idx
>= ARRAY_SIZE(pll
->div
))
1425 clk
= pll
->div
[idx
].clk
;
1427 case QORIQ_CLK_CORECLK
:
1439 return ERR_PTR(-ENOENT
);
1443 pr_err("%s: Bad phandle args %u %u\n", __func__
, type
, idx
);
1444 return ERR_PTR(-EINVAL
);
1448 #include <asm/mpc85xx.h>
1450 static const u32 a4510_svrs
[] __initconst
= {
1451 (SVR_P2040
<< 8) | 0x10, /* P2040 1.0 */
1452 (SVR_P2040
<< 8) | 0x11, /* P2040 1.1 */
1453 (SVR_P2041
<< 8) | 0x10, /* P2041 1.0 */
1454 (SVR_P2041
<< 8) | 0x11, /* P2041 1.1 */
1455 (SVR_P3041
<< 8) | 0x10, /* P3041 1.0 */
1456 (SVR_P3041
<< 8) | 0x11, /* P3041 1.1 */
1457 (SVR_P4040
<< 8) | 0x20, /* P4040 2.0 */
1458 (SVR_P4080
<< 8) | 0x20, /* P4080 2.0 */
1459 (SVR_P5010
<< 8) | 0x10, /* P5010 1.0 */
1460 (SVR_P5010
<< 8) | 0x20, /* P5010 2.0 */
1461 (SVR_P5020
<< 8) | 0x10, /* P5020 1.0 */
1462 (SVR_P5021
<< 8) | 0x10, /* P5021 1.0 */
1463 (SVR_P5040
<< 8) | 0x10, /* P5040 1.0 */
1466 #define SVR_SECURITY 0x80000 /* The Security (E) bit */
1468 static bool __init
has_erratum_a4510(void)
1470 u32 svr
= mfspr(SPRN_SVR
);
1473 svr
&= ~SVR_SECURITY
;
1475 for (i
= 0; i
< ARRAY_SIZE(a4510_svrs
); i
++) {
1476 if (svr
== a4510_svrs
[i
])
1483 static bool __init
has_erratum_a4510(void)
1489 static void __init
_clockgen_init(struct device_node
*np
, bool legacy
)
1492 bool is_old_ls1021a
= false;
1494 /* May have already been called by a legacy probe */
1499 clockgen
.regs
= of_iomap(np
, 0);
1500 if (!clockgen
.regs
&&
1501 of_device_is_compatible(of_root
, "fsl,ls1021a")) {
1502 /* Compatibility hack for old, broken device trees */
1503 clockgen
.regs
= ioremap(0x1ee1000, 0x1000);
1504 is_old_ls1021a
= true;
1506 if (!clockgen
.regs
) {
1507 pr_err("%s(): %pOFn: of_iomap() failed\n", __func__
, np
);
1511 for (i
= 0; i
< ARRAY_SIZE(chipinfo
); i
++) {
1512 if (of_device_is_compatible(np
, chipinfo
[i
].compat
))
1514 if (is_old_ls1021a
&&
1515 !strcmp(chipinfo
[i
].compat
, "fsl,ls1021a-clockgen"))
1519 if (i
== ARRAY_SIZE(chipinfo
)) {
1520 pr_err("%s: unknown clockgen node %pOF\n", __func__
, np
);
1523 clockgen
.info
= chipinfo
[i
];
1525 if (clockgen
.info
.guts_compat
) {
1526 struct device_node
*guts
;
1528 guts
= of_find_compatible_node(NULL
, NULL
,
1529 clockgen
.info
.guts_compat
);
1531 clockgen
.guts
= of_iomap(guts
, 0);
1532 if (!clockgen
.guts
) {
1533 pr_err("%s: Couldn't map %pOF regs\n", __func__
,
1541 if (has_erratum_a4510())
1542 clockgen
.info
.flags
|= CG_CMUX_GE_PLAT
;
1544 clockgen
.sysclk
= create_sysclk("cg-sysclk");
1545 clockgen
.coreclk
= create_coreclk("cg-coreclk");
1546 create_plls(&clockgen
);
1547 create_muxes(&clockgen
);
1549 if (clockgen
.info
.init_periph
)
1550 clockgen
.info
.init_periph(&clockgen
);
1552 ret
= of_clk_add_provider(np
, clockgen_clk_get
, &clockgen
);
1554 pr_err("%s: Couldn't register clk provider for node %pOFn: %d\n",
1558 /* Don't create cpufreq device for legacy clockgen blocks */
1559 add_cpufreq_dev
= !legacy
;
1563 iounmap(clockgen
.regs
);
1564 clockgen
.regs
= NULL
;
1567 static void __init
clockgen_init(struct device_node
*np
)
1569 _clockgen_init(np
, false);
1572 static int __init
clockgen_cpufreq_init(void)
1574 struct platform_device
*pdev
;
1576 if (add_cpufreq_dev
) {
1577 pdev
= platform_device_register_simple("qoriq-cpufreq", -1,
1580 pr_err("Couldn't register qoriq-cpufreq err=%ld\n",
1585 device_initcall(clockgen_cpufreq_init
);
1587 CLK_OF_DECLARE(qoriq_clockgen_1
, "fsl,qoriq-clockgen-1.0", clockgen_init
);
1588 CLK_OF_DECLARE(qoriq_clockgen_2
, "fsl,qoriq-clockgen-2.0", clockgen_init
);
1589 CLK_OF_DECLARE(qoriq_clockgen_b4420
, "fsl,b4420-clockgen", clockgen_init
);
1590 CLK_OF_DECLARE(qoriq_clockgen_b4860
, "fsl,b4860-clockgen", clockgen_init
);
1591 CLK_OF_DECLARE(qoriq_clockgen_ls1012a
, "fsl,ls1012a-clockgen", clockgen_init
);
1592 CLK_OF_DECLARE(qoriq_clockgen_ls1021a
, "fsl,ls1021a-clockgen", clockgen_init
);
1593 CLK_OF_DECLARE(qoriq_clockgen_ls1028a
, "fsl,ls1028a-clockgen", clockgen_init
);
1594 CLK_OF_DECLARE(qoriq_clockgen_ls1043a
, "fsl,ls1043a-clockgen", clockgen_init
);
1595 CLK_OF_DECLARE(qoriq_clockgen_ls1046a
, "fsl,ls1046a-clockgen", clockgen_init
);
1596 CLK_OF_DECLARE(qoriq_clockgen_ls1088a
, "fsl,ls1088a-clockgen", clockgen_init
);
1597 CLK_OF_DECLARE(qoriq_clockgen_ls2080a
, "fsl,ls2080a-clockgen", clockgen_init
);
1598 CLK_OF_DECLARE(qoriq_clockgen_lx2160a
, "fsl,lx2160a-clockgen", clockgen_init
);
1599 CLK_OF_DECLARE(qoriq_clockgen_p2041
, "fsl,p2041-clockgen", clockgen_init
);
1600 CLK_OF_DECLARE(qoriq_clockgen_p3041
, "fsl,p3041-clockgen", clockgen_init
);
1601 CLK_OF_DECLARE(qoriq_clockgen_p4080
, "fsl,p4080-clockgen", clockgen_init
);
1602 CLK_OF_DECLARE(qoriq_clockgen_p5020
, "fsl,p5020-clockgen", clockgen_init
);
1603 CLK_OF_DECLARE(qoriq_clockgen_p5040
, "fsl,p5040-clockgen", clockgen_init
);
1604 CLK_OF_DECLARE(qoriq_clockgen_t1023
, "fsl,t1023-clockgen", clockgen_init
);
1605 CLK_OF_DECLARE(qoriq_clockgen_t1040
, "fsl,t1040-clockgen", clockgen_init
);
1606 CLK_OF_DECLARE(qoriq_clockgen_t2080
, "fsl,t2080-clockgen", clockgen_init
);
1607 CLK_OF_DECLARE(qoriq_clockgen_t4240
, "fsl,t4240-clockgen", clockgen_init
);
1610 CLK_OF_DECLARE(qoriq_sysclk_1
, "fsl,qoriq-sysclk-1.0", sysclk_init
);
1611 CLK_OF_DECLARE(qoriq_sysclk_2
, "fsl,qoriq-sysclk-2.0", sysclk_init
);
1612 CLK_OF_DECLARE(qoriq_core_pll_1
, "fsl,qoriq-core-pll-1.0", core_pll_init
);
1613 CLK_OF_DECLARE(qoriq_core_pll_2
, "fsl,qoriq-core-pll-2.0", core_pll_init
);
1614 CLK_OF_DECLARE(qoriq_core_mux_1
, "fsl,qoriq-core-mux-1.0", core_mux_init
);
1615 CLK_OF_DECLARE(qoriq_core_mux_2
, "fsl,qoriq-core-mux-2.0", core_mux_init
);
1616 CLK_OF_DECLARE(qoriq_pltfrm_pll_1
, "fsl,qoriq-platform-pll-1.0", pltfrm_pll_init
);
1617 CLK_OF_DECLARE(qoriq_pltfrm_pll_2
, "fsl,qoriq-platform-pll-2.0", pltfrm_pll_init
);