All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@codeaurora.org>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v2 3/4] clk: Show symbolic clock flags in debugfs
Date: Wed,  3 Jan 2018 12:06:16 +0100	[thread overview]
Message-ID: <1514977577-11854-4-git-send-email-geert+renesas@glider.be> (raw)
In-Reply-To: <1514977577-11854-1-git-send-email-geert+renesas@glider.be>

Currently the virtual "clk_flags" file in debugfs shows the numeric
value of the top-level framework flags for the specified clock.
Hence the user must manually interpret these values.

Moreover, on big-endian 64-bit systems, the wrong half of the value is
shown, due to the cast from "unsigned long *" to "u32 *".

Fix both issues by showing the symbolic flag names instead.
Any non-standard flags are shown as a hex number.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
  - New.
---
 drivers/clk/clk.c            | 54 ++++++++++++++++++++++++++++++++++++++++++--
 include/linux/clk-provider.h |  2 ++
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 240b1d427fadab66..7cb5143c654cd78f 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2559,6 +2559,56 @@ static const struct file_operations clk_dump_fops = {
 	.release	= single_release,
 };
 
+static const struct {
+	unsigned long flag;
+	const char *name;
+} clk_flags[] = {
+	{ CLK_SET_RATE_GATE,		"CLK_SET_RATE_GATE",		},
+	{ CLK_SET_PARENT_GATE,		"CLK_SET_PARENT_GATE",		},
+	{ CLK_SET_RATE_PARENT,		"CLK_SET_RATE_PARENT",		},
+	{ CLK_IGNORE_UNUSED,		"CLK_IGNORE_UNUSED",		},
+	{ CLK_IS_BASIC,			"CLK_IS_BASIC",			},
+	{ CLK_GET_RATE_NOCACHE,		"CLK_GET_RATE_NOCACHE",		},
+	{ CLK_SET_RATE_NO_REPARENT,	"CLK_SET_RATE_NO_REPARENT",	},
+	{ CLK_GET_ACCURACY_NOCACHE,	"CLK_GET_ACCURACY_NOCACHE",	},
+	{ CLK_RECALC_NEW_RATES,		"CLK_RECALC_NEW_RATES",		},
+	{ CLK_SET_RATE_UNGATE,		"CLK_SET_RATE_UNGATE",		},
+	{ CLK_IS_CRITICAL,		"CLK_IS_CRITICAL",		},
+	{ CLK_OPS_PARENT_ENABLE,	"CLK_OPS_PARENT_ENABLE",	},
+};
+
+static int clk_flags_dump(struct seq_file *s, void *data)
+{
+	struct clk_core *core = s->private;
+	unsigned long flags = core->flags;
+	unsigned int i;
+
+	for (i = 0; flags && i < ARRAY_SIZE(clk_flags); i++) {
+		if (flags & clk_flags[i].flag) {
+			seq_printf(s, "%s\n", clk_flags[i].name);
+			flags &= ~clk_flags[i].flag;
+		}
+	}
+	if (flags) {
+		/* Unknown flags */
+		seq_printf(s, "0x%lx\n", flags);
+	}
+
+	return 0;
+}
+
+static int clk_flags_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, clk_flags_dump, inode->i_private);
+}
+
+static const struct file_operations clk_flags_fops = {
+	.open		= clk_flags_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 static int possible_parents_dump(struct seq_file *s, void *data)
 {
 	struct clk_core *core = s->private;
@@ -2615,8 +2665,8 @@ static int clk_debug_create_one(struct clk_core *core, struct dentry *pdentry)
 	if (!d)
 		goto err_out;
 
-	d = debugfs_create_x32("clk_flags", 0444, core->dentry,
-			(u32 *)&core->flags);
+	d = debugfs_create_file("clk_flags", 0444, core->dentry, core,
+				&clk_flags_fops);
 	if (!d)
 		goto err_out;
 
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 411db2423bd45818..73add58e7d666083 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -20,6 +20,8 @@
  * flags used across common struct clk.  these flags should only affect the
  * top-level framework.  custom flags for dealing with hardware specifics
  * belong in struct clk_foo
+ *
+ * Please update clk_flags[] in drivers/clk/clk.c when making changes here!
  */
 #define CLK_SET_RATE_GATE	BIT(0) /* must be gated across rate change */
 #define CLK_SET_PARENT_GATE	BIT(1) /* must be gated across re-parent */
-- 
2.7.4

  parent reply	other threads:[~2018-01-03 11:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 11:06 [PATCH v2 0/4] clk: Fix debugfs_create_*() usage Geert Uytterhoeven
2018-01-03 11:06 ` [PATCH v2 1/4] clk: Improve flags doc for of_clk_detect_critical() Geert Uytterhoeven
2018-01-10 21:14   ` Stephen Boyd
2018-01-03 11:06 ` [PATCH v2 2/4] clk: Use octal instead of symbolic permissions Geert Uytterhoeven
2018-01-10 21:14   ` Stephen Boyd
2018-01-03 11:06 ` Geert Uytterhoeven [this message]
2018-01-10  2:02   ` [PATCH v2 3/4] clk: Show symbolic clock flags in debugfs Stephen Boyd
2018-01-10  7:53     ` Geert Uytterhoeven
2018-01-10 21:14   ` Stephen Boyd
2018-01-03 11:06 ` [PATCH v2 4/4] clk: Fix debugfs_create_*() usage Geert Uytterhoeven
2018-01-10 21:14   ` Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1514977577-11854-4-git-send-email-geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.