Commit abb25f4e9529c1b91d651c74af9bd3f1c955437b

Authored by Marek Vasut
1 parent 230fe9b202

arm: socfpga: reset: Add function to reset FPGA bridges

Add function to enable and disable FPGA bridges. This code is used
by the FPGA manager to disable the bridges before programming the
FPGA and will later be also used by the initialization code for the
chip to put the chip into well defined state during startup.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chin Liang See <clsee@altera.com>
Cc: Dinh Nguyen <dinguyen@altera.com>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
Cc: Tom Rini <trini@ti.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Pavel Machek <pavel@denx.de>
Acked-by: Pavel Machek <pavel@denx.de>

Showing 2 changed files with 40 additions and 0 deletions Inline Diff

arch/arm/cpu/armv7/socfpga/reset_manager.c
1 /* 1 /*
2 * Copyright (C) 2013 Altera Corporation <www.altera.com> 2 * Copyright (C) 2013 Altera Corporation <www.altera.com>
3 * 3 *
4 * SPDX-License-Identifier: GPL-2.0+ 4 * SPDX-License-Identifier: GPL-2.0+
5 */ 5 */
6 6
7 7
8 #include <common.h> 8 #include <common.h>
9 #include <asm/io.h> 9 #include <asm/io.h>
10 #include <asm/arch/reset_manager.h> 10 #include <asm/arch/reset_manager.h>
11 #include <asm/arch/fpga_manager.h>
11 12
12 DECLARE_GLOBAL_DATA_PTR; 13 DECLARE_GLOBAL_DATA_PTR;
13 14
14 static const struct socfpga_reset_manager *reset_manager_base = 15 static const struct socfpga_reset_manager *reset_manager_base =
15 (void *)SOCFPGA_RSTMGR_ADDRESS; 16 (void *)SOCFPGA_RSTMGR_ADDRESS;
16 17
17 /* Toggle reset signal to watchdog (WDT is disabled after this operation!) */ 18 /* Toggle reset signal to watchdog (WDT is disabled after this operation!) */
18 void socfpga_watchdog_reset(void) 19 void socfpga_watchdog_reset(void)
19 { 20 {
20 /* assert reset for watchdog */ 21 /* assert reset for watchdog */
21 setbits_le32(&reset_manager_base->per_mod_reset, 22 setbits_le32(&reset_manager_base->per_mod_reset,
22 1 << RSTMGR_PERMODRST_L4WD0_LSB); 23 1 << RSTMGR_PERMODRST_L4WD0_LSB);
23 24
24 /* deassert watchdog from reset (watchdog in not running state) */ 25 /* deassert watchdog from reset (watchdog in not running state) */
25 clrbits_le32(&reset_manager_base->per_mod_reset, 26 clrbits_le32(&reset_manager_base->per_mod_reset,
26 1 << RSTMGR_PERMODRST_L4WD0_LSB); 27 1 << RSTMGR_PERMODRST_L4WD0_LSB);
27 } 28 }
28 29
29 /* 30 /*
30 * Write the reset manager register to cause reset 31 * Write the reset manager register to cause reset
31 */ 32 */
32 void reset_cpu(ulong addr) 33 void reset_cpu(ulong addr)
33 { 34 {
34 /* request a warm reset */ 35 /* request a warm reset */
35 writel((1 << RSTMGR_CTRL_SWWARMRSTREQ_LSB), 36 writel((1 << RSTMGR_CTRL_SWWARMRSTREQ_LSB),
36 &reset_manager_base->ctrl); 37 &reset_manager_base->ctrl);
37 /* 38 /*
38 * infinite loop here as watchdog will trigger and reset 39 * infinite loop here as watchdog will trigger and reset
39 * the processor 40 * the processor
40 */ 41 */
41 while (1) 42 while (1)
42 ; 43 ;
43 } 44 }
44 45
45 /* 46 /*
46 * Release peripherals from reset based on handoff 47 * Release peripherals from reset based on handoff
47 */ 48 */
48 void reset_deassert_peripherals_handoff(void) 49 void reset_deassert_peripherals_handoff(void)
49 { 50 {
50 writel(0, &reset_manager_base->per_mod_reset); 51 writel(0, &reset_manager_base->per_mod_reset);
51 } 52 }
53
54 #if defined(CONFIG_SOCFPGA_VIRTUAL_TARGET)
55 void socfpga_bridges_reset(int enable)
56 {
57 /* For SoCFPGA-VT, this is NOP. */
58 }
59 #else
60
61 #define L3REGS_REMAP_LWHPS2FPGA_MASK 0x10
62 #define L3REGS_REMAP_HPS2FPGA_MASK 0x08
63 #define L3REGS_REMAP_OCRAM_MASK 0x01
64
65 void socfpga_bridges_reset(int enable)
66 {
67 const uint32_t l3mask = L3REGS_REMAP_LWHPS2FPGA_MASK |
68 L3REGS_REMAP_HPS2FPGA_MASK |
69 L3REGS_REMAP_OCRAM_MASK;
70
71 if (enable) {
72 /* brdmodrst */
73 writel(0xffffffff, &reset_manager_base->brg_mod_reset);
74 } else {
75 /* Check signal from FPGA. */
76 if (fpgamgr_poll_fpga_ready()) {
77 /* FPGA not ready. Wait for watchdog timeout. */
78 printf("%s: fpga not ready, hanging.\n", __func__);
79 hang();
80 }
81
82 /* brdmodrst */
83 writel(0, &reset_manager_base->brg_mod_reset);
84
85 /* Remap the bridges into memory map */
86 writel(l3mask, SOCFPGA_L3REGS_ADDRESS);
87 }
88 }
89 #endif
52 90
53 /* Change the reset state for EMAC 0 and EMAC 1 */ 91 /* Change the reset state for EMAC 0 and EMAC 1 */
54 void socfpga_emac_reset(int enable) 92 void socfpga_emac_reset(int enable)
55 { 93 {
56 const void *reset = &reset_manager_base->per_mod_reset; 94 const void *reset = &reset_manager_base->per_mod_reset;
57 95
58 if (enable) { 96 if (enable) {
59 setbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC0_LSB); 97 setbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC0_LSB);
60 setbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC1_LSB); 98 setbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC1_LSB);
61 } else { 99 } else {
62 #if (CONFIG_EMAC_BASE == SOCFPGA_EMAC0_ADDRESS) 100 #if (CONFIG_EMAC_BASE == SOCFPGA_EMAC0_ADDRESS)
63 clrbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC0_LSB); 101 clrbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC0_LSB);
64 #elif (CONFIG_EMAC_BASE == SOCFPGA_EMAC1_ADDRESS) 102 #elif (CONFIG_EMAC_BASE == SOCFPGA_EMAC1_ADDRESS)
65 clrbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC1_LSB); 103 clrbits_le32(reset, 1 << RSTMGR_PERMODRST_EMAC1_LSB);
66 #endif 104 #endif
67 } 105 }
68 } 106 }
69 107
arch/arm/include/asm/arch-socfpga/reset_manager.h
1 /* 1 /*
2 * Copyright (C) 2012 Altera Corporation <www.altera.com> 2 * Copyright (C) 2012 Altera Corporation <www.altera.com>
3 * 3 *
4 * SPDX-License-Identifier: GPL-2.0+ 4 * SPDX-License-Identifier: GPL-2.0+
5 */ 5 */
6 6
7 #ifndef _RESET_MANAGER_H_ 7 #ifndef _RESET_MANAGER_H_
8 #define _RESET_MANAGER_H_ 8 #define _RESET_MANAGER_H_
9 9
10 void reset_cpu(ulong addr); 10 void reset_cpu(ulong addr);
11 void reset_deassert_peripherals_handoff(void); 11 void reset_deassert_peripherals_handoff(void);
12 12
13 void socfpga_bridges_reset(int enable);
14
13 void socfpga_emac_reset(int enable); 15 void socfpga_emac_reset(int enable);
14 void socfpga_watchdog_reset(void); 16 void socfpga_watchdog_reset(void);
15 17
16 struct socfpga_reset_manager { 18 struct socfpga_reset_manager {
17 u32 status; 19 u32 status;
18 u32 ctrl; 20 u32 ctrl;
19 u32 counts; 21 u32 counts;
20 u32 padding1; 22 u32 padding1;
21 u32 mpu_mod_reset; 23 u32 mpu_mod_reset;
22 u32 per_mod_reset; 24 u32 per_mod_reset;
23 u32 per2_mod_reset; 25 u32 per2_mod_reset;
24 u32 brg_mod_reset; 26 u32 brg_mod_reset;
25 }; 27 };
26 28
27 #if defined(CONFIG_SOCFPGA_VIRTUAL_TARGET) 29 #if defined(CONFIG_SOCFPGA_VIRTUAL_TARGET)
28 #define RSTMGR_CTRL_SWWARMRSTREQ_LSB 2 30 #define RSTMGR_CTRL_SWWARMRSTREQ_LSB 2
29 #else 31 #else
30 #define RSTMGR_CTRL_SWWARMRSTREQ_LSB 1 32 #define RSTMGR_CTRL_SWWARMRSTREQ_LSB 1
31 #endif 33 #endif
32 34
33 #define RSTMGR_PERMODRST_EMAC0_LSB 0 35 #define RSTMGR_PERMODRST_EMAC0_LSB 0
34 #define RSTMGR_PERMODRST_EMAC1_LSB 1 36 #define RSTMGR_PERMODRST_EMAC1_LSB 1
35 #define RSTMGR_PERMODRST_L4WD0_LSB 6 37 #define RSTMGR_PERMODRST_L4WD0_LSB 6
36 38
37 #endif /* _RESET_MANAGER_H_ */ 39 #endif /* _RESET_MANAGER_H_ */
38 40