]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mmc: sdhci: Implement SDHCI card detect
authorT Karthik Reddy <t.karthik.reddy@xilinx.com>
Wed, 5 Jun 2019 18:40:56 +0000 (00:10 +0530)
committerMichal Simek <michal.simek@xilinx.com>
Fri, 28 Jun 2019 09:25:30 +0000 (11:25 +0200)
Card detect function implemented for SDHCI framework.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
drivers/mmc/sdhci.c
include/sdhci.h

index cdeba914f95cac4037eaf9b9eb521963f9048186..e13f47c2c65391a71d75ac71a17949a1e660db9d 100644 (file)
@@ -12,6 +12,7 @@
 #include <malloc.h>
 #include <mmc.h>
 #include <sdhci.h>
+#include <dm.h>
 
 #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
 void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
@@ -542,9 +543,40 @@ int sdhci_probe(struct udevice *dev)
        return sdhci_init(mmc);
 }
 
+int sdhci_get_cd(struct udevice *dev)
+{
+       struct mmc *mmc = mmc_get_mmc_dev(dev);
+       struct sdhci_host *host = mmc->priv;
+       int value;
+
+       /* If nonremovable, assume that the card is always present. */
+       if (host->host_caps & MMC_CAP_NONREMOVABLE)
+               return 1;
+       /* If polling, assume that the card is always present. */
+       if (host->host_caps & MMC_CAP_NEEDS_POLL)
+               return 1;
+
+#if CONFIG_IS_ENABLED(DM_GPIO)
+       value = dm_gpio_get_value(&host->cd_gpio);
+       if (value >= 0) {
+               if (host->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
+                       return !value;
+               else
+                       return value;
+       }
+#endif
+       value = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
+                  SDHCI_CARD_DETECT_PIN_LEVEL);
+       if (host->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
+               return !value;
+       else
+               return value;
+}
+
 const struct dm_mmc_ops sdhci_ops = {
        .send_cmd       = sdhci_send_command,
        .set_ios        = sdhci_set_ios,
+       .get_cd         = sdhci_get_cd,
 #ifdef MMC_SUPPORTS_TUNING
        .execute_tuning = sdhci_execute_tuning,
 #endif
index bef37df982e4e9e17d3a223d4c81377812f4bb13..6393dee56e04fcfa089079aef6945c13c737541d 100644 (file)
 #define SDHCI_QUIRK_USE_WIDE8          (1 << 8)
 #define SDHCI_QUIRK_NO_1_8_V           (1 << 9)
 
+/*
+ * mmc host capabilities
+ */
+#define MMC_CAP_NONREMOVABLE    BIT(8)
+#define MMC_CAP_NEEDS_POLL      BIT(9)
+#define MMC_CAP_CD_ACTIVE_HIGH  BIT(10)
+
 /* to make gcc happy */
 struct sdhci_host;