misc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  39. return 0;
  40. }
  41. void enable_caches(void)
  42. {
  43. #ifndef CONFIG_SYS_ICACHE_OFF
  44. icache_enable();
  45. #endif
  46. #ifndef CONFIG_SYS_DCACHE_OFF
  47. dcache_enable();
  48. #endif
  49. }
  50. #ifdef CONFIG_SYS_L2_PL310
  51. void v7_outer_cache_enable(void)
  52. {
  53. /* Disable the L2 cache */
  54. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  55. /* enable BRESP, instruction and data prefetch, full line of zeroes */
  56. setbits_le32(&pl310->pl310_aux_ctrl,
  57. L310_AUX_CTRL_DATA_PREFETCH_MASK |
  58. L310_AUX_CTRL_INST_PREFETCH_MASK |
  59. L310_SHARED_ATT_OVERRIDE_ENABLE);
  60. /* Enable the L2 cache */
  61. setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  62. }
  63. void v7_outer_cache_disable(void)
  64. {
  65. /* Disable the L2 cache */
  66. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  67. }
  68. #endif
  69. #if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
  70. defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
  71. int overwrite_console(void)
  72. {
  73. return 0;
  74. }
  75. #endif
  76. #ifdef CONFIG_FPGA
  77. /*
  78. * FPGA programming support for SoC FPGA Cyclone V
  79. */
  80. static Altera_desc altera_fpga[] = {
  81. {
  82. /* Family */
  83. Altera_SoCFPGA,
  84. /* Interface type */
  85. fast_passive_parallel,
  86. /* No limitation as additional data will be ignored */
  87. -1,
  88. /* No device function table */
  89. NULL,
  90. /* Base interface address specified in driver */
  91. NULL,
  92. /* No cookie implementation */
  93. 0
  94. },
  95. };
  96. /* add device descriptor to FPGA device table */
  97. void socfpga_fpga_add(void)
  98. {
  99. int i;
  100. fpga_init();
  101. for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  102. fpga_add(fpga_altera, &altera_fpga[i]);
  103. }
  104. #endif
  105. int arch_cpu_init(void)
  106. {
  107. #ifdef CONFIG_HW_WATCHDOG
  108. /*
  109. * In case the watchdog is enabled, make sure to (re-)configure it
  110. * so that the defined timeout is valid. Otherwise the SPL (Perloader)
  111. * timeout value is still active which might too short for Linux
  112. * booting.
  113. */
  114. hw_watchdog_init();
  115. #else
  116. /*
  117. * If the HW watchdog is NOT enabled, make sure it is not running,
  118. * for example because it was enabled in the preloader. This might
  119. * trigger a watchdog-triggered reboot of Linux kernel later.
  120. * Toggle watchdog reset, so watchdog in not running state.
  121. */
  122. socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
  123. socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
  124. #endif
  125. return 0;
  126. }
  127. #ifdef CONFIG_ETH_DESIGNWARE
  128. static int dwmac_phymode_to_modereg(const char *phymode, u32 *modereg)
  129. {
  130. if (!phymode)
  131. return -EINVAL;
  132. if (!strcmp(phymode, "mii") || !strcmp(phymode, "gmii")) {
  133. *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
  134. return 0;
  135. }
  136. if (!strcmp(phymode, "rgmii")) {
  137. *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
  138. return 0;
  139. }
  140. if (!strcmp(phymode, "rmii")) {
  141. *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
  142. return 0;
  143. }
  144. return -EINVAL;
  145. }
  146. int socfpga_eth_reset_common(void (*resetfn)(const u8 of_reset_id,
  147. const u8 phymode))
  148. {
  149. const void *fdt = gd->fdt_blob;
  150. struct fdtdec_phandle_args args;
  151. const char *phy_mode;
  152. u32 phy_modereg;
  153. int nodes[2]; /* Max. two GMACs */
  154. int ret, count;
  155. int i, node;
  156. count = fdtdec_find_aliases_for_id(fdt, "ethernet",
  157. COMPAT_ALTERA_SOCFPGA_DWMAC,
  158. nodes, ARRAY_SIZE(nodes));
  159. for (i = 0; i < count; i++) {
  160. node = nodes[i];
  161. if (node <= 0)
  162. continue;
  163. ret = fdtdec_parse_phandle_with_args(fdt, node, "resets",
  164. "#reset-cells", 1, 0,
  165. &args);
  166. if (ret || (args.args_count != 1)) {
  167. debug("GMAC%i: Failed to parse DT 'resets'!\n", i);
  168. continue;
  169. }
  170. phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL);
  171. ret = dwmac_phymode_to_modereg(phy_mode, &phy_modereg);
  172. if (ret) {
  173. debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i);
  174. continue;
  175. }
  176. resetfn(args.args[0], phy_modereg);
  177. }
  178. return 0;
  179. }
  180. #endif