Skip to content

Commit 94144a4

Browse files
Kevin Liucjb
Kevin Liu
authored andcommitted
mmc: sdhci: add get_cd() implementation
1. mmc_rescan will call get_cd to know whether the card is present before mmc_rescan_try_freq to avoid useless trials during card removal or start host is called when card is not present. 2. get_cd needs to be checked to resolve slow card removal issue. Signed-off-by: Kevin Liu <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent 1450734 commit 94144a4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/mmc/host/sdhci.c

+32
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,37 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
15811581
sdhci_runtime_pm_put(host);
15821582
}
15831583

1584+
static int sdhci_do_get_cd(struct sdhci_host *host)
1585+
{
1586+
int gpio_cd = mmc_gpio_get_cd(host->mmc);
1587+
1588+
if (host->flags & SDHCI_DEVICE_DEAD)
1589+
return 0;
1590+
1591+
/* If polling/nonremovable, assume that the card is always present. */
1592+
if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
1593+
(host->mmc->caps & MMC_CAP_NONREMOVABLE))
1594+
return 1;
1595+
1596+
/* Try slot gpio detect */
1597+
if (!IS_ERR_VALUE(gpio_cd))
1598+
return !!gpio_cd;
1599+
1600+
/* Host native card detect */
1601+
return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
1602+
}
1603+
1604+
static int sdhci_get_cd(struct mmc_host *mmc)
1605+
{
1606+
struct sdhci_host *host = mmc_priv(mmc);
1607+
int ret;
1608+
1609+
sdhci_runtime_pm_get(host);
1610+
ret = sdhci_do_get_cd(host);
1611+
sdhci_runtime_pm_put(host);
1612+
return ret;
1613+
}
1614+
15841615
static int sdhci_check_ro(struct sdhci_host *host)
15851616
{
15861617
unsigned long flags;
@@ -2038,6 +2069,7 @@ static void sdhci_card_event(struct mmc_host *mmc)
20382069
static const struct mmc_host_ops sdhci_ops = {
20392070
.request = sdhci_request,
20402071
.set_ios = sdhci_set_ios,
2072+
.get_cd = sdhci_get_cd,
20412073
.get_ro = sdhci_get_ro,
20422074
.hw_reset = sdhci_hw_reset,
20432075
.enable_sdio_irq = sdhci_enable_sdio_irq,

0 commit comments

Comments
 (0)