linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Matti Lehtimäki" <matti.lehtimaki@gmail.com>
Cc: linux-iio@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht,
	Lars-Peter Clausen <lars@metafoo.de>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Alexandru Ardelean <aardelean@deviqon.com>,
	Cai Huoqing <cai.huoqing@linux.dev>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: st_sensors: Retry ID verification on failure
Date: Sun, 31 Jul 2022 17:00:57 +0100	[thread overview]
Message-ID: <20220731170057.2b8ac00e@jic23-huawei> (raw)
In-Reply-To: <20220724164316.68393-1-matti.lehtimaki@gmail.com>

On Sun, 24 Jul 2022 19:43:15 +0300
Matti Lehtimäki <matti.lehtimaki@gmail.com> wrote:

> Some sensors do not always start fast enough to read a valid ID from
> registers at first attempt. Let's retry at most 3 times with short sleep
> in between to fix random timing issues.
> 
> Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.com>
Hi Matti,

My gut feeling is this isn't in a fast path, so why not just wait
for whatever the documented power up time of the sensor is?

I'd expect to see a sleep in st_sensors_power_enable() if one is
required.

Jonathan

> ---
>  drivers/iio/common/st_sensors/st_sensors_core.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index 9910ba1da085..106f7953683e 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -21,6 +21,8 @@
>  
>  #include "st_sensors_core.h"
>  
> +#define VERIFY_ID_RETRY_COUNT 3
> +
>  int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
>  				    u8 reg_addr, u8 mask, u8 data)
>  {
> @@ -619,11 +621,18 @@ EXPORT_SYMBOL_NS(st_sensors_get_settings_index, IIO_ST_SENSORS);
>  int st_sensors_verify_id(struct iio_dev *indio_dev)
>  {
>  	struct st_sensor_data *sdata = iio_priv(indio_dev);
> -	int wai, err;
> +	int wai, err, i;
>  
>  	if (sdata->sensor_settings->wai_addr) {
> -		err = regmap_read(sdata->regmap,
> -				  sdata->sensor_settings->wai_addr, &wai);
> +		for (i = 0; i < VERIFY_ID_RETRY_COUNT; i++) {
> +			err = regmap_read(sdata->regmap,
> +					  sdata->sensor_settings->wai_addr, &wai);
> +
> +			if (!err && sdata->sensor_settings->wai == wai)
> +				return 0;
> +
> +			msleep(20);
How do we know 60msecs is long enough for all sensors?

> +		}
>  		if (err < 0) {
>  			dev_err(&indio_dev->dev,
>  				"failed to read Who-Am-I register.\n");


  parent reply	other threads:[~2022-07-31 15:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-24 16:43 [PATCH 1/2] iio: st_sensors: Retry ID verification on failure Matti Lehtimäki
2022-07-24 16:43 ` [PATCH 2/2] iio: st_sensors: Fix null pointer on defer_probe error Matti Lehtimäki
2022-07-25 21:24   ` Andy Shevchenko
2022-07-25 21:20 ` [PATCH 1/2] iio: st_sensors: Retry ID verification on failure Andy Shevchenko
2022-07-31 16:00 ` Jonathan Cameron [this message]
2022-07-31 18:51   ` Matti Lehtimäki
2022-07-31 20:17     ` Jonathan Cameron
2022-08-03 18:20       ` Linus Walleij

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=20220731170057.2b8ac00e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=aardelean@deviqon.com \
    --cc=cai.huoqing@linux.dev \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matti.lehtimaki@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).