axs10x.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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_platform.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/clk.h>
  19. #include <asm/io.h>
  20. #include <asm/mach_desc.h>
  21. #include <asm/mcip.h>
  22. #define AXS_MB_CGU 0xE0010000
  23. #define AXS_MB_CREG 0xE0011000
  24. #define CREG_MB_IRQ_MUX (AXS_MB_CREG + 0x214)
  25. #define CREG_MB_SW_RESET (AXS_MB_CREG + 0x220)
  26. #define CREG_MB_VER (AXS_MB_CREG + 0x230)
  27. #define CREG_MB_CONFIG (AXS_MB_CREG + 0x234)
  28. #define AXC001_CREG 0xF0001000
  29. #define AXC001_GPIO_INTC 0xF0003000
  30. static void __init axs10x_enable_gpio_intc_wire(void)
  31. {
  32. /*
  33. * Peripherals on CPU Card and Mother Board are wired to cpu intc via
  34. * intermediate DW APB GPIO blocks (mainly for debouncing)
  35. *
  36. * ---------------------
  37. * | snps,arc700-intc |
  38. * ---------------------
  39. * | #7 | #15
  40. * ------------------- -------------------
  41. * | snps,dw-apb-gpio | | snps,dw-apb-gpio |
  42. * ------------------- -------------------
  43. * | |
  44. * | [ Debug UART on cpu card ]
  45. * |
  46. * ------------------------
  47. * | snps,dw-apb-intc (MB)|
  48. * ------------------------
  49. * | | | |
  50. * [eth] [uart] [... other perip on Main Board]
  51. *
  52. * Current implementation of "irq-dw-apb-ictl" driver doesn't work well
  53. * with stacked INTCs. In particular problem happens if its master INTC
  54. * not yet instantiated. See discussion here -
  55. * https://lkml.org/lkml/2015/3/4/755
  56. *
  57. * So setup the first gpio block as a passive pass thru and hide it from
  58. * DT hardware topology - connect MB intc directly to cpu intc
  59. * The GPIO "wire" needs to be init nevertheless (here)
  60. *
  61. * One side adv is that peripheral interrupt handling avoids one nested
  62. * intc ISR hop
  63. */
  64. #define GPIO_INTEN (AXC001_GPIO_INTC + 0x30)
  65. #define GPIO_INTMASK (AXC001_GPIO_INTC + 0x34)
  66. #define GPIO_INTTYPE_LEVEL (AXC001_GPIO_INTC + 0x38)
  67. #define GPIO_INT_POLARITY (AXC001_GPIO_INTC + 0x3c)
  68. #define MB_TO_GPIO_IRQ 12
  69. iowrite32(~(1 << MB_TO_GPIO_IRQ), (void __iomem *) GPIO_INTMASK);
  70. iowrite32(0, (void __iomem *) GPIO_INTTYPE_LEVEL);
  71. iowrite32(~0, (void __iomem *) GPIO_INT_POLARITY);
  72. iowrite32(1 << MB_TO_GPIO_IRQ, (void __iomem *) GPIO_INTEN);
  73. }
  74. static inline void __init
  75. write_cgu_reg(uint32_t value, void __iomem *reg, void __iomem *lock_reg)
  76. {
  77. unsigned int loops = 128 * 1024, ctr;
  78. iowrite32(value, reg);
  79. ctr = loops;
  80. while (((ioread32(lock_reg) & 1) == 1) && ctr--) /* wait for unlock */
  81. cpu_relax();
  82. ctr = loops;
  83. while (((ioread32(lock_reg) & 1) == 0) && ctr--) /* wait for re-lock */
  84. cpu_relax();
  85. }
  86. static void __init axs10x_print_board_ver(unsigned int creg, const char *str)
  87. {
  88. union ver {
  89. struct {
  90. #ifdef CONFIG_CPU_BIG_ENDIAN
  91. unsigned int pad:11, y:12, m:4, d:5;
  92. #else
  93. unsigned int d:5, m:4, y:12, pad:11;
  94. #endif
  95. };
  96. unsigned int val;
  97. } board;
  98. board.val = ioread32((void __iomem *)creg);
  99. pr_info("AXS: %s FPGA Date: %u-%u-%u\n", str, board.d, board.m,
  100. board.y);
  101. }
  102. static void __init axs10x_early_init(void)
  103. {
  104. int mb_rev;
  105. char mb[32];
  106. /* Determine motherboard version */
  107. if (ioread32((void __iomem *) CREG_MB_CONFIG) & (1 << 28))
  108. mb_rev = 3; /* HT-3 (rev3.0) */
  109. else
  110. mb_rev = 2; /* HT-2 (rev2.0) */
  111. axs10x_enable_gpio_intc_wire();
  112. scnprintf(mb, 32, "MainBoard v%d", mb_rev);
  113. axs10x_print_board_ver(CREG_MB_VER, mb);
  114. }
  115. #ifdef CONFIG_AXS101
  116. #define CREG_CPU_ADDR_770 (AXC001_CREG + 0x20)
  117. #define CREG_CPU_ADDR_TUNN (AXC001_CREG + 0x60)
  118. #define CREG_CPU_ADDR_770_UPD (AXC001_CREG + 0x34)
  119. #define CREG_CPU_ADDR_TUNN_UPD (AXC001_CREG + 0x74)
  120. #define CREG_CPU_ARC770_IRQ_MUX (AXC001_CREG + 0x114)
  121. #define CREG_CPU_GPIO_UART_MUX (AXC001_CREG + 0x120)
  122. /*
  123. * Set up System Memory Map for ARC cpu / peripherals controllers
  124. *
  125. * Each AXI master has a 4GB memory map specified as 16 apertures of 256MB, each
  126. * of which maps to a corresponding 256MB aperture in Target slave memory map.
  127. *
  128. * e.g. ARC cpu AXI Master's aperture 8 (0x8000_0000) is mapped to aperture 0
  129. * (0x0000_0000) of DDR Port 0 (slave #1)
  130. *
  131. * Access from cpu to MB controllers such as GMAC is setup using AXI Tunnel:
  132. * which has master/slaves on both ends.
  133. * e.g. aperture 14 (0xE000_0000) of ARC cpu is mapped to aperture 14
  134. * (0xE000_0000) of CPU Card AXI Tunnel slave (slave #3) which is mapped to
  135. * MB AXI Tunnel Master, which also has a mem map setup
  136. *
  137. * In the reverse direction, MB AXI Masters (e.g. GMAC) mem map is setup
  138. * to map to MB AXI Tunnel slave which connects to CPU Card AXI Tunnel Master
  139. */
  140. struct aperture {
  141. unsigned int slave_sel:4, slave_off:4, pad:24;
  142. };
  143. /* CPU Card target slaves */
  144. #define AXC001_SLV_NONE 0
  145. #define AXC001_SLV_DDR_PORT0 1
  146. #define AXC001_SLV_SRAM 2
  147. #define AXC001_SLV_AXI_TUNNEL 3
  148. #define AXC001_SLV_AXI2APB 6
  149. #define AXC001_SLV_DDR_PORT1 7
  150. /* MB AXI Target slaves */
  151. #define AXS_MB_SLV_NONE 0
  152. #define AXS_MB_SLV_AXI_TUNNEL_CPU 1
  153. #define AXS_MB_SLV_AXI_TUNNEL_HAPS 2
  154. #define AXS_MB_SLV_SRAM 3
  155. #define AXS_MB_SLV_CONTROL 4
  156. /* MB AXI masters */
  157. #define AXS_MB_MST_TUNNEL_CPU 0
  158. #define AXS_MB_MST_USB_OHCI 10
  159. /*
  160. * memmap for ARC core on CPU Card
  161. */
  162. static const struct aperture axc001_memmap[16] = {
  163. {AXC001_SLV_AXI_TUNNEL, 0x0},
  164. {AXC001_SLV_AXI_TUNNEL, 0x1},
  165. {AXC001_SLV_SRAM, 0x0}, /* 0x2000_0000: Local SRAM */
  166. {AXC001_SLV_NONE, 0x0},
  167. {AXC001_SLV_NONE, 0x0},
  168. {AXC001_SLV_NONE, 0x0},
  169. {AXC001_SLV_NONE, 0x0},
  170. {AXC001_SLV_NONE, 0x0},
  171. {AXC001_SLV_DDR_PORT0, 0x0}, /* 0x8000_0000: DDR 0..256M */
  172. {AXC001_SLV_DDR_PORT0, 0x1}, /* 0x9000_0000: DDR 256..512M */
  173. {AXC001_SLV_DDR_PORT0, 0x2},
  174. {AXC001_SLV_DDR_PORT0, 0x3},
  175. {AXC001_SLV_NONE, 0x0},
  176. {AXC001_SLV_AXI_TUNNEL, 0xD},
  177. {AXC001_SLV_AXI_TUNNEL, 0xE}, /* MB: CREG, CGU... */
  178. {AXC001_SLV_AXI2APB, 0x0}, /* CPU Card local CREG, CGU... */
  179. };
  180. /*
  181. * memmap for CPU Card AXI Tunnel Master (for access by MB controllers)
  182. * GMAC (MB) -> MB AXI Tunnel slave -> CPU Card AXI Tunnel Master -> DDR
  183. */
  184. static const struct aperture axc001_axi_tunnel_memmap[16] = {
  185. {AXC001_SLV_AXI_TUNNEL, 0x0},
  186. {AXC001_SLV_AXI_TUNNEL, 0x1},
  187. {AXC001_SLV_SRAM, 0x0},
  188. {AXC001_SLV_NONE, 0x0},
  189. {AXC001_SLV_NONE, 0x0},
  190. {AXC001_SLV_NONE, 0x0},
  191. {AXC001_SLV_NONE, 0x0},
  192. {AXC001_SLV_NONE, 0x0},
  193. {AXC001_SLV_DDR_PORT1, 0x0},
  194. {AXC001_SLV_DDR_PORT1, 0x1},
  195. {AXC001_SLV_DDR_PORT1, 0x2},
  196. {AXC001_SLV_DDR_PORT1, 0x3},
  197. {AXC001_SLV_NONE, 0x0},
  198. {AXC001_SLV_AXI_TUNNEL, 0xD},
  199. {AXC001_SLV_AXI_TUNNEL, 0xE},
  200. {AXC001_SLV_AXI2APB, 0x0},
  201. };
  202. /*
  203. * memmap for MB AXI Masters
  204. * Same mem map for all perip controllers as well as MB AXI Tunnel Master
  205. */
  206. static const struct aperture axs_mb_memmap[16] = {
  207. {AXS_MB_SLV_SRAM, 0x0},
  208. {AXS_MB_SLV_SRAM, 0x0},
  209. {AXS_MB_SLV_NONE, 0x0},
  210. {AXS_MB_SLV_NONE, 0x0},
  211. {AXS_MB_SLV_NONE, 0x0},
  212. {AXS_MB_SLV_NONE, 0x0},
  213. {AXS_MB_SLV_NONE, 0x0},
  214. {AXS_MB_SLV_NONE, 0x0},
  215. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0x8}, /* DDR on CPU Card */
  216. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0x9}, /* DDR on CPU Card */
  217. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0xA},
  218. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0xB},
  219. {AXS_MB_SLV_NONE, 0x0},
  220. {AXS_MB_SLV_AXI_TUNNEL_HAPS, 0xD},
  221. {AXS_MB_SLV_CONTROL, 0x0}, /* MB Local CREG, CGU... */
  222. {AXS_MB_SLV_AXI_TUNNEL_CPU, 0xF},
  223. };
  224. static noinline void __init
  225. axs101_set_memmap(void __iomem *base, const struct aperture map[16])
  226. {
  227. unsigned int slave_select, slave_offset;
  228. int i;
  229. slave_select = slave_offset = 0;
  230. for (i = 0; i < 8; i++) {
  231. slave_select |= map[i].slave_sel << (i << 2);
  232. slave_offset |= map[i].slave_off << (i << 2);
  233. }
  234. iowrite32(slave_select, base + 0x0); /* SLV0 */
  235. iowrite32(slave_offset, base + 0x8); /* OFFSET0 */
  236. slave_select = slave_offset = 0;
  237. for (i = 0; i < 8; i++) {
  238. slave_select |= map[i+8].slave_sel << (i << 2);
  239. slave_offset |= map[i+8].slave_off << (i << 2);
  240. }
  241. iowrite32(slave_select, base + 0x4); /* SLV1 */
  242. iowrite32(slave_offset, base + 0xC); /* OFFSET1 */
  243. }
  244. static void __init axs101_early_init(void)
  245. {
  246. int i;
  247. /* ARC 770D memory view */
  248. axs101_set_memmap((void __iomem *) CREG_CPU_ADDR_770, axc001_memmap);
  249. iowrite32(1, (void __iomem *) CREG_CPU_ADDR_770_UPD);
  250. /* AXI tunnel memory map (incoming traffic from MB into CPU Card */
  251. axs101_set_memmap((void __iomem *) CREG_CPU_ADDR_TUNN,
  252. axc001_axi_tunnel_memmap);
  253. iowrite32(1, (void __iomem *) CREG_CPU_ADDR_TUNN_UPD);
  254. /* MB peripherals memory map */
  255. for (i = AXS_MB_MST_TUNNEL_CPU; i <= AXS_MB_MST_USB_OHCI; i++)
  256. axs101_set_memmap((void __iomem *) AXS_MB_CREG + (i << 4),
  257. axs_mb_memmap);
  258. iowrite32(0x3ff, (void __iomem *) AXS_MB_CREG + 0x100); /* Update */
  259. /* GPIO pins 18 and 19 are used as UART rx and tx, respectively. */
  260. iowrite32(0x01, (void __iomem *) CREG_CPU_GPIO_UART_MUX);
  261. /* Set up the MB interrupt system: mux interrupts to GPIO7) */
  262. iowrite32(0x01, (void __iomem *) CREG_MB_IRQ_MUX);
  263. /* reset ethernet and ULPI interfaces */
  264. iowrite32(0x18, (void __iomem *) CREG_MB_SW_RESET);
  265. /* map GPIO 14:10 to ARC 9:5 (IRQ mux change for MB v2 onwards) */
  266. iowrite32(0x52, (void __iomem *) CREG_CPU_ARC770_IRQ_MUX);
  267. axs10x_early_init();
  268. }
  269. #endif /* CONFIG_AXS101 */
  270. #ifdef CONFIG_AXS103
  271. #define AXC003_CGU 0xF0000000
  272. #define AXC003_CREG 0xF0001000
  273. #define AXC003_MST_AXI_TUNNEL 0
  274. #define AXC003_MST_HS38 1
  275. #define CREG_CPU_AXI_M0_IRQ_MUX (AXC003_CREG + 0x440)
  276. #define CREG_CPU_GPIO_UART_MUX (AXC003_CREG + 0x480)
  277. #define CREG_CPU_TUN_IO_CTRL (AXC003_CREG + 0x494)
  278. union pll_reg {
  279. struct {
  280. #ifdef CONFIG_CPU_BIG_ENDIAN
  281. unsigned int pad:17, noupd:1, bypass:1, edge:1, high:6, low:6;
  282. #else
  283. unsigned int low:6, high:6, edge:1, bypass:1, noupd:1, pad:17;
  284. #endif
  285. };
  286. unsigned int val;
  287. };
  288. static unsigned int __init axs103_get_freq(void)
  289. {
  290. union pll_reg idiv, fbdiv, odiv;
  291. unsigned int f = 33333333;
  292. idiv.val = ioread32((void __iomem *)AXC003_CGU + 0x80 + 0);
  293. fbdiv.val = ioread32((void __iomem *)AXC003_CGU + 0x80 + 4);
  294. odiv.val = ioread32((void __iomem *)AXC003_CGU + 0x80 + 8);
  295. if (idiv.bypass != 1)
  296. f = f / (idiv.low + idiv.high);
  297. if (fbdiv.bypass != 1)
  298. f = f * (fbdiv.low + fbdiv.high);
  299. if (odiv.bypass != 1)
  300. f = f / (odiv.low + odiv.high);
  301. f = (f + 500000) / 1000000; /* Rounding */
  302. return f;
  303. }
  304. static inline unsigned int __init encode_div(unsigned int id, int upd)
  305. {
  306. union pll_reg div;
  307. div.val = 0;
  308. div.noupd = !upd;
  309. div.bypass = id == 1 ? 1 : 0;
  310. div.edge = (id%2 == 0) ? 0 : 1; /* 0 = rising */
  311. div.low = (id%2 == 0) ? id >> 1 : (id >> 1)+1;
  312. div.high = id >> 1;
  313. return div.val;
  314. }
  315. noinline static void __init
  316. axs103_set_freq(unsigned int id, unsigned int fd, unsigned int od)
  317. {
  318. write_cgu_reg(encode_div(id, 0),
  319. (void __iomem *)AXC003_CGU + 0x80 + 0,
  320. (void __iomem *)AXC003_CGU + 0x110);
  321. write_cgu_reg(encode_div(fd, 0),
  322. (void __iomem *)AXC003_CGU + 0x80 + 4,
  323. (void __iomem *)AXC003_CGU + 0x110);
  324. write_cgu_reg(encode_div(od, 1),
  325. (void __iomem *)AXC003_CGU + 0x80 + 8,
  326. (void __iomem *)AXC003_CGU + 0x110);
  327. }
  328. static void __init axs103_early_init(void)
  329. {
  330. switch (arc_get_core_freq()/1000000) {
  331. case 33:
  332. axs103_set_freq(1, 1, 1);
  333. break;
  334. case 50:
  335. axs103_set_freq(1, 30, 20);
  336. break;
  337. case 75:
  338. axs103_set_freq(2, 45, 10);
  339. break;
  340. case 90:
  341. axs103_set_freq(2, 54, 10);
  342. break;
  343. case 100:
  344. axs103_set_freq(1, 30, 10);
  345. break;
  346. case 125:
  347. axs103_set_freq(2, 45, 6);
  348. break;
  349. default:
  350. /*
  351. * In this case, core_frequency derived from
  352. * DT "clock-frequency" might not match with board value.
  353. * Hence update it to match the board value.
  354. */
  355. arc_set_core_freq(axs103_get_freq() * 1000000);
  356. break;
  357. }
  358. pr_info("Freq is %dMHz\n", axs103_get_freq());
  359. /* Memory maps already config in pre-bootloader */
  360. /* set GPIO mux to UART */
  361. iowrite32(0x01, (void __iomem *) CREG_CPU_GPIO_UART_MUX);
  362. iowrite32((0x00100000U | 0x000C0000U | 0x00003322U),
  363. (void __iomem *) CREG_CPU_TUN_IO_CTRL);
  364. /* Set up the AXS_MB interrupt system.*/
  365. iowrite32(12, (void __iomem *) (CREG_CPU_AXI_M0_IRQ_MUX
  366. + (AXC003_MST_HS38 << 2)));
  367. /* connect ICTL - Main Board with GPIO line */
  368. iowrite32(0x01, (void __iomem *) CREG_MB_IRQ_MUX);
  369. axs10x_print_board_ver(AXC003_CREG + 4088, "AXC003 CPU Card");
  370. axs10x_early_init();
  371. #ifdef CONFIG_ARC_MCIP
  372. /* No Hardware init, but filling the smp ops callbacks */
  373. mcip_init_early_smp();
  374. #endif
  375. }
  376. #endif
  377. #ifdef CONFIG_AXS101
  378. static const char *axs101_compat[] __initconst = {
  379. "snps,axs101",
  380. NULL,
  381. };
  382. MACHINE_START(AXS101, "axs101")
  383. .dt_compat = axs101_compat,
  384. .init_early = axs101_early_init,
  385. MACHINE_END
  386. #endif /* CONFIG_AXS101 */
  387. #ifdef CONFIG_AXS103
  388. static const char *axs103_compat[] __initconst = {
  389. "snps,axs103",
  390. NULL,
  391. };
  392. MACHINE_START(AXS103, "axs103")
  393. .dt_compat = axs103_compat,
  394. .init_early = axs103_early_init,
  395. #ifdef CONFIG_ARC_MCIP
  396. .init_smp = mcip_init_smp,
  397. #endif
  398. MACHINE_END
  399. /*
  400. * For the VDK OS-kit, to get the offset to pid and command fields
  401. */
  402. char coware_swa_pid_offset[TASK_PID];
  403. char coware_swa_comm_offset[TASK_COMM];
  404. #endif /* CONFIG_AXS103 */