spl.c 5.7 KB

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