diff mbox series

[v2] usb: dwc3-generic: use DR_MODE_OTG when dr_mode isn't specified

Message ID 20241018-topic-usb-dwc3-dr-mode-otg-v2-1-d3e98cf6ba48@linaro.org
State New
Headers show
Series [v2] usb: dwc3-generic: use DR_MODE_OTG when dr_mode isn't specified | expand

Commit Message

Neil Armstrong Oct. 18, 2024, 1:27 p.m. UTC
The USB DRD bindingsa at [1] are clear, if not specified the dr_mode
property defaults to otg, and this is how Linux behaves.

A cleanup is ongoing on the Linux Device Trees to remove dr_mode when
set to "otg", so take this in account and do not fail anymore when
dr_mode isn't specified in the glue or dwc3 node.

On the software side, the Linux DWC3 driver behavior defaulting to
DR_MODE_OTG is present since v3.12-rc1 added in commit [2].

[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/usb/usb-drd.yaml
[2] commit a45c82b84c844 ("usb: dwc3: adapt to use dr_mode device tree helper")
    https://github.com/torvalds/linux/commit/a45c82b84c844cd85b2ed1aa32596f1bffa32716

Reviewed-by: Caleb Connolly <caleb.connolly@linaro.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
Changes in v2:
- add ref to linux behaviour
- Link to v1: https://lore.kernel.org/r/20241016-topic-usb-dwc3-dr-mode-otg-v1-1-4fda56072723@linaro.org
---
 drivers/usb/dwc3/dwc3-generic.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)


---
base-commit: d5cab0d6adc26ec1bbd45c2fed101184d04454ae
change-id: 20241016-topic-usb-dwc3-dr-mode-otg-88ec307e0970

Best regards,
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 2ab41cbae45d78ad140d54e602150b6ddd0a3b99..d62d687ece36d70ccb0f7541eb51c6b7550d932d 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -183,10 +183,10 @@  static int dwc3_generic_of_to_plat(struct udevice *dev)
 		/* might be a leaf so check the parent for mode */
 		node = dev_ofnode(dev->parent);
 		plat->dr_mode = usb_get_dr_mode(node);
-		if (plat->dr_mode == USB_DR_MODE_UNKNOWN) {
-			pr_err("Invalid usb mode setup\n");
-			return -ENODEV;
-		}
+
+		/* If none of the nodes have dr_mode, bindings says default is OTG */
+		if (!plat->dr_mode)
+			plat->dr_mode = USB_DR_MODE_OTG;
 	}
 
 	return 0;
@@ -527,6 +527,10 @@  static int dwc3_glue_bind_common(struct udevice *parent, ofnode node)
 	if (!dr_mode)
 		dr_mode = usb_get_dr_mode(node);
 
+	/* If none of the nodes have dr_mode, bindings says default is OTG */
+	if (!dr_mode)
+		dr_mode = USB_DR_MODE_OTG;
+
 	if (CONFIG_IS_ENABLED(DM_USB_GADGET) &&
 	    (dr_mode == USB_DR_MODE_PERIPHERAL || dr_mode == USB_DR_MODE_OTG)) {
 		debug("%s: dr_mode: OTG or Peripheral\n", __func__);