mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] iio: adc: ad7124: support boards without RDY interrupt
@ 2026-11-20 11:26 ILYAS NHASSE via B4 Relay
  2026-11-20 11:26 ` [PATCH 1/2] dt-bindings: iio: adc: adi,ad7124: make interrupts optional ILYAS NHASSE via B4 Relay
  2026-11-20 11:26 ` [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt ILYAS NHASSE via B4 Relay
  0 siblings, 2 replies; 4+ messages in thread
From: ILYAS NHASSE via B4 Relay @ 2026-11-20 11:26 UTC (permalink / raw)
  To: Nuno Sá,
	Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Marcelo Schmitt
  Cc: linux, linux-iio, devicetree, linux-kernel, ILYAS NHASSE

Boards may wire the AD7124 DOUT/RDY pin to the SPI MISO line only, for
instance when the ADC sits behind a digital isolator that carries just
the SPI signals. Such boards can't use the driver today: the binding
requires an interrupt, and the sigma-delta core can't probe without one.

The end of a conversion or calibration is also reported by the RDY bit
of the status register. Analog Devices' no-OS driver waits for AD7124
conversions and calibrations this way (ad7124_wait_for_conv_ready()).

Patch 1 makes the interrupt optional in the AD7124 binding.
Patch 2 lets the sigma-delta core poll the RDY bit when there is no
interrupt, for single conversions and calibrations. These devices then
only support direct mode, as the RDY interrupt is the only trigger of
the triggered buffer. No AD7124 driver change is needed.

The polling applies to every device with registers, but only the AD7124
binding is relaxed: the other bindings still require the interrupt, so
boards using them are not affected.

Open questions:
- Poll period: 20 ms, a fifth of a conversion at the AD7124 default
  10 SPS. On our board the SPI clock runs at about 6 kHz through the
  isolator and the controller uses PIO, so each status read costs about
  2.7 ms of CPU time and the period directly sets the CPU load during a
  conversion.
- Should polling rather be opt-in per driver, with a flag in
  struct ad_sigma_delta_info?

Tested on a TI J721E based board with four AD7124-8 on one SPI bus
behind an isolator, without RDY interrupt: direct reads of all channels
with an equivalent implementation on a v6.12 based kernel. The polled
calibration path is build-tested only.

---
ILYAS NHASSE (2):
      dt-bindings: iio: adc: adi,ad7124: make interrupts optional
      iio: adc: ad_sigma_delta: support devices without RDY interrupt

 .../devicetree/bindings/iio/adc/adi,ad7124.yaml    |  1 -
 drivers/iio/adc/ad_sigma_delta.c                   | 47 +++++++++++++++++++---
 2 files changed, 41 insertions(+), 7 deletions(-)
---
base-commit: 7d80b4b383bc53b48abd3a30ca4a91cdab568bfa
change-id: 20261030-ad7124-no-irq-ded325dea4ac

Best regards,
--  
ILYAS NHASSE <ilyas.nhasse@skf.com>



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

* [PATCH 1/2] dt-bindings: iio: adc: adi,ad7124: make interrupts optional
  2026-11-20 11:26 [PATCH 0/2] iio: adc: ad7124: support boards without RDY interrupt ILYAS NHASSE via B4 Relay
@ 2026-11-20 11:26 ` ILYAS NHASSE via B4 Relay
  2026-11-20 11:26 ` [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt ILYAS NHASSE via B4 Relay
  1 sibling, 0 replies; 4+ messages in thread
From: ILYAS NHASSE via B4 Relay @ 2026-11-20 11:26 UTC (permalink / raw)
  To: Nuno Sá,
	Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Marcelo Schmitt
  Cc: linux, linux-iio, devicetree, linux-kernel, ILYAS NHASSE

From: ILYAS NHASSE <ilyas.nhasse@skf.com>

The AD7124 signals the end of a conversion on its DOUT/RDY pin, which is
also the SPI MISO line. Using it as an interrupt requires the board to
route that pin to an interrupt-capable input as well, which is not always
possible, e.g. when the ADC sits behind a digital isolator that only
carries the SPI signals.

The end of a conversion can also be read from the RDY bit of the status
register, so the interrupt is not needed to operate the device. Drop it
from the required properties.

Signed-off-by: ILYAS NHASSE <ilyas.nhasse@skf.com>
---
 Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
index 2e3f84db6..875f46477 100644
--- a/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7124.yaml
@@ -76,7 +76,6 @@ properties:
 required:
   - compatible
   - reg
-  - interrupts
 
 # Can't have both clock input and output at the same time.
 not:

-- 
2.43.0



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

* [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt
  2026-11-20 11:26 [PATCH 0/2] iio: adc: ad7124: support boards without RDY interrupt ILYAS NHASSE via B4 Relay
  2026-11-20 11:26 ` [PATCH 1/2] dt-bindings: iio: adc: adi,ad7124: make interrupts optional ILYAS NHASSE via B4 Relay
@ 2026-11-20 11:26 ` ILYAS NHASSE via B4 Relay
  2026-11-20 12:24   ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: ILYAS NHASSE via B4 Relay @ 2026-11-20 11:26 UTC (permalink / raw)
  To: Nuno Sá,
	Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Marcelo Schmitt
  Cc: linux, linux-iio, devicetree, linux-kernel, ILYAS NHASSE

From: ILYAS NHASSE <ilyas.nhasse@skf.com>

The end of a conversion or of a calibration is detected with the DOUT/RDY
interrupt, so a device whose DOUT/RDY pin is only wired to the SPI MISO
line can't be used, although its status register reports the same event
in its RDY bit.

For devices with registers but without interrupt, wait for RDY in
ad_sigma_delta_single_conversion() and ad_sd_calibrate() by polling the
status register, with the same timeouts as the interrupt-driven waits.
As with the interrupt, the bus stays locked and CS asserted during the
wait, and ad_sigma_delta_clear_pending_event() has drained any older
result beforehand, so the RDY bit seen by the poll belongs to the
operation just started. A timeout is reported as -ETIMEDOUT.

The RDY interrupt is the only trigger source of the triggered buffer, so
devm_ad_sd_setup_buffer_and_trigger() sets nothing up for these devices
and they only support direct mode. Registerless devices still require
the interrupt.

Each poll is a SPI transfer, so poll every 20 ms: this delays the
detection of the end of a conversion by at most one period, a fifth of
a conversion at the AD7124 default output data rate of 10 SPS, while
keeping the bus traffic, and the CPU time of PIO SPI transfers, low.

Nothing changes for devices with an interrupt.

Signed-off-by: ILYAS NHASSE <ilyas.nhasse@skf.com>
---
 drivers/iio/adc/ad_sigma_delta.c | 47 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 119ddc5a1..546135995 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -17,6 +17,7 @@
 #include <linux/find.h>
 #include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/property.h>
 #include <linux/slab.h>
@@ -43,6 +44,8 @@
 
 #define AD_SD_REG_STATUS_RDY	0x80
 
+#define AD_SD_POLL_PERIOD_US	(20 * USEC_PER_MSEC)
+
 /**
  * ad_sd_set_comm() - Set communications register
  *
@@ -347,6 +350,22 @@ static int ad_sigma_delta_clear_pending_event(struct ad_sigma_delta *sigma_delta
 	return ret;
 }
 
+static int ad_sd_poll_rdy(struct ad_sigma_delta *sigma_delta,
+			  unsigned int timeout_us)
+{
+	unsigned int status;
+	int ret, ret_read;
+
+	ret = read_poll_timeout(ad_sd_read_reg, ret_read,
+				ret_read || !(status & AD_SD_REG_STATUS_RDY),
+				AD_SD_POLL_PERIOD_US, timeout_us, false,
+				sigma_delta, AD_SD_REG_STATUS, 1, &status);
+	if (ret)
+		return ret;
+
+	return ret_read;
+}
+
 int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 	unsigned int mode, unsigned int channel)
 {
@@ -370,6 +389,11 @@ int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
 	if (ret < 0)
 		goto out;
 
+	if (!sigma_delta->irq_line) {
+		ret = ad_sd_poll_rdy(sigma_delta, 2 * USEC_PER_SEC);
+		goto out;
+	}
+
 	ad_sd_enable_irq(sigma_delta);
 	time_left = wait_for_completion_timeout(&sigma_delta->completion, 2 * HZ);
 	if (time_left == 0) {
@@ -447,12 +471,16 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 
 	ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE);
 
-	ad_sd_enable_irq(sigma_delta);
-	ret = wait_for_completion_interruptible_timeout(
-			&sigma_delta->completion, HZ);
+	if (sigma_delta->irq_line) {
+		ad_sd_enable_irq(sigma_delta);
+		ret = wait_for_completion_interruptible_timeout(&sigma_delta->completion,
+								HZ);
 
-	if (ret == 0)
-		ret = -EIO;
+		if (ret == 0)
+			ret = -EIO;
+	} else {
+		ret = ad_sd_poll_rdy(sigma_delta, USEC_PER_SEC);
+	}
 	if (ret < 0)
 		goto out;
 
@@ -466,7 +494,8 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
 		&raw_sample);
 
 out:
-	ad_sd_disable_irq(sigma_delta);
+	if (sigma_delta->irq_line)
+		ad_sd_disable_irq(sigma_delta);
 
 out_unlock:
 	sigma_delta->keep_cs_asserted = false;
@@ -816,12 +845,18 @@ static int devm_ad_sd_probe_trigger(struct device *dev, struct iio_dev *indio_de
  * devm_ad_sd_setup_buffer_and_trigger() - Device-managed buffer & trigger setup
  * @dev: Device object to which to bind the life-time of the resources attached
  * @indio_dev: The IIO device
+ *
+ * Nothing is set up for devices with registers but without R̅D̅Y̅ interrupt:
+ * they only support direct mode, with polled conversions.
  */
 int devm_ad_sd_setup_buffer_and_trigger(struct device *dev, struct iio_dev *indio_dev)
 {
 	struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
 	int ret;
 
+	if (!sigma_delta->irq_line && sigma_delta->info->has_registers)
+		return 0;
+
 	sigma_delta->slots = devm_kcalloc(dev, sigma_delta->num_slots,
 					  sizeof(*sigma_delta->slots), GFP_KERNEL);
 	if (!sigma_delta->slots)

-- 
2.43.0



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

* Re: [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt
  2026-11-20 11:26 ` [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt ILYAS NHASSE via B4 Relay
@ 2026-11-20 12:24   ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-11-20 12:24 UTC (permalink / raw)
  To: ilyas.nhasse
  Cc: Nuno Sá,
	Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Marcelo Schmitt, linux, linux-iio, devicetree, linux-kernel

On Fri, Nov 20, 2026 at 12:26:48PM +0100, ILYAS NHASSE via B4 Relay wrote:
> 
> The end of a conversion or of a calibration is detected with the DOUT/RDY
> interrupt, so a device whose DOUT/RDY pin is only wired to the SPI MISO
> line can't be used, although its status register reports the same event
> in its RDY bit.
> 
> For devices with registers but without interrupt, wait for RDY in
> ad_sigma_delta_single_conversion() and ad_sd_calibrate() by polling the
> status register, with the same timeouts as the interrupt-driven waits.
> As with the interrupt, the bus stays locked and CS asserted during the
> wait, and ad_sigma_delta_clear_pending_event() has drained any older
> result beforehand, so the RDY bit seen by the poll belongs to the
> operation just started. A timeout is reported as -ETIMEDOUT.
> 
> The RDY interrupt is the only trigger source of the triggered buffer, so
> devm_ad_sd_setup_buffer_and_trigger() sets nothing up for these devices
> and they only support direct mode. Registerless devices still require
> the interrupt.
> 
> Each poll is a SPI transfer, so poll every 20 ms: this delays the
> detection of the end of a conversion by at most one period, a fifth of
> a conversion at the AD7124 default output data rate of 10 SPS, while
> keeping the bus traffic, and the CPU time of PIO SPI transfers, low.

...

> +#define AD_SD_POLL_PERIOD_US	(20 * USEC_PER_MSEC)

The multiplier is defined beneath time.h. Is it included?

...

> +static int ad_sd_poll_rdy(struct ad_sigma_delta *sigma_delta,
> +			  unsigned int timeout_us)
> +{
> +	unsigned int status;
> +	int ret, ret_read;

ret_read --> err
It's visible in the code what it's for.

> +	ret = read_poll_timeout(ad_sd_read_reg, ret_read,
> +				ret_read || !(status & AD_SD_REG_STATUS_RDY),
> +				AD_SD_POLL_PERIOD_US, timeout_us, false,
> +				sigma_delta, AD_SD_REG_STATUS, 1, &status);

With that, wrap on a logical boundary.

	ret = read_poll_timeout(ad_sd_read_reg,
				err, err || !(status & AD_SD_REG_STATUS_RDY),
				AD_SD_POLL_PERIOD_US, timeout_us, false,
				sigma_delta, AD_SD_REG_STATUS, 1, &status);

> +	if (ret)
> +		return ret;
> +
> +	return ret_read;
> +}

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-11-20 12:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 11:26 [PATCH 0/2] iio: adc: ad7124: support boards without RDY interrupt ILYAS NHASSE via B4 Relay
2026-11-20 11:26 ` [PATCH 1/2] dt-bindings: iio: adc: adi,ad7124: make interrupts optional ILYAS NHASSE via B4 Relay
2026-11-20 11:26 ` [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt ILYAS NHASSE via B4 Relay
2026-11-20 12:24   ` Andy Shevchenko

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®