misc.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 <altera.h>
  9. #include <miiphy.h>
  10. #include <netdev.h>
  11. #include <watchdog.h>
  12. #include <asm/arch/reset_manager.h>
  13. #include <asm/arch/system_manager.h>
  14. #include <asm/arch/dwmmc.h>
  15. #include <asm/arch/nic301.h>
  16. #include <asm/arch/scu.h>
  17. #include <asm/pl310.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. static struct pl310_regs *const pl310 =
  20. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  21. static struct socfpga_system_manager *sysmgr_regs =
  22. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  23. static struct socfpga_reset_manager *reset_manager_base =
  24. (struct socfpga_reset_manager *)SOCFPGA_RSTMGR_ADDRESS;
  25. static struct nic301_registers *nic301_regs =
  26. (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS;
  27. static struct scu_registers *scu_regs =
  28. (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS;
  29. int dram_init(void)
  30. {
  31. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  32. return 0;
  33. }
  34. void enable_caches(void)
  35. {
  36. #ifndef CONFIG_SYS_ICACHE_OFF
  37. icache_enable();
  38. #endif
  39. #ifndef CONFIG_SYS_DCACHE_OFF
  40. dcache_enable();
  41. #endif
  42. }
  43. /*
  44. * DesignWare Ethernet initialization
  45. */
  46. #ifdef CONFIG_ETH_DESIGNWARE
  47. int cpu_eth_init(bd_t *bis)
  48. {
  49. #if CONFIG_EMAC_BASE == SOCFPGA_EMAC0_ADDRESS
  50. const int physhift = SYSMGR_EMACGRP_CTRL_PHYSEL0_LSB;
  51. #elif CONFIG_EMAC_BASE == SOCFPGA_EMAC1_ADDRESS
  52. const int physhift = SYSMGR_EMACGRP_CTRL_PHYSEL1_LSB;
  53. #else
  54. #error "Incorrect CONFIG_EMAC_BASE value!"
  55. #endif
  56. /* Initialize EMAC. This needs to be done at least once per boot. */
  57. /*
  58. * Putting the EMAC controller to reset when configuring the PHY
  59. * interface select at System Manager
  60. */
  61. socfpga_emac_reset(1);
  62. /* Clearing emac0 PHY interface select to 0 */
  63. clrbits_le32(&sysmgr_regs->emacgrp_ctrl,
  64. SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << physhift);
  65. /* configure to PHY interface select choosed */
  66. setbits_le32(&sysmgr_regs->emacgrp_ctrl,
  67. SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII << physhift);
  68. /* Release the EMAC controller from reset */
  69. socfpga_emac_reset(0);
  70. /* initialize and register the emac */
  71. return designware_initialize(CONFIG_EMAC_BASE,
  72. CONFIG_PHY_INTERFACE_MODE);
  73. }
  74. #endif
  75. #ifdef CONFIG_DWMMC
  76. /*
  77. * Initializes MMC controllers.
  78. * to override, implement board_mmc_init()
  79. */
  80. int cpu_mmc_init(bd_t *bis)
  81. {
  82. return socfpga_dwmmc_init(SOCFPGA_SDMMC_ADDRESS,
  83. CONFIG_HPS_SDMMC_BUSWIDTH, 0);
  84. }
  85. #endif
  86. #if defined(CONFIG_DISPLAY_CPUINFO)
  87. /*
  88. * Print CPU information
  89. */
  90. int print_cpuinfo(void)
  91. {
  92. puts("CPU: Altera SoCFPGA Platform\n");
  93. return 0;
  94. }
  95. #endif
  96. #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
  97. defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
  98. int overwrite_console(void)
  99. {
  100. return 0;
  101. }
  102. #endif
  103. #ifdef CONFIG_FPGA
  104. /*
  105. * FPGA programming support for SoC FPGA Cyclone V
  106. */
  107. static Altera_desc altera_fpga[] = {
  108. {
  109. /* Family */
  110. Altera_SoCFPGA,
  111. /* Interface type */
  112. fast_passive_parallel,
  113. /* No limitation as additional data will be ignored */
  114. -1,
  115. /* No device function table */
  116. NULL,
  117. /* Base interface address specified in driver */
  118. NULL,
  119. /* No cookie implementation */
  120. 0
  121. },
  122. };
  123. /* add device descriptor to FPGA device table */
  124. static void socfpga_fpga_add(void)
  125. {
  126. int i;
  127. fpga_init();
  128. for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  129. fpga_add(fpga_altera, &altera_fpga[i]);
  130. }
  131. #else
  132. static inline void socfpga_fpga_add(void) {}
  133. #endif
  134. int arch_cpu_init(void)
  135. {
  136. #ifdef CONFIG_HW_WATCHDOG
  137. /*
  138. * In case the watchdog is enabled, make sure to (re-)configure it
  139. * so that the defined timeout is valid. Otherwise the SPL (Perloader)
  140. * timeout value is still active which might too short for Linux
  141. * booting.
  142. */
  143. hw_watchdog_init();
  144. #else
  145. /*
  146. * If the HW watchdog is NOT enabled, make sure it is not running,
  147. * for example because it was enabled in the preloader. This might
  148. * trigger a watchdog-triggered reboot of Linux kernel later.
  149. */
  150. socfpga_watchdog_reset();
  151. #endif
  152. return 0;
  153. }
  154. /*
  155. * Convert all NIC-301 AMBA slaves from secure to non-secure
  156. */
  157. static void socfpga_nic301_slave_ns(void)
  158. {
  159. writel(0x1, &nic301_regs->lwhps2fpgaregs);
  160. writel(0x1, &nic301_regs->hps2fpgaregs);
  161. writel(0x1, &nic301_regs->acp);
  162. writel(0x1, &nic301_regs->rom);
  163. writel(0x1, &nic301_regs->ocram);
  164. writel(0x1, &nic301_regs->sdrdata);
  165. }
  166. static uint32_t iswgrp_handoff[8];
  167. int arch_early_init_r(void)
  168. {
  169. int i;
  170. for (i = 0; i < 8; i++) /* Cache initial SW setting regs */
  171. iswgrp_handoff[i] = readl(&sysmgr_regs->iswgrp_handoff[i]);
  172. socfpga_bridges_reset(1);
  173. socfpga_nic301_slave_ns();
  174. /*
  175. * Private components security:
  176. * U-Boot : configure private timer, global timer and cpu component
  177. * access as non secure for kernel stage (as required by Linux)
  178. */
  179. setbits_le32(&scu_regs->sacr, 0xfff);
  180. /* Configure the L2 controller to make SDRAM start at 0 */
  181. #ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
  182. writel(0x2, &nic301_regs->remap);
  183. #else
  184. writel(0x1, &nic301_regs->remap); /* remap.mpuzero */
  185. writel(0x1, &pl310->pl310_addr_filter_start);
  186. #endif
  187. /* Add device descriptor to FPGA device table */
  188. socfpga_fpga_add();
  189. #ifdef CONFIG_DESIGNWARE_SPI
  190. /* Get Designware SPI controller out of reset */
  191. socfpga_spim_enable();
  192. #endif
  193. return 0;
  194. }
  195. static void socfpga_sdram_apply_static_cfg(void)
  196. {
  197. const uint32_t staticcfg = SOCFPGA_SDR_ADDRESS + 0x505c;
  198. const uint32_t applymask = 0x8;
  199. uint32_t val = readl(staticcfg) | applymask;
  200. /*
  201. * SDRAM staticcfg register specific:
  202. * When applying the register setting, the CPU must not access
  203. * SDRAM. Luckily for us, we can abuse i-cache here to help us
  204. * circumvent the SDRAM access issue. The idea is to make sure
  205. * that the code is in one full i-cache line by branching past
  206. * it and back. Once it is in the i-cache, we execute the core
  207. * of the code and apply the register settings.
  208. *
  209. * The code below uses 7 instructions, while the Cortex-A9 has
  210. * 32-byte cachelines, thus the limit is 8 instructions total.
  211. */
  212. asm volatile(
  213. ".align 5 \n"
  214. " b 2f \n"
  215. "1: str %0, [%1] \n"
  216. " dsb \n"
  217. " isb \n"
  218. " b 3f \n"
  219. "2: b 1b \n"
  220. "3: nop \n"
  221. : : "r"(val), "r"(staticcfg) : "memory", "cc");
  222. }
  223. int do_bridge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  224. {
  225. if (argc != 2)
  226. return CMD_RET_USAGE;
  227. argv++;
  228. switch (*argv[0]) {
  229. case 'e': /* Enable */
  230. writel(iswgrp_handoff[2], &sysmgr_regs->fpgaintfgrp_module);
  231. socfpga_sdram_apply_static_cfg();
  232. writel(iswgrp_handoff[3], SOCFPGA_SDR_ADDRESS + 0x5080);
  233. writel(iswgrp_handoff[0], &reset_manager_base->brg_mod_reset);
  234. writel(iswgrp_handoff[1], &nic301_regs->remap);
  235. break;
  236. case 'd': /* Disable */
  237. writel(0, &sysmgr_regs->fpgaintfgrp_module);
  238. writel(0, SOCFPGA_SDR_ADDRESS + 0x5080);
  239. socfpga_sdram_apply_static_cfg();
  240. writel(0, &reset_manager_base->brg_mod_reset);
  241. writel(1, &nic301_regs->remap);
  242. break;
  243. default:
  244. return CMD_RET_USAGE;
  245. }
  246. return 0;
  247. }
  248. U_BOOT_CMD(
  249. bridge, 2, 1, do_bridge,
  250. "SoCFPGA HPS FPGA bridge control",
  251. "enable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
  252. "bridge disable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
  253. ""
  254. );