From c2e172b678be7116b4f2b8cd0274d5d69640362c Mon Sep 17 00:00:00 2001 From: Wenyou Yang Date: Mon, 21 Mar 2016 15:55:56 +0800 Subject: [PATCH] mmc: sdhci: check the card detection when initialization To be sure about the state of the card detection, we have to check all three bits(i.e. Card Detect Pin Level, Card State Stable and Card Inserted) at the same time. Signed-off-by: Wenyou Yang --- drivers/mmc/sdhci.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 1ab5d155d41..fb3de3f2783 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -451,6 +451,7 @@ static void sdhci_set_ios(struct mmc *mmc) static int sdhci_init(struct mmc *mmc) { struct sdhci_host *host = mmc->priv; + u32 status, timeout, card_detect_mask; if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && !aligned_buffer) { aligned_buffer = memalign(8, 512*1024); @@ -481,6 +482,19 @@ static int sdhci_init(struct mmc *mmc) (!(status & SDHCI_CARD_DETECT_PIN_LEVEL))) status = sdhci_readl(host, SDHCI_PRESENT_STATE); #endif + } else { + timeout = 1000000; + card_detect_mask = SDHCI_CARD_PRESENT | + SDHCI_CARD_STATE_STABLE | + SDHCI_CARD_DETECT_PIN_LEVEL; + + status = sdhci_readl(host, SDHCI_PRESENT_STATE); + while (!((status & card_detect_mask) == card_detect_mask) && + timeout--) + status = sdhci_readl(host, SDHCI_PRESENT_STATE); + + if (!timeout) + return -1; } /* Enable only interrupts served by the SD controller */