2015-07-06 12:16:35

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH v2 0/3] mmc: sdhci: Card detection fixes

Following changes aimed to fix some aspects of card detection, when
BROKEN_CARD_DETECTION quirk is set.

Changes since first version [1]:

* Patch 1/3 is a modified to first check for MMC_CAP_NONREMOVABLE
and then check for a valid value in "gpio_cd"

[1] http://permalink.gmane.org/gmane.linux.kernel.mmc/32875

Ivan T. Ivanov (3):
mmc: sdhci: let GPIO based card detection have higher precedence
mmc: sdhci: don't use card state polling when CD GPIO is defined
mmc: sdhci: properly check card present state when quirk
NO_CARD_NO_RESET is set

drivers/mmc/host/sdhci.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

--
1.9.1


2015-07-06 12:17:37

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH v2 1/3] mmc: sdhci: let GPIO based card detection have higher precedence

Controller could have BROKEN_CARD_DETECTION quirk set, but drivers
could use GPIO to detect card present state. Let, when defined, GPIO
take precedence, so drivers could properly detect card state and not
use polling.

Signed-off-by: Ivan T. Ivanov <[email protected]>
---
drivers/mmc/host/sdhci.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index bc14452..dd91b24 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1601,15 +1601,21 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
if (host->flags & SDHCI_DEVICE_DEAD)
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 nonremovable, assume that the card is always present. */
+ if (host->mmc->caps & MMC_CAP_NONREMOVABLE)
return 1;

- /* Try slot gpio detect */
+ /*
+ * Try slot gpio detect, if defined it take precedence
+ * over build in controller functionality
+ */
if (!IS_ERR_VALUE(gpio_cd))
return !!gpio_cd;

+ /* If polling, assume that the card is always present. */
+ if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
+ return 1;
+
/* Host native card detect */
return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
}
--
1.9.1

2015-07-06 12:17:17

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH v2 2/3] mmc: sdhci: don't use card state polling when CD GPIO is defined

There is no reason to use polling for card detection state change when
drivers are using dedicated GPIO for this. Don't poll in this case.

Signed-off-by: Ivan T. Ivanov <[email protected]>
---
drivers/mmc/host/sdhci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index dd91b24..02ac7a4 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -3124,7 +3124,8 @@ int sdhci_add_host(struct sdhci_host *host)
mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;

if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
- !(mmc->caps & MMC_CAP_NONREMOVABLE))
+ !(mmc->caps & MMC_CAP_NONREMOVABLE) &&
+ IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc)))
mmc->caps |= MMC_CAP_NEEDS_POLL;

/* If there are external regulators, get them */
--
1.9.1

2015-07-06 12:16:39

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH v2 3/3] mmc: sdhci: properly check card present state when quirk NO_CARD_NO_RESET is set

Controller could have both NO_CARD_NO_RESET and BROKEN_CARD_DETECTION
quirks set. Use sdhci_do_get_cd() when applying NO_CARD_NO_RESET, which
properly check for BROKEN_CARD_DETECTION quirk.

Signed-off-by: Ivan T. Ivanov <[email protected]>
---
drivers/mmc/host/sdhci.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 02ac7a4..e22e47c 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -207,8 +207,7 @@ EXPORT_SYMBOL_GPL(sdhci_reset);
static void sdhci_do_reset(struct sdhci_host *host, u8 mask)
{
if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
- if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
- SDHCI_CARD_PRESENT))
+ if (!sdhci_do_get_cd(host))
return;
}

--
1.9.1

2015-07-20 14:22:05

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] mmc: sdhci: Card detection fixes

On 6 July 2015 at 14:16, Ivan T. Ivanov <[email protected]> wrote:
> Following changes aimed to fix some aspects of card detection, when
> BROKEN_CARD_DETECTION quirk is set.
>
> Changes since first version [1]:
>
> * Patch 1/3 is a modified to first check for MMC_CAP_NONREMOVABLE
> and then check for a valid value in "gpio_cd"
>
> [1] http://permalink.gmane.org/gmane.linux.kernel.mmc/32875
>
> Ivan T. Ivanov (3):
> mmc: sdhci: let GPIO based card detection have higher precedence
> mmc: sdhci: don't use card state polling when CD GPIO is defined
> mmc: sdhci: properly check card present state when quirk
> NO_CARD_NO_RESET is set
>
> drivers/mmc/host/sdhci.c | 20 +++++++++++++-------
> 1 file changed, 13 insertions(+), 7 deletions(-)
>
> --
> 1.9.1
>

Thanks, applied!

Kind regards
Uffe