1 /* 2 * (C) Copyright 2013 3 * Texas Instruments Incorporated, <www.ti.com> 4 * 5 * Lokesh Vutla <lokeshvutla@ti.com> 6 * 7 * Based on previous work by: 8 * Aneesh V <aneesh@ti.com> 9 * Steve Sakoman <steve@sakoman.com> 10 * 11 * SPDX-License-Identifier: GPL-2.0+ 12 */ 13 #include <common.h> 14 #include <palmas.h> 15 #include <sata.h> 16 #include <asm/gpio.h> 17 #include <usb.h> 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> 28 29 #include "mux_data.h" 30 31 #ifdef CONFIG_DRIVER_TI_CPSW 32 #include <cpsw.h> 33 #endif 34 35 DECLARE_GLOBAL_DATA_PTR; 36 37 /* GPIO 7_11 */ 38 #define GPIO_DDR_VTT_EN 203 39 40 const struct omap_sysinfo sysinfo = { 41 "Board: DRA7xx\n" 42 }; 43 44 /** 45 * @brief board_init 46 * 47 * @return 0 48 */ 49 int board_init(void) 50 { 51 gpmc_init(); 52 gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */ 53 54 return 0; 55 } 56 57 int board_late_init(void) 58 { 59 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG 60 u32 id[4]; 61 62 if (omap_revision() == DRA722_ES1_0) 63 setenv("board_name", "dra72x"); 64 else 65 setenv("board_name", "dra7xx"); 66 67 id[0] = readl((*ctrl)->control_std_fuse_die_id_0); 68 id[1] = readl((*ctrl)->control_std_fuse_die_id_1); 69 usb_set_serial_num_from_die_id(id); 70 #endif 71 return 0; 72 } 73 74 void set_muxconf_regs_essential(void) 75 { 76 do_set_mux32((*ctrl)->control_padconf_core_base, 77 early_padconf, ARRAY_SIZE(early_padconf)); 78 } 79 80 #ifdef CONFIG_IODELAY_RECALIBRATION 81 void recalibrate_iodelay(void) 82 { 83 struct pad_conf_entry const *pads; 84 struct iodelay_cfg_entry const *iodelay; 85 int npads, niodelays; 86 87 switch (omap_revision()) { 88 case DRA722_ES1_0: 89 pads = core_padconf_array_essential; 90 npads = ARRAY_SIZE(core_padconf_array_essential); 91 iodelay = iodelay_cfg_array; 92 niodelays = ARRAY_SIZE(iodelay_cfg_array); 93 break; 94 case DRA752_ES1_0: 95 case DRA752_ES1_1: 96 pads = dra74x_core_padconf_array; 97 npads = ARRAY_SIZE(dra74x_core_padconf_array); 98 iodelay = dra742_es1_1_iodelay_cfg_array; 99 niodelays = ARRAY_SIZE(dra742_es1_1_iodelay_cfg_array); 100 break; 101 default: 102 case DRA752_ES2_0: 103 pads = dra74x_core_padconf_array; 104 npads = ARRAY_SIZE(dra74x_core_padconf_array); 105 iodelay = dra742_es2_0_iodelay_cfg_array; 106 niodelays = ARRAY_SIZE(dra742_es2_0_iodelay_cfg_array); 107 /* Setup port1 and port2 for rgmii with 'no-id' mode */ 108 clrset_spare_register(1, 0, RGMII2_ID_MODE_N_MASK | 109 RGMII1_ID_MODE_N_MASK); 110 break; 111 } 112 __recalibrate_iodelay(pads, npads, iodelay, niodelays); 113 } 114 #endif 115 116 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC) 117 int board_mmc_init(bd_t *bis) 118 { 119 omap_mmc_init(0, 0, 0, -1, -1); 120 omap_mmc_init(1, 0, 0, -1, -1); 121 return 0; 122 } 123 #endif 124 125 #ifdef CONFIG_USB_DWC3 126 static struct dwc3_device usb_otg_ss1 = { 127 .maximum_speed = USB_SPEED_SUPER, 128 .base = DRA7_USB_OTG_SS1_BASE, 129 .tx_fifo_resize = false, 130 .index = 0, 131 }; 132 133 static struct dwc3_omap_device usb_otg_ss1_glue = { 134 .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE, 135 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW, 136 .index = 0, 137 }; 138 139 static struct ti_usb_phy_device usb_phy1_device = { 140 .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL, 141 .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER, 142 .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER, 143 .index = 0, 144 }; 145 146 static struct dwc3_device usb_otg_ss2 = { 147 .maximum_speed = USB_SPEED_SUPER, 148 .base = DRA7_USB_OTG_SS2_BASE, 149 .tx_fifo_resize = false, 150 .index = 1, 151 }; 152 153 static struct dwc3_omap_device usb_otg_ss2_glue = { 154 .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE, 155 .utmi_mode = DWC3_OMAP_UTMI_MODE_SW, 156 .index = 1, 157 }; 158 159 static struct ti_usb_phy_device usb_phy2_device = { 160 .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER, 161 .index = 1, 162 }; 163 164 int board_usb_init(int index, enum usb_init_type init) 165 { 166 switch (index) { 167 case 0: 168 if (init == USB_INIT_DEVICE) { 169 usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL; 170 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID; 171 } else { 172 usb_otg_ss1.dr_mode = USB_DR_MODE_HOST; 173 usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND; 174 } 175 176 ti_usb_phy_uboot_init(&usb_phy1_device); 177 dwc3_omap_uboot_init(&usb_otg_ss1_glue); 178 dwc3_uboot_init(&usb_otg_ss1); 179 break; 180 case 1: 181 if (init == USB_INIT_DEVICE) { 182 usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL; 183 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID; 184 } else { 185 usb_otg_ss2.dr_mode = USB_DR_MODE_HOST; 186 usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND; 187 } 188 189 ti_usb_phy_uboot_init(&usb_phy2_device); 190 dwc3_omap_uboot_init(&usb_otg_ss2_glue); 191 dwc3_uboot_init(&usb_otg_ss2); 192 break; 193 default: 194 printf("Invalid Controller Index\n"); 195 } 196 197 return 0; 198 } 199 200 int board_usb_cleanup(int index, enum usb_init_type init) 201 { 202 switch (index) { 203 case 0: 204 case 1: 205 ti_usb_phy_uboot_exit(index); 206 dwc3_uboot_exit(index); 207 dwc3_omap_uboot_exit(index); 208 break; 209 default: 210 printf("Invalid Controller Index\n"); 211 } 212 return 0; 213 } 214 215 int usb_gadget_handle_interrupts(int index) 216 { 217 u32 status; 218 219 status = dwc3_omap_uboot_interrupt_status(index); 220 if (status) 221 dwc3_uboot_handle_interrupt(index); 222 223 return 0; 224 } 225 #endif 226 227 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT) 228 int spl_start_uboot(void) 229 { 230 /* break into full u-boot on 'c' */ 231 if (serial_tstc() && serial_getc() == 'c') 232 return 1; 233 234 #ifdef CONFIG_SPL_ENV_SUPPORT 235 env_init(); 236 env_relocate_spec(); 237 if (getenv_yesno("boot_os") != 1) 238 return 1; 239 #endif 240 241 return 0; 242 } 243 #endif 244 245 #ifdef CONFIG_DRIVER_TI_CPSW 246 extern u32 *const omap_si_rev; 247 248 static void cpsw_control(int enabled) 249 { 250 /* VTP can be added here */ 251 252 return; 253 } 254 255 static struct cpsw_slave_data cpsw_slaves[] = { 256 { 257 .slave_reg_ofs = 0x208, 258 .sliver_reg_ofs = 0xd80, 259 .phy_addr = 2, 260 }, 261 { 262 .slave_reg_ofs = 0x308, 263 .sliver_reg_ofs = 0xdc0, 264 .phy_addr = 3, 265 }, 266 }; 267 268 static struct cpsw_platform_data cpsw_data = { 269 .mdio_base = CPSW_MDIO_BASE, 270 .cpsw_base = CPSW_BASE, 271 .mdio_div = 0xff, 272 .channels = 8, 273 .cpdma_reg_ofs = 0x800, 274 .slaves = 2, 275 .slave_data = cpsw_slaves, 276 .ale_reg_ofs = 0xd00, 277 .ale_entries = 1024, 278 .host_port_reg_ofs = 0x108, 279 .hw_stats_reg_ofs = 0x900, 280 .bd_ram_ofs = 0x2000, 281 .mac_control = (1 << 5), 282 .control = cpsw_control, 283 .host_port_num = 0, 284 .version = CPSW_CTRL_VERSION_2, 285 }; 286 287 int board_eth_init(bd_t *bis) 288 { 289 int ret; 290 uint8_t mac_addr[6]; 291 uint32_t mac_hi, mac_lo; 292 uint32_t ctrl_val; 293 294 /* try reading mac address from efuse */ 295 mac_lo = readl((*ctrl)->control_core_mac_id_0_lo); 296 mac_hi = readl((*ctrl)->control_core_mac_id_0_hi); 297 mac_addr[0] = (mac_hi & 0xFF0000) >> 16; 298 mac_addr[1] = (mac_hi & 0xFF00) >> 8; 299 mac_addr[2] = mac_hi & 0xFF; 300 mac_addr[3] = (mac_lo & 0xFF0000) >> 16; 301 mac_addr[4] = (mac_lo & 0xFF00) >> 8; 302 mac_addr[5] = mac_lo & 0xFF; 303 304 if (!getenv("ethaddr")) { 305 printf("<ethaddr> not set. Validating first E-fuse MAC\n"); 306 307 if (is_valid_ethaddr(mac_addr)) 308 eth_setenv_enetaddr("ethaddr", mac_addr); 309 } 310 311 mac_lo = readl((*ctrl)->control_core_mac_id_1_lo); 312 mac_hi = readl((*ctrl)->control_core_mac_id_1_hi); 313 mac_addr[0] = (mac_hi & 0xFF0000) >> 16; 314 mac_addr[1] = (mac_hi & 0xFF00) >> 8; 315 mac_addr[2] = mac_hi & 0xFF; 316 mac_addr[3] = (mac_lo & 0xFF0000) >> 16; 317 mac_addr[4] = (mac_lo & 0xFF00) >> 8; 318 mac_addr[5] = mac_lo & 0xFF; 319 320 if (!getenv("eth1addr")) { 321 if (is_valid_ethaddr(mac_addr)) 322 eth_setenv_enetaddr("eth1addr", mac_addr); 323 } 324 325 ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33); 326 ctrl_val |= 0x22; 327 writel(ctrl_val, (*ctrl)->control_core_control_io1); 328 329 if (*omap_si_rev == DRA722_ES1_0) 330 cpsw_data.active_slave = 1; 331 332 ret = cpsw_register(&cpsw_data); 333 if (ret < 0) 334 printf("Error %d registering CPSW switch\n", ret); 335 336 return ret; 337 } 338 #endif 339 340 #ifdef CONFIG_BOARD_EARLY_INIT_F 341 /* VTT regulator enable */ 342 static inline void vtt_regulator_enable(void) 343 { 344 if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL) 345 return; 346 347 /* Do not enable VTT for DRA722 */ 348 if (omap_revision() == DRA722_ES1_0) 349 return; 350 351 /* 352 * EVM Rev G and later use gpio7_11 for DDR3 termination. 353 * This is safe enough to do on older revs. 354 */ 355 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en"); 356 gpio_direction_output(GPIO_DDR_VTT_EN, 1); 357 } 358 359 int board_early_init_f(void) 360 { 361 vtt_regulator_enable(); 362 return 0; 363 } 364 #endif 365