1*3bb16560SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
255b8fd4fSViresh Kumar /*
355b8fd4fSViresh Kumar * Copyright (C) 2012 ST Microelectronics
4da89947bSViresh Kumar * Viresh Kumar <vireshk@kernel.org>
555b8fd4fSViresh Kumar *
655b8fd4fSViresh Kumar * VCO-PLL clock implementation
755b8fd4fSViresh Kumar */
855b8fd4fSViresh Kumar
955b8fd4fSViresh Kumar #define pr_fmt(fmt) "clk-vco-pll: " fmt
1055b8fd4fSViresh Kumar
1155b8fd4fSViresh Kumar #include <linux/clk-provider.h>
1255b8fd4fSViresh Kumar #include <linux/slab.h>
1355b8fd4fSViresh Kumar #include <linux/io.h>
1455b8fd4fSViresh Kumar #include <linux/err.h>
1555b8fd4fSViresh Kumar #include "clk.h"
1655b8fd4fSViresh Kumar
1755b8fd4fSViresh Kumar /*
1855b8fd4fSViresh Kumar * DOC: VCO-PLL clock
1955b8fd4fSViresh Kumar *
2055b8fd4fSViresh Kumar * VCO and PLL rate are derived from following equations:
2155b8fd4fSViresh Kumar *
2255b8fd4fSViresh Kumar * In normal mode
2355b8fd4fSViresh Kumar * vco = (2 * M[15:8] * Fin)/N
2455b8fd4fSViresh Kumar *
2555b8fd4fSViresh Kumar * In Dithered mode
2655b8fd4fSViresh Kumar * vco = (2 * M[15:0] * Fin)/(256 * N)
2755b8fd4fSViresh Kumar *
2855b8fd4fSViresh Kumar * pll_rate = pll/2^p
2955b8fd4fSViresh Kumar *
3055b8fd4fSViresh Kumar * vco and pll are very closely bound to each other, "vco needs to program:
3155b8fd4fSViresh Kumar * mode, m & n" and "pll needs to program p", both share common enable/disable
3255b8fd4fSViresh Kumar * logic.
3355b8fd4fSViresh Kumar *
3455b8fd4fSViresh Kumar * clk_register_vco_pll() registers instances of both vco & pll.
3555b8fd4fSViresh Kumar * CLK_SET_RATE_PARENT flag is forced for pll, as it will always pass its
3655b8fd4fSViresh Kumar * set_rate to vco. A single rate table exists for both the clocks, which
3755b8fd4fSViresh Kumar * configures m, n and p.
3855b8fd4fSViresh Kumar */
3955b8fd4fSViresh Kumar
4055b8fd4fSViresh Kumar /* PLL_CTR register masks */
4155b8fd4fSViresh Kumar #define PLL_MODE_NORMAL 0
4255b8fd4fSViresh Kumar #define PLL_MODE_FRACTION 1
4355b8fd4fSViresh Kumar #define PLL_MODE_DITH_DSM 2
4455b8fd4fSViresh Kumar #define PLL_MODE_DITH_SSM 3
4555b8fd4fSViresh Kumar #define PLL_MODE_MASK 3
4655b8fd4fSViresh Kumar #define PLL_MODE_SHIFT 3
4755b8fd4fSViresh Kumar #define PLL_ENABLE 2
4855b8fd4fSViresh Kumar
4955b8fd4fSViresh Kumar #define PLL_LOCK_SHIFT 0
5055b8fd4fSViresh Kumar #define PLL_LOCK_MASK 1
5155b8fd4fSViresh Kumar
5255b8fd4fSViresh Kumar /* PLL FRQ register masks */
5355b8fd4fSViresh Kumar #define PLL_NORM_FDBK_M_MASK 0xFF
5455b8fd4fSViresh Kumar #define PLL_NORM_FDBK_M_SHIFT 24
5555b8fd4fSViresh Kumar #define PLL_DITH_FDBK_M_MASK 0xFFFF
5655b8fd4fSViresh Kumar #define PLL_DITH_FDBK_M_SHIFT 16
5755b8fd4fSViresh Kumar #define PLL_DIV_P_MASK 0x7
5855b8fd4fSViresh Kumar #define PLL_DIV_P_SHIFT 8
5955b8fd4fSViresh Kumar #define PLL_DIV_N_MASK 0xFF
6055b8fd4fSViresh Kumar #define PLL_DIV_N_SHIFT 0
6155b8fd4fSViresh Kumar
6255b8fd4fSViresh Kumar #define to_clk_vco(_hw) container_of(_hw, struct clk_vco, hw)
6355b8fd4fSViresh Kumar #define to_clk_pll(_hw) container_of(_hw, struct clk_pll, hw)
6455b8fd4fSViresh Kumar
6555b8fd4fSViresh Kumar /* Calculates pll clk rate for specific value of mode, m, n and p */
pll_calc_rate(struct pll_rate_tbl * rtbl,unsigned long prate,int index,unsigned long * pll_rate)6655b8fd4fSViresh Kumar static unsigned long pll_calc_rate(struct pll_rate_tbl *rtbl,
6755b8fd4fSViresh Kumar unsigned long prate, int index, unsigned long *pll_rate)
6855b8fd4fSViresh Kumar {
6955b8fd4fSViresh Kumar unsigned long rate = prate;
7055b8fd4fSViresh Kumar unsigned int mode;
7155b8fd4fSViresh Kumar
7255b8fd4fSViresh Kumar mode = rtbl[index].mode ? 256 : 1;
7355b8fd4fSViresh Kumar rate = (((2 * rate / 10000) * rtbl[index].m) / (mode * rtbl[index].n));
7455b8fd4fSViresh Kumar
7555b8fd4fSViresh Kumar if (pll_rate)
7655b8fd4fSViresh Kumar *pll_rate = (rate / (1 << rtbl[index].p)) * 10000;
7755b8fd4fSViresh Kumar
7855b8fd4fSViresh Kumar return rate * 10000;
7955b8fd4fSViresh Kumar }
8055b8fd4fSViresh Kumar
clk_pll_round_rate_index(struct clk_hw * hw,unsigned long drate,unsigned long * prate,int * index)8155b8fd4fSViresh Kumar static long clk_pll_round_rate_index(struct clk_hw *hw, unsigned long drate,
8255b8fd4fSViresh Kumar unsigned long *prate, int *index)
8355b8fd4fSViresh Kumar {
8455b8fd4fSViresh Kumar struct clk_pll *pll = to_clk_pll(hw);
8555b8fd4fSViresh Kumar unsigned long prev_rate, vco_prev_rate, rate = 0;
8655b8fd4fSViresh Kumar unsigned long vco_parent_rate =
87b73d616dSStephen Boyd clk_hw_get_rate(clk_hw_get_parent(clk_hw_get_parent(hw)));
8855b8fd4fSViresh Kumar
8955b8fd4fSViresh Kumar if (!prate) {
9055b8fd4fSViresh Kumar pr_err("%s: prate is must for pll clk\n", __func__);
9155b8fd4fSViresh Kumar return -EINVAL;
9255b8fd4fSViresh Kumar }
9355b8fd4fSViresh Kumar
9455b8fd4fSViresh Kumar for (*index = 0; *index < pll->vco->rtbl_cnt; (*index)++) {
9555b8fd4fSViresh Kumar prev_rate = rate;
9655b8fd4fSViresh Kumar vco_prev_rate = *prate;
9755b8fd4fSViresh Kumar *prate = pll_calc_rate(pll->vco->rtbl, vco_parent_rate, *index,
9855b8fd4fSViresh Kumar &rate);
9955b8fd4fSViresh Kumar if (drate < rate) {
10055b8fd4fSViresh Kumar /* previous clock was best */
10155b8fd4fSViresh Kumar if (*index) {
10255b8fd4fSViresh Kumar rate = prev_rate;
10355b8fd4fSViresh Kumar *prate = vco_prev_rate;
10455b8fd4fSViresh Kumar (*index)--;
10555b8fd4fSViresh Kumar }
10655b8fd4fSViresh Kumar break;
10755b8fd4fSViresh Kumar }
10855b8fd4fSViresh Kumar }
10955b8fd4fSViresh Kumar
11055b8fd4fSViresh Kumar return rate;
11155b8fd4fSViresh Kumar }
11255b8fd4fSViresh Kumar
clk_pll_round_rate(struct clk_hw * hw,unsigned long drate,unsigned long * prate)11355b8fd4fSViresh Kumar static long clk_pll_round_rate(struct clk_hw *hw, unsigned long drate,
11455b8fd4fSViresh Kumar unsigned long *prate)
11555b8fd4fSViresh Kumar {
11655b8fd4fSViresh Kumar int unused;
11755b8fd4fSViresh Kumar
11855b8fd4fSViresh Kumar return clk_pll_round_rate_index(hw, drate, prate, &unused);
11955b8fd4fSViresh Kumar }
12055b8fd4fSViresh Kumar
clk_pll_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)12155b8fd4fSViresh Kumar static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, unsigned long
12255b8fd4fSViresh Kumar parent_rate)
12355b8fd4fSViresh Kumar {
12455b8fd4fSViresh Kumar struct clk_pll *pll = to_clk_pll(hw);
12555b8fd4fSViresh Kumar unsigned long flags = 0;
12655b8fd4fSViresh Kumar unsigned int p;
12755b8fd4fSViresh Kumar
12855b8fd4fSViresh Kumar if (pll->vco->lock)
12955b8fd4fSViresh Kumar spin_lock_irqsave(pll->vco->lock, flags);
13055b8fd4fSViresh Kumar
13155b8fd4fSViresh Kumar p = readl_relaxed(pll->vco->cfg_reg);
13255b8fd4fSViresh Kumar
13355b8fd4fSViresh Kumar if (pll->vco->lock)
13455b8fd4fSViresh Kumar spin_unlock_irqrestore(pll->vco->lock, flags);
13555b8fd4fSViresh Kumar
13655b8fd4fSViresh Kumar p = (p >> PLL_DIV_P_SHIFT) & PLL_DIV_P_MASK;
13755b8fd4fSViresh Kumar
13855b8fd4fSViresh Kumar return parent_rate / (1 << p);
13955b8fd4fSViresh Kumar }
14055b8fd4fSViresh Kumar
clk_pll_set_rate(struct clk_hw * hw,unsigned long drate,unsigned long prate)14155b8fd4fSViresh Kumar static int clk_pll_set_rate(struct clk_hw *hw, unsigned long drate,
14255b8fd4fSViresh Kumar unsigned long prate)
14355b8fd4fSViresh Kumar {
14455b8fd4fSViresh Kumar struct clk_pll *pll = to_clk_pll(hw);
14555b8fd4fSViresh Kumar struct pll_rate_tbl *rtbl = pll->vco->rtbl;
14655b8fd4fSViresh Kumar unsigned long flags = 0, val;
147fec61ff4SKees Cook int i = 0;
14855b8fd4fSViresh Kumar
14955b8fd4fSViresh Kumar clk_pll_round_rate_index(hw, drate, NULL, &i);
15055b8fd4fSViresh Kumar
15155b8fd4fSViresh Kumar if (pll->vco->lock)
15255b8fd4fSViresh Kumar spin_lock_irqsave(pll->vco->lock, flags);
15355b8fd4fSViresh Kumar
15455b8fd4fSViresh Kumar val = readl_relaxed(pll->vco->cfg_reg);
15555b8fd4fSViresh Kumar val &= ~(PLL_DIV_P_MASK << PLL_DIV_P_SHIFT);
15655b8fd4fSViresh Kumar val |= (rtbl[i].p & PLL_DIV_P_MASK) << PLL_DIV_P_SHIFT;
15755b8fd4fSViresh Kumar writel_relaxed(val, pll->vco->cfg_reg);
15855b8fd4fSViresh Kumar
15955b8fd4fSViresh Kumar if (pll->vco->lock)
16055b8fd4fSViresh Kumar spin_unlock_irqrestore(pll->vco->lock, flags);
16155b8fd4fSViresh Kumar
16255b8fd4fSViresh Kumar return 0;
16355b8fd4fSViresh Kumar }
16455b8fd4fSViresh Kumar
165ba3892dfSBhumika Goyal static const struct clk_ops clk_pll_ops = {
16655b8fd4fSViresh Kumar .recalc_rate = clk_pll_recalc_rate,
16755b8fd4fSViresh Kumar .round_rate = clk_pll_round_rate,
16855b8fd4fSViresh Kumar .set_rate = clk_pll_set_rate,
16955b8fd4fSViresh Kumar };
17055b8fd4fSViresh Kumar
vco_calc_rate(struct clk_hw * hw,unsigned long prate,int index)17155b8fd4fSViresh Kumar static inline unsigned long vco_calc_rate(struct clk_hw *hw,
17255b8fd4fSViresh Kumar unsigned long prate, int index)
17355b8fd4fSViresh Kumar {
17455b8fd4fSViresh Kumar struct clk_vco *vco = to_clk_vco(hw);
17555b8fd4fSViresh Kumar
17655b8fd4fSViresh Kumar return pll_calc_rate(vco->rtbl, prate, index, NULL);
17755b8fd4fSViresh Kumar }
17855b8fd4fSViresh Kumar
clk_vco_round_rate(struct clk_hw * hw,unsigned long drate,unsigned long * prate)17955b8fd4fSViresh Kumar static long clk_vco_round_rate(struct clk_hw *hw, unsigned long drate,
18055b8fd4fSViresh Kumar unsigned long *prate)
18155b8fd4fSViresh Kumar {
18255b8fd4fSViresh Kumar struct clk_vco *vco = to_clk_vco(hw);
18355b8fd4fSViresh Kumar int unused;
18455b8fd4fSViresh Kumar
18555b8fd4fSViresh Kumar return clk_round_rate_index(hw, drate, *prate, vco_calc_rate,
18655b8fd4fSViresh Kumar vco->rtbl_cnt, &unused);
18755b8fd4fSViresh Kumar }
18855b8fd4fSViresh Kumar
clk_vco_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)18955b8fd4fSViresh Kumar static unsigned long clk_vco_recalc_rate(struct clk_hw *hw,
19055b8fd4fSViresh Kumar unsigned long parent_rate)
19155b8fd4fSViresh Kumar {
19255b8fd4fSViresh Kumar struct clk_vco *vco = to_clk_vco(hw);
19355b8fd4fSViresh Kumar unsigned long flags = 0;
19455b8fd4fSViresh Kumar unsigned int num = 2, den = 0, val, mode = 0;
19555b8fd4fSViresh Kumar
19655b8fd4fSViresh Kumar if (vco->lock)
19755b8fd4fSViresh Kumar spin_lock_irqsave(vco->lock, flags);
19855b8fd4fSViresh Kumar
19955b8fd4fSViresh Kumar mode = (readl_relaxed(vco->mode_reg) >> PLL_MODE_SHIFT) & PLL_MODE_MASK;
20055b8fd4fSViresh Kumar
20155b8fd4fSViresh Kumar val = readl_relaxed(vco->cfg_reg);
20255b8fd4fSViresh Kumar
20355b8fd4fSViresh Kumar if (vco->lock)
20455b8fd4fSViresh Kumar spin_unlock_irqrestore(vco->lock, flags);
20555b8fd4fSViresh Kumar
20655b8fd4fSViresh Kumar den = (val >> PLL_DIV_N_SHIFT) & PLL_DIV_N_MASK;
20755b8fd4fSViresh Kumar
20855b8fd4fSViresh Kumar /* calculate numerator & denominator */
20955b8fd4fSViresh Kumar if (!mode) {
21055b8fd4fSViresh Kumar /* Normal mode */
21155b8fd4fSViresh Kumar num *= (val >> PLL_NORM_FDBK_M_SHIFT) & PLL_NORM_FDBK_M_MASK;
21255b8fd4fSViresh Kumar } else {
21355b8fd4fSViresh Kumar /* Dithered mode */
21455b8fd4fSViresh Kumar num *= (val >> PLL_DITH_FDBK_M_SHIFT) & PLL_DITH_FDBK_M_MASK;
21555b8fd4fSViresh Kumar den *= 256;
21655b8fd4fSViresh Kumar }
21755b8fd4fSViresh Kumar
21855b8fd4fSViresh Kumar if (!den) {
21955b8fd4fSViresh Kumar WARN(1, "%s: denominator can't be zero\n", __func__);
22055b8fd4fSViresh Kumar return 0;
22155b8fd4fSViresh Kumar }
22255b8fd4fSViresh Kumar
22355b8fd4fSViresh Kumar return (((parent_rate / 10000) * num) / den) * 10000;
22455b8fd4fSViresh Kumar }
22555b8fd4fSViresh Kumar
22655b8fd4fSViresh Kumar /* Configures new clock rate of vco */
clk_vco_set_rate(struct clk_hw * hw,unsigned long drate,unsigned long prate)22755b8fd4fSViresh Kumar static int clk_vco_set_rate(struct clk_hw *hw, unsigned long drate,
22855b8fd4fSViresh Kumar unsigned long prate)
22955b8fd4fSViresh Kumar {
23055b8fd4fSViresh Kumar struct clk_vco *vco = to_clk_vco(hw);
23155b8fd4fSViresh Kumar struct pll_rate_tbl *rtbl = vco->rtbl;
23255b8fd4fSViresh Kumar unsigned long flags = 0, val;
23355b8fd4fSViresh Kumar int i;
23455b8fd4fSViresh Kumar
23555b8fd4fSViresh Kumar clk_round_rate_index(hw, drate, prate, vco_calc_rate, vco->rtbl_cnt,
23655b8fd4fSViresh Kumar &i);
23755b8fd4fSViresh Kumar
23855b8fd4fSViresh Kumar if (vco->lock)
23955b8fd4fSViresh Kumar spin_lock_irqsave(vco->lock, flags);
24055b8fd4fSViresh Kumar
24155b8fd4fSViresh Kumar val = readl_relaxed(vco->mode_reg);
24255b8fd4fSViresh Kumar val &= ~(PLL_MODE_MASK << PLL_MODE_SHIFT);
24355b8fd4fSViresh Kumar val |= (rtbl[i].mode & PLL_MODE_MASK) << PLL_MODE_SHIFT;
24455b8fd4fSViresh Kumar writel_relaxed(val, vco->mode_reg);
24555b8fd4fSViresh Kumar
24655b8fd4fSViresh Kumar val = readl_relaxed(vco->cfg_reg);
24755b8fd4fSViresh Kumar val &= ~(PLL_DIV_N_MASK << PLL_DIV_N_SHIFT);
24855b8fd4fSViresh Kumar val |= (rtbl[i].n & PLL_DIV_N_MASK) << PLL_DIV_N_SHIFT;
24955b8fd4fSViresh Kumar
25055b8fd4fSViresh Kumar val &= ~(PLL_DITH_FDBK_M_MASK << PLL_DITH_FDBK_M_SHIFT);
25155b8fd4fSViresh Kumar if (rtbl[i].mode)
25255b8fd4fSViresh Kumar val |= (rtbl[i].m & PLL_DITH_FDBK_M_MASK) <<
25355b8fd4fSViresh Kumar PLL_DITH_FDBK_M_SHIFT;
25455b8fd4fSViresh Kumar else
25555b8fd4fSViresh Kumar val |= (rtbl[i].m & PLL_NORM_FDBK_M_MASK) <<
25655b8fd4fSViresh Kumar PLL_NORM_FDBK_M_SHIFT;
25755b8fd4fSViresh Kumar
25855b8fd4fSViresh Kumar writel_relaxed(val, vco->cfg_reg);
25955b8fd4fSViresh Kumar
26055b8fd4fSViresh Kumar if (vco->lock)
26155b8fd4fSViresh Kumar spin_unlock_irqrestore(vco->lock, flags);
26255b8fd4fSViresh Kumar
26355b8fd4fSViresh Kumar return 0;
26455b8fd4fSViresh Kumar }
26555b8fd4fSViresh Kumar
266ba3892dfSBhumika Goyal static const struct clk_ops clk_vco_ops = {
26755b8fd4fSViresh Kumar .recalc_rate = clk_vco_recalc_rate,
26855b8fd4fSViresh Kumar .round_rate = clk_vco_round_rate,
26955b8fd4fSViresh Kumar .set_rate = clk_vco_set_rate,
27055b8fd4fSViresh Kumar };
27155b8fd4fSViresh Kumar
clk_register_vco_pll(const char * vco_name,const char * pll_name,const char * vco_gate_name,const char * parent_name,unsigned long flags,void __iomem * mode_reg,void __iomem * cfg_reg,struct pll_rate_tbl * rtbl,u8 rtbl_cnt,spinlock_t * lock,struct clk ** pll_clk,struct clk ** vco_gate_clk)27255b8fd4fSViresh Kumar struct clk *clk_register_vco_pll(const char *vco_name, const char *pll_name,
27355b8fd4fSViresh Kumar const char *vco_gate_name, const char *parent_name,
27455b8fd4fSViresh Kumar unsigned long flags, void __iomem *mode_reg, void __iomem
27555b8fd4fSViresh Kumar *cfg_reg, struct pll_rate_tbl *rtbl, u8 rtbl_cnt,
27655b8fd4fSViresh Kumar spinlock_t *lock, struct clk **pll_clk,
27755b8fd4fSViresh Kumar struct clk **vco_gate_clk)
27855b8fd4fSViresh Kumar {
27955b8fd4fSViresh Kumar struct clk_vco *vco;
28055b8fd4fSViresh Kumar struct clk_pll *pll;
28155b8fd4fSViresh Kumar struct clk *vco_clk, *tpll_clk, *tvco_gate_clk;
28255b8fd4fSViresh Kumar struct clk_init_data vco_init, pll_init;
28355b8fd4fSViresh Kumar const char **vco_parent_name;
28455b8fd4fSViresh Kumar
28555b8fd4fSViresh Kumar if (!vco_name || !pll_name || !parent_name || !mode_reg || !cfg_reg ||
28655b8fd4fSViresh Kumar !rtbl || !rtbl_cnt) {
28755b8fd4fSViresh Kumar pr_err("Invalid arguments passed");
28855b8fd4fSViresh Kumar return ERR_PTR(-EINVAL);
28955b8fd4fSViresh Kumar }
29055b8fd4fSViresh Kumar
29155b8fd4fSViresh Kumar vco = kzalloc(sizeof(*vco), GFP_KERNEL);
29263b1a5d7SMarkus Elfring if (!vco)
29355b8fd4fSViresh Kumar return ERR_PTR(-ENOMEM);
29455b8fd4fSViresh Kumar
29555b8fd4fSViresh Kumar pll = kzalloc(sizeof(*pll), GFP_KERNEL);
29663b1a5d7SMarkus Elfring if (!pll)
29755b8fd4fSViresh Kumar goto free_vco;
29855b8fd4fSViresh Kumar
29955b8fd4fSViresh Kumar /* struct clk_vco assignments */
30055b8fd4fSViresh Kumar vco->mode_reg = mode_reg;
30155b8fd4fSViresh Kumar vco->cfg_reg = cfg_reg;
30255b8fd4fSViresh Kumar vco->rtbl = rtbl;
30355b8fd4fSViresh Kumar vco->rtbl_cnt = rtbl_cnt;
30455b8fd4fSViresh Kumar vco->lock = lock;
30555b8fd4fSViresh Kumar vco->hw.init = &vco_init;
30655b8fd4fSViresh Kumar
30755b8fd4fSViresh Kumar pll->vco = vco;
30855b8fd4fSViresh Kumar pll->hw.init = &pll_init;
30955b8fd4fSViresh Kumar
31055b8fd4fSViresh Kumar if (vco_gate_name) {
31155b8fd4fSViresh Kumar tvco_gate_clk = clk_register_gate(NULL, vco_gate_name,
31255b8fd4fSViresh Kumar parent_name, 0, mode_reg, PLL_ENABLE, 0, lock);
31355b8fd4fSViresh Kumar if (IS_ERR_OR_NULL(tvco_gate_clk))
31455b8fd4fSViresh Kumar goto free_pll;
31555b8fd4fSViresh Kumar
31655b8fd4fSViresh Kumar if (vco_gate_clk)
31755b8fd4fSViresh Kumar *vco_gate_clk = tvco_gate_clk;
31855b8fd4fSViresh Kumar vco_parent_name = &vco_gate_name;
31955b8fd4fSViresh Kumar } else {
32055b8fd4fSViresh Kumar vco_parent_name = &parent_name;
32155b8fd4fSViresh Kumar }
32255b8fd4fSViresh Kumar
32355b8fd4fSViresh Kumar vco_init.name = vco_name;
32455b8fd4fSViresh Kumar vco_init.ops = &clk_vco_ops;
32555b8fd4fSViresh Kumar vco_init.flags = flags;
32655b8fd4fSViresh Kumar vco_init.parent_names = vco_parent_name;
32755b8fd4fSViresh Kumar vco_init.num_parents = 1;
32855b8fd4fSViresh Kumar
32955b8fd4fSViresh Kumar pll_init.name = pll_name;
33055b8fd4fSViresh Kumar pll_init.ops = &clk_pll_ops;
33155b8fd4fSViresh Kumar pll_init.flags = CLK_SET_RATE_PARENT;
33255b8fd4fSViresh Kumar pll_init.parent_names = &vco_name;
33355b8fd4fSViresh Kumar pll_init.num_parents = 1;
33455b8fd4fSViresh Kumar
33555b8fd4fSViresh Kumar vco_clk = clk_register(NULL, &vco->hw);
33655b8fd4fSViresh Kumar if (IS_ERR_OR_NULL(vco_clk))
33755b8fd4fSViresh Kumar goto free_pll;
33855b8fd4fSViresh Kumar
33955b8fd4fSViresh Kumar tpll_clk = clk_register(NULL, &pll->hw);
34055b8fd4fSViresh Kumar if (IS_ERR_OR_NULL(tpll_clk))
34155b8fd4fSViresh Kumar goto free_pll;
34255b8fd4fSViresh Kumar
34355b8fd4fSViresh Kumar if (pll_clk)
34455b8fd4fSViresh Kumar *pll_clk = tpll_clk;
34555b8fd4fSViresh Kumar
34655b8fd4fSViresh Kumar return vco_clk;
34755b8fd4fSViresh Kumar
34855b8fd4fSViresh Kumar free_pll:
34955b8fd4fSViresh Kumar kfree(pll);
35055b8fd4fSViresh Kumar free_vco:
35155b8fd4fSViresh Kumar kfree(vco);
35255b8fd4fSViresh Kumar
35355b8fd4fSViresh Kumar pr_err("Failed to register vco pll clock\n");
35455b8fd4fSViresh Kumar
35555b8fd4fSViresh Kumar return ERR_PTR(-ENOMEM);
35655b8fd4fSViresh Kumar }
357