setup-sh7750.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. .channels_mask = 7,
  77. };
  78. static struct resource tmu0_resources[] = {
  79. DEFINE_RES_MEM(0xffd80000, 0x30),
  80. DEFINE_RES_IRQ(evt2irq(0x400)),
  81. DEFINE_RES_IRQ(evt2irq(0x420)),
  82. DEFINE_RES_IRQ(evt2irq(0x440)),
  83. };
  84. static struct platform_device tmu0_device = {
  85. .name = "sh-tmu",
  86. .id = 0,
  87. .dev = {
  88. .platform_data = &tmu0_platform_data,
  89. },
  90. .resource = tmu0_resources,
  91. .num_resources = ARRAY_SIZE(tmu0_resources),
  92. };
  93. /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
  94. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  95. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  96. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  97. static struct sh_timer_config tmu1_platform_data = {
  98. .channels_mask = 3,
  99. };
  100. static struct resource tmu1_resources[] = {
  101. DEFINE_RES_MEM(0xfe100000, 0x20),
  102. DEFINE_RES_IRQ(evt2irq(0xb00)),
  103. DEFINE_RES_IRQ(evt2irq(0xb80)),
  104. };
  105. static struct platform_device tmu1_device = {
  106. .name = "sh-tmu",
  107. .id = 1,
  108. .dev = {
  109. .platform_data = &tmu1_platform_data,
  110. },
  111. .resource = tmu1_resources,
  112. .num_resources = ARRAY_SIZE(tmu1_resources),
  113. };
  114. #endif
  115. static struct platform_device *sh7750_devices[] __initdata = {
  116. &rtc_device,
  117. &tmu0_device,
  118. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  119. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  120. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  121. &tmu1_device,
  122. #endif
  123. };
  124. static int __init sh7750_devices_setup(void)
  125. {
  126. if (mach_is_rts7751r2d()) {
  127. platform_device_register(&scif_device);
  128. } else {
  129. platform_device_register(&sci_device);
  130. platform_device_register(&scif_device);
  131. }
  132. return platform_add_devices(sh7750_devices,
  133. ARRAY_SIZE(sh7750_devices));
  134. }
  135. arch_initcall(sh7750_devices_setup);
  136. static struct platform_device *sh7750_early_devices[] __initdata = {
  137. &tmu0_device,
  138. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  139. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  140. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  141. &tmu1_device,
  142. #endif
  143. };
  144. void __init plat_early_device_setup(void)
  145. {
  146. struct platform_device *dev[1];
  147. if (mach_is_rts7751r2d()) {
  148. scif_platform_data.scscr |= SCSCR_CKE1;
  149. dev[0] = &scif_device;
  150. early_platform_add_devices(dev, 1);
  151. } else {
  152. dev[0] = &sci_device;
  153. early_platform_add_devices(dev, 1);
  154. dev[0] = &scif_device;
  155. early_platform_add_devices(dev, 1);
  156. }
  157. early_platform_add_devices(sh7750_early_devices,
  158. ARRAY_SIZE(sh7750_early_devices));
  159. }
  160. enum {
  161. UNUSED = 0,
  162. /* interrupt sources */
  163. IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
  164. HUDI, GPIOI, DMAC,
  165. PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  166. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
  167. TMU3, TMU4, TMU0, TMU1, TMU2, RTC, SCI1, SCIF, WDT, REF,
  168. /* interrupt groups */
  169. PCIC1,
  170. };
  171. static struct intc_vect vectors[] __initdata = {
  172. INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
  173. INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
  174. INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
  175. INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
  176. INTC_VECT(RTC, 0x4c0),
  177. INTC_VECT(SCI1, 0x4e0), INTC_VECT(SCI1, 0x500),
  178. INTC_VECT(SCI1, 0x520), INTC_VECT(SCI1, 0x540),
  179. INTC_VECT(SCIF, 0x700), INTC_VECT(SCIF, 0x720),
  180. INTC_VECT(SCIF, 0x740), INTC_VECT(SCIF, 0x760),
  181. INTC_VECT(WDT, 0x560),
  182. INTC_VECT(REF, 0x580), INTC_VECT(REF, 0x5a0),
  183. };
  184. static struct intc_prio_reg prio_registers[] __initdata = {
  185. { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
  186. { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
  187. { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
  188. { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
  189. { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
  190. TMU4, TMU3,
  191. PCIC1, PCIC0_PCISERR } },
  192. };
  193. static DECLARE_INTC_DESC(intc_desc, "sh7750", vectors, NULL,
  194. NULL, prio_registers, NULL);
  195. /* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
  196. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  197. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  198. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  199. defined(CONFIG_CPU_SUBTYPE_SH7091)
  200. static struct intc_vect vectors_dma4[] __initdata = {
  201. INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
  202. INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
  203. INTC_VECT(DMAC, 0x6c0),
  204. };
  205. static DECLARE_INTC_DESC(intc_desc_dma4, "sh7750_dma4",
  206. vectors_dma4, NULL,
  207. NULL, prio_registers, NULL);
  208. #endif
  209. /* SH7750R and SH7751R both have 8-channel DMA controllers */
  210. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
  211. static struct intc_vect vectors_dma8[] __initdata = {
  212. INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
  213. INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
  214. INTC_VECT(DMAC, 0x780), INTC_VECT(DMAC, 0x7a0),
  215. INTC_VECT(DMAC, 0x7c0), INTC_VECT(DMAC, 0x7e0),
  216. INTC_VECT(DMAC, 0x6c0),
  217. };
  218. static DECLARE_INTC_DESC(intc_desc_dma8, "sh7750_dma8",
  219. vectors_dma8, NULL,
  220. NULL, prio_registers, NULL);
  221. #endif
  222. /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
  223. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  224. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  225. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  226. static struct intc_vect vectors_tmu34[] __initdata = {
  227. INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
  228. };
  229. static struct intc_mask_reg mask_registers[] __initdata = {
  230. { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
  231. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  232. 0, 0, 0, 0, 0, 0, TMU4, TMU3,
  233. PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  234. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2,
  235. PCIC1_PCIDMA3, PCIC0_PCISERR } },
  236. };
  237. static DECLARE_INTC_DESC(intc_desc_tmu34, "sh7750_tmu34",
  238. vectors_tmu34, NULL,
  239. mask_registers, prio_registers, NULL);
  240. #endif
  241. /* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
  242. static struct intc_vect vectors_irlm[] __initdata = {
  243. INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
  244. INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
  245. };
  246. static DECLARE_INTC_DESC(intc_desc_irlm, "sh7750_irlm", vectors_irlm, NULL,
  247. NULL, prio_registers, NULL);
  248. /* SH7751 and SH7751R both have PCI */
  249. #if defined(CONFIG_CPU_SUBTYPE_SH7751) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
  250. static struct intc_vect vectors_pci[] __initdata = {
  251. INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0),
  252. INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0),
  253. INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60),
  254. INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20),
  255. };
  256. static struct intc_group groups_pci[] __initdata = {
  257. INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  258. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3),
  259. };
  260. static DECLARE_INTC_DESC(intc_desc_pci, "sh7750_pci", vectors_pci, groups_pci,
  261. mask_registers, prio_registers, NULL);
  262. #endif
  263. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  264. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  265. defined(CONFIG_CPU_SUBTYPE_SH7091)
  266. void __init plat_irq_setup(void)
  267. {
  268. /*
  269. * same vectors for SH7750, SH7750S and SH7091 except for IRLM,
  270. * see below..
  271. */
  272. register_intc_controller(&intc_desc);
  273. register_intc_controller(&intc_desc_dma4);
  274. }
  275. #endif
  276. #if defined(CONFIG_CPU_SUBTYPE_SH7750R)
  277. void __init plat_irq_setup(void)
  278. {
  279. register_intc_controller(&intc_desc);
  280. register_intc_controller(&intc_desc_dma8);
  281. register_intc_controller(&intc_desc_tmu34);
  282. }
  283. #endif
  284. #if defined(CONFIG_CPU_SUBTYPE_SH7751)
  285. void __init plat_irq_setup(void)
  286. {
  287. register_intc_controller(&intc_desc);
  288. register_intc_controller(&intc_desc_dma4);
  289. register_intc_controller(&intc_desc_tmu34);
  290. register_intc_controller(&intc_desc_pci);
  291. }
  292. #endif
  293. #if defined(CONFIG_CPU_SUBTYPE_SH7751R)
  294. void __init plat_irq_setup(void)
  295. {
  296. register_intc_controller(&intc_desc);
  297. register_intc_controller(&intc_desc_dma8);
  298. register_intc_controller(&intc_desc_tmu34);
  299. register_intc_controller(&intc_desc_pci);
  300. }
  301. #endif
  302. #define INTC_ICR 0xffd00000UL
  303. #define INTC_ICR_IRLM (1<<7)
  304. void __init plat_irq_setup_pins(int mode)
  305. {
  306. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7091)
  307. BUG(); /* impossible to mask interrupts on SH7750 and SH7091 */
  308. return;
  309. #endif
  310. switch (mode) {
  311. case IRQ_MODE_IRQ: /* individual interrupt mode for IRL3-0 */
  312. __raw_writew(__raw_readw(INTC_ICR) | INTC_ICR_IRLM, INTC_ICR);
  313. register_intc_controller(&intc_desc_irlm);
  314. break;
  315. default:
  316. BUG();
  317. }
  318. }