clk: Introduce clk_hw_init_rate_request()
authorMaxime Ripard <maxime@cerno.tech>
Tue, 16 Aug 2022 11:25:21 +0000 (13:25 +0200)
committerStephen Boyd <sboyd@kernel.org>
Thu, 15 Sep 2022 16:31:40 +0000 (09:31 -0700)
clk-divider instantiates clk_rate_request internally for its round_rate
implementations to share the code with its determine_rate
implementations.

However, it's missing a few fields (min_rate, max_rate) that would be
initialized properly if it was using clk_core_init_rate_req().

Let's create the clk_hw_init_rate_request() function for clock providers
to be able to share the code to instation clk_rate_requests with the
framework. This will also be useful for some tests introduced in later
patches.

Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> # imx8mp
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> # exynos4210, meson g12b
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220816112530.1837489-17-maxime@cerno.tech
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clk-divider.c
drivers/clk/clk.c
include/linux/clk-provider.h

index f6b2bf5584867e115c0fb39185b41d0607087b22..a2c2b5203b0a95cf1cf651b1fb4e2c24d230d831 100644 (file)
@@ -386,13 +386,13 @@ long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
                               const struct clk_div_table *table,
                               u8 width, unsigned long flags)
 {
-       struct clk_rate_request req = {
-               .rate = rate,
-               .best_parent_rate = *prate,
-               .best_parent_hw = parent,
-       };
+       struct clk_rate_request req;
        int ret;
 
+       clk_hw_init_rate_request(hw, &req, rate);
+       req.best_parent_rate = *prate;
+       req.best_parent_hw = parent;
+
        ret = divider_determine_rate(hw, &req, table, width, flags);
        if (ret)
                return ret;
@@ -408,13 +408,13 @@ long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
                                  const struct clk_div_table *table, u8 width,
                                  unsigned long flags, unsigned int val)
 {
-       struct clk_rate_request req = {
-               .rate = rate,
-               .best_parent_rate = *prate,
-               .best_parent_hw = parent,
-       };
+       struct clk_rate_request req;
        int ret;
 
+       clk_hw_init_rate_request(hw, &req, rate);
+       req.best_parent_rate = *prate;
+       req.best_parent_hw = parent;
+
        ret = divider_ro_determine_rate(hw, &req, table, width, flags, val);
        if (ret)
                return ret;
index 553e1e9eb3001ce8a8c6549db6a6dc4734fcfd97..96b372ff23c218c92107b913014a7b7da40142db 100644 (file)
@@ -1400,6 +1400,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 a clk_rate_request structure to submit to
+ * __clk_determine_rate() or similar functions.
+ */
+void clk_hw_init_rate_request(const struct clk_hw *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;
index 9a14cfa0d2011c0669490eefb35281c5a870330e..d857717aa386043b56ad93d57660a9e530004f33 100644 (file)
@@ -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(const struct clk_hw *hw,
+                             struct clk_rate_request *req,
+                             unsigned long rate);
+
 /**
  * struct clk_duty - Struture encoding the duty cycle ratio of a clock
  *