.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * drivers/clk/at91/sckc.c |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | | - * |
---|
11 | 6 | */ |
---|
12 | 7 | |
---|
13 | 8 | #include <linux/clk-provider.h> |
---|
.. | .. |
---|
23 | 18 | SLOW_CLOCK_FREQ) |
---|
24 | 19 | |
---|
25 | 20 | #define AT91_SCKC_CR 0x00 |
---|
26 | | -#define AT91_SCKC_RCEN (1 << 0) |
---|
27 | | -#define AT91_SCKC_OSC32EN (1 << 1) |
---|
28 | | -#define AT91_SCKC_OSC32BYP (1 << 2) |
---|
29 | | -#define AT91_SCKC_OSCSEL (1 << 3) |
---|
| 21 | + |
---|
| 22 | +struct clk_slow_bits { |
---|
| 23 | + u32 cr_rcen; |
---|
| 24 | + u32 cr_osc32en; |
---|
| 25 | + u32 cr_osc32byp; |
---|
| 26 | + u32 cr_oscsel; |
---|
| 27 | +}; |
---|
30 | 28 | |
---|
31 | 29 | struct clk_slow_osc { |
---|
32 | 30 | struct clk_hw hw; |
---|
33 | 31 | void __iomem *sckcr; |
---|
| 32 | + const struct clk_slow_bits *bits; |
---|
34 | 33 | unsigned long startup_usec; |
---|
35 | 34 | }; |
---|
36 | 35 | |
---|
.. | .. |
---|
39 | 38 | struct clk_sama5d4_slow_osc { |
---|
40 | 39 | struct clk_hw hw; |
---|
41 | 40 | void __iomem *sckcr; |
---|
| 41 | + const struct clk_slow_bits *bits; |
---|
42 | 42 | unsigned long startup_usec; |
---|
43 | 43 | bool prepared; |
---|
44 | 44 | }; |
---|
.. | .. |
---|
48 | 48 | struct clk_slow_rc_osc { |
---|
49 | 49 | struct clk_hw hw; |
---|
50 | 50 | void __iomem *sckcr; |
---|
| 51 | + const struct clk_slow_bits *bits; |
---|
51 | 52 | unsigned long frequency; |
---|
52 | 53 | unsigned long accuracy; |
---|
53 | 54 | unsigned long startup_usec; |
---|
.. | .. |
---|
58 | 59 | struct clk_sam9x5_slow { |
---|
59 | 60 | struct clk_hw hw; |
---|
60 | 61 | void __iomem *sckcr; |
---|
| 62 | + const struct clk_slow_bits *bits; |
---|
61 | 63 | u8 parent; |
---|
62 | 64 | }; |
---|
63 | 65 | |
---|
.. | .. |
---|
69 | 71 | void __iomem *sckcr = osc->sckcr; |
---|
70 | 72 | u32 tmp = readl(sckcr); |
---|
71 | 73 | |
---|
72 | | - if (tmp & (AT91_SCKC_OSC32BYP | AT91_SCKC_OSC32EN)) |
---|
| 74 | + if (tmp & (osc->bits->cr_osc32byp | osc->bits->cr_osc32en)) |
---|
73 | 75 | return 0; |
---|
74 | 76 | |
---|
75 | | - writel(tmp | AT91_SCKC_OSC32EN, sckcr); |
---|
| 77 | + writel(tmp | osc->bits->cr_osc32en, sckcr); |
---|
76 | 78 | |
---|
77 | 79 | if (system_state < SYSTEM_RUNNING) |
---|
78 | 80 | udelay(osc->startup_usec); |
---|
.. | .. |
---|
88 | 90 | void __iomem *sckcr = osc->sckcr; |
---|
89 | 91 | u32 tmp = readl(sckcr); |
---|
90 | 92 | |
---|
91 | | - if (tmp & AT91_SCKC_OSC32BYP) |
---|
| 93 | + if (tmp & osc->bits->cr_osc32byp) |
---|
92 | 94 | return; |
---|
93 | 95 | |
---|
94 | | - writel(tmp & ~AT91_SCKC_OSC32EN, sckcr); |
---|
| 96 | + writel(tmp & ~osc->bits->cr_osc32en, sckcr); |
---|
95 | 97 | } |
---|
96 | 98 | |
---|
97 | 99 | static int clk_slow_osc_is_prepared(struct clk_hw *hw) |
---|
.. | .. |
---|
100 | 102 | void __iomem *sckcr = osc->sckcr; |
---|
101 | 103 | u32 tmp = readl(sckcr); |
---|
102 | 104 | |
---|
103 | | - if (tmp & AT91_SCKC_OSC32BYP) |
---|
| 105 | + if (tmp & osc->bits->cr_osc32byp) |
---|
104 | 106 | return 1; |
---|
105 | 107 | |
---|
106 | | - return !!(tmp & AT91_SCKC_OSC32EN); |
---|
| 108 | + return !!(tmp & osc->bits->cr_osc32en); |
---|
107 | 109 | } |
---|
108 | 110 | |
---|
109 | 111 | static const struct clk_ops slow_osc_ops = { |
---|
.. | .. |
---|
117 | 119 | const char *name, |
---|
118 | 120 | const char *parent_name, |
---|
119 | 121 | unsigned long startup, |
---|
120 | | - bool bypass) |
---|
| 122 | + bool bypass, |
---|
| 123 | + const struct clk_slow_bits *bits) |
---|
121 | 124 | { |
---|
122 | 125 | struct clk_slow_osc *osc; |
---|
123 | 126 | struct clk_hw *hw; |
---|
124 | | - struct clk_init_data init = {}; |
---|
| 127 | + struct clk_init_data init; |
---|
125 | 128 | int ret; |
---|
126 | 129 | |
---|
127 | 130 | if (!sckcr || !name || !parent_name) |
---|
.. | .. |
---|
140 | 143 | osc->hw.init = &init; |
---|
141 | 144 | osc->sckcr = sckcr; |
---|
142 | 145 | osc->startup_usec = startup; |
---|
| 146 | + osc->bits = bits; |
---|
143 | 147 | |
---|
144 | 148 | if (bypass) |
---|
145 | | - writel((readl(sckcr) & ~AT91_SCKC_OSC32EN) | AT91_SCKC_OSC32BYP, |
---|
146 | | - sckcr); |
---|
| 149 | + writel((readl(sckcr) & ~osc->bits->cr_osc32en) | |
---|
| 150 | + osc->bits->cr_osc32byp, sckcr); |
---|
147 | 151 | |
---|
148 | 152 | hw = &osc->hw; |
---|
149 | 153 | ret = clk_hw_register(NULL, &osc->hw); |
---|
.. | .. |
---|
155 | 159 | return hw; |
---|
156 | 160 | } |
---|
157 | 161 | |
---|
158 | | -static void __init |
---|
159 | | -of_at91sam9x5_clk_slow_osc_setup(struct device_node *np, void __iomem *sckcr) |
---|
| 162 | +static void at91_clk_unregister_slow_osc(struct clk_hw *hw) |
---|
160 | 163 | { |
---|
161 | | - struct clk_hw *hw; |
---|
162 | | - const char *parent_name; |
---|
163 | | - const char *name = np->name; |
---|
164 | | - u32 startup; |
---|
165 | | - bool bypass; |
---|
| 164 | + struct clk_slow_osc *osc = to_clk_slow_osc(hw); |
---|
166 | 165 | |
---|
167 | | - parent_name = of_clk_get_parent_name(np, 0); |
---|
168 | | - of_property_read_string(np, "clock-output-names", &name); |
---|
169 | | - of_property_read_u32(np, "atmel,startup-time-usec", &startup); |
---|
170 | | - bypass = of_property_read_bool(np, "atmel,osc-bypass"); |
---|
171 | | - |
---|
172 | | - hw = at91_clk_register_slow_osc(sckcr, name, parent_name, startup, |
---|
173 | | - bypass); |
---|
174 | | - if (IS_ERR(hw)) |
---|
175 | | - return; |
---|
176 | | - |
---|
177 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
| 166 | + clk_hw_unregister(hw); |
---|
| 167 | + kfree(osc); |
---|
178 | 168 | } |
---|
179 | 169 | |
---|
180 | 170 | static unsigned long clk_slow_rc_osc_recalc_rate(struct clk_hw *hw, |
---|
.. | .. |
---|
198 | 188 | struct clk_slow_rc_osc *osc = to_clk_slow_rc_osc(hw); |
---|
199 | 189 | void __iomem *sckcr = osc->sckcr; |
---|
200 | 190 | |
---|
201 | | - writel(readl(sckcr) | AT91_SCKC_RCEN, sckcr); |
---|
| 191 | + writel(readl(sckcr) | osc->bits->cr_rcen, sckcr); |
---|
202 | 192 | |
---|
203 | 193 | if (system_state < SYSTEM_RUNNING) |
---|
204 | 194 | udelay(osc->startup_usec); |
---|
.. | .. |
---|
213 | 203 | struct clk_slow_rc_osc *osc = to_clk_slow_rc_osc(hw); |
---|
214 | 204 | void __iomem *sckcr = osc->sckcr; |
---|
215 | 205 | |
---|
216 | | - writel(readl(sckcr) & ~AT91_SCKC_RCEN, sckcr); |
---|
| 206 | + writel(readl(sckcr) & ~osc->bits->cr_rcen, sckcr); |
---|
217 | 207 | } |
---|
218 | 208 | |
---|
219 | 209 | static int clk_slow_rc_osc_is_prepared(struct clk_hw *hw) |
---|
220 | 210 | { |
---|
221 | 211 | struct clk_slow_rc_osc *osc = to_clk_slow_rc_osc(hw); |
---|
222 | 212 | |
---|
223 | | - return !!(readl(osc->sckcr) & AT91_SCKC_RCEN); |
---|
| 213 | + return !!(readl(osc->sckcr) & osc->bits->cr_rcen); |
---|
224 | 214 | } |
---|
225 | 215 | |
---|
226 | 216 | static const struct clk_ops slow_rc_osc_ops = { |
---|
.. | .. |
---|
236 | 226 | const char *name, |
---|
237 | 227 | unsigned long frequency, |
---|
238 | 228 | unsigned long accuracy, |
---|
239 | | - unsigned long startup) |
---|
| 229 | + unsigned long startup, |
---|
| 230 | + const struct clk_slow_bits *bits) |
---|
240 | 231 | { |
---|
241 | 232 | struct clk_slow_rc_osc *osc; |
---|
242 | 233 | struct clk_hw *hw; |
---|
243 | | - struct clk_init_data init = {}; |
---|
| 234 | + struct clk_init_data init; |
---|
244 | 235 | int ret; |
---|
245 | 236 | |
---|
246 | 237 | if (!sckcr || !name) |
---|
.. | .. |
---|
258 | 249 | |
---|
259 | 250 | osc->hw.init = &init; |
---|
260 | 251 | osc->sckcr = sckcr; |
---|
| 252 | + osc->bits = bits; |
---|
261 | 253 | osc->frequency = frequency; |
---|
262 | 254 | osc->accuracy = accuracy; |
---|
263 | 255 | osc->startup_usec = startup; |
---|
.. | .. |
---|
272 | 264 | return hw; |
---|
273 | 265 | } |
---|
274 | 266 | |
---|
275 | | -static void __init |
---|
276 | | -of_at91sam9x5_clk_slow_rc_osc_setup(struct device_node *np, void __iomem *sckcr) |
---|
| 267 | +static void at91_clk_unregister_slow_rc_osc(struct clk_hw *hw) |
---|
277 | 268 | { |
---|
278 | | - struct clk_hw *hw; |
---|
279 | | - u32 frequency = 0; |
---|
280 | | - u32 accuracy = 0; |
---|
281 | | - u32 startup = 0; |
---|
282 | | - const char *name = np->name; |
---|
| 269 | + struct clk_slow_rc_osc *osc = to_clk_slow_rc_osc(hw); |
---|
283 | 270 | |
---|
284 | | - of_property_read_string(np, "clock-output-names", &name); |
---|
285 | | - of_property_read_u32(np, "clock-frequency", &frequency); |
---|
286 | | - of_property_read_u32(np, "clock-accuracy", &accuracy); |
---|
287 | | - of_property_read_u32(np, "atmel,startup-time-usec", &startup); |
---|
288 | | - |
---|
289 | | - hw = at91_clk_register_slow_rc_osc(sckcr, name, frequency, accuracy, |
---|
290 | | - startup); |
---|
291 | | - if (IS_ERR(hw)) |
---|
292 | | - return; |
---|
293 | | - |
---|
294 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
| 271 | + clk_hw_unregister(hw); |
---|
| 272 | + kfree(osc); |
---|
295 | 273 | } |
---|
296 | 274 | |
---|
297 | 275 | static int clk_sam9x5_slow_set_parent(struct clk_hw *hw, u8 index) |
---|
.. | .. |
---|
305 | 283 | |
---|
306 | 284 | tmp = readl(sckcr); |
---|
307 | 285 | |
---|
308 | | - if ((!index && !(tmp & AT91_SCKC_OSCSEL)) || |
---|
309 | | - (index && (tmp & AT91_SCKC_OSCSEL))) |
---|
| 286 | + if ((!index && !(tmp & slowck->bits->cr_oscsel)) || |
---|
| 287 | + (index && (tmp & slowck->bits->cr_oscsel))) |
---|
310 | 288 | return 0; |
---|
311 | 289 | |
---|
312 | 290 | if (index) |
---|
313 | | - tmp |= AT91_SCKC_OSCSEL; |
---|
| 291 | + tmp |= slowck->bits->cr_oscsel; |
---|
314 | 292 | else |
---|
315 | | - tmp &= ~AT91_SCKC_OSCSEL; |
---|
| 293 | + tmp &= ~slowck->bits->cr_oscsel; |
---|
316 | 294 | |
---|
317 | 295 | writel(tmp, sckcr); |
---|
318 | 296 | |
---|
.. | .. |
---|
328 | 306 | { |
---|
329 | 307 | struct clk_sam9x5_slow *slowck = to_clk_sam9x5_slow(hw); |
---|
330 | 308 | |
---|
331 | | - return !!(readl(slowck->sckcr) & AT91_SCKC_OSCSEL); |
---|
| 309 | + return !!(readl(slowck->sckcr) & slowck->bits->cr_oscsel); |
---|
332 | 310 | } |
---|
333 | 311 | |
---|
334 | 312 | static const struct clk_ops sam9x5_slow_ops = { |
---|
.. | .. |
---|
340 | 318 | at91_clk_register_sam9x5_slow(void __iomem *sckcr, |
---|
341 | 319 | const char *name, |
---|
342 | 320 | const char **parent_names, |
---|
343 | | - int num_parents) |
---|
| 321 | + int num_parents, |
---|
| 322 | + const struct clk_slow_bits *bits) |
---|
344 | 323 | { |
---|
345 | 324 | struct clk_sam9x5_slow *slowck; |
---|
346 | 325 | struct clk_hw *hw; |
---|
347 | | - struct clk_init_data init = {}; |
---|
| 326 | + struct clk_init_data init; |
---|
348 | 327 | int ret; |
---|
349 | 328 | |
---|
350 | 329 | if (!sckcr || !name || !parent_names || !num_parents) |
---|
.. | .. |
---|
362 | 341 | |
---|
363 | 342 | slowck->hw.init = &init; |
---|
364 | 343 | slowck->sckcr = sckcr; |
---|
365 | | - slowck->parent = !!(readl(sckcr) & AT91_SCKC_OSCSEL); |
---|
| 344 | + slowck->bits = bits; |
---|
| 345 | + slowck->parent = !!(readl(sckcr) & slowck->bits->cr_oscsel); |
---|
366 | 346 | |
---|
367 | 347 | hw = &slowck->hw; |
---|
368 | 348 | ret = clk_hw_register(NULL, &slowck->hw); |
---|
.. | .. |
---|
374 | 354 | return hw; |
---|
375 | 355 | } |
---|
376 | 356 | |
---|
377 | | -static void __init |
---|
378 | | -of_at91sam9x5_clk_slow_setup(struct device_node *np, void __iomem *sckcr) |
---|
| 357 | +static void at91_clk_unregister_sam9x5_slow(struct clk_hw *hw) |
---|
379 | 358 | { |
---|
380 | | - struct clk_hw *hw; |
---|
381 | | - const char *parent_names[2]; |
---|
382 | | - unsigned int num_parents; |
---|
383 | | - const char *name = np->name; |
---|
| 359 | + struct clk_sam9x5_slow *slowck = to_clk_sam9x5_slow(hw); |
---|
384 | 360 | |
---|
385 | | - num_parents = of_clk_get_parent_count(np); |
---|
386 | | - if (num_parents == 0 || num_parents > 2) |
---|
387 | | - return; |
---|
388 | | - |
---|
389 | | - of_clk_parent_fill(np, parent_names, num_parents); |
---|
390 | | - |
---|
391 | | - of_property_read_string(np, "clock-output-names", &name); |
---|
392 | | - |
---|
393 | | - hw = at91_clk_register_sam9x5_slow(sckcr, name, parent_names, |
---|
394 | | - num_parents); |
---|
395 | | - if (IS_ERR(hw)) |
---|
396 | | - return; |
---|
397 | | - |
---|
398 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
| 361 | + clk_hw_unregister(hw); |
---|
| 362 | + kfree(slowck); |
---|
399 | 363 | } |
---|
400 | 364 | |
---|
401 | | -static const struct of_device_id sckc_clk_ids[] __initconst = { |
---|
402 | | - /* Slow clock */ |
---|
403 | | - { |
---|
404 | | - .compatible = "atmel,at91sam9x5-clk-slow-osc", |
---|
405 | | - .data = of_at91sam9x5_clk_slow_osc_setup, |
---|
406 | | - }, |
---|
407 | | - { |
---|
408 | | - .compatible = "atmel,at91sam9x5-clk-slow-rc-osc", |
---|
409 | | - .data = of_at91sam9x5_clk_slow_rc_osc_setup, |
---|
410 | | - }, |
---|
411 | | - { |
---|
412 | | - .compatible = "atmel,at91sam9x5-clk-slow", |
---|
413 | | - .data = of_at91sam9x5_clk_slow_setup, |
---|
414 | | - }, |
---|
415 | | - { /*sentinel*/ } |
---|
416 | | -}; |
---|
417 | | - |
---|
418 | | -static void __init of_at91sam9x5_sckc_setup(struct device_node *np) |
---|
| 365 | +static void __init at91sam9x5_sckc_register(struct device_node *np, |
---|
| 366 | + unsigned int rc_osc_startup_us, |
---|
| 367 | + const struct clk_slow_bits *bits) |
---|
419 | 368 | { |
---|
420 | | - struct device_node *childnp; |
---|
421 | | - void (*clk_setup)(struct device_node *, void __iomem *); |
---|
422 | | - const struct of_device_id *clk_id; |
---|
| 369 | + const char *parent_names[2] = { "slow_rc_osc", "slow_osc" }; |
---|
423 | 370 | void __iomem *regbase = of_iomap(np, 0); |
---|
| 371 | + struct device_node *child = NULL; |
---|
| 372 | + const char *xtal_name; |
---|
| 373 | + struct clk_hw *slow_rc, *slow_osc, *slowck; |
---|
| 374 | + bool bypass; |
---|
| 375 | + int ret; |
---|
424 | 376 | |
---|
425 | 377 | if (!regbase) |
---|
426 | 378 | return; |
---|
427 | 379 | |
---|
428 | | - for_each_child_of_node(np, childnp) { |
---|
429 | | - clk_id = of_match_node(sckc_clk_ids, childnp); |
---|
430 | | - if (!clk_id) |
---|
431 | | - continue; |
---|
432 | | - clk_setup = clk_id->data; |
---|
433 | | - clk_setup(childnp, regbase); |
---|
| 380 | + slow_rc = at91_clk_register_slow_rc_osc(regbase, parent_names[0], |
---|
| 381 | + 32768, 50000000, |
---|
| 382 | + rc_osc_startup_us, bits); |
---|
| 383 | + if (IS_ERR(slow_rc)) |
---|
| 384 | + return; |
---|
| 385 | + |
---|
| 386 | + xtal_name = of_clk_get_parent_name(np, 0); |
---|
| 387 | + if (!xtal_name) { |
---|
| 388 | + /* DT backward compatibility */ |
---|
| 389 | + child = of_get_compatible_child(np, "atmel,at91sam9x5-clk-slow-osc"); |
---|
| 390 | + if (!child) |
---|
| 391 | + goto unregister_slow_rc; |
---|
| 392 | + |
---|
| 393 | + xtal_name = of_clk_get_parent_name(child, 0); |
---|
| 394 | + bypass = of_property_read_bool(child, "atmel,osc-bypass"); |
---|
| 395 | + |
---|
| 396 | + child = of_get_compatible_child(np, "atmel,at91sam9x5-clk-slow"); |
---|
| 397 | + } else { |
---|
| 398 | + bypass = of_property_read_bool(np, "atmel,osc-bypass"); |
---|
434 | 399 | } |
---|
| 400 | + |
---|
| 401 | + if (!xtal_name) |
---|
| 402 | + goto unregister_slow_rc; |
---|
| 403 | + |
---|
| 404 | + slow_osc = at91_clk_register_slow_osc(regbase, parent_names[1], |
---|
| 405 | + xtal_name, 1200000, bypass, bits); |
---|
| 406 | + if (IS_ERR(slow_osc)) |
---|
| 407 | + goto unregister_slow_rc; |
---|
| 408 | + |
---|
| 409 | + slowck = at91_clk_register_sam9x5_slow(regbase, "slowck", parent_names, |
---|
| 410 | + 2, bits); |
---|
| 411 | + if (IS_ERR(slowck)) |
---|
| 412 | + goto unregister_slow_osc; |
---|
| 413 | + |
---|
| 414 | + /* DT backward compatibility */ |
---|
| 415 | + if (child) |
---|
| 416 | + ret = of_clk_add_hw_provider(child, of_clk_hw_simple_get, |
---|
| 417 | + slowck); |
---|
| 418 | + else |
---|
| 419 | + ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, slowck); |
---|
| 420 | + |
---|
| 421 | + if (WARN_ON(ret)) |
---|
| 422 | + goto unregister_slowck; |
---|
| 423 | + |
---|
| 424 | + return; |
---|
| 425 | + |
---|
| 426 | +unregister_slowck: |
---|
| 427 | + at91_clk_unregister_sam9x5_slow(slowck); |
---|
| 428 | +unregister_slow_osc: |
---|
| 429 | + at91_clk_unregister_slow_osc(slow_osc); |
---|
| 430 | +unregister_slow_rc: |
---|
| 431 | + at91_clk_unregister_slow_rc_osc(slow_rc); |
---|
| 432 | +} |
---|
| 433 | + |
---|
| 434 | +static const struct clk_slow_bits at91sam9x5_bits = { |
---|
| 435 | + .cr_rcen = BIT(0), |
---|
| 436 | + .cr_osc32en = BIT(1), |
---|
| 437 | + .cr_osc32byp = BIT(2), |
---|
| 438 | + .cr_oscsel = BIT(3), |
---|
| 439 | +}; |
---|
| 440 | + |
---|
| 441 | +static void __init of_at91sam9x5_sckc_setup(struct device_node *np) |
---|
| 442 | +{ |
---|
| 443 | + at91sam9x5_sckc_register(np, 75, &at91sam9x5_bits); |
---|
435 | 444 | } |
---|
436 | 445 | CLK_OF_DECLARE(at91sam9x5_clk_sckc, "atmel,at91sam9x5-sckc", |
---|
437 | 446 | of_at91sam9x5_sckc_setup); |
---|
| 447 | + |
---|
| 448 | +static void __init of_sama5d3_sckc_setup(struct device_node *np) |
---|
| 449 | +{ |
---|
| 450 | + at91sam9x5_sckc_register(np, 500, &at91sam9x5_bits); |
---|
| 451 | +} |
---|
| 452 | +CLK_OF_DECLARE(sama5d3_clk_sckc, "atmel,sama5d3-sckc", |
---|
| 453 | + of_sama5d3_sckc_setup); |
---|
| 454 | + |
---|
| 455 | +static const struct clk_slow_bits at91sam9x60_bits = { |
---|
| 456 | + .cr_osc32en = BIT(1), |
---|
| 457 | + .cr_osc32byp = BIT(2), |
---|
| 458 | + .cr_oscsel = BIT(24), |
---|
| 459 | +}; |
---|
| 460 | + |
---|
| 461 | +static void __init of_sam9x60_sckc_setup(struct device_node *np) |
---|
| 462 | +{ |
---|
| 463 | + void __iomem *regbase = of_iomap(np, 0); |
---|
| 464 | + struct clk_hw_onecell_data *clk_data; |
---|
| 465 | + struct clk_hw *slow_rc, *slow_osc; |
---|
| 466 | + const char *xtal_name; |
---|
| 467 | + const char *parent_names[2] = { "slow_rc_osc", "slow_osc" }; |
---|
| 468 | + bool bypass; |
---|
| 469 | + int ret; |
---|
| 470 | + |
---|
| 471 | + if (!regbase) |
---|
| 472 | + return; |
---|
| 473 | + |
---|
| 474 | + slow_rc = clk_hw_register_fixed_rate_with_accuracy(NULL, parent_names[0], |
---|
| 475 | + NULL, 0, 32768, |
---|
| 476 | + 93750000); |
---|
| 477 | + if (IS_ERR(slow_rc)) |
---|
| 478 | + return; |
---|
| 479 | + |
---|
| 480 | + xtal_name = of_clk_get_parent_name(np, 0); |
---|
| 481 | + if (!xtal_name) |
---|
| 482 | + goto unregister_slow_rc; |
---|
| 483 | + |
---|
| 484 | + bypass = of_property_read_bool(np, "atmel,osc-bypass"); |
---|
| 485 | + slow_osc = at91_clk_register_slow_osc(regbase, parent_names[1], |
---|
| 486 | + xtal_name, 5000000, bypass, |
---|
| 487 | + &at91sam9x60_bits); |
---|
| 488 | + if (IS_ERR(slow_osc)) |
---|
| 489 | + goto unregister_slow_rc; |
---|
| 490 | + |
---|
| 491 | + clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL); |
---|
| 492 | + if (!clk_data) |
---|
| 493 | + goto unregister_slow_osc; |
---|
| 494 | + |
---|
| 495 | + /* MD_SLCK and TD_SLCK. */ |
---|
| 496 | + clk_data->num = 2; |
---|
| 497 | + clk_data->hws[0] = clk_hw_register_fixed_rate(NULL, "md_slck", |
---|
| 498 | + parent_names[0], |
---|
| 499 | + 0, 32768); |
---|
| 500 | + if (IS_ERR(clk_data->hws[0])) |
---|
| 501 | + goto clk_data_free; |
---|
| 502 | + |
---|
| 503 | + clk_data->hws[1] = at91_clk_register_sam9x5_slow(regbase, "td_slck", |
---|
| 504 | + parent_names, 2, |
---|
| 505 | + &at91sam9x60_bits); |
---|
| 506 | + if (IS_ERR(clk_data->hws[1])) |
---|
| 507 | + goto unregister_md_slck; |
---|
| 508 | + |
---|
| 509 | + ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data); |
---|
| 510 | + if (WARN_ON(ret)) |
---|
| 511 | + goto unregister_td_slck; |
---|
| 512 | + |
---|
| 513 | + return; |
---|
| 514 | + |
---|
| 515 | +unregister_td_slck: |
---|
| 516 | + at91_clk_unregister_sam9x5_slow(clk_data->hws[1]); |
---|
| 517 | +unregister_md_slck: |
---|
| 518 | + clk_hw_unregister(clk_data->hws[0]); |
---|
| 519 | +clk_data_free: |
---|
| 520 | + kfree(clk_data); |
---|
| 521 | +unregister_slow_osc: |
---|
| 522 | + at91_clk_unregister_slow_osc(slow_osc); |
---|
| 523 | +unregister_slow_rc: |
---|
| 524 | + clk_hw_unregister(slow_rc); |
---|
| 525 | +} |
---|
| 526 | +CLK_OF_DECLARE(sam9x60_clk_sckc, "microchip,sam9x60-sckc", |
---|
| 527 | + of_sam9x60_sckc_setup); |
---|
438 | 528 | |
---|
439 | 529 | static int clk_sama5d4_slow_osc_prepare(struct clk_hw *hw) |
---|
440 | 530 | { |
---|
.. | .. |
---|
447 | 537 | * Assume that if it has already been selected (for example by the |
---|
448 | 538 | * bootloader), enough time has aready passed. |
---|
449 | 539 | */ |
---|
450 | | - if ((readl(osc->sckcr) & AT91_SCKC_OSCSEL)) { |
---|
| 540 | + if ((readl(osc->sckcr) & osc->bits->cr_oscsel)) { |
---|
451 | 541 | osc->prepared = true; |
---|
452 | 542 | return 0; |
---|
453 | 543 | } |
---|
.. | .. |
---|
473 | 563 | .is_prepared = clk_sama5d4_slow_osc_is_prepared, |
---|
474 | 564 | }; |
---|
475 | 565 | |
---|
| 566 | +static const struct clk_slow_bits at91sama5d4_bits = { |
---|
| 567 | + .cr_oscsel = BIT(3), |
---|
| 568 | +}; |
---|
| 569 | + |
---|
476 | 570 | static void __init of_sama5d4_sckc_setup(struct device_node *np) |
---|
477 | 571 | { |
---|
478 | 572 | void __iomem *regbase = of_iomap(np, 0); |
---|
479 | | - struct clk_hw *hw; |
---|
| 573 | + struct clk_hw *slow_rc, *slowck; |
---|
480 | 574 | struct clk_sama5d4_slow_osc *osc; |
---|
481 | | - struct clk_init_data init = {}; |
---|
| 575 | + struct clk_init_data init; |
---|
482 | 576 | const char *xtal_name; |
---|
483 | 577 | const char *parent_names[2] = { "slow_rc_osc", "slow_osc" }; |
---|
484 | | - bool bypass; |
---|
485 | 578 | int ret; |
---|
486 | 579 | |
---|
487 | 580 | if (!regbase) |
---|
488 | 581 | return; |
---|
489 | 582 | |
---|
490 | | - hw = clk_hw_register_fixed_rate_with_accuracy(NULL, parent_names[0], |
---|
491 | | - NULL, 0, 32768, |
---|
492 | | - 250000000); |
---|
493 | | - if (IS_ERR(hw)) |
---|
| 583 | + slow_rc = clk_hw_register_fixed_rate_with_accuracy(NULL, |
---|
| 584 | + parent_names[0], |
---|
| 585 | + NULL, 0, 32768, |
---|
| 586 | + 250000000); |
---|
| 587 | + if (IS_ERR(slow_rc)) |
---|
494 | 588 | return; |
---|
495 | 589 | |
---|
496 | 590 | xtal_name = of_clk_get_parent_name(np, 0); |
---|
497 | 591 | |
---|
498 | | - bypass = of_property_read_bool(np, "atmel,osc-bypass"); |
---|
499 | | - |
---|
500 | 592 | osc = kzalloc(sizeof(*osc), GFP_KERNEL); |
---|
501 | 593 | if (!osc) |
---|
502 | | - return; |
---|
| 594 | + goto unregister_slow_rc; |
---|
503 | 595 | |
---|
504 | 596 | init.name = parent_names[1]; |
---|
505 | 597 | init.ops = &sama5d4_slow_osc_ops; |
---|
.. | .. |
---|
510 | 602 | osc->hw.init = &init; |
---|
511 | 603 | osc->sckcr = regbase; |
---|
512 | 604 | osc->startup_usec = 1200000; |
---|
| 605 | + osc->bits = &at91sama5d4_bits; |
---|
513 | 606 | |
---|
514 | | - if (bypass) |
---|
515 | | - writel((readl(regbase) | AT91_SCKC_OSC32BYP), regbase); |
---|
516 | | - |
---|
517 | | - hw = &osc->hw; |
---|
518 | 607 | ret = clk_hw_register(NULL, &osc->hw); |
---|
519 | | - if (ret) { |
---|
520 | | - kfree(osc); |
---|
521 | | - return; |
---|
522 | | - } |
---|
| 608 | + if (ret) |
---|
| 609 | + goto free_slow_osc_data; |
---|
523 | 610 | |
---|
524 | | - hw = at91_clk_register_sam9x5_slow(regbase, "slowck", parent_names, 2); |
---|
525 | | - if (IS_ERR(hw)) |
---|
526 | | - return; |
---|
| 611 | + slowck = at91_clk_register_sam9x5_slow(regbase, "slowck", |
---|
| 612 | + parent_names, 2, |
---|
| 613 | + &at91sama5d4_bits); |
---|
| 614 | + if (IS_ERR(slowck)) |
---|
| 615 | + goto unregister_slow_osc; |
---|
527 | 616 | |
---|
528 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
| 617 | + ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, slowck); |
---|
| 618 | + if (WARN_ON(ret)) |
---|
| 619 | + goto unregister_slowck; |
---|
| 620 | + |
---|
| 621 | + return; |
---|
| 622 | + |
---|
| 623 | +unregister_slowck: |
---|
| 624 | + at91_clk_unregister_sam9x5_slow(slowck); |
---|
| 625 | +unregister_slow_osc: |
---|
| 626 | + clk_hw_unregister(&osc->hw); |
---|
| 627 | +free_slow_osc_data: |
---|
| 628 | + kfree(osc); |
---|
| 629 | +unregister_slow_rc: |
---|
| 630 | + clk_hw_unregister(slow_rc); |
---|
529 | 631 | } |
---|
530 | 632 | CLK_OF_DECLARE(sama5d4_clk_sckc, "atmel,sama5d4-sckc", |
---|
531 | 633 | of_sama5d4_sckc_setup); |
---|