linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Masney <bmasney@redhat.com>
To: Michael Turquette <mturquette@baylibre.com>,
	 Stephen Boyd <sboyd@kernel.org>,
	Maxime Ripard <mripard@kernel.org>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Brian Masney <bmasney@redhat.com>
Subject: [PATCH v3 3/9] clk: test: introduce clk_dummy_div for a mock divider
Date: Tue, 12 Aug 2025 10:40:33 -0400	[thread overview]
Message-ID: <20250812-clk-tests-docs-v3-3-054aed58dcd3@redhat.com> (raw)
In-Reply-To: <20250812-clk-tests-docs-v3-0-054aed58dcd3@redhat.com>

This is used to mock up a divider in the clk kunit tests.

Signed-off-by: Brian Masney <bmasney@redhat.com>
---
 drivers/clk/clk_test.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c
index fafa736ca32144a2feae75a8d641abca3162d42d..61668fcd7203c4cef9f22b8c0c5bb5a50d331f53 100644
--- a/drivers/clk/clk_test.c
+++ b/drivers/clk/clk_test.c
@@ -137,6 +137,48 @@ static const struct clk_ops clk_dummy_single_parent_ops = {
 	.get_parent = clk_dummy_single_get_parent,
 };
 
+// 4 ought to be enough for anybody
+#define CLK_DUMMY_DIV_WIDTH 4
+#define CLK_DUMMY_DIV_FLAGS (CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ROUND_CLOSEST)
+
+struct clk_dummy_div {
+	struct clk_hw hw;
+	unsigned int div;
+};
+
+static unsigned long clk_dummy_div_recalc_rate(struct clk_hw *hw,
+					       unsigned long parent_rate)
+{
+	struct clk_dummy_div *div = container_of(hw, struct clk_dummy_div, hw);
+
+	return divider_recalc_rate(hw, parent_rate, div->div, NULL,
+				   CLK_DUMMY_DIV_FLAGS, CLK_DUMMY_DIV_WIDTH);
+}
+
+static long clk_dummy_div_round_rate(struct clk_hw *hw, unsigned long rate,
+				     unsigned long *parent_rate)
+{
+	return divider_round_rate(hw, rate, parent_rate, NULL,
+				  CLK_DUMMY_DIV_WIDTH, CLK_DUMMY_DIV_FLAGS);
+}
+
+static int clk_dummy_div_set_rate(struct clk_hw *hw, unsigned long rate,
+				  unsigned long parent_rate)
+{
+	struct clk_dummy_div *div = container_of(hw, struct clk_dummy_div, hw);
+
+	div->div = divider_get_val(rate, parent_rate, NULL, CLK_DUMMY_DIV_WIDTH,
+				   CLK_DUMMY_DIV_FLAGS);
+
+	return 0;
+}
+
+static const struct clk_ops clk_dummy_div_ops = {
+	.recalc_rate = clk_dummy_div_recalc_rate,
+	.round_rate = clk_dummy_div_round_rate,
+	.set_rate = clk_dummy_div_set_rate,
+};
+
 struct clk_multiple_parent_ctx {
 	struct clk_dummy_context parents_ctx[2];
 	struct clk_hw hw;

-- 
2.50.1


  parent reply	other threads:[~2025-08-12 14:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-12 14:40 [PATCH v3 0/9] clk: add kunit tests and some documentation Brian Masney
2025-08-12 14:40 ` [PATCH v3 1/9] clk: add kernel docs for struct clk_core Brian Masney
2025-08-19  9:27   ` Maxime Ripard
2025-08-12 14:40 ` [PATCH v3 2/9] clk: test: introduce clk_dummy_rate_mhz() Brian Masney
2025-08-19 14:00   ` Maxime Ripard
2025-08-12 14:40 ` Brian Masney [this message]
2025-08-18 20:01   ` [PATCH v3 3/9] clk: test: introduce clk_dummy_div for a mock divider Brian Masney
2025-08-12 14:40 ` [PATCH v3 4/9] clk: test: introduce test suite for sibling rate changes on a divider Brian Masney
2025-08-12 14:40 ` [PATCH v3 5/9] clk: test: introduce clk_dummy_gate for a mock gate Brian Masney
2025-08-12 14:40 ` [PATCH v3 6/9] clk: test: introduce test suite for sibling rate changes on a gate Brian Masney
2025-08-12 14:40 ` [PATCH v3 7/9] clk: test: introduce helper to create a mock mux Brian Masney
2025-08-12 14:40 ` [PATCH v3 8/9] clk: test: introduce test variation for sibling rate changes on a mux Brian Masney
2025-08-12 14:40 ` [PATCH v3 9/9] clk: test: introduce test variation for sibling rate changes on a gate/mux Brian Masney

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=20250812-clk-tests-docs-v3-3-054aed58dcd3@redhat.com \
    --to=bmasney@redhat.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mripard@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@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).