1 // SPDX-License-Identifier: GPL-2.0+
3 * MISC driver for TI MUSB Glue.
6 * Texas Instruments Incorporated, <www.ti.com>
12 #include <linux/usb/otg.h>
13 #include <dm/device-internal.h>
17 #include <asm/omap_musb.h>
18 #include "musb_uboot.h"
20 DECLARE_GLOBAL_DATA_PTR;
24 /* USB 2.0 PHY Control */
25 #define CM_PHY_PWRDN (1 << 0)
26 #define CM_PHY_OTG_PWRDN (1 << 1)
27 #define OTGVDET_EN (1 << 19)
28 #define OTGSESSENDEN (1 << 20)
30 #define AM335X_USB1_CTRL 0x8
32 struct ti_musb_platdata {
35 struct musb_hdrc_platform_data plat;
36 struct musb_hdrc_config musb_config;
37 struct omap_musb_board_data otg_board_data;
40 static int ti_musb_get_usb_index(int node)
42 const void *fdt = gd->fdt_blob;
45 const char *alias_path;
48 fdt_get_path(fdt, node, path, sizeof(path));
51 snprintf(alias, sizeof(alias), "usb%d", i);
52 alias_path = fdt_get_alias(fdt, alias);
53 if (alias_path == NULL) {
54 debug("USB index not found\n");
58 if (!strcmp(path, alias_path))
67 static void ti_musb_set_phy_power(struct udevice *dev, u8 on)
69 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
72 clrsetbits_le32(platdata->ctrl_mod_base,
73 CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
74 OTGVDET_EN | OTGSESSENDEN);
76 clrsetbits_le32(platdata->ctrl_mod_base, 0,
77 CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
81 static int ti_musb_ofdata_to_platdata(struct udevice *dev)
83 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
84 const void *fdt = gd->fdt_blob;
85 int node = dev_of_offset(dev);
90 platdata->base = (void *)devfdt_get_addr_index(dev, 1);
92 phys = fdtdec_lookup_phandle(fdt, node, "phys");
93 ctrl_mod = fdtdec_lookup_phandle(fdt, phys, "ti,ctrl_mod");
94 platdata->ctrl_mod_base = (void *)fdtdec_get_addr(fdt, ctrl_mod, "reg");
95 usb_index = ti_musb_get_usb_index(node);
98 platdata->ctrl_mod_base += AM335X_USB1_CTRL;
104 platdata->musb_config.multipoint = fdtdec_get_int(fdt, node,
107 if (platdata->musb_config.multipoint < 0) {
108 pr_err("MUSB multipoint DT entry missing\n");
112 platdata->musb_config.dyn_fifo = 1;
114 platdata->musb_config.num_eps = fdtdec_get_int(fdt, node,
115 "mentor,num-eps", -1);
116 if (platdata->musb_config.num_eps < 0) {
117 pr_err("MUSB num-eps DT entry missing\n");
121 platdata->musb_config.ram_bits = fdtdec_get_int(fdt, node,
122 "mentor,ram-bits", -1);
123 if (platdata->musb_config.ram_bits < 0) {
124 pr_err("MUSB ram-bits DT entry missing\n");
128 platdata->otg_board_data.set_phy_power = ti_musb_set_phy_power;
129 platdata->otg_board_data.dev = dev;
130 platdata->plat.config = &platdata->musb_config;
132 platdata->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1);
133 if (platdata->plat.power < 0) {
134 pr_err("MUSB mentor,power DT entry missing\n");
138 platdata->plat.platform_ops = &musb_dsps_ops;
139 platdata->plat.board_data = &platdata->otg_board_data;
144 static int ti_musb_host_probe(struct udevice *dev)
146 struct musb_host_data *host = dev_get_priv(dev);
147 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
148 struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
149 struct omap_musb_board_data *otg_board_data;
152 priv->desc_before_addr = true;
154 otg_board_data = &platdata->otg_board_data;
156 host->host = musb_init_controller(&platdata->plat,
157 (struct device *)otg_board_data,
162 ret = musb_lowlevel_init(host);
167 static int ti_musb_host_remove(struct udevice *dev)
169 struct musb_host_data *host = dev_get_priv(dev);
171 musb_stop(host->host);
176 static int ti_musb_host_ofdata_to_platdata(struct udevice *dev)
178 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
179 const void *fdt = gd->fdt_blob;
180 int node = dev_of_offset(dev);
183 ret = ti_musb_ofdata_to_platdata(dev);
185 pr_err("platdata dt parse error\n");
189 platdata->plat.mode = MUSB_HOST;
194 U_BOOT_DRIVER(ti_musb_host) = {
195 .name = "ti-musb-host",
197 .ofdata_to_platdata = ti_musb_host_ofdata_to_platdata,
198 .probe = ti_musb_host_probe,
199 .remove = ti_musb_host_remove,
200 .ops = &musb_usb_ops,
201 .platdata_auto_alloc_size = sizeof(struct ti_musb_platdata),
202 .priv_auto_alloc_size = sizeof(struct musb_host_data),
205 static int ti_musb_wrapper_bind(struct udevice *parent)
207 const void *fdt = gd->fdt_blob;
211 for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
212 node = fdt_next_subnode(fdt, node)) {
214 const char *name = fdt_get_name(fdt, node, NULL);
215 enum usb_dr_mode dr_mode;
218 if (strncmp(name, "usb@", 4))
221 dr_mode = usb_get_dr_mode(node);
223 case USB_DR_MODE_PERIPHERAL:
224 /* Bind MUSB device */
226 case USB_DR_MODE_HOST:
228 ret = device_bind_driver_to_node(parent, "ti-musb-host",
229 name, offset_to_ofnode(node), &dev);
231 pr_err("musb - not able to bind usb host node\n");
242 static const struct udevice_id ti_musb_ids[] = {
243 { .compatible = "ti,am33xx-usb" },
247 U_BOOT_DRIVER(ti_musb_wrapper) = {
248 .name = "ti-musb-wrapper",
250 .of_match = ti_musb_ids,
251 .bind = ti_musb_wrapper_bind,
254 #endif /* CONFIG_DM_USB */