blob: 9395122dae13854b12ce1e4a7d9f43b86e31feae [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
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <mach/base_addr_ac5.h>
Ley Foon Tandd5d12d2017-04-26 02:44:34 +08008#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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060012#include <linux/bitops.h>
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080013
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080014/* Assert or de-assert SoCFPGA reset manager reset. */
15void socfpga_per_reset(u32 reset, int set)
16{
Ley Foon Tanfed4c952019-11-08 10:38:19 +080017 unsigned long reg;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080018 u32 rstmgr_bank = RSTMGR_BANK(reset);
19
20 switch (rstmgr_bank) {
21 case 0:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080022 reg = RSTMGR_GEN5_MPUMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080023 break;
24 case 1:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080025 reg = RSTMGR_GEN5_PERMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080026 break;
27 case 2:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080028 reg = RSTMGR_GEN5_PER2MODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080029 break;
30 case 3:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080031 reg = RSTMGR_GEN5_BRGMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080032 break;
33 case 4:
Ley Foon Tanfed4c952019-11-08 10:38:19 +080034 reg = RSTMGR_GEN5_MISCMODRST;
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080035 break;
36
37 default:
38 return;
39 }
40
41 if (set)
Ley Foon Tanfed4c952019-11-08 10:38:19 +080042 setbits_le32(socfpga_get_rstmgr_addr() + reg,
43 1 << RSTMGR_RESET(reset));
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080044 else
Ley Foon Tanfed4c952019-11-08 10:38:19 +080045 clrbits_le32(socfpga_get_rstmgr_addr() + reg,
46 1 << RSTMGR_RESET(reset));
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080047}
48
49/*
50 * Assert reset on every peripheral but L4WD0.
51 * Watchdog must be kept intact to prevent glitches
52 * and/or hangs.
53 */
54void socfpga_per_reset_all(void)
55{
56 const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
57
Ley Foon Tanfed4c952019-11-08 10:38:19 +080058 writel(~l4wd0, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_PERMODRST);
59 writel(0xffffffff, socfpga_get_rstmgr_addr() + RSTMGR_GEN5_PER2MODRST);
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080060}
61
Ley Foon Tandd5d12d2017-04-26 02:44:34 +080062#define L3REGS_REMAP_LWHPS2FPGA_MASK 0x10
63#define L3REGS_REMAP_HPS2FPGA_MASK 0x08
64#define L3REGS_REMAP_OCRAM_MASK 0x01
65
Marek Vasut79a5b2c2019-04-16 23:05:24 +020066void socfpga_bridges_set_handoff_regs(bool h2f, bool lwh2f, bool f2h)
67{
68 u32 brgmask = 0x0;
69 u32 l3rmask = L3REGS_REMAP_OCRAM_MASK;
70
71 if (h2f)
72 brgmask |= BIT(0);
73 else
74 l3rmask |= L3REGS_REMAP_HPS2FPGA_MASK;
75
76 if (lwh2f)
77 brgmask |= BIT(1);
78 else
79 l3rmask |= L3REGS_REMAP_LWHPS2FPGA_MASK;
80
81 if (f2h)
82 brgmask |= BIT(2);
83
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080084 writel(brgmask,
85 socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(0));
86 writel(l3rmask,
87 socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(1));
Marek Vasut79a5b2c2019-04-16 23:05:24 +020088}
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}