2 * (C) Copyright 2004-2011
3 * Texas Instruments, <www.ti.com>
6 * Sunil Kumar <sunilsaini05@gmail.com>
7 * Shashi Ranjan <shashiranjanmca05@gmail.com>
9 * Derived from Beagle Board and 3430 SDP code by
10 * Richard Woodruff <r-woodruff2@ti.com>
11 * Syed Mohammed Khasim <khasim@ti.com>
14 * SPDX-License-Identifier: GPL-2.0+
19 #ifdef CONFIG_LED_STATUS
20 #include <status_led.h>
23 #include <linux/mtd/nand.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>
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>
39 #ifdef CONFIG_USB_EHCI_HCD
41 #include <asm/ehci-omap.h>
44 #define TWL4030_I2C_BUS 0
45 #define EXPANSION_EEPROM_I2C_BUS 1
46 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
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
64 DECLARE_GLOBAL_DATA_PTR;
67 unsigned int device_vendor;
68 unsigned char revision;
69 unsigned char content;
75 static const struct ns16550_platdata beagle_serial = {
76 .base = OMAP34XX_UART3,
78 .clock = V_NS16550_CLK,
79 .fcr = UART_FCR_DEFVAL,
82 U_BOOT_DEVICE(beagle_uart) = {
89 * Description: Early hardware init.
93 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
94 /* board id for Linux */
95 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
97 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
99 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
100 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
107 * Routine: get_board_revision
108 * Description: Detect if we are running on a Beagle revision Ax/Bx,
109 * C1/2/3, C4, xM Ax/Bx or xM Cx. This can be done by reading
110 * the level of GPIO173, GPIO172 and GPIO171. This should
112 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
113 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
114 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
115 * GPIO173, GPIO172, GPIO171: 0 1 0 => xM Cx
116 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx
118 static int get_board_revision(void)
120 static int revision = -1;
122 if (revision == -1) {
123 if (!gpio_request(171, "rev0") &&
124 !gpio_request(172, "rev1") &&
125 !gpio_request(173, "rev2")) {
126 gpio_direction_input(171);
127 gpio_direction_input(172);
128 gpio_direction_input(173);
130 revision = gpio_get_value(173) << 2 |
131 gpio_get_value(172) << 1 |
134 printf("Error: unable to acquire board revision GPIOs\n");
141 #ifdef CONFIG_SPL_BUILD
143 * Routine: get_board_mem_timings
144 * Description: If we use SPL then there is no x-loader nor config header
145 * so we have to setup the DDR timings ourself on both banks.
147 void get_board_mem_timings(struct board_sdrc_timings *timings)
152 * We need to identify what PoP memory is on the board so that
153 * we know what timings to use. If we can't identify it then
154 * we know it's an xM. To map the ID values please see nand_ids.c
156 identify_nand_chip(&pop_mfr, &pop_id);
158 timings->mr = MICRON_V_MR_165;
159 switch (get_board_revision()) {
161 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
163 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
164 timings->ctrla = NUMONYX_V_ACTIMA_165;
165 timings->ctrlb = NUMONYX_V_ACTIMB_165;
166 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
168 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
169 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
170 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
171 timings->ctrla = MICRON_V_ACTIMA_165;
172 timings->ctrlb = MICRON_V_ACTIMB_165;
173 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
175 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
176 /* Beagleboard Rev C5, 256MB DDR */
177 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
178 timings->ctrla = MICRON_V_ACTIMA_200;
179 timings->ctrlb = MICRON_V_ACTIMB_200;
180 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
187 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
188 timings->ctrla = MICRON_V_ACTIMA_200;
189 timings->ctrlb = MICRON_V_ACTIMB_200;
190 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
193 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
194 timings->ctrla = NUMONYX_V_ACTIMA_165;
195 timings->ctrlb = NUMONYX_V_ACTIMB_165;
196 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
200 /* Assume 128MB and Micron/165MHz timings to be safe */
201 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
202 timings->ctrla = MICRON_V_ACTIMA_165;
203 timings->ctrlb = MICRON_V_ACTIMB_165;
204 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
210 * Routine: get_expansion_id
211 * Description: This function checks for expansion board by checking I2C
212 * bus 1 for the availability of an AT24C01B serial EEPROM.
213 * returns the device_vendor field from the EEPROM
215 static unsigned int get_expansion_id(void)
217 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
219 /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
220 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
221 i2c_set_bus_num(TWL4030_I2C_BUS);
222 return BEAGLE_NO_EEPROM;
225 /* read configuration data */
226 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
227 sizeof(expansion_config));
229 /* retry reading configuration data with 16bit addressing */
230 if ((expansion_config.device_vendor == 0xFFFFFF00) ||
231 (expansion_config.device_vendor == 0xFFFFFFFF)) {
232 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
233 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
234 sizeof(expansion_config));
237 i2c_set_bus_num(TWL4030_I2C_BUS);
239 return expansion_config.device_vendor;
242 #ifdef CONFIG_VIDEO_OMAP3
244 * Configure DSS to display background color on DVID
245 * Configure VENC to display color bar on S-Video
247 static void beagle_display_init(void)
249 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
250 switch (get_board_revision()) {
254 omap3_dss_panel_config(&dvid_cfg);
259 omap3_dss_panel_config(&dvid_cfg_xm);
267 static void beagle_dvi_pup(void)
271 switch (get_board_revision()) {
275 gpio_request(170, "dvi");
276 gpio_direction_output(170, 0);
277 gpio_set_value(170, 1);
282 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
283 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
285 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
287 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
289 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
291 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
297 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
298 static struct musb_hdrc_config musb_config = {
305 static struct omap_musb_board_data musb_board_data = {
306 .interface_type = MUSB_INTERFACE_ULPI,
309 static struct musb_hdrc_platform_data musb_plat = {
310 #if defined(CONFIG_USB_MUSB_HOST)
312 #elif defined(CONFIG_USB_MUSB_GADGET)
313 .mode = MUSB_PERIPHERAL,
315 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
317 .config = &musb_config,
319 .platform_ops = &omap2430_ops,
320 .board_data = &musb_board_data,
325 * Routine: misc_init_r
326 * Description: Configure board specific parts
328 int misc_init_r(void)
330 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
331 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
332 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
333 bool generate_fake_mac = false;
336 /* Enable i2c2 pullup resisters */
337 value = readl(&prog_io_base->io1);
338 value &= ~(PRG_I2C2_PULLUPRESX);
339 writel(value, &prog_io_base->io1);
341 switch (get_board_revision()) {
343 printf("Beagle Rev Ax/Bx\n");
344 env_set("beaglerev", "AxBx");
347 printf("Beagle Rev C1/C2/C3\n");
348 env_set("beaglerev", "Cx");
352 printf("Beagle Rev C4\n");
353 env_set("beaglerev", "C4");
355 /* Set VAUX2 to 1.8V for EHCI PHY */
356 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
357 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
358 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
359 TWL4030_PM_RECEIVER_DEV_GRP_P1);
362 printf("Beagle xM Rev A/B\n");
363 env_set("beaglerev", "xMAB");
365 /* Set VAUX2 to 1.8V for EHCI PHY */
366 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
367 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
368 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
369 TWL4030_PM_RECEIVER_DEV_GRP_P1);
370 generate_fake_mac = true;
373 printf("Beagle xM Rev C\n");
374 env_set("beaglerev", "xMC");
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;
384 printf("Beagle unknown 0x%02x\n", get_board_revision());
386 /* Set VAUX2 to 1.8V for EHCI PHY */
387 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
388 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
389 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
390 TWL4030_PM_RECEIVER_DEV_GRP_P1);
391 generate_fake_mac = true;
394 switch (get_expansion_id()) {
395 case TINCANTOOLS_ZIPPY:
396 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
397 expansion_config.revision,
398 expansion_config.fab_revision);
399 MUX_TINCANTOOLS_ZIPPY();
400 env_set("buddy", "zippy");
402 case TINCANTOOLS_ZIPPY2:
403 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
404 expansion_config.revision,
405 expansion_config.fab_revision);
406 MUX_TINCANTOOLS_ZIPPY();
407 env_set("buddy", "zippy2");
409 case TINCANTOOLS_TRAINER:
410 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
411 expansion_config.revision,
412 expansion_config.fab_revision);
413 MUX_TINCANTOOLS_ZIPPY();
414 MUX_TINCANTOOLS_TRAINER();
415 env_set("buddy", "trainer");
417 case TINCANTOOLS_SHOWDOG:
418 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
419 expansion_config.revision,
420 expansion_config.fab_revision);
421 /* Place holder for DSS2 definition for showdog lcd */
422 env_set("defaultdisplay", "showdoglcd");
423 env_set("buddy", "showdog");
425 case KBADC_BEAGLEFPGA:
426 printf("Recognized KBADC Beagle FPGA board\n");
427 MUX_KBADC_BEAGLEFPGA();
428 env_set("buddy", "beaglefpga");
431 printf("Recognized Liquidware BeagleTouch board\n");
432 env_set("buddy", "beagletouch");
435 printf("Recognized Brainmux LCDog board\n");
436 env_set("buddy", "lcdog");
438 case BRAINMUX_LCDOGTOUCH:
439 printf("Recognized Brainmux LCDog Touch board\n");
440 env_set("buddy", "lcdogtouch");
443 printf("Recognized BeagleBoardToys WiFi board\n");
445 env_set("buddy", "bbtoys-wifi");
448 printf("Recognized BeagleBoardToys VGA board\n");
451 printf("Recognized BeagleBoardToys LCD board\n");
454 printf("Recognized bct electronic GmbH brettl3 board\n");
457 printf("Recognized bct electronic GmbH brettl4 board\n");
460 printf("Recognized LSR COM6L Adapter Board\n");
462 env_set("buddy", "lsr-com6l-adpt");
464 case BEAGLE_NO_EEPROM:
465 printf("No EEPROM on expansion board\n");
466 env_set("buddy", "none");
469 printf("Unrecognized expansion board: %x\n",
470 expansion_config.device_vendor);
471 env_set("buddy", "unknown");
474 if (expansion_config.content == 1)
475 env_set(expansion_config.env_var, expansion_config.env_setting);
477 twl4030_power_init();
478 switch (get_board_revision()) {
480 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
483 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
487 /* Set GPIO states before they are made outputs */
488 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
489 &gpio6_base->setdataout);
490 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
491 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
493 /* Configure GPIOs to output */
494 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
495 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
496 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
498 omap_die_id_display();
500 #ifdef CONFIG_VIDEO_OMAP3
502 beagle_display_init();
506 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
507 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
510 if (generate_fake_mac)
511 omap_die_id_usbethaddr();
517 * Routine: set_muxconf_regs
518 * Description: Setting up the configuration Mux registers specific to the
519 * hardware. Many pins need to be moved from protect to primary
522 void set_muxconf_regs(void)
527 #if defined(CONFIG_MMC)
528 int board_mmc_init(bd_t *bis)
530 return omap_mmc_init(0, 0, 0, -1, -1);
534 #if defined(CONFIG_MMC)
535 void board_mmc_power_init(void)
537 twl4030_power_mmc_init(0);
541 #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
542 /* Call usb_stop() before starting the kernel */
543 void show_boot_progress(int val)
545 if (val == BOOTSTAGE_ID_RUN_OS)
549 static struct omap_usbhs_board_data usbhs_bdata = {
550 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
551 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
552 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
555 int ehci_hcd_init(int index, enum usb_init_type init,
556 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
558 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
561 int ehci_hcd_stop(int index)
563 return omap_ehci_hcd_stop();
566 #endif /* CONFIG_USB_EHCI_HCD */
568 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
569 int board_eth_init(bd_t *bis)
571 return usb_eth_initialize(bis);