setup-sh7750.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /*
  2. * SH7091/SH7750/SH7750S/SH7750R/SH7751/SH7751R Setup
  3. *
  4. * Copyright (C) 2006 Paul Mundt
  5. * Copyright (C) 2006 Jamie Lenehan
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/init.h>
  13. #include <linux/serial.h>
  14. #include <linux/io.h>
  15. #include <linux/sh_timer.h>
  16. #include <linux/sh_intc.h>
  17. #include <linux/serial_sci.h>
  18. #include <generated/machtypes.h>
  19. static struct resource rtc_resources[] = {
  20. [0] = {
  21. .start = 0xffc80000,
  22. .end = 0xffc80000 + 0x58 - 1,
  23. .flags = IORESOURCE_IO,
  24. },
  25. [1] = {
  26. /* Shared Period/Carry/Alarm IRQ */
  27. .start = evt2irq(0x480),
  28. .flags = IORESOURCE_IRQ,
  29. },
  30. };
  31. static struct platform_device rtc_device = {
  32. .name = "sh-rtc",
  33. .id = -1,
  34. .num_resources = ARRAY_SIZE(rtc_resources),
  35. .resource = rtc_resources,
  36. };
  37. static struct plat_sci_port sci_platform_data = {
  38. .port_reg = 0xffe0001C,
  39. .flags = UPF_BOOT_AUTOCONF,
  40. .scscr = SCSCR_TE | SCSCR_RE,
  41. .type = PORT_SCI,
  42. .regshift = 2,
  43. };
  44. static struct resource sci_resources[] = {
  45. DEFINE_RES_MEM(0xffe00000, 0x100),
  46. DEFINE_RES_IRQ(evt2irq(0x4e0)),
  47. };
  48. static struct platform_device sci_device = {
  49. .name = "sh-sci",
  50. .id = 0,
  51. .resource = sci_resources,
  52. .num_resources = ARRAY_SIZE(sci_resources),
  53. .dev = {
  54. .platform_data = &sci_platform_data,
  55. },
  56. };
  57. static struct plat_sci_port scif_platform_data = {
  58. .flags = UPF_BOOT_AUTOCONF,
  59. .scscr = SCSCR_TE | SCSCR_RE | SCSCR_REIE,
  60. .type = PORT_SCIF,
  61. };
  62. static struct resource scif_resources[] = {
  63. DEFINE_RES_MEM(0xffe80000, 0x100),
  64. DEFINE_RES_IRQ(evt2irq(0x700)),
  65. };
  66. static struct platform_device scif_device = {
  67. .name = "sh-sci",
  68. .id = 1,
  69. .resource = scif_resources,
  70. .num_resources = ARRAY_SIZE(scif_resources),
  71. .dev = {
  72. .platform_data = &scif_platform_data,
  73. },
  74. };
  75. static struct sh_timer_config tmu0_platform_data = {
  76. .channel_offset = 0x04,
  77. .timer_bit = 0,
  78. .clockevent_rating = 200,
  79. };
  80. static struct resource tmu0_resources[] = {
  81. [0] = {
  82. .start = 0xffd80008,
  83. .end = 0xffd80013,
  84. .flags = IORESOURCE_MEM,
  85. },
  86. [1] = {
  87. .start = evt2irq(0x400),
  88. .flags = IORESOURCE_IRQ,
  89. },
  90. };
  91. static struct platform_device tmu0_device = {
  92. .name = "sh_tmu",
  93. .id = 0,
  94. .dev = {
  95. .platform_data = &tmu0_platform_data,
  96. },
  97. .resource = tmu0_resources,
  98. .num_resources = ARRAY_SIZE(tmu0_resources),
  99. };
  100. static struct sh_timer_config tmu1_platform_data = {
  101. .channel_offset = 0x10,
  102. .timer_bit = 1,
  103. .clocksource_rating = 200,
  104. };
  105. static struct resource tmu1_resources[] = {
  106. [0] = {
  107. .start = 0xffd80014,
  108. .end = 0xffd8001f,
  109. .flags = IORESOURCE_MEM,
  110. },
  111. [1] = {
  112. .start = evt2irq(0x420),
  113. .flags = IORESOURCE_IRQ,
  114. },
  115. };
  116. static struct platform_device tmu1_device = {
  117. .name = "sh_tmu",
  118. .id = 1,
  119. .dev = {
  120. .platform_data = &tmu1_platform_data,
  121. },
  122. .resource = tmu1_resources,
  123. .num_resources = ARRAY_SIZE(tmu1_resources),
  124. };
  125. static struct sh_timer_config tmu2_platform_data = {
  126. .channel_offset = 0x1c,
  127. .timer_bit = 2,
  128. };
  129. static struct resource tmu2_resources[] = {
  130. [0] = {
  131. .start = 0xffd80020,
  132. .end = 0xffd8002f,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. [1] = {
  136. .start = evt2irq(0x440),
  137. .flags = IORESOURCE_IRQ,
  138. },
  139. };
  140. static struct platform_device tmu2_device = {
  141. .name = "sh_tmu",
  142. .id = 2,
  143. .dev = {
  144. .platform_data = &tmu2_platform_data,
  145. },
  146. .resource = tmu2_resources,
  147. .num_resources = ARRAY_SIZE(tmu2_resources),
  148. };
  149. /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
  150. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  151. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  152. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  153. static struct sh_timer_config tmu3_platform_data = {
  154. .channel_offset = 0x04,
  155. .timer_bit = 0,
  156. };
  157. static struct resource tmu3_resources[] = {
  158. [0] = {
  159. .start = 0xfe100008,
  160. .end = 0xfe100013,
  161. .flags = IORESOURCE_MEM,
  162. },
  163. [1] = {
  164. .start = evt2irq(0xb00),
  165. .flags = IORESOURCE_IRQ,
  166. },
  167. };
  168. static struct platform_device tmu3_device = {
  169. .name = "sh_tmu",
  170. .id = 3,
  171. .dev = {
  172. .platform_data = &tmu3_platform_data,
  173. },
  174. .resource = tmu3_resources,
  175. .num_resources = ARRAY_SIZE(tmu3_resources),
  176. };
  177. static struct sh_timer_config tmu4_platform_data = {
  178. .channel_offset = 0x10,
  179. .timer_bit = 1,
  180. };
  181. static struct resource tmu4_resources[] = {
  182. [0] = {
  183. .start = 0xfe100014,
  184. .end = 0xfe10001f,
  185. .flags = IORESOURCE_MEM,
  186. },
  187. [1] = {
  188. .start = evt2irq(0xb80),
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. };
  192. static struct platform_device tmu4_device = {
  193. .name = "sh_tmu",
  194. .id = 4,
  195. .dev = {
  196. .platform_data = &tmu4_platform_data,
  197. },
  198. .resource = tmu4_resources,
  199. .num_resources = ARRAY_SIZE(tmu4_resources),
  200. };
  201. #endif
  202. static struct platform_device *sh7750_devices[] __initdata = {
  203. &rtc_device,
  204. &tmu0_device,
  205. &tmu1_device,
  206. &tmu2_device,
  207. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  208. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  209. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  210. &tmu3_device,
  211. &tmu4_device,
  212. #endif
  213. };
  214. static int __init sh7750_devices_setup(void)
  215. {
  216. if (mach_is_rts7751r2d()) {
  217. platform_device_register(&scif_device);
  218. } else {
  219. platform_device_register(&sci_device);
  220. platform_device_register(&scif_device);
  221. }
  222. return platform_add_devices(sh7750_devices,
  223. ARRAY_SIZE(sh7750_devices));
  224. }
  225. arch_initcall(sh7750_devices_setup);
  226. static struct platform_device *sh7750_early_devices[] __initdata = {
  227. &tmu0_device,
  228. &tmu1_device,
  229. &tmu2_device,
  230. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  231. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  232. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  233. &tmu3_device,
  234. &tmu4_device,
  235. #endif
  236. };
  237. void __init plat_early_device_setup(void)
  238. {
  239. struct platform_device *dev[1];
  240. if (mach_is_rts7751r2d()) {
  241. scif_platform_data.scscr |= SCSCR_CKE1;
  242. dev[0] = &scif_device;
  243. early_platform_add_devices(dev, 1);
  244. } else {
  245. dev[0] = &sci_device;
  246. early_platform_add_devices(dev, 1);
  247. dev[0] = &scif_device;
  248. early_platform_add_devices(dev, 1);
  249. }
  250. early_platform_add_devices(sh7750_early_devices,
  251. ARRAY_SIZE(sh7750_early_devices));
  252. }
  253. enum {
  254. UNUSED = 0,
  255. /* interrupt sources */
  256. IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
  257. HUDI, GPIOI, DMAC,
  258. PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  259. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
  260. TMU3, TMU4, TMU0, TMU1, TMU2, RTC, SCI1, SCIF, WDT, REF,
  261. /* interrupt groups */
  262. PCIC1,
  263. };
  264. static struct intc_vect vectors[] __initdata = {
  265. INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
  266. INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
  267. INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
  268. INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
  269. INTC_VECT(RTC, 0x4c0),
  270. INTC_VECT(SCI1, 0x4e0), INTC_VECT(SCI1, 0x500),
  271. INTC_VECT(SCI1, 0x520), INTC_VECT(SCI1, 0x540),
  272. INTC_VECT(SCIF, 0x700), INTC_VECT(SCIF, 0x720),
  273. INTC_VECT(SCIF, 0x740), INTC_VECT(SCIF, 0x760),
  274. INTC_VECT(WDT, 0x560),
  275. INTC_VECT(REF, 0x580), INTC_VECT(REF, 0x5a0),
  276. };
  277. static struct intc_prio_reg prio_registers[] __initdata = {
  278. { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
  279. { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
  280. { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
  281. { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
  282. { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
  283. TMU4, TMU3,
  284. PCIC1, PCIC0_PCISERR } },
  285. };
  286. static DECLARE_INTC_DESC(intc_desc, "sh7750", vectors, NULL,
  287. NULL, prio_registers, NULL);
  288. /* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
  289. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  290. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  291. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  292. defined(CONFIG_CPU_SUBTYPE_SH7091)
  293. static struct intc_vect vectors_dma4[] __initdata = {
  294. INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
  295. INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
  296. INTC_VECT(DMAC, 0x6c0),
  297. };
  298. static DECLARE_INTC_DESC(intc_desc_dma4, "sh7750_dma4",
  299. vectors_dma4, NULL,
  300. NULL, prio_registers, NULL);
  301. #endif
  302. /* SH7750R and SH7751R both have 8-channel DMA controllers */
  303. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
  304. static struct intc_vect vectors_dma8[] __initdata = {
  305. INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
  306. INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
  307. INTC_VECT(DMAC, 0x780), INTC_VECT(DMAC, 0x7a0),
  308. INTC_VECT(DMAC, 0x7c0), INTC_VECT(DMAC, 0x7e0),
  309. INTC_VECT(DMAC, 0x6c0),
  310. };
  311. static DECLARE_INTC_DESC(intc_desc_dma8, "sh7750_dma8",
  312. vectors_dma8, NULL,
  313. NULL, prio_registers, NULL);
  314. #endif
  315. /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
  316. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  317. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  318. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  319. static struct intc_vect vectors_tmu34[] __initdata = {
  320. INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
  321. };
  322. static struct intc_mask_reg mask_registers[] __initdata = {
  323. { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
  324. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  325. 0, 0, 0, 0, 0, 0, TMU4, TMU3,
  326. PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  327. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2,
  328. PCIC1_PCIDMA3, PCIC0_PCISERR } },
  329. };
  330. static DECLARE_INTC_DESC(intc_desc_tmu34, "sh7750_tmu34",
  331. vectors_tmu34, NULL,
  332. mask_registers, prio_registers, NULL);
  333. #endif
  334. /* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
  335. static struct intc_vect vectors_irlm[] __initdata = {
  336. INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
  337. INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
  338. };
  339. static DECLARE_INTC_DESC(intc_desc_irlm, "sh7750_irlm", vectors_irlm, NULL,
  340. NULL, prio_registers, NULL);
  341. /* SH7751 and SH7751R both have PCI */
  342. #if defined(CONFIG_CPU_SUBTYPE_SH7751) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
  343. static struct intc_vect vectors_pci[] __initdata = {
  344. INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0),
  345. INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0),
  346. INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60),
  347. INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20),
  348. };
  349. static struct intc_group groups_pci[] __initdata = {
  350. INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  351. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3),
  352. };
  353. static DECLARE_INTC_DESC(intc_desc_pci, "sh7750_pci", vectors_pci, groups_pci,
  354. mask_registers, prio_registers, NULL);
  355. #endif
  356. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  357. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  358. defined(CONFIG_CPU_SUBTYPE_SH7091)
  359. void __init plat_irq_setup(void)
  360. {
  361. /*
  362. * same vectors for SH7750, SH7750S and SH7091 except for IRLM,
  363. * see below..
  364. */
  365. register_intc_controller(&intc_desc);
  366. register_intc_controller(&intc_desc_dma4);
  367. }
  368. #endif
  369. #if defined(CONFIG_CPU_SUBTYPE_SH7750R)
  370. void __init plat_irq_setup(void)
  371. {
  372. register_intc_controller(&intc_desc);
  373. register_intc_controller(&intc_desc_dma8);
  374. register_intc_controller(&intc_desc_tmu34);
  375. }
  376. #endif
  377. #if defined(CONFIG_CPU_SUBTYPE_SH7751)
  378. void __init plat_irq_setup(void)
  379. {
  380. register_intc_controller(&intc_desc);
  381. register_intc_controller(&intc_desc_dma4);
  382. register_intc_controller(&intc_desc_tmu34);
  383. register_intc_controller(&intc_desc_pci);
  384. }
  385. #endif
  386. #if defined(CONFIG_CPU_SUBTYPE_SH7751R)
  387. void __init plat_irq_setup(void)
  388. {
  389. register_intc_controller(&intc_desc);
  390. register_intc_controller(&intc_desc_dma8);
  391. register_intc_controller(&intc_desc_tmu34);
  392. register_intc_controller(&intc_desc_pci);
  393. }
  394. #endif
  395. #define INTC_ICR 0xffd00000UL
  396. #define INTC_ICR_IRLM (1<<7)
  397. void __init plat_irq_setup_pins(int mode)
  398. {
  399. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7091)
  400. BUG(); /* impossible to mask interrupts on SH7750 and SH7091 */
  401. return;
  402. #endif
  403. switch (mode) {
  404. case IRQ_MODE_IRQ: /* individual interrupt mode for IRL3-0 */
  405. __raw_writew(__raw_readw(INTC_ICR) | INTC_ICR_IRLM, INTC_ICR);
  406. register_intc_controller(&intc_desc_irlm);
  407. break;
  408. default:
  409. BUG();
  410. }
  411. }