setup-shx3.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SH-X3 Prototype Setup
  4. *
  5. * Copyright (C) 2007 - 2010 Paul Mundt
  6. */
  7. #include <linux/platform_device.h>
  8. #include <linux/init.h>
  9. #include <linux/serial.h>
  10. #include <linux/serial_sci.h>
  11. #include <linux/io.h>
  12. #include <linux/gpio.h>
  13. #include <linux/sh_timer.h>
  14. #include <linux/sh_intc.h>
  15. #include <cpu/shx3.h>
  16. #include <asm/mmzone.h>
  17. #include <asm/platform_early.h>
  18. /*
  19. * This intentionally only registers SCIF ports 0, 1, and 3. SCIF 2
  20. * INTEVT values overlap with the FPU EXPEVT ones, requiring special
  21. * demuxing in the exception dispatch path.
  22. *
  23. * As this overlap is something that never should have made it in to
  24. * silicon in the first place, we just refuse to deal with the port at
  25. * all rather than adding infrastructure to hack around it.
  26. */
  27. static struct plat_sci_port scif0_platform_data = {
  28. .scscr = SCSCR_REIE,
  29. .type = PORT_SCIF,
  30. };
  31. static struct resource scif0_resources[] = {
  32. DEFINE_RES_MEM(0xffc30000, 0x100),
  33. DEFINE_RES_IRQ(evt2irq(0x700)),
  34. DEFINE_RES_IRQ(evt2irq(0x720)),
  35. DEFINE_RES_IRQ(evt2irq(0x760)),
  36. DEFINE_RES_IRQ(evt2irq(0x740)),
  37. };
  38. static struct platform_device scif0_device = {
  39. .name = "sh-sci",
  40. .id = 0,
  41. .resource = scif0_resources,
  42. .num_resources = ARRAY_SIZE(scif0_resources),
  43. .dev = {
  44. .platform_data = &scif0_platform_data,
  45. },
  46. };
  47. static struct plat_sci_port scif1_platform_data = {
  48. .scscr = SCSCR_REIE,
  49. .type = PORT_SCIF,
  50. };
  51. static struct resource scif1_resources[] = {
  52. DEFINE_RES_MEM(0xffc40000, 0x100),
  53. DEFINE_RES_IRQ(evt2irq(0x780)),
  54. DEFINE_RES_IRQ(evt2irq(0x7a0)),
  55. DEFINE_RES_IRQ(evt2irq(0x7e0)),
  56. DEFINE_RES_IRQ(evt2irq(0x7c0)),
  57. };
  58. static struct platform_device scif1_device = {
  59. .name = "sh-sci",
  60. .id = 1,
  61. .resource = scif1_resources,
  62. .num_resources = ARRAY_SIZE(scif1_resources),
  63. .dev = {
  64. .platform_data = &scif1_platform_data,
  65. },
  66. };
  67. static struct plat_sci_port scif2_platform_data = {
  68. .scscr = SCSCR_REIE,
  69. .type = PORT_SCIF,
  70. };
  71. static struct resource scif2_resources[] = {
  72. DEFINE_RES_MEM(0xffc60000, 0x100),
  73. DEFINE_RES_IRQ(evt2irq(0x880)),
  74. DEFINE_RES_IRQ(evt2irq(0x8a0)),
  75. DEFINE_RES_IRQ(evt2irq(0x8e0)),
  76. DEFINE_RES_IRQ(evt2irq(0x8c0)),
  77. };
  78. static struct platform_device scif2_device = {
  79. .name = "sh-sci",
  80. .id = 2,
  81. .resource = scif2_resources,
  82. .num_resources = ARRAY_SIZE(scif2_resources),
  83. .dev = {
  84. .platform_data = &scif2_platform_data,
  85. },
  86. };
  87. static struct sh_timer_config tmu0_platform_data = {
  88. .channels_mask = 7,
  89. };
  90. static struct resource tmu0_resources[] = {
  91. DEFINE_RES_MEM(0xffc10000, 0x30),
  92. DEFINE_RES_IRQ(evt2irq(0x400)),
  93. DEFINE_RES_IRQ(evt2irq(0x420)),
  94. DEFINE_RES_IRQ(evt2irq(0x440)),
  95. };
  96. static struct platform_device tmu0_device = {
  97. .name = "sh-tmu",
  98. .id = 0,
  99. .dev = {
  100. .platform_data = &tmu0_platform_data,
  101. },
  102. .resource = tmu0_resources,
  103. .num_resources = ARRAY_SIZE(tmu0_resources),
  104. };
  105. static struct sh_timer_config tmu1_platform_data = {
  106. .channels_mask = 7,
  107. };
  108. static struct resource tmu1_resources[] = {
  109. DEFINE_RES_MEM(0xffc20000, 0x2c),
  110. DEFINE_RES_IRQ(evt2irq(0x460)),
  111. DEFINE_RES_IRQ(evt2irq(0x480)),
  112. DEFINE_RES_IRQ(evt2irq(0x4a0)),
  113. };
  114. static struct platform_device tmu1_device = {
  115. .name = "sh-tmu",
  116. .id = 1,
  117. .dev = {
  118. .platform_data = &tmu1_platform_data,
  119. },
  120. .resource = tmu1_resources,
  121. .num_resources = ARRAY_SIZE(tmu1_resources),
  122. };
  123. static struct platform_device *shx3_early_devices[] __initdata = {
  124. &scif0_device,
  125. &scif1_device,
  126. &scif2_device,
  127. &tmu0_device,
  128. &tmu1_device,
  129. };
  130. static int __init shx3_devices_setup(void)
  131. {
  132. return platform_add_devices(shx3_early_devices,
  133. ARRAY_SIZE(shx3_early_devices));
  134. }
  135. arch_initcall(shx3_devices_setup);
  136. void __init plat_early_device_setup(void)
  137. {
  138. sh_early_platform_add_devices(shx3_early_devices,
  139. ARRAY_SIZE(shx3_early_devices));
  140. }
  141. enum {
  142. UNUSED = 0,
  143. /* interrupt sources */
  144. IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
  145. IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
  146. IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
  147. IRL_HHLL, IRL_HHLH, IRL_HHHL,
  148. IRQ0, IRQ1, IRQ2, IRQ3,
  149. HUDII,
  150. TMU0, TMU1, TMU2, TMU3, TMU4, TMU5,
  151. PCII0, PCII1, PCII2, PCII3, PCII4,
  152. PCII5, PCII6, PCII7, PCII8, PCII9,
  153. SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI,
  154. SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI,
  155. SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI,
  156. SCIF3_ERI, SCIF3_RXI, SCIF3_BRI, SCIF3_TXI,
  157. DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2, DMAC0_DMINT3,
  158. DMAC0_DMINT4, DMAC0_DMINT5, DMAC0_DMAE,
  159. DU,
  160. DMAC1_DMINT6, DMAC1_DMINT7, DMAC1_DMINT8, DMAC1_DMINT9,
  161. DMAC1_DMINT10, DMAC1_DMINT11, DMAC1_DMAE,
  162. IIC, VIN0, VIN1, VCORE0, ATAPI,
  163. DTU0, DTU1, DTU2, DTU3,
  164. FE0, FE1,
  165. GPIO0, GPIO1, GPIO2, GPIO3,
  166. PAM, IRM,
  167. INTICI0, INTICI1, INTICI2, INTICI3,
  168. INTICI4, INTICI5, INTICI6, INTICI7,
  169. /* interrupt groups */
  170. IRL, PCII56789, SCIF0, SCIF1, SCIF2, SCIF3,
  171. DMAC0, DMAC1,
  172. };
  173. static struct intc_vect vectors[] __initdata = {
  174. INTC_VECT(HUDII, 0x3e0),
  175. INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
  176. INTC_VECT(TMU2, 0x440), INTC_VECT(TMU3, 0x460),
  177. INTC_VECT(TMU4, 0x480), INTC_VECT(TMU5, 0x4a0),
  178. INTC_VECT(PCII0, 0x500), INTC_VECT(PCII1, 0x520),
  179. INTC_VECT(PCII2, 0x540), INTC_VECT(PCII3, 0x560),
  180. INTC_VECT(PCII4, 0x580), INTC_VECT(PCII5, 0x5a0),
  181. INTC_VECT(PCII6, 0x5c0), INTC_VECT(PCII7, 0x5e0),
  182. INTC_VECT(PCII8, 0x600), INTC_VECT(PCII9, 0x620),
  183. INTC_VECT(SCIF0_ERI, 0x700), INTC_VECT(SCIF0_RXI, 0x720),
  184. INTC_VECT(SCIF0_BRI, 0x740), INTC_VECT(SCIF0_TXI, 0x760),
  185. INTC_VECT(SCIF1_ERI, 0x780), INTC_VECT(SCIF1_RXI, 0x7a0),
  186. INTC_VECT(SCIF1_BRI, 0x7c0), INTC_VECT(SCIF1_TXI, 0x7e0),
  187. INTC_VECT(SCIF3_ERI, 0x880), INTC_VECT(SCIF3_RXI, 0x8a0),
  188. INTC_VECT(SCIF3_BRI, 0x8c0), INTC_VECT(SCIF3_TXI, 0x8e0),
  189. INTC_VECT(DMAC0_DMINT0, 0x900), INTC_VECT(DMAC0_DMINT1, 0x920),
  190. INTC_VECT(DMAC0_DMINT2, 0x940), INTC_VECT(DMAC0_DMINT3, 0x960),
  191. INTC_VECT(DMAC0_DMINT4, 0x980), INTC_VECT(DMAC0_DMINT5, 0x9a0),
  192. INTC_VECT(DMAC0_DMAE, 0x9c0),
  193. INTC_VECT(DU, 0x9e0),
  194. INTC_VECT(DMAC1_DMINT6, 0xa00), INTC_VECT(DMAC1_DMINT7, 0xa20),
  195. INTC_VECT(DMAC1_DMINT8, 0xa40), INTC_VECT(DMAC1_DMINT9, 0xa60),
  196. INTC_VECT(DMAC1_DMINT10, 0xa80), INTC_VECT(DMAC1_DMINT11, 0xaa0),
  197. INTC_VECT(DMAC1_DMAE, 0xac0),
  198. INTC_VECT(IIC, 0xae0),
  199. INTC_VECT(VIN0, 0xb00), INTC_VECT(VIN1, 0xb20),
  200. INTC_VECT(VCORE0, 0xb00), INTC_VECT(ATAPI, 0xb60),
  201. INTC_VECT(DTU0, 0xc00), INTC_VECT(DTU0, 0xc20),
  202. INTC_VECT(DTU0, 0xc40),
  203. INTC_VECT(DTU1, 0xc60), INTC_VECT(DTU1, 0xc80),
  204. INTC_VECT(DTU1, 0xca0),
  205. INTC_VECT(DTU2, 0xcc0), INTC_VECT(DTU2, 0xce0),
  206. INTC_VECT(DTU2, 0xd00),
  207. INTC_VECT(DTU3, 0xd20), INTC_VECT(DTU3, 0xd40),
  208. INTC_VECT(DTU3, 0xd60),
  209. INTC_VECT(FE0, 0xe00), INTC_VECT(FE1, 0xe20),
  210. INTC_VECT(GPIO0, 0xe40), INTC_VECT(GPIO1, 0xe60),
  211. INTC_VECT(GPIO2, 0xe80), INTC_VECT(GPIO3, 0xea0),
  212. INTC_VECT(PAM, 0xec0), INTC_VECT(IRM, 0xee0),
  213. INTC_VECT(INTICI0, 0xf00), INTC_VECT(INTICI1, 0xf20),
  214. INTC_VECT(INTICI2, 0xf40), INTC_VECT(INTICI3, 0xf60),
  215. INTC_VECT(INTICI4, 0xf80), INTC_VECT(INTICI5, 0xfa0),
  216. INTC_VECT(INTICI6, 0xfc0), INTC_VECT(INTICI7, 0xfe0),
  217. };
  218. static struct intc_group groups[] __initdata = {
  219. INTC_GROUP(IRL, IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
  220. IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
  221. IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
  222. IRL_HHLL, IRL_HHLH, IRL_HHHL),
  223. INTC_GROUP(PCII56789, PCII5, PCII6, PCII7, PCII8, PCII9),
  224. INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
  225. INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
  226. INTC_GROUP(SCIF3, SCIF3_ERI, SCIF3_RXI, SCIF3_BRI, SCIF3_TXI),
  227. INTC_GROUP(DMAC0, DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2,
  228. DMAC0_DMINT3, DMAC0_DMINT4, DMAC0_DMINT5, DMAC0_DMAE),
  229. INTC_GROUP(DMAC1, DMAC1_DMINT6, DMAC1_DMINT7, DMAC1_DMINT8,
  230. DMAC1_DMINT9, DMAC1_DMINT10, DMAC1_DMINT11),
  231. };
  232. #define INT2DISTCR0 0xfe4108a0
  233. #define INT2DISTCR1 0xfe4108a4
  234. #define INT2DISTCR2 0xfe4108a8
  235. static struct intc_mask_reg mask_registers[] __initdata = {
  236. { 0xfe410030, 0xfe410050, 32, /* CnINTMSK0 / CnINTMSKCLR0 */
  237. { IRQ0, IRQ1, IRQ2, IRQ3 } },
  238. { 0xfe410040, 0xfe410060, 32, /* CnINTMSK1 / CnINTMSKCLR1 */
  239. { IRL } },
  240. { 0xfe410820, 0xfe410850, 32, /* CnINT2MSK0 / CnINT2MSKCLR0 */
  241. { FE1, FE0, 0, ATAPI, VCORE0, VIN1, VIN0, IIC,
  242. DU, GPIO3, GPIO2, GPIO1, GPIO0, PAM, 0, 0,
  243. 0, 0, 0, 0, 0, 0, 0, 0, /* HUDI bits ignored */
  244. 0, TMU5, TMU4, TMU3, TMU2, TMU1, TMU0, 0, },
  245. INTC_SMP_BALANCING(INT2DISTCR0) },
  246. { 0xfe410830, 0xfe410860, 32, /* CnINT2MSK1 / CnINT2MSKCLR1 */
  247. { 0, 0, 0, 0, DTU3, DTU2, DTU1, DTU0, /* IRM bits ignored */
  248. PCII9, PCII8, PCII7, PCII6, PCII5, PCII4, PCII3, PCII2,
  249. PCII1, PCII0, DMAC1_DMAE, DMAC1_DMINT11,
  250. DMAC1_DMINT10, DMAC1_DMINT9, DMAC1_DMINT8, DMAC1_DMINT7,
  251. DMAC1_DMINT6, DMAC0_DMAE, DMAC0_DMINT5, DMAC0_DMINT4,
  252. DMAC0_DMINT3, DMAC0_DMINT2, DMAC0_DMINT1, DMAC0_DMINT0 },
  253. INTC_SMP_BALANCING(INT2DISTCR1) },
  254. { 0xfe410840, 0xfe410870, 32, /* CnINT2MSK2 / CnINT2MSKCLR2 */
  255. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  256. SCIF3_TXI, SCIF3_BRI, SCIF3_RXI, SCIF3_ERI,
  257. SCIF2_TXI, SCIF2_BRI, SCIF2_RXI, SCIF2_ERI,
  258. SCIF1_TXI, SCIF1_BRI, SCIF1_RXI, SCIF1_ERI,
  259. SCIF0_TXI, SCIF0_BRI, SCIF0_RXI, SCIF0_ERI },
  260. INTC_SMP_BALANCING(INT2DISTCR2) },
  261. };
  262. static struct intc_prio_reg prio_registers[] __initdata = {
  263. { 0xfe410010, 0, 32, 4, /* INTPRI */ { IRQ0, IRQ1, IRQ2, IRQ3 } },
  264. { 0xfe410800, 0, 32, 4, /* INT2PRI0 */ { 0, HUDII, TMU5, TMU4,
  265. TMU3, TMU2, TMU1, TMU0 } },
  266. { 0xfe410804, 0, 32, 4, /* INT2PRI1 */ { DTU3, DTU2, DTU1, DTU0,
  267. SCIF3, SCIF2,
  268. SCIF1, SCIF0 } },
  269. { 0xfe410808, 0, 32, 4, /* INT2PRI2 */ { DMAC1, DMAC0,
  270. PCII56789, PCII4,
  271. PCII3, PCII2,
  272. PCII1, PCII0 } },
  273. { 0xfe41080c, 0, 32, 4, /* INT2PRI3 */ { FE1, FE0, ATAPI, VCORE0,
  274. VIN1, VIN0, IIC, DU} },
  275. { 0xfe410810, 0, 32, 4, /* INT2PRI4 */ { 0, 0, PAM, GPIO3,
  276. GPIO2, GPIO1, GPIO0, IRM } },
  277. { 0xfe410090, 0xfe4100a0, 32, 4, /* CnICIPRI / CnICIPRICLR */
  278. { INTICI7, INTICI6, INTICI5, INTICI4,
  279. INTICI3, INTICI2, INTICI1, INTICI0 }, INTC_SMP(4, 4) },
  280. };
  281. static DECLARE_INTC_DESC(intc_desc, "shx3", vectors, groups,
  282. mask_registers, prio_registers, NULL);
  283. /* Support for external interrupt pins in IRQ mode */
  284. static struct intc_vect vectors_irq[] __initdata = {
  285. INTC_VECT(IRQ0, 0x240), INTC_VECT(IRQ1, 0x280),
  286. INTC_VECT(IRQ2, 0x2c0), INTC_VECT(IRQ3, 0x300),
  287. };
  288. static struct intc_sense_reg sense_registers[] __initdata = {
  289. { 0xfe41001c, 32, 2, /* ICR1 */ { IRQ0, IRQ1, IRQ2, IRQ3 } },
  290. };
  291. static DECLARE_INTC_DESC(intc_desc_irq, "shx3-irq", vectors_irq, groups,
  292. mask_registers, prio_registers, sense_registers);
  293. /* External interrupt pins in IRL mode */
  294. static struct intc_vect vectors_irl[] __initdata = {
  295. INTC_VECT(IRL_LLLL, 0x200), INTC_VECT(IRL_LLLH, 0x220),
  296. INTC_VECT(IRL_LLHL, 0x240), INTC_VECT(IRL_LLHH, 0x260),
  297. INTC_VECT(IRL_LHLL, 0x280), INTC_VECT(IRL_LHLH, 0x2a0),
  298. INTC_VECT(IRL_LHHL, 0x2c0), INTC_VECT(IRL_LHHH, 0x2e0),
  299. INTC_VECT(IRL_HLLL, 0x300), INTC_VECT(IRL_HLLH, 0x320),
  300. INTC_VECT(IRL_HLHL, 0x340), INTC_VECT(IRL_HLHH, 0x360),
  301. INTC_VECT(IRL_HHLL, 0x380), INTC_VECT(IRL_HHLH, 0x3a0),
  302. INTC_VECT(IRL_HHHL, 0x3c0),
  303. };
  304. static DECLARE_INTC_DESC(intc_desc_irl, "shx3-irl", vectors_irl, groups,
  305. mask_registers, prio_registers, NULL);
  306. void __init plat_irq_setup_pins(int mode)
  307. {
  308. int ret = 0;
  309. switch (mode) {
  310. case IRQ_MODE_IRQ:
  311. ret |= gpio_request(GPIO_FN_IRQ3, intc_desc_irq.name);
  312. ret |= gpio_request(GPIO_FN_IRQ2, intc_desc_irq.name);
  313. ret |= gpio_request(GPIO_FN_IRQ1, intc_desc_irq.name);
  314. ret |= gpio_request(GPIO_FN_IRQ0, intc_desc_irq.name);
  315. if (unlikely(ret)) {
  316. pr_err("Failed to set IRQ mode\n");
  317. return;
  318. }
  319. register_intc_controller(&intc_desc_irq);
  320. break;
  321. case IRQ_MODE_IRL3210:
  322. ret |= gpio_request(GPIO_FN_IRL3, intc_desc_irl.name);
  323. ret |= gpio_request(GPIO_FN_IRL2, intc_desc_irl.name);
  324. ret |= gpio_request(GPIO_FN_IRL1, intc_desc_irl.name);
  325. ret |= gpio_request(GPIO_FN_IRL0, intc_desc_irl.name);
  326. if (unlikely(ret)) {
  327. pr_err("Failed to set IRL mode\n");
  328. return;
  329. }
  330. register_intc_controller(&intc_desc_irl);
  331. break;
  332. default:
  333. BUG();
  334. }
  335. }
  336. void __init plat_irq_setup(void)
  337. {
  338. register_intc_controller(&intc_desc);
  339. }
  340. void __init plat_mem_setup(void)
  341. {
  342. unsigned int nid = 1;
  343. /* Register CPU#0 URAM space as Node 1 */
  344. setup_bootmem_node(nid++, 0x145f0000, 0x14610000); /* CPU0 */
  345. #if 0
  346. /* XXX: Not yet.. */
  347. setup_bootmem_node(nid++, 0x14df0000, 0x14e10000); /* CPU1 */
  348. setup_bootmem_node(nid++, 0x155f0000, 0x15610000); /* CPU2 */
  349. setup_bootmem_node(nid++, 0x15df0000, 0x15e10000); /* CPU3 */
  350. #endif
  351. setup_bootmem_node(nid++, 0x16000000, 0x16020000); /* CSM */
  352. }