spl.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. DECLARE_GLOBAL_DATA_PTR;
  20. static struct pl310_regs *const pl310 =
  21. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  22. void board_init_f(ulong dummy)
  23. {
  24. struct socfpga_system_manager *sysmgr_regs =
  25. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  26. unsigned long reg;
  27. /*
  28. * First C code to run. Clear fake OCRAM ECC first as SBE
  29. * and DBE might triggered during power on
  30. */
  31. reg = readl(&sysmgr_regs->eccgrp_ocram);
  32. if (reg & SYSMGR_ECC_OCRAM_SERR)
  33. writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
  34. &sysmgr_regs->eccgrp_ocram);
  35. if (reg & SYSMGR_ECC_OCRAM_DERR)
  36. writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
  37. &sysmgr_regs->eccgrp_ocram);
  38. memset(__bss_start, 0, __bss_end - __bss_start);
  39. /* Remap SDRAM to 0x0 */
  40. writel(0x1, &pl310->pl310_addr_filter_start);
  41. board_init_r(NULL, 0);
  42. }
  43. u32 spl_boot_device(void)
  44. {
  45. return BOOT_DEVICE_RAM;
  46. }
  47. /*
  48. * Board initialization after bss clearance
  49. */
  50. void spl_board_init(void)
  51. {
  52. unsigned long sdram_size;
  53. #ifndef CONFIG_SOCFPGA_VIRTUAL_TARGET
  54. const struct cm_config *cm_default_cfg = cm_get_default_config();
  55. #endif
  56. debug("Freezing all I/O banks\n");
  57. /* freeze all IO banks */
  58. sys_mgr_frzctrl_freeze_req();
  59. socfpga_per_reset(SOCFPGA_RESET(SDR), 0);
  60. socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
  61. socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
  62. timer_init();
  63. debug("Reconfigure Clock Manager\n");
  64. /* reconfigure the PLLs */
  65. cm_basic_init(cm_default_cfg);
  66. /* Enable bootrom to configure IOs. */
  67. sysmgr_enable_warmrstcfgio();
  68. /* configure the IOCSR / IO buffer settings */
  69. if (scan_mgr_configure_iocsr())
  70. hang();
  71. /* configure the pin muxing through system manager */
  72. sysmgr_pinmux_init();
  73. #endif /* CONFIG_SOCFPGA_VIRTUAL_TARGET */
  74. /* de-assert reset for peripherals and bridges based on handoff */
  75. reset_deassert_peripherals_handoff();
  76. debug("Unfreezing/Thaw all I/O banks\n");
  77. /* unfreeze / thaw all IO banks */
  78. sys_mgr_frzctrl_thaw_req();
  79. /* enable console uart printing */
  80. preloader_console_init();
  81. if (sdram_mmr_init_full(0xffffffff) != 0) {
  82. puts("SDRAM init failed.\n");
  83. hang();
  84. }
  85. debug("SDRAM: Calibrating PHY\n");
  86. /* SDRAM calibration */
  87. if (sdram_calibration_full() == 0) {
  88. puts("SDRAM calibration failed.\n");
  89. hang();
  90. }
  91. sdram_size = sdram_calculate_size();
  92. debug("SDRAM: %ld MiB\n", sdram_size >> 20);
  93. /* Sanity check ensure correct SDRAM size specified */
  94. if (get_ram_size(0, sdram_size) != sdram_size) {
  95. puts("SDRAM size check failed!\n");
  96. hang();
  97. }
  98. }