Lines Matching +full:rate +full:- +full:a
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2005-2008 Texas Instruments, Inc.
6 * Copyright (C) 2004-2010 Nokia Corporation
9 * Richard Woodruff <r-woodruff2@ti.com>
17 #include <linux/clk-provider.h>
25 /* DPLL rate rounding: minimum DPLL multiplier, divider values */
30 #define DPLL_MULT_UNDERFLOW -1
33 * Scale factor to mitigate roundoff errors in DPLL rate rounding.
35 * but the closer the rounded rate to the target rate. DPLL_SCALE_FACTOR
36 * must be a power of DPLL_SCALE_BASE.
51 #define DPLL_FINT_UNDERFLOW -1
52 #define DPLL_FINT_INVALID -2
57 * _dpll_test_fint - test whether an Fint value is valid for the DPLL
61 * Tests whether a particular divider @n will result in a valid DPLL
63 * Correction". Returns 0 if OK, -1 if the enclosing loop can terminate
64 * (assuming that it is counting N upwards), or -2 if the enclosing loop
73 dd = clk->dpll_data; in _dpll_test_fint()
75 /* DPLL divider must result in a valid jitter correction val */ in _dpll_test_fint()
76 fint = clk_hw_get_rate(clk_hw_get_parent(&clk->hw)) / n; in _dpll_test_fint()
78 if (dd->flags & DPLL_J_TYPE) { in _dpll_test_fint()
82 fint_min = ti_clk_get_features()->fint_min; in _dpll_test_fint()
83 fint_max = ti_clk_get_features()->fint_max; in _dpll_test_fint()
91 if (fint < ti_clk_get_features()->fint_min) { in _dpll_test_fint()
94 dd->max_divider = n; in _dpll_test_fint()
96 } else if (fint > ti_clk_get_features()->fint_max) { in _dpll_test_fint()
99 dd->min_divider = n; in _dpll_test_fint()
101 } else if (fint > ti_clk_get_features()->fint_band1_max && in _dpll_test_fint()
102 fint < ti_clk_get_features()->fint_band2_min) { in _dpll_test_fint()
121 * _dpll_test_mult - test a DPLL multiplier value
124 * @new_rate: pointer to storage for the resulting rounded rate
125 * @target_rate: the desired DPLL rate
126 * @parent_rate: the DPLL's parent clock rate
128 * This code tests a DPLL multiplier value, ensuring that the
129 * resulting rate will not be higher than the target_rate, and that
133 * a non-scaled m upon return. This non-scaled m will result in a
137 * non-scaled m attempted to underflow, which can allow the calling
152 * The new rate must be <= the target rate to avoid programming in _dpll_test_mult()
153 * a rate that is impossible for the hardware to handle in _dpll_test_mult()
157 (*m)--; in _dpll_test_mult()
175 * _omap2_dpll_is_in_bypass - check if DPLL is in bypass mode or not
185 mask = ti_clk_get_features()->dpll_bypass_vals; in _omap2_dpll_is_in_bypass()
188 * Each set bit in the mask corresponds to a bypass value equal in _omap2_dpll_is_in_bypass()
189 * to the bitshift. Go through each set-bit in the mask and in _omap2_dpll_is_in_bypass()
209 dd = clk->dpll_data; in omap2_init_dpll_parent()
211 return -EINVAL; in omap2_init_dpll_parent()
213 v = ti_clk_ll_ops->clk_readl(&dd->control_reg); in omap2_init_dpll_parent()
214 v &= dd->enable_mask; in omap2_init_dpll_parent()
215 v >>= __ffs(dd->enable_mask); in omap2_init_dpll_parent()
225 * omap2_get_dpll_rate - returns the current DPLL CLKOUT rate
226 * @clk: struct clk * of a DPLL
228 * DPLLs can be locked or bypassed - basically, enabled or disabled.
230 * bypassed, on OMAP2xxx, the output rate is either the 32KiHz clock
234 * Returns the current DPLL CLKOUT rate (*not* CLKOUTX2) if the DPLL is
235 * locked, or the appropriate bypass rate if the DPLL is bypassed, or 0
236 * if the clock @clk is not a DPLL.
244 dd = clk->dpll_data; in omap2_get_dpll_rate()
248 /* Return bypass rate if DPLL is bypassed */ in omap2_get_dpll_rate()
249 v = ti_clk_ll_ops->clk_readl(&dd->control_reg); in omap2_get_dpll_rate()
250 v &= dd->enable_mask; in omap2_get_dpll_rate()
251 v >>= __ffs(dd->enable_mask); in omap2_get_dpll_rate()
254 return clk_hw_get_rate(dd->clk_bypass); in omap2_get_dpll_rate()
256 v = ti_clk_ll_ops->clk_readl(&dd->mult_div1_reg); in omap2_get_dpll_rate()
257 dpll_mult = v & dd->mult_mask; in omap2_get_dpll_rate()
258 dpll_mult >>= __ffs(dd->mult_mask); in omap2_get_dpll_rate()
259 dpll_div = v & dd->div1_mask; in omap2_get_dpll_rate()
260 dpll_div >>= __ffs(dd->div1_mask); in omap2_get_dpll_rate()
262 dpll_clk = (u64)clk_hw_get_rate(dd->clk_ref) * dpll_mult; in omap2_get_dpll_rate()
268 /* DPLL rate rounding code */
271 * omap2_dpll_determine_rate - round a target rate for an OMAP DPLL
272 * @hw: struct clk_hw containing the struct clk * for a DPLL
273 * @req: rate request
275 * Given a DPLL and a desired target rate, round the target rate to a
276 * possible, programmable rate for this DPLL. Attempts to select the
279 * (expensive) function again. Returns -EINVAL if the target rate
280 * cannot be rounded, or the rounded rate upon success.
295 if (!clk || !clk->dpll_data) in omap2_dpll_determine_rate()
296 return -EINVAL; in omap2_dpll_determine_rate()
298 dd = clk->dpll_data; in omap2_dpll_determine_rate()
300 if (dd->max_rate && req->rate > dd->max_rate) in omap2_dpll_determine_rate()
301 req->rate = dd->max_rate; in omap2_dpll_determine_rate()
303 ref_rate = clk_hw_get_rate(dd->clk_ref); in omap2_dpll_determine_rate()
305 pr_debug("clock: %s: starting DPLL round_rate, target rate %lu\n", in omap2_dpll_determine_rate()
306 clk_name, req->rate); in omap2_dpll_determine_rate()
308 scaled_rt_rp = req->rate / (ref_rate / DPLL_SCALE_FACTOR); in omap2_dpll_determine_rate()
309 scaled_max_m = dd->max_multiplier * DPLL_SCALE_FACTOR; in omap2_dpll_determine_rate()
311 dd->last_rounded_rate = 0; in omap2_dpll_determine_rate()
313 for (n = dd->min_divider; n <= dd->max_divider; n++) { in omap2_dpll_determine_rate()
325 * Since we're counting n up, a m overflow means we in omap2_dpll_determine_rate()
333 r = _dpll_test_mult(&m, n, &new_rate, req->rate, in omap2_dpll_determine_rate()
336 /* m can't be set low enough for this n - try with a larger n */ in omap2_dpll_determine_rate()
340 /* skip rates above our target rate */ in omap2_dpll_determine_rate()
341 delta = req->rate - new_rate; in omap2_dpll_determine_rate()
359 pr_debug("clock: %s: cannot round to rate %lu\n", in omap2_dpll_determine_rate()
360 clk_name, req->rate); in omap2_dpll_determine_rate()
361 return -EINVAL; in omap2_dpll_determine_rate()
364 dd->last_rounded_m = min_delta_m; in omap2_dpll_determine_rate()
365 dd->last_rounded_n = min_delta_n; in omap2_dpll_determine_rate()
366 dd->last_rounded_rate = req->rate - prev_min_delta; in omap2_dpll_determine_rate()
368 req->rate = dd->last_rounded_rate; in omap2_dpll_determine_rate()