[PATCH 09/14] staging: clocking-wizard: Provide more information in debugfs

James Kelly jamespeterkelly at gmail.com
Mon May 7 01:20:35 UTC 2018


Publish clock divider/multiplier ratios and flags specific to our
clock provider implementation as these are not available via the
debugfs entries provided by the common clock framework.

Signed-off-by: James Kelly <jamespeterkelly at gmail.com>
---
 .../clocking-wizard/clk-xlnx-clock-wizard.c        | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
index c892c0d46801..8929913045e7 100644
--- a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
+++ b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
@@ -69,6 +69,8 @@
 #include <linux/module.h>
 #include <linux/err.h>
 #include <linux/regmap.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #define WZRD_MAX_OUTPUTS	7
 #define KHz			1000UL
@@ -423,8 +425,63 @@ static unsigned long clk_wzrd_recalc_rate(struct clk_hw *hw,
 	return clk_wzrd_calc_rate(parent_rate, ratio, cwc->flags);
 }
 
+#ifdef CONFIG_DEBUG_FS
+
+static int clk_wzrd_flags_show(struct seq_file *s, void *data)
+{
+	struct clk_wzrd_clk_data *cwc = s->private;
+
+	seq_puts(s, "Flags:\n");
+	if (cwc->flags & WZRD_FLAG_MULTIPLY)
+		seq_puts(s, "WZRD_FLAG_MULTIPLY\n");
+	if (cwc->flags & WZRD_FLAG_FRAC)
+		seq_puts(s, "WZRD_FLAG_FRAC\n");
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(clk_wzrd_flags);
+
+static int clk_wzrd_ratio_show(struct seq_file *s, void *data)
+{
+	struct clk_wzrd_clk_data *cwc = s->private;
+	unsigned int int_part, frac_part = 0;
+
+	regmap_field_read(cwc->int_field, &int_part);
+	if (cwc->flags & WZRD_FLAG_FRAC) {
+		regmap_field_read(cwc->frac_field, &frac_part);
+		seq_printf(s, "%u.%u\n", int_part, frac_part);
+	} else {
+		seq_printf(s, "%u\n", int_part);
+	}
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(clk_wzrd_ratio);
+
+static int clk_wzrd_debug_init(struct clk_hw *hw, struct dentry *dentry)
+{
+	struct dentry *d;
+	struct clk_wzrd_clk_data *cwc = to_clk_wzrd_clk_data(hw);
+
+	d = debugfs_create_file_unsafe("clk_hw_flags", 0444, dentry, cwc,
+				       &clk_wzrd_flags_fops);
+	if (IS_ERR(d))
+		return PTR_ERR(d);
+
+	d = debugfs_create_file_unsafe("clk_ratio", 0444, dentry, cwc,
+				       &clk_wzrd_ratio_fops);
+	if (IS_ERR(d))
+		return PTR_ERR(d);
+
+	return 0;
+}
+#endif
+
 static const struct clk_ops clk_wzrd_clk_ops = {
 	.recalc_rate = clk_wzrd_recalc_rate,
+#ifdef CONFIG_DEBUG_FS
+	.debug_init = clk_wzrd_debug_init,
+#endif
 };
 
 static int clk_wzrd_register_clk(struct device *dev, const char *name,
-- 
2.15.1 (Apple Git-101)



More information about the devel mailing list