sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / clk / st / clkgen-pll.c
blob25bda48a5d35b919f37eb74228a2710d78d4b0b5
1 /*
2 * Copyright (C) 2014 STMicroelectronics (R&D) Limited
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 */
12 * Authors:
13 * Stephen Gallimore <stephen.gallimore@st.com>,
14 * Pankaj Dev <pankaj.dev@st.com>.
17 #include <linux/slab.h>
18 #include <linux/of_address.h>
19 #include <linux/clk.h>
20 #include <linux/clk-provider.h>
21 #include <linux/iopoll.h>
23 #include "clkgen.h"
25 static DEFINE_SPINLOCK(clkgena_c32_odf_lock);
26 DEFINE_SPINLOCK(clkgen_a9_lock);
29 * PLL configuration register bits for PLL3200 C32
31 #define C32_NDIV_MASK (0xff)
32 #define C32_IDF_MASK (0x7)
33 #define C32_ODF_MASK (0x3f)
34 #define C32_LDF_MASK (0x7f)
35 #define C32_CP_MASK (0x1f)
37 #define C32_MAX_ODFS (4)
40 * PLL configuration register bits for PLL4600 C28
42 #define C28_NDIV_MASK (0xff)
43 #define C28_IDF_MASK (0x7)
44 #define C28_ODF_MASK (0x3f)
46 struct clkgen_pll_data {
47 struct clkgen_field pdn_status;
48 struct clkgen_field pdn_ctrl;
49 struct clkgen_field locked_status;
50 struct clkgen_field mdiv;
51 struct clkgen_field ndiv;
52 struct clkgen_field pdiv;
53 struct clkgen_field idf;
54 struct clkgen_field ldf;
55 struct clkgen_field cp;
56 unsigned int num_odfs;
57 struct clkgen_field odf[C32_MAX_ODFS];
58 struct clkgen_field odf_gate[C32_MAX_ODFS];
59 bool switch2pll_en;
60 struct clkgen_field switch2pll;
61 spinlock_t *lock;
62 const struct clk_ops *ops;
65 static const struct clk_ops stm_pll3200c32_ops;
66 static const struct clk_ops stm_pll3200c32_a9_ops;
67 static const struct clk_ops stm_pll4600c28_ops;
69 static const struct clkgen_pll_data st_pll3200c32_407_a0 = {
70 /* 407 A0 */
71 .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8),
72 .pdn_ctrl = CLKGEN_FIELD(0x2a0, 0x1, 8),
73 .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24),
74 .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16),
75 .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0),
76 .num_odfs = 1,
77 .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) },
78 .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) },
79 .ops = &stm_pll3200c32_ops,
82 static const struct clkgen_pll_data st_pll3200c32_cx_0 = {
83 /* 407 C0 PLL0 */
84 .pdn_status = CLKGEN_FIELD(0x2a0, 0x1, 8),
85 .pdn_ctrl = CLKGEN_FIELD(0x2a0, 0x1, 8),
86 .locked_status = CLKGEN_FIELD(0x2a0, 0x1, 24),
87 .ndiv = CLKGEN_FIELD(0x2a4, C32_NDIV_MASK, 16),
88 .idf = CLKGEN_FIELD(0x2a4, C32_IDF_MASK, 0x0),
89 .num_odfs = 1,
90 .odf = { CLKGEN_FIELD(0x2b4, C32_ODF_MASK, 0) },
91 .odf_gate = { CLKGEN_FIELD(0x2b4, 0x1, 6) },
92 .ops = &stm_pll3200c32_ops,
95 static const struct clkgen_pll_data st_pll3200c32_cx_1 = {
96 /* 407 C0 PLL1 */
97 .pdn_status = CLKGEN_FIELD(0x2c8, 0x1, 8),
98 .pdn_ctrl = CLKGEN_FIELD(0x2c8, 0x1, 8),
99 .locked_status = CLKGEN_FIELD(0x2c8, 0x1, 24),
100 .ndiv = CLKGEN_FIELD(0x2cc, C32_NDIV_MASK, 16),
101 .idf = CLKGEN_FIELD(0x2cc, C32_IDF_MASK, 0x0),
102 .num_odfs = 1,
103 .odf = { CLKGEN_FIELD(0x2dc, C32_ODF_MASK, 0) },
104 .odf_gate = { CLKGEN_FIELD(0x2dc, 0x1, 6) },
105 .ops = &stm_pll3200c32_ops,
108 static const struct clkgen_pll_data st_pll3200c32_407_a9 = {
109 /* 407 A9 */
110 .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0),
111 .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0),
112 .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0),
113 .ndiv = CLKGEN_FIELD(0x1b0, C32_NDIV_MASK, 0),
114 .idf = CLKGEN_FIELD(0x1a8, C32_IDF_MASK, 25),
115 .num_odfs = 1,
116 .odf = { CLKGEN_FIELD(0x1b0, C32_ODF_MASK, 8) },
117 .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) },
118 .switch2pll_en = true,
119 .cp = CLKGEN_FIELD(0x1a8, C32_CP_MASK, 1),
120 .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1),
121 .lock = &clkgen_a9_lock,
122 .ops = &stm_pll3200c32_a9_ops,
125 static struct clkgen_pll_data st_pll4600c28_418_a9 = {
126 /* 418 A9 */
127 .pdn_status = CLKGEN_FIELD(0x1a8, 0x1, 0),
128 .pdn_ctrl = CLKGEN_FIELD(0x1a8, 0x1, 0),
129 .locked_status = CLKGEN_FIELD(0x87c, 0x1, 0),
130 .ndiv = CLKGEN_FIELD(0x1b0, C28_NDIV_MASK, 0),
131 .idf = CLKGEN_FIELD(0x1a8, C28_IDF_MASK, 25),
132 .num_odfs = 1,
133 .odf = { CLKGEN_FIELD(0x1b0, C28_ODF_MASK, 8) },
134 .odf_gate = { CLKGEN_FIELD(0x1ac, 0x1, 28) },
135 .switch2pll_en = true,
136 .switch2pll = CLKGEN_FIELD(0x1a4, 0x1, 1),
137 .lock = &clkgen_a9_lock,
138 .ops = &stm_pll4600c28_ops,
142 * DOC: Clock Generated by PLL, rate set and enabled by bootloader
144 * Traits of this clock:
145 * prepare - clk_(un)prepare only ensures parent is (un)prepared
146 * enable - clk_enable/disable only ensures parent is enabled
147 * rate - rate is fixed. No clk_set_rate support
148 * parent - fixed parent. No clk_set_parent support
152 * PLL clock that is integrated in the ClockGenA instances on the STiH415
153 * and STiH416.
155 * @hw: handle between common and hardware-specific interfaces.
156 * @type: PLL instance type.
157 * @regs_base: base of the PLL configuration register(s).
160 struct clkgen_pll {
161 struct clk_hw hw;
162 struct clkgen_pll_data *data;
163 void __iomem *regs_base;
164 spinlock_t *lock;
166 u32 ndiv;
167 u32 idf;
168 u32 odf;
169 u32 cp;
172 #define to_clkgen_pll(_hw) container_of(_hw, struct clkgen_pll, hw)
174 struct stm_pll {
175 unsigned long mdiv;
176 unsigned long ndiv;
177 unsigned long pdiv;
178 unsigned long odf;
179 unsigned long idf;
180 unsigned long ldf;
181 unsigned long cp;
184 static int clkgen_pll_is_locked(struct clk_hw *hw)
186 struct clkgen_pll *pll = to_clkgen_pll(hw);
187 u32 locked = CLKGEN_READ(pll, locked_status);
189 return !!locked;
192 static int clkgen_pll_is_enabled(struct clk_hw *hw)
194 struct clkgen_pll *pll = to_clkgen_pll(hw);
195 u32 poweroff = CLKGEN_READ(pll, pdn_status);
196 return !poweroff;
199 static int __clkgen_pll_enable(struct clk_hw *hw)
201 struct clkgen_pll *pll = to_clkgen_pll(hw);
202 void __iomem *base = pll->regs_base;
203 struct clkgen_field *field = &pll->data->locked_status;
204 int ret = 0;
205 u32 reg;
207 if (clkgen_pll_is_enabled(hw))
208 return 0;
210 CLKGEN_WRITE(pll, pdn_ctrl, 0);
212 ret = readl_relaxed_poll_timeout(base + field->offset, reg,
213 !!((reg >> field->shift) & field->mask), 0, 10000);
215 if (!ret) {
216 if (pll->data->switch2pll_en)
217 CLKGEN_WRITE(pll, switch2pll, 0);
219 pr_debug("%s:%s enabled\n", __clk_get_name(hw->clk), __func__);
222 return ret;
225 static int clkgen_pll_enable(struct clk_hw *hw)
227 struct clkgen_pll *pll = to_clkgen_pll(hw);
228 unsigned long flags = 0;
229 int ret = 0;
231 if (pll->lock)
232 spin_lock_irqsave(pll->lock, flags);
234 ret = __clkgen_pll_enable(hw);
236 if (pll->lock)
237 spin_unlock_irqrestore(pll->lock, flags);
239 return ret;
242 static void __clkgen_pll_disable(struct clk_hw *hw)
244 struct clkgen_pll *pll = to_clkgen_pll(hw);
246 if (!clkgen_pll_is_enabled(hw))
247 return;
249 if (pll->data->switch2pll_en)
250 CLKGEN_WRITE(pll, switch2pll, 1);
252 CLKGEN_WRITE(pll, pdn_ctrl, 1);
254 pr_debug("%s:%s disabled\n", __clk_get_name(hw->clk), __func__);
257 static void clkgen_pll_disable(struct clk_hw *hw)
259 struct clkgen_pll *pll = to_clkgen_pll(hw);
260 unsigned long flags = 0;
262 if (pll->lock)
263 spin_lock_irqsave(pll->lock, flags);
265 __clkgen_pll_disable(hw);
267 if (pll->lock)
268 spin_unlock_irqrestore(pll->lock, flags);
271 static int clk_pll3200c32_get_params(unsigned long input, unsigned long output,
272 struct stm_pll *pll)
274 unsigned long i, n;
275 unsigned long deviation = ~0;
276 unsigned long new_freq;
277 long new_deviation;
278 /* Charge pump table: highest ndiv value for cp=6 to 25 */
279 static const unsigned char cp_table[] = {
280 48, 56, 64, 72, 80, 88, 96, 104, 112, 120,
281 128, 136, 144, 152, 160, 168, 176, 184, 192
284 /* Output clock range: 800Mhz to 1600Mhz */
285 if (output < 800000000 || output > 1600000000)
286 return -EINVAL;
288 input /= 1000;
289 output /= 1000;
291 for (i = 1; i <= 7 && deviation; i++) {
292 n = i * output / (2 * input);
294 /* Checks */
295 if (n < 8)
296 continue;
297 if (n > 200)
298 break;
300 new_freq = (input * 2 * n) / i;
302 new_deviation = abs(new_freq - output);
304 if (!new_deviation || new_deviation < deviation) {
305 pll->idf = i;
306 pll->ndiv = n;
307 deviation = new_deviation;
311 if (deviation == ~0) /* No solution found */
312 return -EINVAL;
314 /* Computing recommended charge pump value */
315 for (pll->cp = 6; pll->ndiv > cp_table[pll->cp-6]; (pll->cp)++)
318 return 0;
321 static int clk_pll3200c32_get_rate(unsigned long input, struct stm_pll *pll,
322 unsigned long *rate)
324 if (!pll->idf)
325 pll->idf = 1;
327 *rate = ((2 * (input / 1000) * pll->ndiv) / pll->idf) * 1000;
329 return 0;
332 static unsigned long recalc_stm_pll3200c32(struct clk_hw *hw,
333 unsigned long parent_rate)
335 struct clkgen_pll *pll = to_clkgen_pll(hw);
336 unsigned long ndiv, idf;
337 unsigned long rate = 0;
339 if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
340 return 0;
342 ndiv = CLKGEN_READ(pll, ndiv);
343 idf = CLKGEN_READ(pll, idf);
345 if (idf)
346 /* Note: input is divided to avoid overflow */
347 rate = ((2 * (parent_rate/1000) * ndiv) / idf) * 1000;
349 pr_debug("%s:%s rate %lu\n", clk_hw_get_name(hw), __func__, rate);
351 return rate;
354 static long round_rate_stm_pll3200c32(struct clk_hw *hw, unsigned long rate,
355 unsigned long *prate)
357 struct stm_pll params;
359 if (!clk_pll3200c32_get_params(*prate, rate, &params))
360 clk_pll3200c32_get_rate(*prate, &params, &rate);
361 else {
362 pr_debug("%s: %s rate %ld Invalid\n", __func__,
363 __clk_get_name(hw->clk), rate);
364 return 0;
367 pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n",
368 __func__, __clk_get_name(hw->clk),
369 rate, (unsigned int)params.ndiv,
370 (unsigned int)params.idf);
372 return rate;
375 static int set_rate_stm_pll3200c32(struct clk_hw *hw, unsigned long rate,
376 unsigned long parent_rate)
378 struct clkgen_pll *pll = to_clkgen_pll(hw);
379 struct stm_pll params;
380 long hwrate = 0;
381 unsigned long flags = 0;
383 if (!rate || !parent_rate)
384 return -EINVAL;
386 if (!clk_pll3200c32_get_params(parent_rate, rate, &params))
387 clk_pll3200c32_get_rate(parent_rate, &params, &hwrate);
389 pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n",
390 __func__, __clk_get_name(hw->clk),
391 hwrate, (unsigned int)params.ndiv,
392 (unsigned int)params.idf);
394 if (!hwrate)
395 return -EINVAL;
397 pll->ndiv = params.ndiv;
398 pll->idf = params.idf;
399 pll->cp = params.cp;
401 __clkgen_pll_disable(hw);
403 if (pll->lock)
404 spin_lock_irqsave(pll->lock, flags);
406 CLKGEN_WRITE(pll, ndiv, pll->ndiv);
407 CLKGEN_WRITE(pll, idf, pll->idf);
408 CLKGEN_WRITE(pll, cp, pll->cp);
410 if (pll->lock)
411 spin_unlock_irqrestore(pll->lock, flags);
413 __clkgen_pll_enable(hw);
415 return 0;
418 /* PLL output structure
419 * FVCO >> /2 >> FVCOBY2 (no output)
420 * |> Divider (ODF) >> PHI
422 * FVCOby2 output = (input * 2 * NDIV) / IDF (assuming FRAC_CONTROL==L)
424 * Rules:
425 * 4Mhz <= INFF input <= 350Mhz
426 * 4Mhz <= INFIN (INFF / IDF) <= 50Mhz
427 * 19.05Mhz <= FVCOby2 output (PHI w ODF=1) <= 3000Mhz
428 * 1 <= i (register/dec value for IDF) <= 7
429 * 8 <= n (register/dec value for NDIV) <= 246
432 static int clk_pll4600c28_get_params(unsigned long input, unsigned long output,
433 struct stm_pll *pll)
436 unsigned long i, infin, n;
437 unsigned long deviation = ~0;
438 unsigned long new_freq, new_deviation;
440 /* Output clock range: 19Mhz to 3000Mhz */
441 if (output < 19000000 || output > 3000000000u)
442 return -EINVAL;
444 /* For better jitter, IDF should be smallest and NDIV must be maximum */
445 for (i = 1; i <= 7 && deviation; i++) {
446 /* INFIN checks */
447 infin = input / i;
448 if (infin < 4000000 || infin > 50000000)
449 continue; /* Invalid case */
451 n = output / (infin * 2);
452 if (n < 8 || n > 246)
453 continue; /* Invalid case */
454 if (n < 246)
455 n++; /* To work around 'y' when n=x.y */
457 for (; n >= 8 && deviation; n--) {
458 new_freq = infin * 2 * n;
459 if (new_freq < output)
460 break; /* Optimization: shorting loop */
462 new_deviation = new_freq - output;
463 if (!new_deviation || new_deviation < deviation) {
464 pll->idf = i;
465 pll->ndiv = n;
466 deviation = new_deviation;
471 if (deviation == ~0) /* No solution found */
472 return -EINVAL;
474 return 0;
477 static int clk_pll4600c28_get_rate(unsigned long input, struct stm_pll *pll,
478 unsigned long *rate)
480 if (!pll->idf)
481 pll->idf = 1;
483 *rate = (input / pll->idf) * 2 * pll->ndiv;
485 return 0;
488 static unsigned long recalc_stm_pll4600c28(struct clk_hw *hw,
489 unsigned long parent_rate)
491 struct clkgen_pll *pll = to_clkgen_pll(hw);
492 struct stm_pll params;
493 unsigned long rate;
495 if (!clkgen_pll_is_enabled(hw) || !clkgen_pll_is_locked(hw))
496 return 0;
498 params.ndiv = CLKGEN_READ(pll, ndiv);
499 params.idf = CLKGEN_READ(pll, idf);
501 clk_pll4600c28_get_rate(parent_rate, &params, &rate);
503 pr_debug("%s:%s rate %lu\n", __clk_get_name(hw->clk), __func__, rate);
505 return rate;
508 static long round_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate,
509 unsigned long *prate)
511 struct stm_pll params;
513 if (!clk_pll4600c28_get_params(*prate, rate, &params)) {
514 clk_pll4600c28_get_rate(*prate, &params, &rate);
515 } else {
516 pr_debug("%s: %s rate %ld Invalid\n", __func__,
517 __clk_get_name(hw->clk), rate);
518 return 0;
521 pr_debug("%s: %s new rate %ld [ndiv=%u] [idf=%u]\n",
522 __func__, __clk_get_name(hw->clk),
523 rate, (unsigned int)params.ndiv,
524 (unsigned int)params.idf);
526 return rate;
529 static int set_rate_stm_pll4600c28(struct clk_hw *hw, unsigned long rate,
530 unsigned long parent_rate)
532 struct clkgen_pll *pll = to_clkgen_pll(hw);
533 struct stm_pll params;
534 long hwrate;
535 unsigned long flags = 0;
537 if (!rate || !parent_rate)
538 return -EINVAL;
540 if (!clk_pll4600c28_get_params(parent_rate, rate, &params)) {
541 clk_pll4600c28_get_rate(parent_rate, &params, &hwrate);
542 } else {
543 pr_debug("%s: %s rate %ld Invalid\n", __func__,
544 __clk_get_name(hw->clk), rate);
545 return -EINVAL;
548 pr_debug("%s: %s new rate %ld [ndiv=0x%x] [idf=0x%x]\n",
549 __func__, __clk_get_name(hw->clk),
550 hwrate, (unsigned int)params.ndiv,
551 (unsigned int)params.idf);
553 if (!hwrate)
554 return -EINVAL;
556 pll->ndiv = params.ndiv;
557 pll->idf = params.idf;
559 __clkgen_pll_disable(hw);
561 if (pll->lock)
562 spin_lock_irqsave(pll->lock, flags);
564 CLKGEN_WRITE(pll, ndiv, pll->ndiv);
565 CLKGEN_WRITE(pll, idf, pll->idf);
567 if (pll->lock)
568 spin_unlock_irqrestore(pll->lock, flags);
570 __clkgen_pll_enable(hw);
572 return 0;
575 static const struct clk_ops stm_pll3200c32_ops = {
576 .enable = clkgen_pll_enable,
577 .disable = clkgen_pll_disable,
578 .is_enabled = clkgen_pll_is_enabled,
579 .recalc_rate = recalc_stm_pll3200c32,
582 static const struct clk_ops stm_pll3200c32_a9_ops = {
583 .enable = clkgen_pll_enable,
584 .disable = clkgen_pll_disable,
585 .is_enabled = clkgen_pll_is_enabled,
586 .recalc_rate = recalc_stm_pll3200c32,
587 .round_rate = round_rate_stm_pll3200c32,
588 .set_rate = set_rate_stm_pll3200c32,
591 static const struct clk_ops stm_pll4600c28_ops = {
592 .enable = clkgen_pll_enable,
593 .disable = clkgen_pll_disable,
594 .is_enabled = clkgen_pll_is_enabled,
595 .recalc_rate = recalc_stm_pll4600c28,
596 .round_rate = round_rate_stm_pll4600c28,
597 .set_rate = set_rate_stm_pll4600c28,
600 static struct clk * __init clkgen_pll_register(const char *parent_name,
601 struct clkgen_pll_data *pll_data,
602 void __iomem *reg, unsigned long pll_flags,
603 const char *clk_name, spinlock_t *lock)
605 struct clkgen_pll *pll;
606 struct clk *clk;
607 struct clk_init_data init;
609 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
610 if (!pll)
611 return ERR_PTR(-ENOMEM);
613 init.name = clk_name;
614 init.ops = pll_data->ops;
616 init.flags = pll_flags | CLK_IS_BASIC | CLK_GET_RATE_NOCACHE;
617 init.parent_names = &parent_name;
618 init.num_parents = 1;
620 pll->data = pll_data;
621 pll->regs_base = reg;
622 pll->hw.init = &init;
623 pll->lock = lock;
625 clk = clk_register(NULL, &pll->hw);
626 if (IS_ERR(clk)) {
627 kfree(pll);
628 return clk;
631 pr_debug("%s: parent %s rate %lu\n",
632 __clk_get_name(clk),
633 __clk_get_name(clk_get_parent(clk)),
634 clk_get_rate(clk));
636 return clk;
639 static void __iomem * __init clkgen_get_register_base(
640 struct device_node *np)
642 struct device_node *pnode;
643 void __iomem *reg = NULL;
645 pnode = of_get_parent(np);
646 if (!pnode)
647 return NULL;
649 reg = of_iomap(pnode, 0);
651 of_node_put(pnode);
652 return reg;
655 static struct clk * __init clkgen_odf_register(const char *parent_name,
656 void __iomem *reg,
657 struct clkgen_pll_data *pll_data,
658 unsigned long pll_flags, int odf,
659 spinlock_t *odf_lock,
660 const char *odf_name)
662 struct clk *clk;
663 unsigned long flags;
664 struct clk_gate *gate;
665 struct clk_divider *div;
667 flags = pll_flags | CLK_GET_RATE_NOCACHE | CLK_SET_RATE_PARENT;
669 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
670 if (!gate)
671 return ERR_PTR(-ENOMEM);
673 gate->flags = CLK_GATE_SET_TO_DISABLE;
674 gate->reg = reg + pll_data->odf_gate[odf].offset;
675 gate->bit_idx = pll_data->odf_gate[odf].shift;
676 gate->lock = odf_lock;
678 div = kzalloc(sizeof(*div), GFP_KERNEL);
679 if (!div) {
680 kfree(gate);
681 return ERR_PTR(-ENOMEM);
684 div->flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO;
685 div->reg = reg + pll_data->odf[odf].offset;
686 div->shift = pll_data->odf[odf].shift;
687 div->width = fls(pll_data->odf[odf].mask);
688 div->lock = odf_lock;
690 clk = clk_register_composite(NULL, odf_name, &parent_name, 1,
691 NULL, NULL,
692 &div->hw, &clk_divider_ops,
693 &gate->hw, &clk_gate_ops,
694 flags);
695 if (IS_ERR(clk))
696 return clk;
698 pr_debug("%s: parent %s rate %lu\n",
699 __clk_get_name(clk),
700 __clk_get_name(clk_get_parent(clk)),
701 clk_get_rate(clk));
702 return clk;
706 static void __init clkgen_c32_pll_setup(struct device_node *np,
707 struct clkgen_pll_data *data)
709 struct clk *clk;
710 const char *parent_name, *pll_name;
711 void __iomem *pll_base;
712 int num_odfs, odf;
713 struct clk_onecell_data *clk_data;
714 unsigned long pll_flags = 0;
717 parent_name = of_clk_get_parent_name(np, 0);
718 if (!parent_name)
719 return;
721 pll_base = clkgen_get_register_base(np);
722 if (!pll_base)
723 return;
725 of_clk_detect_critical(np, 0, &pll_flags);
727 clk = clkgen_pll_register(parent_name, data, pll_base, pll_flags,
728 np->name, data->lock);
729 if (IS_ERR(clk))
730 return;
732 pll_name = __clk_get_name(clk);
734 num_odfs = data->num_odfs;
736 clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
737 if (!clk_data)
738 return;
740 clk_data->clk_num = num_odfs;
741 clk_data->clks = kzalloc(clk_data->clk_num * sizeof(struct clk *),
742 GFP_KERNEL);
744 if (!clk_data->clks)
745 goto err;
747 for (odf = 0; odf < num_odfs; odf++) {
748 struct clk *clk;
749 const char *clk_name;
750 unsigned long odf_flags = 0;
752 if (of_property_read_string_index(np, "clock-output-names",
753 odf, &clk_name))
754 return;
756 of_clk_detect_critical(np, odf, &odf_flags);
758 clk = clkgen_odf_register(pll_name, pll_base, data, odf_flags,
759 odf, &clkgena_c32_odf_lock, clk_name);
760 if (IS_ERR(clk))
761 goto err;
763 clk_data->clks[odf] = clk;
766 of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
767 return;
769 err:
770 kfree(pll_name);
771 kfree(clk_data->clks);
772 kfree(clk_data);
774 static void __init clkgen_c32_pll0_setup(struct device_node *np)
776 clkgen_c32_pll_setup(np,
777 (struct clkgen_pll_data *) &st_pll3200c32_cx_0);
779 CLK_OF_DECLARE(c32_pll0, "st,clkgen-pll0", clkgen_c32_pll0_setup);
781 static void __init clkgen_c32_pll1_setup(struct device_node *np)
783 clkgen_c32_pll_setup(np,
784 (struct clkgen_pll_data *) &st_pll3200c32_cx_1);
786 CLK_OF_DECLARE(c32_pll1, "st,clkgen-pll1", clkgen_c32_pll1_setup);
788 static void __init clkgen_c32_plla9_setup(struct device_node *np)
790 clkgen_c32_pll_setup(np,
791 (struct clkgen_pll_data *) &st_pll3200c32_407_a9);
793 CLK_OF_DECLARE(c32_plla9, "st,stih407-clkgen-plla9", clkgen_c32_plla9_setup);
795 static void __init clkgen_c28_plla9_setup(struct device_node *np)
797 clkgen_c32_pll_setup(np,
798 (struct clkgen_pll_data *) &st_pll4600c28_418_a9);
800 CLK_OF_DECLARE(c28_plla9, "st,stih418-clkgen-plla9", clkgen_c28_plla9_setup);