blob: 541e3e94a5eb1fb8291504d8d111e20c62fd9e8b [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>
Lukasz Majewskice86bf92017-10-31 17:58:05 +010022#include <miiphy.h>
23#include <netdev.h>
24#include <i2c.h>
25
26#include <dm.h>
27#include <dm/platform_data/serial_mxc.h>
28#include <dm/platdata.h>
29
Lukasz Majewskice86bf92017-10-31 17:58:05 +010030#include "common.h"
31
32DECLARE_GLOBAL_DATA_PTR;
33
34static bool hw_ids_valid;
35static bool sw_ids_valid;
36static u32 cpu_id;
37static u32 unit_id;
38
Lukasz Majewskid7e065a2018-05-11 16:51:08 +020039#define EM_PAD IMX_GPIO_NR(3, 29)
Lukasz Majewskice86bf92017-10-31 17:58:05 +010040#define SW0 IMX_GPIO_NR(2, 4)
41#define SW1 IMX_GPIO_NR(2, 5)
42#define SW2 IMX_GPIO_NR(2, 6)
43#define SW3 IMX_GPIO_NR(2, 7)
44#define HW0 IMX_GPIO_NR(6, 7)
45#define HW1 IMX_GPIO_NR(6, 9)
46#define HW2 IMX_GPIO_NR(6, 10)
47#define HW3 IMX_GPIO_NR(6, 11)
48#define HW4 IMX_GPIO_NR(4, 7)
49#define HW5 IMX_GPIO_NR(4, 11)
50#define HW6 IMX_GPIO_NR(4, 13)
51#define HW7 IMX_GPIO_NR(4, 15)
52
53int gpio_table_sw_ids[] = {
54 SW0, SW1, SW2, SW3
55};
56
57const char *gpio_table_sw_ids_names[] = {
58 "sw0", "sw1", "sw2", "sw3"
59};
60
61int gpio_table_hw_ids[] = {
62 HW0, HW1, HW2, HW3, HW4, HW5, HW6, HW7
63};
64
65const char *gpio_table_hw_ids_names[] = {
66 "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7"
67};
68
69static int get_board_id(int *ids, const char **c, int size,
70 bool *valid, u32 *id)
71{
72 int i, ret, val;
73
74 *valid = false;
75
76 for (i = 0; i < size; i++) {
77 ret = gpio_request(ids[i], c[i]);
78 if (ret) {
79 printf("Can't request SWx gpios\n");
80 return ret;
81 }
82 }
83
84 for (i = 0; i < size; i++) {
85 ret = gpio_direction_input(ids[i]);
86 if (ret) {
87 printf("Can't set SWx gpios direction\n");
88 return ret;
89 }
90 }
91
92 for (i = 0; i < size; i++) {
93 val = gpio_get_value(ids[i]);
94 if (val < 0) {
95 printf("Can't get SW%d ID\n", i);
96 *id = 0;
97 return val;
98 }
99 *id |= val << i;
100 }
101 *valid = true;
102
103 return 0;
104}
105
106int dram_init(void)
107{
108 gd->ram_size = imx_ddr_size();
109
110 return 0;
111}
112
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100113iomux_v3_cfg_t const misc_pads[] = {
114 /* Prod ID GPIO pins */
115 MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL),
116 MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL),
117 MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL),
118 MX6_PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
119
120 /* HW revision GPIO pins */
121 MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
122 MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
123 MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
124 MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
125 MX6_PAD_KEY_ROW0__GPIO4_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
126 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
127 MX6_PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL),
128 MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
129
130 /* XTALOSC */
131 MX6_PAD_GPIO_3__XTALOSC_REF_CLK_24M | MUX_PAD_CTRL(NO_PAD_CTRL),
Lukasz Majewskid7e065a2018-05-11 16:51:08 +0200132
133 /* Emergency recovery pin */
134 MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100135};
136
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200137/*
138 * Do not overwrite the console
139 * Always use serial for U-Boot console
140 */
141int overwrite_console(void)
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100142{
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200143 return 1;
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100144}
145
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200146#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
147int ft_board_setup(void *blob, bd_t *bd)
Lukasz Majewskib336b342018-05-11 16:51:14 +0200148{
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200149 fdt_fixup_ethernet(blob);
Lukasz Majewskib336b342018-05-11 16:51:14 +0200150 return 0;
151}
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200152#endif
Lukasz Majewskib336b342018-05-11 16:51:14 +0200153
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200154int board_phy_config(struct phy_device *phydev)
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100155{
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100156 /* display5 due to PCB routing can only work with 100 Mbps */
157 phydev->advertising &= ~(ADVERTISED_1000baseX_Half |
158 ADVERTISED_1000baseX_Full |
159 SUPPORTED_1000baseT_Half |
160 SUPPORTED_1000baseT_Full);
161
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200162 if (phydev->drv->config)
163 return phydev->drv->config(phydev);
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100164
165 return 0;
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100166}
167
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100168int board_init(void)
169{
Lukasz Majewski75056052019-09-03 16:38:43 +0200170 struct gpio_desc phy_int_gbe, spi2_wp;
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200171 int ret;
172
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100173 debug("board init\n");
174 /* address of boot parameters */
175 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
176
177 /* Setup iomux for non console UARTS */
178 displ5_set_iomux_uart();
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200179 /* Setup misc (application specific) stuff */
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100180 SETUP_IOMUX_PADS(misc_pads);
181
182 get_board_id(gpio_table_sw_ids, &gpio_table_sw_ids_names[0],
183 ARRAY_SIZE(gpio_table_sw_ids), &sw_ids_valid, &unit_id);
184 debug("SWx unit_id 0x%x\n", unit_id);
185
186 get_board_id(gpio_table_hw_ids, &gpio_table_hw_ids_names[0],
187 ARRAY_SIZE(gpio_table_hw_ids), &hw_ids_valid, &cpu_id);
188 debug("HWx cpu_id 0x%x\n", cpu_id);
189
190 if (hw_ids_valid && sw_ids_valid)
191 printf("ID: unit type 0x%x rev 0x%x\n", unit_id, cpu_id);
192
193 udelay(25);
194
Lukasz Majewski40bdb232019-09-03 16:38:42 +0200195 /* Setup low level FEC (ETH) */
196 ret = dm_gpio_lookup_name("GPIO1_28", &phy_int_gbe);
197 if (ret) {
198 printf("Cannot get GPIO1_28\n");
199 } else {
200 ret = dm_gpio_request(&phy_int_gbe, "INT_GBE");
201 if (!ret)
202 dm_gpio_set_dir_flags(&phy_int_gbe, GPIOD_IS_IN);
203 }
204
205 iomuxc_set_rgmii_io_voltage(DDR_SEL_1P5V_IO);
206 enable_fec_anatop_clock(0, ENET_125MHZ);
207
Lukasz Majewski75056052019-09-03 16:38:43 +0200208 /* Setup #WP for SPI-NOR memory */
209 ret = dm_gpio_lookup_name("GPIO7_0", &spi2_wp);
210 if (ret) {
211 printf("Cannot get GPIO7_0\n");
212 } else {
213 ret = dm_gpio_request(&spi2_wp, "spi2_#wp");
214 if (!ret)
215 dm_gpio_set_dir_flags(&spi2_wp, GPIOD_IS_OUT |
216 GPIOD_IS_OUT_ACTIVE);
217 }
218
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100219 return 0;
220}
221
222#ifdef CONFIG_CMD_BMODE
223static const struct boot_mode board_boot_modes[] = {
224 /* eMMC, USDHC-4, 8-bit bus width */
225 /* SPI-NOR, ECSPI-2 SS0, 3-bytes addressing */
226 {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)},
227 {"spinor", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x09)},
228 {NULL, 0},
229};
230
231static void setup_boot_modes(void)
232{
233 add_board_boot_modes(board_boot_modes);
234}
235#else
236static inline void setup_boot_modes(void) {}
237#endif
238
239int misc_init_r(void)
240{
Lukasz Majewskid7e065a2018-05-11 16:51:08 +0200241 int ret;
242
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100243 setup_boot_modes();
Lukasz Majewskid7e065a2018-05-11 16:51:08 +0200244
245 ret = gpio_request(EM_PAD, "Emergency_PAD");
246 if (ret) {
247 printf("Can't request emergency PAD gpio\n");
248 return ret;
249 }
250
251 ret = gpio_direction_input(EM_PAD);
252 if (ret) {
253 printf("Can't set emergency PAD direction\n");
254 return ret;
255 }
256
Lukasz Majewskice86bf92017-10-31 17:58:05 +0100257 return 0;
258}