Re: [PATCH 2/2] iio: adc: ad_sigma_delta: support devices without RDY interrupt

From: Andy Shevchenko

Date: Fri Nov 20 2026 - 07:24:30 EST


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