3 * Texas Instruments Incorporated, <www.ti.com>
5 * Lokesh Vutla <lokeshvutla@ti.com>
7 * Based on previous work by:
8 * Aneesh V <aneesh@ti.com>
9 * Steve Sakoman <steve@sakoman.com>
11 * SPDX-License-Identifier: GPL-2.0+
18 #include <linux/usb/gadget.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/dra7xx_iodelay.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/arch/sata.h>
24 #include <environment.h>
25 #include <dwc3-uboot.h>
26 #include <dwc3-omap-uboot.h>
27 #include <ti-usb-phy-uboot.h>
31 #ifdef CONFIG_DRIVER_TI_CPSW
35 DECLARE_GLOBAL_DATA_PTR;
38 #define GPIO_DDR_VTT_EN 203
40 const struct omap_sysinfo sysinfo = {
52 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
57 int board_late_init(void)
59 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
60 if (omap_revision() == DRA722_ES1_0)
61 setenv("board_name", "dra72x");
63 setenv("board_name", "dra7xx");
70 void set_muxconf_regs_essential(void)
72 do_set_mux32((*ctrl)->control_padconf_core_base,
73 early_padconf, ARRAY_SIZE(early_padconf));
76 #ifdef CONFIG_IODELAY_RECALIBRATION
77 void recalibrate_iodelay(void)
79 struct pad_conf_entry const *pads;
80 struct iodelay_cfg_entry const *iodelay;
83 switch (omap_revision()) {
85 pads = core_padconf_array_essential;
86 npads = ARRAY_SIZE(core_padconf_array_essential);
87 iodelay = iodelay_cfg_array;
88 niodelays = ARRAY_SIZE(iodelay_cfg_array);
92 pads = dra74x_core_padconf_array;
93 npads = ARRAY_SIZE(dra74x_core_padconf_array);
94 iodelay = dra742_es1_1_iodelay_cfg_array;
95 niodelays = ARRAY_SIZE(dra742_es1_1_iodelay_cfg_array);
99 pads = dra74x_core_padconf_array;
100 npads = ARRAY_SIZE(dra74x_core_padconf_array);
101 iodelay = dra742_es2_0_iodelay_cfg_array;
102 niodelays = ARRAY_SIZE(dra742_es2_0_iodelay_cfg_array);
103 /* Setup port1 and port2 for rgmii with 'no-id' mode */
104 clrset_spare_register(1, 0, RGMII2_ID_MODE_N_MASK |
105 RGMII1_ID_MODE_N_MASK);
108 __recalibrate_iodelay(pads, npads, iodelay, niodelays);
112 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
113 int board_mmc_init(bd_t *bis)
115 omap_mmc_init(0, 0, 0, -1, -1);
116 omap_mmc_init(1, 0, 0, -1, -1);
121 #ifdef CONFIG_USB_DWC3
122 static struct dwc3_device usb_otg_ss1 = {
123 .maximum_speed = USB_SPEED_SUPER,
124 .base = DRA7_USB_OTG_SS1_BASE,
125 .tx_fifo_resize = false,
129 static struct dwc3_omap_device usb_otg_ss1_glue = {
130 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
131 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
135 static struct ti_usb_phy_device usb_phy1_device = {
136 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
137 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
138 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
142 static struct dwc3_device usb_otg_ss2 = {
143 .maximum_speed = USB_SPEED_SUPER,
144 .base = DRA7_USB_OTG_SS2_BASE,
145 .tx_fifo_resize = false,
149 static struct dwc3_omap_device usb_otg_ss2_glue = {
150 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
151 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
155 static struct ti_usb_phy_device usb_phy2_device = {
156 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
160 int board_usb_init(int index, enum usb_init_type init)
162 enable_usb_clocks(index);
165 if (init == USB_INIT_DEVICE) {
166 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
167 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
169 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
170 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
173 ti_usb_phy_uboot_init(&usb_phy1_device);
174 dwc3_omap_uboot_init(&usb_otg_ss1_glue);
175 dwc3_uboot_init(&usb_otg_ss1);
178 if (init == USB_INIT_DEVICE) {
179 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
180 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
182 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
183 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
186 ti_usb_phy_uboot_init(&usb_phy2_device);
187 dwc3_omap_uboot_init(&usb_otg_ss2_glue);
188 dwc3_uboot_init(&usb_otg_ss2);
191 printf("Invalid Controller Index\n");
197 int board_usb_cleanup(int index, enum usb_init_type init)
202 ti_usb_phy_uboot_exit(index);
203 dwc3_uboot_exit(index);
204 dwc3_omap_uboot_exit(index);
207 printf("Invalid Controller Index\n");
209 disable_usb_clocks(index);
213 int usb_gadget_handle_interrupts(int index)
217 status = dwc3_omap_uboot_interrupt_status(index);
219 dwc3_uboot_handle_interrupt(index);
225 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
226 int spl_start_uboot(void)
228 /* break into full u-boot on 'c' */
229 if (serial_tstc() && serial_getc() == 'c')
232 #ifdef CONFIG_SPL_ENV_SUPPORT
235 if (getenv_yesno("boot_os") != 1)
243 #ifdef CONFIG_DRIVER_TI_CPSW
244 extern u32 *const omap_si_rev;
246 static void cpsw_control(int enabled)
248 /* VTP can be added here */
253 static struct cpsw_slave_data cpsw_slaves[] = {
255 .slave_reg_ofs = 0x208,
256 .sliver_reg_ofs = 0xd80,
260 .slave_reg_ofs = 0x308,
261 .sliver_reg_ofs = 0xdc0,
266 static struct cpsw_platform_data cpsw_data = {
267 .mdio_base = CPSW_MDIO_BASE,
268 .cpsw_base = CPSW_BASE,
271 .cpdma_reg_ofs = 0x800,
273 .slave_data = cpsw_slaves,
274 .ale_reg_ofs = 0xd00,
276 .host_port_reg_ofs = 0x108,
277 .hw_stats_reg_ofs = 0x900,
278 .bd_ram_ofs = 0x2000,
279 .mac_control = (1 << 5),
280 .control = cpsw_control,
282 .version = CPSW_CTRL_VERSION_2,
285 int board_eth_init(bd_t *bis)
289 uint32_t mac_hi, mac_lo;
292 /* try reading mac address from efuse */
293 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
294 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
295 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
296 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
297 mac_addr[2] = mac_hi & 0xFF;
298 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
299 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
300 mac_addr[5] = mac_lo & 0xFF;
302 if (!getenv("ethaddr")) {
303 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
305 if (is_valid_ethaddr(mac_addr))
306 eth_setenv_enetaddr("ethaddr", mac_addr);
309 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo);
310 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi);
311 mac_addr[0] = (mac_hi & 0xFF0000) >> 16;
312 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
313 mac_addr[2] = mac_hi & 0xFF;
314 mac_addr[3] = (mac_lo & 0xFF0000) >> 16;
315 mac_addr[4] = (mac_lo & 0xFF00) >> 8;
316 mac_addr[5] = mac_lo & 0xFF;
318 if (!getenv("eth1addr")) {
319 if (is_valid_ethaddr(mac_addr))
320 eth_setenv_enetaddr("eth1addr", mac_addr);
323 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
325 writel(ctrl_val, (*ctrl)->control_core_control_io1);
327 if (*omap_si_rev == DRA722_ES1_0)
328 cpsw_data.active_slave = 1;
330 ret = cpsw_register(&cpsw_data);
332 printf("Error %d registering CPSW switch\n", ret);
338 #ifdef CONFIG_BOARD_EARLY_INIT_F
339 /* VTT regulator enable */
340 static inline void vtt_regulator_enable(void)
342 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
345 /* Do not enable VTT for DRA722 */
346 if (omap_revision() == DRA722_ES1_0)
350 * EVM Rev G and later use gpio7_11 for DDR3 termination.
351 * This is safe enough to do on older revs.
353 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
354 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
357 int board_early_init_f(void)
359 vtt_regulator_enable();