1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2004-2011
4 * Texas Instruments, <www.ti.com>
7 * Sunil Kumar <sunilsaini05@gmail.com>
8 * Shashi Ranjan <shashiranjanmca05@gmail.com>
10 * Derived from Beagle Board and 3430 SDP code by
11 * Richard Woodruff <r-woodruff2@ti.com>
12 * Syed Mohammed Khasim <khasim@ti.com>
16 #include <bootstage.h>
23 #ifdef CONFIG_LED_STATUS
24 #include <status_led.h>
27 #include <linux/mtd/rawnand.h>
29 #include <asm/arch/mmc_host_def.h>
30 #include <asm/arch/mux.h>
31 #include <asm/arch/mem.h>
32 #include <asm/arch/sys_proto.h>
34 #include <asm/mach-types.h>
35 #include <asm/omap_musb.h>
36 #include <linux/errno.h>
37 #include <linux/usb/ch9.h>
38 #include <linux/usb/gadget.h>
39 #include <linux/usb/musb.h>
43 #define TWL4030_I2C_BUS 0
44 #define EXPANSION_EEPROM_I2C_BUS 1
45 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
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
63 DECLARE_GLOBAL_DATA_PTR;
66 unsigned int device_vendor;
67 unsigned char revision;
68 unsigned char content;
76 * Description: Early hardware init.
80 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
81 /* board id for Linux */
82 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
84 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
86 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
87 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
93 #if defined(CONFIG_SPL_OS_BOOT)
94 int spl_start_uboot(void)
96 /* break into full u-boot on 'c' */
97 if (serial_tstc() && serial_getc() == 'c')
102 #endif /* CONFIG_SPL_OS_BOOT */
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
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
116 static int get_board_revision(void)
118 static int revision = -1;
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);
128 revision = gpio_get_value(173) << 2 |
129 gpio_get_value(172) << 1 |
132 printf("Error: unable to acquire board revision GPIOs\n");
139 #ifdef CONFIG_SPL_BUILD
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.
145 void get_board_mem_timings(struct board_sdrc_timings *timings)
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
154 identify_nand_chip(&pop_mfr, &pop_id);
156 timings->mr = MICRON_V_MR_165;
157 switch (get_board_revision()) {
159 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
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;
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;
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;
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;
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;
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;
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
213 static unsigned int get_expansion_id(void)
215 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
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;
223 /* read configuration data */
224 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
225 sizeof(expansion_config));
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));
235 i2c_set_bus_num(TWL4030_I2C_BUS);
237 return expansion_config.device_vendor;
240 #ifdef CONFIG_VIDEO_OMAP3
242 * Configure DSS to display background color on DVID
243 * Configure VENC to display color bar on S-Video
245 static void beagle_display_init(void)
247 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
248 switch (get_board_revision()) {
252 omap3_dss_panel_config(&dvid_cfg);
257 omap3_dss_panel_config(&dvid_cfg_xm);
265 static void beagle_dvi_pup(void)
269 switch (get_board_revision()) {
273 gpio_request(170, "dvi");
274 gpio_direction_output(170, 0);
275 gpio_set_value(170, 1);
280 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
281 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
283 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
285 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
287 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
289 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
296 * Routine: misc_init_r
297 * Description: Configure board specific parts
299 int misc_init_r(void)
301 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
302 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
303 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
304 bool generate_fake_mac = false;
307 /* Enable i2c2 pullup resisters */
308 value = readl(&prog_io_base->io1);
309 value &= ~(PRG_I2C2_PULLUPRESX);
310 writel(value, &prog_io_base->io1);
312 switch (get_board_revision()) {
314 printf("Beagle Rev Ax/Bx\n");
315 env_set("beaglerev", "AxBx");
318 printf("Beagle Rev C1/C2/C3\n");
319 env_set("beaglerev", "Cx");
323 printf("Beagle Rev C4\n");
324 env_set("beaglerev", "C4");
326 /* Set VAUX2 to 1.8V for EHCI PHY */
327 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
328 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
329 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
330 TWL4030_PM_RECEIVER_DEV_GRP_P1);
333 printf("Beagle xM Rev A/B\n");
334 env_set("beaglerev", "xMAB");
336 /* Set VAUX2 to 1.8V for EHCI PHY */
337 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
338 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
339 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
340 TWL4030_PM_RECEIVER_DEV_GRP_P1);
341 generate_fake_mac = true;
344 printf("Beagle xM Rev C\n");
345 env_set("beaglerev", "xMC");
347 /* Set VAUX2 to 1.8V for EHCI PHY */
348 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
349 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
350 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
351 TWL4030_PM_RECEIVER_DEV_GRP_P1);
352 generate_fake_mac = true;
355 printf("Beagle unknown 0x%02x\n", get_board_revision());
357 /* Set VAUX2 to 1.8V for EHCI PHY */
358 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
359 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
360 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
361 TWL4030_PM_RECEIVER_DEV_GRP_P1);
362 generate_fake_mac = true;
365 switch (get_expansion_id()) {
366 case TINCANTOOLS_ZIPPY:
367 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
368 expansion_config.revision,
369 expansion_config.fab_revision);
370 MUX_TINCANTOOLS_ZIPPY();
371 env_set("buddy", "zippy");
373 case TINCANTOOLS_ZIPPY2:
374 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
375 expansion_config.revision,
376 expansion_config.fab_revision);
377 MUX_TINCANTOOLS_ZIPPY();
378 env_set("buddy", "zippy2");
380 case TINCANTOOLS_TRAINER:
381 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
382 expansion_config.revision,
383 expansion_config.fab_revision);
384 MUX_TINCANTOOLS_ZIPPY();
385 MUX_TINCANTOOLS_TRAINER();
386 env_set("buddy", "trainer");
388 case TINCANTOOLS_SHOWDOG:
389 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
390 expansion_config.revision,
391 expansion_config.fab_revision);
392 /* Place holder for DSS2 definition for showdog lcd */
393 env_set("defaultdisplay", "showdoglcd");
394 env_set("buddy", "showdog");
396 case KBADC_BEAGLEFPGA:
397 printf("Recognized KBADC Beagle FPGA board\n");
398 MUX_KBADC_BEAGLEFPGA();
399 env_set("buddy", "beaglefpga");
402 printf("Recognized Liquidware BeagleTouch board\n");
403 env_set("buddy", "beagletouch");
406 printf("Recognized Brainmux LCDog board\n");
407 env_set("buddy", "lcdog");
409 case BRAINMUX_LCDOGTOUCH:
410 printf("Recognized Brainmux LCDog Touch board\n");
411 env_set("buddy", "lcdogtouch");
414 printf("Recognized BeagleBoardToys WiFi board\n");
416 env_set("buddy", "bbtoys-wifi");
419 printf("Recognized BeagleBoardToys VGA board\n");
422 printf("Recognized BeagleBoardToys LCD board\n");
425 printf("Recognized bct electronic GmbH brettl3 board\n");
428 printf("Recognized bct electronic GmbH brettl4 board\n");
431 printf("Recognized LSR COM6L Adapter Board\n");
433 env_set("buddy", "lsr-com6l-adpt");
435 case BEAGLE_NO_EEPROM:
436 printf("No EEPROM on expansion board\n");
437 env_set("buddy", "none");
440 printf("Unrecognized expansion board: %x\n",
441 expansion_config.device_vendor);
442 env_set("buddy", "unknown");
445 if (expansion_config.content == 1)
446 env_set(expansion_config.env_var, expansion_config.env_setting);
448 twl4030_power_init();
449 switch (get_board_revision()) {
451 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
454 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
458 /* Set GPIO states before they are made outputs */
459 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
460 &gpio6_base->setdataout);
461 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
462 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
464 /* Configure GPIOs to output */
465 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
466 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
467 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
469 omap_die_id_display();
471 #ifdef CONFIG_VIDEO_OMAP3
473 beagle_display_init();
477 if (generate_fake_mac)
478 omap_die_id_usbethaddr();
480 #if defined(CONFIG_MTDIDS_DEFAULT) && defined(CONFIG_MTDPARTS_DEFAULT)
481 if (strlen(CONFIG_MTDIDS_DEFAULT))
482 env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
484 if (strlen(CONFIG_MTDPARTS_DEFAULT))
485 env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
492 * Routine: set_muxconf_regs
493 * Description: Setting up the configuration Mux registers specific to the
494 * hardware. Many pins need to be moved from protect to primary
497 void set_muxconf_regs(void)
502 #if defined(CONFIG_MMC)
503 int board_mmc_init(bd_t *bis)
505 return omap_mmc_init(0, 0, 0, -1, -1);
509 #if defined(CONFIG_MMC)
510 void board_mmc_power_init(void)
512 twl4030_power_mmc_init(0);