Lines Matching +full:pll +full:- +full:in

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2017-2018 NXP.
10 #include <linux/clk-provider.h>
92 struct clk_pll14xx *pll, unsigned long rate) in imx_get_pll_settings() argument
94 const struct imx_pll14xx_rate_table *rate_table = pll->rate_table; in imx_get_pll_settings()
97 for (i = 0; i < pll->rate_count; i++) in imx_get_pll_settings()
104 static long pll14xx_calc_rate(struct clk_pll14xx *pll, int mdiv, int pdiv, in pll14xx_calc_rate() argument
123 /* calc kdiv = round(rate * pdiv * 65536 * 2^sdiv / prate) - (mdiv * 65536) */ in pll1443x_calc_kdiv()
124 kdiv = ((rate * ((pdiv * 65536) << sdiv) + prate / 2) / prate) - (mdiv * 65536); in pll1443x_calc_kdiv()
129 static void imx_pll14xx_calc_settings(struct clk_pll14xx *pll, unsigned long rate, in imx_pll14xx_calc_settings() argument
138 * Fractional PLL constrains: in imx_pll14xx_calc_settings()
143 * d) -32768 <= k <= 32767 in imx_pll14xx_calc_settings()
150 tt = imx_get_pll_settings(pll, rate); in imx_pll14xx_calc_settings()
152 pr_debug("%s: in=%ld, want=%ld, Using PLL setting from table\n", in imx_pll14xx_calc_settings()
153 clk_hw_get_name(&pll->hw), prate, rate); in imx_pll14xx_calc_settings()
154 t->rate = tt->rate; in imx_pll14xx_calc_settings()
155 t->mdiv = tt->mdiv; in imx_pll14xx_calc_settings()
156 t->pdiv = tt->pdiv; in imx_pll14xx_calc_settings()
157 t->sdiv = tt->sdiv; in imx_pll14xx_calc_settings()
158 t->kdiv = tt->kdiv; in imx_pll14xx_calc_settings()
162 pll_div_ctl0 = readl_relaxed(pll->base + DIV_CTL0); in imx_pll14xx_calc_settings()
166 pll_div_ctl1 = readl_relaxed(pll->base + DIV_CTL1); in imx_pll14xx_calc_settings()
169 rate_min = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, KDIV_MIN, prate); in imx_pll14xx_calc_settings()
170 rate_max = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, KDIV_MAX, prate); in imx_pll14xx_calc_settings()
174 pr_debug("%s: in=%ld, want=%ld Only adjust kdiv %ld -> %d\n", in imx_pll14xx_calc_settings()
175 clk_hw_get_name(&pll->hw), prate, rate, in imx_pll14xx_calc_settings()
177 fout = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, prate); in imx_pll14xx_calc_settings()
178 t->rate = (unsigned int)fout; in imx_pll14xx_calc_settings()
179 t->mdiv = mdiv; in imx_pll14xx_calc_settings()
180 t->pdiv = pdiv; in imx_pll14xx_calc_settings()
181 t->sdiv = sdiv; in imx_pll14xx_calc_settings()
182 t->kdiv = kdiv; in imx_pll14xx_calc_settings()
194 fout = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, prate); in imx_pll14xx_calc_settings()
197 dist = abs((long)rate - (long)fout); in imx_pll14xx_calc_settings()
200 t->rate = (unsigned int)fout; in imx_pll14xx_calc_settings()
201 t->mdiv = mdiv; in imx_pll14xx_calc_settings()
202 t->pdiv = pdiv; in imx_pll14xx_calc_settings()
203 t->sdiv = sdiv; in imx_pll14xx_calc_settings()
204 t->kdiv = kdiv; in imx_pll14xx_calc_settings()
212 pr_debug("%s: in=%ld, want=%ld got=%d (pdiv=%d sdiv=%d mdiv=%d kdiv=%d)\n", in imx_pll14xx_calc_settings()
213 clk_hw_get_name(&pll->hw), prate, rate, t->rate, t->pdiv, t->sdiv, in imx_pll14xx_calc_settings()
214 t->mdiv, t->kdiv); in imx_pll14xx_calc_settings()
220 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll1416x_round_rate() local
221 const struct imx_pll14xx_rate_table *rate_table = pll->rate_table; in clk_pll1416x_round_rate()
224 /* Assuming rate_table is in descending order */ in clk_pll1416x_round_rate()
225 for (i = 0; i < pll->rate_count; i++) in clk_pll1416x_round_rate()
230 return rate_table[pll->rate_count - 1].rate; in clk_pll1416x_round_rate()
236 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll1443x_round_rate() local
239 imx_pll14xx_calc_settings(pll, rate, *prate, &t); in clk_pll1443x_round_rate()
247 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll14xx_recalc_rate() local
250 pll_div_ctl0 = readl_relaxed(pll->base + DIV_CTL0); in clk_pll14xx_recalc_rate()
255 if (pll->type == PLL_1443X) { in clk_pll14xx_recalc_rate()
256 pll_div_ctl1 = readl_relaxed(pll->base + DIV_CTL1); in clk_pll14xx_recalc_rate()
262 return pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, parent_rate); in clk_pll14xx_recalc_rate()
273 return rate->mdiv != old_mdiv || rate->pdiv != old_pdiv; in clk_pll14xx_mp_change()
276 static int clk_pll14xx_wait_lock(struct clk_pll14xx *pll) in clk_pll14xx_wait_lock() argument
280 return readl_poll_timeout(pll->base + GNRL_CTL, val, val & LOCK_STATUS, 0, in clk_pll14xx_wait_lock()
287 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll1416x_set_rate() local
292 rate = imx_get_pll_settings(pll, drate); in clk_pll1416x_set_rate()
294 pr_err("Invalid rate %lu for pll clk %s\n", drate, in clk_pll1416x_set_rate()
296 return -EINVAL; in clk_pll1416x_set_rate()
299 tmp = readl_relaxed(pll->base + DIV_CTL0); in clk_pll1416x_set_rate()
303 tmp |= FIELD_PREP(SDIV_MASK, rate->sdiv); in clk_pll1416x_set_rate()
304 writel_relaxed(tmp, pll->base + DIV_CTL0); in clk_pll1416x_set_rate()
309 /* Bypass clock and set lock to pll output lock */ in clk_pll1416x_set_rate()
310 tmp = readl_relaxed(pll->base + GNRL_CTL); in clk_pll1416x_set_rate()
312 writel_relaxed(tmp, pll->base + GNRL_CTL); in clk_pll1416x_set_rate()
316 writel_relaxed(tmp, pll->base + GNRL_CTL); in clk_pll1416x_set_rate()
320 writel(tmp, pll->base + GNRL_CTL); in clk_pll1416x_set_rate()
322 div_val = FIELD_PREP(MDIV_MASK, rate->mdiv) | FIELD_PREP(PDIV_MASK, rate->pdiv) | in clk_pll1416x_set_rate()
323 FIELD_PREP(SDIV_MASK, rate->sdiv); in clk_pll1416x_set_rate()
324 writel_relaxed(div_val, pll->base + DIV_CTL0); in clk_pll1416x_set_rate()
327 * According to SPEC, t3 - t2 need to be greater than in clk_pll1416x_set_rate()
336 writel_relaxed(tmp, pll->base + GNRL_CTL); in clk_pll1416x_set_rate()
339 ret = clk_pll14xx_wait_lock(pll); in clk_pll1416x_set_rate()
345 writel_relaxed(tmp, pll->base + GNRL_CTL); in clk_pll1416x_set_rate()
353 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll1443x_set_rate() local
358 imx_pll14xx_calc_settings(pll, drate, prate, &rate); in clk_pll1443x_set_rate()
360 div_ctl0 = readl_relaxed(pll->base + DIV_CTL0); in clk_pll1443x_set_rate()
363 /* only sdiv and/or kdiv changed - no need to RESET PLL */ in clk_pll1443x_set_rate()
366 writel_relaxed(div_ctl0, pll->base + DIV_CTL0); in clk_pll1443x_set_rate()
369 pll->base + DIV_CTL1); in clk_pll1443x_set_rate()
375 gnrl_ctl = readl_relaxed(pll->base + GNRL_CTL); in clk_pll1443x_set_rate()
377 writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL); in clk_pll1443x_set_rate()
381 writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL); in clk_pll1443x_set_rate()
386 writel_relaxed(div_ctl0, pll->base + DIV_CTL0); in clk_pll1443x_set_rate()
388 writel_relaxed(FIELD_PREP(KDIV_MASK, rate.kdiv), pll->base + DIV_CTL1); in clk_pll1443x_set_rate()
391 * According to SPEC, t3 - t2 need to be greater than in clk_pll1443x_set_rate()
400 writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL); in clk_pll1443x_set_rate()
403 ret = clk_pll14xx_wait_lock(pll); in clk_pll1443x_set_rate()
409 writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL); in clk_pll1443x_set_rate()
416 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll14xx_prepare() local
421 * RESETB = 1 from 0, PLL starts its normal in clk_pll14xx_prepare()
424 val = readl_relaxed(pll->base + GNRL_CTL); in clk_pll14xx_prepare()
428 writel_relaxed(val, pll->base + GNRL_CTL); in clk_pll14xx_prepare()
430 writel_relaxed(val, pll->base + GNRL_CTL); in clk_pll14xx_prepare()
432 ret = clk_pll14xx_wait_lock(pll); in clk_pll14xx_prepare()
437 writel_relaxed(val, pll->base + GNRL_CTL); in clk_pll14xx_prepare()
444 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll14xx_is_prepared() local
447 val = readl_relaxed(pll->base + GNRL_CTL); in clk_pll14xx_is_prepared()
454 struct clk_pll14xx *pll = to_clk_pll14xx(hw); in clk_pll14xx_unprepare() local
461 val = readl_relaxed(pll->base + GNRL_CTL); in clk_pll14xx_unprepare()
463 writel_relaxed(val, pll->base + GNRL_CTL); in clk_pll14xx_unprepare()
492 struct clk_pll14xx *pll; in imx_dev_clk_hw_pll14xx() local
498 pll = kzalloc(sizeof(*pll), GFP_KERNEL); in imx_dev_clk_hw_pll14xx()
499 if (!pll) in imx_dev_clk_hw_pll14xx()
500 return ERR_PTR(-ENOMEM); in imx_dev_clk_hw_pll14xx()
503 init.flags = pll_clk->flags; in imx_dev_clk_hw_pll14xx()
507 switch (pll_clk->type) { in imx_dev_clk_hw_pll14xx()
509 if (!pll_clk->rate_table) in imx_dev_clk_hw_pll14xx()
518 pr_err("Unknown pll type for pll clk %s\n", name); in imx_dev_clk_hw_pll14xx()
519 kfree(pll); in imx_dev_clk_hw_pll14xx()
520 return ERR_PTR(-EINVAL); in imx_dev_clk_hw_pll14xx()
523 pll->base = base; in imx_dev_clk_hw_pll14xx()
524 pll->hw.init = &init; in imx_dev_clk_hw_pll14xx()
525 pll->type = pll_clk->type; in imx_dev_clk_hw_pll14xx()
526 pll->rate_table = pll_clk->rate_table; in imx_dev_clk_hw_pll14xx()
527 pll->rate_count = pll_clk->rate_count; in imx_dev_clk_hw_pll14xx()
529 val = readl_relaxed(pll->base + GNRL_CTL); in imx_dev_clk_hw_pll14xx()
531 writel_relaxed(val, pll->base + GNRL_CTL); in imx_dev_clk_hw_pll14xx()
533 hw = &pll->hw; in imx_dev_clk_hw_pll14xx()
537 pr_err("failed to register pll %s %d\n", name, ret); in imx_dev_clk_hw_pll14xx()
538 kfree(pll); in imx_dev_clk_hw_pll14xx()