misc.c 6.6 KB

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