Patrick Delaunay | 22929e1 | 2018-10-26 09:02:52 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Generic DWC3 Glue layer |
| 4 | * |
| 5 | * Copyright (C) 2016 - 2018 Xilinx, Inc. |
| 6 | * |
| 7 | * Based on dwc3-omap.c. |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 11 | #include <cpu_func.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 13 | #include <dm.h> |
| 14 | #include <dm/device-internal.h> |
| 15 | #include <dm/lists.h> |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 16 | #include <dwc3-uboot.h> |
Michal Simek | 142d50f | 2022-03-09 10:05:45 +0100 | [diff] [blame] | 17 | #include <generic-phy.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Frank Wang | 5d422ab | 2020-05-26 11:34:31 +0800 | [diff] [blame] | 19 | #include <linux/delay.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 20 | #include <linux/printk.h> |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 21 | #include <linux/usb/ch9.h> |
| 22 | #include <linux/usb/gadget.h> |
| 23 | #include <malloc.h> |
Caleb Connolly | c66c92c | 2023-09-12 22:01:31 +0100 | [diff] [blame] | 24 | #include <power/regulator.h> |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 25 | #include <usb.h> |
| 26 | #include "core.h" |
| 27 | #include "gadget.h" |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 28 | #include <reset.h> |
| 29 | #include <clk.h> |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 30 | #include <usb/xhci.h> |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 31 | #include <asm/gpio.h> |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 32 | |
Kunihiko Hayashi | ef2313b | 2023-02-20 14:50:28 +0900 | [diff] [blame] | 33 | #include "dwc3-generic.h" |
Frank Wang | 5d422ab | 2020-05-26 11:34:31 +0800 | [diff] [blame] | 34 | |
Jean-Jacques Hiblot | 3a38a0a | 2019-09-11 11:33:48 +0200 | [diff] [blame] | 35 | struct dwc3_generic_plat { |
| 36 | fdt_addr_t base; |
| 37 | u32 maximum_speed; |
| 38 | enum usb_dr_mode dr_mode; |
| 39 | }; |
| 40 | |
Jean-Jacques Hiblot | 3a38a0a | 2019-09-11 11:33:48 +0200 | [diff] [blame] | 41 | struct dwc3_generic_priv { |
Jean-Jacques Hiblot | 1af590d | 2019-09-11 11:33:49 +0200 | [diff] [blame] | 42 | void *base; |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 43 | struct dwc3 dwc3; |
Chunfeng Yun | 6dfb8a8 | 2020-05-02 11:35:13 +0200 | [diff] [blame] | 44 | struct phy_bulk phys; |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 45 | struct gpio_desc *ulpi_reset; |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 48 | struct dwc3_generic_host_priv { |
| 49 | struct xhci_ctrl xhci_ctrl; |
| 50 | struct dwc3_generic_priv gen_priv; |
Caleb Connolly | c66c92c | 2023-09-12 22:01:31 +0100 | [diff] [blame] | 51 | struct udevice *vbus_dev; |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Jean-Jacques Hiblot | 1af590d | 2019-09-11 11:33:49 +0200 | [diff] [blame] | 54 | static int dwc3_generic_probe(struct udevice *dev, |
| 55 | struct dwc3_generic_priv *priv) |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 56 | { |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 57 | int rc; |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 58 | struct dwc3_generic_plat *plat = dev_get_plat(dev); |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 59 | struct dwc3 *dwc3 = &priv->dwc3; |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 60 | struct dwc3_glue_data *glue = dev_get_plat(dev->parent); |
Marek Vasut | 8ae84e6 | 2022-11-27 15:31:52 +0100 | [diff] [blame] | 61 | int __maybe_unused index; |
| 62 | ofnode __maybe_unused node; |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 63 | |
Jean-Jacques Hiblot | ba6c5f7 | 2019-09-11 11:33:52 +0200 | [diff] [blame] | 64 | dwc3->dev = dev; |
Jean-Jacques Hiblot | 3a38a0a | 2019-09-11 11:33:48 +0200 | [diff] [blame] | 65 | dwc3->maximum_speed = plat->maximum_speed; |
| 66 | dwc3->dr_mode = plat->dr_mode; |
Jean-Jacques Hiblot | ba6c5f7 | 2019-09-11 11:33:52 +0200 | [diff] [blame] | 67 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
| 68 | dwc3_of_parse(dwc3); |
Marek Vasut | 8ae84e6 | 2022-11-27 15:31:52 +0100 | [diff] [blame] | 69 | |
Marek Vasut | c658335 | 2023-02-20 14:50:25 +0900 | [diff] [blame] | 70 | /* |
| 71 | * There are currently four disparate placement possibilities of DWC3 |
| 72 | * reference clock phandle in SoC DTs: |
| 73 | * - in top level glue node, with generic subnode without clock (ZynqMP) |
| 74 | * - in top level generic node, with no subnode (i.MX8MQ) |
| 75 | * - in generic subnode, with other clock in top level node (i.MX8MP) |
| 76 | * - in both top level node and generic subnode (Rockchip) |
| 77 | * Cover all the possibilities here by looking into both nodes, start |
| 78 | * with the top level node as that seems to be used in majority of DTs |
| 79 | * to reference the clock. |
| 80 | */ |
Marek Vasut | 8ae84e6 | 2022-11-27 15:31:52 +0100 | [diff] [blame] | 81 | node = dev_ofnode(dev->parent); |
| 82 | index = ofnode_stringlist_search(node, "clock-names", "ref"); |
| 83 | if (index < 0) |
| 84 | index = ofnode_stringlist_search(node, "clock-names", "ref_clk"); |
Marek Vasut | c658335 | 2023-02-20 14:50:25 +0900 | [diff] [blame] | 85 | if (index < 0) { |
| 86 | node = dev_ofnode(dev); |
| 87 | index = ofnode_stringlist_search(node, "clock-names", "ref"); |
| 88 | if (index < 0) |
| 89 | index = ofnode_stringlist_search(node, "clock-names", "ref_clk"); |
| 90 | } |
Marek Vasut | 8ae84e6 | 2022-11-27 15:31:52 +0100 | [diff] [blame] | 91 | if (index >= 0) |
| 92 | dwc3->ref_clk = &glue->clks.clks[index]; |
Jean-Jacques Hiblot | ba6c5f7 | 2019-09-11 11:33:52 +0200 | [diff] [blame] | 93 | #endif |
Jean-Jacques Hiblot | 3a38a0a | 2019-09-11 11:33:48 +0200 | [diff] [blame] | 94 | |
Frank Wang | 5d422ab | 2020-05-26 11:34:31 +0800 | [diff] [blame] | 95 | /* |
| 96 | * It must hold whole USB3.0 OTG controller in resetting to hold pipe |
| 97 | * power state in P2 before initializing TypeC PHY on RK3399 platform. |
| 98 | */ |
| 99 | if (device_is_compatible(dev->parent, "rockchip,rk3399-dwc3")) { |
| 100 | reset_assert_bulk(&glue->resets); |
| 101 | udelay(1); |
| 102 | } |
| 103 | |
Chunfeng Yun | 6dfb8a8 | 2020-05-02 11:35:13 +0200 | [diff] [blame] | 104 | rc = dwc3_setup_phy(dev, &priv->phys); |
Siva Durga Prasad Paladugu | e7f9e1f | 2020-10-21 14:17:31 +0200 | [diff] [blame] | 105 | if (rc && rc != -ENOTSUPP) |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 106 | return rc; |
| 107 | |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 108 | if (CONFIG_IS_ENABLED(DM_GPIO) && |
| 109 | device_is_compatible(dev->parent, "xlnx,zynqmp-dwc3")) { |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 110 | priv->ulpi_reset = devm_gpiod_get_optional(dev->parent, "reset", |
Peter Korsgaard | d266d4b | 2023-06-28 14:26:48 +0200 | [diff] [blame] | 111 | GPIOD_IS_OUT | GPIOD_ACTIVE_LOW); |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 112 | /* property is optional, don't return error! */ |
| 113 | if (priv->ulpi_reset) { |
| 114 | /* Toggle ulpi to reset the phy. */ |
| 115 | rc = dm_gpio_set_value(priv->ulpi_reset, 1); |
| 116 | if (rc) |
| 117 | return rc; |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 118 | |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 119 | mdelay(5); |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 120 | |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 121 | rc = dm_gpio_set_value(priv->ulpi_reset, 0); |
| 122 | if (rc) |
| 123 | return rc; |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 124 | |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 125 | mdelay(5); |
| 126 | } |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Frank Wang | 5d422ab | 2020-05-26 11:34:31 +0800 | [diff] [blame] | 129 | if (device_is_compatible(dev->parent, "rockchip,rk3399-dwc3")) |
| 130 | reset_deassert_bulk(&glue->resets); |
| 131 | |
Jean-Jacques Hiblot | 1af590d | 2019-09-11 11:33:49 +0200 | [diff] [blame] | 132 | priv->base = map_physmem(plat->base, DWC3_OTG_REGS_END, MAP_NOCACHE); |
| 133 | dwc3->regs = priv->base + DWC3_GLOBALS_REGS_START; |
Jean-Jacques Hiblot | ba6c5f7 | 2019-09-11 11:33:52 +0200 | [diff] [blame] | 134 | |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 135 | |
| 136 | rc = dwc3_init(dwc3); |
| 137 | if (rc) { |
Jean-Jacques Hiblot | 1af590d | 2019-09-11 11:33:49 +0200 | [diff] [blame] | 138 | unmap_physmem(priv->base, MAP_NOCACHE); |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 139 | return rc; |
| 140 | } |
| 141 | |
| 142 | return 0; |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Jean-Jacques Hiblot | 1af590d | 2019-09-11 11:33:49 +0200 | [diff] [blame] | 145 | static int dwc3_generic_remove(struct udevice *dev, |
| 146 | struct dwc3_generic_priv *priv) |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 147 | { |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 148 | struct dwc3 *dwc3 = &priv->dwc3; |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 149 | |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 150 | if (CONFIG_IS_ENABLED(DM_GPIO) && |
Venkatesh Yadav Abbarapu | 9871b0e | 2023-08-09 09:03:50 +0530 | [diff] [blame] | 151 | device_is_compatible(dev->parent, "xlnx,zynqmp-dwc3") && |
| 152 | priv->ulpi_reset) { |
Venkatesh Yadav Abbarapu | 237d1f6 | 2023-01-13 10:42:02 +0530 | [diff] [blame] | 153 | struct gpio_desc *ulpi_reset = priv->ulpi_reset; |
T Karthik Reddy | b252d79 | 2022-07-08 11:21:59 +0200 | [diff] [blame] | 154 | |
| 155 | dm_gpio_free(ulpi_reset->dev, ulpi_reset); |
| 156 | } |
| 157 | |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 158 | dwc3_remove(dwc3); |
Chunfeng Yun | 6dfb8a8 | 2020-05-02 11:35:13 +0200 | [diff] [blame] | 159 | dwc3_shutdown_phy(dev, &priv->phys); |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 160 | unmap_physmem(dwc3->regs, MAP_NOCACHE); |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 165 | static int dwc3_generic_of_to_plat(struct udevice *dev) |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 166 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 167 | struct dwc3_generic_plat *plat = dev_get_plat(dev); |
Simon Glass | f10643c | 2020-12-19 10:40:14 -0700 | [diff] [blame] | 168 | ofnode node = dev_ofnode(dev); |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 169 | |
Angus Ainslie | c08db05 | 2022-02-02 15:08:54 -0800 | [diff] [blame] | 170 | if (!strncmp(dev->name, "port", 4) || !strncmp(dev->name, "hub", 3)) { |
| 171 | /* This is a leaf so check the parent */ |
| 172 | plat->base = dev_read_addr(dev->parent); |
| 173 | } else { |
| 174 | plat->base = dev_read_addr(dev); |
| 175 | } |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 176 | |
Jean-Jacques Hiblot | 3a38a0a | 2019-09-11 11:33:48 +0200 | [diff] [blame] | 177 | plat->maximum_speed = usb_get_maximum_speed(node); |
| 178 | if (plat->maximum_speed == USB_SPEED_UNKNOWN) { |
Jean-Jacques Hiblot | 1a63e5e | 2019-09-11 11:33:51 +0200 | [diff] [blame] | 179 | pr_info("No USB maximum speed specified. Using super speed\n"); |
| 180 | plat->maximum_speed = USB_SPEED_SUPER; |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Jean-Jacques Hiblot | 3a38a0a | 2019-09-11 11:33:48 +0200 | [diff] [blame] | 183 | plat->dr_mode = usb_get_dr_mode(node); |
| 184 | if (plat->dr_mode == USB_DR_MODE_UNKNOWN) { |
Angus Ainslie | c08db05 | 2022-02-02 15:08:54 -0800 | [diff] [blame] | 185 | /* might be a leaf so check the parent for mode */ |
| 186 | node = dev_ofnode(dev->parent); |
| 187 | plat->dr_mode = usb_get_dr_mode(node); |
| 188 | if (plat->dr_mode == USB_DR_MODE_UNKNOWN) { |
| 189 | pr_err("Invalid usb mode setup\n"); |
| 190 | return -ENODEV; |
| 191 | } |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Jean-Jacques Hiblot | 1af590d | 2019-09-11 11:33:49 +0200 | [diff] [blame] | 197 | #if CONFIG_IS_ENABLED(DM_USB_GADGET) |
| 198 | int dm_usb_gadget_handle_interrupts(struct udevice *dev) |
| 199 | { |
| 200 | struct dwc3_generic_priv *priv = dev_get_priv(dev); |
| 201 | struct dwc3 *dwc3 = &priv->dwc3; |
| 202 | |
| 203 | dwc3_gadget_uboot_handle_interrupt(dwc3); |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static int dwc3_generic_peripheral_probe(struct udevice *dev) |
| 209 | { |
| 210 | struct dwc3_generic_priv *priv = dev_get_priv(dev); |
| 211 | |
| 212 | return dwc3_generic_probe(dev, priv); |
| 213 | } |
| 214 | |
| 215 | static int dwc3_generic_peripheral_remove(struct udevice *dev) |
| 216 | { |
| 217 | struct dwc3_generic_priv *priv = dev_get_priv(dev); |
| 218 | |
| 219 | return dwc3_generic_remove(dev, priv); |
| 220 | } |
| 221 | |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 222 | U_BOOT_DRIVER(dwc3_generic_peripheral) = { |
| 223 | .name = "dwc3-generic-peripheral", |
Jean-Jacques Hiblot | 0131162 | 2018-11-29 10:52:46 +0100 | [diff] [blame] | 224 | .id = UCLASS_USB_GADGET_GENERIC, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 225 | .of_to_plat = dwc3_generic_of_to_plat, |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 226 | .probe = dwc3_generic_peripheral_probe, |
| 227 | .remove = dwc3_generic_peripheral_remove, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 228 | .priv_auto = sizeof(struct dwc3_generic_priv), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 229 | .plat_auto = sizeof(struct dwc3_generic_plat), |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 230 | }; |
Jean-Jacques Hiblot | 687ab54 | 2018-11-29 10:52:42 +0100 | [diff] [blame] | 231 | #endif |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 232 | |
Jonas Karlman | 6913c30 | 2023-07-30 22:59:56 +0000 | [diff] [blame] | 233 | #if CONFIG_IS_ENABLED(USB_HOST) |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 234 | static int dwc3_generic_host_probe(struct udevice *dev) |
| 235 | { |
| 236 | struct xhci_hcor *hcor; |
| 237 | struct xhci_hccr *hccr; |
| 238 | struct dwc3_generic_host_priv *priv = dev_get_priv(dev); |
| 239 | int rc; |
| 240 | |
| 241 | rc = dwc3_generic_probe(dev, &priv->gen_priv); |
| 242 | if (rc) |
| 243 | return rc; |
| 244 | |
Caleb Connolly | c66c92c | 2023-09-12 22:01:31 +0100 | [diff] [blame] | 245 | rc = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_dev); |
| 246 | if (rc) |
| 247 | debug("%s: No vbus regulator found: %d\n", dev->name, rc); |
| 248 | |
| 249 | if (priv->vbus_dev) |
| 250 | regulator_set_enable(priv->vbus_dev, true); |
| 251 | |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 252 | hccr = (struct xhci_hccr *)priv->gen_priv.base; |
| 253 | hcor = (struct xhci_hcor *)(priv->gen_priv.base + |
| 254 | HC_LENGTH(xhci_readl(&(hccr)->cr_capbase))); |
| 255 | |
| 256 | return xhci_register(dev, hccr, hcor); |
| 257 | } |
| 258 | |
| 259 | static int dwc3_generic_host_remove(struct udevice *dev) |
| 260 | { |
| 261 | struct dwc3_generic_host_priv *priv = dev_get_priv(dev); |
| 262 | int rc; |
| 263 | |
| 264 | rc = xhci_deregister(dev); |
| 265 | if (rc) |
| 266 | return rc; |
| 267 | |
Caleb Connolly | c66c92c | 2023-09-12 22:01:31 +0100 | [diff] [blame] | 268 | if (priv->vbus_dev) |
| 269 | regulator_set_enable(priv->vbus_dev, false); |
| 270 | |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 271 | return dwc3_generic_remove(dev, &priv->gen_priv); |
| 272 | } |
| 273 | |
| 274 | U_BOOT_DRIVER(dwc3_generic_host) = { |
| 275 | .name = "dwc3-generic-host", |
| 276 | .id = UCLASS_USB, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 277 | .of_to_plat = dwc3_generic_of_to_plat, |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 278 | .probe = dwc3_generic_host_probe, |
| 279 | .remove = dwc3_generic_host_remove, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 280 | .priv_auto = sizeof(struct dwc3_generic_host_priv), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 281 | .plat_auto = sizeof(struct dwc3_generic_plat), |
Jean-Jacques Hiblot | b575e90 | 2019-09-11 11:33:50 +0200 | [diff] [blame] | 282 | .ops = &xhci_usb_ops, |
| 283 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 284 | }; |
| 285 | #endif |
| 286 | |
Marek Vasut | d0f7a05 | 2022-04-13 00:42:56 +0200 | [diff] [blame] | 287 | void dwc3_imx8mp_glue_configure(struct udevice *dev, int index, |
| 288 | enum usb_dr_mode mode) |
| 289 | { |
| 290 | /* USB glue registers */ |
| 291 | #define USB_CTRL0 0x00 |
| 292 | #define USB_CTRL1 0x04 |
| 293 | |
| 294 | #define USB_CTRL0_PORTPWR_EN BIT(12) /* 1 - PPC enabled (default) */ |
| 295 | #define USB_CTRL0_USB3_FIXED BIT(22) /* 1 - USB3 permanent attached */ |
| 296 | #define USB_CTRL0_USB2_FIXED BIT(23) /* 1 - USB2 permanent attached */ |
| 297 | |
| 298 | #define USB_CTRL1_OC_POLARITY BIT(16) /* 0 - HIGH / 1 - LOW */ |
| 299 | #define USB_CTRL1_PWR_POLARITY BIT(17) /* 0 - HIGH / 1 - LOW */ |
| 300 | fdt_addr_t regs = dev_read_addr_index(dev, 1); |
| 301 | void *base = map_physmem(regs, 0x8, MAP_NOCACHE); |
| 302 | u32 value; |
| 303 | |
| 304 | value = readl(base + USB_CTRL0); |
| 305 | |
| 306 | if (dev_read_bool(dev, "fsl,permanently-attached")) |
| 307 | value |= (USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED); |
| 308 | else |
| 309 | value &= ~(USB_CTRL0_USB2_FIXED | USB_CTRL0_USB3_FIXED); |
| 310 | |
| 311 | if (dev_read_bool(dev, "fsl,disable-port-power-control")) |
| 312 | value &= ~(USB_CTRL0_PORTPWR_EN); |
| 313 | else |
| 314 | value |= USB_CTRL0_PORTPWR_EN; |
| 315 | |
| 316 | writel(value, base + USB_CTRL0); |
| 317 | |
| 318 | value = readl(base + USB_CTRL1); |
| 319 | if (dev_read_bool(dev, "fsl,over-current-active-low")) |
| 320 | value |= USB_CTRL1_OC_POLARITY; |
| 321 | else |
| 322 | value &= ~USB_CTRL1_OC_POLARITY; |
| 323 | |
| 324 | if (dev_read_bool(dev, "fsl,power-active-low")) |
| 325 | value |= USB_CTRL1_PWR_POLARITY; |
| 326 | else |
| 327 | value &= ~USB_CTRL1_PWR_POLARITY; |
| 328 | |
| 329 | writel(value, base + USB_CTRL1); |
| 330 | |
| 331 | unmap_physmem(base, MAP_NOCACHE); |
| 332 | } |
| 333 | |
| 334 | struct dwc3_glue_ops imx8mp_ops = { |
| 335 | .glue_configure = dwc3_imx8mp_glue_configure, |
| 336 | }; |
| 337 | |
Marek Vasut | f1ef955 | 2022-04-13 00:42:55 +0200 | [diff] [blame] | 338 | void dwc3_ti_glue_configure(struct udevice *dev, int index, |
Jean-Jacques Hiblot | d66e54a | 2018-11-29 10:57:40 +0100 | [diff] [blame] | 339 | enum usb_dr_mode mode) |
| 340 | { |
| 341 | #define USBOTGSS_UTMI_OTG_STATUS 0x0084 |
| 342 | #define USBOTGSS_UTMI_OTG_OFFSET 0x0480 |
| 343 | |
| 344 | /* UTMI_OTG_STATUS REGISTER */ |
| 345 | #define USBOTGSS_UTMI_OTG_STATUS_SW_MODE BIT(31) |
| 346 | #define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT BIT(9) |
| 347 | #define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE BIT(8) |
| 348 | #define USBOTGSS_UTMI_OTG_STATUS_IDDIG BIT(4) |
| 349 | #define USBOTGSS_UTMI_OTG_STATUS_SESSEND BIT(3) |
| 350 | #define USBOTGSS_UTMI_OTG_STATUS_SESSVALID BIT(2) |
| 351 | #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID BIT(1) |
| 352 | enum dwc3_omap_utmi_mode { |
| 353 | DWC3_OMAP_UTMI_MODE_UNKNOWN = 0, |
| 354 | DWC3_OMAP_UTMI_MODE_HW, |
| 355 | DWC3_OMAP_UTMI_MODE_SW, |
| 356 | }; |
| 357 | |
| 358 | u32 use_id_pin; |
| 359 | u32 host_mode; |
| 360 | u32 reg; |
| 361 | u32 utmi_mode; |
| 362 | u32 utmi_status_offset = USBOTGSS_UTMI_OTG_STATUS; |
| 363 | |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 364 | struct dwc3_glue_data *glue = dev_get_plat(dev); |
Jean-Jacques Hiblot | d66e54a | 2018-11-29 10:57:40 +0100 | [diff] [blame] | 365 | void *base = map_physmem(glue->regs, 0x10000, MAP_NOCACHE); |
| 366 | |
| 367 | if (device_is_compatible(dev, "ti,am437x-dwc3")) |
| 368 | utmi_status_offset += USBOTGSS_UTMI_OTG_OFFSET; |
| 369 | |
| 370 | utmi_mode = dev_read_u32_default(dev, "utmi-mode", |
| 371 | DWC3_OMAP_UTMI_MODE_UNKNOWN); |
| 372 | if (utmi_mode != DWC3_OMAP_UTMI_MODE_HW) { |
| 373 | debug("%s: OTG is not supported. defaulting to PERIPHERAL\n", |
| 374 | dev->name); |
| 375 | mode = USB_DR_MODE_PERIPHERAL; |
| 376 | } |
| 377 | |
| 378 | switch (mode) { |
| 379 | case USB_DR_MODE_PERIPHERAL: |
| 380 | use_id_pin = 0; |
| 381 | host_mode = 0; |
| 382 | break; |
| 383 | case USB_DR_MODE_HOST: |
| 384 | use_id_pin = 0; |
| 385 | host_mode = 1; |
| 386 | break; |
| 387 | case USB_DR_MODE_OTG: |
| 388 | default: |
| 389 | use_id_pin = 1; |
| 390 | host_mode = 0; |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | reg = readl(base + utmi_status_offset); |
| 395 | |
| 396 | reg &= ~(USBOTGSS_UTMI_OTG_STATUS_SW_MODE); |
| 397 | if (!use_id_pin) |
| 398 | reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
| 399 | |
| 400 | writel(reg, base + utmi_status_offset); |
| 401 | |
| 402 | reg &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSEND | |
| 403 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID | |
| 404 | USBOTGSS_UTMI_OTG_STATUS_IDDIG); |
| 405 | |
| 406 | reg |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID | |
| 407 | USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT; |
| 408 | |
| 409 | if (!host_mode) |
| 410 | reg |= USBOTGSS_UTMI_OTG_STATUS_IDDIG | |
| 411 | USBOTGSS_UTMI_OTG_STATUS_VBUSVALID; |
| 412 | |
| 413 | writel(reg, base + utmi_status_offset); |
| 414 | |
| 415 | unmap_physmem(base, MAP_NOCACHE); |
| 416 | } |
| 417 | |
| 418 | struct dwc3_glue_ops ti_ops = { |
Marek Vasut | f1ef955 | 2022-04-13 00:42:55 +0200 | [diff] [blame] | 419 | .glue_configure = dwc3_ti_glue_configure, |
Jean-Jacques Hiblot | d66e54a | 2018-11-29 10:57:40 +0100 | [diff] [blame] | 420 | }; |
| 421 | |
Caleb Connolly | 896e528 | 2023-09-12 22:00:12 +0100 | [diff] [blame] | 422 | /* USB QSCRATCH Hardware registers */ |
| 423 | #define QSCRATCH_HS_PHY_CTRL 0x10 |
| 424 | #define UTMI_OTG_VBUS_VALID BIT(20) |
| 425 | #define SW_SESSVLD_SEL BIT(28) |
| 426 | |
| 427 | #define QSCRATCH_SS_PHY_CTRL 0x30 |
| 428 | #define LANE0_PWR_PRESENT BIT(24) |
| 429 | |
| 430 | #define QSCRATCH_GENERAL_CFG 0x08 |
| 431 | #define PIPE_UTMI_CLK_SEL BIT(0) |
| 432 | #define PIPE3_PHYSTATUS_SW BIT(3) |
| 433 | #define PIPE_UTMI_CLK_DIS BIT(8) |
| 434 | |
| 435 | #define PWR_EVNT_IRQ_STAT_REG 0x58 |
| 436 | #define PWR_EVNT_LPM_IN_L2_MASK BIT(4) |
| 437 | #define PWR_EVNT_LPM_OUT_L2_MASK BIT(5) |
| 438 | |
| 439 | #define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 |
| 440 | #define SDM845_QSCRATCH_SIZE 0x400 |
| 441 | #define SDM845_DWC3_CORE_SIZE 0xcd00 |
| 442 | static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val) |
| 443 | { |
| 444 | u32 reg; |
| 445 | |
| 446 | reg = readl(base + offset); |
| 447 | reg |= val; |
| 448 | writel(reg, base + offset); |
| 449 | |
| 450 | /* ensure that above write is through */ |
| 451 | readl(base + offset); |
| 452 | } |
| 453 | |
| 454 | static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val) |
| 455 | { |
| 456 | u32 reg; |
| 457 | |
| 458 | reg = readl(base + offset); |
| 459 | reg &= ~val; |
| 460 | writel(reg, base + offset); |
| 461 | |
| 462 | /* ensure that above write is through */ |
| 463 | readl(base + offset); |
| 464 | } |
| 465 | |
| 466 | static void dwc3_qcom_vbus_override_enable(void __iomem *qscratch_base, bool enable) |
| 467 | { |
| 468 | if (enable) { |
| 469 | dwc3_qcom_setbits(qscratch_base, QSCRATCH_SS_PHY_CTRL, |
| 470 | LANE0_PWR_PRESENT); |
| 471 | dwc3_qcom_setbits(qscratch_base, QSCRATCH_HS_PHY_CTRL, |
| 472 | UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); |
| 473 | } else { |
| 474 | dwc3_qcom_clrbits(qscratch_base, QSCRATCH_SS_PHY_CTRL, |
| 475 | LANE0_PWR_PRESENT); |
| 476 | dwc3_qcom_clrbits(qscratch_base, QSCRATCH_HS_PHY_CTRL, |
| 477 | UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | static void dwc3_qcom_select_utmi_clk(void __iomem *qscratch_base) |
| 482 | { |
| 483 | |
| 484 | /* Configure dwc3 to use UTMI clock as PIPE clock not present */ |
| 485 | dwc3_qcom_setbits(qscratch_base, QSCRATCH_GENERAL_CFG, |
| 486 | PIPE_UTMI_CLK_DIS); |
| 487 | |
| 488 | udelay(500); |
| 489 | |
| 490 | dwc3_qcom_setbits(qscratch_base, QSCRATCH_GENERAL_CFG, |
| 491 | PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW); |
| 492 | |
| 493 | udelay(500); |
| 494 | |
| 495 | dwc3_qcom_clrbits(qscratch_base, QSCRATCH_GENERAL_CFG, |
| 496 | PIPE_UTMI_CLK_DIS); |
| 497 | } |
| 498 | |
| 499 | static void dwc3_qcom_glue_configure(struct udevice *dev, int index, |
| 500 | enum usb_dr_mode mode) |
| 501 | { |
| 502 | void __iomem *qscratch_base = (void __iomem *)dev_read_addr(dev); |
| 503 | |
| 504 | debug("%s: qscratch_base = %p mode %d\n", __func__, qscratch_base, mode); |
| 505 | |
| 506 | if (dev_read_bool(dev, "qcom,select-utmi-as-pipe-clk")) |
| 507 | dwc3_qcom_select_utmi_clk(qscratch_base); |
| 508 | |
| 509 | if (mode != USB_DR_MODE_HOST) |
| 510 | dwc3_qcom_vbus_override_enable(qscratch_base, true); |
| 511 | } |
| 512 | |
| 513 | struct dwc3_glue_ops qcom_ops = { |
| 514 | .glue_configure = dwc3_qcom_glue_configure, |
| 515 | }; |
| 516 | |
Jonas Karlman | caaeac8 | 2023-07-30 22:59:57 +0000 | [diff] [blame] | 517 | static int dwc3_rk_glue_get_ctrl_dev(struct udevice *dev, ofnode *node) |
| 518 | { |
| 519 | *node = dev_ofnode(dev); |
| 520 | if (!ofnode_valid(*node)) |
| 521 | return -EINVAL; |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | struct dwc3_glue_ops rk_ops = { |
| 527 | .glue_get_ctrl_dev = dwc3_rk_glue_get_ctrl_dev, |
| 528 | }; |
| 529 | |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 530 | static int dwc3_glue_bind_common(struct udevice *parent, ofnode node) |
| 531 | { |
| 532 | const char *name = ofnode_get_name(node); |
Jonas Karlman | 6913c30 | 2023-07-30 22:59:56 +0000 | [diff] [blame] | 533 | const char *driver; |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 534 | enum usb_dr_mode dr_mode; |
| 535 | struct udevice *dev; |
| 536 | int ret; |
| 537 | |
| 538 | debug("%s: subnode name: %s\n", __func__, name); |
| 539 | |
| 540 | /* if the parent node doesn't have a mode check the leaf */ |
| 541 | dr_mode = usb_get_dr_mode(dev_ofnode(parent)); |
| 542 | if (!dr_mode) |
| 543 | dr_mode = usb_get_dr_mode(node); |
| 544 | |
Jonas Karlman | 6913c30 | 2023-07-30 22:59:56 +0000 | [diff] [blame] | 545 | if (CONFIG_IS_ENABLED(DM_USB_GADGET) && |
| 546 | (dr_mode == USB_DR_MODE_PERIPHERAL || dr_mode == USB_DR_MODE_OTG)) { |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 547 | debug("%s: dr_mode: OTG or Peripheral\n", __func__); |
| 548 | driver = "dwc3-generic-peripheral"; |
Jonas Karlman | 6913c30 | 2023-07-30 22:59:56 +0000 | [diff] [blame] | 549 | } else if (CONFIG_IS_ENABLED(USB_HOST) && dr_mode == USB_DR_MODE_HOST) { |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 550 | debug("%s: dr_mode: HOST\n", __func__); |
| 551 | driver = "dwc3-generic-host"; |
Jonas Karlman | 6913c30 | 2023-07-30 22:59:56 +0000 | [diff] [blame] | 552 | } else { |
| 553 | debug("%s: unsupported dr_mode %d\n", __func__, dr_mode); |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 554 | return -ENODEV; |
Jonas Karlman | 6913c30 | 2023-07-30 22:59:56 +0000 | [diff] [blame] | 555 | } |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 556 | |
| 557 | ret = device_bind_driver_to_node(parent, driver, name, |
| 558 | node, &dev); |
| 559 | if (ret) { |
| 560 | debug("%s: not able to bind usb device mode\n", |
| 561 | __func__); |
| 562 | return ret; |
| 563 | } |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
Kunihiko Hayashi | ef2313b | 2023-02-20 14:50:28 +0900 | [diff] [blame] | 568 | int dwc3_glue_bind(struct udevice *parent) |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 569 | { |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 570 | struct dwc3_glue_ops *ops = (struct dwc3_glue_ops *)dev_get_driver_data(parent); |
Kever Yang | ac28e59 | 2020-03-04 08:59:50 +0800 | [diff] [blame] | 571 | ofnode node; |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 572 | int ret; |
Angus Ainslie | c08db05 | 2022-02-02 15:08:54 -0800 | [diff] [blame] | 573 | |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 574 | if (ops && ops->glue_get_ctrl_dev) { |
| 575 | ret = ops->glue_get_ctrl_dev(parent, &node); |
| 576 | if (ret) |
| 577 | return ret; |
| 578 | |
| 579 | return dwc3_glue_bind_common(parent, node); |
| 580 | } |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 581 | |
Simon Glass | f10643c | 2020-12-19 10:40:14 -0700 | [diff] [blame] | 582 | ofnode_for_each_subnode(node, dev_ofnode(parent)) { |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 583 | ret = dwc3_glue_bind_common(parent, node); |
| 584 | if (ret == -ENXIO) |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 585 | continue; |
Kunihiko Hayashi | f7b7c72 | 2023-02-20 14:50:26 +0900 | [diff] [blame] | 586 | if (ret) |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 587 | return ret; |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 593 | static int dwc3_glue_reset_init(struct udevice *dev, |
| 594 | struct dwc3_glue_data *glue) |
| 595 | { |
| 596 | int ret; |
| 597 | |
| 598 | ret = reset_get_bulk(dev, &glue->resets); |
Vignesh Raghavendra | d624434 | 2019-10-25 13:48:05 +0530 | [diff] [blame] | 599 | if (ret == -ENOTSUPP || ret == -ENOENT) |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 600 | return 0; |
| 601 | else if (ret) |
| 602 | return ret; |
| 603 | |
Caleb Connolly | 896e528 | 2023-09-12 22:00:12 +0100 | [diff] [blame] | 604 | if (device_is_compatible(dev, "qcom,dwc3")) { |
| 605 | reset_assert_bulk(&glue->resets); |
| 606 | udelay(500); |
| 607 | } |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 608 | ret = reset_deassert_bulk(&glue->resets); |
| 609 | if (ret) { |
| 610 | reset_release_bulk(&glue->resets); |
| 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static int dwc3_glue_clk_init(struct udevice *dev, |
| 618 | struct dwc3_glue_data *glue) |
| 619 | { |
| 620 | int ret; |
| 621 | |
| 622 | ret = clk_get_bulk(dev, &glue->clks); |
Vignesh Raghavendra | d624434 | 2019-10-25 13:48:05 +0530 | [diff] [blame] | 623 | if (ret == -ENOSYS || ret == -ENOENT) |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 624 | return 0; |
| 625 | if (ret) |
| 626 | return ret; |
| 627 | |
| 628 | #if CONFIG_IS_ENABLED(CLK) |
| 629 | ret = clk_enable_bulk(&glue->clks); |
| 630 | if (ret) { |
| 631 | clk_release_bulk(&glue->clks); |
| 632 | return ret; |
| 633 | } |
| 634 | #endif |
| 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
Kunihiko Hayashi | ef2313b | 2023-02-20 14:50:28 +0900 | [diff] [blame] | 639 | int dwc3_glue_probe(struct udevice *dev) |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 640 | { |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 641 | struct dwc3_glue_ops *ops = (struct dwc3_glue_ops *)dev_get_driver_data(dev); |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 642 | struct dwc3_glue_data *glue = dev_get_plat(dev); |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 643 | struct udevice *child = NULL; |
| 644 | int index = 0; |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 645 | int ret; |
Michal Simek | 142d50f | 2022-03-09 10:05:45 +0100 | [diff] [blame] | 646 | struct phy phy; |
| 647 | |
| 648 | ret = generic_phy_get_by_name(dev, "usb3-phy", &phy); |
| 649 | if (!ret) { |
| 650 | ret = generic_phy_init(&phy); |
| 651 | if (ret) |
| 652 | return ret; |
Jan Kiszka | 868d58f | 2022-04-25 13:26:45 +0200 | [diff] [blame] | 653 | } else if (ret != -ENOENT && ret != -ENODATA) { |
Michal Simek | 142d50f | 2022-03-09 10:05:45 +0100 | [diff] [blame] | 654 | debug("could not get phy (err %d)\n", ret); |
| 655 | return ret; |
| 656 | } |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 657 | |
Kunihiko Hayashi | 211a066 | 2023-02-20 14:50:29 +0900 | [diff] [blame] | 658 | glue->regs = dev_read_addr_size_index(dev, 0, &glue->size); |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 659 | |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 660 | ret = dwc3_glue_clk_init(dev, glue); |
| 661 | if (ret) |
| 662 | return ret; |
| 663 | |
| 664 | ret = dwc3_glue_reset_init(dev, glue); |
| 665 | if (ret) |
| 666 | return ret; |
| 667 | |
Jonas Karlman | 5ccfdd8 | 2023-08-31 22:16:36 +0000 | [diff] [blame] | 668 | if (generic_phy_valid(&phy)) { |
Michal Simek | 142d50f | 2022-03-09 10:05:45 +0100 | [diff] [blame] | 669 | ret = generic_phy_power_on(&phy); |
| 670 | if (ret) |
| 671 | return ret; |
| 672 | } |
| 673 | |
Jonas Karlman | 4412a2b | 2023-07-30 22:59:55 +0000 | [diff] [blame] | 674 | device_find_first_child(dev, &child); |
| 675 | if (!child) |
| 676 | return 0; |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 677 | |
Kunihiko Hayashi | 7c71c68 | 2023-02-20 14:50:27 +0900 | [diff] [blame] | 678 | if (glue->clks.count == 0) { |
| 679 | ret = dwc3_glue_clk_init(child, glue); |
| 680 | if (ret) |
| 681 | return ret; |
| 682 | } |
| 683 | |
Frank Wang | 5d422ab | 2020-05-26 11:34:31 +0800 | [diff] [blame] | 684 | if (glue->resets.count == 0) { |
| 685 | ret = dwc3_glue_reset_init(child, glue); |
| 686 | if (ret) |
| 687 | return ret; |
| 688 | } |
| 689 | |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 690 | while (child) { |
| 691 | enum usb_dr_mode dr_mode; |
| 692 | |
Simon Glass | f10643c | 2020-12-19 10:40:14 -0700 | [diff] [blame] | 693 | dr_mode = usb_get_dr_mode(dev_ofnode(child)); |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 694 | device_find_next_child(&child); |
Marek Vasut | f1ef955 | 2022-04-13 00:42:55 +0200 | [diff] [blame] | 695 | if (ops && ops->glue_configure) |
| 696 | ops->glue_configure(dev, index, dr_mode); |
Jean-Jacques Hiblot | 93991cf | 2018-11-29 10:52:49 +0100 | [diff] [blame] | 697 | index++; |
| 698 | } |
| 699 | |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 700 | return 0; |
| 701 | } |
| 702 | |
Kunihiko Hayashi | ef2313b | 2023-02-20 14:50:28 +0900 | [diff] [blame] | 703 | int dwc3_glue_remove(struct udevice *dev) |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 704 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 705 | struct dwc3_glue_data *glue = dev_get_plat(dev); |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 706 | |
| 707 | reset_release_bulk(&glue->resets); |
| 708 | |
| 709 | clk_release_bulk(&glue->clks); |
| 710 | |
Jean-Jacques Hiblot | e445d46 | 2019-07-05 09:33:56 +0200 | [diff] [blame] | 711 | return 0; |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static const struct udevice_id dwc3_glue_ids[] = { |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 715 | { .compatible = "xlnx,zynqmp-dwc3" }, |
Siva Durga Prasad Paladugu | 648856a | 2020-05-12 08:36:01 +0200 | [diff] [blame] | 716 | { .compatible = "xlnx,versal-dwc3" }, |
Jean-Jacques Hiblot | 1c03ade | 2018-12-04 11:12:56 +0100 | [diff] [blame] | 717 | { .compatible = "ti,keystone-dwc3"}, |
Jean-Jacques Hiblot | d66e54a | 2018-11-29 10:57:40 +0100 | [diff] [blame] | 718 | { .compatible = "ti,dwc3", .data = (ulong)&ti_ops }, |
Jean-Jacques Hiblot | 1ce5f1f | 2018-12-04 11:30:50 +0100 | [diff] [blame] | 719 | { .compatible = "ti,am437x-dwc3", .data = (ulong)&ti_ops }, |
Vignesh Raghavendra | cab4e27 | 2019-12-09 10:37:29 +0530 | [diff] [blame] | 720 | { .compatible = "ti,am654-dwc3" }, |
Jagan Teki | 185571b | 2023-06-06 22:39:14 +0530 | [diff] [blame] | 721 | { .compatible = "rockchip,rk3328-dwc3", .data = (ulong)&rk_ops }, |
Frank Wang | 5d422ab | 2020-05-26 11:34:31 +0800 | [diff] [blame] | 722 | { .compatible = "rockchip,rk3399-dwc3" }, |
Jonas Karlman | caaeac8 | 2023-07-30 22:59:57 +0000 | [diff] [blame] | 723 | { .compatible = "rockchip,rk3568-dwc3", .data = (ulong)&rk_ops }, |
Caleb Connolly | 896e528 | 2023-09-12 22:00:12 +0100 | [diff] [blame] | 724 | { .compatible = "qcom,dwc3", .data = (ulong)&qcom_ops }, |
Marek Vasut | d0f7a05 | 2022-04-13 00:42:56 +0200 | [diff] [blame] | 725 | { .compatible = "fsl,imx8mp-dwc3", .data = (ulong)&imx8mp_ops }, |
Angus Ainslie | c08db05 | 2022-02-02 15:08:54 -0800 | [diff] [blame] | 726 | { .compatible = "fsl,imx8mq-dwc3" }, |
Andy Shevchenko | 23cdbba | 2020-12-03 19:45:01 +0200 | [diff] [blame] | 727 | { .compatible = "intel,tangier-dwc3" }, |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 728 | { } |
| 729 | }; |
| 730 | |
| 731 | U_BOOT_DRIVER(dwc3_generic_wrapper) = { |
| 732 | .name = "dwc3-generic-wrapper", |
Jean-Jacques Hiblot | 3b83829 | 2019-07-05 09:33:58 +0200 | [diff] [blame] | 733 | .id = UCLASS_NOP, |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 734 | .of_match = dwc3_glue_ids, |
| 735 | .bind = dwc3_glue_bind, |
| 736 | .probe = dwc3_glue_probe, |
| 737 | .remove = dwc3_glue_remove, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 738 | .plat_auto = sizeof(struct dwc3_glue_data), |
Jean-Jacques Hiblot | 446e3a2 | 2018-11-29 10:52:48 +0100 | [diff] [blame] | 739 | |
Michal Simek | 49d6745 | 2018-05-18 13:15:06 +0200 | [diff] [blame] | 740 | }; |