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(at91sam9g45_mck_lock
);
12 static const struct clk_master_characteristics mck_characteristics
= {
13 .output
= { .min
= 0, .max
= 133333333 },
14 .divisors
= { 1, 2, 4, 3 },
17 static u8 plla_out
[] = { 0, 1, 2, 3, 0, 1, 2, 3 };
19 static u16 plla_icpll
[] = { 0, 0, 0, 0, 1, 1, 1, 1 };
21 static const struct clk_range plla_outputs
[] = {
22 { .min
= 745000000, .max
= 800000000 },
23 { .min
= 695000000, .max
= 750000000 },
24 { .min
= 645000000, .max
= 700000000 },
25 { .min
= 595000000, .max
= 650000000 },
26 { .min
= 545000000, .max
= 600000000 },
27 { .min
= 495000000, .max
= 555000000 },
28 { .min
= 445000000, .max
= 500000000 },
29 { .min
= 400000000, .max
= 450000000 },
32 static const struct clk_pll_characteristics plla_characteristics
= {
33 .input
= { .min
= 2000000, .max
= 32000000 },
34 .num_output
= ARRAY_SIZE(plla_outputs
),
35 .output
= plla_outputs
,
44 } at91sam9g45_systemck
[] = {
45 { .n
= "ddrck", .p
= "masterck_div", .id
= 2 },
46 { .n
= "uhpck", .p
= "usbck", .id
= 6 },
47 { .n
= "pck0", .p
= "prog0", .id
= 8 },
48 { .n
= "pck1", .p
= "prog1", .id
= 9 },
56 static const struct pck at91sam9g45_periphck
[] = {
57 { .n
= "pioA_clk", .id
= 2, },
58 { .n
= "pioB_clk", .id
= 3, },
59 { .n
= "pioC_clk", .id
= 4, },
60 { .n
= "pioDE_clk", .id
= 5, },
61 { .n
= "trng_clk", .id
= 6, },
62 { .n
= "usart0_clk", .id
= 7, },
63 { .n
= "usart1_clk", .id
= 8, },
64 { .n
= "usart2_clk", .id
= 9, },
65 { .n
= "usart3_clk", .id
= 10, },
66 { .n
= "mci0_clk", .id
= 11, },
67 { .n
= "twi0_clk", .id
= 12, },
68 { .n
= "twi1_clk", .id
= 13, },
69 { .n
= "spi0_clk", .id
= 14, },
70 { .n
= "spi1_clk", .id
= 15, },
71 { .n
= "ssc0_clk", .id
= 16, },
72 { .n
= "ssc1_clk", .id
= 17, },
73 { .n
= "tcb0_clk", .id
= 18, },
74 { .n
= "pwm_clk", .id
= 19, },
75 { .n
= "adc_clk", .id
= 20, },
76 { .n
= "dma0_clk", .id
= 21, },
77 { .n
= "uhphs_clk", .id
= 22, },
78 { .n
= "lcd_clk", .id
= 23, },
79 { .n
= "ac97_clk", .id
= 24, },
80 { .n
= "macb0_clk", .id
= 25, },
81 { .n
= "isi_clk", .id
= 26, },
82 { .n
= "udphs_clk", .id
= 27, },
83 { .n
= "aestdessha_clk", .id
= 28, },
84 { .n
= "mci1_clk", .id
= 29, },
85 { .n
= "vdec_clk", .id
= 30, },
88 static void __init
at91sam9g45_pmc_setup(struct device_node
*np
)
90 const char *slck_name
, *mainxtal_name
;
91 struct pmc_data
*at91sam9g45_pmc
;
92 const char *parent_names
[6];
93 struct regmap
*regmap
;
98 i
= of_property_match_string(np
, "clock-names", "slow_clk");
102 slck_name
= of_clk_get_parent_name(np
, i
);
104 i
= of_property_match_string(np
, "clock-names", "main_xtal");
107 mainxtal_name
= of_clk_get_parent_name(np
, i
);
109 regmap
= device_node_to_regmap(np
);
113 at91sam9g45_pmc
= pmc_data_allocate(PMC_PLLACK
+ 1,
114 nck(at91sam9g45_systemck
),
115 nck(at91sam9g45_periphck
), 0, 2);
116 if (!at91sam9g45_pmc
)
119 bypass
= of_property_read_bool(np
, "atmel,osc-bypass");
121 hw
= at91_clk_register_main_osc(regmap
, "main_osc", mainxtal_name
,
126 hw
= at91_clk_register_rm9200_main(regmap
, "mainck", "main_osc");
130 at91sam9g45_pmc
->chws
[PMC_MAIN
] = hw
;
132 hw
= at91_clk_register_pll(regmap
, "pllack", "mainck", 0,
133 &at91rm9200_pll_layout
, &plla_characteristics
);
137 hw
= at91_clk_register_plldiv(regmap
, "plladivck", "pllack");
141 at91sam9g45_pmc
->chws
[PMC_PLLACK
] = hw
;
143 hw
= at91_clk_register_utmi(regmap
, NULL
, "utmick", "mainck");
147 at91sam9g45_pmc
->chws
[PMC_UTMI
] = hw
;
149 parent_names
[0] = slck_name
;
150 parent_names
[1] = "mainck";
151 parent_names
[2] = "plladivck";
152 parent_names
[3] = "utmick";
153 hw
= at91_clk_register_master_pres(regmap
, "masterck_pres", 4,
155 &at91rm9200_master_layout
,
156 &mck_characteristics
,
157 &at91sam9g45_mck_lock
,
158 CLK_SET_RATE_GATE
, INT_MIN
);
162 hw
= at91_clk_register_master_div(regmap
, "masterck_div",
164 &at91rm9200_master_layout
,
165 &mck_characteristics
,
166 &at91sam9g45_mck_lock
,
171 at91sam9g45_pmc
->chws
[PMC_MCK
] = hw
;
173 parent_names
[0] = "plladivck";
174 parent_names
[1] = "utmick";
175 hw
= at91sam9x5_clk_register_usb(regmap
, "usbck", parent_names
, 2);
179 parent_names
[0] = slck_name
;
180 parent_names
[1] = "mainck";
181 parent_names
[2] = "plladivck";
182 parent_names
[3] = "utmick";
183 parent_names
[4] = "masterck_div";
184 for (i
= 0; i
< 2; i
++) {
187 snprintf(name
, sizeof(name
), "prog%d", i
);
189 hw
= at91_clk_register_programmable(regmap
, name
,
191 &at91sam9g45_programmable_layout
,
196 at91sam9g45_pmc
->pchws
[i
] = hw
;
199 for (i
= 0; i
< ARRAY_SIZE(at91sam9g45_systemck
); i
++) {
200 hw
= at91_clk_register_system(regmap
, at91sam9g45_systemck
[i
].n
,
201 at91sam9g45_systemck
[i
].p
,
202 at91sam9g45_systemck
[i
].id
);
206 at91sam9g45_pmc
->shws
[at91sam9g45_systemck
[i
].id
] = hw
;
209 for (i
= 0; i
< ARRAY_SIZE(at91sam9g45_periphck
); i
++) {
210 hw
= at91_clk_register_peripheral(regmap
,
211 at91sam9g45_periphck
[i
].n
,
213 at91sam9g45_periphck
[i
].id
);
217 at91sam9g45_pmc
->phws
[at91sam9g45_periphck
[i
].id
] = hw
;
220 of_clk_add_hw_provider(np
, of_clk_hw_pmc_get
, at91sam9g45_pmc
);
225 kfree(at91sam9g45_pmc
);
228 * The TCB is used as the clocksource so its clock is needed early. This means
229 * this can't be a platform driver.
231 CLK_OF_DECLARE_DRIVER(at91sam9g45_pmc
, "atmel,at91sam9g45-pmc",
232 at91sam9g45_pmc_setup
);