From: Frank Oltmanns <frank@oltmanns.dev>
To: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: Frank Oltmanns <frank@oltmanns.dev>,
"A.s. Dong" <aisheng.dong@nxp.com>,
Abel Vesa <abelvesa@kernel.org>,
Fabio Estevam <festevam@gmail.com>,
linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
linux-kernel@vger.kernel.org, NXP Linux Team <linux-imx@nxp.com>,
Peng Fan <peng.fan@nxp.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>,
Shawn Guo <shawnguo@kernel.org>
Subject: [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation
Date: Tue, 13 Jun 2023 10:36:26 +0200 [thread overview]
Message-ID: <20230613083626.227476-3-frank@oltmanns.dev> (raw)
In-Reply-To: <20230613083626.227476-1-frank@oltmanns.dev>
In light of the recent discovery that the fractional divisor
approximation does not utilize the full available range for clocks that
are flagged CLK_FRAC_DIVIDER_ZERO_BASED, implement tests for the edge
cases of this clock type.
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
Link: https://lore.kernel.org/lkml/20230529133433.56215-1-frank@oltmanns.dev
---
drivers/clk/clk_test.c | 69 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 68 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index f9a5c2964c65..b247ba841cbd 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -8,6 +8,9 @@
/* Needed for clk_hw_get_clk() */
#include "clk.h"
+/* Needed for clk_fractional_divider_general_approximation */
+#include "clk-fractional-divider.h"
+
#include <kunit/test.h>
#define DUMMY_CLOCK_INIT_RATE (42 * 1000 * 1000)
@@ -2394,6 +2397,69 @@ static struct kunit_suite clk_mux_notifier_test_suite = {
.test_cases = clk_mux_notifier_test_cases,
};
+
+/*
+ * Test that clk_fractional_divider_general_approximation will work with the
+ * highest available numerator and denominator.
+ */
+static void clk_fd_test_round_rate_max_mn(struct kunit *test)
+{
+ struct clk_fractional_divider *fd;
+ struct clk_hw *hw;
+ unsigned long rate, parent_rate, m, n;
+
+ fd = kunit_kzalloc(test, sizeof(*fd), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, fd);
+
+ fd->mwidth = 3;
+ fd->nwidth = 3;
+
+ hw = &fd->hw;
+
+ rate = DUMMY_CLOCK_RATE_1;
+
+ // Highest denominator, no flags
+ parent_rate = 10 * DUMMY_CLOCK_RATE_1;
+ clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+ KUNIT_EXPECT_EQ(test, m, 1);
+ KUNIT_EXPECT_EQ(test, n, 7);
+
+ // Highest numerator, no flags
+ parent_rate = DUMMY_CLOCK_RATE_1 / 10;
+ clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+ KUNIT_EXPECT_EQ(test, m, 7);
+ KUNIT_EXPECT_EQ(test, n, 1);
+
+ // Highest denominator, zero based
+ parent_rate = 10 * DUMMY_CLOCK_RATE_1;
+ fd->flags = CLK_FRAC_DIVIDER_ZERO_BASED;
+ clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+ KUNIT_EXPECT_EQ(test, m, 1);
+ KUNIT_EXPECT_EQ(test, n, 8);
+
+ // Highest numerator, zero based
+ parent_rate = DUMMY_CLOCK_RATE_1 / 10;
+ clk_fractional_divider_general_approximation(hw, rate, &parent_rate, &m, &n);
+ KUNIT_EXPECT_EQ(test, m, 8);
+ KUNIT_EXPECT_EQ(test, n, 1);
+}
+
+static struct kunit_case clk_fd_test_cases[] = {
+ KUNIT_CASE(clk_fd_test_round_rate_max_mn),
+ {}
+};
+
+/*
+ * Test suite for a fractional divider clock.
+ *
+ * These tests exercise the fractional divider API: clk_recalc_rate,
+ * clk_set_rate(), clk_round_rate().
+ */
+static struct kunit_suite clk_fd_test_suite = {
+ .name = "clk-fd-test",
+ .test_cases = clk_fd_test_cases,
+};
+
kunit_test_suites(
&clk_leaf_mux_set_rate_parent_test_suite,
&clk_test_suite,
@@ -2406,6 +2472,7 @@ kunit_test_suites(
&clk_range_maximize_test_suite,
&clk_range_minimize_test_suite,
&clk_single_parent_mux_test_suite,
- &clk_uncached_test_suite
+ &clk_uncached_test_suite,
+ &clk_fd_test_suite
);
MODULE_LICENSE("GPL v2");
--
2.41.0
next prev parent reply other threads:[~2023-06-13 8:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 8:36 [PATCH v2 0/2] clk: fractional-divider: Improve approximation when zero based Frank Oltmanns
2023-06-13 8:36 ` [PATCH v2 1/2] " Frank Oltmanns
2023-06-13 8:36 ` Frank Oltmanns [this message]
2023-06-13 8:49 ` [PATCH v2 2/2] clk: tests: Add tests for fractional divisor approximation Frank Oltmanns
2023-06-13 12:48 ` kernel test robot
2023-06-14 8:19 ` Frank Oltmanns
[not found] ` <aa23f41c0e313e97122ac384d66e2325.sboyd@kernel.org>
2023-06-15 5:16 ` Frank Oltmanns
[not found] ` <dab61757f0c33453ad19857350117c62.sboyd@kernel.org>
2023-06-17 16:47 ` Frank Oltmanns
[not found] ` <83f9ee3ce26e4d4ba7c395aab316cae6.sboyd@kernel.org>
2023-06-14 6:51 ` Frank Oltmanns
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=20230613083626.227476-3-frank@oltmanns.dev \
--to=frank@oltmanns.dev \
--cc=abelvesa@kernel.org \
--cc=aisheng.dong@nxp.com \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=peng.fan@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).