ehci-omap: driver for EHCI host on OMAP3
[platform/kernel/u-boot.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 "beagle.h"
46 #include <command.h>
47
48 #define pr_debug(fmt, args...) debug(fmt, ##args)
49
50 #define TWL4030_I2C_BUS                 0
51 #define EXPANSION_EEPROM_I2C_BUS        1
52 #define EXPANSION_EEPROM_I2C_ADDRESS    0x50
53
54 #define TINCANTOOLS_ZIPPY               0x01000100
55 #define TINCANTOOLS_ZIPPY2              0x02000100
56 #define TINCANTOOLS_TRAINER             0x04000100
57 #define TINCANTOOLS_SHOWDOG             0x03000100
58 #define KBADC_BEAGLEFPGA                0x01000600
59 #define LW_BEAGLETOUCH                  0x01000700
60 #define BRAINMUX_LCDOG                  0x01000800
61 #define BRAINMUX_LCDOGTOUCH             0x02000800
62 #define BBTOYS_WIFI                     0x01000B00
63 #define BBTOYS_VGA                      0x02000B00
64 #define BBTOYS_LCD                      0x03000B00
65 #define BCT_BRETTL3                     0x01000F00
66 #define BEAGLE_NO_EEPROM                0xffffffff
67
68 DECLARE_GLOBAL_DATA_PTR;
69
70 static struct {
71         unsigned int device_vendor;
72         unsigned char revision;
73         unsigned char content;
74         char fab_revision[8];
75         char env_var[16];
76         char env_setting[64];
77 } expansion_config;
78
79 /*
80  * Routine: board_init
81  * Description: Early hardware init.
82  */
83 int board_init(void)
84 {
85         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
86         /* board id for Linux */
87         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
88         /* boot param addr */
89         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
90
91 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
92         status_led_set (STATUS_LED_BOOT, STATUS_LED_ON);
93 #endif
94
95         return 0;
96 }
97
98 /*
99  * Routine: get_board_revision
100  * Description: Detect if we are running on a Beagle revision Ax/Bx,
101  *              C1/2/3, C4 or xM. This can be done by reading
102  *              the level of GPIO173, GPIO172 and GPIO171. This should
103  *              result in
104  *              GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
105  *              GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
106  *              GPIO173, GPIO172, GPIO171: 1 0 1 => C4
107  *              GPIO173, GPIO172, GPIO171: 0 0 0 => xM
108  */
109 int get_board_revision(void)
110 {
111         int revision;
112
113         if (!gpio_request(171, "") &&
114             !gpio_request(172, "") &&
115             !gpio_request(173, "")) {
116
117                 gpio_direction_input(171);
118                 gpio_direction_input(172);
119                 gpio_direction_input(173);
120
121                 revision = gpio_get_value(173) << 2 |
122                            gpio_get_value(172) << 1 |
123                            gpio_get_value(171);
124         } else {
125                 printf("Error: unable to acquire board revision GPIOs\n");
126                 revision = -1;
127         }
128
129         return revision;
130 }
131
132 #ifdef CONFIG_SPL_BUILD
133 /*
134  * Routine: get_board_mem_timings
135  * Description: If we use SPL then there is no x-loader nor config header
136  * so we have to setup the DDR timings ourself on both banks.
137  */
138 void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl,
139                 u32 *mr)
140 {
141         int pop_mfr, pop_id;
142
143         /*
144          * We need to identify what PoP memory is on the board so that
145          * we know what timings to use.  If we can't identify it then
146          * we know it's an xM.  To map the ID values please see nand_ids.c
147          */
148         identify_nand_chip(&pop_mfr, &pop_id);
149
150         *mr = MICRON_V_MR_165;
151         switch (get_board_revision()) {
152         case REVISION_C4:
153                 if (pop_mfr == NAND_MFR_STMICRO && pop_id == 0xba) {
154                         /* 512MB DDR */
155                         *mcfg = NUMONYX_V_MCFG_165(512 << 20);
156                         *ctrla = NUMONYX_V_ACTIMA_165;
157                         *ctrlb = NUMONYX_V_ACTIMB_165;
158                         *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
159                         break;
160                 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xba) {
161                         /* Beagleboard Rev C4, 512MB Nand/256MB DDR*/
162                         *mcfg = MICRON_V_MCFG_165(128 << 20);
163                         *ctrla = MICRON_V_ACTIMA_165;
164                         *ctrlb = MICRON_V_ACTIMB_165;
165                         *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
166                         break;
167                 } else if (pop_mfr == NAND_MFR_MICRON && pop_id == 0xbc) {
168                         /* Beagleboard Rev C5, 256MB DDR */
169                         *mcfg = MICRON_V_MCFG_200(256 << 20);
170                         *ctrla = MICRON_V_ACTIMA_200;
171                         *ctrlb = MICRON_V_ACTIMB_200;
172                         *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
173                         break;
174                 }
175         case REVISION_XM_A:
176         case REVISION_XM_B:
177         case REVISION_XM_C:
178                 if (pop_mfr == 0) {
179                         /* 256MB DDR */
180                         *mcfg = MICRON_V_MCFG_200(256 << 20);
181                         *ctrla = MICRON_V_ACTIMA_200;
182                         *ctrlb = MICRON_V_ACTIMB_200;
183                         *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
184                 } else {
185                         /* 512MB DDR */
186                         *mcfg = NUMONYX_V_MCFG_165(512 << 20);
187                         *ctrla = NUMONYX_V_ACTIMA_165;
188                         *ctrlb = NUMONYX_V_ACTIMB_165;
189                         *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
190                 }
191                 break;
192         default:
193                 /* Assume 128MB and Micron/165MHz timings to be safe */
194                 *mcfg = MICRON_V_MCFG_165(128 << 20);
195                 *ctrla = MICRON_V_ACTIMA_165;
196                 *ctrlb = MICRON_V_ACTIMB_165;
197                 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
198         }
199 }
200 #endif
201
202 /*
203  * Routine: get_expansion_id
204  * Description: This function checks for expansion board by checking I2C
205  *              bus 1 for the availability of an AT24C01B serial EEPROM.
206  *              returns the device_vendor field from the EEPROM
207  */
208 unsigned int get_expansion_id(void)
209 {
210         i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
211
212         /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
213         if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
214                 i2c_set_bus_num(TWL4030_I2C_BUS);
215                 return BEAGLE_NO_EEPROM;
216         }
217
218         /* read configuration data */
219         i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
220                  sizeof(expansion_config));
221
222         i2c_set_bus_num(TWL4030_I2C_BUS);
223
224         return expansion_config.device_vendor;
225 }
226
227 /*
228  * Configure DSS to display background color on DVID
229  * Configure VENC to display color bar on S-Video
230  */
231 void beagle_display_init(void)
232 {
233         omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
234         switch (get_board_revision()) {
235         case REVISION_AXBX:
236         case REVISION_CX:
237         case REVISION_C4:
238                 omap3_dss_panel_config(&dvid_cfg);
239                 break;
240         case REVISION_XM_A:
241         case REVISION_XM_B:
242         case REVISION_XM_C:
243         default:
244                 omap3_dss_panel_config(&dvid_cfg_xm);
245                 break;
246         }
247 }
248
249 /*
250  * Routine: misc_init_r
251  * Description: Configure board specific parts
252  */
253 int misc_init_r(void)
254 {
255         struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
256         struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
257         struct control_prog_io *prog_io_base = (struct control_prog_io *)OMAP34XX_CTRL_BASE;
258
259         /* Enable i2c2 pullup resisters */
260         writel(~(PRG_I2C2_PULLUPRESX), &prog_io_base->io1);
261
262         switch (get_board_revision()) {
263         case REVISION_AXBX:
264                 printf("Beagle Rev Ax/Bx\n");
265                 setenv("beaglerev", "AxBx");
266                 break;
267         case REVISION_CX:
268                 printf("Beagle Rev C1/C2/C3\n");
269                 setenv("beaglerev", "Cx");
270                 MUX_BEAGLE_C();
271                 break;
272         case REVISION_C4:
273                 printf("Beagle Rev C4\n");
274                 setenv("beaglerev", "C4");
275                 MUX_BEAGLE_C();
276                 /* Set VAUX2 to 1.8V for EHCI PHY */
277                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
278                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
279                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
280                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
281                 break;
282         case REVISION_XM_A:
283                 printf("Beagle xM Rev A\n");
284                 setenv("beaglerev", "xMA");
285                 MUX_BEAGLE_XM();
286                 /* Set VAUX2 to 1.8V for EHCI PHY */
287                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
288                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
289                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
290                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
291                 break;
292         case REVISION_XM_B:
293                 printf("Beagle xM Rev B\n");
294                 setenv("beaglerev", "xMB");
295                 MUX_BEAGLE_XM();
296                 /* Set VAUX2 to 1.8V for EHCI PHY */
297                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
298                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
299                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
300                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
301                 break;
302         case REVISION_XM_C:
303                 printf("Beagle xM Rev C\n");
304                 setenv("beaglerev", "xMC");
305                 MUX_BEAGLE_XM();
306                 /* Set VAUX2 to 1.8V for EHCI PHY */
307                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
308                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
309                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
310                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
311                 break;
312         default:
313                 printf("Beagle unknown 0x%02x\n", get_board_revision());
314                 MUX_BEAGLE_XM();
315                 /* Set VAUX2 to 1.8V for EHCI PHY */
316                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
317                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
318                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
319                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
320         }
321
322         switch (get_expansion_id()) {
323         case TINCANTOOLS_ZIPPY:
324                 printf("Recognized Tincantools Zippy board (rev %d %s)\n",
325                         expansion_config.revision,
326                         expansion_config.fab_revision);
327                 MUX_TINCANTOOLS_ZIPPY();
328                 setenv("buddy", "zippy");
329                 break;
330         case TINCANTOOLS_ZIPPY2:
331                 printf("Recognized Tincantools Zippy2 board (rev %d %s)\n",
332                         expansion_config.revision,
333                         expansion_config.fab_revision);
334                 MUX_TINCANTOOLS_ZIPPY();
335                 setenv("buddy", "zippy2");
336                 break;
337         case TINCANTOOLS_TRAINER:
338                 printf("Recognized Tincantools Trainer board (rev %d %s)\n",
339                         expansion_config.revision,
340                         expansion_config.fab_revision);
341                 MUX_TINCANTOOLS_ZIPPY();
342                 MUX_TINCANTOOLS_TRAINER();
343                 setenv("buddy", "trainer");
344                 break;
345         case TINCANTOOLS_SHOWDOG:
346                 printf("Recognized Tincantools Showdow board (rev %d %s)\n",
347                         expansion_config.revision,
348                         expansion_config.fab_revision);
349                 /* Place holder for DSS2 definition for showdog lcd */
350                 setenv("defaultdisplay", "showdoglcd");
351                 setenv("buddy", "showdog");
352                 break;
353         case KBADC_BEAGLEFPGA:
354                 printf("Recognized KBADC Beagle FPGA board\n");
355                 MUX_KBADC_BEAGLEFPGA();
356                 setenv("buddy", "beaglefpga");
357                 break;
358         case LW_BEAGLETOUCH:
359                 printf("Recognized Liquidware BeagleTouch board\n");
360                 setenv("buddy", "beagletouch");
361                 break;
362         case BRAINMUX_LCDOG:
363                 printf("Recognized Brainmux LCDog board\n");
364                 setenv("buddy", "lcdog");
365                 break;
366         case BRAINMUX_LCDOGTOUCH:
367                 printf("Recognized Brainmux LCDog Touch board\n");
368                 setenv("buddy", "lcdogtouch");
369                 break;
370         case BBTOYS_WIFI:
371                 printf("Recognized BeagleBoardToys WiFi board\n");
372                 MUX_BBTOYS_WIFI()
373                 setenv("buddy", "bbtoys-wifi");
374                 break;;
375         case BBTOYS_VGA:
376                 printf("Recognized BeagleBoardToys VGA board\n");
377                 break;;
378         case BBTOYS_LCD:
379                 printf("Recognized BeagleBoardToys LCD board\n");
380                 break;;
381         case BCT_BRETTL3:
382             printf("Recognized bct electronic GmbH brettl3 board\n");
383             break;
384         case BEAGLE_NO_EEPROM:
385                 printf("No EEPROM on expansion board\n");
386                 setenv("buddy", "none");
387                 break;
388         default:
389                 printf("Unrecognized expansion board: %x\n",
390                         expansion_config.device_vendor);
391                 setenv("buddy", "unknown");
392         }
393
394         if (expansion_config.content == 1)
395                 setenv(expansion_config.env_var, expansion_config.env_setting);
396
397         twl4030_power_init();
398         switch (get_board_revision()) {
399         case REVISION_XM_A:
400         case REVISION_XM_B:
401                 twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
402                 break;
403         default:
404                 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
405                 break;
406         }
407
408         /* Set GPIO states before they are made outputs */
409         writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
410                 &gpio6_base->setdataout);
411         writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
412                 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
413
414         /* Configure GPIOs to output */
415         writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
416         writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
417                 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
418
419         dieid_num_r();
420         beagle_display_init();
421         omap3_dss_enable();
422
423         return 0;
424 }
425
426 /*
427  * Routine: set_muxconf_regs
428  * Description: Setting up the configuration Mux registers specific to the
429  *              hardware. Many pins need to be moved from protect to primary
430  *              mode.
431  */
432 void set_muxconf_regs(void)
433 {
434         MUX_BEAGLE();
435 }
436
437 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
438 int board_mmc_init(bd_t *bis)
439 {
440         omap_mmc_init(0);
441         return 0;
442 }
443 #endif
444
445 #ifdef CONFIG_USB_EHCI
446 /* Call usb_stop() before starting the kernel */
447 void show_boot_progress(int val)
448 {
449         if(val == 15)
450                 usb_stop();
451 }
452 #endif /* CONFIG_USB_EHCI */
453
454 #ifndef CONFIG_SPL_BUILD
455 /*
456  * This command returns the status of the user button on beagle xM
457  * Input - none
458  * Returns -    1 if button is held down
459  *              0 if button is not held down
460  */
461 int do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
462 {
463         int     button = 0;
464         int     gpio;
465
466         /*
467          * pass address parameter as argv[0] (aka command name),
468          * and all remaining args
469          */
470         switch (get_board_revision()) {
471         case REVISION_AXBX:
472         case REVISION_CX:
473         case REVISION_C4:
474                 gpio = 7;
475                 break;
476         case REVISION_XM_A:
477         case REVISION_XM_B:
478         case REVISION_XM_C:
479         default:
480                 gpio = 4;
481                 break;
482         }
483         gpio_request(gpio, "");
484         gpio_direction_input(gpio);
485         printf("The user button is currently ");
486         if (gpio_get_value(gpio))
487         {
488                 button = 1;
489                 printf("PRESSED.\n");
490         }
491         else
492         {
493                 button = 0;
494                 printf("NOT pressed.\n");
495         }
496
497         return !button;
498 }
499
500 /* -------------------------------------------------------------------- */
501
502 U_BOOT_CMD(
503         userbutton, CONFIG_SYS_MAXARGS, 1,      do_userbutton,
504         "Return the status of the BeagleBoard USER button",
505         ""
506 );
507 #endif