1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <common.h>
16#include <dm.h>
17#include <ns16550.h>
18#ifdef CONFIG_LED_STATUS
19#include <status_led.h>
20#endif
21#include <twl4030.h>
22#include <linux/mtd/rawnand.h>
23#include <asm/io.h>
24#include <asm/arch/mmc_host_def.h>
25#include <asm/arch/mux.h>
26#include <asm/arch/mem.h>
27#include <asm/arch/sys_proto.h>
28#include <asm/gpio.h>
29#include <asm/mach-types.h>
30#include <asm/omap_musb.h>
31#include <linux/errno.h>
32#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h>
34#include <linux/usb/musb.h>
35#include "beagle.h"
36#include <command.h>
37
38#ifdef CONFIG_USB_EHCI_HCD
39#include <usb.h>
40#include <asm/ehci-omap.h>
41#endif
42
43#define TWL4030_I2C_BUS 0
44#define EXPANSION_EEPROM_I2C_BUS 1
45#define EXPANSION_EEPROM_I2C_ADDRESS 0x50
46
47#define TINCANTOOLS_ZIPPY 0x01000100
48#define TINCANTOOLS_ZIPPY2 0x02000100
49#define TINCANTOOLS_TRAINER 0x04000100
50#define TINCANTOOLS_SHOWDOG 0x03000100
51#define KBADC_BEAGLEFPGA 0x01000600
52#define LW_BEAGLETOUCH 0x01000700
53#define BRAINMUX_LCDOG 0x01000800
54#define BRAINMUX_LCDOGTOUCH 0x02000800
55#define BBTOYS_WIFI 0x01000B00
56#define BBTOYS_VGA 0x02000B00
57#define BBTOYS_LCD 0x03000B00
58#define BCT_BRETTL3 0x01000F00
59#define BCT_BRETTL4 0x02000F00
60#define LSR_COM6L_ADPT 0x01001300
61#define BEAGLE_NO_EEPROM 0xffffffff
62
63DECLARE_GLOBAL_DATA_PTR;
64
65static struct {
66 unsigned int device_vendor;
67 unsigned char revision;
68 unsigned char content;
69 char fab_revision[8];
70 char env_var[16];
71 char env_setting[64];
72} expansion_config;
73
74static const struct ns16550_platdata beagle_serial = {
75 .base = OMAP34XX_UART3,
76 .reg_shift = 2,
77 .clock = V_NS16550_CLK,
78 .fcr = UART_FCR_DEFVAL,
79};
80
81U_BOOT_DEVICE(beagle_uart) = {
82 "ns16550_serial",
83 &beagle_serial
84};
85
86
87
88
89
90int board_init(void)
91{
92 gpmc_init();
93
94 gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
95
96 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
97
98#if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
99 status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
100#endif
101
102 return 0;
103}
104
105#if defined(CONFIG_SPL_OS_BOOT)
106int spl_start_uboot(void)
107{
108
109 if (serial_tstc() && serial_getc() == 'c')
110 return 1;
111
112 return 0;
113}
114#endif
115
116
117
118
119
120
121
122
123
124
125
126
127
128static int get_board_revision(void)
129{
130 static int revision = -1;
131
132 if (revision == -1) {
133 if (!gpio_request(171, "rev0") &&
134 !gpio_request(172, "rev1") &&
135 !gpio_request(173, "rev2")) {
136 gpio_direction_input(171);
137 gpio_direction_input(172);
138 gpio_direction_input(173);
139
140 revision = gpio_get_value(173) << 2 |
141 gpio_get_value(172) << 1 |
142 gpio_get_value(171);
143 } else {
144 printf("Error: unable to acquire board revision GPIOs\n");
145 }
146 }
147
148 return revision;
149}
150
151#ifdef CONFIG_SPL_BUILD
152
153
154
155
156
157void get_board_mem_timings(struct board_sdrc_timings *timings)
158{
159 int pop_mfr, pop_id;
160
161
162
163
164
165
166 identify_nand_chip(&pop_mfr, &pop_id);
167
168 timings->mr = MICRON_V_MR_165;
169 switch (get_board_revision()) {
170 case REVISION_C4:
171 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
172
173 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
174 timings->ctrla = NUMONYX_V_ACTIMA_165;
175 timings->ctrlb = NUMONYX_V_ACTIMB_165;
176 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
177 break;
178 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
179
180 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
181 timings->ctrla = MICRON_V_ACTIMA_165;
182 timings->ctrlb = MICRON_V_ACTIMB_165;
183 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
184 break;
185 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
186
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;
191 break;
192 }
193 case REVISION_XM_AB:
194 case REVISION_XM_C:
195 if (pop_mfr == 0) {
196
197 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
198 timings->ctrla = MICRON_V_ACTIMA_200;
199 timings->ctrlb = MICRON_V_ACTIMB_200;
200 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
201 } else {
202
203 timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
204 timings->ctrla = NUMONYX_V_ACTIMA_165;
205 timings->ctrlb = NUMONYX_V_ACTIMB_165;
206 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
207 }
208 break;
209 default:
210
211 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
212 timings->ctrla = MICRON_V_ACTIMA_165;
213 timings->ctrlb = MICRON_V_ACTIMB_165;
214 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
215 }
216}
217#endif
218
219
220
221
222
223
224
225static unsigned int get_expansion_id(void)
226{
227 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
228
229
230 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
231 i2c_set_bus_num(TWL4030_I2C_BUS);
232 return BEAGLE_NO_EEPROM;
233 }
234
235
236 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
237 sizeof(expansion_config));
238
239
240 if ((expansion_config.device_vendor == 0xFFFFFF00) ||
241 (expansion_config.device_vendor == 0xFFFFFFFF)) {
242 printf("EEPROM is blank or 8bit addressing failed: retrying with 16bit:\n");
243 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 2, (u8 *)&expansion_config,
244 sizeof(expansion_config));
245 }
246
247 i2c_set_bus_num(TWL4030_I2C_BUS);
248
249 return expansion_config.device_vendor;
250}
251
252#ifdef CONFIG_VIDEO_OMAP3
253
254
255
256
257static void beagle_display_init(void)
258{
259 omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
260 switch (get_board_revision()) {
261 case REVISION_AXBX:
262 case REVISION_CX:
263 case REVISION_C4:
264 omap3_dss_panel_config(&dvid_cfg);
265 break;
266 case REVISION_XM_AB:
267 case REVISION_XM_C:
268 default:
269 omap3_dss_panel_config(&dvid_cfg_xm);
270 break;
271 }
272}
273
274
275
276
277static void beagle_dvi_pup(void)
278{
279 uchar val;
280
281 switch (get_board_revision()) {
282 case REVISION_AXBX:
283 case REVISION_CX:
284 case REVISION_C4:
285 gpio_request(170, "dvi");
286 gpio_direction_output(170, 0);
287 gpio_set_value(170, 1);
288 break;
289 case REVISION_XM_AB:
290 case REVISION_XM_C:
291 default:
292 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
293 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
294
295 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
296 val |= 4;
297 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
298
299 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
300 val |= 4;
301 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
302 break;
303 }
304}
305#endif
306
307#ifdef CONFIG_USB_MUSB_OMAP2PLUS
308static struct musb_hdrc_config musb_config = {
309 .multipoint = 1,
310 .dyn_fifo = 1,
311 .num_eps = 16,
312 .ram_bits = 12,
313};
314
315static struct omap_musb_board_data musb_board_data = {
316 .interface_type = MUSB_INTERFACE_ULPI,
317};
318
319static struct musb_hdrc_platform_data musb_plat = {
320#if defined(CONFIG_USB_MUSB_HOST)
321 .mode = MUSB_HOST,
322#elif defined(CONFIG_USB_MUSB_GADGET)
323 .mode = MUSB_PERIPHERAL,
324#else
325#error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
326#endif
327 .config = &musb_config,
328 .power = 100,
329 .platform_ops = &omap2430_ops,
330 .board_data = &musb_board_data,
331};
332#endif
333
334
335
336
337
338int misc_init_r(void)
339{
340 struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
341 struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
342 struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
343 bool generate_fake_mac = false;
344 u32 value;
345
346
347 value = readl(&prog_io_base->io1);
348 value &= ~(PRG_I2C2_PULLUPRESX);
349 writel(value, &prog_io_base->io1);
350
351 switch (get_board_revision()) {
352 case REVISION_AXBX:
353 printf("Beagle Rev Ax/Bx\n");
354 env_set("beaglerev", "AxBx");
355 break;
356 case REVISION_CX:
357 printf("Beagle Rev C1/C2/C3\n");
358 env_set("beaglerev", "Cx");
359 MUX_BEAGLE_C();
360 break;
361 case REVISION_C4:
362 printf("Beagle Rev C4\n");
363 env_set("beaglerev", "C4");
364 MUX_BEAGLE_C();
365
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 break;
371 case REVISION_XM_AB:
372 printf("Beagle xM Rev A/B\n");
373 env_set("beaglerev", "xMAB");
374 MUX_BEAGLE_XM();
375
376 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
377 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
378 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
379 TWL4030_PM_RECEIVER_DEV_GRP_P1);
380 generate_fake_mac = true;
381 break;
382 case REVISION_XM_C:
383 printf("Beagle xM Rev C\n");
384 env_set("beaglerev", "xMC");
385 MUX_BEAGLE_XM();
386
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;
392 break;
393 default:
394 printf("Beagle unknown 0x%02x\n", get_board_revision());
395 MUX_BEAGLE_XM();
396
397 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
398 TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
399 TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
400 TWL4030_PM_RECEIVER_DEV_GRP_P1);
401 generate_fake_mac = true;
402 }
403
404 switch (get_expansion_id()) {
405 case TINCANTOOLS_ZIPPY:
406 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
407 expansion_config.revision,
408 expansion_config.fab_revision);
409 MUX_TINCANTOOLS_ZIPPY();
410 env_set("buddy", "zippy");
411 break;
412 case TINCANTOOLS_ZIPPY2:
413 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
414 expansion_config.revision,
415 expansion_config.fab_revision);
416 MUX_TINCANTOOLS_ZIPPY();
417 env_set("buddy", "zippy2");
418 break;
419 case TINCANTOOLS_TRAINER:
420 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
421 expansion_config.revision,
422 expansion_config.fab_revision);
423 MUX_TINCANTOOLS_ZIPPY();
424 MUX_TINCANTOOLS_TRAINER();
425 env_set("buddy", "trainer");
426 break;
427 case TINCANTOOLS_SHOWDOG:
428 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
429 expansion_config.revision,
430 expansion_config.fab_revision);
431
432 env_set("defaultdisplay", "showdoglcd");
433 env_set("buddy", "showdog");
434 break;
435 case KBADC_BEAGLEFPGA:
436 printf("Recognized KBADC Beagle FPGA board\n");
437 MUX_KBADC_BEAGLEFPGA();
438 env_set("buddy", "beaglefpga");
439 break;
440 case LW_BEAGLETOUCH:
441 printf("Recognized Liquidware BeagleTouch board\n");
442 env_set("buddy", "beagletouch");
443 break;
444 case BRAINMUX_LCDOG:
445 printf("Recognized Brainmux LCDog board\n");
446 env_set("buddy", "lcdog");
447 break;
448 case BRAINMUX_LCDOGTOUCH:
449 printf("Recognized Brainmux LCDog Touch board\n");
450 env_set("buddy", "lcdogtouch");
451 break;
452 case BBTOYS_WIFI:
453 printf("Recognized BeagleBoardToys WiFi board\n");
454 MUX_BBTOYS_WIFI()
455 env_set("buddy", "bbtoys-wifi");
456 break;
457 case BBTOYS_VGA:
458 printf("Recognized BeagleBoardToys VGA board\n");
459 break;
460 case BBTOYS_LCD:
461 printf("Recognized BeagleBoardToys LCD board\n");
462 break;
463 case BCT_BRETTL3:
464 printf("Recognized bct electronic GmbH brettl3 board\n");
465 break;
466 case BCT_BRETTL4:
467 printf("Recognized bct electronic GmbH brettl4 board\n");
468 break;
469 case LSR_COM6L_ADPT:
470 printf("Recognized LSR COM6L Adapter Board\n");
471 MUX_BBTOYS_WIFI()
472 env_set("buddy", "lsr-com6l-adpt");
473 break;
474 case BEAGLE_NO_EEPROM:
475 printf("No EEPROM on expansion board\n");
476 env_set("buddy", "none");
477 break;
478 default:
479 printf("Unrecognized expansion board: %x\n",
480 expansion_config.device_vendor);
481 env_set("buddy", "unknown");
482 }
483
484 if (expansion_config.content == 1)
485 env_set(expansion_config.env_var, expansion_config.env_setting);
486
487 twl4030_power_init();
488 switch (get_board_revision()) {
489 case REVISION_XM_AB:
490 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
491 break;
492 default:
493 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
494 break;
495 }
496
497
498 writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
499 &gpio6_base->setdataout);
500 writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
501 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
502
503
504 writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
505 writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
506 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
507
508 omap_die_id_display();
509
510#ifdef CONFIG_VIDEO_OMAP3
511 beagle_dvi_pup();
512 beagle_display_init();
513 omap3_dss_enable();
514#endif
515
516#ifdef CONFIG_USB_MUSB_OMAP2PLUS
517 musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
518#endif
519
520 if (generate_fake_mac)
521 omap_die_id_usbethaddr();
522
523#if defined(CONFIG_MTDIDS_DEFAULT) && defined(CONFIG_MTDPARTS_DEFAULT)
524 if (strlen(CONFIG_MTDIDS_DEFAULT))
525 env_set("mtdids", CONFIG_MTDIDS_DEFAULT);
526
527 if (strlen(CONFIG_MTDPARTS_DEFAULT))
528 env_set("mtdparts", CONFIG_MTDPARTS_DEFAULT);
529#endif
530
531 return 0;
532}
533
534
535
536
537
538
539
540void set_muxconf_regs(void)
541{
542 MUX_BEAGLE();
543}
544
545#if defined(CONFIG_MMC)
546int board_mmc_init(bd_t *bis)
547{
548 return omap_mmc_init(0, 0, 0, -1, -1);
549}
550#endif
551
552#if defined(CONFIG_MMC)
553void board_mmc_power_init(void)
554{
555 twl4030_power_mmc_init(0);
556}
557#endif
558
559#if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
560
561void show_boot_progress(int val)
562{
563 if (val == BOOTSTAGE_ID_RUN_OS)
564 usb_stop();
565}
566
567static struct omap_usbhs_board_data usbhs_bdata = {
568 .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
569 .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
570 .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
571};
572
573int ehci_hcd_init(int index, enum usb_init_type init,
574 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
575{
576 return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
577}
578
579int ehci_hcd_stop(int index)
580{
581 return omap_ehci_hcd_stop();
582}
583
584#endif
585
586#if defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)
587int board_eth_init(bd_t *bis)
588{
589 return usb_eth_initialize(bis);
590}
591#endif
592