* [PATCH] mmc_spi: Fix cd-gpios for SPI SD card insertion/removal detection
@ 2025-08-24 8:47 cuu
0 siblings, 0 replies; only message in thread
From: cuu @ 2025-08-24 8:47 UTC (permalink / raw)
To: ulf.hansson; +Cc: linux-mmc, cuu
Previously, SD cards using pure SPI protocol with mmc_spi could not
reliably detect card removal via cd-gpios. This patch fixes the issue
by extending the card alive check in _mmc_detect_card_removed() to
include cd-gpios detection.
Additionally, mmc_rescan() now includes a status probing function
specific to SPI SD cards to ensure the card state is correctly updated
on insertion and removal events.
Signed-off-by: cuu <dexterkidd@gmail.com>
---
drivers/mmc/core/core.c | 15 ++++++++++++---
drivers/mmc/core/core.h | 1 +
drivers/mmc/core/mmc.c | 8 ++++++++
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 874c6fe92855..e028ec8fbf46 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2123,6 +2123,11 @@ int _mmc_detect_card_removed(struct mmc_host *host)
ret = host->bus_ops->alive(host);
+ if(mmc_host_is_spi(host)) {
+ if(host->ops->get_cd){
+ ret = !host->ops->get_cd(host);
+ }
+ }
/*
* Card detect status and alive check may be out of sync if card is
* removed slowly, when card detect switch changes while card/slot
@@ -2238,9 +2243,13 @@ void mmc_rescan(struct work_struct *work)
}
/* Verify a registered card to be functional, else remove it. */
- if (host->bus_ops)
- host->bus_ops->detect(host);
-
+ if (host->bus_ops){
+ if (mmc_host_is_spi(host)){
+ mmc_detect_mmc(host);
+ }else{
+ host->bus_ops->detect(host);
+ }
+ }
host->detect_change = 0;
/* if there still is a card present, stop here */
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 622085cd766f..5b48c50b5bb5 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -78,6 +78,7 @@ void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
int _mmc_detect_card_removed(struct mmc_host *host);
int mmc_detect_card_removed(struct mmc_host *host);
+int mmc_detect_mmc(struct mmc_host *host);
int mmc_attach_mmc(struct mmc_host *host);
int mmc_attach_sd(struct mmc_host *host);
int mmc_attach_sdio(struct mmc_host *host);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 5be9b42d5057..e73de34e072b 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -2316,6 +2316,14 @@ static const struct mmc_bus_ops mmc_ops = {
.flush_cache = _mmc_flush_cache,
};
+/*
+ * Export function for mmc detection
+ */
+int mmc_detect_mmc(struct mmc_host *host){
+ mmc_detect(host);
+ return 0;
+}
+
/*
* Starting point for MMC card init.
*/
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-08-24 8:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-24 8:47 [PATCH] mmc_spi: Fix cd-gpios for SPI SD card insertion/removal detection cuu
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).