gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / clk / at91 / at91rm9200.c
blobc44a431b6c9723770ee286f46499aa462e9c47d0
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>
8 #include "pmc.h"
10 struct sck {
11 char *n;
12 char *p;
13 u8 id;
16 struct pck {
17 char *n;
18 u8 id;
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;
82 struct clk_hw *hw;
83 int i;
84 bool bypass;
86 i = of_property_match_string(np, "clock-names", "slow_xtal");
87 if (i < 0)
88 return;
90 slowxtal_name = of_clk_get_parent_name(np, i);
92 i = of_property_match_string(np, "clock-names", "main_xtal");
93 if (i < 0)
94 return;
95 mainxtal_name = of_clk_get_parent_name(np, i);
97 regmap = device_node_to_regmap(np);
98 if (IS_ERR(regmap))
99 return;
101 at91rm9200_pmc = pmc_data_allocate(PMC_MAIN + 1,
102 nck(at91rm9200_systemck),
103 nck(at91rm9200_periphck), 0);
104 if (!at91rm9200_pmc)
105 return;
107 bypass = of_property_read_bool(np, "atmel,osc-bypass");
109 hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name,
110 bypass);
111 if (IS_ERR(hw))
112 goto err_free;
114 hw = at91_clk_register_rm9200_main(regmap, "mainck", "main_osc");
115 if (IS_ERR(hw))
116 goto err_free;
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);
123 if (IS_ERR(hw))
124 goto err_free;
126 hw = at91_clk_register_pll(regmap, "pllbck", "mainck", 1,
127 &at91rm9200_pll_layout,
128 &rm9200_pll_characteristics);
129 if (IS_ERR(hw))
130 goto err_free;
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);
139 if (IS_ERR(hw))
140 goto err_free;
142 at91rm9200_pmc->chws[PMC_MCK] = hw;
144 hw = at91rm9200_clk_register_usb(regmap, "usbck", "pllbck", usb_div);
145 if (IS_ERR(hw))
146 goto err_free;
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++) {
153 char name[6];
155 snprintf(name, sizeof(name), "prog%d", i);
157 hw = at91_clk_register_programmable(regmap, name,
158 parent_names, 4, i,
159 &at91rm9200_programmable_layout);
160 if (IS_ERR(hw))
161 goto err_free;
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);
168 if (IS_ERR(hw))
169 goto err_free;
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,
177 "masterck",
178 at91rm9200_periphck[i].id);
179 if (IS_ERR(hw))
180 goto err_free;
182 at91rm9200_pmc->phws[at91rm9200_periphck[i].id] = hw;
185 of_clk_add_hw_provider(np, of_clk_hw_pmc_get, at91rm9200_pmc);
187 return;
189 err_free:
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
196 * driver.
198 CLK_OF_DECLARE_DRIVER(at91rm9200_pmc, "atmel,at91rm9200-pmc",
199 at91rm9200_pmc_setup);