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 | |
| 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 |
| 219 | |
| 220 | int board_early_init_f(void) |
| 221 | { |
| 222 | init_clocks(); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | int board_init(void) |
| 228 | { |
| 229 | struct gpio_desc phy_rst; |
| 230 | int ret; |
| 231 | |
| 232 | /* Address of boot parameters */ |
| 233 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 234 | |
| 235 | cpu_eth_init(NULL); |
| 236 | |
| 237 | /* PHY INT#/PWDN# */ |
| 238 | ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst); |
| 239 | if (ret) { |
| 240 | printf("Cannot get GPIO4_13\n"); |
| 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | ret = dm_gpio_request(&phy_rst, "phy-rst"); |
| 245 | if (ret) { |
| 246 | printf("Cannot request GPIO4_13\n"); |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN); |
| 251 | udelay(1000); |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | int dram_init(void) |
| 257 | { |
| 258 | return mxs_dram_init(); |
| 259 | } |
| 260 | |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 261 | #ifdef CONFIG_OF_BOARD_SETUP |
| 262 | static int fdt_fixup_l2switch(void *blob) |
| 263 | { |
| 264 | u8 ethaddr[6]; |
| 265 | int ret; |
| 266 | |
| 267 | if (eth_env_get_enetaddr("ethaddr", ethaddr)) { |
| 268 | ret = fdt_find_and_setprop(blob, |
| 269 | "/ahb@80080000/switch@800f0000", |
| 270 | "local-mac-address", ethaddr, 6, 1); |
| 271 | if (ret < 0) |
| 272 | printf("%s: can't find usbether@1 node: %d\n", |
| 273 | __func__, ret); |
| 274 | } |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 279 | int ft_board_setup(void *blob, struct bd_info *bd) |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 280 | { |
| 281 | /* |
| 282 | * i.MX28 L2 switch needs manual update (fixup) of eth MAC address |
| 283 | * (in 'local-mac-address' property) as it uses "switch@800f0000" |
| 284 | * node, not set by default FIT image handling code in |
| 285 | * "ethernet@800f0000" |
| 286 | */ |
| 287 | fdt_fixup_l2switch(blob); |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | #endif |
Lukasz Majewski | d70cd28 | 2023-05-19 12:43:46 +0200 | [diff] [blame] | 292 | /* |
| 293 | * NOTE: |
| 294 | * |
| 295 | * IMX28 clock "stub" DM driver! |
| 296 | * |
| 297 | * Only used for SPL stage, which is NOT using DM; serial and |
| 298 | * eMMC configuration. |
| 299 | */ |
| 300 | static const struct udevice_id imx28_clk_ids[] = { |
| 301 | { .compatible = "fsl,imx28-clkctrl", }, |
| 302 | { } |
| 303 | }; |
Lukasz Majewski | 363cd97 | 2020-01-25 09:01:37 +0100 | [diff] [blame] | 304 | |
Lukasz Majewski | d70cd28 | 2023-05-19 12:43:46 +0200 | [diff] [blame] | 305 | U_BOOT_DRIVER(fsl_imx28_clkctrl) = { |
| 306 | .name = "fsl_imx28_clkctrl", |
| 307 | .id = UCLASS_CLK, |
| 308 | .of_match = imx28_clk_ids, |
| 309 | }; |
Lukasz Majewski | f3adb66 | 2019-12-08 22:06:56 +0100 | [diff] [blame] | 310 | #endif /* CONFIG_SPL_BUILD */ |