> -----Original Message----- > From: Andy Shevchenko <andy.shevchenko@xxxxxxxxx> > Sent: Wednesday, August 11, 2021 8:15 AM > To: Sa, Nuno <Nuno.Sa@xxxxxxxxxx> > Cc: linux-iio@xxxxxxxxxxxxxxx; =Jonathan Cameron <jic23@xxxxxxxxxx>; > Lars-Peter Clausen <lars@xxxxxxxxxx>; Drew Fustini > <drew@xxxxxxxx> > Subject: Re: [PATCH 1/1] iio: ltc2983: fix device probe > > > > On Tuesday, August 10, 2021, Nuno Sá <nuno.sa@xxxxxxxxxx > <mailto:nuno.sa@xxxxxxxxxx> > wrote: > > > There is no reason to assume that the irq rising edge (indicating > that > the device start up phase is done) will happen after we request > the irq. > If the device is already up by the time we request it, the call to > 'wait_for_completion_timeout()' will timeout and we will fail > the device > probe even though there's nothing wrong. > > This patch fixes it by just polling the status register until we get > the > indication that the device is up and running. As a side effect of > this > fix, requesting the irq is also moved to after the setup function. > > Fixes: f110f3188e563 ("iio: temperature: Add support for > LTC2983") > Reported-by: Drew Fustini <drew@xxxxxxxx > <mailto:drew@xxxxxxxx> > > Signed-off-by: Nuno Sá <nuno.sa@xxxxxxxxxx > <mailto:nuno.sa@xxxxxxxxxx> > > --- > drivers/iio/temperature/ltc2983.c | 31 > +++++++++++++++++++------------ > 1 file changed, 19 insertions(+), 12 deletions(-) > > diff --git a/drivers/iio/temperature/ltc2983.c > b/drivers/iio/temperature/ltc2983.c > index 3b5ba26d7d86..c6c4877bdcff 100644 > --- a/drivers/iio/temperature/ltc2983.c > +++ b/drivers/iio/temperature/ltc2983.c > @@ -89,6 +89,8 @@ > > #define LTC2983_STATUS_START_MASK BIT(7) > #define LTC2983_STATUS_START(x) > FIELD_PREP(LTC2983_STATUS_START_MASK, x) > +#define LTC2983_STATUS_UP_MASK GENMASK(7, 6) > +#define LTC2983_STATUS_UP(reg) > FIELD_GET(LTC2983_STATUS_UP_MASK, reg) > > #define LTC2983_STATUS_CHAN_SEL_MASK > GENMASK(4, 0) > #define LTC2983_STATUS_CHAN_SEL(x) \ > @@ -1362,13 +1364,21 @@ static int ltc2983_parse_dt(struct > ltc2983_data *st) > > static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) > { > - u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0; > + u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status > = 0; > int ret; > - unsigned long time; > + unsigned long time = 10; > > /* make sure the device is up */ > - time = wait_for_completion_timeout(&st->completion, > - msecs_to_jiffies(250)); > + do { > + ret = regmap_read(st->regmap, > LTC2983_STATUS_REG, &status); > + if (ret) > + return ret; > + /* start bit (7) is 0 and done bit (6) is 1 */ > + if (LTC2983_STATUS_UP(status) == 1) > + break; > + > + msleep(25); > + } while (--time); > > > > NIH regmap_read_poll_timeout() Nice helper. Will send a v2 with it... - Nuno Sá