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 #ifdef CONFIG_USB_EHCI_HCD
45 #include <asm/ehci-omap.h>
48 #define TWL4030_I2C_BUS 0
49 #define EXPANSION_EEPROM_I2C_BUS 1
50 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
52 #define TINCANTOOLS_ZIPPY 0x01000100
53 #define TINCANTOOLS_ZIPPY2 0x02000100
54 #define TINCANTOOLS_TRAINER 0x04000100
55 #define TINCANTOOLS_SHOWDOG 0x03000100
56 #define KBADC_BEAGLEFPGA 0x01000600
57 #define LW_BEAGLETOUCH 0x01000700
58 #define BRAINMUX_LCDOG 0x01000800
59 #define BRAINMUX_LCDOGTOUCH 0x02000800
60 #define BBTOYS_WIFI 0x01000B00
61 #define BBTOYS_VGA 0x02000B00
62 #define BBTOYS_LCD 0x03000B00
63 #define BCT_BRETTL3 0x01000F00
64 #define BCT_BRETTL4 0x02000F00
65 #define LSR_COM6L_ADPT 0x01001300
66 #define BEAGLE_NO_EEPROM 0xffffffff
68 DECLARE_GLOBAL_DATA_PTR;
71 unsigned int device_vendor;
72 unsigned char revision;
73 unsigned char content;
81 * Description: Early hardware init.
85 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
86 /* board id for Linux */
87 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
89 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
91 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
92 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
98 #if defined(CONFIG_SPL_OS_BOOT)
99 int spl_start_uboot(void)
101 /* break into full u-boot on 'c' */
102 if (serial_tstc() && serial_getc() == 'c')
107 #endif /* CONFIG_SPL_OS_BOOT */
110 * Routine: get_board_revision
111 * Description: Detect if we are running on a Beagle revision Ax/Bx,
112 * C1/2/3, C4, xM Ax/Bx or xM Cx. This can be done by reading
113 * the level of GPIO173, GPIO172 and GPIO171. This should
115 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
116 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
117 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
118 * GPIO173, GPIO172, GPIO171: 0 1 0 => xM Cx
119 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx
121 static int get_board_revision(void)
123 static int revision = -1;
125 if (revision == -1) {
126 if (!gpio_request(171, "rev0") &&
127 !gpio_request(172, "rev1") &&
128 !gpio_request(173, "rev2")) {
129 gpio_direction_input(171);
130 gpio_direction_input(172);
131 gpio_direction_input(173);
133 revision = gpio_get_value(173) << 2 |
134 gpio_get_value(172) << 1 |
137 printf("Error: unable to acquire board revision GPIOs\n");
144 #ifdef CONFIG_SPL_BUILD
146 * Routine: get_board_mem_timings
147 * Description: If we use SPL then there is no x-loader nor config header
148 * so we have to setup the DDR timings ourself on both banks.
150 void get_board_mem_timings(struct board_sdrc_timings *timings)
155 * We need to identify what PoP memory is on the board so that
156 * we know what timings to use. If we can't identify it then
157 * we know it's an xM. To map the ID values please see nand_ids.c
159 identify_nand_chip(&pop_mfr, &pop_id);
161 timings->mr = MICRON_V_MR_165;
162 switch (get_board_revision()) {
164 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
166 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
167 timings->ctrla = NUMONYX_V_ACTIMA_165;
168 timings->ctrlb = NUMONYX_V_ACTIMB_165;
169 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
171 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
172 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
173 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
174 timings->ctrla = MICRON_V_ACTIMA_165;
175 timings->ctrlb = MICRON_V_ACTIMB_165;
176 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
178 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
179 /* Beagleboard Rev C5, 256MB DDR */
180 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
181 timings->ctrla = MICRON_V_ACTIMA_200;
182 timings->ctrlb = MICRON_V_ACTIMB_200;
183 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
190 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
191 timings->ctrla = MICRON_V_ACTIMA_200;
192 timings->ctrlb = MICRON_V_ACTIMB_200;
193 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
196 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
197 timings->ctrla = NUMONYX_V_ACTIMA_165;
198 timings->ctrlb = NUMONYX_V_ACTIMB_165;
199 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
203 /* Assume 128MB and Micron/165MHz timings to be safe */
204 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
205 timings->ctrla = MICRON_V_ACTIMA_165;
206 timings->ctrlb = MICRON_V_ACTIMB_165;
207 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
213 * Routine: get_expansion_id
214 * Description: This function checks for expansion board by checking I2C
215 * bus 1 for the availability of an AT24C01B serial EEPROM.
216 * returns the device_vendor field from the EEPROM
218 static unsigned int get_expansion_id(void)
220 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
222 /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
223 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
224 i2c_set_bus_num(TWL4030_I2C_BUS);
225 return BEAGLE_NO_EEPROM;
228 /* read configuration data */
229 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
230 sizeof(expansion_config));
232 /* retry reading configuration data with 16bit addressing */
233 if ((expansion_config.device_vendor == 0xFFFFFF00) ||
234 (expansion_config.device_vendor == 0xFFFFFFFF)) {
235 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
236 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
237 sizeof(expansion_config));
240 i2c_set_bus_num(TWL4030_I2C_BUS);
242 return expansion_config.device_vendor;
245 #ifdef CONFIG_VIDEO_OMAP3
247 * Configure DSS to display background color on DVID
248 * Configure VENC to display color bar on S-Video
250 static void beagle_display_init(void)
252 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
253 switch (get_board_revision()) {
257 omap3_dss_panel_config(&dvid_cfg);
262 omap3_dss_panel_config(&dvid_cfg_xm);
270 static void beagle_dvi_pup(void)
274 switch (get_board_revision()) {
278 gpio_request(170, "dvi");
279 gpio_direction_output(170, 0);
280 gpio_set_value(170, 1);
285 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
286 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
288 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
290 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
292 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
294 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
300 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
301 static struct musb_hdrc_config musb_config = {
308 static struct omap_musb_board_data musb_board_data = {
309 .interface_type = MUSB_INTERFACE_ULPI,
312 static struct musb_hdrc_platform_data musb_plat = {
313 #if defined(CONFIG_USB_MUSB_HOST)
315 #elif defined(CONFIG_USB_MUSB_GADGET)
316 .mode = MUSB_PERIPHERAL,
318 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
320 .config = &musb_config,
322 .platform_ops = &omap2430_ops,
323 .board_data = &musb_board_data,
328 * Routine: misc_init_r
329 * Description: Configure board specific parts
331 int misc_init_r(void)
333 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
334 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
335 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
336 bool generate_fake_mac = false;
339 /* Enable i2c2 pullup resisters */
340 value = readl(&prog_io_base->io1);
341 value &= ~(PRG_I2C2_PULLUPRESX);
342 writel(value, &prog_io_base->io1);
344 switch (get_board_revision()) {
346 printf("Beagle Rev Ax/Bx\n");
347 env_set("beaglerev", "AxBx");
350 printf("Beagle Rev C1/C2/C3\n");
351 env_set("beaglerev", "Cx");
355 printf("Beagle Rev C4\n");
356 env_set("beaglerev", "C4");
358 /* Set VAUX2 to 1.8V for EHCI PHY */
359 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
360 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
361 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
362 TWL4030_PM_RECEIVER_DEV_GRP_P1);
365 printf("Beagle xM Rev A/B\n");
366 env_set("beaglerev", "xMAB");
368 /* Set VAUX2 to 1.8V for EHCI PHY */
369 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
370 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
371 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
372 TWL4030_PM_RECEIVER_DEV_GRP_P1);
373 generate_fake_mac = true;
376 printf("Beagle xM Rev C\n");
377 env_set("beaglerev", "xMC");
379 /* Set VAUX2 to 1.8V for EHCI PHY */
380 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
381 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
382 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
383 TWL4030_PM_RECEIVER_DEV_GRP_P1);
384 generate_fake_mac = true;
387 printf("Beagle unknown 0x%02x\n", get_board_revision());
389 /* Set VAUX2 to 1.8V for EHCI PHY */
390 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
391 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
392 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
393 TWL4030_PM_RECEIVER_DEV_GRP_P1);
394 generate_fake_mac = true;
397 switch (get_expansion_id()) {
398 case TINCANTOOLS_ZIPPY:
399 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
400 expansion_config.revision,
401 expansion_config.fab_revision);
402 MUX_TINCANTOOLS_ZIPPY();
403 env_set("buddy", "zippy");
405 case TINCANTOOLS_ZIPPY2:
406 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
407 expansion_config.revision,
408 expansion_config.fab_revision);
409 MUX_TINCANTOOLS_ZIPPY();
410 env_set("buddy", "zippy2");
412 case TINCANTOOLS_TRAINER:
413 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
414 expansion_config.revision,
415 expansion_config.fab_revision);
416 MUX_TINCANTOOLS_ZIPPY();
417 MUX_TINCANTOOLS_TRAINER();
418 env_set("buddy", "trainer");
420 case TINCANTOOLS_SHOWDOG:
421 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
422 expansion_config.revision,
423 expansion_config.fab_revision);
424 /* Place holder for DSS2 definition for showdog lcd */
425 env_set("defaultdisplay", "showdoglcd");
426 env_set("buddy", "showdog");
428 case KBADC_BEAGLEFPGA:
429 printf("Recognized KBADC Beagle FPGA board\n");
430 MUX_KBADC_BEAGLEFPGA();
431 env_set("buddy", "beaglefpga");
434 printf("Recognized Liquidware BeagleTouch board\n");
435 env_set("buddy", "beagletouch");
438 printf("Recognized Brainmux LCDog board\n");
439 env_set("buddy", "lcdog");
441 case BRAINMUX_LCDOGTOUCH:
442 printf("Recognized Brainmux LCDog Touch board\n");
443 env_set("buddy", "lcdogtouch");
446 printf("Recognized BeagleBoardToys WiFi board\n");
448 env_set("buddy", "bbtoys-wifi");
451 printf("Recognized BeagleBoardToys VGA board\n");
454 printf("Recognized BeagleBoardToys LCD board\n");
457 printf("Recognized bct electronic GmbH brettl3 board\n");
460 printf("Recognized bct electronic GmbH brettl4 board\n");
463 printf("Recognized LSR COM6L Adapter Board\n");
465 env_set("buddy", "lsr-com6l-adpt");
467 case BEAGLE_NO_EEPROM:
468 printf("No EEPROM on expansion board\n");
469 env_set("buddy", "none");
472 printf("Unrecognized expansion board: %x\n",
473 expansion_config.device_vendor);
474 env_set("buddy", "unknown");
477 if (expansion_config.content == 1)
478 env_set(expansion_config.env_var, expansion_config.env_setting);
480 twl4030_power_init();
481 switch (get_board_revision()) {
483 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
486 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
490 /* Set GPIO states before they are made outputs */
491 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
492 &gpio6_base->setdataout);
493 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
494 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
496 /* Configure GPIOs to output */
497 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
498 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
499 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
501 omap_die_id_display();
503 #ifdef CONFIG_VIDEO_OMAP3
505 beagle_display_init();
509 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
510 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
513 if (generate_fake_mac)
514 omap_die_id_usbethaddr();
516 #if defined(CONFIG_MTDIDS_DEFAULT) && defined(CONFIG_MTDPARTS_DEFAULT)
517 if (strlen(CONFIG_MTDIDS_DEFAULT))
518 env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
520 if (strlen(CONFIG_MTDPARTS_DEFAULT))
521 env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
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
533 void set_muxconf_regs(void)
538 #if defined(CONFIG_MMC)
539 int board_mmc_init(bd_t *bis)
541 return omap_mmc_init(0, 0, 0, -1, -1);
545 #if defined(CONFIG_MMC)
546 void board_mmc_power_init(void)
548 twl4030_power_mmc_init(0);
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)
556 if (val == BOOTSTAGE_ID_RUN_OS)
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
566 int ehci_hcd_init(int index, enum usb_init_type init,
567 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
569 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
572 int ehci_hcd_stop(int index)
574 return omap_ehci_hcd_stop();
577 #endif /* CONFIG_USB_EHCI_HCD */
579 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
580 int board_eth_init(bd_t *bis)
582 return usb_eth_initialize(bis);