1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/clk-provider.h>
3 #include <linux/clk/at91_pmc.h>
5 #include <linux/mfd/syscon.h>
6 #include <linux/regmap.h>
7 #include <linux/slab.h>
11 #define MASTER_SOURCE_MAX 4
13 #define PERIPHERAL_AT91RM9200 0
14 #define PERIPHERAL_AT91SAM9X5 1
16 #define PERIPHERAL_MAX 64
18 #define PERIPHERAL_ID_MIN 2
20 #define PROG_SOURCE_MAX 5
23 #define SYSTEM_MAX_ID 31
25 #define GCK_INDEX_DT_AUDIO_PLL 5
27 #ifdef CONFIG_HAVE_AT91_AUDIO_PLL
28 static void __init of_sama5d2_clk_audio_pll_frac_setup(struct device_node *np)
31 const char *name = np->name;
32 const char *parent_name;
33 struct regmap *regmap;
35 regmap = syscon_node_to_regmap(of_get_parent(np));
39 parent_name = of_clk_get_parent_name(np, 0);
41 hw = at91_clk_register_audio_pll_frac(regmap, name, parent_name);
45 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
47 CLK_OF_DECLARE(of_sama5d2_clk_audio_pll_frac_setup,
48 "atmel,sama5d2-clk-audio-pll-frac",
49 of_sama5d2_clk_audio_pll_frac_setup);
51 static void __init of_sama5d2_clk_audio_pll_pad_setup(struct device_node *np)
54 const char *name = np->name;
55 const char *parent_name;
56 struct regmap *regmap;
58 regmap = syscon_node_to_regmap(of_get_parent(np));
62 parent_name = of_clk_get_parent_name(np, 0);
64 hw = at91_clk_register_audio_pll_pad(regmap, name, parent_name);
68 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
70 CLK_OF_DECLARE(of_sama5d2_clk_audio_pll_pad_setup,
71 "atmel,sama5d2-clk-audio-pll-pad",
72 of_sama5d2_clk_audio_pll_pad_setup);
74 static void __init of_sama5d2_clk_audio_pll_pmc_setup(struct device_node *np)
77 const char *name = np->name;
78 const char *parent_name;
79 struct regmap *regmap;
81 regmap = syscon_node_to_regmap(of_get_parent(np));
85 parent_name = of_clk_get_parent_name(np, 0);
87 hw = at91_clk_register_audio_pll_pmc(regmap, name, parent_name);
91 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
93 CLK_OF_DECLARE(of_sama5d2_clk_audio_pll_pmc_setup,
94 "atmel,sama5d2-clk-audio-pll-pmc",
95 of_sama5d2_clk_audio_pll_pmc_setup);
96 #endif /* CONFIG_HAVE_AT91_AUDIO_PLL */
98 static const struct clk_pcr_layout dt_pcr_layout = {
101 .pid_mask = GENMASK(5, 0),
102 .div_mask = GENMASK(17, 16),
103 .gckcss_mask = GENMASK(10, 8),
106 #ifdef CONFIG_HAVE_AT91_GENERATED_CLK
107 #define GENERATED_SOURCE_MAX 6
109 #define GCK_ID_I2S0 54
110 #define GCK_ID_I2S1 55
111 #define GCK_ID_CLASSD 59
113 static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
119 unsigned int num_parents;
120 const char *parent_names[GENERATED_SOURCE_MAX];
121 struct device_node *gcknp;
122 struct clk_range range = CLK_RANGE(0, 0);
123 struct regmap *regmap;
125 num_parents = of_clk_get_parent_count(np);
126 if (num_parents == 0 || num_parents > GENERATED_SOURCE_MAX)
129 of_clk_parent_fill(np, parent_names, num_parents);
131 num = of_get_child_count(np);
132 if (!num || num > PERIPHERAL_MAX)
135 regmap = syscon_node_to_regmap(of_get_parent(np));
139 for_each_child_of_node(np, gcknp) {
140 int chg_pid = INT_MIN;
142 if (of_property_read_u32(gcknp, "reg", &id))
145 if (id < PERIPHERAL_ID_MIN || id >= PERIPHERAL_MAX)
148 if (of_property_read_string(np, "clock-output-names", &name))
151 of_at91_get_clk_range(gcknp, "atmel,clk-output-range",
154 if (of_device_is_compatible(np, "atmel,sama5d2-clk-generated") &&
155 (id == GCK_ID_I2S0 || id == GCK_ID_I2S1 ||
156 id == GCK_ID_CLASSD))
157 chg_pid = GCK_INDEX_DT_AUDIO_PLL;
159 hw = at91_clk_register_generated(regmap, &pmc_pcr_lock,
160 &dt_pcr_layout, name,
162 num_parents, id, &range,
167 of_clk_add_hw_provider(gcknp, of_clk_hw_simple_get, hw);
170 CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated",
171 of_sama5d2_clk_generated_setup);
172 #endif /* CONFIG_HAVE_AT91_GENERATED_CLK */
174 #ifdef CONFIG_HAVE_AT91_H32MX
175 static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
178 const char *name = np->name;
179 const char *parent_name;
180 struct regmap *regmap;
182 regmap = syscon_node_to_regmap(of_get_parent(np));
186 parent_name = of_clk_get_parent_name(np, 0);
188 hw = at91_clk_register_h32mx(regmap, name, parent_name);
192 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
194 CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx",
195 of_sama5d4_clk_h32mx_setup);
196 #endif /* CONFIG_HAVE_AT91_H32MX */
198 #ifdef CONFIG_HAVE_AT91_I2S_MUX_CLK
201 static void __init of_sama5d2_clk_i2s_mux_setup(struct device_node *np)
203 struct regmap *regmap_sfr;
205 const char *parent_names[2];
206 struct device_node *i2s_mux_np;
210 regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
211 if (IS_ERR(regmap_sfr))
214 for_each_child_of_node(np, i2s_mux_np) {
215 if (of_property_read_u8(i2s_mux_np, "reg", &bus_id))
218 if (bus_id > I2S_BUS_NR)
221 ret = of_clk_parent_fill(i2s_mux_np, parent_names, 2);
225 hw = at91_clk_i2s_mux_register(regmap_sfr, i2s_mux_np->name,
226 parent_names, 2, bus_id);
230 of_clk_add_hw_provider(i2s_mux_np, of_clk_hw_simple_get, hw);
233 CLK_OF_DECLARE(sama5d2_clk_i2s_mux, "atmel,sama5d2-clk-i2s-mux",
234 of_sama5d2_clk_i2s_mux_setup);
235 #endif /* CONFIG_HAVE_AT91_I2S_MUX_CLK */
237 static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
240 const char *name = np->name;
241 const char *parent_name;
242 struct regmap *regmap;
245 of_property_read_string(np, "clock-output-names", &name);
246 bypass = of_property_read_bool(np, "atmel,osc-bypass");
247 parent_name = of_clk_get_parent_name(np, 0);
249 regmap = syscon_node_to_regmap(of_get_parent(np));
253 hw = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
257 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
259 CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc",
260 of_at91rm9200_clk_main_osc_setup);
262 static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
267 const char *name = np->name;
268 struct regmap *regmap;
270 of_property_read_string(np, "clock-output-names", &name);
271 of_property_read_u32(np, "clock-frequency", &frequency);
272 of_property_read_u32(np, "clock-accuracy", &accuracy);
274 regmap = syscon_node_to_regmap(of_get_parent(np));
278 hw = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
282 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
284 CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc",
285 of_at91sam9x5_clk_main_rc_osc_setup);
287 static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
290 const char *parent_name;
291 const char *name = np->name;
292 struct regmap *regmap;
294 parent_name = of_clk_get_parent_name(np, 0);
295 of_property_read_string(np, "clock-output-names", &name);
297 regmap = syscon_node_to_regmap(of_get_parent(np));
301 hw = at91_clk_register_rm9200_main(regmap, name, parent_name);
305 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
307 CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main",
308 of_at91rm9200_clk_main_setup);
310 static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)
313 const char *parent_names[2];
314 unsigned int num_parents;
315 const char *name = np->name;
316 struct regmap *regmap;
318 num_parents = of_clk_get_parent_count(np);
319 if (num_parents == 0 || num_parents > 2)
322 of_clk_parent_fill(np, parent_names, num_parents);
323 regmap = syscon_node_to_regmap(of_get_parent(np));
327 of_property_read_string(np, "clock-output-names", &name);
329 hw = at91_clk_register_sam9x5_main(regmap, name, parent_names,
334 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
336 CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main",
337 of_at91sam9x5_clk_main_setup);
339 static struct clk_master_characteristics * __init
340 of_at91_clk_master_get_characteristics(struct device_node *np)
342 struct clk_master_characteristics *characteristics;
344 characteristics = kzalloc(sizeof(*characteristics), GFP_KERNEL);
345 if (!characteristics)
348 if (of_at91_get_clk_range(np, "atmel,clk-output-range", &characteristics->output))
349 goto out_free_characteristics;
351 of_property_read_u32_array(np, "atmel,clk-divisors",
352 characteristics->divisors, 4);
354 characteristics->have_div3_pres =
355 of_property_read_bool(np, "atmel,master-clk-have-div3-pres");
357 return characteristics;
359 out_free_characteristics:
360 kfree(characteristics);
365 of_at91_clk_master_setup(struct device_node *np,
366 const struct clk_master_layout *layout)
369 unsigned int num_parents;
370 const char *parent_names[MASTER_SOURCE_MAX];
371 const char *name = np->name;
372 struct clk_master_characteristics *characteristics;
373 struct regmap *regmap;
375 num_parents = of_clk_get_parent_count(np);
376 if (num_parents == 0 || num_parents > MASTER_SOURCE_MAX)
379 of_clk_parent_fill(np, parent_names, num_parents);
381 of_property_read_string(np, "clock-output-names", &name);
383 characteristics = of_at91_clk_master_get_characteristics(np);
384 if (!characteristics)
387 regmap = syscon_node_to_regmap(of_get_parent(np));
391 hw = at91_clk_register_master(regmap, name, num_parents,
392 parent_names, layout,
395 goto out_free_characteristics;
397 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
400 out_free_characteristics:
401 kfree(characteristics);
404 static void __init of_at91rm9200_clk_master_setup(struct device_node *np)
406 of_at91_clk_master_setup(np, &at91rm9200_master_layout);
408 CLK_OF_DECLARE(at91rm9200_clk_master, "atmel,at91rm9200-clk-master",
409 of_at91rm9200_clk_master_setup);
411 static void __init of_at91sam9x5_clk_master_setup(struct device_node *np)
413 of_at91_clk_master_setup(np, &at91sam9x5_master_layout);
415 CLK_OF_DECLARE(at91sam9x5_clk_master, "atmel,at91sam9x5-clk-master",
416 of_at91sam9x5_clk_master_setup);
419 of_at91_clk_periph_setup(struct device_node *np, u8 type)
424 const char *parent_name;
426 struct device_node *periphclknp;
427 struct regmap *regmap;
429 parent_name = of_clk_get_parent_name(np, 0);
433 num = of_get_child_count(np);
434 if (!num || num > PERIPHERAL_MAX)
437 regmap = syscon_node_to_regmap(of_get_parent(np));
441 for_each_child_of_node(np, periphclknp) {
442 if (of_property_read_u32(periphclknp, "reg", &id))
445 if (id >= PERIPHERAL_MAX)
448 if (of_property_read_string(np, "clock-output-names", &name))
449 name = periphclknp->name;
451 if (type == PERIPHERAL_AT91RM9200) {
452 hw = at91_clk_register_peripheral(regmap, name,
455 struct clk_range range = CLK_RANGE(0, 0);
457 of_at91_get_clk_range(periphclknp,
458 "atmel,clk-output-range",
461 hw = at91_clk_register_sam9x5_peripheral(regmap,
473 of_clk_add_hw_provider(periphclknp, of_clk_hw_simple_get, hw);
477 static void __init of_at91rm9200_clk_periph_setup(struct device_node *np)
479 of_at91_clk_periph_setup(np, PERIPHERAL_AT91RM9200);
481 CLK_OF_DECLARE(at91rm9200_clk_periph, "atmel,at91rm9200-clk-peripheral",
482 of_at91rm9200_clk_periph_setup);
484 static void __init of_at91sam9x5_clk_periph_setup(struct device_node *np)
486 of_at91_clk_periph_setup(np, PERIPHERAL_AT91SAM9X5);
488 CLK_OF_DECLARE(at91sam9x5_clk_periph, "atmel,at91sam9x5-clk-peripheral",
489 of_at91sam9x5_clk_periph_setup);
491 static struct clk_pll_characteristics * __init
492 of_at91_clk_pll_get_characteristics(struct device_node *np)
499 struct clk_range input;
500 struct clk_range *output;
503 struct clk_pll_characteristics *characteristics;
505 if (of_at91_get_clk_range(np, "atmel,clk-input-range", &input))
508 if (of_property_read_u32(np, "#atmel,pll-clk-output-range-cells",
512 if (num_cells < 2 || num_cells > 4)
515 if (!of_get_property(np, "atmel,pll-clk-output-ranges", &tmp))
517 num_output = tmp / (sizeof(u32) * num_cells);
519 characteristics = kzalloc(sizeof(*characteristics), GFP_KERNEL);
520 if (!characteristics)
523 output = kcalloc(num_output, sizeof(*output), GFP_KERNEL);
525 goto out_free_characteristics;
528 out = kcalloc(num_output, sizeof(*out), GFP_KERNEL);
530 goto out_free_output;
534 icpll = kcalloc(num_output, sizeof(*icpll), GFP_KERNEL);
536 goto out_free_output;
539 for (i = 0; i < num_output; i++) {
540 offset = i * num_cells;
541 if (of_property_read_u32_index(np,
542 "atmel,pll-clk-output-ranges",
544 goto out_free_output;
546 if (of_property_read_u32_index(np,
547 "atmel,pll-clk-output-ranges",
549 goto out_free_output;
555 if (of_property_read_u32_index(np,
556 "atmel,pll-clk-output-ranges",
558 goto out_free_output;
564 if (of_property_read_u32_index(np,
565 "atmel,pll-clk-output-ranges",
567 goto out_free_output;
571 characteristics->input = input;
572 characteristics->num_output = num_output;
573 characteristics->output = output;
574 characteristics->out = out;
575 characteristics->icpll = icpll;
576 return characteristics;
582 out_free_characteristics:
583 kfree(characteristics);
588 of_at91_clk_pll_setup(struct device_node *np,
589 const struct clk_pll_layout *layout)
593 struct regmap *regmap;
594 const char *parent_name;
595 const char *name = np->name;
596 struct clk_pll_characteristics *characteristics;
598 if (of_property_read_u32(np, "reg", &id))
601 parent_name = of_clk_get_parent_name(np, 0);
603 of_property_read_string(np, "clock-output-names", &name);
605 regmap = syscon_node_to_regmap(of_get_parent(np));
609 characteristics = of_at91_clk_pll_get_characteristics(np);
610 if (!characteristics)
613 hw = at91_clk_register_pll(regmap, name, parent_name, id, layout,
616 goto out_free_characteristics;
618 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
621 out_free_characteristics:
622 kfree(characteristics);
625 static void __init of_at91rm9200_clk_pll_setup(struct device_node *np)
627 of_at91_clk_pll_setup(np, &at91rm9200_pll_layout);
629 CLK_OF_DECLARE(at91rm9200_clk_pll, "atmel,at91rm9200-clk-pll",
630 of_at91rm9200_clk_pll_setup);
632 static void __init of_at91sam9g45_clk_pll_setup(struct device_node *np)
634 of_at91_clk_pll_setup(np, &at91sam9g45_pll_layout);
636 CLK_OF_DECLARE(at91sam9g45_clk_pll, "atmel,at91sam9g45-clk-pll",
637 of_at91sam9g45_clk_pll_setup);
639 static void __init of_at91sam9g20_clk_pllb_setup(struct device_node *np)
641 of_at91_clk_pll_setup(np, &at91sam9g20_pllb_layout);
643 CLK_OF_DECLARE(at91sam9g20_clk_pllb, "atmel,at91sam9g20-clk-pllb",
644 of_at91sam9g20_clk_pllb_setup);
646 static void __init of_sama5d3_clk_pll_setup(struct device_node *np)
648 of_at91_clk_pll_setup(np, &sama5d3_pll_layout);
650 CLK_OF_DECLARE(sama5d3_clk_pll, "atmel,sama5d3-clk-pll",
651 of_sama5d3_clk_pll_setup);
654 of_at91sam9x5_clk_plldiv_setup(struct device_node *np)
657 const char *parent_name;
658 const char *name = np->name;
659 struct regmap *regmap;
661 parent_name = of_clk_get_parent_name(np, 0);
663 of_property_read_string(np, "clock-output-names", &name);
665 regmap = syscon_node_to_regmap(of_get_parent(np));
669 hw = at91_clk_register_plldiv(regmap, name, parent_name);
673 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
675 CLK_OF_DECLARE(at91sam9x5_clk_plldiv, "atmel,at91sam9x5-clk-plldiv",
676 of_at91sam9x5_clk_plldiv_setup);
679 of_at91_clk_prog_setup(struct device_node *np,
680 const struct clk_programmable_layout *layout,
686 unsigned int num_parents;
687 const char *parent_names[PROG_SOURCE_MAX];
689 struct device_node *progclknp;
690 struct regmap *regmap;
692 num_parents = of_clk_get_parent_count(np);
693 if (num_parents == 0 || num_parents > PROG_SOURCE_MAX)
696 of_clk_parent_fill(np, parent_names, num_parents);
698 num = of_get_child_count(np);
699 if (!num || num > (PROG_ID_MAX + 1))
702 regmap = syscon_node_to_regmap(of_get_parent(np));
706 for_each_child_of_node(np, progclknp) {
707 if (of_property_read_u32(progclknp, "reg", &id))
710 if (of_property_read_string(np, "clock-output-names", &name))
711 name = progclknp->name;
713 hw = at91_clk_register_programmable(regmap, name,
714 parent_names, num_parents,
715 id, layout, mux_table);
719 of_clk_add_hw_provider(progclknp, of_clk_hw_simple_get, hw);
723 static void __init of_at91rm9200_clk_prog_setup(struct device_node *np)
725 of_at91_clk_prog_setup(np, &at91rm9200_programmable_layout, NULL);
727 CLK_OF_DECLARE(at91rm9200_clk_prog, "atmel,at91rm9200-clk-programmable",
728 of_at91rm9200_clk_prog_setup);
730 static void __init of_at91sam9g45_clk_prog_setup(struct device_node *np)
732 of_at91_clk_prog_setup(np, &at91sam9g45_programmable_layout, NULL);
734 CLK_OF_DECLARE(at91sam9g45_clk_prog, "atmel,at91sam9g45-clk-programmable",
735 of_at91sam9g45_clk_prog_setup);
737 static void __init of_at91sam9x5_clk_prog_setup(struct device_node *np)
739 of_at91_clk_prog_setup(np, &at91sam9x5_programmable_layout, NULL);
741 CLK_OF_DECLARE(at91sam9x5_clk_prog, "atmel,at91sam9x5-clk-programmable",
742 of_at91sam9x5_clk_prog_setup);
744 static void __init of_at91sam9260_clk_slow_setup(struct device_node *np)
747 const char *parent_names[2];
748 unsigned int num_parents;
749 const char *name = np->name;
750 struct regmap *regmap;
752 num_parents = of_clk_get_parent_count(np);
753 if (num_parents != 2)
756 of_clk_parent_fill(np, parent_names, num_parents);
757 regmap = syscon_node_to_regmap(of_get_parent(np));
761 of_property_read_string(np, "clock-output-names", &name);
763 hw = at91_clk_register_sam9260_slow(regmap, name, parent_names,
768 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
770 CLK_OF_DECLARE(at91sam9260_clk_slow, "atmel,at91sam9260-clk-slow",
771 of_at91sam9260_clk_slow_setup);
773 #ifdef CONFIG_HAVE_AT91_SMD
774 #define SMD_SOURCE_MAX 2
776 static void __init of_at91sam9x5_clk_smd_setup(struct device_node *np)
779 unsigned int num_parents;
780 const char *parent_names[SMD_SOURCE_MAX];
781 const char *name = np->name;
782 struct regmap *regmap;
784 num_parents = of_clk_get_parent_count(np);
785 if (num_parents == 0 || num_parents > SMD_SOURCE_MAX)
788 of_clk_parent_fill(np, parent_names, num_parents);
790 of_property_read_string(np, "clock-output-names", &name);
792 regmap = syscon_node_to_regmap(of_get_parent(np));
796 hw = at91sam9x5_clk_register_smd(regmap, name, parent_names,
801 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
803 CLK_OF_DECLARE(at91sam9x5_clk_smd, "atmel,at91sam9x5-clk-smd",
804 of_at91sam9x5_clk_smd_setup);
805 #endif /* CONFIG_HAVE_AT91_SMD */
807 static void __init of_at91rm9200_clk_sys_setup(struct device_node *np)
813 struct device_node *sysclknp;
814 const char *parent_name;
815 struct regmap *regmap;
817 num = of_get_child_count(np);
818 if (num > (SYSTEM_MAX_ID + 1))
821 regmap = syscon_node_to_regmap(of_get_parent(np));
825 for_each_child_of_node(np, sysclknp) {
826 if (of_property_read_u32(sysclknp, "reg", &id))
829 if (of_property_read_string(np, "clock-output-names", &name))
830 name = sysclknp->name;
832 parent_name = of_clk_get_parent_name(sysclknp, 0);
834 hw = at91_clk_register_system(regmap, name, parent_name, id);
838 of_clk_add_hw_provider(sysclknp, of_clk_hw_simple_get, hw);
841 CLK_OF_DECLARE(at91rm9200_clk_sys, "atmel,at91rm9200-clk-system",
842 of_at91rm9200_clk_sys_setup);
844 #ifdef CONFIG_HAVE_AT91_USB_CLK
845 #define USB_SOURCE_MAX 2
847 static void __init of_at91sam9x5_clk_usb_setup(struct device_node *np)
850 unsigned int num_parents;
851 const char *parent_names[USB_SOURCE_MAX];
852 const char *name = np->name;
853 struct regmap *regmap;
855 num_parents = of_clk_get_parent_count(np);
856 if (num_parents == 0 || num_parents > USB_SOURCE_MAX)
859 of_clk_parent_fill(np, parent_names, num_parents);
861 of_property_read_string(np, "clock-output-names", &name);
863 regmap = syscon_node_to_regmap(of_get_parent(np));
867 hw = at91sam9x5_clk_register_usb(regmap, name, parent_names,
872 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
874 CLK_OF_DECLARE(at91sam9x5_clk_usb, "atmel,at91sam9x5-clk-usb",
875 of_at91sam9x5_clk_usb_setup);
877 static void __init of_at91sam9n12_clk_usb_setup(struct device_node *np)
880 const char *parent_name;
881 const char *name = np->name;
882 struct regmap *regmap;
884 parent_name = of_clk_get_parent_name(np, 0);
888 of_property_read_string(np, "clock-output-names", &name);
890 regmap = syscon_node_to_regmap(of_get_parent(np));
894 hw = at91sam9n12_clk_register_usb(regmap, name, parent_name);
898 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
900 CLK_OF_DECLARE(at91sam9n12_clk_usb, "atmel,at91sam9n12-clk-usb",
901 of_at91sam9n12_clk_usb_setup);
903 static void __init of_at91rm9200_clk_usb_setup(struct device_node *np)
906 const char *parent_name;
907 const char *name = np->name;
908 u32 divisors[4] = {0, 0, 0, 0};
909 struct regmap *regmap;
911 parent_name = of_clk_get_parent_name(np, 0);
915 of_property_read_u32_array(np, "atmel,clk-divisors", divisors, 4);
919 of_property_read_string(np, "clock-output-names", &name);
921 regmap = syscon_node_to_regmap(of_get_parent(np));
924 hw = at91rm9200_clk_register_usb(regmap, name, parent_name, divisors);
928 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
930 CLK_OF_DECLARE(at91rm9200_clk_usb, "atmel,at91rm9200-clk-usb",
931 of_at91rm9200_clk_usb_setup);
932 #endif /* CONFIG_HAVE_AT91_USB_CLK */
934 #ifdef CONFIG_HAVE_AT91_UTMI
935 static void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np)
938 const char *parent_name;
939 const char *name = np->name;
940 struct regmap *regmap_pmc, *regmap_sfr;
942 parent_name = of_clk_get_parent_name(np, 0);
944 of_property_read_string(np, "clock-output-names", &name);
946 regmap_pmc = syscon_node_to_regmap(of_get_parent(np));
947 if (IS_ERR(regmap_pmc))
951 * If the device supports different mainck rates, this value has to be
952 * set in the UTMI Clock Trimming register.
953 * - 9x5: mainck supports several rates but it is indicated that a
954 * 12 MHz is needed in case of USB.
955 * - sama5d3 and sama5d2: mainck supports several rates. Configuring
956 * the FREQ field of the UTMI Clock Trimming register is mandatory.
957 * - sama5d4: mainck is at 12 MHz.
959 * We only need to retrieve sama5d3 or sama5d2 sfr regmap.
961 regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d3-sfr");
962 if (IS_ERR(regmap_sfr)) {
963 regmap_sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
964 if (IS_ERR(regmap_sfr))
968 hw = at91_clk_register_utmi(regmap_pmc, regmap_sfr, name, parent_name);
972 of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
974 CLK_OF_DECLARE(at91sam9x5_clk_utmi, "atmel,at91sam9x5-clk-utmi",
975 of_at91sam9x5_clk_utmi_setup);
976 #endif /* CONFIG_HAVE_AT91_UTMI */