This patchset adds missing documentation for usb-role-switch support in DWC2
bindings. It also fixes build issue when config is DWC2_HOST only,
sleeping while atomic issue and missing usb-role-switch unregistration in probe
error path.
Amelie Delaunay (4):
dt-bindings: usb: dwc2: add optional usb-role-switch property
usb: dwc2: fix build issue when config is USB_DWC2_HOST only
usb: dwc2: drd: fix sleeping while spinlock atomic context
usb: dwc2: fix error path with missing dwc2_drd_exit
.../devicetree/bindings/usb/dwc2.yaml | 4 +++
drivers/usb/dwc2/core.h | 1 +
drivers/usb/dwc2/drd.c | 30 +++++++------------
drivers/usb/dwc2/platform.c | 2 ++
4 files changed, 17 insertions(+), 20 deletions(-)
--
2.17.1
If GINTSTS.CURMODE is not yet reflecting the expecting mode after calling
dwc2_force_mode, we enter in the dwc2_wait_for_mode function while under
spinlock atomic context.
To avoid this situation, move the call to dwc2_force_mode after the
spinlock atomic context.
Fixes: bc0f0d4a5853 ("usb: dwc2: override PHY input signals with usb role switch support")
Reported-by: Martin Blumenstingl <[email protected]>
Signed-off-by: Amelie Delaunay <[email protected]>
---
drivers/usb/dwc2/drd.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/dwc2/drd.c b/drivers/usb/dwc2/drd.c
index 5099841b1417..2d4176f5788e 100644
--- a/drivers/usb/dwc2/drd.c
+++ b/drivers/usb/dwc2/drd.c
@@ -70,6 +70,7 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
{
struct dwc2_hsotg *hsotg = usb_role_switch_get_drvdata(sw);
unsigned long flags;
+ int already = 0;
/* Skip session not in line with dr_mode */
if ((role == USB_ROLE_DEVICE && hsotg->dr_mode == USB_DR_MODE_HOST) ||
@@ -88,26 +89,9 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
spin_lock_irqsave(&hsotg->lock, flags);
if (role == USB_ROLE_HOST) {
- if (dwc2_ovr_avalid(hsotg, true))
- goto unlock;
-
- if (hsotg->dr_mode == USB_DR_MODE_OTG)
- /*
- * This will raise a Connector ID Status Change
- * Interrupt - connID A
- */
- dwc2_force_mode(hsotg, true);
+ already = dwc2_ovr_avalid(hsotg, true);
} else if (role == USB_ROLE_DEVICE) {
- if (dwc2_ovr_bvalid(hsotg, true))
- goto unlock;
-
- if (hsotg->dr_mode == USB_DR_MODE_OTG)
- /*
- * This will raise a Connector ID Status Change
- * Interrupt - connID B
- */
- dwc2_force_mode(hsotg, false);
-
+ already = dwc2_ovr_bvalid(hsotg, true);
/* This clear DCTL.SFTDISCON bit */
dwc2_hsotg_core_connect(hsotg);
} else {
@@ -120,9 +104,12 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role)
}
}
-unlock:
spin_unlock_irqrestore(&hsotg->lock, flags);
+ if (!already && hsotg->dr_mode == USB_DR_MODE_OTG)
+ /* This will raise a Connector ID Status Change Interrupt */
+ dwc2_force_mode(hsotg, role == USB_ROLE_HOST);
+
dev_dbg(hsotg->dev, "%s-session valid\n",
role == USB_ROLE_NONE ? "No" :
role == USB_ROLE_HOST ? "A" : "B");
--
2.17.1
This patch documents the usb-role-switch property in dwc2 bindings, now
that usb-role-switch support is available in dwc2 driver.
Fixes: bc0f0d4a5853 ("usb: dwc2: override PHY input signals with usb role switch support")
Reported-by: Martin Blumenstingl <[email protected]>
Signed-off-by: Amelie Delaunay <[email protected]>
---
Documentation/devicetree/bindings/usb/dwc2.yaml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/usb/dwc2.yaml b/Documentation/devicetree/bindings/usb/dwc2.yaml
index 9352a8ef60a6..7b226eeffe82 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.yaml
+++ b/Documentation/devicetree/bindings/usb/dwc2.yaml
@@ -100,6 +100,10 @@ properties:
dr_mode:
enum: [host, peripheral, otg]
+ usb-role-switch:
+ $ref: /schemas/types.yaml#/definitions/flag
+ description: Support role switch.
+
g-rx-fifo-size:
$ref: /schemas/types.yaml#/definitions/uint32
description: size of rx fifo size in gadget mode.
--
2.17.1
In case of failure, role switch has to be unregistered. It is done by
dwc2_drd_exit.
Fixes: bc0f0d4a5853 ("usb: dwc2: override PHY input signals with usb role switch support")
Reported-by: kernel test robot <[email protected]>
Signed-off-by: Amelie Delaunay <[email protected]>
---
drivers/usb/dwc2/platform.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 68b56b43a45e..f4a0371c3e89 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -600,6 +600,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
return 0;
error_init:
+ dwc2_drd_exit(hsotg);
+
if (hsotg->params.activate_stm_id_vb_detection)
regulator_disable(hsotg->usb33d);
error:
--
2.17.1
On 7/24/20 2:37 PM, Amelie DELAUNAY wrote:
> This patchset adds missing documentation for usb-role-switch support in DWC2
> bindings. It also fixes build issue when config is DWC2_HOST only,
> sleeping while atomic issue and missing usb-role-switch unregistration
> in probe
> error path.
>
> Amelie Delaunay (4):
> dt-bindings: usb: dwc2: add optional usb-role-switch property
> usb: dwc2: fix build issue when config is USB_DWC2_HOST only
> usb: dwc2: drd: fix sleeping while spinlock atomic context
> usb: dwc2: fix error path with missing dwc2_drd_exit
>
> .../devicetree/bindings/usb/dwc2.yaml | 4 +++
> drivers/usb/dwc2/core.h | 1 +
> drivers/usb/dwc2/drd.c | 30 +++++++------------
> drivers/usb/dwc2/platform.c | 2 ++
> 4 files changed, 17 insertions(+), 20 deletions(-)
>
> --
> 2.17.1
>
Patchset dropped.
Regards,
Amelie