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>
21 static const struct clk_master_characteristics rm9200_mck_characteristics
= {
22 .output
= { .min
= 0, .max
= 80000000 },
23 .divisors
= { 1, 2, 3, 4 },
26 static u8 rm9200_pll_out
[] = { 0, 2 };
28 static const struct clk_range rm9200_pll_outputs
[] = {
29 { .min
= 80000000, .max
= 160000000 },
30 { .min
= 150000000, .max
= 180000000 },
33 static const struct clk_pll_characteristics rm9200_pll_characteristics
= {
34 .input
= { .min
= 1000000, .max
= 32000000 },
35 .num_output
= ARRAY_SIZE(rm9200_pll_outputs
),
36 .output
= rm9200_pll_outputs
,
37 .out
= rm9200_pll_out
,
40 static const struct sck at91rm9200_systemck
[] = {
41 { .n
= "udpck", .p
= "usbck", .id
= 2 },
42 { .n
= "uhpck", .p
= "usbck", .id
= 4 },
43 { .n
= "pck0", .p
= "prog0", .id
= 8 },
44 { .n
= "pck1", .p
= "prog1", .id
= 9 },
45 { .n
= "pck2", .p
= "prog2", .id
= 10 },
46 { .n
= "pck3", .p
= "prog3", .id
= 11 },
49 static const struct pck at91rm9200_periphck
[] = {
50 { .n
= "pioA_clk", .id
= 2 },
51 { .n
= "pioB_clk", .id
= 3 },
52 { .n
= "pioC_clk", .id
= 4 },
53 { .n
= "pioD_clk", .id
= 5 },
54 { .n
= "usart0_clk", .id
= 6 },
55 { .n
= "usart1_clk", .id
= 7 },
56 { .n
= "usart2_clk", .id
= 8 },
57 { .n
= "usart3_clk", .id
= 9 },
58 { .n
= "mci0_clk", .id
= 10 },
59 { .n
= "udc_clk", .id
= 11 },
60 { .n
= "twi0_clk", .id
= 12 },
61 { .n
= "spi0_clk", .id
= 13 },
62 { .n
= "ssc0_clk", .id
= 14 },
63 { .n
= "ssc1_clk", .id
= 15 },
64 { .n
= "ssc2_clk", .id
= 16 },
65 { .n
= "tc0_clk", .id
= 17 },
66 { .n
= "tc1_clk", .id
= 18 },
67 { .n
= "tc2_clk", .id
= 19 },
68 { .n
= "tc3_clk", .id
= 20 },
69 { .n
= "tc4_clk", .id
= 21 },
70 { .n
= "tc5_clk", .id
= 22 },
71 { .n
= "ohci_clk", .id
= 23 },
72 { .n
= "macb0_clk", .id
= 24 },
75 static void __init
at91rm9200_pmc_setup(struct device_node
*np
)
77 const char *slowxtal_name
, *mainxtal_name
;
78 struct pmc_data
*at91rm9200_pmc
;
79 u32 usb_div
[] = { 1, 2, 0, 0 };
80 const char *parent_names
[6];
81 struct regmap
*regmap
;
86 i
= of_property_match_string(np
, "clock-names", "slow_xtal");
90 slowxtal_name
= of_clk_get_parent_name(np
, i
);
92 i
= of_property_match_string(np
, "clock-names", "main_xtal");
95 mainxtal_name
= of_clk_get_parent_name(np
, i
);
97 regmap
= device_node_to_regmap(np
);
101 at91rm9200_pmc
= pmc_data_allocate(PMC_MAIN
+ 1,
102 nck(at91rm9200_systemck
),
103 nck(at91rm9200_periphck
), 0);
107 bypass
= of_property_read_bool(np
, "atmel,osc-bypass");
109 hw
= at91_clk_register_main_osc(regmap
, "main_osc", mainxtal_name
,
114 hw
= at91_clk_register_rm9200_main(regmap
, "mainck", "main_osc");
118 at91rm9200_pmc
->chws
[PMC_MAIN
] = hw
;
120 hw
= at91_clk_register_pll(regmap
, "pllack", "mainck", 0,
121 &at91rm9200_pll_layout
,
122 &rm9200_pll_characteristics
);
126 hw
= at91_clk_register_pll(regmap
, "pllbck", "mainck", 1,
127 &at91rm9200_pll_layout
,
128 &rm9200_pll_characteristics
);
132 parent_names
[0] = slowxtal_name
;
133 parent_names
[1] = "mainck";
134 parent_names
[2] = "pllack";
135 parent_names
[3] = "pllbck";
136 hw
= at91_clk_register_master(regmap
, "masterck", 4, parent_names
,
137 &at91rm9200_master_layout
,
138 &rm9200_mck_characteristics
);
142 at91rm9200_pmc
->chws
[PMC_MCK
] = hw
;
144 hw
= at91rm9200_clk_register_usb(regmap
, "usbck", "pllbck", usb_div
);
148 parent_names
[0] = slowxtal_name
;
149 parent_names
[1] = "mainck";
150 parent_names
[2] = "pllack";
151 parent_names
[3] = "pllbck";
152 for (i
= 0; i
< 4; i
++) {
155 snprintf(name
, sizeof(name
), "prog%d", i
);
157 hw
= at91_clk_register_programmable(regmap
, name
,
159 &at91rm9200_programmable_layout
);
164 for (i
= 0; i
< ARRAY_SIZE(at91rm9200_systemck
); i
++) {
165 hw
= at91_clk_register_system(regmap
, at91rm9200_systemck
[i
].n
,
166 at91rm9200_systemck
[i
].p
,
167 at91rm9200_systemck
[i
].id
);
171 at91rm9200_pmc
->shws
[at91rm9200_systemck
[i
].id
] = hw
;
174 for (i
= 0; i
< ARRAY_SIZE(at91rm9200_periphck
); i
++) {
175 hw
= at91_clk_register_peripheral(regmap
,
176 at91rm9200_periphck
[i
].n
,
178 at91rm9200_periphck
[i
].id
);
182 at91rm9200_pmc
->phws
[at91rm9200_periphck
[i
].id
] = hw
;
185 of_clk_add_hw_provider(np
, of_clk_hw_pmc_get
, at91rm9200_pmc
);
190 pmc_data_free(at91rm9200_pmc
);
193 * While the TCB can be used as the clocksource, the system timer is most likely
194 * to be used instead. However, the pinctrl driver doesn't support probe
195 * deferring properly. Once this is fixed, this can be switched to a platform
198 CLK_OF_DECLARE_DRIVER(at91rm9200_pmc
, "atmel,at91rm9200-pmc",
199 at91rm9200_pmc_setup
);