setup-sh7780.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /*
  2. * SH7780 Setup
  3. *
  4. * Copyright (C) 2006 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/io.h>
  14. #include <linux/serial_sci.h>
  15. #include <linux/sh_timer.h>
  16. #include <asm/dma-sh.h>
  17. static struct sh_timer_config tmu0_platform_data = {
  18. .name = "TMU0",
  19. .channel_offset = 0x04,
  20. .timer_bit = 0,
  21. .clk = "peripheral_clk",
  22. .clockevent_rating = 200,
  23. };
  24. static struct resource tmu0_resources[] = {
  25. [0] = {
  26. .name = "TMU0",
  27. .start = 0xffd80008,
  28. .end = 0xffd80013,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. [1] = {
  32. .start = 28,
  33. .flags = IORESOURCE_IRQ,
  34. },
  35. };
  36. static struct platform_device tmu0_device = {
  37. .name = "sh_tmu",
  38. .id = 0,
  39. .dev = {
  40. .platform_data = &tmu0_platform_data,
  41. },
  42. .resource = tmu0_resources,
  43. .num_resources = ARRAY_SIZE(tmu0_resources),
  44. };
  45. static struct sh_timer_config tmu1_platform_data = {
  46. .name = "TMU1",
  47. .channel_offset = 0x10,
  48. .timer_bit = 1,
  49. .clk = "peripheral_clk",
  50. .clocksource_rating = 200,
  51. };
  52. static struct resource tmu1_resources[] = {
  53. [0] = {
  54. .name = "TMU1",
  55. .start = 0xffd80014,
  56. .end = 0xffd8001f,
  57. .flags = IORESOURCE_MEM,
  58. },
  59. [1] = {
  60. .start = 29,
  61. .flags = IORESOURCE_IRQ,
  62. },
  63. };
  64. static struct platform_device tmu1_device = {
  65. .name = "sh_tmu",
  66. .id = 1,
  67. .dev = {
  68. .platform_data = &tmu1_platform_data,
  69. },
  70. .resource = tmu1_resources,
  71. .num_resources = ARRAY_SIZE(tmu1_resources),
  72. };
  73. static struct sh_timer_config tmu2_platform_data = {
  74. .name = "TMU2",
  75. .channel_offset = 0x1c,
  76. .timer_bit = 2,
  77. .clk = "peripheral_clk",
  78. };
  79. static struct resource tmu2_resources[] = {
  80. [0] = {
  81. .name = "TMU2",
  82. .start = 0xffd80020,
  83. .end = 0xffd8002f,
  84. .flags = IORESOURCE_MEM,
  85. },
  86. [1] = {
  87. .start = 30,
  88. .flags = IORESOURCE_IRQ,
  89. },
  90. };
  91. static struct platform_device tmu2_device = {
  92. .name = "sh_tmu",
  93. .id = 2,
  94. .dev = {
  95. .platform_data = &tmu2_platform_data,
  96. },
  97. .resource = tmu2_resources,
  98. .num_resources = ARRAY_SIZE(tmu2_resources),
  99. };
  100. static struct sh_timer_config tmu3_platform_data = {
  101. .name = "TMU3",
  102. .channel_offset = 0x04,
  103. .timer_bit = 0,
  104. .clk = "peripheral_clk",
  105. };
  106. static struct resource tmu3_resources[] = {
  107. [0] = {
  108. .name = "TMU3",
  109. .start = 0xffdc0008,
  110. .end = 0xffdc0013,
  111. .flags = IORESOURCE_MEM,
  112. },
  113. [1] = {
  114. .start = 96,
  115. .flags = IORESOURCE_IRQ,
  116. },
  117. };
  118. static struct platform_device tmu3_device = {
  119. .name = "sh_tmu",
  120. .id = 3,
  121. .dev = {
  122. .platform_data = &tmu3_platform_data,
  123. },
  124. .resource = tmu3_resources,
  125. .num_resources = ARRAY_SIZE(tmu3_resources),
  126. };
  127. static struct sh_timer_config tmu4_platform_data = {
  128. .name = "TMU4",
  129. .channel_offset = 0x10,
  130. .timer_bit = 1,
  131. .clk = "peripheral_clk",
  132. };
  133. static struct resource tmu4_resources[] = {
  134. [0] = {
  135. .name = "TMU4",
  136. .start = 0xffdc0014,
  137. .end = 0xffdc001f,
  138. .flags = IORESOURCE_MEM,
  139. },
  140. [1] = {
  141. .start = 97,
  142. .flags = IORESOURCE_IRQ,
  143. },
  144. };
  145. static struct platform_device tmu4_device = {
  146. .name = "sh_tmu",
  147. .id = 4,
  148. .dev = {
  149. .platform_data = &tmu4_platform_data,
  150. },
  151. .resource = tmu4_resources,
  152. .num_resources = ARRAY_SIZE(tmu4_resources),
  153. };
  154. static struct sh_timer_config tmu5_platform_data = {
  155. .name = "TMU5",
  156. .channel_offset = 0x1c,
  157. .timer_bit = 2,
  158. .clk = "peripheral_clk",
  159. };
  160. static struct resource tmu5_resources[] = {
  161. [0] = {
  162. .name = "TMU5",
  163. .start = 0xffdc0020,
  164. .end = 0xffdc002b,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. [1] = {
  168. .start = 98,
  169. .flags = IORESOURCE_IRQ,
  170. },
  171. };
  172. static struct platform_device tmu5_device = {
  173. .name = "sh_tmu",
  174. .id = 5,
  175. .dev = {
  176. .platform_data = &tmu5_platform_data,
  177. },
  178. .resource = tmu5_resources,
  179. .num_resources = ARRAY_SIZE(tmu5_resources),
  180. };
  181. static struct resource rtc_resources[] = {
  182. [0] = {
  183. .start = 0xffe80000,
  184. .end = 0xffe80000 + 0x58 - 1,
  185. .flags = IORESOURCE_IO,
  186. },
  187. [1] = {
  188. /* Shared Period/Carry/Alarm IRQ */
  189. .start = 20,
  190. .flags = IORESOURCE_IRQ,
  191. },
  192. };
  193. static struct platform_device rtc_device = {
  194. .name = "sh-rtc",
  195. .id = -1,
  196. .num_resources = ARRAY_SIZE(rtc_resources),
  197. .resource = rtc_resources,
  198. };
  199. static struct plat_sci_port sci_platform_data[] = {
  200. {
  201. .mapbase = 0xffe00000,
  202. .flags = UPF_BOOT_AUTOCONF,
  203. .type = PORT_SCIF,
  204. .irqs = { 40, 40, 40, 40 },
  205. }, {
  206. .mapbase = 0xffe10000,
  207. .flags = UPF_BOOT_AUTOCONF,
  208. .type = PORT_SCIF,
  209. .irqs = { 76, 76, 76, 76 },
  210. }, {
  211. .flags = 0,
  212. }
  213. };
  214. static struct platform_device sci_device = {
  215. .name = "sh-sci",
  216. .id = -1,
  217. .dev = {
  218. .platform_data = sci_platform_data,
  219. },
  220. };
  221. static struct sh_dmae_pdata dma_platform_data = {
  222. .mode = (SHDMA_MIX_IRQ | SHDMA_DMAOR1),
  223. };
  224. static struct platform_device dma_device = {
  225. .name = "sh-dma-engine",
  226. .id = -1,
  227. .dev = {
  228. .platform_data = &dma_platform_data,
  229. },
  230. };
  231. static struct platform_device *sh7780_devices[] __initdata = {
  232. &tmu0_device,
  233. &tmu1_device,
  234. &tmu2_device,
  235. &tmu3_device,
  236. &tmu4_device,
  237. &tmu5_device,
  238. &rtc_device,
  239. &sci_device,
  240. &dma_device,
  241. };
  242. static int __init sh7780_devices_setup(void)
  243. {
  244. return platform_add_devices(sh7780_devices,
  245. ARRAY_SIZE(sh7780_devices));
  246. }
  247. arch_initcall(sh7780_devices_setup);
  248. static struct platform_device *sh7780_early_devices[] __initdata = {
  249. &tmu0_device,
  250. &tmu1_device,
  251. &tmu2_device,
  252. &tmu3_device,
  253. &tmu4_device,
  254. &tmu5_device,
  255. };
  256. void __init plat_early_device_setup(void)
  257. {
  258. early_platform_add_devices(sh7780_early_devices,
  259. ARRAY_SIZE(sh7780_early_devices));
  260. }
  261. enum {
  262. UNUSED = 0,
  263. /* interrupt sources */
  264. IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
  265. IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
  266. IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
  267. IRL_HHLL, IRL_HHLH, IRL_HHHL,
  268. IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
  269. RTC, WDT, TMU0, TMU1, TMU2, TMU2_TICPI,
  270. HUDI, DMAC0, SCIF0, DMAC1, CMT, HAC,
  271. PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD, PCIC5,
  272. SCIF1, SIOF, HSPI, MMCIF, TMU3, TMU4, TMU5, SSI, FLCTL, GPIO,
  273. /* interrupt groups */
  274. TMU012, TMU345,
  275. };
  276. static struct intc_vect vectors[] __initdata = {
  277. INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
  278. INTC_VECT(RTC, 0x4c0),
  279. INTC_VECT(WDT, 0x560),
  280. INTC_VECT(TMU0, 0x580), INTC_VECT(TMU1, 0x5a0),
  281. INTC_VECT(TMU2, 0x5c0), INTC_VECT(TMU2_TICPI, 0x5e0),
  282. INTC_VECT(HUDI, 0x600),
  283. INTC_VECT(DMAC0, 0x640), INTC_VECT(DMAC0, 0x660),
  284. INTC_VECT(DMAC0, 0x680), INTC_VECT(DMAC0, 0x6a0),
  285. INTC_VECT(DMAC0, 0x6c0),
  286. INTC_VECT(SCIF0, 0x700), INTC_VECT(SCIF0, 0x720),
  287. INTC_VECT(SCIF0, 0x740), INTC_VECT(SCIF0, 0x760),
  288. INTC_VECT(DMAC0, 0x780), INTC_VECT(DMAC0, 0x7a0),
  289. INTC_VECT(DMAC1, 0x7c0), INTC_VECT(DMAC1, 0x7e0),
  290. INTC_VECT(CMT, 0x900), INTC_VECT(HAC, 0x980),
  291. INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20),
  292. INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60),
  293. INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIC5, 0xaa0),
  294. INTC_VECT(PCIC5, 0xac0), INTC_VECT(PCIC5, 0xae0),
  295. INTC_VECT(PCIC5, 0xb00), INTC_VECT(PCIC5, 0xb20),
  296. INTC_VECT(SCIF1, 0xb80), INTC_VECT(SCIF1, 0xba0),
  297. INTC_VECT(SCIF1, 0xbc0), INTC_VECT(SCIF1, 0xbe0),
  298. INTC_VECT(SIOF, 0xc00), INTC_VECT(HSPI, 0xc80),
  299. INTC_VECT(MMCIF, 0xd00), INTC_VECT(MMCIF, 0xd20),
  300. INTC_VECT(MMCIF, 0xd40), INTC_VECT(MMCIF, 0xd60),
  301. INTC_VECT(DMAC1, 0xd80), INTC_VECT(DMAC1, 0xda0),
  302. INTC_VECT(DMAC1, 0xdc0), INTC_VECT(DMAC1, 0xde0),
  303. INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20),
  304. INTC_VECT(TMU5, 0xe40),
  305. INTC_VECT(SSI, 0xe80),
  306. INTC_VECT(FLCTL, 0xf00), INTC_VECT(FLCTL, 0xf20),
  307. INTC_VECT(FLCTL, 0xf40), INTC_VECT(FLCTL, 0xf60),
  308. INTC_VECT(GPIO, 0xf80), INTC_VECT(GPIO, 0xfa0),
  309. INTC_VECT(GPIO, 0xfc0), INTC_VECT(GPIO, 0xfe0),
  310. };
  311. static struct intc_group groups[] __initdata = {
  312. INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI),
  313. INTC_GROUP(TMU345, TMU3, TMU4, TMU5),
  314. };
  315. static struct intc_mask_reg mask_registers[] __initdata = {
  316. { 0xffd40038, 0xffd4003c, 32, /* INT2MSKR / INT2MSKCR */
  317. { 0, 0, 0, 0, 0, 0, GPIO, FLCTL,
  318. SSI, MMCIF, HSPI, SIOF, PCIC5, PCIINTD, PCIINTC, PCIINTB,
  319. PCIINTA, PCISERR, HAC, CMT, 0, 0, DMAC1, DMAC0,
  320. HUDI, 0, WDT, SCIF1, SCIF0, RTC, TMU345, TMU012 } },
  321. };
  322. static struct intc_prio_reg prio_registers[] __initdata = {
  323. { 0xffd40000, 0, 32, 8, /* INT2PRI0 */ { TMU0, TMU1,
  324. TMU2, TMU2_TICPI } },
  325. { 0xffd40004, 0, 32, 8, /* INT2PRI1 */ { TMU3, TMU4, TMU5, RTC } },
  326. { 0xffd40008, 0, 32, 8, /* INT2PRI2 */ { SCIF0, SCIF1, WDT } },
  327. { 0xffd4000c, 0, 32, 8, /* INT2PRI3 */ { HUDI, DMAC0, DMAC1 } },
  328. { 0xffd40010, 0, 32, 8, /* INT2PRI4 */ { CMT, HAC,
  329. PCISERR, PCIINTA, } },
  330. { 0xffd40014, 0, 32, 8, /* INT2PRI5 */ { PCIINTB, PCIINTC,
  331. PCIINTD, PCIC5 } },
  332. { 0xffd40018, 0, 32, 8, /* INT2PRI6 */ { SIOF, HSPI, MMCIF, SSI } },
  333. { 0xffd4001c, 0, 32, 8, /* INT2PRI7 */ { FLCTL, GPIO } },
  334. };
  335. static DECLARE_INTC_DESC(intc_desc, "sh7780", vectors, groups,
  336. mask_registers, prio_registers, NULL);
  337. /* Support for external interrupt pins in IRQ mode */
  338. static struct intc_vect irq_vectors[] __initdata = {
  339. INTC_VECT(IRQ0, 0x240), INTC_VECT(IRQ1, 0x280),
  340. INTC_VECT(IRQ2, 0x2c0), INTC_VECT(IRQ3, 0x300),
  341. INTC_VECT(IRQ4, 0x340), INTC_VECT(IRQ5, 0x380),
  342. INTC_VECT(IRQ6, 0x3c0), INTC_VECT(IRQ7, 0x200),
  343. };
  344. static struct intc_mask_reg irq_mask_registers[] __initdata = {
  345. { 0xffd00044, 0xffd00064, 32, /* INTMSK0 / INTMSKCLR0 */
  346. { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
  347. };
  348. static struct intc_prio_reg irq_prio_registers[] __initdata = {
  349. { 0xffd00010, 0, 32, 4, /* INTPRI */ { IRQ0, IRQ1, IRQ2, IRQ3,
  350. IRQ4, IRQ5, IRQ6, IRQ7 } },
  351. };
  352. static struct intc_sense_reg irq_sense_registers[] __initdata = {
  353. { 0xffd0001c, 32, 2, /* ICR1 */ { IRQ0, IRQ1, IRQ2, IRQ3,
  354. IRQ4, IRQ5, IRQ6, IRQ7 } },
  355. };
  356. static struct intc_mask_reg irq_ack_registers[] __initdata = {
  357. { 0xffd00024, 0, 32, /* INTREQ */
  358. { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
  359. };
  360. static DECLARE_INTC_DESC_ACK(intc_irq_desc, "sh7780-irq", irq_vectors,
  361. NULL, irq_mask_registers, irq_prio_registers,
  362. irq_sense_registers, irq_ack_registers);
  363. /* External interrupt pins in IRL mode */
  364. static struct intc_vect irl_vectors[] __initdata = {
  365. INTC_VECT(IRL_LLLL, 0x200), INTC_VECT(IRL_LLLH, 0x220),
  366. INTC_VECT(IRL_LLHL, 0x240), INTC_VECT(IRL_LLHH, 0x260),
  367. INTC_VECT(IRL_LHLL, 0x280), INTC_VECT(IRL_LHLH, 0x2a0),
  368. INTC_VECT(IRL_LHHL, 0x2c0), INTC_VECT(IRL_LHHH, 0x2e0),
  369. INTC_VECT(IRL_HLLL, 0x300), INTC_VECT(IRL_HLLH, 0x320),
  370. INTC_VECT(IRL_HLHL, 0x340), INTC_VECT(IRL_HLHH, 0x360),
  371. INTC_VECT(IRL_HHLL, 0x380), INTC_VECT(IRL_HHLH, 0x3a0),
  372. INTC_VECT(IRL_HHHL, 0x3c0),
  373. };
  374. static struct intc_mask_reg irl3210_mask_registers[] __initdata = {
  375. { 0xffd40080, 0xffd40084, 32, /* INTMSK2 / INTMSKCLR2 */
  376. { IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
  377. IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
  378. IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
  379. IRL_HHLL, IRL_HHLH, IRL_HHHL, } },
  380. };
  381. static struct intc_mask_reg irl7654_mask_registers[] __initdata = {
  382. { 0xffd40080, 0xffd40084, 32, /* INTMSK2 / INTMSKCLR2 */
  383. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  384. IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
  385. IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
  386. IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
  387. IRL_HHLL, IRL_HHLH, IRL_HHHL, } },
  388. };
  389. static DECLARE_INTC_DESC(intc_irl7654_desc, "sh7780-irl7654", irl_vectors,
  390. NULL, irl7654_mask_registers, NULL, NULL);
  391. static DECLARE_INTC_DESC(intc_irl3210_desc, "sh7780-irl3210", irl_vectors,
  392. NULL, irl3210_mask_registers, NULL, NULL);
  393. #define INTC_ICR0 0xffd00000
  394. #define INTC_INTMSK0 0xffd00044
  395. #define INTC_INTMSK1 0xffd00048
  396. #define INTC_INTMSK2 0xffd40080
  397. #define INTC_INTMSKCLR1 0xffd00068
  398. #define INTC_INTMSKCLR2 0xffd40084
  399. void __init plat_irq_setup(void)
  400. {
  401. /* disable IRQ7-0 */
  402. ctrl_outl(0xff000000, INTC_INTMSK0);
  403. /* disable IRL3-0 + IRL7-4 */
  404. ctrl_outl(0xc0000000, INTC_INTMSK1);
  405. ctrl_outl(0xfffefffe, INTC_INTMSK2);
  406. /* select IRL mode for IRL3-0 + IRL7-4 */
  407. ctrl_outl(ctrl_inl(INTC_ICR0) & ~0x00c00000, INTC_ICR0);
  408. /* disable holding function, ie enable "SH-4 Mode" */
  409. ctrl_outl(ctrl_inl(INTC_ICR0) | 0x00200000, INTC_ICR0);
  410. register_intc_controller(&intc_desc);
  411. }
  412. void __init plat_irq_setup_pins(int mode)
  413. {
  414. switch (mode) {
  415. case IRQ_MODE_IRQ:
  416. /* select IRQ mode for IRL3-0 + IRL7-4 */
  417. ctrl_outl(ctrl_inl(INTC_ICR0) | 0x00c00000, INTC_ICR0);
  418. register_intc_controller(&intc_irq_desc);
  419. break;
  420. case IRQ_MODE_IRL7654:
  421. /* enable IRL7-4 but don't provide any masking */
  422. ctrl_outl(0x40000000, INTC_INTMSKCLR1);
  423. ctrl_outl(0x0000fffe, INTC_INTMSKCLR2);
  424. break;
  425. case IRQ_MODE_IRL3210:
  426. /* enable IRL0-3 but don't provide any masking */
  427. ctrl_outl(0x80000000, INTC_INTMSKCLR1);
  428. ctrl_outl(0xfffe0000, INTC_INTMSKCLR2);
  429. break;
  430. case IRQ_MODE_IRL7654_MASK:
  431. /* enable IRL7-4 and mask using cpu intc controller */
  432. ctrl_outl(0x40000000, INTC_INTMSKCLR1);
  433. register_intc_controller(&intc_irl7654_desc);
  434. break;
  435. case IRQ_MODE_IRL3210_MASK:
  436. /* enable IRL0-3 and mask using cpu intc controller */
  437. ctrl_outl(0x80000000, INTC_INTMSKCLR1);
  438. register_intc_controller(&intc_irl3210_desc);
  439. break;
  440. default:
  441. BUG();
  442. }
  443. }