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