common: Drop linux/delay.h from common header
[oweals/u-boot.git] / board / overo / overo.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Maintainer : Steve Sakoman <steve@sakoman.com>
4  *
5  * Derived from Beagle Board, 3430 SDP, and OMAP3EVM code by
6  *      Richard Woodruff <r-woodruff2@ti.com>
7  *      Syed Mohammed Khasim <khasim@ti.com>
8  *      Sunil Kumar <sunilsaini05@gmail.com>
9  *      Shashi Ranjan <shashiranjanmca05@gmail.com>
10  *
11  * (C) Copyright 2004-2008
12  * Texas Instruments, <www.ti.com>
13  */
14 #include <common.h>
15 #include <dm.h>
16 #include <env.h>
17 #include <init.h>
18 #include <malloc.h>
19 #include <net.h>
20 #include <ns16550.h>
21 #include <netdev.h>
22 #include <twl4030.h>
23 #include <linux/delay.h>
24 #include <linux/mtd/rawnand.h>
25 #include <asm/io.h>
26 #include <asm/arch/mmc_host_def.h>
27 #include <asm/arch/mux.h>
28 #include <asm/arch/mem.h>
29 #include <asm/arch/sys_proto.h>
30 #include <asm/gpio.h>
31 #include <asm/mach-types.h>
32 #include "overo.h"
33
34 #ifdef CONFIG_USB_EHCI_HCD
35 #include <usb.h>
36 #include <asm/ehci-omap.h>
37 #endif
38
39 #define TWL4030_I2C_BUS                 0
40 #define EXPANSION_EEPROM_I2C_BUS        2
41 #define EXPANSION_EEPROM_I2C_ADDRESS    0x51
42
43 #define GUMSTIX_EMPTY_EEPROM            0x0
44
45 #define GUMSTIX_SUMMIT                  0x01000200
46 #define GUMSTIX_TOBI                    0x02000200
47 #define GUMSTIX_TOBI_DUO                0x03000200
48 #define GUMSTIX_PALO35                  0x04000200
49 #define GUMSTIX_PALO43                  0x05000200
50 #define GUMSTIX_CHESTNUT43              0x06000200
51 #define GUMSTIX_PINTO                   0x07000200
52 #define GUMSTIX_GALLOP43                0x08000200
53 #define GUMSTIX_ALTO35                  0x09000200
54 #define GUMSTIX_STAGECOACH              0x0A000200
55 #define GUMSTIX_THUMBO                  0x0B000200
56 #define GUMSTIX_TURTLECORE              0x0C000200
57 #define GUMSTIX_ARBOR43C                0x0D000200
58
59 #define ETTUS_USRP_E                    0x01000300
60
61 #define GUMSTIX_NO_EEPROM               0xffffffff
62
63 static struct {
64         unsigned int device_vendor;
65         unsigned char revision;
66         unsigned char content;
67         char fab_revision[8];
68         char env_var[16];
69         char env_setting[64];
70 } expansion_config = {0x0};
71
72 static const struct ns16550_platdata overo_serial = {
73         .base = OMAP34XX_UART3,
74         .reg_shift = 2,
75         .clock = V_NS16550_CLK,
76         .fcr = UART_FCR_DEFVAL,
77 };
78
79 U_BOOT_DEVICE(overo_uart) = {
80         "ns16550_serial",
81         &overo_serial
82 };
83
84 /*
85  * Routine: get_sdio2_config
86  * Description: Return information about the wifi module connection
87  *              Returns 0 if the module connects though a level translator
88  *              Returns 1 if the module connects directly
89  */
90 int get_sdio2_config(void)
91 {
92         int sdio_direct;
93
94         if (!gpio_request(130, "") && !gpio_request(139, "")) {
95
96                 gpio_direction_output(130, 0);
97                 gpio_direction_input(139);
98
99                 sdio_direct = 1;
100                 gpio_set_value(130, 0);
101                 if (gpio_get_value(139) == 0) {
102                         gpio_set_value(130, 1);
103                         if (gpio_get_value(139) == 1)
104                                 sdio_direct = 0;
105                 }
106
107                 gpio_direction_input(130);
108         } else {
109                 puts("Error: unable to acquire sdio2 clk GPIOs\n");
110                 sdio_direct = -1;
111         }
112
113         return sdio_direct;
114 }
115
116 /*
117  * Routine: get_expansion_id
118  * Description: This function checks for expansion board by checking I2C
119  *              bus 2 for the availability of an AT24C01B serial EEPROM.
120  *              returns the device_vendor field from the EEPROM
121  */
122 unsigned int get_expansion_id(void)
123 {
124         if (expansion_config.device_vendor != 0x0)
125                 return expansion_config.device_vendor;
126
127         i2c_set_bus_num(EXPANSION_EEPROM_I2C_BUS);
128
129         /* return GUMSTIX_NO_EEPROM if eeprom doesn't respond */
130         if (i2c_probe(EXPANSION_EEPROM_I2C_ADDRESS) == 1) {
131                 i2c_set_bus_num(TWL4030_I2C_BUS);
132                 return GUMSTIX_NO_EEPROM;
133         }
134
135         /* read configuration data */
136         i2c_read(EXPANSION_EEPROM_I2C_ADDRESS, 0, 1, (u8 *)&expansion_config,
137                  sizeof(expansion_config));
138
139         i2c_set_bus_num(TWL4030_I2C_BUS);
140
141         return expansion_config.device_vendor;
142 }
143
144 /*
145  * Routine: misc_init_r
146  * Description: Configure board specific parts
147  */
148 int misc_init_r(void)
149 {
150         unsigned int expansion_id;
151
152         twl4030_power_init();
153         twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
154
155         printf("Board revision: %d\n", get_board_revision());
156
157         switch (get_sdio2_config()) {
158         case 0:
159                 puts("Tranceiver detected on mmc2\n");
160                 MUX_OVERO_SDIO2_TRANSCEIVER();
161                 break;
162         case 1:
163                 puts("Direct connection on mmc2\n");
164                 MUX_OVERO_SDIO2_DIRECT();
165                 break;
166         default:
167                 puts("Unable to detect mmc2 connection type\n");
168         }
169
170         expansion_id = get_expansion_id();
171         switch (expansion_id) {
172         case GUMSTIX_SUMMIT:
173                 printf("Recognized Summit expansion board (rev %d %s)\n",
174                         expansion_config.revision,
175                         expansion_config.fab_revision);
176                 MUX_GUMSTIX();
177                 env_set("defaultdisplay", "dvi");
178                 env_set("expansionname", "summit");
179                 break;
180         case GUMSTIX_TOBI:
181                 printf("Recognized Tobi expansion board (rev %d %s)\n",
182                         expansion_config.revision,
183                         expansion_config.fab_revision);
184                 MUX_GUMSTIX();
185                 env_set("defaultdisplay", "dvi");
186                 env_set("expansionname", "tobi");
187                 break;
188         case GUMSTIX_TOBI_DUO:
189                 printf("Recognized Tobi Duo expansion board (rev %d %s)\n",
190                         expansion_config.revision,
191                         expansion_config.fab_revision);
192                 MUX_GUMSTIX();
193                 env_set("expansionname", "tobiduo");
194                 break;
195         case GUMSTIX_PALO35:
196                 printf("Recognized Palo35 expansion board (rev %d %s)\n",
197                         expansion_config.revision,
198                         expansion_config.fab_revision);
199                 MUX_GUMSTIX();
200                 env_set("defaultdisplay", "lcd35");
201                 env_set("expansionname", "palo35");
202                 break;
203         case GUMSTIX_PALO43:
204                 printf("Recognized Palo43 expansion board (rev %d %s)\n",
205                         expansion_config.revision,
206                         expansion_config.fab_revision);
207                 MUX_GUMSTIX();
208                 env_set("defaultdisplay", "lcd43");
209                 env_set("expansionname", "palo43");
210                 break;
211         case GUMSTIX_CHESTNUT43:
212                 printf("Recognized Chestnut43 expansion board (rev %d %s)\n",
213                         expansion_config.revision,
214                         expansion_config.fab_revision);
215                 MUX_GUMSTIX();
216                 env_set("defaultdisplay", "lcd43");
217                 env_set("expansionname", "chestnut43");
218                 break;
219         case GUMSTIX_PINTO:
220                 printf("Recognized Pinto expansion board (rev %d %s)\n",
221                         expansion_config.revision,
222                         expansion_config.fab_revision);
223                 MUX_GUMSTIX();
224                 break;
225         case GUMSTIX_GALLOP43:
226                 printf("Recognized Gallop43 expansion board (rev %d %s)\n",
227                         expansion_config.revision,
228                         expansion_config.fab_revision);
229                 MUX_GUMSTIX();
230                 env_set("defaultdisplay", "lcd43");
231                 env_set("expansionname", "gallop43");
232                 break;
233         case GUMSTIX_ALTO35:
234                 printf("Recognized Alto35 expansion board (rev %d %s)\n",
235                         expansion_config.revision,
236                         expansion_config.fab_revision);
237                 MUX_GUMSTIX();
238                 MUX_ALTO35();
239                 env_set("defaultdisplay", "lcd35");
240                 env_set("expansionname", "alto35");
241                 break;
242         case GUMSTIX_STAGECOACH:
243                 printf("Recognized Stagecoach expansion board (rev %d %s)\n",
244                         expansion_config.revision,
245                         expansion_config.fab_revision);
246                 MUX_GUMSTIX();
247                 break;
248         case GUMSTIX_THUMBO:
249                 printf("Recognized Thumbo expansion board (rev %d %s)\n",
250                         expansion_config.revision,
251                         expansion_config.fab_revision);
252                 MUX_GUMSTIX();
253                 break;
254         case GUMSTIX_TURTLECORE:
255                 printf("Recognized Turtlecore expansion board (rev %d %s)\n",
256                         expansion_config.revision,
257                         expansion_config.fab_revision);
258                 MUX_GUMSTIX();
259                 break;
260         case GUMSTIX_ARBOR43C:
261                 printf("Recognized Arbor43C expansion board (rev %d %s)\n",
262                         expansion_config.revision,
263                         expansion_config.fab_revision);
264                 MUX_GUMSTIX();
265                 MUX_ARBOR43C();
266                 env_set("defaultdisplay", "lcd43");
267                 env_set("expansionname", "arbor43c");
268                 break;
269         case ETTUS_USRP_E:
270                 printf("Recognized Ettus Research USRP-E (rev %d %s)\n",
271                         expansion_config.revision,
272                         expansion_config.fab_revision);
273                 MUX_GUMSTIX();
274                 MUX_USRP_E();
275                 env_set("defaultdisplay", "dvi");
276                 break;
277         case GUMSTIX_NO_EEPROM:
278         case GUMSTIX_EMPTY_EEPROM:
279                 puts("No or empty EEPROM on expansion board\n");
280                 MUX_GUMSTIX();
281                 env_set("expansionname", "tobi");
282                 break;
283         default:
284                 printf("Unrecognized expansion board 0x%08x\n", expansion_id);
285                 break;
286         }
287
288         if (expansion_config.content == 1)
289                 env_set(expansion_config.env_var, expansion_config.env_setting);
290
291         omap_die_id_display();
292
293         if (get_cpu_family() == CPU_OMAP34XX)
294                 env_set("boardname", "overo");
295         else
296                 env_set("boardname", "overo-storm");
297
298         return 0;
299 }
300
301 #if defined(CONFIG_CMD_NET)
302 /* GPMC definitions for LAN9221 chips on Tobi expansion boards */
303 static const u32 gpmc_lan_config[] = {
304         NET_LAN9221_GPMC_CONFIG1,
305         NET_LAN9221_GPMC_CONFIG2,
306         NET_LAN9221_GPMC_CONFIG3,
307         NET_LAN9221_GPMC_CONFIG4,
308         NET_LAN9221_GPMC_CONFIG5,
309         NET_LAN9221_GPMC_CONFIG6,
310         /*CONFIG7- computed as params */
311 };
312
313 /*
314  * Routine: setup_net_chip
315  * Description: Setting up the configuration GPMC registers specific to the
316  *            Ethernet hardware.
317  */
318 static void setup_net_chip(void)
319 {
320         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
321
322         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
323         writew(readw(&ctrl_base ->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
324         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
325         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
326         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
327         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
328                 &ctrl_base->gpmc_nadv_ale);
329 }
330
331 /*
332  * Routine: reset_net_chip
333  * Description: Reset the Ethernet hardware.
334  */
335 static void reset_net_chip(void)
336 {
337         /* Make GPIO 64 as output pin and send a magic pulse through it */
338         if (!gpio_request(64, "")) {
339                 gpio_direction_output(64, 0);
340                 gpio_set_value(64, 1);
341                 udelay(1);
342                 gpio_set_value(64, 0);
343                 udelay(1);
344                 gpio_set_value(64, 1);
345         }
346 }
347
348 int board_eth_init(bd_t *bis)
349 {
350         unsigned int expansion_id;
351         int rc = 0;
352
353 #ifdef CONFIG_SMC911X
354         expansion_id = get_expansion_id();
355         switch (expansion_id) {
356         case GUMSTIX_TOBI_DUO:
357                 /* second lan chip */
358                 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[4],
359                                       0x2B000000, GPMC_SIZE_16M);
360                 /* no break */
361         case GUMSTIX_TOBI:
362         case GUMSTIX_CHESTNUT43:
363         case GUMSTIX_STAGECOACH:
364         case GUMSTIX_NO_EEPROM:
365         case GUMSTIX_EMPTY_EEPROM:
366                 /* first lan chip */
367                 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
368                                       0x2C000000, GPMC_SIZE_16M);
369
370                 setup_net_chip();
371                 reset_net_chip();
372
373                 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
374                 break;
375         default:
376                 break;
377         }
378 #endif
379
380         return rc;
381 }
382 #endif
383
384 #if defined(CONFIG_USB_EHCI_HCD)
385 static struct omap_usbhs_board_data usbhs_bdata = {
386         .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
387         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
388         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
389 };
390
391 #define GUMSTIX_GPIO_USBH_CPEN          168
392 int ehci_hcd_init(int index, enum usb_init_type init,
393                   struct ehci_hccr **hccr, struct ehci_hcor **hcor)
394 {
395         /* Enable USB power */
396         if (!gpio_request(GUMSTIX_GPIO_USBH_CPEN, "usbh_cpen"))
397                 gpio_direction_output(GUMSTIX_GPIO_USBH_CPEN, 1);
398
399         return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
400 }
401
402 int ehci_hcd_stop(void)
403 {
404         /* Disable USB power */
405         gpio_set_value(GUMSTIX_GPIO_USBH_CPEN, 0);
406         gpio_free(GUMSTIX_GPIO_USBH_CPEN);
407
408         return omap_ehci_hcd_stop();
409 }
410
411 #endif /* CONFIG_USB_EHCI_HCD */