* [PATCH v4 1/7] iio: core: move iio_get_debugfs_dentry() kernel-doc to the C file
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 ` Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 2/7] iio: core: add iio_access_debugfs_regmap_reg() Rupesh Majhi
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, Andy Shevchenko,
crofts
The kernel-doc of iio_get_debugfs_dentry() is in iio.h, above the
CONFIG_DEBUG_FS ifdef. Move it next to the function in
industrialio-debugfs.c.
That file is not in the generated documentation, so add it to core.rst
to keep the function there.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
htmldocs: the function is in driver-api/iio/core.html before and after,
with the same text. The page does not depend on CONFIG_DEBUG_FS.
Cc: crofts@kernel.org
Documentation/driver-api/iio/core.rst | 2 ++
drivers/iio/industrialio-debugfs.c | 5 +++++
include/linux/iio/iio.h | 4 ----
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Documentation/driver-api/iio/core.rst b/Documentation/driver-api/iio/core.rst
index 42b580fb2989..02229605531f 100644
--- a/Documentation/driver-api/iio/core.rst
+++ b/Documentation/driver-api/iio/core.rst
@@ -180,3 +180,5 @@ More details
.. kernel-doc:: include/linux/iio/iio.h
.. kernel-doc:: drivers/iio/industrialio-core.c
:export:
+.. kernel-doc:: drivers/iio/industrialio-debugfs.c
+ :export:
diff --git a/drivers/iio/industrialio-debugfs.c b/drivers/iio/industrialio-debugfs.c
index a8a3c7a3e85d..a331a7c6f8da 100644
--- a/drivers/iio/industrialio-debugfs.c
+++ b/drivers/iio/industrialio-debugfs.c
@@ -25,6 +25,11 @@ static struct dentry *iio_debugfs_dentry;
* There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for
* iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined
*/
+
+/**
+ * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
+ * @indio_dev: IIO device structure for device
+ */
struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
{
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 8b3fd7673293..5104392cce38 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -1000,10 +1000,6 @@ __printf(3, 4)
struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent,
struct module *this_mod,
const char *fmt, ...);
-/**
- * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
- * @indio_dev: IIO device structure for device
- **/
#if defined(CONFIG_DEBUG_FS)
struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
#else
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 2/7] iio: core: add iio_access_debugfs_regmap_reg()
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
2026-12-06 10:03 ` [PATCH v4 3/7] iio: accel: adxl313: use iio_access_debugfs_regmap_reg() Rupesh Majhi
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, crofts
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
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 3/7] iio: accel: adxl313: use iio_access_debugfs_regmap_reg()
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 ` [PATCH v4 2/7] iio: core: add iio_access_debugfs_regmap_reg() Rupesh Majhi
@ 2026-12-06 10:03 ` Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 4/7] iio: accel: adxl372: " Rupesh Majhi
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, Andy Shevchenko
The debugfs callback only reads or writes the regmap of the parent
device, which is what the core helper does.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/accel/adxl313_core.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/iio/accel/adxl313_core.c b/drivers/iio/accel/adxl313_core.c
index 6dc918c4ae17..4f4336a9dc11 100644
--- a/drivers/iio/accel/adxl313_core.c
+++ b/drivers/iio/accel/adxl313_core.c
@@ -1131,16 +1131,6 @@ static irqreturn_t adxl313_irq_handler(int irq, void *p)
return IRQ_HANDLED;
}
-static int adxl313_reg_access(struct iio_dev *indio_dev, unsigned int reg,
- unsigned int writeval, unsigned int *readval)
-{
- struct adxl313_data *data = iio_priv(indio_dev);
-
- if (readval)
- return regmap_read(data->regmap, reg, readval);
- return regmap_write(data->regmap, reg, writeval);
-}
-
static const struct iio_info adxl313_info = {
.read_raw = adxl313_read_raw,
.write_raw = adxl313_write_raw,
@@ -1150,7 +1140,7 @@ static const struct iio_info adxl313_info = {
.write_event_value = adxl313_write_event_value,
.read_avail = adxl313_read_freq_avail,
.hwfifo_set_watermark = adxl313_set_watermark,
- .debugfs_reg_access = &adxl313_reg_access,
+ .debugfs_reg_access = iio_access_debugfs_regmap_reg,
};
static int adxl313_setup(struct device *dev, struct adxl313_data *data,
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 4/7] iio: accel: adxl372: use iio_access_debugfs_regmap_reg()
2026-12-06 10:03 [PATCH v4 0/7] iio: debugfs register access through regmap in the core Rupesh Majhi
` (2 preceding siblings ...)
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 ` Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 5/7] iio: accel: bma220: " Rupesh Majhi
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, Andy Shevchenko
The debugfs callback only reads or writes the regmap of the parent
device, which is what the core helper does.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/accel/adxl372.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index a880ff4bfce1..cb9c424d3298 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -806,19 +806,6 @@ static int adxl372_setup(struct adxl372_state *st)
return adxl372_set_op_mode(st, ADXL372_FULL_BW_MEASUREMENT);
}
-static int adxl372_reg_access(struct iio_dev *indio_dev,
- unsigned int reg,
- unsigned int writeval,
- unsigned int *readval)
-{
- struct adxl372_state *st = iio_priv(indio_dev);
-
- if (readval)
- return regmap_read(st->regmap, reg, readval);
- else
- return regmap_write(st->regmap, reg, writeval);
-}
-
static int adxl372_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long info)
@@ -1221,7 +1208,7 @@ static const struct iio_info adxl372_info = {
.write_event_config = adxl372_write_event_config,
.read_event_value = adxl372_read_event_value,
.write_event_value = adxl372_write_event_value,
- .debugfs_reg_access = &adxl372_reg_access,
+ .debugfs_reg_access = iio_access_debugfs_regmap_reg,
.hwfifo_set_watermark = adxl372_set_watermark,
};
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 5/7] iio: accel: bma220: use iio_access_debugfs_regmap_reg()
2026-12-06 10:03 [PATCH v4 0/7] iio: debugfs register access through regmap in the core Rupesh Majhi
` (3 preceding siblings ...)
2026-12-06 10:03 ` [PATCH v4 4/7] iio: accel: adxl372: " Rupesh Majhi
@ 2026-12-06 10:03 ` 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
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, Andy Shevchenko
The debugfs callback only reads or writes the regmap of the parent
device, which is what the core helper does.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Tested-by: Petre Rodan <petre.rodan@subdimension.ro>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/accel/bma220_core.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 23eff578158c..4c595177688a 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -369,21 +369,11 @@ static int bma220_read_avail(struct iio_dev *indio_dev,
}
}
-static int bma220_reg_access(struct iio_dev *indio_dev, unsigned int reg,
- unsigned int writeval, unsigned int *readval)
-{
- struct bma220_data *data = iio_priv(indio_dev);
-
- if (readval)
- return regmap_read(data->regmap, reg, readval);
- return regmap_write(data->regmap, reg, writeval);
-}
-
static const struct iio_info bma220_info = {
.read_raw = bma220_read_raw,
.write_raw = bma220_write_raw,
.read_avail = bma220_read_avail,
- .debugfs_reg_access = &bma220_reg_access,
+ .debugfs_reg_access = iio_access_debugfs_regmap_reg,
};
static int bma220_reset(struct bma220_data *data, bool up)
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 6/7] iio: adc: ina2xx-adc: use iio_access_debugfs_regmap_reg()
2026-12-06 10:03 [PATCH v4 0/7] iio: debugfs register access through regmap in the core Rupesh Majhi
` (4 preceding siblings ...)
2026-12-06 10:03 ` [PATCH v4 5/7] iio: accel: bma220: " Rupesh Majhi
@ 2026-12-06 10:03 ` Rupesh Majhi
2026-12-06 10:03 ` [PATCH v4 7/7] iio: pressure: dps310: add debugfs register access Rupesh Majhi
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, Andy Shevchenko
The debugfs callback only reads or writes the regmap of the parent
device, which is what the core helper does.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/adc/ina2xx-adc.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index c412f5ed46a1..abaa85da9acc 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -895,17 +895,6 @@ static const struct iio_buffer_setup_ops ina2xx_setup_ops = {
.predisable = &ina2xx_buffer_disable,
};
-static int ina2xx_debug_reg(struct iio_dev *indio_dev,
- unsigned reg, unsigned writeval, unsigned *readval)
-{
- struct ina2xx_chip_info *chip = iio_priv(indio_dev);
-
- if (!readval)
- return regmap_write(chip->regmap, reg, writeval);
-
- return regmap_read(chip->regmap, reg, readval);
-}
-
/* Possible integration times for vshunt and vbus */
static IIO_CONST_ATTR_NAMED(ina219_integration_time_available,
integration_time_available,
@@ -950,14 +939,14 @@ static const struct iio_info ina219_info = {
.read_raw = ina2xx_read_raw,
.read_avail = ina2xx_read_avail,
.write_raw = ina2xx_write_raw,
- .debugfs_reg_access = ina2xx_debug_reg,
+ .debugfs_reg_access = iio_access_debugfs_regmap_reg,
};
static const struct iio_info ina226_info = {
.attrs = &ina226_attribute_group,
.read_raw = ina2xx_read_raw,
.write_raw = ina2xx_write_raw,
- .debugfs_reg_access = ina2xx_debug_reg,
+ .debugfs_reg_access = iio_access_debugfs_regmap_reg,
};
/* Initialize the configuration and calibration registers. */
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 7/7] iio: pressure: dps310: add debugfs register access
2026-12-06 10:03 [PATCH v4 0/7] iio: debugfs register access through regmap in the core Rupesh Majhi
` (5 preceding siblings ...)
2026-12-06 10:03 ` [PATCH v4 6/7] iio: adc: ina2xx-adc: " Rupesh Majhi
@ 2026-12-06 10:03 ` Rupesh Majhi
6 siblings, 0 replies; 8+ messages in thread
From: Rupesh Majhi @ 2026-12-06 10:03 UTC (permalink / raw)
To: Andy Shevchenko, Antoniu Miclaus, David Lechner, Eddie James,
Jonathan Cameron, Jonathan Corbet, Lucas Stankus, Marcelo Schmitt,
Michael Hennerich, Nuno Sá, Petre Rodan, Randy Dunlap,
Shuah Khan
Cc: linux, linux-doc, linux-iio, Rupesh Majhi, Andy Shevchenko
Expose the registers through direct_reg_access with the core regmap
helper, so the configuration and status registers can be looked at
through the driver's regmap instead of around it on the bus.
The access is not serialised with the driver beyond the regmap lock.
Reading INT_STS or a result register clears what the driver waits for,
as it would on the bus.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
---
drivers/iio/pressure/dps310.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 74d4111b5e29..ae132c188c9c 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -1557,6 +1557,7 @@ static const struct iio_info dps310_info = {
.write_raw = dps310_write_raw,
.hwfifo_set_watermark = dps310_hwfifo_set_watermark,
.hwfifo_flush_to_buffer = dps310_hwfifo_flush,
+ .debugfs_reg_access = iio_access_debugfs_regmap_reg,
};
static int dps310_probe(struct i2c_client *client)
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread