spl.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (C) 2012 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/pl310.h>
  9. #include <asm/u-boot.h>
  10. #include <asm/utils.h>
  11. #include <image.h>
  12. #include <asm/arch/reset_manager.h>
  13. #include <spl.h>
  14. #include <asm/arch/system_manager.h>
  15. #include <asm/arch/freeze_controller.h>
  16. #include <asm/arch/clock_manager.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. DECLARE_GLOBAL_DATA_PTR;
  22. static struct pl310_regs *const pl310 =
  23. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  24. static struct scu_registers *scu_regs =
  25. (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS;
  26. static struct nic301_registers *nic301_regs =
  27. (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS;
  28. static struct socfpga_system_manager *sysmgr_regs =
  29. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  30. u32 spl_boot_device(void)
  31. {
  32. const u32 bsel = readl(&sysmgr_regs->bootinfo);
  33. switch (bsel & 0x7) {
  34. case 0x1: /* FPGA (HPS2FPGA Bridge) */
  35. return BOOT_DEVICE_RAM;
  36. case 0x2: /* NAND Flash (1.8V) */
  37. case 0x3: /* NAND Flash (3.0V) */
  38. socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
  39. return BOOT_DEVICE_NAND;
  40. case 0x4: /* SD/MMC External Transceiver (1.8V) */
  41. case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
  42. socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
  43. socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
  44. return BOOT_DEVICE_MMC1;
  45. case 0x6: /* QSPI Flash (1.8V) */
  46. case 0x7: /* QSPI Flash (3.0V) */
  47. socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
  48. return BOOT_DEVICE_SPI;
  49. default:
  50. printf("Invalid boot device (bsel=%08x)!\n", bsel);
  51. hang();
  52. }
  53. }
  54. #ifdef CONFIG_SPL_MMC_SUPPORT
  55. u32 spl_boot_mode(const u32 boot_device)
  56. {
  57. #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
  58. return MMCSD_MODE_FS;
  59. #else
  60. return MMCSD_MODE_RAW;
  61. #endif
  62. }
  63. #endif
  64. static void socfpga_nic301_slave_ns(void)
  65. {
  66. writel(0x1, &nic301_regs->lwhps2fpgaregs);
  67. writel(0x1, &nic301_regs->hps2fpgaregs);
  68. writel(0x1, &nic301_regs->acp);
  69. writel(0x1, &nic301_regs->rom);
  70. writel(0x1, &nic301_regs->ocram);
  71. writel(0x1, &nic301_regs->sdrdata);
  72. }
  73. void board_init_f(ulong dummy)
  74. {
  75. #ifndef CONFIG_SOCFPGA_VIRTUAL_TARGET
  76. const struct cm_config *cm_default_cfg = cm_get_default_config();
  77. #endif
  78. unsigned long sdram_size;
  79. unsigned long reg;
  80. /*
  81. * First C code to run. Clear fake OCRAM ECC first as SBE
  82. * and DBE might triggered during power on
  83. */
  84. reg = readl(&sysmgr_regs->eccgrp_ocram);
  85. if (reg & SYSMGR_ECC_OCRAM_SERR)
  86. writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
  87. &sysmgr_regs->eccgrp_ocram);
  88. if (reg & SYSMGR_ECC_OCRAM_DERR)
  89. writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
  90. &sysmgr_regs->eccgrp_ocram);
  91. memset(__bss_start, 0, __bss_end - __bss_start);
  92. socfpga_nic301_slave_ns();
  93. /* Configure ARM MPU SNSAC register. */
  94. setbits_le32(&scu_regs->sacr, 0xfff);
  95. /* Remap SDRAM to 0x0 */
  96. writel(0x1, &nic301_regs->remap); /* remap.mpuzero */
  97. writel(0x1, &pl310->pl310_addr_filter_start);
  98. #ifndef CONFIG_SOCFPGA_VIRTUAL_TARGET
  99. debug("Freezing all I/O banks\n");
  100. /* freeze all IO banks */
  101. sys_mgr_frzctrl_freeze_req();
  102. /* Put everything into reset but L4WD0. */
  103. socfpga_per_reset_all();
  104. /* Put FPGA bridges into reset too. */
  105. socfpga_bridges_reset(1);
  106. socfpga_per_reset(SOCFPGA_RESET(SDR), 0);
  107. socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
  108. socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
  109. timer_init();
  110. debug("Reconfigure Clock Manager\n");
  111. /* reconfigure the PLLs */
  112. cm_basic_init(cm_default_cfg);
  113. /* Enable bootrom to configure IOs. */
  114. sysmgr_config_warmrstcfgio(1);
  115. /* configure the IOCSR / IO buffer settings */
  116. if (scan_mgr_configure_iocsr())
  117. hang();
  118. sysmgr_config_warmrstcfgio(0);
  119. /* configure the pin muxing through system manager */
  120. sysmgr_config_warmrstcfgio(1);
  121. sysmgr_pinmux_init();
  122. sysmgr_config_warmrstcfgio(0);
  123. #endif /* CONFIG_SOCFPGA_VIRTUAL_TARGET */
  124. /* De-assert reset for peripherals and bridges based on handoff */
  125. reset_deassert_peripherals_handoff();
  126. socfpga_bridges_reset(0);
  127. debug("Unfreezing/Thaw all I/O banks\n");
  128. /* unfreeze / thaw all IO banks */
  129. sys_mgr_frzctrl_thaw_req();
  130. /* enable console uart printing */
  131. preloader_console_init();
  132. if (sdram_mmr_init_full(0xffffffff) != 0) {
  133. puts("SDRAM init failed.\n");
  134. hang();
  135. }
  136. debug("SDRAM: Calibrating PHY\n");
  137. /* SDRAM calibration */
  138. if (sdram_calibration_full() == 0) {
  139. puts("SDRAM calibration failed.\n");
  140. hang();
  141. }
  142. sdram_size = sdram_calculate_size();
  143. debug("SDRAM: %ld MiB\n", sdram_size >> 20);
  144. /* Sanity check ensure correct SDRAM size specified */
  145. if (get_ram_size(0, sdram_size) != sdram_size) {
  146. puts("SDRAM size check failed!\n");
  147. hang();
  148. }
  149. socfpga_bridges_reset(1);
  150. /* Configure simple malloc base pointer into RAM. */
  151. gd->malloc_base = CONFIG_SYS_TEXT_BASE + (1024 * 1024);
  152. }