misc_arria10.c 6.0 KB

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