WSL2-Linux-Kernel/drivers/clk/zynqmp
Quanyang Wang 30eaf02149 clk: zynqmp: pll: rectify rate rounding in zynqmp_pll_round_rate
The function zynqmp_pll_round_rate is used to find a most appropriate
PLL frequency which the hardware can generate according to the desired
frequency. For example, if the desired frequency is 297MHz, considering
the limited range from PS_PLL_VCO_MIN (1.5GHz) to PS_PLL_VCO_MAX (3.0GHz)
of PLL, zynqmp_pll_round_rate should return 1.872GHz (297MHz * 5).

There are two problems with the current code of zynqmp_pll_round_rate:

1) When the rate is below PS_PLL_VCO_MIN, it can't find a correct rate
when the parameter "rate" is an integer multiple of *prate, in other words,
if "f" is zero, zynqmp_pll_round_rate won't return a valid frequency which
is from PS_PLL_VCO_MIN to PS_PLL_VCO_MAX. For example, *prate is 33MHz
and the rate is 660MHz, zynqmp_pll_round_rate will not boost up rate and
just return 660MHz, and this will cause clk_calc_new_rates failure since
zynqmp_pll_round_rate returns an invalid rate out of its boundaries.

2) Even if the rate is higher than PS_PLL_VCO_MIN, there is still a risk
that zynqmp_pll_round_rate returns an invalid rate because the function
DIV_ROUND_CLOSEST makes some loss in the fractional part. If the parent
clock *prate is 33333333Hz and we want to set the PLL rate to 1.5GHz,
this function will return 1499999985Hz by using the formula below:
    value = *prate * DIV_ROUND_CLOSEST(rate, *prate)).
This value is also invalid since it's slightly smaller than PS_PLL_VCO_MIN.
because DIV_ROUND_CLOSEST makes some loss in the fractional part.

Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com>
Link: https://lore.kernel.org/r/20220826142030.213805-1-quanyang.wang@windriver.com
Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2022-08-30 15:05:59 -07:00
..
Kconfig clk: zynqmp: Drop dependency on ARCH_ZYNQMP 2021-04-07 17:26:09 -07:00
Makefile drivers: clk: Add ZynqMP clock driver 2018-10-09 13:29:19 +02:00
clk-gate-zynqmp.c clk: zynqmp: replace warn_once with pr_debug for failed clock ops 2022-01-24 17:18:23 -08:00
clk-mux-zynqmp.c clk: zynqmp: replace warn_once with pr_debug for failed clock ops 2022-01-24 17:18:23 -08:00
clk-zynqmp.h clk: zynqmp: fix kernel doc 2021-08-28 21:19:02 -07:00
clkc.c clk: zynqmp: Check the return type zynqmp_pm_query_data 2022-08-22 17:01:05 -07:00
divider.c clk: zynqmp: Add a check for NULL pointer 2022-08-22 17:01:05 -07:00
pll.c clk: zynqmp: pll: rectify rate rounding in zynqmp_pll_round_rate 2022-08-30 15:05:59 -07:00