Skip to contentSkip to conversation

usb: dwc3: gadget: Check for disabled LPM quirk

PATCH In review Thinh Nguyen 3 participants 7 messages Apr 14, 2021 – Apr 15, 2021

Subsystems (3)
lore
Share & tools
lore

Thinh Nguyen

author maintainer
#0 lore raw

PATCH 1/1 usb: dwc3: gadget: Check for disabled LPM quirk

If the device doesn't support LPM, make sure to disable the LPM capability and don't advertise to the host that it supports it.

---
 drivers/usb/dwc3/gadget.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +8 -1
index e1b04c976da5..509f01b1d830 100644
@@ -3484,6 +3484,7 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 	/* Enable USB2 LPM Capability */
 
 	if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A) &&
+	    !dwc->usb2_lpm_disable &&
 	    (speed != DWC3_DSTS_SUPERSPEED) &&
 	    (speed != DWC3_DSTS_SUPERSPEED_PLUS)) {
 		reg = dwc3_readl(dwc->regs, DWC3_DCFG);
@@ -3510,6 +3511,12 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 
 		dwc3_gadget_dctl_write_safe(dwc, reg);
 	} else {
+		if (dwc->usb2_lpm_disable) {
+			reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+			reg &= ~DWC3_DCFG_LPM_CAP;
+			dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+		}
+
 		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 		reg &= ~DWC3_DCTL_HIRD_THRES_MASK;
 		dwc3_gadget_dctl_write_safe(dwc, reg);
@@ -3958,7 +3965,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 	dwc->gadget->ssp_rate		= USB_SSP_GEN_UNKNOWN;
 	dwc->gadget->sg_supported	= true;
 	dwc->gadget->name		= "dwc3-gadget";
-	dwc->gadget->lpm_capable	= true;
+	dwc->gadget->lpm_capable	= !dwc->usb2_lpm_disable;
 
 	/*
 	 * FIXME We might be setting max_speed to <SUPER, however versions

base-commit: 401411bbc4e62bcbcc020c2c458ecb90843140a8

Signature · 1 line
2.28.0
author maintainer
#1 lore raw

v2 cover usb: dwc3: gadget: Add disabling LPM option

Add a new option to disable LPM for gadget side. Some device may need to disable this capability.

Changes in v2:
- Add cover letter
- Add new DT property for disabling LPM for gadget

Thinh Nguyen (2):
dt-bindings: usb: dwc3: Add disabling LPM for gadget
usb: dwc3: gadget: Check for disabled LPM quirk

 Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 8 +++++++-
 drivers/usb/dwc3/core.c                              | 2 ++
 drivers/usb/dwc3/core.h                              | 4 +++-
 drivers/usb/dwc3/gadget.c                            | 9 ++++++++-
 4 files changed, 20 insertions(+), 3 deletions(-)

base-commit: 401411bbc4e62bcbcc020c2c458ecb90843140a8

Signature · 1 line
2.28.0
author maintainer
#2 lore raw

PATCH v2 1/2 dt-bindings: usb: dwc3: Add disabling LPM for gadget

Add a new DT option to disable LPM for gadget and update the description for usb2-lpm-disable related to host for clarity.

---
Changes in v2:
- New patch

 Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/usb/snps,dwc3.yaml +7 -1
index 2247da77eac1..41416fbd92aa 100644
@@ -87,13 +87,19 @@ properties:
     minItems: 1
 
   snps,usb2-lpm-disable:
-    description: Indicate if we don't want to enable USB2 HW LPM
+    description: Indicate if we don't want to enable USB2 HW LPM for host
+      mode.
     type: boolean
 
   snps,usb3_lpm_capable:
     description: Determines if platform is USB3 LPM capable
     type: boolean
 
+  snps,usb2-gadget-lpm-disable:
+    description: Indicate if we don't want to enable USB2 HW LPM for gadget
+      mode.
+    type: boolean
+
   snps,dis-start-transfer-quirk:
     description:
       When set, disable isoc START TRANSFER command failure SW work-around
Signature · 1 line
2.28.0
maintainer Acked-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: usb: dwc3: Add disabling LPM for gadget

Quoted 11 lines · Thinh Nguyen

Add a new DT option to disable LPM for gadget and update the description for usb2-lpm-disable related to host for clarity.

---
Changes in v2:
- New patch

 Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
author maintainer
#4 lore raw

PATCH v2 2/2 usb: dwc3: gadget: Check for disabled LPM quirk

In reply to Thinh Nguyen

If the device doesn't support LPM, make sure to disable the LPM capability and don't advertise to the host that it supports it.

---
Changes in v2:
- Use a different DT property than usb2-lpm-disable (since it's host specific)

 drivers/usb/dwc3/core.c   | 2 ++
 drivers/usb/dwc3/core.h   | 4 +++-
 drivers/usb/dwc3/gadget.c | 9 ++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/usb/dwc3/core.c +2 -0
index 05e2e54cbbdc..f3316caefbad 100644
@@ -1286,6 +1286,8 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 				"snps,usb3_lpm_capable");
 	dwc->usb2_lpm_disable = device_property_read_bool(dev,
 				"snps,usb2-lpm-disable");
+	dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev,
+				"snps,usb2-gadget-lpm-disable");
 	device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd",
 				&rx_thr_num_pkt_prd);
 	device_property_read_u8(dev, "snps,rx-max-burst-prd",
drivers/usb/dwc3/core.h +3 -1
index 6e9abfbccaa6..83086e71122d 100644
@@ -1035,7 +1035,8 @@ struct dwc3_scratchpad_array {
  * @dis_start_transfer_quirk: set if start_transfer failure SW workaround is
  *			not needed for DWC_usb31 version 1.70a-ea06 and below
  * @usb3_lpm_capable: set if hadrware supports Link Power Management
- * @usb2_lpm_disable: set to disable usb2 lpm
+ * @usb2_lpm_disable: set to disable usb2 lpm for host
+ * @usb2_gadget_lpm_disable: set to disable usb2 lpm for gadget
  * @disable_scramble_quirk: set if we enable the disable scramble quirk
  * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
  * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
@@ -1241,6 +1242,7 @@ struct dwc3 {
 	unsigned		dis_start_transfer_quirk:1;
 	unsigned		usb3_lpm_capable:1;
 	unsigned		usb2_lpm_disable:1;
+	unsigned		usb2_gadget_lpm_disable:1;
 
 	unsigned		disable_scramble_quirk:1;
 	unsigned		u2exit_lfps_quirk:1;
drivers/usb/dwc3/gadget.c +8 -1
index e1b04c976da5..767661b740ab 100644
@@ -3484,6 +3484,7 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 	/* Enable USB2 LPM Capability */
 
 	if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A) &&
+	    !dwc->usb2_gadget_lpm_disable &&
 	    (speed != DWC3_DSTS_SUPERSPEED) &&
 	    (speed != DWC3_DSTS_SUPERSPEED_PLUS)) {
 		reg = dwc3_readl(dwc->regs, DWC3_DCFG);
@@ -3510,6 +3511,12 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 
 		dwc3_gadget_dctl_write_safe(dwc, reg);
 	} else {
+		if (dwc->usb2_gadget_lpm_disable) {
+			reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+			reg &= ~DWC3_DCFG_LPM_CAP;
+			dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+		}
+
 		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 		reg &= ~DWC3_DCTL_HIRD_THRES_MASK;
 		dwc3_gadget_dctl_write_safe(dwc, reg);
@@ -3958,7 +3965,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 	dwc->gadget->ssp_rate		= USB_SSP_GEN_UNKNOWN;
 	dwc->gadget->sg_supported	= true;
 	dwc->gadget->name		= "dwc3-gadget";
-	dwc->gadget->lpm_capable	= true;
+	dwc->gadget->lpm_capable	= !dwc->usb2_gadget_lpm_disable;
 
 	/*
 	 * FIXME We might be setting max_speed to <SUPER, however versions
Signature · 1 line
2.28.0