Skip to contentSkip to conversation

usb: dwc3: keep PHYs disabled during suspend

PATCH In review Johan Hovold 3 participants 5 messages Aug 23, 2022 – Aug 25, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: keep PHYs disabled during suspend

Commit 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend") started leaving the PHYs enabled during suspend for wakeup-capable controllers even though it turns out this had nothing to do with wakeup.

Rather, the wakeup capability flag was (ab-)used as a proxy to configure the suspend behaviour in an attempt to reduce power leakage on some platforms.

Stop abusing the wakeup configuration and restore the 5.19 behaviour of keeping the PHYs powered off during suspend. If needed, a dedicated mechanism for configuring the PHY power state during suspend can be added later.

Fixes 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
---
 drivers/usb/dwc3/core.c      | 4 ++--
 drivers/usb/dwc3/dwc3-qcom.c | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/usb/dwc3/core.c +2 -2
index 8c8e32651473..0cdb6be720e1 100644
@@ -1983,7 +1983,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 		dwc3_core_exit(dwc);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {
 			dwc3_core_exit(dwc);
 			break;
 		}
@@ -2044,7 +2044,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		spin_unlock_irqrestore(&dwc->lock, flags);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {
 			ret = dwc3_core_init_for_resume(dwc);
 			if (ret)
 				return ret;
drivers/usb/dwc3/dwc3-qcom.c +0 -1
index 9a94b1ab8f7a..9995395baa12 100644
@@ -904,7 +904,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
 	wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
 	device_init_wakeup(&pdev->dev, wakeup_source);
-	device_init_wakeup(&qcom->dwc3->dev, wakeup_source);
 
 	qcom->is_suspended = false;
 	pm_runtime_set_active(dev);
Signature · 1 line
2.35.1
#1 lore raw

Hi Johan,

Quoted 27 lines · Johan Hovold

Commit 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend") started leaving the PHYs enabled during suspend for wakeup-capable controllers even though it turns out this had nothing to do with wakeup.

Rather, the wakeup capability flag was (ab-)used as a proxy to configure the suspend behaviour in an attempt to reduce power leakage on some platforms.

Stop abusing the wakeup configuration and restore the 5.19 behaviour of keeping the PHYs powered off during suspend. If needed, a dedicated mechanism for configuring the PHY power state during suspend can be added later.

Fixes 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
---
 drivers/usb/dwc3/core.c      | 4 ++--
 drivers/usb/dwc3/dwc3-qcom.c | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/usb/dwc3/core.c +0 -0
index 8c8e32651473..0cdb6be720e1 100644

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) · line 1986

Quoted 5 lines
drivers/usb/dwc3/core.c +1 -1
@@ -1983,7 +1983,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 		dwc3_core_exit(dwc);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {

My assumption was that the PHYs need to be powered for wakeup to work, but apparently that isn't the case, wakeup still works on sc7x80 with this part of this patch.

Quoted 17 lines
drivers/usb/dwc3/core.c +1 -1
 			dwc3_core_exit(dwc);
 			break;
 		}
@@ -2044,7 +2044,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		spin_unlock_irqrestore(&dwc->lock, flags);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {
 			ret = dwc3_core_init_for_resume(dwc);
 			if (ret)
 				return ret;
drivers/usb/dwc3/dwc3-qcom.c +0 -0
index 9a94b1ab8f7a..9995395baa12 100644

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 907

Quoted 4 lines
drivers/usb/dwc3/dwc3-qcom.c +0 -1
@@ -904,7 +904,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
 	wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
 	device_init_wakeup(&pdev->dev, wakeup_source);
-	device_init_wakeup(&qcom->dwc3->dev, wakeup_source);

Surprisingly this part breaks wakeup on sc7x80, with the above removal of the device_may_wakeup() checks it is not clear to me why wakeup needs to be enabled for the core.

#2 lore raw
Quoted 25 lines · Matthias Kaehlcke

Hi Johan,

Quoted 22 lines · Johan Hovold

Commit 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend") started leaving the PHYs enabled during suspend for wakeup-capable controllers even though it turns out this had nothing to do with wakeup.

Rather, the wakeup capability flag was (ab-)used as a proxy to configure the suspend behaviour in an attempt to reduce power leakage on some platforms.

Stop abusing the wakeup configuration and restore the 5.19 behaviour of keeping the PHYs powered off during suspend. If needed, a dedicated mechanism for configuring the PHY power state during suspend can be added later.

Fixes 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
---
 drivers/usb/dwc3/core.c      | 4 ++--
 drivers/usb/dwc3/dwc3-qcom.c | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) · line 1986

Quoted 10 lines
drivers/usb/dwc3/core.c +1 -1
index 8c8e32651473..0cdb6be720e1 100644
@@ -1983,7 +1983,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 		dwc3_core_exit(dwc);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {

My assumption was that the PHYs need to be powered for wakeup to work, but apparently that isn't the case, wakeup still works on sc7x80 with this part of this patch.

Thanks for confirming.

Quoted 18 lines
Quoted 18 lines
drivers/usb/dwc3/core.c +1 -1
 			dwc3_core_exit(dwc);
 			break;
 		}
@@ -2044,7 +2044,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		spin_unlock_irqrestore(&dwc->lock, flags);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {
 			ret = dwc3_core_init_for_resume(dwc);
 			if (ret)
 				return ret;
drivers/usb/dwc3/dwc3-qcom.c +0 -0
index 9a94b1ab8f7a..9995395baa12 100644
@@ -904,7 +904,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
Quoted 7 lines

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 907

Quoted 3 lines
drivers/usb/dwc3/dwc3-qcom.c +0 -1
 	wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
 	device_init_wakeup(&pdev->dev, wakeup_source);
-	device_init_wakeup(&qcom->dwc3->dev, wakeup_source);

Surprisingly this part breaks wakeup on sc7x80, with the above removal of the device_may_wakeup() checks it is not clear to me why wakeup needs to be enabled for the core.

I can't explain that behaviour either. This change doesn't affect the wakeup_path flag and genpd, and notably wakeup still works here with sc8280xp.

Could it be some Chromium user-space issue in that it expects all devices on the wakeup path to be wakeup capable? Note that the xhci-plat driver (e.g. for the descendant xhci-hcd.1.auto device) unconditionally sets the wakeup-capable flag (but leaves it disabled by default).

I guess we could do something similar for the dwc3 core device, but we'd need to figure out if and why that is at all needed first.

Can you verify that the wakeup source (e.g. keyboard) you're using still has power/wakeup set to "enabled"?

Johan

#3 lore raw
Quoted 79 lines · Johan Hovold
Quoted 25 lines · Matthias Kaehlcke

Hi Johan,

Quoted 22 lines · Johan Hovold

Commit 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend") started leaving the PHYs enabled during suspend for wakeup-capable controllers even though it turns out this had nothing to do with wakeup.

Rather, the wakeup capability flag was (ab-)used as a proxy to configure the suspend behaviour in an attempt to reduce power leakage on some platforms.

Stop abusing the wakeup configuration and restore the 5.19 behaviour of keeping the PHYs powered off during suspend. If needed, a dedicated mechanism for configuring the PHY power state during suspend can be added later.

Fixes 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
---
 drivers/usb/dwc3/core.c      | 4 ++--
 drivers/usb/dwc3/dwc3-qcom.c | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
Quoted 14 lines

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) · line 1986

Quoted 10 lines
drivers/usb/dwc3/core.c +1 -1
index 8c8e32651473..0cdb6be720e1 100644
@@ -1983,7 +1983,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 		dwc3_core_exit(dwc);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {

My assumption was that the PHYs need to be powered for wakeup to work, but apparently that isn't the case, wakeup still works on sc7x80 with this part of this patch.

Thanks for confirming.

Quoted 18 lines
Quoted 18 lines
drivers/usb/dwc3/core.c +1 -1
 			dwc3_core_exit(dwc);
 			break;
 		}
@@ -2044,7 +2044,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		spin_unlock_irqrestore(&dwc->lock, flags);
 		break;
 	case DWC3_GCTL_PRTCAP_HOST:
-		if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) {
+		if (!PMSG_IS_AUTO(msg)) {
 			ret = dwc3_core_init_for_resume(dwc);
 			if (ret)
 				return ret;
drivers/usb/dwc3/dwc3-qcom.c +0 -0
index 9a94b1ab8f7a..9995395baa12 100644
@@ -904,7 +904,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
Quoted 7 lines

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 907

Quoted 3 lines
drivers/usb/dwc3/dwc3-qcom.c +0 -1
 	wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
 	device_init_wakeup(&pdev->dev, wakeup_source);
-	device_init_wakeup(&qcom->dwc3->dev, wakeup_source);

Surprisingly this part breaks wakeup on sc7x80, with the above removal of the device_may_wakeup() checks it is not clear to me why wakeup needs to be enabled for the core.

I can't explain that behaviour either. This change doesn't affect the wakeup_path flag and genpd, and notably wakeup still works here with sc8280xp.

Could it be some Chromium user-space issue in that it expects all devices on the wakeup path to be wakeup capable? Note that the xhci-plat driver (e.g. for the descendant xhci-hcd.1.auto device) unconditionally sets the wakeup-capable flag (but leaves it disabled by default).

Quoted 5 lines

I guess we could do something similar for the dwc3 core device, but we'd need to figure out if and why that is at all needed first.

Can you verify that the wakeup source (e.g. keyboard) you're using still has power/wakeup set to "enabled"?

I confirmed that the wakeup flag of the wakeup source is still enabled when the wakeup source suspends.

It turns out the dwc3 core wakeup flags are evaluated by:

	int usb_phy_roothub_suspend(struct device *controller_dev,
	                            struct usb_phy_roothub *phy_roothub)
	{
		usb_phy_roothub_power_off(phy_roothub);

		/* keep the PHYs initialized so the device can wake up the system */
		if (device_may_wakeup(controller_dev))
			return 0;

		return usb_phy_roothub_exit(phy_roothub);
	}

'controller_dev' is the dwc3 core. The root hub is un-initialized when wakeup is disabled. That causes wakeup to fail, and also happens to be the/one cause of the high power consumption of an onboard USB hub that I mentioned earlier in another thread.

#4 lore raw
Quoted 56 lines · Matthias Kaehlcke
Quoted 37 lines · Johan Hovold
Quoted 28 lines · Matthias Kaehlcke

Hi Johan,

Quoted 25 lines · Johan Hovold

Commit 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend") started leaving the PHYs enabled during suspend for wakeup-capable controllers even though it turns out this had nothing to do with wakeup.

Rather, the wakeup capability flag was (ab-)used as a proxy to configure the suspend behaviour in an attempt to reduce power leakage on some platforms.

Stop abusing the wakeup configuration and restore the 5.19 behaviour of keeping the PHYs powered off during suspend. If needed, a dedicated mechanism for configuring the PHY power state during suspend can be added later.

Fixes 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")

---

drivers/usb/dwc3/dwc3-qcom.c +0 -0
index 9a94b1ab8f7a..9995395baa12 100644
@@ -904,7 +904,6 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
Quoted 7 lines

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 907

Quoted 3 lines
drivers/usb/dwc3/dwc3-qcom.c +0 -1
 	wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
 	device_init_wakeup(&pdev->dev, wakeup_source);
-	device_init_wakeup(&qcom->dwc3->dev, wakeup_source);

Surprisingly this part breaks wakeup on sc7x80, with the above removal of the device_may_wakeup() checks it is not clear to me why wakeup needs to be enabled for the core.

Quoted 3 lines

I can't explain that behaviour either. This change doesn't affect the wakeup_path flag and genpd, and notably wakeup still works here with sc8280xp.

It turns out the dwc3 core wakeup flags are evaluated by:

	int usb_phy_roothub_suspend(struct device *controller_dev,
	                            struct usb_phy_roothub *phy_roothub)
	{
		usb_phy_roothub_power_off(phy_roothub);

		/* keep the PHYs initialized so the device can wake up the system */
		if (device_may_wakeup(controller_dev))
			return 0;

		return usb_phy_roothub_exit(phy_roothub);
	}
Quoted 4 lines

'controller_dev' is the dwc3 core. The root hub is un-initialized when wakeup is disabled. That causes wakeup to fail, and also happens to be the/one cause of the high power consumption of an onboard USB hub that I mentioned earlier in another thread.

Bah, I forgot about the USB core PHY management mess. This should be disabled as the dwc3 driver manages the PHYs itself.

But because it currently enabled, the PHY was kept powered-on by USB core (unless dropping device_init_wakeup()) and this indicates that that is indeed needed for wakeup on your platform.

So this patch should be dropped, and I'll send a patch disabling the USB core PHY management for dwc3 instead.

Johan