blob: c6d50a07acabc18296474b5581c5c41026a86c99 [file] [log] [blame]
Dirk Behme220faba2009-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 Johansson4963f922009-09-29 10:22:45 -040032#include <netdev.h>
Tom Rix0f2a8042009-06-28 12:52:30 -050033#include <twl4030.h>
Andreas Müller785f1f02012-01-04 15:26:25 +000034#include <linux/mtd/nand.h>
Dirk Behme220faba2009-01-28 21:39:57 +010035#include <asm/io.h>
Steve Sakomanb7d80522010-09-19 21:21:07 -070036#include <asm/arch/mmc_host_def.h>
Dirk Behme220faba2009-01-28 21:39:57 +010037#include <asm/arch/mux.h>
Olof Johansson4963f922009-09-29 10:22:45 -040038#include <asm/arch/mem.h>
Dirk Behme220faba2009-01-28 21:39:57 +010039#include <asm/arch/sys_proto.h>
Philip Balister1dc7d232011-09-14 13:32:22 -040040#include <asm/arch/omap_gpmc.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040041#include <asm/gpio.h>
Dirk Behme220faba2009-01-28 21:39:57 +010042#include <asm/mach-types.h>
43#include "overo.h"
44
John Rigby0d21ed02010-12-20 18:27:51 -070045DECLARE_GLOBAL_DATA_PTR;
46
Steve Sakoman0b880632010-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 Johansson4963f922009-09-29 10:22:45 -040073#if defined(CONFIG_CMD_NET)
74static void setup_net_chip(void);
75#endif
76
Steve Sakoman0d1d0082010-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 Rix558bb832009-04-01 22:02:20 -050088/*
Dirk Behme220faba2009-01-28 21:39:57 +010089 * Routine: board_init
90 * Description: Early hardware init.
Tom Rix558bb832009-04-01 22:02:20 -050091 */
Dirk Behme220faba2009-01-28 21:39:57 +010092int board_init(void)
93{
Dirk Behme220faba2009-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 Rix558bb832009-04-01 22:02:20 -0500103/*
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700104 * Routine: get_board_revision
105 * Description: Returns the board revision
106 */
107int get_board_revision(void)
108{
109 int revision;
110
Andreas Müller785f1f02012-01-04 15:26:25 +0000111#ifdef CONFIG_DRIVER_OMAP34XX_I2C
112 unsigned char data;
113
114 /* board revisions <= R2410 connect 4030 irq_1 to gpio112 */
115 /* these boards should return a revision number of 0 */
116 /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */
117 i2c_set_bus_num(TWL4030_I2C_BUS);
118 data = 0x01;
119 i2c_write(0x4B, 0x29, 1, &data, 1);
120 data = 0x0c;
121 i2c_write(0x4B, 0x2b, 1, &data, 1);
122 i2c_read(0x4B, 0x2a, 1, &data, 1);
123#endif
124
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400125 if (!gpio_request(112, "") &&
126 !gpio_request(113, "") &&
127 !gpio_request(115, "")) {
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700128
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400129 gpio_direction_input(112);
130 gpio_direction_input(113);
131 gpio_direction_input(115);
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700132
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400133 revision = gpio_get_value(115) << 2 |
134 gpio_get_value(113) << 1 |
135 gpio_get_value(112);
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700136 } else {
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000137 puts("Error: unable to acquire board revision GPIOs\n");
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700138 revision = -1;
139 }
140
141 return revision;
142}
143
Andreas Müller785f1f02012-01-04 15:26:25 +0000144#ifdef CONFIG_SPL_BUILD
145/*
146 * Routine: get_board_mem_timings
147 * Description: If we use SPL then there is no x-loader nor config header
148 * so we have to setup the DDR timings ourself on both banks.
149 */
150void get_board_mem_timings(u32 *mcfg, u32 *ctrla, u32 *ctrlb, u32 *rfr_ctrl,
151 u32 *mr)
152{
153 *mr = MICRON_V_MR_165;
154 switch (get_board_revision()) {
155 case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */
156 *mcfg = MICRON_V_MCFG_165(128 << 20);
157 *ctrla = MICRON_V_ACTIMA_165;
158 *ctrlb = MICRON_V_ACTIMB_165;
159 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
160 break;
161 case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */
162 *mcfg = MICRON_V_MCFG_165(256 << 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 case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */
168 *mcfg = HYNIX_V_MCFG_165(256 << 20);
169 *ctrla = HYNIX_V_ACTIMA_165;
170 *ctrlb = HYNIX_V_ACTIMB_165;
171 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
172 break;
173 default:
174 *mcfg = MICRON_V_MCFG_165(128 << 20);
175 *ctrla = MICRON_V_ACTIMA_165;
176 *ctrlb = MICRON_V_ACTIMB_165;
177 *rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
178 }
179}
180#endif
181
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700182/*
Steve Sakoman541ce992010-08-24 10:37:29 -0700183 * Routine: get_sdio2_config
184 * Description: Return information about the wifi module connection
185 * Returns 0 if the module connects though a level translator
186 * Returns 1 if the module connects directly
187 */
188int get_sdio2_config(void)
189{
190 int sdio_direct;
191
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400192 if (!gpio_request(130, "") && !gpio_request(139, "")) {
Steve Sakoman541ce992010-08-24 10:37:29 -0700193
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400194 gpio_direction_output(130, 0);
195 gpio_direction_input(139);
Steve Sakoman541ce992010-08-24 10:37:29 -0700196
197 sdio_direct = 1;
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400198 gpio_set_value(130, 0);
199 if (gpio_get_value(139) == 0) {
200 gpio_set_value(130, 1);
201 if (gpio_get_value(139) == 1)
Steve Sakoman541ce992010-08-24 10:37:29 -0700202 sdio_direct = 0;
203 }
204
Joe Hershberger9b124d32011-10-12 10:31:44 +0000205 gpio_direction_input(130);
Steve Sakoman541ce992010-08-24 10:37:29 -0700206 } else {
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000207 puts("Error: unable to acquire sdio2 clk GPIOs\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700208 sdio_direct = -1;
209 }
210
211 return sdio_direct;
212}
213
214/*
Steve Sakoman0b880632010-09-20 08:05:14 -0700215 * Routine: get_expansion_id
216 * Description: This function checks for expansion board by checking I2C
217 * bus 2 for the availability of an AT24C01B serial EEPROM.
218 * returns the device_vendor field from the EEPROM
219 */
220unsigned int get_expansion_id(void)
221{
222 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
223
224 /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
225 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
226 i2c_set_bus_num(TWL4030_I2C_BUS);
227 return GUMSTIX_NO_EEPROM;
228 }
229
230 /* read configuration data */
231 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
232 sizeof(expansion_config));
233
234 i2c_set_bus_num(TWL4030_I2C_BUS);
235
236 return expansion_config.device_vendor;
237}
238
239/*
Dirk Behme220faba2009-01-28 21:39:57 +0100240 * Routine: misc_init_r
241 * Description: Configure board specific parts
Tom Rix558bb832009-04-01 22:02:20 -0500242 */
Dirk Behme220faba2009-01-28 21:39:57 +0100243int misc_init_r(void)
244{
Tom Rix0f2a8042009-06-28 12:52:30 -0500245 twl4030_power_init();
Grazvydas Ignotas17887bf2009-12-10 17:10:21 +0200246 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
Dirk Behme220faba2009-01-28 21:39:57 +0100247
Olof Johansson4963f922009-09-29 10:22:45 -0400248#if defined(CONFIG_CMD_NET)
249 setup_net_chip();
250#endif
251
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700252 printf("Board revision: %d\n", get_board_revision());
Steve Sakoman541ce992010-08-24 10:37:29 -0700253
254 switch (get_sdio2_config()) {
255 case 0:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000256 puts("Tranceiver detected on mmc2\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700257 MUX_OVERO_SDIO2_TRANSCEIVER();
258 break;
259 case 1:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000260 puts("Direct connection on mmc2\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700261 MUX_OVERO_SDIO2_DIRECT();
262 break;
263 default:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000264 puts("Unable to detect mmc2 connection type\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700265 }
266
Steve Sakoman0b880632010-09-20 08:05:14 -0700267 switch (get_expansion_id()) {
268 case GUMSTIX_SUMMIT:
269 printf("Recognized Summit expansion board (rev %d %s)\n",
270 expansion_config.revision,
271 expansion_config.fab_revision);
272 setenv("defaultdisplay", "dvi");
273 break;
274 case GUMSTIX_TOBI:
275 printf("Recognized Tobi expansion board (rev %d %s)\n",
276 expansion_config.revision,
277 expansion_config.fab_revision);
278 setenv("defaultdisplay", "dvi");
279 break;
280 case GUMSTIX_TOBI_DUO:
281 printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
282 expansion_config.revision,
283 expansion_config.fab_revision);
Philip Balistered3cb502011-10-11 11:23:22 +0000284 /* second lan chip */
285 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
286 0x2B000000, GPMC_SIZE_16M);
Steve Sakoman0b880632010-09-20 08:05:14 -0700287 break;
288 case GUMSTIX_PALO35:
289 printf("Recognized Palo35 expansion board (rev %d %s)\n",
290 expansion_config.revision,
291 expansion_config.fab_revision);
292 setenv("defaultdisplay", "lcd35");
293 break;
294 case GUMSTIX_PALO43:
295 printf("Recognized Palo43 expansion board (rev %d %s)\n",
296 expansion_config.revision,
297 expansion_config.fab_revision);
298 setenv("defaultdisplay", "lcd43");
299 break;
300 case GUMSTIX_CHESTNUT43:
301 printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
302 expansion_config.revision,
303 expansion_config.fab_revision);
304 setenv("defaultdisplay", "lcd43");
305 break;
306 case GUMSTIX_PINTO:
307 printf("Recognized Pinto expansion board (rev %d %s)\n",
308 expansion_config.revision,
309 expansion_config.fab_revision);
310 break;
311 case GUMSTIX_GALLOP43:
312 printf("Recognized Gallop43 expansion board (rev %d %s)\n",
313 expansion_config.revision,
314 expansion_config.fab_revision);
315 setenv("defaultdisplay", "lcd43");
316 break;
317 case ETTUS_USRP_E:
318 printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
319 expansion_config.revision,
320 expansion_config.fab_revision);
321 MUX_USRP_E();
322 setenv("defaultdisplay", "dvi");
323 break;
324 case GUMSTIX_NO_EEPROM:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000325 puts("No EEPROM on expansion board\n");
Steve Sakoman0b880632010-09-20 08:05:14 -0700326 break;
327 default:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000328 puts("Unrecognized expansion board\n");
Steve Sakoman0b880632010-09-20 08:05:14 -0700329 }
330
331 if (expansion_config.content == 1)
332 setenv(expansion_config.env_var, expansion_config.env_setting);
333
Dirk Behme12dbcf62009-03-12 19:30:50 +0100334 dieid_num_r();
335
Dirk Behme220faba2009-01-28 21:39:57 +0100336 return 0;
337}
338
Tom Rix558bb832009-04-01 22:02:20 -0500339/*
Dirk Behme220faba2009-01-28 21:39:57 +0100340 * Routine: set_muxconf_regs
341 * Description: Setting up the configuration Mux registers specific to the
342 * hardware. Many pins need to be moved from protect to primary
343 * mode.
Tom Rix558bb832009-04-01 22:02:20 -0500344 */
Dirk Behme220faba2009-01-28 21:39:57 +0100345void set_muxconf_regs(void)
346{
347 MUX_OVERO();
348}
Olof Johansson4963f922009-09-29 10:22:45 -0400349
350#if defined(CONFIG_CMD_NET)
351/*
352 * Routine: setup_net_chip
353 * Description: Setting up the configuration GPMC registers specific to the
354 * Ethernet hardware.
355 */
356static void setup_net_chip(void)
357{
358 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
359
Steve Sakoman0d1d0082010-08-12 21:07:02 -0700360 /* first lan chip */
361 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
362 GPMC_SIZE_16M);
363
Olof Johansson4963f922009-09-29 10:22:45 -0400364 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
365 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
366 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
367 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
368 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
369 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
370 &ctrl_base->gpmc_nadv_ale);
371
372 /* Make GPIO 64 as output pin and send a magic pulse through it */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400373 if (!gpio_request(64, "")) {
374 gpio_direction_output(64, 0);
375 gpio_set_value(64, 1);
Olof Johansson4963f922009-09-29 10:22:45 -0400376 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400377 gpio_set_value(64, 0);
Olof Johansson4963f922009-09-29 10:22:45 -0400378 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400379 gpio_set_value(64, 1);
Olof Johansson4963f922009-09-29 10:22:45 -0400380 }
381}
382#endif
383
384int board_eth_init(bd_t *bis)
385{
386 int rc = 0;
387#ifdef CONFIG_SMC911X
388 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
389#endif
390 return rc;
391}
Steve Sakomanb7d80522010-09-19 21:21:07 -0700392
Andreas Müller785f1f02012-01-04 15:26:25 +0000393#if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
Steve Sakomanb7d80522010-09-19 21:21:07 -0700394int board_mmc_init(bd_t *bis)
395{
Jonathan Solnita9b05562012-02-24 11:30:18 +0000396 omap_mmc_init(0, 0, 0);
Steve Sakomanb7d80522010-09-19 21:21:07 -0700397 return 0;
398}
399#endif