From: Sean Rhodes <sean@starlabs.systems>
To: Ulf Hansson <ulfh@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ricky Wu <ricky_wu@realtek.com>,
Sean Rhodes <sean@starlabs.systems>, Lee Jones <lee@kernel.org>,
Roger Tseng <rogerable@realtek.com>,
Dan Carpenter <error27@gmail.com>,
Jisheng Zhang <jszhang@kernel.org>,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] mmc: rtsx_usb_sdmmc: suppress false CD after init timeout
Date: Mon, 6 Jul 2026 16:40:44 +0100 [thread overview]
Message-ID: <1d6f22a3777e78d6232cbe7dc3aa17ded8fc32e2.1783352430.git.sean@starlabs.systems> (raw)
In-Reply-To: <cover.1783352430.git.sean@starlabs.systems>
Some Realtek USB SD readers with a tray keep raw SD_CD asserted
when an empty tray is inserted. The MMC core then repeatedly tries to
initialize non-existent media, sees command timeouts, calls ->get_cd()
again, and starts the same detect cycle over.
Do not qualify media by open-coding MMC commands in ->get_cd().
Instead, let the normal MMC rescan path probe the card. If an
initialization command times out before a card has been attached,
suppress the raw SD_CD signal so the host can settle and the USB
parent can autosuspend.
Clear the suppression only when raw SD_CD drops. On the affected tray
reader, changing media requires removing and reinserting the tray, so
a low CD transition is the signal that a new insertion attempt can be
trusted again.
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
drivers/mmc/host/rtsx_usb_sdmmc.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
index 84674659a84d..bf37fab233cf 100644
--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
+++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
@@ -44,6 +44,7 @@ struct rtsx_usb_sdmmc {
bool double_clk;
bool host_removal;
bool card_exist;
+ bool suppress_cd;
bool initial_mode;
bool ddr_mode;
@@ -774,6 +775,7 @@ static int sdmmc_get_cd(struct mmc_host *mmc)
struct rtsx_ucr *ucr = host->ucr;
int err;
u16 val;
+ bool cd;
if (host->host_removal)
return -ENOMEDIUM;
@@ -791,8 +793,14 @@ static int sdmmc_get_cd(struct mmc_host *mmc)
/* get OCP status */
host->ocp_stat = (val >> 4) & 0x03;
+ cd = val & SD_CD;
- if (val & SD_CD) {
+ if (!cd) {
+ WRITE_ONCE(host->suppress_cd, false);
+ goto no_card;
+ }
+
+ if (!READ_ONCE(host->suppress_cd)) {
host->card_exist = true;
return 1;
}
@@ -874,6 +882,8 @@ static void sdmmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
* detect card when fail to update card existence state and
* speed up card removal when retry
*/
+ if (!mmc->card && cmd->error == -ETIMEDOUT)
+ WRITE_ONCE(host->suppress_cd, true);
sdmmc_get_cd(mmc);
dev_dbg(sdmmc_dev(host), "cmd->error = %d\n", cmd->error);
}
@@ -1359,6 +1369,7 @@ static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host)
host->power_mode = MMC_POWER_OFF;
host->ocp_stat = 0;
+ host->suppress_cd = false;
}
static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
next prev parent reply other threads:[~2026-07-06 15:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 15:40 [PATCH v2 0/2] rtsx_usb: fix tray-reader false card detect and autosuspend Sean Rhodes
2026-07-06 15:40 ` [PATCH v2 1/2] misc: rtsx_usb: avoid USB I/O in runtime autosuspend Sean Rhodes
2026-10-05 8:30 ` Michal Pecio
2026-10-12 21:34 ` Sean Rhodes
2026-10-13 12:27 ` Michal Pecio
2026-10-13 12:31 ` Sean Rhodes
2026-10-13 12:38 ` Michal Pecio
2026-10-13 13:48 ` Sean Rhodes
2026-10-14 20:24 ` Michal Pecio
2026-07-06 15:40 ` Sean Rhodes [this message]
2026-07-10 13:21 ` [PATCH v2 0/2] rtsx_usb: fix tray-reader false card detect and autosuspend Ulf Hansson
2026-07-10 14:23 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1d6f22a3777e78d6232cbe7dc3aa17ded8fc32e2.1783352430.git.sean@starlabs.systems \
--to=sean@starlabs.systems \
--cc=arnd@arndb.de \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jszhang@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ricky_wu@realtek.com \
--cc=rogerable@realtek.com \
--cc=ulfh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®