18646d4dcSBai Ping // SPDX-License-Identifier: GPL-2.0 28646d4dcSBai Ping /* 38646d4dcSBai Ping * Copyright 2017-2018 NXP. 48646d4dcSBai Ping */ 58646d4dcSBai Ping 6*58f4980cSSascha 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 1008646d4dcSBai Ping static long clk_pll14xx_round_rate(struct clk_hw *hw, unsigned long rate, 1018646d4dcSBai Ping unsigned long *prate) 1028646d4dcSBai Ping { 1038646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 1048646d4dcSBai Ping const struct imx_pll14xx_rate_table *rate_table = pll->rate_table; 1058646d4dcSBai Ping int i; 1068646d4dcSBai Ping 1078646d4dcSBai Ping /* Assumming rate_table is in descending order */ 1088646d4dcSBai Ping for (i = 0; i < pll->rate_count; i++) 1098646d4dcSBai Ping if (rate >= rate_table[i].rate) 1108646d4dcSBai Ping return rate_table[i].rate; 1118646d4dcSBai Ping 1128646d4dcSBai Ping /* return minimum supported value */ 1138646d4dcSBai Ping return rate_table[i - 1].rate; 1148646d4dcSBai Ping } 1158646d4dcSBai Ping 1168646d4dcSBai Ping static unsigned long clk_pll1416x_recalc_rate(struct clk_hw *hw, 1178646d4dcSBai Ping unsigned long parent_rate) 1188646d4dcSBai Ping { 1198646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 120a3c9e13fSPeng Fan u32 mdiv, pdiv, sdiv, pll_div; 1218646d4dcSBai Ping u64 fvco = parent_rate; 1228646d4dcSBai Ping 123485b4ff5SSascha Hauer pll_div = readl_relaxed(pll->base + DIV_CTL0); 124*58f4980cSSascha Hauer mdiv = FIELD_GET(MDIV_MASK, pll_div); 125*58f4980cSSascha Hauer pdiv = FIELD_GET(PDIV_MASK, pll_div); 126*58f4980cSSascha Hauer sdiv = FIELD_GET(SDIV_MASK, pll_div); 1278646d4dcSBai Ping 1288646d4dcSBai Ping fvco *= mdiv; 1298646d4dcSBai Ping do_div(fvco, pdiv << sdiv); 1308646d4dcSBai Ping 1318646d4dcSBai Ping return fvco; 1328646d4dcSBai Ping } 1338646d4dcSBai Ping 1348646d4dcSBai Ping static unsigned long clk_pll1443x_recalc_rate(struct clk_hw *hw, 1358646d4dcSBai Ping unsigned long parent_rate) 1368646d4dcSBai Ping { 1378646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 138a3c9e13fSPeng Fan u32 mdiv, pdiv, sdiv, pll_div_ctl0, pll_div_ctl1; 1398646d4dcSBai Ping short int kdiv; 1408646d4dcSBai Ping u64 fvco = parent_rate; 1418646d4dcSBai Ping 142485b4ff5SSascha Hauer pll_div_ctl0 = readl_relaxed(pll->base + DIV_CTL0); 143485b4ff5SSascha Hauer pll_div_ctl1 = readl_relaxed(pll->base + DIV_CTL1); 144*58f4980cSSascha Hauer mdiv = FIELD_GET(MDIV_MASK, pll_div_ctl0); 145*58f4980cSSascha Hauer pdiv = FIELD_GET(PDIV_MASK, pll_div_ctl0); 146*58f4980cSSascha Hauer sdiv = FIELD_GET(SDIV_MASK, pll_div_ctl0); 147*58f4980cSSascha Hauer kdiv = FIELD_GET(KDIV_MASK, pll_div_ctl1); 1488646d4dcSBai Ping 1498646d4dcSBai Ping /* fvco = (m * 65536 + k) * Fin / (p * 65536) */ 1508646d4dcSBai Ping fvco *= (mdiv * 65536 + kdiv); 1518646d4dcSBai Ping pdiv *= 65536; 1528646d4dcSBai Ping 1538646d4dcSBai Ping do_div(fvco, pdiv << sdiv); 1548646d4dcSBai Ping 1558646d4dcSBai Ping return fvco; 1568646d4dcSBai Ping } 1578646d4dcSBai Ping 158094234fcSLeonard Crestez static inline bool clk_pll14xx_mp_change(const struct imx_pll14xx_rate_table *rate, 1598646d4dcSBai Ping u32 pll_div) 1608646d4dcSBai Ping { 1618646d4dcSBai Ping u32 old_mdiv, old_pdiv; 1628646d4dcSBai Ping 163*58f4980cSSascha Hauer old_mdiv = FIELD_GET(MDIV_MASK, pll_div); 164*58f4980cSSascha Hauer old_pdiv = FIELD_GET(PDIV_MASK, pll_div); 1658646d4dcSBai Ping 1668646d4dcSBai Ping return rate->mdiv != old_mdiv || rate->pdiv != old_pdiv; 1678646d4dcSBai Ping } 1688646d4dcSBai Ping 1698646d4dcSBai Ping static int clk_pll14xx_wait_lock(struct clk_pll14xx *pll) 1708646d4dcSBai Ping { 1718646d4dcSBai Ping u32 val; 1728646d4dcSBai Ping 173485b4ff5SSascha Hauer return readl_poll_timeout(pll->base + GNRL_CTL, val, val & LOCK_STATUS, 0, 1748646d4dcSBai Ping LOCK_TIMEOUT_US); 1758646d4dcSBai Ping } 1768646d4dcSBai Ping 1778646d4dcSBai Ping static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate, 1788646d4dcSBai Ping unsigned long prate) 1798646d4dcSBai Ping { 1808646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 1818646d4dcSBai Ping const struct imx_pll14xx_rate_table *rate; 1828646d4dcSBai Ping u32 tmp, div_val; 1838646d4dcSBai Ping int ret; 1848646d4dcSBai Ping 1858646d4dcSBai Ping rate = imx_get_pll_settings(pll, drate); 1868646d4dcSBai Ping if (!rate) { 1878646d4dcSBai Ping pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__, 1888646d4dcSBai Ping drate, clk_hw_get_name(hw)); 1898646d4dcSBai Ping return -EINVAL; 1908646d4dcSBai Ping } 1918646d4dcSBai Ping 192485b4ff5SSascha Hauer tmp = readl_relaxed(pll->base + DIV_CTL0); 1938646d4dcSBai Ping 194094234fcSLeonard Crestez if (!clk_pll14xx_mp_change(rate, tmp)) { 195d77461a6SSascha Hauer tmp &= ~SDIV_MASK; 196*58f4980cSSascha Hauer tmp |= FIELD_PREP(SDIV_MASK, rate->sdiv); 197485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + DIV_CTL0); 1988646d4dcSBai Ping 1998646d4dcSBai Ping return 0; 2008646d4dcSBai Ping } 2018646d4dcSBai Ping 2028646d4dcSBai Ping /* Bypass clock and set lock to pll output lock */ 203485b4ff5SSascha Hauer tmp = readl_relaxed(pll->base + GNRL_CTL); 2048646d4dcSBai Ping tmp |= LOCK_SEL_MASK; 205485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 2068646d4dcSBai Ping 2078646d4dcSBai Ping /* Enable RST */ 2088646d4dcSBai Ping tmp &= ~RST_MASK; 209485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 2108646d4dcSBai Ping 211dee1bc9cSPeng Fan /* Enable BYPASS */ 212dee1bc9cSPeng Fan tmp |= BYPASS_MASK; 213485b4ff5SSascha Hauer writel(tmp, pll->base + GNRL_CTL); 214dee1bc9cSPeng Fan 215*58f4980cSSascha Hauer div_val = FIELD_PREP(MDIV_MASK, rate->mdiv) | FIELD_PREP(PDIV_MASK, rate->pdiv) | 216*58f4980cSSascha Hauer FIELD_PREP(SDIV_MASK, rate->sdiv); 217485b4ff5SSascha Hauer writel_relaxed(div_val, pll->base + DIV_CTL0); 2188646d4dcSBai Ping 2198646d4dcSBai Ping /* 2208646d4dcSBai Ping * According to SPEC, t3 - t2 need to be greater than 2218646d4dcSBai Ping * 1us and 1/FREF, respectively. 2228646d4dcSBai Ping * FREF is FIN / Prediv, the prediv is [1, 63], so choose 2238646d4dcSBai Ping * 3us. 2248646d4dcSBai Ping */ 2258646d4dcSBai Ping udelay(3); 2268646d4dcSBai Ping 2278646d4dcSBai Ping /* Disable RST */ 2288646d4dcSBai Ping tmp |= RST_MASK; 229485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 2308646d4dcSBai Ping 2318646d4dcSBai Ping /* Wait Lock */ 2328646d4dcSBai Ping ret = clk_pll14xx_wait_lock(pll); 2338646d4dcSBai Ping if (ret) 2348646d4dcSBai Ping return ret; 2358646d4dcSBai Ping 2368646d4dcSBai Ping /* Bypass */ 2378646d4dcSBai Ping tmp &= ~BYPASS_MASK; 238485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 2398646d4dcSBai Ping 2408646d4dcSBai Ping return 0; 2418646d4dcSBai Ping } 2428646d4dcSBai Ping 2438646d4dcSBai Ping static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate, 2448646d4dcSBai Ping unsigned long prate) 2458646d4dcSBai Ping { 2468646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 2478646d4dcSBai Ping const struct imx_pll14xx_rate_table *rate; 2488646d4dcSBai Ping u32 tmp, div_val; 2498646d4dcSBai Ping int ret; 2508646d4dcSBai Ping 2518646d4dcSBai Ping rate = imx_get_pll_settings(pll, drate); 2528646d4dcSBai Ping if (!rate) { 2538646d4dcSBai Ping pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__, 2548646d4dcSBai Ping drate, clk_hw_get_name(hw)); 2558646d4dcSBai Ping return -EINVAL; 2568646d4dcSBai Ping } 2578646d4dcSBai Ping 258485b4ff5SSascha Hauer tmp = readl_relaxed(pll->base + DIV_CTL0); 2598646d4dcSBai Ping 260094234fcSLeonard Crestez if (!clk_pll14xx_mp_change(rate, tmp)) { 261d77461a6SSascha Hauer tmp &= ~SDIV_MASK; 262*58f4980cSSascha Hauer tmp |= FIELD_PREP(SDIV_MASK, rate->sdiv); 263485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + DIV_CTL0); 2648646d4dcSBai Ping 265*58f4980cSSascha Hauer tmp = FIELD_PREP(KDIV_MASK, rate->kdiv); 266485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + DIV_CTL1); 267094234fcSLeonard Crestez 2688646d4dcSBai Ping return 0; 2698646d4dcSBai Ping } 2708646d4dcSBai Ping 2718646d4dcSBai Ping /* Enable RST */ 272485b4ff5SSascha Hauer tmp = readl_relaxed(pll->base + GNRL_CTL); 2738646d4dcSBai Ping tmp &= ~RST_MASK; 274485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 2758646d4dcSBai Ping 276dee1bc9cSPeng Fan /* Enable BYPASS */ 277dee1bc9cSPeng Fan tmp |= BYPASS_MASK; 278485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 279dee1bc9cSPeng Fan 280*58f4980cSSascha Hauer div_val = FIELD_PREP(MDIV_MASK, rate->mdiv) | 281*58f4980cSSascha Hauer FIELD_PREP(PDIV_MASK, rate->pdiv) | 282*58f4980cSSascha Hauer FIELD_PREP(SDIV_MASK, rate->sdiv); 283485b4ff5SSascha Hauer writel_relaxed(div_val, pll->base + DIV_CTL0); 284*58f4980cSSascha Hauer writel_relaxed(FIELD_PREP(KDIV_MASK, rate->kdiv), pll->base + DIV_CTL1); 2858646d4dcSBai Ping 2868646d4dcSBai Ping /* 2878646d4dcSBai Ping * According to SPEC, t3 - t2 need to be greater than 2888646d4dcSBai Ping * 1us and 1/FREF, respectively. 2898646d4dcSBai Ping * FREF is FIN / Prediv, the prediv is [1, 63], so choose 2908646d4dcSBai Ping * 3us. 2918646d4dcSBai Ping */ 2928646d4dcSBai Ping udelay(3); 2938646d4dcSBai Ping 2948646d4dcSBai Ping /* Disable RST */ 2958646d4dcSBai Ping tmp |= RST_MASK; 296485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 2978646d4dcSBai Ping 2988646d4dcSBai Ping /* Wait Lock*/ 2998646d4dcSBai Ping ret = clk_pll14xx_wait_lock(pll); 3008646d4dcSBai Ping if (ret) 3018646d4dcSBai Ping return ret; 3028646d4dcSBai Ping 3038646d4dcSBai Ping /* Bypass */ 3048646d4dcSBai Ping tmp &= ~BYPASS_MASK; 305485b4ff5SSascha Hauer writel_relaxed(tmp, pll->base + GNRL_CTL); 3068646d4dcSBai Ping 3078646d4dcSBai Ping return 0; 3088646d4dcSBai Ping } 3098646d4dcSBai Ping 3108646d4dcSBai Ping static int clk_pll14xx_prepare(struct clk_hw *hw) 3118646d4dcSBai Ping { 3128646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 3138646d4dcSBai Ping u32 val; 314dee1bc9cSPeng Fan int ret; 3158646d4dcSBai Ping 3168646d4dcSBai Ping /* 3178646d4dcSBai Ping * RESETB = 1 from 0, PLL starts its normal 3188646d4dcSBai Ping * operation after lock time 3198646d4dcSBai Ping */ 3208646d4dcSBai Ping val = readl_relaxed(pll->base + GNRL_CTL); 321dee1bc9cSPeng Fan if (val & RST_MASK) 322dee1bc9cSPeng Fan return 0; 323dee1bc9cSPeng Fan val |= BYPASS_MASK; 324dee1bc9cSPeng Fan writel_relaxed(val, pll->base + GNRL_CTL); 3258646d4dcSBai Ping val |= RST_MASK; 3268646d4dcSBai Ping writel_relaxed(val, pll->base + GNRL_CTL); 3278646d4dcSBai Ping 328dee1bc9cSPeng Fan ret = clk_pll14xx_wait_lock(pll); 329dee1bc9cSPeng Fan if (ret) 330dee1bc9cSPeng Fan return ret; 331dee1bc9cSPeng Fan 332dee1bc9cSPeng Fan val &= ~BYPASS_MASK; 333dee1bc9cSPeng Fan writel_relaxed(val, pll->base + GNRL_CTL); 334dee1bc9cSPeng Fan 335dee1bc9cSPeng Fan return 0; 3368646d4dcSBai Ping } 3378646d4dcSBai Ping 3388646d4dcSBai Ping static int clk_pll14xx_is_prepared(struct clk_hw *hw) 3398646d4dcSBai Ping { 3408646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 3418646d4dcSBai Ping u32 val; 3428646d4dcSBai Ping 3438646d4dcSBai Ping val = readl_relaxed(pll->base + GNRL_CTL); 3448646d4dcSBai Ping 3458646d4dcSBai Ping return (val & RST_MASK) ? 1 : 0; 3468646d4dcSBai Ping } 3478646d4dcSBai Ping 3488646d4dcSBai Ping static void clk_pll14xx_unprepare(struct clk_hw *hw) 3498646d4dcSBai Ping { 3508646d4dcSBai Ping struct clk_pll14xx *pll = to_clk_pll14xx(hw); 3518646d4dcSBai Ping u32 val; 3528646d4dcSBai Ping 3538646d4dcSBai Ping /* 3548646d4dcSBai Ping * Set RST to 0, power down mode is enabled and 3558646d4dcSBai Ping * every digital block is reset 3568646d4dcSBai Ping */ 3578646d4dcSBai Ping val = readl_relaxed(pll->base + GNRL_CTL); 3588646d4dcSBai Ping val &= ~RST_MASK; 3598646d4dcSBai Ping writel_relaxed(val, pll->base + GNRL_CTL); 3608646d4dcSBai Ping } 3618646d4dcSBai Ping 3628646d4dcSBai Ping static const struct clk_ops clk_pll1416x_ops = { 3638646d4dcSBai Ping .prepare = clk_pll14xx_prepare, 3648646d4dcSBai Ping .unprepare = clk_pll14xx_unprepare, 3658646d4dcSBai Ping .is_prepared = clk_pll14xx_is_prepared, 3668646d4dcSBai Ping .recalc_rate = clk_pll1416x_recalc_rate, 3678646d4dcSBai Ping .round_rate = clk_pll14xx_round_rate, 3688646d4dcSBai Ping .set_rate = clk_pll1416x_set_rate, 3698646d4dcSBai Ping }; 3708646d4dcSBai Ping 3718646d4dcSBai Ping static const struct clk_ops clk_pll1416x_min_ops = { 3728646d4dcSBai Ping .recalc_rate = clk_pll1416x_recalc_rate, 3738646d4dcSBai Ping }; 3748646d4dcSBai Ping 3758646d4dcSBai Ping static const struct clk_ops clk_pll1443x_ops = { 3768646d4dcSBai Ping .prepare = clk_pll14xx_prepare, 3778646d4dcSBai Ping .unprepare = clk_pll14xx_unprepare, 3788646d4dcSBai Ping .is_prepared = clk_pll14xx_is_prepared, 3798646d4dcSBai Ping .recalc_rate = clk_pll1443x_recalc_rate, 3808646d4dcSBai Ping .round_rate = clk_pll14xx_round_rate, 3818646d4dcSBai Ping .set_rate = clk_pll1443x_set_rate, 3828646d4dcSBai Ping }; 3838646d4dcSBai Ping 38455a8b3cdSAbel Vesa struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name, 38555a8b3cdSAbel Vesa const char *parent_name, void __iomem *base, 3868646d4dcSBai Ping const struct imx_pll14xx_clk *pll_clk) 3878646d4dcSBai Ping { 3888646d4dcSBai Ping struct clk_pll14xx *pll; 38910c34b50SPeng Fan struct clk_hw *hw; 3908646d4dcSBai Ping struct clk_init_data init; 39110c34b50SPeng Fan int ret; 392a9aa8306SPeng Fan u32 val; 3938646d4dcSBai Ping 3948646d4dcSBai Ping pll = kzalloc(sizeof(*pll), GFP_KERNEL); 3958646d4dcSBai Ping if (!pll) 3968646d4dcSBai Ping return ERR_PTR(-ENOMEM); 3978646d4dcSBai Ping 3988646d4dcSBai Ping init.name = name; 3998646d4dcSBai Ping init.flags = pll_clk->flags; 4008646d4dcSBai Ping init.parent_names = &parent_name; 4018646d4dcSBai Ping init.num_parents = 1; 4028646d4dcSBai Ping 4038646d4dcSBai Ping switch (pll_clk->type) { 4048646d4dcSBai Ping case PLL_1416X: 405f89b9e1bSLeonard Crestez if (!pll_clk->rate_table) 4068646d4dcSBai Ping init.ops = &clk_pll1416x_min_ops; 4078646d4dcSBai Ping else 4088646d4dcSBai Ping init.ops = &clk_pll1416x_ops; 4098646d4dcSBai Ping break; 4108646d4dcSBai Ping case PLL_1443X: 4118646d4dcSBai Ping init.ops = &clk_pll1443x_ops; 4128646d4dcSBai Ping break; 4138646d4dcSBai Ping default: 4148646d4dcSBai Ping pr_err("%s: Unknown pll type for pll clk %s\n", 4158646d4dcSBai Ping __func__, name); 416530cf8d4SAnson Huang kfree(pll); 417530cf8d4SAnson Huang return ERR_PTR(-EINVAL); 4188404c661STom Rix } 4198646d4dcSBai Ping 4208646d4dcSBai Ping pll->base = base; 4218646d4dcSBai Ping pll->hw.init = &init; 4228646d4dcSBai Ping pll->type = pll_clk->type; 4238646d4dcSBai Ping pll->rate_table = pll_clk->rate_table; 4248646d4dcSBai Ping pll->rate_count = pll_clk->rate_count; 4258646d4dcSBai Ping 426a9aa8306SPeng Fan val = readl_relaxed(pll->base + GNRL_CTL); 427a9aa8306SPeng Fan val &= ~BYPASS_MASK; 428a9aa8306SPeng Fan writel_relaxed(val, pll->base + GNRL_CTL); 429a9aa8306SPeng Fan 43010c34b50SPeng Fan hw = &pll->hw; 43110c34b50SPeng Fan 43255a8b3cdSAbel Vesa ret = clk_hw_register(dev, hw); 43310c34b50SPeng Fan if (ret) { 43410c34b50SPeng Fan pr_err("%s: failed to register pll %s %d\n", 43510c34b50SPeng Fan __func__, name, ret); 4368646d4dcSBai Ping kfree(pll); 43710c34b50SPeng Fan return ERR_PTR(ret); 4388646d4dcSBai Ping } 4398646d4dcSBai Ping 44010c34b50SPeng Fan return hw; 4418646d4dcSBai Ping } 442870ed5e2SAnson Huang EXPORT_SYMBOL_GPL(imx_dev_clk_hw_pll14xx); 443