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>
21 #ifdef CONFIG_LED_STATUS
22 #include <status_led.h>
25 #include <linux/mtd/rawnand.h>
27 #include <asm/arch/mmc_host_def.h>
28 #include <asm/arch/mux.h>
29 #include <asm/arch/mem.h>
30 #include <asm/arch/sys_proto.h>
32 #include <asm/mach-types.h>
33 #include <asm/omap_musb.h>
34 #include <linux/errno.h>
35 #include <linux/usb/ch9.h>
36 #include <linux/usb/gadget.h>
37 #include <linux/usb/musb.h>
41 #ifdef CONFIG_USB_EHCI_HCD
43 #include <asm/ehci-omap.h>
46 #define TWL4030_I2C_BUS 0
47 #define EXPANSION_EEPROM_I2C_BUS 1
48 #define EXPANSION_EEPROM_I2C_ADDRESS 0x50
50 #define TINCANTOOLS_ZIPPY 0x01000100
51 #define TINCANTOOLS_ZIPPY2 0x02000100
52 #define TINCANTOOLS_TRAINER 0x04000100
53 #define TINCANTOOLS_SHOWDOG 0x03000100
54 #define KBADC_BEAGLEFPGA 0x01000600
55 #define LW_BEAGLETOUCH 0x01000700
56 #define BRAINMUX_LCDOG 0x01000800
57 #define BRAINMUX_LCDOGTOUCH 0x02000800
58 #define BBTOYS_WIFI 0x01000B00
59 #define BBTOYS_VGA 0x02000B00
60 #define BBTOYS_LCD 0x03000B00
61 #define BCT_BRETTL3 0x01000F00
62 #define BCT_BRETTL4 0x02000F00
63 #define LSR_COM6L_ADPT 0x01001300
64 #define BEAGLE_NO_EEPROM 0xffffffff
66 DECLARE_GLOBAL_DATA_PTR;
69 unsigned int device_vendor;
70 unsigned char revision;
71 unsigned char content;
79 * Description: Early hardware init.
83 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
84 /* board id for Linux */
85 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
87 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
89 #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
90 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
96 #if defined(CONFIG_SPL_OS_BOOT)
97 int spl_start_uboot(void)
99 /* break into full u-boot on 'c' */
100 if (serial_tstc() && serial_getc() == 'c')
105 #endif /* CONFIG_SPL_OS_BOOT */
108 * Routine: get_board_revision
109 * Description: Detect if we are running on a Beagle revision Ax/Bx,
110 * C1/2/3, C4, xM Ax/Bx or xM Cx. This can be done by reading
111 * the level of GPIO173, GPIO172 and GPIO171. This should
113 * GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
114 * GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
115 * GPIO173, GPIO172, GPIO171: 1 0 1 => C4
116 * GPIO173, GPIO172, GPIO171: 0 1 0 => xM Cx
117 * GPIO173, GPIO172, GPIO171: 0 0 0 => xM Ax/Bx
119 static int get_board_revision(void)
121 static int revision = -1;
123 if (revision == -1) {
124 if (!gpio_request(171, "rev0") &&
125 !gpio_request(172, "rev1") &&
126 !gpio_request(173, "rev2")) {
127 gpio_direction_input(171);
128 gpio_direction_input(172);
129 gpio_direction_input(173);
131 revision = gpio_get_value(173) << 2 |
132 gpio_get_value(172) << 1 |
135 printf("Error: unable to acquire board revision GPIOs\n");
142 #ifdef CONFIG_SPL_BUILD
144 * Routine: get_board_mem_timings
145 * Description: If we use SPL then there is no x-loader nor config header
146 * so we have to setup the DDR timings ourself on both banks.
148 void get_board_mem_timings(struct board_sdrc_timings *timings)
153 * We need to identify what PoP memory is on the board so that
154 * we know what timings to use. If we can't identify it then
155 * we know it's an xM. To map the ID values please see nand_ids.c
157 identify_nand_chip(&pop_mfr, &pop_id);
159 timings->mr = MICRON_V_MR_165;
160 switch (get_board_revision()) {
162 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
164 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
165 timings->ctrla = NUMONYX_V_ACTIMA_165;
166 timings->ctrlb = NUMONYX_V_ACTIMB_165;
167 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
169 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
170 /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
171 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
172 timings->ctrla = MICRON_V_ACTIMA_165;
173 timings->ctrlb = MICRON_V_ACTIMB_165;
174 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
176 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
177 /* Beagleboard Rev C5, 256MB DDR */
178 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
179 timings->ctrla = MICRON_V_ACTIMA_200;
180 timings->ctrlb = MICRON_V_ACTIMB_200;
181 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
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;
194 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
195 timings->ctrla = NUMONYX_V_ACTIMA_165;
196 timings->ctrlb = NUMONYX_V_ACTIMB_165;
197 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
201 /* Assume 128MB and Micron/165MHz timings to be safe */
202 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
203 timings->ctrla = MICRON_V_ACTIMA_165;
204 timings->ctrlb = MICRON_V_ACTIMB_165;
205 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
211 * Routine: get_expansion_id
212 * Description: This function checks for expansion board by checking I2C
213 * bus 1 for the availability of an AT24C01B serial EEPROM.
214 * returns the device_vendor field from the EEPROM
216 static unsigned int get_expansion_id(void)
218 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
220 /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
221 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
222 i2c_set_bus_num(TWL4030_I2C_BUS);
223 return BEAGLE_NO_EEPROM;
226 /* read configuration data */
227 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
228 sizeof(expansion_config));
230 /* retry reading configuration data with 16bit addressing */
231 if ((expansion_config.device_vendor == 0xFFFFFF00) ||
232 (expansion_config.device_vendor == 0xFFFFFFFF)) {
233 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
234 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
235 sizeof(expansion_config));
238 i2c_set_bus_num(TWL4030_I2C_BUS);
240 return expansion_config.device_vendor;
243 #ifdef CONFIG_VIDEO_OMAP3
245 * Configure DSS to display background color on DVID
246 * Configure VENC to display color bar on S-Video
248 static void beagle_display_init(void)
250 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
251 switch (get_board_revision()) {
255 omap3_dss_panel_config(&dvid_cfg);
260 omap3_dss_panel_config(&dvid_cfg_xm);
268 static void beagle_dvi_pup(void)
272 switch (get_board_revision()) {
276 gpio_request(170, "dvi");
277 gpio_direction_output(170, 0);
278 gpio_set_value(170, 1);
283 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
284 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
286 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
288 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
290 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
292 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
298 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
299 static struct musb_hdrc_config musb_config = {
306 static struct omap_musb_board_data musb_board_data = {
307 .interface_type = MUSB_INTERFACE_ULPI,
310 static struct musb_hdrc_platform_data musb_plat = {
311 #if defined(CONFIG_USB_MUSB_HOST)
313 #elif defined(CONFIG_USB_MUSB_GADGET)
314 .mode = MUSB_PERIPHERAL,
316 #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
318 .config = &musb_config,
320 .platform_ops = &omap2430_ops,
321 .board_data = &musb_board_data,
326 * Routine: misc_init_r
327 * Description: Configure board specific parts
329 int misc_init_r(void)
331 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
332 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
333 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
334 bool generate_fake_mac = false;
337 /* Enable i2c2 pullup resisters */
338 value = readl(&prog_io_base->io1);
339 value &= ~(PRG_I2C2_PULLUPRESX);
340 writel(value, &prog_io_base->io1);
342 switch (get_board_revision()) {
344 printf("Beagle Rev Ax/Bx\n");
345 env_set("beaglerev", "AxBx");
348 printf("Beagle Rev C1/C2/C3\n");
349 env_set("beaglerev", "Cx");
353 printf("Beagle Rev C4\n");
354 env_set("beaglerev", "C4");
356 /* Set VAUX2 to 1.8V for EHCI PHY */
357 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
358 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
359 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
360 TWL4030_PM_RECEIVER_DEV_GRP_P1);
363 printf("Beagle xM Rev A/B\n");
364 env_set("beaglerev", "xMAB");
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);
371 generate_fake_mac = true;
374 printf("Beagle xM Rev C\n");
375 env_set("beaglerev", "xMC");
377 /* Set VAUX2 to 1.8V for EHCI PHY */
378 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
379 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
380 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
381 TWL4030_PM_RECEIVER_DEV_GRP_P1);
382 generate_fake_mac = true;
385 printf("Beagle unknown 0x%02x\n", get_board_revision());
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 switch (get_expansion_id()) {
396 case TINCANTOOLS_ZIPPY:
397 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
398 expansion_config.revision,
399 expansion_config.fab_revision);
400 MUX_TINCANTOOLS_ZIPPY();
401 env_set("buddy", "zippy");
403 case TINCANTOOLS_ZIPPY2:
404 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
405 expansion_config.revision,
406 expansion_config.fab_revision);
407 MUX_TINCANTOOLS_ZIPPY();
408 env_set("buddy", "zippy2");
410 case TINCANTOOLS_TRAINER:
411 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
412 expansion_config.revision,
413 expansion_config.fab_revision);
414 MUX_TINCANTOOLS_ZIPPY();
415 MUX_TINCANTOOLS_TRAINER();
416 env_set("buddy", "trainer");
418 case TINCANTOOLS_SHOWDOG:
419 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
420 expansion_config.revision,
421 expansion_config.fab_revision);
422 /* Place holder for DSS2 definition for showdog lcd */
423 env_set("defaultdisplay", "showdoglcd");
424 env_set("buddy", "showdog");
426 case KBADC_BEAGLEFPGA:
427 printf("Recognized KBADC Beagle FPGA board\n");
428 MUX_KBADC_BEAGLEFPGA();
429 env_set("buddy", "beaglefpga");
432 printf("Recognized Liquidware BeagleTouch board\n");
433 env_set("buddy", "beagletouch");
436 printf("Recognized Brainmux LCDog board\n");
437 env_set("buddy", "lcdog");
439 case BRAINMUX_LCDOGTOUCH:
440 printf("Recognized Brainmux LCDog Touch board\n");
441 env_set("buddy", "lcdogtouch");
444 printf("Recognized BeagleBoardToys WiFi board\n");
446 env_set("buddy", "bbtoys-wifi");
449 printf("Recognized BeagleBoardToys VGA board\n");
452 printf("Recognized BeagleBoardToys LCD board\n");
455 printf("Recognized bct electronic GmbH brettl3 board\n");
458 printf("Recognized bct electronic GmbH brettl4 board\n");
461 printf("Recognized LSR COM6L Adapter Board\n");
463 env_set("buddy", "lsr-com6l-adpt");
465 case BEAGLE_NO_EEPROM:
466 printf("No EEPROM on expansion board\n");
467 env_set("buddy", "none");
470 printf("Unrecognized expansion board: %x\n",
471 expansion_config.device_vendor);
472 env_set("buddy", "unknown");
475 if (expansion_config.content == 1)
476 env_set(expansion_config.env_var, expansion_config.env_setting);
478 twl4030_power_init();
479 switch (get_board_revision()) {
481 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
484 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
488 /* Set GPIO states before they are made outputs */
489 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
490 &gpio6_base->setdataout);
491 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
492 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
494 /* Configure GPIOs to output */
495 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
496 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
497 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
499 omap_die_id_display();
501 #ifdef CONFIG_VIDEO_OMAP3
503 beagle_display_init();
507 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
508 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
511 if (generate_fake_mac)
512 omap_die_id_usbethaddr();
514 #if defined(CONFIG_MTDIDS_DEFAULT) && defined(CONFIG_MTDPARTS_DEFAULT)
515 if (strlen(CONFIG_MTDIDS_DEFAULT))
516 env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
518 if (strlen(CONFIG_MTDPARTS_DEFAULT))
519 env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
526 * Routine: set_muxconf_regs
527 * Description: Setting up the configuration Mux registers specific to the
528 * hardware. Many pins need to be moved from protect to primary
531 void set_muxconf_regs(void)
536 #if defined(CONFIG_MMC)
537 int board_mmc_init(bd_t *bis)
539 return omap_mmc_init(0, 0, 0, -1, -1);
543 #if defined(CONFIG_MMC)
544 void board_mmc_power_init(void)
546 twl4030_power_mmc_init(0);
550 #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
551 /* Call usb_stop() before starting the kernel */
552 void show_boot_progress(int val)
554 if (val == BOOTSTAGE_ID_RUN_OS)
558 static struct omap_usbhs_board_data usbhs_bdata = {
559 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
560 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
561 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
564 int ehci_hcd_init(int index, enum usb_init_type init,
565 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
567 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
570 int ehci_hcd_stop(int index)
572 return omap_ehci_hcd_stop();
575 #endif /* CONFIG_USB_EHCI_HCD */
577 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
578 int board_eth_init(bd_t *bis)
580 return usb_eth_initialize(bis);