1 // SPDX-License-Identifier: GPL-2.0
3 * Generic DWC3 Glue layer
5 * Copyright (C) 2016 - 2018 Xilinx, Inc.
7 * Based on dwc3-omap.c.
12 #include <dm/device-internal.h>
14 #include <linux/usb/otg.h>
15 #include <linux/compat.h>
16 #include <linux/usb/ch9.h>
17 #include <linux/usb/gadget.h>
22 #include "linux-compat.h"
24 #if CONFIG_IS_ENABLED(DM_USB_GADGET)
25 int dm_usb_gadget_handle_interrupts(struct udevice
*dev
)
27 struct dwc3
*priv
= dev_get_priv(dev
);
29 dwc3_gadget_uboot_handle_interrupt(priv
);
34 static int dwc3_generic_peripheral_probe(struct udevice
*dev
)
36 struct dwc3
*priv
= dev_get_priv(dev
);
38 return dwc3_init(priv
);
41 static int dwc3_generic_peripheral_remove(struct udevice
*dev
)
43 struct dwc3
*priv
= dev_get_priv(dev
);
50 static int dwc3_generic_peripheral_ofdata_to_platdata(struct udevice
*dev
)
52 struct dwc3
*priv
= dev_get_priv(dev
);
53 int node
= dev_of_offset(dev
);
55 priv
->regs
= (void *)devfdt_get_addr(dev
);
56 priv
->regs
+= DWC3_GLOBALS_REGS_START
;
58 priv
->maximum_speed
= usb_get_maximum_speed(node
);
59 if (priv
->maximum_speed
== USB_SPEED_UNKNOWN
) {
60 pr_err("Invalid usb maximum speed\n");
64 priv
->dr_mode
= usb_get_dr_mode(node
);
65 if (priv
->dr_mode
== USB_DR_MODE_UNKNOWN
) {
66 pr_err("Invalid usb mode setup\n");
73 U_BOOT_DRIVER(dwc3_generic_peripheral
) = {
74 .name
= "dwc3-generic-peripheral",
75 .id
= UCLASS_USB_DEV_GENERIC
,
76 .ofdata_to_platdata
= dwc3_generic_peripheral_ofdata_to_platdata
,
77 .probe
= dwc3_generic_peripheral_probe
,
78 .remove
= dwc3_generic_peripheral_remove
,
79 .platdata_auto_alloc_size
= sizeof(struct usb_platdata
),
80 .priv_auto_alloc_size
= sizeof(struct dwc3
),
84 static int dwc3_generic_bind(struct udevice
*parent
)
86 const void *fdt
= gd
->fdt_blob
;
90 for (node
= fdt_first_subnode(fdt
, dev_of_offset(parent
)); node
> 0;
91 node
= fdt_next_subnode(fdt
, node
)) {
92 const char *name
= fdt_get_name(fdt
, node
, NULL
);
93 enum usb_dr_mode dr_mode
;
97 debug("%s: subnode name: %s\n", __func__
, name
);
98 if (strncmp(name
, "dwc3@", 4))
101 dr_mode
= usb_get_dr_mode(node
);
104 case USB_DR_MODE_PERIPHERAL
:
105 case USB_DR_MODE_OTG
:
106 debug("%s: dr_mode: OTG or Peripheral\n", __func__
);
107 driver
= "dwc3-generic-peripheral";
109 case USB_DR_MODE_HOST
:
110 debug("%s: dr_mode: HOST\n", __func__
);
111 driver
= "dwc3-generic-host";
114 debug("%s: unsupported dr_mode\n", __func__
);
118 ret
= device_bind_driver_to_node(parent
, driver
, name
,
119 offset_to_ofnode(node
), &dev
);
121 debug("%s: not able to bind usb device mode\n",
130 static const struct udevice_id dwc3_generic_ids
[] = {
131 { .compatible
= "xlnx,zynqmp-dwc3" },
135 U_BOOT_DRIVER(dwc3_generic_wrapper
) = {
136 .name
= "dwc3-generic-wrapper",
138 .of_match
= dwc3_generic_ids
,
139 .bind
= dwc3_generic_bind
,