usb: dwc3: core: Avoid redundant system suspend/resume callbacks
authorRoy Luo <royluo@google.com>
Wed, 12 Mar 2025 22:34:34 +0000 (22:34 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Apr 2025 14:08:32 +0000 (16:08 +0200)
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>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20250312223434.3071598-1-royluo@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.c

index 17ae5c13fe3690c945bcdba108c84b4a38ed0d63..b169913172fc5fadb307e188caf935f7467fb413 100644 (file)
@@ -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>
 
@@ -2670,14 +2671,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