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/clk.h>
13 #include <linux/clk-provider.h>
14 #include <linux/clkdev.h>
15 #include <linux/fsl/guts.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/of_address.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
29 #define PLATFORM_PLL 0
33 #define CGA_PLL4 4 /* only on clockgen-1.0, which lacks CGB */
36 #define MAX_PLL_DIV 32
38 struct clockgen_pll_div
{
44 struct clockgen_pll_div div
[MAX_PLL_DIV
];
47 #define CLKSEL_VALID 1
48 #define CLKSEL_80PCT 2 /* Only allowed if PLL <= 80% of max cpu freq */
50 struct clockgen_sourceinfo
{
51 u32 flags
; /* CLKSEL_xxx */
52 int pll
; /* CGx_PLLn */
53 int div
; /* PLL_DIVn */
56 #define NUM_MUX_PARENTS 16
58 struct clockgen_muxinfo
{
59 struct clockgen_sourceinfo clksel
[NUM_MUX_PARENTS
];
68 * cmux freq must be >= platform pll.
69 * If not set, cmux freq must be >= platform pll/2
71 #define CG_CMUX_GE_PLAT 1
73 #define CG_PLL_8BIT 2 /* PLLCnGSR[CFG] is 8 bits, not 6 */
74 #define CG_VER3 4 /* version 3 cg: reg layout different */
75 #define CG_LITTLE_ENDIAN 8
77 struct clockgen_chipinfo
{
78 const char *compat
, *guts_compat
;
79 const struct clockgen_muxinfo
*cmux_groups
[2];
80 const struct clockgen_muxinfo
*hwaccel
[NUM_HWACCEL
];
81 void (*init_periph
)(struct clockgen
*cg
);
82 int cmux_to_group
[NUM_CMUX
+ 1]; /* array should be -1 terminated */
83 u32 pll_mask
; /* 1 << n bit set if PLL n is valid */
84 u32 flags
; /* CG_xxx */
88 struct device_node
*node
;
90 struct clockgen_chipinfo info
; /* mutable copy */
91 struct clk
*sysclk
, *coreclk
;
92 struct clockgen_pll pll
[6];
93 struct clk
*cmux
[NUM_CMUX
];
94 struct clk
*hwaccel
[NUM_HWACCEL
];
96 struct ccsr_guts __iomem
*guts
;
99 static struct clockgen clockgen
;
100 static bool add_cpufreq_dev __initdata
;
102 static void cg_out(struct clockgen
*cg
, u32 val
, u32 __iomem
*reg
)
104 if (cg
->info
.flags
& CG_LITTLE_ENDIAN
)
107 iowrite32be(val
, reg
);
110 static u32
cg_in(struct clockgen
*cg
, u32 __iomem
*reg
)
114 if (cg
->info
.flags
& CG_LITTLE_ENDIAN
)
117 val
= ioread32be(reg
);
122 static const struct clockgen_muxinfo p2041_cmux_grp1
= {
124 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
125 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
126 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
130 static const struct clockgen_muxinfo p2041_cmux_grp2
= {
132 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
133 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
134 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
138 static const struct clockgen_muxinfo p5020_cmux_grp1
= {
140 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
141 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
142 [4] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL2
, PLL_DIV1
},
146 static const struct clockgen_muxinfo p5020_cmux_grp2
= {
148 [0] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV1
},
149 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
150 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
154 static const struct clockgen_muxinfo p5040_cmux_grp1
= {
156 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
157 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
158 [4] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL2
, PLL_DIV1
},
159 [5] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL2
, PLL_DIV2
},
163 static const struct clockgen_muxinfo p5040_cmux_grp2
= {
165 [0] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV1
},
166 [1] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV2
},
167 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
168 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
172 static const struct clockgen_muxinfo p4080_cmux_grp1
= {
174 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
175 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
176 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
177 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
178 [8] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL3
, PLL_DIV1
},
182 static const struct clockgen_muxinfo p4080_cmux_grp2
= {
184 [0] = { CLKSEL_VALID
| CLKSEL_80PCT
, CGA_PLL1
, PLL_DIV1
},
185 [8] = { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV1
},
186 [9] = { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV2
},
187 [12] = { CLKSEL_VALID
, CGA_PLL4
, PLL_DIV1
},
188 [13] = { CLKSEL_VALID
, CGA_PLL4
, PLL_DIV2
},
192 static const struct clockgen_muxinfo t1023_cmux
= {
194 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
195 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
199 static const struct clockgen_muxinfo t1040_cmux
= {
201 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
202 [1] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
203 [4] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
204 [5] = { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
209 static const struct clockgen_muxinfo clockgen2_cmux_cga
= {
211 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
212 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
213 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
215 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
216 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
217 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
219 { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV1
},
220 { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV2
},
221 { CLKSEL_VALID
, CGA_PLL3
, PLL_DIV4
},
225 static const struct clockgen_muxinfo clockgen2_cmux_cga12
= {
227 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
228 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
229 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
231 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
232 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
233 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
237 static const struct clockgen_muxinfo clockgen2_cmux_cgb
= {
239 { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV1
},
240 { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV2
},
241 { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV4
},
243 { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV1
},
244 { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV2
},
245 { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV4
},
249 static const struct clockgen_muxinfo ls1021a_cmux
= {
251 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
252 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
253 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
257 static const struct clockgen_muxinfo ls1028a_hwa1
= {
259 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
260 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
261 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
262 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
263 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
265 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
266 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
270 static const struct clockgen_muxinfo ls1028a_hwa2
= {
272 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
273 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
274 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
275 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
276 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
278 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
279 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
283 static const struct clockgen_muxinfo ls1028a_hwa3
= {
285 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
286 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
287 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
288 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
289 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
291 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
292 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
296 static const struct clockgen_muxinfo ls1028a_hwa4
= {
298 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
299 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
300 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
301 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
302 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
304 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
305 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
309 static const struct clockgen_muxinfo ls1043a_hwa1
= {
313 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
314 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
317 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
318 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
322 static const struct clockgen_muxinfo ls1043a_hwa2
= {
325 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
327 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
331 static const struct clockgen_muxinfo ls1046a_hwa1
= {
335 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
336 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
337 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
338 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
339 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
340 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
344 static const struct clockgen_muxinfo ls1046a_hwa2
= {
347 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
348 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
349 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
352 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
356 static const struct clockgen_muxinfo ls1088a_hwa1
= {
359 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
360 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
361 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
362 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
364 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
365 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
369 static const struct clockgen_muxinfo ls1088a_hwa2
= {
372 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
373 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
374 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
375 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
377 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
378 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
382 static const struct clockgen_muxinfo ls1012a_cmux
= {
384 [0] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
386 [2] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
390 static const struct clockgen_muxinfo t1023_hwa1
= {
393 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
394 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
395 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
399 static const struct clockgen_muxinfo t1023_hwa2
= {
401 [6] = { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
405 static const struct clockgen_muxinfo t2080_hwa1
= {
408 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
409 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
410 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
411 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
412 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
413 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
414 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
418 static const struct clockgen_muxinfo t2080_hwa2
= {
421 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV1
},
422 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
423 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
424 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV4
},
425 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
426 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
427 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
431 static const struct clockgen_muxinfo t4240_hwa1
= {
433 { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV2
},
434 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV1
},
435 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV2
},
436 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV3
},
437 { CLKSEL_VALID
, CGA_PLL1
, PLL_DIV4
},
439 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV2
},
440 { CLKSEL_VALID
, CGA_PLL2
, PLL_DIV3
},
444 static const struct clockgen_muxinfo t4240_hwa4
= {
446 [2] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV2
},
447 [3] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV3
},
448 [4] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV4
},
449 [5] = { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
450 [6] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV2
},
454 static const struct clockgen_muxinfo t4240_hwa5
= {
456 [2] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV2
},
457 [3] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV3
},
458 [4] = { CLKSEL_VALID
, CGB_PLL2
, PLL_DIV4
},
459 [5] = { CLKSEL_VALID
, PLATFORM_PLL
, PLL_DIV1
},
460 [6] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV2
},
461 [7] = { CLKSEL_VALID
, CGB_PLL1
, PLL_DIV3
},
465 #define RCWSR7_FM1_CLK_SEL 0x40000000
466 #define RCWSR7_FM2_CLK_SEL 0x20000000
467 #define RCWSR7_HWA_ASYNC_DIV 0x04000000
469 static void __init
p2041_init_periph(struct clockgen
*cg
)
473 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
475 if (reg
& RCWSR7_FM1_CLK_SEL
)
476 cg
->fman
[0] = cg
->pll
[CGA_PLL2
].div
[PLL_DIV2
].clk
;
478 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
481 static void __init
p4080_init_periph(struct clockgen
*cg
)
485 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
487 if (reg
& RCWSR7_FM1_CLK_SEL
)
488 cg
->fman
[0] = cg
->pll
[CGA_PLL3
].div
[PLL_DIV2
].clk
;
490 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
492 if (reg
& RCWSR7_FM2_CLK_SEL
)
493 cg
->fman
[1] = cg
->pll
[CGA_PLL3
].div
[PLL_DIV2
].clk
;
495 cg
->fman
[1] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
498 static void __init
p5020_init_periph(struct clockgen
*cg
)
503 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
504 if (reg
& RCWSR7_HWA_ASYNC_DIV
)
507 if (reg
& RCWSR7_FM1_CLK_SEL
)
508 cg
->fman
[0] = cg
->pll
[CGA_PLL2
].div
[div
].clk
;
510 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
513 static void __init
p5040_init_periph(struct clockgen
*cg
)
518 reg
= ioread32be(&cg
->guts
->rcwsr
[7]);
519 if (reg
& RCWSR7_HWA_ASYNC_DIV
)
522 if (reg
& RCWSR7_FM1_CLK_SEL
)
523 cg
->fman
[0] = cg
->pll
[CGA_PLL3
].div
[div
].clk
;
525 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
527 if (reg
& RCWSR7_FM2_CLK_SEL
)
528 cg
->fman
[1] = cg
->pll
[CGA_PLL3
].div
[div
].clk
;
530 cg
->fman
[1] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV2
].clk
;
533 static void __init
t1023_init_periph(struct clockgen
*cg
)
535 cg
->fman
[0] = cg
->hwaccel
[1];
538 static void __init
t1040_init_periph(struct clockgen
*cg
)
540 cg
->fman
[0] = cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV1
].clk
;
543 static void __init
t2080_init_periph(struct clockgen
*cg
)
545 cg
->fman
[0] = cg
->hwaccel
[0];
548 static void __init
t4240_init_periph(struct clockgen
*cg
)
550 cg
->fman
[0] = cg
->hwaccel
[3];
551 cg
->fman
[1] = cg
->hwaccel
[4];
554 static const struct clockgen_chipinfo chipinfo
[] = {
556 .compat
= "fsl,b4420-clockgen",
557 .guts_compat
= "fsl,b4860-device-config",
558 .init_periph
= t2080_init_periph
,
560 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
568 .pll_mask
= BIT(PLATFORM_PLL
) |
569 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
) |
570 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
571 .flags
= CG_PLL_8BIT
,
574 .compat
= "fsl,b4860-clockgen",
575 .guts_compat
= "fsl,b4860-device-config",
576 .init_periph
= t2080_init_periph
,
578 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
586 .pll_mask
= BIT(PLATFORM_PLL
) |
587 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
) |
588 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
589 .flags
= CG_PLL_8BIT
,
592 .compat
= "fsl,ls1021a-clockgen",
599 .pll_mask
= BIT(PLATFORM_PLL
) |
600 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
603 .compat
= "fsl,ls1028a-clockgen",
605 &clockgen2_cmux_cga12
608 &ls1028a_hwa1
, &ls1028a_hwa2
,
609 &ls1028a_hwa3
, &ls1028a_hwa4
614 .pll_mask
= BIT(PLATFORM_PLL
) |
615 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
616 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
619 .compat
= "fsl,ls1043a-clockgen",
620 .init_periph
= t2080_init_periph
,
625 &ls1043a_hwa1
, &ls1043a_hwa2
630 .pll_mask
= BIT(PLATFORM_PLL
) |
631 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
632 .flags
= CG_PLL_8BIT
,
635 .compat
= "fsl,ls1046a-clockgen",
636 .init_periph
= t2080_init_periph
,
641 &ls1046a_hwa1
, &ls1046a_hwa2
646 .pll_mask
= BIT(PLATFORM_PLL
) |
647 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
648 .flags
= CG_PLL_8BIT
,
651 .compat
= "fsl,ls1088a-clockgen",
653 &clockgen2_cmux_cga12
656 &ls1088a_hwa1
, &ls1088a_hwa2
661 .pll_mask
= BIT(PLATFORM_PLL
) |
662 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
663 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
666 .compat
= "fsl,ls1012a-clockgen",
673 .pll_mask
= BIT(PLATFORM_PLL
) | BIT(CGA_PLL1
),
676 .compat
= "fsl,ls2080a-clockgen",
678 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
683 .pll_mask
= BIT(PLATFORM_PLL
) |
684 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) |
685 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
686 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
689 .compat
= "fsl,lx2160a-clockgen",
691 &clockgen2_cmux_cga12
, &clockgen2_cmux_cgb
694 0, 0, 0, 0, 1, 1, 1, 1, -1
696 .pll_mask
= BIT(PLATFORM_PLL
) |
697 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) |
698 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
699 .flags
= CG_VER3
| CG_LITTLE_ENDIAN
,
702 .compat
= "fsl,p2041-clockgen",
703 .guts_compat
= "fsl,qoriq-device-config-1.0",
704 .init_periph
= p2041_init_periph
,
706 &p2041_cmux_grp1
, &p2041_cmux_grp2
711 .pll_mask
= BIT(PLATFORM_PLL
) |
712 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
715 .compat
= "fsl,p3041-clockgen",
716 .guts_compat
= "fsl,qoriq-device-config-1.0",
717 .init_periph
= p2041_init_periph
,
719 &p2041_cmux_grp1
, &p2041_cmux_grp2
724 .pll_mask
= BIT(PLATFORM_PLL
) |
725 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
728 .compat
= "fsl,p4080-clockgen",
729 .guts_compat
= "fsl,qoriq-device-config-1.0",
730 .init_periph
= p4080_init_periph
,
732 &p4080_cmux_grp1
, &p4080_cmux_grp2
735 0, 0, 0, 0, 1, 1, 1, 1, -1
737 .pll_mask
= BIT(PLATFORM_PLL
) |
738 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) |
739 BIT(CGA_PLL3
) | BIT(CGA_PLL4
),
742 .compat
= "fsl,p5020-clockgen",
743 .guts_compat
= "fsl,qoriq-device-config-1.0",
744 .init_periph
= p5020_init_periph
,
746 &p5020_cmux_grp1
, &p5020_cmux_grp2
751 .pll_mask
= BIT(PLATFORM_PLL
) |
752 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
755 .compat
= "fsl,p5040-clockgen",
756 .guts_compat
= "fsl,p5040-device-config",
757 .init_periph
= p5040_init_periph
,
759 &p5040_cmux_grp1
, &p5040_cmux_grp2
764 .pll_mask
= BIT(PLATFORM_PLL
) |
765 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
),
768 .compat
= "fsl,t1023-clockgen",
769 .guts_compat
= "fsl,t1023-device-config",
770 .init_periph
= t1023_init_periph
,
775 &t1023_hwa1
, &t1023_hwa2
780 .pll_mask
= BIT(PLATFORM_PLL
) | BIT(CGA_PLL1
),
781 .flags
= CG_PLL_8BIT
,
784 .compat
= "fsl,t1040-clockgen",
785 .guts_compat
= "fsl,t1040-device-config",
786 .init_periph
= t1040_init_periph
,
793 .pll_mask
= BIT(PLATFORM_PLL
) |
794 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
795 .flags
= CG_PLL_8BIT
,
798 .compat
= "fsl,t2080-clockgen",
799 .guts_compat
= "fsl,t2080-device-config",
800 .init_periph
= t2080_init_periph
,
802 &clockgen2_cmux_cga12
805 &t2080_hwa1
, &t2080_hwa2
810 .pll_mask
= BIT(PLATFORM_PLL
) |
811 BIT(CGA_PLL1
) | BIT(CGA_PLL2
),
812 .flags
= CG_PLL_8BIT
,
815 .compat
= "fsl,t4240-clockgen",
816 .guts_compat
= "fsl,t4240-device-config",
817 .init_periph
= t4240_init_periph
,
819 &clockgen2_cmux_cga
, &clockgen2_cmux_cgb
822 &t4240_hwa1
, NULL
, NULL
, &t4240_hwa4
, &t4240_hwa5
827 .pll_mask
= BIT(PLATFORM_PLL
) |
828 BIT(CGA_PLL1
) | BIT(CGA_PLL2
) | BIT(CGA_PLL3
) |
829 BIT(CGB_PLL1
) | BIT(CGB_PLL2
),
830 .flags
= CG_PLL_8BIT
,
838 const struct clockgen_muxinfo
*info
;
840 u8 parent_to_clksel
[NUM_MUX_PARENTS
];
841 s8 clksel_to_parent
[NUM_MUX_PARENTS
];
845 #define to_mux_hwclock(p) container_of(p, struct mux_hwclock, hw)
846 #define CLKSEL_MASK 0x78000000
847 #define CLKSEL_SHIFT 27
849 static int mux_set_parent(struct clk_hw
*hw
, u8 idx
)
851 struct mux_hwclock
*hwc
= to_mux_hwclock(hw
);
854 if (idx
>= hwc
->num_parents
)
857 clksel
= hwc
->parent_to_clksel
[idx
];
858 cg_out(hwc
->cg
, (clksel
<< CLKSEL_SHIFT
) & CLKSEL_MASK
, hwc
->reg
);
863 static u8
mux_get_parent(struct clk_hw
*hw
)
865 struct mux_hwclock
*hwc
= to_mux_hwclock(hw
);
869 clksel
= (cg_in(hwc
->cg
, hwc
->reg
) & CLKSEL_MASK
) >> CLKSEL_SHIFT
;
871 ret
= hwc
->clksel_to_parent
[clksel
];
873 pr_err("%s: mux at %p has bad clksel\n", __func__
, hwc
->reg
);
880 static const struct clk_ops cmux_ops
= {
881 .determine_rate
= clk_hw_determine_rate_no_reparent
,
882 .get_parent
= mux_get_parent
,
883 .set_parent
= mux_set_parent
,
887 * Don't allow setting for now, as the clock options haven't been
888 * sanitized for additional restrictions.
890 static const struct clk_ops hwaccel_ops
= {
891 .get_parent
= mux_get_parent
,
894 static const struct clockgen_pll_div
*get_pll_div(struct clockgen
*cg
,
895 struct mux_hwclock
*hwc
,
900 if (!(hwc
->info
->clksel
[idx
].flags
& CLKSEL_VALID
))
903 pll
= hwc
->info
->clksel
[idx
].pll
;
904 div
= hwc
->info
->clksel
[idx
].div
;
906 return &cg
->pll
[pll
].div
[div
];
909 static struct clk
* __init
create_mux_common(struct clockgen
*cg
,
910 struct mux_hwclock
*hwc
,
911 const struct clk_ops
*ops
,
912 unsigned long min_rate
,
913 unsigned long max_rate
,
914 unsigned long pct80_rate
,
915 const char *fmt
, int idx
)
917 struct clk_init_data init
= {};
919 const struct clockgen_pll_div
*div
;
920 const char *parent_names
[NUM_MUX_PARENTS
];
924 snprintf(name
, sizeof(name
), fmt
, idx
);
926 for (i
= 0, j
= 0; i
< NUM_MUX_PARENTS
; i
++) {
929 hwc
->clksel_to_parent
[i
] = -1;
931 div
= get_pll_div(cg
, hwc
, i
);
935 rate
= clk_get_rate(div
->clk
);
937 if (hwc
->info
->clksel
[i
].flags
& CLKSEL_80PCT
&&
945 parent_names
[j
] = div
->name
;
946 hwc
->parent_to_clksel
[j
] = i
;
947 hwc
->clksel_to_parent
[i
] = j
;
953 init
.parent_names
= parent_names
;
954 init
.num_parents
= hwc
->num_parents
= j
;
956 hwc
->hw
.init
= &init
;
959 clk
= clk_register(NULL
, &hwc
->hw
);
961 pr_err("%s: Couldn't register %s: %ld\n", __func__
, name
,
970 static struct clk
* __init
create_one_cmux(struct clockgen
*cg
, int idx
)
972 struct mux_hwclock
*hwc
;
973 const struct clockgen_pll_div
*div
;
974 unsigned long plat_rate
, min_rate
;
975 u64 max_rate
, pct80_rate
;
978 hwc
= kzalloc(sizeof(*hwc
), GFP_KERNEL
);
982 if (cg
->info
.flags
& CG_VER3
)
983 hwc
->reg
= cg
->regs
+ 0x70000 + 0x20 * idx
;
985 hwc
->reg
= cg
->regs
+ 0x20 * idx
;
987 hwc
->info
= cg
->info
.cmux_groups
[cg
->info
.cmux_to_group
[idx
]];
990 * Find the rate for the default clksel, and treat it as the
991 * maximum rated core frequency. If this is an incorrect
992 * assumption, certain clock options (possibly including the
993 * default clksel) may be inappropriately excluded on certain
996 clksel
= (cg_in(cg
, hwc
->reg
) & CLKSEL_MASK
) >> CLKSEL_SHIFT
;
997 div
= get_pll_div(cg
, hwc
, clksel
);
1003 max_rate
= clk_get_rate(div
->clk
);
1004 pct80_rate
= max_rate
* 8;
1005 do_div(pct80_rate
, 10);
1007 plat_rate
= clk_get_rate(cg
->pll
[PLATFORM_PLL
].div
[PLL_DIV1
].clk
);
1009 if (cg
->info
.flags
& CG_CMUX_GE_PLAT
)
1010 min_rate
= plat_rate
;
1012 min_rate
= plat_rate
/ 2;
1014 return create_mux_common(cg
, hwc
, &cmux_ops
, min_rate
, max_rate
,
1015 pct80_rate
, "cg-cmux%d", idx
);
1018 static struct clk
* __init
create_one_hwaccel(struct clockgen
*cg
, int idx
)
1020 struct mux_hwclock
*hwc
;
1022 hwc
= kzalloc(sizeof(*hwc
), GFP_KERNEL
);
1026 hwc
->reg
= cg
->regs
+ 0x20 * idx
+ 0x10;
1027 hwc
->info
= cg
->info
.hwaccel
[idx
];
1029 return create_mux_common(cg
, hwc
, &hwaccel_ops
, 0, ULONG_MAX
, 0,
1030 "cg-hwaccel%d", idx
);
1033 static void __init
create_muxes(struct clockgen
*cg
)
1037 for (i
= 0; i
< ARRAY_SIZE(cg
->cmux
); i
++) {
1038 if (cg
->info
.cmux_to_group
[i
] < 0)
1040 if (cg
->info
.cmux_to_group
[i
] >=
1041 ARRAY_SIZE(cg
->info
.cmux_groups
)) {
1046 cg
->cmux
[i
] = create_one_cmux(cg
, i
);
1049 for (i
= 0; i
< ARRAY_SIZE(cg
->hwaccel
); i
++) {
1050 if (!cg
->info
.hwaccel
[i
])
1053 cg
->hwaccel
[i
] = create_one_hwaccel(cg
, i
);
1057 static void __init
_clockgen_init(struct device_node
*np
, bool legacy
);
1060 * Legacy nodes may get probed before the parent clockgen node.
1061 * It is assumed that device trees with legacy nodes will not
1062 * contain a "clocks" property -- otherwise the input clocks may
1063 * not be initialized at this point.
1065 static void __init
legacy_init_clockgen(struct device_node
*np
)
1067 if (!clockgen
.node
) {
1068 struct device_node
*parent_np
;
1070 parent_np
= of_get_parent(np
);
1071 _clockgen_init(parent_np
, true);
1072 of_node_put(parent_np
);
1077 static void __init
core_mux_init(struct device_node
*np
)
1080 struct resource res
;
1083 legacy_init_clockgen(np
);
1085 if (of_address_to_resource(np
, 0, &res
))
1088 idx
= (res
.start
& 0xf0) >> 5;
1089 clk
= clockgen
.cmux
[idx
];
1091 rc
= of_clk_add_provider(np
, of_clk_src_simple_get
, clk
);
1093 pr_err("%s: Couldn't register clk provider for node %pOFn: %d\n",
1099 static struct clk __init
1100 *sysclk_from_fixed(struct device_node
*node
, const char *name
)
1104 if (of_property_read_u32(node
, "clock-frequency", &rate
))
1105 return ERR_PTR(-ENODEV
);
1107 return clk_register_fixed_rate(NULL
, name
, NULL
, 0, rate
);
1110 static struct clk __init
*input_clock(const char *name
, struct clk
*clk
)
1112 const char *input_name
;
1114 /* Register the input clock under the desired name. */
1115 input_name
= __clk_get_name(clk
);
1116 clk
= clk_register_fixed_factor(NULL
, name
, input_name
,
1119 pr_err("%s: Couldn't register %s: %ld\n", __func__
, name
,
1125 static struct clk __init
*input_clock_by_name(const char *name
,
1130 clk
= of_clk_get_by_name(clockgen
.node
, dtname
);
1134 return input_clock(name
, clk
);
1137 static struct clk __init
*input_clock_by_index(const char *name
, int idx
)
1141 clk
= of_clk_get(clockgen
.node
, 0);
1145 return input_clock(name
, clk
);
1148 static struct clk
* __init
create_sysclk(const char *name
)
1150 struct device_node
*sysclk
;
1153 clk
= sysclk_from_fixed(clockgen
.node
, name
);
1157 clk
= input_clock_by_name(name
, "sysclk");
1161 clk
= input_clock_by_index(name
, 0);
1165 sysclk
= of_get_child_by_name(clockgen
.node
, "sysclk");
1167 clk
= sysclk_from_fixed(sysclk
, name
);
1168 of_node_put(sysclk
);
1173 pr_err("%s: No input sysclk\n", __func__
);
1177 static struct clk
* __init
create_coreclk(const char *name
)
1181 clk
= input_clock_by_name(name
, "coreclk");
1186 * This indicates a mix of legacy nodes with the new coreclk
1187 * mechanism, which should never happen. If this error occurs,
1188 * don't use the wrong input clock just because coreclk isn't
1191 if (WARN_ON(PTR_ERR(clk
) == -EPROBE_DEFER
))
1198 static void __init
sysclk_init(struct device_node
*node
)
1202 legacy_init_clockgen(node
);
1204 clk
= clockgen
.sysclk
;
1206 of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
1209 #define PLL_KILL BIT(31)
1211 static void __init
create_one_pll(struct clockgen
*cg
, int idx
)
1215 struct clockgen_pll
*pll
= &cg
->pll
[idx
];
1216 const char *input
= "cg-sysclk";
1219 if (!(cg
->info
.pll_mask
& (1 << idx
)))
1222 if (cg
->coreclk
&& idx
!= PLATFORM_PLL
) {
1223 if (IS_ERR(cg
->coreclk
))
1226 input
= "cg-coreclk";
1229 if (cg
->info
.flags
& CG_VER3
) {
1232 reg
= cg
->regs
+ 0x60080;
1235 reg
= cg
->regs
+ 0x80;
1238 reg
= cg
->regs
+ 0xa0;
1241 reg
= cg
->regs
+ 0x10080;
1244 reg
= cg
->regs
+ 0x100a0;
1247 WARN_ONCE(1, "index %d\n", idx
);
1251 if (idx
== PLATFORM_PLL
)
1252 reg
= cg
->regs
+ 0xc00;
1254 reg
= cg
->regs
+ 0x800 + 0x20 * (idx
- 1);
1257 /* Get the multiple of PLL */
1258 mult
= cg_in(cg
, reg
);
1260 /* Check if this PLL is disabled */
1261 if (mult
& PLL_KILL
) {
1262 pr_debug("%s(): pll %p disabled\n", __func__
, reg
);
1266 if ((cg
->info
.flags
& CG_VER3
) ||
1267 ((cg
->info
.flags
& CG_PLL_8BIT
) && idx
!= PLATFORM_PLL
))
1268 mult
= (mult
& GENMASK(8, 1)) >> 1;
1270 mult
= (mult
& GENMASK(6, 1)) >> 1;
1272 for (i
= 0; i
< ARRAY_SIZE(pll
->div
); i
++) {
1277 * For platform PLL, there are MAX_PLL_DIV divider clocks.
1278 * For core PLL, there are 4 divider clocks at most.
1280 if (idx
!= PLATFORM_PLL
&& i
>= 4)
1283 snprintf(pll
->div
[i
].name
, sizeof(pll
->div
[i
].name
),
1284 "cg-pll%d-div%d", idx
, i
+ 1);
1286 clk
= clk_register_fixed_factor(NULL
,
1287 pll
->div
[i
].name
, input
, 0, mult
, i
+ 1);
1289 pr_err("%s: %s: register failed %ld\n",
1290 __func__
, pll
->div
[i
].name
, PTR_ERR(clk
));
1294 pll
->div
[i
].clk
= clk
;
1295 ret
= clk_register_clkdev(clk
, pll
->div
[i
].name
, NULL
);
1297 pr_err("%s: %s: register to lookup table failed %d\n",
1298 __func__
, pll
->div
[i
].name
, ret
);
1303 static void __init
create_plls(struct clockgen
*cg
)
1307 for (i
= 0; i
< ARRAY_SIZE(cg
->pll
); i
++)
1308 create_one_pll(cg
, i
);
1311 static void __init
legacy_pll_init(struct device_node
*np
, int idx
)
1313 struct clockgen_pll
*pll
;
1314 struct clk_onecell_data
*onecell_data
;
1315 struct clk
**subclks
;
1318 legacy_init_clockgen(np
);
1320 pll
= &clockgen
.pll
[idx
];
1321 count
= of_property_count_strings(np
, "clock-output-names");
1323 BUILD_BUG_ON(ARRAY_SIZE(pll
->div
) < 4);
1324 subclks
= kcalloc(4, sizeof(struct clk
*), GFP_KERNEL
);
1328 onecell_data
= kmalloc(sizeof(*onecell_data
), GFP_KERNEL
);
1333 subclks
[0] = pll
->div
[0].clk
;
1334 subclks
[1] = pll
->div
[1].clk
;
1335 subclks
[2] = pll
->div
[3].clk
;
1337 subclks
[0] = pll
->div
[0].clk
;
1338 subclks
[1] = pll
->div
[1].clk
;
1339 subclks
[2] = pll
->div
[2].clk
;
1340 subclks
[3] = pll
->div
[3].clk
;
1343 onecell_data
->clks
= subclks
;
1344 onecell_data
->clk_num
= count
;
1346 rc
= of_clk_add_provider(np
, of_clk_src_onecell_get
, onecell_data
);
1348 pr_err("%s: Couldn't register clk provider for node %pOFn: %d\n",
1355 kfree(onecell_data
);
1361 static void __init
pltfrm_pll_init(struct device_node
*np
)
1363 legacy_pll_init(np
, PLATFORM_PLL
);
1367 static void __init
core_pll_init(struct device_node
*np
)
1369 struct resource res
;
1372 if (of_address_to_resource(np
, 0, &res
))
1375 if ((res
.start
& 0xfff) == 0xc00) {
1377 * ls1021a devtree labels the platform PLL
1378 * with the core PLL compatible
1380 pltfrm_pll_init(np
);
1382 idx
= (res
.start
& 0xf0) >> 5;
1383 legacy_pll_init(np
, CGA_PLL1
+ idx
);
1387 static struct clk
*clockgen_clk_get(struct of_phandle_args
*clkspec
, void *data
)
1389 struct clockgen
*cg
= data
;
1391 struct clockgen_pll
*pll
;
1394 if (clkspec
->args_count
< 2) {
1395 pr_err("%s: insufficient phandle args\n", __func__
);
1396 return ERR_PTR(-EINVAL
);
1399 type
= clkspec
->args
[0];
1400 idx
= clkspec
->args
[1];
1403 case QORIQ_CLK_SYSCLK
:
1408 case QORIQ_CLK_CMUX
:
1409 if (idx
>= ARRAY_SIZE(cg
->cmux
))
1411 clk
= cg
->cmux
[idx
];
1413 case QORIQ_CLK_HWACCEL
:
1414 if (idx
>= ARRAY_SIZE(cg
->hwaccel
))
1416 clk
= cg
->hwaccel
[idx
];
1418 case QORIQ_CLK_FMAN
:
1419 if (idx
>= ARRAY_SIZE(cg
->fman
))
1421 clk
= cg
->fman
[idx
];
1423 case QORIQ_CLK_PLATFORM_PLL
:
1424 pll
= &cg
->pll
[PLATFORM_PLL
];
1425 if (idx
>= ARRAY_SIZE(pll
->div
))
1427 clk
= pll
->div
[idx
].clk
;
1429 case QORIQ_CLK_CORECLK
:
1441 return ERR_PTR(-ENOENT
);
1445 pr_err("%s: Bad phandle args %u %u\n", __func__
, type
, idx
);
1446 return ERR_PTR(-EINVAL
);
1450 #include <asm/mpc85xx.h>
1452 static const u32 a4510_svrs
[] __initconst
= {
1453 (SVR_P2040
<< 8) | 0x10, /* P2040 1.0 */
1454 (SVR_P2040
<< 8) | 0x11, /* P2040 1.1 */
1455 (SVR_P2041
<< 8) | 0x10, /* P2041 1.0 */
1456 (SVR_P2041
<< 8) | 0x11, /* P2041 1.1 */
1457 (SVR_P3041
<< 8) | 0x10, /* P3041 1.0 */
1458 (SVR_P3041
<< 8) | 0x11, /* P3041 1.1 */
1459 (SVR_P4040
<< 8) | 0x20, /* P4040 2.0 */
1460 (SVR_P4080
<< 8) | 0x20, /* P4080 2.0 */
1461 (SVR_P5010
<< 8) | 0x10, /* P5010 1.0 */
1462 (SVR_P5010
<< 8) | 0x20, /* P5010 2.0 */
1463 (SVR_P5020
<< 8) | 0x10, /* P5020 1.0 */
1464 (SVR_P5021
<< 8) | 0x10, /* P5021 1.0 */
1465 (SVR_P5040
<< 8) | 0x10, /* P5040 1.0 */
1468 #define SVR_SECURITY 0x80000 /* The Security (E) bit */
1470 static bool __init
has_erratum_a4510(void)
1472 u32 svr
= mfspr(SPRN_SVR
);
1475 svr
&= ~SVR_SECURITY
;
1477 for (i
= 0; i
< ARRAY_SIZE(a4510_svrs
); i
++) {
1478 if (svr
== a4510_svrs
[i
])
1485 static bool __init
has_erratum_a4510(void)
1491 static void __init
_clockgen_init(struct device_node
*np
, bool legacy
)
1494 bool is_old_ls1021a
= false;
1496 /* May have already been called by a legacy probe */
1501 clockgen
.regs
= of_iomap(np
, 0);
1502 if (!clockgen
.regs
&&
1503 of_device_is_compatible(of_root
, "fsl,ls1021a")) {
1504 /* Compatibility hack for old, broken device trees */
1505 clockgen
.regs
= ioremap(0x1ee1000, 0x1000);
1506 is_old_ls1021a
= true;
1508 if (!clockgen
.regs
) {
1509 pr_err("%s(): %pOFn: of_iomap() failed\n", __func__
, np
);
1513 for (i
= 0; i
< ARRAY_SIZE(chipinfo
); i
++) {
1514 if (of_device_is_compatible(np
, chipinfo
[i
].compat
))
1516 if (is_old_ls1021a
&&
1517 !strcmp(chipinfo
[i
].compat
, "fsl,ls1021a-clockgen"))
1521 if (i
== ARRAY_SIZE(chipinfo
)) {
1522 pr_err("%s: unknown clockgen node %pOF\n", __func__
, np
);
1525 clockgen
.info
= chipinfo
[i
];
1527 if (clockgen
.info
.guts_compat
) {
1528 struct device_node
*guts
;
1530 guts
= of_find_compatible_node(NULL
, NULL
,
1531 clockgen
.info
.guts_compat
);
1533 clockgen
.guts
= of_iomap(guts
, 0);
1534 if (!clockgen
.guts
) {
1535 pr_err("%s: Couldn't map %pOF regs\n", __func__
,
1543 if (has_erratum_a4510())
1544 clockgen
.info
.flags
|= CG_CMUX_GE_PLAT
;
1546 clockgen
.sysclk
= create_sysclk("cg-sysclk");
1547 clockgen
.coreclk
= create_coreclk("cg-coreclk");
1548 create_plls(&clockgen
);
1549 create_muxes(&clockgen
);
1551 if (clockgen
.info
.init_periph
)
1552 clockgen
.info
.init_periph(&clockgen
);
1554 ret
= of_clk_add_provider(np
, clockgen_clk_get
, &clockgen
);
1556 pr_err("%s: Couldn't register clk provider for node %pOFn: %d\n",
1560 /* Don't create cpufreq device for legacy clockgen blocks */
1561 add_cpufreq_dev
= !legacy
;
1565 iounmap(clockgen
.regs
);
1566 clockgen
.regs
= NULL
;
1569 static void __init
clockgen_init(struct device_node
*np
)
1571 _clockgen_init(np
, false);
1574 static int __init
clockgen_cpufreq_init(void)
1576 struct platform_device
*pdev
;
1578 if (add_cpufreq_dev
) {
1579 pdev
= platform_device_register_simple("qoriq-cpufreq", -1,
1582 pr_err("Couldn't register qoriq-cpufreq err=%ld\n",
1587 device_initcall(clockgen_cpufreq_init
);
1589 CLK_OF_DECLARE(qoriq_clockgen_1
, "fsl,qoriq-clockgen-1.0", clockgen_init
);
1590 CLK_OF_DECLARE(qoriq_clockgen_2
, "fsl,qoriq-clockgen-2.0", clockgen_init
);
1591 CLK_OF_DECLARE(qoriq_clockgen_b4420
, "fsl,b4420-clockgen", clockgen_init
);
1592 CLK_OF_DECLARE(qoriq_clockgen_b4860
, "fsl,b4860-clockgen", clockgen_init
);
1593 CLK_OF_DECLARE(qoriq_clockgen_ls1012a
, "fsl,ls1012a-clockgen", clockgen_init
);
1594 CLK_OF_DECLARE(qoriq_clockgen_ls1021a
, "fsl,ls1021a-clockgen", clockgen_init
);
1595 CLK_OF_DECLARE(qoriq_clockgen_ls1028a
, "fsl,ls1028a-clockgen", clockgen_init
);
1596 CLK_OF_DECLARE(qoriq_clockgen_ls1043a
, "fsl,ls1043a-clockgen", clockgen_init
);
1597 CLK_OF_DECLARE(qoriq_clockgen_ls1046a
, "fsl,ls1046a-clockgen", clockgen_init
);
1598 CLK_OF_DECLARE(qoriq_clockgen_ls1088a
, "fsl,ls1088a-clockgen", clockgen_init
);
1599 CLK_OF_DECLARE(qoriq_clockgen_ls2080a
, "fsl,ls2080a-clockgen", clockgen_init
);
1600 CLK_OF_DECLARE(qoriq_clockgen_lx2160a
, "fsl,lx2160a-clockgen", clockgen_init
);
1601 CLK_OF_DECLARE(qoriq_clockgen_p2041
, "fsl,p2041-clockgen", clockgen_init
);
1602 CLK_OF_DECLARE(qoriq_clockgen_p3041
, "fsl,p3041-clockgen", clockgen_init
);
1603 CLK_OF_DECLARE(qoriq_clockgen_p4080
, "fsl,p4080-clockgen", clockgen_init
);
1604 CLK_OF_DECLARE(qoriq_clockgen_p5020
, "fsl,p5020-clockgen", clockgen_init
);
1605 CLK_OF_DECLARE(qoriq_clockgen_p5040
, "fsl,p5040-clockgen", clockgen_init
);
1606 CLK_OF_DECLARE(qoriq_clockgen_t1023
, "fsl,t1023-clockgen", clockgen_init
);
1607 CLK_OF_DECLARE(qoriq_clockgen_t1040
, "fsl,t1040-clockgen", clockgen_init
);
1608 CLK_OF_DECLARE(qoriq_clockgen_t2080
, "fsl,t2080-clockgen", clockgen_init
);
1609 CLK_OF_DECLARE(qoriq_clockgen_t4240
, "fsl,t4240-clockgen", clockgen_init
);
1612 CLK_OF_DECLARE(qoriq_sysclk_1
, "fsl,qoriq-sysclk-1.0", sysclk_init
);
1613 CLK_OF_DECLARE(qoriq_sysclk_2
, "fsl,qoriq-sysclk-2.0", sysclk_init
);
1614 CLK_OF_DECLARE(qoriq_core_pll_1
, "fsl,qoriq-core-pll-1.0", core_pll_init
);
1615 CLK_OF_DECLARE(qoriq_core_pll_2
, "fsl,qoriq-core-pll-2.0", core_pll_init
);
1616 CLK_OF_DECLARE(qoriq_core_mux_1
, "fsl,qoriq-core-mux-1.0", core_mux_init
);
1617 CLK_OF_DECLARE(qoriq_core_mux_2
, "fsl,qoriq-core-mux-2.0", core_mux_init
);
1618 CLK_OF_DECLARE(qoriq_pltfrm_pll_1
, "fsl,qoriq-platform-pll-1.0", pltfrm_pll_init
);
1619 CLK_OF_DECLARE(qoriq_pltfrm_pll_2
, "fsl,qoriq-platform-pll-2.0", pltfrm_pll_init
);