2015-06-26 10:00:24

by Ivan T. Ivanov

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

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

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 | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

--
1.9.1


2015-06-26 10:00:43

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH 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 | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index bc14452..8bafb9f 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1601,15 +1601,18 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
if (host->flags & SDHCI_DEVICE_DEAD)
return 0;

+ /*
+ * 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/nonremovable, assume that the card is always present. */
if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
(host->mmc->caps & MMC_CAP_NONREMOVABLE))
return 1;

- /* Try slot gpio detect */
- if (!IS_ERR_VALUE(gpio_cd))
- return !!gpio_cd;
-
/* Host native card detect */
return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
}
--
1.9.1

2015-06-26 10:00:39

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH 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 8bafb9f..0b65752 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -3121,7 +3121,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-06-26 10:00:33

by Ivan T. Ivanov

[permalink] [raw]
Subject: [PATCH 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 0b65752..912a3bb 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-06-26 10:22:20

by Adrian Hunter

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

On 26/06/15 13:00, Ivan T. Ivanov wrote:
> 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 | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index bc14452..8bafb9f 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -1601,15 +1601,18 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
> if (host->flags & SDHCI_DEVICE_DEAD)
> return 0;
>
> + /*
> + * Try slot gpio detect, if defined it take precedence
> + * over build in controller functionality
> + */
> + if (!IS_ERR_VALUE(gpio_cd))
> + return !!gpio_cd;
> +

You've also put it above the MMC_CAP_NONREMOVABLE check which doesn't seem
right.

> /* If polling/nonremovable, assume that the card is always present. */
> if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
> (host->mmc->caps & MMC_CAP_NONREMOVABLE))
> return 1;
>
> - /* Try slot gpio detect */
> - if (!IS_ERR_VALUE(gpio_cd))
> - return !!gpio_cd;
> -
> /* Host native card detect */
> return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
> }
> --
> 1.9.1
>
>
>

2015-06-26 10:31:15

by Jaehoon Chung

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

Hi, Ivan.

On 06/26/2015 07:00 PM, Ivan T. Ivanov wrote:
> Following changes aimed to fix some aspects of card detection, when
> BROKEN_CARD_DETECTION quirk is set.

As i know, when there is no card detection scheme, BROKEN_CARD_DETECTION quirks is set.
If it can use CD_GPIO, doesn't it need to set BROKEN_CARD_DETECTION?
Just wondering..

Best Regards,
Jaehoon Chung

>
> 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 | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2015-06-26 11:00:24

by Ivan T. Ivanov

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


On Fri, 2015-06-26 at 13:19 +0300, Adrian Hunter wrote:
> On 26/06/15 13:00, Ivan T. Ivanov wrote:
> > 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 | 11 +++++++----
> > 1 file changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> > index bc14452..8bafb9f 100644
> > --- a/drivers/mmc/host/sdhci.c
> > +++ b/drivers/mmc/host/sdhci.c
> > @@ -1601,15 +1601,18 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
> > if (host->flags & SDHCI_DEVICE_DEAD)
> > return 0;
> >
> > + /*
> > + * Try slot gpio detect, if defined it take precedence
> > + * over build in controller functionality
> > + */
> > + if (!IS_ERR_VALUE(gpio_cd))
> > + return !!gpio_cd;
> > +
>
> You've also put it above the MMC_CAP_NONREMOVABLE check which doesn't seem
> right.
>

Probably, but what are the chances that this is valid GIO for non-removable cards.
I could rework it if you insist.

Thank you,
Ivan

> > /* If polling/nonremovable, assume that the card is always present. */
> > if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
> > (host->mmc->caps & MMC_CAP_NONREMOVABLE))
> > return 1;
> >
> > - /* Try slot gpio detect */
> > - if (!IS_ERR_VALUE(gpio_cd))
> > - return !!gpio_cd;
> > -
> > /* Host native card detect */
> > return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
> > }
> > --
> > 1.9.1
> >
> >
> >
>
>

2015-06-26 11:06:06

by Ivan T. Ivanov

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


On Fri, 2015-06-26 at 19:31 +0900, Jaehoon Chung wrote:
> Hi, Ivan.
>
> On 06/26/2015 07:00 PM, Ivan T. Ivanov wrote:
> > Following changes aimed to fix some aspects of card detection, when
> > BROKEN_CARD_DETECTION quirk is set.
>
> As i know, when there is no card detection scheme, BROKEN_CARD_DETECTION quirks is set.
> If it can use CD_GPIO, doesn't it need to set BROKEN_CARD_DETECTION?
> Just wondering..
>

I am not sure that I get this. My understanding is that if controller have
issues reporting card present state, users could use GPIO for card state sensing.

Probably this don't sound reasonable, but someone could just want to ignore
controller capabilities and use GPIO explicitly.

Regards,
Ivan

> Best Regards,
> Jaehoon Chung
>
> > 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 | 17 ++++++++++-------
> > 1 file changed, 10 insertions(+), 7 deletions(-)
> >
> > --
> > 1.9.1
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
>
>

2015-06-26 11:12:10

by Adrian Hunter

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

On 26/06/15 14:00, Ivan T. Ivanov wrote:
>
> On Fri, 2015-06-26 at 13:19 +0300, Adrian Hunter wrote:
>> On 26/06/15 13:00, Ivan T. Ivanov wrote:
>>> 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 | 11 +++++++----
>>> 1 file changed, 7 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>>> index bc14452..8bafb9f 100644
>>> --- a/drivers/mmc/host/sdhci.c
>>> +++ b/drivers/mmc/host/sdhci.c
>>> @@ -1601,15 +1601,18 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
>>> if (host->flags & SDHCI_DEVICE_DEAD)
>>> return 0;
>>>
>>> + /*
>>> + * Try slot gpio detect, if defined it take precedence
>>> + * over build in controller functionality
>>> + */
>>> + if (!IS_ERR_VALUE(gpio_cd))
>>> + return !!gpio_cd;
>>> +
>>
>> You've also put it above the MMC_CAP_NONREMOVABLE check which doesn't seem
>> right.
>>
>
> Probably, but what are the chances that this is valid GIO for non-removable cards.
> I could rework it if you insist.

It is nicer not to have to think "what are the chances", and nicer that the
logic is strictly correct, so yes please.

>
> Thank you,
> Ivan
>
>>> /* If polling/nonremovable, assume that the card is always present. */
>>> if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) ||
>>> (host->mmc->caps & MMC_CAP_NONREMOVABLE))
>>> return 1;
>>>
>>> - /* Try slot gpio detect */
>>> - if (!IS_ERR_VALUE(gpio_cd))
>>> - return !!gpio_cd;
>>> -
>>> /* Host native card detect */
>>> return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
>>> }
>>> --
>>> 1.9.1
>>>
>>>
>>>
>>
>>
>
>

2015-06-26 11:13:05

by Ivan T. Ivanov

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


On Fri, 2015-06-26 at 14:09 +0300, Adrian Hunter wrote:
> On 26/06/15 14:00, Ivan T. Ivanov wrote:
> > On Fri, 2015-06-26 at 13:19 +0300, Adrian Hunter wrote:
> > > On 26/06/15 13:00, Ivan T. Ivanov wrote:
> > > > 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 | 11 +++++++----
> > > > 1 file changed, 7 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> > > > index bc14452..8bafb9f 100644
> > > > --- a/drivers/mmc/host/sdhci.c
> > > > +++ b/drivers/mmc/host/sdhci.c
> > > > @@ -1601,15 +1601,18 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
> > > > if (host->flags & SDHCI_DEVICE_DEAD)
> > > > return 0;
> > > >
> > > > + /*
> > > > + * Try slot gpio detect, if defined it take precedence
> > > > + * over build in controller functionality
> > > > + */
> > > > + if (!IS_ERR_VALUE(gpio_cd))
> > > > + return !!gpio_cd;
> > > > +
> > >
> > > You've also put it above the MMC_CAP_NONREMOVABLE check which doesn't seem
> > > right.
> > >
> >
> > Probably, but what are the chances that this is valid GIO for non-removable cards.
> > I could rework it if you insist.
>
> It is nicer not to have to think "what are the chances", and nicer that the
> logic is strictly correct, so yes please.
>

Sure, will do.

Thanks,
Ivan