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 * See file CREDITS for list of people who contributed to this 15 * project. 16 * 17 * This program is free software; you can redistribute it and/or 18 * modify it under the terms of the GNU General Public License as 19 * published by the Free Software Foundation; either version 2 of 20 * the License, or (at your option) any later version. 21 * 22 * This program is distributed in the hope that it will be useful, 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * GNU General Public License for more details. 26 * 27 * You should have received a copy of the GNU General Public License 28 * along with this program; if not, write to the Free Software 29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 30 * MA 02111-1307 USA 31 */ 32 #include <common.h> 33 #ifdef CONFIG_STATUS_LED 34 #include <status_led.h> 35 #endif 36 #include <twl4030.h> 37 #include <linux/mtd/nand.h> 38 #include <asm/io.h> 39 #include <asm/arch/mmc_host_def.h> 40 #include <asm/arch/mux.h> 41 #include <asm/arch/mem.h> 42 #include <asm/arch/sys_proto.h> 43 #include <asm/gpio.h> 44 #include <asm/mach-types.h> 45 #include "beagle.h" 46 #include <command.h> 47 48 #ifdef CONFIG_USB_EHCI 49 #include <usb.h> 50 #include <asm/ehci-omap.h> 51 #endif 52 53 #define pr_debug(fmt, args...) debug(fmt, ##args) 54 55 #define TWL4030_I2C_BUS 0 56 #define EXPANSION_EEPROM_I2C_BUS 1 57 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50 58 59 #define TINCANTOOLS_ZIPPY 0x01000100 60 #define TINCANTOOLS_ZIPPY2 0x02000100 61 #define TINCANTOOLS_TRAINER 0x04000100 62 #define TINCANTOOLS_SHOWDOG 0x03000100 63 #define KBADC_BEAGLEFPGA 0x01000600 64 #define LW_BEAGLETOUCH 0x01000700 65 #define BRAINMUX_LCDOG 0x01000800 66 #define BRAINMUX_LCDOGTOUCH 0x02000800 67 #define BBTOYS_WIFI 0x01000B00 68 #define BBTOYS_VGA 0x02000B00 69 #define BBTOYS_LCD 0x03000B00 70 #define BCT_BRETTL3 0x01000F00 71 #define BEAGLE_NO_EEPROM 0xffffffff 72 73 DECLARE_GLOBAL_DATA_PTR; 74 75 static struct { 76 unsigned int device_vendor; 77 unsigned char revision; 78 unsigned char content; 79 char fab_revision[8]; 80 char env_var[16]; 81 char env_setting[64]; 82 } expansion_config; 83 84 /* 85 * Routine: board_init 86 * Description: Early hardware init. 87 */ 88 int board_init(void) 89 { 90 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */ 91 /* board id for Linux */ 92 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE; 93 /* boot param addr */ 94 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100); 95 96 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT) 97 status_led_set (STATUS_LED_BOOT, STATUS_LED_ON); 98 #endif 99 100 return 0; 101 } 102 103 /* 104 * Routine: get_board_revision 105 * Description: Detect if we are running on a Beagle revision Ax/Bx, 106 * C1/2/3, C4 or xM. This can be done by reading 107 * the level of GPIO173, GPIO172 and GPIO171. This should 108 * result in 109 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx 110 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3 111 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4 112 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM 113 */ 114 int get_board_revision(void) 115 { 116 int revision; 117 118 if (!gpio_request(171, "") && 119 !gpio_request(172, "") && 120 !gpio_request(173, "")) { 121 122 gpio_direction_input(171); 123 gpio_direction_input(172); 124 gpio_direction_input(173); 125 126 revision = gpio_get_value(173) << 2 | 127 gpio_get_value(172) << 1 | 128 gpio_get_value(171); 129 } else { 130 printf("Error: unable to acquire board revision GPIOs\n"); 131 revision = -1; 132 } 133 134 return revision; 135 } 136 137 #ifdef CONFIG_SPL_BUILD 138 /* 139 * Routine: get_board_mem_timings 140 * Description: If we use SPL then there is no x-loader nor config header 141 * so we have to setup the DDR timings ourself on both banks. 142 */ 143 void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl, 144 u32 *mr) 145 { 146 int pop_mfr, pop_id; 147 148 /* 149 * We need to identify what PoP memory is on the board so that 150 * we know what timings to use. If we can't identify it then 151 * we know it's an xM. To map the ID values please see nand_ids.c 152 */ 153 identify_nand_chip(&pop_mfr, &pop_id); 154 155 *mr = MICRON_V_MR_165; 156 switch (get_board_revision()) { 157 case REVISION_C4: 158 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) { 159 /* 512MB DDR */ 160 *mcfg = NUMONYX_V_MCFG_165(512 << 20); 161 *ctrla = NUMONYX_V_ACTIMA_165; 162 *ctrlb = NUMONYX_V_ACTIMB_165; 163 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 164 break; 165 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) { 166 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/ 167 *mcfg = MICRON_V_MCFG_165(128 << 20); 168 *ctrla = MICRON_V_ACTIMA_165; 169 *ctrlb = MICRON_V_ACTIMB_165; 170 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 171 break; 172 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) { 173 /* Beagleboard Rev C5, 256MB DDR */ 174 *mcfg = MICRON_V_MCFG_200(256 << 20); 175 *ctrla = MICRON_V_ACTIMA_200; 176 *ctrlb = MICRON_V_ACTIMB_200; 177 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 178 break; 179 } 180 case REVISION_XM_A: 181 case REVISION_XM_B: 182 case REVISION_XM_C: 183 if (pop_mfr == 0) { 184 /* 256MB DDR */ 185 *mcfg = MICRON_V_MCFG_200(256 << 20); 186 *ctrla = MICRON_V_ACTIMA_200; 187 *ctrlb = MICRON_V_ACTIMB_200; 188 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz; 189 } else { 190 /* 512MB DDR */ 191 *mcfg = NUMONYX_V_MCFG_165(512 << 20); 192 *ctrla = NUMONYX_V_ACTIMA_165; 193 *ctrlb = NUMONYX_V_ACTIMB_165; 194 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz; 195 } 196 break; 197 default: 198 /* Assume 128MB and Micron/165MHz timings to be safe */ 199 *mcfg = MICRON_V_MCFG_165(128 << 20); 200 *ctrla = MICRON_V_ACTIMA_165; 201 *ctrlb = MICRON_V_ACTIMB_165; 202 *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 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 i2c_set_bus_num(TWL4030_I2C_BUS); 228 229 return expansion_config.device_vendor; 230 } 231 232 /* 233 * Configure DSS to display background color on DVID 234 * Configure VENC to display color bar on S-Video 235 */ 236 void beagle_display_init(void) 237 { 238 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH); 239 switch (get_board_revision()) { 240 case REVISION_AXBX: 241 case REVISION_CX: 242 case REVISION_C4: 243 omap3_dss_panel_config(&dvid_cfg); 244 break; 245 case REVISION_XM_A: 246 case REVISION_XM_B: 247 case REVISION_XM_C: 248 default: 249 omap3_dss_panel_config(&dvid_cfg_xm); 250 break; 251 } 252 } 253 254 /* 255 * Enable DVI power 256 */ 257 static void beagle_dvi_pup(void) 258 { 259 uchar val; 260 261 switch (get_board_revision()) { 262 case REVISION_AXBX: 263 case REVISION_CX: 264 case REVISION_C4: 265 case REVISION_XM_A: 266 gpio_request(170, ""); 267 gpio_direction_output(170, 0); 268 gpio_set_value(170, 1); 269 break; 270 case REVISION_XM_B: 271 case REVISION_XM_C: 272 default: 273 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3) 274 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6) 275 276 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1); 277 val |= 4; 278 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1); 279 280 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1); 281 val |= 4; 282 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1); 283 break; 284 } 285 } 286 287 /* 288 * Routine: misc_init_r 289 * Description: Configure board specific parts 290 */ 291 int misc_init_r(void) 292 { 293 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE; 294 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE; 295 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE; 296 297 /* Enable i2c2 pullup resisters */ 298 writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1); 299 300 switch (get_board_revision()) { 301 case REVISION_AXBX: 302 printf("Beagle Rev Ax/Bx\n"); 303 setenv("beaglerev", "AxBx"); 304 break; 305 case REVISION_CX: 306 printf("Beagle Rev C1/C2/C3\n"); 307 setenv("beaglerev", "Cx"); 308 MUX_BEAGLE_C(); 309 break; 310 case REVISION_C4: 311 printf("Beagle Rev C4\n"); 312 setenv("beaglerev", "C4"); 313 MUX_BEAGLE_C(); 314 /* Set VAUX2 to 1.8V for EHCI PHY */ 315 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 316 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 317 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 318 TWL4030_PM_RECEIVER_DEV_GRP_P1); 319 break; 320 case REVISION_XM_A: 321 printf("Beagle xM Rev A\n"); 322 setenv("beaglerev", "xMA"); 323 MUX_BEAGLE_XM(); 324 /* Set VAUX2 to 1.8V for EHCI PHY */ 325 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 326 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 327 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 328 TWL4030_PM_RECEIVER_DEV_GRP_P1); 329 break; 330 case REVISION_XM_B: 331 printf("Beagle xM Rev B\n"); 332 setenv("beaglerev", "xMB"); 333 MUX_BEAGLE_XM(); 334 /* Set VAUX2 to 1.8V for EHCI PHY */ 335 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 336 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 337 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 338 TWL4030_PM_RECEIVER_DEV_GRP_P1); 339 break; 340 case REVISION_XM_C: 341 printf("Beagle xM Rev C\n"); 342 setenv("beaglerev", "xMC"); 343 MUX_BEAGLE_XM(); 344 /* Set VAUX2 to 1.8V for EHCI PHY */ 345 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED, 346 TWL4030_PM_RECEIVER_VAUX2_VSEL_18, 347 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP, 348 TWL4030_PM_RECEIVER_DEV_GRP_P1); 349 break; 350 default: 351 printf("Beagle unknown 0x%02x\n", get_board_revision()); 352 MUX_BEAGLE_XM(); 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 } 359 360 switch (get_expansion_id()) { 361 case TINCANTOOLS_ZIPPY: 362 printf("Recognized Tincantools Zippy board (rev %d %s)\n", 363 expansion_config.revision, 364 expansion_config.fab_revision); 365 MUX_TINCANTOOLS_ZIPPY(); 366 setenv("buddy", "zippy"); 367 break; 368 case TINCANTOOLS_ZIPPY2: 369 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n", 370 expansion_config.revision, 371 expansion_config.fab_revision); 372 MUX_TINCANTOOLS_ZIPPY(); 373 setenv("buddy", "zippy2"); 374 break; 375 case TINCANTOOLS_TRAINER: 376 printf("Recognized Tincantools Trainer board (rev %d %s)\n", 377 expansion_config.revision, 378 expansion_config.fab_revision); 379 MUX_TINCANTOOLS_ZIPPY(); 380 MUX_TINCANTOOLS_TRAINER(); 381 setenv("buddy", "trainer"); 382 break; 383 case TINCANTOOLS_SHOWDOG: 384 printf("Recognized Tincantools Showdow board (rev %d %s)\n", 385 expansion_config.revision, 386 expansion_config.fab_revision); 387 /* Place holder for DSS2 definition for showdog lcd */ 388 setenv("defaultdisplay", "showdoglcd"); 389 setenv("buddy", "showdog"); 390 break; 391 case KBADC_BEAGLEFPGA: 392 printf("Recognized KBADC Beagle FPGA board\n"); 393 MUX_KBADC_BEAGLEFPGA(); 394 setenv("buddy", "beaglefpga"); 395 break; 396 case LW_BEAGLETOUCH: 397 printf("Recognized Liquidware BeagleTouch board\n"); 398 setenv("buddy", "beagletouch"); 399 break; 400 case BRAINMUX_LCDOG: 401 printf("Recognized Brainmux LCDog board\n"); 402 setenv("buddy", "lcdog"); 403 break; 404 case BRAINMUX_LCDOGTOUCH: 405 printf("Recognized Brainmux LCDog Touch board\n"); 406 setenv("buddy", "lcdogtouch"); 407 break; 408 case BBTOYS_WIFI: 409 printf("Recognized BeagleBoardToys WiFi board\n"); 410 MUX_BBTOYS_WIFI() 411 setenv("buddy", "bbtoys-wifi"); 412 break;; 413 case BBTOYS_VGA: 414 printf("Recognized BeagleBoardToys VGA board\n"); 415 break;; 416 case BBTOYS_LCD: 417 printf("Recognized BeagleBoardToys LCD board\n"); 418 break;; 419 case BCT_BRETTL3: 420 printf("Recognized bct electronic GmbH brettl3 board\n"); 421 break; 422 case BEAGLE_NO_EEPROM: 423 printf("No EEPROM on expansion board\n"); 424 setenv("buddy", "none"); 425 break; 426 default: 427 printf("Unrecognized expansion board: %x\n", 428 expansion_config.device_vendor); 429 setenv("buddy", "unknown"); 430 } 431 432 if (expansion_config.content == 1) 433 setenv(expansion_config.env_var, expansion_config.env_setting); 434 435 twl4030_power_init(); 436 switch (get_board_revision()) { 437 case REVISION_XM_A: 438 case REVISION_XM_B: 439 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON); 440 break; 441 default: 442 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON); 443 break; 444 } 445 446 /* Set GPIO states before they are made outputs */ 447 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1, 448 &gpio6_base->setdataout); 449 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 | 450 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout); 451 452 /* Configure GPIOs to output */ 453 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe); 454 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 | 455 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe); 456 457 dieid_num_r(); 458 459 beagle_dvi_pup(); 460 beagle_display_init(); 461 omap3_dss_enable(); 462 463 return 0; 464 } 465 466 /* 467 * Routine: set_muxconf_regs 468 * Description: Setting up the configuration Mux registers specific to the 469 * hardware. Many pins need to be moved from protect to primary 470 * mode. 471 */ 472 void set_muxconf_regs(void) 473 { 474 MUX_BEAGLE(); 475 } 476 477 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD) 478 int board_mmc_init(bd_t *bis) 479 { 480 omap_mmc_init(0, 0, 0); 481 return 0; 482 } 483 #endif 484 485 #ifdef CONFIG_USB_EHCI 486 /* Call usb_stop() before starting the kernel */ 487 void show_boot_progress(int val) 488 { 489 if (val == BOOTSTAGE_ID_RUN_OS) 490 usb_stop(); 491 } 492 493 static struct omap_usbhs_board_data usbhs_bdata = { 494 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, 495 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, 496 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED 497 }; 498 499 int ehci_hcd_init(void) 500 { 501 return omap_ehci_hcd_init(&usbhs_bdata); 502 } 503 504 int ehci_hcd_stop(void) 505 { 506 return omap_ehci_hcd_stop(); 507 } 508 509 #endif /* CONFIG_USB_EHCI */ 510