diff mbox series

[3/4] clk: ti: mux: add debugfs support for read/write of parent ID

Message ID 20191001090202.26346-4-t-kristo@ti.com (mailing list archive)
State Changes Requested, archived
Headers show
Series clk: debugfs: add some simple debug functionality | expand

Commit Message

Tero Kristo Oct. 1, 2019, 9:02 a.m. UTC
Add parent_id node under debugfs for mux clocks, that allow both
read/write operations. This can be used to read the current
parent ID, or force a change of current parent of a mux clock.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
---
 drivers/clk/ti/mux.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
diff mbox series

Patch

diff --git a/drivers/clk/ti/mux.c b/drivers/clk/ti/mux.c
index 0069e7cf3ebc..f036ecc78034 100644
--- a/drivers/clk/ti/mux.c
+++ b/drivers/clk/ti/mux.c
@@ -21,6 +21,8 @@ 
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/clk/ti.h>
+#include <linux/debugfs.h>
+
 #include "clock.h"
 
 #undef pr_fmt
@@ -118,12 +120,48 @@  static void clk_mux_restore_context(struct clk_hw *hw)
 	ti_clk_mux_set_parent(hw, mux->saved_parent);
 }
 
+#ifdef CONFIG_COMMON_CLK_DEBUGFS_WRITE_ACCESS
+static int dbg_pid_get(void *data, u64 *val)
+{
+	struct clk_hw *hw = data;
+
+	*val = ti_clk_mux_get_parent(hw);
+
+	return 0;
+}
+
+static int dbg_pid_set(void *data, u64 val)
+{
+	struct clk_hw *hw = data;
+	struct clk_hw *parent = clk_hw_get_parent_by_index(hw, val);
+
+	if (!parent)
+		return -EINVAL;
+
+	clk_hw_reparent(hw, parent);
+
+	return ti_clk_mux_set_parent(hw, val);
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(mux_parent_id_fops, dbg_pid_get, dbg_pid_set, "%llu\n");
+
+static void clk_mux_debug_init(struct clk_hw *hw, struct dentry *dentry)
+{
+	debugfs_create_file("parent_id", 0644, dentry, hw, &mux_parent_id_fops);
+}
+#else
+static void clk_mux_debug_init(struct clk_hw *hw, struct dentry *dentry)
+{
+}
+#endif
+
 const struct clk_ops ti_clk_mux_ops = {
 	.get_parent = ti_clk_mux_get_parent,
 	.set_parent = ti_clk_mux_set_parent,
 	.determine_rate = __clk_mux_determine_rate,
 	.save_context = clk_mux_save_context,
 	.restore_context = clk_mux_restore_context,
+	.debug_init = clk_mux_debug_init,
 };
 
 static struct clk *_register_mux(struct device *dev, const char *name,