* [PATCH v2 1/2] misc: rtsx_usb: avoid USB I/O in runtime autosuspend
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 ` Sean Rhodes
2026-07-06 15:40 ` [PATCH v2 2/2] mmc: rtsx_usb_sdmmc: suppress false CD after init timeout Sean Rhodes
1 sibling, 0 replies; 3+ messages in thread
From: Sean Rhodes @ 2026-07-06 15:40 UTC (permalink / raw)
To: Ulf Hansson
Cc: Arnd Bergmann, Greg Kroah-Hartman, Ricky Wu, Sean Rhodes,
Lee Jones, Roger Tseng, Dan Carpenter, Jisheng Zhang, linux-mmc,
linux-kernel
The runtime autosuspend callback currently queries card status and
clears OCP by issuing USB register accesses. This can run from the
USB runtime-PM path itself, which is the wrong place to start more
device I/O.
Keep a cached copy of the card-status bits from normal status reads
instead. During runtime autosuspend, use that cached value only to
preserve the existing Memory Stick autosuspend deferral.
Do not treat raw SD_CD as an autosuspend blocker, because tray-based
SD readers can assert SD_CD with an empty tray. A real SD card is
protected by the SD/MMC child runtime-PM usage once powered.
Also stop clearing OCP from the runtime autosuspend callback, so the
callback does not issue USB commands.
Fixes: bb400d2120bd ("mfd: rtsx_usb: Defer autosuspend while card exists")
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
drivers/misc/cardreader/rtsx_usb.c | 26 ++++++++++++++++++++------
include/linux/rtsx_usb.h | 3 +++
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/misc/cardreader/rtsx_usb.c b/drivers/misc/cardreader/rtsx_usb.c
index 1830e9ed2521..a127744918f4 100644
--- a/drivers/misc/cardreader/rtsx_usb.c
+++ b/drivers/misc/cardreader/rtsx_usb.c
@@ -312,6 +312,9 @@ int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status)
if (ret < 0)
return ret;
+ ucr->card_status_cache = *status;
+ ucr->card_status_valid = true;
+
return 0;
}
EXPORT_SYMBOL_GPL(rtsx_usb_get_card_status);
@@ -623,6 +626,7 @@ static int rtsx_usb_probe(struct usb_interface *intf,
{
struct usb_device *usb_dev = interface_to_usbdev(intf);
struct rtsx_ucr *ucr;
+ u16 status;
int ret;
dev_dbg(&intf->dev,
@@ -659,6 +663,9 @@ static int rtsx_usb_probe(struct usb_interface *intf,
if (ret)
goto out_init_fail;
+ /* Prime cached status for runtime autosuspend decisions. */
+ rtsx_usb_get_card_status(ucr, &status);
+
/* initialize USB SG transfer timer */
timer_setup(&ucr->sg_timer, rtsx_usb_sg_timed_out, 0);
@@ -713,22 +720,29 @@ static int rtsx_usb_suspend(struct usb_interface *intf, pm_message_t message)
struct rtsx_ucr *ucr =
(struct rtsx_ucr *)usb_get_intfdata(intf);
u16 val = 0;
+ bool valid = false;
dev_dbg(&intf->dev, "%s called with pm message 0x%04x\n",
__func__, message.event);
if (PMSG_IS_AUTO(message)) {
if (mutex_trylock(&ucr->dev_mutex)) {
- rtsx_usb_get_card_status(ucr, &val);
+ valid = ucr->card_status_valid;
+ if (valid)
+ val = ucr->card_status_cache;
mutex_unlock(&ucr->dev_mutex);
- /* Defer the autosuspend if card exists */
- if (val & (SD_CD | MS_CD)) {
+ /*
+ * Do not issue USB commands from runtime autosuspend.
+ * Raw SD_CD is not authoritative on tray-based readers,
+ * while a real SD card is protected by the SD/MMC child
+ * runtime-PM reference once the card is powered. Keep
+ * the historical Memory Stick autosuspend deferral when
+ * the cached status says MS media is present.
+ */
+ if (valid && (val & MS_CD)) {
device_for_each_child(&intf->dev, NULL, rtsx_usb_resume_child);
return -EAGAIN;
- } else {
- /* if the card does not exists, clear OCP status */
- rtsx_usb_write_register(ucr, OCPCTL, MS_OCP_CLEAR, MS_OCP_CLEAR);
}
} else {
/* There is an ongoing operation*/
diff --git a/include/linux/rtsx_usb.h b/include/linux/rtsx_usb.h
index 276b509c03e3..0fc5a74700a8 100644
--- a/include/linux/rtsx_usb.h
+++ b/include/linux/rtsx_usb.h
@@ -61,6 +61,9 @@ struct rtsx_ucr {
struct timer_list sg_timer;
struct mutex dev_mutex;
+
+ u16 card_status_cache;
+ bool card_status_valid;
};
/* buffer size */
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2 2/2] mmc: rtsx_usb_sdmmc: suppress false CD after init timeout
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-07-06 15:40 ` Sean Rhodes
1 sibling, 0 replies; 3+ messages in thread
From: Sean Rhodes @ 2026-07-06 15:40 UTC (permalink / raw)
To: Ulf Hansson
Cc: Arnd Bergmann, Greg Kroah-Hartman, Ricky Wu, Sean Rhodes,
Lee Jones, Roger Tseng, Dan Carpenter, Jisheng Zhang, linux-mmc,
linux-kernel
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)
^ permalink raw reply related [flat|nested] 3+ messages in thread