Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 DENX Software Engineering |
| 4 | * Lukasz Majewski, DENX Software Engineering, lukma@denx.de |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 5 | */ |
| 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 Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 16 | #include <env.h> |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 17 | #include <errno.h> |
| 18 | #include <asm/gpio.h> |
| 19 | #include <malloc.h> |
| 20 | #include <asm/mach-imx/iomux-v3.h> |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 21 | #include <asm/mach-imx/boot_mode.h> |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 22 | #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 Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 30 | #include "common.h" |
| 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | static bool hw_ids_valid; |
| 35 | static bool sw_ids_valid; |
| 36 | static u32 cpu_id; |
| 37 | static u32 unit_id; |
| 38 | |
Lukasz Majewski | 27aede2 | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 39 | #define EM_PAD IMX_GPIO_NR(3, 29) |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 40 | #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 | |
| 53 | int gpio_table_sw_ids[] = { |
| 54 | SW0, SW1, SW2, SW3 |
| 55 | }; |
| 56 | |
| 57 | const char *gpio_table_sw_ids_names[] = { |
| 58 | "sw0", "sw1", "sw2", "sw3" |
| 59 | }; |
| 60 | |
| 61 | int gpio_table_hw_ids[] = { |
| 62 | HW0, HW1, HW2, HW3, HW4, HW5, HW6, HW7 |
| 63 | }; |
| 64 | |
| 65 | const char *gpio_table_hw_ids_names[] = { |
| 66 | "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7" |
| 67 | }; |
| 68 | |
| 69 | static 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 | |
| 106 | int dram_init(void) |
| 107 | { |
| 108 | gd->ram_size = imx_ddr_size(); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 113 | iomux_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 Majewski | 27aede2 | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 132 | |
| 133 | /* Emergency recovery pin */ |
| 134 | MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL), |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 135 | }; |
| 136 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 137 | /* |
| 138 | * Do not overwrite the console |
| 139 | * Always use serial for U-Boot console |
| 140 | */ |
| 141 | int overwrite_console(void) |
| 142 | { |
| 143 | return 1; |
| 144 | } |
| 145 | |
| 146 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 147 | int ft_board_setup(void *blob, bd_t *bd) |
| 148 | { |
| 149 | fdt_fixup_ethernet(blob); |
| 150 | return 0; |
| 151 | } |
| 152 | #endif |
| 153 | |
Lukasz Majewski | 32e0751 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 154 | int board_phy_config(struct phy_device *phydev) |
| 155 | { |
| 156 | /* 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 | |
| 162 | if (phydev->drv->config) |
| 163 | return phydev->drv->config(phydev); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 168 | int board_init(void) |
| 169 | { |
Lukasz Majewski | e95b4bd | 2019-09-03 16:38:43 +0200 | [diff] [blame] | 170 | struct gpio_desc phy_int_gbe, spi2_wp; |
Lukasz Majewski | 32e0751 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 171 | int ret; |
| 172 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 173 | debug("board init\n"); |
| 174 | /* address of boot parameters */ |
| 175 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 176 | |
Lukasz Majewski | 32e0751 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 177 | /* Setup misc (application specific) stuff */ |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 178 | SETUP_IOMUX_PADS(misc_pads); |
| 179 | |
| 180 | get_board_id(gpio_table_sw_ids, &gpio_table_sw_ids_names[0], |
| 181 | ARRAY_SIZE(gpio_table_sw_ids), &sw_ids_valid, &unit_id); |
| 182 | debug("SWx unit_id 0x%x\n", unit_id); |
| 183 | |
| 184 | get_board_id(gpio_table_hw_ids, &gpio_table_hw_ids_names[0], |
| 185 | ARRAY_SIZE(gpio_table_hw_ids), &hw_ids_valid, &cpu_id); |
| 186 | debug("HWx cpu_id 0x%x\n", cpu_id); |
| 187 | |
| 188 | if (hw_ids_valid && sw_ids_valid) |
| 189 | printf("ID: unit type 0x%x rev 0x%x\n", unit_id, cpu_id); |
| 190 | |
| 191 | udelay(25); |
| 192 | |
Lukasz Majewski | 32e0751 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 193 | /* Setup low level FEC (ETH) */ |
| 194 | ret = dm_gpio_lookup_name("GPIO1_28", &phy_int_gbe); |
| 195 | if (ret) { |
| 196 | printf("Cannot get GPIO1_28\n"); |
| 197 | } else { |
| 198 | ret = dm_gpio_request(&phy_int_gbe, "INT_GBE"); |
| 199 | if (!ret) |
| 200 | dm_gpio_set_dir_flags(&phy_int_gbe, GPIOD_IS_IN); |
| 201 | } |
| 202 | |
| 203 | iomuxc_set_rgmii_io_voltage(DDR_SEL_1P5V_IO); |
| 204 | enable_fec_anatop_clock(0, ENET_125MHZ); |
| 205 | |
Lukasz Majewski | e95b4bd | 2019-09-03 16:38:43 +0200 | [diff] [blame] | 206 | /* Setup #WP for SPI-NOR memory */ |
| 207 | ret = dm_gpio_lookup_name("GPIO7_0", &spi2_wp); |
| 208 | if (ret) { |
| 209 | printf("Cannot get GPIO7_0\n"); |
| 210 | } else { |
| 211 | ret = dm_gpio_request(&spi2_wp, "spi2_#wp"); |
| 212 | if (!ret) |
| 213 | dm_gpio_set_dir_flags(&spi2_wp, GPIOD_IS_OUT | |
| 214 | GPIOD_IS_OUT_ACTIVE); |
| 215 | } |
| 216 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | #ifdef CONFIG_CMD_BMODE |
| 221 | static const struct boot_mode board_boot_modes[] = { |
| 222 | /* eMMC, USDHC-4, 8-bit bus width */ |
| 223 | /* SPI-NOR, ECSPI-2 SS0, 3-bytes addressing */ |
| 224 | {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)}, |
| 225 | {"spinor", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x09)}, |
| 226 | {NULL, 0}, |
| 227 | }; |
| 228 | |
| 229 | static void setup_boot_modes(void) |
| 230 | { |
| 231 | add_board_boot_modes(board_boot_modes); |
| 232 | } |
| 233 | #else |
| 234 | static inline void setup_boot_modes(void) {} |
| 235 | #endif |
| 236 | |
| 237 | int misc_init_r(void) |
| 238 | { |
Lukasz Majewski | 27aede2 | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 239 | int ret; |
| 240 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 241 | setup_boot_modes(); |
Lukasz Majewski | 27aede2 | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 242 | |
| 243 | ret = gpio_request(EM_PAD, "Emergency_PAD"); |
| 244 | if (ret) { |
| 245 | printf("Can't request emergency PAD gpio\n"); |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | ret = gpio_direction_input(EM_PAD); |
| 250 | if (ret) { |
| 251 | printf("Can't set emergency PAD direction\n"); |
| 252 | return ret; |
| 253 | } |
| 254 | |
Lukasz Majewski | a3eec24 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 255 | return 0; |
| 256 | } |