blob: 3746e6a60c3c1188c177b758c8df958cee70fdf0 [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>
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080012#include <linux/iopoll.h>
Ley Foon Tan449cbae2018-05-18 22:05:23 +080013
14DECLARE_GLOBAL_DATA_PTR;
15
Ley Foon Tan449cbae2018-05-18 22:05:23 +080016/* Assert or de-assert SoCFPGA reset manager reset. */
17void socfpga_per_reset(u32 reset, int set)
18{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080019 unsigned long reg;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080020
21 if (RSTMGR_BANK(reset) == 0)
Ley Foon Tan89700b42019-11-27 15:55:16 +080022 reg = RSTMGR_SOC64_MPUMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080023 else if (RSTMGR_BANK(reset) == 1)
Ley Foon Tan89700b42019-11-27 15:55:16 +080024 reg = RSTMGR_SOC64_PER0MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080025 else if (RSTMGR_BANK(reset) == 2)
Ley Foon Tan89700b42019-11-27 15:55:16 +080026 reg = RSTMGR_SOC64_PER1MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080027 else if (RSTMGR_BANK(reset) == 3)
Ley Foon Tan89700b42019-11-27 15:55:16 +080028 reg = RSTMGR_SOC64_BRGMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080029 else /* Invalid reset register, do nothing */
30 return;
31
32 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080033 setbits_le32(socfpga_get_rstmgr_addr() + reg,
34 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080035 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080036 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
37 1 << RSTMGR_RESET(reset));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080038}
39
40/*
41 * Assert reset on every peripheral but L4WD0.
42 * Watchdog must be kept intact to prevent glitches
43 * and/or hangs.
44 */
45void socfpga_per_reset_all(void)
46{
47 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
48
49 /* disable all except OCP and l4wd0. OCP disable later */
50 writel(~(l4wd0 | RSTMGR_PER0MODRST_OCP_MASK),
Ley Foon Tan89700b42019-11-27 15:55:16 +080051 socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
52 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER0MODRST);
53 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_SOC64_PER1MODRST);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080054}
55
56void socfpga_bridges_reset(int enable)
57{
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080058 u32 reg;
59
Ley Foon Tan449cbae2018-05-18 22:05:23 +080060 if (enable) {
61 /* clear idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080062 setbits_le32(socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080063 SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080064
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070065 /* Release all bridges from reset state */
Ley Foon Tan89700b42019-11-27 15:55:16 +080066 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ley Foon Tanfed4c952019-11-08 10:38:19 +080067 ~0);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080068
69 /* Poll until all idleack to 0 */
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080070 read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
71 SYSMGR_SOC64_NOC_IDLEACK, reg, !reg, 1000,
72 300000);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080073 } else {
74 /* set idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080075 writel(~0,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080076 socfpga_get_sysmgr_addr() +
77 SYSMGR_SOC64_NOC_IDLEREQ_SET);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080078
79 /* Enable the NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080080 writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080081
82 /* Poll until all idleack to 1 */
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080083 read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
84 SYSMGR_SOC64_NOC_IDLEACK, reg,
85 reg == (SYSMGR_NOC_H2F_MSK |
86 SYSMGR_NOC_LWH2F_MSK),
87 1000, 300000);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080088
89 /* Poll until all idlestatus to 1 */
Chee Hong Ang1f9f0e32020-08-10 22:59:49 +080090 read_poll_timeout(readl, socfpga_get_sysmgr_addr() +
91 SYSMGR_SOC64_NOC_IDLESTATUS, reg,
92 reg == (SYSMGR_NOC_H2F_MSK |
93 SYSMGR_NOC_LWH2F_MSK),
94 1000, 300000);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080095
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070096 /* Reset all bridges (except NOR DDR scheduler & F2S) */
Ley Foon Tan89700b42019-11-27 15:55:16 +080097 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST,
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070098 ~(RSTMGR_BRGMODRST_DDRSCH_MASK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +080099 RSTMGR_BRGMODRST_FPGA2SOC_MASK));
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800100
101 /* Disable NOC timeout */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +0800102 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800103 }
104}
105
Ley Foon Tan449cbae2018-05-18 22:05:23 +0800106/*
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800107 * Return non-zero if the CPU has been warm reset
108 */
109int cpu_has_been_warmreset(void)
110{
Ley Foon Tan89700b42019-11-27 15:55:16 +0800111 return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) &
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800112 RSTMGR_L4WD_MPU_WARMRESET_MASK;
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800113}
Chee Hong Ang6cf193c2020-08-05 21:15:57 +0800114
115void print_reset_info(void)
116{
117 bool iswd;
118 int n;
119 u32 stat = cpu_has_been_warmreset();
120
121 printf("Reset state: %s%s", stat ? "Warm " : "Cold",
122 (stat & RSTMGR_STAT_SDMWARMRST) ? "[from SDM] " : "");
123
124 stat &= ~RSTMGR_STAT_SDMWARMRST;
125 if (!stat) {
126 puts("\n");
127 return;
128 }
129
130 n = generic_ffs(stat) - 1;
131 iswd = (n >= RSTMGR_STAT_L4WD0RST_BITPOS);
132 printf("(Triggered by %s %d)\n", iswd ? "Watchdog" : "MPU",
133 iswd ? (n - RSTMGR_STAT_L4WD0RST_BITPOS) :
134 (n - RSTMGR_STAT_MPU0RST_BITPOS));
135}