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