blob: aa5299415a74391b8347099ad62f743e94f08ddd [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
6#include <asm/io.h>
7#include <asm/arch/fpga_manager.h>
8#include <asm/arch/misc.h>
9#include <asm/arch/reset_manager.h>
10#include <asm/arch/system_manager.h>
11#include <common.h>
12#include <errno.h>
13#include <fdtdec.h>
14#include <wait_bit.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080018struct bridge_cfg {
19 int compat_id;
20 u32 mask_noc;
21 u32 mask_rstmgr;
22};
23
24static const struct bridge_cfg bridge_cfg_tbl[] = {
25 {
26 COMPAT_ALTERA_SOCFPGA_H2F_BRG,
27 ALT_SYSMGR_NOC_H2F_SET_MSK,
28 ALT_RSTMGR_BRGMODRST_H2F_SET_MSK,
29 },
30 {
31 COMPAT_ALTERA_SOCFPGA_LWH2F_BRG,
32 ALT_SYSMGR_NOC_LWH2F_SET_MSK,
33 ALT_RSTMGR_BRGMODRST_LWH2F_SET_MSK,
34 },
35 {
36 COMPAT_ALTERA_SOCFPGA_F2H_BRG,
37 ALT_SYSMGR_NOC_F2H_SET_MSK,
38 ALT_RSTMGR_BRGMODRST_F2H_SET_MSK,
39 },
40 {
41 COMPAT_ALTERA_SOCFPGA_F2SDR0,
42 ALT_SYSMGR_NOC_F2SDR0_SET_MSK,
43 ALT_RSTMGR_BRGMODRST_F2SSDRAM0_SET_MSK,
44 },
45 {
46 COMPAT_ALTERA_SOCFPGA_F2SDR1,
47 ALT_SYSMGR_NOC_F2SDR1_SET_MSK,
48 ALT_RSTMGR_BRGMODRST_F2SSDRAM1_SET_MSK,
49 },
50 {
51 COMPAT_ALTERA_SOCFPGA_F2SDR2,
52 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
53 ALT_RSTMGR_BRGMODRST_F2SSDRAM2_SET_MSK,
54 },
55};
56
57/* Disable the watchdog (toggle reset to watchdog) */
58void socfpga_watchdog_disable(void)
59{
60 /* assert reset for watchdog */
Ley Foon Tanfed4c952019-11-08 10:38:19 +080061 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER1MODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080062 ALT_RSTMGR_PER1MODRST_WD0_SET_MSK);
63}
64
65/* Release NOC ddr scheduler from reset */
66void socfpga_reset_deassert_noc_ddr_scheduler(void)
67{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080068 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080069 ALT_RSTMGR_BRGMODRST_DDRSCH_SET_MSK);
70}
71
Ley Foon Tan778ed2c2017-04-26 02:44:38 +080072static int get_bridge_init_val(const void *blob, int compat_id)
73{
74 int node;
75
76 node = fdtdec_next_compatible(blob, 0, compat_id);
77 if (node < 0)
78 return 0;
79
80 return fdtdec_get_uint(blob, node, "init-val", 0);
81}
82
83/* Enable bridges (hps2fpga, lwhps2fpga, fpga2hps, fpga2sdram) per handoff */
84int socfpga_reset_deassert_bridges_handoff(void)
85{
86 u32 mask_noc = 0, mask_rstmgr = 0;
87 int i;
88
89 for (i = 0; i < ARRAY_SIZE(bridge_cfg_tbl); i++) {
90 if (get_bridge_init_val(gd->fdt_blob,
91 bridge_cfg_tbl[i].compat_id)) {
92 mask_noc |= bridge_cfg_tbl[i].mask_noc;
93 mask_rstmgr |= bridge_cfg_tbl[i].mask_rstmgr;
94 }
95 }
96
97 /* clear idle request to all bridges */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080098 setbits_le32(socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_IDLEREQ_CLR,
99 mask_noc);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800100
101 /* Release bridges from reset state per handoff value */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800102 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
103 mask_rstmgr);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800104
105 /* Poll until all idleack to 0, timeout at 1000ms */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800106 return wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
107 SYSMGR_A10_NOC_IDLEACK),
108 mask_noc, false, 1000, false);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800109}
110
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800111/* Release L4 OSC1 Watchdog Timer 0 from reset through reset manager */
112void socfpga_reset_deassert_osc1wd0(void)
113{
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800114 clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER1MODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800115 ALT_RSTMGR_PER1MODRST_WD0_SET_MSK);
116}
117
118/*
119 * Assert or de-assert SoCFPGA reset manager reset.
120 */
121void socfpga_per_reset(u32 reset, int set)
122{
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800123 unsigned long reg;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800124 u32 rstmgr_bank = RSTMGR_BANK(reset);
125
126 switch (rstmgr_bank) {
127 case 0:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800128 reg = RSTMGR_A10_MPUMODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800129 break;
130 case 1:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800131 reg = RSTMGR_A10_PER0MODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800132 break;
133 case 2:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800134 reg = RSTMGR_A10_PER1MODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800135 break;
136 case 3:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800137 reg = RSTMGR_A10_BRGMODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800138 break;
139 case 4:
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800140 reg = RSTMGR_A10_SYSMODRST;
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800141 break;
142
143 default:
144 return;
145 }
146
147 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800148 setbits_le32(socfpga_get_rstmgr_addr() + reg,
149 1 << RSTMGR_RESET(reset));
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800150 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800151 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
152 1 << RSTMGR_RESET(reset));
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800153}
154
155/*
156 * Assert reset on every peripheral but L4WD0.
157 * Watchdog must be kept intact to prevent glitches
158 * and/or hangs.
159 * For the Arria10, we disable all the peripherals except L4 watchdog0,
160 * L4 Timer 0, and ECC.
161 */
162void socfpga_per_reset_all(void)
163{
164 const u32 l4wd0 = (1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0)) |
165 (1 << RSTMGR_RESET(SOCFPGA_RESET(L4SYSTIMER0))));
166 unsigned mask_ecc_ocp =
167 ALT_RSTMGR_PER0MODRST_EMACECC0_SET_MSK |
168 ALT_RSTMGR_PER0MODRST_EMACECC1_SET_MSK |
169 ALT_RSTMGR_PER0MODRST_EMACECC2_SET_MSK |
170 ALT_RSTMGR_PER0MODRST_USBECC0_SET_MSK |
171 ALT_RSTMGR_PER0MODRST_USBECC1_SET_MSK |
172 ALT_RSTMGR_PER0MODRST_NANDECC_SET_MSK |
173 ALT_RSTMGR_PER0MODRST_QSPIECC_SET_MSK |
174 ALT_RSTMGR_PER0MODRST_SDMMCECC_SET_MSK;
175
176 /* disable all components except ECC_OCP, L4 Timer0 and L4 WD0 */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800177 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_A10_PER1MODRST);
178 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER0MODRST,
179 ~mask_ecc_ocp);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800180
181 /* Finally disable the ECC_OCP */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800182 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_PER0MODRST,
183 mask_ecc_ocp);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800184}
185
Tien Fong Chee7b7b6252017-07-26 13:05:37 +0800186int socfpga_bridges_reset(void)
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800187{
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800188 int ret;
189
190 /* Disable all the bridges (hps2fpga, lwhps2fpga, fpga2hps,
191 fpga2sdram) */
192 /* set idle request to all bridges */
193 writel(ALT_SYSMGR_NOC_H2F_SET_MSK |
194 ALT_SYSMGR_NOC_LWH2F_SET_MSK |
195 ALT_SYSMGR_NOC_F2H_SET_MSK |
196 ALT_SYSMGR_NOC_F2SDR0_SET_MSK |
197 ALT_SYSMGR_NOC_F2SDR1_SET_MSK |
198 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800199 socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_IDLEREQ_SET);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800200
201 /* Enable the NOC timeout */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800202 writel(ALT_SYSMGR_NOC_TMO_EN_SET_MSK,
203 socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_TIMEOUT);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800204
205 /* Poll until all idleack to 1 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800206 ret = wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
207 SYSMGR_A10_NOC_IDLEACK),
Álvaro Fernández Rojas918de032018-01-23 17:14:55 +0100208 ALT_SYSMGR_NOC_H2F_SET_MSK |
209 ALT_SYSMGR_NOC_LWH2F_SET_MSK |
210 ALT_SYSMGR_NOC_F2H_SET_MSK |
211 ALT_SYSMGR_NOC_F2SDR0_SET_MSK |
212 ALT_SYSMGR_NOC_F2SDR1_SET_MSK |
213 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
214 true, 10000, false);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800215 if (ret)
216 return ret;
217
218 /* Poll until all idlestatus to 1 */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800219 ret = wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
220 SYSMGR_A10_NOC_IDLESTATUS),
Álvaro Fernández Rojas918de032018-01-23 17:14:55 +0100221 ALT_SYSMGR_NOC_H2F_SET_MSK |
222 ALT_SYSMGR_NOC_LWH2F_SET_MSK |
223 ALT_SYSMGR_NOC_F2H_SET_MSK |
224 ALT_SYSMGR_NOC_F2SDR0_SET_MSK |
225 ALT_SYSMGR_NOC_F2SDR1_SET_MSK |
226 ALT_SYSMGR_NOC_F2SDR2_SET_MSK,
227 true, 10000, false);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800228 if (ret)
229 return ret;
230
231 /* Put all bridges (except NOR DDR scheduler) into reset state */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800232 setbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800233 (ALT_RSTMGR_BRGMODRST_H2F_SET_MSK |
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800234 ALT_RSTMGR_BRGMODRST_LWH2F_SET_MSK |
235 ALT_RSTMGR_BRGMODRST_F2H_SET_MSK |
236 ALT_RSTMGR_BRGMODRST_F2SSDRAM0_SET_MSK |
237 ALT_RSTMGR_BRGMODRST_F2SSDRAM1_SET_MSK |
238 ALT_RSTMGR_BRGMODRST_F2SSDRAM2_SET_MSK));
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800239
240 /* Disable NOC timeout */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800241 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_A10_NOC_TIMEOUT);
Ley Foon Tan778ed2c2017-04-26 02:44:38 +0800242
243 return 0;
244}