2 * Copyright 2013 Emilio López
4 * Emilio López <emilio@elopez.com.ar>
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.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/clk-provider.h>
18 #include <linux/clkdev.h>
20 #include <linux/of_address.h>
22 #include "clk-factors.h"
24 static DEFINE_SPINLOCK(clk_lock);
26 /* Maximum number of parents our clocks have */
27 #define SUNXI_MAX_PARENTS 5
30 * sun4i_osc_clk_setup() - Setup function for gatable oscillator
33 #define SUNXI_OSC24M_GATE 0
35 static void __init sun4i_osc_clk_setup(struct device_node *node)
38 struct clk_fixed_rate *fixed;
39 struct clk_gate *gate;
40 const char *clk_name = node->name;
43 if (of_property_read_u32(node, "clock-frequency", &rate))
46 /* allocate fixed-rate and gate clock structs */
47 fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
50 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
54 of_property_read_string(node, "clock-output-names", &clk_name);
56 /* set up gate and fixed rate properties */
57 gate->reg = of_iomap(node, 0);
58 gate->bit_idx = SUNXI_OSC24M_GATE;
59 gate->lock = &clk_lock;
60 fixed->fixed_rate = rate;
62 clk = clk_register_composite(NULL, clk_name,
65 &fixed->hw, &clk_fixed_rate_ops,
66 &gate->hw, &clk_gate_ops,
72 of_clk_add_provider(node, of_clk_src_simple_get, clk);
73 clk_register_clkdev(clk, clk_name, NULL);
82 CLK_OF_DECLARE(sun4i_osc, "allwinner,sun4i-osc-clk", sun4i_osc_clk_setup);
87 * sun4i_get_pll1_factors() - calculates n, k, m, p factors for PLL1
88 * PLL1 rate is calculated as follows
89 * rate = (parent_rate * n * (k + 1) >> p) / (m + 1);
90 * parent_rate is always 24Mhz
93 static void sun4i_get_pll1_factors(u32 *freq, u32 parent_rate,
94 u8 *n, u8 *k, u8 *m, u8 *p)
98 /* Normalize value to a 6M multiple */
99 div = *freq / 6000000;
100 *freq = 6000000 * div;
102 /* we were called to round the frequency, we can now return */
106 /* m is always zero for pll1 */
109 /* k is 1 only on these cases */
110 if (*freq >= 768000000 || *freq == 42000000 || *freq == 54000000)
115 /* p will be 3 for divs under 10 */
119 /* p will be 2 for divs between 10 - 20 and odd divs under 32 */
120 else if (div < 20 || (div < 32 && (div & 1)))
123 /* p will be 1 for even divs under 32, divs under 40 and odd pairs
124 * of divs between 40-62 */
125 else if (div < 40 || (div < 64 && (div & 2)))
128 /* any other entries have p = 0 */
132 /* calculate a suitable n based on k and p */
139 * sun6i_a31_get_pll1_factors() - calculates n, k and m factors for PLL1
140 * PLL1 rate is calculated as follows
141 * rate = parent_rate * (n + 1) * (k + 1) / (m + 1);
142 * parent_rate should always be 24MHz
144 static void sun6i_a31_get_pll1_factors(u32 *freq, u32 parent_rate,
145 u8 *n, u8 *k, u8 *m, u8 *p)
148 * We can operate only on MHz, this will make our life easier
151 u32 freq_mhz = *freq / 1000000;
152 u32 parent_freq_mhz = parent_rate / 1000000;
155 * Round down the frequency to the closest multiple of either
158 u32 round_freq_6 = round_down(freq_mhz, 6);
159 u32 round_freq_16 = round_down(freq_mhz, 16);
161 if (round_freq_6 > round_freq_16)
162 freq_mhz = round_freq_6;
164 freq_mhz = round_freq_16;
166 *freq = freq_mhz * 1000000;
169 * If the factors pointer are null, we were just called to
170 * round down the frequency.
176 /* If the frequency is a multiple of 32 MHz, k is always 3 */
177 if (!(freq_mhz % 32))
179 /* If the frequency is a multiple of 9 MHz, k is always 2 */
180 else if (!(freq_mhz % 9))
182 /* If the frequency is a multiple of 8 MHz, k is always 1 */
183 else if (!(freq_mhz % 8))
185 /* Otherwise, we don't use the k factor */
190 * If the frequency is a multiple of 2 but not a multiple of
191 * 3, m is 3. This is the first time we use 6 here, yet we
192 * will use it on several other places.
193 * We use this number because it's the lowest frequency we can
194 * generate (with n = 0, k = 0, m = 3), so every other frequency
195 * somehow relates to this frequency.
197 if ((freq_mhz % 6) == 2 || (freq_mhz % 6) == 4)
200 * If the frequency is a multiple of 6MHz, but the factor is
203 else if ((freq_mhz / 6) & 1)
205 /* Otherwise, we end up with m = 1 */
209 /* Calculate n thanks to the above factors we already got */
210 *n = freq_mhz * (*m + 1) / ((*k + 1) * parent_freq_mhz) - 1;
213 * If n end up being outbound, and that we can still decrease
216 if ((*n + 1) > 31 && (*m + 1) > 1) {
217 *n = (*n + 1) / 2 - 1;
218 *m = (*m + 1) / 2 - 1;
223 * sun4i_get_pll5_factors() - calculates n, k factors for PLL5
224 * PLL5 rate is calculated as follows
225 * rate = parent_rate * n * (k + 1)
226 * parent_rate is always 24Mhz
229 static void sun4i_get_pll5_factors(u32 *freq, u32 parent_rate,
230 u8 *n, u8 *k, u8 *m, u8 *p)
234 /* Normalize value to a parent_rate multiple (24M) */
235 div = *freq / parent_rate;
236 *freq = parent_rate * div;
238 /* we were called to round the frequency, we can now return */
244 else if (div / 2 < 31)
246 else if (div / 3 < 31)
251 *n = DIV_ROUND_UP(div, (*k+1));
257 * sun4i_get_apb1_factors() - calculates m, p factors for APB1
258 * APB1 rate is calculated as follows
259 * rate = (parent_rate >> p) / (m + 1);
262 static void sun4i_get_apb1_factors(u32 *freq, u32 parent_rate,
263 u8 *n, u8 *k, u8 *m, u8 *p)
267 if (parent_rate < *freq)
270 parent_rate = (parent_rate + (*freq - 1)) / *freq;
273 if (parent_rate > 32)
276 if (parent_rate <= 4)
278 else if (parent_rate <= 8)
280 else if (parent_rate <= 16)
285 calcm = (parent_rate >> calcp) - 1;
287 *freq = (parent_rate >> calcp) / (calcm + 1);
289 /* we were called to round the frequency, we can now return */
300 * sun4i_get_mod0_factors() - calculates m, n factors for MOD0-style clocks
301 * MMC rate is calculated as follows
302 * rate = (parent_rate >> p) / (m + 1);
305 static void sun4i_get_mod0_factors(u32 *freq, u32 parent_rate,
306 u8 *n, u8 *k, u8 *m, u8 *p)
308 u8 div, calcm, calcp;
310 /* These clocks can only divide, so we will never be able to achieve
311 * frequencies higher than the parent frequency */
312 if (*freq > parent_rate)
315 div = parent_rate / *freq;
319 else if (div / 2 < 16)
321 else if (div / 4 < 16)
326 calcm = DIV_ROUND_UP(div, 1 << calcp);
328 *freq = (parent_rate >> calcp) / calcm;
330 /* we were called to round the frequency, we can now return */
341 * sun7i_a20_get_out_factors() - calculates m, p factors for CLK_OUT_A/B
342 * CLK_OUT rate is calculated as follows
343 * rate = (parent_rate >> p) / (m + 1);
346 static void sun7i_a20_get_out_factors(u32 *freq, u32 parent_rate,
347 u8 *n, u8 *k, u8 *m, u8 *p)
349 u8 div, calcm, calcp;
351 /* These clocks can only divide, so we will never be able to achieve
352 * frequencies higher than the parent frequency */
353 if (*freq > parent_rate)
356 div = parent_rate / *freq;
360 else if (div / 2 < 32)
362 else if (div / 4 < 32)
367 calcm = DIV_ROUND_UP(div, 1 << calcp);
369 *freq = (parent_rate >> calcp) / calcm;
371 /* we were called to round the frequency, we can now return */
382 * sunxi_factors_clk_setup() - Setup function for factor clocks
385 #define SUNXI_FACTORS_MUX_MASK 0x3
387 struct factors_data {
390 struct clk_factors_config *table;
391 void (*getter) (u32 *rate, u32 parent_rate, u8 *n, u8 *k, u8 *m, u8 *p);
395 static struct clk_factors_config sun4i_pll1_config = {
406 static struct clk_factors_config sun6i_a31_pll1_config = {
415 static struct clk_factors_config sun4i_pll5_config = {
422 static struct clk_factors_config sun4i_apb1_config = {
429 /* user manual says "n" but it's really "p" */
430 static struct clk_factors_config sun4i_mod0_config = {
437 /* user manual says "n" but it's really "p" */
438 static struct clk_factors_config sun7i_a20_out_config = {
445 static const struct factors_data sun4i_pll1_data __initconst = {
447 .table = &sun4i_pll1_config,
448 .getter = sun4i_get_pll1_factors,
451 static const struct factors_data sun6i_a31_pll1_data __initconst = {
453 .table = &sun6i_a31_pll1_config,
454 .getter = sun6i_a31_get_pll1_factors,
457 static const struct factors_data sun4i_pll5_data __initconst = {
459 .table = &sun4i_pll5_config,
460 .getter = sun4i_get_pll5_factors,
464 static const struct factors_data sun4i_pll6_data __initconst = {
466 .table = &sun4i_pll5_config,
467 .getter = sun4i_get_pll5_factors,
471 static const struct factors_data sun4i_apb1_data __initconst = {
472 .table = &sun4i_apb1_config,
473 .getter = sun4i_get_apb1_factors,
476 static const struct factors_data sun4i_mod0_data __initconst = {
479 .table = &sun4i_mod0_config,
480 .getter = sun4i_get_mod0_factors,
483 static const struct factors_data sun7i_a20_out_data __initconst = {
486 .table = &sun7i_a20_out_config,
487 .getter = sun7i_a20_get_out_factors,
490 static struct clk * __init sunxi_factors_clk_setup(struct device_node *node,
491 const struct factors_data *data)
494 struct clk_factors *factors;
495 struct clk_gate *gate = NULL;
496 struct clk_mux *mux = NULL;
497 struct clk_hw *gate_hw = NULL;
498 struct clk_hw *mux_hw = NULL;
499 const char *clk_name = node->name;
500 const char *parents[SUNXI_MAX_PARENTS];
504 reg = of_iomap(node, 0);
506 /* if we have a mux, we will have >1 parents */
507 while (i < SUNXI_MAX_PARENTS &&
508 (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
512 * some factor clocks, such as pll5 and pll6, may have multiple
513 * outputs, and have their name designated in factors_data
516 clk_name = data->name;
518 of_property_read_string(node, "clock-output-names", &clk_name);
520 factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
524 /* Add a gate if this factor clock can be gated */
526 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
532 /* set up gate properties */
534 gate->bit_idx = data->enable;
535 gate->lock = &clk_lock;
539 /* Add a mux if this factor clock can be muxed */
541 mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
548 /* set up gate properties */
550 mux->shift = data->mux;
551 mux->mask = SUNXI_FACTORS_MUX_MASK;
552 mux->lock = &clk_lock;
556 /* set up factors properties */
558 factors->config = data->table;
559 factors->get_factors = data->getter;
560 factors->lock = &clk_lock;
562 clk = clk_register_composite(NULL, clk_name,
564 mux_hw, &clk_mux_ops,
565 &factors->hw, &clk_factors_ops,
566 gate_hw, &clk_gate_ops, 0);
569 of_clk_add_provider(node, of_clk_src_simple_get, clk);
570 clk_register_clkdev(clk, clk_name, NULL);
579 * sunxi_mux_clk_setup() - Setup function for muxes
582 #define SUNXI_MUX_GATE_WIDTH 2
588 static const struct mux_data sun4i_cpu_mux_data __initconst = {
592 static const struct mux_data sun6i_a31_ahb1_mux_data __initconst = {
596 static const struct mux_data sun4i_apb1_mux_data __initconst = {
600 static void __init sunxi_mux_clk_setup(struct device_node *node,
601 struct mux_data *data)
604 const char *clk_name = node->name;
605 const char *parents[SUNXI_MAX_PARENTS];
609 reg = of_iomap(node, 0);
611 while (i < SUNXI_MAX_PARENTS &&
612 (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
615 of_property_read_string(node, "clock-output-names", &clk_name);
617 clk = clk_register_mux(NULL, clk_name, parents, i,
618 CLK_SET_RATE_NO_REPARENT, reg,
619 data->shift, SUNXI_MUX_GATE_WIDTH,
623 of_clk_add_provider(node, of_clk_src_simple_get, clk);
624 clk_register_clkdev(clk, clk_name, NULL);
631 * sunxi_divider_clk_setup() - Setup function for simple divider clocks
640 static const struct div_data sun4i_axi_data __initconst = {
646 static const struct div_data sun4i_ahb_data __initconst = {
652 static const struct div_data sun4i_apb0_data __initconst = {
658 static const struct div_data sun6i_a31_apb2_div_data __initconst = {
664 static void __init sunxi_divider_clk_setup(struct device_node *node,
665 struct div_data *data)
668 const char *clk_name = node->name;
669 const char *clk_parent;
672 reg = of_iomap(node, 0);
674 clk_parent = of_clk_get_parent_name(node, 0);
676 of_property_read_string(node, "clock-output-names", &clk_name);
678 clk = clk_register_divider(NULL, clk_name, clk_parent, 0,
679 reg, data->shift, data->width,
680 data->pow ? CLK_DIVIDER_POWER_OF_TWO : 0,
683 of_clk_add_provider(node, of_clk_src_simple_get, clk);
684 clk_register_clkdev(clk, clk_name, NULL);
691 * sunxi_gates_clk_setup() - Setup function for leaf gates on clocks
694 #define SUNXI_GATES_MAX_SIZE 64
697 DECLARE_BITMAP(mask, SUNXI_GATES_MAX_SIZE);
700 static const struct gates_data sun4i_axi_gates_data __initconst = {
704 static const struct gates_data sun4i_ahb_gates_data __initconst = {
705 .mask = {0x7F77FFF, 0x14FB3F},
708 static const struct gates_data sun5i_a10s_ahb_gates_data __initconst = {
709 .mask = {0x147667e7, 0x185915},
712 static const struct gates_data sun5i_a13_ahb_gates_data __initconst = {
713 .mask = {0x107067e7, 0x185111},
716 static const struct gates_data sun6i_a31_ahb1_gates_data __initconst = {
717 .mask = {0xEDFE7F62, 0x794F931},
720 static const struct gates_data sun7i_a20_ahb_gates_data __initconst = {
721 .mask = { 0x12f77fff, 0x16ff3f },
724 static const struct gates_data sun4i_apb0_gates_data __initconst = {
728 static const struct gates_data sun5i_a10s_apb0_gates_data __initconst = {
732 static const struct gates_data sun5i_a13_apb0_gates_data __initconst = {
736 static const struct gates_data sun7i_a20_apb0_gates_data __initconst = {
740 static const struct gates_data sun4i_apb1_gates_data __initconst = {
744 static const struct gates_data sun5i_a10s_apb1_gates_data __initconst = {
748 static const struct gates_data sun5i_a13_apb1_gates_data __initconst = {
752 static const struct gates_data sun6i_a31_apb1_gates_data __initconst = {
756 static const struct gates_data sun6i_a31_apb2_gates_data __initconst = {
760 static const struct gates_data sun7i_a20_apb1_gates_data __initconst = {
761 .mask = { 0xff80ff },
764 static void __init sunxi_gates_clk_setup(struct device_node *node,
765 struct gates_data *data)
767 struct clk_onecell_data *clk_data;
768 const char *clk_parent;
769 const char *clk_name;
776 reg = of_iomap(node, 0);
778 clk_parent = of_clk_get_parent_name(node, 0);
780 /* Worst-case size approximation and memory allocation */
781 qty = find_last_bit(data->mask, SUNXI_GATES_MAX_SIZE);
782 clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
785 clk_data->clks = kzalloc((qty+1) * sizeof(struct clk *), GFP_KERNEL);
786 if (!clk_data->clks) {
791 for_each_set_bit(i, data->mask, SUNXI_GATES_MAX_SIZE) {
792 of_property_read_string_index(node, "clock-output-names",
795 /* No driver claims this clock, but it should remain gated */
796 ignore = !strcmp("ahb_sdram", clk_name) ? CLK_IGNORE_UNUSED : 0;
798 clk_data->clks[i] = clk_register_gate(NULL, clk_name,
800 reg + 4 * (i/32), i % 32,
802 WARN_ON(IS_ERR(clk_data->clks[i]));
807 /* Adjust to the real max */
808 clk_data->clk_num = i;
810 of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
816 * sunxi_divs_clk_setup() helper data
819 #define SUNXI_DIVS_MAX_QTY 2
820 #define SUNXI_DIVISOR_WIDTH 2
823 const struct factors_data *factors; /* data for the factor clock */
825 u8 fixed; /* is it a fixed divisor? if not... */
826 struct clk_div_table *table; /* is it a table based divisor? */
827 u8 shift; /* otherwise it's a normal divisor with this shift */
828 u8 pow; /* is it power-of-two based? */
829 u8 gate; /* is it independently gateable? */
830 } div[SUNXI_DIVS_MAX_QTY];
833 static struct clk_div_table pll6_sata_tbl[] = {
834 { .val = 0, .div = 6, },
835 { .val = 1, .div = 12, },
836 { .val = 2, .div = 18, },
837 { .val = 3, .div = 24, },
841 static const struct divs_data pll5_divs_data __initconst = {
842 .factors = &sun4i_pll5_data,
844 { .shift = 0, .pow = 0, }, /* M, DDR */
845 { .shift = 16, .pow = 1, }, /* P, other */
849 static const struct divs_data pll6_divs_data __initconst = {
850 .factors = &sun4i_pll6_data,
852 { .shift = 0, .table = pll6_sata_tbl, .gate = 14 }, /* M, SATA */
853 { .fixed = 2 }, /* P, other */
858 * sunxi_divs_clk_setup() - Setup function for leaf divisors on clocks
860 * These clocks look something like this
861 * ________________________
862 * | ___divisor 1---|----> to consumer
863 * parent >--| pll___/___divisor 2---|----> to consumer
864 * | \_______________|____> to consumer
865 * |________________________|
868 static void __init sunxi_divs_clk_setup(struct device_node *node,
869 struct divs_data *data)
871 struct clk_onecell_data *clk_data;
873 const char *clk_name;
874 struct clk **clks, *pclk;
875 struct clk_hw *gate_hw, *rate_hw;
876 const struct clk_ops *rate_ops;
877 struct clk_gate *gate = NULL;
878 struct clk_fixed_factor *fix_factor;
879 struct clk_divider *divider;
884 /* Set up factor clock that we will be dividing */
885 pclk = sunxi_factors_clk_setup(node, data->factors);
886 parent = __clk_get_name(pclk);
888 reg = of_iomap(node, 0);
890 clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
894 clks = kzalloc((SUNXI_DIVS_MAX_QTY+1) * sizeof(*clks), GFP_KERNEL);
898 clk_data->clks = clks;
900 /* It's not a good idea to have automatic reparenting changing
902 clkflags = !strcmp("pll5", parent) ? 0 : CLK_SET_RATE_PARENT;
904 for (i = 0; i < SUNXI_DIVS_MAX_QTY; i++) {
905 if (of_property_read_string_index(node, "clock-output-names",
913 /* If this leaf clock can be gated, create a gate */
914 if (data->div[i].gate) {
915 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
920 gate->bit_idx = data->div[i].gate;
921 gate->lock = &clk_lock;
926 /* Leaves can be fixed or configurable divisors */
927 if (data->div[i].fixed) {
928 fix_factor = kzalloc(sizeof(*fix_factor), GFP_KERNEL);
932 fix_factor->mult = 1;
933 fix_factor->div = data->div[i].fixed;
935 rate_hw = &fix_factor->hw;
936 rate_ops = &clk_fixed_factor_ops;
938 divider = kzalloc(sizeof(*divider), GFP_KERNEL);
942 flags = data->div[i].pow ? CLK_DIVIDER_POWER_OF_TWO : 0;
945 divider->shift = data->div[i].shift;
946 divider->width = SUNXI_DIVISOR_WIDTH;
947 divider->flags = flags;
948 divider->lock = &clk_lock;
949 divider->table = data->div[i].table;
951 rate_hw = ÷r->hw;
952 rate_ops = &clk_divider_ops;
955 /* Wrap the (potential) gate and the divisor on a composite
956 * clock to unify them */
957 clks[i] = clk_register_composite(NULL, clk_name, &parent, 1,
960 gate_hw, &clk_gate_ops,
963 WARN_ON(IS_ERR(clk_data->clks[i]));
964 clk_register_clkdev(clks[i], clk_name, NULL);
967 /* The last clock available on the getter is the parent */
970 /* Adjust to the real max */
971 clk_data->clk_num = i;
973 of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
987 /* Matches for factors clocks */
988 static const struct of_device_id clk_factors_match[] __initconst = {
989 {.compatible = "allwinner,sun4i-pll1-clk", .data = &sun4i_pll1_data,},
990 {.compatible = "allwinner,sun6i-a31-pll1-clk", .data = &sun6i_a31_pll1_data,},
991 {.compatible = "allwinner,sun4i-apb1-clk", .data = &sun4i_apb1_data,},
992 {.compatible = "allwinner,sun4i-mod0-clk", .data = &sun4i_mod0_data,},
993 {.compatible = "allwinner,sun7i-a20-out-clk", .data = &sun7i_a20_out_data,},
997 /* Matches for divider clocks */
998 static const struct of_device_id clk_div_match[] __initconst = {
999 {.compatible = "allwinner,sun4i-axi-clk", .data = &sun4i_axi_data,},
1000 {.compatible = "allwinner,sun4i-ahb-clk", .data = &sun4i_ahb_data,},
1001 {.compatible = "allwinner,sun4i-apb0-clk", .data = &sun4i_apb0_data,},
1002 {.compatible = "allwinner,sun6i-a31-apb2-div-clk", .data = &sun6i_a31_apb2_div_data,},
1006 /* Matches for divided outputs */
1007 static const struct of_device_id clk_divs_match[] __initconst = {
1008 {.compatible = "allwinner,sun4i-pll5-clk", .data = &pll5_divs_data,},
1009 {.compatible = "allwinner,sun4i-pll6-clk", .data = &pll6_divs_data,},
1013 /* Matches for mux clocks */
1014 static const struct of_device_id clk_mux_match[] __initconst = {
1015 {.compatible = "allwinner,sun4i-cpu-clk", .data = &sun4i_cpu_mux_data,},
1016 {.compatible = "allwinner,sun4i-apb1-mux-clk", .data = &sun4i_apb1_mux_data,},
1017 {.compatible = "allwinner,sun6i-a31-ahb1-mux-clk", .data = &sun6i_a31_ahb1_mux_data,},
1021 /* Matches for gate clocks */
1022 static const struct of_device_id clk_gates_match[] __initconst = {
1023 {.compatible = "allwinner,sun4i-axi-gates-clk", .data = &sun4i_axi_gates_data,},
1024 {.compatible = "allwinner,sun4i-ahb-gates-clk", .data = &sun4i_ahb_gates_data,},
1025 {.compatible = "allwinner,sun5i-a10s-ahb-gates-clk", .data = &sun5i_a10s_ahb_gates_data,},
1026 {.compatible = "allwinner,sun5i-a13-ahb-gates-clk", .data = &sun5i_a13_ahb_gates_data,},
1027 {.compatible = "allwinner,sun6i-a31-ahb1-gates-clk", .data = &sun6i_a31_ahb1_gates_data,},
1028 {.compatible = "allwinner,sun7i-a20-ahb-gates-clk", .data = &sun7i_a20_ahb_gates_data,},
1029 {.compatible = "allwinner,sun4i-apb0-gates-clk", .data = &sun4i_apb0_gates_data,},
1030 {.compatible = "allwinner,sun5i-a10s-apb0-gates-clk", .data = &sun5i_a10s_apb0_gates_data,},
1031 {.compatible = "allwinner,sun5i-a13-apb0-gates-clk", .data = &sun5i_a13_apb0_gates_data,},
1032 {.compatible = "allwinner,sun7i-a20-apb0-gates-clk", .data = &sun7i_a20_apb0_gates_data,},
1033 {.compatible = "allwinner,sun4i-apb1-gates-clk", .data = &sun4i_apb1_gates_data,},
1034 {.compatible = "allwinner,sun5i-a10s-apb1-gates-clk", .data = &sun5i_a10s_apb1_gates_data,},
1035 {.compatible = "allwinner,sun5i-a13-apb1-gates-clk", .data = &sun5i_a13_apb1_gates_data,},
1036 {.compatible = "allwinner,sun6i-a31-apb1-gates-clk", .data = &sun6i_a31_apb1_gates_data,},
1037 {.compatible = "allwinner,sun7i-a20-apb1-gates-clk", .data = &sun7i_a20_apb1_gates_data,},
1038 {.compatible = "allwinner,sun6i-a31-apb2-gates-clk", .data = &sun6i_a31_apb2_gates_data,},
1042 static void __init of_sunxi_table_clock_setup(const struct of_device_id *clk_match,
1045 struct device_node *np;
1046 const struct div_data *data;
1047 const struct of_device_id *match;
1048 void (*setup_function)(struct device_node *, const void *) = function;
1050 for_each_matching_node(np, clk_match) {
1051 match = of_match_node(clk_match, np);
1053 setup_function(np, data);
1058 * System clock protection
1060 * By enabling these critical clocks, we prevent their accidental gating
1063 static void __init sunxi_clock_protect(void)
1067 /* memory bus clock - sun5i+ */
1068 clk = clk_get(NULL, "mbus");
1070 clk_prepare_enable(clk);
1074 /* DDR clock - sun4i+ */
1075 clk = clk_get(NULL, "pll5_ddr");
1077 clk_prepare_enable(clk);
1082 static void __init sunxi_init_clocks(void)
1084 /* Register factor clocks */
1085 of_sunxi_table_clock_setup(clk_factors_match, sunxi_factors_clk_setup);
1087 /* Register divider clocks */
1088 of_sunxi_table_clock_setup(clk_div_match, sunxi_divider_clk_setup);
1090 /* Register divided output clocks */
1091 of_sunxi_table_clock_setup(clk_divs_match, sunxi_divs_clk_setup);
1093 /* Register mux clocks */
1094 of_sunxi_table_clock_setup(clk_mux_match, sunxi_mux_clk_setup);
1096 /* Register gate clocks */
1097 of_sunxi_table_clock_setup(clk_gates_match, sunxi_gates_clk_setup);
1099 /* Enable core system clocks */
1100 sunxi_clock_protect();
1102 CLK_OF_DECLARE(sun4i_a10_clk_init, "allwinner,sun4i-a10", sunxi_init_clocks);
1103 CLK_OF_DECLARE(sun5i_a10s_clk_init, "allwinner,sun5i-a10s", sunxi_init_clocks);
1104 CLK_OF_DECLARE(sun5i_a13_clk_init, "allwinner,sun5i-a13", sunxi_init_clocks);
1105 CLK_OF_DECLARE(sun6i_a31_clk_init, "allwinner,sun6i-a31", sunxi_init_clocks);
1106 CLK_OF_DECLARE(sun7i_a20_clk_init, "allwinner,sun7i-a20", sunxi_init_clocks);