Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * clkgen-mux.c: ST GEN-MUX Clock driver |
| 3 | * |
| 4 | * Copyright (C) 2014 STMicroelectronics (R&D) Limited |
| 5 | * |
| 6 | * Authors: Stephen Gallimore <stephen.gallimore@st.com> |
| 7 | * Pankaj Dev <pankaj.dev@st.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/of_address.h> |
| 18 | #include <linux/clk-provider.h> |
| 19 | |
| 20 | static DEFINE_SPINLOCK(clkgena_divmux_lock); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 21 | static DEFINE_SPINLOCK(clkgenf_lock); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 22 | |
| 23 | static const char ** __init clkgen_mux_get_parents(struct device_node *np, |
| 24 | int *num_parents) |
| 25 | { |
| 26 | const char **parents; |
| 27 | int nparents, i; |
| 28 | |
Geert Uytterhoeven | 0a65239 | 2015-05-29 11:25:46 +0200 | [diff] [blame] | 29 | nparents = of_clk_get_parent_count(np); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 30 | if (WARN_ON(nparents <= 0)) |
| 31 | return ERR_PTR(-EINVAL); |
| 32 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 33 | parents = kcalloc(nparents, sizeof(const char *), GFP_KERNEL); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 34 | if (!parents) |
| 35 | return ERR_PTR(-ENOMEM); |
| 36 | |
| 37 | for (i = 0; i < nparents; i++) |
| 38 | parents[i] = of_clk_get_parent_name(np, i); |
| 39 | |
| 40 | *num_parents = nparents; |
| 41 | return parents; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * DOC: Clock mux with a programmable divider on each of its three inputs. |
| 46 | * The mux has an input setting which effectively gates its output. |
| 47 | * |
| 48 | * Traits of this clock: |
| 49 | * prepare - clk_(un)prepare only ensures parent is (un)prepared |
| 50 | * enable - clk_enable and clk_disable are functional & control gating |
| 51 | * rate - set rate is supported |
| 52 | * parent - set/get parent |
| 53 | */ |
| 54 | |
| 55 | #define NUM_INPUTS 3 |
| 56 | |
| 57 | struct clkgena_divmux { |
| 58 | struct clk_hw hw; |
| 59 | /* Subclassed mux and divider structures */ |
| 60 | struct clk_mux mux; |
| 61 | struct clk_divider div[NUM_INPUTS]; |
| 62 | /* Enable/running feedback register bits for each input */ |
| 63 | void __iomem *feedback_reg[NUM_INPUTS]; |
| 64 | int feedback_bit_idx; |
| 65 | |
| 66 | u8 muxsel; |
| 67 | }; |
| 68 | |
| 69 | #define to_clkgena_divmux(_hw) container_of(_hw, struct clkgena_divmux, hw) |
| 70 | |
| 71 | struct clkgena_divmux_data { |
| 72 | int num_outputs; |
| 73 | int mux_offset; |
| 74 | int mux_offset2; |
| 75 | int mux_start_bit; |
| 76 | int div_offsets[NUM_INPUTS]; |
| 77 | int fb_offsets[NUM_INPUTS]; |
| 78 | int fb_start_bit_idx; |
| 79 | }; |
| 80 | |
| 81 | #define CKGAX_CLKOPSRC_SWITCH_OFF 0x3 |
| 82 | |
| 83 | static int clkgena_divmux_is_running(struct clkgena_divmux *mux) |
| 84 | { |
| 85 | u32 regval = readl(mux->feedback_reg[mux->muxsel]); |
| 86 | u32 running = regval & BIT(mux->feedback_bit_idx); |
| 87 | return !!running; |
| 88 | } |
| 89 | |
| 90 | static int clkgena_divmux_enable(struct clk_hw *hw) |
| 91 | { |
| 92 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 93 | struct clk_hw *mux_hw = &genamux->mux.hw; |
| 94 | unsigned long timeout; |
| 95 | int ret = 0; |
| 96 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 97 | __clk_hw_set_clk(mux_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 98 | |
| 99 | ret = clk_mux_ops.set_parent(mux_hw, genamux->muxsel); |
| 100 | if (ret) |
| 101 | return ret; |
| 102 | |
| 103 | timeout = jiffies + msecs_to_jiffies(10); |
| 104 | |
| 105 | while (!clkgena_divmux_is_running(genamux)) { |
| 106 | if (time_after(jiffies, timeout)) |
| 107 | return -ETIMEDOUT; |
| 108 | cpu_relax(); |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static void clkgena_divmux_disable(struct clk_hw *hw) |
| 115 | { |
| 116 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 117 | struct clk_hw *mux_hw = &genamux->mux.hw; |
| 118 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 119 | __clk_hw_set_clk(mux_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 120 | |
| 121 | clk_mux_ops.set_parent(mux_hw, CKGAX_CLKOPSRC_SWITCH_OFF); |
| 122 | } |
| 123 | |
| 124 | static int clkgena_divmux_is_enabled(struct clk_hw *hw) |
| 125 | { |
| 126 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 127 | struct clk_hw *mux_hw = &genamux->mux.hw; |
| 128 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 129 | __clk_hw_set_clk(mux_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 130 | |
| 131 | return (s8)clk_mux_ops.get_parent(mux_hw) > 0; |
| 132 | } |
| 133 | |
Stephen Boyd | 8e6dd77 | 2015-05-01 12:45:53 -0700 | [diff] [blame] | 134 | static u8 clkgena_divmux_get_parent(struct clk_hw *hw) |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 135 | { |
| 136 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 137 | struct clk_hw *mux_hw = &genamux->mux.hw; |
| 138 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 139 | __clk_hw_set_clk(mux_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 140 | |
| 141 | genamux->muxsel = clk_mux_ops.get_parent(mux_hw); |
| 142 | if ((s8)genamux->muxsel < 0) { |
| 143 | pr_debug("%s: %s: Invalid parent, setting to default.\n", |
| 144 | __func__, __clk_get_name(hw->clk)); |
| 145 | genamux->muxsel = 0; |
| 146 | } |
| 147 | |
| 148 | return genamux->muxsel; |
| 149 | } |
| 150 | |
| 151 | static int clkgena_divmux_set_parent(struct clk_hw *hw, u8 index) |
| 152 | { |
| 153 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 154 | |
| 155 | if (index >= CKGAX_CLKOPSRC_SWITCH_OFF) |
| 156 | return -EINVAL; |
| 157 | |
| 158 | genamux->muxsel = index; |
| 159 | |
| 160 | /* |
| 161 | * If the mux is already enabled, call enable directly to set the |
| 162 | * new mux position and wait for it to start running again. Otherwise |
| 163 | * do nothing. |
| 164 | */ |
| 165 | if (clkgena_divmux_is_enabled(hw)) |
| 166 | clkgena_divmux_enable(hw); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Stephen Boyd | 8e6dd77 | 2015-05-01 12:45:53 -0700 | [diff] [blame] | 171 | static unsigned long clkgena_divmux_recalc_rate(struct clk_hw *hw, |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 172 | unsigned long parent_rate) |
| 173 | { |
| 174 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 175 | struct clk_hw *div_hw = &genamux->div[genamux->muxsel].hw; |
| 176 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 177 | __clk_hw_set_clk(div_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 178 | |
| 179 | return clk_divider_ops.recalc_rate(div_hw, parent_rate); |
| 180 | } |
| 181 | |
| 182 | static int clkgena_divmux_set_rate(struct clk_hw *hw, unsigned long rate, |
| 183 | unsigned long parent_rate) |
| 184 | { |
| 185 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 186 | struct clk_hw *div_hw = &genamux->div[genamux->muxsel].hw; |
| 187 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 188 | __clk_hw_set_clk(div_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 189 | |
| 190 | return clk_divider_ops.set_rate(div_hw, rate, parent_rate); |
| 191 | } |
| 192 | |
| 193 | static long clkgena_divmux_round_rate(struct clk_hw *hw, unsigned long rate, |
| 194 | unsigned long *prate) |
| 195 | { |
| 196 | struct clkgena_divmux *genamux = to_clkgena_divmux(hw); |
| 197 | struct clk_hw *div_hw = &genamux->div[genamux->muxsel].hw; |
| 198 | |
Javier Martinez Canillas | 4e907ef | 2015-02-12 14:58:30 +0100 | [diff] [blame] | 199 | __clk_hw_set_clk(div_hw, hw); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 200 | |
| 201 | return clk_divider_ops.round_rate(div_hw, rate, prate); |
| 202 | } |
| 203 | |
| 204 | static const struct clk_ops clkgena_divmux_ops = { |
| 205 | .enable = clkgena_divmux_enable, |
| 206 | .disable = clkgena_divmux_disable, |
| 207 | .is_enabled = clkgena_divmux_is_enabled, |
| 208 | .get_parent = clkgena_divmux_get_parent, |
| 209 | .set_parent = clkgena_divmux_set_parent, |
| 210 | .round_rate = clkgena_divmux_round_rate, |
| 211 | .recalc_rate = clkgena_divmux_recalc_rate, |
| 212 | .set_rate = clkgena_divmux_set_rate, |
| 213 | }; |
| 214 | |
| 215 | /** |
| 216 | * clk_register_genamux - register a genamux clock with the clock framework |
| 217 | */ |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 218 | static struct clk * __init clk_register_genamux(const char *name, |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 219 | const char **parent_names, u8 num_parents, |
| 220 | void __iomem *reg, |
| 221 | const struct clkgena_divmux_data *muxdata, |
| 222 | u32 idx) |
| 223 | { |
| 224 | /* |
| 225 | * Fixed constants across all ClockgenA variants |
| 226 | */ |
| 227 | const int mux_width = 2; |
| 228 | const int divider_width = 5; |
| 229 | struct clkgena_divmux *genamux; |
| 230 | struct clk *clk; |
| 231 | struct clk_init_data init; |
| 232 | int i; |
| 233 | |
| 234 | genamux = kzalloc(sizeof(*genamux), GFP_KERNEL); |
| 235 | if (!genamux) |
| 236 | return ERR_PTR(-ENOMEM); |
| 237 | |
| 238 | init.name = name; |
| 239 | init.ops = &clkgena_divmux_ops; |
Pankaj Dev | 18fee45 | 2015-06-23 16:09:24 +0200 | [diff] [blame] | 240 | init.flags = CLK_IS_BASIC | CLK_GET_RATE_NOCACHE; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 241 | init.parent_names = parent_names; |
| 242 | init.num_parents = num_parents; |
| 243 | |
| 244 | genamux->mux.lock = &clkgena_divmux_lock; |
| 245 | genamux->mux.mask = BIT(mux_width) - 1; |
| 246 | genamux->mux.shift = muxdata->mux_start_bit + (idx * mux_width); |
| 247 | if (genamux->mux.shift > 31) { |
| 248 | /* |
| 249 | * We have spilled into the second mux register so |
| 250 | * adjust the register address and the bit shift accordingly |
| 251 | */ |
| 252 | genamux->mux.reg = reg + muxdata->mux_offset2; |
| 253 | genamux->mux.shift -= 32; |
| 254 | } else { |
| 255 | genamux->mux.reg = reg + muxdata->mux_offset; |
| 256 | } |
| 257 | |
| 258 | for (i = 0; i < NUM_INPUTS; i++) { |
| 259 | /* |
| 260 | * Divider config for each input |
| 261 | */ |
| 262 | void __iomem *divbase = reg + muxdata->div_offsets[i]; |
| 263 | genamux->div[i].width = divider_width; |
| 264 | genamux->div[i].reg = divbase + (idx * sizeof(u32)); |
| 265 | |
| 266 | /* |
| 267 | * Mux enabled/running feedback register for each input. |
| 268 | */ |
| 269 | genamux->feedback_reg[i] = reg + muxdata->fb_offsets[i]; |
| 270 | } |
| 271 | |
| 272 | genamux->feedback_bit_idx = muxdata->fb_start_bit_idx + idx; |
| 273 | genamux->hw.init = &init; |
| 274 | |
| 275 | clk = clk_register(NULL, &genamux->hw); |
| 276 | if (IS_ERR(clk)) { |
| 277 | kfree(genamux); |
| 278 | goto err; |
| 279 | } |
| 280 | |
| 281 | pr_debug("%s: parent %s rate %lu\n", |
| 282 | __clk_get_name(clk), |
| 283 | __clk_get_name(clk_get_parent(clk)), |
| 284 | clk_get_rate(clk)); |
| 285 | err: |
| 286 | return clk; |
| 287 | } |
| 288 | |
| 289 | static struct clkgena_divmux_data st_divmux_c65hs = { |
| 290 | .num_outputs = 4, |
| 291 | .mux_offset = 0x14, |
| 292 | .mux_start_bit = 0, |
| 293 | .div_offsets = { 0x800, 0x900, 0xb00 }, |
| 294 | .fb_offsets = { 0x18, 0x1c, 0x20 }, |
| 295 | .fb_start_bit_idx = 0, |
| 296 | }; |
| 297 | |
| 298 | static struct clkgena_divmux_data st_divmux_c65ls = { |
| 299 | .num_outputs = 14, |
| 300 | .mux_offset = 0x14, |
| 301 | .mux_offset2 = 0x24, |
| 302 | .mux_start_bit = 8, |
| 303 | .div_offsets = { 0x810, 0xa10, 0xb10 }, |
| 304 | .fb_offsets = { 0x18, 0x1c, 0x20 }, |
| 305 | .fb_start_bit_idx = 4, |
| 306 | }; |
| 307 | |
| 308 | static struct clkgena_divmux_data st_divmux_c32odf0 = { |
| 309 | .num_outputs = 8, |
| 310 | .mux_offset = 0x1c, |
| 311 | .mux_start_bit = 0, |
| 312 | .div_offsets = { 0x800, 0x900, 0xa60 }, |
| 313 | .fb_offsets = { 0x2c, 0x24, 0x28 }, |
| 314 | .fb_start_bit_idx = 0, |
| 315 | }; |
| 316 | |
| 317 | static struct clkgena_divmux_data st_divmux_c32odf1 = { |
| 318 | .num_outputs = 8, |
| 319 | .mux_offset = 0x1c, |
| 320 | .mux_start_bit = 16, |
| 321 | .div_offsets = { 0x820, 0x980, 0xa80 }, |
| 322 | .fb_offsets = { 0x2c, 0x24, 0x28 }, |
| 323 | .fb_start_bit_idx = 8, |
| 324 | }; |
| 325 | |
| 326 | static struct clkgena_divmux_data st_divmux_c32odf2 = { |
| 327 | .num_outputs = 8, |
| 328 | .mux_offset = 0x20, |
| 329 | .mux_start_bit = 0, |
| 330 | .div_offsets = { 0x840, 0xa20, 0xb10 }, |
| 331 | .fb_offsets = { 0x2c, 0x24, 0x28 }, |
| 332 | .fb_start_bit_idx = 16, |
| 333 | }; |
| 334 | |
| 335 | static struct clkgena_divmux_data st_divmux_c32odf3 = { |
| 336 | .num_outputs = 8, |
| 337 | .mux_offset = 0x20, |
| 338 | .mux_start_bit = 16, |
| 339 | .div_offsets = { 0x860, 0xa40, 0xb30 }, |
| 340 | .fb_offsets = { 0x2c, 0x24, 0x28 }, |
| 341 | .fb_start_bit_idx = 24, |
| 342 | }; |
| 343 | |
Fabian Frederick | f375573 | 2015-03-31 20:50:42 +0200 | [diff] [blame] | 344 | static const struct of_device_id clkgena_divmux_of_match[] = { |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 345 | { |
| 346 | .compatible = "st,clkgena-divmux-c65-hs", |
| 347 | .data = &st_divmux_c65hs, |
| 348 | }, |
| 349 | { |
| 350 | .compatible = "st,clkgena-divmux-c65-ls", |
| 351 | .data = &st_divmux_c65ls, |
| 352 | }, |
| 353 | { |
| 354 | .compatible = "st,clkgena-divmux-c32-odf0", |
| 355 | .data = &st_divmux_c32odf0, |
| 356 | }, |
| 357 | { |
| 358 | .compatible = "st,clkgena-divmux-c32-odf1", |
| 359 | .data = &st_divmux_c32odf1, |
| 360 | }, |
| 361 | { |
| 362 | .compatible = "st,clkgena-divmux-c32-odf2", |
| 363 | .data = &st_divmux_c32odf2, |
| 364 | }, |
| 365 | { |
| 366 | .compatible = "st,clkgena-divmux-c32-odf3", |
| 367 | .data = &st_divmux_c32odf3, |
| 368 | }, |
| 369 | {} |
| 370 | }; |
| 371 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 372 | static void __iomem * __init clkgen_get_register_base(struct device_node *np) |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 373 | { |
| 374 | struct device_node *pnode; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 375 | void __iomem *reg; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 376 | |
| 377 | pnode = of_get_parent(np); |
| 378 | if (!pnode) |
| 379 | return NULL; |
| 380 | |
| 381 | reg = of_iomap(pnode, 0); |
| 382 | |
| 383 | of_node_put(pnode); |
| 384 | return reg; |
| 385 | } |
| 386 | |
Stephen Boyd | 8e6dd77 | 2015-05-01 12:45:53 -0700 | [diff] [blame] | 387 | static void __init st_of_clkgena_divmux_setup(struct device_node *np) |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 388 | { |
| 389 | const struct of_device_id *match; |
| 390 | const struct clkgena_divmux_data *data; |
| 391 | struct clk_onecell_data *clk_data; |
| 392 | void __iomem *reg; |
| 393 | const char **parents; |
| 394 | int num_parents = 0, i; |
| 395 | |
| 396 | match = of_match_node(clkgena_divmux_of_match, np); |
| 397 | if (WARN_ON(!match)) |
| 398 | return; |
| 399 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 400 | data = match->data; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 401 | |
| 402 | reg = clkgen_get_register_base(np); |
| 403 | if (!reg) |
| 404 | return; |
| 405 | |
| 406 | parents = clkgen_mux_get_parents(np, &num_parents); |
| 407 | if (IS_ERR(parents)) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 408 | goto err_parents; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 409 | |
| 410 | clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); |
| 411 | if (!clk_data) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 412 | goto err_alloc; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 413 | |
| 414 | clk_data->clk_num = data->num_outputs; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 415 | clk_data->clks = kcalloc(clk_data->clk_num, sizeof(struct clk *), |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 416 | GFP_KERNEL); |
| 417 | |
| 418 | if (!clk_data->clks) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 419 | goto err_alloc_clks; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 420 | |
| 421 | for (i = 0; i < clk_data->clk_num; i++) { |
| 422 | struct clk *clk; |
| 423 | const char *clk_name; |
| 424 | |
| 425 | if (of_property_read_string_index(np, "clock-output-names", |
| 426 | i, &clk_name)) |
| 427 | break; |
| 428 | |
| 429 | /* |
| 430 | * If we read an empty clock name then the output is unused |
| 431 | */ |
| 432 | if (*clk_name == '\0') |
| 433 | continue; |
| 434 | |
| 435 | clk = clk_register_genamux(clk_name, parents, num_parents, |
| 436 | reg, data, i); |
| 437 | |
| 438 | if (IS_ERR(clk)) |
| 439 | goto err; |
| 440 | |
| 441 | clk_data->clks[i] = clk; |
| 442 | } |
| 443 | |
| 444 | kfree(parents); |
| 445 | |
| 446 | of_clk_add_provider(np, of_clk_src_onecell_get, clk_data); |
| 447 | return; |
| 448 | err: |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 449 | kfree(clk_data->clks); |
| 450 | err_alloc_clks: |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 451 | kfree(clk_data); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 452 | err_alloc: |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 453 | kfree(parents); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 454 | err_parents: |
| 455 | iounmap(reg); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 456 | } |
| 457 | CLK_OF_DECLARE(clkgenadivmux, "st,clkgena-divmux", st_of_clkgena_divmux_setup); |
| 458 | |
| 459 | struct clkgena_prediv_data { |
| 460 | u32 offset; |
| 461 | u8 shift; |
| 462 | struct clk_div_table *table; |
| 463 | }; |
| 464 | |
| 465 | static struct clk_div_table prediv_table16[] = { |
| 466 | { .val = 0, .div = 1 }, |
| 467 | { .val = 1, .div = 16 }, |
| 468 | { .div = 0 }, |
| 469 | }; |
| 470 | |
| 471 | static struct clkgena_prediv_data prediv_c65_data = { |
| 472 | .offset = 0x4c, |
| 473 | .shift = 31, |
| 474 | .table = prediv_table16, |
| 475 | }; |
| 476 | |
| 477 | static struct clkgena_prediv_data prediv_c32_data = { |
| 478 | .offset = 0x50, |
| 479 | .shift = 1, |
| 480 | .table = prediv_table16, |
| 481 | }; |
| 482 | |
Fabian Frederick | f375573 | 2015-03-31 20:50:42 +0200 | [diff] [blame] | 483 | static const struct of_device_id clkgena_prediv_of_match[] = { |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 484 | { .compatible = "st,clkgena-prediv-c65", .data = &prediv_c65_data }, |
| 485 | { .compatible = "st,clkgena-prediv-c32", .data = &prediv_c32_data }, |
| 486 | {} |
| 487 | }; |
| 488 | |
Stephen Boyd | 8e6dd77 | 2015-05-01 12:45:53 -0700 | [diff] [blame] | 489 | static void __init st_of_clkgena_prediv_setup(struct device_node *np) |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 490 | { |
| 491 | const struct of_device_id *match; |
| 492 | void __iomem *reg; |
| 493 | const char *parent_name, *clk_name; |
| 494 | struct clk *clk; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 495 | const struct clkgena_prediv_data *data; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 496 | |
| 497 | match = of_match_node(clkgena_prediv_of_match, np); |
| 498 | if (!match) { |
| 499 | pr_err("%s: No matching data\n", __func__); |
| 500 | return; |
| 501 | } |
| 502 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 503 | data = match->data; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 504 | |
| 505 | reg = clkgen_get_register_base(np); |
| 506 | if (!reg) |
| 507 | return; |
| 508 | |
| 509 | parent_name = of_clk_get_parent_name(np, 0); |
| 510 | if (!parent_name) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 511 | goto err; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 512 | |
| 513 | if (of_property_read_string_index(np, "clock-output-names", |
| 514 | 0, &clk_name)) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 515 | goto err; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 516 | |
Pankaj Dev | 18fee45 | 2015-06-23 16:09:24 +0200 | [diff] [blame] | 517 | clk = clk_register_divider_table(NULL, clk_name, parent_name, |
| 518 | CLK_GET_RATE_NOCACHE, |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 519 | reg + data->offset, data->shift, 1, |
| 520 | 0, data->table, NULL); |
| 521 | if (IS_ERR(clk)) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 522 | goto err; |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 523 | |
| 524 | of_clk_add_provider(np, of_clk_src_simple_get, clk); |
| 525 | pr_debug("%s: parent %s rate %u\n", |
| 526 | __clk_get_name(clk), |
| 527 | __clk_get_name(clk_get_parent(clk)), |
| 528 | (unsigned int)clk_get_rate(clk)); |
| 529 | |
| 530 | return; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 531 | err: |
| 532 | iounmap(reg); |
Gabriel FERNANDEZ | 94885fa | 2014-02-27 16:24:14 +0100 | [diff] [blame] | 533 | } |
| 534 | CLK_OF_DECLARE(clkgenaprediv, "st,clkgena-prediv", st_of_clkgena_prediv_setup); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 535 | |
| 536 | struct clkgen_mux_data { |
| 537 | u32 offset; |
| 538 | u8 shift; |
| 539 | u8 width; |
| 540 | spinlock_t *lock; |
| 541 | unsigned long clk_flags; |
| 542 | u8 mux_flags; |
| 543 | }; |
| 544 | |
| 545 | static struct clkgen_mux_data clkgen_mux_c_vcc_hd_416 = { |
| 546 | .offset = 0, |
| 547 | .shift = 0, |
| 548 | .width = 1, |
| 549 | }; |
| 550 | |
| 551 | static struct clkgen_mux_data clkgen_mux_f_vcc_fvdp_416 = { |
| 552 | .offset = 0, |
| 553 | .shift = 0, |
| 554 | .width = 1, |
| 555 | }; |
| 556 | |
| 557 | static struct clkgen_mux_data clkgen_mux_f_vcc_hva_416 = { |
| 558 | .offset = 0, |
| 559 | .shift = 0, |
| 560 | .width = 1, |
| 561 | }; |
| 562 | |
| 563 | static struct clkgen_mux_data clkgen_mux_f_vcc_hd_416 = { |
| 564 | .offset = 0, |
| 565 | .shift = 16, |
| 566 | .width = 1, |
| 567 | .lock = &clkgenf_lock, |
| 568 | }; |
| 569 | |
| 570 | static struct clkgen_mux_data clkgen_mux_c_vcc_sd_416 = { |
| 571 | .offset = 0, |
| 572 | .shift = 17, |
| 573 | .width = 1, |
| 574 | .lock = &clkgenf_lock, |
| 575 | }; |
| 576 | |
Gabriel FERNANDEZ | ab35dc1 | 2014-02-27 16:24:19 +0100 | [diff] [blame] | 577 | static struct clkgen_mux_data stih415_a9_mux_data = { |
| 578 | .offset = 0, |
| 579 | .shift = 1, |
| 580 | .width = 2, |
| 581 | }; |
| 582 | static struct clkgen_mux_data stih416_a9_mux_data = { |
| 583 | .offset = 0, |
| 584 | .shift = 0, |
| 585 | .width = 2, |
| 586 | }; |
Gabriel FERNANDEZ | 13e6f2d | 2014-07-15 17:20:23 +0200 | [diff] [blame] | 587 | static struct clkgen_mux_data stih407_a9_mux_data = { |
| 588 | .offset = 0x1a4, |
Gabriel Fernandez | 3be6d8c | 2015-06-23 16:09:25 +0200 | [diff] [blame] | 589 | .shift = 0, |
Gabriel FERNANDEZ | 13e6f2d | 2014-07-15 17:20:23 +0200 | [diff] [blame] | 590 | .width = 2, |
| 591 | }; |
Gabriel FERNANDEZ | ab35dc1 | 2014-02-27 16:24:19 +0100 | [diff] [blame] | 592 | |
Fabian Frederick | f375573 | 2015-03-31 20:50:42 +0200 | [diff] [blame] | 593 | static const struct of_device_id mux_of_match[] = { |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 594 | { |
| 595 | .compatible = "st,stih416-clkgenc-vcc-hd", |
| 596 | .data = &clkgen_mux_c_vcc_hd_416, |
| 597 | }, |
| 598 | { |
| 599 | .compatible = "st,stih416-clkgenf-vcc-fvdp", |
| 600 | .data = &clkgen_mux_f_vcc_fvdp_416, |
| 601 | }, |
| 602 | { |
| 603 | .compatible = "st,stih416-clkgenf-vcc-hva", |
| 604 | .data = &clkgen_mux_f_vcc_hva_416, |
| 605 | }, |
| 606 | { |
| 607 | .compatible = "st,stih416-clkgenf-vcc-hd", |
| 608 | .data = &clkgen_mux_f_vcc_hd_416, |
| 609 | }, |
| 610 | { |
| 611 | .compatible = "st,stih416-clkgenf-vcc-sd", |
| 612 | .data = &clkgen_mux_c_vcc_sd_416, |
| 613 | }, |
Gabriel FERNANDEZ | ab35dc1 | 2014-02-27 16:24:19 +0100 | [diff] [blame] | 614 | { |
| 615 | .compatible = "st,stih415-clkgen-a9-mux", |
| 616 | .data = &stih415_a9_mux_data, |
| 617 | }, |
| 618 | { |
| 619 | .compatible = "st,stih416-clkgen-a9-mux", |
| 620 | .data = &stih416_a9_mux_data, |
| 621 | }, |
Gabriel FERNANDEZ | 13e6f2d | 2014-07-15 17:20:23 +0200 | [diff] [blame] | 622 | { |
| 623 | .compatible = "st,stih407-clkgen-a9-mux", |
| 624 | .data = &stih407_a9_mux_data, |
| 625 | }, |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 626 | {} |
| 627 | }; |
| 628 | |
Stephen Boyd | 8e6dd77 | 2015-05-01 12:45:53 -0700 | [diff] [blame] | 629 | static void __init st_of_clkgen_mux_setup(struct device_node *np) |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 630 | { |
| 631 | const struct of_device_id *match; |
| 632 | struct clk *clk; |
| 633 | void __iomem *reg; |
| 634 | const char **parents; |
| 635 | int num_parents; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 636 | const struct clkgen_mux_data *data; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 637 | |
| 638 | match = of_match_node(mux_of_match, np); |
| 639 | if (!match) { |
| 640 | pr_err("%s: No matching data\n", __func__); |
| 641 | return; |
| 642 | } |
| 643 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 644 | data = match->data; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 645 | |
| 646 | reg = of_iomap(np, 0); |
| 647 | if (!reg) { |
| 648 | pr_err("%s: Failed to get base address\n", __func__); |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | parents = clkgen_mux_get_parents(np, &num_parents); |
| 653 | if (IS_ERR(parents)) { |
| 654 | pr_err("%s: Failed to get parents (%ld)\n", |
| 655 | __func__, PTR_ERR(parents)); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 656 | goto err_parents; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | clk = clk_register_mux(NULL, np->name, parents, num_parents, |
| 660 | data->clk_flags | CLK_SET_RATE_PARENT, |
| 661 | reg + data->offset, |
| 662 | data->shift, data->width, data->mux_flags, |
| 663 | data->lock); |
| 664 | if (IS_ERR(clk)) |
| 665 | goto err; |
| 666 | |
| 667 | pr_debug("%s: parent %s rate %u\n", |
| 668 | __clk_get_name(clk), |
| 669 | __clk_get_name(clk_get_parent(clk)), |
| 670 | (unsigned int)clk_get_rate(clk)); |
| 671 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 672 | kfree(parents); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 673 | of_clk_add_provider(np, of_clk_src_simple_get, clk); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 674 | return; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 675 | |
| 676 | err: |
| 677 | kfree(parents); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 678 | err_parents: |
| 679 | iounmap(reg); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 680 | } |
| 681 | CLK_OF_DECLARE(clkgen_mux, "st,clkgen-mux", st_of_clkgen_mux_setup); |
| 682 | |
| 683 | #define VCC_MAX_CHANNELS 16 |
| 684 | |
| 685 | #define VCC_GATE_OFFSET 0x0 |
| 686 | #define VCC_MUX_OFFSET 0x4 |
| 687 | #define VCC_DIV_OFFSET 0x8 |
| 688 | |
| 689 | struct clkgen_vcc_data { |
| 690 | spinlock_t *lock; |
| 691 | unsigned long clk_flags; |
| 692 | }; |
| 693 | |
| 694 | static struct clkgen_vcc_data st_clkgenc_vcc_416 = { |
| 695 | .clk_flags = CLK_SET_RATE_PARENT, |
| 696 | }; |
| 697 | |
| 698 | static struct clkgen_vcc_data st_clkgenf_vcc_416 = { |
| 699 | .lock = &clkgenf_lock, |
| 700 | }; |
| 701 | |
Fabian Frederick | f375573 | 2015-03-31 20:50:42 +0200 | [diff] [blame] | 702 | static const struct of_device_id vcc_of_match[] = { |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 703 | { .compatible = "st,stih416-clkgenc", .data = &st_clkgenc_vcc_416 }, |
| 704 | { .compatible = "st,stih416-clkgenf", .data = &st_clkgenf_vcc_416 }, |
| 705 | {} |
| 706 | }; |
| 707 | |
Stephen Boyd | 8e6dd77 | 2015-05-01 12:45:53 -0700 | [diff] [blame] | 708 | static void __init st_of_clkgen_vcc_setup(struct device_node *np) |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 709 | { |
| 710 | const struct of_device_id *match; |
| 711 | void __iomem *reg; |
| 712 | const char **parents; |
| 713 | int num_parents, i; |
| 714 | struct clk_onecell_data *clk_data; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 715 | const struct clkgen_vcc_data *data; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 716 | |
| 717 | match = of_match_node(vcc_of_match, np); |
| 718 | if (WARN_ON(!match)) |
| 719 | return; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 720 | data = match->data; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 721 | |
| 722 | reg = of_iomap(np, 0); |
| 723 | if (!reg) |
| 724 | return; |
| 725 | |
| 726 | parents = clkgen_mux_get_parents(np, &num_parents); |
| 727 | if (IS_ERR(parents)) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 728 | goto err_parents; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 729 | |
| 730 | clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); |
| 731 | if (!clk_data) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 732 | goto err_alloc; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 733 | |
| 734 | clk_data->clk_num = VCC_MAX_CHANNELS; |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 735 | clk_data->clks = kcalloc(clk_data->clk_num, sizeof(struct clk *), |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 736 | GFP_KERNEL); |
| 737 | |
| 738 | if (!clk_data->clks) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 739 | goto err_alloc_clks; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 740 | |
| 741 | for (i = 0; i < clk_data->clk_num; i++) { |
| 742 | struct clk *clk; |
| 743 | const char *clk_name; |
| 744 | struct clk_gate *gate; |
| 745 | struct clk_divider *div; |
| 746 | struct clk_mux *mux; |
| 747 | |
| 748 | if (of_property_read_string_index(np, "clock-output-names", |
| 749 | i, &clk_name)) |
| 750 | break; |
| 751 | |
| 752 | /* |
| 753 | * If we read an empty clock name then the output is unused |
| 754 | */ |
| 755 | if (*clk_name == '\0') |
| 756 | continue; |
| 757 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 758 | gate = kzalloc(sizeof(*gate), GFP_KERNEL); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 759 | if (!gate) |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 760 | goto err; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 761 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 762 | div = kzalloc(sizeof(*div), GFP_KERNEL); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 763 | if (!div) { |
| 764 | kfree(gate); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 765 | goto err; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 768 | mux = kzalloc(sizeof(*mux), GFP_KERNEL); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 769 | if (!mux) { |
| 770 | kfree(gate); |
| 771 | kfree(div); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 772 | goto err; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | gate->reg = reg + VCC_GATE_OFFSET; |
| 776 | gate->bit_idx = i; |
| 777 | gate->flags = CLK_GATE_SET_TO_DISABLE; |
| 778 | gate->lock = data->lock; |
| 779 | |
| 780 | div->reg = reg + VCC_DIV_OFFSET; |
| 781 | div->shift = 2 * i; |
| 782 | div->width = 2; |
Gabriel FERNANDEZ | eee40bb | 2014-07-15 17:20:31 +0200 | [diff] [blame] | 783 | div->flags = CLK_DIVIDER_POWER_OF_TWO | |
| 784 | CLK_DIVIDER_ROUND_CLOSEST; |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 785 | |
| 786 | mux->reg = reg + VCC_MUX_OFFSET; |
| 787 | mux->shift = 2 * i; |
| 788 | mux->mask = 0x3; |
| 789 | |
| 790 | clk = clk_register_composite(NULL, clk_name, parents, |
| 791 | num_parents, |
| 792 | &mux->hw, &clk_mux_ops, |
| 793 | &div->hw, &clk_divider_ops, |
| 794 | &gate->hw, &clk_gate_ops, |
Pankaj Dev | 18fee45 | 2015-06-23 16:09:24 +0200 | [diff] [blame] | 795 | data->clk_flags | |
| 796 | CLK_GET_RATE_NOCACHE); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 797 | if (IS_ERR(clk)) { |
| 798 | kfree(gate); |
| 799 | kfree(div); |
| 800 | kfree(mux); |
| 801 | goto err; |
| 802 | } |
| 803 | |
| 804 | pr_debug("%s: parent %s rate %u\n", |
| 805 | __clk_get_name(clk), |
| 806 | __clk_get_name(clk_get_parent(clk)), |
| 807 | (unsigned int)clk_get_rate(clk)); |
| 808 | |
| 809 | clk_data->clks[i] = clk; |
| 810 | } |
| 811 | |
| 812 | kfree(parents); |
| 813 | |
| 814 | of_clk_add_provider(np, of_clk_src_onecell_get, clk_data); |
| 815 | return; |
| 816 | |
| 817 | err: |
| 818 | for (i = 0; i < clk_data->clk_num; i++) { |
| 819 | struct clk_composite *composite; |
| 820 | |
| 821 | if (!clk_data->clks[i]) |
| 822 | continue; |
| 823 | |
| 824 | composite = container_of(__clk_get_hw(clk_data->clks[i]), |
| 825 | struct clk_composite, hw); |
| 826 | kfree(container_of(composite->gate_hw, struct clk_gate, hw)); |
| 827 | kfree(container_of(composite->rate_hw, struct clk_divider, hw)); |
| 828 | kfree(container_of(composite->mux_hw, struct clk_mux, hw)); |
| 829 | } |
| 830 | |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 831 | kfree(clk_data->clks); |
| 832 | err_alloc_clks: |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 833 | kfree(clk_data); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 834 | err_alloc: |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 835 | kfree(parents); |
Stephen Boyd | 86665d2 | 2015-07-07 18:30:05 -0700 | [diff] [blame^] | 836 | err_parents: |
| 837 | iounmap(reg); |
Gabriel FERNANDEZ | 44993d3 | 2014-02-27 16:24:16 +0100 | [diff] [blame] | 838 | } |
| 839 | CLK_OF_DECLARE(clkgen_vcc, "st,clkgen-vcc", st_of_clkgen_vcc_setup); |