spl.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Altera Corporation <www.altera.com>
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #include <asm/pl310.h>
  8. #include <asm/u-boot.h>
  9. #include <asm/utils.h>
  10. #include <image.h>
  11. #include <asm/arch/reset_manager.h>
  12. #include <spl.h>
  13. #include <asm/arch/system_manager.h>
  14. #include <asm/arch/freeze_controller.h>
  15. #include <asm/arch/clock_manager.h>
  16. #include <asm/arch/scan_manager.h>
  17. #include <asm/arch/sdram.h>
  18. #include <asm/arch/scu.h>
  19. #include <asm/arch/nic301.h>
  20. #include <asm/sections.h>
  21. #include <fdtdec.h>
  22. #include <watchdog.h>
  23. #if defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
  24. #include <asm/arch/pinmux.h>
  25. #endif
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
  28. static struct pl310_regs *const pl310 =
  29. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  30. static struct scu_registers *scu_regs =
  31. (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS;
  32. static struct nic301_registers *nic301_regs =
  33. (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS;
  34. #endif
  35. static const struct socfpga_system_manager *sysmgr_regs =
  36. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  37. u32 spl_boot_device(void)
  38. {
  39. const u32 bsel = readl(&sysmgr_regs->bootinfo);
  40. switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
  41. case 0x1: /* FPGA (HPS2FPGA Bridge) */
  42. return BOOT_DEVICE_RAM;
  43. case 0x2: /* NAND Flash (1.8V) */
  44. case 0x3: /* NAND Flash (3.0V) */
  45. socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
  46. return BOOT_DEVICE_NAND;
  47. case 0x4: /* SD/MMC External Transceiver (1.8V) */
  48. case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
  49. socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
  50. socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
  51. return BOOT_DEVICE_MMC1;
  52. case 0x6: /* QSPI Flash (1.8V) */
  53. case 0x7: /* QSPI Flash (3.0V) */
  54. socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
  55. return BOOT_DEVICE_SPI;
  56. default:
  57. printf("Invalid boot device (bsel=%08x)!\n", bsel);
  58. hang();
  59. }
  60. }
  61. #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
  62. static void socfpga_nic301_slave_ns(void)
  63. {
  64. writel(0x1, &nic301_regs->lwhps2fpgaregs);
  65. writel(0x1, &nic301_regs->hps2fpgaregs);
  66. writel(0x1, &nic301_regs->acp);
  67. writel(0x1, &nic301_regs->rom);
  68. writel(0x1, &nic301_regs->ocram);
  69. writel(0x1, &nic301_regs->sdrdata);
  70. }
  71. void board_init_f(ulong dummy)
  72. {
  73. const struct cm_config *cm_default_cfg = cm_get_default_config();
  74. unsigned long sdram_size;
  75. unsigned long reg;
  76. /*
  77. * First C code to run. Clear fake OCRAM ECC first as SBE
  78. * and DBE might triggered during power on
  79. */
  80. reg = readl(&sysmgr_regs->eccgrp_ocram);
  81. if (reg & SYSMGR_ECC_OCRAM_SERR)
  82. writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
  83. &sysmgr_regs->eccgrp_ocram);
  84. if (reg & SYSMGR_ECC_OCRAM_DERR)
  85. writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
  86. &sysmgr_regs->eccgrp_ocram);
  87. memset(__bss_start, 0, __bss_end - __bss_start);
  88. socfpga_nic301_slave_ns();
  89. /* Configure ARM MPU SNSAC register. */
  90. setbits_le32(&scu_regs->sacr, 0xfff);
  91. /* Remap SDRAM to 0x0 */
  92. writel(0x1, &nic301_regs->remap); /* remap.mpuzero */
  93. writel(0x1, &pl310->pl310_addr_filter_start);
  94. debug("Freezing all I/O banks\n");
  95. /* freeze all IO banks */
  96. sys_mgr_frzctrl_freeze_req();
  97. /* Put everything into reset but L4WD0. */
  98. socfpga_per_reset_all();
  99. /* Put FPGA bridges into reset too. */
  100. socfpga_bridges_reset(1);
  101. socfpga_per_reset(SOCFPGA_RESET(SDR), 0);
  102. socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
  103. socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
  104. timer_init();
  105. debug("Reconfigure Clock Manager\n");
  106. /* reconfigure the PLLs */
  107. if (cm_basic_init(cm_default_cfg))
  108. hang();
  109. /* Enable bootrom to configure IOs. */
  110. sysmgr_config_warmrstcfgio(1);
  111. /* configure the IOCSR / IO buffer settings */
  112. if (scan_mgr_configure_iocsr())
  113. hang();
  114. sysmgr_config_warmrstcfgio(0);
  115. /* configure the pin muxing through system manager */
  116. sysmgr_config_warmrstcfgio(1);
  117. sysmgr_pinmux_init();
  118. sysmgr_config_warmrstcfgio(0);
  119. /* De-assert reset for peripherals and bridges based on handoff */
  120. reset_deassert_peripherals_handoff();
  121. socfpga_bridges_reset(0);
  122. debug("Unfreezing/Thaw all I/O banks\n");
  123. /* unfreeze / thaw all IO banks */
  124. sys_mgr_frzctrl_thaw_req();
  125. /* enable console uart printing */
  126. preloader_console_init();
  127. if (sdram_mmr_init_full(0xffffffff) != 0) {
  128. puts("SDRAM init failed.\n");
  129. hang();
  130. }
  131. debug("SDRAM: Calibrating PHY\n");
  132. /* SDRAM calibration */
  133. if (sdram_calibration_full() == 0) {
  134. puts("SDRAM calibration failed.\n");
  135. hang();
  136. }
  137. sdram_size = sdram_calculate_size();
  138. debug("SDRAM: %ld MiB\n", sdram_size >> 20);
  139. /* Sanity check ensure correct SDRAM size specified */
  140. if (get_ram_size(0, sdram_size) != sdram_size) {
  141. puts("SDRAM size check failed!\n");
  142. hang();
  143. }
  144. socfpga_bridges_reset(1);
  145. /* Configure simple malloc base pointer into RAM. */
  146. gd->malloc_base = CONFIG_SYS_TEXT_BASE + (1024 * 1024);
  147. }
  148. #elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
  149. void spl_board_init(void)
  150. {
  151. /* configuring the clock based on handoff */
  152. cm_basic_init(gd->fdt_blob);
  153. WATCHDOG_RESET();
  154. config_dedicated_pins(gd->fdt_blob);
  155. WATCHDOG_RESET();
  156. /* Release UART from reset */
  157. socfpga_reset_uart(0);
  158. /* enable console uart printing */
  159. preloader_console_init();
  160. }
  161. void board_init_f(ulong dummy)
  162. {
  163. /*
  164. * Configure Clock Manager to use intosc clock instead external osc to
  165. * ensure success watchdog operation. We do it as early as possible.
  166. */
  167. cm_use_intosc();
  168. socfpga_watchdog_disable();
  169. arch_early_init_r();
  170. #ifdef CONFIG_HW_WATCHDOG
  171. /* release osc1 watchdog timer 0 from reset */
  172. socfpga_reset_deassert_osc1wd0();
  173. /* reconfigure and enable the watchdog */
  174. hw_watchdog_init();
  175. WATCHDOG_RESET();
  176. #endif /* CONFIG_HW_WATCHDOG */
  177. }
  178. #endif