aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2021-09-11 13:20:03 -0400
committerLeo Yu-Chi Liang <ycliang@andestech.com>2021-10-07 16:08:23 +0800
commit425c08faa8a2d6af5d9c1d83a97572f6401137bf (patch)
treec00a4d17c8b2458c20126929ee8e7f82f1d4c8e2 /drivers
parent6e23c9f0c1ebe9b93077b6901733cd01d3848208 (diff)
downloadu-boot-425c08faa8a2d6af5d9c1d83a97572f6401137bf.zip
u-boot-425c08faa8a2d6af5d9c1d83a97572f6401137bf.tar.gz
u-boot-425c08faa8a2d6af5d9c1d83a97572f6401137bf.tar.bz2
clk: k210: Try harder to get the best config
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> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/clk/clk_kendryte.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c
index 69691c4..97efda5 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;
}