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_round_rate() local
103 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_round_rate()
104 int div; in sclk_div_round_rate() local
106 div = sclk_div_bestdiv(hw, rate, prate, sclk); in sclk_div_round_rate()
108 return DIV_ROUND_UP_ULL((u64)*prate, div); in sclk_div_round_rate()
111 static void sclk_apply_ratio(struct clk_regmap *clk, in sclk_apply_ratio() argument
114 unsigned int hi = DIV_ROUND_CLOSEST(sclk->cached_div * in sclk_apply_ratio()
115 sclk->cached_duty.num, in sclk_apply_ratio()
116 sclk->cached_duty.den); in sclk_apply_ratio()
119 hi -= 1; in sclk_apply_ratio()
121 meson_parm_write(clk->map, &sclk->hi, hi); in sclk_apply_ratio()
127 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_set_duty_cycle() local
128 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_set_duty_cycle()
130 if (MESON_PARM_APPLICABLE(&sclk->hi)) { in sclk_div_set_duty_cycle()
131 memcpy(&sclk->cached_duty, duty, sizeof(*duty)); in sclk_div_set_duty_cycle()
132 sclk_apply_ratio(clk, sclk); in sclk_div_set_duty_cycle()
141 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_get_duty_cycle() local
142 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_get_duty_cycle()
145 if (!MESON_PARM_APPLICABLE(&sclk->hi)) { in sclk_div_get_duty_cycle()
146 duty->num = 1; in sclk_div_get_duty_cycle()
147 duty->den = 2; in sclk_div_get_duty_cycle()
151 hi = meson_parm_read(clk->map, &sclk->hi); in sclk_div_get_duty_cycle()
152 duty->num = hi + 1; in sclk_div_get_duty_cycle()
153 duty->den = sclk->cached_div; in sclk_div_get_duty_cycle()
157 static void sclk_apply_divider(struct clk_regmap *clk, in sclk_apply_divider() argument
160 if (MESON_PARM_APPLICABLE(&sclk->hi)) in sclk_apply_divider()
161 sclk_apply_ratio(clk, sclk); in sclk_apply_divider()
163 meson_parm_write(clk->map, &sclk->div, sclk->cached_div - 1); in sclk_apply_divider()
169 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_set_rate() local
170 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_set_rate()
173 sclk->cached_div = sclk_div_getdiv(hw, rate, prate, maxdiv); in sclk_div_set_rate()
176 sclk_apply_divider(clk, sclk); in sclk_div_set_rate()
184 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_recalc_rate() local
185 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_recalc_rate()
187 return DIV_ROUND_UP_ULL((u64)prate, sclk->cached_div); in sclk_div_recalc_rate()
192 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_enable() local
193 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_enable()
195 sclk_apply_divider(clk, sclk); in sclk_div_enable()
202 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_disable() local
203 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_disable()
205 meson_parm_write(clk->map, &sclk->div, 0); in sclk_div_disable()
210 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_is_enabled() local
211 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_is_enabled()
213 if (meson_parm_read(clk->map, &sclk->div)) in sclk_div_is_enabled()
221 struct clk_regmap *clk = to_clk_regmap(hw); in sclk_div_init() local
222 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); in sclk_div_init()
225 val = meson_parm_read(clk->map, &sclk->div); in sclk_div_init()
229 sclk->cached_div = sclk_div_maxdiv(sclk); in sclk_div_init()
231 sclk->cached_div = val + 1; in sclk_div_init()
233 sclk_div_get_duty_cycle(hw, &sclk->cached_duty); in sclk_div_init()