ARMV7: OMAP4: Use generic mmc driver on Overo
[platform/kernel/u-boot.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  * 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>
32 #include <netdev.h>
33 #include <twl4030.h>
34 #include <asm/io.h>
35 #include <asm/arch/mmc_host_def.h>
36 #include <asm/arch/mux.h>
37 #include <asm/arch/mem.h>
38 #include <asm/arch/sys_proto.h>
39 #include <asm/arch/gpio.h>
40 #include <asm/mach-types.h>
41 #include "overo.h"
42
43 #if defined(CONFIG_CMD_NET)
44 static void setup_net_chip(void);
45 #endif
46
47 /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
48 static const u32 gpmc_lan_config[] = {
49     NET_LAN9221_GPMC_CONFIG1,
50     NET_LAN9221_GPMC_CONFIG2,
51     NET_LAN9221_GPMC_CONFIG3,
52     NET_LAN9221_GPMC_CONFIG4,
53     NET_LAN9221_GPMC_CONFIG5,
54     NET_LAN9221_GPMC_CONFIG6,
55     /*CONFIG7- computed as params */
56 };
57
58 /*
59  * Routine: board_init
60  * Description: Early hardware init.
61  */
62 int board_init(void)
63 {
64         DECLARE_GLOBAL_DATA_PTR;
65
66         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
67         /* board id for Linux */
68         gd->bd->bi_arch_number = MACH_TYPE_OVERO;
69         /* boot param addr */
70         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
71
72         return 0;
73 }
74
75 /*
76  * Routine: get_board_revision
77  * Description: Returns the board revision
78  */
79 int get_board_revision(void)
80 {
81         int revision;
82
83         if (!omap_request_gpio(112) &&
84             !omap_request_gpio(113) &&
85             !omap_request_gpio(115)) {
86
87                 omap_set_gpio_direction(112, 1);
88                 omap_set_gpio_direction(113, 1);
89                 omap_set_gpio_direction(115, 1);
90
91                 revision = omap_get_gpio_datain(115) << 2 |
92                            omap_get_gpio_datain(113) << 1 |
93                            omap_get_gpio_datain(112);
94
95                 omap_free_gpio(112);
96                 omap_free_gpio(113);
97                 omap_free_gpio(115);
98         } else {
99                 printf("Error: unable to acquire board revision GPIOs\n");
100                 revision = -1;
101         }
102
103         return revision;
104 }
105
106 /*
107  * Routine: get_sdio2_config
108  * Description: Return information about the wifi module connection
109  *              Returns 0 if the module connects though a level translator
110  *              Returns 1 if the module connects directly
111  */
112 int get_sdio2_config(void)
113 {
114         int sdio_direct;
115
116         if (!omap_request_gpio(130) && !omap_request_gpio(139)) {
117
118                 omap_set_gpio_direction(130, 0);
119                 omap_set_gpio_direction(139, 1);
120
121                 sdio_direct = 1;
122                 omap_set_gpio_dataout(130, 0);
123                 if (omap_get_gpio_datain(139) == 0) {
124                         omap_set_gpio_dataout(130, 1);
125                         if (omap_get_gpio_datain(139) == 1)
126                                 sdio_direct = 0;
127                 }
128
129                 omap_free_gpio(130);
130                 omap_free_gpio(139);
131         } else {
132                 printf("Error: unable to acquire sdio2 clk GPIOs\n");
133                 sdio_direct = -1;
134         }
135
136         return sdio_direct;
137 }
138
139 /*
140  * Routine: misc_init_r
141  * Description: Configure board specific parts
142  */
143 int misc_init_r(void)
144 {
145         twl4030_power_init();
146         twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
147
148 #if defined(CONFIG_CMD_NET)
149         setup_net_chip();
150 #endif
151
152         printf("Board revision: %d\n", get_board_revision());
153
154         switch (get_sdio2_config()) {
155         case 0:
156                 printf("Tranceiver detected on mmc2\n");
157                 MUX_OVERO_SDIO2_TRANSCEIVER();
158                 break;
159         case 1:
160                 printf("Direct connection on mmc2\n");
161                 MUX_OVERO_SDIO2_DIRECT();
162                 break;
163         default:
164                 printf("Unable to detect mmc2 connection type\n");
165         }
166
167         dieid_num_r();
168
169         return 0;
170 }
171
172 /*
173  * Routine: set_muxconf_regs
174  * Description: Setting up the configuration Mux registers specific to the
175  *              hardware. Many pins need to be moved from protect to primary
176  *              mode.
177  */
178 void set_muxconf_regs(void)
179 {
180         MUX_OVERO();
181 }
182
183 #if defined(CONFIG_CMD_NET)
184 /*
185  * Routine: setup_net_chip
186  * Description: Setting up the configuration GPMC registers specific to the
187  *            Ethernet hardware.
188  */
189 static void setup_net_chip(void)
190 {
191         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
192
193         /* first lan chip */
194         enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5], 0x2C000000,
195                         GPMC_SIZE_16M);
196
197         /* second lan chip */
198         enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4], 0x2B000000,
199                         GPMC_SIZE_16M);
200
201         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
202         writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
203         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
204         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
205         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
206         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
207                 &ctrl_base->gpmc_nadv_ale);
208
209         /* Make GPIO 64 as output pin and send a magic pulse through it */
210         if (!omap_request_gpio(64)) {
211                 omap_set_gpio_direction(64, 0);
212                 omap_set_gpio_dataout(64, 1);
213                 udelay(1);
214                 omap_set_gpio_dataout(64, 0);
215                 udelay(1);
216                 omap_set_gpio_dataout(64, 1);
217         }
218 }
219 #endif
220
221 int board_eth_init(bd_t *bis)
222 {
223         int rc = 0;
224 #ifdef CONFIG_SMC911X
225         rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
226 #endif
227         return rc;
228 }
229
230 #ifdef CONFIG_GENERIC_MMC
231 int board_mmc_init(bd_t *bis)
232 {
233         omap_mmc_init(0);
234         return 0;
235 }
236 #endif