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 <netdev.h> 17 #include <twl4030.h> 18 #include <linux/mtd/nand.h> 19 #include <asm/io.h> 20 #include <asm/arch/mmc_host_def.h> 21 #include <asm/arch/mux.h> 22 #include <asm/arch/mem.h> 23 #include <asm/arch/sys_proto.h> 24 #include <asm/gpio.h> 25 #include <asm/mach-types.h> 26 #include "overo.h" 27 28 #ifdef CONFIG_USB_EHCI 29 #include <usb.h> 30 #include <asm/ehci-omap.h> 31 #endif 32 33 DECLARE_GLOBAL_DATA_PTR; 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 /* 69 * Routine: board_init 70 * Description: Early hardware init. 71 */ 72 int board_init(void) 73 { 74 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ 75 /* board id for Linux */ 76 gd->bd->bi_arch_number = MACH_TYPE_OVERO; 77 /* boot param addr */ 78 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); 79 80 return 0; 81 } 82 83 /* 84 * Routine: get_board_revision 85 * Description: Returns the board revision 86 */ 87 int get_board_revision(void) 88 { 89 int revision; 90 91 #ifdef CONFIG_SYS_I2C_OMAP34XX 92 unsigned char data; 93 94 /* board revisions <= R2410 connect 4030 irq_1 to gpio112 */ 95 /* these boards should return a revision number of 0 */ 96 /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */ 97 i2c_set_bus_num(TWL4030_I2C_BUS); 98 data = 0x01; 99 i2c_write(0x4B, 0x29, 1, &data, 1); 100 data = 0x0c; 101 i2c_write(0x4B, 0x2b, 1, &data, 1); 102 i2c_read(0x4B, 0x2a, 1, &data, 1); 103 #endif 104 105 if (!gpio_request(112, "") && 106 !gpio_request(113, "") && 107 !gpio_request(115, "")) { 108 109 gpio_direction_input(112); 110 gpio_direction_input(113); 111 gpio_direction_input(115); 112 113 revision = gpio_get_value(115) << 2 | 114 gpio_get_value(113) << 1 | 115 gpio_get_value(112); 116 } else { 117 puts("Error: unable to acquire board revision GPIOs\n"); 118 revision = -1; 119 } 120 121 return revision; 122 } 123 124 #ifdef CONFIG_SPL_BUILD 125 /* 126 * Routine: get_board_mem_timings 127 * Description: If we use SPL then there is no x-loader nor config header 128 * so we have to setup the DDR timings ourself on both banks. 129 */ 130 void get_board_mem_timings(struct board_sdrc_timings *timings) 131 { 132 timings->mr = MICRON_V_MR_165; 133 switch (get_board_revision()) { 134 case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */ 135 timings->mcfg = MICRON_V_MCFG_165(128 << 20); 136 timings->ctrla = MICRON_V_ACTIMA_165; 137 timings->ctrlb = MICRON_V_ACTIMB_165; 138 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 139 break; 140 case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */ 141 case REVISION_4: 142 timings->mcfg = MICRON_V_MCFG_200(256 << 20); 143 timings->ctrla = MICRON_V_ACTIMA_200; 144 timings->ctrlb = MICRON_V_ACTIMB_200; 145 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 146 break; 147 case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */ 148 timings->mcfg = HYNIX_V_MCFG_200(256 << 20); 149 timings->ctrla = HYNIX_V_ACTIMA_200; 150 timings->ctrlb = HYNIX_V_ACTIMB_200; 151 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 152 break; 153 case REVISION_3: /* Micron 512MB/1024MB, 1/2 banks of 512MB */ 154 timings->mcfg = MCFG(512 << 20, 15); 155 timings->ctrla = MICRON_V_ACTIMA_200; 156 timings->ctrlb = MICRON_V_ACTIMB_200; 157 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 158 break; 159 default: 160 timings->mcfg = MICRON_V_MCFG_165(128 << 20); 161 timings->ctrla = MICRON_V_ACTIMA_165; 162 timings->ctrlb = MICRON_V_ACTIMB_165; 163 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 164 } 165 } 166 #endif 167 168 /* 169 * Routine: get_sdio2_config 170 * Description: Return information about the wifi module connection 171 * Returns 0 if the module connects though a level translator 172 * Returns 1 if the module connects directly 173 */ 174 int get_sdio2_config(void) 175 { 176 int sdio_direct; 177 178 if (!gpio_request(130, "") && !gpio_request(139, "")) { 179 180 gpio_direction_output(130, 0); 181 gpio_direction_input(139); 182 183 sdio_direct = 1; 184 gpio_set_value(130, 0); 185 if (gpio_get_value(139) == 0) { 186 gpio_set_value(130, 1); 187 if (gpio_get_value(139) == 1) 188 sdio_direct = 0; 189 } 190 191 gpio_direction_input(130); 192 } else { 193 puts("Error: unable to acquire sdio2 clk GPIOs\n"); 194 sdio_direct = -1; 195 } 196 197 return sdio_direct; 198 } 199 200 /* 201 * Routine: get_expansion_id 202 * Description: This function checks for expansion board by checking I2C 203 * bus 2 for the availability of an AT24C01B serial EEPROM. 204 * returns the device_vendor field from the EEPROM 205 */ 206 unsigned int get_expansion_id(void) 207 { 208 if (expansion_config.device_vendor != 0x0) 209 return expansion_config.device_vendor; 210 211 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS); 212 213 /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */ 214 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) { 215 i2c_set_bus_num(TWL4030_I2C_BUS); 216 return GUMSTIX_NO_EEPROM; 217 } 218 219 /* read configuration data */ 220 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config, 221 sizeof(expansion_config)); 222 223 i2c_set_bus_num(TWL4030_I2C_BUS); 224 225 return expansion_config.device_vendor; 226 } 227 228 /* 229 * Routine: misc_init_r 230 * Description: Configure board specific parts 231 */ 232 int misc_init_r(void) 233 { 234 unsigned int expansion_id; 235 236 twl4030_power_init(); 237 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON); 238 239 printf("Board revision: %d\n", get_board_revision()); 240 241 switch (get_sdio2_config()) { 242 case 0: 243 puts("Tranceiver detected on mmc2\n"); 244 MUX_OVERO_SDIO2_TRANSCEIVER(); 245 break; 246 case 1: 247 puts("Direct connection on mmc2\n"); 248 MUX_OVERO_SDIO2_DIRECT(); 249 break; 250 default: 251 puts("Unable to detect mmc2 connection type\n"); 252 } 253 254 expansion_id = get_expansion_id(); 255 switch (expansion_id) { 256 case GUMSTIX_SUMMIT: 257 printf("Recognized Summit expansion board (rev %d %s)\n", 258 expansion_config.revision, 259 expansion_config.fab_revision); 260 MUX_GUMSTIX(); 261 setenv("defaultdisplay", "dvi"); 262 setenv("expansionname", "summit"); 263 break; 264 case GUMSTIX_TOBI: 265 printf("Recognized Tobi expansion board (rev %d %s)\n", 266 expansion_config.revision, 267 expansion_config.fab_revision); 268 MUX_GUMSTIX(); 269 setenv("defaultdisplay", "dvi"); 270 setenv("expansionname", "tobi"); 271 break; 272 case GUMSTIX_TOBI_DUO: 273 printf("Recognized Tobi Duo expansion board (rev %d %s)\n", 274 expansion_config.revision, 275 expansion_config.fab_revision); 276 MUX_GUMSTIX(); 277 break; 278 case GUMSTIX_PALO35: 279 printf("Recognized Palo35 expansion board (rev %d %s)\n", 280 expansion_config.revision, 281 expansion_config.fab_revision); 282 MUX_GUMSTIX(); 283 setenv("defaultdisplay", "lcd35"); 284 break; 285 case GUMSTIX_PALO43: 286 printf("Recognized Palo43 expansion board (rev %d %s)\n", 287 expansion_config.revision, 288 expansion_config.fab_revision); 289 MUX_GUMSTIX(); 290 setenv("defaultdisplay", "lcd43"); 291 setenv("expansionname", "palo43"); 292 break; 293 case GUMSTIX_CHESTNUT43: 294 printf("Recognized Chestnut43 expansion board (rev %d %s)\n", 295 expansion_config.revision, 296 expansion_config.fab_revision); 297 MUX_GUMSTIX(); 298 setenv("defaultdisplay", "lcd43"); 299 setenv("expansionname", "chestnut43"); 300 break; 301 case GUMSTIX_PINTO: 302 printf("Recognized Pinto expansion board (rev %d %s)\n", 303 expansion_config.revision, 304 expansion_config.fab_revision); 305 MUX_GUMSTIX(); 306 break; 307 case GUMSTIX_GALLOP43: 308 printf("Recognized Gallop43 expansion board (rev %d %s)\n", 309 expansion_config.revision, 310 expansion_config.fab_revision); 311 MUX_GUMSTIX(); 312 setenv("defaultdisplay", "lcd43"); 313 setenv("expansionname", "gallop43"); 314 break; 315 case GUMSTIX_ALTO35: 316 printf("Recognized Alto35 expansion board (rev %d %s)\n", 317 expansion_config.revision, 318 expansion_config.fab_revision); 319 MUX_GUMSTIX(); 320 MUX_ALTO35(); 321 setenv("defaultdisplay", "lcd35"); 322 setenv("expansionname", "alto35"); 323 break; 324 case GUMSTIX_STAGECOACH: 325 printf("Recognized Stagecoach expansion board (rev %d %s)\n", 326 expansion_config.revision, 327 expansion_config.fab_revision); 328 MUX_GUMSTIX(); 329 break; 330 case GUMSTIX_THUMBO: 331 printf("Recognized Thumbo expansion board (rev %d %s)\n", 332 expansion_config.revision, 333 expansion_config.fab_revision); 334 MUX_GUMSTIX(); 335 break; 336 case GUMSTIX_TURTLECORE: 337 printf("Recognized Turtlecore expansion board (rev %d %s)\n", 338 expansion_config.revision, 339 expansion_config.fab_revision); 340 MUX_GUMSTIX(); 341 break; 342 case GUMSTIX_ARBOR43C: 343 printf("Recognized Arbor43C expansion board (rev %d %s)\n", 344 expansion_config.revision, 345 expansion_config.fab_revision); 346 MUX_GUMSTIX(); 347 MUX_ARBOR43C(); 348 setenv("defaultdisplay", "lcd43"); 349 break; 350 case ETTUS_USRP_E: 351 printf("Recognized Ettus Research USRP-E (rev %d %s)\n", 352 expansion_config.revision, 353 expansion_config.fab_revision); 354 MUX_GUMSTIX(); 355 MUX_USRP_E(); 356 setenv("defaultdisplay", "dvi"); 357 break; 358 case GUMSTIX_NO_EEPROM: 359 case GUMSTIX_EMPTY_EEPROM: 360 puts("No or empty EEPROM on expansion board\n"); 361 MUX_GUMSTIX(); 362 setenv("expansionname", "tobi"); 363 break; 364 default: 365 printf("Unrecognized expansion board 0x%08x\n", expansion_id); 366 break; 367 } 368 369 if (expansion_config.content == 1) 370 setenv(expansion_config.env_var, expansion_config.env_setting); 371 372 dieid_num_r(); 373 374 if (get_cpu_family() == CPU_OMAP34XX) 375 setenv("boardname", "overo"); 376 else 377 setenv("boardname", "overo-storm"); 378 379 return 0; 380 } 381 382 /* 383 * Routine: set_muxconf_regs 384 * Description: Setting up the configuration Mux registers specific to the 385 * hardware. Many pins need to be moved from protect to primary 386 * mode. 387 */ 388 void set_muxconf_regs(void) 389 { 390 MUX_OVERO(); 391 } 392 393 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_SPL_BUILD) 394 /* GPMC definitions for LAN9221 chips on Tobi expansion boards */ 395 static const u32 gpmc_lan_config[] = { 396 NET_LAN9221_GPMC_CONFIG1, 397 NET_LAN9221_GPMC_CONFIG2, 398 NET_LAN9221_GPMC_CONFIG3, 399 NET_LAN9221_GPMC_CONFIG4, 400 NET_LAN9221_GPMC_CONFIG5, 401 NET_LAN9221_GPMC_CONFIG6, 402 /*CONFIG7- computed as params */ 403 }; 404 405 /* 406 * Routine: setup_net_chip 407 * Description: Setting up the configuration GPMC registers specific to the 408 * Ethernet hardware. 409 */ 410 static void setup_net_chip(void) 411 { 412 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE; 413 414 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */ 415 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe); 416 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */ 417 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe); 418 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */ 419 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00, 420 &ctrl_base->gpmc_nadv_ale); 421 } 422 423 /* 424 * Routine: reset_net_chip 425 * Description: Reset the Ethernet hardware. 426 */ 427 static void reset_net_chip(void) 428 { 429 /* Make GPIO 64 as output pin and send a magic pulse through it */ 430 if (!gpio_request(64, "")) { 431 gpio_direction_output(64, 0); 432 gpio_set_value(64, 1); 433 udelay(1); 434 gpio_set_value(64, 0); 435 udelay(1); 436 gpio_set_value(64, 1); 437 } 438 } 439 440 int board_eth_init(bd_t *bis) 441 { 442 unsigned int expansion_id; 443 int rc = 0; 444 445 #ifdef CONFIG_SMC911X 446 expansion_id = get_expansion_id(); 447 switch (expansion_id) { 448 case GUMSTIX_TOBI_DUO: 449 /* second lan chip */ 450 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4], 451 0x2B000000, GPMC_SIZE_16M); 452 /* no break */ 453 case GUMSTIX_TOBI: 454 case GUMSTIX_CHESTNUT43: 455 case GUMSTIX_STAGECOACH: 456 case GUMSTIX_NO_EEPROM: 457 case GUMSTIX_EMPTY_EEPROM: 458 /* first lan chip */ 459 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 460 0x2C000000, GPMC_SIZE_16M); 461 462 setup_net_chip(); 463 reset_net_chip(); 464 465 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); 466 break; 467 default: 468 break; 469 } 470 #endif 471 472 return rc; 473 } 474 #endif 475 476 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD) 477 int board_mmc_init(bd_t *bis) 478 { 479 return omap_mmc_init(0, 0, 0, -1, -1); 480 } 481 #endif 482 483 #if defined(CONFIG_USB_EHCI) && !defined(CONFIG_SPL_BUILD) 484 static struct omap_usbhs_board_data usbhs_bdata = { 485 .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, 486 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, 487 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED 488 }; 489 490 #define GUMSTIX_GPIO_USBH_CPEN 168 491 int ehci_hcd_init(int index, enum usb_init_type init, 492 struct ehci_hccr **hccr, struct ehci_hcor **hcor) 493 { 494 /* Enable USB power */ 495 if (!gpio_request(GUMSTIX_GPIO_USBH_CPEN, "usbh_cpen")) 496 gpio_direction_output(GUMSTIX_GPIO_USBH_CPEN, 1); 497 498 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); 499 } 500 501 int ehci_hcd_stop(void) 502 { 503 /* Disable USB power */ 504 gpio_set_value(GUMSTIX_GPIO_USBH_CPEN, 0); 505 gpio_free(GUMSTIX_GPIO_USBH_CPEN); 506 507 return omap_ehci_hcd_stop(); 508 } 509 510 #endif /* CONFIG_USB_EHCI */ 511