Merge branch 'master' of git://git.denx.de/u-boot-nand-flash
[oweals/u-boot.git] / board / ti / beagle / beagle.c
1 /*
2  * (C) Copyright 2004-2008
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 #include <twl4030.h>
34 #include <asm/io.h>
35 #include <asm/arch/mmc_host_def.h>
36 #include <asm/arch/mux.h>
37 #include <asm/arch/sys_proto.h>
38 #include <asm/arch/gpio.h>
39 #include <asm/mach-types.h>
40 #include "beagle.h"
41
42 /*
43  * Routine: board_init
44  * Description: Early hardware init.
45  */
46 int board_init(void)
47 {
48         DECLARE_GLOBAL_DATA_PTR;
49
50         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
51         /* board id for Linux */
52         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
53         /* boot param addr */
54         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
55
56         return 0;
57 }
58
59 /*
60  * Routine: get_board_revision
61  * Description: Detect if we are running on a Beagle revision Ax/Bx,
62  *              C1/2/3, C4 or xM. This can be done by reading
63  *              the level of GPIO173, GPIO172 and GPIO171. This should
64  *              result in
65  *              GPIO173, GPIO172, GPIO171: 1 1 1 => Ax/Bx
66  *              GPIO173, GPIO172, GPIO171: 1 1 0 => C1/2/3
67  *              GPIO173, GPIO172, GPIO171: 1 0 1 => C4
68  *              GPIO173, GPIO172, GPIO171: 0 0 0 => xM
69  */
70 int get_board_revision(void)
71 {
72         int revision;
73
74         if (!omap_request_gpio(171) &&
75             !omap_request_gpio(172) &&
76             !omap_request_gpio(173)) {
77
78                 omap_set_gpio_direction(171, 1);
79                 omap_set_gpio_direction(172, 1);
80                 omap_set_gpio_direction(173, 1);
81
82                 revision = omap_get_gpio_datain(173) << 2 |
83                            omap_get_gpio_datain(172) << 1 |
84                            omap_get_gpio_datain(171);
85
86                 omap_free_gpio(171);
87                 omap_free_gpio(172);
88                 omap_free_gpio(173);
89         } else {
90                 printf("Error: unable to acquire board revision GPIOs\n");
91                 revision = -1;
92         }
93
94         return revision;
95 }
96
97 /*
98  * Routine: misc_init_r
99  * Description: Configure board specific parts
100  */
101 int misc_init_r(void)
102 {
103         struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
104         struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
105
106         switch (get_board_revision()) {
107         case REVISION_AXBX:
108                 printf("Beagle Rev Ax/Bx\n");
109                 setenv("beaglerev", "AxBx");
110                 setenv("mpurate", "600");
111                 break;
112         case REVISION_CX:
113                 printf("Beagle Rev C1/C2/C3\n");
114                 setenv("beaglerev", "Cx");
115                 setenv("mpurate", "600");
116                 MUX_BEAGLE_C();
117                 break;
118         case REVISION_C4:
119                 printf("Beagle Rev C4\n");
120                 setenv("beaglerev", "C4");
121                 setenv("mpurate", "720");
122                 MUX_BEAGLE_C();
123                 /* Set VAUX2 to 1.8V for EHCI PHY */
124                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
125                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
126                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
127                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
128                 break;
129         case REVISION_XM:
130                 printf("Beagle xM Rev A\n");
131                 setenv("beaglerev", "xMA");
132                 setenv("mpurate", "1000");
133                 MUX_BEAGLE_XM();
134                 /* Set VAUX2 to 1.8V for EHCI PHY */
135                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
136                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
137                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
138                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
139                 break;
140         default:
141                 printf("Beagle unknown 0x%02x\n", get_board_revision());
142         }
143
144         twl4030_power_init();
145         twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
146
147         /* Configure GPIOs to output */
148         writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
149         writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
150                 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
151
152         /* Set GPIOs */
153         writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
154                 &gpio6_base->setdataout);
155         writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
156                 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
157
158         dieid_num_r();
159
160         return 0;
161 }
162
163 /*
164  * Routine: set_muxconf_regs
165  * Description: Setting up the configuration Mux registers specific to the
166  *              hardware. Many pins need to be moved from protect to primary
167  *              mode.
168  */
169 void set_muxconf_regs(void)
170 {
171         MUX_BEAGLE();
172 }
173
174 #ifdef CONFIG_GENERIC_MMC
175 int board_mmc_init(bd_t *bis)
176 {
177         omap_mmc_init(0);
178         return 0;
179 }
180 #endif