From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Roy Luo <royluo@google.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] usb: dwc3: core: Avoid redundant system suspend/resume callbacks
Date: Wed, 12 Mar 2025 23:02:20 +0000 [thread overview]
Message-ID: <20250312230216.l2e55tb5l6e4xyt2@synopsys.com> (raw)
In-Reply-To: <20250312223434.3071598-1-royluo@google.com>
On Wed, Mar 12, 2025, Roy Luo wrote:
> dwc3 device suspend/resume callbacks were being triggered during system
> suspend and resume even if the device was already runtime-suspended.
> This is redundant for device mode because the suspend and resume routines
> are essentially identical for system PM and runtime PM.
>
> To prevent these unnecessary callbacks, indicate to the PM core that it
> can safely leave the device in runtime suspend if it's already
> runtime-suspended in device mode by returning a positive value in
> prepare() callback. This optimization only applies to devices without
> pinctrl, as pinctrl has distinct logic tied to system suspend/resume.
>
> Signed-off-by: Roy Luo <royluo@google.com>
> ---
> Changes in v2:
> - leave the pinctrl logic untouched, apply the optimization only when
> pinctrl isn't being used.
> ---
> drivers/usb/dwc3/core.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 66a08b527165..02cdd0727a5e 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -26,6 +26,7 @@
> #include <linux/of_graph.h>
> #include <linux/acpi.h>
> #include <linux/pinctrl/consumer.h>
> +#include <linux/pinctrl/devinfo.h>
> #include <linux/reset.h>
> #include <linux/bitfield.h>
>
> @@ -2658,14 +2659,31 @@ static void dwc3_complete(struct device *dev)
> dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
> }
> }
> +
> +static int dwc3_prepare(struct device *dev)
> +{
> + struct dwc3 *dwc = dev_get_drvdata(dev);
> +
> + /*
> + * Indicate to the PM core that it may safely leave the device in
> + * runtime suspend if runtime-suspended already in device mode.
> + */
> + if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE &&
> + pm_runtime_suspended(dev) &&
> + !dev_pinctrl(dev))
> + return 1;
> +
> + return 0;
> +}
> #else
> #define dwc3_complete NULL
> +#define dwc3_prepare NULL
> #endif /* CONFIG_PM_SLEEP */
>
> static const struct dev_pm_ops dwc3_dev_pm_ops = {
> SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
> .complete = dwc3_complete,
> -
> + .prepare = dwc3_prepare,
> /*
> * Runtime suspend halts the controller on disconnection. It relies on
> * platforms with custom connection notification to start the controller
>
> base-commit: 0fed89a961ea851945d23cc35beb59d6e56c0964
> --
> 2.49.0.rc1.451.g8f38331e32-goog
>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Thanks,
Thinh
next prev parent reply other threads:[~2025-03-12 23:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-12 22:34 [PATCH v2] usb: dwc3: core: Avoid redundant system suspend/resume callbacks Roy Luo
2025-03-12 23:02 ` Thinh Nguyen [this message]
2025-03-13 14:27 ` Alan Stern
2025-03-13 19:30 ` Roy Luo
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=20250312230216.l2e55tb5l6e4xyt2@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=royluo@google.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