From: Li Chen <me@linux.beauty>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>
Cc: Li Chen <lchen@ambarella.com>, linux-kernel@vger.kernel.org
Subject: [PATCH v2] debugfs: allow to use regmap for print regs
Date: Wed, 11 Jan 2023 15:21:29 +0800 [thread overview]
Message-ID: <20230111072130.3885460-1-me@linux.beauty> (raw)
From: Li Chen <lchen@ambarella.com>
Currently, debugfs_regset32 only contains void __iomem *base,
and it is not friendly to regmap user.
Let's add regmap to debugfs_regset32, and add debugfs_print_regmap_reg32
to allow debugfs_regset32_show handle regmap.
Signed-off-by: Li Chen <lchen@ambarella.com>
---
Changelog:
v1 -> v2:
Suggested by Greg, provide a new function for regmap instead of trying to overload old function.
---
fs/debugfs/file.c | 46 ++++++++++++++++++++++++++++++++++++++++-
include/linux/debugfs.h | 10 +++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index b54f470e0d03..f204b27f757f 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -1137,14 +1137,58 @@ void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
}
EXPORT_SYMBOL_GPL(debugfs_print_regs32);
+/**
+ * debugfs_print_regmap_regs32 - use seq_print to describe a set of registers
+ * @s: the seq_file structure being used to generate output
+ * @regs: an array if struct debugfs_reg32 structures
+ * @nregs: the length of the above array
+ * @regmap: regmap to be used in reading the registers
+ * @prefix: a string to be prefixed to every output line
+ *
+ * This function outputs a text block describing the current values of
+ * some 32-bit hardware registers. It is meant to be used within debugfs
+ * files based on seq_file that need to show registers, intermixed with other
+ * information. The prefix argument may be used to specify a leading string,
+ * because some peripherals have several blocks of identical registers,
+ * for example configuration of dma channels
+ */
+void debugfs_print_regmap_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
+ int nregs, struct regmap *regmap, char *prefix)
+{
+ int i;
+ u32 val;
+
+ for (i = 0; i < nregs; i++, regs++) {
+ if (prefix)
+ seq_printf(s, "%s", prefix);
+ regmap_read(regmap, regs->offset, &val);
+ seq_printf(s, "%s = 0x%08x\n", regs->name, val);
+ if (seq_has_overflowed(s))
+ break;
+ }
+}
+EXPORT_SYMBOL_GPL(debugfs_print_regmap_regs32);
+
static int debugfs_regset32_show(struct seq_file *s, void *data)
{
struct debugfs_regset32 *regset = s->private;
+ void __iomem *base = regset->base;
+ struct regmap *regmap = regset->regmap;
+
+ if ((regmap && base) || (!regmap && !base)) {
+ seq_puts(
+ s,
+ "You should provide one and only one between base and regmap!\n");
+ return -EINVAL;
+ }
if (regset->dev)
pm_runtime_get_sync(regset->dev);
- debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
+ if (base)
+ debugfs_print_regs32(s, regset->regs, regset->nregs, base, "");
+ if (regmap)
+ debugfs_print_regmap_regs32(s, regset->regs, regset->nregs, regmap, "");
if (regset->dev)
pm_runtime_put(regset->dev);
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index ea2d919fd9c7..04bc2bb70b79 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -17,6 +17,7 @@
#include <linux/types.h>
#include <linux/compiler.h>
+#include <linux/regmap.h>
struct device;
struct file_operations;
@@ -35,6 +36,7 @@ struct debugfs_regset32 {
const struct debugfs_reg32 *regs;
int nregs;
void __iomem *base;
+ struct regmap *regmap;
struct device *dev; /* Optional device for Runtime PM */
};
@@ -152,6 +154,9 @@ void debugfs_create_regset32(const char *name, umode_t mode,
void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
int nregs, void __iomem *base, char *prefix);
+void debugfs_print_regmap_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
+ int nregs, struct regmap *regmap, char *prefix);
+
void debugfs_create_u32_array(const char *name, umode_t mode,
struct dentry *parent,
struct debugfs_u32_array *array);
@@ -338,6 +343,11 @@ static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs
{
}
+static inline void debugfs_print_regmap_regs32(struct seq_file *s,
+ const struct debugfs_reg32 *regs,
+ int nregs, struct regmap *regmap,
+ char *prefix);
+
static inline bool debugfs_initialized(void)
{
return false;
--
2.34.1
next reply other threads:[~2023-01-11 7:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 7:21 Li Chen [this message]
2023-01-11 7:42 ` Greg Kroah-Hartman
2023-01-11 8:27 ` Li Chen
2023-01-11 10:48 ` Greg Kroah-Hartman
2023-01-23 7:49 ` Li Chen
2023-01-11 14:59 ` kernel test robot
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=20230111072130.3885460-1-me@linux.beauty \
--to=me@linux.beauty \
--cc=gregkh@linuxfoundation.org \
--cc=lchen@ambarella.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®