Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20b2ab10 authored by Krishna Konda's avatar Krishna Konda
Browse files

mmc: sdhci: fix card detection code



There are certain cases where the card detect gpio is not handled properly
when broken card detection quirk is used.

Currently the code enables polling irrespective of the presence of card
detect gpio when broken card detect quirk is enabled. Instead only enable
polling when the card detect gpio is missing along with the quirk.

Also when checking for the card detect status, check for the presence or
absence of a valid gpio before assuming that the card is always present.

Change-Id: I178b22031704ff102602271ae4ad16e30f14778f
Signed-off-by: default avatarKrishna Konda <kkonda@codeaurora.org>
parent b16fa45c
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -2008,14 +2008,20 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
		return 0;

	/* If polling/nonremovable, assume that the card is always present. */
	if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
	    (host->mmc->caps & MMC_CAP_NONREMOVABLE))
	if (host->mmc->caps & MMC_CAP_NONREMOVABLE)
		return 1;

	/* Try slot gpio detect */
	/*
	 * Try slot gpio detect before checking for the broken card detection
	 * quirk. There might be hosts that might have broken card detection
	 * but still provide a gpio for card detection.
	 */
	if (!IS_ERR_VALUE(gpio_cd))
		return !!gpio_cd;

	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
		return 1;

	/* Host native card detect */
	return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
}
@@ -3582,8 +3588,13 @@ int sdhci_add_host(struct sdhci_host *host)
	if (caps[0] & SDHCI_CAN_DO_HISPD)
		mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;

	/*
	 * Enable polling on when card detection is broken and no card detect
	 * gpio is present.
	 */
	if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
	    !(host->mmc->caps & MMC_CAP_NONREMOVABLE))
	    !(host->mmc->caps & MMC_CAP_NONREMOVABLE) &&
	    (mmc_gpio_get_cd(host->mmc) < 0))
		mmc->caps |= MMC_CAP_NEEDS_POLL;

	/* If vqmmc regulator and no 1.8V signalling, then there's no UHS */