Re: [PATCH v7 2/2] iio: pressure: dps310: Reset chip after timeout

From: Andy Shevchenko
Date: Wed Sep 14 2022 - 06:58:15 EST


On Tue, Sep 13, 2022 at 12:27 AM Eddie James <eajames@xxxxxxxxxxxxx> wrote:
>
> The DPS310 chip has been observed to get "stuck" such that pressure
> and temperature measurements are never indicated as "ready" in the
> MEAS_CFG register. The only solution is to reset the device and try
> again. In order to avoid continual failures, use a boolean flag to
> only try the reset after timeout once if errors persist.

...

> +static int dps310_ready_status(struct dps310_data *data, int ready_bit, int timeout)
> +{
> + int ready;
> + int sleep = DPS310_POLL_SLEEP_US(timeout);

Longer line first?

> + return regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, ready & ready_bit,
> + sleep, timeout);
> +}

...

> +static int dps310_ready(struct dps310_data *data, int ready_bit, int timeout)
> +{
> + int rc;
> +
> + rc = dps310_ready_status(data, ready_bit, timeout);
> + if (rc) {
> + if (rc == -ETIMEDOUT && !data->timeout_recovery_failed) {
> + int rc2;
> +
> + /* Reset and reinitialize the chip. */
> + rc2 = dps310_reset_reinit(data);
> + if (rc2) {

With below in mind this might become

if (dps310_reset_init(...))
... = true;

> + data->timeout_recovery_failed = true;
> + } else {
> + /* Try again to get sensor ready status. */

> + rc2 = dps310_ready_status(data, ready_bit, timeout);
> + if (rc2)
> + data->timeout_recovery_failed = true;

Shouldn't you re-use rc here again?

> + else
> + return 0;
> + }
> + }
> +
> + return rc;
> + }

--
With Best Regards,
Andy Shevchenko