misc_arria10.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2016-2017 Intel Corporation
  4. */
  5. #include <altera.h>
  6. #include <common.h>
  7. #include <errno.h>
  8. #include <fdtdec.h>
  9. #include <miiphy.h>
  10. #include <netdev.h>
  11. #include <ns16550.h>
  12. #include <watchdog.h>
  13. #include <asm/arch/misc.h>
  14. #include <asm/arch/pinmux.h>
  15. #include <asm/arch/reset_manager.h>
  16. #include <asm/arch/sdram_arria10.h>
  17. #include <asm/arch/system_manager.h>
  18. #include <asm/arch/nic301.h>
  19. #include <asm/io.h>
  20. #include <asm/pl310.h>
  21. #define PINMUX_UART0_TX_SHARED_IO_OFFSET_Q1_3 0x08
  22. #define PINMUX_UART0_TX_SHARED_IO_OFFSET_Q2_11 0x58
  23. #define PINMUX_UART0_TX_SHARED_IO_OFFSET_Q3_3 0x68
  24. #define PINMUX_UART1_TX_SHARED_IO_OFFSET_Q1_7 0x18
  25. #define PINMUX_UART1_TX_SHARED_IO_OFFSET_Q3_7 0x78
  26. #define PINMUX_UART1_TX_SHARED_IO_OFFSET_Q4_3 0x98
  27. #if defined(CONFIG_SPL_BUILD)
  28. static struct pl310_regs *const pl310 =
  29. (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
  30. static const struct socfpga_noc_fw_ocram *noc_fw_ocram_base =
  31. (void *)SOCFPGA_SDR_FIREWALL_OCRAM_ADDRESS;
  32. #endif
  33. static struct socfpga_system_manager *sysmgr_regs =
  34. (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
  35. /*
  36. * DesignWare Ethernet initialization
  37. */
  38. #ifdef CONFIG_ETH_DESIGNWARE
  39. static void arria10_dwmac_reset(const u8 of_reset_id, const u8 phymode)
  40. {
  41. u32 reset;
  42. if (of_reset_id == EMAC0_RESET) {
  43. reset = SOCFPGA_RESET(EMAC0);
  44. } else if (of_reset_id == EMAC1_RESET) {
  45. reset = SOCFPGA_RESET(EMAC1);
  46. } else if (of_reset_id == EMAC2_RESET) {
  47. reset = SOCFPGA_RESET(EMAC2);
  48. } else {
  49. printf("GMAC: Invalid reset ID (%i)!\n", of_reset_id);
  50. return;
  51. }
  52. clrsetbits_le32(&sysmgr_regs->emac[of_reset_id - EMAC0_RESET],
  53. SYSMGR_EMACGRP_CTRL_PHYSEL_MASK,
  54. phymode);
  55. /* Release the EMAC controller from reset */
  56. socfpga_per_reset(reset, 0);
  57. }
  58. static int socfpga_eth_reset(void)
  59. {
  60. /* Put all GMACs into RESET state. */
  61. socfpga_per_reset(SOCFPGA_RESET(EMAC0), 1);
  62. socfpga_per_reset(SOCFPGA_RESET(EMAC1), 1);
  63. socfpga_per_reset(SOCFPGA_RESET(EMAC2), 1);
  64. return socfpga_eth_reset_common(arria10_dwmac_reset);
  65. };
  66. #else
  67. static int socfpga_eth_reset(void)
  68. {
  69. return 0;
  70. };
  71. #endif
  72. #if defined(CONFIG_SPL_BUILD)
  73. /*
  74. + * This function initializes security policies to be consistent across
  75. + * all logic units in the Arria 10.
  76. + *
  77. + * The idea is to set all security policies to be normal, nonsecure
  78. + * for all units.
  79. + */
  80. static void initialize_security_policies(void)
  81. {
  82. /* Put OCRAM in non-secure */
  83. writel(0x003f0000, &noc_fw_ocram_base->region0);
  84. writel(0x1, &noc_fw_ocram_base->enable);
  85. }
  86. int arch_early_init_r(void)
  87. {
  88. initialize_security_policies();
  89. /* Configure the L2 controller to make SDRAM start at 0 */
  90. writel(0x1, &pl310->pl310_addr_filter_start);
  91. /* assert reset to all except L4WD0 and L4TIMER0 */
  92. socfpga_per_reset_all();
  93. return 0;
  94. }
  95. #else
  96. int arch_early_init_r(void)
  97. {
  98. return 0;
  99. }
  100. #endif
  101. /*
  102. * This function looking the 1st encounter UART peripheral,
  103. * and then return its offset of the dedicated/shared IO pin
  104. * mux. offset value (zero and above).
  105. */
  106. static int find_peripheral_uart(const void *blob,
  107. int child, const char *node_name)
  108. {
  109. int len;
  110. fdt_addr_t base_addr = 0;
  111. fdt_size_t size;
  112. const u32 *cell;
  113. u32 value, offset = 0;
  114. base_addr = fdtdec_get_addr_size(blob, child, "reg", &size);
  115. if (base_addr != FDT_ADDR_T_NONE) {
  116. cell = fdt_getprop(blob, child, "pinctrl-single,pins",
  117. &len);
  118. if (cell != NULL) {
  119. for (; len > 0; len -= (2 * sizeof(u32))) {
  120. offset = fdt32_to_cpu(*cell++);
  121. value = fdt32_to_cpu(*cell++);
  122. /* Found UART peripheral. */
  123. if (value == PINMUX_UART)
  124. return offset;
  125. }
  126. }
  127. }
  128. return -EINVAL;
  129. }
  130. /*
  131. * This function looks up the 1st encounter UART peripheral,
  132. * and then return its offset of the dedicated/shared IO pin
  133. * mux. UART peripheral is found if the offset is not in negative
  134. * value.
  135. */
  136. static int is_peripheral_uart_true(const void *blob,
  137. int node, const char *child_name)
  138. {
  139. int child, len;
  140. const char *node_name;
  141. child = fdt_first_subnode(blob, node);
  142. if (child < 0)
  143. return -EINVAL;
  144. node_name = fdt_get_name(blob, child, &len);
  145. while (node_name) {
  146. if (!strcmp(child_name, node_name))
  147. return find_peripheral_uart(blob, child, node_name);
  148. child = fdt_next_subnode(blob, child);
  149. if (child < 0)
  150. break;
  151. node_name = fdt_get_name(blob, child, &len);
  152. }
  153. return -1;
  154. }
  155. /*
  156. * This function looking the 1st encounter UART dedicated IO peripheral,
  157. * and then return based address of the 1st encounter UART dedicated
  158. * IO peripheral.
  159. */
  160. unsigned int dedicated_uart_com_port(const void *blob)
  161. {
  162. int node;
  163. node = fdtdec_next_compatible(blob, 0,
  164. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE);
  165. if (node < 0)
  166. return 0;
  167. if (is_peripheral_uart_true(blob, node, "dedicated") >= 0)
  168. return SOCFPGA_UART1_ADDRESS;
  169. return 0;
  170. }
  171. /*
  172. * This function looking the 1st encounter UART shared IO peripheral, and then
  173. * return based address of the 1st encounter UART shared IO peripheral.
  174. */
  175. unsigned int shared_uart_com_port(const void *blob)
  176. {
  177. int node, ret;
  178. node = fdtdec_next_compatible(blob, 0,
  179. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE);
  180. if (node < 0)
  181. return 0;
  182. ret = is_peripheral_uart_true(blob, node, "shared");
  183. if (ret == PINMUX_UART0_TX_SHARED_IO_OFFSET_Q1_3 ||
  184. ret == PINMUX_UART0_TX_SHARED_IO_OFFSET_Q2_11 ||
  185. ret == PINMUX_UART0_TX_SHARED_IO_OFFSET_Q3_3)
  186. return SOCFPGA_UART0_ADDRESS;
  187. else if (ret == PINMUX_UART1_TX_SHARED_IO_OFFSET_Q1_7 ||
  188. ret == PINMUX_UART1_TX_SHARED_IO_OFFSET_Q3_7 ||
  189. ret == PINMUX_UART1_TX_SHARED_IO_OFFSET_Q4_3)
  190. return SOCFPGA_UART1_ADDRESS;
  191. return 0;
  192. }
  193. /*
  194. * This function looking the 1st encounter UART peripheral, and then return
  195. * base address of the 1st encounter UART peripheral.
  196. */
  197. unsigned int uart_com_port(const void *blob)
  198. {
  199. unsigned int ret;
  200. ret = dedicated_uart_com_port(blob);
  201. if (ret)
  202. return ret;
  203. return shared_uart_com_port(blob);
  204. }
  205. /*
  206. * Print CPU information
  207. */
  208. #if defined(CONFIG_DISPLAY_CPUINFO)
  209. int print_cpuinfo(void)
  210. {
  211. const u32 bsel =
  212. SYSMGR_GET_BOOTINFO_BSEL(readl(&sysmgr_regs->bootinfo));
  213. puts("CPU: Altera SoCFPGA Arria 10\n");
  214. printf("BOOT: %s\n", bsel_str[bsel].name);
  215. return 0;
  216. }
  217. #endif
  218. #ifdef CONFIG_ARCH_MISC_INIT
  219. int arch_misc_init(void)
  220. {
  221. return socfpga_eth_reset();
  222. }
  223. #endif