common: Drop net.h from common header
[oweals/u-boot.git] / board / isee / igep00x0 / igep00x0.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2010
4  * ISEE 2007 SL, <www.iseebcn.com>
5  */
6 #include <common.h>
7 #include <env.h>
8 #include <malloc.h>
9 #include <net.h>
10 #include <status_led.h>
11 #include <dm.h>
12 #include <ns16550.h>
13 #include <twl4030.h>
14 #include <netdev.h>
15 #include <spl.h>
16 #include <asm/gpio.h>
17 #include <asm/io.h>
18 #include <asm/arch/mem.h>
19 #include <asm/arch/mmc_host_def.h>
20 #include <asm/arch/mux.h>
21 #include <asm/arch/sys_proto.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/rawnand.h>
24 #include <linux/mtd/onenand.h>
25 #include <jffs2/load_kernel.h>
26 #include <mtd_node.h>
27 #include <fdt_support.h>
28 #include "igep00x0.h"
29
30 static const struct ns16550_platdata igep_serial = {
31         .base = OMAP34XX_UART3,
32         .reg_shift = 2,
33         .clock = V_NS16550_CLK,
34         .fcr = UART_FCR_DEFVAL,
35 };
36
37 U_BOOT_DEVICE(igep_uart) = {
38         "ns16550_serial",
39         &igep_serial
40 };
41
42 /*
43  * Routine: get_board_revision
44  * Description: GPIO_28 and GPIO_129 are used to read board and revision from
45  * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from
46  * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because
47  * this functionality is shared by USB HOST.
48  * Once USB reset is applied, U-boot configures these pins as input pullup to
49  * detect board and revision:
50  * IGEP0020-RF = 0b00
51  * IGEP0020-RC = 0b01
52  * IGEP0030-RG = 0b10
53  * IGEP0030-RE = 0b11
54  */
55 static int get_board_revision(void)
56 {
57         int revision;
58
59         gpio_request(IGEP0030_USB_TRANSCEIVER_RESET,
60                                 "igep0030_usb_transceiver_reset");
61         gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0);
62
63         gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection");
64         gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION);
65         revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION);
66         gpio_free(GPIO_IGEP00X0_BOARD_DETECTION);
67
68         gpio_request(GPIO_IGEP00X0_REVISION_DETECTION,
69                                 "igep00x0_revision_detection");
70         gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION);
71         revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION);
72         gpio_free(GPIO_IGEP00X0_REVISION_DETECTION);
73
74         gpio_free(IGEP0030_USB_TRANSCEIVER_RESET);
75
76         return revision;
77 }
78
79 int onenand_board_init(struct mtd_info *mtd)
80 {
81         if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
82                 struct onenand_chip *this = mtd->priv;
83                 this->base = (void *)CONFIG_SYS_ONENAND_BASE;
84                 return 0;
85         }
86         return 1;
87 }
88
89 #if defined(CONFIG_CMD_NET)
90 static void reset_net_chip(int gpio)
91 {
92         if (!gpio_request(gpio, "eth nrst")) {
93                 gpio_direction_output(gpio, 1);
94                 udelay(1);
95                 gpio_set_value(gpio, 0);
96                 udelay(40);
97                 gpio_set_value(gpio, 1);
98                 mdelay(10);
99         }
100 }
101
102 /*
103  * Routine: setup_net_chip
104  * Description: Setting up the configuration GPMC registers specific to the
105  *              Ethernet hardware.
106  */
107 static void setup_net_chip(void)
108 {
109         struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
110         static const u32 gpmc_lan_config[] = {
111                 NET_LAN9221_GPMC_CONFIG1,
112                 NET_LAN9221_GPMC_CONFIG2,
113                 NET_LAN9221_GPMC_CONFIG3,
114                 NET_LAN9221_GPMC_CONFIG4,
115                 NET_LAN9221_GPMC_CONFIG5,
116                 NET_LAN9221_GPMC_CONFIG6,
117         };
118
119         enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
120                         CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
121
122         /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
123         writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
124         /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
125         writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
126         /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
127         writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
128                 &ctrl_base->gpmc_nadv_ale);
129
130         reset_net_chip(64);
131 }
132
133 int board_eth_init(bd_t *bis)
134 {
135 #ifdef CONFIG_SMC911X
136         return smc911x_initialize(0, CONFIG_SMC911X_BASE);
137 #else
138         return 0;
139 #endif
140 }
141 #else
142 static inline void setup_net_chip(void) {}
143 #endif
144
145 #ifdef CONFIG_OF_BOARD_SETUP
146 static int ft_enable_by_compatible(void *blob, char *compat, int enable)
147 {
148         int off = fdt_node_offset_by_compatible(blob, -1, compat);
149         if (off < 0)
150                 return off;
151
152         if (enable)
153                 fdt_status_okay(blob, off);
154         else
155                 fdt_status_disabled(blob, off);
156
157         return 0;
158 }
159
160 int ft_board_setup(void *blob, bd_t *bd)
161 {
162 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
163         static const struct node_info nodes[] = {
164                 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
165                 { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
166         };
167
168         fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
169 #endif
170         ft_enable_by_compatible(blob, "ti,omap2-nand",
171                                 gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
172         ft_enable_by_compatible(blob, "ti,omap2-onenand",
173                                 gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
174
175         return 0;
176 }
177 #endif
178
179 void set_led(void)
180 {
181         switch (get_board_revision()) {
182         case 0:
183         case 1:
184                 gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led");
185                 gpio_direction_output(IGEP0020_GPIO_LED, 1);
186                 break;
187         case 2:
188         case 3:
189                 gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led");
190                 gpio_direction_output(IGEP0030_GPIO_LED, 0);
191                 break;
192         default:
193                 /* Should not happen... */
194                 break;
195         }
196 }
197
198 void set_boardname(void)
199 {
200         char rev[5] = { 'F','C','G','E', };
201         int i = get_board_revision();
202
203         rev[i+1] = 0;
204         env_set("board_rev", rev + i);
205         env_set("board_name", i < 2 ? "igep0020" : "igep0030");
206 }
207
208 /*
209  * Routine: misc_init_r
210  * Description: Configure board specific parts
211  */
212 int misc_init_r(void)
213 {
214         t2_t *t2_base = (t2_t *)T2_BASE;
215         u32 pbias_lite;
216
217         twl4030_power_init();
218
219         /* set VSIM to 1.8V */
220         twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
221                                 TWL4030_PM_RECEIVER_VSIM_VSEL_18,
222                                 TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
223                                 TWL4030_PM_RECEIVER_DEV_GRP_P1);
224
225         /* set up dual-voltage GPIOs to 1.8V */
226         pbias_lite = readl(&t2_base->pbias_lite);
227         pbias_lite &= ~PBIASLITEVMODE1;
228         pbias_lite |= PBIASLITEPWRDNZ1;
229         writel(pbias_lite, &t2_base->pbias_lite);
230         if (get_cpu_family() == CPU_OMAP36XX)
231                 writel(readl(OMAP34XX_CTRL_WKUP_CTRL) |
232                                          OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
233                                          OMAP34XX_CTRL_WKUP_CTRL);
234
235         setup_net_chip();
236
237         omap_die_id_display();
238
239         set_led();
240
241         set_boardname();
242
243         return 0;
244 }
245
246 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
247 {
248         struct mtd_info *mtd = get_mtd_device(NULL, 0);
249         if (mtd) {
250                 static char ids[24];
251                 static char parts[48];
252                 const char *linux_name = "omap2-nand";
253                 if (strncmp(mtd->name, "onenand0", 8) == 0)
254                         linux_name = "omap2-onenand";
255                 snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
256                 snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
257                          linux_name, 4 * mtd->erasesize >> 10);
258                 *mtdids = ids;
259                 *mtdparts = parts;
260         }
261 }