Re: [PATCH v2 5/7] iio: pressure: dps310: use time unit macros for sleeps and timeouts
From: Joshua Crofts
Date: Thu Nov 26 2026 - 08:17:43 EST
On 26-Nov-26 13:13, Rupesh Majhi wrote:
> Write the microsecond values as multiples of USEC_PER_MSEC, like the
> poll timeout next to them already uses USEC_PER_SEC.
>
> After a reset wait 20 ms with msleep() instead of 15 to 55 ms. The
> specification says 15 ms, so this keeps some margin.
>
> Signed-off-by: Rupesh Majhi <zoone.rupert@xxxxxxxxx>
> ---
> v2:
> - wrap the poll call on logical boundaries (Andy)
> - msleep(20) after a reset (Andy)
>
> drivers/iio/pressure/dps310.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
> index f802c2c59072..1d46817ad04a 100644
> --- a/drivers/iio/pressure/dps310.c
> +++ b/drivers/iio/pressure/dps310.c
> @@ -20,6 +20,7 @@
>
> #include <linux/bitfield.h>
> #include <linux/cleanup.h>
> +#include <linux/delay.h>
> #include <linux/devm-helpers.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> @@ -103,7 +104,7 @@
> #define DPS310_DRAIN_MAX_MS (2 * MSEC_PER_SEC)
>
> /* Make sure sleep time is <= 30ms for usleep_range */
> -#define DPS310_POLL_SLEEP_US(t) min(30000, (t) / 8)
> +#define DPS310_POLL_SLEEP_US(t) min(30 * USEC_PER_MSEC, (t) / 8)
> /* 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))
>
> @@ -369,8 +370,9 @@ static int dps310_startup(struct dps310_data *data)
> * Calibration coefficients required for reporting temperature.
> * They are available 40ms after the device has started
> */
> - rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready,
> - ready & DPS310_COEF_RDY, 10000, 40000);
> + rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG,
> + ready, ready & DPS310_COEF_RDY,
> + 10 * USEC_PER_MSEC, 40 * USEC_PER_MSEC);
> if (rc)
> return rc;
>
> @@ -558,7 +560,7 @@ static int dps310_reset_wait(struct dps310_data *data)
> return rc;
>
> /* Wait for device chip access: 15ms in specification */
> - usleep_range(15000, 55000);
> + msleep(20);
I think it's safe to use 15 as specified in the datasheet, as msleep()
guarantees sleep for the specified time + a max of 12.5% slack.
This can be tweaked whilst applying though (or not, at it's pretty minuscule).
Either way,
Reviewed-by: Joshua Crofts <crofts@xxxxxxxxxx>
--
Kind regards,
Joshua Crofts