.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com> |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License as published by |
---|
6 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
7 | | - * (at your option) any later version. |
---|
8 | | - * |
---|
9 | 4 | */ |
---|
10 | 5 | |
---|
11 | 6 | #include <linux/clk-provider.h> |
---|
.. | .. |
---|
17 | 12 | |
---|
18 | 13 | #include "pmc.h" |
---|
19 | 14 | |
---|
20 | | -#define USB_SOURCE_MAX 2 |
---|
21 | | - |
---|
22 | 15 | #define SAM9X5_USB_DIV_SHIFT 8 |
---|
23 | 16 | #define SAM9X5_USB_MAX_DIV 0xf |
---|
24 | 17 | |
---|
25 | 18 | #define RM9200_USB_DIV_SHIFT 28 |
---|
26 | 19 | #define RM9200_USB_DIV_TAB_SIZE 4 |
---|
27 | 20 | |
---|
| 21 | +#define SAM9X5_USBS_MASK GENMASK(0, 0) |
---|
| 22 | +#define SAM9X60_USBS_MASK GENMASK(1, 0) |
---|
| 23 | + |
---|
28 | 24 | struct at91sam9x5_clk_usb { |
---|
29 | 25 | struct clk_hw hw; |
---|
30 | 26 | struct regmap *regmap; |
---|
| 27 | + u32 usbs_mask; |
---|
| 28 | + u8 num_parents; |
---|
31 | 29 | }; |
---|
32 | 30 | |
---|
33 | 31 | #define to_at91sam9x5_clk_usb(hw) \ |
---|
.. | .. |
---|
113 | 111 | { |
---|
114 | 112 | struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); |
---|
115 | 113 | |
---|
116 | | - if (index > 1) |
---|
| 114 | + if (index >= usb->num_parents) |
---|
117 | 115 | return -EINVAL; |
---|
118 | 116 | |
---|
119 | | - regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS, |
---|
120 | | - index ? AT91_PMC_USBS : 0); |
---|
| 117 | + regmap_update_bits(usb->regmap, AT91_PMC_USB, usb->usbs_mask, index); |
---|
121 | 118 | |
---|
122 | 119 | return 0; |
---|
123 | 120 | } |
---|
.. | .. |
---|
129 | 126 | |
---|
130 | 127 | regmap_read(usb->regmap, AT91_PMC_USB, &usbr); |
---|
131 | 128 | |
---|
132 | | - return usbr & AT91_PMC_USBS; |
---|
| 129 | + return usbr & usb->usbs_mask; |
---|
133 | 130 | } |
---|
134 | 131 | |
---|
135 | 132 | static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate, |
---|
.. | .. |
---|
196 | 193 | }; |
---|
197 | 194 | |
---|
198 | 195 | static struct clk_hw * __init |
---|
199 | | -at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, |
---|
200 | | - const char **parent_names, u8 num_parents) |
---|
| 196 | +_at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, |
---|
| 197 | + const char **parent_names, u8 num_parents, |
---|
| 198 | + u32 usbs_mask) |
---|
201 | 199 | { |
---|
202 | 200 | struct at91sam9x5_clk_usb *usb; |
---|
203 | 201 | struct clk_hw *hw; |
---|
204 | | - struct clk_init_data init = {}; |
---|
| 202 | + struct clk_init_data init; |
---|
205 | 203 | int ret; |
---|
206 | 204 | |
---|
207 | 205 | usb = kzalloc(sizeof(*usb), GFP_KERNEL); |
---|
.. | .. |
---|
217 | 215 | |
---|
218 | 216 | usb->hw.init = &init; |
---|
219 | 217 | usb->regmap = regmap; |
---|
| 218 | + usb->usbs_mask = usbs_mask; |
---|
| 219 | + usb->num_parents = num_parents; |
---|
220 | 220 | |
---|
221 | 221 | hw = &usb->hw; |
---|
222 | 222 | ret = clk_hw_register(NULL, &usb->hw); |
---|
.. | .. |
---|
228 | 228 | return hw; |
---|
229 | 229 | } |
---|
230 | 230 | |
---|
231 | | -static struct clk_hw * __init |
---|
| 231 | +struct clk_hw * __init |
---|
| 232 | +at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name, |
---|
| 233 | + const char **parent_names, u8 num_parents) |
---|
| 234 | +{ |
---|
| 235 | + return _at91sam9x5_clk_register_usb(regmap, name, parent_names, |
---|
| 236 | + num_parents, SAM9X5_USBS_MASK); |
---|
| 237 | +} |
---|
| 238 | + |
---|
| 239 | +struct clk_hw * __init |
---|
| 240 | +sam9x60_clk_register_usb(struct regmap *regmap, const char *name, |
---|
| 241 | + const char **parent_names, u8 num_parents) |
---|
| 242 | +{ |
---|
| 243 | + return _at91sam9x5_clk_register_usb(regmap, name, parent_names, |
---|
| 244 | + num_parents, SAM9X60_USBS_MASK); |
---|
| 245 | +} |
---|
| 246 | + |
---|
| 247 | +struct clk_hw * __init |
---|
232 | 248 | at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name, |
---|
233 | 249 | const char *parent_name) |
---|
234 | 250 | { |
---|
235 | 251 | struct at91sam9x5_clk_usb *usb; |
---|
236 | 252 | struct clk_hw *hw; |
---|
237 | | - struct clk_init_data init = {}; |
---|
| 253 | + struct clk_init_data init; |
---|
238 | 254 | int ret; |
---|
239 | 255 | |
---|
240 | 256 | usb = kzalloc(sizeof(*usb), GFP_KERNEL); |
---|
.. | .. |
---|
345 | 361 | .set_rate = at91rm9200_clk_usb_set_rate, |
---|
346 | 362 | }; |
---|
347 | 363 | |
---|
348 | | -static struct clk_hw * __init |
---|
| 364 | +struct clk_hw * __init |
---|
349 | 365 | at91rm9200_clk_register_usb(struct regmap *regmap, const char *name, |
---|
350 | 366 | const char *parent_name, const u32 *divisors) |
---|
351 | 367 | { |
---|
352 | 368 | struct at91rm9200_clk_usb *usb; |
---|
353 | 369 | struct clk_hw *hw; |
---|
354 | | - struct clk_init_data init = {}; |
---|
| 370 | + struct clk_init_data init; |
---|
355 | 371 | int ret; |
---|
356 | 372 | |
---|
357 | 373 | usb = kzalloc(sizeof(*usb), GFP_KERNEL); |
---|
.. | .. |
---|
377 | 393 | |
---|
378 | 394 | return hw; |
---|
379 | 395 | } |
---|
380 | | - |
---|
381 | | -static void __init of_at91sam9x5_clk_usb_setup(struct device_node *np) |
---|
382 | | -{ |
---|
383 | | - struct clk_hw *hw; |
---|
384 | | - unsigned int num_parents; |
---|
385 | | - const char *parent_names[USB_SOURCE_MAX]; |
---|
386 | | - const char *name = np->name; |
---|
387 | | - struct regmap *regmap; |
---|
388 | | - |
---|
389 | | - num_parents = of_clk_get_parent_count(np); |
---|
390 | | - if (num_parents == 0 || num_parents > USB_SOURCE_MAX) |
---|
391 | | - return; |
---|
392 | | - |
---|
393 | | - of_clk_parent_fill(np, parent_names, num_parents); |
---|
394 | | - |
---|
395 | | - of_property_read_string(np, "clock-output-names", &name); |
---|
396 | | - |
---|
397 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
---|
398 | | - if (IS_ERR(regmap)) |
---|
399 | | - return; |
---|
400 | | - |
---|
401 | | - hw = at91sam9x5_clk_register_usb(regmap, name, parent_names, |
---|
402 | | - num_parents); |
---|
403 | | - if (IS_ERR(hw)) |
---|
404 | | - return; |
---|
405 | | - |
---|
406 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
407 | | -} |
---|
408 | | -CLK_OF_DECLARE(at91sam9x5_clk_usb, "atmel,at91sam9x5-clk-usb", |
---|
409 | | - of_at91sam9x5_clk_usb_setup); |
---|
410 | | - |
---|
411 | | -static void __init of_at91sam9n12_clk_usb_setup(struct device_node *np) |
---|
412 | | -{ |
---|
413 | | - struct clk_hw *hw; |
---|
414 | | - const char *parent_name; |
---|
415 | | - const char *name = np->name; |
---|
416 | | - struct regmap *regmap; |
---|
417 | | - |
---|
418 | | - parent_name = of_clk_get_parent_name(np, 0); |
---|
419 | | - if (!parent_name) |
---|
420 | | - return; |
---|
421 | | - |
---|
422 | | - of_property_read_string(np, "clock-output-names", &name); |
---|
423 | | - |
---|
424 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
---|
425 | | - if (IS_ERR(regmap)) |
---|
426 | | - return; |
---|
427 | | - |
---|
428 | | - hw = at91sam9n12_clk_register_usb(regmap, name, parent_name); |
---|
429 | | - if (IS_ERR(hw)) |
---|
430 | | - return; |
---|
431 | | - |
---|
432 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
433 | | -} |
---|
434 | | -CLK_OF_DECLARE(at91sam9n12_clk_usb, "atmel,at91sam9n12-clk-usb", |
---|
435 | | - of_at91sam9n12_clk_usb_setup); |
---|
436 | | - |
---|
437 | | -static void __init of_at91rm9200_clk_usb_setup(struct device_node *np) |
---|
438 | | -{ |
---|
439 | | - struct clk_hw *hw; |
---|
440 | | - const char *parent_name; |
---|
441 | | - const char *name = np->name; |
---|
442 | | - u32 divisors[4] = {0, 0, 0, 0}; |
---|
443 | | - struct regmap *regmap; |
---|
444 | | - |
---|
445 | | - parent_name = of_clk_get_parent_name(np, 0); |
---|
446 | | - if (!parent_name) |
---|
447 | | - return; |
---|
448 | | - |
---|
449 | | - of_property_read_u32_array(np, "atmel,clk-divisors", divisors, 4); |
---|
450 | | - if (!divisors[0]) |
---|
451 | | - return; |
---|
452 | | - |
---|
453 | | - of_property_read_string(np, "clock-output-names", &name); |
---|
454 | | - |
---|
455 | | - regmap = syscon_node_to_regmap(of_get_parent(np)); |
---|
456 | | - if (IS_ERR(regmap)) |
---|
457 | | - return; |
---|
458 | | - hw = at91rm9200_clk_register_usb(regmap, name, parent_name, divisors); |
---|
459 | | - if (IS_ERR(hw)) |
---|
460 | | - return; |
---|
461 | | - |
---|
462 | | - of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw); |
---|
463 | | -} |
---|
464 | | -CLK_OF_DECLARE(at91rm9200_clk_usb, "atmel,at91rm9200-clk-usb", |
---|
465 | | - of_at91rm9200_clk_usb_setup); |
---|