Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: Fix spurious wakeup when port is on device mode
@ 2023-11-22 16:51 Guilherme G. Piccoli
  2023-12-04 11:36 ` Guilherme G. Piccoli
  0 siblings, 1 reply; 33+ messages in thread
From: Guilherme G. Piccoli @ 2023-11-22 16:51 UTC (permalink / raw)
  To: linux-usb, Thinh.Nguyen
  Cc: balbi, gregkh, johan, quic_wcheng, kernel, kernel-dev,
	Guilherme G. Piccoli, Andrey Smirnov, Vivek Dasmohapatra

It was noticed that on plugging a low-power USB source on Steam
Deck USB-C port (handled by dwc3), if such port is on device role,
the HW somehow keep asseting the PCIe PME line and triggering a
wakeup event on S3/deep suspend (that manifests as a PME wakeup
interrupt, failing the suspend path). That doesn't happen when the USB
port is on host mode or if the USB device connected is not a low-power
type (for example, a connected keyboard doesn't reproduce that).

Even by masking all maskable ACPI GPEs, the problem still reproduces; also
by having the PCIe PME mechanism using non-MSI interrupts, the symptom is
observed as the HW succeeding to S3/suspend but waking up right after.

By changing the PRTCAP mode to DWC3_GCTL_PRTCAP_HOST in the controller
(as one of the latest steps on gadget common suspend), we managed to
circumvent the issue. The mode restore is already done in the common
resume function. Notice that this patch does not change the in-driver
port state on suspend, or else the resume path "thinks" the port was
in host mode prior to suspend and resume it on a wrong fashion.

Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Vivek Dasmohapatra <vivek@collabora.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---


Hi folks, first of all thanks in advance for reviews/feedback on this one.

This patch is the result of a debug approach with no datasheet access.
With that said, I'm not 100% sure writing to this register is free of
undesired side-effects; one thing I'm considering is the following scenario:
imagine a device A with the USB port on device/peripheral mode, and a device B
connected to it, acting as host. What if we want device B be able to wakeup
device A? Would this patch prevent that for all cases, always?

I appreciate ideas in case this is not the best approach to fix the
problem. We could also gate this approach to the HW board as a first step,
for example.

Thanks,


Guilherme


 drivers/usb/dwc3/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 0328c86ef806..5801d3ebbbcb 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -104,7 +104,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 	return 0;
 }
 
-void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
+static void __dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
 {
 	u32 reg;
 
@@ -112,7 +112,11 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
 	reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
 	reg |= DWC3_GCTL_PRTCAPDIR(mode);
 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
 
+void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
+{
+	__dwc3_set_prtcap(dwc, mode);
 	dwc->current_dr_role = mode;
 }
 
@@ -2128,6 +2132,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 			break;
 		dwc3_gadget_suspend(dwc);
 		synchronize_irq(dwc->irq_gadget);
+		__dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
 		dwc3_core_exit(dwc);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-- 
2.42.0


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

end of thread, other threads:[~2024-03-08 11:52 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 16:51 [PATCH] usb: dwc3: Fix spurious wakeup when port is on device mode Guilherme G. Piccoli
2023-12-04 11:36 ` Guilherme G. Piccoli
2023-12-05  1:23   ` Thinh Nguyen
2023-12-05 14:40     ` Guilherme G. Piccoli
2024-01-09 18:00       ` Guilherme G. Piccoli
2024-01-11  2:01         ` Thinh Nguyen
2024-01-11 16:13           ` Guilherme G. Piccoli
2024-01-13  1:33             ` Thinh Nguyen
2024-01-15 10:44               ` Vivek Dasmohapatra
2024-01-17  0:37                 ` Thinh Nguyen
2024-01-16 16:11               ` Guilherme G. Piccoli
2024-01-17  0:34                 ` Thinh Nguyen
2024-01-17 10:44                   ` Guilherme G. Piccoli
2024-01-18  0:39                     ` Thinh Nguyen
2024-01-21 17:48                       ` Guilherme G. Piccoli
2024-01-23  2:12                         ` Thinh Nguyen
2024-01-28 15:25                           ` Guilherme G. Piccoli
2024-01-30  2:17                             ` Thinh Nguyen
2024-01-31 18:16                               ` Guilherme G. Piccoli
2024-01-31 19:16                                 ` Guilherme G. Piccoli
2024-02-01  1:23                                   ` Thinh Nguyen
2024-02-01  1:23                                 ` Thinh Nguyen
2024-02-01 14:39                                   ` Guilherme G. Piccoli
2024-02-06  2:53                                     ` Thinh Nguyen
2024-02-06 10:30                                       ` Guilherme G. Piccoli
2024-02-08 23:53                                         ` Thinh Nguyen
2024-02-09  1:18                                           ` Guilherme G. Piccoli
2024-03-04 15:59                                             ` Guilherme G. Piccoli
2024-03-05  2:41                                               ` Thinh Nguyen
2024-03-07  0:40                                               ` Thinh Nguyen
2024-03-07 19:22                                                 ` Guilherme G. Piccoli
2024-03-08  2:42                                                   ` Thinh Nguyen
2024-03-08 11:52                                                     ` Guilherme G. Piccoli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox