Lines Matching +full:fixed +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0+
6 // Author: David Liu <liuwei@actions-semi.com>
11 #include <linux/clk-provider.h>
16 #include "owl-pll.h"
18 static u32 owl_pll_calculate_mul(struct owl_pll_hw *pll_hw, unsigned long rate) in owl_pll_calculate_mul() argument
22 mul = DIV_ROUND_CLOSEST(rate, pll_hw->bfreq); in owl_pll_calculate_mul()
23 if (mul < pll_hw->min_mul) in owl_pll_calculate_mul()
24 mul = pll_hw->min_mul; in owl_pll_calculate_mul()
25 else if (mul > pll_hw->max_mul) in owl_pll_calculate_mul()
26 mul = pll_hw->max_mul; in owl_pll_calculate_mul()
36 for (clkt = table; clkt->rate; clkt++) in _get_table_rate()
37 if (clkt->val == val) in _get_table_rate()
38 return clkt->rate; in _get_table_rate()
44 const struct clk_pll_table *table, unsigned long rate) in _get_pll_table() argument
48 for (clkt = table; clkt->rate; clkt++) { in _get_pll_table()
49 if (clkt->rate == rate) { in _get_pll_table()
52 } else if (clkt->rate < rate) in _get_pll_table()
59 static long owl_pll_round_rate(struct clk_hw *hw, unsigned long rate, in owl_pll_round_rate() argument
63 struct owl_pll_hw *pll_hw = &pll->pll_hw; in owl_pll_round_rate()
67 if (pll_hw->table) { in owl_pll_round_rate()
68 clkt = _get_pll_table(pll_hw->table, rate); in owl_pll_round_rate()
69 return clkt->rate; in owl_pll_round_rate()
72 /* fixed frequency */ in owl_pll_round_rate()
73 if (pll_hw->width == 0) in owl_pll_round_rate()
74 return pll_hw->bfreq; in owl_pll_round_rate()
76 mul = owl_pll_calculate_mul(pll_hw, rate); in owl_pll_round_rate()
78 return pll_hw->bfreq * mul; in owl_pll_round_rate()
85 struct owl_pll_hw *pll_hw = &pll->pll_hw; in owl_pll_recalc_rate()
86 const struct owl_clk_common *common = &pll->common; in owl_pll_recalc_rate()
89 if (pll_hw->table) { in owl_pll_recalc_rate()
90 regmap_read(common->regmap, pll_hw->reg, &val); in owl_pll_recalc_rate()
92 val = val >> pll_hw->shift; in owl_pll_recalc_rate()
95 return _get_table_rate(pll_hw->table, val); in owl_pll_recalc_rate()
98 /* fixed frequency */ in owl_pll_recalc_rate()
99 if (pll_hw->width == 0) in owl_pll_recalc_rate()
100 return pll_hw->bfreq; in owl_pll_recalc_rate()
102 regmap_read(common->regmap, pll_hw->reg, &val); in owl_pll_recalc_rate()
104 val = val >> pll_hw->shift; in owl_pll_recalc_rate()
107 return pll_hw->bfreq * val; in owl_pll_recalc_rate()
113 struct owl_pll_hw *pll_hw = &pll->pll_hw; in owl_pll_is_enabled()
114 const struct owl_clk_common *common = &pll->common; in owl_pll_is_enabled()
117 regmap_read(common->regmap, pll_hw->reg, &reg); in owl_pll_is_enabled()
119 return !!(reg & BIT(pll_hw->bit_idx)); in owl_pll_is_enabled()
127 regmap_read(common->regmap, pll_hw->reg, &reg); in owl_pll_set()
130 reg |= BIT(pll_hw->bit_idx); in owl_pll_set()
132 reg &= ~BIT(pll_hw->bit_idx); in owl_pll_set()
134 regmap_write(common->regmap, pll_hw->reg, reg); in owl_pll_set()
140 const struct owl_clk_common *common = &pll->common; in owl_pll_enable()
142 owl_pll_set(common, &pll->pll_hw, true); in owl_pll_enable()
150 const struct owl_clk_common *common = &pll->common; in owl_pll_disable()
152 owl_pll_set(common, &pll->pll_hw, false); in owl_pll_disable()
155 static int owl_pll_set_rate(struct clk_hw *hw, unsigned long rate, in owl_pll_set_rate() argument
159 struct owl_pll_hw *pll_hw = &pll->pll_hw; in owl_pll_set_rate()
160 const struct owl_clk_common *common = &pll->common; in owl_pll_set_rate()
164 /* fixed frequency */ in owl_pll_set_rate()
165 if (pll_hw->width == 0) in owl_pll_set_rate()
168 if (pll_hw->table) { in owl_pll_set_rate()
169 clkt = _get_pll_table(pll_hw->table, rate); in owl_pll_set_rate()
170 val = clkt->val; in owl_pll_set_rate()
172 val = owl_pll_calculate_mul(pll_hw, rate); in owl_pll_set_rate()
175 regmap_read(common->regmap, pll_hw->reg, &reg); in owl_pll_set_rate()
178 reg |= val << pll_hw->shift; in owl_pll_set_rate()
180 regmap_write(common->regmap, pll_hw->reg, reg); in owl_pll_set_rate()
182 udelay(pll_hw->delay); in owl_pll_set_rate()