1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2019 DENX Software Engineering
6 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
8 * Copyright (C) 2018 DENX Software Engineering
9 * Måns Rullgård, DENX Software Engineering, mans@mansr.com
11 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
12 * on behalf of DENX Software Engineering GmbH
16 #include <fdt_support.h>
20 #include <asm/global_data.h>
23 #include <asm/arch/imx-regs.h>
24 #include <asm/arch/iomux-mx28.h>
25 #include <asm/arch/clock.h>
26 #include <asm/arch/sys_proto.h>
27 #include <linux/delay.h>
28 #include <linux/mii.h>
34 #include <u-boot/crc.h>
35 #include "boot_img_scr.h"
38 #include <spi_flash.h>
40 #ifdef CONFIG_SPL_BUILD
44 DECLARE_GLOBAL_DATA_PTR;
50 static void init_clocks(void)
52 /* IO0 clock at 480MHz */
53 mxs_set_ioclk(MXC_IOCLK0, 480000);
54 /* IO1 clock at 480MHz */
55 mxs_set_ioclk(MXC_IOCLK1, 480000);
57 /* SSP0 clock at 96MHz */
58 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
59 /* SSP2 clock at 160MHz */
60 mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
61 /* SSP3 clock at 96MHz */
62 mxs_set_sspclk(MXC_SSPCLK3, 96000, 0);
65 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK)
66 void board_init_f(ulong arg)
70 preloader_console_init();
73 static struct boot_img_src img_src[2];
74 static int spi_load_boot_info(void)
76 struct spi_flash *flash;
79 flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
81 CONFIG_SF_DEFAULT_SPEED,
82 CONFIG_SF_DEFAULT_MODE);
84 printf("%s: SPI probe err\n", __func__);
89 * Load both boot info structs from SPI flash
91 err = spi_flash_read(flash, SPI_FLASH_BOOT_SRC_OFFS,
95 debug("%s: First boot info NOR sector read error %d\n",
100 err = spi_flash_read(flash,
101 SPI_FLASH_BOOT_SRC_OFFS + SPI_FLASH_SECTOR_SIZE,
103 (void *)&img_src[1]);
105 debug("%s: First boot info NOR sector read error %d\n",
110 debug("%s: BI0 0x%x 0x%x 0x%x\n", __func__,
111 img_src[0].magic, img_src[0].flags, img_src[0].crc8);
113 debug("%s: BI1 0x%x 0x%x 0x%x\n", __func__,
114 img_src[1].magic, img_src[1].flags, img_src[1].crc8);
119 static int boot_tiva0, boot_tiva1;
121 /* Check if TIVAs request booting via U-Boot proper */
122 void spl_board_init(void)
124 struct gpio_desc btiva0, btiva1, en_3_3v;
128 * Setup GPIO0_0 (TIVA power enable pin) to be output high
129 * to allow TIVA startup.
131 ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
133 printf("Cannot get GPIO0_0\n");
135 ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
137 printf("Cannot request GPIO0_0\n");
139 /* Set GPIO0_0 to HIGH */
140 dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
142 ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
144 printf("Cannot get GPIO0_23\n");
146 ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
148 printf("Cannot get GPIO0_25\n");
150 ret = dm_gpio_request(&btiva0, "boot-tiva0");
152 printf("Cannot request GPIO0_23\n");
154 ret = dm_gpio_request(&btiva1, "boot-tiva1");
156 printf("Cannot request GPIO0_25\n");
158 dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
159 dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
163 boot_tiva0 = dm_gpio_get_value(&btiva0);
164 boot_tiva1 = dm_gpio_get_value(&btiva1);
167 int spl_mmc_emmc_boot_partition(struct mmc *mmc)
169 int i, src_idx = -1, ret;
171 ret = spi_load_boot_info();
173 printf("%s: Cannot read XEA boot info! [%d]\n", __func__, ret);
174 /* To avoid bricking board - by default boot from boot0 eMMC */
178 for (i = 0; i < 2; i++) {
179 if (img_src[i].magic == 'B' &&
180 img_src[i].crc8 == crc8(0, &img_src[i].magic, 2)) {
186 debug("%s: src idx: %d\n", __func__, src_idx);
190 * Always use eMMC (mmcblkX) boot0 if no
191 * valid image source description found
195 if (img_src[src_idx].flags & BOOT_SRC_PART1)
201 void board_boot_order(u32 *spl_boot_list)
203 spl_boot_list[0] = BOOT_DEVICE_MMC1;
204 spl_boot_list[1] = BOOT_DEVICE_SPI;
205 spl_boot_list[2] = BOOT_DEVICE_UART;
208 int spl_start_uboot(void)
210 /* break into full u-boot on 'c' */
211 if (serial_tstc() && serial_getc() == 'c')
214 debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
215 return !boot_tiva0 || !boot_tiva1;
219 * Reading the HW ID number for XEA SoM module
221 * GPIOs from Port 1 (GPIO1_15, GPIO1_16, GPIO1_17 and GPIO1_18)
222 * are used to store HW revision information.
223 * Reading of GPIOs values is performed before the Device Model is
224 * bring up as the proper DTB needs to be chosen first.
226 * Moreover, this approach is required as "single binary" configuration
227 * of U-Boot (imx28_xea_sb_defconfig) is NOT using SPL framework, so
228 * only minimal subset of functionality is provided when ID is read.
230 * Hence, the direct registers' access.
232 #define XEA_SOM_HW_ID_GPIO_PORT (MXS_PINCTRL_BASE + (0x0900 + ((1) * 0x10)))
233 #define XEA_SOM_REV_MASK GENMASK(18, 15)
234 #define XEA_SOM_REV_SHIFT 15
236 static u8 get_som_rev(void)
238 struct mxs_register_32 *reg =
239 (struct mxs_register_32 *)XEA_SOM_HW_ID_GPIO_PORT;
241 u32 tmp = ~readl(®->reg);
242 u8 id = (tmp & XEA_SOM_REV_MASK) >> XEA_SOM_REV_SHIFT;
247 int board_early_init_f(void)
256 struct gpio_desc phy_rst;
259 /* Address of boot parameters */
260 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
265 ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
267 printf("Cannot get GPIO4_13\n");
271 ret = dm_gpio_request(&phy_rst, "phy-rst");
273 printf("Cannot request GPIO4_13\n");
277 dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
283 #if defined(CONFIG_BOARD_LATE_INIT)
284 int board_late_init(void)
286 int ret = env_set_ulong("board_som_rev", get_som_rev());
289 printf("Cannot set XEA's SoM revision env variable!\n");
295 #if defined(CONFIG_DISPLAY_BOARDINFO)
298 printf("Board: LWE XEA SoM HW rev %d\n", get_som_rev());
306 return mxs_dram_init();
309 #ifdef CONFIG_OF_BOARD_SETUP
310 static int fdt_fixup_l2switch(void *blob)
315 if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
316 ret = fdt_find_and_setprop(blob,
317 "/ahb@80080000/switch@800f0000",
318 "local-mac-address", ethaddr, 6, 1);
320 printf("%s: can't find usbether@1 node: %d\n",
327 int ft_board_setup(void *blob, struct bd_info *bd)
330 * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
331 * (in 'local-mac-address' property) as it uses "switch@800f0000"
332 * node, not set by default FIT image handling code in
333 * "ethernet@800f0000"
335 fdt_fixup_l2switch(blob);
343 * IMX28 clock "stub" DM driver!
345 * Only used for SPL stage, which is NOT using DM; serial and
346 * eMMC configuration.
348 static const struct udevice_id imx28_clk_ids[] = {
349 { .compatible = "fsl,imx28-clkctrl", },
353 U_BOOT_DRIVER(fsl_imx28_clkctrl) = {
354 .name = "fsl_imx28_clkctrl",
356 .of_match = imx28_clk_ids,
358 #endif /* CONFIG_SPL_BUILD */