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

From: Andy Shevchenko
Date: Tue Sep 06 2022 - 16:37:10 EST


On Tue, Sep 6, 2022 at 11:05 PM 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.

If the previous patch is a dependency to this one, you need to use its
Subject in a Cc: stable@ tag as it's pointed out in the documentation.
Otherwise, Fixes go first in the series.

...

> +static int dps310_reset_reinit(struct dps310_data *data)
> +{
> + int rc;
> +
> + rc = dps310_reset_wait(data);
> + if (rc)
> + return rc;

> + rc = dps310_startup(data);
> + if (rc)
> + return rc;
> +
> + return 0;

Can be simply return _startup(...);

> +}

...

Can it be a helper here?

int dps310_get_ready_status(data, ready_bit, timeout)
{
sleep = ...
int ready;

return regmap_read_poll_timeout(...);

}

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

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

rc = dps310_get_ready_status(...);

> + if (rc) {
> + if (rc == -ETIMEDOUT && !data->timeout_recovery_failed) {
> + int rc2;
> +
> + /* Reset and reinitialize the chip. */
> + rc2 = dps310_reset_reinit(data);
> + if (rc2) {
> + data->timeout_recovery_failed = true;
> + } else {

> + /* Try again to get sensor ready status. */
> + rc2 = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG,
> + ready, ready & ready_bit, sleep,
> + timeout);

rc2 = dps310_get_ready_status(...);

> + if (rc2)
> + data->timeout_recovery_failed = true;
> + else
> + return 0;
> + }
> + }
> +
> + return rc;
> + }
> +
> + data->timeout_recovery_failed = false;
> + return 0;
> +}

--
With Best Regards,
Andy Shevchenko