OMAP3: beagle: add more expansionboards, based on http://www.elinux.org/BeagleBoardPi...
[beagleboard-validation: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/mux.h>
36 #include <asm/arch/sys_proto.h>
37 #include <asm/arch/gpio.h>
38 #include <asm/mach-types.h>
39 #include "beagle.h"
40
41 static struct {
42         unsigned int device_vendor;
43         unsigned char revision;
44         unsigned char content;
45         unsigned char fab_revision[8];
46         unsigned char env_var[16];
47         unsigned char env_setting[64];
48 } expansion_config;
49
50 #define TWL4030_I2C_BUS                 0
51
52 #define EXPANSION_EEPROM_I2C_BUS        1
53 #define EXPANSION_EEPROM_I2C_ADDRESS    0x50
54
55 #define TINCANTOOLS_VENDORID    0x0100
56 #define GUMSTIX_VENDORID                0x0200
57 #define SPECIALCOMP_VENDORID    0x0300
58 #define HYR_VENDORID                    0x0400
59 #define MENTOREL_VENDORID               0x0500
60 #define KBADC_VENDORID                  0x0600
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
68 #define BEAGLE_NO_EEPROM                0xffffffff
69
70 static int beagle_revision;
71
72 /*
73  * Routine: board_init
74  * Description: Early hardware init.
75  */
76 int board_init(void)
77 {
78         DECLARE_GLOBAL_DATA_PTR;
79
80         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
81         /* board id for Linux */
82         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_BEAGLE;
83         /* boot param addr */
84         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
85
86         return 0;
87 }
88
89 /*
90  * Routine: beagle_get_revision
91  * Description: Return the revision of the BeagleBoard this code is running on.
92  */
93 int beagle_get_revision(void)
94 {
95         return beagle_revision;
96 }
97
98 /*
99  * Routine: beagle_identify
100  * Description: Detect if we are running on a Beagle revision Ax/Bx,
101  *              C1/2/3, C4 or D. 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 void beagle_identify(void)
110 {
111         omap_request_gpio(171);
112         omap_request_gpio(172);
113         omap_request_gpio(173);
114         omap_set_gpio_direction(171, 1);
115         omap_set_gpio_direction(172, 1);
116         omap_set_gpio_direction(173, 1);
117
118         beagle_revision = omap_get_gpio_datain(173) << 2 |
119                           omap_get_gpio_datain(172) << 1 |
120                           omap_get_gpio_datain(171);
121         omap_free_gpio(171);
122         omap_free_gpio(172);
123         omap_free_gpio(173);
124 }
125
126 /*
127  * Routine: get_expansion_id
128  * Description: This function checks for expansion board by checking I2C
129  *              bus 2 for the availability of an AT24C01B serial EEPROM.
130  *              returns the device_vendor field from the EEPROM
131  */
132 unsigned int get_expansion_id(void)
133 {
134         i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
135
136         /* return BEAGLE_NO_EEPROM if eeprom doesn't respond */
137         if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1)
138                 return BEAGLE_NO_EEPROM;
139
140         /* read configuration data */
141         i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
142                  sizeof(expansion_config));
143
144         return expansion_config.device_vendor;
145 }
146
147 /*
148  * Configure DSS to display background color on DVID
149  * Configure VENC to display color bar on S-Video
150  */
151 void display_init(void)
152 {
153         omap3_dss_venc_config(&venc_config_std_tv, VENC_HEIGHT, VENC_WIDTH);
154         omap3_dss_panel_config(&dvid_cfg);
155 }
156
157 /*
158  * Routine: misc_init_r
159  * Description: Configure board specific parts
160  */
161 int misc_init_r(void)
162 {
163         struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
164         struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
165
166         beagle_identify();
167
168         printf("\nProbing for expansion boards, if none are connected you'll see a harmless I2C error.\n");
169
170         switch (get_expansion_id()) {
171                 case TINCANTOOLS_ZIPPY:
172                         printf("Recognized Tincantools Zippy expansion board (rev %d %s)\n",
173                                 expansion_config.revision, expansion_config.fab_revision);
174                         MUX_TINCANTOOLS_ZIPPY();
175                         break;
176                 case TINCANTOOLS_ZIPPY2:
177                         printf("Recognized Tincantools Zippy2 expansion board (rev %d %s)\n",
178                                 expansion_config.revision, expansion_config.fab_revision);
179                         MUX_TINCANTOOLS_ZIPPY();
180                         break;
181                 case TINCANTOOLS_TRAINER:
182                         printf("Recognized Tincantools Trainer expansion board (rev %d %s)\n",
183                                 expansion_config.revision, expansion_config.fab_revision);
184                         break;
185                 case TINCANTOOLS_SHOWDOG:
186                         printf("Recognized Tincantools Showdow expansion board (rev %d %s)\n",
187                                 expansion_config.revision, expansion_config.fab_revision);
188                         /* Place holder for DSS2 definition for showdog lcd */
189                         setenv("defaultdisplay", "showdoglcd");
190                         break;
191                 case KBADC_BEAGLEFPGA:
192                         printf("Recognized KBADC Beagle FPGA board\n");
193                         MUX_KBADC_BEAGLEFPGA();
194                         break;
195                 case BEAGLE_NO_EEPROM:
196                         printf("No EEPROM on expansion board\n");
197                         break;
198                 default:
199                         printf("Unrecognized expansion board: %x\n", expansion_config.device_vendor);
200         }
201
202         if (expansion_config.content == 1)
203                 setenv(expansion_config.env_var, expansion_config.env_setting);
204
205         i2c_set_bus_num(TWL4030_I2C_BUS);
206
207         twl4030_power_init();
208         twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
209         display_init();
210
211         switch (beagle_revision) {
212         case REVISION_AXBX:
213                 printf("Beagle Rev Ax/Bx\n");
214                 break;
215         case REVISION_CX:
216                 printf("Beagle Rev C1/C2/C3\n");
217                 MUX_BEAGLE_C();
218                 break;
219         case REVISION_C4:
220                 printf("Beagle Rev C4\n");
221                 MUX_BEAGLE_C();
222                 /* Set VAUX2 to 1.8V for EHCI PHY */
223                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
224                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
225                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
226                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
227                 setenv("mpurate", "720");
228                 break;
229         case REVISION_XM:
230                 printf("Beagle xM Rev A\n");
231                 MUX_BEAGLE_XM();
232                 /* Set VAUX2 to 1.8V for EHCI PHY */
233                 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VAUX2_DEDICATED,
234                                         TWL4030_PM_RECEIVER_VAUX2_VSEL_18,
235                                         TWL4030_PM_RECEIVER_VAUX2_DEV_GRP,
236                                         TWL4030_PM_RECEIVER_DEV_GRP_P1);
237                 break;
238         default:
239                 printf("Beagle unknown 0x%02x\n", beagle_revision);
240         }
241
242         /* Configure GPIOs to output */
243         writel(~(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
244         writel(~(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
245                 GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
246
247         /* Set GPIOs */
248         writel(GPIO23 | GPIO10 | GPIO8 | GPIO2 | GPIO1,
249                 &gpio6_base->setdataout);
250         writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
251                 GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
252
253         dieid_num_r();
254         omap3_dss_enable();
255
256         return 0;
257 }
258
259 /*
260  * Routine: set_muxconf_regs
261  * Description: Setting up the configuration Mux registers specific to the
262  *              hardware. Many pins need to be moved from protect to primary
263  *              mode.
264  */
265 void set_muxconf_regs(void)
266 {
267         MUX_BEAGLE();
268 }