From: Stephen Boyd <sb...@kernel.org>

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 <abelv...@kernel.org>
Cc: Alessandro Zummo <a.zu...@towertech.it>
Cc: Alexandre Belloni <alexandre.bell...@bootlin.com>
Cc: Alexandre Torgue <alexandre.tor...@foss.st.com>
Cc: "Andreas Färber" <afaer...@suse.de>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delre...@collabora.com>
Cc: Baolin Wang <baolin.w...@linux.alibaba.com>
Cc: Charles Keepax <ckee...@opensource.cirrus.com>
Cc: Chen-Yu Tsai <w...@csie.org>
Cc: Chen-Yu Tsai <we...@chromium.org>
Cc: Chunyan Zhang <zhang.l...@gmail.com>
Cc: Claudiu Beznea <claudiu.bez...@microchip.com>
Cc: Daniel Vetter <dan...@ffwll.ch>
Cc: David Airlie <airl...@gmail.com>
Cc: David Lechner <da...@lechnology.com>
Cc: Dinh Nguyen <dingu...@kernel.org>
Cc: Fabio Estevam <feste...@gmail.com>
Cc: Geert Uytterhoeven <geert+rene...@glider.be>
Cc: Jaroslav Kysela <pe...@perex.cz>
Cc: Jernej Skrabec <jernej.skra...@gmail.com>
Cc: Jonathan Hunter <jonath...@nvidia.com>
Cc: Kishon Vijay Abraham I <kis...@kernel.org>
Cc: Liam Girdwood <lgirdw...@gmail.com>
Cc: Linus Walleij <linus.wall...@linaro.org>
Cc: Luca Ceresoli <luca.ceres...@bootlin.com>
Cc: Manivannan Sadhasivam <m...@kernel.org>
Cc: Mark Brown <broo...@kernel.org>
Cc: Markus Schneider-Pargmann <m...@baylibre.com>
Cc: Max Filippov <jcmvb...@gmail.com>
Cc: Maxime Coquelin <mcoquelin.st...@gmail.com>
Cc: Mikko Perttunen <mperttu...@nvidia.com>
Cc: Miles Chen <miles.c...@mediatek.com>
Cc: Nicolas Ferre <nicolas.fe...@microchip.com>
Cc: Orson Zhai <orsonz...@gmail.com>
Cc: Paul Cercueil <p...@crapouillou.net>
Cc: Peng Fan <peng....@nxp.com>
Cc: Peter De Schrijver <pdeschrij...@nvidia.com>
Cc: Prashant Gaikwad <pgaik...@nvidia.com>
Cc: Richard Fitzgerald <r...@opensource.cirrus.com>
Cc: Samuel Holland <sam...@sholland.org>
Cc: Sascha Hauer <s.ha...@pengutronix.de>
Cc: Sekhar Nori <nsek...@ti.com>
Cc: Shawn Guo <shawn...@kernel.org>
Cc: Takashi Iwai <ti...@suse.com>
Cc: Thierry Reding <thierry.red...@gmail.com>
Cc: Ulf Hansson <ulf.hans...@linaro.org>
Cc: Vinod Koul <vk...@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-acti...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-m...@vger.kernel.org
Cc: linux-...@lists.infradead.org
Cc: linux-renesas-...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Cc: linux-st...@st-md-mailman.stormreply.com
Cc: linux-su...@lists.linux.dev
Cc: linux-te...@vger.kernel.org
Cc: NXP Linux Team <linux-...@nxp.com>
Cc: patc...@opensource.cirrus.com
Cc: Pengutronix Kernel Team <ker...@pengutronix.de>
Signed-off-by: Stephen Boyd <sb...@kernel.org>
Signed-off-by: Maxime Ripard <max...@cerno.tech>
---
 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