blob: 89e04fe027d44b0a740889f59b7f743e23a5e635 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ley Foon Tandd5d12d2017-04-26 02:44:34 +08002/*
3 * Copyright (C) 2013 Altera Corporation <www.altera.com>
Ley Foon Tandd5d12d2017-04-26 02:44:34 +08004 */
5
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/fpga_manager.h>
10#include <asm/arch/reset_manager.h>
11#include <asm/arch/system_manager.h>
12
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080013static const struct socfpga_system_manager *sysmgr_regs =
14 (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
15
16/* Assert or de-assert SoCFPGA reset manager reset. */
17void socfpga_per_reset(u32 reset, int set)
18{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080019 unsigned long reg;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080020 u32 rstmgr_bank = RSTMGR_BANK(reset);
21
22 switch (rstmgr_bank) {
23 case 0:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080024 reg = RSTMGR_GEN5_MPUMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080025 break;
26 case 1:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080027 reg = RSTMGR_GEN5_PERMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080028 break;
29 case 2:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080030 reg = RSTMGR_GEN5_PER2MODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080031 break;
32 case 3:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080033 reg = RSTMGR_GEN5_BRGMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080034 break;
35 case 4:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080036 reg = RSTMGR_GEN5_MISCMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080037 break;
38
39 default:
40 return;
41 }
42
43 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080044 setbits_le32(socfpga_get_rstmgr_addr() + reg,
45 1 << RSTMGR_RESET(reset));
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080046 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080047 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
48 1 << RSTMGR_RESET(reset));
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080049}
50
51/*
52 * Assert reset on every peripheral but L4WD0.
53 * Watchdog must be kept intact to prevent glitches
54 * and/or hangs.
55 */
56void socfpga_per_reset_all(void)
57{
58 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
59
Ley Foon Tanfed4c952019-11-08 10:38:19 +080060 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_PERMODRST);
61 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_PER2MODRST);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080062}
63
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080064#define L3REGS_REMAP_LWHPS2FPGA_MASK 0x10
65#define L3REGS_REMAP_HPS2FPGA_MASK 0x08
66#define L3REGS_REMAP_OCRAM_MASK 0x01
67
Marek Vasut79a5b2c2019-04-16 23:05:24 +020068void socfpga_bridges_set_handoff_regs(bool h2f, bool lwh2f, bool f2h)
69{
70 u32 brgmask = 0x0;
71 u32 l3rmask = L3REGS_REMAP_OCRAM_MASK;
72
73 if (h2f)
74 brgmask |= BIT(0);
75 else
76 l3rmask |= L3REGS_REMAP_HPS2FPGA_MASK;
77
78 if (lwh2f)
79 brgmask |= BIT(1);
80 else
81 l3rmask |= L3REGS_REMAP_LWHPS2FPGA_MASK;
82
83 if (f2h)
84 brgmask |= BIT(2);
85
86 writel(brgmask, &sysmgr_regs->iswgrp_handoff[0]);
87 writel(l3rmask, &sysmgr_regs->iswgrp_handoff[1]);
88}
89
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080090void socfpga_bridges_reset(int enable)
91{
92 const u32 l3mask = L3REGS_REMAP_LWHPS2FPGA_MASK |
93 L3REGS_REMAP_HPS2FPGA_MASK |
94 L3REGS_REMAP_OCRAM_MASK;
95
96 if (enable) {
97 /* brdmodrst */
Ley Foon Tanfed4c952019-11-08 10:38:19 +080098 writel(0x7, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_BRGMODRST);
Marek Vasut0c3ddb62019-04-16 22:13:29 +020099 writel(L3REGS_REMAP_OCRAM_MASK, SOCFPGA_L3REGS_ADDRESS);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +0800100 } else {
Marek Vasut79a5b2c2019-04-16 23:05:24 +0200101 socfpga_bridges_set_handoff_regs(false, false, false);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +0800102
103 /* Check signal from FPGA. */
104 if (!fpgamgr_test_fpga_ready()) {
105 /* FPGA not ready, do nothing. We allow system to boot
106 * without FPGA ready. So, return 0 instead of error. */
107 printf("%s: FPGA not ready, aborting.\n", __func__);
108 return;
109 }
110
111 /* brdmodrst */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800112 writel(0, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_BRGMODRST);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +0800113
114 /* Remap the bridges into memory map */
115 writel(l3mask, SOCFPGA_L3REGS_ADDRESS);
116 }
117 return;
118}