diff mbox

mmc: sdhci: Test cd-gpio instead of SDHCI presence when probing

Message ID m3a9wpyqnc.fsf_-_@pullcord.laptop.org (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Chris Ball Sept. 17, 2012, 8:55 a.m. UTC
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Previously to this patch, an SDHCI platform that uses a GPIO for
card detection instead of the internal SDHCI_CARD_PRESENT bit on
the presence register would fail to bring up a new card because
logic in sdhci_request() fails the request if that bit is 0.

Some drivers worked around this in various ways: esdhc-imx defines
an IO accessor to fake the presence bit being true, s3c turns on
polling (which stops the SDHCI driver from checking the bit) after
a card's inserted.  But none of this should be necessary; the real
fix is to check whether we're using a GPIO and avoid relying on
the presence bit if so, as this patch implements.

Signed-off-by: Chris Ball <cjb@laptop.org>
---
 drivers/mmc/host/sdhci.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Guennadi Liakhovetski Sept. 17, 2012, 9:09 a.m. UTC | #1
On Mon, 17 Sep 2012, Chris Ball wrote:

> From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> 
> Previously to this patch, an SDHCI platform that uses a GPIO for
> card detection instead of the internal SDHCI_CARD_PRESENT bit on
> the presence register would fail to bring up a new card because
> logic in sdhci_request() fails the request if that bit is 0.
> 
> Some drivers worked around this in various ways: esdhc-imx defines
> an IO accessor to fake the presence bit being true, s3c turns on
> polling (which stops the SDHCI driver from checking the bit) after
> a card's inserted.  But none of this should be necessary; the real
> fix is to check whether we're using a GPIO and avoid relying on
> the presence bit if so, as this patch implements.
> 

Well, ok, thanks for attributing this patch to me:-) I guess then my Sob 
should go in the first, as you'll be forwarding the patch upstream? But 
feel free to swap them if you disagree

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Thanks
Guennadi

> Signed-off-by: Chris Ball <cjb@laptop.org>
> ---
>  drivers/mmc/host/sdhci.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index d98b199..0e15c79 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -28,6 +28,7 @@
>  #include <linux/mmc/mmc.h>
>  #include <linux/mmc/host.h>
>  #include <linux/mmc/card.h>
> +#include <linux/mmc/slot-gpio.h>
>  
>  #include "sdhci.h"
>  
> @@ -1293,6 +1294,13 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>  		present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
>  				SDHCI_CARD_PRESENT;
>  
> +	/* If we're using a cd-gpio, testing the presence bit might fail. */
> +	if (!present) {
> +		int ret = mmc_gpio_get_cd(host->mmc);
> +		if (ret > 0)
> +			present = true;
> +	}
> +
>  	if (!present || host->flags & SDHCI_DEVICE_DEAD) {
>  		host->mrq->cmd->error = -ENOMEDIUM;
>  		tasklet_schedule(&host->finish_tasklet);
> -- 
> 1.7.11.2
> 
> 
> 
> - Chris.
> -- 
> Chris Ball   <cjb@laptop.org>   <http://printf.net/>
> One Laptop Per Child
> 

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chris Ball Sept. 17, 2012, 10:08 a.m. UTC | #2
Hi,

On Mon, Sep 17 2012, Guennadi Liakhovetski wrote:
> On Mon, 17 Sep 2012, Chris Ball wrote:
>
>> From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
>> 
>> Previously to this patch, an SDHCI platform that uses a GPIO for
>> card detection instead of the internal SDHCI_CARD_PRESENT bit on
>> the presence register would fail to bring up a new card because
>> logic in sdhci_request() fails the request if that bit is 0.
>> 
>> Some drivers worked around this in various ways: esdhc-imx defines
>> an IO accessor to fake the presence bit being true, s3c turns on
>> polling (which stops the SDHCI driver from checking the bit) after
>> a card's inserted.  But none of this should be necessary; the real
>> fix is to check whether we're using a GPIO and avoid relying on
>> the presence bit if so, as this patch implements.
>> 
>
> Well, ok, thanks for attributing this patch to me:-) I guess then my Sob 
> should go in the first, as you'll be forwarding the patch upstream? But 
> feel free to swap them if you disagree
>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Yes, I'll put yours in first.  Pushed to mmc-next for 3.7; thanks!

- Chris.
diff mbox

Patch

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index d98b199..0e15c79 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -28,6 +28,7 @@ 
 #include <linux/mmc/mmc.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/card.h>
+#include <linux/mmc/slot-gpio.h>
 
 #include "sdhci.h"
 
@@ -1293,6 +1294,13 @@  static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 		present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
 				SDHCI_CARD_PRESENT;
 
+	/* If we're using a cd-gpio, testing the presence bit might fail. */
+	if (!present) {
+		int ret = mmc_gpio_get_cd(host->mmc);
+		if (ret > 0)
+			present = true;
+	}
+
 	if (!present || host->flags & SDHCI_DEVICE_DEAD) {
 		host->mrq->cmd->error = -ENOMEDIUM;
 		tasklet_schedule(&host->finish_tasklet);