platform.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ARC HSDK Platform support code
  4. *
  5. * Copyright (C) 2017 Synopsys, Inc. (www.synopsys.com)
  6. */
  7. #include <linux/init.h>
  8. #include <linux/of_fdt.h>
  9. #include <linux/libfdt.h>
  10. #include <linux/smp.h>
  11. #include <asm/arcregs.h>
  12. #include <asm/io.h>
  13. #include <asm/mach_desc.h>
  14. int arc_hsdk_axi_dmac_coherent __section(".data") = 0;
  15. #define ARC_CCM_UNUSED_ADDR 0x60000000
  16. #define ARC_PERIPHERAL_BASE 0xf0000000
  17. #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
  18. #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
  19. #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
  20. #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
  21. #define HSDK_GPIO_INTC (ARC_PERIPHERAL_BASE + 0x3000)
  22. static void __init hsdk_enable_gpio_intc_wire(void)
  23. {
  24. /*
  25. * Peripherals on CPU Card are wired to cpu intc via intermediate
  26. * DW APB GPIO blocks (mainly for debouncing)
  27. *
  28. * ---------------------
  29. * | snps,archs-intc |
  30. * ---------------------
  31. * |
  32. * ----------------------
  33. * | snps,archs-idu-intc |
  34. * ----------------------
  35. * | | | | |
  36. * | [eth] [USB] [... other peripherals]
  37. * |
  38. * -------------------
  39. * | snps,dw-apb-intc |
  40. * -------------------
  41. * | | | |
  42. * [Bt] [HAPS] [... other peripherals]
  43. *
  44. * Current implementation of "irq-dw-apb-ictl" driver doesn't work well
  45. * with stacked INTCs. In particular problem happens if its master INTC
  46. * not yet instantiated. See discussion here -
  47. * https://lore.kernel.org/lkml/[email protected]
  48. *
  49. * So setup the first gpio block as a passive pass thru and hide it from
  50. * DT hardware topology - connect intc directly to cpu intc
  51. * The GPIO "wire" needs to be init nevertheless (here)
  52. *
  53. * One side adv is that peripheral interrupt handling avoids one nested
  54. * intc ISR hop
  55. *
  56. * According to HSDK User's Manual [1], "Table 2 Interrupt Mapping"
  57. * we have the following GPIO input lines used as sources of interrupt:
  58. * - GPIO[0] - Bluetooth interrupt of RS9113 module
  59. * - GPIO[2] - HAPS interrupt (on HapsTrak 3 connector)
  60. * - GPIO[3] - Audio codec (MAX9880A) interrupt
  61. * - GPIO[8-23] - Available on Arduino and PMOD_x headers
  62. * For now there's no use of Arduino and PMOD_x headers in Linux
  63. * use-case so we only enable lines 0, 2 and 3.
  64. *
  65. * [1] https://github.com/foss-for-synopsys-dwc-arc-processors/ARC-Development-Systems-Forum/wiki/docs/ARC_HSDK_User_Guide.pdf
  66. */
  67. #define GPIO_INTEN (HSDK_GPIO_INTC + 0x30)
  68. #define GPIO_INTMASK (HSDK_GPIO_INTC + 0x34)
  69. #define GPIO_INTTYPE_LEVEL (HSDK_GPIO_INTC + 0x38)
  70. #define GPIO_INT_POLARITY (HSDK_GPIO_INTC + 0x3c)
  71. #define GPIO_INT_CONNECTED_MASK 0x0d
  72. iowrite32(0xffffffff, (void __iomem *) GPIO_INTMASK);
  73. iowrite32(~GPIO_INT_CONNECTED_MASK, (void __iomem *) GPIO_INTMASK);
  74. iowrite32(0x00000000, (void __iomem *) GPIO_INTTYPE_LEVEL);
  75. iowrite32(0xffffffff, (void __iomem *) GPIO_INT_POLARITY);
  76. iowrite32(GPIO_INT_CONNECTED_MASK, (void __iomem *) GPIO_INTEN);
  77. }
  78. static int __init hsdk_tweak_node_coherency(const char *path, bool coherent)
  79. {
  80. void *fdt = initial_boot_params;
  81. const void *prop;
  82. int node, ret;
  83. bool dt_coh_set;
  84. node = fdt_path_offset(fdt, path);
  85. if (node < 0)
  86. goto tweak_fail;
  87. prop = fdt_getprop(fdt, node, "dma-coherent", &ret);
  88. if (!prop && ret != -FDT_ERR_NOTFOUND)
  89. goto tweak_fail;
  90. dt_coh_set = ret != -FDT_ERR_NOTFOUND;
  91. ret = 0;
  92. /* need to remove "dma-coherent" property */
  93. if (dt_coh_set && !coherent)
  94. ret = fdt_delprop(fdt, node, "dma-coherent");
  95. /* need to set "dma-coherent" property */
  96. if (!dt_coh_set && coherent)
  97. ret = fdt_setprop(fdt, node, "dma-coherent", NULL, 0);
  98. if (ret < 0)
  99. goto tweak_fail;
  100. return 0;
  101. tweak_fail:
  102. pr_err("failed to tweak %s to %scoherent\n", path, coherent ? "" : "non");
  103. return -EFAULT;
  104. }
  105. enum hsdk_axi_masters {
  106. M_HS_CORE = 0,
  107. M_HS_RTT,
  108. M_AXI_TUN,
  109. M_HDMI_VIDEO,
  110. M_HDMI_AUDIO,
  111. M_USB_HOST,
  112. M_ETHERNET,
  113. M_SDIO,
  114. M_GPU,
  115. M_DMAC_0,
  116. M_DMAC_1,
  117. M_DVFS
  118. };
  119. #define UPDATE_VAL 1
  120. /*
  121. * This is modified configuration of AXI bridge. Default settings
  122. * are specified in "Table 111 CREG Address Decoder register reset values".
  123. *
  124. * AXI_M_m_SLV{0|1} - Slave Select register for master 'm'.
  125. * Possible slaves are:
  126. * - 0 => no slave selected
  127. * - 1 => DDR controller port #1
  128. * - 2 => SRAM controller
  129. * - 3 => AXI tunnel
  130. * - 4 => EBI controller
  131. * - 5 => ROM controller
  132. * - 6 => AXI2APB bridge
  133. * - 7 => DDR controller port #2
  134. * - 8 => DDR controller port #3
  135. * - 9 => HS38x4 IOC
  136. * - 10 => HS38x4 DMI
  137. * AXI_M_m_OFFSET{0|1} - Addr Offset register for master 'm'
  138. *
  139. * Please read ARC HS Development IC Specification, section 17.2 for more
  140. * information about apertures configuration.
  141. *
  142. * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
  143. * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
  144. * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
  145. * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
  146. * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
  147. * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
  148. * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
  149. * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
  150. * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
  151. * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
  152. * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
  153. * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
  154. * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
  155. */
  156. #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x20 * (m)))
  157. #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x20 * (m) + 0x04))
  158. #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x20 * (m) + 0x08))
  159. #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x20 * (m) + 0x0C))
  160. #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x20 * (m) + 0x14))
  161. #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
  162. #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
  163. #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
  164. static void __init hsdk_init_memory_bridge_axi_dmac(void)
  165. {
  166. bool coherent = !!arc_hsdk_axi_dmac_coherent;
  167. u32 axi_m_slv1, axi_m_oft1;
  168. /*
  169. * Don't tweak memory bridge configuration if we failed to tweak DTB
  170. * as we will end up in a inconsistent state.
  171. */
  172. if (hsdk_tweak_node_coherency("/soc/dmac@80000", coherent))
  173. return;
  174. if (coherent) {
  175. axi_m_slv1 = 0x77999999;
  176. axi_m_oft1 = 0x76DCBA98;
  177. } else {
  178. axi_m_slv1 = 0x77777777;
  179. axi_m_oft1 = 0x76543210;
  180. }
  181. writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0));
  182. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0));
  183. writel(axi_m_slv1, CREG_AXI_M_SLV1(M_DMAC_0));
  184. writel(axi_m_oft1, CREG_AXI_M_OFT1(M_DMAC_0));
  185. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_0));
  186. writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1));
  187. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1));
  188. writel(axi_m_slv1, CREG_AXI_M_SLV1(M_DMAC_1));
  189. writel(axi_m_oft1, CREG_AXI_M_OFT1(M_DMAC_1));
  190. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_1));
  191. }
  192. static void __init hsdk_init_memory_bridge(void)
  193. {
  194. u32 reg;
  195. /*
  196. * M_HS_CORE has one unique register - BOOT.
  197. * We need to clean boot mirror (BOOT[1:0]) bits in them to avoid first
  198. * aperture to be masked by 'boot mirror'.
  199. */
  200. reg = readl(CREG_AXI_M_HS_CORE_BOOT) & (~0x3);
  201. writel(reg, CREG_AXI_M_HS_CORE_BOOT);
  202. writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE));
  203. writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE));
  204. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE));
  205. writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE));
  206. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_CORE));
  207. writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT));
  208. writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT));
  209. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT));
  210. writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT));
  211. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_RTT));
  212. writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN));
  213. writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN));
  214. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN));
  215. writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN));
  216. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_AXI_TUN));
  217. writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO));
  218. writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO));
  219. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO));
  220. writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO));
  221. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_VIDEO));
  222. writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO));
  223. writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO));
  224. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO));
  225. writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO));
  226. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_AUDIO));
  227. writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST));
  228. writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST));
  229. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST));
  230. writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST));
  231. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_USB_HOST));
  232. writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET));
  233. writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET));
  234. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET));
  235. writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET));
  236. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_ETHERNET));
  237. writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO));
  238. writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO));
  239. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO));
  240. writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO));
  241. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_SDIO));
  242. writel(0x77777777, CREG_AXI_M_SLV0(M_GPU));
  243. writel(0x77777777, CREG_AXI_M_SLV1(M_GPU));
  244. writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU));
  245. writel(0x76543210, CREG_AXI_M_OFT1(M_GPU));
  246. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_GPU));
  247. writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS));
  248. writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS));
  249. writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS));
  250. writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS));
  251. writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DVFS));
  252. hsdk_init_memory_bridge_axi_dmac();
  253. /*
  254. * PAE remapping for DMA clients does not work due to an RTL bug, so
  255. * CREG_PAE register must be programmed to all zeroes, otherwise it
  256. * will cause problems with DMA to/from peripherals even if PAE40 is
  257. * not used.
  258. */
  259. writel(0x00000000, CREG_PAE);
  260. writel(UPDATE_VAL, CREG_PAE_UPDT);
  261. }
  262. static void __init hsdk_init_early(void)
  263. {
  264. hsdk_init_memory_bridge();
  265. /*
  266. * Switch SDIO external ciu clock divider from default div-by-8 to
  267. * minimum possible div-by-2.
  268. */
  269. iowrite32(SDIO_UHS_REG_EXT_DIV_2, (void __iomem *) SDIO_UHS_REG_EXT);
  270. hsdk_enable_gpio_intc_wire();
  271. }
  272. static const char *hsdk_compat[] __initconst = {
  273. "snps,hsdk",
  274. NULL,
  275. };
  276. MACHINE_START(SIMULATION, "hsdk")
  277. .dt_compat = hsdk_compat,
  278. .init_early = hsdk_init_early,
  279. MACHINE_END