blob: a35a7cd3b1f7ba014d131501314f61cf095539bc [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 */
Tom Rinif524eba2024-04-30 20:42:03 -06006#include <config.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
Pau Pajuelo4ddc3092017-08-17 03:09:14 +020032/*
33 * Routine: get_board_revision
34 * Description: GPIO_28 and GPIO_129 are used to read board and revision from
35 * IGEP00x0 boards. First of all, it is necessary to reset USB transceiver from
36 * IGEP0030 in order to read GPIO_IGEP00X0_BOARD_DETECTION correctly, because
37 * this functionality is shared by USB HOST.
Michal Simek50fa1182023-05-17 09:17:16 +020038 * Once USB reset is applied, U-Boot configures these pins as input pullup to
Pau Pajuelo4ddc3092017-08-17 03:09:14 +020039 * detect board and revision:
40 * IGEP0020-RF = 0b00
41 * IGEP0020-RC = 0b01
42 * IGEP0030-RG = 0b10
43 * IGEP0030-RE = 0b11
44 */
45static int get_board_revision(void)
46{
47 int revision;
48
49 gpio_request(IGEP0030_USB_TRANSCEIVER_RESET,
50 "igep0030_usb_transceiver_reset");
51 gpio_direction_output(IGEP0030_USB_TRANSCEIVER_RESET, 0);
52
53 gpio_request(GPIO_IGEP00X0_BOARD_DETECTION, "igep00x0_board_detection");
54 gpio_direction_input(GPIO_IGEP00X0_BOARD_DETECTION);
55 revision = 2 * gpio_get_value(GPIO_IGEP00X0_BOARD_DETECTION);
56 gpio_free(GPIO_IGEP00X0_BOARD_DETECTION);
57
58 gpio_request(GPIO_IGEP00X0_REVISION_DETECTION,
59 "igep00x0_revision_detection");
60 gpio_direction_input(GPIO_IGEP00X0_REVISION_DETECTION);
61 revision = revision + gpio_get_value(GPIO_IGEP00X0_REVISION_DETECTION);
62 gpio_free(GPIO_IGEP00X0_REVISION_DETECTION);
63
64 gpio_free(IGEP0030_USB_TRANSCEIVER_RESET);
65
66 return revision;
67}
68
Ladislav Michl3e349282016-07-12 20:28:31 +020069int onenand_board_init(struct mtd_info *mtd)
70{
71 if (gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND) {
72 struct onenand_chip *this = mtd->priv;
Tom Rini6a5dccc2022-11-16 13:10:41 -050073 this->base = (void *)CFG_SYS_ONENAND_BASE;
Ladislav Michl3e349282016-07-12 20:28:31 +020074 return 0;
75 }
76 return 1;
77}
78
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010079#ifdef CONFIG_OF_BOARD_SETUP
Ladislav Michl4e7241a2017-02-19 00:24:49 +010080static int ft_enable_by_compatible(void *blob, char *compat, int enable)
81{
82 int off = fdt_node_offset_by_compatible(blob, -1, compat);
83 if (off < 0)
84 return off;
85
86 if (enable)
87 fdt_status_okay(blob, off);
88 else
89 fdt_status_disabled(blob, off);
90
91 return 0;
92}
93
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090094int ft_board_setup(void *blob, struct bd_info *bd)
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010095{
96#ifdef CONFIG_FDT_FIXUP_PARTITIONS
Masahiro Yamada20ead6f2018-07-19 16:28:23 +090097 static const struct node_info nodes[] = {
Ladislav Michlbe8e06d2017-01-09 11:21:06 +010098 { "ti,omap2-nand", MTD_DEV_TYPE_NAND, },
99 { "ti,omap2-onenand", MTD_DEV_TYPE_ONENAND, },
100 };
101
102 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
103#endif
Ladislav Michl4e7241a2017-02-19 00:24:49 +0100104 ft_enable_by_compatible(blob, "ti,omap2-nand",
105 gpmc_cs0_flash == MTD_DEV_TYPE_NAND);
106 ft_enable_by_compatible(blob, "ti,omap2-onenand",
107 gpmc_cs0_flash == MTD_DEV_TYPE_ONENAND);
108
Ladislav Michlbe8e06d2017-01-09 11:21:06 +0100109 return 0;
110}
111#endif
112
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200113void set_led(void)
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200114{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200115 switch (get_board_revision()) {
116 case 0:
117 case 1:
118 gpio_request(IGEP0020_GPIO_LED, "igep0020_gpio_led");
119 gpio_direction_output(IGEP0020_GPIO_LED, 1);
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200120 break;
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200121 case 2:
122 case 3:
123 gpio_request(IGEP0030_GPIO_LED, "igep0030_gpio_led");
124 gpio_direction_output(IGEP0030_GPIO_LED, 0);
125 break;
126 default:
127 /* Should not happen... */
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200128 break;
129 }
130}
131
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200132void set_boardname(void)
133{
134 char rev[5] = { 'F','C','G','E', };
135 int i = get_board_revision();
136
137 rev[i+1] = 0;
138 env_set("board_rev", rev + i);
139 env_set("board_name", i < 2 ? "igep0020" : "igep0030");
140}
141
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400142/*
143 * Routine: misc_init_r
144 * Description: Configure board specific parts
145 */
146int misc_init_r(void)
147{
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200148 t2_t *t2_base = (t2_t *)T2_BASE;
149 u32 pbias_lite;
150
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400151 twl4030_power_init();
152
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200153 /* set VSIM to 1.8V */
154 twl4030_pmrecv_vsel_cfg(TWL4030_PM_RECEIVER_VSIM_DEDICATED,
155 TWL4030_PM_RECEIVER_VSIM_VSEL_18,
156 TWL4030_PM_RECEIVER_VSIM_DEV_GRP,
157 TWL4030_PM_RECEIVER_DEV_GRP_P1);
158
159 /* set up dual-voltage GPIOs to 1.8V */
160 pbias_lite = readl(&t2_base->pbias_lite);
161 pbias_lite &= ~PBIASLITEVMODE1;
162 pbias_lite |= PBIASLITEPWRDNZ1;
163 writel(pbias_lite, &t2_base->pbias_lite);
164 if (get_cpu_family() == CPU_OMAP36XX)
165 writel(readl(OMAP34XX_CTRL_WKUP_CTRL) |
166 OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
167 OMAP34XX_CTRL_WKUP_CTRL);
168
Paul Kocialkowski6bc318e2015-08-27 19:37:13 +0200169 omap_die_id_display();
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400170
Pau Pajuelo4ddc3092017-08-17 03:09:14 +0200171 set_led();
172
173 set_boardname();
Javier Martinez Canillas7a0155e2013-08-07 17:53:19 +0200174
Enric Balletbo i Serra2ce268c2010-10-14 16:54:59 -0400175 return 0;
176}
177
Ladislav Michlc44e29f2016-07-12 20:28:33 +0200178void board_mtdparts_default(const char **mtdids, const char **mtdparts)
179{
180 struct mtd_info *mtd = get_mtd_device(NULL, 0);
181 if (mtd) {
182 static char ids[24];
183 static char parts[48];
184 const char *linux_name = "omap2-nand";
185 if (strncmp(mtd->name, "onenand0", 8) == 0)
186 linux_name = "omap2-onenand";
187 snprintf(ids, sizeof(ids), "%s=%s", mtd->name, linux_name);
188 snprintf(parts, sizeof(parts), "mtdparts=%s:%dk(SPL),-(UBI)",
189 linux_name, 4 * mtd->erasesize >> 10);
190 *mtdids = ids;
191 *mtdparts = parts;
192 }
193}