From: Stephen Boyd <[email protected]>

We'll need to turn the code in clk_mux_determine_rate_flags() to deal
with CLK_SET_RATE_NO_REPARENT into a helper clock drivers will be able
to use if they don't want to allow reparenting.

Cc: Abel Vesa <[email protected]>
Cc: Alessandro Zummo <[email protected]>
Cc: Alexandre Belloni <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: "Andreas Färber" <[email protected]>
Cc: AngeloGioacchino Del Regno <[email protected]>
Cc: Baolin Wang <[email protected]>
Cc: Charles Keepax <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>
Cc: Chunyan Zhang <[email protected]>
Cc: Claudiu Beznea <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: David Airlie <[email protected]>
Cc: David Lechner <[email protected]>
Cc: Dinh Nguyen <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Jonathan Hunter <[email protected]>
Cc: Kishon Vijay Abraham I <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Linus Walleij <[email protected]>
Cc: Luca Ceresoli <[email protected]>
Cc: Manivannan Sadhasivam <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Markus Schneider-Pargmann <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Mikko Perttunen <[email protected]>
Cc: Miles Chen <[email protected]>
Cc: Nicolas Ferre <[email protected]>
Cc: Orson Zhai <[email protected]>
Cc: Paul Cercueil <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Peter De Schrijver <[email protected]>
Cc: Prashant Gaikwad <[email protected]>
Cc: Richard Fitzgerald <[email protected]>
Cc: Samuel Holland <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Sekhar Nori <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: Ulf Hansson <[email protected]>
Cc: Vinod Koul <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: NXP Linux Team <[email protected]>
Cc: [email protected]
Cc: Pengutronix Kernel Team <[email protected]>
Signed-off-by: Stephen Boyd <[email protected]>
Signed-off-by: Maxime Ripard <[email protected]>
---
 drivers/clk/clk.c | 75 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 43 insertions(+), 32 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index e495dd7a1eae..f57f821a5e5a 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -594,6 +594,46 @@ clk_core_forward_rate_req(struct clk_core *core,
                req->max_rate = old_req->max_rate;
 }
 
+static int
+clk_core_determine_rate_no_reparent(struct clk_hw *hw,
+                                   struct clk_rate_request *req)
+{
+       struct clk_core *core = hw->core;
+       struct clk_core *parent = core->parent;
+       unsigned long best;
+       int ret;
+
+       if (core->flags & CLK_SET_RATE_PARENT) {
+               struct clk_rate_request parent_req;
+
+               if (!parent) {
+                       req->rate = 0;
+                       return 0;
+               }
+
+               clk_core_forward_rate_req(core, req, parent, &parent_req,
+                                         req->rate);
+
+               trace_clk_rate_request_start(&parent_req);
+
+               ret = clk_core_round_rate_nolock(parent, &parent_req);
+               if (ret)
+                       return ret;
+
+               trace_clk_rate_request_done(&parent_req);
+
+               best = parent_req.rate;
+       } else if (parent) {
+               best = clk_core_get_rate_nolock(parent);
+       } else {
+               best = clk_core_get_rate_nolock(core);
+       }
+
+       req->rate = best;
+
+       return 0;
+}
+
 int clk_mux_determine_rate_flags(struct clk_hw *hw,
                                 struct clk_rate_request *req,
                                 unsigned long flags)
@@ -603,35 +643,8 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw,
        unsigned long best = 0;
 
        /* if NO_REPARENT flag set, pass through to current parent */
-       if (core->flags & CLK_SET_RATE_NO_REPARENT) {
-               parent = core->parent;
-               if (core->flags & CLK_SET_RATE_PARENT) {
-                       struct clk_rate_request parent_req;
-
-                       if (!parent) {
-                               req->rate = 0;
-                               return 0;
-                       }
-
-                       clk_core_forward_rate_req(core, req, parent, 
&parent_req, req->rate);
-
-                       trace_clk_rate_request_start(&parent_req);
-
-                       ret = clk_core_round_rate_nolock(parent, &parent_req);
-                       if (ret)
-                               return ret;
-
-                       trace_clk_rate_request_done(&parent_req);
-
-                       best = parent_req.rate;
-               } else if (parent) {
-                       best = clk_core_get_rate_nolock(parent);
-               } else {
-                       best = clk_core_get_rate_nolock(core);
-               }
-
-               goto out;
-       }
+       if (core->flags & CLK_SET_RATE_NO_REPARENT)
+               return clk_core_determine_rate_no_reparent(hw, req);
 
        /* find the parent that can provide the fastest rate <= rate */
        num_parents = core->num_parents;
@@ -670,9 +683,7 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw,
        if (!best_parent)
                return -EINVAL;
 
-out:
-       if (best_parent)
-               req->best_parent_hw = best_parent->hw;
+       req->best_parent_hw = best_parent->hw;
        req->best_parent_rate = best;
        req->rate = best;
 

-- 
2.40.0

Reply via email to