[PATCH 1/6] iio: core: add iio_debugfs_reg_access_regmap()
From: Rupesh Majhi
Date: Tue Nov 24 2026 - 01:50:28 EST
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.
Signed-off-by: Rupesh Majhi <zoone.rupert@xxxxxxxxx>
---
drivers/iio/industrialio-core.c | 28 ++++++++++++++++++++++++++++
include/linux/iio/iio.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index dabd57a0994e..e658687d978f 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -28,6 +28,7 @@
#include <linux/overflow.h>
#include <linux/poll.h>
#include <linux/property.h>
+#include <linux/regmap.h>
#include <linux/sched.h>
#include <linux/seq_buf.h>
#include <linux/slab.h>
@@ -446,6 +447,33 @@ static void __exit iio_exit(void)
debugfs_remove(iio_debugfs_dentry);
}
+/**
+ * iio_debugfs_reg_access_regmap() - 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_debugfs_reg_access_regmap(struct iio_dev *indio_dev, unsigned int reg,
+ unsigned int writeval, unsigned int *readval)
+{
+ struct regmap *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_debugfs_reg_access_regmap);
+
#if defined(CONFIG_DEBUG_FS)
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 8b3fd7673293..8407e6e4620a 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -677,6 +677,8 @@ struct iio_dev {
int iio_device_id(struct iio_dev *indio_dev);
int iio_device_get_current_mode(struct iio_dev *indio_dev);
+int iio_debugfs_reg_access_regmap(struct iio_dev *indio_dev, unsigned int reg,
+ unsigned int writeval, unsigned int *readval);
bool iio_buffer_enabled(struct iio_dev *indio_dev);
const struct iio_chan_spec
--
2.43.0