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 DEFINE_SPINLOCK(mck_lock
);
12 static const struct clk_master_characteristics mck_characteristics
= {
13 .output
= { .min
= 125000000, .max
= 200000000 },
14 .divisors
= { 1, 2, 4, 3 },
17 static u8 plla_out
[] = { 0 };
19 static u16 plla_icpll
[] = { 0 };
21 static const struct clk_range plla_outputs
[] = {
22 { .min
= 600000000, .max
= 1200000000 },
25 static const struct clk_pll_characteristics plla_characteristics
= {
26 .input
= { .min
= 12000000, .max
= 12000000 },
27 .num_output
= ARRAY_SIZE(plla_outputs
),
28 .output
= plla_outputs
,
33 static const struct clk_pcr_layout sama5d4_pcr_layout
= {
36 .pid_mask
= GENMASK(6, 0),
44 } sama5d4_systemck
[] = {
46 * ddrck feeds DDR controller and is enabled by bootloader thus we need
47 * to keep it enabled in case there is no Linux consumer for it.
49 { .n
= "ddrck", .p
= "masterck_div", .id
= 2, .flags
= CLK_IS_CRITICAL
},
50 { .n
= "lcdck", .p
= "masterck_div", .id
= 3 },
51 { .n
= "smdck", .p
= "smdclk", .id
= 4 },
52 { .n
= "uhpck", .p
= "usbck", .id
= 6 },
53 { .n
= "udpck", .p
= "usbck", .id
= 7 },
54 { .n
= "pck0", .p
= "prog0", .id
= 8 },
55 { .n
= "pck1", .p
= "prog1", .id
= 9 },
56 { .n
= "pck2", .p
= "prog2", .id
= 10 },
62 } sama5d4_periph32ck
[] = {
63 { .n
= "pioD_clk", .id
= 5 },
64 { .n
= "usart0_clk", .id
= 6 },
65 { .n
= "usart1_clk", .id
= 7 },
66 { .n
= "icm_clk", .id
= 9 },
67 { .n
= "aes_clk", .id
= 12 },
68 { .n
= "tdes_clk", .id
= 14 },
69 { .n
= "sha_clk", .id
= 15 },
70 { .n
= "matrix1_clk", .id
= 17 },
71 { .n
= "hsmc_clk", .id
= 22 },
72 { .n
= "pioA_clk", .id
= 23 },
73 { .n
= "pioB_clk", .id
= 24 },
74 { .n
= "pioC_clk", .id
= 25 },
75 { .n
= "pioE_clk", .id
= 26 },
76 { .n
= "uart0_clk", .id
= 27 },
77 { .n
= "uart1_clk", .id
= 28 },
78 { .n
= "usart2_clk", .id
= 29 },
79 { .n
= "usart3_clk", .id
= 30 },
80 { .n
= "usart4_clk", .id
= 31 },
81 { .n
= "twi0_clk", .id
= 32 },
82 { .n
= "twi1_clk", .id
= 33 },
83 { .n
= "twi2_clk", .id
= 34 },
84 { .n
= "mci0_clk", .id
= 35 },
85 { .n
= "mci1_clk", .id
= 36 },
86 { .n
= "spi0_clk", .id
= 37 },
87 { .n
= "spi1_clk", .id
= 38 },
88 { .n
= "spi2_clk", .id
= 39 },
89 { .n
= "tcb0_clk", .id
= 40 },
90 { .n
= "tcb1_clk", .id
= 41 },
91 { .n
= "tcb2_clk", .id
= 42 },
92 { .n
= "pwm_clk", .id
= 43 },
93 { .n
= "adc_clk", .id
= 44 },
94 { .n
= "dbgu_clk", .id
= 45 },
95 { .n
= "uhphs_clk", .id
= 46 },
96 { .n
= "udphs_clk", .id
= 47 },
97 { .n
= "ssc0_clk", .id
= 48 },
98 { .n
= "ssc1_clk", .id
= 49 },
99 { .n
= "trng_clk", .id
= 53 },
100 { .n
= "macb0_clk", .id
= 54 },
101 { .n
= "macb1_clk", .id
= 55 },
102 { .n
= "fuse_clk", .id
= 57 },
103 { .n
= "securam_clk", .id
= 59 },
104 { .n
= "smd_clk", .id
= 61 },
105 { .n
= "twi3_clk", .id
= 62 },
106 { .n
= "catb_clk", .id
= 63 },
109 static const struct {
113 } sama5d4_periphck
[] = {
114 { .n
= "dma0_clk", .id
= 8 },
115 { .n
= "cpkcc_clk", .id
= 10 },
116 { .n
= "aesb_clk", .id
= 13 },
118 * mpddr_clk feeds DDR controller and is enabled by bootloader thus we
119 * need to keep it enabled in case there is no Linux consumer for it.
121 { .n
= "mpddr_clk", .id
= 16, .flags
= CLK_IS_CRITICAL
},
122 { .n
= "matrix0_clk", .id
= 18 },
123 { .n
= "vdec_clk", .id
= 19 },
124 { .n
= "dma1_clk", .id
= 50 },
125 { .n
= "lcdc_clk", .id
= 51 },
126 { .n
= "isi_clk", .id
= 52 },
129 static void __init
sama5d4_pmc_setup(struct device_node
*np
)
131 struct clk_range range
= CLK_RANGE(0, 0);
132 const char *slck_name
, *mainxtal_name
;
133 struct pmc_data
*sama5d4_pmc
;
134 const char *parent_names
[5];
135 struct regmap
*regmap
;
140 i
= of_property_match_string(np
, "clock-names", "slow_clk");
144 slck_name
= of_clk_get_parent_name(np
, i
);
146 i
= of_property_match_string(np
, "clock-names", "main_xtal");
149 mainxtal_name
= of_clk_get_parent_name(np
, i
);
151 regmap
= device_node_to_regmap(np
);
155 sama5d4_pmc
= pmc_data_allocate(PMC_PLLACK
+ 1,
156 nck(sama5d4_systemck
),
157 nck(sama5d4_periph32ck
), 0, 3);
161 hw
= at91_clk_register_main_rc_osc(regmap
, "main_rc_osc", 12000000,
166 bypass
= of_property_read_bool(np
, "atmel,osc-bypass");
168 hw
= at91_clk_register_main_osc(regmap
, "main_osc", mainxtal_name
, NULL
,
173 parent_names
[0] = "main_rc_osc";
174 parent_names
[1] = "main_osc";
175 hw
= at91_clk_register_sam9x5_main(regmap
, "mainck", parent_names
, NULL
, 2);
179 hw
= at91_clk_register_pll(regmap
, "pllack", "mainck", 0,
180 &sama5d3_pll_layout
, &plla_characteristics
);
184 hw
= at91_clk_register_plldiv(regmap
, "plladivck", "pllack");
188 sama5d4_pmc
->chws
[PMC_PLLACK
] = hw
;
190 hw
= at91_clk_register_utmi(regmap
, NULL
, "utmick", "mainck", NULL
);
194 sama5d4_pmc
->chws
[PMC_UTMI
] = hw
;
196 parent_names
[0] = slck_name
;
197 parent_names
[1] = "mainck";
198 parent_names
[2] = "plladivck";
199 parent_names
[3] = "utmick";
200 hw
= at91_clk_register_master_pres(regmap
, "masterck_pres", 4,
202 &at91sam9x5_master_layout
,
203 &mck_characteristics
, &mck_lock
);
207 hw
= at91_clk_register_master_div(regmap
, "masterck_div",
208 "masterck_pres", NULL
,
209 &at91sam9x5_master_layout
,
210 &mck_characteristics
, &mck_lock
,
211 CLK_SET_RATE_GATE
, 0);
215 sama5d4_pmc
->chws
[PMC_MCK
] = hw
;
217 hw
= at91_clk_register_h32mx(regmap
, "h32mxck", "masterck_div");
221 sama5d4_pmc
->chws
[PMC_MCK2
] = hw
;
223 parent_names
[0] = "plladivck";
224 parent_names
[1] = "utmick";
225 hw
= at91sam9x5_clk_register_usb(regmap
, "usbck", parent_names
, 2);
229 parent_names
[0] = "plladivck";
230 parent_names
[1] = "utmick";
231 hw
= at91sam9x5_clk_register_smd(regmap
, "smdclk", parent_names
, 2);
235 parent_names
[0] = slck_name
;
236 parent_names
[1] = "mainck";
237 parent_names
[2] = "plladivck";
238 parent_names
[3] = "utmick";
239 parent_names
[4] = "masterck_div";
240 for (i
= 0; i
< 3; i
++) {
243 snprintf(name
, sizeof(name
), "prog%d", i
);
245 hw
= at91_clk_register_programmable(regmap
, name
,
246 parent_names
, NULL
, 5, i
,
247 &at91sam9x5_programmable_layout
,
252 sama5d4_pmc
->pchws
[i
] = hw
;
255 for (i
= 0; i
< ARRAY_SIZE(sama5d4_systemck
); i
++) {
256 hw
= at91_clk_register_system(regmap
, sama5d4_systemck
[i
].n
,
257 sama5d4_systemck
[i
].p
, NULL
,
258 sama5d4_systemck
[i
].id
,
259 sama5d4_systemck
[i
].flags
);
263 sama5d4_pmc
->shws
[sama5d4_systemck
[i
].id
] = hw
;
266 for (i
= 0; i
< ARRAY_SIZE(sama5d4_periphck
); i
++) {
267 hw
= at91_clk_register_sam9x5_peripheral(regmap
, &pmc_pcr_lock
,
269 sama5d4_periphck
[i
].n
,
270 "masterck_div", NULL
,
271 sama5d4_periphck
[i
].id
,
273 sama5d4_periphck
[i
].flags
);
277 sama5d4_pmc
->phws
[sama5d4_periphck
[i
].id
] = hw
;
280 for (i
= 0; i
< ARRAY_SIZE(sama5d4_periph32ck
); i
++) {
281 hw
= at91_clk_register_sam9x5_peripheral(regmap
, &pmc_pcr_lock
,
283 sama5d4_periph32ck
[i
].n
,
285 sama5d4_periph32ck
[i
].id
,
290 sama5d4_pmc
->phws
[sama5d4_periph32ck
[i
].id
] = hw
;
293 of_clk_add_hw_provider(np
, of_clk_hw_pmc_get
, sama5d4_pmc
);
301 CLK_OF_DECLARE(sama5d4_pmc
, "atmel,sama5d4-pmc", sama5d4_pmc_setup
);