blob: 74fc5f08900ae7128415c45f44508cb449ad5bfc [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>
Enric Balletbo i Serraa66c8872015-01-28 15:01:32 +01008#include <status_led.h>
Simon Glassbc0f4ea2014-10-22 21:37:15 -06009#include <dm.h>
10#include <ns16550.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040011#include <twl4030.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000012#include <netdev.h>
Ladislav Michlac870362016-07-12 20:28:34 +020013#include <spl.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040014#include <asm/gpio.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000015#include <asm/io.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040016#include <asm/arch/mem.h>
Enric Balletbo i Serrada898a92010-11-04 15:34:33 -040017#include <asm/arch/mmc_host_def.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040018#include <asm/arch/mux.h>
19#include <asm/arch/sys_proto.h>
Ladislav Michlc44e29f2016-07-12 20:28:33 +020020#include <linux/mtd/mtd.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090021#include <linux/mtd/rawnand.h>
Ladislav Michl3e349282016-07-12 20:28:31 +020022#include <linux/mtd/onenand.h>
23#include <jffs2/load_kernel.h>
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010024#include <mtd_node.h>
25#include <fdt_support.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000026#include "igep00x0.h"
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040027
Simon Glassbc0f4ea2014-10-22 21:37:15 -060028static const struct ns16550_platdata igep_serial = {
Adam Fordd1e22fa2016-03-07 21:08:49 -060029 .base = OMAP34XX_UART3,
30 .reg_shift = 2,
Heiko Schocher06f108e2017-01-18 08:05:49 +010031 .clock = V_NS16550_CLK,
32 .fcr = UART_FCR_DEFVAL,
Simon Glassbc0f4ea2014-10-22 21:37:15 -060033};
34
35U_BOOT_DEVICE(igep_uart) = {
Thomas Chou52ac4432015-11-19 21:48:12 +080036 "ns16550_serial",
Simon Glassbc0f4ea2014-10-22 21:37:15 -060037 &igep_serial
38};
39
Pau Pajuelo4ddc3092017-08-17 03:09:14 +020040/*
41 * Routine: get_board_revision
42 * Description: GPIO_28 and GPIO_129 are used to read board and revision from
43 * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from
44 * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because
45 * this functionality is shared by USB HOST.
46 * Once USB reset is applied, U-boot configures these pins as input pullup to
47 * detect board and revision:
48 * IGEP0020-RF = 0b00
49 * IGEP0020-RC = 0b01
50 * IGEP0030-RG = 0b10
51 * IGEP0030-RE = 0b11
52 */
53static int get_board_revision(void)
54{
55 int revision;
56
57 gpio_request(IGEP0030_USB_TRANSCEIVER_RESET,
58 "igep0030_usb_transceiver_reset");
59 gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0);
60
61 gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection");
62 gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION);
63 revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION);
64 gpio_free(GPIO_IGEP00X0_BOARD_DETECTION);
65
66 gpio_request(GPIO_IGEP00X0_REVISION_DETECTION,
67 "igep00x0_revision_detection");
68 gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION);
69 revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION);
70 gpio_free(GPIO_IGEP00X0_REVISION_DETECTION);
71
72 gpio_free(IGEP0030_USB_TRANSCEIVER_RESET);
73
74 return revision;
75}
76
Ladislav Michl3e349282016-07-12 20:28:31 +020077int onenand_board_init(struct mtd_info *mtd)
78{
79 if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
80 struct onenand_chip *this = mtd->priv;
81 this->base = (void *)CONFIG_SYS_ONENAND_BASE;
82 return 0;
83 }
84 return 1;
85}
86
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000087#if defined(CONFIG_CMD_NET)
Ladislav Michl6399e5e2016-01-04 23:07:59 +010088static void reset_net_chip(int gpio)
89{
90 if (!gpio_request(gpio, "eth nrst")) {
91 gpio_direction_output(gpio, 1);
92 udelay(1);
93 gpio_set_value(gpio, 0);
94 udelay(40);
95 gpio_set_value(gpio, 1);
96 mdelay(10);
97 }
98}
99
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400100/*
101 * Routine: setup_net_chip
102 * Description: Setting up the configuration GPMC registers specific to the
103 * Ethernet hardware.
104 */
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400105static void setup_net_chip(void)
106{
107 struct ctrl *ctrl_base = (struct ctrl *)OMAP34XX_CTRL_BASE;
Ladislav Michl11279dc2016-07-12 20:28:28 +0200108 static const u32 gpmc_lan_config[] = {
109 NET_LAN9221_GPMC_CONFIG1,
110 NET_LAN9221_GPMC_CONFIG2,
111 NET_LAN9221_GPMC_CONFIG3,
112 NET_LAN9221_GPMC_CONFIG4,
113 NET_LAN9221_GPMC_CONFIG5,
114 NET_LAN9221_GPMC_CONFIG6,
115 };
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400116
Ladislav Michl6399e5e2016-01-04 23:07:59 +0100117 enable_gpmc_cs_config(gpmc_lan_config, &gpmc_cfg->cs[5],
118 CONFIG_SMC911X_BASE, GPMC_SIZE_16M);
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400119
120 /* Enable off mode for NWE in PADCONF_GPMC_NWE register */
121 writew(readw(&ctrl_base->gpmc_nwe) | 0x0E00, &ctrl_base->gpmc_nwe);
122 /* Enable off mode for NOE in PADCONF_GPMC_NADV_ALE register */
123 writew(readw(&ctrl_base->gpmc_noe) | 0x0E00, &ctrl_base->gpmc_noe);
124 /* Enable off mode for ALE in PADCONF_GPMC_NADV_ALE register */
125 writew(readw(&ctrl_base->gpmc_nadv_ale) | 0x0E00,
126 &ctrl_base->gpmc_nadv_ale);
127
Ladislav Michl6399e5e2016-01-04 23:07:59 +0100128 reset_net_chip(64);
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400129}
Ladislav Michl11279dc2016-07-12 20:28:28 +0200130
131int board_eth_init(bd_t *bis)
132{
133#ifdef CONFIG_SMC911X
134 return smc911x_initialize(0, CONFIG_SMC911X_BASE);
135#else
136 return 0;
137#endif
138}
Javier Martinez Canillase9b14522012-12-27 01:35:56 +0000139#else
140static inline void setup_net_chip(void) {}
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400141#endif
142
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100143#ifdef CONFIG_OF_BOARD_SETUP
Ladislav Michl4e7241a2017-02-19 00:24:49 +0100144static int ft_enable_by_compatible(void *blob, char *compat, int enable)
145{
146 int off = fdt_node_offset_by_compatible(blob, -1, compat);
147 if (off < 0)
148 return off;
149
150 if (enable)
151 fdt_status_okay(blob, off);
152 else
153 fdt_status_disabled(blob, off);
154
155 return 0;
156}
157
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100158int ft_board_setup(void *blob, bd_t *bd)
159{
160#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900161 static const struct node_info nodes[] = {
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100162 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
163 { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
164 };
165
166 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
167#endif
Ladislav Michl4e7241a2017-02-19 00:24:49 +0100168 ft_enable_by_compatible(blob, "ti,omap2-nand",
169 gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
170 ft_enable_by_compatible(blob, "ti,omap2-onenand",
171 gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
172
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100173 return 0;
174}
175#endif
176
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200177void set_led(void)
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200178{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200179 switch (get_board_revision()) {
180 case 0:
181 case 1:
182 gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led");
183 gpio_direction_output(IGEP0020_GPIO_LED, 1);
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200184 break;
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200185 case 2:
186 case 3:
187 gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led");
188 gpio_direction_output(IGEP0030_GPIO_LED, 0);
189 break;
190 default:
191 /* Should not happen... */
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200192 break;
193 }
194}
195
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200196void set_boardname(void)
197{
198 char rev[5] = { 'F','C','G','E', };
199 int i = get_board_revision();
200
201 rev[i+1] = 0;
202 env_set("board_rev", rev + i);
203 env_set("board_name", i < 2 ? "igep0020" : "igep0030");
204}
205
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400206/*
207 * Routine: misc_init_r
208 * Description: Configure board specific parts
209 */
210int misc_init_r(void)
211{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200212 t2_t *t2_base = (t2_t *)T2_BASE;
213 u32 pbias_lite;
214
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400215 twl4030_power_init();
216
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200217 /* set VSIM to 1.8V */
218 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
219 TWL4030_PM_RECEIVER_VSIM_VSEL_18,
220 TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
221 TWL4030_PM_RECEIVER_DEV_GRP_P1);
222
223 /* set up dual-voltage GPIOs to 1.8V */
224 pbias_lite = readl(&t2_base->pbias_lite);
225 pbias_lite &= ~PBIASLITEVMODE1;
226 pbias_lite |= PBIASLITEPWRDNZ1;
227 writel(pbias_lite, &t2_base->pbias_lite);
228 if (get_cpu_family() == CPU_OMAP36XX)
229 writel(readl(OMAP34XX_CTRL_WKUP_CTRL) |
230 OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
231 OMAP34XX_CTRL_WKUP_CTRL);
232
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400233 setup_net_chip();
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400234
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200235 omap_die_id_display();
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400236
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200237 set_led();
238
239 set_boardname();
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200240
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400241 return 0;
242}
243
Ladislav Michlc44e29f2016-07-12 20:28:33 +0200244void board_mtdparts_default(const char **mtdids, const char **mtdparts)
245{
246 struct mtd_info *mtd = get_mtd_device(NULL, 0);
247 if (mtd) {
248 static char ids[24];
249 static char parts[48];
250 const char *linux_name = "omap2-nand";
251 if (strncmp(mtd->name, "onenand0", 8) == 0)
252 linux_name = "omap2-onenand";
253 snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
254 snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
255 linux_name, 4 * mtd->erasesize >> 10);
256 *mtdids = ids;
257 *mtdparts = parts;
258 }
259}