Lines Matching full:pll

3 // Spreadtrum pll clock driver
13 #include "pll.h"
18 #define pindex(pll, member) \ argument
19 (pll->factors[member].shift / (8 * sizeof(pll->regs_num)))
21 #define pshift(pll, member) \ argument
22 (pll->factors[member].shift % (8 * sizeof(pll->regs_num)))
24 #define pwidth(pll, member) \ argument
25 pll->factors[member].width
27 #define pmask(pll, member) \ argument
28 ((pwidth(pll, member)) ? \
29 GENMASK(pwidth(pll, member) + pshift(pll, member) - 1, \
30 pshift(pll, member)) : 0)
32 #define pinternal(pll, cfg, member) \ argument
33 (cfg[pindex(pll, member)] & pmask(pll, member))
35 #define pinternal_val(pll, cfg, member) \ argument
36 (pinternal(pll, cfg, member) >> pshift(pll, member))
39 sprd_pll_read(const struct sprd_pll *pll, u8 index) in sprd_pll_read() argument
41 const struct sprd_clk_common *common = &pll->common; in sprd_pll_read()
44 if (WARN_ON(index >= pll->regs_num)) in sprd_pll_read()
53 sprd_pll_write(const struct sprd_pll *pll, u8 index, in sprd_pll_write() argument
56 const struct sprd_clk_common *common = &pll->common; in sprd_pll_write()
60 if (WARN_ON(index >= pll->regs_num)) in sprd_pll_write()
69 static unsigned long pll_get_refin(const struct sprd_pll *pll) in pll_get_refin() argument
74 if (pwidth(pll, PLL_REFIN)) { in pll_get_refin()
75 index = pindex(pll, PLL_REFIN); in pll_get_refin()
76 shift = pshift(pll, PLL_REFIN); in pll_get_refin()
77 mask = pmask(pll, PLL_REFIN); in pll_get_refin()
78 refin_id = (sprd_pll_read(pll, index) & mask) >> shift; in pll_get_refin()
98 static unsigned long _sprd_pll_recalc_rate(const struct sprd_pll *pll, in _sprd_pll_recalc_rate() argument
102 u32 i, mask, regs_num = pll->regs_num; in _sprd_pll_recalc_rate()
112 cfg[i] = sprd_pll_read(pll, i); in _sprd_pll_recalc_rate()
114 refin = pll_get_refin(pll); in _sprd_pll_recalc_rate()
116 if (pinternal(pll, cfg, PLL_PREDIV)) in _sprd_pll_recalc_rate()
119 if (pwidth(pll, PLL_POSTDIV) && in _sprd_pll_recalc_rate()
120 ((pll->fflag == 1 && pinternal(pll, cfg, PLL_POSTDIV)) || in _sprd_pll_recalc_rate()
121 (!pll->fflag && !pinternal(pll, cfg, PLL_POSTDIV)))) in _sprd_pll_recalc_rate()
124 if (!pinternal(pll, cfg, PLL_DIV_S)) { in _sprd_pll_recalc_rate()
125 rate = refin * pinternal_val(pll, cfg, PLL_N) * CLK_PLL_10M; in _sprd_pll_recalc_rate()
127 nint = pinternal_val(pll, cfg, PLL_NINT); in _sprd_pll_recalc_rate()
128 if (pinternal(pll, cfg, PLL_SDM_EN)) in _sprd_pll_recalc_rate()
129 kint = pinternal_val(pll, cfg, PLL_KINT); in _sprd_pll_recalc_rate()
131 mask = pmask(pll, PLL_KINT); in _sprd_pll_recalc_rate()
133 k1 = pll->k1; in _sprd_pll_recalc_rate()
134 k2 = pll->k2; in _sprd_pll_recalc_rate()
144 #define SPRD_PLL_WRITE_CHECK(pll, i, mask, val) \ argument
145 (((sprd_pll_read(pll, i) & mask) == val) ? 0 : (-EFAULT))
147 static int _sprd_pll_set_rate(const struct sprd_pll *pll, in _sprd_pll_set_rate() argument
154 u32 regs_num = pll->regs_num, i = 0; in _sprd_pll_set_rate()
162 refin = pll_get_refin(pll); in _sprd_pll_set_rate()
164 mask = pmask(pll, PLL_PREDIV); in _sprd_pll_set_rate()
165 index = pindex(pll, PLL_PREDIV); in _sprd_pll_set_rate()
166 width = pwidth(pll, PLL_PREDIV); in _sprd_pll_set_rate()
167 if (width && (sprd_pll_read(pll, index) & mask)) in _sprd_pll_set_rate()
170 mask = pmask(pll, PLL_POSTDIV); in _sprd_pll_set_rate()
171 index = pindex(pll, PLL_POSTDIV); in _sprd_pll_set_rate()
172 width = pwidth(pll, PLL_POSTDIV); in _sprd_pll_set_rate()
174 if (width && ((pll->fflag == 1 && fvco <= pll->fvco) || in _sprd_pll_set_rate()
175 (pll->fflag == 0 && fvco > pll->fvco))) in _sprd_pll_set_rate()
178 if (width && fvco <= pll->fvco) in _sprd_pll_set_rate()
181 mask = pmask(pll, PLL_DIV_S); in _sprd_pll_set_rate()
182 index = pindex(pll, PLL_DIV_S); in _sprd_pll_set_rate()
186 mask = pmask(pll, PLL_SDM_EN); in _sprd_pll_set_rate()
187 index = pindex(pll, PLL_SDM_EN); in _sprd_pll_set_rate()
192 mask = pmask(pll, PLL_NINT); in _sprd_pll_set_rate()
193 index = pindex(pll, PLL_NINT); in _sprd_pll_set_rate()
194 shift = pshift(pll, PLL_NINT); in _sprd_pll_set_rate()
198 mask = pmask(pll, PLL_KINT); in _sprd_pll_set_rate()
199 index = pindex(pll, PLL_KINT); in _sprd_pll_set_rate()
200 width = pwidth(pll, PLL_KINT); in _sprd_pll_set_rate()
201 shift = pshift(pll, PLL_KINT); in _sprd_pll_set_rate()
208 ibias_val = pll_get_ibias(fvco, pll->itable); in _sprd_pll_set_rate()
210 mask = pmask(pll, PLL_IBIAS); in _sprd_pll_set_rate()
211 index = pindex(pll, PLL_IBIAS); in _sprd_pll_set_rate()
212 shift = pshift(pll, PLL_IBIAS); in _sprd_pll_set_rate()
218 sprd_pll_write(pll, i, cfg[i].msk, cfg[i].val); in _sprd_pll_set_rate()
219 ret |= SPRD_PLL_WRITE_CHECK(pll, i, cfg[i].msk, in _sprd_pll_set_rate()
225 udelay(pll->udelay); in _sprd_pll_set_rate()
234 struct sprd_pll *pll = hw_to_sprd_pll(hw); in sprd_pll_recalc_rate() local
236 return _sprd_pll_recalc_rate(pll, parent_rate); in sprd_pll_recalc_rate()
243 struct sprd_pll *pll = hw_to_sprd_pll(hw); in sprd_pll_set_rate() local
245 return _sprd_pll_set_rate(pll, rate, parent_rate); in sprd_pll_set_rate()
250 struct sprd_pll *pll = hw_to_sprd_pll(hw); in sprd_pll_clk_prepare() local
252 udelay(pll->udelay); in sprd_pll_clk_prepare()