]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/overo/overo.c
omap3: overo: Move ethernet setup to board_eth_init function
[karo-tx-uboot.git] / board / overo / overo.c
1 /*
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  * SPDX-License-Identifier:     GPL-2.0+
14  */
15 #include <common.h>
16 #include <netdev.h>
17 #include <twl4030.h>
18 #include <linux/mtd/nand.h>
19 #include <asm/io.h>
20 #include <asm/arch/mmc_host_def.h>
21 #include <asm/arch/mux.h>
22 #include <asm/arch/mem.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/gpio.h>
25 #include <asm/mach-types.h>
26 #include "overo.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #define TWL4030_I2C_BUS                 0
31 #define EXPANSION_EEPROM_I2C_BUS        2
32 #define EXPANSION_EEPROM_I2C_ADDRESS    0x51
33
34 #define GUMSTIX_SUMMIT                  0x01000200
35 #define GUMSTIX_TOBI                    0x02000200
36 #define GUMSTIX_TOBI_DUO                0x03000200
37 #define GUMSTIX_PALO35                  0x04000200
38 #define GUMSTIX_PALO43                  0x05000200
39 #define GUMSTIX_CHESTNUT43              0x06000200
40 #define GUMSTIX_PINTO                   0x07000200
41 #define GUMSTIX_GALLOP43                0x08000200
42 #define GUMSTIX_ALTO35                  0x09000200
43 #define GUMSTIX_STAGECOACH              0x0A000200
44 #define GUMSTIX_THUMBO                  0x0B000200
45 #define GUMSTIX_TURTLECORE              0x0C000200
46 #define GUMSTIX_ARBOR43C                0x0D000200
47
48 #define ETTUS_USRP_E                    0x01000300
49
50 #define GUMSTIX_NO_EEPROM               0xffffffff
51
52 static struct {
53         unsigned int device_vendor;
54         unsigned char revision;
55         unsigned char content;
56         char fab_revision[8];
57         char env_var[16];
58         char env_setting[64];
59 } expansion_config;
60
61 /*
62  * Routine: board_init
63  * Description: Early hardware init.
64  */
65 int board_init(void)
66 {
67         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
68         /* board id for Linux */
69         gd->bd->bi_arch_number = MACH_TYPE_OVERO;
70         /* boot param addr */
71         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
72
73         return 0;
74 }
75
76 /*
77  * Routine: get_board_revision
78  * Description: Returns the board revision
79  */
80 int get_board_revision(void)
81 {
82         int revision;
83
84 #ifdef CONFIG_SYS_I2C_OMAP34XX
85         unsigned char data;
86
87         /* board revisions <= R2410 connect 4030 irq_1 to gpio112             */
88         /* these boards should return a revision number of 0                  */
89         /* the code below forces a 4030 RTC irq to ensure that gpio112 is low */
90         i2c_set_bus_num(TWL4030_I2C_BUS);
91         data = 0x01;
92         i2c_write(0x4B, 0x29, 1, &data, 1);
93         data = 0x0c;
94         i2c_write(0x4B, 0x2b, 1, &data, 1);
95         i2c_read(0x4B, 0x2a, 1, &data, 1);
96 #endif
97
98         if (!gpio_request(112, "") &&
99             !gpio_request(113, "") &&
100             !gpio_request(115, "")) {
101
102                 gpio_direction_input(112);
103                 gpio_direction_input(113);
104                 gpio_direction_input(115);
105
106                 revision = gpio_get_value(115) << 2 |
107                            gpio_get_value(113) << 1 |
108                            gpio_get_value(112);
109         } else {
110                 puts("Error: unable to acquire board revision GPIOs\n");
111                 revision = -1;
112         }
113
114         return revision;
115 }
116
117 #ifdef CONFIG_SPL_BUILD
118 /*
119  * Routine: get_board_mem_timings
120  * Description: If we use SPL then there is no x-loader nor config header
121  * so we have to setup the DDR timings ourself on both banks.
122  */
123 void get_board_mem_timings(struct board_sdrc_timings *timings)
124 {
125         timings->mr = MICRON_V_MR_165;
126         switch (get_board_revision()) {
127         case REVISION_0: /* Micron 1286MB/256MB, 1/2 banks of 128MB */
128                 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
129                 timings->ctrla = MICRON_V_ACTIMA_165;
130                 timings->ctrlb = MICRON_V_ACTIMB_165;
131                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
132                 break;
133         case REVISION_1: /* Micron 256MB/512MB, 1/2 banks of 256MB */
134         case REVISION_4:
135                 timings->mcfg = MICRON_V_MCFG_200(256 << 20);
136                 timings->ctrla = MICRON_V_ACTIMA_200;
137                 timings->ctrlb = MICRON_V_ACTIMB_200;
138                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
139                 break;
140         case REVISION_2: /* Hynix 256MB/512MB, 1/2 banks of 256MB */
141                 timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
142                 timings->ctrla = HYNIX_V_ACTIMA_200;
143                 timings->ctrlb = HYNIX_V_ACTIMB_200;
144                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
145                 break;
146         case REVISION_3: /* Micron 512MB/1024MB, 1/2 banks of 512MB */
147                 timings->mcfg = MCFG(512 << 20, 15);
148                 timings->ctrla = MICRON_V_ACTIMA_200;
149                 timings->ctrlb = MICRON_V_ACTIMB_200;
150                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
151                 break;
152         default:
153                 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
154                 timings->ctrla = MICRON_V_ACTIMA_165;
155                 timings->ctrlb = MICRON_V_ACTIMB_165;
156                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
157         }
158 }
159 #endif
160
161 /*
162  * Routine: get_sdio2_config
163  * Description: Return information about the wifi module connection
164  *              Returns 0 if the module connects though a level translator
165  *              Returns 1 if the module connects directly
166  */
167 int get_sdio2_config(void)
168 {
169         int sdio_direct;
170
171         if (!gpio_request(130, "") && !gpio_request(139, "")) {
172
173                 gpio_direction_output(130, 0);
174                 gpio_direction_input(139);
175
176                 sdio_direct = 1;
177                 gpio_set_value(130, 0);
178                 if (gpio_get_value(139) == 0) {
179                         gpio_set_value(130, 1);
180                         if (gpio_get_value(139) == 1)
181                                 sdio_direct = 0;
182                 }
183
184                 gpio_direction_input(130);
185         } else {
186                 puts("Error: unable to acquire sdio2 clk GPIOs\n");
187                 sdio_direct = -1;
188         }
189
190         return sdio_direct;
191 }
192
193 /*
194  * Routine: get_expansion_id
195  * Description: This function checks for expansion board by checking I2C
196  *              bus 2 for the availability of an AT24C01B serial EEPROM.
197  *              returns the device_vendor field from the EEPROM
198  */
199 unsigned int get_expansion_id(void)
200 {
201         i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
202
203         /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
204         if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
205                 i2c_set_bus_num(TWL4030_I2C_BUS);
206                 return GUMSTIX_NO_EEPROM;
207         }
208
209         /* read configuration data */
210         i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
211                  sizeof(expansion_config));
212
213         i2c_set_bus_num(TWL4030_I2C_BUS);
214
215         return expansion_config.device_vendor;
216 }
217
218 /*
219  * Routine: misc_init_r
220  * Description: Configure board specific parts
221  */
222 int misc_init_r(void)
223 {
224         unsigned int expansion_id;
225
226         twl4030_power_init();
227         twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
228
229         printf("Board revision: %d\n", get_board_revision());
230
231         switch (get_sdio2_config()) {
232         case 0:
233                 puts("Tranceiver detected on mmc2\n");
234                 MUX_OVERO_SDIO2_TRANSCEIVER();
235                 break;
236         case 1:
237                 puts("Direct connection on mmc2\n");
238                 MUX_OVERO_SDIO2_DIRECT();
239                 break;
240         default:
241                 puts("Unable to detect mmc2 connection type\n");
242         }
243
244         expansion_id = get_expansion_id();
245         switch (expansion_id) {
246         case GUMSTIX_SUMMIT:
247                 printf("Recognized Summit expansion board (rev %d %s)\n",
248                         expansion_config.revision,
249                         expansion_config.fab_revision);
250                 setenv("defaultdisplay", "dvi");
251                 setenv("expansionname", "summit");
252                 break;
253         case GUMSTIX_TOBI:
254                 printf("Recognized Tobi expansion board (rev %d %s)\n",
255                         expansion_config.revision,
256                         expansion_config.fab_revision);
257                 setenv("defaultdisplay", "dvi");
258                 setenv("expansionname", "tobi");
259                 break;
260         case GUMSTIX_TOBI_DUO:
261                 printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
262                         expansion_config.revision,
263                         expansion_config.fab_revision);
264                 break;
265         case GUMSTIX_PALO35:
266                 printf("Recognized Palo35 expansion board (rev %d %s)\n",
267                         expansion_config.revision,
268                         expansion_config.fab_revision);
269                 setenv("defaultdisplay", "lcd35");
270                 break;
271         case GUMSTIX_PALO43:
272                 printf("Recognized Palo43 expansion board (rev %d %s)\n",
273                         expansion_config.revision,
274                         expansion_config.fab_revision);
275                 setenv("defaultdisplay", "lcd43");
276                 setenv("expansionname", "palo43");
277                 break;
278         case GUMSTIX_CHESTNUT43:
279                 printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
280                         expansion_config.revision,
281                         expansion_config.fab_revision);
282                 setenv("defaultdisplay", "lcd43");
283                 setenv("expansionname", "chestnut43");
284                 break;
285         case GUMSTIX_PINTO:
286                 printf("Recognized Pinto expansion board (rev %d %s)\n",
287                         expansion_config.revision,
288                         expansion_config.fab_revision);
289                 break;
290         case GUMSTIX_GALLOP43:
291                 printf("Recognized Gallop43 expansion board (rev %d %s)\n",
292                         expansion_config.revision,
293                         expansion_config.fab_revision);
294                 setenv("defaultdisplay", "lcd43");
295                 setenv("expansionname", "gallop43");
296                 break;
297         case GUMSTIX_ALTO35:
298                 printf("Recognized Alto35 expansion board (rev %d %s)\n",
299                         expansion_config.revision,
300                         expansion_config.fab_revision);
301                 MUX_ALTO35();
302                 setenv("defaultdisplay", "lcd35");
303                 setenv("expansionname", "alto35");
304                 break;
305         case GUMSTIX_STAGECOACH:
306                 printf("Recognized Stagecoach expansion board (rev %d %s)\n",
307                         expansion_config.revision,
308                         expansion_config.fab_revision);
309                 break;
310         case GUMSTIX_THUMBO:
311                 printf("Recognized Thumbo expansion board (rev %d %s)\n",
312                         expansion_config.revision,
313                         expansion_config.fab_revision);
314                 break;
315         case GUMSTIX_TURTLECORE:
316                 printf("Recognized Turtlecore expansion board (rev %d %s)\n",
317                         expansion_config.revision,
318                         expansion_config.fab_revision);
319                 break;
320         case GUMSTIX_ARBOR43C:
321                 printf("Recognized Arbor43C expansion board (rev %d %s)\n",
322                         expansion_config.revision,
323                         expansion_config.fab_revision);
324                 MUX_ARBOR43C();
325                 setenv("defaultdisplay", "lcd43");
326                 break;
327         case ETTUS_USRP_E:
328                 printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
329                         expansion_config.revision,
330                         expansion_config.fab_revision);
331                 MUX_USRP_E();
332                 setenv("defaultdisplay", "dvi");
333                 break;
334         case GUMSTIX_NO_EEPROM:
335                 puts("No EEPROM on expansion board\n");
336                 setenv("expansionname", "tobi");
337                 break;
338         default:
339                 if (expansion_id == 0x0)
340                         setenv("expansionname", "tobi");
341                 printf("Unrecognized expansion board 0x%08x\n", expansion_id);
342                 break;
343         }
344
345         if (expansion_config.content == 1)
346                 setenv(expansion_config.env_var, expansion_config.env_setting);
347
348         dieid_num_r();
349
350         if (get_cpu_family() == CPU_OMAP34XX)
351                 setenv("boardname", "overo");
352         else
353                 setenv("boardname", "overo-storm");
354
355         return 0;
356 }
357
358 /*
359  * Routine: set_muxconf_regs
360  * Description: Setting up the configuration Mux registers specific to the
361  *              hardware. Many pins need to be moved from protect to primary
362  *              mode.
363  */
364 void set_muxconf_regs(void)
365 {
366         MUX_OVERO();
367 }
368
369 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_SPL_BUILD)
370 /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
371 static const u32 gpmc_lan_config[] = {
372         NET_LAN9221_GPMC_CONFIG1,
373         NET_LAN9221_GPMC_CONFIG2,
374         NET_LAN9221_GPMC_CONFIG3,
375         NET_LAN9221_GPMC_CONFIG4,
376         NET_LAN9221_GPMC_CONFIG5,
377         NET_LAN9221_GPMC_CONFIG6,
378         /*CONFIG7- computed as params */
379 };
380
381 /*
382  * Routine: setup_net_chip
383  * Description: Setting up the configuration GPMC registers specific to the
384  *            Ethernet hardware.
385  */
386 static void setup_net_chip(void)
387 {
388         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
389
390         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
391         writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
392         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
393         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
394         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
395         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
396                 &ctrl_base->gpmc_nadv_ale);
397 }
398
399 /*
400  * Routine: reset_net_chip
401  * Description: Reset the Ethernet hardware.
402  */
403 static void reset_net_chip(void)
404 {
405         /* Make GPIO 64 as output pin and send a magic pulse through it */
406         if (!gpio_request(64, "")) {
407                 gpio_direction_output(64, 0);
408                 gpio_set_value(64, 1);
409                 udelay(1);
410                 gpio_set_value(64, 0);
411                 udelay(1);
412                 gpio_set_value(64, 1);
413         }
414 }
415
416 int board_eth_init(bd_t *bis)
417 {
418         unsigned int expansion_id;
419         int rc = 0;
420
421 #ifdef CONFIG_SMC911X
422         expansion_id = get_expansion_id();
423         switch (expansion_id) {
424         case GUMSTIX_TOBI_DUO:
425                 /* second lan chip */
426                 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
427                                       0x2B000000, GPMC_SIZE_16M);
428                 /* no break */
429         case GUMSTIX_TOBI:
430         case GUMSTIX_CHESTNUT43:
431         case GUMSTIX_STAGECOACH:
432         case GUMSTIX_NO_EEPROM:
433         case GUMSTIX_EMPTY_EEPROM:
434                 /* first lan chip */
435                 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
436                                       0x2C000000, GPMC_SIZE_16M);
437
438                 setup_net_chip();
439                 reset_net_chip();
440
441                 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
442                 break;
443         default:
444                 break;
445         }
446 #endif
447
448         return rc;
449 }
450 #endif
451
452 #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
453 int board_mmc_init(bd_t *bis)
454 {
455         return omap_mmc_init(0, 0, 0, -1, -1);
456 }
457 #endif