misc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
  4. */
  5. #include <common.h>
  6. #include <asm/io.h>
  7. #include <errno.h>
  8. #include <fdtdec.h>
  9. #include <linux/libfdt.h>
  10. #include <altera.h>
  11. #include <miiphy.h>
  12. #include <netdev.h>
  13. #include <watchdog.h>
  14. #include <asm/arch/misc.h>
  15. #include <asm/arch/reset_manager.h>
  16. #include <asm/arch/scan_manager.h>
  17. #include <asm/arch/system_manager.h>
  18. #include <asm/arch/nic301.h>
  19. #include <asm/arch/scu.h>
  20. #include <asm/pl310.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. #ifdef CONFIG_SYS_L2_PL310
  23. static const struct pl310_regs *const pl310 =
  24. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  25. #endif
  26. struct bsel bsel_str[] = {
  27. { "rsvd", "Reserved", },
  28. { "fpga", "FPGA (HPS2FPGA Bridge)", },
  29. { "nand", "NAND Flash (1.8V)", },
  30. { "nand", "NAND Flash (3.0V)", },
  31. { "sd", "SD/MMC External Transceiver (1.8V)", },
  32. { "sd", "SD/MMC Internal Transceiver (3.0V)", },
  33. { "qspi", "QSPI Flash (1.8V)", },
  34. { "qspi", "QSPI Flash (3.0V)", },
  35. };
  36. int dram_init(void)
  37. {
  38. if (fdtdec_setup_mem_size_base() != 0)
  39. return -EINVAL;
  40. return 0;
  41. }
  42. void enable_caches(void)
  43. {
  44. #ifndef CONFIG_SYS_ICACHE_OFF
  45. icache_enable();
  46. #endif
  47. #ifndef CONFIG_SYS_DCACHE_OFF
  48. dcache_enable();
  49. #endif
  50. }
  51. #ifdef CONFIG_SYS_L2_PL310
  52. void v7_outer_cache_enable(void)
  53. {
  54. /* Disable the L2 cache */
  55. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  56. /* enable BRESP, instruction and data prefetch, full line of zeroes */
  57. setbits_le32(&pl310->pl310_aux_ctrl,
  58. L310_AUX_CTRL_DATA_PREFETCH_MASK |
  59. L310_AUX_CTRL_INST_PREFETCH_MASK |
  60. L310_SHARED_ATT_OVERRIDE_ENABLE);
  61. /* Enable the L2 cache */
  62. setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  63. }
  64. void v7_outer_cache_disable(void)
  65. {
  66. /* Disable the L2 cache */
  67. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  68. }
  69. #endif
  70. #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
  71. defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
  72. int overwrite_console(void)
  73. {
  74. return 0;
  75. }
  76. #endif
  77. #ifdef CONFIG_FPGA
  78. /*
  79. * FPGA programming support for SoC FPGA Cyclone V
  80. */
  81. static Altera_desc altera_fpga[] = {
  82. {
  83. /* Family */
  84. Altera_SoCFPGA,
  85. /* Interface type */
  86. fast_passive_parallel,
  87. /* No limitation as additional data will be ignored */
  88. -1,
  89. /* No device function table */
  90. NULL,
  91. /* Base interface address specified in driver */
  92. NULL,
  93. /* No cookie implementation */
  94. 0
  95. },
  96. };
  97. /* add device descriptor to FPGA device table */
  98. void socfpga_fpga_add(void)
  99. {
  100. int i;
  101. fpga_init();
  102. for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  103. fpga_add(fpga_altera, &altera_fpga[i]);
  104. }
  105. #endif
  106. int arch_cpu_init(void)
  107. {
  108. #ifdef CONFIG_HW_WATCHDOG
  109. /*
  110. * In case the watchdog is enabled, make sure to (re-)configure it
  111. * so that the defined timeout is valid. Otherwise the SPL (Perloader)
  112. * timeout value is still active which might too short for Linux
  113. * booting.
  114. */
  115. hw_watchdog_init();
  116. #else
  117. /*
  118. * If the HW watchdog is NOT enabled, make sure it is not running,
  119. * for example because it was enabled in the preloader. This might
  120. * trigger a watchdog-triggered reboot of Linux kernel later.
  121. * Toggle watchdog reset, so watchdog in not running state.
  122. */
  123. socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
  124. socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
  125. #endif
  126. return 0;
  127. }
  128. #ifdef CONFIG_ETH_DESIGNWARE
  129. static int dwmac_phymode_to_modereg(const char *phymode, u32 *modereg)
  130. {
  131. if (!phymode)
  132. return -EINVAL;
  133. if (!strcmp(phymode, "mii") || !strcmp(phymode, "gmii")) {
  134. *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
  135. return 0;
  136. }
  137. if (!strcmp(phymode, "rgmii")) {
  138. *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
  139. return 0;
  140. }
  141. if (!strcmp(phymode, "rmii")) {
  142. *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
  143. return 0;
  144. }
  145. return -EINVAL;
  146. }
  147. int socfpga_eth_reset_common(void (*resetfn)(const u8 of_reset_id,
  148. const u8 phymode))
  149. {
  150. const void *fdt = gd->fdt_blob;
  151. struct fdtdec_phandle_args args;
  152. const char *phy_mode;
  153. u32 phy_modereg;
  154. int nodes[2]; /* Max. two GMACs */
  155. int ret, count;
  156. int i, node;
  157. count = fdtdec_find_aliases_for_id(fdt, "ethernet",
  158. COMPAT_ALTERA_SOCFPGA_DWMAC,
  159. nodes, ARRAY_SIZE(nodes));
  160. for (i = 0; i < count; i++) {
  161. node = nodes[i];
  162. if (node <= 0)
  163. continue;
  164. ret = fdtdec_parse_phandle_with_args(fdt, node, "resets",
  165. "#reset-cells", 1, 0,
  166. &args);
  167. if (ret || (args.args_count != 1)) {
  168. debug("GMAC%i: Failed to parse DT 'resets'!\n", i);
  169. continue;
  170. }
  171. phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL);
  172. ret = dwmac_phymode_to_modereg(phy_mode, &phy_modereg);
  173. if (ret) {
  174. debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i);
  175. continue;
  176. }
  177. resetfn(args.args[0], phy_modereg);
  178. }
  179. return 0;
  180. }
  181. #endif
  182. #ifndef CONFIG_SPL_BUILD
  183. static int do_bridge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  184. {
  185. if (argc != 2)
  186. return CMD_RET_USAGE;
  187. argv++;
  188. switch (*argv[0]) {
  189. case 'e': /* Enable */
  190. do_bridge_reset(1);
  191. break;
  192. case 'd': /* Disable */
  193. do_bridge_reset(0);
  194. break;
  195. default:
  196. return CMD_RET_USAGE;
  197. }
  198. return 0;
  199. }
  200. U_BOOT_CMD(bridge, 2, 1, do_bridge,
  201. "SoCFPGA HPS FPGA bridge control",
  202. "enable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
  203. "bridge disable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
  204. ""
  205. );
  206. #endif