1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2016-2021 Intel Corporation
14 #include <spi_flash.h>
16 #include <asm/arch/misc.h>
17 #include <asm/arch/pinmux.h>
18 #include <asm/arch/reset_manager.h>
19 #include <asm/arch/reset_manager_arria10.h>
20 #include <asm/arch/sdram_arria10.h>
21 #include <asm/arch/system_manager.h>
22 #include <asm/arch/nic301.h>
24 #include <asm/pl310.h>
25 #include <linux/sizes.h>
27 #define PINMUX_UART0_TX_SHARED_IO_OFFSET_Q1_3 0x08
28 #define PINMUX_UART0_TX_SHARED_IO_OFFSET_Q2_11 0x58
29 #define PINMUX_UART0_TX_SHARED_IO_OFFSET_Q3_3 0x68
30 #define PINMUX_UART1_TX_SHARED_IO_OFFSET_Q1_7 0x18
31 #define PINMUX_UART1_TX_SHARED_IO_OFFSET_Q3_7 0x78
32 #define PINMUX_UART1_TX_SHARED_IO_OFFSET_Q4_3 0x98
34 #define REGULAR_BOOT_MAGIC 0xd15ea5e
35 #define PERIPH_RBF_PROG_FORCE 0x50455249
37 #define QSPI_S25FL_SOFT_RESET_COMMAND 0x00f0ff82
38 #define QSPI_N25_SOFT_RESET_COMMAND 0x00000001
39 #define QSPI_NO_SOFT_RESET 0x00000000
42 * FPGA programming support for SoC FPGA Arria 10
44 static Altera_desc altera_fpga[] = {
49 fast_passive_parallel,
50 /* No limitation as additional data will be ignored */
52 /* No device function table */
54 /* Base interface address specified in driver */
56 /* No cookie implementation */
61 #if defined(CONFIG_SPL_BUILD)
62 static struct pl310_regs *const pl310 =
63 (struct pl310_regs *)CFG_SYS_PL310_BASE;
64 static const struct socfpga_noc_fw_ocram *noc_fw_ocram_base =
65 (void *)SOCFPGA_SDR_FIREWALL_OCRAM_ADDRESS;
68 + * This function initializes security policies to be consistent across
69 + * all logic units in the Arria 10.
71 + * The idea is to set all security policies to be normal, nonsecure
74 void socfpga_init_security_policies(void)
76 /* Put OCRAM in non-secure */
77 writel(0x003f0000, &noc_fw_ocram_base->region0);
78 writel(0x1, &noc_fw_ocram_base->enable);
80 /* Put DDR in non-secure */
81 writel(0xffff0000, SOCFPGA_SDR_FIREWALL_L3_ADDRESS + 0xc);
82 writel(0x1, SOCFPGA_SDR_FIREWALL_L3_ADDRESS);
84 /* Enable priviledged and non-priviledged access to L4 peripherals */
85 writel(~0, SOCFPGA_NOC_L4_PRIV_FLT_OFST);
87 /* Enable secure and non-secure transactions to bridges */
88 writel(~0, SOCFPGA_NOC_FW_H2F_SCR_OFST);
89 writel(~0, SOCFPGA_NOC_FW_H2F_SCR_OFST + 4);
92 socfpga_get_sysmgr_addr() + SYSMGR_A10_ECC_INTMASK_SET);
95 void socfpga_sdram_remap_zero(void)
97 /* Configure the L2 controller to make SDRAM start at 0 */
98 writel(0x1, &pl310->pl310_addr_filter_start);
102 int arch_early_init_r(void)
104 /* Add device descriptor to FPGA device table */
105 socfpga_fpga_add(&altera_fpga[0]);
111 * Print CPU information
113 #if defined(CONFIG_DISPLAY_CPUINFO)
114 int print_cpuinfo(void)
116 const u32 bootinfo = readl(socfpga_get_sysmgr_addr() +
117 SYSMGR_A10_BOOTINFO);
118 const u32 bsel = SYSMGR_GET_BOOTINFO_BSEL(bootinfo);
120 puts("CPU: Altera SoCFPGA Arria 10\n");
122 printf("BOOT: %s\n", bsel_str[bsel].name);
127 void do_bridge_reset(int enable, unsigned int mask)
130 socfpga_reset_deassert_bridges_handoff();
132 socfpga_bridges_reset();
136 * This function set/unset flag with number "0x50455249" to
137 * handoff register isw_handoff[7] - 0xffd0624c
138 * This flag is used to force periph RBF program regardless FPGA status
139 * and double periph RBF config are needed on some devices or boards to
140 * stabilize the IO config system.
142 void force_periph_program(unsigned int status)
145 writel(PERIPH_RBF_PROG_FORCE, socfpga_get_sysmgr_addr() +
146 SYSMGR_A10_ISW_HANDOFF_BASE + SYSMGR_A10_ISW_HANDOFF_7);
148 writel(0, socfpga_get_sysmgr_addr() +
149 SYSMGR_A10_ISW_HANDOFF_BASE + SYSMGR_A10_ISW_HANDOFF_7);
153 * This function is used to check whether
154 * handoff register isw_handoff[7] contains
155 * flag for forcing the periph RBF program "0x50455249".
157 bool is_periph_program_force(void)
161 status = readl(socfpga_get_sysmgr_addr() +
162 SYSMGR_A10_ISW_HANDOFF_BASE + SYSMGR_A10_ISW_HANDOFF_7);
164 if (status == PERIPH_RBF_PROG_FORCE)
171 * This function set/unset magic number "0xd15ea5e" to
172 * handoff register isw_handoff[7] - 0xffd0624c
173 * This magic number is part of boot progress tracking
174 * and it's required for warm reset workaround on MPFE hang issue.
176 void set_regular_boot(unsigned int status)
179 writel(REGULAR_BOOT_MAGIC, socfpga_get_sysmgr_addr() +
180 SYSMGR_A10_ISW_HANDOFF_BASE + SYSMGR_A10_ISW_HANDOFF_7);
182 writel(0, socfpga_get_sysmgr_addr() +
183 SYSMGR_A10_ISW_HANDOFF_BASE + SYSMGR_A10_ISW_HANDOFF_7);
187 * This function is used to check whether
188 * handoff register isw_handoff[7] contains
189 * magic number "0xd15ea5e".
191 bool is_regular_boot_valid(void)
195 status = readl(socfpga_get_sysmgr_addr() +
196 SYSMGR_A10_ISW_HANDOFF_BASE + SYSMGR_A10_ISW_HANDOFF_7);
198 if (status == REGULAR_BOOT_MAGIC)
204 #if IS_ENABLED(CONFIG_CADENCE_QSPI)
205 /* This function is used to trigger software reset
206 * to the QSPI flash. On some boards, the QSPI flash reset may
207 * not be connected to the HPS warm reset.
209 int qspi_flash_software_reset(void)
211 struct udevice *flash;
214 /* Get the flash info */
215 ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS,
216 CONFIG_SF_DEFAULT_CS,
217 CONFIG_SF_DEFAULT_SPEED,
218 CONFIG_SF_DEFAULT_MODE,
222 debug("Failed to initialize SPI flash at ");
223 debug("%u:%u (error %d)\n", CONFIG_SF_DEFAULT_BUS,
224 CONFIG_SF_DEFAULT_CS, ret);
232 * QSPI flash software reset command, for the case where
233 * no HPS reset connected to QSPI flash reset
235 if (!memcmp(flash->name, "N25", SZ_1 + SZ_2))
236 writel(QSPI_N25_SOFT_RESET_COMMAND, socfpga_get_sysmgr_addr() +
237 SYSMGR_A10_ROMCODE_QSPIRESETCOMMAND);
238 else if (!memcmp(flash->name, "S25FL", SZ_1 + SZ_4))
239 writel(QSPI_S25FL_SOFT_RESET_COMMAND,
240 socfpga_get_sysmgr_addr() +
241 SYSMGR_A10_ROMCODE_QSPIRESETCOMMAND);
242 else /* No software reset */
243 writel(QSPI_NO_SOFT_RESET, socfpga_get_sysmgr_addr() +
244 SYSMGR_A10_ROMCODE_QSPIRESETCOMMAND);
250 void dram_bank_mmu_setup(int bank)
252 struct bd_info *bd = gd->bd;
256 /* If we're still in OCRAM, don't set the XN bit on it */
257 if (!(gd->flags & GD_FLG_RELOC)) {
259 CFG_SYS_INIT_RAM_ADDR >> MMU_SECTION_SHIFT,
260 DCACHE_WRITETHROUGH);
264 * The default implementation of this function allows the DRAM dcache
265 * to be enabled only after relocation. However, to speed up ECC
266 * initialization, we want to be able to enable DRAM dcache before
267 * relocation, so we don't check GD_FLG_RELOC (this assumes bd->bi_dram
270 start = bd->bi_dram[bank].start >> MMU_SECTION_SHIFT;
271 size = bd->bi_dram[bank].size >> MMU_SECTION_SHIFT;
272 for (i = start; i < start + size; i++)
273 set_section_dcache(i, DCACHE_DEFAULT_OPTION);