17b9487a9SPaul Walmsley // SPDX-License-Identifier: GPL-2.0
27b9487a9SPaul Walmsley /*
37b9487a9SPaul Walmsley * Copyright (C) 2018-2019 SiFive, Inc.
47b9487a9SPaul Walmsley * Wesley Terpstra
57b9487a9SPaul Walmsley * Paul Walmsley
67b9487a9SPaul Walmsley *
77b9487a9SPaul Walmsley * This library supports configuration parsing and reprogramming of
87b9487a9SPaul Walmsley * the CLN28HPC variant of the Analog Bits Wide Range PLL. The
97b9487a9SPaul Walmsley * intention is for this library to be reusable for any device that
107b9487a9SPaul Walmsley * integrates this PLL; thus the register structure and programming
117b9487a9SPaul Walmsley * details are expected to be provided by a separate IP block driver.
127b9487a9SPaul Walmsley *
137b9487a9SPaul Walmsley * The bulk of this code is primarily useful for clock configurations
147b9487a9SPaul Walmsley * that must operate at arbitrary rates, as opposed to clock configurations
157b9487a9SPaul Walmsley * that are restricted by software or manufacturer guidance to a small,
167b9487a9SPaul Walmsley * pre-determined set of performance points.
177b9487a9SPaul Walmsley *
187b9487a9SPaul Walmsley * References:
197b9487a9SPaul Walmsley * - Analog Bits "Wide Range PLL Datasheet", version 2015.10.01
207b9487a9SPaul Walmsley * - SiFive FU540-C000 Manual v1p0, Chapter 7 "Clocking and Reset"
217b9487a9SPaul Walmsley * https://static.dev.sifive.com/FU540-C000-v1.0.pdf
227b9487a9SPaul Walmsley */
237b9487a9SPaul Walmsley
247b9487a9SPaul Walmsley #include <linux/bug.h>
257b9487a9SPaul Walmsley #include <linux/err.h>
26f39650deSAndy Shevchenko #include <linux/limits.h>
277b9487a9SPaul Walmsley #include <linux/log2.h>
287b9487a9SPaul Walmsley #include <linux/math64.h>
29f39650deSAndy Shevchenko #include <linux/math.h>
30f39650deSAndy Shevchenko #include <linux/minmax.h>
31f39650deSAndy Shevchenko
327b9487a9SPaul Walmsley #include <linux/clk/analogbits-wrpll-cln28hpc.h>
337b9487a9SPaul Walmsley
347b9487a9SPaul Walmsley /* MIN_INPUT_FREQ: minimum input clock frequency, in Hz (Fref_min) */
357b9487a9SPaul Walmsley #define MIN_INPUT_FREQ 7000000
367b9487a9SPaul Walmsley
377b9487a9SPaul Walmsley /* MAX_INPUT_FREQ: maximum input clock frequency, in Hz (Fref_max) */
387b9487a9SPaul Walmsley #define MAX_INPUT_FREQ 600000000
397b9487a9SPaul Walmsley
407b9487a9SPaul Walmsley /* MIN_POST_DIVIDE_REF_FREQ: minimum post-divider reference frequency, in Hz */
417b9487a9SPaul Walmsley #define MIN_POST_DIVR_FREQ 7000000
427b9487a9SPaul Walmsley
437b9487a9SPaul Walmsley /* MAX_POST_DIVIDE_REF_FREQ: maximum post-divider reference frequency, in Hz */
447b9487a9SPaul Walmsley #define MAX_POST_DIVR_FREQ 200000000
457b9487a9SPaul Walmsley
467b9487a9SPaul Walmsley /* MIN_VCO_FREQ: minimum VCO frequency, in Hz (Fvco_min) */
477b9487a9SPaul Walmsley #define MIN_VCO_FREQ 2400000000UL
487b9487a9SPaul Walmsley
497b9487a9SPaul Walmsley /* MAX_VCO_FREQ: maximum VCO frequency, in Hz (Fvco_max) */
507b9487a9SPaul Walmsley #define MAX_VCO_FREQ 4800000000ULL
517b9487a9SPaul Walmsley
527b9487a9SPaul Walmsley /* MAX_DIVQ_DIVISOR: maximum output divisor. Selected by DIVQ = 6 */
537b9487a9SPaul Walmsley #define MAX_DIVQ_DIVISOR 64
547b9487a9SPaul Walmsley
557b9487a9SPaul Walmsley /* MAX_DIVR_DIVISOR: maximum reference divisor. Selected by DIVR = 63 */
567b9487a9SPaul Walmsley #define MAX_DIVR_DIVISOR 64
577b9487a9SPaul Walmsley
587b9487a9SPaul Walmsley /* MAX_LOCK_US: maximum PLL lock time, in microseconds (tLOCK_max) */
597b9487a9SPaul Walmsley #define MAX_LOCK_US 70
607b9487a9SPaul Walmsley
617b9487a9SPaul Walmsley /*
627b9487a9SPaul Walmsley * ROUND_SHIFT: number of bits to shift to avoid precision loss in the rounding
637b9487a9SPaul Walmsley * algorithm
647b9487a9SPaul Walmsley */
657b9487a9SPaul Walmsley #define ROUND_SHIFT 20
667b9487a9SPaul Walmsley
677b9487a9SPaul Walmsley /*
687b9487a9SPaul Walmsley * Private functions
697b9487a9SPaul Walmsley */
707b9487a9SPaul Walmsley
717b9487a9SPaul Walmsley /**
727b9487a9SPaul Walmsley * __wrpll_calc_filter_range() - determine PLL loop filter bandwidth
737b9487a9SPaul Walmsley * @post_divr_freq: input clock rate after the R divider
747b9487a9SPaul Walmsley *
757b9487a9SPaul Walmsley * Select the value to be presented to the PLL RANGE input signals, based
767b9487a9SPaul Walmsley * on the input clock frequency after the post-R-divider @post_divr_freq.
777b9487a9SPaul Walmsley * This code follows the recommendations in the PLL datasheet for filter
787b9487a9SPaul Walmsley * range selection.
797b9487a9SPaul Walmsley *
807b9487a9SPaul Walmsley * Return: The RANGE value to be presented to the PLL configuration inputs,
817b9487a9SPaul Walmsley * or a negative return code upon error.
827b9487a9SPaul Walmsley */
__wrpll_calc_filter_range(unsigned long post_divr_freq)837b9487a9SPaul Walmsley static int __wrpll_calc_filter_range(unsigned long post_divr_freq)
847b9487a9SPaul Walmsley {
857b9487a9SPaul Walmsley if (post_divr_freq < MIN_POST_DIVR_FREQ ||
867b9487a9SPaul Walmsley post_divr_freq > MAX_POST_DIVR_FREQ) {
877b9487a9SPaul Walmsley WARN(1, "%s: post-divider reference freq out of range: %lu",
887b9487a9SPaul Walmsley __func__, post_divr_freq);
897b9487a9SPaul Walmsley return -ERANGE;
907b9487a9SPaul Walmsley }
917b9487a9SPaul Walmsley
927b9487a9SPaul Walmsley switch (post_divr_freq) {
937b9487a9SPaul Walmsley case 0 ... 10999999:
947b9487a9SPaul Walmsley return 1;
957b9487a9SPaul Walmsley case 11000000 ... 17999999:
967b9487a9SPaul Walmsley return 2;
977b9487a9SPaul Walmsley case 18000000 ... 29999999:
987b9487a9SPaul Walmsley return 3;
997b9487a9SPaul Walmsley case 30000000 ... 49999999:
1007b9487a9SPaul Walmsley return 4;
1017b9487a9SPaul Walmsley case 50000000 ... 79999999:
1027b9487a9SPaul Walmsley return 5;
1037b9487a9SPaul Walmsley case 80000000 ... 129999999:
1047b9487a9SPaul Walmsley return 6;
1057b9487a9SPaul Walmsley }
1067b9487a9SPaul Walmsley
1077b9487a9SPaul Walmsley return 7;
1087b9487a9SPaul Walmsley }
1097b9487a9SPaul Walmsley
1107b9487a9SPaul Walmsley /**
1117b9487a9SPaul Walmsley * __wrpll_calc_fbdiv() - return feedback fixed divide value
1127b9487a9SPaul Walmsley * @c: ptr to a struct wrpll_cfg record to read from
1137b9487a9SPaul Walmsley *
1147b9487a9SPaul Walmsley * The internal feedback path includes a fixed by-two divider; the
1157b9487a9SPaul Walmsley * external feedback path does not. Return the appropriate divider
1167b9487a9SPaul Walmsley * value (2 or 1) depending on whether internal or external feedback
1177b9487a9SPaul Walmsley * is enabled. This code doesn't test for invalid configurations
1187b9487a9SPaul Walmsley * (e.g. both or neither of WRPLL_FLAGS_*_FEEDBACK are set); it relies
1197b9487a9SPaul Walmsley * on the caller to do so.
1207b9487a9SPaul Walmsley *
1217b9487a9SPaul Walmsley * Context: Any context. Caller must protect the memory pointed to by
1227b9487a9SPaul Walmsley * @c from simultaneous modification.
1237b9487a9SPaul Walmsley *
1247b9487a9SPaul Walmsley * Return: 2 if internal feedback is enabled or 1 if external feedback
1257b9487a9SPaul Walmsley * is enabled.
1267b9487a9SPaul Walmsley */
__wrpll_calc_fbdiv(const struct wrpll_cfg * c)1277b9487a9SPaul Walmsley static u8 __wrpll_calc_fbdiv(const struct wrpll_cfg *c)
1287b9487a9SPaul Walmsley {
1297b9487a9SPaul Walmsley return (c->flags & WRPLL_FLAGS_INT_FEEDBACK_MASK) ? 2 : 1;
1307b9487a9SPaul Walmsley }
1317b9487a9SPaul Walmsley
1327b9487a9SPaul Walmsley /**
1337b9487a9SPaul Walmsley * __wrpll_calc_divq() - determine DIVQ based on target PLL output clock rate
1347b9487a9SPaul Walmsley * @target_rate: target PLL output clock rate
1357b9487a9SPaul Walmsley * @vco_rate: pointer to a u64 to store the computed VCO rate into
1367b9487a9SPaul Walmsley *
1377b9487a9SPaul Walmsley * Determine a reasonable value for the PLL Q post-divider, based on the
1387b9487a9SPaul Walmsley * target output rate @target_rate for the PLL. Along with returning the
1397b9487a9SPaul Walmsley * computed Q divider value as the return value, this function stores the
1407b9487a9SPaul Walmsley * desired target VCO rate into the variable pointed to by @vco_rate.
1417b9487a9SPaul Walmsley *
1427b9487a9SPaul Walmsley * Context: Any context. Caller must protect the memory pointed to by
1437b9487a9SPaul Walmsley * @vco_rate from simultaneous access or modification.
1447b9487a9SPaul Walmsley *
1457b9487a9SPaul Walmsley * Return: a positive integer DIVQ value to be programmed into the hardware
1467b9487a9SPaul Walmsley * upon success, or 0 upon error (since 0 is an invalid DIVQ value)
1477b9487a9SPaul Walmsley */
__wrpll_calc_divq(u32 target_rate,u64 * vco_rate)1487b9487a9SPaul Walmsley static u8 __wrpll_calc_divq(u32 target_rate, u64 *vco_rate)
1497b9487a9SPaul Walmsley {
1507b9487a9SPaul Walmsley u64 s;
1517b9487a9SPaul Walmsley u8 divq = 0;
1527b9487a9SPaul Walmsley
1537b9487a9SPaul Walmsley if (!vco_rate) {
1547b9487a9SPaul Walmsley WARN_ON(1);
1557b9487a9SPaul Walmsley goto wcd_out;
1567b9487a9SPaul Walmsley }
1577b9487a9SPaul Walmsley
1587b9487a9SPaul Walmsley s = div_u64(MAX_VCO_FREQ, target_rate);
1597b9487a9SPaul Walmsley if (s <= 1) {
1607b9487a9SPaul Walmsley divq = 1;
1617b9487a9SPaul Walmsley *vco_rate = MAX_VCO_FREQ;
1627b9487a9SPaul Walmsley } else if (s > MAX_DIVQ_DIVISOR) {
1637b9487a9SPaul Walmsley divq = ilog2(MAX_DIVQ_DIVISOR);
1647b9487a9SPaul Walmsley *vco_rate = MIN_VCO_FREQ;
1657b9487a9SPaul Walmsley } else {
1667b9487a9SPaul Walmsley divq = ilog2(s);
1677b9487a9SPaul Walmsley *vco_rate = (u64)target_rate << divq;
1687b9487a9SPaul Walmsley }
1697b9487a9SPaul Walmsley
1707b9487a9SPaul Walmsley wcd_out:
1717b9487a9SPaul Walmsley return divq;
1727b9487a9SPaul Walmsley }
1737b9487a9SPaul Walmsley
1747b9487a9SPaul Walmsley /**
1757b9487a9SPaul Walmsley * __wrpll_update_parent_rate() - update PLL data when parent rate changes
1767b9487a9SPaul Walmsley * @c: ptr to a struct wrpll_cfg record to write PLL data to
1777b9487a9SPaul Walmsley * @parent_rate: PLL input refclk rate (pre-R-divider)
1787b9487a9SPaul Walmsley *
1797b9487a9SPaul Walmsley * Pre-compute some data used by the PLL configuration algorithm when
1807b9487a9SPaul Walmsley * the PLL's reference clock rate changes. The intention is to avoid
1817b9487a9SPaul Walmsley * computation when the parent rate remains constant - expected to be
1827b9487a9SPaul Walmsley * the common case.
1837b9487a9SPaul Walmsley *
1847b9487a9SPaul Walmsley * Returns: 0 upon success or -ERANGE if the reference clock rate is
1857b9487a9SPaul Walmsley * out of range.
1867b9487a9SPaul Walmsley */
__wrpll_update_parent_rate(struct wrpll_cfg * c,unsigned long parent_rate)1877b9487a9SPaul Walmsley static int __wrpll_update_parent_rate(struct wrpll_cfg *c,
1887b9487a9SPaul Walmsley unsigned long parent_rate)
1897b9487a9SPaul Walmsley {
1907b9487a9SPaul Walmsley u8 max_r_for_parent;
1917b9487a9SPaul Walmsley
1927b9487a9SPaul Walmsley if (parent_rate > MAX_INPUT_FREQ || parent_rate < MIN_POST_DIVR_FREQ)
1937b9487a9SPaul Walmsley return -ERANGE;
1947b9487a9SPaul Walmsley
1957b9487a9SPaul Walmsley c->parent_rate = parent_rate;
1967b9487a9SPaul Walmsley max_r_for_parent = div_u64(parent_rate, MIN_POST_DIVR_FREQ);
1977b9487a9SPaul Walmsley c->max_r = min_t(u8, MAX_DIVR_DIVISOR, max_r_for_parent);
1987b9487a9SPaul Walmsley
1997b9487a9SPaul Walmsley c->init_r = DIV_ROUND_UP_ULL(parent_rate, MAX_POST_DIVR_FREQ);
2007b9487a9SPaul Walmsley
2017b9487a9SPaul Walmsley return 0;
2027b9487a9SPaul Walmsley }
2037b9487a9SPaul Walmsley
2047b9487a9SPaul Walmsley /**
20506abc753SYang Yingliang * wrpll_configure_for_rate() - compute PLL configuration for a target rate
2067b9487a9SPaul Walmsley * @c: ptr to a struct wrpll_cfg record to write into
2077b9487a9SPaul Walmsley * @target_rate: target PLL output clock rate (post-Q-divider)
2087b9487a9SPaul Walmsley * @parent_rate: PLL input refclk rate (pre-R-divider)
2097b9487a9SPaul Walmsley *
2107b9487a9SPaul Walmsley * Compute the appropriate PLL signal configuration values and store
2117b9487a9SPaul Walmsley * in PLL context @c. PLL reprogramming is not glitchless, so the
2127b9487a9SPaul Walmsley * caller should switch any downstream logic to a different clock
2137b9487a9SPaul Walmsley * source or clock-gate it before presenting these values to the PLL
2147b9487a9SPaul Walmsley * configuration signals.
2157b9487a9SPaul Walmsley *
2167b9487a9SPaul Walmsley * The caller must pass this function a pre-initialized struct
2177b9487a9SPaul Walmsley * wrpll_cfg record: either initialized to zero (with the
2187b9487a9SPaul Walmsley * exception of the .name and .flags fields) or read from the PLL.
2197b9487a9SPaul Walmsley *
2207b9487a9SPaul Walmsley * Context: Any context. Caller must protect the memory pointed to by @c
2217b9487a9SPaul Walmsley * from simultaneous access or modification.
2227b9487a9SPaul Walmsley *
2237b9487a9SPaul Walmsley * Return: 0 upon success; anything else upon failure.
2247b9487a9SPaul Walmsley */
wrpll_configure_for_rate(struct wrpll_cfg * c,u32 target_rate,unsigned long parent_rate)2257b9487a9SPaul Walmsley int wrpll_configure_for_rate(struct wrpll_cfg *c, u32 target_rate,
2267b9487a9SPaul Walmsley unsigned long parent_rate)
2277b9487a9SPaul Walmsley {
2287b9487a9SPaul Walmsley unsigned long ratio;
2297b9487a9SPaul Walmsley u64 target_vco_rate, delta, best_delta, f_pre_div, vco, vco_pre;
2307b9487a9SPaul Walmsley u32 best_f, f, post_divr_freq;
2317b9487a9SPaul Walmsley u8 fbdiv, divq, best_r, r;
2327b9487a9SPaul Walmsley int range;
2337b9487a9SPaul Walmsley
2347b9487a9SPaul Walmsley if (c->flags == 0) {
2357b9487a9SPaul Walmsley WARN(1, "%s called with uninitialized PLL config", __func__);
2367b9487a9SPaul Walmsley return -EINVAL;
2377b9487a9SPaul Walmsley }
2387b9487a9SPaul Walmsley
2397b9487a9SPaul Walmsley /* Initialize rounding data if it hasn't been initialized already */
2407b9487a9SPaul Walmsley if (parent_rate != c->parent_rate) {
2417b9487a9SPaul Walmsley if (__wrpll_update_parent_rate(c, parent_rate)) {
2427b9487a9SPaul Walmsley pr_err("%s: PLL input rate is out of range\n",
2437b9487a9SPaul Walmsley __func__);
2447b9487a9SPaul Walmsley return -ERANGE;
2457b9487a9SPaul Walmsley }
2467b9487a9SPaul Walmsley }
2477b9487a9SPaul Walmsley
2487b9487a9SPaul Walmsley c->flags &= ~WRPLL_FLAGS_RESET_MASK;
2497b9487a9SPaul Walmsley
2507b9487a9SPaul Walmsley /* Put the PLL into bypass if the user requests the parent clock rate */
2517b9487a9SPaul Walmsley if (target_rate == parent_rate) {
2527b9487a9SPaul Walmsley c->flags |= WRPLL_FLAGS_BYPASS_MASK;
2537b9487a9SPaul Walmsley return 0;
2547b9487a9SPaul Walmsley }
2557b9487a9SPaul Walmsley
2567b9487a9SPaul Walmsley c->flags &= ~WRPLL_FLAGS_BYPASS_MASK;
2577b9487a9SPaul Walmsley
2587b9487a9SPaul Walmsley /* Calculate the Q shift and target VCO rate */
2597b9487a9SPaul Walmsley divq = __wrpll_calc_divq(target_rate, &target_vco_rate);
2607b9487a9SPaul Walmsley if (!divq)
2617b9487a9SPaul Walmsley return -1;
2627b9487a9SPaul Walmsley c->divq = divq;
2637b9487a9SPaul Walmsley
2647b9487a9SPaul Walmsley /* Precalculate the pre-Q divider target ratio */
2657b9487a9SPaul Walmsley ratio = div64_u64((target_vco_rate << ROUND_SHIFT), parent_rate);
2667b9487a9SPaul Walmsley
2677b9487a9SPaul Walmsley fbdiv = __wrpll_calc_fbdiv(c);
2687b9487a9SPaul Walmsley best_r = 0;
2697b9487a9SPaul Walmsley best_f = 0;
2707b9487a9SPaul Walmsley best_delta = MAX_VCO_FREQ;
2717b9487a9SPaul Walmsley
2727b9487a9SPaul Walmsley /*
2737b9487a9SPaul Walmsley * Consider all values for R which land within
2747b9487a9SPaul Walmsley * [MIN_POST_DIVR_FREQ, MAX_POST_DIVR_FREQ]; prefer smaller R
2757b9487a9SPaul Walmsley */
2767b9487a9SPaul Walmsley for (r = c->init_r; r <= c->max_r; ++r) {
2777b9487a9SPaul Walmsley f_pre_div = ratio * r;
2787b9487a9SPaul Walmsley f = (f_pre_div + (1 << ROUND_SHIFT)) >> ROUND_SHIFT;
2797b9487a9SPaul Walmsley f >>= (fbdiv - 1);
2807b9487a9SPaul Walmsley
2817b9487a9SPaul Walmsley post_divr_freq = div_u64(parent_rate, r);
2827b9487a9SPaul Walmsley vco_pre = fbdiv * post_divr_freq;
2837b9487a9SPaul Walmsley vco = vco_pre * f;
2847b9487a9SPaul Walmsley
2857b9487a9SPaul Walmsley /* Ensure rounding didn't take us out of range */
2867b9487a9SPaul Walmsley if (vco > target_vco_rate) {
2877b9487a9SPaul Walmsley --f;
2887b9487a9SPaul Walmsley vco = vco_pre * f;
2897b9487a9SPaul Walmsley } else if (vco < MIN_VCO_FREQ) {
2907b9487a9SPaul Walmsley ++f;
2917b9487a9SPaul Walmsley vco = vco_pre * f;
2927b9487a9SPaul Walmsley }
2937b9487a9SPaul Walmsley
294*b8e33f0aSBo Gan delta = abs(target_vco_rate - vco);
2957b9487a9SPaul Walmsley if (delta < best_delta) {
2967b9487a9SPaul Walmsley best_delta = delta;
2977b9487a9SPaul Walmsley best_r = r;
2987b9487a9SPaul Walmsley best_f = f;
2997b9487a9SPaul Walmsley }
3007b9487a9SPaul Walmsley }
3017b9487a9SPaul Walmsley
3027b9487a9SPaul Walmsley c->divr = best_r - 1;
3037b9487a9SPaul Walmsley c->divf = best_f - 1;
3047b9487a9SPaul Walmsley
3057b9487a9SPaul Walmsley post_divr_freq = div_u64(parent_rate, best_r);
3067b9487a9SPaul Walmsley
3077b9487a9SPaul Walmsley /* Pick the best PLL jitter filter */
3087b9487a9SPaul Walmsley range = __wrpll_calc_filter_range(post_divr_freq);
3097b9487a9SPaul Walmsley if (range < 0)
3107b9487a9SPaul Walmsley return range;
3117b9487a9SPaul Walmsley c->range = range;
3127b9487a9SPaul Walmsley
3137b9487a9SPaul Walmsley return 0;
3147b9487a9SPaul Walmsley }
3157b9487a9SPaul Walmsley
3167b9487a9SPaul Walmsley /**
3177b9487a9SPaul Walmsley * wrpll_calc_output_rate() - calculate the PLL's target output rate
3187b9487a9SPaul Walmsley * @c: ptr to a struct wrpll_cfg record to read from
3197b9487a9SPaul Walmsley * @parent_rate: PLL refclk rate
3207b9487a9SPaul Walmsley *
3217b9487a9SPaul Walmsley * Given a pointer to the PLL's current input configuration @c and the
3227b9487a9SPaul Walmsley * PLL's input reference clock rate @parent_rate (before the R
3237b9487a9SPaul Walmsley * pre-divider), calculate the PLL's output clock rate (after the Q
3247b9487a9SPaul Walmsley * post-divider).
3257b9487a9SPaul Walmsley *
3267b9487a9SPaul Walmsley * Context: Any context. Caller must protect the memory pointed to by @c
3277b9487a9SPaul Walmsley * from simultaneous modification.
3287b9487a9SPaul Walmsley *
3297b9487a9SPaul Walmsley * Return: the PLL's output clock rate, in Hz. The return value from
3307b9487a9SPaul Walmsley * this function is intended to be convenient to pass directly
3317b9487a9SPaul Walmsley * to the Linux clock framework; thus there is no explicit
3327b9487a9SPaul Walmsley * error return value.
3337b9487a9SPaul Walmsley */
wrpll_calc_output_rate(const struct wrpll_cfg * c,unsigned long parent_rate)3347b9487a9SPaul Walmsley unsigned long wrpll_calc_output_rate(const struct wrpll_cfg *c,
3357b9487a9SPaul Walmsley unsigned long parent_rate)
3367b9487a9SPaul Walmsley {
3377b9487a9SPaul Walmsley u8 fbdiv;
3387b9487a9SPaul Walmsley u64 n;
3397b9487a9SPaul Walmsley
3407b9487a9SPaul Walmsley if (c->flags & WRPLL_FLAGS_EXT_FEEDBACK_MASK) {
3417b9487a9SPaul Walmsley WARN(1, "external feedback mode not yet supported");
3427b9487a9SPaul Walmsley return ULONG_MAX;
3437b9487a9SPaul Walmsley }
3447b9487a9SPaul Walmsley
3457b9487a9SPaul Walmsley fbdiv = __wrpll_calc_fbdiv(c);
3467b9487a9SPaul Walmsley n = parent_rate * fbdiv * (c->divf + 1);
3477b9487a9SPaul Walmsley n = div_u64(n, c->divr + 1);
3487b9487a9SPaul Walmsley n >>= c->divq;
3497b9487a9SPaul Walmsley
3507b9487a9SPaul Walmsley return n;
3517b9487a9SPaul Walmsley }
3527b9487a9SPaul Walmsley
3537b9487a9SPaul Walmsley /**
3547b9487a9SPaul Walmsley * wrpll_calc_max_lock_us() - return the time for the PLL to lock
3557b9487a9SPaul Walmsley * @c: ptr to a struct wrpll_cfg record to read from
3567b9487a9SPaul Walmsley *
3577b9487a9SPaul Walmsley * Return the minimum amount of time (in microseconds) that the caller
3587b9487a9SPaul Walmsley * must wait after reprogramming the PLL to ensure that it is locked
3597b9487a9SPaul Walmsley * to the input frequency and stable. This is likely to depend on the DIVR
3607b9487a9SPaul Walmsley * value; this is under discussion with the manufacturer.
3617b9487a9SPaul Walmsley *
3627b9487a9SPaul Walmsley * Return: the minimum amount of time the caller must wait for the PLL
3637b9487a9SPaul Walmsley * to lock (in microseconds)
3647b9487a9SPaul Walmsley */
wrpll_calc_max_lock_us(const struct wrpll_cfg * c)3657b9487a9SPaul Walmsley unsigned int wrpll_calc_max_lock_us(const struct wrpll_cfg *c)
3667b9487a9SPaul Walmsley {
3677b9487a9SPaul Walmsley return MAX_LOCK_US;
3687b9487a9SPaul Walmsley }
369