Re: [PATCH] iio: pressure: dps310: wait for a new sample after a ratio change

From: Jonathan Cameron

Date: Sun Oct 25 2026 - 22:46:36 EST


On Mon, 19 Oct 2026 22:06:49 +0300
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> 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
Do we want to have the extra churn on the below?
I'm not that bothered by a temporary state of different styles.
Nice indeed to have a follow up tidying up other cases though!

There is quite a bit going on around this driver, so I'm going to pick this
one up for the testing branch of iio.git rather than the faster path.

Thanks,

Jonathan

>
> > -/* 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))
>