All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Faiz Abbas <faiz_abbas@ti.com>,
	linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org
Cc: ulf.hansson@linaro.org
Subject: Re: [PATCH] mmc: sdhci_am654: Add workaround for card detect debounce timer
Date: Wed, 5 Aug 2020 11:14:32 +0300	[thread overview]
Message-ID: <2d692a90-0e58-ae69-9b5b-c9eb3ffe21ec@intel.com> (raw)
In-Reply-To: <20200729234130.25056-1-faiz_abbas@ti.com>

On 30/07/20 2:41 am, Faiz Abbas wrote:
> There is a one time delay because of a card detect debounce timer in the
> controller IP. This timer runs as soon as power is applied to the module
> regardless of whether a card is present or not and any writes to
> SDHCI_POWER_ON will return 0 before it expires. This timeout has been
> measured to be about 1 second in am654x and j721e.
> 
> Write-and-read-back in a loop on SDHCI_POWER_ON for a maximum of
> 1.5 seconds to make sure that the controller actually powers on.
> 
> Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
> ---
>  drivers/mmc/host/sdhci_am654.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
> index 1718b9e8af63..55cff9de2f3e 100644
> --- a/drivers/mmc/host/sdhci_am654.c
> +++ b/drivers/mmc/host/sdhci_am654.c
> @@ -272,6 +272,7 @@ static void sdhci_j721e_4bit_set_clock(struct sdhci_host *host,
>  	sdhci_set_clock(host, clock);
>  }
>  
> +#define MAX_POWER_ON_TIMEOUT	1500 /* ms */
>  static void sdhci_am654_write_b(struct sdhci_host *host, u8 val, int reg)
>  {
>  	unsigned char timing = host->mmc->ios.timing;
> @@ -291,6 +292,26 @@ static void sdhci_am654_write_b(struct sdhci_host *host, u8 val, int reg)
>  	}
>  
>  	writeb(val, host->ioaddr + reg);
> +	if (reg == SDHCI_POWER_CONTROL && (val & SDHCI_POWER_ON)) {
> +		/*
> +		 * Power on will not happen until the card detect debounce
> +		 * timer expires. Wait at least 1.5 seconds for the power on
> +		 * bit to be set
> +		 */

Can you use readb_poll_timeout() here?

> +		ktime_t timeout = ktime_add_ms(ktime_get(),
> +					       MAX_POWER_ON_TIMEOUT);
> +		do {
> +			if (ktime_compare(ktime_get(), timeout) > 0) {
> +				dev_warn(mmc_dev(host->mmc),
> +					 "Power on failed\n");
> +
> +				return;
> +			}
> +
> +			writeb(val, host->ioaddr + reg);
> +			usleep_range(1000, 10000);
> +		} while (!(readb(host->ioaddr + reg) & SDHCI_POWER_ON));
> +	}
>  }
>  
>  static int sdhci_am654_execute_tuning(struct mmc_host *mmc, u32 opcode)
> 


  reply	other threads:[~2020-08-05  8:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 23:41 [PATCH] mmc: sdhci_am654: Add workaround for card detect debounce timer Faiz Abbas
2020-08-05  8:14 ` Adrian Hunter [this message]
2020-08-05  8:22   ` Faiz Abbas
2020-08-05  9:46     ` Adrian Hunter
2020-08-05 13:16       ` Faiz Abbas
2020-08-05 13:16         ` Faiz Abbas

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=2d692a90-0e58-ae69-9b5b-c9eb3ffe21ec@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=faiz_abbas@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /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.