hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/clk/at91/clk-usb.c
....@@ -1,11 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 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
- *
94 */
105
116 #include <linux/clk-provider.h>
....@@ -17,17 +12,20 @@
1712
1813 #include "pmc.h"
1914
20
-#define USB_SOURCE_MAX 2
21
-
2215 #define SAM9X5_USB_DIV_SHIFT 8
2316 #define SAM9X5_USB_MAX_DIV 0xf
2417
2518 #define RM9200_USB_DIV_SHIFT 28
2619 #define RM9200_USB_DIV_TAB_SIZE 4
2720
21
+#define SAM9X5_USBS_MASK GENMASK(0, 0)
22
+#define SAM9X60_USBS_MASK GENMASK(1, 0)
23
+
2824 struct at91sam9x5_clk_usb {
2925 struct clk_hw hw;
3026 struct regmap *regmap;
27
+ u32 usbs_mask;
28
+ u8 num_parents;
3129 };
3230
3331 #define to_at91sam9x5_clk_usb(hw) \
....@@ -113,11 +111,10 @@
113111 {
114112 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
115113
116
- if (index > 1)
114
+ if (index >= usb->num_parents)
117115 return -EINVAL;
118116
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);
121118
122119 return 0;
123120 }
....@@ -129,7 +126,7 @@
129126
130127 regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
131128
132
- return usbr & AT91_PMC_USBS;
129
+ return usbr & usb->usbs_mask;
133130 }
134131
135132 static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
....@@ -196,12 +193,13 @@
196193 };
197194
198195 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)
201199 {
202200 struct at91sam9x5_clk_usb *usb;
203201 struct clk_hw *hw;
204
- struct clk_init_data init = {};
202
+ struct clk_init_data init;
205203 int ret;
206204
207205 usb = kzalloc(sizeof(*usb), GFP_KERNEL);
....@@ -217,6 +215,8 @@
217215
218216 usb->hw.init = &init;
219217 usb->regmap = regmap;
218
+ usb->usbs_mask = usbs_mask;
219
+ usb->num_parents = num_parents;
220220
221221 hw = &usb->hw;
222222 ret = clk_hw_register(NULL, &usb->hw);
....@@ -228,13 +228,29 @@
228228 return hw;
229229 }
230230
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
232248 at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name,
233249 const char *parent_name)
234250 {
235251 struct at91sam9x5_clk_usb *usb;
236252 struct clk_hw *hw;
237
- struct clk_init_data init = {};
253
+ struct clk_init_data init;
238254 int ret;
239255
240256 usb = kzalloc(sizeof(*usb), GFP_KERNEL);
....@@ -345,13 +361,13 @@
345361 .set_rate = at91rm9200_clk_usb_set_rate,
346362 };
347363
348
-static struct clk_hw * __init
364
+struct clk_hw * __init
349365 at91rm9200_clk_register_usb(struct regmap *regmap, const char *name,
350366 const char *parent_name, const u32 *divisors)
351367 {
352368 struct at91rm9200_clk_usb *usb;
353369 struct clk_hw *hw;
354
- struct clk_init_data init = {};
370
+ struct clk_init_data init;
355371 int ret;
356372
357373 usb = kzalloc(sizeof(*usb), GFP_KERNEL);
....@@ -377,89 +393,3 @@
377393
378394 return hw;
379395 }
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);