blob: 0f0a9c592fcc3f76fc0630c33b89edefd862ccbd [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 Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <net.h>
Enric Balletbo i Serraa66c8872015-01-28 15:01:32 +010011#include <status_led.h>
Simon Glassbc0f4ea2014-10-22 21:37:15 -060012#include <dm.h>
13#include <ns16550.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040014#include <twl4030.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000015#include <netdev.h>
Ladislav Michlac870362016-07-12 20:28:34 +020016#include <spl.h>
Sanjeev Premi7b3dc822011-09-08 10:51:01 -040017#include <asm/gpio.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000018#include <asm/io.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040019#include <asm/arch/mem.h>
Enric Balletbo i Serrada898a92010-11-04 15:34:33 -040020#include <asm/arch/mmc_host_def.h>
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040021#include <asm/arch/mux.h>
22#include <asm/arch/sys_proto.h>
Simon Glassdbd79542020-05-10 11:40:11 -060023#include <linux/delay.h>
Ladislav Michlc44e29f2016-07-12 20:28:33 +020024#include <linux/mtd/mtd.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090025#include <linux/mtd/rawnand.h>
Ladislav Michl3e349282016-07-12 20:28:31 +020026#include <linux/mtd/onenand.h>
27#include <jffs2/load_kernel.h>
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010028#include <mtd_node.h>
29#include <fdt_support.h>
Javier Martinez Canillase9b14522012-12-27 01:35:56 +000030#include "igep00x0.h"
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -040031
Simon Glassb75b15b2020-12-03 16:55:23 -070032static const struct ns16550_plat igep_serial = {
Adam Fordd1e22fa2016-03-07 21:08:49 -060033 .base = OMAP34XX_UART3,
34 .reg_shift = 2,
Heiko Schocher06f108e2017-01-18 08:05:49 +010035 .clock = V_NS16550_CLK,
36 .fcr = UART_FCR_DEFVAL,
Simon Glassbc0f4ea2014-10-22 21:37:15 -060037};
38
Simon Glass1d8364a2020-12-28 20:34:54 -070039U_BOOT_DRVINFO(igep_uart) = {
Thomas Chou52ac4432015-11-19 21:48:12 +080040 "ns16550_serial",
Simon Glassbc0f4ea2014-10-22 21:37:15 -060041 &igep_serial
42};
43
Pau Pajuelo4ddc3092017-08-17 03:09:14 +020044/*
45 * Routine: get_board_revision
46 * Description: GPIO_28 and GPIO_129 are used to read board and revision from
47 * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from
48 * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because
49 * this functionality is shared by USB HOST.
Michal Simek50fa1182023-05-17 09:17:16 +020050 * Once USB reset is applied, U-Boot configures these pins as input pullup to
Pau Pajuelo4ddc3092017-08-17 03:09:14 +020051 * detect board and revision:
52 * IGEP0020-RF = 0b00
53 * IGEP0020-RC = 0b01
54 * IGEP0030-RG = 0b10
55 * IGEP0030-RE = 0b11
56 */
57static int get_board_revision(void)
58{
59 int revision;
60
61 gpio_request(IGEP0030_USB_TRANSCEIVER_RESET,
62 "igep0030_usb_transceiver_reset");
63 gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0);
64
65 gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection");
66 gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION);
67 revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION);
68 gpio_free(GPIO_IGEP00X0_BOARD_DETECTION);
69
70 gpio_request(GPIO_IGEP00X0_REVISION_DETECTION,
71 "igep00x0_revision_detection");
72 gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION);
73 revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION);
74 gpio_free(GPIO_IGEP00X0_REVISION_DETECTION);
75
76 gpio_free(IGEP0030_USB_TRANSCEIVER_RESET);
77
78 return revision;
79}
80
Ladislav Michl3e349282016-07-12 20:28:31 +020081int onenand_board_init(struct mtd_info *mtd)
82{
83 if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
84 struct onenand_chip *this = mtd->priv;
Tom Rini6a5dccc2022-11-16 13:10:41 -050085 this->base = (void *)CFG_SYS_ONENAND_BASE;
Ladislav Michl3e349282016-07-12 20:28:31 +020086 return 0;
87 }
88 return 1;
89}
90
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010091#ifdef CONFIG_OF_BOARD_SETUP
Ladislav Michl4e7241a2017-02-19 00:24:49 +010092static int ft_enable_by_compatible(void *blob, char *compat, int enable)
93{
94 int off = fdt_node_offset_by_compatible(blob, -1, compat);
95 if (off < 0)
96 return off;
97
98 if (enable)
99 fdt_status_okay(blob, off);
100 else
101 fdt_status_disabled(blob, off);
102
103 return 0;
104}
105
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900106int ft_board_setup(void *blob, struct bd_info *bd)
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100107{
108#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamada20ead6f2018-07-19 16:28:23 +0900109 static const struct node_info nodes[] = {
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100110 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
111 { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
112 };
113
114 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
115#endif
Ladislav Michl4e7241a2017-02-19 00:24:49 +0100116 ft_enable_by_compatible(blob, "ti,omap2-nand",
117 gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
118 ft_enable_by_compatible(blob, "ti,omap2-onenand",
119 gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
120
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100121 return 0;
122}
123#endif
124
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200125void set_led(void)
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200126{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200127 switch (get_board_revision()) {
128 case 0:
129 case 1:
130 gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led");
131 gpio_direction_output(IGEP0020_GPIO_LED, 1);
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200132 break;
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200133 case 2:
134 case 3:
135 gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led");
136 gpio_direction_output(IGEP0030_GPIO_LED, 0);
137 break;
138 default:
139 /* Should not happen... */
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200140 break;
141 }
142}
143
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200144void set_boardname(void)
145{
146 char rev[5] = { 'F','C','G','E', };
147 int i = get_board_revision();
148
149 rev[i+1] = 0;
150 env_set("board_rev", rev + i);
151 env_set("board_name", i < 2 ? "igep0020" : "igep0030");
152}
153
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400154/*
155 * Routine: misc_init_r
156 * Description: Configure board specific parts
157 */
158int misc_init_r(void)
159{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200160 t2_t *t2_base = (t2_t *)T2_BASE;
161 u32 pbias_lite;
162
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400163 twl4030_power_init();
164
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200165 /* set VSIM to 1.8V */
166 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
167 TWL4030_PM_RECEIVER_VSIM_VSEL_18,
168 TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
169 TWL4030_PM_RECEIVER_DEV_GRP_P1);
170
171 /* set up dual-voltage GPIOs to 1.8V */
172 pbias_lite = readl(&t2_base->pbias_lite);
173 pbias_lite &= ~PBIASLITEVMODE1;
174 pbias_lite |= PBIASLITEPWRDNZ1;
175 writel(pbias_lite, &t2_base->pbias_lite);
176 if (get_cpu_family() == CPU_OMAP36XX)
177 writel(readl(OMAP34XX_CTRL_WKUP_CTRL) |
178 OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
179 OMAP34XX_CTRL_WKUP_CTRL);
180
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200181 omap_die_id_display();
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400182
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200183 set_led();
184
185 set_boardname();
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200186
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400187 return 0;
188}
189
Ladislav Michlc44e29f2016-07-12 20:28:33 +0200190void board_mtdparts_default(const char **mtdids, const char **mtdparts)
191{
192 struct mtd_info *mtd = get_mtd_device(NULL, 0);
193 if (mtd) {
194 static char ids[24];
195 static char parts[48];
196 const char *linux_name = "omap2-nand";
197 if (strncmp(mtd->name, "onenand0", 8) == 0)
198 linux_name = "omap2-onenand";
199 snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
200 snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
201 linux_name, 4 * mtd->erasesize >> 10);
202 *mtdids = ids;
203 *mtdparts = parts;
204 }
205}