blob: e008ea9a3fb8017ecf93d1242d09cbd1ebee8f63 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskice86bf92017-10-31 17:58:05 +01002/*
3 * Copyright (C) 2017 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
Lukasz Majewskice86bf92017-10-31 17:58:05 +01005 */
6
7#include <common.h>
8#include <dm.h>
9#include <asm/io.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/iomux.h>
13#include <asm/arch/mx6-pins.h>
14#include <asm/arch/mx6-ddr.h>
15#include <asm/arch/sys_proto.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Lukasz Majewskice86bf92017-10-31 17:58:05 +010017#include <errno.h>
18#include <asm/gpio.h>
19#include <malloc.h>
20#include <asm/mach-imx/iomux-v3.h>
Lukasz Majewskice86bf92017-10-31 17:58:05 +010021#include <asm/mach-imx/boot_mode.h>
22#include <asm/mach-imx/spi.h>
Lukasz Majewskice86bf92017-10-31 17:58:05 +010023#include <miiphy.h>
24#include <netdev.h>
25#include <i2c.h>
26
27#include <dm.h>
28#include <dm/platform_data/serial_mxc.h>
29#include <dm/platdata.h>
30
31#ifndef CONFIG_MXC_SPI
32#error "CONFIG_SPI must be set for this board"
33#error "Please check your config file"
34#endif
35
36#include "common.h"
37
38DECLARE_GLOBAL_DATA_PTR;
39
40static bool hw_ids_valid;
41static bool sw_ids_valid;
42static u32 cpu_id;
43static u32 unit_id;
44
Lukasz Majewskid7e065a2018-05-11 16:51:08 +020045#define EM_PAD IMX_GPIO_NR(3, 29)
Lukasz Majewskice86bf92017-10-31 17:58:05 +010046#define SW0 IMX_GPIO_NR(2, 4)
47#define SW1 IMX_GPIO_NR(2, 5)
48#define SW2 IMX_GPIO_NR(2, 6)
49#define SW3 IMX_GPIO_NR(2, 7)
50#define HW0 IMX_GPIO_NR(6, 7)
51#define HW1 IMX_GPIO_NR(6, 9)
52#define HW2 IMX_GPIO_NR(6, 10)
53#define HW3 IMX_GPIO_NR(6, 11)
54#define HW4 IMX_GPIO_NR(4, 7)
55#define HW5 IMX_GPIO_NR(4, 11)
56#define HW6 IMX_GPIO_NR(4, 13)
57#define HW7 IMX_GPIO_NR(4, 15)
58
59int gpio_table_sw_ids[] = {
60 SW0, SW1, SW2, SW3
61};
62
63const char *gpio_table_sw_ids_names[] = {
64 "sw0", "sw1", "sw2", "sw3"
65};
66
67int gpio_table_hw_ids[] = {
68 HW0, HW1, HW2, HW3, HW4, HW5, HW6, HW7
69};
70
71const char *gpio_table_hw_ids_names[] = {
72 "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7"
73};
74
75static int get_board_id(int *ids, const char **c, int size,
76 bool *valid, u32 *id)
77{
78 int i, ret, val;
79
80 *valid = false;
81
82 for (i = 0; i < size; i++) {
83 ret = gpio_request(ids[i], c[i]);
84 if (ret) {
85 printf("Can't request SWx gpios\n");
86 return ret;
87 }
88 }
89
90 for (i = 0; i < size; i++) {
91 ret = gpio_direction_input(ids[i]);
92 if (ret) {
93 printf("Can't set SWx gpios direction\n");
94 return ret;
95 }
96 }
97
98 for (i = 0; i < size; i++) {
99 val = gpio_get_value(ids[i]);
100 if (val < 0) {
101 printf("Can't get SW%d ID\n", i);
102 *id = 0;
103 return val;
104 }
105 *id |= val << i;
106 }
107 *valid = true;
108
109 return 0;
110}
111
112int dram_init(void)
113{
114 gd->ram_size = imx_ddr_size();
115
116 return 0;
117}
118
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100119iomux_v3_cfg_t const misc_pads[] = {
120 /* Prod ID GPIO pins */
121 MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL),
122 MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL),
123 MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL),
124 MX6_PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
125
126 /* HW revision GPIO pins */
127 MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
128 MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
129 MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
130 MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
131 MX6_PAD_KEY_ROW0__GPIO4_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
132 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
133 MX6_PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL),
134 MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
135
136 /* XTALOSC */
137 MX6_PAD_GPIO_3__XTALOSC_REF_CLK_24M | MUX_PAD_CTRL(NO_PAD_CTRL),
Lukasz Majewskid7e065a2018-05-11 16:51:08 +0200138
139 /* Emergency recovery pin */
140 MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100141};
142
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100143static void displ5_setup_ecspi(void)
144{
145 int ret;
146
147 displ5_set_iomux_ecspi();
148
149 ret = gpio_request(IMX_GPIO_NR(5, 29), "spi2_cs0");
150 if (!ret)
151 gpio_direction_output(IMX_GPIO_NR(5, 29), 1);
152
153 ret = gpio_request(IMX_GPIO_NR(7, 0), "spi2_#wp");
154 if (!ret)
155 gpio_direction_output(IMX_GPIO_NR(7, 0), 1);
156}
157
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200158/*
159 * Do not overwrite the console
160 * Always use serial for U-Boot console
161 */
162int overwrite_console(void)
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100163{
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200164 return 1;
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100165}
166
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200167#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
168int ft_board_setup(void *blob, bd_t *bd)
Lukasz Majewskib336b342018-05-11 16:51:14 +0200169{
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200170 fdt_fixup_ethernet(blob);
Lukasz Majewskib336b342018-05-11 16:51:14 +0200171 return 0;
172}
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200173#endif
Lukasz Majewskib336b342018-05-11 16:51:14 +0200174
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200175int board_phy_config(struct phy_device *phydev)
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100176{
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100177 /* display5 due to PCB routing can only work with 100 Mbps */
178 phydev->advertising &= ~(ADVERTISED_1000baseX_Half |
179 ADVERTISED_1000baseX_Full |
180 SUPPORTED_1000baseT_Half |
181 SUPPORTED_1000baseT_Full);
182
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200183 if (phydev->drv->config)
184 return phydev->drv->config(phydev);
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100185
186 return 0;
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100187}
188
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100189int board_init(void)
190{
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200191 struct gpio_desc phy_int_gbe;
192 int ret;
193
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100194 debug("board init\n");
195 /* address of boot parameters */
196 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
197
198 /* Setup iomux for non console UARTS */
199 displ5_set_iomux_uart();
200
201 displ5_setup_ecspi();
202
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200203 /* Setup misc (application specific) stuff */
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100204 SETUP_IOMUX_PADS(misc_pads);
205
206 get_board_id(gpio_table_sw_ids, &gpio_table_sw_ids_names[0],
207 ARRAY_SIZE(gpio_table_sw_ids), &sw_ids_valid, &unit_id);
208 debug("SWx unit_id 0x%x\n", unit_id);
209
210 get_board_id(gpio_table_hw_ids, &gpio_table_hw_ids_names[0],
211 ARRAY_SIZE(gpio_table_hw_ids), &hw_ids_valid, &cpu_id);
212 debug("HWx cpu_id 0x%x\n", cpu_id);
213
214 if (hw_ids_valid && sw_ids_valid)
215 printf("ID: unit type 0x%x rev 0x%x\n", unit_id, cpu_id);
216
217 udelay(25);
218
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200219 /* Setup low level FEC (ETH) */
220 ret = dm_gpio_lookup_name("GPIO1_28", &phy_int_gbe);
221 if (ret) {
222 printf("Cannot get GPIO1_28\n");
223 } else {
224 ret = dm_gpio_request(&phy_int_gbe, "INT_GBE");
225 if (!ret)
226 dm_gpio_set_dir_flags(&phy_int_gbe, GPIOD_IS_IN);
227 }
228
229 iomuxc_set_rgmii_io_voltage(DDR_SEL_1P5V_IO);
230 enable_fec_anatop_clock(0, ENET_125MHZ);
231
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100232 return 0;
233}
234
235#ifdef CONFIG_CMD_BMODE
236static const struct boot_mode board_boot_modes[] = {
237 /* eMMC, USDHC-4, 8-bit bus width */
238 /* SPI-NOR, ECSPI-2 SS0, 3-bytes addressing */
239 {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)},
240 {"spinor", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x09)},
241 {NULL, 0},
242};
243
244static void setup_boot_modes(void)
245{
246 add_board_boot_modes(board_boot_modes);
247}
248#else
249static inline void setup_boot_modes(void) {}
250#endif
251
252int misc_init_r(void)
253{
Lukasz Majewskid7e065a2018-05-11 16:51:08 +0200254 int ret;
255
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100256 setup_boot_modes();
Lukasz Majewskid7e065a2018-05-11 16:51:08 +0200257
258 ret = gpio_request(EM_PAD, "Emergency_PAD");
259 if (ret) {
260 printf("Can't request emergency PAD gpio\n");
261 return ret;
262 }
263
264 ret = gpio_direction_input(EM_PAD);
265 if (ret) {
266 printf("Can't set emergency PAD direction\n");
267 return ret;
268 }
269
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100270 return 0;
271}