linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: Add clk_determine_rate function call
@ 2025-06-16 10:35 Jayesh Choudhary
  2025-06-17 20:03 ` Brian Masney
  2025-06-17 22:28 ` Russell King (Oracle)
  0 siblings, 2 replies; 5+ messages in thread
From: Jayesh Choudhary @ 2025-06-16 10:35 UTC (permalink / raw)
  To: mturquette, sboyd, linux, linux-clk, devarsht
  Cc: linux-kernel, tomi.valkeinen, j-choudhary

Add a function to determine if a particular rate can be set for a clock
with its argument being the clock and the desired rate so that it could
be exposed to other peripherals.
For example, the display controllers typically has to perform multiple
checks for supported display resolutions including those related to
clock rates. The controller has to check this way before it actually
enables the clock and has to do it multiple times (typically for each
mode), and therefore using the clk_set_rate when its not needed, does
not make sense.

The driver does have "__clk_determine_rate()" but this cannot be used
by other subsystems because of the function arguments used.
"clk_hw" is not accessible to other peripherals due to clk and clk_core
structure definition in driver instead of include file, so we cannot use
already exisiting "__clk_determine_rate()" in other drivers.

Signed-off-by: Jayesh Choudhary <j-choudhary@ti.com>
---
 drivers/clk/clk.c   | 22 ++++++++++++++++++++++
 include/linux/clk.h | 15 +++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 0565c87656cf..f72d638cc211 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2566,6 +2566,28 @@ static int clk_core_set_rate_nolock(struct clk_core *core,
 	return ret;
 }
 
+/**
+ * clk_determine_rate - determine if the rate for clk can be set or not
+ * @clk: the clk whose rate is being changed
+ * @rate: the new rate for clk
+ *
+ * Check if there is a best match frequency for the desired rate that
+ * can be set for clk.
+ * Returns 0 on success, -EERROR otherwise.
+ */
+int clk_determine_rate(struct clk *clk, unsigned long rate)
+{
+	struct clk_rate_request req;
+
+	if (!clk)
+		return 0;
+
+	clk_hw_init_rate_request(clk->core->hw, &req, rate);
+
+	return __clk_determine_rate(clk->core->hw, &req);
+}
+EXPORT_SYMBOL_GPL(clk_determine_rate);
+
 /**
  * clk_set_rate - specify a new rate for clk
  * @clk: the clk whose rate is being changed
diff --git a/include/linux/clk.h b/include/linux/clk.h
index b607482ca77e..fd81ba738e50 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -829,6 +829,16 @@ void devm_clk_put(struct device *dev, struct clk *clk);
  */
 long clk_round_rate(struct clk *clk, unsigned long rate);
 
+/**
+ * clk_determine_rate - determine if the clock rate for a clock source
+ * can be set or not
+ * @clk: clock source
+ * @rate: desired clock rate in Hz
+ *
+ * Returns success (0) or negative errno.
+ */
+int clk_determine_rate(struct clk *clk, unsigned long rate);
+
 /**
  * clk_set_rate - set the clock rate for a clock source
  * @clk: clock source
@@ -1078,6 +1088,11 @@ static inline unsigned long clk_get_rate(struct clk *clk)
 	return 0;
 }
 
+static inline int clk_determine_rate(struct clk *clk, unsigned long rate)
+{
+	return 0;
+}
+
 static inline int clk_set_rate(struct clk *clk, unsigned long rate)
 {
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-18  8:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 10:35 [PATCH] clk: Add clk_determine_rate function call Jayesh Choudhary
2025-06-17 20:03 ` Brian Masney
2025-06-18  8:10   ` Jayesh Choudhary
2025-06-17 22:28 ` Russell King (Oracle)
2025-06-18  8:07   ` Jayesh Choudhary

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).