Skip to contentSkip to conversation

misc: rtsx: Avoid wakeup events from runtime resume during system sleep

PATCH New Adrian Hunter 1 participant 1 message Nov 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: rtsx: Avoid wakeup events from runtime resume during system sleep

Userspace such as KDE Plasma writes /sys/power/wakeup_count before entering system sleep, so that the kernel aborts the transition if a wakeup event is reported. On machines with a Realtek PCIe card reader, suspend then fails:

PM: Wakeup pending, aborting suspend
PM: active wakeup source: mmc0

During a system sleep transition, the card reader gets runtime resumed, for example by mmc_claim_host() in mmc_queue_suspend(), or by pci_pm_suspend() and pci_pm_freeze(). rtsx_pci_runtime_resume() then calls the SD slot card_event() callback, which calls mmc_detect_change(), which reports a wakeup event that aborts the transition. Plasma writes wakeup_count before hibernation too, so hibernation is affected as well.

The rescan is not needed then, because the mmc host class .complete() callback always triggers a rescan at the end of the transition, including when it is aborted.

Skip card_event() while dev->power.is_prepared is set. The PM core sets it after the PCI device is prepared and clears it before the device is completed. The PCI device is prepared before, and completed after, its mmc host descendant, so every skipped card_event() is followed by that rescan.

---

Note, this patch has not been tested at all, however WisdomWebMan offered to do testing.

 drivers/misc/cardreader/rtsx_pcr.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/misc/cardreader/rtsx_pcr.c +7 -1
index c6e602523538..4b9585c961df 100644
@@ -1800,7 +1800,13 @@ static int rtsx_pci_runtime_resume(struct device *device)
 
 	rtsx_pci_init_hw(pcr);
 
-	if (pcr->slots[RTSX_SD_CARD].p_dev != NULL) {
+	/*
+	 * card_event() triggers a rescan to catch card changes made while
+	 * runtime suspended, but mmc_detect_change() reports a wakeup event
+	 * that can abort a system sleep transition. Skip it then: the mmc host
+	 * class .complete() callback rescans anyway.
+	 */
+	if (pcr->slots[RTSX_SD_CARD].p_dev != NULL && !device->power.is_prepared) {
 		pcr->slots[RTSX_SD_CARD].card_event(
 				pcr->slots[RTSX_SD_CARD].p_dev);
 	}
Signature · 1 line
2.53.0