1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
10 #include <asm/cache.h>
12 #include <asm/global_data.h>
16 #include <linux/libfdt.h>
21 #include <asm/arch/misc.h>
22 #include <asm/arch/reset_manager.h>
23 #include <asm/arch/scan_manager.h>
24 #include <asm/arch/system_manager.h>
25 #include <asm/arch/nic301.h>
26 #include <asm/arch/scu.h>
27 #include <asm/pl310.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 phys_addr_t socfpga_clkmgr_base __section(".data");
32 phys_addr_t socfpga_rstmgr_base __section(".data");
33 phys_addr_t socfpga_sysmgr_base __section(".data");
35 #ifdef CONFIG_SYS_L2_PL310
36 static const struct pl310_regs *const pl310 =
37 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
40 struct bsel bsel_str[] = {
41 { "rsvd", "Reserved", },
42 { "fpga", "FPGA (HPS2FPGA Bridge)", },
43 { "nand", "NAND Flash (1.8V)", },
44 { "nand", "NAND Flash (3.0V)", },
45 { "sd", "SD/MMC External Transceiver (1.8V)", },
46 { "sd", "SD/MMC Internal Transceiver (3.0V)", },
47 { "qspi", "QSPI Flash (1.8V)", },
48 { "qspi", "QSPI Flash (3.0V)", },
53 if (fdtdec_setup_mem_size_base() != 0)
59 void enable_caches(void)
61 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
64 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
69 #ifdef CONFIG_SYS_L2_PL310
70 void v7_outer_cache_enable(void)
74 if (uclass_get_device(UCLASS_CACHE, 0, &dev))
75 pr_err("cache controller driver NOT found!\n");
78 void v7_outer_cache_disable(void)
80 /* Disable the L2 cache */
81 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
84 void socfpga_pl310_clear(void)
86 u32 mask = 0xff, ena = 0;
90 /* Disable the L2 cache */
91 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
93 writel(0x0, &pl310->pl310_tag_latency_ctrl);
94 writel(0x10, &pl310->pl310_data_latency_ctrl);
96 /* enable BRESP, instruction and data prefetch, full line of zeroes */
97 setbits_le32(&pl310->pl310_aux_ctrl,
98 L310_AUX_CTRL_DATA_PREFETCH_MASK |
99 L310_AUX_CTRL_INST_PREFETCH_MASK |
100 L310_SHARED_ATT_OVERRIDE_ENABLE);
102 /* Enable the L2 cache */
103 ena = readl(&pl310->pl310_ctrl);
107 * Invalidate the PL310 L2 cache. Keep the invalidation code
108 * entirely in L1 I-cache to avoid any bus traffic through
129 : "+r"(mask), "+r"(ena)
130 : "r"(&pl310->pl310_inv_way),
131 "r"(&pl310->pl310_cache_sync), "r"(&pl310->pl310_ctrl)
134 /* Disable the L2 cache */
135 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
139 #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
140 defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
141 int overwrite_console(void)
148 /* add device descriptor to FPGA device table */
149 void socfpga_fpga_add(void *fpga_desc)
152 fpga_add(fpga_altera, fpga_desc);
156 int arch_cpu_init(void)
158 socfpga_get_managers_addr();
160 #ifdef CONFIG_HW_WATCHDOG
162 * In case the watchdog is enabled, make sure to (re-)configure it
163 * so that the defined timeout is valid. Otherwise the SPL (Perloader)
164 * timeout value is still active which might too short for Linux
170 * If the HW watchdog is NOT enabled, make sure it is not running,
171 * for example because it was enabled in the preloader. This might
172 * trigger a watchdog-triggered reboot of Linux kernel later.
173 * Toggle watchdog reset, so watchdog in not running state.
175 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
176 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
182 #ifndef CONFIG_SPL_BUILD
183 static int do_bridge(struct cmd_tbl *cmdtp, int flag, int argc,
186 unsigned int mask = ~0;
188 if (argc < 2 || argc > 3)
189 return CMD_RET_USAGE;
194 mask = hextoul(argv[1], NULL);
197 case 'e': /* Enable */
198 do_bridge_reset(1, mask);
200 case 'd': /* Disable */
201 do_bridge_reset(0, mask);
204 return CMD_RET_USAGE;
210 U_BOOT_CMD(bridge, 3, 1, do_bridge,
211 "SoCFPGA HPS FPGA bridge control",
212 "enable [mask] - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
213 "bridge disable [mask] - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
219 static int socfpga_get_base_addr(const char *compat, phys_addr_t *base)
221 const void *blob = gd->fdt_blob;
222 struct fdt_resource r;
226 node = fdt_node_offset_by_compatible(blob, -1, compat);
230 if (!fdtdec_get_is_enabled(blob, node))
233 ret = fdt_get_resource(blob, node, "reg", 0, &r);
237 *base = (phys_addr_t)r.start;
242 void socfpga_get_managers_addr(void)
246 ret = socfpga_get_base_addr("altr,rst-mgr", &socfpga_rstmgr_base);
250 ret = socfpga_get_base_addr("altr,sys-mgr", &socfpga_sysmgr_base);
254 #ifdef CONFIG_TARGET_SOCFPGA_AGILEX
255 ret = socfpga_get_base_addr("intel,agilex-clkmgr",
256 &socfpga_clkmgr_base);
257 #elif IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
258 ret = socfpga_get_base_addr("intel,n5x-clkmgr",
259 &socfpga_clkmgr_base);
261 ret = socfpga_get_base_addr("altr,clk-mgr", &socfpga_clkmgr_base);
267 phys_addr_t socfpga_get_rstmgr_addr(void)
269 return socfpga_rstmgr_base;
272 phys_addr_t socfpga_get_sysmgr_addr(void)
274 return socfpga_sysmgr_base;
277 phys_addr_t socfpga_get_clkmgr_addr(void)
279 return socfpga_clkmgr_base;