clk: analogbits: Fix incorrect calculation of vco rate delta
authorBo Gan <ganboing@gmail.com>
Fri, 30 Aug 2024 06:16:39 +0000 (23:16 -0700)
committerStephen Boyd <sboyd@kernel.org>
Thu, 16 Jan 2025 21:43:49 +0000 (13:43 -0800)
In wrpll_configure_for_rate() we try to determine the best PLL
configuration for a target rate. However, in the loop where we try
values of R, we should compare the derived `vco` with `target_vco_rate`.
However, we were in fact comparing it with `target_rate`, which is
actually after Q shift. This is incorrect, and sometimes can result in
suboptimal clock rates. Fix it.

Fixes: 7b9487a9a5c4 ("clk: analogbits: add Wide-Range PLL library")
Signed-off-by: Bo Gan <ganboing@gmail.com>
Link: https://lore.kernel.org/r/20240830061639.2316-1-ganboing@gmail.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/analogbits/wrpll-cln28hpc.c

index 65d422a588e1f1af91f2d610c178f0f4fe5616af..9d178afc73bdd1f41f13888ed9584eb9d5a377ac 100644 (file)
@@ -292,7 +292,7 @@ int wrpll_configure_for_rate(struct wrpll_cfg *c, u32 target_rate,
                        vco = vco_pre * f;
                }
 
-               delta = abs(target_rate - vco);
+               delta = abs(target_vco_rate - vco);
                if (delta < best_delta) {
                        best_delta = delta;
                        best_r = r;