]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
drivers: mmc: Add wait_dat0 support for sdhci driver
authorStephen Carlson <stcarlso@linux.microsoft.com>
Tue, 17 Aug 2021 19:46:41 +0000 (12:46 -0700)
committerJaehoon Chung <jh80.chung@samsung.com>
Fri, 29 Oct 2021 09:22:32 +0000 (18:22 +0900)
Adds an implementation of the wait_dat0 MMC operation for the DM SDHCI
driver, allowing the driver to continue when the card is ready rather
than waiting for the worst case time on each MMC switch operation.

Signed-off-by: Stephen Carlson <stcarlso@linux.microsoft.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/mmc/sdhci.c
include/sdhci.h

index 03bfd9d18aea1f78edc71e2fe406a807a2823cd4..766e4a6b0c5eeb1b7fd2fe32bafd62f349432922 100644 (file)
@@ -780,6 +780,25 @@ static int sdhci_get_cd(struct udevice *dev)
                return value;
 }
 
+static int sdhci_wait_dat0(struct udevice *dev, int state,
+                          int timeout_us)
+{
+       int tmp;
+       struct mmc *mmc = mmc_get_mmc_dev(dev);
+       struct sdhci_host *host = mmc->priv;
+       unsigned long timeout = timer_get_us() + timeout_us;
+
+       // readx_poll_timeout is unsuitable because sdhci_readl accepts
+       // two arguments
+       do {
+               tmp = sdhci_readl(host, SDHCI_PRESENT_STATE);
+               if (!!(tmp & SDHCI_DATA_0_LVL_MASK) == !!state)
+                       return 0;
+       } while (!timeout_us || !time_after(timer_get_us(), timeout));
+
+       return -ETIMEDOUT;
+}
+
 const struct dm_mmc_ops sdhci_ops = {
        .send_cmd       = sdhci_send_command,
        .set_ios        = sdhci_set_ios,
@@ -788,6 +807,7 @@ const struct dm_mmc_ops sdhci_ops = {
 #ifdef MMC_SUPPORTS_TUNING
        .execute_tuning = sdhci_execute_tuning,
 #endif
+       .wait_dat0      = sdhci_wait_dat0,
 };
 #else
 static const struct mmc_ops sdhci_ops = {
index 44a0d84e5ab37b7678209d3a45a466042eda964f..c718dd7206c1e2171465bf540963e9a6f163184a 100644 (file)
@@ -65,6 +65,8 @@
 #define  SDHCI_CARD_STATE_STABLE       BIT(17)
 #define  SDHCI_CARD_DETECT_PIN_LEVEL   BIT(18)
 #define  SDHCI_WRITE_PROTECT   BIT(19)
+#define  SDHCI_DATA_LVL_MASK   0x00F00000
+#define   SDHCI_DATA_0_LVL_MASK BIT(20)
 
 #define SDHCI_HOST_CONTROL     0x28
 #define  SDHCI_CTRL_LED                BIT(0)