All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de, Leo Liang <ycliang@andestech.com>
Cc: Bin Meng <bmeng.cn@gmail.com>,
	Damien Le Moal <Damien.LeMoal@wdc.com>,
	Lukasz Majewski <lukma@denx.de>,
	Sean Anderson <seanga2@gmail.com>, Simon Glass <sjg@chromium.org>
Subject: [PATCH v2 4/4] clk: k210: Try harder to get the best config
Date: Sat, 11 Sep 2021 13:20:03 -0400	[thread overview]
Message-ID: <20210911172003.899301-4-seanga2@gmail.com> (raw)
In-Reply-To: <20210911172003.899301-1-seanga2@gmail.com>

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(+)

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;
 }
-- 
2.33.0


  parent reply	other threads:[~2021-09-11 17:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 17:20 [PATCH v2 1/4] clk: k210: Fix checking if ulongs are less than 0 Sean Anderson
2021-09-11 17:20 ` [PATCH v2 2/4] k210: clk: Refactor out_of_spec tests Sean Anderson
2021-09-14  8:45   ` Leo Liang
2021-09-11 17:20 ` [PATCH v2 3/4] test: dm: k210: Reduce duplication in test cases Sean Anderson
2021-09-14  8:48   ` Leo Liang
2021-09-11 17:20 ` Sean Anderson [this message]
2021-09-30  4:08   ` [PATCH v2 4/4] clk: k210: Try harder to get the best config Simon Glass
2021-09-14  8:39 ` [PATCH v2 1/4] clk: k210: Fix checking if ulongs are less than 0 Leo Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210911172003.899301-4-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=bmeng.cn@gmail.com \
    --cc=lukma@denx.de \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=ycliang@andestech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.