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