]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
clk: fractional-divider: Split out clk_fd_get_div() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 22 Nov 2022 13:07:30 +0000 (15:07 +0200)
committerStephen Boyd <sboyd@kernel.org>
Wed, 23 Nov 2022 02:19:38 +0000 (18:19 -0800)
Split out clk_fd_get_div() helper for the future use elsewhere.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20221122130732.48537-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clk-fractional-divider.c

index 8efa5142ff8c725ff4a1522b97785a4aed994a96..5c6f1d0f8fb4b873ca4ef54255fc29b0d4a461a5 100644 (file)
@@ -40,6 +40,7 @@
 
 #include <linux/clk-provider.h>
 #include <linux/io.h>
+#include <linux/math.h>
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/slab.h>
@@ -63,14 +64,12 @@ static inline void clk_fd_writel(struct clk_fractional_divider *fd, u32 val)
                writel(val, fd->reg);
 }
 
-static unsigned long clk_fd_recalc_rate(struct clk_hw *hw,
-                                       unsigned long parent_rate)
+static void clk_fd_get_div(struct clk_hw *hw, struct u32_fract *fract)
 {
        struct clk_fractional_divider *fd = to_clk_fd(hw);
        unsigned long flags = 0;
        unsigned long m, n;
        u32 val;
-       u64 ret;
 
        if (fd->lock)
                spin_lock_irqsave(fd->lock, flags);
@@ -92,11 +91,22 @@ static unsigned long clk_fd_recalc_rate(struct clk_hw *hw,
                n++;
        }
 
-       if (!n || !m)
+       fract->numerator = m;
+       fract->denominator = n;
+}
+
+static unsigned long clk_fd_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
+{
+       struct u32_fract fract;
+       u64 ret;
+
+       clk_fd_get_div(hw, &fract);
+
+       if (!fract.numerator || !fract.denominator)
                return parent_rate;
 
-       ret = (u64)parent_rate * m;
-       do_div(ret, n);
+       ret = (u64)parent_rate * fract.numerator;
+       do_div(ret, fract.denominator);
 
        return ret;
 }