Fix DWC2 USB role switch support
Subsystems (3)
cover Fix DWC2 USB role switch support
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(-)
Signature · 1 line
2.17.1
PATCH 1/4 dt-bindings: usb: dwc2: add optional usb-role-switch property
This patch documents the usb-role-switch property in dwc2 bindings, now that usb-role-switch support is available in dwc2 driver.
--- Documentation/devicetree/bindings/usb/dwc2.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/usb/dwc2.yaml +4 -0
@@ -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.
Signature · 1 line
2.17.1
PATCH 2/4 usb: dwc2: fix build issue when config is USB_DWC2_HOST only
In reply to Amelie DelaunayThis patch add missing definition of dwc2_hsotg_core_disconnect and check configuration before using hsotg->test_mode, to fix build issue when config USB_DWC2_PERIPHERAL or USB_DWC2_DUAL_ROLE are not set.
--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/drd.c | 3 +++ 2 files changed, 4 insertions(+)
drivers/usb/dwc2/core.h +1 -0
@@ -1425,6 +1425,7 @@ static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg) {return 0 ; }static inline void dwc2_hsotg_core_init_disconnected (struct dwc2_hsotg *dwc2,bool reset) {} +static inline void dwc2_hsotg_core_disconnect (struct dwc2_hsotg *hsotg) {}static inline void dwc2_hsotg_core_connect (struct dwc2_hsotg *hsotg) {}static inline void dwc2_hsotg_disconnect (struct dwc2_hsotg *dwc2) {} static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
drivers/usb/dwc2/drd.c +3 -0
@@ -76,11 +76,14 @@ static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role) (role == USB_ROLE_HOST && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL))return -EINVAL ; +#if IS_ENABLED (CONFIG_USB_DWC2_PERIPHERAL ) || \ +IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE )/* Skip session if core is in test mode */ if (role ==USB_ROLE_NONE && hsotg->test_mode) {dev_dbg (hsotg->dev,"Core is in test mode\n" );return -EBUSY ; } +#endif spin_lock_irqsave (&hsotg->lock, flags);
Signature · 1 line
2.17.1
PATCH 3/4 usb: dwc2: drd: fix sleeping while spinlock atomic context
In reply to Amelie DelaunayIf 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.
--- drivers/usb/dwc2/drd.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)
drivers/usb/dwc2/drd.c +7 -20
@@ -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" );
Signature · 1 line
2.17.1
PATCH 4/4 usb: dwc2: fix error path with missing dwc2_drd_exit
In reply to Amelie DelaunayIn case of failure, role switch has to be unregistered. It is done by dwc2_drd_exit.
--- drivers/usb/dwc2/platform.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/dwc2/platform.c +2 -0
@@ -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:
Signature · 1 line
2.17.1
Quoted 11 lines · Amelie DELAUNAY
This patchset adds missing documentation for usb-role-switch support in DWC2 bindings. It also fixes build issue when config is
DWC2_HOSTonly, 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 isUSB_DWC2_HOSTonly
usb: dwc2: drd: fix sleeping while spinlock atomic context
usb: dwc2: fix error path with missingdwc2_drd_exit
Quoted 9 lines
.../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(-)Signature · 1 line
2.17.1
Patchset dropped.
Regards,
Amelie