1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
10 #include <asm/cache.h>
15 #include <linux/libfdt.h>
20 #include <asm/arch/misc.h>
21 #include <asm/arch/reset_manager.h>
22 #include <asm/arch/scan_manager.h>
23 #include <asm/arch/system_manager.h>
24 #include <asm/arch/nic301.h>
25 #include <asm/arch/scu.h>
26 #include <asm/pl310.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 phys_addr_t socfpga_clkmgr_base __section(".data");
31 phys_addr_t socfpga_rstmgr_base __section(".data");
32 phys_addr_t socfpga_sysmgr_base __section(".data");
34 #ifdef CONFIG_SYS_L2_PL310
35 static const struct pl310_regs *const pl310 =
36 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
39 struct bsel bsel_str[] = {
40 { "rsvd", "Reserved", },
41 { "fpga", "FPGA (HPS2FPGA Bridge)", },
42 { "nand", "NAND Flash (1.8V)", },
43 { "nand", "NAND Flash (3.0V)", },
44 { "sd", "SD/MMC External Transceiver (1.8V)", },
45 { "sd", "SD/MMC Internal Transceiver (3.0V)", },
46 { "qspi", "QSPI Flash (1.8V)", },
47 { "qspi", "QSPI Flash (3.0V)", },
52 if (fdtdec_setup_mem_size_base() != 0)
58 void enable_caches(void)
60 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
63 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
68 #ifdef CONFIG_SYS_L2_PL310
69 void v7_outer_cache_enable(void)
73 if (uclass_get_device(UCLASS_CACHE, 0, &dev))
74 pr_err("cache controller driver NOT found!\n");
77 void v7_outer_cache_disable(void)
79 /* Disable the L2 cache */
80 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
83 void socfpga_pl310_clear(void)
85 u32 mask = 0xff, ena = 0;
89 /* Disable the L2 cache */
90 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
92 writel(0x0, &pl310->pl310_tag_latency_ctrl);
93 writel(0x10, &pl310->pl310_data_latency_ctrl);
95 /* enable BRESP, instruction and data prefetch, full line of zeroes */
96 setbits_le32(&pl310->pl310_aux_ctrl,
97 L310_AUX_CTRL_DATA_PREFETCH_MASK |
98 L310_AUX_CTRL_INST_PREFETCH_MASK |
99 L310_SHARED_ATT_OVERRIDE_ENABLE);
101 /* Enable the L2 cache */
102 ena = readl(&pl310->pl310_ctrl);
106 * Invalidate the PL310 L2 cache. Keep the invalidation code
107 * entirely in L1 I-cache to avoid any bus traffic through
128 : "+r"(mask), "+r"(ena)
129 : "r"(&pl310->pl310_inv_way),
130 "r"(&pl310->pl310_cache_sync), "r"(&pl310->pl310_ctrl)
133 /* Disable the L2 cache */
134 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
138 #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
139 defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
140 int overwrite_console(void)
147 /* add device descriptor to FPGA device table */
148 void socfpga_fpga_add(void *fpga_desc)
151 fpga_add(fpga_altera, fpga_desc);
155 int arch_cpu_init(void)
157 socfpga_get_managers_addr();
159 #ifdef CONFIG_HW_WATCHDOG
161 * In case the watchdog is enabled, make sure to (re-)configure it
162 * so that the defined timeout is valid. Otherwise the SPL (Perloader)
163 * timeout value is still active which might too short for Linux
169 * If the HW watchdog is NOT enabled, make sure it is not running,
170 * for example because it was enabled in the preloader. This might
171 * trigger a watchdog-triggered reboot of Linux kernel later.
172 * Toggle watchdog reset, so watchdog in not running state.
174 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
175 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
181 #ifndef CONFIG_SPL_BUILD
182 static int do_bridge(struct cmd_tbl *cmdtp, int flag, int argc,
185 unsigned int mask = ~0;
187 if (argc < 2 || argc > 3)
188 return CMD_RET_USAGE;
193 mask = simple_strtoul(argv[1], NULL, 16);
196 case 'e': /* Enable */
197 do_bridge_reset(1, mask);
199 case 'd': /* Disable */
200 do_bridge_reset(0, mask);
203 return CMD_RET_USAGE;
209 U_BOOT_CMD(bridge, 3, 1, do_bridge,
210 "SoCFPGA HPS FPGA bridge control",
211 "enable [mask] - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
212 "bridge disable [mask] - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
218 static int socfpga_get_base_addr(const char *compat, phys_addr_t *base)
220 const void *blob = gd->fdt_blob;
221 struct fdt_resource r;
225 node = fdt_node_offset_by_compatible(blob, -1, compat);
229 if (!fdtdec_get_is_enabled(blob, node))
232 ret = fdt_get_resource(blob, node, "reg", 0, &r);
236 *base = (phys_addr_t)r.start;
241 void socfpga_get_managers_addr(void)
245 ret = socfpga_get_base_addr("altr,rst-mgr", &socfpga_rstmgr_base);
249 ret = socfpga_get_base_addr("altr,sys-mgr", &socfpga_sysmgr_base);
253 #ifdef CONFIG_TARGET_SOCFPGA_AGILEX
254 ret = socfpga_get_base_addr("intel,agilex-clkmgr",
255 &socfpga_clkmgr_base);
257 ret = socfpga_get_base_addr("altr,clk-mgr", &socfpga_clkmgr_base);
263 phys_addr_t socfpga_get_rstmgr_addr(void)
265 return socfpga_rstmgr_base;
268 phys_addr_t socfpga_get_sysmgr_addr(void)
270 return socfpga_sysmgr_base;
273 phys_addr_t socfpga_get_clkmgr_addr(void)
275 return socfpga_clkmgr_base;