Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 2 | /* |
| 3 | * MISC driver for TI MUSB Glue. |
| 4 | * |
| 5 | * (C) Copyright 2016 |
| 6 | * Texas Instruments Incorporated, <www.ti.com> |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 7 | */ |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 8 | #include <command.h> |
| 9 | #include <console.h> |
| 10 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 14 | #include <linux/printk.h> |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 15 | #include <linux/usb/otg.h> |
| 16 | #include <dm/device-internal.h> |
| 17 | #include <dm/lists.h> |
| 18 | |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 19 | #include <asm/io.h> |
| 20 | #include <asm/omap_musb.h> |
| 21 | #include "musb_uboot.h" |
| 22 | |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 25 | #if CONFIG_IS_ENABLED(DM_USB) |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 26 | /* USB 2.0 PHY Control */ |
| 27 | #define CM_PHY_PWRDN (1 << 0) |
| 28 | #define CM_PHY_OTG_PWRDN (1 << 1) |
| 29 | #define OTGVDET_EN (1 << 19) |
| 30 | #define OTGSESSENDEN (1 << 20) |
| 31 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 32 | #define AM335X_USB0_CTRL 0x0 |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 33 | #define AM335X_USB1_CTRL 0x8 |
| 34 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 35 | static void ti_musb_set_phy_power(struct udevice *dev, u8 on) |
| 36 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 37 | struct ti_musb_plat *plat = dev_get_plat(dev); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 38 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 39 | if (!plat->ctrl_mod_base) |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 40 | return; |
| 41 | |
| 42 | if (on) { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 43 | clrsetbits_le32(plat->ctrl_mod_base, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 44 | CM_PHY_PWRDN | CM_PHY_OTG_PWRDN, |
| 45 | OTGVDET_EN | OTGSESSENDEN); |
| 46 | } else { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 47 | clrsetbits_le32(plat->ctrl_mod_base, 0, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 48 | CM_PHY_PWRDN | CM_PHY_OTG_PWRDN); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 53 | |
| 54 | static int ti_musb_get_usb_index(int node) |
| 55 | { |
| 56 | const void *fdt = gd->fdt_blob; |
| 57 | int i = 0; |
| 58 | char path[64]; |
| 59 | const char *alias_path; |
| 60 | char alias[16]; |
| 61 | |
| 62 | fdt_get_path(fdt, node, path, sizeof(path)); |
| 63 | |
| 64 | do { |
| 65 | snprintf(alias, sizeof(alias), "usb%d", i); |
| 66 | alias_path = fdt_get_alias(fdt, alias); |
| 67 | if (alias_path == NULL) { |
| 68 | debug("USB index not found\n"); |
| 69 | return -ENOENT; |
| 70 | } |
| 71 | |
| 72 | if (!strcmp(path, alias_path)) |
| 73 | return i; |
| 74 | |
| 75 | i++; |
| 76 | } while (alias_path); |
| 77 | |
| 78 | return -ENOENT; |
| 79 | } |
| 80 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 81 | static int ti_musb_of_to_plat(struct udevice *dev) |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 82 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 83 | struct ti_musb_plat *plat = dev_get_plat(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 84 | const void *fdt = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 85 | int node = dev_of_offset(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 86 | int phys; |
| 87 | int ctrl_mod; |
| 88 | int usb_index; |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 89 | struct musb_hdrc_config *musb_config; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 90 | |
Johan Jonker | b52189e | 2023-03-13 01:32:31 +0100 | [diff] [blame] | 91 | plat->base = devfdt_get_addr_index_ptr(dev, 1); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 92 | |
| 93 | phys = fdtdec_lookup_phandle(fdt, node, "phys"); |
| 94 | ctrl_mod = fdtdec_lookup_phandle(fdt, phys, "ti,ctrl_mod"); |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 95 | plat->ctrl_mod_base = (void *)fdtdec_get_addr(fdt, ctrl_mod, "reg"); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 96 | usb_index = ti_musb_get_usb_index(node); |
| 97 | switch (usb_index) { |
| 98 | case 1: |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 99 | plat->ctrl_mod_base += AM335X_USB1_CTRL; |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 100 | break; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 101 | case 0: |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 102 | plat->ctrl_mod_base += AM335X_USB0_CTRL; |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 103 | break; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 104 | default: |
| 105 | break; |
| 106 | } |
| 107 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 108 | musb_config = malloc(sizeof(struct musb_hdrc_config)); |
| 109 | memset(musb_config, 0, sizeof(struct musb_hdrc_config)); |
| 110 | |
| 111 | musb_config->multipoint = fdtdec_get_int(fdt, node, |
| 112 | "mentor,multipoint", -1); |
| 113 | if (musb_config->multipoint < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 114 | pr_err("MUSB multipoint DT entry missing\n"); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 115 | return -ENOENT; |
| 116 | } |
| 117 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 118 | musb_config->dyn_fifo = 1; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 119 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 120 | musb_config->num_eps = fdtdec_get_int(fdt, node, "mentor,num-eps", |
| 121 | -1); |
| 122 | if (musb_config->num_eps < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 123 | pr_err("MUSB num-eps DT entry missing\n"); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 124 | return -ENOENT; |
| 125 | } |
| 126 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 127 | musb_config->ram_bits = fdtdec_get_int(fdt, node, "mentor,ram-bits", |
| 128 | -1); |
| 129 | if (musb_config->ram_bits < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 130 | pr_err("MUSB ram-bits DT entry missing\n"); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 131 | return -ENOENT; |
| 132 | } |
| 133 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 134 | plat->plat.config = musb_config; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 135 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 136 | plat->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1); |
| 137 | if (plat->plat.power < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 138 | pr_err("MUSB mentor,power DT entry missing\n"); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 139 | return -ENOENT; |
| 140 | } |
| 141 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 142 | plat->plat.platform_ops = &musb_dsps_ops; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 146 | #endif |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 147 | |
| 148 | static int ti_musb_host_probe(struct udevice *dev) |
| 149 | { |
| 150 | struct musb_host_data *host = dev_get_priv(dev); |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 151 | struct ti_musb_plat *plat = dev_get_plat(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 152 | struct usb_bus_priv *priv = dev_get_uclass_priv(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 153 | int ret; |
| 154 | |
| 155 | priv->desc_before_addr = true; |
| 156 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 157 | host->host = musb_init_controller(&plat->plat, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 158 | NULL, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 159 | plat->base); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 160 | if (!host->host) |
| 161 | return -EIO; |
| 162 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 163 | ti_musb_set_phy_power(dev, 1); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 164 | ret = musb_lowlevel_init(host); |
| 165 | |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | static int ti_musb_host_remove(struct udevice *dev) |
| 170 | { |
| 171 | struct musb_host_data *host = dev_get_priv(dev); |
| 172 | |
| 173 | musb_stop(host->host); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 174 | ti_musb_set_phy_power(dev, 0); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 179 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 180 | static int ti_musb_host_of_to_plat(struct udevice *dev) |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 181 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 182 | struct ti_musb_plat *plat = dev_get_plat(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 183 | const void *fdt = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 184 | int node = dev_of_offset(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 185 | int ret; |
| 186 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 187 | ret = ti_musb_of_to_plat(dev); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 188 | if (ret) { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 189 | pr_err("plat dt parse error\n"); |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 190 | return ret; |
| 191 | } |
| 192 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 193 | plat->plat.mode = MUSB_HOST; |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 194 | |
| 195 | return 0; |
| 196 | } |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 197 | #endif |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 198 | |
| 199 | U_BOOT_DRIVER(ti_musb_host) = { |
| 200 | .name = "ti-musb-host", |
| 201 | .id = UCLASS_USB, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 202 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 203 | .of_to_plat = ti_musb_host_of_to_plat, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 204 | #endif |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 205 | .probe = ti_musb_host_probe, |
| 206 | .remove = ti_musb_host_remove, |
| 207 | .ops = &musb_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 208 | .plat_auto = sizeof(struct ti_musb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 209 | .priv_auto = sizeof(struct musb_host_data), |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 210 | }; |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 211 | |
| 212 | #if CONFIG_IS_ENABLED(DM_USB_GADGET) |
| 213 | struct ti_musb_peripheral { |
| 214 | struct musb *periph; |
| 215 | }; |
| 216 | |
| 217 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 218 | static int ti_musb_peripheral_of_to_plat(struct udevice *dev) |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 219 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 220 | struct ti_musb_plat *plat = dev_get_plat(dev); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 221 | const void *fdt = gd->fdt_blob; |
| 222 | int node = dev_of_offset(dev); |
| 223 | int ret; |
| 224 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 225 | ret = ti_musb_of_to_plat(dev); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 226 | if (ret) { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 227 | pr_err("plat dt parse error\n"); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 228 | return ret; |
| 229 | } |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 230 | plat->plat.mode = MUSB_PERIPHERAL; |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | #endif |
| 235 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 236 | static int ti_musb_peripheral_probe(struct udevice *dev) |
| 237 | { |
| 238 | struct ti_musb_peripheral *priv = dev_get_priv(dev); |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 239 | struct ti_musb_plat *plat = dev_get_plat(dev); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 240 | int ret; |
| 241 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 242 | priv->periph = musb_init_controller(&plat->plat, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 243 | NULL, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 244 | plat->base); |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 245 | if (!priv->periph) |
| 246 | return -EIO; |
| 247 | |
| 248 | ti_musb_set_phy_power(dev, 1); |
| 249 | musb_gadget_setup(priv->periph); |
| 250 | return usb_add_gadget_udc((struct device *)dev, &priv->periph->g); |
| 251 | } |
| 252 | |
| 253 | static int ti_musb_peripheral_remove(struct udevice *dev) |
| 254 | { |
| 255 | struct ti_musb_peripheral *priv = dev_get_priv(dev); |
| 256 | |
| 257 | usb_del_gadget_udc(&priv->periph->g); |
| 258 | ti_musb_set_phy_power(dev, 0); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Marek Vasut | 3dcae15 | 2024-06-14 02:51:23 +0200 | [diff] [blame] | 263 | static int ti_musb_gadget_handle_interrupts(struct udevice *dev) |
| 264 | { |
| 265 | struct ti_musb_peripheral *priv = dev_get_priv(dev); |
| 266 | |
| 267 | priv->periph->isr(0, priv->periph); |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | static const struct usb_gadget_generic_ops ti_musb_gadget_ops = { |
| 273 | .handle_interrupts = ti_musb_gadget_handle_interrupts, |
| 274 | }; |
| 275 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 276 | U_BOOT_DRIVER(ti_musb_peripheral) = { |
| 277 | .name = "ti-musb-peripheral", |
| 278 | .id = UCLASS_USB_GADGET_GENERIC, |
| 279 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 280 | .of_to_plat = ti_musb_peripheral_of_to_plat, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 281 | #endif |
Marek Vasut | 3dcae15 | 2024-06-14 02:51:23 +0200 | [diff] [blame] | 282 | .ops = &ti_musb_gadget_ops, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 283 | .probe = ti_musb_peripheral_probe, |
| 284 | .remove = ti_musb_peripheral_remove, |
| 285 | .ops = &musb_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 286 | .plat_auto = sizeof(struct ti_musb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 287 | .priv_auto = sizeof(struct ti_musb_peripheral), |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 288 | .flags = DM_FLAG_PRE_RELOC, |
| 289 | }; |
| 290 | #endif |
Mugunthan V N | 2d6f8c0 | 2016-11-17 14:38:11 +0530 | [diff] [blame] | 291 | |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 292 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 293 | static int ti_musb_wrapper_bind(struct udevice *parent) |
| 294 | { |
Kever Yang | 1b80705 | 2020-03-04 08:59:50 +0800 | [diff] [blame] | 295 | ofnode node; |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 296 | int ret; |
| 297 | |
Simon Glass | a7ece58 | 2020-12-19 10:40:14 -0700 | [diff] [blame] | 298 | ofnode_for_each_subnode(node, dev_ofnode(parent)) { |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 299 | struct udevice *dev; |
Kever Yang | 1b80705 | 2020-03-04 08:59:50 +0800 | [diff] [blame] | 300 | const char *name = ofnode_get_name(node); |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 301 | enum usb_dr_mode dr_mode; |
| 302 | struct driver *drv; |
| 303 | |
| 304 | if (strncmp(name, "usb@", 4)) |
| 305 | continue; |
| 306 | |
| 307 | dr_mode = usb_get_dr_mode(node); |
| 308 | switch (dr_mode) { |
| 309 | case USB_DR_MODE_PERIPHERAL: |
| 310 | /* Bind MUSB device */ |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 311 | ret = device_bind_driver_to_node(parent, |
| 312 | "ti-musb-peripheral", |
| 313 | name, |
Kever Yang | 1b80705 | 2020-03-04 08:59:50 +0800 | [diff] [blame] | 314 | node, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 315 | &dev); |
| 316 | if (ret) |
| 317 | pr_err("musb - not able to bind usb peripheral node\n"); |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 318 | break; |
| 319 | case USB_DR_MODE_HOST: |
| 320 | /* Bind MUSB host */ |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 321 | ret = device_bind_driver_to_node(parent, |
| 322 | "ti-musb-host", |
| 323 | name, |
Kever Yang | 1b80705 | 2020-03-04 08:59:50 +0800 | [diff] [blame] | 324 | node, |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 325 | &dev); |
| 326 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 327 | pr_err("musb - not able to bind usb host node\n"); |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 328 | break; |
| 329 | default: |
| 330 | break; |
| 331 | }; |
| 332 | } |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | static const struct udevice_id ti_musb_ids[] = { |
| 337 | { .compatible = "ti,am33xx-usb" }, |
| 338 | { } |
| 339 | }; |
| 340 | |
| 341 | U_BOOT_DRIVER(ti_musb_wrapper) = { |
| 342 | .name = "ti-musb-wrapper", |
| 343 | .id = UCLASS_MISC, |
| 344 | .of_match = ti_musb_ids, |
| 345 | .bind = ti_musb_wrapper_bind, |
| 346 | }; |
Jean-Jacques Hiblot | 57118f6 | 2018-12-04 11:30:57 +0100 | [diff] [blame] | 347 | #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */ |
Mugunthan V N | 5b5479c | 2016-11-17 14:38:08 +0530 | [diff] [blame] | 348 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 349 | #endif /* CONFIG_IS_ENABLED(DM_USB) */ |