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> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <fdt_support.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame^] | 10 | #include <init.h> |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/iomux.h> |
| 15 | #include <asm/arch/mx6-pins.h> |
| 16 | #include <asm/arch/mx6-ddr.h> |
| 17 | #include <asm/arch/sys_proto.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 18 | #include <env.h> |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <asm/gpio.h> |
| 21 | #include <malloc.h> |
| 22 | #include <asm/mach-imx/iomux-v3.h> |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 23 | #include <asm/mach-imx/boot_mode.h> |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 24 | #include <miiphy.h> |
| 25 | #include <netdev.h> |
| 26 | #include <i2c.h> |
| 27 | |
| 28 | #include <dm.h> |
| 29 | #include <dm/platform_data/serial_mxc.h> |
| 30 | #include <dm/platdata.h> |
| 31 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 32 | #include "common.h" |
| 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | static bool hw_ids_valid; |
| 37 | static bool sw_ids_valid; |
| 38 | static u32 cpu_id; |
| 39 | static u32 unit_id; |
| 40 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 41 | const char *gpio_table_sw_names[] = { |
| 42 | "GPIO2_4", "GPIO2_5", "GPIO2_6", "GPIO2_7" |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | const char *gpio_table_sw_ids_names[] = { |
| 46 | "sw0", "sw1", "sw2", "sw3" |
| 47 | }; |
| 48 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 49 | const char *gpio_table_hw_names[] = { |
| 50 | "GPIO6_7", "GPIO6_9", "GPIO6_10", "GPIO6_11", |
| 51 | "GPIO4_7", "GPIO4_11", "GPIO4_13", "GPIO4_15" |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | const char *gpio_table_hw_ids_names[] = { |
| 55 | "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7" |
| 56 | }; |
| 57 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 58 | static int get_board_id(const char **pin_names, const char **ids_names, |
| 59 | int size, bool *valid, u32 *id) |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 60 | { |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 61 | struct gpio_desc desc; |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 62 | int i, ret, val; |
| 63 | |
| 64 | *valid = false; |
| 65 | |
| 66 | for (i = 0; i < size; i++) { |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 67 | memset(&desc, 0, sizeof(desc)); |
| 68 | |
| 69 | ret = dm_gpio_lookup_name(pin_names[i], &desc); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 70 | if (ret) { |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 71 | printf("Can't lookup request SWx gpios\n"); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 72 | return ret; |
| 73 | } |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 74 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 75 | ret = dm_gpio_request(&desc, ids_names[i]); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 76 | if (ret) { |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 77 | printf("Can't lookup request SWx gpios\n"); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 78 | return ret; |
| 79 | } |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 80 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 81 | dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN); |
| 82 | |
| 83 | val = dm_gpio_get_value(&desc); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 84 | if (val < 0) { |
| 85 | printf("Can't get SW%d ID\n", i); |
| 86 | *id = 0; |
| 87 | return val; |
| 88 | } |
| 89 | *id |= val << i; |
| 90 | } |
| 91 | *valid = true; |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int dram_init(void) |
| 97 | { |
| 98 | gd->ram_size = imx_ddr_size(); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 103 | iomux_v3_cfg_t const misc_pads[] = { |
| 104 | /* Prod ID GPIO pins */ |
| 105 | MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 106 | MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 107 | MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 108 | MX6_PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 109 | |
| 110 | /* HW revision GPIO pins */ |
| 111 | MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 112 | MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 113 | MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 114 | MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 115 | MX6_PAD_KEY_ROW0__GPIO4_IO07 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 116 | MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 117 | MX6_PAD_KEY_ROW3__GPIO4_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 118 | MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 119 | |
| 120 | /* XTALOSC */ |
| 121 | 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] | 122 | |
| 123 | /* Emergency recovery pin */ |
| 124 | MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL), |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 125 | }; |
| 126 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 127 | /* |
| 128 | * Do not overwrite the console |
| 129 | * Always use serial for U-Boot console |
| 130 | */ |
| 131 | int overwrite_console(void) |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 132 | { |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 133 | return 1; |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 136 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 137 | int ft_board_setup(void *blob, bd_t *bd) |
Lukasz Majewski | b336b34 | 2018-05-11 16:51:14 +0200 | [diff] [blame] | 138 | { |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 139 | fdt_fixup_ethernet(blob); |
Lukasz Majewski | b336b34 | 2018-05-11 16:51:14 +0200 | [diff] [blame] | 140 | return 0; |
| 141 | } |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 142 | #endif |
Lukasz Majewski | b336b34 | 2018-05-11 16:51:14 +0200 | [diff] [blame] | 143 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 144 | int board_phy_config(struct phy_device *phydev) |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 145 | { |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 146 | /* display5 due to PCB routing can only work with 100 Mbps */ |
| 147 | phydev->advertising &= ~(ADVERTISED_1000baseX_Half | |
| 148 | ADVERTISED_1000baseX_Full | |
| 149 | SUPPORTED_1000baseT_Half | |
| 150 | SUPPORTED_1000baseT_Full); |
| 151 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 152 | if (phydev->drv->config) |
| 153 | return phydev->drv->config(phydev); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 154 | |
| 155 | return 0; |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 158 | int board_init(void) |
| 159 | { |
Lukasz Majewski | 7505605 | 2019-09-03 16:38:43 +0200 | [diff] [blame] | 160 | struct gpio_desc phy_int_gbe, spi2_wp; |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 161 | int ret; |
| 162 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 163 | debug("board init\n"); |
| 164 | /* address of boot parameters */ |
| 165 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 166 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 167 | /* Setup misc (application specific) stuff */ |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 168 | SETUP_IOMUX_PADS(misc_pads); |
| 169 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 170 | get_board_id(gpio_table_sw_names, &gpio_table_sw_ids_names[0], |
| 171 | ARRAY_SIZE(gpio_table_sw_names), &sw_ids_valid, &unit_id); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 172 | debug("SWx unit_id 0x%x\n", unit_id); |
| 173 | |
Lukasz Majewski | f795939 | 2019-09-03 16:38:50 +0200 | [diff] [blame] | 174 | get_board_id(gpio_table_hw_names, &gpio_table_hw_ids_names[0], |
| 175 | ARRAY_SIZE(gpio_table_hw_names), &hw_ids_valid, &cpu_id); |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 176 | debug("HWx cpu_id 0x%x\n", cpu_id); |
| 177 | |
| 178 | if (hw_ids_valid && sw_ids_valid) |
| 179 | printf("ID: unit type 0x%x rev 0x%x\n", unit_id, cpu_id); |
| 180 | |
| 181 | udelay(25); |
| 182 | |
Lukasz Majewski | 40bdb23 | 2019-09-03 16:38:42 +0200 | [diff] [blame] | 183 | /* Setup low level FEC (ETH) */ |
| 184 | ret = dm_gpio_lookup_name("GPIO1_28", &phy_int_gbe); |
| 185 | if (ret) { |
| 186 | printf("Cannot get GPIO1_28\n"); |
| 187 | } else { |
| 188 | ret = dm_gpio_request(&phy_int_gbe, "INT_GBE"); |
| 189 | if (!ret) |
| 190 | dm_gpio_set_dir_flags(&phy_int_gbe, GPIOD_IS_IN); |
| 191 | } |
| 192 | |
| 193 | iomuxc_set_rgmii_io_voltage(DDR_SEL_1P5V_IO); |
| 194 | enable_fec_anatop_clock(0, ENET_125MHZ); |
| 195 | |
Lukasz Majewski | 7505605 | 2019-09-03 16:38:43 +0200 | [diff] [blame] | 196 | /* Setup #WP for SPI-NOR memory */ |
| 197 | ret = dm_gpio_lookup_name("GPIO7_0", &spi2_wp); |
| 198 | if (ret) { |
| 199 | printf("Cannot get GPIO7_0\n"); |
| 200 | } else { |
| 201 | ret = dm_gpio_request(&spi2_wp, "spi2_#wp"); |
| 202 | if (!ret) |
| 203 | dm_gpio_set_dir_flags(&spi2_wp, GPIOD_IS_OUT | |
| 204 | GPIOD_IS_OUT_ACTIVE); |
| 205 | } |
| 206 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | #ifdef CONFIG_CMD_BMODE |
| 211 | static const struct boot_mode board_boot_modes[] = { |
| 212 | /* eMMC, USDHC-4, 8-bit bus width */ |
| 213 | /* SPI-NOR, ECSPI-2 SS0, 3-bytes addressing */ |
| 214 | {"emmc", MAKE_CFGVAL(0x60, 0x58, 0x00, 0x00)}, |
| 215 | {"spinor", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x09)}, |
| 216 | {NULL, 0}, |
| 217 | }; |
| 218 | |
| 219 | static void setup_boot_modes(void) |
| 220 | { |
| 221 | add_board_boot_modes(board_boot_modes); |
| 222 | } |
| 223 | #else |
| 224 | static inline void setup_boot_modes(void) {} |
| 225 | #endif |
| 226 | |
| 227 | int misc_init_r(void) |
| 228 | { |
Lukasz Majewski | 3490a20 | 2019-09-03 16:38:49 +0200 | [diff] [blame] | 229 | struct gpio_desc em_pad; |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 230 | int ret; |
| 231 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 232 | setup_boot_modes(); |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 233 | |
Lukasz Majewski | 3490a20 | 2019-09-03 16:38:49 +0200 | [diff] [blame] | 234 | ret = dm_gpio_lookup_name("GPIO3_29", &em_pad); |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 235 | if (ret) { |
Lukasz Majewski | 3490a20 | 2019-09-03 16:38:49 +0200 | [diff] [blame] | 236 | printf("Can't find emergency PAD gpio\n"); |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 237 | return ret; |
| 238 | } |
| 239 | |
Lukasz Majewski | 3490a20 | 2019-09-03 16:38:49 +0200 | [diff] [blame] | 240 | ret = dm_gpio_request(&em_pad, "Emergency_PAD"); |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 241 | if (ret) { |
Lukasz Majewski | 3490a20 | 2019-09-03 16:38:49 +0200 | [diff] [blame] | 242 | printf("Can't request emergency PAD gpio\n"); |
Lukasz Majewski | d7e065a | 2018-05-11 16:51:08 +0200 | [diff] [blame] | 243 | return ret; |
| 244 | } |
| 245 | |
Lukasz Majewski | 3490a20 | 2019-09-03 16:38:49 +0200 | [diff] [blame] | 246 | dm_gpio_set_dir_flags(&em_pad, GPIOD_IS_IN); |
| 247 | |
Lukasz Majewski | ce86bf9 | 2017-10-31 17:58:05 +0100 | [diff] [blame] | 248 | return 0; |
| 249 | } |