reset_manager.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2013 Altera Corporation <www.altera.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/fpga_manager.h>
  9. #include <asm/arch/reset_manager.h>
  10. #include <asm/arch/system_manager.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. static const struct socfpga_reset_manager *reset_manager_base =
  13. (void *)SOCFPGA_RSTMGR_ADDRESS;
  14. static struct socfpga_system_manager *sysmgr_regs =
  15. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  16. /* Assert or de-assert SoCFPGA reset manager reset. */
  17. void socfpga_per_reset(u32 reset, int set)
  18. {
  19. const void *reg;
  20. if (RSTMGR_BANK(reset) == 0)
  21. reg = &reset_manager_base->mpu_mod_reset;
  22. else if (RSTMGR_BANK(reset) == 1)
  23. reg = &reset_manager_base->per_mod_reset;
  24. else if (RSTMGR_BANK(reset) == 2)
  25. reg = &reset_manager_base->per2_mod_reset;
  26. else if (RSTMGR_BANK(reset) == 3)
  27. reg = &reset_manager_base->brg_mod_reset;
  28. else if (RSTMGR_BANK(reset) == 4)
  29. reg = &reset_manager_base->misc_mod_reset;
  30. else /* Invalid reset register, do nothing */
  31. return;
  32. if (set)
  33. setbits_le32(reg, 1 << RSTMGR_RESET(reset));
  34. else
  35. clrbits_le32(reg, 1 << RSTMGR_RESET(reset));
  36. }
  37. /*
  38. * Assert reset on every peripheral but L4WD0.
  39. * Watchdog must be kept intact to prevent glitches
  40. * and/or hangs.
  41. */
  42. void socfpga_per_reset_all(void)
  43. {
  44. const u32 l4wd0 = 1 << RSTMGR_RESET(SOCFPGA_RESET(L4WD0));
  45. writel(~l4wd0, &reset_manager_base->per_mod_reset);
  46. writel(0xffffffff, &reset_manager_base->per2_mod_reset);
  47. }
  48. /*
  49. * Write the reset manager register to cause reset
  50. */
  51. void reset_cpu(ulong addr)
  52. {
  53. /* request a warm reset */
  54. writel((1 << RSTMGR_CTRL_SWWARMRSTREQ_LSB),
  55. &reset_manager_base->ctrl);
  56. /*
  57. * infinite loop here as watchdog will trigger and reset
  58. * the processor
  59. */
  60. while (1)
  61. ;
  62. }
  63. /*
  64. * Release peripherals from reset based on handoff
  65. */
  66. void reset_deassert_peripherals_handoff(void)
  67. {
  68. writel(0, &reset_manager_base->per_mod_reset);
  69. }
  70. #if defined(CONFIG_SOCFPGA_VIRTUAL_TARGET)
  71. void socfpga_bridges_reset(int enable)
  72. {
  73. /* For SoCFPGA-VT, this is NOP. */
  74. }
  75. #else
  76. #define L3REGS_REMAP_LWHPS2FPGA_MASK 0x10
  77. #define L3REGS_REMAP_HPS2FPGA_MASK 0x08
  78. #define L3REGS_REMAP_OCRAM_MASK 0x01
  79. void socfpga_bridges_reset(int enable)
  80. {
  81. const uint32_t l3mask = L3REGS_REMAP_LWHPS2FPGA_MASK |
  82. L3REGS_REMAP_HPS2FPGA_MASK |
  83. L3REGS_REMAP_OCRAM_MASK;
  84. if (enable) {
  85. /* brdmodrst */
  86. writel(0xffffffff, &reset_manager_base->brg_mod_reset);
  87. } else {
  88. writel(0, &sysmgr_regs->iswgrp_handoff[0]);
  89. writel(l3mask, &sysmgr_regs->iswgrp_handoff[1]);
  90. /* Check signal from FPGA. */
  91. if (!fpgamgr_test_fpga_ready()) {
  92. /* FPGA not ready, do nothing. */
  93. printf("%s: FPGA not ready, aborting.\n", __func__);
  94. return;
  95. }
  96. /* brdmodrst */
  97. writel(0, &reset_manager_base->brg_mod_reset);
  98. /* Remap the bridges into memory map */
  99. writel(l3mask, SOCFPGA_L3REGS_ADDRESS);
  100. }
  101. }
  102. #endif