Lines Matching +full:clock +full:- +full:skip
1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP2/3/4 DPLL clock functions
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>
23 #include "clock.h"
30 #define DPLL_MULT_UNDERFLOW -1
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
62 * internal clock frequency Fint. See the 34xx TRM 4.7.6.2 "DPLL Jitter
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
65 * should skip to the next iteration (again assuming N is increasing).
73 dd = clk->dpll_data; 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
126 * @parent_rate: the DPLL's parent clock rate
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
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()
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
228 * DPLLs can be locked or bypassed - basically, enabled or disabled.
230 * bypassed, on OMAP2xxx, the output rate is either the 32KiHz clock
236 * if the clock @clk is not a DPLL.
244 dd = clk->dpll_data; 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()
271 * omap2_dpll_round_rate - round a target rate for an OMAP DPLL
273 * @target_rate: desired DPLL clock rate
274 * @parent_rate: parent's DPLL clock rate
297 if (!clk || !clk->dpll_data) in omap2_dpll_round_rate()
300 dd = clk->dpll_data; in omap2_dpll_round_rate()
302 if (dd->max_rate && target_rate > dd->max_rate) in omap2_dpll_round_rate()
303 target_rate = dd->max_rate; in omap2_dpll_round_rate()
305 ref_rate = clk_hw_get_rate(dd->clk_ref); in omap2_dpll_round_rate()
307 pr_debug("clock: %s: starting DPLL round_rate, target rate %lu\n", in omap2_dpll_round_rate()
311 scaled_max_m = dd->max_multiplier * DPLL_SCALE_FACTOR; in omap2_dpll_round_rate()
313 dd->last_rounded_rate = 0; in omap2_dpll_round_rate()
315 for (n = dd->min_divider; n <= dd->max_divider; n++) { in omap2_dpll_round_rate()
338 /* m can't be set low enough for this n - try with a larger n */ in omap2_dpll_round_rate()
342 /* skip rates above our target rate */ in omap2_dpll_round_rate()
343 delta = target_rate - new_rate; in omap2_dpll_round_rate()
353 pr_debug("clock: %s: m = %d: n = %d: new_rate = %lu\n", in omap2_dpll_round_rate()
361 pr_debug("clock: %s: cannot round to rate %lu\n", in omap2_dpll_round_rate()
366 dd->last_rounded_m = min_delta_m; in omap2_dpll_round_rate()
367 dd->last_rounded_n = min_delta_n; in omap2_dpll_round_rate()
368 dd->last_rounded_rate = target_rate - prev_min_delta; in omap2_dpll_round_rate()
370 return dd->last_rounded_rate; in omap2_dpll_round_rate()