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(sam9rl_mck_lock);
12 static const struct clk_master_characteristics sam9rl_mck_characteristics = {
13 .output = { .min = 0, .max = 94000000 },
14 .divisors = { 1, 2, 4, 0 },
17 static u8 sam9rl_plla_out[] = { 0, 2 };
19 static const struct clk_range sam9rl_plla_outputs[] = {
20 { .min = 80000000, .max = 200000000 },
21 { .min = 190000000, .max = 240000000 },
24 static const struct clk_pll_characteristics sam9rl_plla_characteristics = {
25 .input = { .min = 1000000, .max = 32000000 },
26 .num_output = ARRAY_SIZE(sam9rl_plla_outputs),
27 .output = sam9rl_plla_outputs,
28 .out = sam9rl_plla_out,
35 } at91sam9rl_systemck[] = {
36 { .n = "pck0", .p = "prog0", .id = 8 },
37 { .n = "pck1", .p = "prog1", .id = 9 },
43 } at91sam9rl_periphck[] = {
44 { .n = "pioA_clk", .id = 2, },
45 { .n = "pioB_clk", .id = 3, },
46 { .n = "pioC_clk", .id = 4, },
47 { .n = "pioD_clk", .id = 5, },
48 { .n = "usart0_clk", .id = 6, },
49 { .n = "usart1_clk", .id = 7, },
50 { .n = "usart2_clk", .id = 8, },
51 { .n = "usart3_clk", .id = 9, },
52 { .n = "mci0_clk", .id = 10, },
53 { .n = "twi0_clk", .id = 11, },
54 { .n = "twi1_clk", .id = 12, },
55 { .n = "spi0_clk", .id = 13, },
56 { .n = "ssc0_clk", .id = 14, },
57 { .n = "ssc1_clk", .id = 15, },
58 { .n = "tc0_clk", .id = 16, },
59 { .n = "tc1_clk", .id = 17, },
60 { .n = "tc2_clk", .id = 18, },
61 { .n = "pwm_clk", .id = 19, },
62 { .n = "adc_clk", .id = 20, },
63 { .n = "dma0_clk", .id = 21, },
64 { .n = "udphs_clk", .id = 22, },
65 { .n = "lcd_clk", .id = 23, },
68 static void __init at91sam9rl_pmc_setup(struct device_node *np)
70 const char *slck_name, *mainxtal_name;
71 struct pmc_data *at91sam9rl_pmc;
72 const char *parent_names[6];
73 struct regmap *regmap;
77 i = of_property_match_string(np, "clock-names", "slow_clk");
81 slck_name = of_clk_get_parent_name(np, i);
83 i = of_property_match_string(np, "clock-names", "main_xtal");
86 mainxtal_name = of_clk_get_parent_name(np, i);
88 regmap = device_node_to_regmap(np);
92 at91sam9rl_pmc = pmc_data_allocate(PMC_PLLACK + 1,
93 nck(at91sam9rl_systemck),
94 nck(at91sam9rl_periphck), 0, 2);
98 hw = at91_clk_register_rm9200_main(regmap, "mainck", mainxtal_name);
102 at91sam9rl_pmc->chws[PMC_MAIN] = hw;
104 hw = at91_clk_register_pll(regmap, "pllack", "mainck", 0,
105 &at91rm9200_pll_layout,
106 &sam9rl_plla_characteristics);
110 at91sam9rl_pmc->chws[PMC_PLLACK] = hw;
112 hw = at91_clk_register_utmi(regmap, NULL, "utmick", "mainck");
116 at91sam9rl_pmc->chws[PMC_UTMI] = hw;
118 parent_names[0] = slck_name;
119 parent_names[1] = "mainck";
120 parent_names[2] = "pllack";
121 parent_names[3] = "utmick";
122 hw = at91_clk_register_master_pres(regmap, "masterck_pres", 4,
124 &at91rm9200_master_layout,
125 &sam9rl_mck_characteristics,
126 &sam9rl_mck_lock, CLK_SET_RATE_GATE,
131 hw = at91_clk_register_master_div(regmap, "masterck_div",
133 &at91rm9200_master_layout,
134 &sam9rl_mck_characteristics,
135 &sam9rl_mck_lock, CLK_SET_RATE_GATE);
139 at91sam9rl_pmc->chws[PMC_MCK] = hw;
141 parent_names[0] = slck_name;
142 parent_names[1] = "mainck";
143 parent_names[2] = "pllack";
144 parent_names[3] = "utmick";
145 parent_names[4] = "masterck_div";
146 for (i = 0; i < 2; i++) {
149 snprintf(name, sizeof(name), "prog%d", i);
151 hw = at91_clk_register_programmable(regmap, name,
153 &at91rm9200_programmable_layout,
158 at91sam9rl_pmc->pchws[i] = hw;
161 for (i = 0; i < ARRAY_SIZE(at91sam9rl_systemck); i++) {
162 hw = at91_clk_register_system(regmap, at91sam9rl_systemck[i].n,
163 at91sam9rl_systemck[i].p,
164 at91sam9rl_systemck[i].id);
168 at91sam9rl_pmc->shws[at91sam9rl_systemck[i].id] = hw;
171 for (i = 0; i < ARRAY_SIZE(at91sam9rl_periphck); i++) {
172 hw = at91_clk_register_peripheral(regmap,
173 at91sam9rl_periphck[i].n,
175 at91sam9rl_periphck[i].id);
179 at91sam9rl_pmc->phws[at91sam9rl_periphck[i].id] = hw;
182 of_clk_add_hw_provider(np, of_clk_hw_pmc_get, at91sam9rl_pmc);
187 kfree(at91sam9rl_pmc);
190 CLK_OF_DECLARE(at91sam9rl_pmc, "atmel,at91sam9rl-pmc", at91sam9rl_pmc_setup);