1 /* 2 * Maintainer : Steve Sakoman <steve@sakoman.com> 3 * 4 * Derived from Beagle Board, 3430 SDP, and OMAP3EVM code by 5 * Richard Woodruff <r-woodruff2@ti.com> 6 * Syed Mohammed Khasim <khasim@ti.com> 7 * Sunil Kumar <sunilsaini05@gmail.com> 8 * Shashi Ranjan <shashiranjanmca05@gmail.com> 9 * 10 * (C) Copyright 2004-2008 11 * Texas Instruments, <www.ti.com> 12 * 13 * SPDX-License-Identifier: GPL-2.0+ 14 */ 15 #include <common.h> 16 #include <dm.h> 17 #include <ns16550.h> 18 #include <netdev.h> 19 #include <twl4030.h> 20 #include <linux/mtd/rawnand.h> 21 #include <asm/io.h> 22 #include <asm/arch/mmc_host_def.h> 23 #include <asm/arch/mux.h> 24 #include <asm/arch/mem.h> 25 #include <asm/arch/sys_proto.h> 26 #include <asm/gpio.h> 27 #include <asm/mach-types.h> 28 #include "overo.h" 29 30 #ifdef CONFIG_USB_EHCI_HCD 31 #include <usb.h> 32 #include <asm/ehci-omap.h> 33 #endif 34 35 #define TWL4030_I2C_BUS 0 36 #define EXPANSION_EEPROM_I2C_BUS 2 37 #define EXPANSION_EEPROM_I2C_ADDRESS 0x51 38 39 #define GUMSTIX_EMPTY_EEPROM 0x0 40 41 #define GUMSTIX_SUMMIT 0x01000200 42 #define GUMSTIX_TOBI 0x02000200 43 #define GUMSTIX_TOBI_DUO 0x03000200 44 #define GUMSTIX_PALO35 0x04000200 45 #define GUMSTIX_PALO43 0x05000200 46 #define GUMSTIX_CHESTNUT43 0x06000200 47 #define GUMSTIX_PINTO 0x07000200 48 #define GUMSTIX_GALLOP43 0x08000200 49 #define GUMSTIX_ALTO35 0x09000200 50 #define GUMSTIX_STAGECOACH 0x0A000200 51 #define GUMSTIX_THUMBO 0x0B000200 52 #define GUMSTIX_TURTLECORE 0x0C000200 53 #define GUMSTIX_ARBOR43C 0x0D000200 54 55 #define ETTUS_USRP_E 0x01000300 56 57 #define GUMSTIX_NO_EEPROM 0xffffffff 58 59 static struct { 60 unsigned int device_vendor; 61 unsigned char revision; 62 unsigned char content; 63 char fab_revision[8]; 64 char env_var[16]; 65 char env_setting[64]; 66 } expansion_config = {0x0}; 67 68 static const struct ns16550_platdata overo_serial = { 69 .base = OMAP34XX_UART3, 70 .reg_shift = 2, 71 .clock = V_NS16550_CLK, 72 .fcr = UART_FCR_DEFVAL, 73 }; 74 75 U_BOOT_DEVICE(overo_uart) = { 76 "ns16550_serial", 77 &overo_serial 78 }; 79 80 /* 81 * Routine: get_sdio2_config 82 * Description: Return information about the wifi module connection 83 * Returns 0 if the module connects though a level translator 84 * Returns 1 if the module connects directly 85 */ 86 int get_sdio2_config(void) 87 { 88 int sdio_direct; 89 90 if (!gpio_request(130, "") && !gpio_request(139, "")) { 91 92 gpio_direction_output(130, 0); 93 gpio_direction_input(139); 94 95 sdio_direct = 1; 96 gpio_set_value(130, 0); 97 if (gpio_get_value(139) == 0) { 98 gpio_set_value(130, 1); 99 if (gpio_get_value(139) == 1) 100 sdio_direct = 0; 101 } 102 103 gpio_direction_input(130); 104 } else { 105 puts("Error: unable to acquire sdio2 clk GPIOs\n"); 106 sdio_direct = -1; 107 } 108 109 return sdio_direct; 110 } 111 112 /* 113 * Routine: get_expansion_id 114 * Description: This function checks for expansion board by checking I2C 115 * bus 2 for the availability of an AT24C01B serial EEPROM. 116 * returns the device_vendor field from the EEPROM 117 */ 118 unsigned int get_expansion_id(void) 119 { 120 if (expansion_config.device_vendor != 0x0) 121 return expansion_config.device_vendor; 122 123 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS); 124 125 /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */ 126 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) { 127 i2c_set_bus_num(TWL4030_I2C_BUS); 128 return GUMSTIX_NO_EEPROM; 129 } 130 131 /* read configuration data */ 132 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config, 133 sizeof(expansion_config)); 134 135 i2c_set_bus_num(TWL4030_I2C_BUS); 136 137 return expansion_config.device_vendor; 138 } 139 140 /* 141 * Routine: misc_init_r 142 * Description: Configure board specific parts 143 */ 144 int misc_init_r(void) 145 { 146 unsigned int expansion_id; 147 148 twl4030_power_init(); 149 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON); 150 151 printf("Board revision: %d\n", get_board_revision()); 152 153 switch (get_sdio2_config()) { 154 case 0: 155 puts("Tranceiver detected on mmc2\n"); 156 MUX_OVERO_SDIO2_TRANSCEIVER(); 157 break; 158 case 1: 159 puts("Direct connection on mmc2\n"); 160 MUX_OVERO_SDIO2_DIRECT(); 161 break; 162 default: 163 puts("Unable to detect mmc2 connection type\n"); 164 } 165 166 expansion_id = get_expansion_id(); 167 switch (expansion_id) { 168 case GUMSTIX_SUMMIT: 169 printf("Recognized Summit expansion board (rev %d %s)\n", 170 expansion_config.revision, 171 expansion_config.fab_revision); 172 MUX_GUMSTIX(); 173 env_set("defaultdisplay", "dvi"); 174 env_set("expansionname", "summit"); 175 break; 176 case GUMSTIX_TOBI: 177 printf("Recognized Tobi expansion board (rev %d %s)\n", 178 expansion_config.revision, 179 expansion_config.fab_revision); 180 MUX_GUMSTIX(); 181 env_set("defaultdisplay", "dvi"); 182 env_set("expansionname", "tobi"); 183 break; 184 case GUMSTIX_TOBI_DUO: 185 printf("Recognized Tobi Duo expansion board (rev %d %s)\n", 186 expansion_config.revision, 187 expansion_config.fab_revision); 188 MUX_GUMSTIX(); 189 env_set("expansionname", "tobiduo"); 190 break; 191 case GUMSTIX_PALO35: 192 printf("Recognized Palo35 expansion board (rev %d %s)\n", 193 expansion_config.revision, 194 expansion_config.fab_revision); 195 MUX_GUMSTIX(); 196 env_set("defaultdisplay", "lcd35"); 197 env_set("expansionname", "palo35"); 198 break; 199 case GUMSTIX_PALO43: 200 printf("Recognized Palo43 expansion board (rev %d %s)\n", 201 expansion_config.revision, 202 expansion_config.fab_revision); 203 MUX_GUMSTIX(); 204 env_set("defaultdisplay", "lcd43"); 205 env_set("expansionname", "palo43"); 206 break; 207 case GUMSTIX_CHESTNUT43: 208 printf("Recognized Chestnut43 expansion board (rev %d %s)\n", 209 expansion_config.revision, 210 expansion_config.fab_revision); 211 MUX_GUMSTIX(); 212 env_set("defaultdisplay", "lcd43"); 213 env_set("expansionname", "chestnut43"); 214 break; 215 case GUMSTIX_PINTO: 216 printf("Recognized Pinto expansion board (rev %d %s)\n", 217 expansion_config.revision, 218 expansion_config.fab_revision); 219 MUX_GUMSTIX(); 220 break; 221 case GUMSTIX_GALLOP43: 222 printf("Recognized Gallop43 expansion board (rev %d %s)\n", 223 expansion_config.revision, 224 expansion_config.fab_revision); 225 MUX_GUMSTIX(); 226 env_set("defaultdisplay", "lcd43"); 227 env_set("expansionname", "gallop43"); 228 break; 229 case GUMSTIX_ALTO35: 230 printf("Recognized Alto35 expansion board (rev %d %s)\n", 231 expansion_config.revision, 232 expansion_config.fab_revision); 233 MUX_GUMSTIX(); 234 MUX_ALTO35(); 235 env_set("defaultdisplay", "lcd35"); 236 env_set("expansionname", "alto35"); 237 break; 238 case GUMSTIX_STAGECOACH: 239 printf("Recognized Stagecoach expansion board (rev %d %s)\n", 240 expansion_config.revision, 241 expansion_config.fab_revision); 242 MUX_GUMSTIX(); 243 break; 244 case GUMSTIX_THUMBO: 245 printf("Recognized Thumbo expansion board (rev %d %s)\n", 246 expansion_config.revision, 247 expansion_config.fab_revision); 248 MUX_GUMSTIX(); 249 break; 250 case GUMSTIX_TURTLECORE: 251 printf("Recognized Turtlecore expansion board (rev %d %s)\n", 252 expansion_config.revision, 253 expansion_config.fab_revision); 254 MUX_GUMSTIX(); 255 break; 256 case GUMSTIX_ARBOR43C: 257 printf("Recognized Arbor43C expansion board (rev %d %s)\n", 258 expansion_config.revision, 259 expansion_config.fab_revision); 260 MUX_GUMSTIX(); 261 MUX_ARBOR43C(); 262 env_set("defaultdisplay", "lcd43"); 263 env_set("expansionname", "arbor43c"); 264 break; 265 case ETTUS_USRP_E: 266 printf("Recognized Ettus Research USRP-E (rev %d %s)\n", 267 expansion_config.revision, 268 expansion_config.fab_revision); 269 MUX_GUMSTIX(); 270 MUX_USRP_E(); 271 env_set("defaultdisplay", "dvi"); 272 break; 273 case GUMSTIX_NO_EEPROM: 274 case GUMSTIX_EMPTY_EEPROM: 275 puts("No or empty EEPROM on expansion board\n"); 276 MUX_GUMSTIX(); 277 env_set("expansionname", "tobi"); 278 break; 279 default: 280 printf("Unrecognized expansion board 0x%08x\n", expansion_id); 281 break; 282 } 283 284 if (expansion_config.content == 1) 285 env_set(expansion_config.env_var, expansion_config.env_setting); 286 287 omap_die_id_display(); 288 289 if (get_cpu_family() == CPU_OMAP34XX) 290 env_set("boardname", "overo"); 291 else 292 env_set("boardname", "overo-storm"); 293 294 return 0; 295 } 296 297 #if defined(CONFIG_CMD_NET) 298 /* GPMC definitions for LAN9221 chips on Tobi expansion boards */ 299 static const u32 gpmc_lan_config[] = { 300 NET_LAN9221_GPMC_CONFIG1, 301 NET_LAN9221_GPMC_CONFIG2, 302 NET_LAN9221_GPMC_CONFIG3, 303 NET_LAN9221_GPMC_CONFIG4, 304 NET_LAN9221_GPMC_CONFIG5, 305 NET_LAN9221_GPMC_CONFIG6, 306 /*CONFIG7- computed as params */ 307 }; 308 309 /* 310 * Routine: setup_net_chip 311 * Description: Setting up the configuration GPMC registers specific to the 312 * Ethernet hardware. 313 */ 314 static void setup_net_chip(void) 315 { 316 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE; 317 318 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */ 319 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe); 320 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */ 321 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe); 322 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */ 323 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00, 324 &ctrl_base->gpmc_nadv_ale); 325 } 326 327 /* 328 * Routine: reset_net_chip 329 * Description: Reset the Ethernet hardware. 330 */ 331 static void reset_net_chip(void) 332 { 333 /* Make GPIO 64 as output pin and send a magic pulse through it */ 334 if (!gpio_request(64, "")) { 335 gpio_direction_output(64, 0); 336 gpio_set_value(64, 1); 337 udelay(1); 338 gpio_set_value(64, 0); 339 udelay(1); 340 gpio_set_value(64, 1); 341 } 342 } 343 344 int board_eth_init(bd_t *bis) 345 { 346 unsigned int expansion_id; 347 int rc = 0; 348 349 #ifdef CONFIG_SMC911X 350 expansion_id = get_expansion_id(); 351 switch (expansion_id) { 352 case GUMSTIX_TOBI_DUO: 353 /* second lan chip */ 354 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4], 355 0x2B000000, GPMC_SIZE_16M); 356 /* no break */ 357 case GUMSTIX_TOBI: 358 case GUMSTIX_CHESTNUT43: 359 case GUMSTIX_STAGECOACH: 360 case GUMSTIX_NO_EEPROM: 361 case GUMSTIX_EMPTY_EEPROM: 362 /* first lan chip */ 363 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 364 0x2C000000, GPMC_SIZE_16M); 365 366 setup_net_chip(); 367 reset_net_chip(); 368 369 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); 370 break; 371 default: 372 break; 373 } 374 #endif 375 376 return rc; 377 } 378 #endif 379 380 #if defined(CONFIG_MMC) 381 int board_mmc_init(bd_t *bis) 382 { 383 return omap_mmc_init(0, 0, 0, -1, -1); 384 } 385 #endif 386 387 #if defined(CONFIG_MMC) 388 void board_mmc_power_init(void) 389 { 390 twl4030_power_mmc_init(0); 391 } 392 #endif 393 394 #if defined(CONFIG_USB_EHCI_HCD) 395 static struct omap_usbhs_board_data usbhs_bdata = { 396 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, 397 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, 398 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED 399 }; 400 401 #define GUMSTIX_GPIO_USBH_CPEN 168 402 int ehci_hcd_init(int index, enum usb_init_type init, 403 struct ehci_hccr **hccr, struct ehci_hcor **hcor) 404 { 405 /* Enable USB power */ 406 if (!gpio_request(GUMSTIX_GPIO_USBH_CPEN, "usbh_cpen")) 407 gpio_direction_output(GUMSTIX_GPIO_USBH_CPEN, 1); 408 409 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); 410 } 411 412 int ehci_hcd_stop(void) 413 { 414 /* Disable USB power */ 415 gpio_set_value(GUMSTIX_GPIO_USBH_CPEN, 0); 416 gpio_free(GUMSTIX_GPIO_USBH_CPEN); 417 418 return omap_ehci_hcd_stop(); 419 } 420 421 #endif /* CONFIG_USB_EHCI_HCD */ 422