misc_arria10.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. void dwmac_deassert_reset(const unsigned int of_reset_id,
  40. const u32 phymode)
  41. {
  42. u32 reset;
  43. if (of_reset_id == EMAC0_RESET) {
  44. reset = SOCFPGA_RESET(EMAC0);
  45. } else if (of_reset_id == EMAC1_RESET) {
  46. reset = SOCFPGA_RESET(EMAC1);
  47. } else if (of_reset_id == EMAC2_RESET) {
  48. reset = SOCFPGA_RESET(EMAC2);
  49. } else {
  50. printf("GMAC: Invalid reset ID (%i)!\n", of_reset_id);
  51. return;
  52. }
  53. clrsetbits_le32(&sysmgr_regs->emac[of_reset_id - EMAC0_RESET],
  54. SYSMGR_EMACGRP_CTRL_PHYSEL_MASK,
  55. phymode);
  56. /* Release the EMAC controller from reset */
  57. socfpga_per_reset(reset, 0);
  58. }
  59. #endif
  60. #if defined(CONFIG_SPL_BUILD)
  61. /*
  62. + * This function initializes security policies to be consistent across
  63. + * all logic units in the Arria 10.
  64. + *
  65. + * The idea is to set all security policies to be normal, nonsecure
  66. + * for all units.
  67. + */
  68. static void initialize_security_policies(void)
  69. {
  70. /* Put OCRAM in non-secure */
  71. writel(0x003f0000, &noc_fw_ocram_base->region0);
  72. writel(0x1, &noc_fw_ocram_base->enable);
  73. }
  74. int arch_early_init_r(void)
  75. {
  76. initialize_security_policies();
  77. /* Configure the L2 controller to make SDRAM start at 0 */
  78. writel(0x1, &pl310->pl310_addr_filter_start);
  79. /* assert reset to all except L4WD0 and L4TIMER0 */
  80. socfpga_per_reset_all();
  81. /* configuring the clock based on handoff */
  82. /* TODO: Add call to cm_basic_init() */
  83. /* Add device descriptor to FPGA device table */
  84. socfpga_fpga_add();
  85. return 0;
  86. }
  87. #else
  88. int arch_early_init_r(void)
  89. {
  90. return 0;
  91. }
  92. #endif
  93. /*
  94. * This function looking the 1st encounter UART peripheral,
  95. * and then return its offset of the dedicated/shared IO pin
  96. * mux. offset value (zero and above).
  97. */
  98. static int find_peripheral_uart(const void *blob,
  99. int child, const char *node_name)
  100. {
  101. int len;
  102. fdt_addr_t base_addr = 0;
  103. fdt_size_t size;
  104. const u32 *cell;
  105. u32 value, offset = 0;
  106. base_addr = fdtdec_get_addr_size(blob, child, "reg", &size);
  107. if (base_addr != FDT_ADDR_T_NONE) {
  108. cell = fdt_getprop(blob, child, "pinctrl-single,pins",
  109. &len);
  110. if (cell != NULL) {
  111. for (; len > 0; len -= (2 * sizeof(u32))) {
  112. offset = fdt32_to_cpu(*cell++);
  113. value = fdt32_to_cpu(*cell++);
  114. /* Found UART peripheral. */
  115. if (value == PINMUX_UART)
  116. return offset;
  117. }
  118. }
  119. }
  120. return -EINVAL;
  121. }
  122. /*
  123. * This function looks up the 1st encounter UART peripheral,
  124. * and then return its offset of the dedicated/shared IO pin
  125. * mux. UART peripheral is found if the offset is not in negative
  126. * value.
  127. */
  128. static int is_peripheral_uart_true(const void *blob,
  129. int node, const char *child_name)
  130. {
  131. int child, len;
  132. const char *node_name;
  133. child = fdt_first_subnode(blob, node);
  134. if (child < 0)
  135. return -EINVAL;
  136. node_name = fdt_get_name(blob, child, &len);
  137. while (node_name) {
  138. if (!strcmp(child_name, node_name))
  139. return find_peripheral_uart(blob, child, node_name);
  140. child = fdt_next_subnode(blob, child);
  141. if (child < 0)
  142. break;
  143. node_name = fdt_get_name(blob, child, &len);
  144. }
  145. return -1;
  146. }
  147. /*
  148. * This function looking the 1st encounter UART dedicated IO peripheral,
  149. * and then return based address of the 1st encounter UART dedicated
  150. * IO peripheral.
  151. */
  152. unsigned int dedicated_uart_com_port(const void *blob)
  153. {
  154. int node;
  155. node = fdtdec_next_compatible(blob, 0,
  156. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE);
  157. if (node < 0)
  158. return 0;
  159. if (is_peripheral_uart_true(blob, node, "dedicated") >= 0)
  160. return SOCFPGA_UART1_ADDRESS;
  161. return 0;
  162. }
  163. /*
  164. * This function looking the 1st encounter UART shared IO peripheral, and then
  165. * return based address of the 1st encounter UART shared IO peripheral.
  166. */
  167. unsigned int shared_uart_com_port(const void *blob)
  168. {
  169. int node, ret;
  170. node = fdtdec_next_compatible(blob, 0,
  171. COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE);
  172. if (node < 0)
  173. return 0;
  174. ret = is_peripheral_uart_true(blob, node, "shared");
  175. if (ret == PINMUX_UART0_TX_SHARED_IO_OFFSET_Q1_3 ||
  176. ret == PINMUX_UART0_TX_SHARED_IO_OFFSET_Q2_11 ||
  177. ret == PINMUX_UART0_TX_SHARED_IO_OFFSET_Q3_3)
  178. return SOCFPGA_UART0_ADDRESS;
  179. else if (ret == PINMUX_UART1_TX_SHARED_IO_OFFSET_Q1_7 ||
  180. ret == PINMUX_UART1_TX_SHARED_IO_OFFSET_Q3_7 ||
  181. ret == PINMUX_UART1_TX_SHARED_IO_OFFSET_Q4_3)
  182. return SOCFPGA_UART1_ADDRESS;
  183. return 0;
  184. }
  185. /*
  186. * This function looking the 1st encounter UART peripheral, and then return
  187. * base address of the 1st encounter UART peripheral.
  188. */
  189. unsigned int uart_com_port(const void *blob)
  190. {
  191. unsigned int ret;
  192. ret = dedicated_uart_com_port(blob);
  193. if (ret)
  194. return ret;
  195. return shared_uart_com_port(blob);
  196. }
  197. /*
  198. * Print CPU information
  199. */
  200. #if defined(CONFIG_DISPLAY_CPUINFO)
  201. int print_cpuinfo(void)
  202. {
  203. const u32 bsel =
  204. SYSMGR_GET_BOOTINFO_BSEL(readl(&sysmgr_regs->bootinfo));
  205. puts("CPU: Altera SoCFPGA Arria 10\n");
  206. printf("BOOT: %s\n", bsel_str[bsel].name);
  207. return 0;
  208. }
  209. #endif
  210. #ifdef CONFIG_ARCH_MISC_INIT
  211. int arch_misc_init(void)
  212. {
  213. return 0;
  214. }
  215. #endif