linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sdhci: Fix SD card detection issue
@ 2024-04-15  7:06 Richard Clark
  2024-04-15  7:18 ` Adrian Hunter
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Clark @ 2024-04-15  7:06 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson
  Cc: linux-mmc, linux-kernel, linux-arm-kernel, richard.xnu.clark

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.

Signed-off-by: Richard Clark <richard.xnu.clark@gmail.com>
---
 drivers/mmc/host/sdhci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c79f73459915..79f33a161ca8 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -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;
 
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-16  2:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15  7:06 [PATCH] sdhci: Fix SD card detection issue Richard Clark
2024-04-15  7:18 ` Adrian Hunter
2024-04-15  7:22   ` Russell King (Oracle)
2024-04-15  8:17     ` richard clark
2024-04-15  8:23       ` Russell King (Oracle)
2024-04-16  2:15         ` richard clark
2024-04-15  8:11   ` richard clark
2024-04-15  9:35     ` Adrian Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).