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 | |
| 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 Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 12 | #include <linux/iopoll.h> |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 16 | /* Assert or de-assert SoCFPGA reset manager reset. */ |
| 17 | void socfpga_per_reset(u32 reset, int set) |
| 18 | { |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 19 | unsigned long reg; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 20 | |
| 21 | if (RSTMGR_BANK(reset) == 0) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 22 | reg = RSTMGR_SOC64_MPUMODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 23 | else if (RSTMGR_BANK(reset) == 1) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 24 | reg = RSTMGR_SOC64_PER0MODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 25 | else if (RSTMGR_BANK(reset) == 2) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 26 | reg = RSTMGR_SOC64_PER1MODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 27 | else if (RSTMGR_BANK(reset) == 3) |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 28 | reg = RSTMGR_SOC64_BRGMODRST; |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 29 | else /* Invalid reset register, do nothing */ |
| 30 | return; |
| 31 | |
| 32 | if (set) |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 33 | setbits_le32(socfpga_get_rstmgr_addr() + reg, |
| 34 | 1 << RSTMGR_RESET(reset)); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 35 | else |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 36 | clrbits_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 | } |
| 39 | |
| 40 | /* |
| 41 | * Assert reset on every peripheral but L4WD0. |
| 42 | * Watchdog must be kept intact to prevent glitches |
| 43 | * and/or hangs. |
| 44 | */ |
| 45 | void 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 Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 51 | 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 Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void socfpga_bridges_reset(int enable) |
| 57 | { |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 58 | u32 reg; |
| 59 | |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 60 | if (enable) { |
| 61 | /* clear idle request to all bridges */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 62 | setbits_le32(socfpga_get_sysmgr_addr() + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 63 | SYSMGR_SOC64_NOC_IDLEREQ_CLR, ~0); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 64 | |
Ang, Chee Hong | fadf65b | 2019-05-03 01:19:08 -0700 | [diff] [blame] | 65 | /* Release all bridges from reset state */ |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 66 | clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST, |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 67 | ~0); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 68 | |
| 69 | /* Poll until all idleack to 0 */ |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 70 | read_poll_timeout(readl, socfpga_get_sysmgr_addr() + |
| 71 | SYSMGR_SOC64_NOC_IDLEACK, reg, !reg, 1000, |
| 72 | 300000); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 73 | } else { |
| 74 | /* set idle request to all bridges */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 75 | writel(~0, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 76 | socfpga_get_sysmgr_addr() + |
| 77 | SYSMGR_SOC64_NOC_IDLEREQ_SET); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 78 | |
| 79 | /* Enable the NOC timeout */ |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 80 | writel(1, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 81 | |
| 82 | /* Poll until all idleack to 1 */ |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 83 | 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 Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 88 | |
| 89 | /* Poll until all idlestatus to 1 */ |
Chee Hong Ang | 1f9f0e3 | 2020-08-10 22:59:49 +0800 | [diff] [blame] | 90 | 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 Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 95 | |
Ang, Chee Hong | fadf65b | 2019-05-03 01:19:08 -0700 | [diff] [blame] | 96 | /* Reset all bridges (except NOR DDR scheduler & F2S) */ |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 97 | setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_BRGMODRST, |
Ang, Chee Hong | fadf65b | 2019-05-03 01:19:08 -0700 | [diff] [blame] | 98 | ~(RSTMGR_BRGMODRST_DDRSCH_MASK | |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 99 | RSTMGR_BRGMODRST_FPGA2SOC_MASK)); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 100 | |
| 101 | /* Disable NOC timeout */ |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 102 | writel(0, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NOC_TIMEOUT); |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Ley Foon Tan | 449cbae | 2018-05-18 22:05:23 +0800 | [diff] [blame] | 106 | /* |
Ley Foon Tan | 3e263c7 | 2019-03-22 01:24:04 +0800 | [diff] [blame] | 107 | * Return non-zero if the CPU has been warm reset |
| 108 | */ |
| 109 | int cpu_has_been_warmreset(void) |
| 110 | { |
Ley Foon Tan | 89700b4 | 2019-11-27 15:55:16 +0800 | [diff] [blame] | 111 | return readl(socfpga_get_rstmgr_addr() + RSTMGR_SOC64_STATUS) & |
Ley Foon Tan | fed4c95 | 2019-11-08 10:38:19 +0800 | [diff] [blame] | 112 | RSTMGR_L4WD_MPU_WARMRESET_MASK; |
Ley Foon Tan | 3e263c7 | 2019-03-22 01:24:04 +0800 | [diff] [blame] | 113 | } |
Chee Hong Ang | 6cf193c | 2020-08-05 21:15:57 +0800 | [diff] [blame] | 114 | |
| 115 | void 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 | } |