From: Rupesh Majhi <zoone.rupert@gmail.com>
To: "Andy Shevchenko" <andy@kernel.org>,
"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Eddie James" <eajames@linux.ibm.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Lucas Stankus" <lucas.p.stankus@gmail.com>,
"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Petre Rodan" <petre.rodan@subdimension.ro>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Shuah Khan" <skhan@linuxfoundation.org>
Cc: linux@analog.com, linux-doc@vger.kernel.org,
linux-iio@vger.kernel.org, Rupesh Majhi <zoone.rupert@gmail.com>,
crofts@kernel.org
Subject: [PATCH v4 2/7] iio: core: add iio_access_debugfs_regmap_reg()
Date: Sun, 6 Dec 2026 12:03:21 +0200 [thread overview]
Message-ID: <20261206100326.45569-3-zoone.rupert@gmail.com> (raw)
In-Reply-To: <20261206100326.45569-1-zoone.rupert@gmail.com>
More than 25 drivers implement .debugfs_reg_access() with only a
regmap_read() or regmap_write() on the regmap of the parent device.
Add a helper that looks that regmap up with dev_get_regmap(), so these
drivers can drop their own copy.
Without CONFIG_DEBUG_FS the helper is defined as NULL, like
adis_debugfs_reg_access(), so drivers can use it without ifdefs.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
v4:
- regmap lookup split from the declaration (Andy)
- kernel-doc of iio_get_debugfs_dentry() left alone, patch 1 moves it
- htmldocs: the helper is in driver-api/iio/core.html
v3:
- rename to iio_access_debugfs_regmap_reg() (Andy)
- kernel-doc of iio_get_debugfs_dentry() moves inside the #if, so the
new prototype can share the block; kernel-doc output is unchanged (Andy)
- callback written as .debugfs_reg_access() (Andy)
v2:
- move the helper to industrialio-debugfs.c (Andy)
- NULL without CONFIG_DEBUG_FS, that file is not built then
- Nuno's tag kept, given "With Andy split"
Cc: crofts@kernel.org
drivers/iio/industrialio-debugfs.c | 29 +++++++++++++++++++++++++++++
include/linux/iio/iio.h | 4 ++++
2 files changed, 33 insertions(+)
diff --git a/drivers/iio/industrialio-debugfs.c b/drivers/iio/industrialio-debugfs.c
index a331a7c6f8da..37101c8e7f8e 100644
--- a/drivers/iio/industrialio-debugfs.c
+++ b/drivers/iio/industrialio-debugfs.c
@@ -10,6 +10,7 @@
#include <linux/export.h>
#include <linux/fs.h>
#include <linux/init.h>
+#include <linux/regmap.h>
#include <linux/sprintf.h>
#include <linux/sysfs.h>
#include <linux/types.h>
@@ -48,6 +49,34 @@ void __exit iio_debugfs_remove(void)
debugfs_remove(iio_debugfs_dentry);
}
+/**
+ * iio_access_debugfs_regmap_reg() - debugfs register access through regmap
+ * @indio_dev: IIO device
+ * @reg: register address
+ * @writeval: value to write when @readval is NULL
+ * @readval: where to store the value read, or NULL for a write
+ *
+ * For &iio_info.debugfs_reg_access when the parent device has one regmap.
+ *
+ * Returns: 0 on success, -ENODEV if the parent has no regmap, or the error
+ * from regmap.
+ */
+int iio_access_debugfs_regmap_reg(struct iio_dev *indio_dev, unsigned int reg,
+ unsigned int writeval, unsigned int *readval)
+{
+ struct regmap *map;
+
+ map = dev_get_regmap(indio_dev->dev.parent, NULL);
+ if (!map)
+ return -ENODEV;
+
+ if (readval)
+ return regmap_read(map, reg, readval);
+
+ return regmap_write(map, reg, writeval);
+}
+EXPORT_SYMBOL_GPL(iio_access_debugfs_regmap_reg);
+
static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 5104392cce38..d82db4c768bc 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -1002,11 +1002,15 @@ struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent,
const char *fmt, ...);
#if defined(CONFIG_DEBUG_FS)
struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
+int iio_access_debugfs_regmap_reg(struct iio_dev *indio_dev, unsigned int reg,
+ unsigned int writeval, unsigned int *readval);
#else
static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
{
return NULL;
}
+
+#define iio_access_debugfs_regmap_reg NULL
#endif
/**
--
2.43.0
next prev parent reply other threads:[~2026-12-06 10:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 10:03 [PATCH v4 0/7] iio: debugfs register access through regmap in the core Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 1/7] iio: core: move iio_get_debugfs_dentry() kernel-doc to the C file Rupesh Majhi
2026-12-06 10:03 ` Rupesh Majhi [this message]
2026-12-06 10:03 ` [PATCH v4 3/7] iio: accel: adxl313: use iio_access_debugfs_regmap_reg() Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 4/7] iio: accel: adxl372: " Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 5/7] iio: accel: bma220: " Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 6/7] iio: adc: ina2xx-adc: " Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 7/7] iio: pressure: dps310: add debugfs register access Rupesh Majhi
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=20261206100326.45569-3-zoone.rupert@gmail.com \
--to=zoone.rupert@gmail.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=antoniu.miclaus@analog.com \
--cc=corbet@lwn.net \
--cc=crofts@kernel.org \
--cc=dlechner@baylibre.com \
--cc=eajames@linux.ibm.com \
--cc=jic23@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux@analog.com \
--cc=lucas.p.stankus@gmail.com \
--cc=marcelo.schmitt@analog.com \
--cc=nuno.sa@analog.com \
--cc=petre.rodan@subdimension.ro \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.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