Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * XEA iMX28 board |
| 4 | * |
| 5 | * Copyright (C) 2019 DENX Software Engineering |
| 6 | * Lukasz Majewski, DENX Software Engineering, lukma@denx.de |
| 7 | * |
| 8 | * Copyright (C) 2018 DENX Software Engineering |
| 9 | * Måns Rullgård, DENX Software Engineering, mans@mansr.com |
| 10 | * |
| 11 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
| 12 | * on behalf of DENX Software Engineering GmbH |
| 13 | * |
| 14 | */ |
| 15 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 16 | #include <common.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 17 | #include <fdt_support.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 18 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 19 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 22 | #include <asm/gpio.h> |
| 23 | #include <asm/io.h> |
| 24 | #include <asm/arch/imx-regs.h> |
| 25 | #include <asm/arch/iomux-mx28.h> |
| 26 | #include <asm/arch/clock.h> |
| 27 | #include <asm/arch/sys_proto.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 28 | #include <linux/delay.h> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 29 | #include <linux/mii.h> |
| 30 | #include <miiphy.h> |
| 31 | #include <netdev.h> |
| 32 | #include <errno.h> |
| 33 | #include <usb.h> |
| 34 | #include <serial.h> |
Anatolij Gustschin | 6322fc1 | 2024-01-15 14:51:30 +0100 | [diff] [blame] | 35 | #include <u-boot/crc.h> |
| 36 | #include "boot_img_scr.h" |
| 37 | |
| 38 | #include <spi.h> |
| 39 | #include <spi_flash.h> |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 40 | |
| 41 | #ifdef CONFIG_SPL_BUILD |
| 42 | #include <spl.h> |
| 43 | #endif |
| 44 | |
| 45 | DECLARE_GLOBAL_DATA_PTR; |
| 46 | |
| 47 | /* |
| 48 | * Functions |
| 49 | */ |
| 50 | |
| 51 | static void init_clocks(void) |
| 52 | { |
| 53 | /* IO0 clock at 480MHz */ |
| 54 | mxs_set_ioclk(MXC_IOCLK0, 480000); |
| 55 | /* IO1 clock at 480MHz */ |
| 56 | mxs_set_ioclk(MXC_IOCLK1, 480000); |
| 57 | |
| 58 | /* SSP0 clock at 96MHz */ |
| 59 | mxs_set_sspclk(MXC_SSPCLK0, 96000, 0); |
| 60 | /* SSP2 clock at 160MHz */ |
| 61 | mxs_set_sspclk(MXC_SSPCLK2, 160000, 0); |
| 62 | /* SSP3 clock at 96MHz */ |
| 63 | mxs_set_sspclk(MXC_SSPCLK3, 96000, 0); |
| 64 | } |
| 65 | |
Lukasz Majewski | 0920716 | 2021-12-27 11:38:21 +0100 | [diff] [blame] | 66 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK) |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 67 | void board_init_f(ulong arg) |
| 68 | { |
| 69 | init_clocks(); |
Lukasz Majewski | bc6026d | 2023-05-19 12:43:55 +0200 | [diff] [blame] | 70 | spl_early_init(); |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 71 | preloader_console_init(); |
| 72 | } |
| 73 | |
Anatolij Gustschin | 6322fc1 | 2024-01-15 14:51:30 +0100 | [diff] [blame] | 74 | static struct boot_img_src img_src[2]; |
| 75 | static int spi_load_boot_info(void) |
| 76 | { |
| 77 | struct spi_flash *flash; |
| 78 | int err; |
| 79 | |
| 80 | flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, |
| 81 | CONFIG_SF_DEFAULT_CS, |
| 82 | CONFIG_SF_DEFAULT_SPEED, |
| 83 | CONFIG_SF_DEFAULT_MODE); |
| 84 | if (!flash) { |
| 85 | printf("%s: SPI probe err\n", __func__); |
| 86 | return -ENODEV; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * Load both boot info structs from SPI flash |
| 91 | */ |
| 92 | err = spi_flash_read(flash, SPI_FLASH_BOOT_SRC_OFFS, |
| 93 | sizeof(img_src[0]), |
| 94 | (void *)&img_src[0]); |
| 95 | if (err) { |
| 96 | debug("%s: First boot info NOR sector read error %d\n", |
| 97 | __func__, err); |
| 98 | return err; |
| 99 | } |
| 100 | |
| 101 | err = spi_flash_read(flash, |
| 102 | SPI_FLASH_BOOT_SRC_OFFS + SPI_FLASH_SECTOR_SIZE, |
| 103 | sizeof(img_src[0]), |
| 104 | (void *)&img_src[1]); |
| 105 | if (err) { |
| 106 | debug("%s: First boot info NOR sector read error %d\n", |
| 107 | __func__, err); |
| 108 | return err; |
| 109 | } |
| 110 | |
| 111 | debug("%s: BI0 0x%x 0x%x 0x%x\n", __func__, |
| 112 | img_src[0].magic, img_src[0].flags, img_src[0].crc8); |
| 113 | |
| 114 | debug("%s: BI1 0x%x 0x%x 0x%x\n", __func__, |
| 115 | img_src[1].magic, img_src[1].flags, img_src[1].crc8); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 120 | static int boot_tiva0, boot_tiva1; |
| 121 | |
| 122 | /* Check if TIVAs request booting via U-Boot proper */ |
| 123 | void spl_board_init(void) |
| 124 | { |
Lukasz Majewski | 07adfb1 | 2020-01-25 09:01:39 +0100 | [diff] [blame] | 125 | struct gpio_desc btiva0, btiva1, en_3_3v; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 126 | int ret; |
| 127 | |
Lukasz Majewski | 07adfb1 | 2020-01-25 09:01:39 +0100 | [diff] [blame] | 128 | /* |
| 129 | * Setup GPIO0_0 (TIVA power enable pin) to be output high |
| 130 | * to allow TIVA startup. |
| 131 | */ |
| 132 | ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v); |
| 133 | if (ret) |
| 134 | printf("Cannot get GPIO0_0\n"); |
| 135 | |
| 136 | ret = dm_gpio_request(&en_3_3v, "pwr_3_3v"); |
| 137 | if (ret) |
| 138 | printf("Cannot request GPIO0_0\n"); |
| 139 | |
| 140 | /* Set GPIO0_0 to HIGH */ |
| 141 | dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 142 | |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 143 | ret = dm_gpio_lookup_name("GPIO0_23", &btiva0); |
| 144 | if (ret) |
| 145 | printf("Cannot get GPIO0_23\n"); |
| 146 | |
| 147 | ret = dm_gpio_lookup_name("GPIO0_25", &btiva1); |
| 148 | if (ret) |
| 149 | printf("Cannot get GPIO0_25\n"); |
| 150 | |
| 151 | ret = dm_gpio_request(&btiva0, "boot-tiva0"); |
| 152 | if (ret) |
| 153 | printf("Cannot request GPIO0_23\n"); |
| 154 | |
| 155 | ret = dm_gpio_request(&btiva1, "boot-tiva1"); |
| 156 | if (ret) |
| 157 | printf("Cannot request GPIO0_25\n"); |
| 158 | |
| 159 | dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN); |
| 160 | dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN); |
| 161 | |
| 162 | udelay(1000); |
| 163 | |
| 164 | boot_tiva0 = dm_gpio_get_value(&btiva0); |
| 165 | boot_tiva1 = dm_gpio_get_value(&btiva1); |
| 166 | } |
| 167 | |
Anatolij Gustschin | 6322fc1 | 2024-01-15 14:51:30 +0100 | [diff] [blame] | 168 | int spl_mmc_emmc_boot_partition(struct mmc *mmc) |
| 169 | { |
| 170 | int i, src_idx = -1, ret; |
| 171 | |
| 172 | ret = spi_load_boot_info(); |
| 173 | if (ret) { |
| 174 | printf("%s: Cannot read XEA boot info! [%d]\n", __func__, ret); |
| 175 | /* To avoid bricking board - by default boot from boot0 eMMC */ |
| 176 | return 1; |
| 177 | } |
| 178 | |
| 179 | for (i = 0; i < 2; i++) { |
| 180 | if (img_src[i].magic == 'B' && |
| 181 | img_src[i].crc8 == crc8(0, &img_src[i].magic, 2)) { |
| 182 | src_idx = i; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | debug("%s: src idx: %d\n", __func__, src_idx); |
| 188 | |
| 189 | if (src_idx < 0) |
| 190 | /* |
| 191 | * Always use eMMC (mmcblkX) boot0 if no |
| 192 | * valid image source description found |
| 193 | */ |
| 194 | return 1; |
| 195 | |
| 196 | if (img_src[src_idx].flags & BOOT_SRC_PART1) |
| 197 | return 2; |
| 198 | |
| 199 | return 1; |
| 200 | } |
| 201 | |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 202 | void board_boot_order(u32 *spl_boot_list) |
| 203 | { |
| 204 | spl_boot_list[0] = BOOT_DEVICE_MMC1; |
| 205 | spl_boot_list[1] = BOOT_DEVICE_SPI; |
Lukasz Majewski | 27458d2 | 2020-07-10 09:49:32 +0200 | [diff] [blame] | 206 | spl_boot_list[2] = BOOT_DEVICE_UART; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | int spl_start_uboot(void) |
| 210 | { |
| 211 | /* break into full u-boot on 'c' */ |
| 212 | if (serial_tstc() && serial_getc() == 'c') |
| 213 | return 1; |
| 214 | |
| 215 | debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1); |
| 216 | return !boot_tiva0 || !boot_tiva1; |
| 217 | } |
| 218 | #else |
Lukasz Majewski | 80361a1 | 2024-03-29 12:18:08 +0100 | [diff] [blame] | 219 | /* |
| 220 | * Reading the HW ID number for XEA SoM module |
| 221 | * |
| 222 | * GPIOs from Port 1 (GPIO1_15, GPIO1_16, GPIO1_17 and GPIO1_18) |
| 223 | * are used to store HW revision information. |
| 224 | * Reading of GPIOs values is performed before the Device Model is |
| 225 | * bring up as the proper DTB needs to be chosen first. |
| 226 | * |
| 227 | * Moreover, this approach is required as "single binary" configuration |
| 228 | * of U-Boot (imx28_xea_sb_defconfig) is NOT using SPL framework, so |
| 229 | * only minimal subset of functionality is provided when ID is read. |
| 230 | * |
| 231 | * Hence, the direct registers' access. |
| 232 | */ |
| 233 | #define XEA_SOM_HW_ID_GPIO_PORT (MXS_PINCTRL_BASE + (0x0900 + ((1) * 0x10))) |
| 234 | #define XEA_SOM_REV_MASK GENMASK(18, 15) |
| 235 | #define XEA_SOM_REV_SHIFT 15 |
| 236 | |
| 237 | static u8 get_som_rev(void) |
| 238 | { |
| 239 | struct mxs_register_32 *reg = |
| 240 | (struct mxs_register_32 *)XEA_SOM_HW_ID_GPIO_PORT; |
| 241 | |
| 242 | u32 tmp = ~readl(®->reg); |
| 243 | u8 id = (tmp & XEA_SOM_REV_MASK) >> XEA_SOM_REV_SHIFT; |
| 244 | |
| 245 | return id; |
| 246 | } |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 247 | |
| 248 | int board_early_init_f(void) |
| 249 | { |
| 250 | init_clocks(); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | int board_init(void) |
| 256 | { |
| 257 | struct gpio_desc phy_rst; |
| 258 | int ret; |
| 259 | |
| 260 | /* Address of boot parameters */ |
| 261 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 262 | |
| 263 | cpu_eth_init(NULL); |
| 264 | |
| 265 | /* PHY INT#/PWDN# */ |
| 266 | ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst); |
| 267 | if (ret) { |
| 268 | printf("Cannot get GPIO4_13\n"); |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | ret = dm_gpio_request(&phy_rst, "phy-rst"); |
| 273 | if (ret) { |
| 274 | printf("Cannot request GPIO4_13\n"); |
| 275 | return ret; |
| 276 | } |
| 277 | |
| 278 | dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN); |
| 279 | udelay(1000); |
| 280 | |
| 281 | return 0; |
| 282 | } |
Lukasz Majewski | 80361a1 | 2024-03-29 12:18:08 +0100 | [diff] [blame] | 283 | |
| 284 | #if defined(CONFIG_BOARD_LATE_INIT) |
| 285 | int board_late_init(void) |
| 286 | { |
| 287 | int ret = env_set_ulong("board_som_rev", get_som_rev()); |
| 288 | |
| 289 | if (ret) |
| 290 | printf("Cannot set XEA's SoM revision env variable!\n"); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | #endif |
| 295 | |
| 296 | #if defined(CONFIG_DISPLAY_BOARDINFO) |
| 297 | int checkboard(void) |
| 298 | { |
| 299 | printf("Board: LWE XEA SoM HW rev %d\n", get_som_rev()); |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | #endif |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 304 | |
| 305 | int dram_init(void) |
| 306 | { |
| 307 | return mxs_dram_init(); |
| 308 | } |
| 309 | |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 310 | #ifdef CONFIG_OF_BOARD_SETUP |
| 311 | static int fdt_fixup_l2switch(void *blob) |
| 312 | { |
| 313 | u8 ethaddr[6]; |
| 314 | int ret; |
| 315 | |
| 316 | if (eth_env_get_enetaddr("ethaddr", ethaddr)) { |
| 317 | ret = fdt_find_and_setprop(blob, |
| 318 | "/ahb@80080000/switch@800f0000", |
| 319 | "local-mac-address", ethaddr, 6, 1); |
| 320 | if (ret < 0) |
| 321 | printf("%s: can't find usbether@1 node: %d\n", |
| 322 | __func__, ret); |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 328 | int ft_board_setup(void *blob, struct bd_info *bd) |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 329 | { |
| 330 | /* |
| 331 | * i.MX28 L2 switch needs manual update (fixup) of eth MAC address |
| 332 | * (in 'local-mac-address' property) as it uses "switch@800f0000" |
| 333 | * node, not set by default FIT image handling code in |
| 334 | * "ethernet@800f0000" |
| 335 | */ |
| 336 | fdt_fixup_l2switch(blob); |
| 337 | |
| 338 | return 0; |
| 339 | } |
| 340 | #endif |
Lukasz Majewski | d70cd28 | 2023-05-19 12:43:46 +0200 | [diff] [blame] | 341 | /* |
| 342 | * NOTE: |
| 343 | * |
| 344 | * IMX28 clock "stub" DM driver! |
| 345 | * |
| 346 | * Only used for SPL stage, which is NOT using DM; serial and |
| 347 | * eMMC configuration. |
| 348 | */ |
| 349 | static const struct udevice_id imx28_clk_ids[] = { |
| 350 | { .compatible = "fsl,imx28-clkctrl", }, |
| 351 | { } |
| 352 | }; |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 353 | |
Lukasz Majewski | d70cd28 | 2023-05-19 12:43:46 +0200 | [diff] [blame] | 354 | U_BOOT_DRIVER(fsl_imx28_clkctrl) = { |
| 355 | .name = "fsl_imx28_clkctrl", |
| 356 | .id = UCLASS_CLK, |
| 357 | .of_match = imx28_clk_ids, |
| 358 | }; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 359 | #endif /* CONFIG_SPL_BUILD */ |