1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/clk-provider.h>
3 #include <linux/mfd/syscon.h>
4 #include <linux/slab.h>
6 #include <dt-bindings/clock/at91.h>
10 static const struct clk_master_characteristics mck_characteristics
= {
11 .output
= { .min
= 125000000, .max
= 200000000 },
12 .divisors
= { 1, 2, 4, 3 },
15 static u8 plla_out
[] = { 0 };
17 static u16 plla_icpll
[] = { 0 };
19 static const struct clk_range plla_outputs
[] = {
20 { .min
= 600000000, .max
= 1200000000 },
23 static const struct clk_pll_characteristics plla_characteristics
= {
24 .input
= { .min
= 12000000, .max
= 12000000 },
25 .num_output
= ARRAY_SIZE(plla_outputs
),
26 .output
= plla_outputs
,
31 static const struct clk_pcr_layout sama5d4_pcr_layout
= {
34 .pid_mask
= GENMASK(6, 0),
41 } sama5d4_systemck
[] = {
42 { .n
= "ddrck", .p
= "masterck", .id
= 2 },
43 { .n
= "lcdck", .p
= "masterck", .id
= 3 },
44 { .n
= "smdck", .p
= "smdclk", .id
= 4 },
45 { .n
= "uhpck", .p
= "usbck", .id
= 6 },
46 { .n
= "udpck", .p
= "usbck", .id
= 7 },
47 { .n
= "pck0", .p
= "prog0", .id
= 8 },
48 { .n
= "pck1", .p
= "prog1", .id
= 9 },
49 { .n
= "pck2", .p
= "prog2", .id
= 10 },
55 } sama5d4_periph32ck
[] = {
56 { .n
= "pioD_clk", .id
= 5 },
57 { .n
= "usart0_clk", .id
= 6 },
58 { .n
= "usart1_clk", .id
= 7 },
59 { .n
= "icm_clk", .id
= 9 },
60 { .n
= "aes_clk", .id
= 12 },
61 { .n
= "tdes_clk", .id
= 14 },
62 { .n
= "sha_clk", .id
= 15 },
63 { .n
= "matrix1_clk", .id
= 17 },
64 { .n
= "hsmc_clk", .id
= 22 },
65 { .n
= "pioA_clk", .id
= 23 },
66 { .n
= "pioB_clk", .id
= 24 },
67 { .n
= "pioC_clk", .id
= 25 },
68 { .n
= "pioE_clk", .id
= 26 },
69 { .n
= "uart0_clk", .id
= 27 },
70 { .n
= "uart1_clk", .id
= 28 },
71 { .n
= "usart2_clk", .id
= 29 },
72 { .n
= "usart3_clk", .id
= 30 },
73 { .n
= "usart4_clk", .id
= 31 },
74 { .n
= "twi0_clk", .id
= 32 },
75 { .n
= "twi1_clk", .id
= 33 },
76 { .n
= "twi2_clk", .id
= 34 },
77 { .n
= "mci0_clk", .id
= 35 },
78 { .n
= "mci1_clk", .id
= 36 },
79 { .n
= "spi0_clk", .id
= 37 },
80 { .n
= "spi1_clk", .id
= 38 },
81 { .n
= "spi2_clk", .id
= 39 },
82 { .n
= "tcb0_clk", .id
= 40 },
83 { .n
= "tcb1_clk", .id
= 41 },
84 { .n
= "tcb2_clk", .id
= 42 },
85 { .n
= "pwm_clk", .id
= 43 },
86 { .n
= "adc_clk", .id
= 44 },
87 { .n
= "dbgu_clk", .id
= 45 },
88 { .n
= "uhphs_clk", .id
= 46 },
89 { .n
= "udphs_clk", .id
= 47 },
90 { .n
= "ssc0_clk", .id
= 48 },
91 { .n
= "ssc1_clk", .id
= 49 },
92 { .n
= "trng_clk", .id
= 53 },
93 { .n
= "macb0_clk", .id
= 54 },
94 { .n
= "macb1_clk", .id
= 55 },
95 { .n
= "fuse_clk", .id
= 57 },
96 { .n
= "securam_clk", .id
= 59 },
97 { .n
= "smd_clk", .id
= 61 },
98 { .n
= "twi3_clk", .id
= 62 },
99 { .n
= "catb_clk", .id
= 63 },
102 static const struct {
105 } sama5d4_periphck
[] = {
106 { .n
= "dma0_clk", .id
= 8 },
107 { .n
= "cpkcc_clk", .id
= 10 },
108 { .n
= "aesb_clk", .id
= 13 },
109 { .n
= "mpddr_clk", .id
= 16 },
110 { .n
= "matrix0_clk", .id
= 18 },
111 { .n
= "vdec_clk", .id
= 19 },
112 { .n
= "dma1_clk", .id
= 50 },
113 { .n
= "lcdc_clk", .id
= 51 },
114 { .n
= "isi_clk", .id
= 52 },
117 static void __init
sama5d4_pmc_setup(struct device_node
*np
)
119 struct clk_range range
= CLK_RANGE(0, 0);
120 const char *slck_name
, *mainxtal_name
;
121 struct pmc_data
*sama5d4_pmc
;
122 const char *parent_names
[5];
123 struct regmap
*regmap
;
128 i
= of_property_match_string(np
, "clock-names", "slow_clk");
132 slck_name
= of_clk_get_parent_name(np
, i
);
134 i
= of_property_match_string(np
, "clock-names", "main_xtal");
137 mainxtal_name
= of_clk_get_parent_name(np
, i
);
139 regmap
= device_node_to_regmap(np
);
143 sama5d4_pmc
= pmc_data_allocate(PMC_PLLACK
+ 1,
144 nck(sama5d4_systemck
),
145 nck(sama5d4_periph32ck
), 0, 3);
149 hw
= at91_clk_register_main_rc_osc(regmap
, "main_rc_osc", 12000000,
154 bypass
= of_property_read_bool(np
, "atmel,osc-bypass");
156 hw
= at91_clk_register_main_osc(regmap
, "main_osc", mainxtal_name
,
161 parent_names
[0] = "main_rc_osc";
162 parent_names
[1] = "main_osc";
163 hw
= at91_clk_register_sam9x5_main(regmap
, "mainck", parent_names
, 2);
167 hw
= at91_clk_register_pll(regmap
, "pllack", "mainck", 0,
168 &sama5d3_pll_layout
, &plla_characteristics
);
172 hw
= at91_clk_register_plldiv(regmap
, "plladivck", "pllack");
176 sama5d4_pmc
->chws
[PMC_PLLACK
] = hw
;
178 hw
= at91_clk_register_utmi(regmap
, NULL
, "utmick", "mainck");
182 sama5d4_pmc
->chws
[PMC_UTMI
] = hw
;
184 parent_names
[0] = slck_name
;
185 parent_names
[1] = "mainck";
186 parent_names
[2] = "plladivck";
187 parent_names
[3] = "utmick";
188 hw
= at91_clk_register_master(regmap
, "masterck", 4, parent_names
,
189 &at91sam9x5_master_layout
,
190 &mck_characteristics
);
194 sama5d4_pmc
->chws
[PMC_MCK
] = hw
;
196 hw
= at91_clk_register_h32mx(regmap
, "h32mxck", "masterck");
200 sama5d4_pmc
->chws
[PMC_MCK2
] = hw
;
202 parent_names
[0] = "plladivck";
203 parent_names
[1] = "utmick";
204 hw
= at91sam9x5_clk_register_usb(regmap
, "usbck", parent_names
, 2);
208 parent_names
[0] = "plladivck";
209 parent_names
[1] = "utmick";
210 hw
= at91sam9x5_clk_register_smd(regmap
, "smdclk", parent_names
, 2);
214 parent_names
[0] = slck_name
;
215 parent_names
[1] = "mainck";
216 parent_names
[2] = "plladivck";
217 parent_names
[3] = "utmick";
218 parent_names
[4] = "masterck";
219 for (i
= 0; i
< 3; i
++) {
222 snprintf(name
, sizeof(name
), "prog%d", i
);
224 hw
= at91_clk_register_programmable(regmap
, name
,
226 &at91sam9x5_programmable_layout
,
231 sama5d4_pmc
->pchws
[i
] = hw
;
234 for (i
= 0; i
< ARRAY_SIZE(sama5d4_systemck
); i
++) {
235 hw
= at91_clk_register_system(regmap
, sama5d4_systemck
[i
].n
,
236 sama5d4_systemck
[i
].p
,
237 sama5d4_systemck
[i
].id
);
241 sama5d4_pmc
->shws
[sama5d4_systemck
[i
].id
] = hw
;
244 for (i
= 0; i
< ARRAY_SIZE(sama5d4_periphck
); i
++) {
245 hw
= at91_clk_register_sam9x5_peripheral(regmap
, &pmc_pcr_lock
,
247 sama5d4_periphck
[i
].n
,
249 sama5d4_periphck
[i
].id
,
254 sama5d4_pmc
->phws
[sama5d4_periphck
[i
].id
] = hw
;
257 for (i
= 0; i
< ARRAY_SIZE(sama5d4_periph32ck
); i
++) {
258 hw
= at91_clk_register_sam9x5_peripheral(regmap
, &pmc_pcr_lock
,
260 sama5d4_periph32ck
[i
].n
,
262 sama5d4_periph32ck
[i
].id
,
267 sama5d4_pmc
->phws
[sama5d4_periph32ck
[i
].id
] = hw
;
270 of_clk_add_hw_provider(np
, of_clk_hw_pmc_get
, sama5d4_pmc
);
277 CLK_OF_DECLARE_DRIVER(sama5d4_pmc
, "atmel,sama5d4-pmc", sama5d4_pmc_setup
);