From: Sanath S <sanaths2@amd.com>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Cc: John Youn <John.Youn@synopsys.com>,
"Guilherme G.Piccoli" <gpiccoli@igalia.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] usb: dwc3: Properly set system wakeup
Date: Fri, 8 Mar 2024 12:31:43 +0530 [thread overview]
Message-ID: <ecf5c9e8-4ef6-34d0-824b-a5dcf66cc0c6@amd.com> (raw)
In-Reply-To: <667cfda7009b502e08462c8fb3f65841d103cc0a.1709865476.git.Thinh.Nguyen@synopsys.com>
On 3/8/2024 8:10 AM, Thinh Nguyen wrote:
> If the device is configured for system wakeup, then make sure that the
> xHCI driver knows about it and make sure to permit wakeup only at the
> appropriate time.
>
> For host mode, if the controller goes through the dwc3 code path, then a
> child xHCI platform device is created. Make sure the platform device
> also inherits the wakeup setting for xHCI to enable remote wakeup.
>
> For device mode, make sure to disable system wakeup if no gadget driver
> is bound. We may experience unwanted system wakeup due to the wakeup
> signal from the controller PMU detecting connection/disconnection when
> in low power (D3). E.g. In the case of Steam Deck, the PCI PME prevents
> the system staying in suspend.
We were chasing down same issue at our end and found this patch to be
helpful.
Tested on both host and device mode. Patch is working as expected.
Please feel free to add my tag
Tested-by: Sanath S <Sanath.S@amd.com>
> Cc: stable@vger.kernel.org
> Reported-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
> Closes: https://lore.kernel.org/linux-usb/70a7692d-647c-9be7-00a6-06fc60f77294@igalia.com/T/#mf00d6669c2eff7b308d1162acd1d66c09f0853c7
> Fixes: d07e8819a03d ("usb: dwc3: add xHCI Host support")
> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> ---
> drivers/usb/dwc3/core.c | 2 ++
> drivers/usb/dwc3/core.h | 2 ++
> drivers/usb/dwc3/gadget.c | 10 ++++++++++
> drivers/usb/dwc3/host.c | 11 +++++++++++
> 4 files changed, 25 insertions(+)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 3e55838c0001..31684cdaaae3 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1519,6 +1519,8 @@ static void dwc3_get_properties(struct dwc3 *dwc)
> else
> dwc->sysdev = dwc->dev;
>
> + dwc->sys_wakeup = device_may_wakeup(dwc->sysdev);
> +
> ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
> if (ret >= 0) {
> dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index e120611a5174..893b1e694efe 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1132,6 +1132,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
> @@ -1355,6 +1356,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 28f49400f3e8..07820b1a88a2 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2968,6 +2968,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;
> }
>
> @@ -2983,6 +2986,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;
> @@ -4664,6 +4670,10 @@ int dwc3_gadget_init(struct dwc3 *dwc)
> else
> dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed);
>
> + /* No system wakeup if no gadget driver bound */
> + 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 43230915323c..f6a020d77fa1 100644
> --- a/drivers/usb/dwc3/host.c
> +++ b/drivers/usb/dwc3/host.c
> @@ -123,6 +123,14 @@ int dwc3_host_init(struct dwc3 *dwc)
> goto err;
> }
>
> + if (dwc->sys_wakeup) {
> + /* Restore wakeup setting if switched from device */
> + device_wakeup_enable(dwc->sysdev);
> +
> + /* Pass on wakeup setting to the new xhci platform device */
> + device_init_wakeup(&xhci->dev, true);
> + }
> +
> return 0;
> err:
> platform_device_put(xhci);
> @@ -131,6 +139,9 @@ int dwc3_host_init(struct dwc3 *dwc)
>
> void dwc3_host_exit(struct dwc3 *dwc)
> {
> + if (dwc->sys_wakeup)
> + device_init_wakeup(&dwc->xhci->dev, false);
> +
> platform_device_unregister(dwc->xhci);
> dwc->xhci = NULL;
> }
>
> base-commit: b234c70fefa7532d34ebee104de64cc16f1b21e4
next prev parent reply other threads:[~2024-03-08 7:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 2:40 [PATCH] usb: dwc3: Properly set system wakeup Thinh Nguyen
2024-03-08 7:01 ` Sanath S [this message]
2024-03-08 14:34 ` Guilherme G. Piccoli
2024-03-15 1:03 ` Thinh Nguyen
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=ecf5c9e8-4ef6-34d0-824b-a5dcf66cc0c6@amd.com \
--to=sanaths2@amd.com \
--cc=John.Youn@synopsys.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=gpiccoli@igalia.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.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