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