blob: a362d25c01a5c25e73917cf3a9ca1a4281cfb6af [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewskia3eec242017-10-31 17:58:05 +01002/*
3 * Copyright (C) 2017 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
Lukasz Majewskia3eec242017-10-31 17:58:05 +01005 */
6
7#include <common.h>
8#include <dm.h>
Simon Glass4d72caa2020-05-10 11:40:01 -06009#include <fdt_support.h>
Lukasz Majewskia3eec242017-10-31 17:58:05 +010010#include <asm/io.h>
11#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
14#include <asm/arch/mx6-pins.h>
15#include <asm/arch/mx6-ddr.h>
16#include <asm/arch/sys_proto.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060017#include <env.h>
Lukasz Majewskia3eec242017-10-31 17:58:05 +010018#include <errno.h>
19#include <asm/gpio.h>
20#include <malloc.h>
21#include <asm/mach-imx/iomux-v3.h>
Lukasz Majewskia3eec242017-10-31 17:58:05 +010022#include <asm/mach-imx/boot_mode.h>
Lukasz Majewskia3eec242017-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
Lukasz Majewskia3eec242017-10-31 17:58:05 +010031#include "common.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
35static bool hw_ids_valid;
36static bool sw_ids_valid;
37static u32 cpu_id;
38static u32 unit_id;
39
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020040const char *gpio_table_sw_names[] = {
41 "GPIO2_4", "GPIO2_5", "GPIO2_6", "GPIO2_7"
Lukasz Majewskia3eec242017-10-31 17:58:05 +010042};
43
44const char *gpio_table_sw_ids_names[] = {
45 "sw0", "sw1", "sw2", "sw3"
46};
47
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020048const char *gpio_table_hw_names[] = {
49 "GPIO6_7", "GPIO6_9", "GPIO6_10", "GPIO6_11",
50 "GPIO4_7", "GPIO4_11", "GPIO4_13", "GPIO4_15"
Lukasz Majewskia3eec242017-10-31 17:58:05 +010051};
52
53const char *gpio_table_hw_ids_names[] = {
54 "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7"
55};
56
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020057static int get_board_id(const char **pin_names, const char **ids_names,
58 int size, bool *valid, u32 *id)
Lukasz Majewskia3eec242017-10-31 17:58:05 +010059{
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020060 struct gpio_desc desc;
Lukasz Majewskia3eec242017-10-31 17:58:05 +010061 int i, ret, val;
62
63 *valid = false;
64
65 for (i = 0; i < size; i++) {
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020066 memset(&desc, 0, sizeof(desc));
67
68 ret = dm_gpio_lookup_name(pin_names[i], &desc);
Lukasz Majewskia3eec242017-10-31 17:58:05 +010069 if (ret) {
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020070 printf("Can't lookup request SWx gpios\n");
Lukasz Majewskia3eec242017-10-31 17:58:05 +010071 return ret;
72 }
Lukasz Majewskia3eec242017-10-31 17:58:05 +010073
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020074 ret = dm_gpio_request(&desc, ids_names[i]);
Lukasz Majewskia3eec242017-10-31 17:58:05 +010075 if (ret) {
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020076 printf("Can't lookup request SWx gpios\n");
Lukasz Majewskia3eec242017-10-31 17:58:05 +010077 return ret;
78 }
Lukasz Majewskia3eec242017-10-31 17:58:05 +010079
Lukasz Majewski45aac6d2019-09-03 16:38:50 +020080 dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN);
81
82 val = dm_gpio_get_value(&desc);
Lukasz Majewskia3eec242017-10-31 17:58:05 +010083 if (val < 0) {
84 printf("Can't get SW%d ID\n", i);
85 *id = 0;
86 return val;
87 }
88 *id |= val << i;
89 }
90 *valid = true;
91
92 return 0;
93}
94
95int dram_init(void)
96{
97 gd->ram_size = imx_ddr_size();
98
99 return 0;
100}
101
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100102iomux_v3_cfg_t const misc_pads[] = {
103 /* Prod ID GPIO pins */
104 MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL),
105 MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL),
106 MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL),
107 MX6_PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
108
109 /* HW revision GPIO pins */
110 MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
111 MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
112 MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL),
113 MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
114 MX6_PAD_KEY_ROW0__GPIO4_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL),
115 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
116 MX6_PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL),
117 MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
118
119 /* XTALOSC */
120 MX6_PAD_GPIO_3__XTALOSC_REF_CLK_24M | MUX_PAD_CTRL(NO_PAD_CTRL),
Lukasz Majewski27aede22018-05-11 16:51:08 +0200121
122 /* Emergency recovery pin */
123 MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100124};
125
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100126/*
127 * Do not overwrite the console
128 * Always use serial for U-Boot console
129 */
130int overwrite_console(void)
131{
132 return 1;
133}
134
135#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
136int ft_board_setup(void *blob, bd_t *bd)
137{
138 fdt_fixup_ethernet(blob);
139 return 0;
140}
141#endif
142
Lukasz Majewski32e07512019-09-03 16:38:42 +0200143int board_phy_config(struct phy_device *phydev)
144{
145 /* display5 due to PCB routing can only work with 100 Mbps */
146 phydev->advertising &= ~(ADVERTISED_1000baseX_Half |
147 ADVERTISED_1000baseX_Full |
148 SUPPORTED_1000baseT_Half |
149 SUPPORTED_1000baseT_Full);
150
151 if (phydev->drv->config)
152 return phydev->drv->config(phydev);
153
154 return 0;
155}
156
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100157int board_init(void)
158{
Lukasz Majewskie95b4bd2019-09-03 16:38:43 +0200159 struct gpio_desc phy_int_gbe, spi2_wp;
Lukasz Majewski32e07512019-09-03 16:38:42 +0200160 int ret;
161
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100162 debug("board init\n");
163 /* address of boot parameters */
164 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
165
Lukasz Majewski32e07512019-09-03 16:38:42 +0200166 /* Setup misc (application specific) stuff */
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100167 SETUP_IOMUX_PADS(misc_pads);
168
Lukasz Majewski45aac6d2019-09-03 16:38:50 +0200169 get_board_id(gpio_table_sw_names, &gpio_table_sw_ids_names[0],
170 ARRAY_SIZE(gpio_table_sw_names), &sw_ids_valid, &unit_id);
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100171 debug("SWx unit_id 0x%x\n", unit_id);
172
Lukasz Majewski45aac6d2019-09-03 16:38:50 +0200173 get_board_id(gpio_table_hw_names, &gpio_table_hw_ids_names[0],
174 ARRAY_SIZE(gpio_table_hw_names), &hw_ids_valid, &cpu_id);
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100175 debug("HWx cpu_id 0x%x\n", cpu_id);
176
177 if (hw_ids_valid && sw_ids_valid)
178 printf("ID: unit type 0x%x rev 0x%x\n", unit_id, cpu_id);
179
180 udelay(25);
181
Lukasz Majewski32e07512019-09-03 16:38:42 +0200182 /* Setup low level FEC (ETH) */
183 ret = dm_gpio_lookup_name("GPIO1_28", &phy_int_gbe);
184 if (ret) {
185 printf("Cannot get GPIO1_28\n");
186 } else {
187 ret = dm_gpio_request(&phy_int_gbe, "INT_GBE");
188 if (!ret)
189 dm_gpio_set_dir_flags(&phy_int_gbe, GPIOD_IS_IN);
190 }
191
192 iomuxc_set_rgmii_io_voltage(DDR_SEL_1P5V_IO);
193 enable_fec_anatop_clock(0, ENET_125MHZ);
194
Lukasz Majewskie95b4bd2019-09-03 16:38:43 +0200195 /* Setup #WP for SPI-NOR memory */
196 ret = dm_gpio_lookup_name("GPIO7_0", &spi2_wp);
197 if (ret) {
198 printf("Cannot get GPIO7_0\n");
199 } else {
200 ret = dm_gpio_request(&spi2_wp, "spi2_#wp");
201 if (!ret)
202 dm_gpio_set_dir_flags(&spi2_wp, GPIOD_IS_OUT |
203 GPIOD_IS_OUT_ACTIVE);
204 }
205
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100206 return 0;
207}
208
209#ifdef CONFIG_CMD_BMODE
210static const struct boot_mode board_boot_modes[] = {
211 /* eMMC, USDHC-4, 8-bit bus width */
212 /* SPI-NOR, ECSPI-2 SS0, 3-bytes addressing */
213 {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)},
214 {"spinor", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x09)},
215 {NULL, 0},
216};
217
218static void setup_boot_modes(void)
219{
220 add_board_boot_modes(board_boot_modes);
221}
222#else
223static inline void setup_boot_modes(void) {}
224#endif
225
226int misc_init_r(void)
227{
Lukasz Majewskifeeff152019-09-03 16:38:49 +0200228 struct gpio_desc em_pad;
Lukasz Majewski27aede22018-05-11 16:51:08 +0200229 int ret;
230
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100231 setup_boot_modes();
Lukasz Majewski27aede22018-05-11 16:51:08 +0200232
Lukasz Majewskifeeff152019-09-03 16:38:49 +0200233 ret = dm_gpio_lookup_name("GPIO3_29", &em_pad);
234 if (ret) {
235 printf("Can't find emergency PAD gpio\n");
236 return ret;
237 }
238
239 ret = dm_gpio_request(&em_pad, "Emergency_PAD");
Lukasz Majewski27aede22018-05-11 16:51:08 +0200240 if (ret) {
241 printf("Can't request emergency PAD gpio\n");
242 return ret;
243 }
244
Lukasz Majewskifeeff152019-09-03 16:38:49 +0200245 dm_gpio_set_dir_flags(&em_pad, GPIOD_IS_IN);
Lukasz Majewski27aede22018-05-11 16:51:08 +0200246
Lukasz Majewskia3eec242017-10-31 17:58:05 +0100247 return 0;
248}