Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'sunxi-clocks-for-4.6' of https://git.kernel.org/pub/scm/linux/kernel/git/mripard/linux into clk-next

Pull Allwinner clk updates from Maxime Ripard:

Allwinner clocks additions for 4.6

A bunch of things, mostly:
- Finally switched everything over to OF_CLK_DECLARE, which should remove
orphans clocks entirely
- Reworked the clk-factors to be able to add new parameters
- Improved the error reporting
- A bunch of new clocks for new SoCs.

* tag 'sunxi-clocks-for-4.6' of https://git.kernel.org/pub/scm/linux/kernel/git/mripard/linux: (25 commits)
clk: sunxi: Add apb0 gates for H3
clk: sunxi: Improve divs_clk error handling and reporting
clk: sunxi: improve divider_clk error handling and reporting
clk: sunxi: improve mux_clk error handling and reporting
clk: sunxi: Fix sun8i-a23-apb0-clk divider flags
clk: sunxi: Remove clk_register_clkdev calls
clk: sunxi: Remove old probe and protection code
clk: sunxi: convert current clocks registration to CLK_OF_DECLARE
clk: sunxi: Make clocks setup functions take const pointer
clk: sunxi: Make clocks setup functions return their clock
clk: sunxi: improve error reporting for the mux clock
clk: sunxi: don't mark sun6i_ar100_data __initconst
clk: sunxi: add bus gates for A83T
clk: sunxi: Add apb0 gates for A83T
clk: sunxi: rewrite sun8i-a23-mbus-clk using the simpler composite clk
clk: sunxi: rewrite sun6i-ar100 using factors clk
clk: sunxi: rewrite sun6i-a31-ahb1-clk using factors clk with custom recalc
clk: sunxi: factors: Drop round_rate from clk ops
clk: sunxi: factors: Support custom formulas
clk: sunxi: factors: Consolidate get_factors parameters into a struct
...

+844 -989
+4
Documentation/devicetree/bindings/clock/sunxi.txt
··· 18 18 "allwinner,sun4i-a10-cpu-clk" - for the CPU multiplexer clock 19 19 "allwinner,sun4i-a10-axi-clk" - for the AXI clock 20 20 "allwinner,sun8i-a23-axi-clk" - for the AXI clock on A23 21 + "allwinner,sun4i-a10-gates-clk" - for generic gates on all compatible SoCs 21 22 "allwinner,sun4i-a10-axi-gates-clk" - for the AXI gates 22 23 "allwinner,sun4i-a10-ahb-clk" - for the AHB clock 23 24 "allwinner,sun5i-a13-ahb-clk" - for the AHB clock on A13 ··· 40 39 "allwinner,sun6i-a31-apb0-clk" - for the APB0 clock on A31 41 40 "allwinner,sun8i-a23-apb0-clk" - for the APB0 clock on A23 42 41 "allwinner,sun9i-a80-apb0-clk" - for the APB0 bus clock on A80 42 + "allwinner,sun8i-a83t-apb0-gates-clk" - for the APB0 gates on A83T 43 43 "allwinner,sun4i-a10-apb0-gates-clk" - for the APB0 gates on A10 44 44 "allwinner,sun5i-a13-apb0-gates-clk" - for the APB0 gates on A13 45 45 "allwinner,sun5i-a10s-apb0-gates-clk" - for the APB0 gates on A10s 46 46 "allwinner,sun6i-a31-apb0-gates-clk" - for the APB0 gates on A31 47 47 "allwinner,sun7i-a20-apb0-gates-clk" - for the APB0 gates on A20 48 48 "allwinner,sun8i-a23-apb0-gates-clk" - for the APB0 gates on A23 49 + "allwinner,sun8i-h3-apb0-gates-clk" - for the APB0 gates on H3 49 50 "allwinner,sun9i-a80-apb0-gates-clk" - for the APB0 gates on A80 50 51 "allwinner,sun4i-a10-apb1-clk" - for the APB1 clock 51 52 "allwinner,sun9i-a80-apb1-clk" - for the APB1 bus clock on A80 ··· 60 57 "allwinner,sun9i-a80-apb1-gates-clk" - for the APB1 gates on A80 61 58 "allwinner,sun6i-a31-apb2-gates-clk" - for the APB2 gates on A31 62 59 "allwinner,sun8i-a23-apb2-gates-clk" - for the APB2 gates on A23 60 + "allwinner,sun8i-a83t-bus-gates-clk" - for the bus gates on A83T 63 61 "allwinner,sun8i-h3-bus-gates-clk" - for the bus gates on H3 64 62 "allwinner,sun9i-a80-apbs-gates-clk" - for the APBS gates on A80 65 63 "allwinner,sun4i-a10-dram-gates-clk" - for the DRAM gates on A10
+1 -2
drivers/clk/sunxi/clk-a10-hosc.c
··· 15 15 */ 16 16 17 17 #include <linux/clk-provider.h> 18 - #include <linux/clkdev.h> 19 18 #include <linux/of.h> 20 19 #include <linux/of_address.h> 20 + #include <linux/slab.h> 21 21 22 22 #define SUNXI_OSC24M_GATE 0 23 23 ··· 61 61 goto err_free_gate; 62 62 63 63 of_clk_add_provider(node, of_clk_src_simple_get, clk); 64 - clk_register_clkdev(clk, clk_name, NULL); 65 64 66 65 return; 67 66
-2
drivers/clk/sunxi/clk-a20-gmac.c
··· 17 17 */ 18 18 19 19 #include <linux/clk-provider.h> 20 - #include <linux/clkdev.h> 21 20 #include <linux/of.h> 22 21 #include <linux/of_address.h> 23 22 #include <linux/slab.h> ··· 106 107 goto iounmap_reg; 107 108 108 109 of_clk_add_provider(node, of_clk_src_simple_get, clk); 109 - clk_register_clkdev(clk, clk_name, NULL); 110 110 111 111 return; 112 112
+87 -36
drivers/clk/sunxi/clk-factors.c
··· 48 48 u32 reg; 49 49 unsigned long rate; 50 50 struct clk_factors *factors = to_clk_factors(hw); 51 - struct clk_factors_config *config = factors->config; 51 + const struct clk_factors_config *config = factors->config; 52 52 53 53 /* Fetch the register value */ 54 54 reg = readl(factors->reg); ··· 63 63 if (config->pwidth != SUNXI_FACTORS_NOT_APPLICABLE) 64 64 p = FACTOR_GET(config->pshift, config->pwidth, reg); 65 65 66 + if (factors->recalc) { 67 + struct factors_request factors_req = { 68 + .parent_rate = parent_rate, 69 + .n = n, 70 + .k = k, 71 + .m = m, 72 + .p = p, 73 + }; 74 + 75 + /* get mux details from mux clk structure */ 76 + if (factors->mux) 77 + factors_req.parent_index = 78 + (reg >> factors->mux->shift) & 79 + factors->mux->mask; 80 + 81 + factors->recalc(&factors_req); 82 + 83 + return factors_req.rate; 84 + } 85 + 66 86 /* Calculate the rate */ 67 87 rate = (parent_rate * (n + config->n_start) * (k + 1) >> p) / (m + 1); 68 - 69 - return rate; 70 - } 71 - 72 - static long clk_factors_round_rate(struct clk_hw *hw, unsigned long rate, 73 - unsigned long *parent_rate) 74 - { 75 - struct clk_factors *factors = to_clk_factors(hw); 76 - factors->get_factors((u32 *)&rate, (u32)*parent_rate, 77 - NULL, NULL, NULL, NULL); 78 88 79 89 return rate; 80 90 } ··· 92 82 static int clk_factors_determine_rate(struct clk_hw *hw, 93 83 struct clk_rate_request *req) 94 84 { 85 + struct clk_factors *factors = to_clk_factors(hw); 95 86 struct clk_hw *parent, *best_parent = NULL; 96 87 int i, num_parents; 97 88 unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0; ··· 100 89 /* find the parent that can help provide the fastest rate <= rate */ 101 90 num_parents = clk_hw_get_num_parents(hw); 102 91 for (i = 0; i < num_parents; i++) { 92 + struct factors_request factors_req = { 93 + .rate = req->rate, 94 + .parent_index = i, 95 + }; 103 96 parent = clk_hw_get_parent_by_index(hw, i); 104 97 if (!parent) 105 98 continue; ··· 112 97 else 113 98 parent_rate = clk_hw_get_rate(parent); 114 99 115 - child_rate = clk_factors_round_rate(hw, req->rate, 116 - &parent_rate); 100 + factors_req.parent_rate = parent_rate; 101 + factors->get_factors(&factors_req); 102 + child_rate = factors_req.rate; 117 103 118 104 if (child_rate <= req->rate && child_rate > best_child_rate) { 119 105 best_parent = parent; ··· 136 120 static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate, 137 121 unsigned long parent_rate) 138 122 { 139 - u8 n = 0, k = 0, m = 0, p = 0; 123 + struct factors_request req = { 124 + .rate = rate, 125 + .parent_rate = parent_rate, 126 + }; 140 127 u32 reg; 141 128 struct clk_factors *factors = to_clk_factors(hw); 142 - struct clk_factors_config *config = factors->config; 129 + const struct clk_factors_config *config = factors->config; 143 130 unsigned long flags = 0; 144 131 145 - factors->get_factors((u32 *)&rate, (u32)parent_rate, &n, &k, &m, &p); 132 + factors->get_factors(&req); 146 133 147 134 if (factors->lock) 148 135 spin_lock_irqsave(factors->lock, flags); ··· 154 135 reg = readl(factors->reg); 155 136 156 137 /* Set up the new factors - macros do not do anything if width is 0 */ 157 - reg = FACTOR_SET(config->nshift, config->nwidth, reg, n); 158 - reg = FACTOR_SET(config->kshift, config->kwidth, reg, k); 159 - reg = FACTOR_SET(config->mshift, config->mwidth, reg, m); 160 - reg = FACTOR_SET(config->pshift, config->pwidth, reg, p); 138 + reg = FACTOR_SET(config->nshift, config->nwidth, reg, req.n); 139 + reg = FACTOR_SET(config->kshift, config->kwidth, reg, req.k); 140 + reg = FACTOR_SET(config->mshift, config->mwidth, reg, req.m); 141 + reg = FACTOR_SET(config->pshift, config->pwidth, reg, req.p); 161 142 162 143 /* Apply them now */ 163 144 writel(reg, factors->reg); ··· 174 155 static const struct clk_ops clk_factors_ops = { 175 156 .determine_rate = clk_factors_determine_rate, 176 157 .recalc_rate = clk_factors_recalc_rate, 177 - .round_rate = clk_factors_round_rate, 178 158 .set_rate = clk_factors_set_rate, 179 159 }; 180 160 ··· 190 172 struct clk_hw *mux_hw = NULL; 191 173 const char *clk_name = node->name; 192 174 const char *parents[FACTORS_MAX_PARENTS]; 193 - int i = 0; 175 + int ret, i = 0; 194 176 195 177 /* if we have a mux, we will have >1 parents */ 196 178 i = of_clk_parent_fill(node, parents, FACTORS_MAX_PARENTS); ··· 206 188 207 189 factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL); 208 190 if (!factors) 209 - return NULL; 191 + goto err_factors; 210 192 211 193 /* set up factors properties */ 212 194 factors->reg = reg; 213 195 factors->config = data->table; 214 196 factors->get_factors = data->getter; 197 + factors->recalc = data->recalc; 215 198 factors->lock = lock; 216 199 217 200 /* Add a gate if this factor clock can be gated */ 218 201 if (data->enable) { 219 202 gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL); 220 - if (!gate) { 221 - kfree(factors); 222 - return NULL; 223 - } 203 + if (!gate) 204 + goto err_gate; 205 + 206 + factors->gate = gate; 224 207 225 208 /* set up gate properties */ 226 209 gate->reg = reg; ··· 233 214 /* Add a mux if this factor clock can be muxed */ 234 215 if (data->mux) { 235 216 mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL); 236 - if (!mux) { 237 - kfree(factors); 238 - kfree(gate); 239 - return NULL; 240 - } 217 + if (!mux) 218 + goto err_mux; 219 + 220 + factors->mux = mux; 241 221 242 222 /* set up gate properties */ 243 223 mux->reg = reg; ··· 251 233 mux_hw, &clk_mux_ops, 252 234 &factors->hw, &clk_factors_ops, 253 235 gate_hw, &clk_gate_ops, 0); 236 + if (IS_ERR(clk)) 237 + goto err_register; 254 238 255 - if (!IS_ERR(clk)) { 256 - of_clk_add_provider(node, of_clk_src_simple_get, clk); 257 - clk_register_clkdev(clk, clk_name, NULL); 258 - } 239 + ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); 240 + if (ret) 241 + goto err_provider; 259 242 260 243 return clk; 244 + 245 + err_provider: 246 + /* TODO: The composite clock stuff will leak a bit here. */ 247 + clk_unregister(clk); 248 + err_register: 249 + kfree(mux); 250 + err_mux: 251 + kfree(gate); 252 + err_gate: 253 + kfree(factors); 254 + err_factors: 255 + return NULL; 256 + } 257 + 258 + void sunxi_factors_unregister(struct device_node *node, struct clk *clk) 259 + { 260 + struct clk_hw *hw = __clk_get_hw(clk); 261 + struct clk_factors *factors; 262 + const char *name; 263 + 264 + if (!hw) 265 + return; 266 + 267 + factors = to_clk_factors(hw); 268 + name = clk_hw_get_name(hw); 269 + 270 + of_clk_del_provider(node); 271 + /* TODO: The composite clock stuff will leak a bit here. */ 272 + clk_unregister(clk); 273 + kfree(factors->mux); 274 + kfree(factors->gate); 275 + kfree(factors); 261 276 }
+21 -5
drivers/clk/sunxi/clk-factors.h
··· 2 2 #define __MACH_SUNXI_CLK_FACTORS_H 3 3 4 4 #include <linux/clk-provider.h> 5 - #include <linux/clkdev.h> 6 5 #include <linux/spinlock.h> 7 6 8 7 #define SUNXI_FACTORS_NOT_APPLICABLE (0) ··· 18 19 u8 n_start; 19 20 }; 20 21 22 + struct factors_request { 23 + unsigned long rate; 24 + unsigned long parent_rate; 25 + u8 parent_index; 26 + u8 n; 27 + u8 k; 28 + u8 m; 29 + u8 p; 30 + }; 31 + 21 32 struct factors_data { 22 33 int enable; 23 34 int mux; 24 35 int muxmask; 25 - struct clk_factors_config *table; 26 - void (*getter) (u32 *rate, u32 parent_rate, u8 *n, u8 *k, u8 *m, u8 *p); 36 + const struct clk_factors_config *table; 37 + void (*getter)(struct factors_request *req); 38 + void (*recalc)(struct factors_request *req); 27 39 const char *name; 28 40 }; 29 41 30 42 struct clk_factors { 31 43 struct clk_hw hw; 32 44 void __iomem *reg; 33 - struct clk_factors_config *config; 34 - void (*get_factors) (u32 *rate, u32 parent, u8 *n, u8 *k, u8 *m, u8 *p); 45 + const struct clk_factors_config *config; 46 + void (*get_factors)(struct factors_request *req); 47 + void (*recalc)(struct factors_request *req); 35 48 spinlock_t *lock; 49 + /* for cleanup */ 50 + struct clk_mux *mux; 51 + struct clk_gate *gate; 36 52 }; 37 53 38 54 struct clk *sunxi_factors_register(struct device_node *node, 39 55 const struct factors_data *data, 40 56 spinlock_t *lock, 41 57 void __iomem *reg); 58 + 59 + void sunxi_factors_unregister(struct device_node *node, struct clk *clk); 42 60 43 61 #endif
+9 -14
drivers/clk/sunxi/clk-mod0.c
··· 15 15 */ 16 16 17 17 #include <linux/clk.h> 18 + #include <linux/clkdev.h> 18 19 #include <linux/clk-provider.h> 19 20 #include <linux/of_address.h> 20 21 #include <linux/platform_device.h> ··· 29 28 * rate = (parent_rate >> p) / (m + 1); 30 29 */ 31 30 32 - static void sun4i_a10_get_mod0_factors(u32 *freq, u32 parent_rate, 33 - u8 *n, u8 *k, u8 *m, u8 *p) 31 + static void sun4i_a10_get_mod0_factors(struct factors_request *req) 34 32 { 35 33 u8 div, calcm, calcp; 36 34 37 35 /* These clocks can only divide, so we will never be able to achieve 38 36 * frequencies higher than the parent frequency */ 39 - if (*freq > parent_rate) 40 - *freq = parent_rate; 37 + if (req->rate > req->parent_rate) 38 + req->rate = req->parent_rate; 41 39 42 - div = DIV_ROUND_UP(parent_rate, *freq); 40 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 43 41 44 42 if (div < 16) 45 43 calcp = 0; ··· 51 51 52 52 calcm = DIV_ROUND_UP(div, 1 << calcp); 53 53 54 - *freq = (parent_rate >> calcp) / calcm; 55 - 56 - /* we were called to round the frequency, we can now return */ 57 - if (n == NULL) 58 - return; 59 - 60 - *m = calcm - 1; 61 - *p = calcp; 54 + req->rate = (req->parent_rate >> calcp) / calcm; 55 + req->m = calcm - 1; 56 + req->p = calcp; 62 57 } 63 58 64 59 /* user manual says "n" but it's really "p" */ 65 - static struct clk_factors_config sun4i_a10_mod0_config = { 60 + static const struct clk_factors_config sun4i_a10_mod0_config = { 66 61 .mshift = 0, 67 62 .mwidth = 4, 68 63 .pshift = 16,
+4
drivers/clk/sunxi/clk-simple-gates.c
··· 98 98 sunxi_simple_gates_setup(node, NULL, 0); 99 99 } 100 100 101 + CLK_OF_DECLARE(sun4i_a10_gates, "allwinner,sun4i-a10-gates-clk", 102 + sunxi_simple_gates_init); 101 103 CLK_OF_DECLARE(sun4i_a10_apb0, "allwinner,sun4i-a10-apb0-gates-clk", 102 104 sunxi_simple_gates_init); 103 105 CLK_OF_DECLARE(sun4i_a10_apb1, "allwinner,sun4i-a10-apb1-gates-clk", ··· 131 129 CLK_OF_DECLARE(sun8i_a23_apb2, "allwinner,sun8i-a23-apb2-gates-clk", 132 130 sunxi_simple_gates_init); 133 131 CLK_OF_DECLARE(sun8i_a33_ahb1, "allwinner,sun8i-a33-ahb1-gates-clk", 132 + sunxi_simple_gates_init); 133 + CLK_OF_DECLARE(sun8i_a83t_apb0, "allwinner,sun8i-a83t-apb0-gates-clk", 134 134 sunxi_simple_gates_init); 135 135 CLK_OF_DECLARE(sun9i_a80_ahb0, "allwinner,sun9i-a80-ahb0-gates-clk", 136 136 sunxi_simple_gates_init);
-2
drivers/clk/sunxi/clk-sun6i-apb0-gates.c
··· 9 9 */ 10 10 11 11 #include <linux/clk-provider.h> 12 - #include <linux/clkdev.h> 13 12 #include <linux/module.h> 14 13 #include <linux/of.h> 15 14 #include <linux/of_device.h> ··· 86 87 clk_parent, 0, reg, i, 87 88 0, NULL); 88 89 WARN_ON(IS_ERR(clk_data->clks[i])); 89 - clk_register_clkdev(clk_data->clks[i], clk_name, NULL); 90 90 91 91 j++; 92 92 }
+70 -183
drivers/clk/sunxi/clk-sun6i-ar100.c
··· 8 8 * 9 9 */ 10 10 11 + #include <linux/bitops.h> 11 12 #include <linux/clk-provider.h> 12 13 #include <linux/module.h> 13 14 #include <linux/of.h> 14 15 #include <linux/platform_device.h> 16 + #include <linux/spinlock.h> 15 17 16 - #define SUN6I_AR100_MAX_PARENTS 4 17 - #define SUN6I_AR100_SHIFT_MASK 0x3 18 - #define SUN6I_AR100_SHIFT_MAX SUN6I_AR100_SHIFT_MASK 19 - #define SUN6I_AR100_SHIFT_SHIFT 4 20 - #define SUN6I_AR100_DIV_MASK 0x1f 21 - #define SUN6I_AR100_DIV_MAX (SUN6I_AR100_DIV_MASK + 1) 22 - #define SUN6I_AR100_DIV_SHIFT 8 23 - #define SUN6I_AR100_MUX_MASK 0x3 24 - #define SUN6I_AR100_MUX_SHIFT 16 18 + #include "clk-factors.h" 25 19 26 - struct ar100_clk { 27 - struct clk_hw hw; 28 - void __iomem *reg; 29 - }; 30 - 31 - static inline struct ar100_clk *to_ar100_clk(struct clk_hw *hw) 20 + /** 21 + * sun6i_get_ar100_factors - Calculates factors p, m for AR100 22 + * 23 + * AR100 rate is calculated as follows 24 + * rate = (parent_rate >> p) / (m + 1); 25 + */ 26 + static void sun6i_get_ar100_factors(struct factors_request *req) 32 27 { 33 - return container_of(hw, struct ar100_clk, hw); 34 - } 35 - 36 - static unsigned long ar100_recalc_rate(struct clk_hw *hw, 37 - unsigned long parent_rate) 38 - { 39 - struct ar100_clk *clk = to_ar100_clk(hw); 40 - u32 val = readl(clk->reg); 41 - int shift = (val >> SUN6I_AR100_SHIFT_SHIFT) & SUN6I_AR100_SHIFT_MASK; 42 - int div = (val >> SUN6I_AR100_DIV_SHIFT) & SUN6I_AR100_DIV_MASK; 43 - 44 - return (parent_rate >> shift) / (div + 1); 45 - } 46 - 47 - static int ar100_determine_rate(struct clk_hw *hw, 48 - struct clk_rate_request *req) 49 - { 50 - int nparents = clk_hw_get_num_parents(hw); 51 - long best_rate = -EINVAL; 52 - int i; 53 - 54 - req->best_parent_hw = NULL; 55 - 56 - for (i = 0; i < nparents; i++) { 57 - unsigned long parent_rate; 58 - unsigned long tmp_rate; 59 - struct clk_hw *parent; 60 - unsigned long div; 61 - int shift; 62 - 63 - parent = clk_hw_get_parent_by_index(hw, i); 64 - parent_rate = clk_hw_get_rate(parent); 65 - div = DIV_ROUND_UP(parent_rate, req->rate); 66 - 67 - /* 68 - * The AR100 clk contains 2 divisors: 69 - * - one power of 2 divisor 70 - * - one regular divisor 71 - * 72 - * First check if we can safely shift (or divide by a power 73 - * of 2) without losing precision on the requested rate. 74 - */ 75 - shift = ffs(div) - 1; 76 - if (shift > SUN6I_AR100_SHIFT_MAX) 77 - shift = SUN6I_AR100_SHIFT_MAX; 78 - 79 - div >>= shift; 80 - 81 - /* 82 - * Then if the divisor is still bigger than what the HW 83 - * actually supports, use a bigger shift (or power of 2 84 - * divider) value and accept to lose some precision. 85 - */ 86 - while (div > SUN6I_AR100_DIV_MAX) { 87 - shift++; 88 - div >>= 1; 89 - if (shift > SUN6I_AR100_SHIFT_MAX) 90 - break; 91 - } 92 - 93 - /* 94 - * If the shift value (or power of 2 divider) is bigger 95 - * than what the HW actually support, skip this parent. 96 - */ 97 - if (shift > SUN6I_AR100_SHIFT_MAX) 98 - continue; 99 - 100 - tmp_rate = (parent_rate >> shift) / div; 101 - if (!req->best_parent_hw || tmp_rate > best_rate) { 102 - req->best_parent_hw = parent; 103 - req->best_parent_rate = parent_rate; 104 - best_rate = tmp_rate; 105 - } 106 - } 107 - 108 - if (best_rate < 0) 109 - return best_rate; 110 - 111 - req->rate = best_rate; 112 - 113 - return 0; 114 - } 115 - 116 - static int ar100_set_parent(struct clk_hw *hw, u8 index) 117 - { 118 - struct ar100_clk *clk = to_ar100_clk(hw); 119 - u32 val = readl(clk->reg); 120 - 121 - if (index >= SUN6I_AR100_MAX_PARENTS) 122 - return -EINVAL; 123 - 124 - val &= ~(SUN6I_AR100_MUX_MASK << SUN6I_AR100_MUX_SHIFT); 125 - val |= (index << SUN6I_AR100_MUX_SHIFT); 126 - writel(val, clk->reg); 127 - 128 - return 0; 129 - } 130 - 131 - static u8 ar100_get_parent(struct clk_hw *hw) 132 - { 133 - struct ar100_clk *clk = to_ar100_clk(hw); 134 - return (readl(clk->reg) >> SUN6I_AR100_MUX_SHIFT) & 135 - SUN6I_AR100_MUX_MASK; 136 - } 137 - 138 - static int ar100_set_rate(struct clk_hw *hw, unsigned long rate, 139 - unsigned long parent_rate) 140 - { 141 - unsigned long div = parent_rate / rate; 142 - struct ar100_clk *clk = to_ar100_clk(hw); 143 - u32 val = readl(clk->reg); 28 + unsigned long div; 144 29 int shift; 145 30 146 - if (parent_rate % rate) 147 - return -EINVAL; 31 + /* clock only divides */ 32 + if (req->rate > req->parent_rate) 33 + req->rate = req->parent_rate; 148 34 149 - shift = ffs(div) - 1; 150 - if (shift > SUN6I_AR100_SHIFT_MAX) 151 - shift = SUN6I_AR100_SHIFT_MAX; 35 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 36 + 37 + if (div < 32) 38 + shift = 0; 39 + else if (div >> 1 < 32) 40 + shift = 1; 41 + else if (div >> 2 < 32) 42 + shift = 2; 43 + else 44 + shift = 3; 152 45 153 46 div >>= shift; 154 47 155 - if (div > SUN6I_AR100_DIV_MAX) 156 - return -EINVAL; 48 + if (div > 32) 49 + div = 32; 157 50 158 - val &= ~((SUN6I_AR100_SHIFT_MASK << SUN6I_AR100_SHIFT_SHIFT) | 159 - (SUN6I_AR100_DIV_MASK << SUN6I_AR100_DIV_SHIFT)); 160 - val |= (shift << SUN6I_AR100_SHIFT_SHIFT) | 161 - (div << SUN6I_AR100_DIV_SHIFT); 162 - writel(val, clk->reg); 51 + req->rate = (req->parent_rate >> shift) / div; 52 + req->m = div - 1; 53 + req->p = shift; 54 + } 55 + 56 + static const struct clk_factors_config sun6i_ar100_config = { 57 + .mwidth = 5, 58 + .mshift = 8, 59 + .pwidth = 2, 60 + .pshift = 4, 61 + }; 62 + 63 + static const struct factors_data sun6i_ar100_data = { 64 + .mux = 16, 65 + .muxmask = GENMASK(1, 0), 66 + .table = &sun6i_ar100_config, 67 + .getter = sun6i_get_ar100_factors, 68 + }; 69 + 70 + static DEFINE_SPINLOCK(sun6i_ar100_lock); 71 + 72 + static int sun6i_a31_ar100_clk_probe(struct platform_device *pdev) 73 + { 74 + struct device_node *np = pdev->dev.of_node; 75 + struct resource *r; 76 + void __iomem *reg; 77 + struct clk *clk; 78 + 79 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 80 + reg = devm_ioremap_resource(&pdev->dev, r); 81 + if (IS_ERR(reg)) 82 + return PTR_ERR(reg); 83 + 84 + clk = sunxi_factors_register(np, &sun6i_ar100_data, &sun6i_ar100_lock, 85 + reg); 86 + if (!clk) 87 + return -ENOMEM; 88 + 89 + platform_set_drvdata(pdev, clk); 163 90 164 91 return 0; 165 92 } 166 93 167 - static struct clk_ops ar100_ops = { 168 - .recalc_rate = ar100_recalc_rate, 169 - .determine_rate = ar100_determine_rate, 170 - .set_parent = ar100_set_parent, 171 - .get_parent = ar100_get_parent, 172 - .set_rate = ar100_set_rate, 173 - }; 174 - 175 - static int sun6i_a31_ar100_clk_probe(struct platform_device *pdev) 94 + static int sun6i_a31_ar100_clk_remove(struct platform_device *pdev) 176 95 { 177 - const char *parents[SUN6I_AR100_MAX_PARENTS]; 178 96 struct device_node *np = pdev->dev.of_node; 179 - const char *clk_name = np->name; 180 - struct clk_init_data init; 181 - struct ar100_clk *ar100; 182 - struct resource *r; 183 - struct clk *clk; 184 - unsigned int nparents; 97 + struct clk *clk = platform_get_drvdata(pdev); 185 98 186 - ar100 = devm_kzalloc(&pdev->dev, sizeof(*ar100), GFP_KERNEL); 187 - if (!ar100) 188 - return -ENOMEM; 99 + sunxi_factors_unregister(np, clk); 189 100 190 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 191 - ar100->reg = devm_ioremap_resource(&pdev->dev, r); 192 - if (IS_ERR(ar100->reg)) 193 - return PTR_ERR(ar100->reg); 194 - 195 - nparents = of_clk_get_parent_count(np); 196 - if (nparents > SUN6I_AR100_MAX_PARENTS) 197 - nparents = SUN6I_AR100_MAX_PARENTS; 198 - 199 - of_clk_parent_fill(np, parents, nparents); 200 - 201 - of_property_read_string(np, "clock-output-names", &clk_name); 202 - 203 - init.name = clk_name; 204 - init.ops = &ar100_ops; 205 - init.parent_names = parents; 206 - init.num_parents = nparents; 207 - init.flags = 0; 208 - 209 - ar100->hw.init = &init; 210 - 211 - clk = clk_register(&pdev->dev, &ar100->hw); 212 - if (IS_ERR(clk)) 213 - return PTR_ERR(clk); 214 - 215 - return of_clk_add_provider(np, of_clk_src_simple_get, clk); 101 + return 0; 216 102 } 217 103 218 104 static const struct of_device_id sun6i_a31_ar100_clk_dt_ids[] = { ··· 113 227 .of_match_table = sun6i_a31_ar100_clk_dt_ids, 114 228 }, 115 229 .probe = sun6i_a31_ar100_clk_probe, 230 + .remove = sun6i_a31_ar100_clk_remove, 116 231 }; 117 232 module_platform_driver(sun6i_a31_ar100_clk_driver); 118 233
+1 -1
drivers/clk/sunxi/clk-sun8i-apb0.c
··· 36 36 37 37 /* The A23 APB0 clock is a standard 2 bit wide divider clock */ 38 38 clk = clk_register_divider(NULL, clk_name, clk_parent, 0, reg, 39 - 0, 2, CLK_DIVIDER_POWER_OF_TWO, NULL); 39 + 0, 2, 0, NULL); 40 40 if (IS_ERR(clk)) 41 41 return clk; 42 42
+2 -1
drivers/clk/sunxi/clk-sun8i-bus-gates.c
··· 17 17 * GNU General Public License for more details. 18 18 */ 19 19 20 - #include <linux/clk.h> 21 20 #include <linux/clk-provider.h> 22 21 #include <linux/of.h> 23 22 #include <linux/of_address.h> ··· 108 109 } 109 110 110 111 CLK_OF_DECLARE(sun8i_h3_bus_gates, "allwinner,sun8i-h3-bus-gates-clk", 112 + sun8i_h3_bus_gates_init); 113 + CLK_OF_DECLARE(sun8i_a83t_bus_gates, "allwinner,sun8i-a83t-bus-gates-clk", 111 114 sun8i_h3_bus_gates_init);
+78 -53
drivers/clk/sunxi/clk-sun8i-mbus.c
··· 15 15 */ 16 16 17 17 #include <linux/clk.h> 18 + #include <linux/clkdev.h> 18 19 #include <linux/clk-provider.h> 20 + #include <linux/slab.h> 21 + #include <linux/spinlock.h> 19 22 #include <linux/of_address.h> 20 23 21 - #include "clk-factors.h" 22 - 23 - /** 24 - * sun8i_a23_get_mbus_factors() - calculates m factor for MBUS clocks 25 - * MBUS rate is calculated as follows 26 - * rate = parent_rate / (m + 1); 27 - */ 28 - 29 - static void sun8i_a23_get_mbus_factors(u32 *freq, u32 parent_rate, 30 - u8 *n, u8 *k, u8 *m, u8 *p) 31 - { 32 - u8 div; 33 - 34 - /* 35 - * These clocks can only divide, so we will never be able to 36 - * achieve frequencies higher than the parent frequency 37 - */ 38 - if (*freq > parent_rate) 39 - *freq = parent_rate; 40 - 41 - div = DIV_ROUND_UP(parent_rate, *freq); 42 - 43 - if (div > 8) 44 - div = 8; 45 - 46 - *freq = parent_rate / div; 47 - 48 - /* we were called to round the frequency, we can now return */ 49 - if (m == NULL) 50 - return; 51 - 52 - *m = div - 1; 53 - } 54 - 55 - static struct clk_factors_config sun8i_a23_mbus_config = { 56 - .mshift = 0, 57 - .mwidth = 3, 58 - }; 59 - 60 - static const struct factors_data sun8i_a23_mbus_data __initconst = { 61 - .enable = 31, 62 - .mux = 24, 63 - .muxmask = BIT(1) | BIT(0), 64 - .table = &sun8i_a23_mbus_config, 65 - .getter = sun8i_a23_get_mbus_factors, 66 - }; 24 + #define SUN8I_MBUS_ENABLE 31 25 + #define SUN8I_MBUS_MUX_SHIFT 24 26 + #define SUN8I_MBUS_MUX_MASK 0x3 27 + #define SUN8I_MBUS_DIV_SHIFT 0 28 + #define SUN8I_MBUS_DIV_WIDTH 3 29 + #define SUN8I_MBUS_MAX_PARENTS 4 67 30 68 31 static DEFINE_SPINLOCK(sun8i_a23_mbus_lock); 69 32 70 33 static void __init sun8i_a23_mbus_setup(struct device_node *node) 71 34 { 72 - struct clk *mbus; 35 + int num_parents = of_clk_get_parent_count(node); 36 + const char *parents[num_parents]; 37 + const char *clk_name = node->name; 38 + struct resource res; 39 + struct clk_divider *div; 40 + struct clk_gate *gate; 41 + struct clk_mux *mux; 42 + struct clk *clk; 73 43 void __iomem *reg; 44 + int err; 74 45 75 - reg = of_iomap(node, 0); 46 + reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 76 47 if (!reg) { 77 - pr_err("Could not get registers for a23-mbus-clk\n"); 48 + pr_err("Could not get registers for sun8i-mbus-clk\n"); 78 49 return; 79 50 } 80 51 81 - mbus = sunxi_factors_register(node, &sun8i_a23_mbus_data, 82 - &sun8i_a23_mbus_lock, reg); 52 + div = kzalloc(sizeof(*div), GFP_KERNEL); 53 + if (!div) 54 + goto err_unmap; 55 + 56 + mux = kzalloc(sizeof(*mux), GFP_KERNEL); 57 + if (!mux) 58 + goto err_free_div; 59 + 60 + gate = kzalloc(sizeof(*gate), GFP_KERNEL); 61 + if (!gate) 62 + goto err_free_mux; 63 + 64 + of_property_read_string(node, "clock-output-names", &clk_name); 65 + of_clk_parent_fill(node, parents, num_parents); 66 + 67 + gate->reg = reg; 68 + gate->bit_idx = SUN8I_MBUS_ENABLE; 69 + gate->lock = &sun8i_a23_mbus_lock; 70 + 71 + div->reg = reg; 72 + div->shift = SUN8I_MBUS_DIV_SHIFT; 73 + div->width = SUN8I_MBUS_DIV_WIDTH; 74 + div->lock = &sun8i_a23_mbus_lock; 75 + 76 + mux->reg = reg; 77 + mux->shift = SUN8I_MBUS_MUX_SHIFT; 78 + mux->mask = SUN8I_MBUS_MUX_MASK; 79 + mux->lock = &sun8i_a23_mbus_lock; 80 + 81 + clk = clk_register_composite(NULL, clk_name, parents, num_parents, 82 + &mux->hw, &clk_mux_ops, 83 + &div->hw, &clk_divider_ops, 84 + &gate->hw, &clk_gate_ops, 85 + 0); 86 + if (IS_ERR(clk)) 87 + goto err_free_gate; 88 + 89 + err = of_clk_add_provider(node, of_clk_src_simple_get, clk); 90 + if (err) 91 + goto err_unregister_clk; 83 92 84 93 /* The MBUS clocks needs to be always enabled */ 85 - __clk_get(mbus); 86 - clk_prepare_enable(mbus); 94 + __clk_get(clk); 95 + clk_prepare_enable(clk); 96 + 97 + return; 98 + 99 + err_unregister_clk: 100 + /* TODO: The composite clock stuff will leak a bit here. */ 101 + clk_unregister(clk); 102 + err_free_gate: 103 + kfree(gate); 104 + err_free_mux: 105 + kfree(mux); 106 + err_free_div: 107 + kfree(div); 108 + err_unmap: 109 + iounmap(reg); 110 + of_address_to_resource(node, 0, &res); 111 + release_mem_region(res.start, resource_size(&res)); 87 112 } 88 113 CLK_OF_DECLARE(sun8i_a23_mbus, "allwinner,sun8i-a23-mbus-clk", sun8i_a23_mbus_setup);
+30 -56
drivers/clk/sunxi/clk-sun9i-core.c
··· 15 15 */ 16 16 17 17 #include <linux/clk.h> 18 + #include <linux/clkdev.h> 18 19 #include <linux/clk-provider.h> 19 20 #include <linux/of.h> 20 21 #include <linux/of_address.h> ··· 33 32 * p and m are named div1 and div2 in Allwinner's SDK 34 33 */ 35 34 36 - static void sun9i_a80_get_pll4_factors(u32 *freq, u32 parent_rate, 37 - u8 *n_ret, u8 *k, u8 *m_ret, u8 *p_ret) 35 + static void sun9i_a80_get_pll4_factors(struct factors_request *req) 38 36 { 39 37 int n; 40 38 int m = 1; 41 39 int p = 1; 42 40 43 41 /* Normalize value to a 6 MHz multiple (24 MHz / 4) */ 44 - n = DIV_ROUND_UP(*freq, 6000000); 42 + n = DIV_ROUND_UP(req->rate, 6000000); 45 43 46 44 /* If n is too large switch to steps of 12 MHz */ 47 45 if (n > 255) { ··· 60 60 else if (n < 12) 61 61 n = 12; 62 62 63 - *freq = ((24000000 * n) >> p) / (m + 1); 64 - 65 - /* we were called to round the frequency, we can now return */ 66 - if (n_ret == NULL) 67 - return; 68 - 69 - *n_ret = n; 70 - *m_ret = m; 71 - *p_ret = p; 63 + req->rate = ((24000000 * n) >> p) / (m + 1); 64 + req->n = n; 65 + req->m = m; 66 + req->p = p; 72 67 } 73 68 74 - static struct clk_factors_config sun9i_a80_pll4_config = { 69 + static const struct clk_factors_config sun9i_a80_pll4_config = { 75 70 .mshift = 18, 76 71 .mwidth = 1, 77 72 .nshift = 8, ··· 106 111 * rate = parent_rate / (m + 1); 107 112 */ 108 113 109 - static void sun9i_a80_get_gt_factors(u32 *freq, u32 parent_rate, 110 - u8 *n, u8 *k, u8 *m, u8 *p) 114 + static void sun9i_a80_get_gt_factors(struct factors_request *req) 111 115 { 112 116 u32 div; 113 117 114 - if (parent_rate < *freq) 115 - *freq = parent_rate; 118 + if (req->parent_rate < req->rate) 119 + req->rate = req->parent_rate; 116 120 117 - div = DIV_ROUND_UP(parent_rate, *freq); 121 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 118 122 119 123 /* maximum divider is 4 */ 120 124 if (div > 4) 121 125 div = 4; 122 126 123 - *freq = parent_rate / div; 124 - 125 - /* we were called to round the frequency, we can now return */ 126 - if (!m) 127 - return; 128 - 129 - *m = div; 127 + req->rate = req->parent_rate / div; 128 + req->m = div; 130 129 } 131 130 132 - static struct clk_factors_config sun9i_a80_gt_config = { 131 + static const struct clk_factors_config sun9i_a80_gt_config = { 133 132 .mshift = 0, 134 133 .mwidth = 2, 135 134 }; ··· 165 176 * rate = parent_rate >> p; 166 177 */ 167 178 168 - static void sun9i_a80_get_ahb_factors(u32 *freq, u32 parent_rate, 169 - u8 *n, u8 *k, u8 *m, u8 *p) 179 + static void sun9i_a80_get_ahb_factors(struct factors_request *req) 170 180 { 171 181 u32 _p; 172 182 173 - if (parent_rate < *freq) 174 - *freq = parent_rate; 183 + if (req->parent_rate < req->rate) 184 + req->rate = req->parent_rate; 175 185 176 - _p = order_base_2(DIV_ROUND_UP(parent_rate, *freq)); 186 + _p = order_base_2(DIV_ROUND_UP(req->parent_rate, req->rate)); 177 187 178 188 /* maximum p is 3 */ 179 189 if (_p > 3) 180 190 _p = 3; 181 191 182 - *freq = parent_rate >> _p; 183 - 184 - /* we were called to round the frequency, we can now return */ 185 - if (!p) 186 - return; 187 - 188 - *p = _p; 192 + req->rate = req->parent_rate >> _p; 193 + req->p = _p; 189 194 } 190 195 191 - static struct clk_factors_config sun9i_a80_ahb_config = { 196 + static const struct clk_factors_config sun9i_a80_ahb_config = { 192 197 .pshift = 0, 193 198 .pwidth = 2, 194 199 }; ··· 245 262 * rate = (parent_rate >> p) / (m + 1); 246 263 */ 247 264 248 - static void sun9i_a80_get_apb1_factors(u32 *freq, u32 parent_rate, 249 - u8 *n, u8 *k, u8 *m, u8 *p) 265 + static void sun9i_a80_get_apb1_factors(struct factors_request *req) 250 266 { 251 267 u32 div; 252 - u8 calcm, calcp; 253 268 254 - if (parent_rate < *freq) 255 - *freq = parent_rate; 269 + if (req->parent_rate < req->rate) 270 + req->rate = req->parent_rate; 256 271 257 - div = DIV_ROUND_UP(parent_rate, *freq); 272 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 258 273 259 274 /* Highest possible divider is 256 (p = 3, m = 31) */ 260 275 if (div > 256) 261 276 div = 256; 262 277 263 - calcp = order_base_2(div); 264 - calcm = (parent_rate >> calcp) - 1; 265 - *freq = (parent_rate >> calcp) / (calcm + 1); 266 - 267 - /* we were called to round the frequency, we can now return */ 268 - if (n == NULL) 269 - return; 270 - 271 - *m = calcm; 272 - *p = calcp; 278 + req->p = order_base_2(div); 279 + req->m = (req->parent_rate >> req->p) - 1; 280 + req->rate = (req->parent_rate >> req->p) / (req->m + 1); 273 281 } 274 282 275 - static struct clk_factors_config sun9i_a80_apb1_config = { 283 + static const struct clk_factors_config sun9i_a80_apb1_config = { 276 284 .mshift = 0, 277 285 .mwidth = 5, 278 286 .pshift = 16,
+525 -622
drivers/clk/sunxi/clk-sunxi.c
··· 28 28 29 29 static DEFINE_SPINLOCK(clk_lock); 30 30 31 + /* Maximum number of parents our clocks have */ 32 + #define SUNXI_MAX_PARENTS 5 33 + 31 34 /** 32 - * sun6i_a31_ahb1_clk_setup() - Setup function for a31 ahb1 composite clk 35 + * sun4i_get_pll1_factors() - calculates n, k, m, p factors for PLL1 36 + * PLL1 rate is calculated as follows 37 + * rate = (parent_rate * n * (k + 1) >> p) / (m + 1); 38 + * parent_rate is always 24Mhz 33 39 */ 34 40 35 - #define SUN6I_AHB1_MAX_PARENTS 4 36 - #define SUN6I_AHB1_MUX_PARENT_PLL6 3 37 - #define SUN6I_AHB1_MUX_SHIFT 12 38 - /* un-shifted mask is what mux_clk expects */ 39 - #define SUN6I_AHB1_MUX_MASK 0x3 40 - #define SUN6I_AHB1_MUX_GET_PARENT(reg) ((reg >> SUN6I_AHB1_MUX_SHIFT) & \ 41 - SUN6I_AHB1_MUX_MASK) 42 - 43 - #define SUN6I_AHB1_DIV_SHIFT 4 44 - #define SUN6I_AHB1_DIV_MASK (0x3 << SUN6I_AHB1_DIV_SHIFT) 45 - #define SUN6I_AHB1_DIV_GET(reg) ((reg & SUN6I_AHB1_DIV_MASK) >> \ 46 - SUN6I_AHB1_DIV_SHIFT) 47 - #define SUN6I_AHB1_DIV_SET(reg, div) ((reg & ~SUN6I_AHB1_DIV_MASK) | \ 48 - (div << SUN6I_AHB1_DIV_SHIFT)) 49 - #define SUN6I_AHB1_PLL6_DIV_SHIFT 6 50 - #define SUN6I_AHB1_PLL6_DIV_MASK (0x3 << SUN6I_AHB1_PLL6_DIV_SHIFT) 51 - #define SUN6I_AHB1_PLL6_DIV_GET(reg) ((reg & SUN6I_AHB1_PLL6_DIV_MASK) >> \ 52 - SUN6I_AHB1_PLL6_DIV_SHIFT) 53 - #define SUN6I_AHB1_PLL6_DIV_SET(reg, div) ((reg & ~SUN6I_AHB1_PLL6_DIV_MASK) | \ 54 - (div << SUN6I_AHB1_PLL6_DIV_SHIFT)) 55 - 56 - struct sun6i_ahb1_clk { 57 - struct clk_hw hw; 58 - void __iomem *reg; 59 - }; 60 - 61 - #define to_sun6i_ahb1_clk(_hw) container_of(_hw, struct sun6i_ahb1_clk, hw) 62 - 63 - static unsigned long sun6i_ahb1_clk_recalc_rate(struct clk_hw *hw, 64 - unsigned long parent_rate) 41 + static void sun4i_get_pll1_factors(struct factors_request *req) 65 42 { 66 - struct sun6i_ahb1_clk *ahb1 = to_sun6i_ahb1_clk(hw); 67 - unsigned long rate; 68 - u32 reg; 43 + u8 div; 69 44 70 - /* Fetch the register value */ 71 - reg = readl(ahb1->reg); 45 + /* Normalize value to a 6M multiple */ 46 + div = req->rate / 6000000; 47 + req->rate = 6000000 * div; 72 48 73 - /* apply pre-divider first if parent is pll6 */ 74 - if (SUN6I_AHB1_MUX_GET_PARENT(reg) == SUN6I_AHB1_MUX_PARENT_PLL6) 75 - parent_rate /= SUN6I_AHB1_PLL6_DIV_GET(reg) + 1; 49 + /* m is always zero for pll1 */ 50 + req->m = 0; 76 51 77 - /* clk divider */ 78 - rate = parent_rate >> SUN6I_AHB1_DIV_GET(reg); 52 + /* k is 1 only on these cases */ 53 + if (req->rate >= 768000000 || req->rate == 42000000 || 54 + req->rate == 54000000) 55 + req->k = 1; 56 + else 57 + req->k = 0; 79 58 80 - return rate; 59 + /* p will be 3 for divs under 10 */ 60 + if (div < 10) 61 + req->p = 3; 62 + 63 + /* p will be 2 for divs between 10 - 20 and odd divs under 32 */ 64 + else if (div < 20 || (div < 32 && (div & 1))) 65 + req->p = 2; 66 + 67 + /* p will be 1 for even divs under 32, divs under 40 and odd pairs 68 + * of divs between 40-62 */ 69 + else if (div < 40 || (div < 64 && (div & 2))) 70 + req->p = 1; 71 + 72 + /* any other entries have p = 0 */ 73 + else 74 + req->p = 0; 75 + 76 + /* calculate a suitable n based on k and p */ 77 + div <<= req->p; 78 + div /= (req->k + 1); 79 + req->n = div / 4; 81 80 } 82 81 83 - static long sun6i_ahb1_clk_round(unsigned long rate, u8 *divp, u8 *pre_divp, 84 - u8 parent, unsigned long parent_rate) 82 + /** 83 + * sun6i_a31_get_pll1_factors() - calculates n, k and m factors for PLL1 84 + * PLL1 rate is calculated as follows 85 + * rate = parent_rate * (n + 1) * (k + 1) / (m + 1); 86 + * parent_rate should always be 24MHz 87 + */ 88 + static void sun6i_a31_get_pll1_factors(struct factors_request *req) 89 + { 90 + /* 91 + * We can operate only on MHz, this will make our life easier 92 + * later. 93 + */ 94 + u32 freq_mhz = req->rate / 1000000; 95 + u32 parent_freq_mhz = req->parent_rate / 1000000; 96 + 97 + /* 98 + * Round down the frequency to the closest multiple of either 99 + * 6 or 16 100 + */ 101 + u32 round_freq_6 = round_down(freq_mhz, 6); 102 + u32 round_freq_16 = round_down(freq_mhz, 16); 103 + 104 + if (round_freq_6 > round_freq_16) 105 + freq_mhz = round_freq_6; 106 + else 107 + freq_mhz = round_freq_16; 108 + 109 + req->rate = freq_mhz * 1000000; 110 + 111 + /* If the frequency is a multiple of 32 MHz, k is always 3 */ 112 + if (!(freq_mhz % 32)) 113 + req->k = 3; 114 + /* If the frequency is a multiple of 9 MHz, k is always 2 */ 115 + else if (!(freq_mhz % 9)) 116 + req->k = 2; 117 + /* If the frequency is a multiple of 8 MHz, k is always 1 */ 118 + else if (!(freq_mhz % 8)) 119 + req->k = 1; 120 + /* Otherwise, we don't use the k factor */ 121 + else 122 + req->k = 0; 123 + 124 + /* 125 + * If the frequency is a multiple of 2 but not a multiple of 126 + * 3, m is 3. This is the first time we use 6 here, yet we 127 + * will use it on several other places. 128 + * We use this number because it's the lowest frequency we can 129 + * generate (with n = 0, k = 0, m = 3), so every other frequency 130 + * somehow relates to this frequency. 131 + */ 132 + if ((freq_mhz % 6) == 2 || (freq_mhz % 6) == 4) 133 + req->m = 2; 134 + /* 135 + * If the frequency is a multiple of 6MHz, but the factor is 136 + * odd, m will be 3 137 + */ 138 + else if ((freq_mhz / 6) & 1) 139 + req->m = 3; 140 + /* Otherwise, we end up with m = 1 */ 141 + else 142 + req->m = 1; 143 + 144 + /* Calculate n thanks to the above factors we already got */ 145 + req->n = freq_mhz * (req->m + 1) / ((req->k + 1) * parent_freq_mhz) 146 + - 1; 147 + 148 + /* 149 + * If n end up being outbound, and that we can still decrease 150 + * m, do it. 151 + */ 152 + if ((req->n + 1) > 31 && (req->m + 1) > 1) { 153 + req->n = (req->n + 1) / 2 - 1; 154 + req->m = (req->m + 1) / 2 - 1; 155 + } 156 + } 157 + 158 + /** 159 + * sun8i_a23_get_pll1_factors() - calculates n, k, m, p factors for PLL1 160 + * PLL1 rate is calculated as follows 161 + * rate = (parent_rate * (n + 1) * (k + 1) >> p) / (m + 1); 162 + * parent_rate is always 24Mhz 163 + */ 164 + 165 + static void sun8i_a23_get_pll1_factors(struct factors_request *req) 166 + { 167 + u8 div; 168 + 169 + /* Normalize value to a 6M multiple */ 170 + div = req->rate / 6000000; 171 + req->rate = 6000000 * div; 172 + 173 + /* m is always zero for pll1 */ 174 + req->m = 0; 175 + 176 + /* k is 1 only on these cases */ 177 + if (req->rate >= 768000000 || req->rate == 42000000 || 178 + req->rate == 54000000) 179 + req->k = 1; 180 + else 181 + req->k = 0; 182 + 183 + /* p will be 2 for divs under 20 and odd divs under 32 */ 184 + if (div < 20 || (div < 32 && (div & 1))) 185 + req->p = 2; 186 + 187 + /* p will be 1 for even divs under 32, divs under 40 and odd pairs 188 + * of divs between 40-62 */ 189 + else if (div < 40 || (div < 64 && (div & 2))) 190 + req->p = 1; 191 + 192 + /* any other entries have p = 0 */ 193 + else 194 + req->p = 0; 195 + 196 + /* calculate a suitable n based on k and p */ 197 + div <<= req->p; 198 + div /= (req->k + 1); 199 + req->n = div / 4 - 1; 200 + } 201 + 202 + /** 203 + * sun4i_get_pll5_factors() - calculates n, k factors for PLL5 204 + * PLL5 rate is calculated as follows 205 + * rate = parent_rate * n * (k + 1) 206 + * parent_rate is always 24Mhz 207 + */ 208 + 209 + static void sun4i_get_pll5_factors(struct factors_request *req) 210 + { 211 + u8 div; 212 + 213 + /* Normalize value to a parent_rate multiple (24M) */ 214 + div = req->rate / req->parent_rate; 215 + req->rate = req->parent_rate * div; 216 + 217 + if (div < 31) 218 + req->k = 0; 219 + else if (div / 2 < 31) 220 + req->k = 1; 221 + else if (div / 3 < 31) 222 + req->k = 2; 223 + else 224 + req->k = 3; 225 + 226 + req->n = DIV_ROUND_UP(div, (req->k + 1)); 227 + } 228 + 229 + /** 230 + * sun6i_a31_get_pll6_factors() - calculates n, k factors for A31 PLL6x2 231 + * PLL6x2 rate is calculated as follows 232 + * rate = parent_rate * (n + 1) * (k + 1) 233 + * parent_rate is always 24Mhz 234 + */ 235 + 236 + static void sun6i_a31_get_pll6_factors(struct factors_request *req) 237 + { 238 + u8 div; 239 + 240 + /* Normalize value to a parent_rate multiple (24M) */ 241 + div = req->rate / req->parent_rate; 242 + req->rate = req->parent_rate * div; 243 + 244 + req->k = div / 32; 245 + if (req->k > 3) 246 + req->k = 3; 247 + 248 + req->n = DIV_ROUND_UP(div, (req->k + 1)) - 1; 249 + } 250 + 251 + /** 252 + * sun5i_a13_get_ahb_factors() - calculates m, p factors for AHB 253 + * AHB rate is calculated as follows 254 + * rate = parent_rate >> p 255 + */ 256 + 257 + static void sun5i_a13_get_ahb_factors(struct factors_request *req) 258 + { 259 + u32 div; 260 + 261 + /* divide only */ 262 + if (req->parent_rate < req->rate) 263 + req->rate = req->parent_rate; 264 + 265 + /* 266 + * user manual says valid speed is 8k ~ 276M, but tests show it 267 + * can work at speeds up to 300M, just after reparenting to pll6 268 + */ 269 + if (req->rate < 8000) 270 + req->rate = 8000; 271 + if (req->rate > 300000000) 272 + req->rate = 300000000; 273 + 274 + div = order_base_2(DIV_ROUND_UP(req->parent_rate, req->rate)); 275 + 276 + /* p = 0 ~ 3 */ 277 + if (div > 3) 278 + div = 3; 279 + 280 + req->rate = req->parent_rate >> div; 281 + 282 + req->p = div; 283 + } 284 + 285 + #define SUN6I_AHB1_PARENT_PLL6 3 286 + 287 + /** 288 + * sun6i_a31_get_ahb_factors() - calculates m, p factors for AHB 289 + * AHB rate is calculated as follows 290 + * rate = parent_rate >> p 291 + * 292 + * if parent is pll6, then 293 + * parent_rate = pll6 rate / (m + 1) 294 + */ 295 + 296 + static void sun6i_get_ahb1_factors(struct factors_request *req) 85 297 { 86 298 u8 div, calcp, calcm = 1; 87 299 ··· 301 89 * clock can only divide, so we will never be able to achieve 302 90 * frequencies higher than the parent frequency 303 91 */ 304 - if (parent_rate && rate > parent_rate) 305 - rate = parent_rate; 92 + if (req->parent_rate && req->rate > req->parent_rate) 93 + req->rate = req->parent_rate; 306 94 307 - div = DIV_ROUND_UP(parent_rate, rate); 95 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 308 96 309 97 /* calculate pre-divider if parent is pll6 */ 310 - if (parent == SUN6I_AHB1_MUX_PARENT_PLL6) { 98 + if (req->parent_index == SUN6I_AHB1_PARENT_PLL6) { 311 99 if (div < 4) 312 100 calcp = 0; 313 101 else if (div / 2 < 4) ··· 323 111 calcp = calcp > 3 ? 3 : calcp; 324 112 } 325 113 326 - /* we were asked to pass back divider values */ 327 - if (divp) { 328 - *divp = calcp; 329 - *pre_divp = calcm - 1; 330 - } 331 - 332 - return (parent_rate / calcm) >> calcp; 333 - } 334 - 335 - static int sun6i_ahb1_clk_determine_rate(struct clk_hw *hw, 336 - struct clk_rate_request *req) 337 - { 338 - struct clk_hw *parent, *best_parent = NULL; 339 - int i, num_parents; 340 - unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0; 341 - 342 - /* find the parent that can help provide the fastest rate <= rate */ 343 - num_parents = clk_hw_get_num_parents(hw); 344 - for (i = 0; i < num_parents; i++) { 345 - parent = clk_hw_get_parent_by_index(hw, i); 346 - if (!parent) 347 - continue; 348 - if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) 349 - parent_rate = clk_hw_round_rate(parent, req->rate); 350 - else 351 - parent_rate = clk_hw_get_rate(parent); 352 - 353 - child_rate = sun6i_ahb1_clk_round(req->rate, NULL, NULL, i, 354 - parent_rate); 355 - 356 - if (child_rate <= req->rate && child_rate > best_child_rate) { 357 - best_parent = parent; 358 - best = parent_rate; 359 - best_child_rate = child_rate; 360 - } 361 - } 362 - 363 - if (!best_parent) 364 - return -EINVAL; 365 - 366 - req->best_parent_hw = best_parent; 367 - req->best_parent_rate = best; 368 - req->rate = best_child_rate; 369 - 370 - return 0; 371 - } 372 - 373 - static int sun6i_ahb1_clk_set_rate(struct clk_hw *hw, unsigned long rate, 374 - unsigned long parent_rate) 375 - { 376 - struct sun6i_ahb1_clk *ahb1 = to_sun6i_ahb1_clk(hw); 377 - unsigned long flags; 378 - u8 div, pre_div, parent; 379 - u32 reg; 380 - 381 - spin_lock_irqsave(&clk_lock, flags); 382 - 383 - reg = readl(ahb1->reg); 384 - 385 - /* need to know which parent is used to apply pre-divider */ 386 - parent = SUN6I_AHB1_MUX_GET_PARENT(reg); 387 - sun6i_ahb1_clk_round(rate, &div, &pre_div, parent, parent_rate); 388 - 389 - reg = SUN6I_AHB1_DIV_SET(reg, div); 390 - reg = SUN6I_AHB1_PLL6_DIV_SET(reg, pre_div); 391 - writel(reg, ahb1->reg); 392 - 393 - spin_unlock_irqrestore(&clk_lock, flags); 394 - 395 - return 0; 396 - } 397 - 398 - static const struct clk_ops sun6i_ahb1_clk_ops = { 399 - .determine_rate = sun6i_ahb1_clk_determine_rate, 400 - .recalc_rate = sun6i_ahb1_clk_recalc_rate, 401 - .set_rate = sun6i_ahb1_clk_set_rate, 402 - }; 403 - 404 - static void __init sun6i_ahb1_clk_setup(struct device_node *node) 405 - { 406 - struct clk *clk; 407 - struct sun6i_ahb1_clk *ahb1; 408 - struct clk_mux *mux; 409 - const char *clk_name = node->name; 410 - const char *parents[SUN6I_AHB1_MAX_PARENTS]; 411 - void __iomem *reg; 412 - int i; 413 - 414 - reg = of_io_request_and_map(node, 0, of_node_full_name(node)); 415 - if (IS_ERR(reg)) 416 - return; 417 - 418 - /* we have a mux, we will have >1 parents */ 419 - i = of_clk_parent_fill(node, parents, SUN6I_AHB1_MAX_PARENTS); 420 - of_property_read_string(node, "clock-output-names", &clk_name); 421 - 422 - ahb1 = kzalloc(sizeof(struct sun6i_ahb1_clk), GFP_KERNEL); 423 - if (!ahb1) 424 - return; 425 - 426 - mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL); 427 - if (!mux) { 428 - kfree(ahb1); 429 - return; 430 - } 431 - 432 - /* set up clock properties */ 433 - mux->reg = reg; 434 - mux->shift = SUN6I_AHB1_MUX_SHIFT; 435 - mux->mask = SUN6I_AHB1_MUX_MASK; 436 - mux->lock = &clk_lock; 437 - ahb1->reg = reg; 438 - 439 - clk = clk_register_composite(NULL, clk_name, parents, i, 440 - &mux->hw, &clk_mux_ops, 441 - &ahb1->hw, &sun6i_ahb1_clk_ops, 442 - NULL, NULL, 0); 443 - 444 - if (!IS_ERR(clk)) { 445 - of_clk_add_provider(node, of_clk_src_simple_get, clk); 446 - clk_register_clkdev(clk, clk_name, NULL); 447 - } 448 - } 449 - CLK_OF_DECLARE(sun6i_a31_ahb1, "allwinner,sun6i-a31-ahb1-clk", sun6i_ahb1_clk_setup); 450 - 451 - /* Maximum number of parents our clocks have */ 452 - #define SUNXI_MAX_PARENTS 5 453 - 454 - /** 455 - * sun4i_get_pll1_factors() - calculates n, k, m, p factors for PLL1 456 - * PLL1 rate is calculated as follows 457 - * rate = (parent_rate * n * (k + 1) >> p) / (m + 1); 458 - * parent_rate is always 24Mhz 459 - */ 460 - 461 - static void sun4i_get_pll1_factors(u32 *freq, u32 parent_rate, 462 - u8 *n, u8 *k, u8 *m, u8 *p) 463 - { 464 - u8 div; 465 - 466 - /* Normalize value to a 6M multiple */ 467 - div = *freq / 6000000; 468 - *freq = 6000000 * div; 469 - 470 - /* we were called to round the frequency, we can now return */ 471 - if (n == NULL) 472 - return; 473 - 474 - /* m is always zero for pll1 */ 475 - *m = 0; 476 - 477 - /* k is 1 only on these cases */ 478 - if (*freq >= 768000000 || *freq == 42000000 || *freq == 54000000) 479 - *k = 1; 480 - else 481 - *k = 0; 482 - 483 - /* p will be 3 for divs under 10 */ 484 - if (div < 10) 485 - *p = 3; 486 - 487 - /* p will be 2 for divs between 10 - 20 and odd divs under 32 */ 488 - else if (div < 20 || (div < 32 && (div & 1))) 489 - *p = 2; 490 - 491 - /* p will be 1 for even divs under 32, divs under 40 and odd pairs 492 - * of divs between 40-62 */ 493 - else if (div < 40 || (div < 64 && (div & 2))) 494 - *p = 1; 495 - 496 - /* any other entries have p = 0 */ 497 - else 498 - *p = 0; 499 - 500 - /* calculate a suitable n based on k and p */ 501 - div <<= *p; 502 - div /= (*k + 1); 503 - *n = div / 4; 114 + req->rate = (req->parent_rate / calcm) >> calcp; 115 + req->p = calcp; 116 + req->m = calcm - 1; 504 117 } 505 118 506 119 /** 507 - * sun6i_a31_get_pll1_factors() - calculates n, k and m factors for PLL1 508 - * PLL1 rate is calculated as follows 509 - * rate = parent_rate * (n + 1) * (k + 1) / (m + 1); 510 - * parent_rate should always be 24MHz 120 + * sun6i_ahb1_recalc() - calculates AHB clock rate from m, p factors and 121 + * parent index 511 122 */ 512 - static void sun6i_a31_get_pll1_factors(u32 *freq, u32 parent_rate, 513 - u8 *n, u8 *k, u8 *m, u8 *p) 123 + static void sun6i_ahb1_recalc(struct factors_request *req) 514 124 { 515 - /* 516 - * We can operate only on MHz, this will make our life easier 517 - * later. 518 - */ 519 - u32 freq_mhz = *freq / 1000000; 520 - u32 parent_freq_mhz = parent_rate / 1000000; 125 + req->rate = req->parent_rate; 521 126 522 - /* 523 - * Round down the frequency to the closest multiple of either 524 - * 6 or 16 525 - */ 526 - u32 round_freq_6 = round_down(freq_mhz, 6); 527 - u32 round_freq_16 = round_down(freq_mhz, 16); 127 + /* apply pre-divider first if parent is pll6 */ 128 + if (req->parent_index == SUN6I_AHB1_PARENT_PLL6) 129 + req->rate /= req->m + 1; 528 130 529 - if (round_freq_6 > round_freq_16) 530 - freq_mhz = round_freq_6; 531 - else 532 - freq_mhz = round_freq_16; 533 - 534 - *freq = freq_mhz * 1000000; 535 - 536 - /* 537 - * If the factors pointer are null, we were just called to 538 - * round down the frequency. 539 - * Exit. 540 - */ 541 - if (n == NULL) 542 - return; 543 - 544 - /* If the frequency is a multiple of 32 MHz, k is always 3 */ 545 - if (!(freq_mhz % 32)) 546 - *k = 3; 547 - /* If the frequency is a multiple of 9 MHz, k is always 2 */ 548 - else if (!(freq_mhz % 9)) 549 - *k = 2; 550 - /* If the frequency is a multiple of 8 MHz, k is always 1 */ 551 - else if (!(freq_mhz % 8)) 552 - *k = 1; 553 - /* Otherwise, we don't use the k factor */ 554 - else 555 - *k = 0; 556 - 557 - /* 558 - * If the frequency is a multiple of 2 but not a multiple of 559 - * 3, m is 3. This is the first time we use 6 here, yet we 560 - * will use it on several other places. 561 - * We use this number because it's the lowest frequency we can 562 - * generate (with n = 0, k = 0, m = 3), so every other frequency 563 - * somehow relates to this frequency. 564 - */ 565 - if ((freq_mhz % 6) == 2 || (freq_mhz % 6) == 4) 566 - *m = 2; 567 - /* 568 - * If the frequency is a multiple of 6MHz, but the factor is 569 - * odd, m will be 3 570 - */ 571 - else if ((freq_mhz / 6) & 1) 572 - *m = 3; 573 - /* Otherwise, we end up with m = 1 */ 574 - else 575 - *m = 1; 576 - 577 - /* Calculate n thanks to the above factors we already got */ 578 - *n = freq_mhz * (*m + 1) / ((*k + 1) * parent_freq_mhz) - 1; 579 - 580 - /* 581 - * If n end up being outbound, and that we can still decrease 582 - * m, do it. 583 - */ 584 - if ((*n + 1) > 31 && (*m + 1) > 1) { 585 - *n = (*n + 1) / 2 - 1; 586 - *m = (*m + 1) / 2 - 1; 587 - } 588 - } 589 - 590 - /** 591 - * sun8i_a23_get_pll1_factors() - calculates n, k, m, p factors for PLL1 592 - * PLL1 rate is calculated as follows 593 - * rate = (parent_rate * (n + 1) * (k + 1) >> p) / (m + 1); 594 - * parent_rate is always 24Mhz 595 - */ 596 - 597 - static void sun8i_a23_get_pll1_factors(u32 *freq, u32 parent_rate, 598 - u8 *n, u8 *k, u8 *m, u8 *p) 599 - { 600 - u8 div; 601 - 602 - /* Normalize value to a 6M multiple */ 603 - div = *freq / 6000000; 604 - *freq = 6000000 * div; 605 - 606 - /* we were called to round the frequency, we can now return */ 607 - if (n == NULL) 608 - return; 609 - 610 - /* m is always zero for pll1 */ 611 - *m = 0; 612 - 613 - /* k is 1 only on these cases */ 614 - if (*freq >= 768000000 || *freq == 42000000 || *freq == 54000000) 615 - *k = 1; 616 - else 617 - *k = 0; 618 - 619 - /* p will be 2 for divs under 20 and odd divs under 32 */ 620 - if (div < 20 || (div < 32 && (div & 1))) 621 - *p = 2; 622 - 623 - /* p will be 1 for even divs under 32, divs under 40 and odd pairs 624 - * of divs between 40-62 */ 625 - else if (div < 40 || (div < 64 && (div & 2))) 626 - *p = 1; 627 - 628 - /* any other entries have p = 0 */ 629 - else 630 - *p = 0; 631 - 632 - /* calculate a suitable n based on k and p */ 633 - div <<= *p; 634 - div /= (*k + 1); 635 - *n = div / 4 - 1; 636 - } 637 - 638 - /** 639 - * sun4i_get_pll5_factors() - calculates n, k factors for PLL5 640 - * PLL5 rate is calculated as follows 641 - * rate = parent_rate * n * (k + 1) 642 - * parent_rate is always 24Mhz 643 - */ 644 - 645 - static void sun4i_get_pll5_factors(u32 *freq, u32 parent_rate, 646 - u8 *n, u8 *k, u8 *m, u8 *p) 647 - { 648 - u8 div; 649 - 650 - /* Normalize value to a parent_rate multiple (24M) */ 651 - div = *freq / parent_rate; 652 - *freq = parent_rate * div; 653 - 654 - /* we were called to round the frequency, we can now return */ 655 - if (n == NULL) 656 - return; 657 - 658 - if (div < 31) 659 - *k = 0; 660 - else if (div / 2 < 31) 661 - *k = 1; 662 - else if (div / 3 < 31) 663 - *k = 2; 664 - else 665 - *k = 3; 666 - 667 - *n = DIV_ROUND_UP(div, (*k+1)); 668 - } 669 - 670 - /** 671 - * sun6i_a31_get_pll6_factors() - calculates n, k factors for A31 PLL6x2 672 - * PLL6x2 rate is calculated as follows 673 - * rate = parent_rate * (n + 1) * (k + 1) 674 - * parent_rate is always 24Mhz 675 - */ 676 - 677 - static void sun6i_a31_get_pll6_factors(u32 *freq, u32 parent_rate, 678 - u8 *n, u8 *k, u8 *m, u8 *p) 679 - { 680 - u8 div; 681 - 682 - /* Normalize value to a parent_rate multiple (24M) */ 683 - div = *freq / parent_rate; 684 - *freq = parent_rate * div; 685 - 686 - /* we were called to round the frequency, we can now return */ 687 - if (n == NULL) 688 - return; 689 - 690 - *k = div / 32; 691 - if (*k > 3) 692 - *k = 3; 693 - 694 - *n = DIV_ROUND_UP(div, (*k+1)) - 1; 695 - } 696 - 697 - /** 698 - * sun5i_a13_get_ahb_factors() - calculates m, p factors for AHB 699 - * AHB rate is calculated as follows 700 - * rate = parent_rate >> p 701 - */ 702 - 703 - static void sun5i_a13_get_ahb_factors(u32 *freq, u32 parent_rate, 704 - u8 *n, u8 *k, u8 *m, u8 *p) 705 - { 706 - u32 div; 707 - 708 - /* divide only */ 709 - if (parent_rate < *freq) 710 - *freq = parent_rate; 711 - 712 - /* 713 - * user manual says valid speed is 8k ~ 276M, but tests show it 714 - * can work at speeds up to 300M, just after reparenting to pll6 715 - */ 716 - if (*freq < 8000) 717 - *freq = 8000; 718 - if (*freq > 300000000) 719 - *freq = 300000000; 720 - 721 - div = order_base_2(DIV_ROUND_UP(parent_rate, *freq)); 722 - 723 - /* p = 0 ~ 3 */ 724 - if (div > 3) 725 - div = 3; 726 - 727 - *freq = parent_rate >> div; 728 - 729 - /* we were called to round the frequency, we can now return */ 730 - if (p == NULL) 731 - return; 732 - 733 - *p = div; 131 + /* clk divider */ 132 + req->rate >>= req->p; 734 133 } 735 134 736 135 /** ··· 350 527 * rate = (parent_rate >> p) / (m + 1); 351 528 */ 352 529 353 - static void sun4i_get_apb1_factors(u32 *freq, u32 parent_rate, 354 - u8 *n, u8 *k, u8 *m, u8 *p) 530 + static void sun4i_get_apb1_factors(struct factors_request *req) 355 531 { 356 532 u8 calcm, calcp; 533 + int div; 357 534 358 - if (parent_rate < *freq) 359 - *freq = parent_rate; 535 + if (req->parent_rate < req->rate) 536 + req->rate = req->parent_rate; 360 537 361 - parent_rate = DIV_ROUND_UP(parent_rate, *freq); 538 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 362 539 363 540 /* Invalid rate! */ 364 - if (parent_rate > 32) 541 + if (div > 32) 365 542 return; 366 543 367 - if (parent_rate <= 4) 544 + if (div <= 4) 368 545 calcp = 0; 369 - else if (parent_rate <= 8) 546 + else if (div <= 8) 370 547 calcp = 1; 371 - else if (parent_rate <= 16) 548 + else if (div <= 16) 372 549 calcp = 2; 373 550 else 374 551 calcp = 3; 375 552 376 - calcm = (parent_rate >> calcp) - 1; 553 + calcm = (req->parent_rate >> calcp) - 1; 377 554 378 - *freq = (parent_rate >> calcp) / (calcm + 1); 379 - 380 - /* we were called to round the frequency, we can now return */ 381 - if (n == NULL) 382 - return; 383 - 384 - *m = calcm; 385 - *p = calcp; 555 + req->rate = (req->parent_rate >> calcp) / (calcm + 1); 556 + req->m = calcm; 557 + req->p = calcp; 386 558 } 387 559 388 560 ··· 389 571 * rate = (parent_rate >> p) / (m + 1); 390 572 */ 391 573 392 - static void sun7i_a20_get_out_factors(u32 *freq, u32 parent_rate, 393 - u8 *n, u8 *k, u8 *m, u8 *p) 574 + static void sun7i_a20_get_out_factors(struct factors_request *req) 394 575 { 395 576 u8 div, calcm, calcp; 396 577 397 578 /* These clocks can only divide, so we will never be able to achieve 398 579 * frequencies higher than the parent frequency */ 399 - if (*freq > parent_rate) 400 - *freq = parent_rate; 580 + if (req->rate > req->parent_rate) 581 + req->rate = req->parent_rate; 401 582 402 - div = DIV_ROUND_UP(parent_rate, *freq); 583 + div = DIV_ROUND_UP(req->parent_rate, req->rate); 403 584 404 585 if (div < 32) 405 586 calcp = 0; ··· 411 594 412 595 calcm = DIV_ROUND_UP(div, 1 << calcp); 413 596 414 - *freq = (parent_rate >> calcp) / calcm; 415 - 416 - /* we were called to round the frequency, we can now return */ 417 - if (n == NULL) 418 - return; 419 - 420 - *m = calcm - 1; 421 - *p = calcp; 597 + req->rate = (req->parent_rate >> calcp) / calcm; 598 + req->m = calcm - 1; 599 + req->p = calcp; 422 600 } 423 601 424 602 /** 425 603 * sunxi_factors_clk_setup() - Setup function for factor clocks 426 604 */ 427 605 428 - static struct clk_factors_config sun4i_pll1_config = { 606 + static const struct clk_factors_config sun4i_pll1_config = { 429 607 .nshift = 8, 430 608 .nwidth = 5, 431 609 .kshift = 4, ··· 431 619 .pwidth = 2, 432 620 }; 433 621 434 - static struct clk_factors_config sun6i_a31_pll1_config = { 622 + static const struct clk_factors_config sun6i_a31_pll1_config = { 435 623 .nshift = 8, 436 624 .nwidth = 5, 437 625 .kshift = 4, ··· 441 629 .n_start = 1, 442 630 }; 443 631 444 - static struct clk_factors_config sun8i_a23_pll1_config = { 632 + static const struct clk_factors_config sun8i_a23_pll1_config = { 445 633 .nshift = 8, 446 634 .nwidth = 5, 447 635 .kshift = 4, ··· 453 641 .n_start = 1, 454 642 }; 455 643 456 - static struct clk_factors_config sun4i_pll5_config = { 644 + static const struct clk_factors_config sun4i_pll5_config = { 457 645 .nshift = 8, 458 646 .nwidth = 5, 459 647 .kshift = 4, 460 648 .kwidth = 2, 461 649 }; 462 650 463 - static struct clk_factors_config sun6i_a31_pll6_config = { 651 + static const struct clk_factors_config sun6i_a31_pll6_config = { 464 652 .nshift = 8, 465 653 .nwidth = 5, 466 654 .kshift = 4, ··· 468 656 .n_start = 1, 469 657 }; 470 658 471 - static struct clk_factors_config sun5i_a13_ahb_config = { 659 + static const struct clk_factors_config sun5i_a13_ahb_config = { 472 660 .pshift = 4, 473 661 .pwidth = 2, 474 662 }; 475 663 476 - static struct clk_factors_config sun4i_apb1_config = { 664 + static const struct clk_factors_config sun6i_ahb1_config = { 665 + .mshift = 6, 666 + .mwidth = 2, 667 + .pshift = 4, 668 + .pwidth = 2, 669 + }; 670 + 671 + static const struct clk_factors_config sun4i_apb1_config = { 477 672 .mshift = 0, 478 673 .mwidth = 5, 479 674 .pshift = 16, ··· 488 669 }; 489 670 490 671 /* user manual says "n" but it's really "p" */ 491 - static struct clk_factors_config sun7i_a20_out_config = { 672 + static const struct clk_factors_config sun7i_a20_out_config = { 492 673 .mshift = 8, 493 674 .mwidth = 5, 494 675 .pshift = 20, ··· 547 728 .getter = sun5i_a13_get_ahb_factors, 548 729 }; 549 730 731 + static const struct factors_data sun6i_ahb1_data __initconst = { 732 + .mux = 12, 733 + .muxmask = BIT(1) | BIT(0), 734 + .table = &sun6i_ahb1_config, 735 + .getter = sun6i_get_ahb1_factors, 736 + .recalc = sun6i_ahb1_recalc, 737 + }; 738 + 550 739 static const struct factors_data sun4i_apb1_data __initconst = { 551 740 .mux = 24, 552 741 .muxmask = BIT(1) | BIT(0), ··· 585 758 return sunxi_factors_register(node, data, &clk_lock, reg); 586 759 } 587 760 761 + static void __init sun4i_pll1_clk_setup(struct device_node *node) 762 + { 763 + sunxi_factors_clk_setup(node, &sun4i_pll1_data); 764 + } 765 + CLK_OF_DECLARE(sun4i_pll1, "allwinner,sun4i-a10-pll1-clk", 766 + sun4i_pll1_clk_setup); 767 + 768 + static void __init sun6i_pll1_clk_setup(struct device_node *node) 769 + { 770 + sunxi_factors_clk_setup(node, &sun6i_a31_pll1_data); 771 + } 772 + CLK_OF_DECLARE(sun6i_pll1, "allwinner,sun6i-a31-pll1-clk", 773 + sun6i_pll1_clk_setup); 774 + 775 + static void __init sun8i_pll1_clk_setup(struct device_node *node) 776 + { 777 + sunxi_factors_clk_setup(node, &sun8i_a23_pll1_data); 778 + } 779 + CLK_OF_DECLARE(sun8i_pll1, "allwinner,sun8i-a23-pll1-clk", 780 + sun8i_pll1_clk_setup); 781 + 782 + static void __init sun7i_pll4_clk_setup(struct device_node *node) 783 + { 784 + sunxi_factors_clk_setup(node, &sun7i_a20_pll4_data); 785 + } 786 + CLK_OF_DECLARE(sun7i_pll4, "allwinner,sun7i-a20-pll4-clk", 787 + sun7i_pll4_clk_setup); 788 + 789 + static void __init sun5i_ahb_clk_setup(struct device_node *node) 790 + { 791 + sunxi_factors_clk_setup(node, &sun5i_a13_ahb_data); 792 + } 793 + CLK_OF_DECLARE(sun5i_ahb, "allwinner,sun5i-a13-ahb-clk", 794 + sun5i_ahb_clk_setup); 795 + 796 + static void __init sun6i_ahb1_clk_setup(struct device_node *node) 797 + { 798 + sunxi_factors_clk_setup(node, &sun6i_ahb1_data); 799 + } 800 + CLK_OF_DECLARE(sun6i_a31_ahb1, "allwinner,sun6i-a31-ahb1-clk", 801 + sun6i_ahb1_clk_setup); 802 + 803 + static void __init sun4i_apb1_clk_setup(struct device_node *node) 804 + { 805 + sunxi_factors_clk_setup(node, &sun4i_apb1_data); 806 + } 807 + CLK_OF_DECLARE(sun4i_apb1, "allwinner,sun4i-a10-apb1-clk", 808 + sun4i_apb1_clk_setup); 809 + 810 + static void __init sun7i_out_clk_setup(struct device_node *node) 811 + { 812 + sunxi_factors_clk_setup(node, &sun7i_a20_out_data); 813 + } 814 + CLK_OF_DECLARE(sun7i_out, "allwinner,sun7i-a20-out-clk", 815 + sun7i_out_clk_setup); 588 816 589 817 590 818 /** ··· 664 782 .shift = 0, 665 783 }; 666 784 667 - static void __init sunxi_mux_clk_setup(struct device_node *node, 668 - struct mux_data *data) 785 + static struct clk * __init sunxi_mux_clk_setup(struct device_node *node, 786 + const struct mux_data *data) 669 787 { 670 788 struct clk *clk; 671 789 const char *clk_name = node->name; ··· 674 792 int i; 675 793 676 794 reg = of_iomap(node, 0); 795 + if (!reg) { 796 + pr_err("Could not map registers for mux-clk: %s\n", 797 + of_node_full_name(node)); 798 + return NULL; 799 + } 677 800 678 801 i = of_clk_parent_fill(node, parents, SUNXI_MAX_PARENTS); 679 - of_property_read_string(node, "clock-output-names", &clk_name); 802 + if (of_property_read_string(node, "clock-output-names", &clk_name)) { 803 + pr_err("%s: could not read clock-output-names from \"%s\"\n", 804 + __func__, of_node_full_name(node)); 805 + goto out_unmap; 806 + } 680 807 681 808 clk = clk_register_mux(NULL, clk_name, parents, i, 682 809 CLK_SET_RATE_PARENT, reg, 683 810 data->shift, SUNXI_MUX_GATE_WIDTH, 684 811 0, &clk_lock); 685 812 686 - if (clk) { 687 - of_clk_add_provider(node, of_clk_src_simple_get, clk); 688 - clk_register_clkdev(clk, clk_name, NULL); 813 + if (IS_ERR(clk)) { 814 + pr_err("%s: failed to register mux clock %s: %ld\n", __func__, 815 + clk_name, PTR_ERR(clk)); 816 + goto out_unmap; 689 817 } 818 + 819 + if (of_clk_add_provider(node, of_clk_src_simple_get, clk)) { 820 + pr_err("%s: failed to add clock provider for %s\n", 821 + __func__, clk_name); 822 + clk_unregister_divider(clk); 823 + goto out_unmap; 824 + } 825 + 826 + return clk; 827 + out_unmap: 828 + iounmap(reg); 829 + return NULL; 690 830 } 691 831 832 + static void __init sun4i_cpu_clk_setup(struct device_node *node) 833 + { 834 + struct clk *clk; 835 + 836 + clk = sunxi_mux_clk_setup(node, &sun4i_cpu_mux_data); 837 + if (!clk) 838 + return; 839 + 840 + /* Protect CPU clock */ 841 + __clk_get(clk); 842 + clk_prepare_enable(clk); 843 + } 844 + CLK_OF_DECLARE(sun4i_cpu, "allwinner,sun4i-a10-cpu-clk", 845 + sun4i_cpu_clk_setup); 846 + 847 + static void __init sun6i_ahb1_mux_clk_setup(struct device_node *node) 848 + { 849 + sunxi_mux_clk_setup(node, &sun6i_a31_ahb1_mux_data); 850 + } 851 + CLK_OF_DECLARE(sun6i_ahb1_mux, "allwinner,sun6i-a31-ahb1-mux-clk", 852 + sun6i_ahb1_mux_clk_setup); 853 + 854 + static void __init sun8i_ahb2_clk_setup(struct device_node *node) 855 + { 856 + sunxi_mux_clk_setup(node, &sun8i_h3_ahb2_mux_data); 857 + } 858 + CLK_OF_DECLARE(sun8i_ahb2, "allwinner,sun8i-h3-ahb2-clk", 859 + sun8i_ahb2_clk_setup); 692 860 693 861 694 862 /** ··· 797 865 }; 798 866 799 867 static void __init sunxi_divider_clk_setup(struct device_node *node, 800 - struct div_data *data) 868 + const struct div_data *data) 801 869 { 802 870 struct clk *clk; 803 871 const char *clk_name = node->name; ··· 805 873 void __iomem *reg; 806 874 807 875 reg = of_iomap(node, 0); 876 + if (!reg) { 877 + pr_err("Could not map registers for mux-clk: %s\n", 878 + of_node_full_name(node)); 879 + return; 880 + } 808 881 809 882 clk_parent = of_clk_get_parent_name(node, 0); 810 883 811 - of_property_read_string(node, "clock-output-names", &clk_name); 884 + if (of_property_read_string(node, "clock-output-names", &clk_name)) { 885 + pr_err("%s: could not read clock-output-names from \"%s\"\n", 886 + __func__, of_node_full_name(node)); 887 + goto out_unmap; 888 + } 812 889 813 890 clk = clk_register_divider_table(NULL, clk_name, clk_parent, 0, 814 891 reg, data->shift, data->width, 815 892 data->pow ? CLK_DIVIDER_POWER_OF_TWO : 0, 816 893 data->table, &clk_lock); 817 - if (clk) { 818 - of_clk_add_provider(node, of_clk_src_simple_get, clk); 819 - clk_register_clkdev(clk, clk_name, NULL); 894 + if (IS_ERR(clk)) { 895 + pr_err("%s: failed to register divider clock %s: %ld\n", 896 + __func__, clk_name, PTR_ERR(clk)); 897 + goto out_unmap; 820 898 } 899 + 900 + if (of_clk_add_provider(node, of_clk_src_simple_get, clk)) { 901 + pr_err("%s: failed to add clock provider for %s\n", 902 + __func__, clk_name); 903 + goto out_unregister; 904 + } 905 + 906 + if (clk_register_clkdev(clk, clk_name, NULL)) { 907 + of_clk_del_provider(node); 908 + goto out_unregister; 909 + } 910 + 911 + return; 912 + out_unregister: 913 + clk_unregister_divider(clk); 914 + 915 + out_unmap: 916 + iounmap(reg); 821 917 } 918 + 919 + static void __init sun4i_ahb_clk_setup(struct device_node *node) 920 + { 921 + sunxi_divider_clk_setup(node, &sun4i_ahb_data); 922 + } 923 + CLK_OF_DECLARE(sun4i_ahb, "allwinner,sun4i-a10-ahb-clk", 924 + sun4i_ahb_clk_setup); 925 + 926 + static void __init sun4i_apb0_clk_setup(struct device_node *node) 927 + { 928 + sunxi_divider_clk_setup(node, &sun4i_apb0_data); 929 + } 930 + CLK_OF_DECLARE(sun4i_apb0, "allwinner,sun4i-a10-apb0-clk", 931 + sun4i_apb0_clk_setup); 932 + 933 + static void __init sun4i_axi_clk_setup(struct device_node *node) 934 + { 935 + sunxi_divider_clk_setup(node, &sun4i_axi_data); 936 + } 937 + CLK_OF_DECLARE(sun4i_axi, "allwinner,sun4i-a10-axi-clk", 938 + sun4i_axi_clk_setup); 939 + 940 + static void __init sun8i_axi_clk_setup(struct device_node *node) 941 + { 942 + sunxi_divider_clk_setup(node, &sun8i_a23_axi_data); 943 + } 944 + CLK_OF_DECLARE(sun8i_axi, "allwinner,sun8i-a23-axi-clk", 945 + sun8i_axi_clk_setup); 822 946 823 947 824 948 ··· 963 975 * |________________________| 964 976 */ 965 977 966 - static void __init sunxi_divs_clk_setup(struct device_node *node, 967 - struct divs_data *data) 978 + static struct clk ** __init sunxi_divs_clk_setup(struct device_node *node, 979 + const struct divs_data *data) 968 980 { 969 981 struct clk_onecell_data *clk_data; 970 982 const char *parent; ··· 985 997 986 998 /* Set up factor clock that we will be dividing */ 987 999 pclk = sunxi_factors_clk_setup(node, data->factors); 1000 + if (!pclk) 1001 + return NULL; 988 1002 parent = __clk_get_name(pclk); 989 1003 990 1004 reg = of_iomap(node, 0); 1005 + if (!reg) { 1006 + pr_err("Could not map registers for divs-clk: %s\n", 1007 + of_node_full_name(node)); 1008 + return NULL; 1009 + } 991 1010 992 1011 clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL); 993 1012 if (!clk_data) 994 - return; 1013 + goto out_unmap; 995 1014 996 1015 clks = kcalloc(ndivs, sizeof(*clks), GFP_KERNEL); 997 1016 if (!clks) ··· 1076 1081 clkflags); 1077 1082 1078 1083 WARN_ON(IS_ERR(clk_data->clks[i])); 1079 - clk_register_clkdev(clks[i], clk_name, NULL); 1080 1084 } 1081 1085 1082 1086 /* Adjust to the real max */ 1083 1087 clk_data->clk_num = i; 1084 1088 1085 - of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); 1089 + if (of_clk_add_provider(node, of_clk_src_onecell_get, clk_data)) { 1090 + pr_err("%s: failed to add clock provider for %s\n", 1091 + __func__, clk_name); 1092 + goto free_gate; 1093 + } 1086 1094 1087 - return; 1088 - 1095 + return clks; 1089 1096 free_gate: 1090 1097 kfree(gate); 1091 1098 free_clks: 1092 1099 kfree(clks); 1093 1100 free_clkdata: 1094 1101 kfree(clk_data); 1102 + out_unmap: 1103 + iounmap(reg); 1104 + return NULL; 1095 1105 } 1096 1106 1097 - 1098 - 1099 - /* Matches for factors clocks */ 1100 - static const struct of_device_id clk_factors_match[] __initconst = { 1101 - {.compatible = "allwinner,sun4i-a10-pll1-clk", .data = &sun4i_pll1_data,}, 1102 - {.compatible = "allwinner,sun6i-a31-pll1-clk", .data = &sun6i_a31_pll1_data,}, 1103 - {.compatible = "allwinner,sun8i-a23-pll1-clk", .data = &sun8i_a23_pll1_data,}, 1104 - {.compatible = "allwinner,sun7i-a20-pll4-clk", .data = &sun7i_a20_pll4_data,}, 1105 - {.compatible = "allwinner,sun5i-a13-ahb-clk", .data = &sun5i_a13_ahb_data,}, 1106 - {.compatible = "allwinner,sun4i-a10-apb1-clk", .data = &sun4i_apb1_data,}, 1107 - {.compatible = "allwinner,sun7i-a20-out-clk", .data = &sun7i_a20_out_data,}, 1108 - {} 1109 - }; 1110 - 1111 - /* Matches for divider clocks */ 1112 - static const struct of_device_id clk_div_match[] __initconst = { 1113 - {.compatible = "allwinner,sun4i-a10-axi-clk", .data = &sun4i_axi_data,}, 1114 - {.compatible = "allwinner,sun8i-a23-axi-clk", .data = &sun8i_a23_axi_data,}, 1115 - {.compatible = "allwinner,sun4i-a10-ahb-clk", .data = &sun4i_ahb_data,}, 1116 - {.compatible = "allwinner,sun4i-a10-apb0-clk", .data = &sun4i_apb0_data,}, 1117 - {} 1118 - }; 1119 - 1120 - /* Matches for divided outputs */ 1121 - static const struct of_device_id clk_divs_match[] __initconst = { 1122 - {.compatible = "allwinner,sun4i-a10-pll5-clk", .data = &pll5_divs_data,}, 1123 - {.compatible = "allwinner,sun4i-a10-pll6-clk", .data = &pll6_divs_data,}, 1124 - {.compatible = "allwinner,sun6i-a31-pll6-clk", .data = &sun6i_a31_pll6_divs_data,}, 1125 - {} 1126 - }; 1127 - 1128 - /* Matches for mux clocks */ 1129 - static const struct of_device_id clk_mux_match[] __initconst = { 1130 - {.compatible = "allwinner,sun4i-a10-cpu-clk", .data = &sun4i_cpu_mux_data,}, 1131 - {.compatible = "allwinner,sun6i-a31-ahb1-mux-clk", .data = &sun6i_a31_ahb1_mux_data,}, 1132 - {.compatible = "allwinner,sun8i-h3-ahb2-clk", .data = &sun8i_h3_ahb2_mux_data,}, 1133 - {} 1134 - }; 1135 - 1136 - 1137 - static void __init of_sunxi_table_clock_setup(const struct of_device_id *clk_match, 1138 - void *function) 1107 + static void __init sun4i_pll5_clk_setup(struct device_node *node) 1139 1108 { 1140 - struct device_node *np; 1141 - const struct div_data *data; 1142 - const struct of_device_id *match; 1143 - void (*setup_function)(struct device_node *, const void *) = function; 1109 + struct clk **clks; 1144 1110 1145 - for_each_matching_node_and_match(np, clk_match, &match) { 1146 - data = match->data; 1147 - setup_function(np, data); 1148 - } 1111 + clks = sunxi_divs_clk_setup(node, &pll5_divs_data); 1112 + if (!clks) 1113 + return; 1114 + 1115 + /* Protect PLL5_DDR */ 1116 + __clk_get(clks[0]); 1117 + clk_prepare_enable(clks[0]); 1149 1118 } 1119 + CLK_OF_DECLARE(sun4i_pll5, "allwinner,sun4i-a10-pll5-clk", 1120 + sun4i_pll5_clk_setup); 1150 1121 1151 - static void __init sunxi_init_clocks(const char *clocks[], int nclocks) 1122 + static void __init sun4i_pll6_clk_setup(struct device_node *node) 1152 1123 { 1153 - unsigned int i; 1154 - 1155 - /* Register divided output clocks */ 1156 - of_sunxi_table_clock_setup(clk_divs_match, sunxi_divs_clk_setup); 1157 - 1158 - /* Register factor clocks */ 1159 - of_sunxi_table_clock_setup(clk_factors_match, sunxi_factors_clk_setup); 1160 - 1161 - /* Register divider clocks */ 1162 - of_sunxi_table_clock_setup(clk_div_match, sunxi_divider_clk_setup); 1163 - 1164 - /* Register mux clocks */ 1165 - of_sunxi_table_clock_setup(clk_mux_match, sunxi_mux_clk_setup); 1166 - 1167 - /* Protect the clocks that needs to stay on */ 1168 - for (i = 0; i < nclocks; i++) { 1169 - struct clk *clk = clk_get(NULL, clocks[i]); 1170 - 1171 - if (!IS_ERR(clk)) 1172 - clk_prepare_enable(clk); 1173 - } 1124 + sunxi_divs_clk_setup(node, &pll6_divs_data); 1174 1125 } 1126 + CLK_OF_DECLARE(sun4i_pll6, "allwinner,sun4i-a10-pll6-clk", 1127 + sun4i_pll6_clk_setup); 1175 1128 1176 - static const char *sun4i_a10_critical_clocks[] __initdata = { 1177 - "pll5_ddr", 1178 - }; 1179 - 1180 - static void __init sun4i_a10_init_clocks(struct device_node *node) 1129 + static void __init sun6i_pll6_clk_setup(struct device_node *node) 1181 1130 { 1182 - sunxi_init_clocks(sun4i_a10_critical_clocks, 1183 - ARRAY_SIZE(sun4i_a10_critical_clocks)); 1131 + sunxi_divs_clk_setup(node, &sun6i_a31_pll6_divs_data); 1184 1132 } 1185 - CLK_OF_DECLARE(sun4i_a10_clk_init, "allwinner,sun4i-a10", sun4i_a10_init_clocks); 1186 - 1187 - static const char *sun5i_critical_clocks[] __initdata = { 1188 - "cpu", 1189 - "pll5_ddr", 1190 - }; 1191 - 1192 - static void __init sun5i_init_clocks(struct device_node *node) 1193 - { 1194 - sunxi_init_clocks(sun5i_critical_clocks, 1195 - ARRAY_SIZE(sun5i_critical_clocks)); 1196 - } 1197 - CLK_OF_DECLARE(sun5i_a10s_clk_init, "allwinner,sun5i-a10s", sun5i_init_clocks); 1198 - CLK_OF_DECLARE(sun5i_a13_clk_init, "allwinner,sun5i-a13", sun5i_init_clocks); 1199 - CLK_OF_DECLARE(sun5i_r8_clk_init, "allwinner,sun5i-r8", sun5i_init_clocks); 1200 - CLK_OF_DECLARE(sun7i_a20_clk_init, "allwinner,sun7i-a20", sun5i_init_clocks); 1201 - 1202 - static const char *sun6i_critical_clocks[] __initdata = { 1203 - "cpu", 1204 - }; 1205 - 1206 - static void __init sun6i_init_clocks(struct device_node *node) 1207 - { 1208 - sunxi_init_clocks(sun6i_critical_clocks, 1209 - ARRAY_SIZE(sun6i_critical_clocks)); 1210 - } 1211 - CLK_OF_DECLARE(sun6i_a31_clk_init, "allwinner,sun6i-a31", sun6i_init_clocks); 1212 - CLK_OF_DECLARE(sun6i_a31s_clk_init, "allwinner,sun6i-a31s", sun6i_init_clocks); 1213 - CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks); 1214 - CLK_OF_DECLARE(sun8i_a33_clk_init, "allwinner,sun8i-a33", sun6i_init_clocks); 1215 - CLK_OF_DECLARE(sun8i_h3_clk_init, "allwinner,sun8i-h3", sun6i_init_clocks); 1216 - 1217 - static void __init sun9i_init_clocks(struct device_node *node) 1218 - { 1219 - sunxi_init_clocks(NULL, 0); 1220 - } 1221 - CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80", sun9i_init_clocks); 1133 + CLK_OF_DECLARE(sun6i_pll6, "allwinner,sun6i-a31-pll6-clk", 1134 + sun6i_pll6_clk_setup);
+12 -12
drivers/clk/sunxi/clk-usb.c
··· 216 216 } 217 217 CLK_OF_DECLARE(sun8i_a23_usb, "allwinner,sun8i-a23-usb-clk", sun8i_a23_usb_setup); 218 218 219 + static const struct usb_clk_data sun8i_h3_usb_clk_data __initconst = { 220 + .clk_mask = BIT(19) | BIT(18) | BIT(17) | BIT(16) | 221 + BIT(11) | BIT(10) | BIT(9) | BIT(8), 222 + .reset_mask = BIT(3) | BIT(2) | BIT(1) | BIT(0), 223 + }; 224 + 225 + static void __init sun8i_h3_usb_setup(struct device_node *node) 226 + { 227 + sunxi_usb_clk_setup(node, &sun8i_h3_usb_clk_data, &sun4i_a10_usb_lock); 228 + } 229 + CLK_OF_DECLARE(sun8i_h3_usb, "allwinner,sun8i-h3-usb-clk", sun8i_h3_usb_setup); 230 + 219 231 static const struct usb_clk_data sun9i_a80_usb_mod_data __initconst = { 220 232 .clk_mask = BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1), 221 233 .reset_mask = BIT(19) | BIT(18) | BIT(17), ··· 255 243 sunxi_usb_clk_setup(node, &sun9i_a80_usb_phy_data, &a80_usb_phy_lock); 256 244 } 257 245 CLK_OF_DECLARE(sun9i_a80_usb_phy, "allwinner,sun9i-a80-usb-phy-clk", sun9i_a80_usb_phy_setup); 258 - 259 - static const struct usb_clk_data sun8i_h3_usb_clk_data __initconst = { 260 - .clk_mask = BIT(19) | BIT(18) | BIT(17) | BIT(16) | 261 - BIT(11) | BIT(10) | BIT(9) | BIT(8), 262 - .reset_mask = BIT(3) | BIT(2) | BIT(1) | BIT(0), 263 - }; 264 - 265 - static void __init sun8i_h3_usb_setup(struct device_node *node) 266 - { 267 - sunxi_usb_clk_setup(node, &sun8i_h3_usb_clk_data, &sun4i_a10_usb_lock); 268 - } 269 - CLK_OF_DECLARE(sun8i_h3_usb, "allwinner,sun8i-h3-usb-clk", sun8i_h3_usb_setup);