Lines Matching +full:clk +full:- +full:div

1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
15 * hi = [0 - val]
19 #include <linux/clk-provider.h>
22 #include "clk-regmap.h"
23 #include "sclk-div.h"
26 meson_sclk_div_data(struct clk_regmap *clk) in meson_sclk_div_data() argument
28 return (struct meson_sclk_div_data *)clk->data; in meson_sclk_div_data()
33 return (1 << sclk->div.width) - 1; in sclk_div_maxval()
44 int div = DIV_ROUND_CLOSEST_ULL((u64)prate, rate); in sclk_div_getdiv() local
46 return clamp(div, 2, maxdiv); in sclk_div_getdiv()
84 if (abs(rate - now) < abs(rate - best)) { in sclk_div_bestdiv()
102 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_determine_rate() local
103 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_determine_rate()
104 int div; in sclk_div_determine_rate() local
106 div = sclk_div_bestdiv(hw, req->rate, &req->best_parent_rate, sclk); in sclk_div_determine_rate()
107 req->rate = DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div); in sclk_div_determine_rate()
112 static void sclk_apply_ratio(struct clk_regmap *clk, in sclk_apply_ratio() argument
115 unsigned int hi = DIV_ROUND_CLOSEST(sclk->cached_div * in sclk_apply_ratio()
116 sclk->cached_duty.num, in sclk_apply_ratio()
117 sclk->cached_duty.den); in sclk_apply_ratio()
120 hi -= 1; in sclk_apply_ratio()
122 meson_parm_write(clk->map, &sclk->hi, hi); in sclk_apply_ratio()
128 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_set_duty_cycle() local
129 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_set_duty_cycle()
131 if (MESON_PARM_APPLICABLE(&sclk->hi)) { in sclk_div_set_duty_cycle()
132 memcpy(&sclk->cached_duty, duty, sizeof(*duty)); in sclk_div_set_duty_cycle()
133 sclk_apply_ratio(clk, sclk); in sclk_div_set_duty_cycle()
142 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_get_duty_cycle() local
143 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_get_duty_cycle()
146 if (!MESON_PARM_APPLICABLE(&sclk->hi)) { in sclk_div_get_duty_cycle()
147 duty->num = 1; in sclk_div_get_duty_cycle()
148 duty->den = 2; in sclk_div_get_duty_cycle()
152 hi = meson_parm_read(clk->map, &sclk->hi); in sclk_div_get_duty_cycle()
153 duty->num = hi + 1; in sclk_div_get_duty_cycle()
154 duty->den = sclk->cached_div; in sclk_div_get_duty_cycle()
158 static void sclk_apply_divider(struct clk_regmap *clk, in sclk_apply_divider() argument
161 if (MESON_PARM_APPLICABLE(&sclk->hi)) in sclk_apply_divider()
162 sclk_apply_ratio(clk, sclk); in sclk_apply_divider()
164 meson_parm_write(clk->map, &sclk->div, sclk->cached_div - 1); in sclk_apply_divider()
170 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_set_rate() local
171 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_set_rate()
174 sclk->cached_div = sclk_div_getdiv(hw, rate, prate, maxdiv); in sclk_div_set_rate()
177 sclk_apply_divider(clk, sclk); in sclk_div_set_rate()
185 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_recalc_rate() local
186 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_recalc_rate()
188 return DIV_ROUND_UP_ULL((u64)prate, sclk->cached_div); in sclk_div_recalc_rate()
193 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_enable() local
194 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_enable()
196 sclk_apply_divider(clk, sclk); in sclk_div_enable()
203 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_disable() local
204 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_disable()
206 meson_parm_write(clk->map, &sclk->div, 0); in sclk_div_disable()
211 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_is_enabled() local
212 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_is_enabled()
214 if (meson_parm_read(clk->map, &sclk->div)) in sclk_div_is_enabled()
222 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_init() local
223 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_init()
226 val = meson_parm_read(clk->map, &sclk->div); in sclk_div_init()
230 sclk->cached_div = sclk_div_maxdiv(sclk); in sclk_div_init()
232 sclk->cached_div = val + 1; in sclk_div_init()
234 sclk_div_get_duty_cycle(hw, &sclk->cached_duty); in sclk_div_init()