2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-10-04 06:46:02 +00:00
|
|
|
/*
|
2017-04-25 18:44:36 +00:00
|
|
|
* Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
|
2012-10-04 06:46:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2019-11-14 19:57:37 +00:00
|
|
|
#include <cpu_func.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2012-10-04 06:46:02 +00:00
|
|
|
#include <asm/io.h>
|
2015-08-01 01:42:10 +00:00
|
|
|
#include <errno.h>
|
2015-07-25 17:33:56 +00:00
|
|
|
#include <fdtdec.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2014-09-08 12:08:45 +00:00
|
|
|
#include <altera.h>
|
2014-07-14 12:14:17 +00:00
|
|
|
#include <miiphy.h>
|
|
|
|
#include <netdev.h>
|
2014-12-19 12:49:10 +00:00
|
|
|
#include <watchdog.h>
|
2017-04-25 18:44:36 +00:00
|
|
|
#include <asm/arch/misc.h>
|
2014-09-09 12:03:28 +00:00
|
|
|
#include <asm/arch/reset_manager.h>
|
2015-08-01 01:42:10 +00:00
|
|
|
#include <asm/arch/scan_manager.h>
|
2014-09-08 12:08:45 +00:00
|
|
|
#include <asm/arch/system_manager.h>
|
2014-09-15 01:58:22 +00:00
|
|
|
#include <asm/arch/nic301.h>
|
2014-09-08 12:08:45 +00:00
|
|
|
#include <asm/arch/scu.h>
|
2014-09-15 01:58:22 +00:00
|
|
|
#include <asm/pl310.h>
|
2012-10-04 06:46:02 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2019-11-08 02:38:21 +00:00
|
|
|
phys_addr_t socfpga_clkmgr_base __section(".data");
|
2019-11-08 02:38:19 +00:00
|
|
|
phys_addr_t socfpga_rstmgr_base __section(".data");
|
2019-11-08 02:38:20 +00:00
|
|
|
phys_addr_t socfpga_sysmgr_base __section(".data");
|
2019-11-08 02:38:19 +00:00
|
|
|
|
2018-05-18 14:05:25 +00:00
|
|
|
#ifdef CONFIG_SYS_L2_PL310
|
2017-04-25 18:44:36 +00:00
|
|
|
static const struct pl310_regs *const pl310 =
|
2014-09-15 01:58:22 +00:00
|
|
|
(struct pl310_regs *)CONFIG_SYS_PL310_BASE;
|
2018-05-18 14:05:25 +00:00
|
|
|
#endif
|
2017-04-25 18:44:36 +00:00
|
|
|
|
|
|
|
struct bsel bsel_str[] = {
|
|
|
|
{ "rsvd", "Reserved", },
|
|
|
|
{ "fpga", "FPGA (HPS2FPGA Bridge)", },
|
|
|
|
{ "nand", "NAND Flash (1.8V)", },
|
|
|
|
{ "nand", "NAND Flash (3.0V)", },
|
|
|
|
{ "sd", "SD/MMC External Transceiver (1.8V)", },
|
|
|
|
{ "sd", "SD/MMC Internal Transceiver (3.0V)", },
|
|
|
|
{ "qspi", "QSPI Flash (1.8V)", },
|
|
|
|
{ "qspi", "QSPI Flash (3.0V)", },
|
|
|
|
};
|
2014-09-08 12:08:45 +00:00
|
|
|
|
2012-10-04 06:46:02 +00:00
|
|
|
int dram_init(void)
|
|
|
|
{
|
2018-07-16 10:26:11 +00:00
|
|
|
if (fdtdec_setup_mem_size_base() != 0)
|
2018-05-28 15:09:45 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-10-04 06:46:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-06-10 07:23:45 +00:00
|
|
|
|
2014-09-21 11:57:40 +00:00
|
|
|
void enable_caches(void)
|
|
|
|
{
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
|
2014-09-21 11:57:40 +00:00
|
|
|
icache_enable();
|
|
|
|
#endif
|
2019-05-03 13:41:00 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
|
2014-09-21 11:57:40 +00:00
|
|
|
dcache_enable();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-18 14:05:25 +00:00
|
|
|
#ifdef CONFIG_SYS_L2_PL310
|
2015-10-15 15:13:36 +00:00
|
|
|
void v7_outer_cache_enable(void)
|
|
|
|
{
|
2019-04-23 21:55:05 +00:00
|
|
|
struct udevice *dev;
|
2015-12-20 03:00:09 +00:00
|
|
|
|
2019-04-23 21:55:05 +00:00
|
|
|
if (uclass_get_device(UCLASS_CACHE, 0, &dev))
|
|
|
|
pr_err("cache controller driver NOT found!\n");
|
2015-12-20 03:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void v7_outer_cache_disable(void)
|
|
|
|
{
|
|
|
|
/* Disable the L2 cache */
|
|
|
|
clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
|
2015-10-15 15:13:36 +00:00
|
|
|
}
|
2019-03-21 22:05:38 +00:00
|
|
|
|
|
|
|
void socfpga_pl310_clear(void)
|
|
|
|
{
|
|
|
|
u32 mask = 0xff, ena = 0;
|
|
|
|
|
|
|
|
icache_enable();
|
|
|
|
|
|
|
|
/* Disable the L2 cache */
|
|
|
|
clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
|
|
|
|
|
|
|
|
writel(0x0, &pl310->pl310_tag_latency_ctrl);
|
|
|
|
writel(0x10, &pl310->pl310_data_latency_ctrl);
|
|
|
|
|
|
|
|
/* enable BRESP, instruction and data prefetch, full line of zeroes */
|
|
|
|
setbits_le32(&pl310->pl310_aux_ctrl,
|
|
|
|
L310_AUX_CTRL_DATA_PREFETCH_MASK |
|
|
|
|
L310_AUX_CTRL_INST_PREFETCH_MASK |
|
|
|
|
L310_SHARED_ATT_OVERRIDE_ENABLE);
|
|
|
|
|
|
|
|
/* Enable the L2 cache */
|
|
|
|
ena = readl(&pl310->pl310_ctrl);
|
|
|
|
ena |= L2X0_CTRL_EN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Invalidate the PL310 L2 cache. Keep the invalidation code
|
|
|
|
* entirely in L1 I-cache to avoid any bus traffic through
|
|
|
|
* the L2.
|
|
|
|
*/
|
|
|
|
asm volatile(
|
|
|
|
".align 5 \n"
|
|
|
|
" b 3f \n"
|
|
|
|
"1: str %1, [%4] \n"
|
|
|
|
" dsb \n"
|
|
|
|
" isb \n"
|
|
|
|
" str %0, [%2] \n"
|
|
|
|
" dsb \n"
|
|
|
|
" isb \n"
|
|
|
|
"2: ldr %0, [%2] \n"
|
|
|
|
" cmp %0, #0 \n"
|
|
|
|
" bne 2b \n"
|
|
|
|
" str %0, [%3] \n"
|
|
|
|
" dsb \n"
|
|
|
|
" isb \n"
|
|
|
|
" b 4f \n"
|
|
|
|
"3: b 1b \n"
|
|
|
|
"4: nop \n"
|
|
|
|
: "+r"(mask), "+r"(ena)
|
|
|
|
: "r"(&pl310->pl310_inv_way),
|
|
|
|
"r"(&pl310->pl310_cache_sync), "r"(&pl310->pl310_ctrl)
|
|
|
|
: "memory", "cc");
|
|
|
|
|
|
|
|
/* Disable the L2 cache */
|
|
|
|
clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
|
|
|
|
}
|
2018-05-18 14:05:25 +00:00
|
|
|
#endif
|
2015-10-15 15:13:36 +00:00
|
|
|
|
2014-06-10 07:23:45 +00:00
|
|
|
#if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
|
|
|
|
defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
|
|
|
|
int overwrite_console(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-08 12:08:45 +00:00
|
|
|
#ifdef CONFIG_FPGA
|
|
|
|
/* add device descriptor to FPGA device table */
|
2018-12-20 02:35:15 +00:00
|
|
|
void socfpga_fpga_add(void *fpga_desc)
|
2014-09-08 12:08:45 +00:00
|
|
|
{
|
|
|
|
fpga_init();
|
2018-12-20 02:35:15 +00:00
|
|
|
fpga_add(fpga_altera, fpga_desc);
|
2014-09-08 12:08:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-09 12:03:28 +00:00
|
|
|
int arch_cpu_init(void)
|
|
|
|
{
|
2019-11-08 02:38:19 +00:00
|
|
|
socfpga_get_managers_addr();
|
|
|
|
|
2014-12-19 12:49:10 +00:00
|
|
|
#ifdef CONFIG_HW_WATCHDOG
|
|
|
|
/*
|
|
|
|
* In case the watchdog is enabled, make sure to (re-)configure it
|
|
|
|
* so that the defined timeout is valid. Otherwise the SPL (Perloader)
|
|
|
|
* timeout value is still active which might too short for Linux
|
|
|
|
* booting.
|
|
|
|
*/
|
|
|
|
hw_watchdog_init();
|
|
|
|
#else
|
2014-09-09 12:03:28 +00:00
|
|
|
/*
|
|
|
|
* If the HW watchdog is NOT enabled, make sure it is not running,
|
|
|
|
* for example because it was enabled in the preloader. This might
|
|
|
|
* trigger a watchdog-triggered reboot of Linux kernel later.
|
2015-07-09 00:51:56 +00:00
|
|
|
* Toggle watchdog reset, so watchdog in not running state.
|
2014-09-09 12:03:28 +00:00
|
|
|
*/
|
2015-07-09 00:51:56 +00:00
|
|
|
socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
|
|
|
|
socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
|
2014-09-09 12:03:28 +00:00
|
|
|
#endif
|
2014-12-19 12:49:10 +00:00
|
|
|
|
2014-09-09 12:03:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-04-23 20:49:31 +00:00
|
|
|
|
2018-05-23 16:17:23 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_bridge(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2018-05-23 16:17:23 +00:00
|
|
|
{
|
2019-04-16 20:28:08 +00:00
|
|
|
unsigned int mask = ~0;
|
|
|
|
|
|
|
|
if (argc < 2 || argc > 3)
|
2018-05-23 16:17:23 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
argv++;
|
|
|
|
|
2019-04-16 20:28:08 +00:00
|
|
|
if (argc == 3)
|
2021-07-24 15:03:29 +00:00
|
|
|
mask = hextoul(argv[1], NULL);
|
2019-04-16 20:28:08 +00:00
|
|
|
|
2018-05-23 16:17:23 +00:00
|
|
|
switch (*argv[0]) {
|
|
|
|
case 'e': /* Enable */
|
2019-04-16 20:28:08 +00:00
|
|
|
do_bridge_reset(1, mask);
|
2018-05-23 16:17:23 +00:00
|
|
|
break;
|
|
|
|
case 'd': /* Disable */
|
2019-04-16 20:28:08 +00:00
|
|
|
do_bridge_reset(0, mask);
|
2018-05-23 16:17:23 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-16 20:28:08 +00:00
|
|
|
U_BOOT_CMD(bridge, 3, 1, do_bridge,
|
2018-05-23 16:17:30 +00:00
|
|
|
"SoCFPGA HPS FPGA bridge control",
|
2019-04-16 20:28:08 +00:00
|
|
|
"enable [mask] - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
|
|
|
|
"bridge disable [mask] - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
|
2018-05-23 16:17:30 +00:00
|
|
|
""
|
2018-05-23 16:17:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#endif
|
2019-11-08 02:38:19 +00:00
|
|
|
|
|
|
|
static int socfpga_get_base_addr(const char *compat, phys_addr_t *base)
|
|
|
|
{
|
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
struct fdt_resource r;
|
|
|
|
int node;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
node = fdt_node_offset_by_compatible(blob, -1, compat);
|
|
|
|
if (node < 0)
|
|
|
|
return node;
|
|
|
|
|
|
|
|
if (!fdtdec_get_is_enabled(blob, node))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = fdt_get_resource(blob, node, "reg", 0, &r);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*base = (phys_addr_t)r.start;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void socfpga_get_managers_addr(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = socfpga_get_base_addr("altr,rst-mgr", &socfpga_rstmgr_base);
|
|
|
|
if (ret)
|
|
|
|
hang();
|
2019-11-08 02:38:20 +00:00
|
|
|
|
|
|
|
ret = socfpga_get_base_addr("altr,sys-mgr", &socfpga_sysmgr_base);
|
|
|
|
if (ret)
|
|
|
|
hang();
|
2019-11-08 02:38:21 +00:00
|
|
|
|
2019-11-27 07:55:22 +00:00
|
|
|
#ifdef CONFIG_TARGET_SOCFPGA_AGILEX
|
|
|
|
ret = socfpga_get_base_addr("intel,agilex-clkmgr",
|
|
|
|
&socfpga_clkmgr_base);
|
2021-08-10 03:26:31 +00:00
|
|
|
#elif IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
|
|
|
|
ret = socfpga_get_base_addr("intel,n5x-clkmgr",
|
|
|
|
&socfpga_clkmgr_base);
|
2019-11-27 07:55:22 +00:00
|
|
|
#else
|
2019-11-08 02:38:21 +00:00
|
|
|
ret = socfpga_get_base_addr("altr,clk-mgr", &socfpga_clkmgr_base);
|
2019-11-27 07:55:22 +00:00
|
|
|
#endif
|
2019-11-08 02:38:21 +00:00
|
|
|
if (ret)
|
|
|
|
hang();
|
2019-11-08 02:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
phys_addr_t socfpga_get_rstmgr_addr(void)
|
|
|
|
{
|
|
|
|
return socfpga_rstmgr_base;
|
|
|
|
}
|
2019-11-08 02:38:20 +00:00
|
|
|
|
|
|
|
phys_addr_t socfpga_get_sysmgr_addr(void)
|
|
|
|
{
|
|
|
|
return socfpga_sysmgr_base;
|
|
|
|
}
|
2019-11-08 02:38:21 +00:00
|
|
|
|
|
|
|
phys_addr_t socfpga_get_clkmgr_addr(void)
|
|
|
|
{
|
|
|
|
return socfpga_clkmgr_base;
|
|
|
|
}
|