setup-shx3.c 13 KB

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