setup-r8a7790.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * r8a7790 processor support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Copyright (C) 2013 Magnus Damm
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/irq.h>
  21. #include <linux/kernel.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/platform_data/gpio-rcar.h>
  24. #include <linux/platform_data/irq-renesas-irqc.h>
  25. #include <linux/serial_sci.h>
  26. #include <linux/sh_dma.h>
  27. #include <linux/sh_timer.h>
  28. #include <mach/common.h>
  29. #include <mach/dma-register.h>
  30. #include <mach/irqs.h>
  31. #include <mach/r8a7790.h>
  32. #include <asm/mach/arch.h>
  33. /* Audio-DMAC */
  34. #define AUDIO_DMAC_SLAVE(_id, _addr, t, r) \
  35. { \
  36. .slave_id = AUDIO_DMAC_SLAVE_## _id ##_TX, \
  37. .addr = _addr + 0x8, \
  38. .chcr = CHCR_TX(XMIT_SZ_32BIT), \
  39. .mid_rid = t, \
  40. }, { \
  41. .slave_id = AUDIO_DMAC_SLAVE_## _id ##_RX, \
  42. .addr = _addr + 0xc, \
  43. .chcr = CHCR_RX(XMIT_SZ_32BIT), \
  44. .mid_rid = r, \
  45. }
  46. static const struct sh_dmae_slave_config r8a7790_audio_dmac_slaves[] = {
  47. AUDIO_DMAC_SLAVE(SSI0, 0xec241000, 0x01, 0x02),
  48. AUDIO_DMAC_SLAVE(SSI1, 0xec241040, 0x03, 0x04),
  49. AUDIO_DMAC_SLAVE(SSI2, 0xec241080, 0x05, 0x06),
  50. AUDIO_DMAC_SLAVE(SSI3, 0xec2410c0, 0x07, 0x08),
  51. AUDIO_DMAC_SLAVE(SSI4, 0xec241100, 0x09, 0x0a),
  52. AUDIO_DMAC_SLAVE(SSI5, 0xec241140, 0x0b, 0x0c),
  53. AUDIO_DMAC_SLAVE(SSI6, 0xec241180, 0x0d, 0x0e),
  54. AUDIO_DMAC_SLAVE(SSI7, 0xec2411c0, 0x0f, 0x10),
  55. AUDIO_DMAC_SLAVE(SSI8, 0xec241200, 0x11, 0x12),
  56. AUDIO_DMAC_SLAVE(SSI9, 0xec241240, 0x13, 0x14),
  57. };
  58. #define DMAE_CHANNEL(a, b) \
  59. { \
  60. .offset = (a) - 0x20, \
  61. .dmars = (a) - 0x20 + 0x40, \
  62. .chclr_bit = (b), \
  63. .chclr_offset = 0x80 - 0x20, \
  64. }
  65. static const struct sh_dmae_channel r8a7790_audio_dmac_channels[] = {
  66. DMAE_CHANNEL(0x8000, 0),
  67. DMAE_CHANNEL(0x8080, 1),
  68. DMAE_CHANNEL(0x8100, 2),
  69. DMAE_CHANNEL(0x8180, 3),
  70. DMAE_CHANNEL(0x8200, 4),
  71. DMAE_CHANNEL(0x8280, 5),
  72. DMAE_CHANNEL(0x8300, 6),
  73. DMAE_CHANNEL(0x8380, 7),
  74. DMAE_CHANNEL(0x8400, 8),
  75. DMAE_CHANNEL(0x8480, 9),
  76. DMAE_CHANNEL(0x8500, 10),
  77. DMAE_CHANNEL(0x8580, 11),
  78. DMAE_CHANNEL(0x8600, 12),
  79. };
  80. static struct sh_dmae_pdata r8a7790_audio_dmac_platform_data = {
  81. .slave = r8a7790_audio_dmac_slaves,
  82. .slave_num = ARRAY_SIZE(r8a7790_audio_dmac_slaves),
  83. .channel = r8a7790_audio_dmac_channels,
  84. .channel_num = ARRAY_SIZE(r8a7790_audio_dmac_channels),
  85. .ts_low_shift = TS_LOW_SHIFT,
  86. .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
  87. .ts_high_shift = TS_HI_SHIFT,
  88. .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
  89. .ts_shift = dma_ts_shift,
  90. .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
  91. .dmaor_init = DMAOR_DME,
  92. .chclr_present = 1,
  93. .chclr_bitwise = 1,
  94. };
  95. static struct resource r8a7790_audio_dmac_resources[] = {
  96. /* Channel registers and DMAOR for low */
  97. DEFINE_RES_MEM(0xec700020, 0x8663 - 0x20),
  98. DEFINE_RES_IRQ(gic_spi(346)),
  99. DEFINE_RES_NAMED(gic_spi(320), 13, NULL, IORESOURCE_IRQ),
  100. /* Channel registers and DMAOR for hi */
  101. DEFINE_RES_MEM(0xec720020, 0x8663 - 0x20), /* hi */
  102. DEFINE_RES_IRQ(gic_spi(347)),
  103. DEFINE_RES_NAMED(gic_spi(333), 13, NULL, IORESOURCE_IRQ),
  104. };
  105. #define r8a7790_register_audio_dmac(id) \
  106. platform_device_register_resndata( \
  107. &platform_bus, "sh-dma-engine", id, \
  108. &r8a7790_audio_dmac_resources[id * 3], 3, \
  109. &r8a7790_audio_dmac_platform_data, \
  110. sizeof(r8a7790_audio_dmac_platform_data))
  111. static const struct resource pfc_resources[] __initconst = {
  112. DEFINE_RES_MEM(0xe6060000, 0x250),
  113. };
  114. #define r8a7790_register_pfc() \
  115. platform_device_register_simple("pfc-r8a7790", -1, pfc_resources, \
  116. ARRAY_SIZE(pfc_resources))
  117. #define R8A7790_GPIO(idx) \
  118. static const struct resource r8a7790_gpio##idx##_resources[] __initconst = { \
  119. DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50), \
  120. DEFINE_RES_IRQ(gic_spi(4 + (idx))), \
  121. }; \
  122. \
  123. static const struct gpio_rcar_config \
  124. r8a7790_gpio##idx##_platform_data __initconst = { \
  125. .gpio_base = 32 * (idx), \
  126. .irq_base = 0, \
  127. .number_of_pins = 32, \
  128. .pctl_name = "pfc-r8a7790", \
  129. .has_both_edge_trigger = 1, \
  130. }; \
  131. R8A7790_GPIO(0);
  132. R8A7790_GPIO(1);
  133. R8A7790_GPIO(2);
  134. R8A7790_GPIO(3);
  135. R8A7790_GPIO(4);
  136. R8A7790_GPIO(5);
  137. #define r8a7790_register_gpio(idx) \
  138. platform_device_register_resndata(&platform_bus, "gpio_rcar", idx, \
  139. r8a7790_gpio##idx##_resources, \
  140. ARRAY_SIZE(r8a7790_gpio##idx##_resources), \
  141. &r8a7790_gpio##idx##_platform_data, \
  142. sizeof(r8a7790_gpio##idx##_platform_data))
  143. static struct resource i2c_resources[] __initdata = {
  144. /* I2C0 */
  145. DEFINE_RES_MEM(0xE6508000, 0x40),
  146. DEFINE_RES_IRQ(gic_spi(287)),
  147. /* I2C1 */
  148. DEFINE_RES_MEM(0xE6518000, 0x40),
  149. DEFINE_RES_IRQ(gic_spi(288)),
  150. /* I2C2 */
  151. DEFINE_RES_MEM(0xE6530000, 0x40),
  152. DEFINE_RES_IRQ(gic_spi(286)),
  153. /* I2C3 */
  154. DEFINE_RES_MEM(0xE6540000, 0x40),
  155. DEFINE_RES_IRQ(gic_spi(290)),
  156. };
  157. #define r8a7790_register_i2c(idx) \
  158. platform_device_register_simple( \
  159. "i2c-rcar_gen2", idx, \
  160. i2c_resources + (2 * idx), 2); \
  161. void __init r8a7790_pinmux_init(void)
  162. {
  163. r8a7790_register_pfc();
  164. r8a7790_register_gpio(0);
  165. r8a7790_register_gpio(1);
  166. r8a7790_register_gpio(2);
  167. r8a7790_register_gpio(3);
  168. r8a7790_register_gpio(4);
  169. r8a7790_register_gpio(5);
  170. }
  171. #define __R8A7790_SCIF(scif_type, _scscr, index, baseaddr, irq) \
  172. static struct plat_sci_port scif##index##_platform_data = { \
  173. .type = scif_type, \
  174. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
  175. .scscr = _scscr, \
  176. }; \
  177. \
  178. static struct resource scif##index##_resources[] = { \
  179. DEFINE_RES_MEM(baseaddr, 0x100), \
  180. DEFINE_RES_IRQ(irq), \
  181. }
  182. #define R8A7790_SCIF(index, baseaddr, irq) \
  183. __R8A7790_SCIF(PORT_SCIF, SCSCR_RE | SCSCR_TE, \
  184. index, baseaddr, irq)
  185. #define R8A7790_SCIFA(index, baseaddr, irq) \
  186. __R8A7790_SCIF(PORT_SCIFA, SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \
  187. index, baseaddr, irq)
  188. #define R8A7790_SCIFB(index, baseaddr, irq) \
  189. __R8A7790_SCIF(PORT_SCIFB, SCSCR_RE | SCSCR_TE, \
  190. index, baseaddr, irq)
  191. #define R8A7790_HSCIF(index, baseaddr, irq) \
  192. __R8A7790_SCIF(PORT_HSCIF, SCSCR_RE | SCSCR_TE, \
  193. index, baseaddr, irq)
  194. R8A7790_SCIFA(0, 0xe6c40000, gic_spi(144)); /* SCIFA0 */
  195. R8A7790_SCIFA(1, 0xe6c50000, gic_spi(145)); /* SCIFA1 */
  196. R8A7790_SCIFB(2, 0xe6c20000, gic_spi(148)); /* SCIFB0 */
  197. R8A7790_SCIFB(3, 0xe6c30000, gic_spi(149)); /* SCIFB1 */
  198. R8A7790_SCIFB(4, 0xe6ce0000, gic_spi(150)); /* SCIFB2 */
  199. R8A7790_SCIFA(5, 0xe6c60000, gic_spi(151)); /* SCIFA2 */
  200. R8A7790_SCIF(6, 0xe6e60000, gic_spi(152)); /* SCIF0 */
  201. R8A7790_SCIF(7, 0xe6e68000, gic_spi(153)); /* SCIF1 */
  202. R8A7790_HSCIF(8, 0xe62c0000, gic_spi(154)); /* HSCIF0 */
  203. R8A7790_HSCIF(9, 0xe62c8000, gic_spi(155)); /* HSCIF1 */
  204. #define r8a7790_register_scif(index) \
  205. platform_device_register_resndata(&platform_bus, "sh-sci", index, \
  206. scif##index##_resources, \
  207. ARRAY_SIZE(scif##index##_resources), \
  208. &scif##index##_platform_data, \
  209. sizeof(scif##index##_platform_data))
  210. static const struct renesas_irqc_config irqc0_data __initconst = {
  211. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  212. };
  213. static const struct resource irqc0_resources[] __initconst = {
  214. DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
  215. DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
  216. DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
  217. DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
  218. DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
  219. };
  220. #define r8a7790_register_irqc(idx) \
  221. platform_device_register_resndata(&platform_bus, "renesas_irqc", \
  222. idx, irqc##idx##_resources, \
  223. ARRAY_SIZE(irqc##idx##_resources), \
  224. &irqc##idx##_data, \
  225. sizeof(struct renesas_irqc_config))
  226. static const struct resource thermal_resources[] __initconst = {
  227. DEFINE_RES_MEM(0xe61f0000, 0x14),
  228. DEFINE_RES_MEM(0xe61f0100, 0x38),
  229. DEFINE_RES_IRQ(gic_spi(69)),
  230. };
  231. #define r8a7790_register_thermal() \
  232. platform_device_register_simple("rcar_thermal", -1, \
  233. thermal_resources, \
  234. ARRAY_SIZE(thermal_resources))
  235. static struct sh_timer_config cmt0_platform_data = {
  236. .channels_mask = 0x60,
  237. };
  238. static struct resource cmt0_resources[] = {
  239. DEFINE_RES_MEM(0xffca0000, 0x1004),
  240. DEFINE_RES_IRQ(gic_spi(142)),
  241. };
  242. #define r8a7790_register_cmt(idx) \
  243. platform_device_register_resndata(&platform_bus, "sh-cmt-48-gen2", \
  244. idx, cmt##idx##_resources, \
  245. ARRAY_SIZE(cmt##idx##_resources), \
  246. &cmt##idx##_platform_data, \
  247. sizeof(struct sh_timer_config))
  248. void __init r8a7790_add_dt_devices(void)
  249. {
  250. r8a7790_register_cmt(0);
  251. }
  252. void __init r8a7790_add_standard_devices(void)
  253. {
  254. r8a7790_register_scif(0);
  255. r8a7790_register_scif(1);
  256. r8a7790_register_scif(2);
  257. r8a7790_register_scif(3);
  258. r8a7790_register_scif(4);
  259. r8a7790_register_scif(5);
  260. r8a7790_register_scif(6);
  261. r8a7790_register_scif(7);
  262. r8a7790_register_scif(8);
  263. r8a7790_register_scif(9);
  264. r8a7790_add_dt_devices();
  265. r8a7790_register_irqc(0);
  266. r8a7790_register_thermal();
  267. r8a7790_register_i2c(0);
  268. r8a7790_register_i2c(1);
  269. r8a7790_register_i2c(2);
  270. r8a7790_register_i2c(3);
  271. r8a7790_register_audio_dmac(0);
  272. r8a7790_register_audio_dmac(1);
  273. }
  274. void __init r8a7790_init_early(void)
  275. {
  276. #ifndef CONFIG_ARM_ARCH_TIMER
  277. shmobile_setup_delay(1300, 2, 4); /* Cortex-A15 @ 1300MHz */
  278. #endif
  279. }
  280. #ifdef CONFIG_USE_OF
  281. static const char * const r8a7790_boards_compat_dt[] __initconst = {
  282. "renesas,r8a7790",
  283. NULL,
  284. };
  285. DT_MACHINE_START(R8A7790_DT, "Generic R8A7790 (Flattened Device Tree)")
  286. .smp = smp_ops(r8a7790_smp_ops),
  287. .init_early = r8a7790_init_early,
  288. .init_time = rcar_gen2_timer_init,
  289. .dt_compat = r8a7790_boards_compat_dt,
  290. MACHINE_END
  291. #endif /* CONFIG_USE_OF */