Lines Matching +full:max +full:- +full:bit +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Maxime Ripard <maxime.ripard@free-electrons.com>
7 #include <linux/clk-provider.h>
13 static void ccu_mp_find_best(unsigned long parent, unsigned long rate, in ccu_mp_find_best() argument
25 if (tmp_rate > rate) in ccu_mp_find_best()
28 if ((rate - tmp_rate) < (rate - best_rate)) { in ccu_mp_find_best()
42 unsigned long rate, in ccu_mp_find_best_with_parent_adj() argument
56 * unsigned long in rate * m * p below in ccu_mp_find_best_with_parent_adj()
59 maxdiv = min(ULONG_MAX / rate, maxdiv); in ccu_mp_find_best_with_parent_adj()
68 if (rate * div == parent_rate_saved) { in ccu_mp_find_best_with_parent_adj()
71 * rate can be divided from parent clock without in ccu_mp_find_best_with_parent_adj()
72 * needing to change parent rate, so return the in ccu_mp_find_best_with_parent_adj()
76 return rate; in ccu_mp_find_best_with_parent_adj()
79 parent_rate = clk_hw_round_rate(hw, rate * div); in ccu_mp_find_best_with_parent_adj()
82 if (now <= rate && now > best_rate) { in ccu_mp_find_best_with_parent_adj()
86 if (now == rate) in ccu_mp_find_best_with_parent_adj()
87 return rate; in ccu_mp_find_best_with_parent_adj()
98 unsigned long rate, in ccu_mp_round_rate() argument
105 if (cmp->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_mp_round_rate()
106 rate *= cmp->fixed_post_div; in ccu_mp_round_rate()
108 max_m = cmp->m.max ?: 1 << cmp->m.width; in ccu_mp_round_rate()
109 max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1); in ccu_mp_round_rate()
112 ccu_mp_find_best(*parent_rate, rate, max_m, max_p, &m, &p); in ccu_mp_round_rate()
113 rate = *parent_rate / p / m; in ccu_mp_round_rate()
115 rate = ccu_mp_find_best_with_parent_adj(hw, parent_rate, rate, in ccu_mp_round_rate()
119 if (cmp->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_mp_round_rate()
120 rate /= cmp->fixed_post_div; in ccu_mp_round_rate()
122 return rate; in ccu_mp_round_rate()
129 return ccu_gate_helper_disable(&cmp->common, cmp->enable); in ccu_mp_disable()
136 return ccu_gate_helper_enable(&cmp->common, cmp->enable); in ccu_mp_enable()
143 return ccu_gate_helper_is_enabled(&cmp->common, cmp->enable); in ccu_mp_is_enabled()
150 unsigned long rate; in ccu_mp_recalc_rate() local
154 /* Adjust parent_rate according to pre-dividers */ in ccu_mp_recalc_rate()
155 parent_rate = ccu_mux_helper_apply_prediv(&cmp->common, &cmp->mux, -1, in ccu_mp_recalc_rate()
158 reg = readl(cmp->common.base + cmp->common.reg); in ccu_mp_recalc_rate()
160 m = reg >> cmp->m.shift; in ccu_mp_recalc_rate()
161 m &= (1 << cmp->m.width) - 1; in ccu_mp_recalc_rate()
162 m += cmp->m.offset; in ccu_mp_recalc_rate()
166 p = reg >> cmp->p.shift; in ccu_mp_recalc_rate()
167 p &= (1 << cmp->p.width) - 1; in ccu_mp_recalc_rate()
169 rate = (parent_rate >> p) / m; in ccu_mp_recalc_rate()
170 if (cmp->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_mp_recalc_rate()
171 rate /= cmp->fixed_post_div; in ccu_mp_recalc_rate()
173 return rate; in ccu_mp_recalc_rate()
181 return ccu_mux_helper_determine_rate(&cmp->common, &cmp->mux, in ccu_mp_determine_rate()
185 static int ccu_mp_set_rate(struct clk_hw *hw, unsigned long rate, in ccu_mp_set_rate() argument
194 /* Adjust parent_rate according to pre-dividers */ in ccu_mp_set_rate()
195 parent_rate = ccu_mux_helper_apply_prediv(&cmp->common, &cmp->mux, -1, in ccu_mp_set_rate()
198 max_m = cmp->m.max ?: 1 << cmp->m.width; in ccu_mp_set_rate()
199 max_p = cmp->p.max ?: 1 << ((1 << cmp->p.width) - 1); in ccu_mp_set_rate()
201 /* Adjust target rate according to post-dividers */ in ccu_mp_set_rate()
202 if (cmp->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_mp_set_rate()
203 rate = rate * cmp->fixed_post_div; in ccu_mp_set_rate()
205 ccu_mp_find_best(parent_rate, rate, max_m, max_p, &m, &p); in ccu_mp_set_rate()
207 spin_lock_irqsave(cmp->common.lock, flags); in ccu_mp_set_rate()
209 reg = readl(cmp->common.base + cmp->common.reg); in ccu_mp_set_rate()
210 reg &= ~GENMASK(cmp->m.width + cmp->m.shift - 1, cmp->m.shift); in ccu_mp_set_rate()
211 reg &= ~GENMASK(cmp->p.width + cmp->p.shift - 1, cmp->p.shift); in ccu_mp_set_rate()
212 reg |= (m - cmp->m.offset) << cmp->m.shift; in ccu_mp_set_rate()
213 reg |= ilog2(p) << cmp->p.shift; in ccu_mp_set_rate()
215 writel(reg, cmp->common.base + cmp->common.reg); in ccu_mp_set_rate()
217 spin_unlock_irqrestore(cmp->common.lock, flags); in ccu_mp_set_rate()
226 return ccu_mux_helper_get_parent(&cmp->common, &cmp->mux); in ccu_mp_get_parent()
233 return ccu_mux_helper_set_parent(&cmp->common, &cmp->mux, index); in ccu_mp_set_parent()
258 * mode is active, the clock output rate is halved. This new class
261 * if the new timing mode bit is set, to account for the post
263 * are halved if the mode bit is set.
269 unsigned long rate = ccu_mp_recalc_rate(hw, parent_rate); in ccu_mp_mmc_recalc_rate() local
271 u32 val = readl(cm->base + cm->reg); in ccu_mp_mmc_recalc_rate()
274 return rate / 2; in ccu_mp_mmc_recalc_rate()
275 return rate; in ccu_mp_mmc_recalc_rate()
282 u32 val = readl(cm->base + cm->reg); in ccu_mp_mmc_determine_rate()
285 /* adjust the requested clock rate */ in ccu_mp_mmc_determine_rate()
287 req->rate *= 2; in ccu_mp_mmc_determine_rate()
288 req->min_rate *= 2; in ccu_mp_mmc_determine_rate()
289 req->max_rate *= 2; in ccu_mp_mmc_determine_rate()
294 /* re-adjust the requested clock rate back */ in ccu_mp_mmc_determine_rate()
296 req->rate /= 2; in ccu_mp_mmc_determine_rate()
297 req->min_rate /= 2; in ccu_mp_mmc_determine_rate()
298 req->max_rate /= 2; in ccu_mp_mmc_determine_rate()
304 static int ccu_mp_mmc_set_rate(struct clk_hw *hw, unsigned long rate, in ccu_mp_mmc_set_rate() argument
308 u32 val = readl(cm->base + cm->reg); in ccu_mp_mmc_set_rate()
311 rate *= 2; in ccu_mp_mmc_set_rate()
313 return ccu_mp_set_rate(hw, rate, parent_rate); in ccu_mp_mmc_set_rate()