blob: 9edbbf4a29c35a35d2f0a230cec5f3e1229d5211 [file] [log] [blame]
Tom Rini914bb7e2018-07-13 09:05:05 -04001// SPDX-License-Identifier: GPL-2.0+
Ley Foon Tanc859f2a2018-05-24 00:17:27 +08002/*
Tien Fong Chee2f277542021-11-07 23:08:54 +08003 * Copyright (C) 2012-2021 Altera Corporation <www.altera.com>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +08004 */
5
6#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glassdb41d652019-12-28 10:45:07 -07008#include <hang.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Simon Glass401d1c42020-10-30 21:38:53 -060010#include <asm/global_data.h>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080011#include <asm/io.h>
12#include <asm/pl310.h>
13#include <asm/u-boot.h>
14#include <asm/utils.h>
15#include <image.h>
16#include <asm/arch/reset_manager.h>
17#include <spl.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>
Marek Vasutaf746582018-07-30 13:58:54 +020024#include <asm/arch/misc.h>
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080025#include <asm/arch/nic301.h>
26#include <asm/sections.h>
27#include <fdtdec.h>
28#include <watchdog.h>
29#include <asm/arch/pinmux.h>
Tien Fong Chee1085bb32019-05-07 17:42:30 +080030#include <asm/arch/fpga_manager.h>
31#include <mmc.h>
32#include <memalign.h>
Tien Fong Chee3b4ee402021-11-07 23:08:55 +080033#include <linux/delay.h>
Tien Fong Chee1085bb32019-05-07 17:42:30 +080034
35#define FPGA_BUFSIZ 16 * 1024
Tien Fong Chee2f277542021-11-07 23:08:54 +080036#define FSBL_IMAGE_IS_VALID 0x49535756
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080037
Tien Fong Chee3b4ee402021-11-07 23:08:55 +080038#define FSBL_IMAGE_IS_INVALID 0x0
39#define BOOTROM_CONFIGURES_IO_PINMUX 0x3
40
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080041DECLARE_GLOBAL_DATA_PTR;
42
Ley Foon Tan3d884ff2020-03-06 16:55:20 +080043#define BOOTROM_SHARED_MEM_SIZE 0x800 /* 2KB */
Tom Rini65cc0e22022-11-16 13:10:41 -050044#define BOOTROM_SHARED_MEM_ADDR (CFG_SYS_INIT_RAM_ADDR + \
Ley Foon Tan3d884ff2020-03-06 16:55:20 +080045 SOCFPGA_PHYS_OCRAM_SIZE - \
46 BOOTROM_SHARED_MEM_SIZE)
47#define RST_STATUS_SHARED_ADDR (BOOTROM_SHARED_MEM_ADDR + 0x438)
Marek BehĂșn236f2ec2021-05-20 13:23:52 +020048static u32 rst_mgr_status __section(".data");
Ley Foon Tan3d884ff2020-03-06 16:55:20 +080049
50/*
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
53 * 2KB of onchip RAM.
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.
59 *
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.
65 */
66void save_boot_params(unsigned long r0, unsigned long r1, unsigned long r2,
67 unsigned long r3)
68{
69 if (r0 == BOOTROM_SHARED_MEM_ADDR)
70 rst_mgr_status = readl(RST_STATUS_SHARED_ADDR);
71
72 save_boot_params_ret();
73}
74
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080075u32 spl_boot_device(void)
76{
Ley Foon Tandb5741f2019-11-08 10:38:20 +080077 const u32 bsel = readl(socfpga_get_sysmgr_addr() + SYSMGR_A10_BOOTINFO);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +080078
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;
95 default:
96 printf("Invalid boot device (bsel=%08x)!\n", bsel);
97 hang();
98 }
99}
100
Simon Glass103c5f12021-08-08 12:20:09 -0600101#ifdef CONFIG_SPL_MMC
Andre Przywara59073572021-07-12 11:06:49 +0100102u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800103{
Tien Fong Cheef4b40922019-01-23 14:20:05 +0800104#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800105 return MMCSD_MODE_FS;
106#else
107 return MMCSD_MODE_RAW;
108#endif
109}
110#endif
111
112void spl_board_init(void)
113{
Tien Fong Chee3b4ee402021-11-07 23:08:55 +0800114 int ret;
115
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800116 ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ);
117
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800118 /* enable console uart printing */
119 preloader_console_init();
Stefan Roese29caf932022-09-02 14:10:46 +0200120 schedule();
Marek Vasutaf746582018-07-30 13:58:54 +0200121
Marek Vasut0b8f6372018-08-18 19:11:52 +0200122 arch_early_init_r();
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800123
124 /* If the full FPGA is already loaded, ie.from EPCQ, config fpga pins */
125 if (is_fpgamgr_user_mode()) {
Tien Fong Chee3b4ee402021-11-07 23:08:55 +0800126 ret = config_pins(gd->fdt_blob, "shared");
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800127 if (ret)
128 return;
129
130 ret = config_pins(gd->fdt_blob, "fpga");
131 if (ret)
132 return;
133 } else if (!is_fpgamgr_early_user_mode()) {
134 /* Program IOSSM(early IO release) or full FPGA */
135 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
Tien Fong Chee4720b832021-11-07 23:08:56 +0800136
137 /* Skipping double program for combined RBF */
138 if (!is_fpgamgr_user_mode()) {
139 /*
140 * Expect FPGA entered early user mode, so
141 * the flag is set to re-program IOSSM
142 */
143 force_periph_program(true);
144
145 /* Re-program IOSSM to stabilize IO system */
146 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
147
148 force_periph_program(false);
149 }
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800150 }
151
152 /* If the IOSSM/full FPGA is already loaded, start DDR */
Tien Fong Chee3b4ee402021-11-07 23:08:55 +0800153 if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode()) {
154 if (!is_regular_boot_valid()) {
155 /*
156 * Ensure all signals in stable state before triggering
157 * warm reset. This value is recommended from stress
158 * test.
159 */
160 mdelay(10);
161
162#if IS_ENABLED(CONFIG_CADENCE_QSPI)
163 /*
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.
167 */
168 qspi_flash_software_reset();
169#endif
170
171 ret = readl(socfpga_get_rstmgr_addr() +
172 RSTMGR_A10_SYSWARMMASK);
173 /*
174 * Masking s2f & FPGA manager module reset from warm
175 * reset
176 */
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);
181
182 /*
183 * BootROM will configure both IO and pin mux after a
184 * warm reset
185 */
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);
191
192 /*
193 * Up to here, image is considered valid and should be
194 * set as valid before warm reset is triggered
195 */
196 writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() +
197 SYSMGR_A10_ROMCODE_INITSWSTATE);
198
199 /*
200 * Set this flag to scratch register, so that a proper
201 * boot progress before / after warm reset can be
202 * tracked by FSBL
203 */
204 set_regular_boot(true);
205
Stefan Roese29caf932022-09-02 14:10:46 +0200206 schedule();
Tien Fong Chee3b4ee402021-11-07 23:08:55 +0800207
208 reset_cpu();
209 }
210
211 /*
212 * Reset this flag to scratch register, so that a proper
213 * boot progress before / after warm reset can be
214 * tracked by FSBL
215 */
216 set_regular_boot(false);
217
218 ret = readl(socfpga_get_rstmgr_addr() +
219 RSTMGR_A10_SYSWARMMASK);
220
221 /*
222 * Unmasking s2f & FPGA manager module reset from warm
223 * reset
224 */
225 writel(ret | ALT_RSTMGR_SYSWARMMASK_S2F_SET_MSK |
226 ALT_RSTMGR_FPGAMGRWARMMASK_S2F_SET_MSK,
227 socfpga_get_rstmgr_addr() + RSTMGR_A10_SYSWARMMASK);
228
229 /*
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
233 * valid
234 */
235 writel(FSBL_IMAGE_IS_INVALID, socfpga_get_sysmgr_addr() +
236 SYSMGR_A10_ROMCODE_INITSWSTATE);
237
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800238 ddr_calibration_sequence();
Tien Fong Chee3b4ee402021-11-07 23:08:55 +0800239 }
Tien Fong Chee1085bb32019-05-07 17:42:30 +0800240
241 if (!is_fpgamgr_user_mode())
242 fpgamgr_program(buf, FPGA_BUFSIZ, 0);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800243}
244
245void board_init_f(ulong dummy)
246{
Ley Foon Tanbb25aca2019-11-08 10:38:19 +0800247 if (spl_early_init())
248 hang();
249
250 socfpga_get_managers_addr();
251
Marek Vasut7544ad02018-05-08 20:32:01 +0200252 dcache_disable();
253
Marek Vasut0b8f6372018-08-18 19:11:52 +0200254 socfpga_init_security_policies();
255 socfpga_sdram_remap_zero();
Marek Vasut476abb72019-03-09 22:25:57 +0100256 socfpga_pl310_clear();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800257
Marek Vasut0b8f6372018-08-18 19:11:52 +0200258 /* Assert reset to all except L4WD0 and L4TIMER0 */
259 socfpga_per_reset_all();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800260 socfpga_watchdog_disable();
261
Marek Vasut0b8f6372018-08-18 19:11:52 +0200262 /* Configure the clock based on handoff */
263 cm_basic_init(gd->fdt_blob);
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800264
265#ifdef CONFIG_HW_WATCHDOG
266 /* release osc1 watchdog timer 0 from reset */
267 socfpga_reset_deassert_osc1wd0();
268
269 /* reconfigure and enable the watchdog */
270 hw_watchdog_init();
Stefan Roese29caf932022-09-02 14:10:46 +0200271 schedule();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800272#endif /* CONFIG_HW_WATCHDOG */
Marek Vasut0b8f6372018-08-18 19:11:52 +0200273
274 config_dedicated_pins(gd->fdt_blob);
Stefan Roese29caf932022-09-02 14:10:46 +0200275 schedule();
Ley Foon Tanc859f2a2018-05-24 00:17:27 +0800276}
Tien Fong Chee2f277542021-11-07 23:08:54 +0800277
278/* board specific function prior loading SSBL / U-Boot proper */
279void spl_board_prepare_for_boot(void)
280{
281 writel(FSBL_IMAGE_IS_VALID, socfpga_get_sysmgr_addr() +
282 SYSMGR_A10_ROMCODE_INITSWSTATE);
283}