spl_s10.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
  4. *
  5. */
  6. #include <asm/io.h>
  7. #include <asm/u-boot.h>
  8. #include <asm/utils.h>
  9. #include <common.h>
  10. #include <debug_uart.h>
  11. #include <image.h>
  12. #include <spl.h>
  13. #include <asm/arch/clock_manager.h>
  14. #include <asm/arch/firewall_s10.h>
  15. #include <asm/arch/mailbox_s10.h>
  16. #include <asm/arch/reset_manager.h>
  17. #include <asm/arch/sdram_s10.h>
  18. #include <asm/arch/system_manager.h>
  19. #include <watchdog.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. static struct socfpga_system_manager *sysmgr_regs =
  22. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  23. u32 spl_boot_device(void)
  24. {
  25. /* TODO: Get from SDM or handoff */
  26. return BOOT_DEVICE_MMC1;
  27. }
  28. #ifdef CONFIG_SPL_MMC_SUPPORT
  29. u32 spl_boot_mode(const u32 boot_device)
  30. {
  31. #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
  32. return MMCSD_MODE_FS;
  33. #else
  34. return MMCSD_MODE_RAW;
  35. #endif
  36. }
  37. #endif
  38. void spl_disable_firewall_l4_per(void)
  39. {
  40. const struct socfpga_firwall_l4_per *firwall_l4_per_base =
  41. (struct socfpga_firwall_l4_per *)SOCFPGA_FIREWALL_L4_PER;
  42. u32 i;
  43. const u32 *addr[] = {
  44. &firwall_l4_per_base->nand,
  45. &firwall_l4_per_base->nand_data,
  46. &firwall_l4_per_base->usb0,
  47. &firwall_l4_per_base->usb1,
  48. &firwall_l4_per_base->spim0,
  49. &firwall_l4_per_base->spim1,
  50. &firwall_l4_per_base->emac0,
  51. &firwall_l4_per_base->emac1,
  52. &firwall_l4_per_base->emac2,
  53. &firwall_l4_per_base->sdmmc,
  54. &firwall_l4_per_base->gpio0,
  55. &firwall_l4_per_base->gpio1,
  56. &firwall_l4_per_base->i2c0,
  57. &firwall_l4_per_base->i2c1,
  58. &firwall_l4_per_base->i2c2,
  59. &firwall_l4_per_base->i2c3,
  60. &firwall_l4_per_base->i2c4,
  61. &firwall_l4_per_base->timer0,
  62. &firwall_l4_per_base->timer1,
  63. &firwall_l4_per_base->uart0,
  64. &firwall_l4_per_base->uart1
  65. };
  66. /*
  67. * The following lines of code will enable non-secure access
  68. * to nand, usb, spi, emac, sdmmc, gpio, i2c, timers and uart. This
  69. * is needed as most OS run in non-secure mode. Thus we need to
  70. * enable non-secure access to these peripherals in order for the
  71. * OS to use these peripherals.
  72. */
  73. for (i = 0; i < ARRAY_SIZE(addr); i++)
  74. writel(FIREWALL_L4_DISABLE_ALL, addr[i]);
  75. }
  76. void spl_disable_firewall_l4_sys(void)
  77. {
  78. const struct socfpga_firwall_l4_sys *firwall_l4_sys_base =
  79. (struct socfpga_firwall_l4_sys *)SOCFPGA_FIREWALL_L4_SYS;
  80. u32 i;
  81. const u32 *addr[] = {
  82. &firwall_l4_sys_base->dma_ecc,
  83. &firwall_l4_sys_base->emac0rx_ecc,
  84. &firwall_l4_sys_base->emac0tx_ecc,
  85. &firwall_l4_sys_base->emac1rx_ecc,
  86. &firwall_l4_sys_base->emac1tx_ecc,
  87. &firwall_l4_sys_base->emac2rx_ecc,
  88. &firwall_l4_sys_base->emac2tx_ecc,
  89. &firwall_l4_sys_base->nand_ecc,
  90. &firwall_l4_sys_base->nand_read_ecc,
  91. &firwall_l4_sys_base->nand_write_ecc,
  92. &firwall_l4_sys_base->ocram_ecc,
  93. &firwall_l4_sys_base->sdmmc_ecc,
  94. &firwall_l4_sys_base->usb0_ecc,
  95. &firwall_l4_sys_base->usb1_ecc,
  96. &firwall_l4_sys_base->clock_manager,
  97. &firwall_l4_sys_base->io_manager,
  98. &firwall_l4_sys_base->reset_manager,
  99. &firwall_l4_sys_base->system_manager,
  100. &firwall_l4_sys_base->watchdog0,
  101. &firwall_l4_sys_base->watchdog1,
  102. &firwall_l4_sys_base->watchdog2,
  103. &firwall_l4_sys_base->watchdog3
  104. };
  105. for (i = 0; i < ARRAY_SIZE(addr); i++)
  106. writel(FIREWALL_L4_DISABLE_ALL, addr[i]);
  107. }
  108. void board_init_f(ulong dummy)
  109. {
  110. const struct cm_config *cm_default_cfg = cm_get_default_config();
  111. int ret;
  112. #ifdef CONFIG_HW_WATCHDOG
  113. /* Ensure watchdog is paused when debugging is happening */
  114. writel(SYSMGR_WDDBG_PAUSE_ALL_CPU, &sysmgr_regs->wddbg);
  115. /* Enable watchdog before initializing the HW */
  116. socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
  117. socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
  118. hw_watchdog_init();
  119. #endif
  120. /* ensure all processors are not released prior Linux boot */
  121. writeq(0, CPU_RELEASE_ADDR);
  122. socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
  123. timer_init();
  124. sysmgr_pinmux_init();
  125. /* configuring the HPS clocks */
  126. cm_basic_init(cm_default_cfg);
  127. #ifdef CONFIG_DEBUG_UART
  128. socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
  129. debug_uart_init();
  130. #endif
  131. ret = spl_early_init();
  132. if (ret) {
  133. debug("spl_early_init() failed: %d\n", ret);
  134. hang();
  135. }
  136. preloader_console_init();
  137. cm_print_clock_quick_summary();
  138. /* enable non-secure interface to DMA330 DMA and peripherals */
  139. writel(SYSMGR_DMA_IRQ_NS | SYSMGR_DMA_MGR_NS, &sysmgr_regs->dma);
  140. writel(SYSMGR_DMAPERIPH_ALL_NS, &sysmgr_regs->dma_periph);
  141. spl_disable_firewall_l4_per();
  142. spl_disable_firewall_l4_sys();
  143. /* disable lwsocf2fpga and soc2fpga bridge security */
  144. writel(FIREWALL_BRIDGE_DISABLE_ALL, SOCFPGA_FIREWALL_SOC2FPGA);
  145. writel(FIREWALL_BRIDGE_DISABLE_ALL, SOCFPGA_FIREWALL_LWSOC2FPGA);
  146. /* disable SMMU security */
  147. writel(FIREWALL_L4_DISABLE_ALL, SOCFPGA_FIREWALL_TCU);
  148. /* disable ocram security at CCU for non secure access */
  149. clrbits_le32(CCU_REG_ADDR(CCU_CPU0_MPRT_ADMASK_MEM_RAM0),
  150. CCU_ADMASK_P_MASK | CCU_ADMASK_NS_MASK);
  151. clrbits_le32(CCU_REG_ADDR(CCU_IOM_MPRT_ADMASK_MEM_RAM0),
  152. CCU_ADMASK_P_MASK | CCU_ADMASK_NS_MASK);
  153. debug("DDR: Initializing Hard Memory Controller\n");
  154. if (sdram_mmr_init_full(0)) {
  155. puts("DDR: Initialization failed.\n");
  156. hang();
  157. }
  158. gd->ram_size = sdram_calculate_size();
  159. printf("DDR: %d MiB\n", (int)(gd->ram_size >> 20));
  160. /* Sanity check ensure correct SDRAM size specified */
  161. debug("DDR: Running SDRAM size sanity check\n");
  162. if (get_ram_size(0, gd->ram_size) != gd->ram_size) {
  163. puts("DDR: SDRAM size check failed!\n");
  164. hang();
  165. }
  166. debug("DDR: SDRAM size check passed!\n");
  167. mbox_init();
  168. #ifdef CONFIG_CADENCE_QSPI
  169. mbox_qspi_open();
  170. #endif
  171. }