1 /* 2 * (C) Copyright 2004-2011 3 * Texas Instruments, <www.ti.com> 4 * 5 * Author : 6 * Sunil Kumar <sunilsaini05@gmail.com> 7 * Shashi Ranjan <shashiranjanmca05@gmail.com> 8 * 9 * Derived from Beagle Board and 3430 SDP code by 10 * Richard Woodruff <r-woodruff2@ti.com> 11 * Syed Mohammed Khasim <khasim@ti.com> 12 * 13 * 14 * SPDX-License-Identifier: GPL-2.0+ 15 */ 16 #include <common.h> 17 #include <dm.h> 18 #include <ns16550.h> 19 #ifdef CONFIG_LED_STATUS 20 #include <status_led.h> 21 #endif 22 #include <twl4030.h> 23 #include <linux/mtd/rawnand.h> 24 #include <asm/io.h> 25 #include <asm/arch/mmc_host_def.h> 26 #include <asm/arch/mux.h> 27 #include <asm/arch/mem.h> 28 #include <asm/arch/sys_proto.h> 29 #include <asm/gpio.h> 30 #include <asm/mach-types.h> 31 #include <asm/omap_musb.h> 32 #include <linux/errno.h> 33 #include <linux/usb/ch9.h> 34 #include <linux/usb/gadget.h> 35 #include <linux/usb/musb.h> 36 #include "beagle.h" 37 #include <command.h> 38 39 #ifdef CONFIG_USB_EHCI_HCD 40 #include <usb.h> 41 #include <asm/ehci-omap.h> 42 #endif 43 44 #define TWL4030_I2C_BUS 0 45 #define EXPANSION_EEPROM_I2C_BUS 1 46 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50 47 48 #define TINCANTOOLS_ZIPPY 0x01000100 49 #define TINCANTOOLS_ZIPPY2 0x02000100 50 #define TINCANTOOLS_TRAINER 0x04000100 51 #define TINCANTOOLS_SHOWDOG 0x03000100 52 #define KBADC_BEAGLEFPGA 0x01000600 53 #define LW_BEAGLETOUCH 0x01000700 54 #define BRAINMUX_LCDOG 0x01000800 55 #define BRAINMUX_LCDOGTOUCH 0x02000800 56 #define BBTOYS_WIFI 0x01000B00 57 #define BBTOYS_VGA 0x02000B00 58 #define BBTOYS_LCD 0x03000B00 59 #define BCT_BRETTL3 0x01000F00 60 #define BCT_BRETTL4 0x02000F00 61 #define LSR_COM6L_ADPT 0x01001300 62 #define BEAGLE_NO_EEPROM 0xffffffff 63 64 DECLARE_GLOBAL_DATA_PTR; 65 66 static struct { 67 unsigned int device_vendor; 68 unsigned char revision; 69 unsigned char content; 70 char fab_revision[8]; 71 char env_var[16]; 72 char env_setting[64]; 73 } expansion_config; 74 75 static const struct ns16550_platdata beagle_serial = { 76 .base = OMAP34XX_UART3, 77 .reg_shift = 2, 78 .clock = V_NS16550_CLK, 79 .fcr = UART_FCR_DEFVAL, 80 }; 81 82 U_BOOT_DEVICE(beagle_uart) = { 83 "ns16550_serial", 84 &beagle_serial 85 }; 86 87 /* 88 * Routine: board_init 89 * Description: Early hardware init. 90 */ 91 int board_init(void) 92 { 93 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ 94 /* board id for Linux */ 95 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE; 96 /* boot param addr */ 97 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); 98 99 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE) 100 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON); 101 #endif 102 103 return 0; 104 } 105 106 #if defined(CONFIG_SPL_OS_BOOT) 107 int spl_start_uboot(void) 108 { 109 /* break into full u-boot on 'c' */ 110 if (serial_tstc() && serial_getc() == 'c') 111 return 1; 112 113 return 0; 114 } 115 #endif /* CONFIG_SPL_OS_BOOT */ 116 117 /* 118 * Routine: get_board_revision 119 * Description: Detect if we are running on a Beagle revision Ax/Bx, 120 * C1/2/3, C4, xM Ax/Bx or xM Cx. This can be done by reading 121 * the level of GPIO173, GPIO172 and GPIO171. This should 122 * result in 123 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx 124 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3 125 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4 126 * GPIO173, GPIO172, GPIO171: 0 1 0 => xM Cx 127 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx 128 */ 129 static int get_board_revision(void) 130 { 131 static int revision = -1; 132 133 if (revision == -1) { 134 if (!gpio_request(171, "rev0") && 135 !gpio_request(172, "rev1") && 136 !gpio_request(173, "rev2")) { 137 gpio_direction_input(171); 138 gpio_direction_input(172); 139 gpio_direction_input(173); 140 141 revision = gpio_get_value(173) << 2 | 142 gpio_get_value(172) << 1 | 143 gpio_get_value(171); 144 } else { 145 printf("Error: unable to acquire board revision GPIOs\n"); 146 } 147 } 148 149 return revision; 150 } 151 152 #ifdef CONFIG_SPL_BUILD 153 /* 154 * Routine: get_board_mem_timings 155 * Description: If we use SPL then there is no x-loader nor config header 156 * so we have to setup the DDR timings ourself on both banks. 157 */ 158 void get_board_mem_timings(struct board_sdrc_timings *timings) 159 { 160 int pop_mfr, pop_id; 161 162 /* 163 * We need to identify what PoP memory is on the board so that 164 * we know what timings to use. If we can't identify it then 165 * we know it's an xM. To map the ID values please see nand_ids.c 166 */ 167 identify_nand_chip(&pop_mfr, &pop_id); 168 169 timings->mr = MICRON_V_MR_165; 170 switch (get_board_revision()) { 171 case REVISION_C4: 172 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) { 173 /* 512MB DDR */ 174 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20); 175 timings->ctrla = NUMONYX_V_ACTIMA_165; 176 timings->ctrlb = NUMONYX_V_ACTIMB_165; 177 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 178 break; 179 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) { 180 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/ 181 timings->mcfg = MICRON_V_MCFG_165(128 << 20); 182 timings->ctrla = MICRON_V_ACTIMA_165; 183 timings->ctrlb = MICRON_V_ACTIMB_165; 184 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 185 break; 186 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) { 187 /* Beagleboard Rev C5, 256MB DDR */ 188 timings->mcfg = MICRON_V_MCFG_200(256 << 20); 189 timings->ctrla = MICRON_V_ACTIMA_200; 190 timings->ctrlb = MICRON_V_ACTIMB_200; 191 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 192 break; 193 } 194 case REVISION_XM_AB: 195 case REVISION_XM_C: 196 if (pop_mfr == 0) { 197 /* 256MB DDR */ 198 timings->mcfg = MICRON_V_MCFG_200(256 << 20); 199 timings->ctrla = MICRON_V_ACTIMA_200; 200 timings->ctrlb = MICRON_V_ACTIMB_200; 201 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 202 } else { 203 /* 512MB DDR */ 204 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20); 205 timings->ctrla = NUMONYX_V_ACTIMA_165; 206 timings->ctrlb = NUMONYX_V_ACTIMB_165; 207 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 208 } 209 break; 210 default: 211 /* Assume 128MB and Micron/165MHz timings to be safe */ 212 timings->mcfg = MICRON_V_MCFG_165(128 << 20); 213 timings->ctrla = MICRON_V_ACTIMA_165; 214 timings->ctrlb = MICRON_V_ACTIMB_165; 215 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 216 } 217 } 218 #endif 219 220 /* 221 * Routine: get_expansion_id 222 * Description: This function checks for expansion board by checking I2C 223 * bus 1 for the availability of an AT24C01B serial EEPROM. 224 * returns the device_vendor field from the EEPROM 225 */ 226 static unsigned int get_expansion_id(void) 227 { 228 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS); 229 230 /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */ 231 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) { 232 i2c_set_bus_num(TWL4030_I2C_BUS); 233 return BEAGLE_NO_EEPROM; 234 } 235 236 /* read configuration data */ 237 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config, 238 sizeof(expansion_config)); 239 240 /* retry reading configuration data with 16bit addressing */ 241 if ((expansion_config.device_vendor == 0xFFFFFF00) || 242 (expansion_config.device_vendor == 0xFFFFFFFF)) { 243 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n"); 244 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config, 245 sizeof(expansion_config)); 246 } 247 248 i2c_set_bus_num(TWL4030_I2C_BUS); 249 250 return expansion_config.device_vendor; 251 } 252 253 #ifdef CONFIG_VIDEO_OMAP3 254 /* 255 * Configure DSS to display background color on DVID 256 * Configure VENC to display color bar on S-Video 257 */ 258 static void beagle_display_init(void) 259 { 260 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH); 261 switch (get_board_revision()) { 262 case REVISION_AXBX: 263 case REVISION_CX: 264 case REVISION_C4: 265 omap3_dss_panel_config(&dvid_cfg); 266 break; 267 case REVISION_XM_AB: 268 case REVISION_XM_C: 269 default: 270 omap3_dss_panel_config(&dvid_cfg_xm); 271 break; 272 } 273 } 274 275 /* 276 * Enable DVI power 277 */ 278 static void beagle_dvi_pup(void) 279 { 280 uchar val; 281 282 switch (get_board_revision()) { 283 case REVISION_AXBX: 284 case REVISION_CX: 285 case REVISION_C4: 286 gpio_request(170, "dvi"); 287 gpio_direction_output(170, 0); 288 gpio_set_value(170, 1); 289 break; 290 case REVISION_XM_AB: 291 case REVISION_XM_C: 292 default: 293 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3) 294 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6) 295 296 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1); 297 val |= 4; 298 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1); 299 300 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1); 301 val |= 4; 302 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1); 303 break; 304 } 305 } 306 #endif 307 308 #ifdef CONFIG_USB_MUSB_OMAP2PLUS 309 static struct musb_hdrc_config musb_config = { 310 .multipoint = 1, 311 .dyn_fifo = 1, 312 .num_eps = 16, 313 .ram_bits = 12, 314 }; 315 316 static struct omap_musb_board_data musb_board_data = { 317 .interface_type = MUSB_INTERFACE_ULPI, 318 }; 319 320 static struct musb_hdrc_platform_data musb_plat = { 321 #if defined(CONFIG_USB_MUSB_HOST) 322 .mode = MUSB_HOST, 323 #elif defined(CONFIG_USB_MUSB_GADGET) 324 .mode = MUSB_PERIPHERAL, 325 #else 326 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET" 327 #endif 328 .config = &musb_config, 329 .power = 100, 330 .platform_ops = &omap2430_ops, 331 .board_data = &musb_board_data, 332 }; 333 #endif 334 335 /* 336 * Routine: misc_init_r 337 * Description: Configure board specific parts 338 */ 339 int misc_init_r(void) 340 { 341 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE; 342 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE; 343 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE; 344 bool generate_fake_mac = false; 345 u32 value; 346 347 /* Enable i2c2 pullup resisters */ 348 value = readl(&prog_io_base->io1); 349 value &= ~(PRG_I2C2_PULLUPRESX); 350 writel(value, &prog_io_base->io1); 351 352 switch (get_board_revision()) { 353 case REVISION_AXBX: 354 printf("Beagle Rev Ax/Bx\n"); 355 env_set("beaglerev", "AxBx"); 356 break; 357 case REVISION_CX: 358 printf("Beagle Rev C1/C2/C3\n"); 359 env_set("beaglerev", "Cx"); 360 MUX_BEAGLE_C(); 361 break; 362 case REVISION_C4: 363 printf("Beagle Rev C4\n"); 364 env_set("beaglerev", "C4"); 365 MUX_BEAGLE_C(); 366 /* Set VAUX2 to 1.8V for EHCI PHY */ 367 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 368 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 369 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 370 TWL4030_PM_RECEIVER_DEV_GRP_P1); 371 break; 372 case REVISION_XM_AB: 373 printf("Beagle xM Rev A/B\n"); 374 env_set("beaglerev", "xMAB"); 375 MUX_BEAGLE_XM(); 376 /* Set VAUX2 to 1.8V for EHCI PHY */ 377 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 378 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 379 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 380 TWL4030_PM_RECEIVER_DEV_GRP_P1); 381 generate_fake_mac = true; 382 break; 383 case REVISION_XM_C: 384 printf("Beagle xM Rev C\n"); 385 env_set("beaglerev", "xMC"); 386 MUX_BEAGLE_XM(); 387 /* Set VAUX2 to 1.8V for EHCI PHY */ 388 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 389 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 390 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 391 TWL4030_PM_RECEIVER_DEV_GRP_P1); 392 generate_fake_mac = true; 393 break; 394 default: 395 printf("Beagle unknown 0x%02x\n", get_board_revision()); 396 MUX_BEAGLE_XM(); 397 /* Set VAUX2 to 1.8V for EHCI PHY */ 398 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 399 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 400 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 401 TWL4030_PM_RECEIVER_DEV_GRP_P1); 402 generate_fake_mac = true; 403 } 404 405 switch (get_expansion_id()) { 406 case TINCANTOOLS_ZIPPY: 407 printf("Recognized Tincantools Zippy board (rev %d %s)\n", 408 expansion_config.revision, 409 expansion_config.fab_revision); 410 MUX_TINCANTOOLS_ZIPPY(); 411 env_set("buddy", "zippy"); 412 break; 413 case TINCANTOOLS_ZIPPY2: 414 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n", 415 expansion_config.revision, 416 expansion_config.fab_revision); 417 MUX_TINCANTOOLS_ZIPPY(); 418 env_set("buddy", "zippy2"); 419 break; 420 case TINCANTOOLS_TRAINER: 421 printf("Recognized Tincantools Trainer board (rev %d %s)\n", 422 expansion_config.revision, 423 expansion_config.fab_revision); 424 MUX_TINCANTOOLS_ZIPPY(); 425 MUX_TINCANTOOLS_TRAINER(); 426 env_set("buddy", "trainer"); 427 break; 428 case TINCANTOOLS_SHOWDOG: 429 printf("Recognized Tincantools Showdow board (rev %d %s)\n", 430 expansion_config.revision, 431 expansion_config.fab_revision); 432 /* Place holder for DSS2 definition for showdog lcd */ 433 env_set("defaultdisplay", "showdoglcd"); 434 env_set("buddy", "showdog"); 435 break; 436 case KBADC_BEAGLEFPGA: 437 printf("Recognized KBADC Beagle FPGA board\n"); 438 MUX_KBADC_BEAGLEFPGA(); 439 env_set("buddy", "beaglefpga"); 440 break; 441 case LW_BEAGLETOUCH: 442 printf("Recognized Liquidware BeagleTouch board\n"); 443 env_set("buddy", "beagletouch"); 444 break; 445 case BRAINMUX_LCDOG: 446 printf("Recognized Brainmux LCDog board\n"); 447 env_set("buddy", "lcdog"); 448 break; 449 case BRAINMUX_LCDOGTOUCH: 450 printf("Recognized Brainmux LCDog Touch board\n"); 451 env_set("buddy", "lcdogtouch"); 452 break; 453 case BBTOYS_WIFI: 454 printf("Recognized BeagleBoardToys WiFi board\n"); 455 MUX_BBTOYS_WIFI() 456 env_set("buddy", "bbtoys-wifi"); 457 break; 458 case BBTOYS_VGA: 459 printf("Recognized BeagleBoardToys VGA board\n"); 460 break; 461 case BBTOYS_LCD: 462 printf("Recognized BeagleBoardToys LCD board\n"); 463 break; 464 case BCT_BRETTL3: 465 printf("Recognized bct electronic GmbH brettl3 board\n"); 466 break; 467 case BCT_BRETTL4: 468 printf("Recognized bct electronic GmbH brettl4 board\n"); 469 break; 470 case LSR_COM6L_ADPT: 471 printf("Recognized LSR COM6L Adapter Board\n"); 472 MUX_BBTOYS_WIFI() 473 env_set("buddy", "lsr-com6l-adpt"); 474 break; 475 case BEAGLE_NO_EEPROM: 476 printf("No EEPROM on expansion board\n"); 477 env_set("buddy", "none"); 478 break; 479 default: 480 printf("Unrecognized expansion board: %x\n", 481 expansion_config.device_vendor); 482 env_set("buddy", "unknown"); 483 } 484 485 if (expansion_config.content == 1) 486 env_set(expansion_config.env_var, expansion_config.env_setting); 487 488 twl4030_power_init(); 489 switch (get_board_revision()) { 490 case REVISION_XM_AB: 491 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON); 492 break; 493 default: 494 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON); 495 break; 496 } 497 498 /* Set GPIO states before they are made outputs */ 499 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1, 500 &gpio6_base->setdataout); 501 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 | 502 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout); 503 504 /* Configure GPIOs to output */ 505 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe); 506 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 | 507 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe); 508 509 omap_die_id_display(); 510 511 #ifdef CONFIG_VIDEO_OMAP3 512 beagle_dvi_pup(); 513 beagle_display_init(); 514 omap3_dss_enable(); 515 #endif 516 517 #ifdef CONFIG_USB_MUSB_OMAP2PLUS 518 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE); 519 #endif 520 521 if (generate_fake_mac) 522 omap_die_id_usbethaddr(); 523 524 return 0; 525 } 526 527 /* 528 * Routine: set_muxconf_regs 529 * Description: Setting up the configuration Mux registers specific to the 530 * hardware. Many pins need to be moved from protect to primary 531 * mode. 532 */ 533 void set_muxconf_regs(void) 534 { 535 MUX_BEAGLE(); 536 } 537 538 #if defined(CONFIG_MMC) 539 int board_mmc_init(bd_t *bis) 540 { 541 return omap_mmc_init(0, 0, 0, -1, -1); 542 } 543 #endif 544 545 #if defined(CONFIG_MMC) 546 void board_mmc_power_init(void) 547 { 548 twl4030_power_mmc_init(0); 549 } 550 #endif 551 552 #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD) 553 /* Call usb_stop() before starting the kernel */ 554 void show_boot_progress(int val) 555 { 556 if (val == BOOTSTAGE_ID_RUN_OS) 557 usb_stop(); 558 } 559 560 static struct omap_usbhs_board_data usbhs_bdata = { 561 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, 562 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, 563 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED 564 }; 565 566 int ehci_hcd_init(int index, enum usb_init_type init, 567 struct ehci_hccr **hccr, struct ehci_hcor **hcor) 568 { 569 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor); 570 } 571 572 int ehci_hcd_stop(int index) 573 { 574 return omap_ehci_hcd_stop(); 575 } 576 577 #endif /* CONFIG_USB_EHCI_HCD */ 578 579 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET) 580 int board_eth_init(bd_t *bis) 581 { 582 return usb_eth_initialize(bis); 583 } 584 #endif 585