setup-r8a7790.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/irqchip.h>
  22. #include <linux/kernel.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/serial_sci.h>
  25. #include <linux/platform_data/gpio-rcar.h>
  26. #include <linux/platform_data/irq-renesas-irqc.h>
  27. #include <mach/common.h>
  28. #include <mach/irqs.h>
  29. #include <mach/r8a7790.h>
  30. #include <asm/mach/arch.h>
  31. static struct resource pfc_resources[] __initdata = {
  32. DEFINE_RES_MEM(0xe6060000, 0x250),
  33. };
  34. #define R8A7790_GPIO(idx) \
  35. static struct resource r8a7790_gpio##idx##_resources[] __initdata = { \
  36. DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50), \
  37. DEFINE_RES_IRQ(gic_spi(4 + (idx))), \
  38. }; \
  39. \
  40. static struct gpio_rcar_config r8a7790_gpio##idx##_platform_data __initdata = { \
  41. .gpio_base = 32 * (idx), \
  42. .irq_base = 0, \
  43. .number_of_pins = 32, \
  44. .pctl_name = "pfc-r8a7790", \
  45. .has_both_edge_trigger = 1, \
  46. }; \
  47. R8A7790_GPIO(0);
  48. R8A7790_GPIO(1);
  49. R8A7790_GPIO(2);
  50. R8A7790_GPIO(3);
  51. R8A7790_GPIO(4);
  52. R8A7790_GPIO(5);
  53. #define r8a7790_register_gpio(idx) \
  54. platform_device_register_resndata(&platform_bus, "gpio_rcar", idx, \
  55. r8a7790_gpio##idx##_resources, \
  56. ARRAY_SIZE(r8a7790_gpio##idx##_resources), \
  57. &r8a7790_gpio##idx##_platform_data, \
  58. sizeof(r8a7790_gpio##idx##_platform_data))
  59. void __init r8a7790_pinmux_init(void)
  60. {
  61. platform_device_register_simple("pfc-r8a7790", -1, pfc_resources,
  62. ARRAY_SIZE(pfc_resources));
  63. r8a7790_register_gpio(0);
  64. r8a7790_register_gpio(1);
  65. r8a7790_register_gpio(2);
  66. r8a7790_register_gpio(3);
  67. r8a7790_register_gpio(4);
  68. r8a7790_register_gpio(5);
  69. }
  70. #define SCIF_COMMON(scif_type, baseaddr, irq) \
  71. .type = scif_type, \
  72. .mapbase = baseaddr, \
  73. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
  74. .irqs = SCIx_IRQ_MUXED(irq)
  75. #define SCIFA_DATA(index, baseaddr, irq) \
  76. [index] = { \
  77. SCIF_COMMON(PORT_SCIFA, baseaddr, irq), \
  78. .scbrr_algo_id = SCBRR_ALGO_4, \
  79. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \
  80. }
  81. #define SCIFB_DATA(index, baseaddr, irq) \
  82. [index] = { \
  83. SCIF_COMMON(PORT_SCIFB, baseaddr, irq), \
  84. .scbrr_algo_id = SCBRR_ALGO_4, \
  85. .scscr = SCSCR_RE | SCSCR_TE, \
  86. }
  87. #define SCIF_DATA(index, baseaddr, irq) \
  88. [index] = { \
  89. SCIF_COMMON(PORT_SCIF, baseaddr, irq), \
  90. .scbrr_algo_id = SCBRR_ALGO_2, \
  91. .scscr = SCSCR_RE | SCSCR_TE, \
  92. }
  93. #define HSCIF_DATA(index, baseaddr, irq) \
  94. [index] = { \
  95. SCIF_COMMON(PORT_HSCIF, baseaddr, irq), \
  96. .scbrr_algo_id = SCBRR_ALGO_6, \
  97. .scscr = SCSCR_RE | SCSCR_TE, \
  98. }
  99. enum { SCIFA0, SCIFA1, SCIFB0, SCIFB1, SCIFB2, SCIFA2, SCIF0, SCIF1,
  100. HSCIF0, HSCIF1 };
  101. static struct plat_sci_port scif[] __initdata = {
  102. SCIFA_DATA(SCIFA0, 0xe6c40000, gic_spi(144)), /* SCIFA0 */
  103. SCIFA_DATA(SCIFA1, 0xe6c50000, gic_spi(145)), /* SCIFA1 */
  104. SCIFB_DATA(SCIFB0, 0xe6c20000, gic_spi(148)), /* SCIFB0 */
  105. SCIFB_DATA(SCIFB1, 0xe6c30000, gic_spi(149)), /* SCIFB1 */
  106. SCIFB_DATA(SCIFB2, 0xe6ce0000, gic_spi(150)), /* SCIFB2 */
  107. SCIFA_DATA(SCIFA2, 0xe6c60000, gic_spi(151)), /* SCIFA2 */
  108. SCIF_DATA(SCIF0, 0xe6e60000, gic_spi(152)), /* SCIF0 */
  109. SCIF_DATA(SCIF1, 0xe6e68000, gic_spi(153)), /* SCIF1 */
  110. HSCIF_DATA(HSCIF0, 0xe62c0000, gic_spi(154)), /* HSCIF0 */
  111. HSCIF_DATA(HSCIF1, 0xe62c8000, gic_spi(155)), /* HSCIF1 */
  112. };
  113. static inline void r8a7790_register_scif(int idx)
  114. {
  115. platform_device_register_data(&platform_bus, "sh-sci", idx, &scif[idx],
  116. sizeof(struct plat_sci_port));
  117. }
  118. static struct renesas_irqc_config irqc0_data __initdata = {
  119. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  120. };
  121. static struct resource irqc0_resources[] __initdata = {
  122. DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
  123. DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
  124. DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
  125. DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
  126. DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
  127. };
  128. #define r8a7790_register_irqc(idx) \
  129. platform_device_register_resndata(&platform_bus, "renesas_irqc", \
  130. idx, irqc##idx##_resources, \
  131. ARRAY_SIZE(irqc##idx##_resources), \
  132. &irqc##idx##_data, \
  133. sizeof(struct renesas_irqc_config))
  134. void __init r8a7790_add_standard_devices(void)
  135. {
  136. r8a7790_register_scif(SCIFA0);
  137. r8a7790_register_scif(SCIFA1);
  138. r8a7790_register_scif(SCIFB0);
  139. r8a7790_register_scif(SCIFB1);
  140. r8a7790_register_scif(SCIFB2);
  141. r8a7790_register_scif(SCIFA2);
  142. r8a7790_register_scif(SCIF0);
  143. r8a7790_register_scif(SCIF1);
  144. r8a7790_register_scif(HSCIF0);
  145. r8a7790_register_scif(HSCIF1);
  146. r8a7790_register_irqc(0);
  147. }
  148. void __init r8a7790_timer_init(void)
  149. {
  150. void __iomem *cntcr;
  151. /* make sure arch timer is started by setting bit 0 of CNTCT */
  152. cntcr = ioremap(0xe6080000, PAGE_SIZE);
  153. iowrite32(1, cntcr);
  154. iounmap(cntcr);
  155. shmobile_timer_init();
  156. }
  157. #ifdef CONFIG_USE_OF
  158. void __init r8a7790_add_standard_devices_dt(void)
  159. {
  160. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  161. }
  162. static const char *r8a7790_boards_compat_dt[] __initdata = {
  163. "renesas,r8a7790",
  164. NULL,
  165. };
  166. DT_MACHINE_START(R8A7790_DT, "Generic R8A7790 (Flattened Device Tree)")
  167. .init_irq = irqchip_init,
  168. .init_machine = r8a7790_add_standard_devices_dt,
  169. .init_time = r8a7790_timer_init,
  170. .dt_compat = r8a7790_boards_compat_dt,
  171. MACHINE_END
  172. #endif /* CONFIG_USE_OF */