sdhci: Fix SD card detection issue
PATCH 1/1 sdhci: Fix SD card detection issue
The mmc_gpio_get_cd(...) will return 0 called from sdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, more specificly below if condition is true in mmc_rescan(...):
...
if (mmc_card_is_removable(host) && host->ops->get_cd &&
host->ops->get_cd(host) == 0) {
...
goto out;
}The SD card device will have no chance to be created.
This commit fixes this detection issue via the MMC_CAP2_CD_ACTIVE_HIGH cap2 flag, parsed from the 'cd-inverted' property of DT.
--- drivers/mmc/host/sdhci.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/host/sdhci.c +3 -0
@@ -2483,6 +2483,9 @@ static int sdhci_get_cd(struct mmc_host *mmc)* Try slot gpio detect, if defined it take precedence * over build in controller functionality */ +if (!(mmc->caps2 &MMC_CAP2_CD_ACTIVE_HIGH )) + gpio_cd = !gpio_cd; +if (gpio_cd >=0 )return !!gpio_cd;
Signature · 1 line
2.34.1
Adrian Hunter
maintainerQuoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, more
SDHCI spec covers the SDHCI lines. GPIO is separate.
Quoted 11 lines
specificly below if condition is true in
mmc_rescan(...):... if (mmc_card_is_removable(host) && host->ops->get_cd && host->ops->get_cd(host) == 0) { ... goto out; }The SD card device will have no chance to be created.
This commit fixes this detection issue via the
MMC_CAP2_CD_ACTIVE_HIGHcap2 flag, parsed from the 'cd-inverted' property of DT.
What hardware / driver is it?
Quoted 11 lines
Signed-off-by Richard Clark <[email protected]>--- drivers/mmc/host/sdhci.c | 3 +++ 1 file changed, 3 insertions(+)drivers/mmc/host/sdhci.c +0
-0
drivers/mmc/host/sdhci.c static int sdhci_get_cd(struct mmc_host *mmc) · line 2487
Quoted 5 lines
drivers/mmc/host/sdhci.c +2
-0@@ -2483,6 +2483,9 @@ static int sdhci_get_cd(struct mmc_host *mmc)* Try slot gpio detect, if defined it take precedence * over build in controller functionality */ +if (!(mmc->caps2 &MMC_CAP2_CD_ACTIVE_HIGH )) + gpio_cd = !gpio_cd;
MMC_CAP2_CD_ACTIVE_HIGH is already handled in mmc_gpiod_request_cd(), and this turns an error (gpio_cd < 0) into 0, which is not right.
Quoted 4 lines
drivers/mmc/host/sdhci.c +1
-0+if (gpio_cd >=0 )return !!gpio_cd;
Quoted 6 lines · Adrian Hunter
Quoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, moreSDHCI spec covers the SDHCI lines. GPIO is separate.
... and the key bit of information that should be mentioned is in the case of a GPIO, the GPIO library can be told if a GPIO is active-high or active-low in either firmware or via the GPIO lookup data, and this should be used instead of drivers inventing their own "quirking".
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 7 lines · Russell King (Oracle)
Quoted 5 lines · Adrian Hunter
Quoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, more
Quoted 7 lines
Quoted 1 line
SDHCI spec covers the SDHCI lines. GPIO is separate.
... and the key bit of information that should be mentioned is in the case of a GPIO, the GPIO library can be told if a GPIO is active-high or active-low in either firmware or via the GPIO lookup data, and this should be used instead of drivers inventing their own "quirking".
Agree! But unfortunately, it seems I can't find the right place to handle this from either firmware or via the GPIO lookup data. Will be appreciated if any suggestion about that?!
Quoted 3 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 11 lines · richard clark
Quoted 9 lines · Russell King (Oracle)
Quoted 6 lines · Adrian Hunter
Quoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, moreSDHCI spec covers the SDHCI lines. GPIO is separate.
Quoted 8 lines
Quoted 5 lines
... and the key bit of information that should be mentioned is in the case of a GPIO, the GPIO library can be told if a GPIO is active-high or active-low in either firmware or via the GPIO lookup data, and this should be used instead of drivers inventing their own "quirking".
Agree! But unfortunately, it seems I can't find the right place to handle this from either firmware or via the GPIO lookup data. Will be appreciated if any suggestion about that?!
If you're using DT, then, for example:
cd-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
is all it takes. If you are using firmware then GPIO lookup data isn't what you should be using. I'm afraid I don't know the ACPI bindings for SDHCI.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 22 lines · Russell King (Oracle)
Quoted 11 lines · richard clark
Quoted 9 lines · Russell King (Oracle)
Quoted 6 lines · Adrian Hunter
Quoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, moreSDHCI spec covers the SDHCI lines. GPIO is separate.
Quoted 8 lines
Quoted 5 lines
... and the key bit of information that should be mentioned is in the case of a GPIO, the GPIO library can be told if a GPIO is active-high or active-low in either firmware or via the GPIO lookup data, and this should be used instead of drivers inventing their own "quirking".
Agree! But unfortunately, it seems I can't find the right place to handle this from either firmware or via the GPIO lookup data. Will be appreciated if any suggestion about that?!
Quoted 8 lines
If you're using DT, then, for example:
cd-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;is all it takes. If you are using firmware then GPIO lookup data isn't what you should be using. I'm afraid I don't know the ACPI bindings for SDHCI.
Ah, this seems to be a bug of the Nvidia DT, its cd-gpios=<... 0x00> meaning the GPIO_ACTIVE_HIGH, but the CD gpio value is 0 when the card is inserted. In the kernel v5.10, the sdhci-tegra use below logic as the card present indicator:
if (!host->mmc->cd_cap_invert)
host->mmc->rem_card_present = (mmc_gpio_get_cd(host->mmc) == 0);
But the newer version kernel removes the 'rem_card_present', and the CD gpio still value 0 will be interpreted as the card is not present, thus the issue happens...
Quoted 3 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 17 lines · Adrian Hunter
Quoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, moreSDHCI spec covers the SDHCI lines. GPIO is separate.
Quoted 9 lines
specificly below if condition is true in
mmc_rescan(...):... if (mmc_card_is_removable(host) && host->ops->get_cd && host->ops->get_cd(host) == 0) { ... goto out; }The SD card device will have no chance to be created.
Quoted 4 lines
Quoted 2 lines
This commit fixes this detection issue via the
MMC_CAP2_CD_ACTIVE_HIGHcap2 flag, parsed from the 'cd-inverted' property of DT.What hardware / driver is it?
sdhci-tegra on Orin.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Richard Clark <[email protected]>--- drivers/mmc/host/sdhci.c | 3 +++ 1 file changed, 3 insertions(+)
Quoted 14 lines
drivers/mmc/host/sdhci.c static int sdhci_get_cd(struct mmc_host *mmc) · line 2487
Quoted 10 lines
drivers/mmc/host/sdhci.c +2
-0@@ -2483,6 +2483,9 @@ static int sdhci_get_cd(struct mmc_host *mmc)* Try slot gpio detect, if defined it take precedence * over build in controller functionality */ +if (!(mmc->caps2 &MMC_CAP2_CD_ACTIVE_HIGH )) + gpio_cd = !gpio_cd;
MMC_CAP2_CD_ACTIVE_HIGHis already handled inmmc_gpiod_request_cd(), and this turns an error (gpio_cd< 0) into 0, which is not right.
But in case of 'cd-inverted' is not specified, the gpio CD pin return 0 which will be explained as card is not present.
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +1
-0+if (gpio_cd >=0 )return !!gpio_cd;
Adrian Hunter
maintainer+Nvidia guys
Quoted 52 lines · richard clark
Quoted 17 lines · Adrian Hunter
Quoted 3 lines · Richard Clark
The
mmc_gpio_get_cd(...)will return 0 called fromsdhci_get_cd(...), which means the card is not present. Actually, the card detection pin is active low by default according to the SDHCI psec, thus the card detection result is not correct, moreSDHCI spec covers the SDHCI lines. GPIO is separate.
Quoted 9 lines
specificly below if condition is true in
mmc_rescan(...):... if (mmc_card_is_removable(host) && host->ops->get_cd && host->ops->get_cd(host) == 0) { ... goto out; }The SD card device will have no chance to be created.
Quoted 4 lines
Quoted 2 lines
This commit fixes this detection issue via the
MMC_CAP2_CD_ACTIVE_HIGHcap2 flag, parsed from the 'cd-inverted' property of DT.What hardware / driver is it?
sdhci-tegra on Orin.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Richard Clark <[email protected]>--- drivers/mmc/host/sdhci.c | 3 +++ 1 file changed, 3 insertions(+)Quoted 14 lines
drivers/mmc/host/sdhci.c static int sdhci_get_cd(struct mmc_host *mmc) · line 2487
Quoted 10 lines
drivers/mmc/host/sdhci.c +2
-0@@ -2483,6 +2483,9 @@ static int sdhci_get_cd(struct mmc_host *mmc)* Try slot gpio detect, if defined it take precedence * over build in controller functionality */ +if (!(mmc->caps2 &MMC_CAP2_CD_ACTIVE_HIGH )) + gpio_cd = !gpio_cd;
MMC_CAP2_CD_ACTIVE_HIGHis already handled inmmc_gpiod_request_cd(), and this turns an error (gpio_cd< 0) into 0, which is not right.But in case of 'cd-inverted' is not specified, the gpio CD pin return 0 which will be explained as card is not present.
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +1
-0+if (gpio_cd >=0 )return !!gpio_cd;