spl_gen5.c 4.1 KB

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