Re: [PATCH 1/2] iio: adc: ti-ads112c14: add DRDY interrupt support

From: Jonathan Cameron

Date: Sun Jul 26 2026 - 21:34:18 EST


On Fri, 24 Jul 2026 15:13:10 -0500
"David Lechner (TI)" <dlechner@xxxxxxxxxxxx> wrote:

> Add handling for the DRDY interrupt to wait for data ready events rather
> than polling (only when it is wired up).
>
> Signed-off-by: David Lechner (TI) <dlechner@xxxxxxxxxxxx>

I'm not sure the comment that I've made will still be true by end
of the various series you've posted but for now the complex
code flow would be simplified by duplicating a couple of lines
and having two helper functions to pick between dependent on whether
we have the drdy interrupt or not.

> ---
>
> Small note: the hard-coded 100 ms timeout will be replaced in a future
> series with a dynamic value, so I didn't bother with a macro or comments
> to explain why the value was chosen.
>
> And passing indio_dev instead of data to irq is intentional as it will
> be used in the next patch.
> ---
> drivers/iio/adc/ti-ads112c14.c | 82 ++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 75 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> index 8ad8caee0ff7..57e301c15314 100644
> --- a/drivers/iio/adc/ti-ads112c14.c
> +++ b/drivers/iio/adc/ti-ads112c14.c

> +
> static bool ads112c14_writeable_reg(struct device *dev, unsigned int reg)
> {
> switch (reg) {
> @@ -601,17 +621,33 @@ static int ads112c14_single_conversion(struct ads112c14_data *data,
> return ret;
> }
>
> + if (data->drdy_irq) {
> + reinit_completion(&data->drdy_completion);
> + enable_irq(data->drdy_irq);
> + }
> +
> ret = regmap_write(data->regmap, ADS112C14_REG_CONVERSION_CTRL,
> ADS112C14_CONVERSION_CTRL_START);

Given this is basically the only shared code, maybe just split into
two helpers and chose between them? The outer code in single_conversion
would be shared. I just mean this inner bit to establish we have data.


> - if (ret)
> + if (ret) {
> + if (data->drdy_irq)
> + disable_irq(data->drdy_irq);
> return ret;
> + }
>
> - ret = regmap_read_poll_timeout(data->regmap,
> - ADS112C14_REG_STATUS_MSB, reg_val,
> - FIELD_GET(ADS112C14_STATUS_MSB_DRDY, reg_val),
> - 1 * USEC_PER_MSEC, 100 * USEC_PER_MSEC);
> - if (ret)
> - return ret;
> + if (data->drdy_irq) {
> + ret = wait_for_completion_timeout(&data->drdy_completion,
> + msecs_to_jiffies(100));
> + disable_irq(data->drdy_irq);
> + if (ret == 0)
> + return -ETIMEDOUT;
> + } else {
> + ret = regmap_read_poll_timeout(data->regmap,
> + ADS112C14_REG_STATUS_MSB, reg_val,
> + FIELD_GET(ADS112C14_STATUS_MSB_DRDY, reg_val),
> + 1 * USEC_PER_MSEC, 100 * USEC_PER_MSEC);
> + if (ret)
> + return ret;
> + }