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+
17 #ifdef CONFIG_STATUS_LED
18 #include <status_led.h>
21 #include <linux/mtd/nand.h>
23 #include <asm/arch/mmc_host_def.h>
24 #include <asm/arch/mux.h>
25 #include <asm/arch/mem.h>
26 #include <asm/arch/sys_proto.h>
28 #include <asm/mach-types.h>
29 #include <asm/omap_musb.h>
30 #include <asm/errno.h>
31 #include <linux/usb/ch9.h>
32 #include <linux/usb/gadget.h>
33 #include <linux/usb/musb.h>
37 #ifdef CONFIG_USB_EHCI
39 #include <asm/ehci-omap.h>
42 #define TWL4030_I2C_BUS 0
43 #define EXPANSION_EEPROM_I2C_BUS 1
44 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
46 #define TINCANTOOLS_ZIPPY 0x01000100
47 #define TINCANTOOLS_ZIPPY2 0x02000100
48 #define TINCANTOOLS_TRAINER 0x04000100
49 #define TINCANTOOLS_SHOWDOG 0x03000100
50 #define KBADC_BEAGLEFPGA 0x01000600
51 #define LW_BEAGLETOUCH 0x01000700
52 #define BRAINMUX_LCDOG 0x01000800
53 #define BRAINMUX_LCDOGTOUCH 0x02000800
54 #define BBTOYS_WIFI 0x01000B00
55 #define BBTOYS_VGA 0x02000B00
56 #define BBTOYS_LCD 0x03000B00
57 #define BCT_BRETTL3 0x01000F00
58 #define BCT_BRETTL4 0x02000F00
59 #define LSR_COM6L_ADPT 0x01001300
60 #define BEAGLE_NO_EEPROM 0xffffffff
62 DECLARE_GLOBAL_DATA_PTR;
65 unsigned int device_vendor;
66 unsigned char revision;
67 unsigned char content;
75 * Description: Early hardware init.
79 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
80 /* board id for Linux */
81 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
83 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
85 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
86 status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
93 * Routine: get_board_revision
94 * Description: Detect if we are running on a Beagle revision Ax/Bx,
95 * C1/2/3, C4, xM Ax/Bx or xM Cx. This can be done by reading
96 * the level of GPIO173, GPIO172 and GPIO171. This should
98 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
99 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
100 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
101 * GPIO173, GPIO172, GPIO171: 0 1 0 => xM Cx
102 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx
104 static int get_board_revision(void)
108 if (!gpio_request(171, "") &&
109 !gpio_request(172, "") &&
110 !gpio_request(173, "")) {
112 gpio_direction_input(171);
113 gpio_direction_input(172);
114 gpio_direction_input(173);
116 revision = gpio_get_value(173) << 2 |
117 gpio_get_value(172) << 1 |
120 printf("Error: unable to acquire board revision GPIOs\n");
127 #ifdef CONFIG_SPL_BUILD
129 * Routine: get_board_mem_timings
130 * Description: If we use SPL then there is no x-loader nor config header
131 * so we have to setup the DDR timings ourself on both banks.
133 void get_board_mem_timings(struct board_sdrc_timings *timings)
138 * We need to identify what PoP memory is on the board so that
139 * we know what timings to use. If we can't identify it then
140 * we know it's an xM. To map the ID values please see nand_ids.c
142 identify_nand_chip(&pop_mfr, &pop_id);
144 timings->mr = MICRON_V_MR_165;
145 switch (get_board_revision()) {
147 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
149 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
150 timings->ctrla = NUMONYX_V_ACTIMA_165;
151 timings->ctrlb = NUMONYX_V_ACTIMB_165;
152 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
154 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
155 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
156 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
157 timings->ctrla = MICRON_V_ACTIMA_165;
158 timings->ctrlb = MICRON_V_ACTIMB_165;
159 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
161 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
162 /* Beagleboard Rev C5, 256MB DDR */
163 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
164 timings->ctrla = MICRON_V_ACTIMA_200;
165 timings->ctrlb = MICRON_V_ACTIMB_200;
166 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
173 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
174 timings->ctrla = MICRON_V_ACTIMA_200;
175 timings->ctrlb = MICRON_V_ACTIMB_200;
176 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
179 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
180 timings->ctrla = NUMONYX_V_ACTIMA_165;
181 timings->ctrlb = NUMONYX_V_ACTIMB_165;
182 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
186 /* Assume 128MB and Micron/165MHz timings to be safe */
187 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
188 timings->ctrla = MICRON_V_ACTIMA_165;
189 timings->ctrlb = MICRON_V_ACTIMB_165;
190 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
196 * Routine: get_expansion_id
197 * Description: This function checks for expansion board by checking I2C
198 * bus 1 for the availability of an AT24C01B serial EEPROM.
199 * returns the device_vendor field from the EEPROM
201 static unsigned int get_expansion_id(void)
203 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
205 /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
206 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
207 i2c_set_bus_num(TWL4030_I2C_BUS);
208 return BEAGLE_NO_EEPROM;
211 /* read configuration data */
212 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
213 sizeof(expansion_config));
215 /* retry reading configuration data with 16bit addressing */
216 if ((expansion_config.device_vendor == 0xFFFFFF00) ||
217 (expansion_config.device_vendor == 0xFFFFFFFF)) {
218 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
219 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
220 sizeof(expansion_config));
223 i2c_set_bus_num(TWL4030_I2C_BUS);
225 return expansion_config.device_vendor;
228 #ifdef CONFIG_VIDEO_OMAP3
230 * Configure DSS to display background color on DVID
231 * Configure VENC to display color bar on S-Video
233 static void beagle_display_init(void)
235 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
236 switch (get_board_revision()) {
240 omap3_dss_panel_config(&dvid_cfg);
245 omap3_dss_panel_config(&dvid_cfg_xm);
253 static void beagle_dvi_pup(void)
257 switch (get_board_revision()) {
261 gpio_request(170, "");
262 gpio_direction_output(170, 0);
263 gpio_set_value(170, 1);
268 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
269 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
271 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
273 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
275 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
277 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
283 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
284 static struct musb_hdrc_config musb_config = {
291 static struct omap_musb_board_data musb_board_data = {
292 .interface_type = MUSB_INTERFACE_ULPI,
295 static struct musb_hdrc_platform_data musb_plat = {
296 #if defined(CONFIG_MUSB_HOST)
298 #elif defined(CONFIG_MUSB_GADGET)
299 .mode = MUSB_PERIPHERAL,
301 #error "Please define either CONFIG_MUSB_HOST or CONFIG_MUSB_GADGET"
303 .config = &musb_config,
305 .platform_ops = &omap2430_ops,
306 .board_data = &musb_board_data,
311 * Routine: misc_init_r
312 * Description: Configure board specific parts
314 int misc_init_r(void)
316 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
317 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
318 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
320 /* Enable i2c2 pullup resisters */
321 writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
323 switch (get_board_revision()) {
325 printf("Beagle Rev Ax/Bx\n");
326 setenv("beaglerev", "AxBx");
329 printf("Beagle Rev C1/C2/C3\n");
330 setenv("beaglerev", "Cx");
334 printf("Beagle Rev C4\n");
335 setenv("beaglerev", "C4");
337 /* Set VAUX2 to 1.8V for EHCI PHY */
338 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
339 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
340 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
341 TWL4030_PM_RECEIVER_DEV_GRP_P1);
344 printf("Beagle xM Rev A/B\n");
345 setenv("beaglerev", "xMAB");
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);
354 printf("Beagle xM Rev C\n");
355 setenv("beaglerev", "xMC");
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);
364 printf("Beagle unknown 0x%02x\n", get_board_revision());
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 switch (get_expansion_id()) {
374 case TINCANTOOLS_ZIPPY:
375 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
376 expansion_config.revision,
377 expansion_config.fab_revision);
378 MUX_TINCANTOOLS_ZIPPY();
379 setenv("buddy", "zippy");
381 case TINCANTOOLS_ZIPPY2:
382 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
383 expansion_config.revision,
384 expansion_config.fab_revision);
385 MUX_TINCANTOOLS_ZIPPY();
386 setenv("buddy", "zippy2");
388 case TINCANTOOLS_TRAINER:
389 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
390 expansion_config.revision,
391 expansion_config.fab_revision);
392 MUX_TINCANTOOLS_ZIPPY();
393 MUX_TINCANTOOLS_TRAINER();
394 setenv("buddy", "trainer");
396 case TINCANTOOLS_SHOWDOG:
397 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
398 expansion_config.revision,
399 expansion_config.fab_revision);
400 /* Place holder for DSS2 definition for showdog lcd */
401 setenv("defaultdisplay", "showdoglcd");
402 setenv("buddy", "showdog");
404 case KBADC_BEAGLEFPGA:
405 printf("Recognized KBADC Beagle FPGA board\n");
406 MUX_KBADC_BEAGLEFPGA();
407 setenv("buddy", "beaglefpga");
410 printf("Recognized Liquidware BeagleTouch board\n");
411 setenv("buddy", "beagletouch");
414 printf("Recognized Brainmux LCDog board\n");
415 setenv("buddy", "lcdog");
417 case BRAINMUX_LCDOGTOUCH:
418 printf("Recognized Brainmux LCDog Touch board\n");
419 setenv("buddy", "lcdogtouch");
422 printf("Recognized BeagleBoardToys WiFi board\n");
424 setenv("buddy", "bbtoys-wifi");
427 printf("Recognized BeagleBoardToys VGA board\n");
430 printf("Recognized BeagleBoardToys LCD board\n");
433 printf("Recognized bct electronic GmbH brettl3 board\n");
436 printf("Recognized bct electronic GmbH brettl4 board\n");
439 printf("Recognized LSR COM6L Adapter Board\n");
441 setenv("buddy", "lsr-com6l-adpt");
443 case BEAGLE_NO_EEPROM:
444 printf("No EEPROM on expansion board\n");
445 setenv("buddy", "none");
448 printf("Unrecognized expansion board: %x\n",
449 expansion_config.device_vendor);
450 setenv("buddy", "unknown");
453 if (expansion_config.content == 1)
454 setenv(expansion_config.env_var, expansion_config.env_setting);
456 twl4030_power_init();
457 switch (get_board_revision()) {
459 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
462 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
466 /* Set GPIO states before they are made outputs */
467 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
468 &gpio6_base->setdataout);
469 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
470 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
472 /* Configure GPIOs to output */
473 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
474 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
475 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
479 #ifdef CONFIG_VIDEO_OMAP3
481 beagle_display_init();
485 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
486 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
493 * Routine: set_muxconf_regs
494 * Description: Setting up the configuration Mux registers specific to the
495 * hardware. Many pins need to be moved from protect to primary
498 void set_muxconf_regs(void)
503 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
504 int board_mmc_init(bd_t *bis)
506 return omap_mmc_init(0, 0, 0, -1, -1);
510 #if defined(CONFIG_USB_EHCI) && !defined(CONFIG_SPL_BUILD)
511 /* Call usb_stop() before starting the kernel */
512 void show_boot_progress(int val)
514 if (val == BOOTSTAGE_ID_RUN_OS)
518 static struct omap_usbhs_board_data usbhs_bdata = {
519 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
520 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
521 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
524 int ehci_hcd_init(int index, enum usb_init_type init,
525 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
527 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
530 int ehci_hcd_stop(int index)
532 return omap_ehci_hcd_stop();
535 #endif /* CONFIG_USB_EHCI */
537 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)
538 int board_eth_init(bd_t *bis)
540 return usb_eth_initialize(bis);