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