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