2 * MISC driver for TI MUSB Glue.
5 * Texas Instruments Incorporated, <www.ti.com>
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <linux/usb/otg.h>
14 #include <dm/device-internal.h>
18 #include <asm/omap_musb.h>
19 #include "musb_uboot.h"
21 DECLARE_GLOBAL_DATA_PTR;
25 /* USB 2.0 PHY Control */
26 #define CM_PHY_PWRDN (1 << 0)
27 #define CM_PHY_OTG_PWRDN (1 << 1)
28 #define OTGVDET_EN (1 << 19)
29 #define OTGSESSENDEN (1 << 20)
31 #define AM335X_USB1_CTRL 0x8
33 struct ti_musb_platdata {
36 struct musb_hdrc_platform_data plat;
37 struct musb_hdrc_config musb_config;
38 struct omap_musb_board_data otg_board_data;
41 static int ti_musb_get_usb_index(int node)
43 const void *fdt = gd->fdt_blob;
46 const char *alias_path;
49 fdt_get_path(fdt, node, path, sizeof(path));
52 snprintf(alias, sizeof(alias), "usb%d", i);
53 alias_path = fdt_get_alias(fdt, alias);
54 if (alias_path == NULL) {
55 debug("USB index not found\n");
59 if (!strcmp(path, alias_path))
68 static void ti_musb_set_phy_power(struct udevice *dev, u8 on)
70 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
73 clrsetbits_le32(platdata->ctrl_mod_base,
74 CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
75 OTGVDET_EN | OTGSESSENDEN);
77 clrsetbits_le32(platdata->ctrl_mod_base, 0,
78 CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
82 static int ti_musb_ofdata_to_platdata(struct udevice *dev)
84 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
85 const void *fdt = gd->fdt_blob;
86 int node = dev_of_offset(dev);
91 platdata->base = (void *)dev_get_addr_index(dev, 1);
93 phys = fdtdec_lookup_phandle(fdt, node, "phys");
94 ctrl_mod = fdtdec_lookup_phandle(fdt, phys, "ti,ctrl_mod");
95 platdata->ctrl_mod_base = (void *)fdtdec_get_addr(fdt, ctrl_mod, "reg");
96 usb_index = ti_musb_get_usb_index(node);
99 platdata->ctrl_mod_base += AM335X_USB1_CTRL;
105 platdata->musb_config.multipoint = fdtdec_get_int(fdt, node,
108 if (platdata->musb_config.multipoint < 0) {
109 error("MUSB multipoint DT entry missing\n");
113 platdata->musb_config.dyn_fifo = 1;
115 platdata->musb_config.num_eps = fdtdec_get_int(fdt, node,
116 "mentor,num-eps", -1);
117 if (platdata->musb_config.num_eps < 0) {
118 error("MUSB num-eps DT entry missing\n");
122 platdata->musb_config.ram_bits = fdtdec_get_int(fdt, node,
123 "mentor,ram-bits", -1);
124 if (platdata->musb_config.ram_bits < 0) {
125 error("MUSB ram-bits DT entry missing\n");
129 platdata->otg_board_data.set_phy_power = ti_musb_set_phy_power;
130 platdata->otg_board_data.dev = dev;
131 platdata->plat.config = &platdata->musb_config;
133 platdata->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1);
134 if (platdata->plat.power < 0) {
135 error("MUSB mentor,power DT entry missing\n");
139 platdata->plat.platform_ops = &musb_dsps_ops;
140 platdata->plat.board_data = &platdata->otg_board_data;
145 static int ti_musb_host_probe(struct udevice *dev)
147 struct musb_host_data *host = dev_get_priv(dev);
148 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
149 struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
150 struct omap_musb_board_data *otg_board_data;
153 priv->desc_before_addr = true;
155 otg_board_data = &platdata->otg_board_data;
157 host->host = musb_init_controller(&platdata->plat,
158 (struct device *)otg_board_data,
163 ret = musb_lowlevel_init(host);
168 static int ti_musb_host_remove(struct udevice *dev)
170 struct musb_host_data *host = dev_get_priv(dev);
172 musb_stop(host->host);
177 static int ti_musb_host_ofdata_to_platdata(struct udevice *dev)
179 struct ti_musb_platdata *platdata = dev_get_platdata(dev);
180 const void *fdt = gd->fdt_blob;
181 int node = dev_of_offset(dev);
184 ret = ti_musb_ofdata_to_platdata(dev);
186 error("platdata dt parse error\n");
190 platdata->plat.mode = MUSB_HOST;
195 U_BOOT_DRIVER(ti_musb_host) = {
196 .name = "ti-musb-host",
198 .ofdata_to_platdata = ti_musb_host_ofdata_to_platdata,
199 .probe = ti_musb_host_probe,
200 .remove = ti_musb_host_remove,
201 .ops = &musb_usb_ops,
202 .platdata_auto_alloc_size = sizeof(struct ti_musb_platdata),
203 .priv_auto_alloc_size = sizeof(struct musb_host_data),
206 static int ti_musb_wrapper_bind(struct udevice *parent)
208 const void *fdt = gd->fdt_blob;
212 for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
213 node = fdt_next_subnode(fdt, node)) {
215 const char *name = fdt_get_name(fdt, node, NULL);
216 enum usb_dr_mode dr_mode;
219 if (strncmp(name, "usb@", 4))
222 dr_mode = usb_get_dr_mode(node);
224 case USB_DR_MODE_PERIPHERAL:
225 /* Bind MUSB device */
227 case USB_DR_MODE_HOST:
229 ret = device_bind_driver_to_node(parent, "ti-musb-host",
232 error("musb - not able to bind usb host node\n");
243 static const struct udevice_id ti_musb_ids[] = {
244 { .compatible = "ti,am33xx-usb" },
248 U_BOOT_DRIVER(ti_musb_wrapper) = {
249 .name = "ti-musb-wrapper",
251 .of_match = ti_musb_ids,
252 .bind = ti_musb_wrapper_bind,
255 #endif /* CONFIG_DM_USB */