blob: a6e2e935a7c3059f45c7e2d6a41efc403d34727c [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020013 * SPDX-License-Identifier: GPL-2.0+
Dirk Behme220faba2009-01-28 21:39:57 +010014 */
15#include <common.h>
Olof Johansson4963f922009-09-29 10:22:45 -040016#include <netdev.h>
Tom Rix0f2a8042009-06-28 12:52:30 -050017#include <twl4030.h>
Andreas Müller785f1f02012-01-04 15:26:25 +000018#include <linux/mtd/nand.h>
Dirk Behme220faba2009-01-28 21:39:57 +010019#include <asm/io.h>
Steve Sakomanb7d80522010-09-19 21:21:07 -070020#include <asm/arch/mmc_host_def.h>
Dirk Behme220faba2009-01-28 21:39:57 +010021#include <asm/arch/mux.h>
Olof Johansson4963f922009-09-29 10:22:45 -040022#include <asm/arch/mem.h>
Dirk Behme220faba2009-01-28 21:39:57 +010023#include <asm/arch/sys_proto.h>
Andreas Bießmann9a48c5c2013-04-02 06:05:54 +000024#include <asm/omap_gpmc.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040025#include <asm/gpio.h>
Dirk Behme220faba2009-01-28 21:39:57 +010026#include <asm/mach-types.h>
27#include "overo.h"
28
John Rigby0d21ed02010-12-20 18:27:51 -070029DECLARE_GLOBAL_DATA_PTR;
30
Steve Sakoman0b880632010-09-20 08:05:14 -070031#define TWL4030_I2C_BUS 0
32#define EXPANSION_EEPROM_I2C_BUS 2
33#define EXPANSION_EEPROM_I2C_ADDRESS 0x51
34
35#define GUMSTIX_SUMMIT 0x01000200
36#define GUMSTIX_TOBI 0x02000200
37#define GUMSTIX_TOBI_DUO 0x03000200
38#define GUMSTIX_PALO35 0x04000200
39#define GUMSTIX_PALO43 0x05000200
40#define GUMSTIX_CHESTNUT43 0x06000200
41#define GUMSTIX_PINTO 0x07000200
42#define GUMSTIX_GALLOP43 0x08000200
43
44#define ETTUS_USRP_E 0x01000300
45
46#define GUMSTIX_NO_EEPROM 0xffffffff
47
48static struct {
49 unsigned int device_vendor;
50 unsigned char revision;
51 unsigned char content;
52 char fab_revision[8];
53 char env_var[16];
54 char env_setting[64];
55} expansion_config;
56
Olof Johansson4963f922009-09-29 10:22:45 -040057#if defined(CONFIG_CMD_NET)
58static void setup_net_chip(void);
59#endif
60
Steve Sakoman0d1d0082010-08-12 21:07:02 -070061/* GPMC definitions for LAN9221 chips on Tobi expansion boards */
62static const u32 gpmc_lan_config[] = {
63 NET_LAN9221_GPMC_CONFIG1,
64 NET_LAN9221_GPMC_CONFIG2,
65 NET_LAN9221_GPMC_CONFIG3,
66 NET_LAN9221_GPMC_CONFIG4,
67 NET_LAN9221_GPMC_CONFIG5,
68 NET_LAN9221_GPMC_CONFIG6,
69 /*CONFIG7- computed as params */
70};
71
Tom Rix558bb832009-04-01 22:02:20 -050072/*
Dirk Behme220faba2009-01-28 21:39:57 +010073 * Routine: board_init
74 * Description: Early hardware init.
Tom Rix558bb832009-04-01 22:02:20 -050075 */
Dirk Behme220faba2009-01-28 21:39:57 +010076int board_init(void)
77{
Dirk Behme220faba2009-01-28 21:39:57 +010078 gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
79 /* board id for Linux */
80 gd->bd->bi_arch_number = MACH_TYPE_OVERO;
81 /* boot param addr */
82 gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
83
84 return 0;
85}
86
Tom Rix558bb832009-04-01 22:02:20 -050087/*
Steve Sakoman5ddc70b2010-08-12 15:13:02 -070088 * Routine: get_board_revision
89 * Description: Returns the board revision
90 */
91int get_board_revision(void)
92{
93 int revision;
94
Andreas Müller785f1f02012-01-04 15:26:25 +000095#ifdef CONFIG_DRIVER_OMAP34XX_I2C
96 unsigned char data;
97
98 /* board revisions <= R2410 connect 4030 irq_1 to gpio112 */
99 /* these boards should return a revision number of 0 */
100 /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */
101 i2c_set_bus_num(TWL4030_I2C_BUS);
102 data = 0x01;
103 i2c_write(0x4B, 0x29, 1, &data, 1);
104 data = 0x0c;
105 i2c_write(0x4B, 0x2b, 1, &data, 1);
106 i2c_read(0x4B, 0x2a, 1, &data, 1);
107#endif
108
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400109 if (!gpio_request(112, "") &&
110 !gpio_request(113, "") &&
111 !gpio_request(115, "")) {
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700112
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400113 gpio_direction_input(112);
114 gpio_direction_input(113);
115 gpio_direction_input(115);
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700116
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400117 revision = gpio_get_value(115) << 2 |
118 gpio_get_value(113) << 1 |
119 gpio_get_value(112);
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700120 } else {
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000121 puts("Error: unable to acquire board revision GPIOs\n");
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700122 revision = -1;
123 }
124
125 return revision;
126}
127
Andreas Müller785f1f02012-01-04 15:26:25 +0000128#ifdef CONFIG_SPL_BUILD
129/*
130 * Routine: get_board_mem_timings
131 * Description: If we use SPL then there is no x-loader nor config header
132 * so we have to setup the DDR timings ourself on both banks.
133 */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000134void get_board_mem_timings(struct board_sdrc_timings *timings)
Andreas Müller785f1f02012-01-04 15:26:25 +0000135{
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000136 timings->mr = MICRON_V_MR_165;
Andreas Müller785f1f02012-01-04 15:26:25 +0000137 switch (get_board_revision()) {
138 case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000139 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
140 timings->ctrla = MICRON_V_ACTIMA_165;
141 timings->ctrlb = MICRON_V_ACTIMB_165;
142 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
Andreas Müller785f1f02012-01-04 15:26:25 +0000143 break;
144 case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000145 timings->mcfg = MICRON_V_MCFG_165(256 << 20);
146 timings->ctrla = MICRON_V_ACTIMA_165;
147 timings->ctrlb = MICRON_V_ACTIMB_165;
148 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
Andreas Müller785f1f02012-01-04 15:26:25 +0000149 break;
150 case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000151 timings->mcfg = HYNIX_V_MCFG_165(256 << 20);
152 timings->ctrla = HYNIX_V_ACTIMA_165;
153 timings->ctrlb = HYNIX_V_ACTIMB_165;
154 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
Andreas Müller785f1f02012-01-04 15:26:25 +0000155 break;
156 default:
Peter Baradaedb5c2f2012-11-13 07:40:28 +0000157 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
158 timings->ctrla = MICRON_V_ACTIMA_165;
159 timings->ctrlb = MICRON_V_ACTIMB_165;
160 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
Andreas Müller785f1f02012-01-04 15:26:25 +0000161 }
162}
163#endif
164
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700165/*
Steve Sakoman541ce992010-08-24 10:37:29 -0700166 * Routine: get_sdio2_config
167 * Description: Return information about the wifi module connection
168 * Returns 0 if the module connects though a level translator
169 * Returns 1 if the module connects directly
170 */
171int get_sdio2_config(void)
172{
173 int sdio_direct;
174
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400175 if (!gpio_request(130, "") && !gpio_request(139, "")) {
Steve Sakoman541ce992010-08-24 10:37:29 -0700176
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400177 gpio_direction_output(130, 0);
178 gpio_direction_input(139);
Steve Sakoman541ce992010-08-24 10:37:29 -0700179
180 sdio_direct = 1;
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400181 gpio_set_value(130, 0);
182 if (gpio_get_value(139) == 0) {
183 gpio_set_value(130, 1);
184 if (gpio_get_value(139) == 1)
Steve Sakoman541ce992010-08-24 10:37:29 -0700185 sdio_direct = 0;
186 }
187
Joe Hershberger9b124d32011-10-12 10:31:44 +0000188 gpio_direction_input(130);
Steve Sakoman541ce992010-08-24 10:37:29 -0700189 } else {
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000190 puts("Error: unable to acquire sdio2 clk GPIOs\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700191 sdio_direct = -1;
192 }
193
194 return sdio_direct;
195}
196
197/*
Steve Sakoman0b880632010-09-20 08:05:14 -0700198 * Routine: get_expansion_id
199 * Description: This function checks for expansion board by checking I2C
200 * bus 2 for the availability of an AT24C01B serial EEPROM.
201 * returns the device_vendor field from the EEPROM
202 */
203unsigned int get_expansion_id(void)
204{
205 i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
206
207 /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
208 if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
209 i2c_set_bus_num(TWL4030_I2C_BUS);
210 return GUMSTIX_NO_EEPROM;
211 }
212
213 /* read configuration data */
214 i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
215 sizeof(expansion_config));
216
217 i2c_set_bus_num(TWL4030_I2C_BUS);
218
219 return expansion_config.device_vendor;
220}
221
222/*
Dirk Behme220faba2009-01-28 21:39:57 +0100223 * Routine: misc_init_r
224 * Description: Configure board specific parts
Tom Rix558bb832009-04-01 22:02:20 -0500225 */
Dirk Behme220faba2009-01-28 21:39:57 +0100226int misc_init_r(void)
227{
Tom Rix0f2a8042009-06-28 12:52:30 -0500228 twl4030_power_init();
Grazvydas Ignotas17887bf2009-12-10 17:10:21 +0200229 twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
Dirk Behme220faba2009-01-28 21:39:57 +0100230
Olof Johansson4963f922009-09-29 10:22:45 -0400231#if defined(CONFIG_CMD_NET)
232 setup_net_chip();
233#endif
234
Steve Sakoman5ddc70b2010-08-12 15:13:02 -0700235 printf("Board revision: %d\n", get_board_revision());
Steve Sakoman541ce992010-08-24 10:37:29 -0700236
237 switch (get_sdio2_config()) {
238 case 0:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000239 puts("Tranceiver detected on mmc2\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700240 MUX_OVERO_SDIO2_TRANSCEIVER();
241 break;
242 case 1:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000243 puts("Direct connection on mmc2\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700244 MUX_OVERO_SDIO2_DIRECT();
245 break;
246 default:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000247 puts("Unable to detect mmc2 connection type\n");
Steve Sakoman541ce992010-08-24 10:37:29 -0700248 }
249
Steve Sakoman0b880632010-09-20 08:05:14 -0700250 switch (get_expansion_id()) {
251 case GUMSTIX_SUMMIT:
252 printf("Recognized Summit expansion board (rev %d %s)\n",
253 expansion_config.revision,
254 expansion_config.fab_revision);
255 setenv("defaultdisplay", "dvi");
256 break;
257 case GUMSTIX_TOBI:
258 printf("Recognized Tobi expansion board (rev %d %s)\n",
259 expansion_config.revision,
260 expansion_config.fab_revision);
261 setenv("defaultdisplay", "dvi");
262 break;
263 case GUMSTIX_TOBI_DUO:
264 printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
265 expansion_config.revision,
266 expansion_config.fab_revision);
Philip Balistered3cb502011-10-11 11:23:22 +0000267 /* second lan chip */
268 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
269 0x2B000000, GPMC_SIZE_16M);
Steve Sakoman0b880632010-09-20 08:05:14 -0700270 break;
271 case GUMSTIX_PALO35:
272 printf("Recognized Palo35 expansion board (rev %d %s)\n",
273 expansion_config.revision,
274 expansion_config.fab_revision);
275 setenv("defaultdisplay", "lcd35");
276 break;
277 case GUMSTIX_PALO43:
278 printf("Recognized Palo43 expansion board (rev %d %s)\n",
279 expansion_config.revision,
280 expansion_config.fab_revision);
281 setenv("defaultdisplay", "lcd43");
282 break;
283 case GUMSTIX_CHESTNUT43:
284 printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
285 expansion_config.revision,
286 expansion_config.fab_revision);
287 setenv("defaultdisplay", "lcd43");
288 break;
289 case GUMSTIX_PINTO:
290 printf("Recognized Pinto expansion board (rev %d %s)\n",
291 expansion_config.revision,
292 expansion_config.fab_revision);
293 break;
294 case GUMSTIX_GALLOP43:
295 printf("Recognized Gallop43 expansion board (rev %d %s)\n",
296 expansion_config.revision,
297 expansion_config.fab_revision);
298 setenv("defaultdisplay", "lcd43");
299 break;
300 case ETTUS_USRP_E:
301 printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
302 expansion_config.revision,
303 expansion_config.fab_revision);
304 MUX_USRP_E();
305 setenv("defaultdisplay", "dvi");
306 break;
307 case GUMSTIX_NO_EEPROM:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000308 puts("No EEPROM on expansion board\n");
Steve Sakoman0b880632010-09-20 08:05:14 -0700309 break;
310 default:
Andreas Müllerb958a5d2012-01-04 15:26:20 +0000311 puts("Unrecognized expansion board\n");
Steve Sakoman0b880632010-09-20 08:05:14 -0700312 }
313
314 if (expansion_config.content == 1)
315 setenv(expansion_config.env_var, expansion_config.env_setting);
316
Dirk Behme12dbcf62009-03-12 19:30:50 +0100317 dieid_num_r();
318
Dirk Behme220faba2009-01-28 21:39:57 +0100319 return 0;
320}
321
Tom Rix558bb832009-04-01 22:02:20 -0500322/*
Dirk Behme220faba2009-01-28 21:39:57 +0100323 * Routine: set_muxconf_regs
324 * Description: Setting up the configuration Mux registers specific to the
325 * hardware. Many pins need to be moved from protect to primary
326 * mode.
Tom Rix558bb832009-04-01 22:02:20 -0500327 */
Dirk Behme220faba2009-01-28 21:39:57 +0100328void set_muxconf_regs(void)
329{
330 MUX_OVERO();
331}
Olof Johansson4963f922009-09-29 10:22:45 -0400332
333#if defined(CONFIG_CMD_NET)
334/*
335 * Routine: setup_net_chip
336 * Description: Setting up the configuration GPMC registers specific to the
337 * Ethernet hardware.
338 */
339static void setup_net_chip(void)
340{
341 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
342
Steve Sakoman0d1d0082010-08-12 21:07:02 -0700343 /* first lan chip */
344 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
345 GPMC_SIZE_16M);
346
Olof Johansson4963f922009-09-29 10:22:45 -0400347 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
348 writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
349 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
350 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
351 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
352 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
353 &ctrl_base->gpmc_nadv_ale);
354
355 /* Make GPIO 64 as output pin and send a magic pulse through it */
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400356 if (!gpio_request(64, "")) {
357 gpio_direction_output(64, 0);
358 gpio_set_value(64, 1);
Olof Johansson4963f922009-09-29 10:22:45 -0400359 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400360 gpio_set_value(64, 0);
Olof Johansson4963f922009-09-29 10:22:45 -0400361 udelay(1);
Sanjeev Premi7b3dc822011-09-08 10:51:01 -0400362 gpio_set_value(64, 1);
Olof Johansson4963f922009-09-29 10:22:45 -0400363 }
364}
365#endif
366
367int board_eth_init(bd_t *bis)
368{
369 int rc = 0;
370#ifdef CONFIG_SMC911X
371 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
372#endif
373 return rc;
374}
Steve Sakomanb7d80522010-09-19 21:21:07 -0700375
Andreas Müller785f1f02012-01-04 15:26:25 +0000376#if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
Steve Sakomanb7d80522010-09-19 21:21:07 -0700377int board_mmc_init(bd_t *bis)
378{
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +0000379 return omap_mmc_init(0, 0, 0, -1, -1);
Steve Sakomanb7d80522010-09-19 21:21:07 -0700380}
381#endif