blob: 1b871fdcc5af4190f633d4f3b35bc7fa1a3238a7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -04002/*
3 * (C) Copyright 2010
4 * ISEE 2007 SL, <www.iseebcn.com>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -04005 */
6#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06007#include <env.h>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Enric Balletbo i Serraa66c8872015-01-28 15:01:32 +01009#include <status_led.h>
Simon Glassbc0f4ea2014-10-22 21:37:15 -060010#include <dm.h>
11#include <ns16550.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040012#include <twl4030.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000013#include <netdev.h>
Ladislav Michlac870362016-07-12 20:28:34 +020014#include <spl.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040015#include <asm/gpio.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000016#include <asm/io.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040017#include <asm/arch/mem.h>
Enric Balletbo i Serrada898a92010-11-04 15:34:33 -040018#include <asm/arch/mmc_host_def.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040019#include <asm/arch/mux.h>
20#include <asm/arch/sys_proto.h>
Ladislav Michlc44e29f2016-07-12 20:28:33 +020021#include <linux/mtd/mtd.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090022#include <linux/mtd/rawnand.h>
Ladislav Michl3e349282016-07-12 20:28:31 +020023#include <linux/mtd/onenand.h>
24#include <jffs2/load_kernel.h>
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010025#include <mtd_node.h>
26#include <fdt_support.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000027#include "igep00x0.h"
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040028
Simon Glassbc0f4ea2014-10-22 21:37:15 -060029static const struct ns16550_platdata igep_serial = {
Adam Fordd1e22fa2016-03-07 21:08:49 -060030 .base = OMAP34XX_UART3,
31 .reg_shift = 2,
Heiko Schocher06f108e2017-01-18 08:05:49 +010032 .clock = V_NS16550_CLK,
33 .fcr = UART_FCR_DEFVAL,
Simon Glassbc0f4ea2014-10-22 21:37:15 -060034};
35
36U_BOOT_DEVICE(igep_uart) = {
Thomas Chou52ac4432015-11-19 21:48:12 +080037 "ns16550_serial",
Simon Glassbc0f4ea2014-10-22 21:37:15 -060038 &igep_serial
39};
40
Pau Pajuelo4ddc3092017-08-17 03:09:14 +020041/*
42 * Routine: get_board_revision
43 * Description: GPIO_28 and GPIO_129 are used to read board and revision from
44 * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from
45 * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because
46 * this functionality is shared by USB HOST.
47 * Once USB reset is applied, U-boot configures these pins as input pullup to
48 * detect board and revision:
49 * IGEP0020-RF = 0b00
50 * IGEP0020-RC = 0b01
51 * IGEP0030-RG = 0b10
52 * IGEP0030-RE = 0b11
53 */
54static int get_board_revision(void)
55{
56 int revision;
57
58 gpio_request(IGEP0030_USB_TRANSCEIVER_RESET,
59 "igep0030_usb_transceiver_reset");
60 gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0);
61
62 gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection");
63 gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION);
64 revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION);
65 gpio_free(GPIO_IGEP00X0_BOARD_DETECTION);
66
67 gpio_request(GPIO_IGEP00X0_REVISION_DETECTION,
68 "igep00x0_revision_detection");
69 gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION);
70 revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION);
71 gpio_free(GPIO_IGEP00X0_REVISION_DETECTION);
72
73 gpio_free(IGEP0030_USB_TRANSCEIVER_RESET);
74
75 return revision;
76}
77
Ladislav Michl3e349282016-07-12 20:28:31 +020078int onenand_board_init(struct mtd_info *mtd)
79{
80 if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
81 struct onenand_chip *this = mtd->priv;
82 this->base = (void *)CONFIG_SYS_ONENAND_BASE;
83 return 0;
84 }
85 return 1;
86}
87
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000088#if defined(CONFIG_CMD_NET)
Ladislav Michl6399e5e2016-01-04 23:07:59 +010089static void reset_net_chip(int gpio)
90{
91 if (!gpio_request(gpio, "eth nrst")) {
92 gpio_direction_output(gpio, 1);
93 udelay(1);
94 gpio_set_value(gpio, 0);
95 udelay(40);
96 gpio_set_value(gpio, 1);
97 mdelay(10);
98 }
99}
100
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400101/*
102 * Routine: setup_net_chip
103 * Description: Setting up the configuration GPMC registers specific to the
104 * Ethernet hardware.
105 */
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400106static void setup_net_chip(void)
107{
108 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
Ladislav Michl11279dc2016-07-12 20:28:28 +0200109 static const u32 gpmc_lan_config[] = {
110 NET_LAN9221_GPMC_CONFIG1,
111 NET_LAN9221_GPMC_CONFIG2,
112 NET_LAN9221_GPMC_CONFIG3,
113 NET_LAN9221_GPMC_CONFIG4,
114 NET_LAN9221_GPMC_CONFIG5,
115 NET_LAN9221_GPMC_CONFIG6,
116 };
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400117
Ladislav Michl6399e5e2016-01-04 23:07:59 +0100118 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
119 CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400120
121 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
122 writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
123 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
124 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
125 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
126 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
127 &ctrl_base->gpmc_nadv_ale);
128
Ladislav Michl6399e5e2016-01-04 23:07:59 +0100129 reset_net_chip(64);
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400130}
Ladislav Michl11279dc2016-07-12 20:28:28 +0200131
132int board_eth_init(bd_t *bis)
133{
134#ifdef CONFIG_SMC911X
135 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
136#else
137 return 0;
138#endif
139}
Javier Martinez Canillase9b14522012-12-27 01:35:56 +0000140#else
141static inline void setup_net_chip(void) {}
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400142#endif
143
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100144#ifdef CONFIG_OF_BOARD_SETUP
Ladislav Michl4e7241a2017-02-19 00:24:49 +0100145static int ft_enable_by_compatible(void *blob, char *compat, int enable)
146{
147 int off = fdt_node_offset_by_compatible(blob, -1, compat);
148 if (off < 0)
149 return off;
150
151 if (enable)
152 fdt_status_okay(blob, off);
153 else
154 fdt_status_disabled(blob, off);
155
156 return 0;
157}
158
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100159int ft_board_setup(void *blob, bd_t *bd)
160{
161#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900162 static const struct node_info nodes[] = {
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100163 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
164 { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
165 };
166
167 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
168#endif
Ladislav Michl4e7241a2017-02-19 00:24:49 +0100169 ft_enable_by_compatible(blob, "ti,omap2-nand",
170 gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
171 ft_enable_by_compatible(blob, "ti,omap2-onenand",
172 gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
173
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100174 return 0;
175}
176#endif
177
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200178void set_led(void)
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200179{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200180 switch (get_board_revision()) {
181 case 0:
182 case 1:
183 gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led");
184 gpio_direction_output(IGEP0020_GPIO_LED, 1);
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200185 break;
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200186 case 2:
187 case 3:
188 gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led");
189 gpio_direction_output(IGEP0030_GPIO_LED, 0);
190 break;
191 default:
192 /* Should not happen... */
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200193 break;
194 }
195}
196
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200197void set_boardname(void)
198{
199 char rev[5] = { 'F','C','G','E', };
200 int i = get_board_revision();
201
202 rev[i+1] = 0;
203 env_set("board_rev", rev + i);
204 env_set("board_name", i < 2 ? "igep0020" : "igep0030");
205}
206
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400207/*
208 * Routine: misc_init_r
209 * Description: Configure board specific parts
210 */
211int misc_init_r(void)
212{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200213 t2_t *t2_base = (t2_t *)T2_BASE;
214 u32 pbias_lite;
215
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400216 twl4030_power_init();
217
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200218 /* set VSIM to 1.8V */
219 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
220 TWL4030_PM_RECEIVER_VSIM_VSEL_18,
221 TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
222 TWL4030_PM_RECEIVER_DEV_GRP_P1);
223
224 /* set up dual-voltage GPIOs to 1.8V */
225 pbias_lite = readl(&t2_base->pbias_lite);
226 pbias_lite &= ~PBIASLITEVMODE1;
227 pbias_lite |= PBIASLITEPWRDNZ1;
228 writel(pbias_lite, &t2_base->pbias_lite);
229 if (get_cpu_family() == CPU_OMAP36XX)
230 writel(readl(OMAP34XX_CTRL_WKUP_CTRL) |
231 OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
232 OMAP34XX_CTRL_WKUP_CTRL);
233
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400234 setup_net_chip();
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400235
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200236 omap_die_id_display();
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400237
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200238 set_led();
239
240 set_boardname();
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200241
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400242 return 0;
243}
244
Ladislav Michlc44e29f2016-07-12 20:28:33 +0200245void board_mtdparts_default(const char **mtdids, const char **mtdparts)
246{
247 struct mtd_info *mtd = get_mtd_device(NULL, 0);
248 if (mtd) {
249 static char ids[24];
250 static char parts[48];
251 const char *linux_name = "omap2-nand";
252 if (strncmp(mtd->name, "onenand0", 8) == 0)
253 linux_name = "omap2-onenand";
254 snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
255 snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
256 linux_name, 4 * mtd->erasesize >> 10);
257 *mtdids = ids;
258 *mtdparts = parts;
259 }
260}