From: Drew Fustini <drew@pdp7.com>
To: "Nuno Sá" <nuno.sa@analog.com>
Cc: linux-iio@vger.kernel.org, Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v2 1/1] iio: ltc2983: fix device probe
Date: Wed, 11 Aug 2021 18:09:24 -0700 [thread overview]
Message-ID: <20210812010924.GA3061491@x1> (raw)
In-Reply-To: <20210811133220.190264-2-nuno.sa@analog.com>
On Wed, Aug 11, 2021 at 03:32:20PM +0200, Nuno Sá 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@pdp7.com>
> Reviewed-by: Drew Fustini <drew@pdp7.com>
> Tested-by: Drew Fustini <drew@pdp7.com>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---
> drivers/iio/temperature/ltc2983.c | 30 ++++++++++++++----------------
> 1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
> index 3b5ba26d7d86..657eb8cb4be4 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,17 +1364,16 @@ 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;
> -
> - /* make sure the device is up */
> - time = wait_for_completion_timeout(&st->completion,
> - msecs_to_jiffies(250));
>
> - if (!time) {
> + /* make sure the device is up: start bit (7) is 0 and done bit (6) is 1 */
> + ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status,
> + LTC2983_STATUS_UP(status) == 1, 25000,
> + 25000 * 10);
> + if (ret) {
> dev_err(&st->spi->dev, "Device startup timed out\n");
> - return -ETIMEDOUT;
> + return ret;
> }
>
> st->iio_chan = devm_kzalloc(&st->spi->dev,
> @@ -1492,10 +1493,11 @@ static int ltc2983_probe(struct spi_device *spi)
> ret = ltc2983_parse_dt(st);
> if (ret)
> return ret;
> - /*
> - * let's request the irq now so it is used to sync the device
> - * startup in ltc2983_setup()
> - */
> +
> + ret = ltc2983_setup(st, true);
> + if (ret)
> + return ret;
> +
> ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler,
> IRQF_TRIGGER_RISING, name, st);
> if (ret) {
> @@ -1503,10 +1505,6 @@ static int ltc2983_probe(struct spi_device *spi)
> return ret;
> }
>
> - ret = ltc2983_setup(st, true);
> - if (ret)
> - return ret;
> -
> indio_dev->name = name;
> indio_dev->num_channels = st->iio_channels;
> indio_dev->channels = st->iio_chan;
> --
> 2.32.0
>
I tested this version on my Zynq-7000 board and it works well too.
Thanks,
Drew
prev parent reply other threads:[~2021-08-12 1:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 13:32 [PATCH v2 0/1] Fix ltc2983 probing Nuno Sá
2021-08-11 13:32 ` [PATCH v2 1/1] iio: ltc2983: fix device probe Nuno Sá
2021-08-11 16:15 ` Andy Shevchenko
2021-08-12 6:54 ` Sa, Nuno
2021-08-12 18:19 ` Jonathan Cameron
2021-08-12 18:31 ` Drew Fustini
2021-08-13 7:21 ` Sa, Nuno
2021-08-15 15:33 ` Jonathan Cameron
2021-08-12 1:09 ` Drew Fustini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210812010924.GA3061491@x1 \
--to=drew@pdp7.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.