From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"balbi@kernel.org" <balbi@kernel.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"johan@kernel.org" <johan@kernel.org>,
"quic_wcheng@quicinc.com" <quic_wcheng@quicinc.com>,
"kernel@gpiccoli.net" <kernel@gpiccoli.net>,
"kernel-dev@igalia.com" <kernel-dev@igalia.com>,
Andrey Smirnov <andrew.smirnov@gmail.com>,
Vivek Dasmohapatra <vivek@collabora.com>,
"piyush.mehta@amd.com" <piyush.mehta@amd.com>,
"ray.huang@amd.com" <ray.huang@amd.com>
Subject: Re: [PATCH] usb: dwc3: Fix spurious wakeup when port is on device mode
Date: Thu, 7 Mar 2024 00:40:08 +0000 [thread overview]
Message-ID: <20240307003955.js57ik6cuxhhsae3@synopsys.com> (raw)
In-Reply-To: <7594701a-34d7-579b-6c9c-05a18d3ab651@igalia.com>
Hi,
On Mon, Mar 04, 2024, Guilherme G. Piccoli wrote:
> On 08/02/2024 22:18, Guilherme G. Piccoli wrote:
> > On 08/02/2024 20:53, Thinh Nguyen wrote:
> >> [...]
> >>
> >> Thanks. I have some suspicions of what happened. I'll create a patch,
> >> but I'll need some time.
> >>
> >> Thanks,
> >> Thinh
> >
> > Thank you a bunch! Let us know when you have a candidate, I can test it
> > quickly in the Steam Deck =)
> >
> > Cheers,
> >
> >
> > Guilherme
> >
>
> Hi Thinh, hope everything is alright.
>
> Let me know if we can help in anything or provide more test results,
> we'd be glad to.
>
Can you try this? I made some adjustments to the previous conditions:
* If operate as device mode, only allow system wakeup if there's gadget
* driver binded.
* Make sure to pass the wakeup config to the xhci platform device when
switch to host.
If it works, I'll clean this up and split this into 2 separate patches.
Thanks,
Thinh
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 3e55838c0001..63202b1748d3 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1977,6 +1977,8 @@ static int dwc3_probe(struct platform_device *pdev)
pm_runtime_forbid(dev);
+ dwc->sys_wakeup = !!device_may_wakeup(dwc->sysdev);
+
ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
if (ret) {
dev_err(dwc->dev, "failed to allocate event buffers\n");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index c07edfc954f7..7e80dd3d466b 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1133,6 +1133,7 @@ struct dwc3_scratchpad_array {
* 3 - Reserved
* @dis_metastability_quirk: set to disable metastability quirk.
* @dis_split_quirk: set to disable split boundary.
+ * @sys_wakeup: set if the device may do system wakeup.
* @wakeup_configured: set if the device is configured for remote wakeup.
* @suspended: set to track suspend event due to U3/L2.
* @imod_interval: set the interrupt moderation interval in 250ns
@@ -1357,6 +1358,7 @@ struct dwc3 {
unsigned dis_split_quirk:1;
unsigned async_callbacks:1;
+ unsigned sys_wakeup:1;
unsigned wakeup_configured:1;
unsigned suspended:1;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 40c52dbc28d3..2d394c4ad735 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2955,6 +2955,9 @@ static int dwc3_gadget_start(struct usb_gadget *g,
dwc->gadget_driver = driver;
spin_unlock_irqrestore(&dwc->lock, flags);
+ if (dwc->sys_wakeup)
+ device_wakeup_enable(dwc->sysdev);
+
return 0;
}
@@ -2970,6 +2973,9 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long flags;
+ if (dwc->sys_wakeup)
+ device_wakeup_disable(dwc->sysdev);
+
spin_lock_irqsave(&dwc->lock, flags);
dwc->gadget_driver = NULL;
dwc->max_cfg_eps = 0;
@@ -4651,6 +4657,9 @@ int dwc3_gadget_init(struct dwc3 *dwc)
else
dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed);
+ if (dwc->sys_wakeup)
+ device_wakeup_disable(dwc->sysdev);
+
return 0;
err5:
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index 5a5cb6ce9946..8a72d4005352 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -173,6 +173,14 @@ int dwc3_host_init(struct dwc3 *dwc)
goto err;
}
+ if (dwc->sys_wakeup) {
+ /* Restore/re-enable wakeup if switched from device */
+ device_wakeup_enable(dwc->sysdev);
+
+ /* Pass wakeup config to the new xhci platform device */
+ device_init_wakeup(&xhci->dev, true);
+ }
+
return 0;
err:
platform_device_put(xhci);
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 3d071b875308..abbf4d751a54 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -451,6 +451,9 @@ static int xhci_plat_suspend(struct device *dev)
ret = xhci_priv_suspend_quirk(hcd);
if (ret)
return ret;
+
+ dev_info(dev, "%s: device_may_wakeup: %d\n",
+ __func__, !!device_may_wakeup(dev));
/*
* xhci_suspend() needs `do_wakeup` to know whether host is allowed
* to do wakeup during suspend.
next prev parent reply other threads:[~2024-03-07 0:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-03-07 19:22 ` Guilherme G. Piccoli
2024-03-08 2:42 ` Thinh Nguyen
2024-03-08 11:52 ` Guilherme G. Piccoli
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=20240307003955.js57ik6cuxhhsae3@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=andrew.smirnov@gmail.com \
--cc=balbi@kernel.org \
--cc=gpiccoli@igalia.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=kernel-dev@igalia.com \
--cc=kernel@gpiccoli.net \
--cc=linux-usb@vger.kernel.org \
--cc=piyush.mehta@amd.com \
--cc=quic_wcheng@quicinc.com \
--cc=ray.huang@amd.com \
--cc=vivek@collabora.com \
/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