Message ID | 20210911172003.899301-4-seanga2@gmail.com |
---|---|
State | Accepted |
Commit | 425c08faa8a2d6af5d9c1d83a97572f6401137bf |
Delegated to: | Andes |
Headers | show |
Series | [v2,1/4] clk: k210: Fix checking if ulongs are less than 0 | expand |
On Sat, 11 Sept 2021 at 11:20, Sean Anderson <seanga2@gmail.com> wrote: > > In some cases, the best config cannot be used because the VCO would be > out-of-spec. In these cases, we may need to try a worse combination of r/od > in order to find the best representable config. This also adds a few test > cases to catch this and other (possible) unlikely errors. > > Signed-off-by: Sean Anderson <seanga2@gmail.com> > --- > > (no changes since v1) > > drivers/clk/clk_kendryte.c | 24 ++++++++++++++++++++++++ > test/dm/k210_pll.c | 4 ++++ > 2 files changed, 28 insertions(+) Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c index 69691c4a04..97efda5b6f 100644 --- a/drivers/clk/clk_kendryte.c +++ b/drivers/clk/clk_kendryte.c @@ -816,6 +816,30 @@ again: i--; } + /* + * Try looking back to see if there is a worse ratio + * that we could try anyway + */ + while (i > 0) { + i--; + new_r = UNPACK_R(factors[i]); + new_od = UNPACK_OD(factors[i]); + /* + * Don't loop over factors for the same product + * to avoid getting stuck because of the above + * clause + */ + if (r * od != new_r * new_od) { + if (new_r * new_od > last_r * last_od) { + r = new_r; + od = new_od; + swapped = false; + goto again; + } + break; + } + } + /* We ran out of things to try */ continue; } diff --git a/test/dm/k210_pll.c b/test/dm/k210_pll.c index 5574ac96fa..f55379f336 100644 --- a/test/dm/k210_pll.c +++ b/test/dm/k210_pll.c @@ -84,6 +84,10 @@ static int dm_test_k210_pll(struct unit_test_state *uts) compare(400000000, 26000000); compare(27000000, 26000000); compare(26000000, 27000000); + compare(13300000 * 64, 13300000); + compare(21250000, 21250000 * 70); + compare(21250000, 1750000000); + compare(1750000000, 1750000000); return 0; }
In some cases, the best config cannot be used because the VCO would be out-of-spec. In these cases, we may need to try a worse combination of r/od in order to find the best representable config. This also adds a few test cases to catch this and other (possible) unlikely errors. Signed-off-by: Sean Anderson <seanga2@gmail.com> --- (no changes since v1) drivers/clk/clk_kendryte.c | 24 ++++++++++++++++++++++++ test/dm/k210_pll.c | 4 ++++ 2 files changed, 28 insertions(+)