Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2016-2018 Intel Corporation <www.intel.com> |
| 4 | * |
| 5 | */ |
| 6 | |
Chee Hong Ang | 129df66 | 2020-12-24 18:21:06 +0800 | [diff] [blame] | 7 | #include <hang.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/reset_manager.h> |
Chee Hong Ang | 129df66 | 2020-12-24 18:21:06 +0800 | [diff] [blame] | 11 | #include <asm/arch/smc_api.h> |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 12 | #include <asm/arch/system_manager.h> |
| 13 | #include <dt-bindings/reset/altr,rst-mgr-s10.h> |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 14 | #include <linux/iopoll.h> |
Chee Hong Ang | 129df66 | 2020-12-24 18:21:06 +0800 | [diff] [blame] | 15 | #include <linux/intel-smc.h> |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 19 | /* Assert or de-assert SoCFPGA reset manager reset. */ |
| 20 | void socfpga_per_reset(u32 reset, int set) |
| 21 | { |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 22 | unsigned long reg; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 23 | |
| 24 | if (RSTMGR_BANK(reset) == 0) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 25 | reg = RSTMGR_SOC64_MPUMODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 26 | else if (RSTMGR_BANK(reset) == 1) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 27 | reg = RSTMGR_SOC64_PER0MODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 28 | else if (RSTMGR_BANK(reset) == 2) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 29 | reg = RSTMGR_SOC64_PER1MODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 30 | else if (RSTMGR_BANK(reset) == 3) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 31 | reg = RSTMGR_SOC64_BRGMODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 32 | else /* Invalid reset register, do nothing */ |
| 33 | return; |
| 34 | |
| 35 | if (set) |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 36 | setbits_le32(socfpga_get_rstmgr_addr() + reg, |
| 37 | 1 << RSTMGR_RESET(reset)); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 38 | else |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 39 | clrbits_le32(socfpga_get_rstmgr_addr() + reg, |
| 40 | 1 << RSTMGR_RESET(reset)); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /* |
| 44 | * Assert reset on every peripheral but L4WD0. |
| 45 | * Watchdog must be kept intact to prevent glitches |
| 46 | * and/or hangs. |
| 47 | */ |
| 48 | void 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 Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 54 | 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 Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void socfpga_bridges_reset(int enable) |
| 60 | { |
Chee Hong Ang | 129df66 | 2020-12-24 18:21:06 +0800 | [diff] [blame] | 61 | #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 Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 70 | u32 reg; |
| 71 | |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 72 | if (enable) { |
| 73 | /* clear idle request to all bridges */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 74 | setbits_le32(socfpga_get_sysmgr_addr() + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 75 | SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 76 | |
Ang, Chee Hong | fadf65b | 2019-05-03 01:19:08 -0700 | [diff] [blame] | 77 | /* Release all bridges from reset state */ |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 78 | clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST, |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 79 | ~0); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 80 | |
| 81 | /* Poll until all idleack to 0 */ |
Ariel D'Alessandro | 8557361 | 2022-04-12 10:31:35 -0300 | [diff] [blame] | 82 | read_poll_timeout(readl, reg, !reg, 1000, 300000, |
| 83 | socfpga_get_sysmgr_addr() + |
| 84 | SYSMGR_SOC64_NOC_IDLEACK); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 85 | } else { |
| 86 | /* set idle request to all bridges */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 87 | writel(~0, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 88 | socfpga_get_sysmgr_addr() + |
| 89 | SYSMGR_SOC64_NOC_IDLEREQ_SET); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 90 | |
| 91 | /* Enable the NOC timeout */ |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 92 | writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 93 | |
| 94 | /* Poll until all idleack to 1 */ |
Ariel D'Alessandro | 8557361 | 2022-04-12 10:31:35 -0300 | [diff] [blame] | 95 | read_poll_timeout(readl, reg, |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 96 | reg == (SYSMGR_NOC_H2F_MSK | |
| 97 | SYSMGR_NOC_LWH2F_MSK), |
Ariel D'Alessandro | 8557361 | 2022-04-12 10:31:35 -0300 | [diff] [blame] | 98 | 1000, 300000, |
| 99 | socfpga_get_sysmgr_addr() + |
| 100 | SYSMGR_SOC64_NOC_IDLEACK); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 101 | |
| 102 | /* Poll until all idlestatus to 1 */ |
Ariel D'Alessandro | 8557361 | 2022-04-12 10:31:35 -0300 | [diff] [blame] | 103 | read_poll_timeout(readl, reg, |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 104 | reg == (SYSMGR_NOC_H2F_MSK | |
| 105 | SYSMGR_NOC_LWH2F_MSK), |
Ariel D'Alessandro | 8557361 | 2022-04-12 10:31:35 -0300 | [diff] [blame] | 106 | 1000, 300000, |
| 107 | socfpga_get_sysmgr_addr() + |
| 108 | SYSMGR_SOC64_NOC_IDLESTATUS); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 109 | |
Ang, Chee Hong | fadf65b | 2019-05-03 01:19:08 -0700 | [diff] [blame] | 110 | /* Reset all bridges (except NOR DDR scheduler & F2S) */ |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 111 | setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST, |
Ang, Chee Hong | fadf65b | 2019-05-03 01:19:08 -0700 | [diff] [blame] | 112 | ~(RSTMGR_BRGMODRST_DDRSCH_MASK | |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 113 | RSTMGR_BRGMODRST_FPGA2SOC_MASK)); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 114 | |
| 115 | /* Disable NOC timeout */ |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 116 | writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 117 | } |
Chee Hong Ang | 129df66 | 2020-12-24 18:21:06 +0800 | [diff] [blame] | 118 | #endif |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 119 | } |
| 120 | |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 121 | /* |
Ley Foon Tan | 3e263c7 | 2019-03-22 01:24:04 +0800 | [diff] [blame] | 122 | * Return non-zero if the CPU has been warm reset |
| 123 | */ |
| 124 | int cpu_has_been_warmreset(void) |
| 125 | { |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 126 | return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) & |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 127 | RSTMGR_L4WD_MPU_WARMRESET_MASK; |
Ley Foon Tan | 3e263c7 | 2019-03-22 01:24:04 +0800 | [diff] [blame] | 128 | } |
Chee Hong Ang | 6cf193c | 2020-08-05 21:15:57 +0800 | [diff] [blame] | 129 | |
| 130 | void print_reset_info(void) |
| 131 | { |
| 132 | bool iswd; |
| 133 | int n; |
| 134 | u32 stat = cpu_has_been_warmreset(); |
| 135 | |
| 136 | printf("Reset state: %s%s", stat ? "Warm " : "Cold", |
| 137 | (stat & RSTMGR_STAT_SDMWARMRST) ? "[from SDM] " : ""); |
| 138 | |
| 139 | stat &= ~RSTMGR_STAT_SDMWARMRST; |
| 140 | if (!stat) { |
| 141 | puts("\n"); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | n = generic_ffs(stat) - 1; |
| 146 | iswd = (n >= RSTMGR_STAT_L4WD0RST_BITPOS); |
| 147 | printf("(Triggered by %s %d)\n", iswd ? "Watchdog" : "MPU", |
| 148 | iswd ? (n - RSTMGR_STAT_L4WD0RST_BITPOS) : |
| 149 | (n - RSTMGR_STAT_MPU0RST_BITPOS)); |
| 150 | } |