Lines Matching +full:max +full:- +full:cur

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
55 uint32_t ti_clksel_offset; /* mult-div1 */
82 uint32_t max; in ti_clk_factor_get_max() local
84 if (factor->flags & TI_CLK_FACTOR_FIXED) in ti_clk_factor_get_max()
85 max = factor->value; in ti_clk_factor_get_max()
87 max = (1 << factor->width); in ti_clk_factor_get_max()
90 return (max); in ti_clk_factor_get_max()
98 if (factor->flags & TI_CLK_FACTOR_FIXED) in ti_clk_factor_get_min()
99 min = factor->value; in ti_clk_factor_get_min()
100 else if (factor->flags & TI_CLK_FACTOR_ZERO_BASED) in ti_clk_factor_get_min()
102 else if (factor->flags & TI_CLK_FACTOR_MIN_VALUE) in ti_clk_factor_get_min()
103 min = factor->min_value; in ti_clk_factor_get_min()
114 uint64_t cur, best; in ti_dpll_clk_find_best() local
119 max_n = ti_clk_factor_get_max(&sc->n); in ti_dpll_clk_find_best()
120 max_p = ti_clk_factor_get_max(&sc->p); in ti_dpll_clk_find_best()
121 min_n = ti_clk_factor_get_min(&sc->n); in ti_dpll_clk_find_best()
122 min_p = ti_clk_factor_get_min(&sc->p); in ti_dpll_clk_find_best()
126 cur = fparent * n / p; in ti_dpll_clk_find_best()
127 if (abs(*fout - cur) < abs(*fout - best)) { in ti_dpll_clk_find_best()
128 best = cur; in ti_dpll_clk_find_best()
146 if (factor->flags & TI_CLK_FACTOR_FIXED) in ti_clk_get_factor()
147 return (factor->value); in ti_clk_get_factor()
149 factor_val = (val & factor->mask) >> factor->shift; in ti_clk_get_factor()
150 if (!(factor->flags & TI_CLK_FACTOR_ZERO_BASED)) in ti_clk_get_factor()
161 if (factor->flags & TI_CLK_FACTOR_FIXED) in ti_clk_factor_get_value()
162 return (factor->value); in ti_clk_factor_get_value()
164 if (factor->flags & TI_CLK_FACTOR_ZERO_BASED) in ti_clk_factor_get_value()
166 else if (factor->flags & TI_CLK_FACTOR_MAX_VALUE && in ti_clk_factor_get_value()
167 raw > factor->max_value) in ti_clk_factor_get_value()
168 val = factor->max_value; in ti_clk_factor_get_value()
170 val = raw - 1; in ti_clk_factor_get_value()
180 uint64_t cur, best; in ti_dpll_clk_set_freq() local
185 best = cur = 0; in ti_dpll_clk_set_freq()
209 WRITE4(clk, sc->ti_clkmode_offset, DPLL_EN_MN_BYPASS_MODE); in ti_dpll_clk_set_freq()
215 READ4(clk, sc->ti_idlest_offset, &val); in ti_dpll_clk_set_freq()
216 } while (!(val & ST_MN_BYPASS_MASK) && timeout--); in ti_dpll_clk_set_freq()
224 READ4(clk, sc->ti_clksel_offset, &val); in ti_dpll_clk_set_freq()
226 n = ti_clk_factor_get_value(&sc->n, best_n); in ti_dpll_clk_set_freq()
227 p = ti_clk_factor_get_value(&sc->p, best_p); in ti_dpll_clk_set_freq()
228 val &= ~sc->n.mask; in ti_dpll_clk_set_freq()
229 val &= ~sc->p.mask; in ti_dpll_clk_set_freq()
230 val |= n << sc->n.shift; in ti_dpll_clk_set_freq()
231 val |= p << sc->p.shift; in ti_dpll_clk_set_freq()
233 WRITE4(clk, sc->ti_clksel_offset, val); in ti_dpll_clk_set_freq()
242 WRITE4(clk, sc->ti_clkmode_offset, DPLL_EN_LOCK_MODE); in ti_dpll_clk_set_freq()
248 READ4(clk, sc->ti_idlest_offset, &val); in ti_dpll_clk_set_freq()
249 } while (!(val & ST_DPLL_CLK_MASK) && timeout--); in ti_dpll_clk_set_freq()
271 READ4(clk, sc->ti_clksel_offset, &val); in ti_dpll_clk_recalc()
274 n = ti_clk_get_factor(val, &sc->n); in ti_dpll_clk_recalc()
275 p = ti_clk_get_factor(val, &sc->p); in ti_dpll_clk_recalc()
299 clk = clknode_create(clkdom, &ti_dpll_clknode_class, &clkdef->clkdef); in ti_clknode_dpll_register()
305 sc->ti_clkmode_offset = clkdef->ti_clkmode_offset; in ti_clknode_dpll_register()
306 sc->ti_clkmode_flags = clkdef->ti_clkmode_flags; in ti_clknode_dpll_register()
307 sc->ti_idlest_offset = clkdef->ti_idlest_offset; in ti_clknode_dpll_register()
308 sc->ti_clksel_offset = clkdef->ti_clksel_offset; in ti_clknode_dpll_register()
310 sc->n.shift = clkdef->ti_clksel_mult.shift; in ti_clknode_dpll_register()
311 sc->n.mask = clkdef->ti_clksel_mult.mask; in ti_clknode_dpll_register()
312 sc->n.width = clkdef->ti_clksel_mult.width; in ti_clknode_dpll_register()
313 sc->n.value = clkdef->ti_clksel_mult.value; in ti_clknode_dpll_register()
314 sc->n.min_value = clkdef->ti_clksel_mult.min_value; in ti_clknode_dpll_register()
315 sc->n.max_value = clkdef->ti_clksel_mult.max_value; in ti_clknode_dpll_register()
316 sc->n.flags = clkdef->ti_clksel_mult.flags; in ti_clknode_dpll_register()
318 sc->p.shift = clkdef->ti_clksel_div.shift; in ti_clknode_dpll_register()
319 sc->p.mask = clkdef->ti_clksel_div.mask; in ti_clknode_dpll_register()
320 sc->p.width = clkdef->ti_clksel_div.width; in ti_clknode_dpll_register()
321 sc->p.value = clkdef->ti_clksel_div.value; in ti_clknode_dpll_register()
322 sc->p.min_value = clkdef->ti_clksel_div.min_value; in ti_clknode_dpll_register()
323 sc->p.max_value = clkdef->ti_clksel_div.max_value; in ti_clknode_dpll_register()
324 sc->p.flags = clkdef->ti_clksel_div.flags; in ti_clknode_dpll_register()
326 sc->ti_autoidle_offset = clkdef->ti_autoidle_offset; in ti_clknode_dpll_register()