Skip to content

Commit b76d26d

Browse files
nunojsaJonathan Cameron
authored andcommitted
iio: ltc2983: fix device probe
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. Fix 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: f110f31 ("iio: temperature: Add support for LTC2983") Reported-and-tested-by: Drew Fustini <drew@pdp7.com> Reviewed-by: Drew Fustini <drew@pdp7.com> Signed-off-by: Nuno Sá <nuno.sa@analog.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: <Stable@vger.kernel.org> Link: https://lore.kernel.org/r/20210811133220.190264-2-nuno.sa@analog.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent d03a74b commit b76d26d

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

‎drivers/iio/temperature/ltc2983.c‎

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989

9090
#define LTC2983_STATUS_START_MASK BIT(7)
9191
#define LTC2983_STATUS_START(x) FIELD_PREP(LTC2983_STATUS_START_MASK, x)
92+
#define LTC2983_STATUS_UP_MASK GENMASK(7, 6)
93+
#define LTC2983_STATUS_UP(reg) FIELD_GET(LTC2983_STATUS_UP_MASK, reg)
9294

9395
#define LTC2983_STATUS_CHAN_SEL_MASK GENMASK(4, 0)
9496
#define LTC2983_STATUS_CHAN_SEL(x) \
@@ -1362,17 +1364,16 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
13621364

13631365
static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
13641366
{
1365-
u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0;
1367+
u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status;
13661368
int ret;
1367-
unsigned long time;
1368-
1369-
/* make sure the device is up */
1370-
time = wait_for_completion_timeout(&st->completion,
1371-
msecs_to_jiffies(250));
13721369

1373-
if (!time) {
1370+
/* make sure the device is up: start bit (7) is 0 and done bit (6) is 1 */
1371+
ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status,
1372+
LTC2983_STATUS_UP(status) == 1, 25000,
1373+
25000 * 10);
1374+
if (ret) {
13741375
dev_err(&st->spi->dev, "Device startup timed out\n");
1375-
return -ETIMEDOUT;
1376+
return ret;
13761377
}
13771378

13781379
st->iio_chan = devm_kzalloc(&st->spi->dev,
@@ -1492,21 +1493,18 @@ static int ltc2983_probe(struct spi_device *spi)
14921493
ret = ltc2983_parse_dt(st);
14931494
if (ret)
14941495
return ret;
1495-
/*
1496-
* let's request the irq now so it is used to sync the device
1497-
* startup in ltc2983_setup()
1498-
*/
1496+
1497+
ret = ltc2983_setup(st, true);
1498+
if (ret)
1499+
return ret;
1500+
14991501
ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler,
15001502
IRQF_TRIGGER_RISING, name, st);
15011503
if (ret) {
15021504
dev_err(&spi->dev, "failed to request an irq, %d", ret);
15031505
return ret;
15041506
}
15051507

1506-
ret = ltc2983_setup(st, true);
1507-
if (ret)
1508-
return ret;
1509-
15101508
indio_dev->name = name;
15111509
indio_dev->num_channels = st->iio_channels;
15121510
indio_dev->channels = st->iio_chan;

0 commit comments

Comments
 (0)