linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mmc: sdhci_am654: Add workaround for card detect debounce timer
@ 2020-08-25 17:00 Faiz Abbas
  2020-08-28  8:44 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Faiz Abbas @ 2020-08-25 17:00 UTC (permalink / raw)
  To: linux-kernel, linux-mmc, linux-arm-kernel
  Cc: ulf.hansson, adrian.hunter, faiz_abbas

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>
---

v2: Use read_poll_timeout() standard macro

 drivers/mmc/host/sdhci_am654.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
index f9d24af12396..9a048c80dad4 100644
--- a/drivers/mmc/host/sdhci_am654.c
+++ b/drivers/mmc/host/sdhci_am654.c
@@ -6,6 +6,7 @@
  *
  */
 #include <linux/clk.h>
+#include <linux/iopoll.h>
 #include <linux/of.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
@@ -272,9 +273,19 @@ static void sdhci_j721e_4bit_set_clock(struct sdhci_host *host,
 	sdhci_set_clock(host, clock);
 }
 
+static u8 sdhci_am654_write_power_on(struct sdhci_host *host, u8 val, int reg)
+{
+	writeb(val, host->ioaddr + reg);
+	usleep_range(1000, 10000);
+	return readb(host->ioaddr + reg);
+}
+
+#define MAX_POWER_ON_TIMEOUT	1500000 /* us */
 static void sdhci_am654_write_b(struct sdhci_host *host, u8 val, int reg)
 {
 	unsigned char timing = host->mmc->ios.timing;
+	u8 pwr;
+	int ret;
 
 	if (reg == SDHCI_HOST_CONTROL) {
 		switch (timing) {
@@ -291,6 +302,19 @@ 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
+		 */
+		ret = read_poll_timeout(sdhci_am654_write_power_on, pwr,
+					pwr & SDHCI_POWER_ON, 0,
+					MAX_POWER_ON_TIMEOUT, false, host, val,
+					reg);
+		if (ret)
+			dev_warn(mmc_dev(host->mmc), "Power on failed\n");
+	}
 }
 
 static int sdhci_am654_execute_tuning(struct mmc_host *mmc, u32 opcode)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] mmc: sdhci_am654: Add workaround for card detect debounce timer
  2020-08-25 17:00 [PATCH v2] mmc: sdhci_am654: Add workaround for card detect debounce timer Faiz Abbas
@ 2020-08-28  8:44 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2020-08-28  8:44 UTC (permalink / raw)
  To: Faiz Abbas; +Cc: Linux Kernel Mailing List, linux-mmc, Linux ARM, Adrian Hunter

On Tue, 25 Aug 2020 at 19:00, Faiz Abbas <faiz_abbas@ti.com> 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>

Applied for next, thanks!

Kind regards
Uffe


> ---
>
> v2: Use read_poll_timeout() standard macro
>
>  drivers/mmc/host/sdhci_am654.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
> index f9d24af12396..9a048c80dad4 100644
> --- a/drivers/mmc/host/sdhci_am654.c
> +++ b/drivers/mmc/host/sdhci_am654.c
> @@ -6,6 +6,7 @@
>   *
>   */
>  #include <linux/clk.h>
> +#include <linux/iopoll.h>
>  #include <linux/of.h>
>  #include <linux/module.h>
>  #include <linux/pm_runtime.h>
> @@ -272,9 +273,19 @@ static void sdhci_j721e_4bit_set_clock(struct sdhci_host *host,
>         sdhci_set_clock(host, clock);
>  }
>
> +static u8 sdhci_am654_write_power_on(struct sdhci_host *host, u8 val, int reg)
> +{
> +       writeb(val, host->ioaddr + reg);
> +       usleep_range(1000, 10000);
> +       return readb(host->ioaddr + reg);
> +}
> +
> +#define MAX_POWER_ON_TIMEOUT   1500000 /* us */
>  static void sdhci_am654_write_b(struct sdhci_host *host, u8 val, int reg)
>  {
>         unsigned char timing = host->mmc->ios.timing;
> +       u8 pwr;
> +       int ret;
>
>         if (reg == SDHCI_HOST_CONTROL) {
>                 switch (timing) {
> @@ -291,6 +302,19 @@ 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
> +                */
> +               ret = read_poll_timeout(sdhci_am654_write_power_on, pwr,
> +                                       pwr & SDHCI_POWER_ON, 0,
> +                                       MAX_POWER_ON_TIMEOUT, false, host, val,
> +                                       reg);
> +               if (ret)
> +                       dev_warn(mmc_dev(host->mmc), "Power on failed\n");
> +       }
>  }
>
>  static int sdhci_am654_execute_tuning(struct mmc_host *mmc, u32 opcode)
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-28  8:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 17:00 [PATCH v2] mmc: sdhci_am654: Add workaround for card detect debounce timer Faiz Abbas
2020-08-28  8:44 ` Ulf Hansson

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).