diff mbox series

[v1,1/6] mmc: sdhci: Introduce couple of quirks to ignore particular state of CD GPIO

Message ID 20211005102430.63716-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series mmc: sdhci-pci: Add some CD GPIO related quirks | expand

Commit Message

Andy Shevchenko Oct. 5, 2021, 10:24 a.m. UTC
Some platforms may provide contradictory info in some states of CD GPIO line,
and hence that state or states should be ignored. Introduce couple of quirks
for that.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/mmc/host/sdhci.c | 13 ++++++++-----
 drivers/mmc/host/sdhci.h |  4 ++++
 2 files changed, 12 insertions(+), 5 deletions(-)

Comments

Adrian Hunter Oct. 8, 2021, 9:38 a.m. UTC | #1
On 05/10/2021 13:24, Andy Shevchenko wrote:
> Some platforms may provide contradictory info in some states of CD GPIO line,
> and hence that state or states should be ignored. Introduce couple of quirks
> for that.

OK, I have looked closer now :-)

Hooking ->get_cd() should work, and that is preferred to new quirks.
Please try that.

> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/mmc/host/sdhci.c | 13 ++++++++-----
>  drivers/mmc/host/sdhci.h |  4 ++++
>  2 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 357b365bf0ec..a7960ee3ef4f 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -2395,7 +2395,7 @@ EXPORT_SYMBOL_GPL(sdhci_set_ios);
>  static int sdhci_get_cd(struct mmc_host *mmc)
>  {
>  	struct sdhci_host *host = mmc_priv(mmc);
> -	int gpio_cd = mmc_gpio_get_cd(mmc);
> +	int gpio_cd;
>  
>  	if (host->flags & SDHCI_DEVICE_DEAD)
>  		return 0;
> @@ -2405,11 +2405,14 @@ static int sdhci_get_cd(struct mmc_host *mmc)
>  		return 1;
>  
>  	/*
> -	 * Try slot gpio detect, if defined it take precedence
> -	 * over build in controller functionality
> +	 * Try slot GPIO detect, if defined it take precedence
> +	 * over build in controller functionality.
>  	 */
> -	if (gpio_cd >= 0)
> -		return !!gpio_cd;
> +	gpio_cd = mmc_gpio_get_cd(mmc);
> +	if (gpio_cd == 0 && !(host->quirks2 & SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_LOW))
> +		return 0;
> +	if (gpio_cd > 0 && !(host->quirks2 & SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_HIGH))
> +		return 1;
>  
>  	/* If polling, assume that the card is always present. */
>  	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
> index e8d04e42a5af..fb7910d22b18 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -464,6 +464,10 @@ struct sdhci_host {
>  #define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN		(1<<15)
>  /* Controller has CRC in 136 bit Command Response */
>  #define SDHCI_QUIRK2_RSP_136_HAS_CRC			(1<<16)
> +/* Controller requires additional card detection test on GPIO low */
> +#define SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_LOW		(1<<17)
> +/* Controller requires additional card detection test on GPIO high */
> +#define SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_HIGH		(1<<18)
>  /*
>   * Disable HW timeout if the requested timeout is more than the maximum
>   * obtainable timeout.
>
diff mbox series

Patch

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 357b365bf0ec..a7960ee3ef4f 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -2395,7 +2395,7 @@  EXPORT_SYMBOL_GPL(sdhci_set_ios);
 static int sdhci_get_cd(struct mmc_host *mmc)
 {
 	struct sdhci_host *host = mmc_priv(mmc);
-	int gpio_cd = mmc_gpio_get_cd(mmc);
+	int gpio_cd;
 
 	if (host->flags & SDHCI_DEVICE_DEAD)
 		return 0;
@@ -2405,11 +2405,14 @@  static int sdhci_get_cd(struct mmc_host *mmc)
 		return 1;
 
 	/*
-	 * Try slot gpio detect, if defined it take precedence
-	 * over build in controller functionality
+	 * Try slot GPIO detect, if defined it take precedence
+	 * over build in controller functionality.
 	 */
-	if (gpio_cd >= 0)
-		return !!gpio_cd;
+	gpio_cd = mmc_gpio_get_cd(mmc);
+	if (gpio_cd == 0 && !(host->quirks2 & SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_LOW))
+		return 0;
+	if (gpio_cd > 0 && !(host->quirks2 & SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_HIGH))
+		return 1;
 
 	/* If polling, assume that the card is always present. */
 	if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index e8d04e42a5af..fb7910d22b18 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -464,6 +464,10 @@  struct sdhci_host {
 #define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN		(1<<15)
 /* Controller has CRC in 136 bit Command Response */
 #define SDHCI_QUIRK2_RSP_136_HAS_CRC			(1<<16)
+/* Controller requires additional card detection test on GPIO low */
+#define SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_LOW		(1<<17)
+/* Controller requires additional card detection test on GPIO high */
+#define SDHCI_QUIRK_CARD_DETECTION_IF_GPIO_HIGH		(1<<18)
 /*
  * Disable HW timeout if the requested timeout is more than the maximum
  * obtainable timeout.