Re: [PATCH v7 1/3] iio: adc: ti-ads1100: Fix incorrect reading when datarate changed in single mode
From: Andy Shevchenko
Date: Wed Jul 15 2026 - 02:45:43 EST
On Tue, Jul 14, 2026 at 09:55:26PM +0200, Jakub Szczudlo 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
> datarate and gain will wait for a new data.
...
> +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, 5 * 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 (ret)
> + return ret;
> + return data_ready < 0 ? data_ready : 0;
I would unroll this to if-cond as it will be more readable (to get that
data_ready is negative when it holds an error code).
if (data_ready < 0)
return data_ready;
return 0;
> +}
--
With Best Regards,
Andy Shevchenko