2018-05-18 14:05:23 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-12-24 10:21:06 +00:00
|
|
|
#include <hang.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-05-18 14:05:23 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/reset_manager.h>
|
2020-12-24 10:21:06 +00:00
|
|
|
#include <asm/arch/smc_api.h>
|
2018-05-18 14:05:23 +00:00
|
|
|
#include <asm/arch/system_manager.h>
|
|
|
|
#include <dt-bindings/reset/altr,rst-mgr-s10.h>
|
2020-08-10 14:59:49 +00:00
|
|
|
#include <linux/iopoll.h>
|
2020-12-24 10:21:06 +00:00
|
|
|
#include <linux/intel-smc.h>
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/* Assert or de-assert SoCFPGA reset manager reset. */
|
|
|
|
void socfpga_per_reset(u32 reset, int set)
|
|
|
|
{
|
2019-11-08 02:38:19 +00:00
|
|
|
unsigned long reg;
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
if (RSTMGR_BANK(reset) == 0)
|
2019-11-27 07:55:16 +00:00
|
|
|
reg = RSTMGR_SOC64_MPUMODRST;
|
2018-05-18 14:05:23 +00:00
|
|
|
else if (RSTMGR_BANK(reset) == 1)
|
2019-11-27 07:55:16 +00:00
|
|
|
reg = RSTMGR_SOC64_PER0MODRST;
|
2018-05-18 14:05:23 +00:00
|
|
|
else if (RSTMGR_BANK(reset) == 2)
|
2019-11-27 07:55:16 +00:00
|
|
|
reg = RSTMGR_SOC64_PER1MODRST;
|
2018-05-18 14:05:23 +00:00
|
|
|
else if (RSTMGR_BANK(reset) == 3)
|
2019-11-27 07:55:16 +00:00
|
|
|
reg = RSTMGR_SOC64_BRGMODRST;
|
2018-05-18 14:05:23 +00:00
|
|
|
else /* Invalid reset register, do nothing */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (set)
|
2019-11-08 02:38:19 +00:00
|
|
|
setbits_le32(socfpga_get_rstmgr_addr() + reg,
|
|
|
|
1 << RSTMGR_RESET(reset));
|
2018-05-18 14:05:23 +00:00
|
|
|
else
|
2019-11-08 02:38:19 +00:00
|
|
|
clrbits_le32(socfpga_get_rstmgr_addr() + reg,
|
|
|
|
1 << RSTMGR_RESET(reset));
|
2018-05-18 14:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assert reset on every peripheral but L4WD0.
|
|
|
|
* Watchdog must be kept intact to prevent glitches
|
|
|
|
* and/or hangs.
|
|
|
|
*/
|
|
|
|
void socfpga_per_reset_all(void)
|
|
|
|
{
|
|
|
|
const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
|
|
|
|
|
|
|
|
/* disable all except OCP and l4wd0. OCP disable later */
|
|
|
|
writel(~(l4wd0 | RSTMGR_PER0MODRST_OCP_MASK),
|
2019-11-27 07:55:16 +00:00
|
|
|
socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
|
|
|
|
writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
|
|
|
|
writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER1MODRST);
|
2018-05-18 14:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void socfpga_bridges_reset(int enable)
|
|
|
|
{
|
2020-12-24 10:21:06 +00:00
|
|
|
#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_ATF)
|
|
|
|
u64 arg = enable;
|
|
|
|
|
|
|
|
int ret = invoke_smc(INTEL_SIP_SMC_HPS_SET_BRIDGES, &arg, 1, NULL, 0);
|
|
|
|
if (ret) {
|
|
|
|
printf("SMC call failed with error %d in %s.\n", ret, __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
2020-08-10 14:59:49 +00:00
|
|
|
u32 reg;
|
|
|
|
|
2018-05-18 14:05:23 +00:00
|
|
|
if (enable) {
|
|
|
|
/* clear idle request to all bridges */
|
2019-11-08 02:38:20 +00:00
|
|
|
setbits_le32(socfpga_get_sysmgr_addr() +
|
2019-11-27 07:55:18 +00:00
|
|
|
SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0);
|
2018-05-18 14:05:23 +00:00
|
|
|
|
2019-05-03 08:19:08 +00:00
|
|
|
/* Release all bridges from reset state */
|
2019-11-27 07:55:16 +00:00
|
|
|
clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
|
2019-11-08 02:38:19 +00:00
|
|
|
~0);
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
/* Poll until all idleack to 0 */
|
2020-08-10 14:59:49 +00:00
|
|
|
read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
|
|
|
|
SYSMGR_SOC64_NOC_IDLEACK, reg, !reg, 1000,
|
|
|
|
300000);
|
2018-05-18 14:05:23 +00:00
|
|
|
} else {
|
|
|
|
/* set idle request to all bridges */
|
2019-11-08 02:38:20 +00:00
|
|
|
writel(~0,
|
2019-11-27 07:55:18 +00:00
|
|
|
socfpga_get_sysmgr_addr() +
|
|
|
|
SYSMGR_SOC64_NOC_IDLEREQ_SET);
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
/* Enable the NOC timeout */
|
2019-11-27 07:55:18 +00:00
|
|
|
writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
/* Poll until all idleack to 1 */
|
2020-08-10 14:59:49 +00:00
|
|
|
read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
|
|
|
|
SYSMGR_SOC64_NOC_IDLEACK, reg,
|
|
|
|
reg == (SYSMGR_NOC_H2F_MSK |
|
|
|
|
SYSMGR_NOC_LWH2F_MSK),
|
|
|
|
1000, 300000);
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
/* Poll until all idlestatus to 1 */
|
2020-08-10 14:59:49 +00:00
|
|
|
read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
|
|
|
|
SYSMGR_SOC64_NOC_IDLESTATUS, reg,
|
|
|
|
reg == (SYSMGR_NOC_H2F_MSK |
|
|
|
|
SYSMGR_NOC_LWH2F_MSK),
|
|
|
|
1000, 300000);
|
2018-05-18 14:05:23 +00:00
|
|
|
|
2019-05-03 08:19:08 +00:00
|
|
|
/* Reset all bridges (except NOR DDR scheduler & F2S) */
|
2019-11-27 07:55:16 +00:00
|
|
|
setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
|
2019-05-03 08:19:08 +00:00
|
|
|
~(RSTMGR_BRGMODRST_DDRSCH_MASK |
|
2019-11-08 02:38:19 +00:00
|
|
|
RSTMGR_BRGMODRST_FPGA2SOC_MASK));
|
2018-05-18 14:05:23 +00:00
|
|
|
|
|
|
|
/* Disable NOC timeout */
|
2019-11-27 07:55:18 +00:00
|
|
|
writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
|
2018-05-18 14:05:23 +00:00
|
|
|
}
|
2020-12-24 10:21:06 +00:00
|
|
|
#endif
|
2018-05-18 14:05:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 17:24:04 +00:00
|
|
|
/*
|
|
|
|
* Return non-zero if the CPU has been warm reset
|
|
|
|
*/
|
|
|
|
int cpu_has_been_warmreset(void)
|
|
|
|
{
|
2019-11-27 07:55:16 +00:00
|
|
|
return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) &
|
2019-11-08 02:38:19 +00:00
|
|
|
RSTMGR_L4WD_MPU_WARMRESET_MASK;
|
2019-03-21 17:24:04 +00:00
|
|
|
}
|
2020-08-05 13:15:57 +00:00
|
|
|
|
|
|
|
void print_reset_info(void)
|
|
|
|
{
|
|
|
|
bool iswd;
|
|
|
|
int n;
|
|
|
|
u32 stat = cpu_has_been_warmreset();
|
|
|
|
|
|
|
|
printf("Reset state: %s%s", stat ? "Warm " : "Cold",
|
|
|
|
(stat & RSTMGR_STAT_SDMWARMRST) ? "[from SDM] " : "");
|
|
|
|
|
|
|
|
stat &= ~RSTMGR_STAT_SDMWARMRST;
|
|
|
|
if (!stat) {
|
|
|
|
puts("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = generic_ffs(stat) - 1;
|
|
|
|
iswd = (n >= RSTMGR_STAT_L4WD0RST_BITPOS);
|
|
|
|
printf("(Triggered by %s %d)\n", iswd ? "Watchdog" : "MPU",
|
|
|
|
iswd ? (n - RSTMGR_STAT_L4WD0RST_BITPOS) :
|
|
|
|
(n - RSTMGR_STAT_MPU0RST_BITPOS));
|
|
|
|
}
|