Re: [PATCH v8 1/3] iio: adc: ti-ads1100: Fix incorrect reading when datarate changed in single mode

From: Jonathan Cameron

Date: Fri Jul 17 2026 - 20:54:55 EST


On Fri, 17 Jul 2026 20:50:31 +0200
Jakub Szczudlo <jakubszczudlo40@xxxxxxxxx> wrote:

> When device is suspended and it is in single mode then changing
> datarate doesn't make it actually wait for new measurement, so to
> be sure that read after change is correct functions that changes

be sure that read after change is correct, functions that change

(to make it easier to read)

> datarate and gain will wait for a new data.
>
> Fixes: 541880542f2b ("iio: adc: Add TI ADS1100 and ADS1000")
> Signed-off-by: Jakub Szczudlo <jakubszczudlo40@xxxxxxxxx>
> ---
> drivers/iio/adc/ti-ads1100.c | 71 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 67 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads1100.c b/drivers/iio/adc/ti-ads1100.c
> index 9fe8d54cce83..363f790ca5d5 100644
> --- a/drivers/iio/adc/ti-ads1100.c
> +++ b/drivers/iio/adc/ti-ads1100.c
> @@ -15,10 +15,12 @@
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/i2c.h>
> +#include <linux/iopoll.h>
> #include <linux/mutex.h>
> #include <linux/property.h>
> #include <linux/pm_runtime.h>
> #include <linux/regulator/consumer.h>
> +#include <linux/time.h>
> #include <linux/units.h>
>
> #include <linux/iio/iio.h>
> @@ -43,6 +45,9 @@
> static const int ads1100_data_rate[] = { 128, 32, 16, 8 };
> static const int ads1100_data_rate_bits[] = { 12, 14, 15, 16 };
>
> +/* Timeout based on the minimum sample rate of 8 SPS (7500ms) */
> +#define ADS1100_MAX_DRDY_TIMEOUT_US (7500 * USEC_PER_MSEC)
> +
> struct ads1100_data {
> struct i2c_client *client;
> struct regulator *reg_vdd;
> @@ -123,10 +128,50 @@ static int ads1100_get_adc_result(struct ads1100_data *data, int chan, int *val)
> return 0;
> }
>
> +static int ads1100_new_data_is_ready(struct ads1100_data *data)
> +{
> + u8 buffer[3];
> + int ret;
> +
> + ret = i2c_master_recv(data->client, (char *)&buffer, sizeof(buffer));
> + if (ret < 0) {
> + dev_err(&data->client->dev, "I2C read fail: %d\n", ret);
> + return ret;
> + }
> +
> + return FIELD_GET(ADS1100_CFG_ST_BSY, buffer[2]) ? 0 : 1;

There is question from sashiko on this one. I'm kind of assuming it is wrong
but do check (link below)

> +}
> +
> +static int ads1100_poll_data_ready(struct ads1100_data *data)
> +{
> + int data_rate_Hz = ads1100_data_rate[FIELD_GET(ADS1100_DR_MASK, data->config)];
> + /* To be sure we wait 5 times more than data rate */
> + unsigned long wait_time_us = DIV_ROUND_CLOSEST(USEC_PER_SEC, 2 * data_rate_Hz);
> + int data_ready;
> + u8 buffer[3];
> + int ret;
> +
> + /* To be sure that polled value will have value after config change */
> + ret = i2c_master_recv(data->client, (char *)&buffer, sizeof(buffer));
> + if (ret < 0) {
> + dev_err(&data->client->dev, "I2C read fail: %d\n", ret);
> + return ret;
> + }
> +
> + ret = readx_poll_timeout(ads1100_new_data_is_ready, data,
> + data_ready, data_ready != 0,
> + wait_time_us, ADS1100_MAX_DRDY_TIMEOUT_US);
> + if (data_ready < 0)
> + return data_ready;

https://sashiko.dev/#/patchset/20260717185033.246580-1-jakubszczudlo40%40gmail.com

ret needs checking.

> +
> + return 0;
> +}

Otherwise this looks fine to me.

Jonathan