axs10x.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * AXS101/AXS103 Software Development Platform
  3. *
  4. * Copyright (C) 2013-15 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/of_fdt.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/libfdt.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/io.h>
  21. #include <asm/mach_desc.h>
  22. #include <soc/arc/mcip.h>
  23. #define AXS_MB_CGU 0xE0010000
  24. #define AXS_MB_CREG 0xE0011000
  25. #define CREG_MB_IRQ_MUX (AXS_MB_CREG + 0x214)
  26. #define CREG_MB_SW_RESET (AXS_MB_CREG + 0x220)
  27. #define CREG_MB_VER (AXS_MB_CREG + 0x230)
  28. #define CREG_MB_CONFIG (AXS_MB_CREG + 0x234)
  29. #define AXC001_CREG 0xF0001000
  30. #define AXC001_GPIO_INTC 0xF0003000
  31. static void __init axs10x_enable_gpio_intc_wire(void)
  32. {
  33. /*
  34. * Peripherals on CPU Card and Mother Board are wired to cpu intc via
  35. * intermediate DW APB GPIO blocks (mainly for debouncing)
  36. *
  37. * ---------------------
  38. * | snps,arc700-intc |
  39. * ---------------------
  40. * | #7 | #15
  41. * ------------------- -------------------
  42. * | snps,dw-apb-gpio | | snps,dw-apb-gpio |
  43. * ------------------- -------------------
  44. * | #12 |
  45. * | [ Debug UART on cpu card ]
  46. * |
  47. * ------------------------
  48. * | snps,dw-apb-intc (MB)|
  49. * ------------------------
  50. * | | | |
  51. * [eth] [uart] [... other perip on Main Board]
  52. *
  53. * Current implementation of "irq-dw-apb-ictl" driver doesn't work well
  54. * with stacked INTCs. In particular problem happens if its master INTC
  55. * not yet instantiated. See discussion here -
  56. * https://lkml.org/lkml/2015/3/4/755
  57. *
  58. * So setup the first gpio block as a passive pass thru and hide it from
  59. * DT hardware topology - connect MB intc directly to cpu intc
  60. * The GPIO "wire" needs to be init nevertheless (here)
  61. *
  62. * One side adv is that peripheral interrupt handling avoids one nested
  63. * intc ISR hop
  64. */
  65. #define GPIO_INTEN (AXC001_GPIO_INTC + 0x30)
  66. #define GPIO_INTMASK (AXC001_GPIO_INTC + 0x34)
  67. #define GPIO_INTTYPE_LEVEL (AXC001_GPIO_INTC + 0x38)
  68. #define GPIO_INT_POLARITY (AXC001_GPIO_INTC + 0x3c)
  69. #define MB_TO_GPIO_IRQ 12
  70. iowrite32(~(1 << MB_TO_GPIO_IRQ), (void __iomem *) GPIO_INTMASK);
  71. iowrite32(0, (void __iomem *) GPIO_INTTYPE_LEVEL);
  72. iowrite32(~0, (void __iomem *) GPIO_INT_POLARITY);
  73. iowrite32(1 << MB_TO_GPIO_IRQ, (void __iomem *) GPIO_INTEN);
  74. }
  75. static void __init axs10x_print_board_ver(unsigned int creg, const char *str)
  76. {
  77. union ver {
  78. struct {
  79. #ifdef CONFIG_CPU_BIG_ENDIAN
  80. unsigned int pad:11, y:12, m:4, d:5;
  81. #else
  82. unsigned int d:5, m:4, y:12, pad:11;
  83. #endif
  84. };
  85. unsigned int val;
  86. } board;
  87. board.val = ioread32((void __iomem *)creg);
  88. pr_info("AXS: %s FPGA Date: %u-%u-%u\n", str, board.d, board.m,
  89. board.y);
  90. }
  91. static void __init axs10x_early_init(void)
  92. {
  93. int mb_rev;
  94. char mb[32];
  95. /* Determine motherboard version */
  96. if (ioread32((void __iomem *) CREG_MB_CONFIG) & (1 << 28))
  97. mb_rev = 3; /* HT-3 (rev3.0) */
  98. else
  99. mb_rev = 2; /* HT-2 (rev2.0) */
  100. axs10x_enable_gpio_intc_wire();
  101. scnprintf(mb, 32, "MainBoard v%d", mb_rev);
  102. axs10x_print_board_ver(CREG_MB_VER, mb);
  103. }
  104. #ifdef CONFIG_AXS101
  105. #define CREG_CPU_ADDR_770 (AXC001_CREG + 0x20)
  106. #define CREG_CPU_ADDR_TUNN (AXC001_CREG + 0x60)
  107. #define CREG_CPU_ADDR_770_UPD (AXC001_CREG + 0x34)
  108. #define CREG_CPU_ADDR_TUNN_UPD (AXC001_CREG + 0x74)
  109. #define CREG_CPU_ARC770_IRQ_MUX (AXC001_CREG + 0x114)
  110. #define CREG_CPU_GPIO_UART_MUX (AXC001_CREG + 0x120)
  111. /*
  112. * Set up System Memory Map for ARC cpu / peripherals controllers
  113. *
  114. * Each AXI master has a 4GB memory map specified as 16 apertures of 256MB, each
  115. * of which maps to a corresponding 256MB aperture in Target slave memory map.
  116. *
  117. * e.g. ARC cpu AXI Master's aperture 8 (0x8000_0000) is mapped to aperture 0
  118. * (0x0000_0000) of DDR Port 0 (slave #1)
  119. *
  120. * Access from cpu to MB controllers such as GMAC is setup using AXI Tunnel:
  121. * which has master/slaves on both ends.
  122. * e.g. aperture 14 (0xE000_0000) of ARC cpu is mapped to aperture 14
  123. * (0xE000_0000) of CPU Card AXI Tunnel slave (slave #3) which is mapped to
  124. * MB AXI Tunnel Master, which also has a mem map setup
  125. *
  126. * In the reverse direction, MB AXI Masters (e.g. GMAC) mem map is setup
  127. * to map to MB AXI Tunnel slave which connects to CPU Card AXI Tunnel Master
  128. */
  129. struct aperture {
  130. unsigned int slave_sel:4, slave_off:4, pad:24;
  131. };
  132. /* CPU Card target slaves */
  133. #define AXC001_SLV_NONE 0
  134. #define AXC001_SLV_DDR_PORT0 1
  135. #define AXC001_SLV_SRAM 2
  136. #define AXC001_SLV_AXI_TUNNEL 3
  137. #define AXC001_SLV_AXI2APB 6
  138. #define AXC001_SLV_DDR_PORT1 7
  139. /* MB AXI Target slaves */
  140. #define AXS_MB_SLV_NONE 0
  141. #define AXS_MB_SLV_AXI_TUNNEL_CPU 1
  142. #define AXS_MB_SLV_AXI_TUNNEL_HAPS 2
  143. #define AXS_MB_SLV_SRAM 3
  144. #define AXS_MB_SLV_CONTROL 4
  145. /* MB AXI masters */
  146. #define AXS_MB_MST_TUNNEL_CPU 0
  147. #define AXS_MB_MST_USB_OHCI 10
  148. /*
  149. * memmap for ARC core on CPU Card
  150. */
  151. static const struct aperture axc001_memmap[16] = {
  152. {AXC001_SLV_AXI_TUNNEL, 0x0},
  153. {AXC001_SLV_AXI_TUNNEL, 0x1},
  154. {AXC001_SLV_SRAM, 0x0}, /* 0x2000_0000: Local SRAM */
  155. {AXC001_SLV_NONE, 0x0},
  156. {AXC001_SLV_NONE, 0x0},
  157. {AXC001_SLV_NONE, 0x0},
  158. {AXC001_SLV_NONE, 0x0},
  159. {AXC001_SLV_NONE, 0x0},
  160. {AXC001_SLV_DDR_PORT0, 0x0}, /* 0x8000_0000: DDR 0..256M */
  161. {AXC001_SLV_DDR_PORT0, 0x1}, /* 0x9000_0000: DDR 256..512M */
  162. {AXC001_SLV_DDR_PORT0, 0x2},
  163. {AXC001_SLV_DDR_PORT0, 0x3},
  164. {AXC001_SLV_NONE, 0x0},
  165. {AXC001_SLV_AXI_TUNNEL, 0xD},
  166. {AXC001_SLV_AXI_TUNNEL, 0xE}, /* MB: CREG, CGU... */
  167. {AXC001_SLV_AXI2APB, 0x0}, /* CPU Card local CREG, CGU... */
  168. };
  169. /*
  170. * memmap for CPU Card AXI Tunnel Master (for access by MB controllers)
  171. * GMAC (MB) -> MB AXI Tunnel slave -> CPU Card AXI Tunnel Master -> DDR
  172. */
  173. static const struct aperture axc001_axi_tunnel_memmap[16] = {
  174. {AXC001_SLV_AXI_TUNNEL, 0x0},
  175. {AXC001_SLV_AXI_TUNNEL, 0x1},
  176. {AXC001_SLV_SRAM, 0x0},
  177. {AXC001_SLV_NONE, 0x0},
  178. {AXC001_SLV_NONE, 0x0},
  179. {AXC001_SLV_NONE, 0x0},
  180. {AXC001_SLV_NONE, 0x0},
  181. {AXC001_SLV_NONE, 0x0},
  182. {AXC001_SLV_DDR_PORT1, 0x0},
  183. {AXC001_SLV_DDR_PORT1, 0x1},
  184. {AXC001_SLV_DDR_PORT1, 0x2},
  185. {AXC001_SLV_DDR_PORT1, 0x3},
  186. {AXC001_SLV_NONE, 0x0},
  187. {AXC001_SLV_AXI_TUNNEL, 0xD},
  188. {AXC001_SLV_AXI_TUNNEL, 0xE},
  189. {AXC001_SLV_AXI2APB, 0x0},
  190. };
  191. /*
  192. * memmap for MB AXI Masters
  193. * Same mem map for all perip controllers as well as MB AXI Tunnel Master
  194. */
  195. static const struct aperture axs_mb_memmap[16] = {
  196. {AXS_MB_SLV_SRAM, 0x0},
  197. {AXS_MB_SLV_SRAM, 0x0},
  198. {AXS_MB_SLV_NONE, 0x0},
  199. {AXS_MB_SLV_NONE, 0x0},
  200. {AXS_MB_SLV_NONE, 0x0},
  201. {AXS_MB_SLV_NONE, 0x0},
  202. {AXS_MB_SLV_NONE, 0x0},
  203. {AXS_MB_SLV_NONE, 0x0},
  204. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0x8}, /* DDR on CPU Card */
  205. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0x9}, /* DDR on CPU Card */
  206. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0xA},
  207. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0xB},
  208. {AXS_MB_SLV_NONE, 0x0},
  209. {AXS_MB_SLV_AXI_TUNNEL_HAPS, 0xD},
  210. {AXS_MB_SLV_CONTROL, 0x0}, /* MB Local CREG, CGU... */
  211. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0xF},
  212. };
  213. static noinline void __init
  214. axs101_set_memmap(void __iomem *base, const struct aperture map[16])
  215. {
  216. unsigned int slave_select, slave_offset;
  217. int i;
  218. slave_select = slave_offset = 0;
  219. for (i = 0; i < 8; i++) {
  220. slave_select |= map[i].slave_sel << (i << 2);
  221. slave_offset |= map[i].slave_off << (i << 2);
  222. }
  223. iowrite32(slave_select, base + 0x0); /* SLV0 */
  224. iowrite32(slave_offset, base + 0x8); /* OFFSET0 */
  225. slave_select = slave_offset = 0;
  226. for (i = 0; i < 8; i++) {
  227. slave_select |= map[i+8].slave_sel << (i << 2);
  228. slave_offset |= map[i+8].slave_off << (i << 2);
  229. }
  230. iowrite32(slave_select, base + 0x4); /* SLV1 */
  231. iowrite32(slave_offset, base + 0xC); /* OFFSET1 */
  232. }
  233. static void __init axs101_early_init(void)
  234. {
  235. int i;
  236. /* ARC 770D memory view */
  237. axs101_set_memmap((void __iomem *) CREG_CPU_ADDR_770, axc001_memmap);
  238. iowrite32(1, (void __iomem *) CREG_CPU_ADDR_770_UPD);
  239. /* AXI tunnel memory map (incoming traffic from MB into CPU Card */
  240. axs101_set_memmap((void __iomem *) CREG_CPU_ADDR_TUNN,
  241. axc001_axi_tunnel_memmap);
  242. iowrite32(1, (void __iomem *) CREG_CPU_ADDR_TUNN_UPD);
  243. /* MB peripherals memory map */
  244. for (i = AXS_MB_MST_TUNNEL_CPU; i <= AXS_MB_MST_USB_OHCI; i++)
  245. axs101_set_memmap((void __iomem *) AXS_MB_CREG + (i << 4),
  246. axs_mb_memmap);
  247. iowrite32(0x3ff, (void __iomem *) AXS_MB_CREG + 0x100); /* Update */
  248. /* GPIO pins 18 and 19 are used as UART rx and tx, respectively. */
  249. iowrite32(0x01, (void __iomem *) CREG_CPU_GPIO_UART_MUX);
  250. /* Set up the MB interrupt system: mux interrupts to GPIO7) */
  251. iowrite32(0x01, (void __iomem *) CREG_MB_IRQ_MUX);
  252. /* reset ethernet and ULPI interfaces */
  253. iowrite32(0x18, (void __iomem *) CREG_MB_SW_RESET);
  254. /* map GPIO 14:10 to ARC 9:5 (IRQ mux change for MB v2 onwards) */
  255. iowrite32(0x52, (void __iomem *) CREG_CPU_ARC770_IRQ_MUX);
  256. axs10x_early_init();
  257. }
  258. #endif /* CONFIG_AXS101 */
  259. #ifdef CONFIG_AXS103
  260. #define AXC003_CREG 0xF0001000
  261. #define AXC003_MST_AXI_TUNNEL 0
  262. #define AXC003_MST_HS38 1
  263. #define CREG_CPU_AXI_M0_IRQ_MUX (AXC003_CREG + 0x440)
  264. #define CREG_CPU_GPIO_UART_MUX (AXC003_CREG + 0x480)
  265. #define CREG_CPU_TUN_IO_CTRL (AXC003_CREG + 0x494)
  266. static void __init axs103_early_init(void)
  267. {
  268. #ifdef CONFIG_ARC_MCIP
  269. /*
  270. * AXS103 configurations for SMP/QUAD configurations share device tree
  271. * which defaults to 100 MHz. However recent failures of Quad config
  272. * revealed P&R timing violations so clamp it down to safe 50 MHz
  273. * Instead of duplicating defconfig/DT for SMP/QUAD, add a small hack
  274. * of fudging the freq in DT
  275. */
  276. #define AXS103_QUAD_CORE_CPU_FREQ_HZ 50000000
  277. unsigned int num_cores = (read_aux_reg(ARC_REG_MCIP_BCR) >> 16) & 0x3F;
  278. if (num_cores > 2) {
  279. u32 freq;
  280. int off = fdt_path_offset(initial_boot_params, "/cpu_card/core_clk");
  281. const struct fdt_property *prop;
  282. prop = fdt_get_property(initial_boot_params, off,
  283. "assigned-clock-rates", NULL);
  284. freq = be32_to_cpu(*(u32 *)(prop->data));
  285. /* Patching .dtb in-place with new core clock value */
  286. if (freq != AXS103_QUAD_CORE_CPU_FREQ_HZ) {
  287. freq = cpu_to_be32(AXS103_QUAD_CORE_CPU_FREQ_HZ);
  288. fdt_setprop_inplace(initial_boot_params, off,
  289. "assigned-clock-rates", &freq, sizeof(freq));
  290. }
  291. }
  292. #endif
  293. /* Memory maps already config in pre-bootloader */
  294. /* set GPIO mux to UART */
  295. iowrite32(0x01, (void __iomem *) CREG_CPU_GPIO_UART_MUX);
  296. iowrite32((0x00100000U | 0x000C0000U | 0x00003322U),
  297. (void __iomem *) CREG_CPU_TUN_IO_CTRL);
  298. /* Set up the AXS_MB interrupt system.*/
  299. iowrite32(12, (void __iomem *) (CREG_CPU_AXI_M0_IRQ_MUX
  300. + (AXC003_MST_HS38 << 2)));
  301. /* connect ICTL - Main Board with GPIO line */
  302. iowrite32(0x01, (void __iomem *) CREG_MB_IRQ_MUX);
  303. axs10x_print_board_ver(AXC003_CREG + 4088, "AXC003 CPU Card");
  304. axs10x_early_init();
  305. }
  306. #endif
  307. #ifdef CONFIG_AXS101
  308. static const char *axs101_compat[] __initconst = {
  309. "snps,axs101",
  310. NULL,
  311. };
  312. MACHINE_START(AXS101, "axs101")
  313. .dt_compat = axs101_compat,
  314. .init_early = axs101_early_init,
  315. MACHINE_END
  316. #endif /* CONFIG_AXS101 */
  317. #ifdef CONFIG_AXS103
  318. static const char *axs103_compat[] __initconst = {
  319. "snps,axs103",
  320. NULL,
  321. };
  322. MACHINE_START(AXS103, "axs103")
  323. .dt_compat = axs103_compat,
  324. .init_early = axs103_early_init,
  325. MACHINE_END
  326. /*
  327. * For the VDK OS-kit, to get the offset to pid and command fields
  328. */
  329. char coware_swa_pid_offset[TASK_PID];
  330. char coware_swa_comm_offset[TASK_COMM];
  331. #endif /* CONFIG_AXS103 */