blob: 28c7344f0d1020f21c0999ad92b3b835ca69ff9b [file] [log] [blame]
Dirk Behme9d0fc812009-01-28 21:39:57 +01001/*
2 * Maintainer : Steve Sakoman <steve@sakoman.com>
3 *
4 * Derived from Beagle Board, 3430 SDP, and OMAP3EVM code by
5 * Richard Woodruff <r-woodruff2@ti.com>
6 * Syed Mohammed Khasim <khasim@ti.com>
7 * Sunil Kumar <sunilsaini05@gmail.com>
8 * Shashi Ranjan <shashiranjanmca05@gmail.com>
9 *
10 * (C) Copyright 2004-2008
11 * Texas Instruments, <www.ti.com>
12 *
13 * See file CREDITS for list of people who contributed to this
14 * project.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 */
31#include <common.h>
Olof Johanssondf382622009-09-29 10:22:45 -040032#include <netdev.h>
Tom Rix2c155132009-06-28 12:52:30 -050033#include <twl4030.h>
Andreas Müller137703b2012-01-04 15:26:25 +000034#include <linux/mtd/nand.h>
Dirk Behme9d0fc812009-01-28 21:39:57 +010035#include <asm/io.h>
Steve Sakomancd7c5722010-09-19 21:21:07 -070036#include <asm/arch/mmc_host_def.h>
Dirk Behme9d0fc812009-01-28 21:39:57 +010037#include <asm/arch/mux.h>
Olof Johanssondf382622009-09-29 10:22:45 -040038#include <asm/arch/mem.h>
Dirk Behme9d0fc812009-01-28 21:39:57 +010039#include <asm/arch/sys_proto.h>
Philip Balister5213d242011-09-14 13:32:22 -040040#include <asm/arch/omap_gpmc.h>
Sanjeev Premi84c3b632011-09-08 10:51:01 -040041#include <asm/gpio.h>
Dirk Behme9d0fc812009-01-28 21:39:57 +010042#include <asm/mach-types.h>
43#include "overo.h"
44
John Rigby29565322010-12-20 18:27:51 -070045DECLARE_GLOBAL_DATA_PTR;
46
Steve Sakomand64b5b82010-09-20 08:05:14 -070047#define TWL4030_I2C_BUS 0
48#define EXPANSION_EEPROM_I2C_BUS 2
49#define EXPANSION_EEPROM_I2C_ADDRESS 0x51
50
51#define GUMSTIX_SUMMIT 0x01000200
52#define GUMSTIX_TOBI 0x02000200
53#define GUMSTIX_TOBI_DUO 0x03000200
54#define GUMSTIX_PALO35 0x04000200
55#define GUMSTIX_PALO43 0x05000200
56#define GUMSTIX_CHESTNUT43 0x06000200
57#define GUMSTIX_PINTO 0x07000200
58#define GUMSTIX_GALLOP43 0x08000200
59
60#define ETTUS_USRP_E 0x01000300
61
62#define GUMSTIX_NO_EEPROM 0xffffffff
63
64static struct {
65 unsigned int device_vendor;
66 unsigned char revision;
67 unsigned char content;
68 char fab_revision[8];
69 char env_var[16];
70 char env_setting[64];
71} expansion_config;
72
Olof Johanssondf382622009-09-29 10:22:45 -040073#if defined(CONFIG_CMD_NET)
74static void setup_net_chip(void);
75#endif
76
Steve Sakomanba9a11e2010-08-12 21:07:02 -070077/* GPMC definitions for LAN9221 chips on Tobi expansion boards */
78static const u32 gpmc_lan_config[] = {
79 NET_LAN9221_GPMC_CONFIG1,
80 NET_LAN9221_GPMC_CONFIG2,
81 NET_LAN9221_GPMC_CONFIG3,
82 NET_LAN9221_GPMC_CONFIG4,
83 NET_LAN9221_GPMC_CONFIG5,
84 NET_LAN9221_GPMC_CONFIG6,
85 /*CONFIG7- computed as params */
86};
87
Tom Rix58911512009-04-01 22:02:20 -050088/*
Dirk Behme9d0fc812009-01-28 21:39:57 +010089 * Routine: board_init
90 * Description: Early hardware init.
Tom Rix58911512009-04-01 22:02:20 -050091 */
Dirk Behme9d0fc812009-01-28 21:39:57 +010092int board_init(void)
93{
Dirk Behme9d0fc812009-01-28 21:39:57 +010094 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
95 /* board id for Linux */
96 gd->bd->bi_arch_number = MACH_TYPE_OVERO;
97 /* boot param addr */
98 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
99
100 return 0;
101}
102
Tom Rix58911512009-04-01 22:02:20 -0500103/*
Andreas Müller137703b2012-01-04 15:26:25 +0000104 * Routine: omap_rev_string
105 * Description: For SPL builds output board rev
106 */
107#ifdef CONFIG_SPL_BUILD
108void omap_rev_string(void)
109{
110}
111#endif
112
113/*
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700114 * Routine: get_board_revision
115 * Description: Returns the board revision
116 */
117int get_board_revision(void)
118{
119 int revision;
120
Andreas Müller137703b2012-01-04 15:26:25 +0000121#ifdef CONFIG_DRIVER_OMAP34XX_I2C
122 unsigned char data;
123
124 /* board revisions <= R2410 connect 4030 irq_1 to gpio112 */
125 /* these boards should return a revision number of 0 */
126 /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */
127 i2c_set_bus_num(TWL4030_I2C_BUS);
128 data = 0x01;
129 i2c_write(0x4B, 0x29, 1, &data, 1);
130 data = 0x0c;
131 i2c_write(0x4B, 0x2b, 1, &data, 1);
132 i2c_read(0x4B, 0x2a, 1, &data, 1);
133#endif
134
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400135 if (!gpio_request(112, "") &&
136 !gpio_request(113, "") &&
137 !gpio_request(115, "")) {
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700138
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400139 gpio_direction_input(112);
140 gpio_direction_input(113);
141 gpio_direction_input(115);
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700142
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400143 revision = gpio_get_value(115) << 2 |
144 gpio_get_value(113) << 1 |
145 gpio_get_value(112);
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700146 } else {
Andreas Müllerbae485d2012-01-04 15:26:20 +0000147 puts("Error: unable to acquire board revision GPIOs\n");
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700148 revision = -1;
149 }
150
151 return revision;
152}
153
Andreas Müller137703b2012-01-04 15:26:25 +0000154#ifdef CONFIG_SPL_BUILD
155/*
156 * Routine: get_board_mem_timings
157 * Description: If we use SPL then there is no x-loader nor config header
158 * so we have to setup the DDR timings ourself on both banks.
159 */
160void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl,
161 u32 *mr)
162{
163 *mr = MICRON_V_MR_165;
164 switch (get_board_revision()) {
165 case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */
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 case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */
Steve Sakoman401339b2012-03-02 14:20:31 -0800172 if (get_cpu_family() != CPU_OMAP36XX) {
173 *mcfg = MICRON_V_MCFG_165(256 << 20);
174 *ctrla = MICRON_V_ACTIMA_165;
175 *ctrlb = MICRON_V_ACTIMB_165;
176 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
177 } else {
178 *mcfg = MICRON_V_MCFG_200(256 << 20);
179 *ctrla = MICRON_V_ACTIMA_200;
180 *ctrlb = MICRON_V_ACTIMB_200;
181 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
182 }
Andreas Müller137703b2012-01-04 15:26:25 +0000183 break;
184 case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */
Steve Sakoman401339b2012-03-02 14:20:31 -0800185 if (get_cpu_family() != CPU_OMAP36XX) {
186 *mcfg = HYNIX_V_MCFG_165(256 << 20);
187 *ctrla = HYNIX_V_ACTIMA_165;
188 *ctrlb = HYNIX_V_ACTIMB_165;
189 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
190 } else {
191 *mcfg = HYNIX_V_MCFG_200(256 << 20);
192 *ctrla = HYNIX_V_ACTIMA_200;
193 *ctrlb = HYNIX_V_ACTIMB_200;
194 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
195 }
Andreas Müller137703b2012-01-04 15:26:25 +0000196 break;
197 default:
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
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700206/*
Steve Sakomana06e1622010-08-24 10:37:29 -0700207 * Routine: get_sdio2_config
208 * Description: Return information about the wifi module connection
209 * Returns 0 if the module connects though a level translator
210 * Returns 1 if the module connects directly
211 */
212int get_sdio2_config(void)
213{
214 int sdio_direct;
215
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400216 if (!gpio_request(130, "") && !gpio_request(139, "")) {
Steve Sakomana06e1622010-08-24 10:37:29 -0700217
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400218 gpio_direction_output(130, 0);
219 gpio_direction_input(139);
Steve Sakomana06e1622010-08-24 10:37:29 -0700220
221 sdio_direct = 1;
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400222 gpio_set_value(130, 0);
223 if (gpio_get_value(139) == 0) {
224 gpio_set_value(130, 1);
225 if (gpio_get_value(139) == 1)
Steve Sakomana06e1622010-08-24 10:37:29 -0700226 sdio_direct = 0;
227 }
228
Joe Hershbergerb5db0a02011-10-12 10:31:44 +0000229 gpio_direction_input(130);
Steve Sakomana06e1622010-08-24 10:37:29 -0700230 } else {
Andreas Müllerbae485d2012-01-04 15:26:20 +0000231 puts("Error: unable to acquire sdio2 clk GPIOs\n");
Steve Sakomana06e1622010-08-24 10:37:29 -0700232 sdio_direct = -1;
233 }
234
235 return sdio_direct;
236}
237
238/*
Steve Sakomand64b5b82010-09-20 08:05:14 -0700239 * Routine: get_expansion_id
240 * Description: This function checks for expansion board by checking I2C
241 * bus 2 for the availability of an AT24C01B serial EEPROM.
242 * returns the device_vendor field from the EEPROM
243 */
244unsigned int get_expansion_id(void)
245{
246 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
247
248 /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
249 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
250 i2c_set_bus_num(TWL4030_I2C_BUS);
251 return GUMSTIX_NO_EEPROM;
252 }
253
254 /* read configuration data */
255 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
256 sizeof(expansion_config));
257
258 i2c_set_bus_num(TWL4030_I2C_BUS);
259
260 return expansion_config.device_vendor;
261}
262
263/*
Dirk Behme9d0fc812009-01-28 21:39:57 +0100264 * Routine: misc_init_r
265 * Description: Configure board specific parts
Tom Rix58911512009-04-01 22:02:20 -0500266 */
Dirk Behme9d0fc812009-01-28 21:39:57 +0100267int misc_init_r(void)
268{
Tom Rix2c155132009-06-28 12:52:30 -0500269 twl4030_power_init();
Grazvydas Ignotasead39d72009-12-10 17:10:21 +0200270 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
Dirk Behme9d0fc812009-01-28 21:39:57 +0100271
Olof Johanssondf382622009-09-29 10:22:45 -0400272#if defined(CONFIG_CMD_NET)
273 setup_net_chip();
274#endif
275
Steve Sakomanc2d5b342010-08-12 15:13:02 -0700276 printf("Board revision: %d\n", get_board_revision());
Steve Sakomana06e1622010-08-24 10:37:29 -0700277
278 switch (get_sdio2_config()) {
279 case 0:
Andreas Müllerbae485d2012-01-04 15:26:20 +0000280 puts("Tranceiver detected on mmc2\n");
Steve Sakomana06e1622010-08-24 10:37:29 -0700281 MUX_OVERO_SDIO2_TRANSCEIVER();
282 break;
283 case 1:
Andreas Müllerbae485d2012-01-04 15:26:20 +0000284 puts("Direct connection on mmc2\n");
Steve Sakomana06e1622010-08-24 10:37:29 -0700285 MUX_OVERO_SDIO2_DIRECT();
286 break;
287 default:
Andreas Müllerbae485d2012-01-04 15:26:20 +0000288 puts("Unable to detect mmc2 connection type\n");
Steve Sakomana06e1622010-08-24 10:37:29 -0700289 }
290
Steve Sakomand64b5b82010-09-20 08:05:14 -0700291 switch (get_expansion_id()) {
292 case GUMSTIX_SUMMIT:
293 printf("Recognized Summit expansion board (rev %d %s)\n",
294 expansion_config.revision,
295 expansion_config.fab_revision);
296 setenv("defaultdisplay", "dvi");
297 break;
298 case GUMSTIX_TOBI:
299 printf("Recognized Tobi expansion board (rev %d %s)\n",
300 expansion_config.revision,
301 expansion_config.fab_revision);
302 setenv("defaultdisplay", "dvi");
303 break;
304 case GUMSTIX_TOBI_DUO:
305 printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
306 expansion_config.revision,
307 expansion_config.fab_revision);
Philip Balister8f7109b2011-10-11 11:23:22 +0000308 /* second lan chip */
309 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
310 0x2B000000, GPMC_SIZE_16M);
Steve Sakomand64b5b82010-09-20 08:05:14 -0700311 break;
312 case GUMSTIX_PALO35:
313 printf("Recognized Palo35 expansion board (rev %d %s)\n",
314 expansion_config.revision,
315 expansion_config.fab_revision);
316 setenv("defaultdisplay", "lcd35");
317 break;
318 case GUMSTIX_PALO43:
319 printf("Recognized Palo43 expansion board (rev %d %s)\n",
320 expansion_config.revision,
321 expansion_config.fab_revision);
322 setenv("defaultdisplay", "lcd43");
323 break;
324 case GUMSTIX_CHESTNUT43:
325 printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
326 expansion_config.revision,
327 expansion_config.fab_revision);
328 setenv("defaultdisplay", "lcd43");
329 break;
330 case GUMSTIX_PINTO:
331 printf("Recognized Pinto expansion board (rev %d %s)\n",
332 expansion_config.revision,
333 expansion_config.fab_revision);
334 break;
335 case GUMSTIX_GALLOP43:
336 printf("Recognized Gallop43 expansion board (rev %d %s)\n",
337 expansion_config.revision,
338 expansion_config.fab_revision);
339 setenv("defaultdisplay", "lcd43");
340 break;
341 case ETTUS_USRP_E:
342 printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
343 expansion_config.revision,
344 expansion_config.fab_revision);
345 MUX_USRP_E();
346 setenv("defaultdisplay", "dvi");
347 break;
348 case GUMSTIX_NO_EEPROM:
Andreas Müllerbae485d2012-01-04 15:26:20 +0000349 puts("No EEPROM on expansion board\n");
Steve Sakomand64b5b82010-09-20 08:05:14 -0700350 break;
351 default:
Andreas Müllerbae485d2012-01-04 15:26:20 +0000352 puts("Unrecognized expansion board\n");
Steve Sakomand64b5b82010-09-20 08:05:14 -0700353 }
354
355 if (expansion_config.content == 1)
356 setenv(expansion_config.env_var, expansion_config.env_setting);
357
Dirk Behmee6a6a702009-03-12 19:30:50 +0100358 dieid_num_r();
359
Dirk Behme9d0fc812009-01-28 21:39:57 +0100360 return 0;
361}
362
Tom Rix58911512009-04-01 22:02:20 -0500363/*
Dirk Behme9d0fc812009-01-28 21:39:57 +0100364 * Routine: set_muxconf_regs
365 * Description: Setting up the configuration Mux registers specific to the
366 * hardware. Many pins need to be moved from protect to primary
367 * mode.
Tom Rix58911512009-04-01 22:02:20 -0500368 */
Dirk Behme9d0fc812009-01-28 21:39:57 +0100369void set_muxconf_regs(void)
370{
371 MUX_OVERO();
372}
Olof Johanssondf382622009-09-29 10:22:45 -0400373
374#if defined(CONFIG_CMD_NET)
375/*
376 * Routine: setup_net_chip
377 * Description: Setting up the configuration GPMC registers specific to the
378 * Ethernet hardware.
379 */
380static void setup_net_chip(void)
381{
382 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
383
Steve Sakomanba9a11e2010-08-12 21:07:02 -0700384 /* first lan chip */
385 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
386 GPMC_SIZE_16M);
387
Olof Johanssondf382622009-09-29 10:22:45 -0400388 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
389 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
390 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
391 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
392 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
393 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
394 &ctrl_base->gpmc_nadv_ale);
395
396 /* Make GPIO 64 as output pin and send a magic pulse through it */
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400397 if (!gpio_request(64, "")) {
398 gpio_direction_output(64, 0);
399 gpio_set_value(64, 1);
Olof Johanssondf382622009-09-29 10:22:45 -0400400 udelay(1);
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400401 gpio_set_value(64, 0);
Olof Johanssondf382622009-09-29 10:22:45 -0400402 udelay(1);
Sanjeev Premi84c3b632011-09-08 10:51:01 -0400403 gpio_set_value(64, 1);
Olof Johanssondf382622009-09-29 10:22:45 -0400404 }
405}
406#endif
407
408int board_eth_init(bd_t *bis)
409{
410 int rc = 0;
411#ifdef CONFIG_SMC911X
412 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
413#endif
414 return rc;
415}
Steve Sakomancd7c5722010-09-19 21:21:07 -0700416
Andreas Müller137703b2012-01-04 15:26:25 +0000417#if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
Steve Sakomancd7c5722010-09-19 21:21:07 -0700418int board_mmc_init(bd_t *bis)
419{
420 omap_mmc_init(0);
421 return 0;
422}
423#endif