Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | ce86bf9 | 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 | ce86bf9 | 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 | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 16 | #include <env.h> |
Lukasz Majewski | ce86bf9 | 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 | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 21 | #include <asm/mach-imx/boot_mode.h> |
| 22 | #include <asm/mach-imx/spi.h> |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 23 | #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 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
| 40 | static bool hw_ids_valid; |
| 41 | static bool sw_ids_valid; |
| 42 | static u32 cpu_id; |
| 43 | static u32 unit_id; |
| 44 | |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 45 | #define EM_PAD IMX_GPIO_NR(3, 29) |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 46 | #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 | |
| 59 | int gpio_table_sw_ids[] = { |
| 60 | SW0, SW1, SW2, SW3 |
| 61 | }; |
| 62 | |
| 63 | const char *gpio_table_sw_ids_names[] = { |
| 64 | "sw0", "sw1", "sw2", "sw3" |
| 65 | }; |
| 66 | |
| 67 | int gpio_table_hw_ids[] = { |
| 68 | HW0, HW1, HW2, HW3, HW4, HW5, HW6, HW7 |
| 69 | }; |
| 70 | |
| 71 | const char *gpio_table_hw_ids_names[] = { |
| 72 | "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7" |
| 73 | }; |
| 74 | |
| 75 | static 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 | |
| 112 | int dram_init(void) |
| 113 | { |
| 114 | gd->ram_size = imx_ddr_size(); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 119 | iomux_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 Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 138 | |
| 139 | /* Emergency recovery pin */ |
| 140 | MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL), |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 141 | }; |
| 142 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 143 | static 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 Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 158 | /* |
| 159 | * Do not overwrite the console |
| 160 | * Always use serial for U-Boot console |
| 161 | */ |
| 162 | int overwrite_console(void) |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 163 | { |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 164 | return 1; |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 167 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 168 | int ft_board_setup(void *blob, bd_t *bd) |
Lukasz Majewski | b336b34 | 2018-05-11 16:51:14 +0200 | [diff] [blame] | 169 | { |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 170 | fdt_fixup_ethernet(blob); |
Lukasz Majewski | b336b34 | 2018-05-11 16:51:14 +0200 | [diff] [blame] | 171 | return 0; |
| 172 | } |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 173 | #endif |
Lukasz Majewski | b336b34 | 2018-05-11 16:51:14 +0200 | [diff] [blame] | 174 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 175 | int board_phy_config(struct phy_device *phydev) |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 176 | { |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 177 | /* 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 Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 183 | if (phydev->drv->config) |
| 184 | return phydev->drv->config(phydev); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 185 | |
| 186 | return 0; |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 189 | int board_init(void) |
| 190 | { |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 191 | struct gpio_desc phy_int_gbe; |
| 192 | int ret; |
| 193 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 194 | 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 Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 203 | /* Setup misc (application specific) stuff */ |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 204 | 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 Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame^] | 219 | /* 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 Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | #ifdef CONFIG_CMD_BMODE |
| 236 | static 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 | |
| 244 | static void setup_boot_modes(void) |
| 245 | { |
| 246 | add_board_boot_modes(board_boot_modes); |
| 247 | } |
| 248 | #else |
| 249 | static inline void setup_boot_modes(void) {} |
| 250 | #endif |
| 251 | |
| 252 | int misc_init_r(void) |
| 253 | { |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 254 | int ret; |
| 255 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 256 | setup_boot_modes(); |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 257 | |
| 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 Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 270 | return 0; |
| 271 | } |