Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends
@ 2026-02-10 10:53 Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 1/6] iio: industrialio-backend: support backend capabilities Tomas Melin
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin, Andy Shevchenko

To facilitate backends with different set of features, add support
for defining capabilities provided by the backend. These capabilities
typically extend beyond a single operation and are therefore not
directly linked to if a single function call is implemented or not.
Furthermore, the capabilities determine if a certain set of operations
should be attempted, or skipped by the frontend. This way
the frontend driver can work with a minimalistic set of features and
still have the device in fully functional state.

Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
Changes in v7:
- Fix missing check for calibration for test mode off
- Add commit to clean up device usage in probe
- Add empty lines around calibration check
- Link to v6: https://patch.msgid.link/20260205-b4-ad9467-optional-backend-v6-0-7ca20c40c59a@vaisala.com

Changes in v6:
- Renamed CAP_ALWAYS_ON to CAP_ENABLE with inverted interpretation
- Renamed CAP_BUFFERING to CAP_BUFFER
- Added sd_adc_modulator capability commit (CAP_ENABLE)
- minor fixups in code and docs
- Link to v5: https://patch.msgid.link/20260130-b4-ad9467-optional-backend-v5-0-7da803ba7326@vaisala.com

Changes in v5:
- As per recommendation, use guard for whole block
- Typo fix in commit message and cover letter
- Link to v4: https://lore.kernel.org/r/20260121-b4-ad9467-optional-backend-v4-0-18d2c0d450cc@vaisala.com

Changes in v4:
- Readd CAP_BUFFERING and also add CAP_ALWAYS_ON to support backends
  that do not need explicit enable/disable
- Don't mix checks for eopnotsupp and caps. Prefer capability checking
  also for caps that map to single operation
- Move capability checking to top of call stack
- Revise iio_backend_has_caps to use bool signature and fixup semantics
- Amend documentation texts
- Add capability checks for axi-dac
- Drop two's complement patch from this series, already applied
- Link to v3: https://lore.kernel.org/r/20260114-b4-ad9467-optional-backend-v3-0-d2c84979d010@vaisala.com

Changes in v3:
- Reduce set of capabilities to only include calibration. The other
  ones propsed in V2 can be seen as subset of calibration, or single
  operation failing with opnotsupported
- Rename backends checking function
- Relocate caps field inside backend struct (pahole)
- Add kernel-docs
- Add capabilites for exisiting backend variants
- Link to v2: https://lore.kernel.org/r/20260113-b4-ad9467-optional-backend-v2-0-0a27e7e72f41@vaisala.com

Changes in v2:
- Added industrialio-backend capabilities feature
- Removed acceptance for fully optional backend, instead require atleast
  minimalistic backend to exist
- Switched to FIELD_MODIFY()
- Fixed kernel test robot reported failure for missing bitfield.h
- Link to v1: https://lore.kernel.org/r/20251216-b4-ad9467-optional-backend-v1-0-83e61531ef4d@vaisala.com

---
Tomas Melin (6):
      iio: industrialio-backend: support backend capabilities
      iio: adc: adi-axi-adc: define supported iio-backend capabilities
      iio: dac: adi-axi-dac: define supported iio-backend capabilities
      iio: adc: sd_adc_modulator: define supported iio-backend capabilities
      iio: adc: ad9467: simplify device pointer in probe
      iio: adc: ad9467: check for backend capabilities

 drivers/iio/adc/ad9467.c           | 95 +++++++++++++++++++++++---------------
 drivers/iio/adc/adi-axi-adc.c      |  5 ++
 drivers/iio/adc/sd_adc_modulator.c |  1 +
 drivers/iio/dac/adi-axi-dac.c      |  2 +
 drivers/iio/industrialio-backend.c | 16 +++++++
 include/linux/iio/backend.h        | 24 ++++++++++
 6 files changed, 105 insertions(+), 38 deletions(-)
---
base-commit: a7b10f0963c651a6406d958a5f64b9c5594f84da
change-id: 20251215-b4-ad9467-optional-backend-23f1099ee4d7

Best regards,
--  
Tomas Melin <tomas.melin@vaisala.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v7 1/6] iio: industrialio-backend: support backend capabilities
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
@ 2026-02-10 10:53 ` Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 2/6] iio: adc: adi-axi-adc: define supported iio-backend capabilities Tomas Melin
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin

Not all backends support the full set of capabilities provided by the
industrialio-backend framework. Capability bits can be used in frontends
and backends for checking for a certain feature set, or if using
related functions can be expected to fail.

Capability bits should be set by a compatible backend and provided when
registering the backend.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
 drivers/iio/industrialio-backend.c | 16 ++++++++++++++++
 include/linux/iio/backend.h        | 24 ++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index 447b694d6d5f..1afd00763da9 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -56,6 +56,7 @@ struct iio_backend {
 	void *priv;
 	const char *name;
 	unsigned int cached_reg_addr;
+	u32 caps;
 	/*
 	 * This index is relative to the frontend. Meaning that for
 	 * frontends with multiple backends, this will be the index of this
@@ -774,6 +775,20 @@ int iio_backend_extend_chan_spec(struct iio_backend *back,
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_extend_chan_spec, "IIO_BACKEND");
 
+/**
+ * iio_backend_has_caps - Check if backend has specific capabilities
+ * @back: Backend device
+ * @caps: Capabilities to check
+ *
+ * RETURNS:
+ * True if backend has all the requested capabilities, false otherwise.
+ */
+bool iio_backend_has_caps(struct iio_backend *back, u32 caps)
+{
+	return (back->caps & caps) == caps;
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_has_caps, "IIO_BACKEND");
+
 static void iio_backend_release(void *arg)
 {
 	struct iio_backend *back = arg;
@@ -1114,6 +1129,7 @@ int devm_iio_backend_register(struct device *dev,
 
 	back->ops = info->ops;
 	back->name = info->name;
+	back->caps = info->caps;
 	back->owner = dev->driver->owner;
 	back->dev = dev;
 	back->priv = priv;
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index 7f815f3fed6a..4d15c2a9802c 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -84,6 +84,27 @@ enum iio_backend_filter_type {
 	IIO_BACKEND_FILTER_TYPE_MAX
 };
 
+/**
+ * enum iio_backend_capabilities - Backend capabilities
+ * Backend capabilities can be used by frontends to check if a given
+ * functionality is supported by the backend. This is useful for frontend
+ * devices which are expected to work with alternative backend
+ * implementations. Capabilities are loosely coupled with operations,
+ * meaning that a capability requires certain operations to be implemented
+ * by the backend. A capability might be mapped to a single operation or
+ * multiple operations.
+ *
+ * @IIO_BACKEND_CAP_CALIBRATION: Backend supports digital interface
+ * calibration. Calibration procedure is device specific.
+ * @IIO_BACKEND_CAP_BUFFER: Support for IIO buffer interface.
+ * @IIO_BACKEND_CAP_ENABLE: Backend can be explicitly enabled/disabled.
+ */
+enum iio_backend_capabilities {
+	IIO_BACKEND_CAP_CALIBRATION = BIT(0),
+	IIO_BACKEND_CAP_BUFFER = BIT(1),
+	IIO_BACKEND_CAP_ENABLE = BIT(2),
+};
+
 /**
  * struct iio_backend_ops - operations structure for an iio_backend
  * @enable: Enable backend.
@@ -179,10 +200,12 @@ struct iio_backend_ops {
  * struct iio_backend_info - info structure for an iio_backend
  * @name: Backend name.
  * @ops: Backend operations.
+ * @caps: Backend capabilities. (bitmask of enum iio_backend_capabilities).
  */
 struct iio_backend_info {
 	const char *name;
 	const struct iio_backend_ops *ops;
+	u32 caps;
 };
 
 int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
@@ -235,6 +258,7 @@ int iio_backend_read_raw(struct iio_backend *back,
 			 long mask);
 int iio_backend_extend_chan_spec(struct iio_backend *back,
 				 struct iio_chan_spec *chan);
+bool iio_backend_has_caps(struct iio_backend *back, u32 caps);
 void *iio_backend_get_priv(const struct iio_backend *conv);
 struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
 struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev,

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v7 2/6] iio: adc: adi-axi-adc: define supported iio-backend capabilities
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 1/6] iio: industrialio-backend: support backend capabilities Tomas Melin
@ 2026-02-10 10:53 ` Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 3/6] iio: dac: adi-axi-dac: " Tomas Melin
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin

axi-adc and axi-ad485x backend variants provide calibration support,
whereas the axi-ad408x does not. Set accordingly.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
 drivers/iio/adc/adi-axi-adc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index 14fa4238c2b9..a27745695b7f 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -626,6 +626,8 @@ static const struct iio_backend_ops adi_axi_adc_ops = {
 static const struct iio_backend_info adi_axi_adc_generic = {
 	.name = "axi-adc",
 	.ops = &adi_axi_adc_ops,
+	.caps = IIO_BACKEND_CAP_CALIBRATION | IIO_BACKEND_CAP_BUFFER |
+		IIO_BACKEND_CAP_ENABLE,
 };
 
 static const struct iio_backend_ops adi_ad485x_ops = {
@@ -650,6 +652,8 @@ static const struct iio_backend_ops adi_ad485x_ops = {
 static const struct iio_backend_info axi_ad485x = {
 	.name = "axi-ad485x",
 	.ops = &adi_ad485x_ops,
+	.caps = IIO_BACKEND_CAP_CALIBRATION | IIO_BACKEND_CAP_BUFFER |
+		IIO_BACKEND_CAP_ENABLE,
 };
 
 static const struct iio_backend_ops adi_ad408x_ops = {
@@ -670,6 +674,7 @@ static const struct iio_backend_ops adi_ad408x_ops = {
 static const struct iio_backend_info axi_ad408x = {
 	.name = "axi-ad408x",
 	.ops = &adi_ad408x_ops,
+	.caps = IIO_BACKEND_CAP_BUFFER | IIO_BACKEND_CAP_ENABLE,
 };
 
 static int adi_axi_adc_probe(struct platform_device *pdev)

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v7 3/6] iio: dac: adi-axi-dac: define supported iio-backend capabilities
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 1/6] iio: industrialio-backend: support backend capabilities Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 2/6] iio: adc: adi-axi-adc: define supported iio-backend capabilities Tomas Melin
@ 2026-02-10 10:53 ` Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 4/6] iio: adc: sd_adc_modulator: " Tomas Melin
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin

Backends support the buffer/enable capabilities so advertise it
while registering in case a frontend makes checks for it.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
 drivers/iio/dac/adi-axi-dac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index 0d525272a8a8..b02498aed43e 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -869,11 +869,13 @@ static const struct iio_backend_ops axi_ad3552r_ops = {
 static const struct iio_backend_info axi_dac_generic = {
 	.name = "axi-dac",
 	.ops = &axi_dac_generic_ops,
+	.caps = IIO_BACKEND_CAP_BUFFER | IIO_BACKEND_CAP_ENABLE,
 };
 
 static const struct iio_backend_info axi_ad3552r = {
 	.name = "axi-ad3552r",
 	.ops = &axi_ad3552r_ops,
+	.caps = IIO_BACKEND_CAP_BUFFER | IIO_BACKEND_CAP_ENABLE,
 };
 
 static const struct regmap_config axi_dac_regmap_config = {

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v7 4/6] iio: adc: sd_adc_modulator: define supported iio-backend capabilities
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
                   ` (2 preceding siblings ...)
  2026-02-10 10:53 ` [PATCH v7 3/6] iio: dac: adi-axi-dac: " Tomas Melin
@ 2026-02-10 10:53 ` Tomas Melin
  2026-02-10 10:53 ` [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe Tomas Melin
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin

This backend supports the added CAP_ENABLE capability.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
 drivers/iio/adc/sd_adc_modulator.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/adc/sd_adc_modulator.c b/drivers/iio/adc/sd_adc_modulator.c
index 9f7a75168aac..218117c45ec8 100644
--- a/drivers/iio/adc/sd_adc_modulator.c
+++ b/drivers/iio/adc/sd_adc_modulator.c
@@ -77,6 +77,7 @@ static const struct iio_backend_ops sd_backend_ops = {
 static const struct iio_backend_info sd_backend_info = {
 	.name = "sd-modulator",
 	.ops = &sd_backend_ops,
+	.caps = IIO_BACKEND_CAP_ENABLE,
 };
 
 static int iio_sd_mod_register(struct platform_device *pdev)

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
                   ` (3 preceding siblings ...)
  2026-02-10 10:53 ` [PATCH v7 4/6] iio: adc: sd_adc_modulator: " Tomas Melin
@ 2026-02-10 10:53 ` Tomas Melin
  2026-02-10 12:11   ` Nuno Sá
  2026-02-10 15:00   ` Andy Shevchenko
  2026-02-10 10:53 ` [PATCH v7 6/6] iio: adc: ad9467: check for backend capabilities Tomas Melin
  2026-02-14 15:57 ` [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Jonathan Cameron
  6 siblings, 2 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin, Andy Shevchenko

Create alias for the device pointer to simplify referencing
and keeping syntax and column width shorter.

Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
 drivers/iio/adc/ad9467.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index 59c3fa3bcc9b..ae9139290c22 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -1283,12 +1283,13 @@ static void ad9467_debugfs_init(struct iio_dev *indio_dev)
 
 static int ad9467_probe(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
 	struct iio_dev *indio_dev;
 	struct ad9467_state *st;
 	unsigned int id;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -1303,16 +1304,16 @@ static int ad9467_probe(struct spi_device *spi)
 	if (AD9467_CAN_INVERT(st))
 		st->calib_map_size *= 2;
 
-	st->clk = devm_clk_get_enabled(&spi->dev, "adc-clk");
+	st->clk = devm_clk_get_enabled(dev, "adc-clk");
 	if (IS_ERR(st->clk))
 		return PTR_ERR(st->clk);
 
-	st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
+	st->pwrdown_gpio = devm_gpiod_get_optional(dev, "powerdown",
 						   GPIOD_OUT_LOW);
 	if (IS_ERR(st->pwrdown_gpio))
 		return PTR_ERR(st->pwrdown_gpio);
 
-	ret = ad9467_reset(&spi->dev);
+	ret = ad9467_reset(dev);
 	if (ret)
 		return ret;
 
@@ -1322,8 +1323,8 @@ static int ad9467_probe(struct spi_device *spi)
 
 	id = ad9467_spi_read(st, AN877_ADC_REG_CHIP_ID);
 	if (id != st->info->id) {
-		dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n",
-			id, st->info->id);
+		dev_err(dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", id,
+			st->info->id);
 		return -ENODEV;
 	}
 
@@ -1339,11 +1340,11 @@ static int ad9467_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = devm_iio_backend_request_buffer(&spi->dev, st->back, indio_dev);
+	ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
 	if (ret)
 		return ret;
 
-	ret = devm_iio_backend_enable(&spi->dev, st->back);
+	ret = devm_iio_backend_enable(dev, st->back);
 	if (ret)
 		return ret;
 
@@ -1351,7 +1352,7 @@ static int ad9467_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = devm_iio_device_register(&spi->dev, indio_dev);
+	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret)
 		return ret;
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v7 6/6] iio: adc: ad9467: check for backend capabilities
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
                   ` (4 preceding siblings ...)
  2026-02-10 10:53 ` [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe Tomas Melin
@ 2026-02-10 10:53 ` Tomas Melin
  2026-02-14 15:57 ` [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Jonathan Cameron
  6 siblings, 0 replies; 10+ messages in thread
From: Tomas Melin @ 2026-02-10 10:53 UTC (permalink / raw)
  To: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Tomas Melin

Add capability checks for operation with backends that do not necessarily
support full set of features, but are otherwise compatible with the device.
This ensures a fully functional device, but with limited capabilities.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
 drivers/iio/adc/ad9467.c | 80 +++++++++++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
index ae9139290c22..fbdacdc2c823 100644
--- a/drivers/iio/adc/ad9467.c
+++ b/drivers/iio/adc/ad9467.c
@@ -913,7 +913,11 @@ static int __ad9467_update_clock(struct ad9467_state *st, long r_clk)
 		return ret;
 
 	guard(mutex)(&st->lock);
-	return ad9467_calibrate(st);
+
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION))
+		return ad9467_calibrate(st);
+
+	return 0;
 }
 
 static int ad9467_write_raw(struct iio_dev *indio_dev,
@@ -1119,12 +1123,15 @@ static ssize_t ad9467_chan_test_mode_read(struct file *file,
 		len = scnprintf(buf, sizeof(buf), "Running \"%s\" Test:\n\t",
 				ad9467_test_modes[chan->mode]);
 
-		ret = iio_backend_debugfs_print_chan_status(st->back, chan->idx,
-							    buf + len,
-							    sizeof(buf) - len);
-		if (ret < 0)
-			return ret;
-		len += ret;
+		if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) {
+			ret = iio_backend_debugfs_print_chan_status(st->back,
+								    chan->idx,
+								    buf + len,
+								    sizeof(buf) - len);
+			if (ret < 0)
+				return ret;
+			len += ret;
+		}
 	} else if (chan->mode == AN877_ADC_TESTMODE_OFF) {
 		len = scnprintf(buf, sizeof(buf), "No test Running...\n");
 	} else {
@@ -1163,11 +1170,13 @@ static ssize_t ad9467_chan_test_mode_write(struct file *file,
 	if (mode == AN877_ADC_TESTMODE_OFF) {
 		unsigned int out_mode;
 
-		if (chan->mode == AN877_ADC_TESTMODE_PN9_SEQ ||
-		    chan->mode == AN877_ADC_TESTMODE_PN23_SEQ) {
-			ret = ad9467_backend_testmode_off(st, chan->idx);
-			if (ret)
-				return ret;
+		if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) {
+			if (chan->mode == AN877_ADC_TESTMODE_PN9_SEQ ||
+			    chan->mode == AN877_ADC_TESTMODE_PN23_SEQ) {
+				ret = ad9467_backend_testmode_off(st, chan->idx);
+				if (ret)
+					return ret;
+			}
 		}
 
 		ret = ad9467_testmode_set(st, chan->idx, mode);
@@ -1188,16 +1197,18 @@ static ssize_t ad9467_chan_test_mode_write(struct file *file,
 			return ret;
 
 		/*  some patterns have a backend matching monitoring block */
-		if (mode == AN877_ADC_TESTMODE_PN9_SEQ) {
-			ret = ad9467_backend_testmode_on(st, chan->idx,
+		if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) {
+			if (mode == AN877_ADC_TESTMODE_PN9_SEQ) {
+				ret = ad9467_backend_testmode_on(st, chan->idx,
 							 IIO_BACKEND_ADI_PRBS_9A);
-			if (ret)
-				return ret;
-		} else if (mode == AN877_ADC_TESTMODE_PN23_SEQ) {
-			ret = ad9467_backend_testmode_on(st, chan->idx,
+				if (ret)
+					return ret;
+			} else if (mode == AN877_ADC_TESTMODE_PN23_SEQ) {
+				ret = ad9467_backend_testmode_on(st, chan->idx,
 							 IIO_BACKEND_ADI_PRBS_23A);
-			if (ret)
-				return ret;
+				if (ret)
+					return ret;
+			}
 		}
 	}
 
@@ -1263,8 +1274,9 @@ static void ad9467_debugfs_init(struct iio_dev *indio_dev)
 	if (!st->chan_test)
 		return;
 
-	debugfs_create_file("calibration_table_dump", 0400, d, st,
-			    &ad9467_calib_table_fops);
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION))
+		debugfs_create_file("calibration_table_dump", 0400, d, st,
+				    &ad9467_calib_table_fops);
 
 	for (chan = 0; chan < st->info->num_channels; chan++) {
 		snprintf(attr_name, sizeof(attr_name), "in_voltage%u_test_mode",
@@ -1340,17 +1352,23 @@ static int ad9467_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
-	ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
-	if (ret)
-		return ret;
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_BUFFER)) {
+		ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
+		if (ret)
+			return ret;
+	}
 
-	ret = devm_iio_backend_enable(dev, st->back);
-	if (ret)
-		return ret;
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_ENABLE)) {
+		ret = devm_iio_backend_enable(dev, st->back);
+		if (ret)
+			return ret;
+	}
 
-	ret = ad9467_calibrate(st);
-	if (ret)
-		return ret;
+	if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) {
+		ret = ad9467_calibrate(st);
+		if (ret)
+			return ret;
+	}
 
 	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret)

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe
  2026-02-10 10:53 ` [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe Tomas Melin
@ 2026-02-10 12:11   ` Nuno Sá
  2026-02-10 15:00   ` Andy Shevchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Nuno Sá @ 2026-02-10 12:11 UTC (permalink / raw)
  To: Tomas Melin, Michael Hennerich, Nuno Sa, Lars-Peter Clausen,
	Jonathan Cameron, David Lechner, Andy Shevchenko, Olivier Moysan
  Cc: linux-iio, linux-kernel, Andy Shevchenko

On Tue, 2026-02-10 at 10:53 +0000, Tomas Melin wrote:
> Create alias for the device pointer to simplify referencing
> and keeping syntax and column width shorter.
> 
> Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/adc/ad9467.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
> index 59c3fa3bcc9b..ae9139290c22 100644
> --- a/drivers/iio/adc/ad9467.c
> +++ b/drivers/iio/adc/ad9467.c
> @@ -1283,12 +1283,13 @@ static void ad9467_debugfs_init(struct iio_dev *indio_dev)
>  
>  static int ad9467_probe(struct spi_device *spi)
>  {
> +	struct device *dev = &spi->dev;
>  	struct iio_dev *indio_dev;
>  	struct ad9467_state *st;
>  	unsigned int id;
>  	int ret;
>  
> -	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
> @@ -1303,16 +1304,16 @@ static int ad9467_probe(struct spi_device *spi)
>  	if (AD9467_CAN_INVERT(st))
>  		st->calib_map_size *= 2;
>  
> -	st->clk = devm_clk_get_enabled(&spi->dev, "adc-clk");
> +	st->clk = devm_clk_get_enabled(dev, "adc-clk");
>  	if (IS_ERR(st->clk))
>  		return PTR_ERR(st->clk);
>  
> -	st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
> +	st->pwrdown_gpio = devm_gpiod_get_optional(dev, "powerdown",
>  						   GPIOD_OUT_LOW);
>  	if (IS_ERR(st->pwrdown_gpio))
>  		return PTR_ERR(st->pwrdown_gpio);
>  
> -	ret = ad9467_reset(&spi->dev);
> +	ret = ad9467_reset(dev);
>  	if (ret)
>  		return ret;
>  
> @@ -1322,8 +1323,8 @@ static int ad9467_probe(struct spi_device *spi)
>  
>  	id = ad9467_spi_read(st, AN877_ADC_REG_CHIP_ID);
>  	if (id != st->info->id) {
> -		dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n",
> -			id, st->info->id);
> +		dev_err(dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", id,
> +			st->info->id);
>  		return -ENODEV;
>  	}
>  
> @@ -1339,11 +1340,11 @@ static int ad9467_probe(struct spi_device *spi)
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_iio_backend_request_buffer(&spi->dev, st->back, indio_dev);
> +	ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev);
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_iio_backend_enable(&spi->dev, st->back);
> +	ret = devm_iio_backend_enable(dev, st->back);
>  	if (ret)
>  		return ret;
>  
> @@ -1351,7 +1352,7 @@ static int ad9467_probe(struct spi_device *spi)
>  	if (ret)
>  		return ret;
>  
> -	ret = devm_iio_device_register(&spi->dev, indio_dev);
> +	ret = devm_iio_device_register(dev, indio_dev);
>  	if (ret)
>  		return ret;
>  

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe
  2026-02-10 10:53 ` [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe Tomas Melin
  2026-02-10 12:11   ` Nuno Sá
@ 2026-02-10 15:00   ` Andy Shevchenko
  1 sibling, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2026-02-10 15:00 UTC (permalink / raw)
  To: Tomas Melin
  Cc: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, Jonathan Cameron,
	David Lechner, Andy Shevchenko, Olivier Moysan, linux-iio,
	linux-kernel

On Tue, Feb 10, 2026 at 10:53:38AM +0000, Tomas Melin wrote:
> Create alias for the device pointer to simplify referencing
> and keeping syntax and column width shorter.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

Some nit-picks in case it will be a new version or Jonathan will be keen to
tweak it.

...

> -	st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
> +	st->pwrdown_gpio = devm_gpiod_get_optional(dev, "powerdown",
>  						   GPIOD_OUT_LOW);

I would dare to make it a single line.

>  	if (IS_ERR(st->pwrdown_gpio))
>  		return PTR_ERR(st->pwrdown_gpio);

...

> -		dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n",
> -			id, st->info->id);
> +		dev_err(dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", id,

> +			st->info->id);

I would not touch the second line as it makes a logical split.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends
  2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
                   ` (5 preceding siblings ...)
  2026-02-10 10:53 ` [PATCH v7 6/6] iio: adc: ad9467: check for backend capabilities Tomas Melin
@ 2026-02-14 15:57 ` Jonathan Cameron
  6 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2026-02-14 15:57 UTC (permalink / raw)
  To: Tomas Melin
  Cc: Michael Hennerich, Nuno Sa, Lars-Peter Clausen, David Lechner,
	Andy Shevchenko, Olivier Moysan, linux-iio, linux-kernel,
	Andy Shevchenko

On Tue, 10 Feb 2026 10:53:33 +0000
Tomas Melin <tomas.melin@vaisala.com> wrote:

> To facilitate backends with different set of features, add support
> for defining capabilities provided by the backend. These capabilities
> typically extend beyond a single operation and are therefore not
> directly linked to if a single function call is implemented or not.
> Furthermore, the capabilities determine if a certain set of operations
> should be attempted, or skipped by the frontend. This way
> the frontend driver can work with a minimalistic set of features and
> still have the device in fully functional state.
> 
> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
Hi Tomas,

I made the two tweaks Andy suggested to patch 5 and applied the
whole series to my temporary IIO branch that gets pushed out as testing.
I'll be rebasing that on rc1 once available.

Jonathan

> ---
> Changes in v7:
> - Fix missing check for calibration for test mode off
> - Add commit to clean up device usage in probe
> - Add empty lines around calibration check
> - Link to v6: https://patch.msgid.link/20260205-b4-ad9467-optional-backend-v6-0-7ca20c40c59a@vaisala.com
> 
> Changes in v6:
> - Renamed CAP_ALWAYS_ON to CAP_ENABLE with inverted interpretation
> - Renamed CAP_BUFFERING to CAP_BUFFER
> - Added sd_adc_modulator capability commit (CAP_ENABLE)
> - minor fixups in code and docs
> - Link to v5: https://patch.msgid.link/20260130-b4-ad9467-optional-backend-v5-0-7da803ba7326@vaisala.com
> 
> Changes in v5:
> - As per recommendation, use guard for whole block
> - Typo fix in commit message and cover letter
> - Link to v4: https://lore.kernel.org/r/20260121-b4-ad9467-optional-backend-v4-0-18d2c0d450cc@vaisala.com
> 
> Changes in v4:
> - Readd CAP_BUFFERING and also add CAP_ALWAYS_ON to support backends
>   that do not need explicit enable/disable
> - Don't mix checks for eopnotsupp and caps. Prefer capability checking
>   also for caps that map to single operation
> - Move capability checking to top of call stack
> - Revise iio_backend_has_caps to use bool signature and fixup semantics
> - Amend documentation texts
> - Add capability checks for axi-dac
> - Drop two's complement patch from this series, already applied
> - Link to v3: https://lore.kernel.org/r/20260114-b4-ad9467-optional-backend-v3-0-d2c84979d010@vaisala.com
> 
> Changes in v3:
> - Reduce set of capabilities to only include calibration. The other
>   ones propsed in V2 can be seen as subset of calibration, or single
>   operation failing with opnotsupported
> - Rename backends checking function
> - Relocate caps field inside backend struct (pahole)
> - Add kernel-docs
> - Add capabilites for exisiting backend variants
> - Link to v2: https://lore.kernel.org/r/20260113-b4-ad9467-optional-backend-v2-0-0a27e7e72f41@vaisala.com
> 
> Changes in v2:
> - Added industrialio-backend capabilities feature
> - Removed acceptance for fully optional backend, instead require atleast
>   minimalistic backend to exist
> - Switched to FIELD_MODIFY()
> - Fixed kernel test robot reported failure for missing bitfield.h
> - Link to v1: https://lore.kernel.org/r/20251216-b4-ad9467-optional-backend-v1-0-83e61531ef4d@vaisala.com
> 
> ---
> Tomas Melin (6):
>       iio: industrialio-backend: support backend capabilities
>       iio: adc: adi-axi-adc: define supported iio-backend capabilities
>       iio: dac: adi-axi-dac: define supported iio-backend capabilities
>       iio: adc: sd_adc_modulator: define supported iio-backend capabilities
>       iio: adc: ad9467: simplify device pointer in probe
>       iio: adc: ad9467: check for backend capabilities
> 
>  drivers/iio/adc/ad9467.c           | 95 +++++++++++++++++++++++---------------
>  drivers/iio/adc/adi-axi-adc.c      |  5 ++
>  drivers/iio/adc/sd_adc_modulator.c |  1 +
>  drivers/iio/dac/adi-axi-dac.c      |  2 +
>  drivers/iio/industrialio-backend.c | 16 +++++++
>  include/linux/iio/backend.h        | 24 ++++++++++
>  6 files changed, 105 insertions(+), 38 deletions(-)
> ---
> base-commit: a7b10f0963c651a6406d958a5f64b9c5594f84da
> change-id: 20251215-b4-ad9467-optional-backend-23f1099ee4d7
> 
> Best regards,
> --  
> Tomas Melin <tomas.melin@vaisala.com>
> 
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-02-14 15:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-10 10:53 [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Tomas Melin
2026-02-10 10:53 ` [PATCH v7 1/6] iio: industrialio-backend: support backend capabilities Tomas Melin
2026-02-10 10:53 ` [PATCH v7 2/6] iio: adc: adi-axi-adc: define supported iio-backend capabilities Tomas Melin
2026-02-10 10:53 ` [PATCH v7 3/6] iio: dac: adi-axi-dac: " Tomas Melin
2026-02-10 10:53 ` [PATCH v7 4/6] iio: adc: sd_adc_modulator: " Tomas Melin
2026-02-10 10:53 ` [PATCH v7 5/6] iio: adc: ad9467: simplify device pointer in probe Tomas Melin
2026-02-10 12:11   ` Nuno Sá
2026-02-10 15:00   ` Andy Shevchenko
2026-02-10 10:53 ` [PATCH v7 6/6] iio: adc: ad9467: check for backend capabilities Tomas Melin
2026-02-14 15:57 ` [PATCH v7 0/6] iio: adc: ad9467: Support alternative backends Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox