blob: 27c030801134e597efcc4bcab85d218f0fd17bce [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Ley Foon Tan778ed2c2017-04-26 02:44:38 +08002/*
3 * Copyright (C) 2016-2017 Intel Corporation
Ley Foon Tan778ed2c2017-04-26 02:44:38 +08004 */
5
Simon Glass3ba929a2020-10-30 21:38:53 -06006#include <asm/global_data.h>
Ley Foon Tan778ed2c2017-04-26 02:44:38 +08007#include <asm/io.h>
8#include <asm/arch/fpga_manager.h>
9#include <asm/arch/misc.h>
10#include <asm/arch/reset_manager.h>
11#include <asm/arch/system_manager.h>
12#include <common.h>
13#include <errno.h>
14#include <fdtdec.h>
15#include <wait_bit.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080019struct bridge_cfg {
20 int compat_id;
21 u32 mask_noc;
22 u32 mask_rstmgr;
23};
24
25static const struct bridge_cfg bridge_cfg_tbl[] = {
26 {
27 COMPAT_ALTERA_SOCFPGA_H2F_BRG,
28 ALT_SYSMGR_NOC_H2F_SET_MSK,
29 ALT_RSTMGR_BRGMODRST_H2F_SET_MSK,
30 },
31 {
32 COMPAT_ALTERA_SOCFPGA_LWH2F_BRG,
33 ALT_SYSMGR_NOC_LWH2F_SET_MSK,
34 ALT_RSTMGR_BRGMODRST_LWH2F_SET_MSK,
35 },
36 {
37 COMPAT_ALTERA_SOCFPGA_F2H_BRG,
38 ALT_SYSMGR_NOC_F2H_SET_MSK,
39 ALT_RSTMGR_BRGMODRST_F2H_SET_MSK,
40 },
41 {
42 COMPAT_ALTERA_SOCFPGA_F2SDR0,
43 ALT_SYSMGR_NOC_F2SDR0_SET_MSK,
44 ALT_RSTMGR_BRGMODRST_F2SSDRAM0_SET_MSK,
45 },
46 {
47 COMPAT_ALTERA_SOCFPGA_F2SDR1,
48 ALT_SYSMGR_NOC_F2SDR1_SET_MSK,
49 ALT_RSTMGR_BRGMODRST_F2SSDRAM1_SET_MSK,
50 },
51 {
52 COMPAT_ALTERA_SOCFPGA_F2SDR2,
53 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
54 ALT_RSTMGR_BRGMODRST_F2SSDRAM2_SET_MSK,
55 },
56};
57
58/* Disable the watchdog (toggle reset to watchdog) */
59void socfpga_watchdog_disable(void)
60{
61 /* assert reset for watchdog */
Ley Foon Tanfed4c952019-11-08 10:38:19 +080062 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER1MODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080063 ALT_RSTMGR_PER1MODRST_WD0_SET_MSK);
64}
65
66/* Release NOC ddr scheduler from reset */
67void socfpga_reset_deassert_noc_ddr_scheduler(void)
68{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080069 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080070 ALT_RSTMGR_BRGMODRST_DDRSCH_SET_MSK);
71}
72
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080073static int get_bridge_init_val(const void *blob, int compat_id)
74{
75 int node;
76
77 node = fdtdec_next_compatible(blob, 0, compat_id);
78 if (node < 0)
79 return 0;
80
81 return fdtdec_get_uint(blob, node, "init-val", 0);
82}
83
84/* Enable bridges (hps2fpga, lwhps2fpga, fpga2hps, fpga2sdram) per handoff */
85int socfpga_reset_deassert_bridges_handoff(void)
86{
87 u32 mask_noc = 0, mask_rstmgr = 0;
88 int i;
89
90 for (i = 0; i < ARRAY_SIZE(bridge_cfg_tbl); i++) {
91 if (get_bridge_init_val(gd->fdt_blob,
92 bridge_cfg_tbl[i].compat_id)) {
93 mask_noc |= bridge_cfg_tbl[i].mask_noc;
94 mask_rstmgr |= bridge_cfg_tbl[i].mask_rstmgr;
95 }
96 }
97
98 /* clear idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080099 setbits_le32(socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_IDLEREQ_CLR,
100 mask_noc);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800101
102 /* Release bridges from reset state per handoff value */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800103 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
104 mask_rstmgr);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800105
106 /* Poll until all idleack to 0, timeout at 1000ms */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800107 return wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
108 SYSMGR_A10_NOC_IDLEACK),
109 mask_noc, false, 1000, false);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800110}
111
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800112/* Release L4 OSC1 Watchdog Timer 0 from reset through reset manager */
113void socfpga_reset_deassert_osc1wd0(void)
114{
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800115 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER1MODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800116 ALT_RSTMGR_PER1MODRST_WD0_SET_MSK);
117}
118
119/*
120 * Assert or de-assert SoCFPGA reset manager reset.
121 */
122void socfpga_per_reset(u32 reset, int set)
123{
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800124 unsigned long reg;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800125 u32 rstmgr_bank = RSTMGR_BANK(reset);
126
127 switch (rstmgr_bank) {
128 case 0:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800129 reg = RSTMGR_A10_MPUMODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800130 break;
131 case 1:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800132 reg = RSTMGR_A10_PER0MODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800133 break;
134 case 2:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800135 reg = RSTMGR_A10_PER1MODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800136 break;
137 case 3:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800138 reg = RSTMGR_A10_BRGMODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800139 break;
140 case 4:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800141 reg = RSTMGR_A10_SYSMODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800142 break;
143
144 default:
145 return;
146 }
147
148 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800149 setbits_le32(socfpga_get_rstmgr_addr() + reg,
150 1 << RSTMGR_RESET(reset));
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800151 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800152 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
153 1 << RSTMGR_RESET(reset));
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800154}
155
156/*
157 * Assert reset on every peripheral but L4WD0.
158 * Watchdog must be kept intact to prevent glitches
159 * and/or hangs.
160 * For the Arria10, we disable all the peripherals except L4 watchdog0,
161 * L4 Timer 0, and ECC.
162 */
163void socfpga_per_reset_all(void)
164{
165 const u32 l4wd0 = (1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0)) |
166 (1 << RSTMGR_RESET(SOCFPGA_RESET(L4SYSTIMER0))));
167 unsigned mask_ecc_ocp =
168 ALT_RSTMGR_PER0MODRST_EMACECC0_SET_MSK |
169 ALT_RSTMGR_PER0MODRST_EMACECC1_SET_MSK |
170 ALT_RSTMGR_PER0MODRST_EMACECC2_SET_MSK |
171 ALT_RSTMGR_PER0MODRST_USBECC0_SET_MSK |
172 ALT_RSTMGR_PER0MODRST_USBECC1_SET_MSK |
173 ALT_RSTMGR_PER0MODRST_NANDECC_SET_MSK |
174 ALT_RSTMGR_PER0MODRST_QSPIECC_SET_MSK |
175 ALT_RSTMGR_PER0MODRST_SDMMCECC_SET_MSK;
176
177 /* disable all components except ECC_OCP, L4 Timer0 and L4 WD0 */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800178 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_A10_PER1MODRST);
179 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER0MODRST,
180 ~mask_ecc_ocp);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800181
182 /* Finally disable the ECC_OCP */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800183 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER0MODRST,
184 mask_ecc_ocp);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800185}
186
Tien Fong Chee7b7b6252017-07-26 13:05:37 +0800187int socfpga_bridges_reset(void)
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800188{
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800189 int ret;
190
191 /* Disable all the bridges (hps2fpga, lwhps2fpga, fpga2hps,
192 fpga2sdram) */
193 /* set idle request to all bridges */
194 writel(ALT_SYSMGR_NOC_H2F_SET_MSK |
195 ALT_SYSMGR_NOC_LWH2F_SET_MSK |
196 ALT_SYSMGR_NOC_F2H_SET_MSK |
197 ALT_SYSMGR_NOC_F2SDR0_SET_MSK |
198 ALT_SYSMGR_NOC_F2SDR1_SET_MSK |
199 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800200 socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_IDLEREQ_SET);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800201
202 /* Enable the NOC timeout */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800203 writel(ALT_SYSMGR_NOC_TMO_EN_SET_MSK,
204 socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_TIMEOUT);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800205
206 /* Poll until all idleack to 1 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800207 ret = wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
208 SYSMGR_A10_NOC_IDLEACK),
Álvaro Fernández Rojas918de032018-01-23 17:14:55 +0100209 ALT_SYSMGR_NOC_H2F_SET_MSK |
210 ALT_SYSMGR_NOC_LWH2F_SET_MSK |
211 ALT_SYSMGR_NOC_F2H_SET_MSK |
212 ALT_SYSMGR_NOC_F2SDR0_SET_MSK |
213 ALT_SYSMGR_NOC_F2SDR1_SET_MSK |
214 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
215 true, 10000, false);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800216 if (ret)
217 return ret;
218
219 /* Poll until all idlestatus to 1 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800220 ret = wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
221 SYSMGR_A10_NOC_IDLESTATUS),
Álvaro Fernández Rojas918de032018-01-23 17:14:55 +0100222 ALT_SYSMGR_NOC_H2F_SET_MSK |
223 ALT_SYSMGR_NOC_LWH2F_SET_MSK |
224 ALT_SYSMGR_NOC_F2H_SET_MSK |
225 ALT_SYSMGR_NOC_F2SDR0_SET_MSK |
226 ALT_SYSMGR_NOC_F2SDR1_SET_MSK |
227 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
228 true, 10000, false);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800229 if (ret)
230 return ret;
231
232 /* Put all bridges (except NOR DDR scheduler) into reset state */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800233 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800234 (ALT_RSTMGR_BRGMODRST_H2F_SET_MSK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800235 ALT_RSTMGR_BRGMODRST_LWH2F_SET_MSK |
236 ALT_RSTMGR_BRGMODRST_F2H_SET_MSK |
237 ALT_RSTMGR_BRGMODRST_F2SSDRAM0_SET_MSK |
238 ALT_RSTMGR_BRGMODRST_F2SSDRAM1_SET_MSK |
239 ALT_RSTMGR_BRGMODRST_F2SSDRAM2_SET_MSK));
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800240
241 /* Disable NOC timeout */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800242 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_TIMEOUT);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800243
244 return 0;
245}