]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
clk: at91: peripheral: convert from round_rate() to determine_rate()
authorBrian Masney <bmasney@redhat.com>
Mon, 11 Aug 2025 15:17:54 +0000 (11:17 -0400)
committerBrian Masney <bmasney@redhat.com>
Mon, 8 Sep 2025 13:41:25 +0000 (09:41 -0400)
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.

This driver already has a clk_sam9x5_peripheral_determine_rate()
implementation, however it can change the parent rate. The existing
round rate does not have this functionality. I could add a check
for CLK_SET_RATE_PARENT, and combine the two functions, however there
are some other minor differences in the two implementations. I don't
have access to this particular hardware. I believe that they could
be combined, however it would need to be tested on real hardware.
So, let's play it safe and convert the existing round rate
implementation to ensure that the driver keeps the same functionality
as before.

Reviewed-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
Signed-off-by: Brian Masney <bmasney@redhat.com>
drivers/clk/at91/clk-peripheral.c

index 629f050a855aaebfd1a03ff87c2b016cd2284a5a..e700f40fd87f9327365f250366f7f7bde01f5987 100644 (file)
@@ -335,50 +335,57 @@ end:
        return 0;
 }
 
-static long clk_sam9x5_peripheral_round_rate(struct clk_hw *hw,
-                                            unsigned long rate,
-                                            unsigned long *parent_rate)
+static int clk_sam9x5_peripheral_no_parent_determine_rate(struct clk_hw *hw,
+                                                         struct clk_rate_request *req)
 {
        int shift = 0;
        unsigned long best_rate;
        unsigned long best_diff;
-       unsigned long cur_rate = *parent_rate;
+       unsigned long cur_rate = req->best_parent_rate;
        unsigned long cur_diff;
        struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
 
-       if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max)
-               return *parent_rate;
+       if (periph->id < PERIPHERAL_ID_MIN || !periph->range.max) {
+               req->rate = req->best_parent_rate;
+
+               return 0;
+       }
 
        if (periph->range.max) {
                for (; shift <= PERIPHERAL_MAX_SHIFT; shift++) {
-                       cur_rate = *parent_rate >> shift;
+                       cur_rate = req->best_parent_rate >> shift;
                        if (cur_rate <= periph->range.max)
                                break;
                }
        }
 
-       if (rate >= cur_rate)
-               return cur_rate;
+       if (req->rate >= cur_rate) {
+               req->rate = cur_rate;
+
+               return 0;
+       }
 
-       best_diff = cur_rate - rate;
+       best_diff = cur_rate - req->rate;
        best_rate = cur_rate;
        for (; shift <= PERIPHERAL_MAX_SHIFT; shift++) {
-               cur_rate = *parent_rate >> shift;
-               if (cur_rate < rate)
-                       cur_diff = rate - cur_rate;
+               cur_rate = req->best_parent_rate >> shift;
+               if (cur_rate < req->rate)
+                       cur_diff = req->rate - cur_rate;
                else
-                       cur_diff = cur_rate - rate;
+                       cur_diff = cur_rate - req->rate;
 
                if (cur_diff < best_diff) {
                        best_diff = cur_diff;
                        best_rate = cur_rate;
                }
 
-               if (!best_diff || cur_rate < rate)
+               if (!best_diff || cur_rate < req->rate)
                        break;
        }
 
-       return best_rate;
+       req->rate = best_rate;
+
+       return 0;
 }
 
 static int clk_sam9x5_peripheral_set_rate(struct clk_hw *hw,
@@ -430,7 +437,7 @@ static const struct clk_ops sam9x5_peripheral_ops = {
        .disable = clk_sam9x5_peripheral_disable,
        .is_enabled = clk_sam9x5_peripheral_is_enabled,
        .recalc_rate = clk_sam9x5_peripheral_recalc_rate,
-       .round_rate = clk_sam9x5_peripheral_round_rate,
+       .determine_rate = clk_sam9x5_peripheral_no_parent_determine_rate,
        .set_rate = clk_sam9x5_peripheral_set_rate,
        .save_context = clk_sam9x5_peripheral_save_context,
        .restore_context = clk_sam9x5_peripheral_restore_context,