setup-sh7780.c 13 KB

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