public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: patches@opensource.cirrus.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mfd: madera: Don't use regmap_read_poll_timeout to poll for BOOT_DONE
Date: Thu, 16 Aug 2018 10:12:11 +0100	[thread overview]
Message-ID: <20180816091211.GF10054@dell> (raw)
In-Reply-To: <20180807090813.15695-2-rf@opensource.cirrus.com>

On Tue, 07 Aug 2018, Richard Fitzgerald wrote:

> While polling for BOOT_DONE the chip could NAK a read because it is
> still booting, which would terminate the regmap_read_poll_timeout()
> with an error.
> 
> Instead implement a polling loop that ignores read errors so we
> always poll until the chip signals boot or the loop times out.
> 
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> ---
>  drivers/mfd/madera-core.c | 38 ++++++++++++++++++++++++--------------
>  1 file changed, 24 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/mfd/madera-core.c b/drivers/mfd/madera-core.c
> index 8cfea969b060..bc5545c53ee5 100644
> --- a/drivers/mfd/madera-core.c
> +++ b/drivers/mfd/madera-core.c
> @@ -132,33 +132,43 @@ const char *madera_name_from_type(enum madera_type type)
>  }
>  EXPORT_SYMBOL_GPL(madera_name_from_type);
>  
> -#define MADERA_BOOT_POLL_MAX_INTERVAL_US  5000
> -#define MADERA_BOOT_POLL_TIMEOUT_US	 25000
> +#define MADERA_BOOT_POLL_INTERVAL_USEC		5000
> +#define MADERA_BOOT_POLL_TIMEOUT_USEC		25000
>  
>  static int madera_wait_for_boot(struct madera *madera)
>  {
> -	unsigned int val;
> -	int ret;
> +	ktime_t timeout;
> +	unsigned int val = 0;
> +	int ret = 0;
>  
>  	/*
>  	 * We can't use an interrupt as we need to runtime resume to do so,
>  	 * so we poll the status bit. This won't race with the interrupt
>  	 * handler because it will be blocked on runtime resume.
> +	 * The chip could NAK a read request while it is booting so ignore
> +	 * errors from regmap_read.
>  	 */
> -	ret = regmap_read_poll_timeout(madera->regmap,
> -				       MADERA_IRQ1_RAW_STATUS_1,
> -				       val,
> -				       (val & MADERA_BOOT_DONE_STS1),
> -				       MADERA_BOOT_POLL_MAX_INTERVAL_US,
> -				       MADERA_BOOT_POLL_TIMEOUT_US);
> -
> -	if (ret)
> -		dev_err(madera->dev, "Polling BOOT_DONE_STS failed: %d\n", ret);
> +	regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_1, &val);
> +	if (val & MADERA_BOOT_DONE_STS1)
> +		goto done;

Move the usleep_range() invokation to after the regmap_read(), then
you can remove these 3 lines and have the same semantics.

> +	timeout = ktime_add_us(ktime_get(), MADERA_BOOT_POLL_TIMEOUT_USEC);
> +	do {
> +		usleep_range(MADERA_BOOT_POLL_INTERVAL_USEC / 2,
> +			     MADERA_BOOT_POLL_INTERVAL_USEC);
> +		regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_1, &val);
> +		if (val & MADERA_BOOT_DONE_STS1)
> +			goto done;
> +	} while (ktime_compare(ktime_get(), timeout) <= 0);
> +
> +	dev_err(madera->dev, "Polling BOOT_DONE_STS timed out\n");
> +	ret = -ETIMEDOUT;
>  
>  	/*
>  	 * BOOT_DONE defaults to unmasked on boot so we must ack it.
> -	 * Do this unconditionally to avoid interrupt storms.
> +	 * Do this even after a timeout to avoid interrupt storms.
>  	 */
> +done:
>  	regmap_write(madera->regmap, MADERA_IRQ1_STATUS_1,
>  		     MADERA_BOOT_DONE_EINT1);
>  

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

  reply	other threads:[~2018-08-16  9:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07  9:08 [PATCH 1/2] mfd: madera: Add register definitions for accessory detect Richard Fitzgerald
2018-08-07  9:08 ` [PATCH 2/2] mfd: madera: Don't use regmap_read_poll_timeout to poll for BOOT_DONE Richard Fitzgerald
2018-08-16  9:12   ` Lee Jones [this message]
2018-08-16  9:12 ` [PATCH 1/2] mfd: madera: Add register definitions for accessory detect Lee Jones

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=20180816091211.GF10054@dell \
    --to=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@opensource.cirrus.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox