blob: 1008a78dc8367dbae022fa779ea2ebccd727cbae [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 +080013/* Assert or de-assert SoCFPGA reset manager reset. */
14void socfpga_per_reset(u32 reset, int set)
15{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080016 unsigned long reg;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080017 u32 rstmgr_bank = RSTMGR_BANK(reset);
18
19 switch (rstmgr_bank) {
20 case 0:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080021 reg = RSTMGR_GEN5_MPUMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080022 break;
23 case 1:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080024 reg = RSTMGR_GEN5_PERMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080025 break;
26 case 2:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080027 reg = RSTMGR_GEN5_PER2MODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080028 break;
29 case 3:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080030 reg = RSTMGR_GEN5_BRGMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080031 break;
32 case 4:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080033 reg = RSTMGR_GEN5_MISCMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080034 break;
35
36 default:
37 return;
38 }
39
40 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080041 setbits_le32(socfpga_get_rstmgr_addr() + reg,
42 1 << RSTMGR_RESET(reset));
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080043 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080044 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
45 1 << RSTMGR_RESET(reset));
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080046}
47
48/*
49 * Assert reset on every peripheral but L4WD0.
50 * Watchdog must be kept intact to prevent glitches
51 * and/or hangs.
52 */
53void socfpga_per_reset_all(void)
54{
55 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
56
Ley Foon Tanfed4c952019-11-08 10:38:19 +080057 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_PERMODRST);
58 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_PER2MODRST);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080059}
60
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080061#define L3REGS_REMAP_LWHPS2FPGA_MASK 0x10
62#define L3REGS_REMAP_HPS2FPGA_MASK 0x08
63#define L3REGS_REMAP_OCRAM_MASK 0x01
64
Marek Vasut79a5b2c2019-04-16 23:05:24 +020065void socfpga_bridges_set_handoff_regs(bool h2f, bool lwh2f, bool f2h)
66{
67 u32 brgmask = 0x0;
68 u32 l3rmask = L3REGS_REMAP_OCRAM_MASK;
69
70 if (h2f)
71 brgmask |= BIT(0);
72 else
73 l3rmask |= L3REGS_REMAP_HPS2FPGA_MASK;
74
75 if (lwh2f)
76 brgmask |= BIT(1);
77 else
78 l3rmask |= L3REGS_REMAP_LWHPS2FPGA_MASK;
79
80 if (f2h)
81 brgmask |= BIT(2);
82
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080083 writel(brgmask,
84 socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(0));
85 writel(l3rmask,
86 socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(1));
Marek Vasut79a5b2c2019-04-16 23:05:24 +020087}
88
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080089void socfpga_bridges_reset(int enable)
90{
91 const u32 l3mask = L3REGS_REMAP_LWHPS2FPGA_MASK |
92 L3REGS_REMAP_HPS2FPGA_MASK |
93 L3REGS_REMAP_OCRAM_MASK;
94
95 if (enable) {
96 /* brdmodrst */
Ley Foon Tanfed4c952019-11-08 10:38:19 +080097 writel(0x7, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_BRGMODRST);
Marek Vasut0c3ddb62019-04-16 22:13:29 +020098 writel(L3REGS_REMAP_OCRAM_MASK, SOCFPGA_L3REGS_ADDRESS);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080099 } else {
Marek Vasut79a5b2c2019-04-16 23:05:24 +0200100 socfpga_bridges_set_handoff_regs(false, false, false);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +0800101
102 /* Check signal from FPGA. */
103 if (!fpgamgr_test_fpga_ready()) {
104 /* FPGA not ready, do nothing. We allow system to boot
105 * without FPGA ready. So, return 0 instead of error. */
106 printf("%s: FPGA not ready, aborting.\n", __func__);
107 return;
108 }
109
110 /* brdmodrst */
Ley Foon Tanfed4c952019-11-08 10:38:19 +0800111 writel(0, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_BRGMODRST);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +0800112
113 /* Remap the bridges into memory map */
114 writel(l3mask, SOCFPGA_L3REGS_ADDRESS);
115 }
116 return;
117}