[PATCH v2 2/2] usb: dwc3: Add support for standalone DWC3 nodes
Alban Bedel
alban.bedel at aerq.com
Thu Jun 16 10:47:12 CEST 2022
Most DWC3 implementations use a top glue node with DWC3 subnodes,
which is what the dwc3-generic-wrapper driver support. But there is
also implementations where the DWC3 node is directly on the main bus,
like on the imx8mq.
To support this case split the handling of each DWC3 node out of
dwc3_glue_bind() to make it reusable and add a new driver to handle
standalone DWC3 nodes.
While at it also rename the dwc3-generic-wrapper to dwc3-glue-wrapper
to better reflect what it support and the general naming in the
driver.
Signed-off-by: Alban Bedel <alban.bedel at aerq.com>
---
drivers/usb/dwc3/dwc3-generic.c | 103 ++++++++++++++++++++------------
1 file changed, 65 insertions(+), 38 deletions(-)
diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
index 38367ea0f116..31858ba4c81b 100644
--- a/drivers/usb/dwc3/dwc3-generic.c
+++ b/drivers/usb/dwc3/dwc3-generic.c
@@ -349,50 +349,64 @@ struct dwc3_glue_ops ti_ops = {
.glue_configure = dwc3_ti_glue_configure,
};
+static int dwc3_bind_to_node(struct udevice *parent, ofnode node)
+{
+ const char *name = ofnode_get_name(node);
+ enum usb_dr_mode dr_mode;
+ struct udevice *dev;
+ const char *driver = NULL;
+ int ret;
+
+ debug("%s: subnode name: %s\n", __func__, name);
+
+ dr_mode = usb_get_dr_mode(node);
+
+ switch (dr_mode) {
+ case USB_DR_MODE_PERIPHERAL:
+ case USB_DR_MODE_OTG:
+#if CONFIG_IS_ENABLED(DM_USB_GADGET)
+ debug("%s: dr_mode: OTG or Peripheral\n", __func__);
+ driver = "dwc3-generic-peripheral";
+#endif
+ break;
+#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
+ case USB_DR_MODE_HOST:
+ debug("%s: dr_mode: HOST\n", __func__);
+ driver = "dwc3-generic-host";
+ break;
+#endif
+ default:
+ debug("%s: unsupported dr_mode\n", __func__);
+ return -ENODEV;
+ };
+
+ if (!driver)
+ return -ENOTSUPP;
+
+ ret = device_bind_driver_to_node(parent, driver, name,
+ node, &dev);
+ if (ret)
+ debug("%s: not able to bind usb device mode\n",
+ __func__);
+ return ret;
+}
+
+static int dwc3_bind(struct udevice *parent)
+{
+ return dwc3_bind_to_node(parent, dev_ofnode(parent));
+}
+
static int dwc3_glue_bind(struct udevice *parent)
{
ofnode node;
int ret;
ofnode_for_each_subnode(node, dev_ofnode(parent)) {
- const char *name = ofnode_get_name(node);
- enum usb_dr_mode dr_mode;
- struct udevice *dev;
- const char *driver = NULL;
-
- debug("%s: subnode name: %s\n", __func__, name);
-
- dr_mode = usb_get_dr_mode(node);
-
- switch (dr_mode) {
- case USB_DR_MODE_PERIPHERAL:
- case USB_DR_MODE_OTG:
-#if CONFIG_IS_ENABLED(DM_USB_GADGET)
- debug("%s: dr_mode: OTG or Peripheral\n", __func__);
- driver = "dwc3-generic-peripheral";
-#endif
- break;
-#if defined(CONFIG_SPL_USB_HOST) || !defined(CONFIG_SPL_BUILD)
- case USB_DR_MODE_HOST:
- debug("%s: dr_mode: HOST\n", __func__);
- driver = "dwc3-generic-host";
- break;
-#endif
- default:
- debug("%s: unsupported dr_mode\n", __func__);
- return -ENODEV;
- };
-
- if (!driver)
+ ret = dwc3_bind_to_node(parent, node);
+ if (ret == -ENOTSUPP)
continue;
-
- ret = device_bind_driver_to_node(parent, driver, name,
- node, &dev);
- if (ret) {
- debug("%s: not able to bind usb device mode\n",
- __func__);
+ if (ret)
return ret;
- }
}
return 0;
@@ -511,6 +525,19 @@ static int dwc3_glue_remove(struct udevice *dev)
return 0;
}
+static const struct udevice_id dwc3_ids[] = {
+ { .compatible = "snps,dwc3" },
+ { .compatible = "synopsys,dwc3" },
+ { }
+};
+
+U_BOOT_DRIVER(dwc3_wrapper) = {
+ .name = "dwc3-wrapper",
+ .id = UCLASS_NOP,
+ .of_match = dwc3_ids,
+ .bind = dwc3_bind,
+};
+
static const struct udevice_id dwc3_glue_ids[] = {
{ .compatible = "xlnx,zynqmp-dwc3" },
{ .compatible = "xlnx,versal-dwc3" },
@@ -526,8 +553,8 @@ static const struct udevice_id dwc3_glue_ids[] = {
{ }
};
-U_BOOT_DRIVER(dwc3_generic_wrapper) = {
- .name = "dwc3-generic-wrapper",
+U_BOOT_DRIVER(dwc3_glue_wrapper) = {
+ .name = "dwc3-glue-wrapper",
.id = UCLASS_NOP,
.of_match = dwc3_glue_ids,
.bind = dwc3_glue_bind,
--
2.34.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3627 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20220616/99cd2a2e/attachment.bin>
More information about the U-Boot
mailing list