clk: imx: pllv4: convert from round_rate() to determine_rate()
authorBrian Masney <bmasney@redhat.com>
Thu, 10 Jul 2025 21:10:44 +0000 (17:10 -0400)
committerStephen Boyd <sboyd@kernel.org>
Thu, 24 Jul 2025 22:17:52 +0000 (15:17 -0700)
The round_rate() clk ops is deprecated, so migrate this driver from
round_rate() to determine_rate() using the Coccinelle semantic patch
on the cover letter of this series.

Signed-off-by: Brian Masney <bmasney@redhat.com>
Link: https://lore.kernel.org/r/20250710-clk-imx-round-rate-v1-12-5726f98e6d8d@redhat.com
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/imx/clk-pllv4.c

index 9b136c951762c23cb7424405e1a66ec70af57d5c..01d05b5d543852c9eb48d1ae2b63e8f32b4f4a89 100644 (file)
@@ -95,11 +95,11 @@ static unsigned long clk_pllv4_recalc_rate(struct clk_hw *hw,
        return (parent_rate * mult) + (u32)temp64;
 }
 
-static long clk_pllv4_round_rate(struct clk_hw *hw, unsigned long rate,
-                                unsigned long *prate)
+static int clk_pllv4_determine_rate(struct clk_hw *hw,
+                                   struct clk_rate_request *req)
 {
        struct clk_pllv4 *pll = to_clk_pllv4(hw);
-       unsigned long parent_rate = *prate;
+       unsigned long parent_rate = req->best_parent_rate;
        unsigned long round_rate, i;
        u32 mfn, mfd = DEFAULT_MFD;
        bool found = false;
@@ -107,7 +107,7 @@ static long clk_pllv4_round_rate(struct clk_hw *hw, unsigned long rate,
        u32 mult;
 
        if (pll->use_mult_range) {
-               temp64 = (u64)rate;
+               temp64 = (u64) req->rate;
                do_div(temp64, parent_rate);
                mult = temp64;
                if (mult >= pllv4_mult_range[1] &&
@@ -118,7 +118,7 @@ static long clk_pllv4_round_rate(struct clk_hw *hw, unsigned long rate,
        } else {
                for (i = 0; i < ARRAY_SIZE(pllv4_mult_table); i++) {
                        round_rate = parent_rate * pllv4_mult_table[i];
-                       if (rate >= round_rate) {
+                       if (req->rate >= round_rate) {
                                found = true;
                                break;
                        }
@@ -127,14 +127,16 @@ static long clk_pllv4_round_rate(struct clk_hw *hw, unsigned long rate,
 
        if (!found) {
                pr_warn("%s: unable to round rate %lu, parent rate %lu\n",
-                       clk_hw_get_name(hw), rate, parent_rate);
+                       clk_hw_get_name(hw), req->rate, parent_rate);
+               req->rate = 0;
+
                return 0;
        }
 
        if (parent_rate <= MAX_MFD)
                mfd = parent_rate;
 
-       temp64 = (u64)(rate - round_rate);
+       temp64 = (u64)(req->rate - round_rate);
        temp64 *= mfd;
        do_div(temp64, parent_rate);
        mfn = temp64;
@@ -145,14 +147,19 @@ static long clk_pllv4_round_rate(struct clk_hw *hw, unsigned long rate,
         * pair of mfn/mfd, we simply return the round_rate without using
         * the frac part.
         */
-       if (mfn >= mfd)
-               return round_rate;
+       if (mfn >= mfd) {
+               req->rate = round_rate;
+
+               return 0;
+       }
 
        temp64 = (u64)parent_rate;
        temp64 *= mfn;
        do_div(temp64, mfd);
 
-       return round_rate + (u32)temp64;
+       req->rate = round_rate + (u32)temp64;
+
+       return 0;
 }
 
 static bool clk_pllv4_is_valid_mult(struct clk_pllv4 *pll, unsigned int mult)
@@ -229,7 +236,7 @@ static void clk_pllv4_unprepare(struct clk_hw *hw)
 
 static const struct clk_ops clk_pllv4_ops = {
        .recalc_rate    = clk_pllv4_recalc_rate,
-       .round_rate     = clk_pllv4_round_rate,
+       .determine_rate = clk_pllv4_determine_rate,
        .set_rate       = clk_pllv4_set_rate,
        .prepare        = clk_pllv4_prepare,
        .unprepare      = clk_pllv4_unprepare,