11b26cb8aSPeng Fan // SPDX-License-Identifier: GPL-2.0
21b26cb8aSPeng Fan /*
31b26cb8aSPeng Fan * Copyright 2021 NXP
41b26cb8aSPeng Fan */
51b26cb8aSPeng Fan
61b26cb8aSPeng Fan #include <linux/bitfield.h>
71b26cb8aSPeng Fan #include <linux/clk-provider.h>
81b26cb8aSPeng Fan #include <linux/err.h>
91b26cb8aSPeng Fan #include <linux/export.h>
101b26cb8aSPeng Fan #include <linux/io.h>
111b26cb8aSPeng Fan #include <linux/iopoll.h>
121b26cb8aSPeng Fan #include <linux/slab.h>
131b26cb8aSPeng Fan #include <asm/div64.h>
141b26cb8aSPeng Fan
151b26cb8aSPeng Fan #include "clk.h"
161b26cb8aSPeng Fan
171b26cb8aSPeng Fan #define PLL_CTRL 0x0
184435467bSPeng Fan #define HW_CTRL_SEL BIT(16)
191b26cb8aSPeng Fan #define CLKMUX_BYPASS BIT(2)
201b26cb8aSPeng Fan #define CLKMUX_EN BIT(1)
211b26cb8aSPeng Fan #define POWERUP_MASK BIT(0)
221b26cb8aSPeng Fan
231b26cb8aSPeng Fan #define PLL_ANA_PRG 0x10
241b26cb8aSPeng Fan #define PLL_SPREAD_SPECTRUM 0x30
251b26cb8aSPeng Fan
261b26cb8aSPeng Fan #define PLL_NUMERATOR 0x40
271b26cb8aSPeng Fan #define PLL_MFN_MASK GENMASK(31, 2)
281b26cb8aSPeng Fan
291b26cb8aSPeng Fan #define PLL_DENOMINATOR 0x50
301b26cb8aSPeng Fan #define PLL_MFD_MASK GENMASK(29, 0)
311b26cb8aSPeng Fan
321b26cb8aSPeng Fan #define PLL_DIV 0x60
331b26cb8aSPeng Fan #define PLL_MFI_MASK GENMASK(24, 16)
341b26cb8aSPeng Fan #define PLL_RDIV_MASK GENMASK(15, 13)
351b26cb8aSPeng Fan #define PLL_ODIV_MASK GENMASK(7, 0)
361b26cb8aSPeng Fan
371b26cb8aSPeng Fan #define PLL_DFS_CTRL(x) (0x70 + (x) * 0x10)
381b26cb8aSPeng Fan
391b26cb8aSPeng Fan #define PLL_STATUS 0xF0
401b26cb8aSPeng Fan #define LOCK_STATUS BIT(0)
411b26cb8aSPeng Fan
421b26cb8aSPeng Fan #define DFS_STATUS 0xF4
431b26cb8aSPeng Fan
441b26cb8aSPeng Fan #define LOCK_TIMEOUT_US 200
451b26cb8aSPeng Fan
461b26cb8aSPeng Fan #define PLL_FRACN_GP(_rate, _mfi, _mfn, _mfd, _rdiv, _odiv) \
471b26cb8aSPeng Fan { \
481b26cb8aSPeng Fan .rate = (_rate), \
491b26cb8aSPeng Fan .mfi = (_mfi), \
501b26cb8aSPeng Fan .mfn = (_mfn), \
511b26cb8aSPeng Fan .mfd = (_mfd), \
521b26cb8aSPeng Fan .rdiv = (_rdiv), \
531b26cb8aSPeng Fan .odiv = (_odiv), \
541b26cb8aSPeng Fan }
551b26cb8aSPeng Fan
5656b8d0bfSPeng Fan #define PLL_FRACN_GP_INTEGER(_rate, _mfi, _rdiv, _odiv) \
5756b8d0bfSPeng Fan { \
5856b8d0bfSPeng Fan .rate = (_rate), \
5956b8d0bfSPeng Fan .mfi = (_mfi), \
6056b8d0bfSPeng Fan .mfn = 0, \
6156b8d0bfSPeng Fan .mfd = 0, \
6256b8d0bfSPeng Fan .rdiv = (_rdiv), \
6356b8d0bfSPeng Fan .odiv = (_odiv), \
6456b8d0bfSPeng Fan }
6556b8d0bfSPeng Fan
661b26cb8aSPeng Fan struct clk_fracn_gppll {
671b26cb8aSPeng Fan struct clk_hw hw;
681b26cb8aSPeng Fan void __iomem *base;
691b26cb8aSPeng Fan const struct imx_fracn_gppll_rate_table *rate_table;
701b26cb8aSPeng Fan int rate_count;
7156b8d0bfSPeng Fan u32 flags;
721b26cb8aSPeng Fan };
731b26cb8aSPeng Fan
741b26cb8aSPeng Fan /*
75cf8dccfeSPeng Fan * Fvco = (Fref / rdiv) * (MFI + MFN / MFD)
76cf8dccfeSPeng Fan * Fout = Fvco / odiv
77cf8dccfeSPeng Fan * The (Fref / rdiv) should be in range 20MHz to 40MHz
78cf8dccfeSPeng Fan * The Fvco should be in range 2.5Ghz to 5Ghz
791b26cb8aSPeng Fan */
801b26cb8aSPeng Fan static const struct imx_fracn_gppll_rate_table fracn_tbl[] = {
81cf8dccfeSPeng Fan PLL_FRACN_GP(650000000U, 162, 50, 100, 0, 6),
82044034efSPeng Fan PLL_FRACN_GP(594000000U, 198, 0, 1, 0, 8),
83cf8dccfeSPeng Fan PLL_FRACN_GP(560000000U, 140, 0, 1, 0, 6),
8407ba6d1aSJacky Bai PLL_FRACN_GP(519750000U, 173, 25, 100, 1, 8),
85cf8dccfeSPeng Fan PLL_FRACN_GP(498000000U, 166, 0, 1, 0, 8),
86c196175aSPeng Fan PLL_FRACN_GP(484000000U, 121, 0, 1, 0, 6),
87c196175aSPeng Fan PLL_FRACN_GP(445333333U, 167, 0, 1, 0, 9),
88cf8dccfeSPeng Fan PLL_FRACN_GP(400000000U, 200, 0, 1, 0, 12),
89e0408971SJacky Bai PLL_FRACN_GP(393216000U, 163, 84, 100, 0, 10),
90e0408971SJacky Bai PLL_FRACN_GP(300000000U, 150, 0, 1, 0, 12)
911b26cb8aSPeng Fan };
921b26cb8aSPeng Fan
931b26cb8aSPeng Fan struct imx_fracn_gppll_clk imx_fracn_gppll = {
941b26cb8aSPeng Fan .rate_table = fracn_tbl,
951b26cb8aSPeng Fan .rate_count = ARRAY_SIZE(fracn_tbl),
961b26cb8aSPeng Fan };
971b26cb8aSPeng Fan EXPORT_SYMBOL_GPL(imx_fracn_gppll);
981b26cb8aSPeng Fan
9956b8d0bfSPeng Fan /*
10056b8d0bfSPeng Fan * Fvco = (Fref / rdiv) * MFI
10156b8d0bfSPeng Fan * Fout = Fvco / odiv
10256b8d0bfSPeng Fan * The (Fref / rdiv) should be in range 20MHz to 40MHz
10356b8d0bfSPeng Fan * The Fvco should be in range 2.5Ghz to 5Ghz
10456b8d0bfSPeng Fan */
10556b8d0bfSPeng Fan static const struct imx_fracn_gppll_rate_table int_tbl[] = {
10656b8d0bfSPeng Fan PLL_FRACN_GP_INTEGER(1700000000U, 141, 1, 2),
10756b8d0bfSPeng Fan PLL_FRACN_GP_INTEGER(1400000000U, 175, 1, 3),
10856b8d0bfSPeng Fan PLL_FRACN_GP_INTEGER(900000000U, 150, 1, 4),
10956b8d0bfSPeng Fan };
11056b8d0bfSPeng Fan
11156b8d0bfSPeng Fan struct imx_fracn_gppll_clk imx_fracn_gppll_integer = {
11256b8d0bfSPeng Fan .rate_table = int_tbl,
11356b8d0bfSPeng Fan .rate_count = ARRAY_SIZE(int_tbl),
11456b8d0bfSPeng Fan };
11556b8d0bfSPeng Fan EXPORT_SYMBOL_GPL(imx_fracn_gppll_integer);
11656b8d0bfSPeng Fan
to_clk_fracn_gppll(struct clk_hw * hw)1171b26cb8aSPeng Fan static inline struct clk_fracn_gppll *to_clk_fracn_gppll(struct clk_hw *hw)
1181b26cb8aSPeng Fan {
1191b26cb8aSPeng Fan return container_of(hw, struct clk_fracn_gppll, hw);
1201b26cb8aSPeng Fan }
1211b26cb8aSPeng Fan
1221b26cb8aSPeng Fan static const struct imx_fracn_gppll_rate_table *
imx_get_pll_settings(struct clk_fracn_gppll * pll,unsigned long rate)1231b26cb8aSPeng Fan imx_get_pll_settings(struct clk_fracn_gppll *pll, unsigned long rate)
1241b26cb8aSPeng Fan {
1251b26cb8aSPeng Fan const struct imx_fracn_gppll_rate_table *rate_table = pll->rate_table;
1261b26cb8aSPeng Fan int i;
1271b26cb8aSPeng Fan
1281b26cb8aSPeng Fan for (i = 0; i < pll->rate_count; i++)
1291b26cb8aSPeng Fan if (rate == rate_table[i].rate)
1301b26cb8aSPeng Fan return &rate_table[i];
1311b26cb8aSPeng Fan
1321b26cb8aSPeng Fan return NULL;
1331b26cb8aSPeng Fan }
1341b26cb8aSPeng Fan
clk_fracn_gppll_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * prate)1351b26cb8aSPeng Fan static long clk_fracn_gppll_round_rate(struct clk_hw *hw, unsigned long rate,
1361b26cb8aSPeng Fan unsigned long *prate)
1371b26cb8aSPeng Fan {
1381b26cb8aSPeng Fan struct clk_fracn_gppll *pll = to_clk_fracn_gppll(hw);
1391b26cb8aSPeng Fan const struct imx_fracn_gppll_rate_table *rate_table = pll->rate_table;
1401b26cb8aSPeng Fan int i;
1411b26cb8aSPeng Fan
1421b26cb8aSPeng Fan /* Assuming rate_table is in descending order */
1431b26cb8aSPeng Fan for (i = 0; i < pll->rate_count; i++)
1441b26cb8aSPeng Fan if (rate >= rate_table[i].rate)
1451b26cb8aSPeng Fan return rate_table[i].rate;
1461b26cb8aSPeng Fan
1471b26cb8aSPeng Fan /* return minimum supported value */
1481b26cb8aSPeng Fan return rate_table[pll->rate_count - 1].rate;
1491b26cb8aSPeng Fan }
1501b26cb8aSPeng Fan
clk_fracn_gppll_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)1511b26cb8aSPeng Fan static unsigned long clk_fracn_gppll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
1521b26cb8aSPeng Fan {
1531b26cb8aSPeng Fan struct clk_fracn_gppll *pll = to_clk_fracn_gppll(hw);
1541b26cb8aSPeng Fan const struct imx_fracn_gppll_rate_table *rate_table = pll->rate_table;
1551b26cb8aSPeng Fan u32 pll_numerator, pll_denominator, pll_div;
1561b26cb8aSPeng Fan u32 mfi, mfn, mfd, rdiv, odiv;
1571b26cb8aSPeng Fan u64 fvco = parent_rate;
1581b26cb8aSPeng Fan long rate = 0;
1591b26cb8aSPeng Fan int i;
1601b26cb8aSPeng Fan
1611b26cb8aSPeng Fan pll_numerator = readl_relaxed(pll->base + PLL_NUMERATOR);
1621b26cb8aSPeng Fan mfn = FIELD_GET(PLL_MFN_MASK, pll_numerator);
1631b26cb8aSPeng Fan
1641b26cb8aSPeng Fan pll_denominator = readl_relaxed(pll->base + PLL_DENOMINATOR);
1651b26cb8aSPeng Fan mfd = FIELD_GET(PLL_MFD_MASK, pll_denominator);
1661b26cb8aSPeng Fan
1671b26cb8aSPeng Fan pll_div = readl_relaxed(pll->base + PLL_DIV);
1681b26cb8aSPeng Fan mfi = FIELD_GET(PLL_MFI_MASK, pll_div);
1691b26cb8aSPeng Fan
1701b26cb8aSPeng Fan rdiv = FIELD_GET(PLL_RDIV_MASK, pll_div);
1711b26cb8aSPeng Fan odiv = FIELD_GET(PLL_ODIV_MASK, pll_div);
1721b26cb8aSPeng Fan
1731b26cb8aSPeng Fan /*
1741b26cb8aSPeng Fan * Sometimes, the recalculated rate has deviation due to
1751b26cb8aSPeng Fan * the frac part. So find the accurate pll rate from the table
1761b26cb8aSPeng Fan * first, if no match rate in the table, use the rate calculated
1771b26cb8aSPeng Fan * from the equation below.
1781b26cb8aSPeng Fan */
1791b26cb8aSPeng Fan for (i = 0; i < pll->rate_count; i++) {
1801b26cb8aSPeng Fan if (rate_table[i].mfn == mfn && rate_table[i].mfi == mfi &&
1811b26cb8aSPeng Fan rate_table[i].mfd == mfd && rate_table[i].rdiv == rdiv &&
1821b26cb8aSPeng Fan rate_table[i].odiv == odiv)
1831b26cb8aSPeng Fan rate = rate_table[i].rate;
1841b26cb8aSPeng Fan }
1851b26cb8aSPeng Fan
1861b26cb8aSPeng Fan if (rate)
1871b26cb8aSPeng Fan return (unsigned long)rate;
1881b26cb8aSPeng Fan
189f300cb7fSPeng Fan if (!rdiv)
1905ebaf9f7SLiu Ying rdiv = rdiv + 1;
1915ebaf9f7SLiu Ying
1925ebaf9f7SLiu Ying switch (odiv) {
1935ebaf9f7SLiu Ying case 0:
1945ebaf9f7SLiu Ying odiv = 2;
1955ebaf9f7SLiu Ying break;
1965ebaf9f7SLiu Ying case 1:
1975ebaf9f7SLiu Ying odiv = 3;
1985ebaf9f7SLiu Ying break;
1995ebaf9f7SLiu Ying default:
2005ebaf9f7SLiu Ying break;
2015ebaf9f7SLiu Ying }
2025ebaf9f7SLiu Ying
20356b8d0bfSPeng Fan if (pll->flags & CLK_FRACN_GPPLL_INTEGER) {
20456b8d0bfSPeng Fan /* Fvco = (Fref / rdiv) * MFI */
20556b8d0bfSPeng Fan fvco = fvco * mfi;
20656b8d0bfSPeng Fan do_div(fvco, rdiv * odiv);
20756b8d0bfSPeng Fan } else {
20856b8d0bfSPeng Fan /* Fvco = (Fref / rdiv) * (MFI + MFN / MFD) */
2091b26cb8aSPeng Fan fvco = fvco * mfi * mfd + fvco * mfn;
2101b26cb8aSPeng Fan do_div(fvco, mfd * rdiv * odiv);
21156b8d0bfSPeng Fan }
2121b26cb8aSPeng Fan
2131b26cb8aSPeng Fan return (unsigned long)fvco;
2141b26cb8aSPeng Fan }
2151b26cb8aSPeng Fan
clk_fracn_gppll_wait_lock(struct clk_fracn_gppll * pll)2161b26cb8aSPeng Fan static int clk_fracn_gppll_wait_lock(struct clk_fracn_gppll *pll)
2171b26cb8aSPeng Fan {
2181b26cb8aSPeng Fan u32 val;
2191b26cb8aSPeng Fan
2201b26cb8aSPeng Fan return readl_poll_timeout(pll->base + PLL_STATUS, val,
2211b26cb8aSPeng Fan val & LOCK_STATUS, 0, LOCK_TIMEOUT_US);
2221b26cb8aSPeng Fan }
2231b26cb8aSPeng Fan
clk_fracn_gppll_set_rate(struct clk_hw * hw,unsigned long drate,unsigned long prate)2241b26cb8aSPeng Fan static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate,
2251b26cb8aSPeng Fan unsigned long prate)
2261b26cb8aSPeng Fan {
2271b26cb8aSPeng Fan struct clk_fracn_gppll *pll = to_clk_fracn_gppll(hw);
2281b26cb8aSPeng Fan const struct imx_fracn_gppll_rate_table *rate;
2291b26cb8aSPeng Fan u32 tmp, pll_div, ana_mfn;
2301b26cb8aSPeng Fan int ret;
2311b26cb8aSPeng Fan
2321b26cb8aSPeng Fan rate = imx_get_pll_settings(pll, drate);
2331b26cb8aSPeng Fan
2344435467bSPeng Fan /* Hardware control select disable. PLL is control by register */
2354435467bSPeng Fan tmp = readl_relaxed(pll->base + PLL_CTRL);
2364435467bSPeng Fan tmp &= ~HW_CTRL_SEL;
2374435467bSPeng Fan writel_relaxed(tmp, pll->base + PLL_CTRL);
2384435467bSPeng Fan
2391b26cb8aSPeng Fan /* Disable output */
2401b26cb8aSPeng Fan tmp = readl_relaxed(pll->base + PLL_CTRL);
2411b26cb8aSPeng Fan tmp &= ~CLKMUX_EN;
2421b26cb8aSPeng Fan writel_relaxed(tmp, pll->base + PLL_CTRL);
2431b26cb8aSPeng Fan
2441b26cb8aSPeng Fan /* Power Down */
2451b26cb8aSPeng Fan tmp &= ~POWERUP_MASK;
2461b26cb8aSPeng Fan writel_relaxed(tmp, pll->base + PLL_CTRL);
2471b26cb8aSPeng Fan
2481b26cb8aSPeng Fan /* Disable BYPASS */
2491b26cb8aSPeng Fan tmp &= ~CLKMUX_BYPASS;
2501b26cb8aSPeng Fan writel_relaxed(tmp, pll->base + PLL_CTRL);
2511b26cb8aSPeng Fan
2521b26cb8aSPeng Fan pll_div = FIELD_PREP(PLL_RDIV_MASK, rate->rdiv) | rate->odiv |
2531b26cb8aSPeng Fan FIELD_PREP(PLL_MFI_MASK, rate->mfi);
2541b26cb8aSPeng Fan writel_relaxed(pll_div, pll->base + PLL_DIV);
255*b92706bdSPeng Fan readl(pll->base + PLL_DIV);
25656b8d0bfSPeng Fan if (pll->flags & CLK_FRACN_GPPLL_FRACN) {
2571b26cb8aSPeng Fan writel_relaxed(rate->mfd, pll->base + PLL_DENOMINATOR);
2581b26cb8aSPeng Fan writel_relaxed(FIELD_PREP(PLL_MFN_MASK, rate->mfn), pll->base + PLL_NUMERATOR);
259*b92706bdSPeng Fan readl(pll->base + PLL_NUMERATOR);
26056b8d0bfSPeng Fan }
2611b26cb8aSPeng Fan
2621b26cb8aSPeng Fan /* Wait for 5us according to fracn mode pll doc */
2631b26cb8aSPeng Fan udelay(5);
2641b26cb8aSPeng Fan
2651b26cb8aSPeng Fan /* Enable Powerup */
2661b26cb8aSPeng Fan tmp |= POWERUP_MASK;
2671b26cb8aSPeng Fan writel_relaxed(tmp, pll->base + PLL_CTRL);
268*b92706bdSPeng Fan readl(pll->base + PLL_CTRL);
2691b26cb8aSPeng Fan
2701b26cb8aSPeng Fan /* Wait Lock */
2711b26cb8aSPeng Fan ret = clk_fracn_gppll_wait_lock(pll);
2721b26cb8aSPeng Fan if (ret)
2731b26cb8aSPeng Fan return ret;
2741b26cb8aSPeng Fan
2751b26cb8aSPeng Fan /* Enable output */
2761b26cb8aSPeng Fan tmp |= CLKMUX_EN;
2771b26cb8aSPeng Fan writel_relaxed(tmp, pll->base + PLL_CTRL);
2781b26cb8aSPeng Fan
2791b26cb8aSPeng Fan ana_mfn = readl_relaxed(pll->base + PLL_STATUS);
2801b26cb8aSPeng Fan ana_mfn = FIELD_GET(PLL_MFN_MASK, ana_mfn);
2811b26cb8aSPeng Fan
2821b26cb8aSPeng Fan WARN(ana_mfn != rate->mfn, "ana_mfn != rate->mfn\n");
2831b26cb8aSPeng Fan
2841b26cb8aSPeng Fan return 0;
2851b26cb8aSPeng Fan }
2861b26cb8aSPeng Fan
clk_fracn_gppll_prepare(struct clk_hw * hw)2871b26cb8aSPeng Fan static int clk_fracn_gppll_prepare(struct clk_hw *hw)
2881b26cb8aSPeng Fan {
2891b26cb8aSPeng Fan struct clk_fracn_gppll *pll = to_clk_fracn_gppll(hw);
2901b26cb8aSPeng Fan u32 val;
2911b26cb8aSPeng Fan int ret;
2921b26cb8aSPeng Fan
2931b26cb8aSPeng Fan val = readl_relaxed(pll->base + PLL_CTRL);
2941b26cb8aSPeng Fan if (val & POWERUP_MASK)
2951b26cb8aSPeng Fan return 0;
2961b26cb8aSPeng Fan
297908165b5SPengfei Li if (pll->flags & CLK_FRACN_GPPLL_FRACN)
298908165b5SPengfei Li writel_relaxed(readl_relaxed(pll->base + PLL_NUMERATOR),
299908165b5SPengfei Li pll->base + PLL_NUMERATOR);
300908165b5SPengfei Li
3011b26cb8aSPeng Fan val |= CLKMUX_BYPASS;
3021b26cb8aSPeng Fan writel_relaxed(val, pll->base + PLL_CTRL);
3031b26cb8aSPeng Fan
3041b26cb8aSPeng Fan val |= POWERUP_MASK;
3051b26cb8aSPeng Fan writel_relaxed(val, pll->base + PLL_CTRL);
306*b92706bdSPeng Fan readl(pll->base + PLL_CTRL);
3071b26cb8aSPeng Fan
3081b26cb8aSPeng Fan ret = clk_fracn_gppll_wait_lock(pll);
3091b26cb8aSPeng Fan if (ret)
3101b26cb8aSPeng Fan return ret;
3111b26cb8aSPeng Fan
312db62437bSPeng Fan val |= CLKMUX_EN;
313db62437bSPeng Fan writel_relaxed(val, pll->base + PLL_CTRL);
314db62437bSPeng Fan
3151b26cb8aSPeng Fan val &= ~CLKMUX_BYPASS;
3161b26cb8aSPeng Fan writel_relaxed(val, pll->base + PLL_CTRL);
3171b26cb8aSPeng Fan
3181b26cb8aSPeng Fan return 0;
3191b26cb8aSPeng Fan }
3201b26cb8aSPeng Fan
clk_fracn_gppll_is_prepared(struct clk_hw * hw)3211b26cb8aSPeng Fan static int clk_fracn_gppll_is_prepared(struct clk_hw *hw)
3221b26cb8aSPeng Fan {
3231b26cb8aSPeng Fan struct clk_fracn_gppll *pll = to_clk_fracn_gppll(hw);
3241b26cb8aSPeng Fan u32 val;
3251b26cb8aSPeng Fan
3261b26cb8aSPeng Fan val = readl_relaxed(pll->base + PLL_CTRL);
3271b26cb8aSPeng Fan
3281b26cb8aSPeng Fan return (val & POWERUP_MASK) ? 1 : 0;
3291b26cb8aSPeng Fan }
3301b26cb8aSPeng Fan
clk_fracn_gppll_unprepare(struct clk_hw * hw)3311b26cb8aSPeng Fan static void clk_fracn_gppll_unprepare(struct clk_hw *hw)
3321b26cb8aSPeng Fan {
3331b26cb8aSPeng Fan struct clk_fracn_gppll *pll = to_clk_fracn_gppll(hw);
3341b26cb8aSPeng Fan u32 val;
3351b26cb8aSPeng Fan
3361b26cb8aSPeng Fan val = readl_relaxed(pll->base + PLL_CTRL);
3371b26cb8aSPeng Fan val &= ~POWERUP_MASK;
3381b26cb8aSPeng Fan writel_relaxed(val, pll->base + PLL_CTRL);
3391b26cb8aSPeng Fan }
3401b26cb8aSPeng Fan
3411b26cb8aSPeng Fan static const struct clk_ops clk_fracn_gppll_ops = {
3421b26cb8aSPeng Fan .prepare = clk_fracn_gppll_prepare,
3431b26cb8aSPeng Fan .unprepare = clk_fracn_gppll_unprepare,
3441b26cb8aSPeng Fan .is_prepared = clk_fracn_gppll_is_prepared,
3451b26cb8aSPeng Fan .recalc_rate = clk_fracn_gppll_recalc_rate,
3461b26cb8aSPeng Fan .round_rate = clk_fracn_gppll_round_rate,
3471b26cb8aSPeng Fan .set_rate = clk_fracn_gppll_set_rate,
3481b26cb8aSPeng Fan };
3491b26cb8aSPeng Fan
_imx_clk_fracn_gppll(const char * name,const char * parent_name,void __iomem * base,const struct imx_fracn_gppll_clk * pll_clk,u32 pll_flags)35056b8d0bfSPeng Fan static struct clk_hw *_imx_clk_fracn_gppll(const char *name, const char *parent_name,
35156b8d0bfSPeng Fan void __iomem *base,
35256b8d0bfSPeng Fan const struct imx_fracn_gppll_clk *pll_clk,
35356b8d0bfSPeng Fan u32 pll_flags)
3541b26cb8aSPeng Fan {
3551b26cb8aSPeng Fan struct clk_fracn_gppll *pll;
3561b26cb8aSPeng Fan struct clk_hw *hw;
3571b26cb8aSPeng Fan struct clk_init_data init;
3581b26cb8aSPeng Fan int ret;
3591b26cb8aSPeng Fan
3601b26cb8aSPeng Fan pll = kzalloc(sizeof(*pll), GFP_KERNEL);
3611b26cb8aSPeng Fan if (!pll)
3621b26cb8aSPeng Fan return ERR_PTR(-ENOMEM);
3631b26cb8aSPeng Fan
3641b26cb8aSPeng Fan init.name = name;
3651b26cb8aSPeng Fan init.flags = pll_clk->flags;
3661b26cb8aSPeng Fan init.parent_names = &parent_name;
3671b26cb8aSPeng Fan init.num_parents = 1;
3681b26cb8aSPeng Fan init.ops = &clk_fracn_gppll_ops;
3691b26cb8aSPeng Fan
3701b26cb8aSPeng Fan pll->base = base;
3711b26cb8aSPeng Fan pll->hw.init = &init;
3721b26cb8aSPeng Fan pll->rate_table = pll_clk->rate_table;
3731b26cb8aSPeng Fan pll->rate_count = pll_clk->rate_count;
37456b8d0bfSPeng Fan pll->flags = pll_flags;
3751b26cb8aSPeng Fan
3761b26cb8aSPeng Fan hw = &pll->hw;
3771b26cb8aSPeng Fan
3781b26cb8aSPeng Fan ret = clk_hw_register(NULL, hw);
3791b26cb8aSPeng Fan if (ret) {
3801b26cb8aSPeng Fan pr_err("%s: failed to register pll %s %d\n", __func__, name, ret);
3811b26cb8aSPeng Fan kfree(pll);
3821b26cb8aSPeng Fan return ERR_PTR(ret);
3831b26cb8aSPeng Fan }
3841b26cb8aSPeng Fan
3851b26cb8aSPeng Fan return hw;
3861b26cb8aSPeng Fan }
38756b8d0bfSPeng Fan
imx_clk_fracn_gppll(const char * name,const char * parent_name,void __iomem * base,const struct imx_fracn_gppll_clk * pll_clk)38856b8d0bfSPeng Fan struct clk_hw *imx_clk_fracn_gppll(const char *name, const char *parent_name, void __iomem *base,
38956b8d0bfSPeng Fan const struct imx_fracn_gppll_clk *pll_clk)
39056b8d0bfSPeng Fan {
39156b8d0bfSPeng Fan return _imx_clk_fracn_gppll(name, parent_name, base, pll_clk, CLK_FRACN_GPPLL_FRACN);
39256b8d0bfSPeng Fan }
3931b26cb8aSPeng Fan EXPORT_SYMBOL_GPL(imx_clk_fracn_gppll);
39456b8d0bfSPeng Fan
imx_clk_fracn_gppll_integer(const char * name,const char * parent_name,void __iomem * base,const struct imx_fracn_gppll_clk * pll_clk)39556b8d0bfSPeng Fan struct clk_hw *imx_clk_fracn_gppll_integer(const char *name, const char *parent_name,
39656b8d0bfSPeng Fan void __iomem *base,
39756b8d0bfSPeng Fan const struct imx_fracn_gppll_clk *pll_clk)
39856b8d0bfSPeng Fan {
39956b8d0bfSPeng Fan return _imx_clk_fracn_gppll(name, parent_name, base, pll_clk, CLK_FRACN_GPPLL_INTEGER);
40056b8d0bfSPeng Fan }
40156b8d0bfSPeng Fan EXPORT_SYMBOL_GPL(imx_clk_fracn_gppll_integer);
402