xref: /openbmc/linux/drivers/clk/imx/clk-pll14xx.c (revision 5ff50031cb8852bfcf587d003ba6bad3c2336852)
18646d4dcSBai Ping // SPDX-License-Identifier: GPL-2.0
28646d4dcSBai Ping /*
38646d4dcSBai Ping  * Copyright 2017-2018 NXP.
48646d4dcSBai Ping  */
58646d4dcSBai Ping 
658f4980cSSascha Hauer #include <linux/bitfield.h>
77d6b5e4fSAnson Huang #include <linux/bits.h>
88646d4dcSBai Ping #include <linux/clk-provider.h>
98646d4dcSBai Ping #include <linux/err.h>
10870ed5e2SAnson Huang #include <linux/export.h>
118646d4dcSBai Ping #include <linux/io.h>
128646d4dcSBai Ping #include <linux/iopoll.h>
138646d4dcSBai Ping #include <linux/slab.h>
148646d4dcSBai Ping #include <linux/jiffies.h>
158646d4dcSBai Ping 
168646d4dcSBai Ping #include "clk.h"
178646d4dcSBai Ping 
188646d4dcSBai Ping #define GNRL_CTL	0x0
19485b4ff5SSascha Hauer #define DIV_CTL0	0x4
20485b4ff5SSascha Hauer #define DIV_CTL1	0x8
218646d4dcSBai Ping #define LOCK_STATUS	BIT(31)
228646d4dcSBai Ping #define LOCK_SEL_MASK	BIT(29)
238646d4dcSBai Ping #define CLKE_MASK	BIT(11)
248646d4dcSBai Ping #define RST_MASK	BIT(9)
258646d4dcSBai Ping #define BYPASS_MASK	BIT(4)
268646d4dcSBai Ping #define MDIV_MASK	GENMASK(21, 12)
278646d4dcSBai Ping #define PDIV_MASK	GENMASK(9, 4)
288646d4dcSBai Ping #define SDIV_MASK	GENMASK(2, 0)
298646d4dcSBai Ping #define KDIV_MASK	GENMASK(15, 0)
308646d4dcSBai Ping 
318646d4dcSBai Ping #define LOCK_TIMEOUT_US		10000
328646d4dcSBai Ping 
338646d4dcSBai Ping struct clk_pll14xx {
348646d4dcSBai Ping 	struct clk_hw			hw;
358646d4dcSBai Ping 	void __iomem			*base;
368646d4dcSBai Ping 	enum imx_pll14xx_type		type;
378646d4dcSBai Ping 	const struct imx_pll14xx_rate_table *rate_table;
388646d4dcSBai Ping 	int rate_count;
398646d4dcSBai Ping };
408646d4dcSBai Ping 
418646d4dcSBai Ping #define to_clk_pll14xx(_hw) container_of(_hw, struct clk_pll14xx, hw)
428646d4dcSBai Ping 
438f2d3c17SYueHaibing static const struct imx_pll14xx_rate_table imx_pll1416x_tbl[] = {
4443cdaa15SAnson Huang 	PLL_1416X_RATE(1800000000U, 225, 3, 0),
4543cdaa15SAnson Huang 	PLL_1416X_RATE(1600000000U, 200, 3, 0),
460ae4fbc6SAnson Huang 	PLL_1416X_RATE(1500000000U, 375, 3, 1),
470ae4fbc6SAnson Huang 	PLL_1416X_RATE(1400000000U, 350, 3, 1),
4843cdaa15SAnson Huang 	PLL_1416X_RATE(1200000000U, 300, 3, 1),
4943cdaa15SAnson Huang 	PLL_1416X_RATE(1000000000U, 250, 3, 1),
5043cdaa15SAnson Huang 	PLL_1416X_RATE(800000000U,  200, 3, 1),
5143cdaa15SAnson Huang 	PLL_1416X_RATE(750000000U,  250, 2, 2),
5243cdaa15SAnson Huang 	PLL_1416X_RATE(700000000U,  350, 3, 2),
5343cdaa15SAnson Huang 	PLL_1416X_RATE(600000000U,  300, 3, 2),
5443cdaa15SAnson Huang };
5543cdaa15SAnson Huang 
568f2d3c17SYueHaibing static const struct imx_pll14xx_rate_table imx_pll1443x_tbl[] = {
5757795654SAnson Huang 	PLL_1443X_RATE(1039500000U, 173, 2, 1, 16384),
5843cdaa15SAnson Huang 	PLL_1443X_RATE(650000000U, 325, 3, 2, 0),
5943cdaa15SAnson Huang 	PLL_1443X_RATE(594000000U, 198, 2, 2, 0),
6057795654SAnson Huang 	PLL_1443X_RATE(519750000U, 173, 2, 2, 16384),
6143cdaa15SAnson Huang 	PLL_1443X_RATE(393216000U, 262, 2, 3, 9437),
6243cdaa15SAnson Huang 	PLL_1443X_RATE(361267200U, 361, 3, 3, 17511),
6343cdaa15SAnson Huang };
6443cdaa15SAnson Huang 
6543cdaa15SAnson Huang struct imx_pll14xx_clk imx_1443x_pll = {
6643cdaa15SAnson Huang 	.type = PLL_1443X,
6743cdaa15SAnson Huang 	.rate_table = imx_pll1443x_tbl,
6843cdaa15SAnson Huang 	.rate_count = ARRAY_SIZE(imx_pll1443x_tbl),
6943cdaa15SAnson Huang };
70870ed5e2SAnson Huang EXPORT_SYMBOL_GPL(imx_1443x_pll);
7143cdaa15SAnson Huang 
72e18f6471SLeonard Crestez struct imx_pll14xx_clk imx_1443x_dram_pll = {
73e18f6471SLeonard Crestez 	.type = PLL_1443X,
74e18f6471SLeonard Crestez 	.rate_table = imx_pll1443x_tbl,
75e18f6471SLeonard Crestez 	.rate_count = ARRAY_SIZE(imx_pll1443x_tbl),
76e18f6471SLeonard Crestez 	.flags = CLK_GET_RATE_NOCACHE,
77e18f6471SLeonard Crestez };
78870ed5e2SAnson Huang EXPORT_SYMBOL_GPL(imx_1443x_dram_pll);
79e18f6471SLeonard Crestez 
8043cdaa15SAnson Huang struct imx_pll14xx_clk imx_1416x_pll = {
8143cdaa15SAnson Huang 	.type = PLL_1416X,
8243cdaa15SAnson Huang 	.rate_table = imx_pll1416x_tbl,
8343cdaa15SAnson Huang 	.rate_count = ARRAY_SIZE(imx_pll1416x_tbl),
8443cdaa15SAnson Huang };
85870ed5e2SAnson Huang EXPORT_SYMBOL_GPL(imx_1416x_pll);
8643cdaa15SAnson Huang 
878646d4dcSBai Ping static const struct imx_pll14xx_rate_table *imx_get_pll_settings(
888646d4dcSBai Ping 		struct clk_pll14xx *pll, unsigned long rate)
898646d4dcSBai Ping {
908646d4dcSBai Ping 	const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
918646d4dcSBai Ping 	int i;
928646d4dcSBai Ping 
938646d4dcSBai Ping 	for (i = 0; i < pll->rate_count; i++)
948646d4dcSBai Ping 		if (rate == rate_table[i].rate)
958646d4dcSBai Ping 			return &rate_table[i];
968646d4dcSBai Ping 
978646d4dcSBai Ping 	return NULL;
988646d4dcSBai Ping }
998646d4dcSBai Ping 
10053990cf9SSascha Hauer static long pll14xx_calc_rate(struct clk_pll14xx *pll, int mdiv, int pdiv,
10153990cf9SSascha Hauer 			      int sdiv, int kdiv, unsigned long prate)
10253990cf9SSascha Hauer {
10353990cf9SSascha Hauer 	u64 fvco = prate;
10453990cf9SSascha Hauer 
10553990cf9SSascha Hauer 	/* fvco = (m * 65536 + k) * Fin / (p * 65536) */
10653990cf9SSascha Hauer 	fvco *= (mdiv * 65536 + kdiv);
10753990cf9SSascha Hauer 	pdiv *= 65536;
10853990cf9SSascha Hauer 
10953990cf9SSascha Hauer 	do_div(fvco, pdiv << sdiv);
11053990cf9SSascha Hauer 
11153990cf9SSascha Hauer 	return fvco;
11253990cf9SSascha Hauer }
11353990cf9SSascha Hauer 
1148646d4dcSBai Ping static long clk_pll14xx_round_rate(struct clk_hw *hw, unsigned long rate,
1158646d4dcSBai Ping 			unsigned long *prate)
1168646d4dcSBai Ping {
1178646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
1188646d4dcSBai Ping 	const struct imx_pll14xx_rate_table *rate_table = pll->rate_table;
1198646d4dcSBai Ping 	int i;
1208646d4dcSBai Ping 
121*5ff50031SSascha Hauer 	/* Assuming rate_table is in descending order */
1228646d4dcSBai Ping 	for (i = 0; i < pll->rate_count; i++)
1238646d4dcSBai Ping 		if (rate >= rate_table[i].rate)
1248646d4dcSBai Ping 			return rate_table[i].rate;
1258646d4dcSBai Ping 
1268646d4dcSBai Ping 	/* return minimum supported value */
127*5ff50031SSascha Hauer 	return rate_table[pll->rate_count - 1].rate;
1288646d4dcSBai Ping }
1298646d4dcSBai Ping 
13053990cf9SSascha Hauer static unsigned long clk_pll14xx_recalc_rate(struct clk_hw *hw,
1318646d4dcSBai Ping 						  unsigned long parent_rate)
1328646d4dcSBai Ping {
1338646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
13453990cf9SSascha Hauer 	u32 mdiv, pdiv, sdiv, kdiv, pll_div_ctl0, pll_div_ctl1;
1358646d4dcSBai Ping 
136485b4ff5SSascha Hauer 	pll_div_ctl0 = readl_relaxed(pll->base + DIV_CTL0);
13758f4980cSSascha Hauer 	mdiv = FIELD_GET(MDIV_MASK, pll_div_ctl0);
13858f4980cSSascha Hauer 	pdiv = FIELD_GET(PDIV_MASK, pll_div_ctl0);
13958f4980cSSascha Hauer 	sdiv = FIELD_GET(SDIV_MASK, pll_div_ctl0);
14053990cf9SSascha Hauer 
14153990cf9SSascha Hauer 	if (pll->type == PLL_1443X) {
14253990cf9SSascha Hauer 		pll_div_ctl1 = readl_relaxed(pll->base + DIV_CTL1);
14358f4980cSSascha Hauer 		kdiv = FIELD_GET(KDIV_MASK, pll_div_ctl1);
14453990cf9SSascha Hauer 	} else {
14553990cf9SSascha Hauer 		kdiv = 0;
14653990cf9SSascha Hauer 	}
1478646d4dcSBai Ping 
14853990cf9SSascha Hauer 	return pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, parent_rate);
1498646d4dcSBai Ping }
1508646d4dcSBai Ping 
151094234fcSLeonard Crestez static inline bool clk_pll14xx_mp_change(const struct imx_pll14xx_rate_table *rate,
1528646d4dcSBai Ping 					  u32 pll_div)
1538646d4dcSBai Ping {
1548646d4dcSBai Ping 	u32 old_mdiv, old_pdiv;
1558646d4dcSBai Ping 
15658f4980cSSascha Hauer 	old_mdiv = FIELD_GET(MDIV_MASK, pll_div);
15758f4980cSSascha Hauer 	old_pdiv = FIELD_GET(PDIV_MASK, pll_div);
1588646d4dcSBai Ping 
1598646d4dcSBai Ping 	return rate->mdiv != old_mdiv || rate->pdiv != old_pdiv;
1608646d4dcSBai Ping }
1618646d4dcSBai Ping 
1628646d4dcSBai Ping static int clk_pll14xx_wait_lock(struct clk_pll14xx *pll)
1638646d4dcSBai Ping {
1648646d4dcSBai Ping 	u32 val;
1658646d4dcSBai Ping 
166485b4ff5SSascha Hauer 	return readl_poll_timeout(pll->base + GNRL_CTL, val, val & LOCK_STATUS, 0,
1678646d4dcSBai Ping 			LOCK_TIMEOUT_US);
1688646d4dcSBai Ping }
1698646d4dcSBai Ping 
1708646d4dcSBai Ping static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate,
1718646d4dcSBai Ping 				 unsigned long prate)
1728646d4dcSBai Ping {
1738646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
1748646d4dcSBai Ping 	const struct imx_pll14xx_rate_table *rate;
1758646d4dcSBai Ping 	u32 tmp, div_val;
1768646d4dcSBai Ping 	int ret;
1778646d4dcSBai Ping 
1788646d4dcSBai Ping 	rate = imx_get_pll_settings(pll, drate);
1798646d4dcSBai Ping 	if (!rate) {
1808646d4dcSBai Ping 		pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__,
1818646d4dcSBai Ping 		       drate, clk_hw_get_name(hw));
1828646d4dcSBai Ping 		return -EINVAL;
1838646d4dcSBai Ping 	}
1848646d4dcSBai Ping 
185485b4ff5SSascha Hauer 	tmp = readl_relaxed(pll->base + DIV_CTL0);
1868646d4dcSBai Ping 
187094234fcSLeonard Crestez 	if (!clk_pll14xx_mp_change(rate, tmp)) {
188d77461a6SSascha Hauer 		tmp &= ~SDIV_MASK;
18958f4980cSSascha Hauer 		tmp |= FIELD_PREP(SDIV_MASK, rate->sdiv);
190485b4ff5SSascha Hauer 		writel_relaxed(tmp, pll->base + DIV_CTL0);
1918646d4dcSBai Ping 
1928646d4dcSBai Ping 		return 0;
1938646d4dcSBai Ping 	}
1948646d4dcSBai Ping 
1958646d4dcSBai Ping 	/* Bypass clock and set lock to pll output lock */
196485b4ff5SSascha Hauer 	tmp = readl_relaxed(pll->base + GNRL_CTL);
1978646d4dcSBai Ping 	tmp |= LOCK_SEL_MASK;
198485b4ff5SSascha Hauer 	writel_relaxed(tmp, pll->base + GNRL_CTL);
1998646d4dcSBai Ping 
2008646d4dcSBai Ping 	/* Enable RST */
2018646d4dcSBai Ping 	tmp &= ~RST_MASK;
202485b4ff5SSascha Hauer 	writel_relaxed(tmp, pll->base + GNRL_CTL);
2038646d4dcSBai Ping 
204dee1bc9cSPeng Fan 	/* Enable BYPASS */
205dee1bc9cSPeng Fan 	tmp |= BYPASS_MASK;
206485b4ff5SSascha Hauer 	writel(tmp, pll->base + GNRL_CTL);
207dee1bc9cSPeng Fan 
20858f4980cSSascha Hauer 	div_val = FIELD_PREP(MDIV_MASK, rate->mdiv) | FIELD_PREP(PDIV_MASK, rate->pdiv) |
20958f4980cSSascha Hauer 		FIELD_PREP(SDIV_MASK, rate->sdiv);
210485b4ff5SSascha Hauer 	writel_relaxed(div_val, pll->base + DIV_CTL0);
2118646d4dcSBai Ping 
2128646d4dcSBai Ping 	/*
2138646d4dcSBai Ping 	 * According to SPEC, t3 - t2 need to be greater than
2148646d4dcSBai Ping 	 * 1us and 1/FREF, respectively.
2158646d4dcSBai Ping 	 * FREF is FIN / Prediv, the prediv is [1, 63], so choose
2168646d4dcSBai Ping 	 * 3us.
2178646d4dcSBai Ping 	 */
2188646d4dcSBai Ping 	udelay(3);
2198646d4dcSBai Ping 
2208646d4dcSBai Ping 	/* Disable RST */
2218646d4dcSBai Ping 	tmp |= RST_MASK;
222485b4ff5SSascha Hauer 	writel_relaxed(tmp, pll->base + GNRL_CTL);
2238646d4dcSBai Ping 
2248646d4dcSBai Ping 	/* Wait Lock */
2258646d4dcSBai Ping 	ret = clk_pll14xx_wait_lock(pll);
2268646d4dcSBai Ping 	if (ret)
2278646d4dcSBai Ping 		return ret;
2288646d4dcSBai Ping 
2298646d4dcSBai Ping 	/* Bypass */
2308646d4dcSBai Ping 	tmp &= ~BYPASS_MASK;
231485b4ff5SSascha Hauer 	writel_relaxed(tmp, pll->base + GNRL_CTL);
2328646d4dcSBai Ping 
2338646d4dcSBai Ping 	return 0;
2348646d4dcSBai Ping }
2358646d4dcSBai Ping 
2368646d4dcSBai Ping static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate,
2378646d4dcSBai Ping 				 unsigned long prate)
2388646d4dcSBai Ping {
2398646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
2408646d4dcSBai Ping 	const struct imx_pll14xx_rate_table *rate;
241052d03a0SSascha Hauer 	u32 gnrl_ctl, div_ctl0;
2428646d4dcSBai Ping 	int ret;
2438646d4dcSBai Ping 
2448646d4dcSBai Ping 	rate = imx_get_pll_settings(pll, drate);
2458646d4dcSBai Ping 	if (!rate) {
2468646d4dcSBai Ping 		pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__,
2478646d4dcSBai Ping 			drate, clk_hw_get_name(hw));
2488646d4dcSBai Ping 		return -EINVAL;
2498646d4dcSBai Ping 	}
2508646d4dcSBai Ping 
251052d03a0SSascha Hauer 	div_ctl0 = readl_relaxed(pll->base + DIV_CTL0);
2528646d4dcSBai Ping 
253052d03a0SSascha Hauer 	if (!clk_pll14xx_mp_change(rate, div_ctl0)) {
254052d03a0SSascha Hauer 		div_ctl0 &= ~SDIV_MASK;
255052d03a0SSascha Hauer 		div_ctl0 |= FIELD_PREP(SDIV_MASK, rate->sdiv);
256052d03a0SSascha Hauer 		writel_relaxed(div_ctl0, pll->base + DIV_CTL0);
2578646d4dcSBai Ping 
258052d03a0SSascha Hauer 		writel_relaxed(FIELD_PREP(KDIV_MASK, rate->kdiv),
259052d03a0SSascha Hauer 			       pll->base + DIV_CTL1);
260094234fcSLeonard Crestez 
2618646d4dcSBai Ping 		return 0;
2628646d4dcSBai Ping 	}
2638646d4dcSBai Ping 
2648646d4dcSBai Ping 	/* Enable RST */
265052d03a0SSascha Hauer 	gnrl_ctl = readl_relaxed(pll->base + GNRL_CTL);
266052d03a0SSascha Hauer 	gnrl_ctl &= ~RST_MASK;
267052d03a0SSascha Hauer 	writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL);
2688646d4dcSBai Ping 
269dee1bc9cSPeng Fan 	/* Enable BYPASS */
270052d03a0SSascha Hauer 	gnrl_ctl |= BYPASS_MASK;
271052d03a0SSascha Hauer 	writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL);
272dee1bc9cSPeng Fan 
273052d03a0SSascha Hauer 	div_ctl0 = FIELD_PREP(MDIV_MASK, rate->mdiv) |
27458f4980cSSascha Hauer 		   FIELD_PREP(PDIV_MASK, rate->pdiv) |
27558f4980cSSascha Hauer 		   FIELD_PREP(SDIV_MASK, rate->sdiv);
276052d03a0SSascha Hauer 	writel_relaxed(div_ctl0, pll->base + DIV_CTL0);
27758f4980cSSascha Hauer 	writel_relaxed(FIELD_PREP(KDIV_MASK, rate->kdiv), pll->base + DIV_CTL1);
2788646d4dcSBai Ping 
2798646d4dcSBai Ping 	/*
2808646d4dcSBai Ping 	 * According to SPEC, t3 - t2 need to be greater than
2818646d4dcSBai Ping 	 * 1us and 1/FREF, respectively.
2828646d4dcSBai Ping 	 * FREF is FIN / Prediv, the prediv is [1, 63], so choose
2838646d4dcSBai Ping 	 * 3us.
2848646d4dcSBai Ping 	 */
2858646d4dcSBai Ping 	udelay(3);
2868646d4dcSBai Ping 
2878646d4dcSBai Ping 	/* Disable RST */
288052d03a0SSascha Hauer 	gnrl_ctl |= RST_MASK;
289052d03a0SSascha Hauer 	writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL);
2908646d4dcSBai Ping 
2918646d4dcSBai Ping 	/* Wait Lock*/
2928646d4dcSBai Ping 	ret = clk_pll14xx_wait_lock(pll);
2938646d4dcSBai Ping 	if (ret)
2948646d4dcSBai Ping 		return ret;
2958646d4dcSBai Ping 
2968646d4dcSBai Ping 	/* Bypass */
297052d03a0SSascha Hauer 	gnrl_ctl &= ~BYPASS_MASK;
298052d03a0SSascha Hauer 	writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL);
2998646d4dcSBai Ping 
3008646d4dcSBai Ping 	return 0;
3018646d4dcSBai Ping }
3028646d4dcSBai Ping 
3038646d4dcSBai Ping static int clk_pll14xx_prepare(struct clk_hw *hw)
3048646d4dcSBai Ping {
3058646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
3068646d4dcSBai Ping 	u32 val;
307dee1bc9cSPeng Fan 	int ret;
3088646d4dcSBai Ping 
3098646d4dcSBai Ping 	/*
3108646d4dcSBai Ping 	 * RESETB = 1 from 0, PLL starts its normal
3118646d4dcSBai Ping 	 * operation after lock time
3128646d4dcSBai Ping 	 */
3138646d4dcSBai Ping 	val = readl_relaxed(pll->base + GNRL_CTL);
314dee1bc9cSPeng Fan 	if (val & RST_MASK)
315dee1bc9cSPeng Fan 		return 0;
316dee1bc9cSPeng Fan 	val |= BYPASS_MASK;
317dee1bc9cSPeng Fan 	writel_relaxed(val, pll->base + GNRL_CTL);
3188646d4dcSBai Ping 	val |= RST_MASK;
3198646d4dcSBai Ping 	writel_relaxed(val, pll->base + GNRL_CTL);
3208646d4dcSBai Ping 
321dee1bc9cSPeng Fan 	ret = clk_pll14xx_wait_lock(pll);
322dee1bc9cSPeng Fan 	if (ret)
323dee1bc9cSPeng Fan 		return ret;
324dee1bc9cSPeng Fan 
325dee1bc9cSPeng Fan 	val &= ~BYPASS_MASK;
326dee1bc9cSPeng Fan 	writel_relaxed(val, pll->base + GNRL_CTL);
327dee1bc9cSPeng Fan 
328dee1bc9cSPeng Fan 	return 0;
3298646d4dcSBai Ping }
3308646d4dcSBai Ping 
3318646d4dcSBai Ping static int clk_pll14xx_is_prepared(struct clk_hw *hw)
3328646d4dcSBai Ping {
3338646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
3348646d4dcSBai Ping 	u32 val;
3358646d4dcSBai Ping 
3368646d4dcSBai Ping 	val = readl_relaxed(pll->base + GNRL_CTL);
3378646d4dcSBai Ping 
3388646d4dcSBai Ping 	return (val & RST_MASK) ? 1 : 0;
3398646d4dcSBai Ping }
3408646d4dcSBai Ping 
3418646d4dcSBai Ping static void clk_pll14xx_unprepare(struct clk_hw *hw)
3428646d4dcSBai Ping {
3438646d4dcSBai Ping 	struct clk_pll14xx *pll = to_clk_pll14xx(hw);
3448646d4dcSBai Ping 	u32 val;
3458646d4dcSBai Ping 
3468646d4dcSBai Ping 	/*
3478646d4dcSBai Ping 	 * Set RST to 0, power down mode is enabled and
3488646d4dcSBai Ping 	 * every digital block is reset
3498646d4dcSBai Ping 	 */
3508646d4dcSBai Ping 	val = readl_relaxed(pll->base + GNRL_CTL);
3518646d4dcSBai Ping 	val &= ~RST_MASK;
3528646d4dcSBai Ping 	writel_relaxed(val, pll->base + GNRL_CTL);
3538646d4dcSBai Ping }
3548646d4dcSBai Ping 
3558646d4dcSBai Ping static const struct clk_ops clk_pll1416x_ops = {
3568646d4dcSBai Ping 	.prepare	= clk_pll14xx_prepare,
3578646d4dcSBai Ping 	.unprepare	= clk_pll14xx_unprepare,
3588646d4dcSBai Ping 	.is_prepared	= clk_pll14xx_is_prepared,
35953990cf9SSascha Hauer 	.recalc_rate	= clk_pll14xx_recalc_rate,
3608646d4dcSBai Ping 	.round_rate	= clk_pll14xx_round_rate,
3618646d4dcSBai Ping 	.set_rate	= clk_pll1416x_set_rate,
3628646d4dcSBai Ping };
3638646d4dcSBai Ping 
3648646d4dcSBai Ping static const struct clk_ops clk_pll1416x_min_ops = {
36553990cf9SSascha Hauer 	.recalc_rate	= clk_pll14xx_recalc_rate,
3668646d4dcSBai Ping };
3678646d4dcSBai Ping 
3688646d4dcSBai Ping static const struct clk_ops clk_pll1443x_ops = {
3698646d4dcSBai Ping 	.prepare	= clk_pll14xx_prepare,
3708646d4dcSBai Ping 	.unprepare	= clk_pll14xx_unprepare,
3718646d4dcSBai Ping 	.is_prepared	= clk_pll14xx_is_prepared,
37253990cf9SSascha Hauer 	.recalc_rate	= clk_pll14xx_recalc_rate,
3738646d4dcSBai Ping 	.round_rate	= clk_pll14xx_round_rate,
3748646d4dcSBai Ping 	.set_rate	= clk_pll1443x_set_rate,
3758646d4dcSBai Ping };
3768646d4dcSBai Ping 
37755a8b3cdSAbel Vesa struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name,
37855a8b3cdSAbel Vesa 				const char *parent_name, void __iomem *base,
3798646d4dcSBai Ping 				const struct imx_pll14xx_clk *pll_clk)
3808646d4dcSBai Ping {
3818646d4dcSBai Ping 	struct clk_pll14xx *pll;
38210c34b50SPeng Fan 	struct clk_hw *hw;
3838646d4dcSBai Ping 	struct clk_init_data init;
38410c34b50SPeng Fan 	int ret;
385a9aa8306SPeng Fan 	u32 val;
3868646d4dcSBai Ping 
3878646d4dcSBai Ping 	pll = kzalloc(sizeof(*pll), GFP_KERNEL);
3888646d4dcSBai Ping 	if (!pll)
3898646d4dcSBai Ping 		return ERR_PTR(-ENOMEM);
3908646d4dcSBai Ping 
3918646d4dcSBai Ping 	init.name = name;
3928646d4dcSBai Ping 	init.flags = pll_clk->flags;
3938646d4dcSBai Ping 	init.parent_names = &parent_name;
3948646d4dcSBai Ping 	init.num_parents = 1;
3958646d4dcSBai Ping 
3968646d4dcSBai Ping 	switch (pll_clk->type) {
3978646d4dcSBai Ping 	case PLL_1416X:
398f89b9e1bSLeonard Crestez 		if (!pll_clk->rate_table)
3998646d4dcSBai Ping 			init.ops = &clk_pll1416x_min_ops;
4008646d4dcSBai Ping 		else
4018646d4dcSBai Ping 			init.ops = &clk_pll1416x_ops;
4028646d4dcSBai Ping 		break;
4038646d4dcSBai Ping 	case PLL_1443X:
4048646d4dcSBai Ping 		init.ops = &clk_pll1443x_ops;
4058646d4dcSBai Ping 		break;
4068646d4dcSBai Ping 	default:
4078646d4dcSBai Ping 		pr_err("%s: Unknown pll type for pll clk %s\n",
4088646d4dcSBai Ping 		       __func__, name);
409530cf8d4SAnson Huang 		kfree(pll);
410530cf8d4SAnson Huang 		return ERR_PTR(-EINVAL);
4118404c661STom Rix 	}
4128646d4dcSBai Ping 
4138646d4dcSBai Ping 	pll->base = base;
4148646d4dcSBai Ping 	pll->hw.init = &init;
4158646d4dcSBai Ping 	pll->type = pll_clk->type;
4168646d4dcSBai Ping 	pll->rate_table = pll_clk->rate_table;
4178646d4dcSBai Ping 	pll->rate_count = pll_clk->rate_count;
4188646d4dcSBai Ping 
419a9aa8306SPeng Fan 	val = readl_relaxed(pll->base + GNRL_CTL);
420a9aa8306SPeng Fan 	val &= ~BYPASS_MASK;
421a9aa8306SPeng Fan 	writel_relaxed(val, pll->base + GNRL_CTL);
422a9aa8306SPeng Fan 
42310c34b50SPeng Fan 	hw = &pll->hw;
42410c34b50SPeng Fan 
42555a8b3cdSAbel Vesa 	ret = clk_hw_register(dev, hw);
42610c34b50SPeng Fan 	if (ret) {
42710c34b50SPeng Fan 		pr_err("%s: failed to register pll %s %d\n",
42810c34b50SPeng Fan 			__func__, name, ret);
4298646d4dcSBai Ping 		kfree(pll);
43010c34b50SPeng Fan 		return ERR_PTR(ret);
4318646d4dcSBai Ping 	}
4328646d4dcSBai Ping 
43310c34b50SPeng Fan 	return hw;
4348646d4dcSBai Ping }
435870ed5e2SAnson Huang EXPORT_SYMBOL_GPL(imx_dev_clk_hw_pll14xx);
436