blob: e92de3d84eb854d77059f9d99bff00a5612a7a0d [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 Tanfed4c952019-11-08 10:38:19 +080021 reg = RSTMGR_S10_MPUMODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080022 else if (RSTMGR_BANK(reset) == 1)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080023 reg = RSTMGR_S10_PER0MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080024 else if (RSTMGR_BANK(reset) == 2)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080025 reg = RSTMGR_S10_PER1MODRST;
Ley Foon Tan449cbae2018-05-18 22:05:23 +080026 else if (RSTMGR_BANK(reset) == 3)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080027 reg = RSTMGR_S10_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 Tanfed4c952019-11-08 10:38:19 +080050 socfpga_get_rstmgr_addr() + RSTMGR_S10_PER0MODRST);
51 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_S10_PER0MODRST);
52 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_S10_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() +
60 SYSMGR_S10_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 Tanfed4c952019-11-08 10:38:19 +080063 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_S10_BRGMODRST,
64 ~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() +
68 SYSMGR_S10_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,
73 socfpga_get_sysmgr_addr() + SYSMGR_S10_NOC_IDLEREQ_SET);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080074
75 /* Enable the NOC timeout */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080076 writel(1, socfpga_get_sysmgr_addr() + SYSMGR_S10_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080077
78 /* Poll until all idleack to 1 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080079 while ((readl(socfpga_get_sysmgr_addr() + SYSMGR_S10_NOC_IDLEACK) ^
Ley Foon Tan449cbae2018-05-18 22:05:23 +080080 (SYSMGR_NOC_H2F_MSK | SYSMGR_NOC_LWH2F_MSK)))
81 ;
82
83 /* Poll until all idlestatus to 1 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080084 while ((readl(socfpga_get_sysmgr_addr() + SYSMGR_S10_NOC_IDLESTATUS) ^
Ley Foon Tan449cbae2018-05-18 22:05:23 +080085 (SYSMGR_NOC_H2F_MSK | SYSMGR_NOC_LWH2F_MSK)))
86 ;
87
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070088 /* Reset all bridges (except NOR DDR scheduler & F2S) */
Ley Foon Tanfed4c952019-11-08 10:38:19 +080089 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_S10_BRGMODRST,
Ang, Chee Hongfadf65b2019-05-03 01:19:08 -070090 ~(RSTMGR_BRGMODRST_DDRSCH_MASK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +080091 RSTMGR_BRGMODRST_FPGA2SOC_MASK));
Ley Foon Tan449cbae2018-05-18 22:05:23 +080092
93 /* Disable NOC timeout */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080094 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_S10_NOC_TIMEOUT);
Ley Foon Tan449cbae2018-05-18 22:05:23 +080095 }
96}
97
Ley Foon Tan449cbae2018-05-18 22:05:23 +080098/*
Ley Foon Tan3e263c72019-03-22 01:24:04 +080099 * Return non-zero if the CPU has been warm reset
100 */
101int cpu_has_been_warmreset(void)
102{
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800103 return readl(socfpga_get_rstmgr_addr() + RSTMGR_S10_STATUS) &
104 RSTMGR_L4WD_MPU_WARMRESET_MASK;
Ley Foon Tan3e263c72019-03-22 01:24:04 +0800105}