Skip to content

Commit

Permalink
mmc: sdhci: check the card detection when initialization
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
wenyouya committed Apr 14, 2016
1 parent a11daa2 commit c2e172b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/mmc/sdhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit c2e172b

Please sign in to comment.