blob: af8f2c0873104b96eb9c70f8949b7fbe74e3c997 [file] [log] [blame]
Ley Foon Tan449cbae2018-05-18 22:05:23 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
4 *
5 */
6
7#include <common.h>
Chee Hong Ang129df662020-12-24 18:21:06 +08008#include <hang.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +08009#include <asm/io.h>
10#include <asm/arch/reset_manager.h>
Chee Hong Ang129df662020-12-24 18:21:06 +080011#include <asm/arch/smc_api.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +080012#include <asm/arch/system_manager.h>
13#include <dt-bindings/reset/altr,rst-mgr-s10.h>
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080014#include <linux/iopoll.h>
Chee Hong Ang129df662020-12-24 18:21:06 +080015#include <linux/intel-smc.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +080016
17DECLARE_GLOBAL_DATA_PTR;
18
Ley Foon Tan449cbae2018-05-18 22:05:23 +080019/* Assert or de-assert SoCFPGA reset manager reset. */
20void socfpga_per_reset(u32 reset, int set)
21{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080022 unsigned long reg;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080023
24 if (RSTMGR_BANK(reset) == 0)
Ley Foon Tan89700b42019-11-27 15:55:16 +080025 reg = RSTMGR_SOC64_MPUMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080026 else if (RSTMGR_BANK(reset) == 1)
Ley Foon Tan89700b42019-11-27 15:55:16 +080027 reg = RSTMGR_SOC64_PER0MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080028 else if (RSTMGR_BANK(reset) == 2)
Ley Foon Tan89700b42019-11-27 15:55:16 +080029 reg = RSTMGR_SOC64_PER1MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080030 else if (RSTMGR_BANK(reset) == 3)
Ley Foon Tan89700b42019-11-27 15:55:16 +080031 reg = RSTMGR_SOC64_BRGMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080032 else /* Invalid reset register, do nothing */
33 return;
34
35 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080036 setbits_le32(socfpga_get_rstmgr_addr() + reg,
37 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080038 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080039 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
40 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080041}
42
43/*
44 * Assert reset on every peripheral but L4WD0.
45 * Watchdog must be kept intact to prevent glitches
46 * and/or hangs.
47 */
48void socfpga_per_reset_all(void)
49{
50 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
51
52 /* disable all except OCP and l4wd0. OCP disable later */
53 writel(~(l4wd0 | RSTMGR_PER0MODRST_OCP_MASK),
Ley Foon Tan89700b42019-11-27 15:55:16 +080054 socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
55 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
56 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER1MODRST);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080057}
58
59void socfpga_bridges_reset(int enable)
60{
Chee Hong Ang129df662020-12-24 18:21:06 +080061#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_ATF)
62 u64 arg = enable;
63
64 int ret = invoke_smc(INTEL_SIP_SMC_HPS_SET_BRIDGES, &arg, 1, NULL, 0);
65 if (ret) {
66 printf("SMC call failed with error %d in %s.\n", ret, __func__);
67 return;
68 }
69#else
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080070 u32 reg;
71
Ley Foon Tan449cbae2018-05-18 22:05:23 +080072 if (enable) {
73 /* clear idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080074 setbits_le32(socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080075 SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080076
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070077 /* Release all bridges from reset state */
Ley Foon Tan89700b42019-11-27 15:55:16 +080078 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ley Foon Tanfed4c952019-11-08 10:38:19 +080079 ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080080
81 /* Poll until all idleack to 0 */
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080082 read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
83 SYSMGR_SOC64_NOC_IDLEACK, reg, !reg, 1000,
84 300000);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080085 } else {
86 /* set idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080087 writel(~0,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080088 socfpga_get_sysmgr_addr() +
89 SYSMGR_SOC64_NOC_IDLEREQ_SET);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080090
91 /* Enable the NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080092 writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080093
94 /* Poll until all idleack to 1 */
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080095 read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
96 SYSMGR_SOC64_NOC_IDLEACK, reg,
97 reg == (SYSMGR_NOC_H2F_MSK |
98 SYSMGR_NOC_LWH2F_MSK),
99 1000, 300000);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800100
101 /* Poll until all idlestatus to 1 */
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +0800102 read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
103 SYSMGR_SOC64_NOC_IDLESTATUS, reg,
104 reg == (SYSMGR_NOC_H2F_MSK |
105 SYSMGR_NOC_LWH2F_MSK),
106 1000, 300000);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800107
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -0700108 /* Reset all bridges (except NOR DDR scheduler & F2S) */
Ley Foon Tan89700b42019-11-27 15:55:16 +0800109 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -0700110 ~(RSTMGR_BRGMODRST_DDRSCH_MASK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800111 RSTMGR_BRGMODRST_FPGA2SOC_MASK));
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800112
113 /* Disable NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +0800114 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800115 }
Chee Hong Ang129df662020-12-24 18:21:06 +0800116#endif
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800117}
118
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800119/*
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800120 * Return non-zero if the CPU has been warm reset
121 */
122int cpu_has_been_warmreset(void)
123{
Ley Foon Tan89700b42019-11-27 15:55:16 +0800124 return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) &
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800125 RSTMGR_L4WD_MPU_WARMRESET_MASK;
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800126}
Chee Hong Ang6cf193c2020-08-05 21:15:57 +0800127
128void print_reset_info(void)
129{
130 bool iswd;
131 int n;
132 u32 stat = cpu_has_been_warmreset();
133
134 printf("Reset state: %s%s", stat ? "Warm " : "Cold",
135 (stat & RSTMGR_STAT_SDMWARMRST) ? "[from SDM] " : "");
136
137 stat &= ~RSTMGR_STAT_SDMWARMRST;
138 if (!stat) {
139 puts("\n");
140 return;
141 }
142
143 n = generic_ffs(stat) - 1;
144 iswd = (n >= RSTMGR_STAT_L4WD0RST_BITPOS);
145 printf("(Triggered by %s %d)\n", iswd ? "Watchdog" : "MPU",
146 iswd ? (n - RSTMGR_STAT_L4WD0RST_BITPOS) :
147 (n - RSTMGR_STAT_MPU0RST_BITPOS));
148}