Re: [PATCH] iio: pressure: dps310: wait for a new sample after a ratio change
From: Andy Shevchenko
Date: Mon Oct 19 2026 - 15:08:59 EST
On Mon, Oct 19, 2026 at 06:33:28PM +0300, Rupesh Majhi wrote:
> After an oversampling ratio change, the sample waiting in the result
> registers and the one being measured are both from the old ratio, but
> are scaled with the new one. Pressure ratio 2 to 16 reads 192 kPa instead
> of 103 kPa, and temperature is off by hundreds of degrees. Pressure is
> also wrong after a temperature ratio change, as it is compensated with
> the cached temperature.
>
> Discard those two samples on a ratio change, and for temperature cache
> the one after. The ratio write now blocks until then.
>
> That wait can be longer than the 1/rate timeout, after which the driver
> resets the chip and the ratio silently goes back to 1. Allow two periods.
...
> /* Make sure sleep time is <= 30ms for usleep_range */
> #define DPS310_POLL_SLEEP_US(t) min(30000, (t) / 8)
Seems the use of USEC_PER_SEC below should be postponed to a regular cleanup.
Because otherwise it will be inconsistent with the above where it would need
to be 30 * USEC_PER_MSEC
> -/* Silently handle error in rate value here */
> -#define DPS310_POLL_TIMEOUT_US(rc) ((rc) <= 0 ? 1000000 : 1000000 / (rc))
> +/* A period plus a measurement time; silently handle error in rate value */
> +#define DPS310_POLL_TIMEOUT_US(rc) (2 * USEC_PER_SEC / max(rc, 1))
--
With Best Regards,
Andy Shevchenko