]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/ti/beagle/beagle.c
beagle: expansion boards: retry i2c_read with 16bit addressing
[karo-tx-uboot.git] / board / ti / beagle / beagle.c
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  * See file CREDITS for list of people who contributed to this
15  * project.
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License as
19  * published by the Free Software Foundation; either version 2 of
20  * the License, or (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30  * MA 02111-1307 USA
31  */
32 #include <common.h>
33 #ifdef CONFIG_STATUS_LED
34 #include <status_led.h>
35 #endif
36 #include <twl4030.h>
37 #include <linux/mtd/nand.h>
38 #include <asm/io.h>
39 #include <asm/arch/mmc_host_def.h>
40 #include <asm/arch/mux.h>
41 #include <asm/arch/mem.h>
42 #include <asm/arch/sys_proto.h>
43 #include <asm/gpio.h>
44 #include <asm/mach-types.h>
45 #include <asm/omap_musb.h>
46 #include <asm/errno.h>
47 #include <linux/usb/ch9.h>
48 #include <linux/usb/gadget.h>
49 #include <linux/usb/musb.h>
50 #include "beagle.h"
51 #include <command.h>
52
53 #ifdef CONFIG_USB_EHCI
54 #include <usb.h>
55 #include <asm/ehci-omap.h>
56 #endif
57
58 #define TWL4030_I2C_BUS                 0
59 #define EXPANSION_EEPROM_I2C_BUS        1
60 #define EXPANSION_EEPROM_I2C_ADDRESS    0x50
61
62 #define TINCANTOOLS_ZIPPY               0x01000100
63 #define TINCANTOOLS_ZIPPY2              0x02000100
64 #define TINCANTOOLS_TRAINER             0x04000100
65 #define TINCANTOOLS_SHOWDOG             0x03000100
66 #define KBADC_BEAGLEFPGA                0x01000600
67 #define LW_BEAGLETOUCH                  0x01000700
68 #define BRAINMUX_LCDOG                  0x01000800
69 #define BRAINMUX_LCDOGTOUCH             0x02000800
70 #define BBTOYS_WIFI                     0x01000B00
71 #define BBTOYS_VGA                      0x02000B00
72 #define BBTOYS_LCD                      0x03000B00
73 #define BCT_BRETTL3                     0x01000F00
74 #define BCT_BRETTL4                     0x02000F00
75 #define BEAGLE_NO_EEPROM                0xffffffff
76
77 DECLARE_GLOBAL_DATA_PTR;
78
79 static struct {
80         unsigned int device_vendor;
81         unsigned char revision;
82         unsigned char content;
83         char fab_revision[8];
84         char env_var[16];
85         char env_setting[64];
86 } expansion_config;
87
88 /*
89  * Routine: board_init
90  * Description: Early hardware init.
91  */
92 int board_init(void)
93 {
94         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
95         /* board id for Linux */
96         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
97         /* boot param addr */
98         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
99
100 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
101         status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
102 #endif
103
104         return 0;
105 }
106
107 /*
108  * Routine: get_board_revision
109  * Description: Detect if we are running on a Beagle revision Ax/Bx,
110  *              C1/2/3, C4 or xM. This can be done by reading
111  *              the level of GPIO173, GPIO172 and GPIO171. This should
112  *              result in
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 0 0 => xM
117  */
118 static int get_board_revision(void)
119 {
120         int revision;
121
122         if (!gpio_request(171, "") &&
123             !gpio_request(172, "") &&
124             !gpio_request(173, "")) {
125
126                 gpio_direction_input(171);
127                 gpio_direction_input(172);
128                 gpio_direction_input(173);
129
130                 revision = gpio_get_value(173) << 2 |
131                            gpio_get_value(172) << 1 |
132                            gpio_get_value(171);
133         } else {
134                 printf("Error: unable to acquire board revision GPIOs\n");
135                 revision = -1;
136         }
137
138         return revision;
139 }
140
141 #ifdef CONFIG_SPL_BUILD
142 /*
143  * Routine: get_board_mem_timings
144  * Description: If we use SPL then there is no x-loader nor config header
145  * so we have to setup the DDR timings ourself on both banks.
146  */
147 void get_board_mem_timings(struct board_sdrc_timings *timings)
148 {
149         int pop_mfr, pop_id;
150
151         /*
152          * We need to identify what PoP memory is on the board so that
153          * we know what timings to use.  If we can't identify it then
154          * we know it's an xM.  To map the ID values please see nand_ids.c
155          */
156         identify_nand_chip(&pop_mfr, &pop_id);
157
158         timings->mr = MICRON_V_MR_165;
159         switch (get_board_revision()) {
160         case REVISION_C4:
161                 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
162                         /* 512MB DDR */
163                         timings->mcfg = NUMONYX_V_MCFG_165(512 << 20);
164                         timings->ctrla = NUMONYX_V_ACTIMA_165;
165                         timings->ctrlb = NUMONYX_V_ACTIMB_165;
166                         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
167                         break;
168                 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
169                         /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
170                         timings->mcfg = MICRON_V_MCFG_165(128 << 20);
171                         timings->ctrla = MICRON_V_ACTIMA_165;
172                         timings->ctrlb = MICRON_V_ACTIMB_165;
173                         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
174                         break;
175                 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
176                         /* Beagleboard Rev C5, 256MB DDR */
177                         timings->mcfg = MICRON_V_MCFG_200(256 << 20);
178                         timings->ctrla = MICRON_V_ACTIMA_200;
179                         timings->ctrlb = MICRON_V_ACTIMB_200;
180                         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
181                         break;
182                 }
183         case REVISION_XM_A:
184         case REVISION_XM_B:
185         case REVISION_XM_C:
186                 if (pop_mfr == 0) {
187                         /* 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;
192                 } else {
193                         /* 512MB DDR */
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;
198                 }
199                 break;
200         default:
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;
206         }
207 }
208 #endif
209
210 /*
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
215  */
216 static unsigned int get_expansion_id(void)
217 {
218         i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
219
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;
224         }
225
226         /* read configuration data */
227         i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
228                  sizeof(expansion_config));
229
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));
236         }
237
238         i2c_set_bus_num(TWL4030_I2C_BUS);
239
240         return expansion_config.device_vendor;
241 }
242
243 #ifdef CONFIG_VIDEO_OMAP3
244 /*
245  * Configure DSS to display background color on DVID
246  * Configure VENC to display color bar on S-Video
247  */
248 static void beagle_display_init(void)
249 {
250         omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
251         switch (get_board_revision()) {
252         case REVISION_AXBX:
253         case REVISION_CX:
254         case REVISION_C4:
255                 omap3_dss_panel_config(&dvid_cfg);
256                 break;
257         case REVISION_XM_A:
258         case REVISION_XM_B:
259         case REVISION_XM_C:
260         default:
261                 omap3_dss_panel_config(&dvid_cfg_xm);
262                 break;
263         }
264 }
265
266 /*
267  * Enable DVI power
268  */
269 static void beagle_dvi_pup(void)
270 {
271         uchar val;
272
273         switch (get_board_revision()) {
274         case REVISION_AXBX:
275         case REVISION_CX:
276         case REVISION_C4:
277         case REVISION_XM_A:
278                 gpio_request(170, "");
279                 gpio_direction_output(170, 0);
280                 gpio_set_value(170, 1);
281                 break;
282         case REVISION_XM_B:
283         case REVISION_XM_C:
284         default:
285                 #define GPIODATADIR1 (TWL4030_BASEADD_GPIO+3)
286                 #define GPIODATAOUT1 (TWL4030_BASEADD_GPIO+6)
287
288                 i2c_read(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
289                 val |= 4;
290                 i2c_write(TWL4030_CHIP_GPIO, GPIODATADIR1, 1, &val, 1);
291
292                 i2c_read(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
293                 val |= 4;
294                 i2c_write(TWL4030_CHIP_GPIO, GPIODATAOUT1, 1, &val, 1);
295                 break;
296         }
297 }
298 #endif
299
300 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
301 static struct musb_hdrc_config musb_config = {
302         .multipoint     = 1,
303         .dyn_fifo       = 1,
304         .num_eps        = 16,
305         .ram_bits       = 12,
306 };
307
308 static struct omap_musb_board_data musb_board_data = {
309         .interface_type = MUSB_INTERFACE_ULPI,
310 };
311
312 static struct musb_hdrc_platform_data musb_plat = {
313 #if defined(CONFIG_MUSB_HOST)
314         .mode           = MUSB_HOST,
315 #elif defined(CONFIG_MUSB_GADGET)
316         .mode           = MUSB_PERIPHERAL,
317 #else
318 #error "Please define either CONFIG_MUSB_HOST or CONFIG_MUSB_GADGET"
319 #endif
320         .config         = &musb_config,
321         .power          = 100,
322         .platform_ops   = &omap2430_ops,
323         .board_data     = &musb_board_data,
324 };
325 #endif
326
327 /*
328  * Routine: misc_init_r
329  * Description: Configure board specific parts
330  */
331 int misc_init_r(void)
332 {
333         struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
334         struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
335         struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
336
337         /* Enable i2c2 pullup resisters */
338         writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
339
340         switch (get_board_revision()) {
341         case REVISION_AXBX:
342                 printf("Beagle Rev Ax/Bx\n");
343                 setenv("beaglerev", "AxBx");
344                 break;
345         case REVISION_CX:
346                 printf("Beagle Rev C1/C2/C3\n");
347                 setenv("beaglerev", "Cx");
348                 MUX_BEAGLE_C();
349                 break;
350         case REVISION_C4:
351                 printf("Beagle Rev C4\n");
352                 setenv("beaglerev", "C4");
353                 MUX_BEAGLE_C();
354                 /* Set VAUX2 to 1.8V for EHCI PHY */
355                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
356                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
357                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
358                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
359                 break;
360         case REVISION_XM_A:
361                 printf("Beagle xM Rev A\n");
362                 setenv("beaglerev", "xMA");
363                 MUX_BEAGLE_XM();
364                 /* Set VAUX2 to 1.8V for EHCI PHY */
365                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
366                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
367                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
368                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
369                 break;
370         case REVISION_XM_B:
371                 printf("Beagle xM Rev B\n");
372                 setenv("beaglerev", "xMB");
373                 MUX_BEAGLE_XM();
374                 /* Set VAUX2 to 1.8V for EHCI PHY */
375                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
376                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
377                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
378                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
379                 break;
380         case REVISION_XM_C:
381                 printf("Beagle xM Rev C\n");
382                 setenv("beaglerev", "xMC");
383                 MUX_BEAGLE_XM();
384                 /* Set VAUX2 to 1.8V for EHCI PHY */
385                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
386                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
387                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
388                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
389                 break;
390         default:
391                 printf("Beagle unknown 0x%02x\n", get_board_revision());
392                 MUX_BEAGLE_XM();
393                 /* Set VAUX2 to 1.8V for EHCI PHY */
394                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
395                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
396                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
397                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
398         }
399
400         switch (get_expansion_id()) {
401         case TINCANTOOLS_ZIPPY:
402                 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
403                         expansion_config.revision,
404                         expansion_config.fab_revision);
405                 MUX_TINCANTOOLS_ZIPPY();
406                 setenv("buddy", "zippy");
407                 break;
408         case TINCANTOOLS_ZIPPY2:
409                 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
410                         expansion_config.revision,
411                         expansion_config.fab_revision);
412                 MUX_TINCANTOOLS_ZIPPY();
413                 setenv("buddy", "zippy2");
414                 break;
415         case TINCANTOOLS_TRAINER:
416                 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
417                         expansion_config.revision,
418                         expansion_config.fab_revision);
419                 MUX_TINCANTOOLS_ZIPPY();
420                 MUX_TINCANTOOLS_TRAINER();
421                 setenv("buddy", "trainer");
422                 break;
423         case TINCANTOOLS_SHOWDOG:
424                 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
425                         expansion_config.revision,
426                         expansion_config.fab_revision);
427                 /* Place holder for DSS2 definition for showdog lcd */
428                 setenv("defaultdisplay", "showdoglcd");
429                 setenv("buddy", "showdog");
430                 break;
431         case KBADC_BEAGLEFPGA:
432                 printf("Recognized KBADC Beagle FPGA board\n");
433                 MUX_KBADC_BEAGLEFPGA();
434                 setenv("buddy", "beaglefpga");
435                 break;
436         case LW_BEAGLETOUCH:
437                 printf("Recognized Liquidware BeagleTouch board\n");
438                 setenv("buddy", "beagletouch");
439                 break;
440         case BRAINMUX_LCDOG:
441                 printf("Recognized Brainmux LCDog board\n");
442                 setenv("buddy", "lcdog");
443                 break;
444         case BRAINMUX_LCDOGTOUCH:
445                 printf("Recognized Brainmux LCDog Touch board\n");
446                 setenv("buddy", "lcdogtouch");
447                 break;
448         case BBTOYS_WIFI:
449                 printf("Recognized BeagleBoardToys WiFi board\n");
450                 MUX_BBTOYS_WIFI()
451                 setenv("buddy", "bbtoys-wifi");
452                 break;;
453         case BBTOYS_VGA:
454                 printf("Recognized BeagleBoardToys VGA board\n");
455                 break;;
456         case BBTOYS_LCD:
457                 printf("Recognized BeagleBoardToys LCD board\n");
458                 break;;
459         case BCT_BRETTL3:
460                 printf("Recognized bct electronic GmbH brettl3 board\n");
461                 break;
462         case BCT_BRETTL4:
463                 printf("Recognized bct electronic GmbH brettl4 board\n");
464                 break;
465         case BEAGLE_NO_EEPROM:
466                 printf("No EEPROM on expansion board\n");
467                 setenv("buddy", "none");
468                 break;
469         default:
470                 printf("Unrecognized expansion board: %x\n",
471                         expansion_config.device_vendor);
472                 setenv("buddy", "unknown");
473         }
474
475         if (expansion_config.content == 1)
476                 setenv(expansion_config.env_var, expansion_config.env_setting);
477
478         twl4030_power_init();
479         switch (get_board_revision()) {
480         case REVISION_XM_A:
481         case REVISION_XM_B:
482                 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
483                 break;
484         default:
485                 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
486                 break;
487         }
488
489         /* Set GPIO states before they are made outputs */
490         writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
491                 &gpio6_base->setdataout);
492         writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
493                 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
494
495         /* Configure GPIOs to output */
496         writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
497         writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
498                 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
499
500         dieid_num_r();
501
502 #ifdef CONFIG_VIDEO_OMAP3
503         beagle_dvi_pup();
504         beagle_display_init();
505         omap3_dss_enable();
506 #endif
507
508 #ifdef CONFIG_USB_MUSB_OMAP2PLUS
509         musb_register(&musb_plat, &musb_board_data, (void *)MUSB_BASE);
510 #endif
511
512         return 0;
513 }
514
515 /*
516  * Routine: set_muxconf_regs
517  * Description: Setting up the configuration Mux registers specific to the
518  *              hardware. Many pins need to be moved from protect to primary
519  *              mode.
520  */
521 void set_muxconf_regs(void)
522 {
523         MUX_BEAGLE();
524 }
525
526 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
527 int board_mmc_init(bd_t *bis)
528 {
529         omap_mmc_init(0, 0, 0);
530         return 0;
531 }
532 #endif
533
534 #if defined(CONFIG_USB_EHCI) && !defined(CONFIG_SPL_BUILD)
535 /* Call usb_stop() before starting the kernel */
536 void show_boot_progress(int val)
537 {
538         if (val == BOOTSTAGE_ID_RUN_OS)
539                 usb_stop();
540 }
541
542 static struct omap_usbhs_board_data usbhs_bdata = {
543         .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
544         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
545         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
546 };
547
548 int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
549 {
550         return omap_ehci_hcd_init(&usbhs_bdata, hccr, hcor);
551 }
552
553 int ehci_hcd_stop(int index)
554 {
555         return omap_ehci_hcd_stop();
556 }
557
558 #endif /* CONFIG_USB_EHCI */
559
560 #if defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)
561 int board_eth_init(bd_t *bis)
562 {
563         return usb_eth_initialize(bis);
564 }
565 #endif