Lines Matching +full:delta +full:- +full:sigma

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Maxime Ripard <maxime.ripard@free-electrons.com>
7 #include <linux/clk-provider.h>
37 for (_n = nm->min_n; _n <= nm->max_n; _n++) { in ccu_nm_find_best()
38 for (_m = nm->min_m; _m <= nm->max_m; _m++) { in ccu_nm_find_best()
50 nm->n = best_n; in ccu_nm_find_best()
51 nm->m = best_m; in ccu_nm_find_best()
60 return ccu_gate_helper_disable(&nm->common, nm->enable); in ccu_nm_disable()
67 return ccu_gate_helper_enable(&nm->common, nm->enable); in ccu_nm_enable()
74 return ccu_gate_helper_is_enabled(&nm->common, nm->enable); in ccu_nm_is_enabled()
85 if (ccu_frac_helper_is_enabled(&nm->common, &nm->frac)) { in ccu_nm_recalc_rate()
86 rate = ccu_frac_helper_read_rate(&nm->common, &nm->frac); in ccu_nm_recalc_rate()
88 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_recalc_rate()
89 rate /= nm->fixed_post_div; in ccu_nm_recalc_rate()
94 reg = readl(nm->common.base + nm->common.reg); in ccu_nm_recalc_rate()
96 n = reg >> nm->n.shift; in ccu_nm_recalc_rate()
97 n &= (1 << nm->n.width) - 1; in ccu_nm_recalc_rate()
98 n += nm->n.offset; in ccu_nm_recalc_rate()
102 m = reg >> nm->m.shift; in ccu_nm_recalc_rate()
103 m &= (1 << nm->m.width) - 1; in ccu_nm_recalc_rate()
104 m += nm->m.offset; in ccu_nm_recalc_rate()
108 if (ccu_sdm_helper_is_enabled(&nm->common, &nm->sdm)) in ccu_nm_recalc_rate()
109 rate = ccu_sdm_helper_read_rate(&nm->common, &nm->sdm, m, n); in ccu_nm_recalc_rate()
113 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_recalc_rate()
114 rate /= nm->fixed_post_div; in ccu_nm_recalc_rate()
125 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_round_rate()
126 rate *= nm->fixed_post_div; in ccu_nm_round_rate()
128 if (rate < nm->min_rate) { in ccu_nm_round_rate()
129 rate = nm->min_rate; in ccu_nm_round_rate()
130 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_round_rate()
131 rate /= nm->fixed_post_div; in ccu_nm_round_rate()
135 if (nm->max_rate && rate > nm->max_rate) { in ccu_nm_round_rate()
136 rate = nm->max_rate; in ccu_nm_round_rate()
137 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_round_rate()
138 rate /= nm->fixed_post_div; in ccu_nm_round_rate()
142 if (ccu_frac_helper_has_rate(&nm->common, &nm->frac, rate)) { in ccu_nm_round_rate()
143 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_round_rate()
144 rate /= nm->fixed_post_div; in ccu_nm_round_rate()
148 if (ccu_sdm_helper_has_rate(&nm->common, &nm->sdm, rate)) { in ccu_nm_round_rate()
149 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_round_rate()
150 rate /= nm->fixed_post_div; in ccu_nm_round_rate()
154 _nm.min_n = nm->n.min ?: 1; in ccu_nm_round_rate()
155 _nm.max_n = nm->n.max ?: 1 << nm->n.width; in ccu_nm_round_rate()
157 _nm.max_m = nm->m.max ?: 1 << nm->m.width; in ccu_nm_round_rate()
159 rate = ccu_nm_find_best(&nm->common, *parent_rate, rate, &_nm); in ccu_nm_round_rate()
161 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_round_rate()
162 rate /= nm->fixed_post_div; in ccu_nm_round_rate()
175 /* Adjust target rate according to post-dividers */ in ccu_nm_set_rate()
176 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) in ccu_nm_set_rate()
177 rate = rate * nm->fixed_post_div; in ccu_nm_set_rate()
179 if (ccu_frac_helper_has_rate(&nm->common, &nm->frac, rate)) { in ccu_nm_set_rate()
180 spin_lock_irqsave(nm->common.lock, flags); in ccu_nm_set_rate()
183 reg = readl(nm->common.base + nm->common.reg); in ccu_nm_set_rate()
184 reg &= ~GENMASK(nm->m.width + nm->m.shift - 1, nm->m.shift); in ccu_nm_set_rate()
185 writel(reg, nm->common.base + nm->common.reg); in ccu_nm_set_rate()
187 spin_unlock_irqrestore(nm->common.lock, flags); in ccu_nm_set_rate()
189 ccu_frac_helper_enable(&nm->common, &nm->frac); in ccu_nm_set_rate()
191 return ccu_frac_helper_set_rate(&nm->common, &nm->frac, in ccu_nm_set_rate()
192 rate, nm->lock); in ccu_nm_set_rate()
194 ccu_frac_helper_disable(&nm->common, &nm->frac); in ccu_nm_set_rate()
197 _nm.min_n = nm->n.min ?: 1; in ccu_nm_set_rate()
198 _nm.max_n = nm->n.max ?: 1 << nm->n.width; in ccu_nm_set_rate()
200 _nm.max_m = nm->m.max ?: 1 << nm->m.width; in ccu_nm_set_rate()
202 if (ccu_sdm_helper_has_rate(&nm->common, &nm->sdm, rate)) { in ccu_nm_set_rate()
203 ccu_sdm_helper_enable(&nm->common, &nm->sdm, rate); in ccu_nm_set_rate()
205 /* Sigma delta modulation requires specific N and M factors */ in ccu_nm_set_rate()
206 ccu_sdm_helper_get_factors(&nm->common, &nm->sdm, rate, in ccu_nm_set_rate()
209 ccu_sdm_helper_disable(&nm->common, &nm->sdm); in ccu_nm_set_rate()
210 ccu_nm_find_best(&nm->common, parent_rate, rate, &_nm); in ccu_nm_set_rate()
213 spin_lock_irqsave(nm->common.lock, flags); in ccu_nm_set_rate()
215 reg = readl(nm->common.base + nm->common.reg); in ccu_nm_set_rate()
216 reg &= ~GENMASK(nm->n.width + nm->n.shift - 1, nm->n.shift); in ccu_nm_set_rate()
217 reg &= ~GENMASK(nm->m.width + nm->m.shift - 1, nm->m.shift); in ccu_nm_set_rate()
219 reg |= (_nm.n - nm->n.offset) << nm->n.shift; in ccu_nm_set_rate()
220 reg |= (_nm.m - nm->m.offset) << nm->m.shift; in ccu_nm_set_rate()
221 writel(reg, nm->common.base + nm->common.reg); in ccu_nm_set_rate()
223 spin_unlock_irqrestore(nm->common.lock, flags); in ccu_nm_set_rate()
225 ccu_helper_wait_for_lock(&nm->common, nm->lock); in ccu_nm_set_rate()