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/rawnand.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);
106 #if defined(CONFIG_SPL_OS_BOOT)
107 int spl_start_uboot(void)
109 /* break into full u-boot on 'c' */
110 if (serial_tstc() && serial_getc() == 'c')
115 #endif /* CONFIG_SPL_OS_BOOT */
118 * Routine: get_board_revision
119 * Description: Detect if we are running on a Beagle revision Ax/Bx,
120 * C1/2/3, C4, xM Ax/Bx or xM Cx. This can be done by reading
121 * the level of GPIO173, GPIO172 and GPIO171. This should
123 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
124 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
125 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
126 * GPIO173, GPIO172, GPIO171: 0 1 0 => xM Cx
127 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx
129 static int get_board_revision(void)
131 static int revision = -1;
133 if (revision == -1) {
134 if (!gpio_request(171, "rev0") &&
135 !gpio_request(172, "rev1") &&
136 !gpio_request(173, "rev2")) {
137 gpio_direction_input(171);
138 gpio_direction_input(172);
139 gpio_direction_input(173);
141 revision = gpio_get_value(173) << 2 |
142 gpio_get_value(172) << 1 |
145 printf("Error: unable to acquire board revision GPIOs\n");
152 #ifdef CONFIG_SPL_BUILD
154 * Routine: get_board_mem_timings
155 * Description: If we use SPL then there is no x-loader nor config header
156 * so we have to setup the DDR timings ourself on both banks.
158 void get_board_mem_timings(struct board_sdrc_timings *timings)
163 * We need to identify what PoP memory is on the board so that
164 * we know what timings to use. If we can't identify it then
165 * we know it's an xM. To map the ID values please see nand_ids.c
167 identify_nand_chip(&pop_mfr, &pop_id);
169 timings->mr = MICRON_V_MR_165;
170 switch (get_board_revision()) {
172 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
174 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
175 timings->ctrla = NUMONYX_V_ACTIMA_165;
176 timings->ctrlb = NUMONYX_V_ACTIMB_165;
177 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
179 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
180 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
181 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
182 timings->ctrla = MICRON_V_ACTIMA_165;
183 timings->ctrlb = MICRON_V_ACTIMB_165;
184 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
186 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
187 /* Beagleboard Rev C5, 256MB DDR */
188 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
189 timings->ctrla = MICRON_V_ACTIMA_200;
190 timings->ctrlb = MICRON_V_ACTIMB_200;
191 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
198 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
199 timings->ctrla = MICRON_V_ACTIMA_200;
200 timings->ctrlb = MICRON_V_ACTIMB_200;
201 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
204 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
205 timings->ctrla = NUMONYX_V_ACTIMA_165;
206 timings->ctrlb = NUMONYX_V_ACTIMB_165;
207 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
211 /* Assume 128MB and Micron/165MHz timings to be safe */
212 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
213 timings->ctrla = MICRON_V_ACTIMA_165;
214 timings->ctrlb = MICRON_V_ACTIMB_165;
215 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
221 * Routine: get_expansion_id
222 * Description: This function checks for expansion board by checking I2C
223 * bus 1 for the availability of an AT24C01B serial EEPROM.
224 * returns the device_vendor field from the EEPROM
226 static unsigned int get_expansion_id(void)
228 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
230 /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
231 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
232 i2c_set_bus_num(TWL4030_I2C_BUS);
233 return BEAGLE_NO_EEPROM;
236 /* read configuration data */
237 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
238 sizeof(expansion_config));
240 /* retry reading configuration data with 16bit addressing */
241 if ((expansion_config.device_vendor == 0xFFFFFF00) ||
242 (expansion_config.device_vendor == 0xFFFFFFFF)) {
243 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
244 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
245 sizeof(expansion_config));
248 i2c_set_bus_num(TWL4030_I2C_BUS);
250 return expansion_config.device_vendor;
253 #ifdef CONFIG_VIDEO_OMAP3
255 * Configure DSS to display background color on DVID
256 * Configure VENC to display color bar on S-Video
258 static void beagle_display_init(void)
260 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
261 switch (get_board_revision()) {
265 omap3_dss_panel_config(&dvid_cfg);
270 omap3_dss_panel_config(&dvid_cfg_xm);
278 static void beagle_dvi_pup(void)
282 switch (get_board_revision()) {
286 gpio_request(170, "dvi");
287 gpio_direction_output(170, 0);
288 gpio_set_value(170, 1);
293 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
294 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
296 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
298 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
300 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
302 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
308 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
309 static struct musb_hdrc_config musb_config = {
316 static struct omap_musb_board_data musb_board_data = {
317 .interface_type = MUSB_INTERFACE_ULPI,
320 static struct musb_hdrc_platform_data musb_plat = {
321 #if defined(CONFIG_USB_MUSB_HOST)
323 #elif defined(CONFIG_USB_MUSB_GADGET)
324 .mode = MUSB_PERIPHERAL,
326 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
328 .config = &musb_config,
330 .platform_ops = &omap2430_ops,
331 .board_data = &musb_board_data,
336 * Routine: misc_init_r
337 * Description: Configure board specific parts
339 int misc_init_r(void)
341 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
342 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
343 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
344 bool generate_fake_mac = false;
347 /* Enable i2c2 pullup resisters */
348 value = readl(&prog_io_base->io1);
349 value &= ~(PRG_I2C2_PULLUPRESX);
350 writel(value, &prog_io_base->io1);
352 switch (get_board_revision()) {
354 printf("Beagle Rev Ax/Bx\n");
355 env_set("beaglerev", "AxBx");
358 printf("Beagle Rev C1/C2/C3\n");
359 env_set("beaglerev", "Cx");
363 printf("Beagle Rev C4\n");
364 env_set("beaglerev", "C4");
366 /* Set VAUX2 to 1.8V for EHCI PHY */
367 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
368 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
369 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
370 TWL4030_PM_RECEIVER_DEV_GRP_P1);
373 printf("Beagle xM Rev A/B\n");
374 env_set("beaglerev", "xMAB");
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 xM Rev C\n");
385 env_set("beaglerev", "xMC");
387 /* Set VAUX2 to 1.8V for EHCI PHY */
388 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
389 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
390 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
391 TWL4030_PM_RECEIVER_DEV_GRP_P1);
392 generate_fake_mac = true;
395 printf("Beagle unknown 0x%02x\n", get_board_revision());
397 /* Set VAUX2 to 1.8V for EHCI PHY */
398 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
399 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
400 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
401 TWL4030_PM_RECEIVER_DEV_GRP_P1);
402 generate_fake_mac = true;
405 switch (get_expansion_id()) {
406 case TINCANTOOLS_ZIPPY:
407 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
408 expansion_config.revision,
409 expansion_config.fab_revision);
410 MUX_TINCANTOOLS_ZIPPY();
411 env_set("buddy", "zippy");
413 case TINCANTOOLS_ZIPPY2:
414 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
415 expansion_config.revision,
416 expansion_config.fab_revision);
417 MUX_TINCANTOOLS_ZIPPY();
418 env_set("buddy", "zippy2");
420 case TINCANTOOLS_TRAINER:
421 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
422 expansion_config.revision,
423 expansion_config.fab_revision);
424 MUX_TINCANTOOLS_ZIPPY();
425 MUX_TINCANTOOLS_TRAINER();
426 env_set("buddy", "trainer");
428 case TINCANTOOLS_SHOWDOG:
429 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
430 expansion_config.revision,
431 expansion_config.fab_revision);
432 /* Place holder for DSS2 definition for showdog lcd */
433 env_set("defaultdisplay", "showdoglcd");
434 env_set("buddy", "showdog");
436 case KBADC_BEAGLEFPGA:
437 printf("Recognized KBADC Beagle FPGA board\n");
438 MUX_KBADC_BEAGLEFPGA();
439 env_set("buddy", "beaglefpga");
442 printf("Recognized Liquidware BeagleTouch board\n");
443 env_set("buddy", "beagletouch");
446 printf("Recognized Brainmux LCDog board\n");
447 env_set("buddy", "lcdog");
449 case BRAINMUX_LCDOGTOUCH:
450 printf("Recognized Brainmux LCDog Touch board\n");
451 env_set("buddy", "lcdogtouch");
454 printf("Recognized BeagleBoardToys WiFi board\n");
456 env_set("buddy", "bbtoys-wifi");
459 printf("Recognized BeagleBoardToys VGA board\n");
462 printf("Recognized BeagleBoardToys LCD board\n");
465 printf("Recognized bct electronic GmbH brettl3 board\n");
468 printf("Recognized bct electronic GmbH brettl4 board\n");
471 printf("Recognized LSR COM6L Adapter Board\n");
473 env_set("buddy", "lsr-com6l-adpt");
475 case BEAGLE_NO_EEPROM:
476 printf("No EEPROM on expansion board\n");
477 env_set("buddy", "none");
480 printf("Unrecognized expansion board: %x\n",
481 expansion_config.device_vendor);
482 env_set("buddy", "unknown");
485 if (expansion_config.content == 1)
486 env_set(expansion_config.env_var, expansion_config.env_setting);
488 twl4030_power_init();
489 switch (get_board_revision()) {
491 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
494 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
498 /* Set GPIO states before they are made outputs */
499 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
500 &gpio6_base->setdataout);
501 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
502 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
504 /* Configure GPIOs to output */
505 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
506 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
507 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
509 omap_die_id_display();
511 #ifdef CONFIG_VIDEO_OMAP3
513 beagle_display_init();
517 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
518 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
521 if (generate_fake_mac)
522 omap_die_id_usbethaddr();
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);