Lines Matching +full:n +full:- +full:factor
1 // SPDX-License-Identifier: GPL-2.0+
3 // OWL factor clock driver
6 // Author: David Liu <liuwei@actions-semi.com>
11 #include <linux/clk-provider.h>
14 #include "owl-factor.h"
21 for (clkt = table; clkt->div; clkt++) in _get_table_maxval()
22 if (clkt->val > maxval) in _get_table_maxval()
23 maxval = clkt->val; in _get_table_maxval()
32 for (clkt = table; clkt->div; clkt++) { in _get_table_div_mul()
33 if (clkt->val == val) { in _get_table_div_mul()
34 *mul = clkt->mul; in _get_table_div_mul()
35 *div = clkt->div; in _get_table_div_mul()
47 int val = -1; in _get_table_val()
50 for (clkt = table; clkt->div; clkt++) { in _get_table_val()
51 calc_rate = parent_rate * clkt->mul; in _get_table_val()
52 do_div(calc_rate, clkt->div); in _get_table_val()
55 val = clkt->val; in _get_table_val()
60 if (val == -1) in _get_table_val()
70 const struct clk_factor_table *clkt = factor_hw->table; in owl_clk_val_best()
84 for (clkt = factor_hw->table; clkt->div; clkt++) { in owl_clk_val_best()
85 try_parent_rate = rate * clkt->div / clkt->mul; in owl_clk_val_best()
88 pr_debug("%s: [%d %d %d] found try_parent_rate %ld\n", in owl_clk_val_best()
89 __func__, clkt->val, clkt->mul, clkt->div, in owl_clk_val_best()
97 return clkt->val; in owl_clk_val_best()
102 cur_rate = DIV_ROUND_UP(parent_rate, clkt->div) * clkt->mul; in owl_clk_val_best()
104 bestval = clkt->val; in owl_clk_val_best()
124 const struct clk_factor_table *clkt = factor_hw->table; in owl_factor_helper_round_rate()
127 val = owl_clk_val_best(factor_hw, &common->hw, rate, parent_rate); in owl_factor_helper_round_rate()
136 struct owl_factor *factor = hw_to_owl_factor(hw); in owl_factor_round_rate() local
137 struct owl_factor_hw *factor_hw = &factor->factor_hw; in owl_factor_round_rate()
139 return owl_factor_helper_round_rate(&factor->common, factor_hw, in owl_factor_round_rate()
147 const struct clk_factor_table *clkt = factor_hw->table; in owl_factor_helper_recalc_rate()
154 regmap_read(common->regmap, factor_hw->reg, ®); in owl_factor_helper_recalc_rate()
156 val = reg >> factor_hw->shift; in owl_factor_helper_recalc_rate()
161 WARN(!(factor_hw->fct_flags & CLK_DIVIDER_ALLOW_ZERO), in owl_factor_helper_recalc_rate()
162 "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n", in owl_factor_helper_recalc_rate()
163 __clk_get_name(common->hw.clk)); in owl_factor_helper_recalc_rate()
176 struct owl_factor *factor = hw_to_owl_factor(hw); in owl_factor_recalc_rate() local
177 struct owl_factor_hw *factor_hw = &factor->factor_hw; in owl_factor_recalc_rate()
178 struct owl_clk_common *common = &factor->common; in owl_factor_recalc_rate()
190 val = _get_table_val(factor_hw->table, rate, parent_rate); in owl_factor_helper_set_rate()
195 regmap_read(common->regmap, factor_hw->reg, ®); in owl_factor_helper_set_rate()
197 reg &= ~(div_mask(factor_hw) << factor_hw->shift); in owl_factor_helper_set_rate()
198 reg |= val << factor_hw->shift; in owl_factor_helper_set_rate()
200 regmap_write(common->regmap, factor_hw->reg, reg); in owl_factor_helper_set_rate()
208 struct owl_factor *factor = hw_to_owl_factor(hw); in owl_factor_set_rate() local
209 struct owl_factor_hw *factor_hw = &factor->factor_hw; in owl_factor_set_rate()
210 struct owl_clk_common *common = &factor->common; in owl_factor_set_rate()