setup-sh7750.c 12 KB

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