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/utils.h>
15 #include <asm/arch/reset_manager.h>
17 #include <asm/arch/system_manager.h>
18 #include <asm/arch/freeze_controller.h>
19 #include <asm/arch/clock_manager.h>
20 #include <asm/arch/scan_manager.h>
21 #include <asm/arch/sdram.h>
22 #include <asm/arch/scu.h>
23 #include <asm/arch/misc.h>
24 #include <asm/arch/nic301.h>
25 #include <asm/sections.h>
28 #include <asm/arch/pinmux.h>
29 #include <asm/arch/fpga_manager.h>
32 #include <linux/delay.h>
34 #define FPGA_BUFSIZ 16 * 1024
35 #define FSBL_IMAGE_IS_VALID 0x49535756
37 #define FSBL_IMAGE_IS_INVALID 0x0
38 #define BOOTROM_CONFIGURES_IO_PINMUX 0x3
40 DECLARE_GLOBAL_DATA_PTR;
42 #define BOOTROM_SHARED_MEM_SIZE 0x800 /* 2KB */
43 #define BOOTROM_SHARED_MEM_ADDR (CFG_SYS_INIT_RAM_ADDR + \
44 SOCFPGA_PHYS_OCRAM_SIZE - \
45 BOOTROM_SHARED_MEM_SIZE)
46 #define RST_STATUS_SHARED_ADDR (BOOTROM_SHARED_MEM_ADDR + 0x438)
47 static u32 rst_mgr_status __section(".data");
50 * Bootrom will clear the status register in reset manager and stores the
51 * reset status value in shared memory. Bootrom stores shared data at last
53 * This function save reset status provided by BootROM to rst_mgr_status.
54 * More information about reset status register value can be found in reset
55 * manager register description.
56 * When running in debugger without Bootrom, r0 to r3 are random values.
57 * So, skip save the value when r0 is not BootROM shared data address.
59 * r0 - Contains the pointer to the shared memory block. The shared
60 * memory block is located in the top 2 KB of on-chip RAM.
61 * r1 - contains the length of the shared memory.
62 * r2 - unused and set to 0x0.
63 * r3 - points to the version block.
65 void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
68 if (r0 == BOOTROM_SHARED_MEM_ADDR)
69 rst_mgr_status = readl(RST_STATUS_SHARED_ADDR);
71 save_boot_params_ret();
74 u32 spl_boot_device(void)
76 const u32 bsel = readl(socfpga_get_sysmgr_addr() + SYSMGR_A10_BOOTINFO);
78 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
79 case 0x1: /* FPGA (HPS2FPGA Bridge) */
80 return BOOT_DEVICE_RAM;
81 case 0x2: /* NAND Flash (1.8V) */
82 case 0x3: /* NAND Flash (3.0V) */
83 socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
84 return BOOT_DEVICE_NAND;
85 case 0x4: /* SD/MMC External Transceiver (1.8V) */
86 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
87 socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
88 socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
89 return BOOT_DEVICE_MMC1;
90 case 0x6: /* QSPI Flash (1.8V) */
91 case 0x7: /* QSPI Flash (3.0V) */
92 socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
93 return BOOT_DEVICE_SPI;
95 printf("Invalid boot device (bsel=%08x)!\n", bsel);
100 #ifdef CONFIG_SPL_MMC
101 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
103 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
104 return MMCSD_MODE_FS;
106 return MMCSD_MODE_RAW;
111 void spl_board_init(void)
115 ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ);
117 /* enable console uart printing */
118 preloader_console_init();
123 /* If the full FPGA is already loaded, ie.from EPCQ, config fpga pins */
124 if ((IS_ENABLED(CONFIG_SOCFPGA_ARRIA10_ALWAYS_REPROGRAM) &&
125 is_regular_boot_valid()) ||
126 (!IS_ENABLED(CONFIG_SOCFPGA_ARRIA10_ALWAYS_REPROGRAM) &&
127 is_fpgamgr_user_mode())) {
128 ret = config_pins(gd->fdt_blob, "shared");
132 ret = config_pins(gd->fdt_blob, "fpga");
135 } else if (IS_ENABLED(CONFIG_SOCFPGA_ARRIA10_ALWAYS_REPROGRAM) ||
136 !is_fpgamgr_early_user_mode()) {
137 /* Program IOSSM(early IO release) or full FPGA */
138 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
140 /* Skipping double program for combined RBF */
141 if (!is_fpgamgr_user_mode()) {
143 * Expect FPGA entered early user mode, so
144 * the flag is set to re-program IOSSM
146 force_periph_program(true);
148 /* Re-program IOSSM to stabilize IO system */
149 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
151 force_periph_program(false);
155 /* If the IOSSM/full FPGA is already loaded, start DDR */
156 if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode()) {
157 if (!is_regular_boot_valid()) {
159 * Ensure all signals in stable state before triggering
160 * warm reset. This value is recommended from stress
165 #if IS_ENABLED(CONFIG_CADENCE_QSPI)
167 * Trigger software reset to QSPI flash.
168 * On some boards, the QSPI flash reset may not be
169 * connected to the HPS warm reset.
171 qspi_flash_software_reset();
174 ret = readl(socfpga_get_rstmgr_addr() +
175 RSTMGR_A10_SYSWARMMASK);
177 * Masking s2f & FPGA manager module reset from warm
180 writel(ret & (~(ALT_RSTMGR_SYSWARMMASK_S2F_SET_MSK |
181 ALT_RSTMGR_FPGAMGRWARMMASK_S2F_SET_MSK)),
182 socfpga_get_rstmgr_addr() +
183 RSTMGR_A10_SYSWARMMASK);
186 * BootROM will configure both IO and pin mux after a
189 ret = readl(socfpga_get_sysmgr_addr() +
190 SYSMGR_A10_ROMCODE_CTRL);
191 writel(ret | BOOTROM_CONFIGURES_IO_PINMUX,
192 socfpga_get_sysmgr_addr() +
193 SYSMGR_A10_ROMCODE_CTRL);
196 * Up to here, image is considered valid and should be
197 * set as valid before warm reset is triggered
199 writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() +
200 SYSMGR_A10_ROMCODE_INITSWSTATE);
203 * Set this flag to scratch register, so that a proper
204 * boot progress before / after warm reset can be
207 set_regular_boot(true);
215 * Reset this flag to scratch register, so that a proper
216 * boot progress before / after warm reset can be
219 set_regular_boot(false);
221 ret = readl(socfpga_get_rstmgr_addr() +
222 RSTMGR_A10_SYSWARMMASK);
225 * Unmasking s2f & FPGA manager module reset from warm
228 writel(ret | ALT_RSTMGR_SYSWARMMASK_S2F_SET_MSK |
229 ALT_RSTMGR_FPGAMGRWARMMASK_S2F_SET_MSK,
230 socfpga_get_rstmgr_addr() + RSTMGR_A10_SYSWARMMASK);
233 * Up to here, MPFE hang workaround is considered done and
234 * should be reset as invalid until FSBL successfully loading
235 * SSBL, and prepare jumping to SSBL, then only setting as
238 writel(FSBL_IMAGE_IS_INVALID, socfpga_get_sysmgr_addr() +
239 SYSMGR_A10_ROMCODE_INITSWSTATE);
241 ddr_calibration_sequence();
244 if (!is_fpgamgr_user_mode())
245 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
248 void board_init_f(ulong dummy)
250 if (spl_early_init())
253 socfpga_get_managers_addr();
257 socfpga_init_security_policies();
258 socfpga_sdram_remap_zero();
259 socfpga_pl310_clear();
261 /* Assert reset to all except L4WD0 and L4TIMER0 */
262 socfpga_per_reset_all();
263 socfpga_watchdog_disable();
265 /* Configure the clock based on handoff */
266 cm_basic_init(gd->fdt_blob);
268 #ifdef CONFIG_HW_WATCHDOG
269 /* release osc1 watchdog timer 0 from reset */
270 socfpga_reset_deassert_osc1wd0();
272 /* reconfigure and enable the watchdog */
275 #endif /* CONFIG_HW_WATCHDOG */
277 config_dedicated_pins(gd->fdt_blob);
281 /* board specific function prior loading SSBL / U-Boot proper */
282 void spl_board_prepare_for_boot(void)
284 writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() +
285 SYSMGR_A10_ROMCODE_INITSWSTATE);