xref: /openbmc/u-boot/board/ti/beagle/beagle.c (revision 1a4596601fd395f3afb8f82f3f840c5e00bdd57a)
1 /*
2  * (C) Copyright 2004-2011
3  * Texas Instruments, <www.ti.com>
4  *
5  * Author :
6  *	Sunil Kumar <sunilsaini05@gmail.com>
7  *	Shashi Ranjan <shashiranjanmca05@gmail.com>
8  *
9  * Derived from Beagle Board and 3430 SDP code by
10  *	Richard Woodruff <r-woodruff2@ti.com>
11  *	Syed Mohammed Khasim <khasim@ti.com>
12  *
13  *
14  * SPDX-License-Identifier:	GPL-2.0+
15  */
16 #include <common.h>
17 #ifdef CONFIG_STATUS_LED
18 #include <status_led.h>
19 #endif
20 #include <twl4030.h>
21 #include <linux/mtd/nand.h>
22 #include <asm/io.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>
27 #include <asm/gpio.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>
34 #include "beagle.h"
35 #include <command.h>
36 
37 #ifdef CONFIG_USB_EHCI
38 #include <usb.h>
39 #include <asm/ehci-omap.h>
40 #endif
41 
42 #define TWL4030_I2C_BUS			0
43 #define EXPANSION_EEPROM_I2C_BUS	1
44 #define EXPANSION_EEPROM_I2C_ADDRESS	0x50
45 
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
61 
62 DECLARE_GLOBAL_DATA_PTR;
63 
64 static struct {
65 	unsigned int device_vendor;
66 	unsigned char revision;
67 	unsigned char content;
68 	char fab_revision[8];
69 	char env_var[16];
70 	char env_setting[64];
71 } expansion_config;
72 
73 /*
74  * Routine: board_init
75  * Description: Early hardware init.
76  */
77 int board_init(void)
78 {
79 	gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
80 	/* board id for Linux */
81 	gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
82 	/* boot param addr */
83 	gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
84 
85 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
86 	status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
87 #endif
88 
89 	return 0;
90 }
91 
92 /*
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
97  *		result in
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
103  */
104 static int get_board_revision(void)
105 {
106 	int revision;
107 
108 	if (!gpio_request(171, "") &&
109 	    !gpio_request(172, "") &&
110 	    !gpio_request(173, "")) {
111 
112 		gpio_direction_input(171);
113 		gpio_direction_input(172);
114 		gpio_direction_input(173);
115 
116 		revision = gpio_get_value(173) << 2 |
117 			   gpio_get_value(172) << 1 |
118 			   gpio_get_value(171);
119 	} else {
120 		printf("Error: unable to acquire board revision GPIOs\n");
121 		revision = -1;
122 	}
123 
124 	return revision;
125 }
126 
127 #ifdef CONFIG_SPL_BUILD
128 /*
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.
132  */
133 void get_board_mem_timings(struct board_sdrc_timings *timings)
134 {
135 	int pop_mfr, pop_id;
136 
137 	/*
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
141 	 */
142 	identify_nand_chip(&pop_mfr, &pop_id);
143 
144 	timings->mr = MICRON_V_MR_165;
145 	switch (get_board_revision()) {
146 	case REVISION_C4:
147 		if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
148 			/* 512MB DDR */
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;
153 			break;
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;
160 			break;
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;
167 			break;
168 		}
169 	case REVISION_XM_A:
170 	case REVISION_XM_B:
171 	case REVISION_XM_C:
172 		if (pop_mfr == 0) {
173 			/* 256MB DDR */
174 			timings->mcfg = MICRON_V_MCFG_200(256 << 20);
175 			timings->ctrla = MICRON_V_ACTIMA_200;
176 			timings->ctrlb = MICRON_V_ACTIMB_200;
177 			timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
178 		} else {
179 			/* 512MB DDR */
180 			timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
181 			timings->ctrla = NUMONYX_V_ACTIMA_165;
182 			timings->ctrlb = NUMONYX_V_ACTIMB_165;
183 			timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
184 		}
185 		break;
186 	default:
187 		/* Assume 128MB and Micron/165MHz timings to be safe */
188 		timings->mcfg = MICRON_V_MCFG_165(128 << 20);
189 		timings->ctrla = MICRON_V_ACTIMA_165;
190 		timings->ctrlb = MICRON_V_ACTIMB_165;
191 		timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
192 	}
193 }
194 #endif
195 
196 /*
197  * Routine: get_expansion_id
198  * Description: This function checks for expansion board by checking I2C
199  *		bus 1 for the availability of an AT24C01B serial EEPROM.
200  *		returns the device_vendor field from the EEPROM
201  */
202 static unsigned int get_expansion_id(void)
203 {
204 	i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
205 
206 	/* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
207 	if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
208 		i2c_set_bus_num(TWL4030_I2C_BUS);
209 		return BEAGLE_NO_EEPROM;
210 	}
211 
212 	/* read configuration data */
213 	i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
214 		 sizeof(expansion_config));
215 
216 	/* retry reading configuration data with 16bit addressing */
217 	if ((expansion_config.device_vendor == 0xFFFFFF00) ||
218 	    (expansion_config.device_vendor == 0xFFFFFFFF)) {
219 		printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
220 		i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
221 			 sizeof(expansion_config));
222 	}
223 
224 	i2c_set_bus_num(TWL4030_I2C_BUS);
225 
226 	return expansion_config.device_vendor;
227 }
228 
229 #ifdef CONFIG_VIDEO_OMAP3
230 /*
231  * Configure DSS to display background color on DVID
232  * Configure VENC to display color bar on S-Video
233  */
234 static void beagle_display_init(void)
235 {
236 	omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
237 	switch (get_board_revision()) {
238 	case REVISION_AXBX:
239 	case REVISION_CX:
240 	case REVISION_C4:
241 		omap3_dss_panel_config(&dvid_cfg);
242 		break;
243 	case REVISION_XM_A:
244 	case REVISION_XM_B:
245 	case REVISION_XM_C:
246 	default:
247 		omap3_dss_panel_config(&dvid_cfg_xm);
248 		break;
249 	}
250 }
251 
252 /*
253  * Enable DVI power
254  */
255 static void beagle_dvi_pup(void)
256 {
257 	uchar val;
258 
259 	switch (get_board_revision()) {
260 	case REVISION_AXBX:
261 	case REVISION_CX:
262 	case REVISION_C4:
263 	case REVISION_XM_A:
264 		gpio_request(170, "");
265 		gpio_direction_output(170, 0);
266 		gpio_set_value(170, 1);
267 		break;
268 	case REVISION_XM_B:
269 	case REVISION_XM_C:
270 	default:
271 		#define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
272 		#define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
273 
274 		i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
275 		val |= 4;
276 		i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
277 
278 		i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
279 		val |= 4;
280 		i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
281 		break;
282 	}
283 }
284 #endif
285 
286 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
287 static struct musb_hdrc_config musb_config = {
288 	.multipoint     = 1,
289 	.dyn_fifo       = 1,
290 	.num_eps        = 16,
291 	.ram_bits       = 12,
292 };
293 
294 static struct omap_musb_board_data musb_board_data = {
295 	.interface_type	= MUSB_INTERFACE_ULPI,
296 };
297 
298 static struct musb_hdrc_platform_data musb_plat = {
299 #if defined(CONFIG_MUSB_HOST)
300 	.mode           = MUSB_HOST,
301 #elif defined(CONFIG_MUSB_GADGET)
302 	.mode		= MUSB_PERIPHERAL,
303 #else
304 #error "Please define either CONFIG_MUSB_HOST or CONFIG_MUSB_GADGET"
305 #endif
306 	.config         = &musb_config,
307 	.power          = 100,
308 	.platform_ops	= &omap2430_ops,
309 	.board_data	= &musb_board_data,
310 };
311 #endif
312 
313 /*
314  * Routine: misc_init_r
315  * Description: Configure board specific parts
316  */
317 int misc_init_r(void)
318 {
319 	struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
320 	struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
321 	struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
322 
323 	/* Enable i2c2 pullup resisters */
324 	writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
325 
326 	switch (get_board_revision()) {
327 	case REVISION_AXBX:
328 		printf("Beagle Rev Ax/Bx\n");
329 		setenv("beaglerev", "AxBx");
330 		break;
331 	case REVISION_CX:
332 		printf("Beagle Rev C1/C2/C3\n");
333 		setenv("beaglerev", "Cx");
334 		MUX_BEAGLE_C();
335 		break;
336 	case REVISION_C4:
337 		printf("Beagle Rev C4\n");
338 		setenv("beaglerev", "C4");
339 		MUX_BEAGLE_C();
340 		/* Set VAUX2 to 1.8V for EHCI PHY */
341 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
342 					TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
343 					TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
344 					TWL4030_PM_RECEIVER_DEV_GRP_P1);
345 		break;
346 	case REVISION_XM_A:
347 		printf("Beagle xM Rev A\n");
348 		setenv("beaglerev", "xMA");
349 		MUX_BEAGLE_XM();
350 		/* Set VAUX2 to 1.8V for EHCI PHY */
351 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
352 					TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
353 					TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
354 					TWL4030_PM_RECEIVER_DEV_GRP_P1);
355 		break;
356 	case REVISION_XM_B:
357 		printf("Beagle xM Rev B\n");
358 		setenv("beaglerev", "xMB");
359 		MUX_BEAGLE_XM();
360 		/* Set VAUX2 to 1.8V for EHCI PHY */
361 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
362 					TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
363 					TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
364 					TWL4030_PM_RECEIVER_DEV_GRP_P1);
365 		break;
366 	case REVISION_XM_C:
367 		printf("Beagle xM Rev C\n");
368 		setenv("beaglerev", "xMC");
369 		MUX_BEAGLE_XM();
370 		/* Set VAUX2 to 1.8V for EHCI PHY */
371 		twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
372 					TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
373 					TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
374 					TWL4030_PM_RECEIVER_DEV_GRP_P1);
375 		break;
376 	default:
377 		printf("Beagle unknown 0x%02x\n", get_board_revision());
378 		MUX_BEAGLE_XM();
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 	}
385 
386 	switch (get_expansion_id()) {
387 	case TINCANTOOLS_ZIPPY:
388 		printf("Recognized Tincantools Zippy board (rev %d %s)\n",
389 			expansion_config.revision,
390 			expansion_config.fab_revision);
391 		MUX_TINCANTOOLS_ZIPPY();
392 		setenv("buddy", "zippy");
393 		break;
394 	case TINCANTOOLS_ZIPPY2:
395 		printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
396 			expansion_config.revision,
397 			expansion_config.fab_revision);
398 		MUX_TINCANTOOLS_ZIPPY();
399 		setenv("buddy", "zippy2");
400 		break;
401 	case TINCANTOOLS_TRAINER:
402 		printf("Recognized Tincantools Trainer board (rev %d %s)\n",
403 			expansion_config.revision,
404 			expansion_config.fab_revision);
405 		MUX_TINCANTOOLS_ZIPPY();
406 		MUX_TINCANTOOLS_TRAINER();
407 		setenv("buddy", "trainer");
408 		break;
409 	case TINCANTOOLS_SHOWDOG:
410 		printf("Recognized Tincantools Showdow board (rev %d %s)\n",
411 			expansion_config.revision,
412 			expansion_config.fab_revision);
413 		/* Place holder for DSS2 definition for showdog lcd */
414 		setenv("defaultdisplay", "showdoglcd");
415 		setenv("buddy", "showdog");
416 		break;
417 	case KBADC_BEAGLEFPGA:
418 		printf("Recognized KBADC Beagle FPGA board\n");
419 		MUX_KBADC_BEAGLEFPGA();
420 		setenv("buddy", "beaglefpga");
421 		break;
422 	case LW_BEAGLETOUCH:
423 		printf("Recognized Liquidware BeagleTouch board\n");
424 		setenv("buddy", "beagletouch");
425 		break;
426 	case BRAINMUX_LCDOG:
427 		printf("Recognized Brainmux LCDog board\n");
428 		setenv("buddy", "lcdog");
429 		break;
430 	case BRAINMUX_LCDOGTOUCH:
431 		printf("Recognized Brainmux LCDog Touch board\n");
432 		setenv("buddy", "lcdogtouch");
433 		break;
434 	case BBTOYS_WIFI:
435 		printf("Recognized BeagleBoardToys WiFi board\n");
436 		MUX_BBTOYS_WIFI()
437 		setenv("buddy", "bbtoys-wifi");
438 		break;;
439 	case BBTOYS_VGA:
440 		printf("Recognized BeagleBoardToys VGA board\n");
441 		break;;
442 	case BBTOYS_LCD:
443 		printf("Recognized BeagleBoardToys LCD board\n");
444 		break;;
445 	case BCT_BRETTL3:
446 		printf("Recognized bct electronic GmbH brettl3 board\n");
447 		break;
448 	case BCT_BRETTL4:
449 		printf("Recognized bct electronic GmbH brettl4 board\n");
450 		break;
451 	case LSR_COM6L_ADPT:
452 		printf("Recognized LSR COM6L Adapter Board\n");
453 		MUX_BBTOYS_WIFI()
454 		setenv("buddy", "lsr-com6l-adpt");
455 		break;
456 	case BEAGLE_NO_EEPROM:
457 		printf("No EEPROM on expansion board\n");
458 		setenv("buddy", "none");
459 		break;
460 	default:
461 		printf("Unrecognized expansion board: %x\n",
462 			expansion_config.device_vendor);
463 		setenv("buddy", "unknown");
464 	}
465 
466 	if (expansion_config.content == 1)
467 		setenv(expansion_config.env_var, expansion_config.env_setting);
468 
469 	twl4030_power_init();
470 	switch (get_board_revision()) {
471 	case REVISION_XM_A:
472 	case REVISION_XM_B:
473 		twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
474 		break;
475 	default:
476 		twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
477 		break;
478 	}
479 
480 	/* Set GPIO states before they are made outputs */
481 	writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
482 		&gpio6_base->setdataout);
483 	writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
484 		GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
485 
486 	/* Configure GPIOs to output */
487 	writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
488 	writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
489 		GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
490 
491 	dieid_num_r();
492 
493 #ifdef CONFIG_VIDEO_OMAP3
494 	beagle_dvi_pup();
495 	beagle_display_init();
496 	omap3_dss_enable();
497 #endif
498 
499 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
500 	musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
501 #endif
502 
503 	return 0;
504 }
505 
506 /*
507  * Routine: set_muxconf_regs
508  * Description: Setting up the configuration Mux registers specific to the
509  *		hardware. Many pins need to be moved from protect to primary
510  *		mode.
511  */
512 void set_muxconf_regs(void)
513 {
514 	MUX_BEAGLE();
515 }
516 
517 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
518 int board_mmc_init(bd_t *bis)
519 {
520 	return omap_mmc_init(0, 0, 0, -1, -1);
521 }
522 #endif
523 
524 #if defined(CONFIG_USB_EHCI) && !defined(CONFIG_SPL_BUILD)
525 /* Call usb_stop() before starting the kernel */
526 void show_boot_progress(int val)
527 {
528 	if (val == BOOTSTAGE_ID_RUN_OS)
529 		usb_stop();
530 }
531 
532 static struct omap_usbhs_board_data usbhs_bdata = {
533 	.port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
534 	.port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
535 	.port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
536 };
537 
538 int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
539 {
540 	return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
541 }
542 
543 int ehci_hcd_stop(int index)
544 {
545 	return omap_ehci_hcd_stop();
546 }
547 
548 #endif /* CONFIG_USB_EHCI */
549 
550 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)
551 int board_eth_init(bd_t *bis)
552 {
553 	return usb_eth_initialize(bis);
554 }
555 #endif
556