public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/3] clk: fractional-divider: Split out clk_fd_get_div() helper
@ 2022-11-17 15:51 Andy Shevchenko
  2022-11-17 15:51 ` [PATCH v1 2/3] clk: fractional-divider: Show numerator and denominator in debugfs Andy Shevchenko
  2022-11-17 15:51 ` [PATCH v1 3/3] clk: fractional-divider: Regroup inclusions Andy Shevchenko
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2022-11-17 15:51 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel; +Cc: Michael Turquette, Stephen Boyd

Split out clk_fd_get_div() helper for the future use elsewhere.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/clk/clk-fractional-divider.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index 8efa5142ff8c..5c6f1d0f8fb4 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -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;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 2/3] clk: fractional-divider: Show numerator and denominator in debugfs
  2022-11-17 15:51 [PATCH v1 1/3] clk: fractional-divider: Split out clk_fd_get_div() helper Andy Shevchenko
@ 2022-11-17 15:51 ` Andy Shevchenko
  2022-11-17 15:51 ` [PATCH v1 3/3] clk: fractional-divider: Regroup inclusions Andy Shevchenko
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2022-11-17 15:51 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel; +Cc: Michael Turquette, Stephen Boyd

It's very useful to see what are the values of the fractional divider.
For that, add respective debugfs files.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/clk/clk-fractional-divider.c | 36 ++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index 5c6f1d0f8fb4..b6b52b79d671 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -39,6 +39,7 @@
  */
 
 #include <linux/clk-provider.h>
+#include <linux/debugfs.h>
 #include <linux/io.h>
 #include <linux/math.h>
 #include <linux/module.h>
@@ -193,10 +194,45 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
 	return 0;
 }
 
+#ifdef CONFIG_DEBUG_FS
+static int clk_fd_numerator_get(void *hw, u64 *val)
+{
+	struct u32_fract fract;
+
+	clk_fd_get_div(hw, &fract);
+
+	*val = fract.numerator;
+
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(clk_fd_numerator_fops, clk_fd_numerator_get, NULL, "%llu\n");
+
+static int clk_fd_denominator_get(void *hw, u64 *val)
+{
+	struct u32_fract fract;
+
+	clk_fd_get_div(hw, &fract);
+
+	*val = fract.denominator;
+
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(clk_fd_denominator_fops, clk_fd_denominator_get, NULL, "%llu\n");
+
+static void clk_fd_debug_init(struct clk_hw *hw, struct dentry *dentry)
+{
+	debugfs_create_file("numerator", 0444, dentry, hw, &clk_fd_numerator_fops);
+	debugfs_create_file("denominator", 0444, dentry, hw, &clk_fd_denominator_fops);
+}
+#endif
+
 const struct clk_ops clk_fractional_divider_ops = {
 	.recalc_rate = clk_fd_recalc_rate,
 	.round_rate = clk_fd_round_rate,
 	.set_rate = clk_fd_set_rate,
+#ifdef CONFIG_DEBUG_FS
+	.debug_init = clk_fd_debug_init,
+#endif
 };
 EXPORT_SYMBOL_GPL(clk_fractional_divider_ops);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 3/3] clk: fractional-divider: Regroup inclusions
  2022-11-17 15:51 [PATCH v1 1/3] clk: fractional-divider: Split out clk_fd_get_div() helper Andy Shevchenko
  2022-11-17 15:51 ` [PATCH v1 2/3] clk: fractional-divider: Show numerator and denominator in debugfs Andy Shevchenko
@ 2022-11-17 15:51 ` Andy Shevchenko
  2022-11-17 16:17   ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2022-11-17 15:51 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel; +Cc: Michael Turquette, Stephen Boyd

For the better maintenance regroup inclusions as follows:
- split CCF related headers in its own group
- order groups from generic to particular
- sort each group alphabetically

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/clk/clk-fractional-divider.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index b6b52b79d671..ebd007f5ce5d 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -40,12 +40,14 @@
 
 #include <linux/clk-provider.h>
 #include <linux/debugfs.h>
+#include <linux/device.h>
 #include <linux/io.h>
 #include <linux/math.h>
 #include <linux/module.h>
-#include <linux/device.h>
-#include <linux/slab.h>
 #include <linux/rational.h>
+#include <linux/slab.h>
+
+#include <linux/clk-provider.h>
 
 #include "clk-fractional-divider.h"
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 3/3] clk: fractional-divider: Regroup inclusions
  2022-11-17 15:51 ` [PATCH v1 3/3] clk: fractional-divider: Regroup inclusions Andy Shevchenko
@ 2022-11-17 16:17   ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2022-11-17 16:17 UTC (permalink / raw)
  To: linux-clk, linux-kernel; +Cc: Michael Turquette, Stephen Boyd

On Thu, Nov 17, 2022 at 05:51:05PM +0200, Andy Shevchenko wrote:
> For the better maintenance regroup inclusions as follows:
> - split CCF related headers in its own group
> - order groups from generic to particular
> - sort each group alphabetically

...

>  #include <linux/clk-provider.h>

Forgot removing this one.

Anyway, I will wait for comments and then will send a v2.


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-17 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-17 15:51 [PATCH v1 1/3] clk: fractional-divider: Split out clk_fd_get_div() helper Andy Shevchenko
2022-11-17 15:51 ` [PATCH v1 2/3] clk: fractional-divider: Show numerator and denominator in debugfs Andy Shevchenko
2022-11-17 15:51 ` [PATCH v1 3/3] clk: fractional-divider: Regroup inclusions Andy Shevchenko
2022-11-17 16:17   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox