blob: 9f16bf92d5effdc0973b54d8287793a1b9c64d9e [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>
8#include <asm/io.h>
9#include <asm/arch/reset_manager.h>
10#include <asm/arch/system_manager.h>
11#include <dt-bindings/reset/altr,rst-mgr-s10.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
Ley Foon Tan449cbae2018-05-18 22:05:23 +080015/* Assert or de-assert SoCFPGA reset manager reset. */
16void socfpga_per_reset(u32 reset, int set)
17{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080018 unsigned long reg;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080019
20 if (RSTMGR_BANK(reset) == 0)
Ley Foon Tan89700b42019-11-27 15:55:16 +080021 reg = RSTMGR_SOC64_MPUMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080022 else if (RSTMGR_BANK(reset) == 1)
Ley Foon Tan89700b42019-11-27 15:55:16 +080023 reg = RSTMGR_SOC64_PER0MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080024 else if (RSTMGR_BANK(reset) == 2)
Ley Foon Tan89700b42019-11-27 15:55:16 +080025 reg = RSTMGR_SOC64_PER1MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080026 else if (RSTMGR_BANK(reset) == 3)
Ley Foon Tan89700b42019-11-27 15:55:16 +080027 reg = RSTMGR_SOC64_BRGMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080028 else /* Invalid reset register, do nothing */
29 return;
30
31 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080032 setbits_le32(socfpga_get_rstmgr_addr() + reg,
33 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080034 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080035 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
36 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080037}
38
39/*
40 * Assert reset on every peripheral but L4WD0.
41 * Watchdog must be kept intact to prevent glitches
42 * and/or hangs.
43 */
44void socfpga_per_reset_all(void)
45{
46 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
47
48 /* disable all except OCP and l4wd0. OCP disable later */
49 writel(~(l4wd0 | RSTMGR_PER0MODRST_OCP_MASK),
Ley Foon Tan89700b42019-11-27 15:55:16 +080050 socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
51 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
52 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER1MODRST);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080053}
54
55void socfpga_bridges_reset(int enable)
56{
57 if (enable) {
58 /* clear idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080059 setbits_le32(socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080060 SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080061
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070062 /* Release all bridges from reset state */
Ley Foon Tan89700b42019-11-27 15:55:16 +080063 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ley Foon Tanfed4c952019-11-08 10:38:19 +080064 ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080065
66 /* Poll until all idleack to 0 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080067 while (readl(socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080068 SYSMGR_SOC64_NOC_IDLEACK))
Ley Foon Tan449cbae2018-05-18 22:05:23 +080069 ;
70 } else {
71 /* set idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080072 writel(~0,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080073 socfpga_get_sysmgr_addr() +
74 SYSMGR_SOC64_NOC_IDLEREQ_SET);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080075
76 /* Enable the NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080077 writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080078
79 /* Poll until all idleack to 1 */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080080 while ((readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_IDLEACK) ^
Ley Foon Tan449cbae2018-05-18 22:05:23 +080081 (SYSMGR_NOC_H2F_MSK | SYSMGR_NOC_LWH2F_MSK)))
82 ;
83
84 /* Poll until all idlestatus to 1 */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080085 while ((readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_IDLESTATUS) ^
Ley Foon Tan449cbae2018-05-18 22:05:23 +080086 (SYSMGR_NOC_H2F_MSK | SYSMGR_NOC_LWH2F_MSK)))
87 ;
88
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070089 /* Reset all bridges (except NOR DDR scheduler & F2S) */
Ley Foon Tan89700b42019-11-27 15:55:16 +080090 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070091 ~(RSTMGR_BRGMODRST_DDRSCH_MASK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +080092 RSTMGR_BRGMODRST_FPGA2SOC_MASK));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080093
94 /* Disable NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080095 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080096 }
97}
98
Ley Foon Tan449cbae2018-05-18 22:05:23 +080099/*
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800100 * Return non-zero if the CPU has been warm reset
101 */
102int cpu_has_been_warmreset(void)
103{
Ley Foon Tan89700b42019-11-27 15:55:16 +0800104 return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) &
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800105 RSTMGR_L4WD_MPU_WARMRESET_MASK;
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800106}
Chee Hong Ang6cf193c2020-08-05 21:15:57 +0800107
108void print_reset_info(void)
109{
110 bool iswd;
111 int n;
112 u32 stat = cpu_has_been_warmreset();
113
114 printf("Reset state: %s%s", stat ? "Warm " : "Cold",
115 (stat & RSTMGR_STAT_SDMWARMRST) ? "[from SDM] " : "");
116
117 stat &= ~RSTMGR_STAT_SDMWARMRST;
118 if (!stat) {
119 puts("\n");
120 return;
121 }
122
123 n = generic_ffs(stat) - 1;
124 iswd = (n >= RSTMGR_STAT_L4WD0RST_BITPOS);
125 printf("(Triggered by %s %d)\n", iswd ? "Watchdog" : "MPU",
126 iswd ? (n - RSTMGR_STAT_L4WD0RST_BITPOS) :
127 (n - RSTMGR_STAT_MPU0RST_BITPOS));
128}