public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Faiz Abbas <faiz_abbas@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 06/10] mmc: am654_sdhci: Implement workaround for card detect
Date: Fri, 24 Jan 2020 17:22:48 +0530	[thread overview]
Message-ID: <20200124115252.15712-7-faiz_abbas@ti.com> (raw)
In-Reply-To: <20200124115252.15712-1-faiz_abbas@ti.com>

The 4 bit MMC controllers have an internal debounce for the SDCD line
with a debounce delay of 1 second. Therefore, after clocks to the IP are
enabled, software has to wait for this time before it can power on the
controller.

Add an init() callback which polls on sdcd for a maximum of 2 seconds
before switching on power to the controller or (in the case of no card)
returning a ENOMEDIUM. This pushes the 1 second wait time to when the
card is actually needed rather than at every probe() making sure that
users who don't insert an SD card in the slot don't have to wait such a
long time.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
---
 drivers/mmc/am654_sdhci.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/am654_sdhci.c b/drivers/mmc/am654_sdhci.c
index ff0a81eaab..ccae3fea31 100644
--- a/drivers/mmc/am654_sdhci.c
+++ b/drivers/mmc/am654_sdhci.c
@@ -254,7 +254,7 @@ const struct am654_driver_data j721e_4bit_drv_data = {
 	.flags = IOMUX_PRESENT,
 };
 
-int am654_sdhci_init(struct am654_sdhci_plat *plat)
+int am654_sdhci_init_phy(struct am654_sdhci_plat *plat)
 {
 	u32 ctl_cfg_2 = 0;
 	u32 mask, val;
@@ -331,8 +331,37 @@ static int sdhci_am654_get_otap_delay(struct udevice *dev,
 	return 0;
 }
 
+#define MAX_SDCD_DEBOUNCE_TIME 2000
+int am654_sdhci_init(struct udevice *dev)
+{
+	struct am654_sdhci_plat *plat = dev_get_platdata(dev);
+	struct mmc *mmc = mmc_get_mmc_dev(dev);
+	struct sdhci_host *host = mmc->priv;
+	unsigned long start;
+	int val;
+
+	/*
+	 * The controller takes about 1 second to debounce the card detect line
+	 * and doesn't let us power on until that time is up. Instead of waiting
+	 * for 1 second at every stage, poll on the CARD_PRESENT bit upto a
+	 * maximum of 2 seconds to be safe..
+	 */
+	start = get_timer(0);
+	do {
+		if (get_timer(start) > MAX_SDCD_DEBOUNCE_TIME)
+			return -ENOMEDIUM;
+
+		val = mmc_getcd(host->mmc);
+	} while (!val);
+
+	am654_sdhci_init_phy(plat);
+
+	return sdhci_init(mmc);
+}
+
 static int am654_sdhci_probe(struct udevice *dev)
 {
+	struct dm_mmc_ops *ops = mmc_get_ops(dev);
 	struct am654_driver_data *drv_data =
 			(struct am654_driver_data *)dev_get_driver_data(dev);
 	struct am654_sdhci_plat *plat = dev_get_platdata(dev);
@@ -373,9 +402,9 @@ static int am654_sdhci_probe(struct udevice *dev)
 
 	regmap_init_mem_index(dev_ofnode(dev), &plat->base, 1);
 
-	am654_sdhci_init(plat);
+	ops->init = am654_sdhci_init;
 
-	return sdhci_probe(dev);
+	return 0;
 }
 
 static int am654_sdhci_ofdata_to_platdata(struct udevice *dev)
-- 
2.19.2

  parent reply	other threads:[~2020-01-24 11:52 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 11:52 [PATCH v2 00/10] Add Support for eMMC boot in AM65x and J721e Faiz Abbas
2020-01-24 11:52 ` [PATCH v2 01/10] mmc: Add a saved_clock member Faiz Abbas
2020-01-28 23:28   ` Jaehoon Chung
2020-01-24 11:52 ` [PATCH v2 02/10] mmc: Add init() API Faiz Abbas
2020-01-29  8:03   ` Simon Goldschmidt
2020-01-29  8:07     ` Simon Goldschmidt
2020-01-30 15:03       ` Faiz Abbas
2020-01-30 15:07         ` Michal Simek
2020-01-30 15:14           ` Faiz Abbas
2020-01-30 15:30             ` Michal Simek
2020-01-30 15:32               ` Tom Rini
2020-01-30 15:35                 ` Simon Goldschmidt
2020-01-30 15:38                   ` Tom Rini
2020-01-31 13:43                     ` Wolfgang Denk
2020-02-03  6:04                     ` Sekhar Nori
2020-02-03  7:08                       ` Michal Simek
2020-01-31 13:41                   ` Wolfgang Denk
2020-01-31 13:37                 ` Wolfgang Denk
2020-01-30 15:10         ` Simon Goldschmidt
2020-01-29 14:08     ` Faiz Abbas
2020-02-01 13:13       ` Peng Fan
2020-02-03 10:48         ` Faiz Abbas
2020-02-03 12:04           ` Peng Fan
2020-02-04 10:24             ` Faiz Abbas
2020-02-09 13:38               ` Wolfgang Denk
2020-02-10 14:28                 ` Tom Rini
2020-02-11 13:56                   ` Wolfgang Denk
2020-02-11 15:08                     ` Wolfgang Denk
2020-02-11 16:25                       ` Wolfgang Denk
2020-02-11 16:47                         ` Tom Rini
2020-01-24 11:52 ` [PATCH v2 03/10] mmc: Merge SD_LEGACY and MMC_LEGACY bus modes Faiz Abbas
2020-01-24 11:52 ` [PATCH v2 04/10] mmc: sdhci: Expose sdhci_init() as non-static Faiz Abbas
2020-01-28 22:59   ` Jaehoon Chung
2020-01-29 14:16     ` Simon Goldschmidt
2020-01-30 22:21       ` Jaehoon Chung
2020-01-30 22:25         ` Simon Goldschmidt
2020-02-04  6:53           ` Faiz Abbas
2020-02-05  7:28             ` Peng Fan
2020-02-05  7:33               ` Faiz Abbas
2020-02-17 12:17                 ` Jaehoon Chung
2020-02-17 12:42                   ` Faiz Abbas
2020-02-17 22:35                     ` Jaehoon Chung
2020-02-17 23:24                       ` Jaehoon Chung
2020-02-18  7:51                         ` Faiz Abbas
2020-02-18  8:20                           ` Jaehoon Chung
2020-01-24 11:52 ` [PATCH v2 05/10] mmc: am654_sdhci: Update output tap delay writes Faiz Abbas
2020-01-24 11:52 ` Faiz Abbas [this message]
2020-01-29 14:18   ` [PATCH v2 06/10] mmc: am654_sdhci: Implement workaround for card detect Simon Goldschmidt
2020-02-10  9:48     ` Faiz Abbas
2020-02-10 11:26       ` Simon Goldschmidt
2020-02-10 23:13         ` Simon Glass
2020-01-24 11:52 ` [PATCH v2 07/10] spl: mmc: Fix spl_mmc_get_uboot_raw_sector() implementation Faiz Abbas
2020-01-24 11:52 ` [PATCH v2 08/10] arm: K3: sysfw-loader: Add a config_pm_pre_callback() Faiz Abbas
2020-01-28 23:30   ` Jaehoon Chung
2020-01-29 14:03     ` Faiz Abbas
2020-01-24 11:52 ` [PATCH v2 09/10] configs: am65x_evm: Add CONFIG_SUPPORT_EMMC_BOOT Faiz Abbas
2020-01-24 11:52 ` [PATCH v2 10/10] configs: j721e_evm: Add Support for eMMC boot 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=20200124115252.15712-7-faiz_abbas@ti.com \
    --to=faiz_abbas@ti.com \
    --cc=u-boot@lists.denx.de \
    /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