[PATCH 14/22] clk: Introduce clk_hw_init_rate_request()

Maxime Ripard
2022-04-08T09:14:11Z

Some drivers (at91, imx, qcom) use __clk_determine_rate directly, and
thus will need to initialise a clk_rate_request structure.

However, drivers don't have access to the function that the core uses to
initialize that structure which could prove to be useful.

Let's create a function for clock providers that will initialize a
clk_rate_request for a given clk_hw pointer and a rate.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
drivers/clk/clk.c | 20 ++++++++++++++++++++
include/linux/clk-provider.h | 6 ++++++
2 files changed, 26 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 399080456e45..83dd5f1df0b9 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -1396,6 +1396,26 @@ static void clk_core_init_rate_req(struct clk_core * const core,
}
}

+/**
+ * clk_hw_init_rate_request - Initializes a clk_rate_request
+ * @hw: the clk for which we want to submit a rate request
+ * @req: the clk_rate_request structure we want to initialise
+ * @rate: the rate which is to be requested
+ *
+ * Initializes and fills a clk_rate_request structure to submit to
+ * __clk_determine_rate or similar functions.
+ */
+void clk_hw_init_rate_request(struct clk_hw * const hw,
+ struct clk_rate_request *req,
+ unsigned long rate)
+{
+ if (WARN_ON(!hw || !req))
+ return;
+
+ clk_core_init_rate_req(hw->core, req, rate);
+}
+EXPORT_SYMBOL_GPL(clk_hw_init_rate_request);
+
static bool clk_core_can_round(struct clk_core * const core)
{
return core->ops->determine_rate || core->ops->round_rate;
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index c10dc4c659e2..39e4ed301ec5 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -42,6 +42,8 @@ struct dentry;
* struct clk_rate_request - Structure encoding the clk constraints that
* a clock user might require.
*
+ * Should be initialized by calling clk_hw_init_rate_request().
+ *
* @rate: Requested clock rate. This field will be adjusted by
* clock drivers according to hardware capabilities.
* @min_rate: Minimum rate imposed by clk users.
@@ -60,6 +62,10 @@ struct clk_rate_request {
struct clk_hw *best_parent_hw;
};

+void clk_hw_init_rate_request(struct clk_hw * const hw,
+ struct clk_rate_request *req,
+ unsigned long rate);
+
/**
* struct clk_duty - Struture encoding the duty cycle ratio of a clock
*
--
2.35.1