blob: f47fec10a0c6b24d8b73addf0269b2bccaedcf94 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +080010#include <asm/io.h>
11#include <asm/arch/reset_manager.h>
Chee Hong Ang129df662020-12-24 18:21:06 +080012#include <asm/arch/smc_api.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +080013#include <asm/arch/system_manager.h>
14#include <dt-bindings/reset/altr,rst-mgr-s10.h>
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080015#include <linux/iopoll.h>
Chee Hong Ang129df662020-12-24 18:21:06 +080016#include <linux/intel-smc.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +080017
18DECLARE_GLOBAL_DATA_PTR;
19
Ley Foon Tan449cbae2018-05-18 22:05:23 +080020/* Assert or de-assert SoCFPGA reset manager reset. */
21void socfpga_per_reset(u32 reset, int set)
22{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080023 unsigned long reg;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080024
25 if (RSTMGR_BANK(reset) == 0)
Ley Foon Tan89700b42019-11-27 15:55:16 +080026 reg = RSTMGR_SOC64_MPUMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080027 else if (RSTMGR_BANK(reset) == 1)
Ley Foon Tan89700b42019-11-27 15:55:16 +080028 reg = RSTMGR_SOC64_PER0MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080029 else if (RSTMGR_BANK(reset) == 2)
Ley Foon Tan89700b42019-11-27 15:55:16 +080030 reg = RSTMGR_SOC64_PER1MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080031 else if (RSTMGR_BANK(reset) == 3)
Ley Foon Tan89700b42019-11-27 15:55:16 +080032 reg = RSTMGR_SOC64_BRGMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080033 else /* Invalid reset register, do nothing */
34 return;
35
36 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080037 setbits_le32(socfpga_get_rstmgr_addr() + reg,
38 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080039 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080040 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
41 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080042}
43
44/*
45 * Assert reset on every peripheral but L4WD0.
46 * Watchdog must be kept intact to prevent glitches
47 * and/or hangs.
48 */
49void socfpga_per_reset_all(void)
50{
51 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
52
53 /* disable all except OCP and l4wd0. OCP disable later */
54 writel(~(l4wd0 | RSTMGR_PER0MODRST_OCP_MASK),
Ley Foon Tan89700b42019-11-27 15:55:16 +080055 socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
56 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
57 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER1MODRST);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080058}
59
60void socfpga_bridges_reset(int enable)
61{
Chee Hong Ang129df662020-12-24 18:21:06 +080062#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_ATF)
63 u64 arg = enable;
64
65 int ret = invoke_smc(INTEL_SIP_SMC_HPS_SET_BRIDGES, &arg, 1, NULL, 0);
66 if (ret) {
67 printf("SMC call failed with error %d in %s.\n", ret, __func__);
68 return;
69 }
70#else
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080071 u32 reg;
72
Ley Foon Tan449cbae2018-05-18 22:05:23 +080073 if (enable) {
74 /* clear idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080075 setbits_le32(socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080076 SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080077
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070078 /* Release all bridges from reset state */
Ley Foon Tan89700b42019-11-27 15:55:16 +080079 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ley Foon Tanfed4c952019-11-08 10:38:19 +080080 ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080081
82 /* Poll until all idleack to 0 */
Ariel D'Alessandro85573612022-04-12 10:31:35 -030083 read_poll_timeout(readl, reg, !reg, 1000, 300000,
84 socfpga_get_sysmgr_addr() +
85 SYSMGR_SOC64_NOC_IDLEACK);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080086 } else {
87 /* set idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080088 writel(~0,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080089 socfpga_get_sysmgr_addr() +
90 SYSMGR_SOC64_NOC_IDLEREQ_SET);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080091
92 /* Enable the NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080093 writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080094
95 /* Poll until all idleack to 1 */
Ariel D'Alessandro85573612022-04-12 10:31:35 -030096 read_poll_timeout(readl, reg,
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080097 reg == (SYSMGR_NOC_H2F_MSK |
98 SYSMGR_NOC_LWH2F_MSK),
Ariel D'Alessandro85573612022-04-12 10:31:35 -030099 1000, 300000,
100 socfpga_get_sysmgr_addr() +
101 SYSMGR_SOC64_NOC_IDLEACK);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800102
103 /* Poll until all idlestatus to 1 */
Ariel D'Alessandro85573612022-04-12 10:31:35 -0300104 read_poll_timeout(readl, reg,
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +0800105 reg == (SYSMGR_NOC_H2F_MSK |
106 SYSMGR_NOC_LWH2F_MSK),
Ariel D'Alessandro85573612022-04-12 10:31:35 -0300107 1000, 300000,
108 socfpga_get_sysmgr_addr() +
109 SYSMGR_SOC64_NOC_IDLESTATUS);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800110
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -0700111 /* Reset all bridges (except NOR DDR scheduler & F2S) */
Ley Foon Tan89700b42019-11-27 15:55:16 +0800112 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -0700113 ~(RSTMGR_BRGMODRST_DDRSCH_MASK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800114 RSTMGR_BRGMODRST_FPGA2SOC_MASK));
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800115
116 /* Disable NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +0800117 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800118 }
Chee Hong Ang129df662020-12-24 18:21:06 +0800119#endif
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800120}
121
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800122/*
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800123 * Return non-zero if the CPU has been warm reset
124 */
125int cpu_has_been_warmreset(void)
126{
Ley Foon Tan89700b42019-11-27 15:55:16 +0800127 return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) &
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800128 RSTMGR_L4WD_MPU_WARMRESET_MASK;
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800129}
Chee Hong Ang6cf193c2020-08-05 21:15:57 +0800130
131void print_reset_info(void)
132{
133 bool iswd;
134 int n;
135 u32 stat = cpu_has_been_warmreset();
136
137 printf("Reset state: %s%s", stat ? "Warm " : "Cold",
138 (stat & RSTMGR_STAT_SDMWARMRST) ? "[from SDM] " : "");
139
140 stat &= ~RSTMGR_STAT_SDMWARMRST;
141 if (!stat) {
142 puts("\n");
143 return;
144 }
145
146 n = generic_ffs(stat) - 1;
147 iswd = (n >= RSTMGR_STAT_L4WD0RST_BITPOS);
148 printf("(Triggered by %s %d)\n", iswd ? "Watchdog" : "MPU",
149 iswd ? (n - RSTMGR_STAT_L4WD0RST_BITPOS) :
150 (n - RSTMGR_STAT_MPU0RST_BITPOS));
151}