setup-sh7750.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SH7091/SH7750/SH7750S/SH7750R/SH7751/SH7751R Setup
  4. *
  5. * Copyright (C) 2006 Paul Mundt
  6. * Copyright (C) 2006 Jamie Lenehan
  7. */
  8. #include <linux/platform_device.h>
  9. #include <linux/init.h>
  10. #include <linux/serial.h>
  11. #include <linux/io.h>
  12. #include <linux/sh_timer.h>
  13. #include <linux/sh_intc.h>
  14. #include <linux/serial_sci.h>
  15. #include <generated/machtypes.h>
  16. #include <asm/platform_early.h>
  17. static struct resource rtc_resources[] = {
  18. [0] = {
  19. .start = 0xffc80000,
  20. .end = 0xffc80000 + 0x58 - 1,
  21. .flags = IORESOURCE_IO,
  22. },
  23. [1] = {
  24. /* Shared Period/Carry/Alarm IRQ */
  25. .start = evt2irq(0x480),
  26. .flags = IORESOURCE_IRQ,
  27. },
  28. };
  29. static struct platform_device rtc_device = {
  30. .name = "sh-rtc",
  31. .id = -1,
  32. .num_resources = ARRAY_SIZE(rtc_resources),
  33. .resource = rtc_resources,
  34. };
  35. static struct plat_sci_port sci_platform_data = {
  36. .type = PORT_SCI,
  37. };
  38. static struct resource sci_resources[] = {
  39. DEFINE_RES_MEM(0xffe00000, 0x20),
  40. DEFINE_RES_IRQ(evt2irq(0x4e0)),
  41. };
  42. static struct platform_device sci_device = {
  43. .name = "sh-sci",
  44. .id = 0,
  45. .resource = sci_resources,
  46. .num_resources = ARRAY_SIZE(sci_resources),
  47. .dev = {
  48. .platform_data = &sci_platform_data,
  49. },
  50. };
  51. static struct plat_sci_port scif_platform_data = {
  52. .scscr = SCSCR_REIE,
  53. .type = PORT_SCIF,
  54. };
  55. static struct resource scif_resources[] = {
  56. DEFINE_RES_MEM(0xffe80000, 0x100),
  57. DEFINE_RES_IRQ(evt2irq(0x700)),
  58. };
  59. static struct platform_device scif_device = {
  60. .name = "sh-sci",
  61. .id = 1,
  62. .resource = scif_resources,
  63. .num_resources = ARRAY_SIZE(scif_resources),
  64. .dev = {
  65. .platform_data = &scif_platform_data,
  66. },
  67. };
  68. static struct sh_timer_config tmu0_platform_data = {
  69. .channels_mask = 7,
  70. };
  71. static struct resource tmu0_resources[] = {
  72. DEFINE_RES_MEM(0xffd80000, 0x30),
  73. DEFINE_RES_IRQ(evt2irq(0x400)),
  74. DEFINE_RES_IRQ(evt2irq(0x420)),
  75. DEFINE_RES_IRQ(evt2irq(0x440)),
  76. };
  77. static struct platform_device tmu0_device = {
  78. .name = "sh-tmu",
  79. .id = 0,
  80. .dev = {
  81. .platform_data = &tmu0_platform_data,
  82. },
  83. .resource = tmu0_resources,
  84. .num_resources = ARRAY_SIZE(tmu0_resources),
  85. };
  86. /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
  87. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  88. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  89. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  90. static struct sh_timer_config tmu1_platform_data = {
  91. .channels_mask = 3,
  92. };
  93. static struct resource tmu1_resources[] = {
  94. DEFINE_RES_MEM(0xfe100000, 0x20),
  95. DEFINE_RES_IRQ(evt2irq(0xb00)),
  96. DEFINE_RES_IRQ(evt2irq(0xb80)),
  97. };
  98. static struct platform_device tmu1_device = {
  99. .name = "sh-tmu",
  100. .id = 1,
  101. .dev = {
  102. .platform_data = &tmu1_platform_data,
  103. },
  104. .resource = tmu1_resources,
  105. .num_resources = ARRAY_SIZE(tmu1_resources),
  106. };
  107. #endif
  108. static struct platform_device *sh7750_devices[] __initdata = {
  109. &rtc_device,
  110. &tmu0_device,
  111. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  112. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  113. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  114. &tmu1_device,
  115. #endif
  116. };
  117. static int __init sh7750_devices_setup(void)
  118. {
  119. if (mach_is_rts7751r2d()) {
  120. platform_device_register(&scif_device);
  121. } else {
  122. platform_device_register(&sci_device);
  123. platform_device_register(&scif_device);
  124. }
  125. return platform_add_devices(sh7750_devices,
  126. ARRAY_SIZE(sh7750_devices));
  127. }
  128. arch_initcall(sh7750_devices_setup);
  129. static struct platform_device *sh7750_early_devices[] __initdata = {
  130. &tmu0_device,
  131. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  132. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  133. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  134. &tmu1_device,
  135. #endif
  136. };
  137. void __init plat_early_device_setup(void)
  138. {
  139. struct platform_device *dev[1];
  140. if (mach_is_rts7751r2d()) {
  141. scif_platform_data.scscr |= SCSCR_CKE1;
  142. dev[0] = &scif_device;
  143. sh_early_platform_add_devices(dev, 1);
  144. } else {
  145. dev[0] = &sci_device;
  146. sh_early_platform_add_devices(dev, 1);
  147. dev[0] = &scif_device;
  148. sh_early_platform_add_devices(dev, 1);
  149. }
  150. sh_early_platform_add_devices(sh7750_early_devices,
  151. ARRAY_SIZE(sh7750_early_devices));
  152. }
  153. enum {
  154. UNUSED = 0,
  155. /* interrupt sources */
  156. IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
  157. HUDI, GPIOI, DMAC,
  158. PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  159. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
  160. TMU3, TMU4, TMU0, TMU1, TMU2, RTC, SCI1, SCIF, WDT, REF,
  161. /* interrupt groups */
  162. PCIC1,
  163. };
  164. static struct intc_vect vectors[] __initdata = {
  165. INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
  166. INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
  167. INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
  168. INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
  169. INTC_VECT(RTC, 0x4c0),
  170. INTC_VECT(SCI1, 0x4e0), INTC_VECT(SCI1, 0x500),
  171. INTC_VECT(SCI1, 0x520), INTC_VECT(SCI1, 0x540),
  172. INTC_VECT(SCIF, 0x700), INTC_VECT(SCIF, 0x720),
  173. INTC_VECT(SCIF, 0x740), INTC_VECT(SCIF, 0x760),
  174. INTC_VECT(WDT, 0x560),
  175. INTC_VECT(REF, 0x580), INTC_VECT(REF, 0x5a0),
  176. };
  177. static struct intc_prio_reg prio_registers[] __initdata = {
  178. { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
  179. { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
  180. { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
  181. { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
  182. { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
  183. TMU4, TMU3,
  184. PCIC1, PCIC0_PCISERR } },
  185. };
  186. static DECLARE_INTC_DESC(intc_desc, "sh7750", vectors, NULL,
  187. NULL, prio_registers, NULL);
  188. /* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
  189. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  190. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  191. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  192. defined(CONFIG_CPU_SUBTYPE_SH7091)
  193. static struct intc_vect vectors_dma4[] __initdata = {
  194. INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
  195. INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
  196. INTC_VECT(DMAC, 0x6c0),
  197. };
  198. static DECLARE_INTC_DESC(intc_desc_dma4, "sh7750_dma4",
  199. vectors_dma4, NULL,
  200. NULL, prio_registers, NULL);
  201. #endif
  202. /* SH7750R and SH7751R both have 8-channel DMA controllers */
  203. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
  204. static struct intc_vect vectors_dma8[] __initdata = {
  205. INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
  206. INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
  207. INTC_VECT(DMAC, 0x780), INTC_VECT(DMAC, 0x7a0),
  208. INTC_VECT(DMAC, 0x7c0), INTC_VECT(DMAC, 0x7e0),
  209. INTC_VECT(DMAC, 0x6c0),
  210. };
  211. static DECLARE_INTC_DESC(intc_desc_dma8, "sh7750_dma8",
  212. vectors_dma8, NULL,
  213. NULL, prio_registers, NULL);
  214. #endif
  215. /* SH7750R, SH7751 and SH7751R all have two extra timer channels */
  216. #if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
  217. defined(CONFIG_CPU_SUBTYPE_SH7751) || \
  218. defined(CONFIG_CPU_SUBTYPE_SH7751R)
  219. static struct intc_vect vectors_tmu34[] __initdata = {
  220. INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
  221. };
  222. static struct intc_mask_reg mask_registers[] __initdata = {
  223. { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
  224. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  225. 0, 0, 0, 0, 0, 0, TMU4, TMU3,
  226. PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  227. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2,
  228. PCIC1_PCIDMA3, PCIC0_PCISERR } },
  229. };
  230. static DECLARE_INTC_DESC(intc_desc_tmu34, "sh7750_tmu34",
  231. vectors_tmu34, NULL,
  232. mask_registers, prio_registers, NULL);
  233. #endif
  234. /* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
  235. static struct intc_vect vectors_irlm[] __initdata = {
  236. INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
  237. INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
  238. };
  239. static DECLARE_INTC_DESC(intc_desc_irlm, "sh7750_irlm", vectors_irlm, NULL,
  240. NULL, prio_registers, NULL);
  241. /* SH7751 and SH7751R both have PCI */
  242. #if defined(CONFIG_CPU_SUBTYPE_SH7751) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
  243. static struct intc_vect vectors_pci[] __initdata = {
  244. INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0),
  245. INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0),
  246. INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60),
  247. INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20),
  248. };
  249. static struct intc_group groups_pci[] __initdata = {
  250. INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
  251. PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3),
  252. };
  253. static DECLARE_INTC_DESC(intc_desc_pci, "sh7750_pci", vectors_pci, groups_pci,
  254. mask_registers, prio_registers, NULL);
  255. #endif
  256. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || \
  257. defined(CONFIG_CPU_SUBTYPE_SH7750S) || \
  258. defined(CONFIG_CPU_SUBTYPE_SH7091)
  259. void __init plat_irq_setup(void)
  260. {
  261. /*
  262. * same vectors for SH7750, SH7750S and SH7091 except for IRLM,
  263. * see below..
  264. */
  265. register_intc_controller(&intc_desc);
  266. register_intc_controller(&intc_desc_dma4);
  267. }
  268. #endif
  269. #if defined(CONFIG_CPU_SUBTYPE_SH7750R)
  270. void __init plat_irq_setup(void)
  271. {
  272. register_intc_controller(&intc_desc);
  273. register_intc_controller(&intc_desc_dma8);
  274. register_intc_controller(&intc_desc_tmu34);
  275. }
  276. #endif
  277. #if defined(CONFIG_CPU_SUBTYPE_SH7751)
  278. void __init plat_irq_setup(void)
  279. {
  280. register_intc_controller(&intc_desc);
  281. register_intc_controller(&intc_desc_dma4);
  282. register_intc_controller(&intc_desc_tmu34);
  283. register_intc_controller(&intc_desc_pci);
  284. }
  285. #endif
  286. #if defined(CONFIG_CPU_SUBTYPE_SH7751R)
  287. void __init plat_irq_setup(void)
  288. {
  289. register_intc_controller(&intc_desc);
  290. register_intc_controller(&intc_desc_dma8);
  291. register_intc_controller(&intc_desc_tmu34);
  292. register_intc_controller(&intc_desc_pci);
  293. }
  294. #endif
  295. #define INTC_ICR 0xffd00000UL
  296. #define INTC_ICR_IRLM (1<<7)
  297. void __init plat_irq_setup_pins(int mode)
  298. {
  299. #if defined(CONFIG_CPU_SUBTYPE_SH7750) || defined(CONFIG_CPU_SUBTYPE_SH7091)
  300. BUG(); /* impossible to mask interrupts on SH7750 and SH7091 */
  301. return;
  302. #endif
  303. switch (mode) {
  304. case IRQ_MODE_IRQ: /* individual interrupt mode for IRL3-0 */
  305. __raw_writew(__raw_readw(INTC_ICR) | INTC_ICR_IRLM, INTC_ICR);
  306. register_intc_controller(&intc_desc_irlm);
  307. break;
  308. default:
  309. BUG();
  310. }
  311. }