1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012-2021 Altera Corporation <www.altera.com>
10 #include <asm/global_data.h>
12 #include <asm/pl310.h>
13 #include <asm/u-boot.h>
14 #include <asm/utils.h>
16 #include <asm/arch/reset_manager.h>
18 #include <asm/arch/system_manager.h>
19 #include <asm/arch/freeze_controller.h>
20 #include <asm/arch/clock_manager.h>
21 #include <asm/arch/scan_manager.h>
22 #include <asm/arch/sdram.h>
23 #include <asm/arch/scu.h>
24 #include <asm/arch/misc.h>
25 #include <asm/arch/nic301.h>
26 #include <asm/sections.h>
29 #include <asm/arch/pinmux.h>
30 #include <asm/arch/fpga_manager.h>
33 #include <linux/delay.h>
35 #define FPGA_BUFSIZ 16 * 1024
36 #define FSBL_IMAGE_IS_VALID 0x49535756
38 #define FSBL_IMAGE_IS_INVALID 0x0
39 #define BOOTROM_CONFIGURES_IO_PINMUX 0x3
41 DECLARE_GLOBAL_DATA_PTR;
43 #define BOOTROM_SHARED_MEM_SIZE 0x800 /* 2KB */
44 #define BOOTROM_SHARED_MEM_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
45 SOCFPGA_PHYS_OCRAM_SIZE - \
46 BOOTROM_SHARED_MEM_SIZE)
47 #define RST_STATUS_SHARED_ADDR (BOOTROM_SHARED_MEM_ADDR + 0x438)
48 static u32 rst_mgr_status __section(".data");
51 * Bootrom will clear the status register in reset manager and stores the
52 * reset status value in shared memory. Bootrom stores shared data at last
54 * This function save reset status provided by BootROM to rst_mgr_status.
55 * More information about reset status register value can be found in reset
56 * manager register description.
57 * When running in debugger without Bootrom, r0 to r3 are random values.
58 * So, skip save the value when r0 is not BootROM shared data address.
60 * r0 - Contains the pointer to the shared memory block. The shared
61 * memory block is located in the top 2 KB of on-chip RAM.
62 * r1 - contains the length of the shared memory.
63 * r2 - unused and set to 0x0.
64 * r3 - points to the version block.
66 void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
69 if (r0 == BOOTROM_SHARED_MEM_ADDR)
70 rst_mgr_status = readl(RST_STATUS_SHARED_ADDR);
72 save_boot_params_ret();
75 u32 spl_boot_device(void)
77 const u32 bsel = readl(socfpga_get_sysmgr_addr() + SYSMGR_A10_BOOTINFO);
79 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
80 case 0x1: /* FPGA (HPS2FPGA Bridge) */
81 return BOOT_DEVICE_RAM;
82 case 0x2: /* NAND Flash (1.8V) */
83 case 0x3: /* NAND Flash (3.0V) */
84 socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
85 return BOOT_DEVICE_NAND;
86 case 0x4: /* SD/MMC External Transceiver (1.8V) */
87 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
88 socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
89 socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
90 return BOOT_DEVICE_MMC1;
91 case 0x6: /* QSPI Flash (1.8V) */
92 case 0x7: /* QSPI Flash (3.0V) */
93 socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
94 return BOOT_DEVICE_SPI;
96 printf("Invalid boot device (bsel=%08x)!\n", bsel);
101 #ifdef CONFIG_SPL_MMC
102 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
104 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
105 return MMCSD_MODE_FS;
107 return MMCSD_MODE_RAW;
112 void spl_board_init(void)
116 ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ);
118 /* enable console uart printing */
119 preloader_console_init();
124 /* If the full FPGA is already loaded, ie.from EPCQ, config fpga pins */
125 if (is_fpgamgr_user_mode()) {
126 ret = config_pins(gd->fdt_blob, "shared");
130 ret = config_pins(gd->fdt_blob, "fpga");
133 } else if (!is_fpgamgr_early_user_mode()) {
134 /* Program IOSSM(early IO release) or full FPGA */
135 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
137 /* Skipping double program for combined RBF */
138 if (!is_fpgamgr_user_mode()) {
140 * Expect FPGA entered early user mode, so
141 * the flag is set to re-program IOSSM
143 force_periph_program(true);
145 /* Re-program IOSSM to stabilize IO system */
146 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
148 force_periph_program(false);
152 /* If the IOSSM/full FPGA is already loaded, start DDR */
153 if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode()) {
154 if (!is_regular_boot_valid()) {
156 * Ensure all signals in stable state before triggering
157 * warm reset. This value is recommended from stress
162 #if IS_ENABLED(CONFIG_CADENCE_QSPI)
164 * Trigger software reset to QSPI flash.
165 * On some boards, the QSPI flash reset may not be
166 * connected to the HPS warm reset.
168 qspi_flash_software_reset();
171 ret = readl(socfpga_get_rstmgr_addr() +
172 RSTMGR_A10_SYSWARMMASK);
174 * Masking s2f & FPGA manager module reset from warm
177 writel(ret & (~(ALT_RSTMGR_SYSWARMMASK_S2F_SET_MSK |
178 ALT_RSTMGR_FPGAMGRWARMMASK_S2F_SET_MSK)),
179 socfpga_get_rstmgr_addr() +
180 RSTMGR_A10_SYSWARMMASK);
183 * BootROM will configure both IO and pin mux after a
186 ret = readl(socfpga_get_sysmgr_addr() +
187 SYSMGR_A10_ROMCODE_CTRL);
188 writel(ret | BOOTROM_CONFIGURES_IO_PINMUX,
189 socfpga_get_sysmgr_addr() +
190 SYSMGR_A10_ROMCODE_CTRL);
193 * Up to here, image is considered valid and should be
194 * set as valid before warm reset is triggered
196 writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() +
197 SYSMGR_A10_ROMCODE_INITSWSTATE);
200 * Set this flag to scratch register, so that a proper
201 * boot progress before / after warm reset can be
204 set_regular_boot(true);
212 * Reset this flag to scratch register, so that a proper
213 * boot progress before / after warm reset can be
216 set_regular_boot(false);
218 ret = readl(socfpga_get_rstmgr_addr() +
219 RSTMGR_A10_SYSWARMMASK);
222 * Unmasking s2f & FPGA manager module reset from warm
225 writel(ret | ALT_RSTMGR_SYSWARMMASK_S2F_SET_MSK |
226 ALT_RSTMGR_FPGAMGRWARMMASK_S2F_SET_MSK,
227 socfpga_get_rstmgr_addr() + RSTMGR_A10_SYSWARMMASK);
230 * Up to here, MPFE hang workaround is considered done and
231 * should be reset as invalid until FSBL successfully loading
232 * SSBL, and prepare jumping to SSBL, then only setting as
235 writel(FSBL_IMAGE_IS_INVALID, socfpga_get_sysmgr_addr() +
236 SYSMGR_A10_ROMCODE_INITSWSTATE);
238 ddr_calibration_sequence();
241 if (!is_fpgamgr_user_mode())
242 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
245 void board_init_f(ulong dummy)
247 if (spl_early_init())
250 socfpga_get_managers_addr();
254 socfpga_init_security_policies();
255 socfpga_sdram_remap_zero();
256 socfpga_pl310_clear();
258 /* Assert reset to all except L4WD0 and L4TIMER0 */
259 socfpga_per_reset_all();
260 socfpga_watchdog_disable();
262 /* Configure the clock based on handoff */
263 cm_basic_init(gd->fdt_blob);
265 #ifdef CONFIG_HW_WATCHDOG
266 /* release osc1 watchdog timer 0 from reset */
267 socfpga_reset_deassert_osc1wd0();
269 /* reconfigure and enable the watchdog */
272 #endif /* CONFIG_HW_WATCHDOG */
274 config_dedicated_pins(gd->fdt_blob);
278 /* board specific function prior loading SSBL / U-Boot proper */
279 void spl_board_prepare_for_boot(void)
281 writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() +
282 SYSMGR_A10_ROMCODE_INITSWSTATE);