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