[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250616103527.509999-1-j-choudhary@ti.com>
Date: Mon, 16 Jun 2025 16:05:27 +0530
From: Jayesh Choudhary <j-choudhary@...com>
To: <mturquette@...libre.com>, <sboyd@...nel.org>, <linux@...linux.org.uk>,
<linux-clk@...r.kernel.org>, <devarsht@...com>
CC: <linux-kernel@...r.kernel.org>, <tomi.valkeinen@...asonboard.com>,
<j-choudhary@...com>
Subject: [PATCH] clk: Add clk_determine_rate function call
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@...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
Powered by blists - more mailing lists