setup-r8a7790.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/clocksource.h>
  21. #include <linux/irq.h>
  22. #include <linux/kernel.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/platform_data/gpio-rcar.h>
  25. #include <linux/platform_data/irq-renesas-irqc.h>
  26. #include <linux/serial_sci.h>
  27. #include <linux/sh_timer.h>
  28. #include <mach/common.h>
  29. #include <mach/irqs.h>
  30. #include <mach/r8a7790.h>
  31. #include <asm/mach/arch.h>
  32. static struct resource pfc_resources[] __initdata = {
  33. DEFINE_RES_MEM(0xe6060000, 0x250),
  34. };
  35. #define R8A7790_GPIO(idx) \
  36. static struct resource r8a7790_gpio##idx##_resources[] __initdata = { \
  37. DEFINE_RES_MEM(0xe6050000 + 0x1000 * (idx), 0x50), \
  38. DEFINE_RES_IRQ(gic_spi(4 + (idx))), \
  39. }; \
  40. \
  41. static struct gpio_rcar_config r8a7790_gpio##idx##_platform_data __initdata = { \
  42. .gpio_base = 32 * (idx), \
  43. .irq_base = 0, \
  44. .number_of_pins = 32, \
  45. .pctl_name = "pfc-r8a7790", \
  46. .has_both_edge_trigger = 1, \
  47. }; \
  48. R8A7790_GPIO(0);
  49. R8A7790_GPIO(1);
  50. R8A7790_GPIO(2);
  51. R8A7790_GPIO(3);
  52. R8A7790_GPIO(4);
  53. R8A7790_GPIO(5);
  54. #define r8a7790_register_gpio(idx) \
  55. platform_device_register_resndata(&platform_bus, "gpio_rcar", idx, \
  56. r8a7790_gpio##idx##_resources, \
  57. ARRAY_SIZE(r8a7790_gpio##idx##_resources), \
  58. &r8a7790_gpio##idx##_platform_data, \
  59. sizeof(r8a7790_gpio##idx##_platform_data))
  60. void __init r8a7790_pinmux_init(void)
  61. {
  62. platform_device_register_simple("pfc-r8a7790", -1, pfc_resources,
  63. ARRAY_SIZE(pfc_resources));
  64. r8a7790_register_gpio(0);
  65. r8a7790_register_gpio(1);
  66. r8a7790_register_gpio(2);
  67. r8a7790_register_gpio(3);
  68. r8a7790_register_gpio(4);
  69. r8a7790_register_gpio(5);
  70. }
  71. #define SCIF_COMMON(scif_type, baseaddr, irq) \
  72. .type = scif_type, \
  73. .mapbase = baseaddr, \
  74. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
  75. .irqs = SCIx_IRQ_MUXED(irq)
  76. #define SCIFA_DATA(index, baseaddr, irq) \
  77. [index] = { \
  78. SCIF_COMMON(PORT_SCIFA, baseaddr, irq), \
  79. .scbrr_algo_id = SCBRR_ALGO_4, \
  80. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE0, \
  81. }
  82. #define SCIFB_DATA(index, baseaddr, irq) \
  83. [index] = { \
  84. SCIF_COMMON(PORT_SCIFB, baseaddr, irq), \
  85. .scbrr_algo_id = SCBRR_ALGO_4, \
  86. .scscr = SCSCR_RE | SCSCR_TE, \
  87. }
  88. #define SCIF_DATA(index, baseaddr, irq) \
  89. [index] = { \
  90. SCIF_COMMON(PORT_SCIF, baseaddr, irq), \
  91. .scbrr_algo_id = SCBRR_ALGO_2, \
  92. .scscr = SCSCR_RE | SCSCR_TE, \
  93. }
  94. #define HSCIF_DATA(index, baseaddr, irq) \
  95. [index] = { \
  96. SCIF_COMMON(PORT_HSCIF, baseaddr, irq), \
  97. .scbrr_algo_id = SCBRR_ALGO_6, \
  98. .scscr = SCSCR_RE | SCSCR_TE, \
  99. }
  100. enum { SCIFA0, SCIFA1, SCIFB0, SCIFB1, SCIFB2, SCIFA2, SCIF0, SCIF1,
  101. HSCIF0, HSCIF1 };
  102. static struct plat_sci_port scif[] __initdata = {
  103. SCIFA_DATA(SCIFA0, 0xe6c40000, gic_spi(144)), /* SCIFA0 */
  104. SCIFA_DATA(SCIFA1, 0xe6c50000, gic_spi(145)), /* SCIFA1 */
  105. SCIFB_DATA(SCIFB0, 0xe6c20000, gic_spi(148)), /* SCIFB0 */
  106. SCIFB_DATA(SCIFB1, 0xe6c30000, gic_spi(149)), /* SCIFB1 */
  107. SCIFB_DATA(SCIFB2, 0xe6ce0000, gic_spi(150)), /* SCIFB2 */
  108. SCIFA_DATA(SCIFA2, 0xe6c60000, gic_spi(151)), /* SCIFA2 */
  109. SCIF_DATA(SCIF0, 0xe6e60000, gic_spi(152)), /* SCIF0 */
  110. SCIF_DATA(SCIF1, 0xe6e68000, gic_spi(153)), /* SCIF1 */
  111. HSCIF_DATA(HSCIF0, 0xe62c0000, gic_spi(154)), /* HSCIF0 */
  112. HSCIF_DATA(HSCIF1, 0xe62c8000, gic_spi(155)), /* HSCIF1 */
  113. };
  114. static inline void r8a7790_register_scif(int idx)
  115. {
  116. platform_device_register_data(&platform_bus, "sh-sci", idx, &scif[idx],
  117. sizeof(struct plat_sci_port));
  118. }
  119. static struct renesas_irqc_config irqc0_data __initdata = {
  120. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  121. };
  122. static struct resource irqc0_resources[] __initdata = {
  123. DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
  124. DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
  125. DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
  126. DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
  127. DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
  128. };
  129. #define r8a7790_register_irqc(idx) \
  130. platform_device_register_resndata(&platform_bus, "renesas_irqc", \
  131. idx, irqc##idx##_resources, \
  132. ARRAY_SIZE(irqc##idx##_resources), \
  133. &irqc##idx##_data, \
  134. sizeof(struct renesas_irqc_config))
  135. static struct resource thermal_resources[] __initdata = {
  136. DEFINE_RES_MEM(0xe61f0000, 0x14),
  137. DEFINE_RES_MEM(0xe61f0100, 0x38),
  138. DEFINE_RES_IRQ(gic_spi(69)),
  139. };
  140. #define r8a7790_register_thermal() \
  141. platform_device_register_simple("rcar_thermal", -1, \
  142. thermal_resources, \
  143. ARRAY_SIZE(thermal_resources))
  144. static struct sh_timer_config cmt00_platform_data __initdata = {
  145. .name = "CMT00",
  146. .timer_bit = 0,
  147. .clockevent_rating = 80,
  148. };
  149. static struct resource cmt00_resources[] __initdata = {
  150. DEFINE_RES_MEM(0xffca0510, 0x0c),
  151. DEFINE_RES_MEM(0xffca0500, 0x04),
  152. DEFINE_RES_IRQ(gic_spi(142)), /* CMT0_0 */
  153. };
  154. #define r8a7790_register_cmt(idx) \
  155. platform_device_register_resndata(&platform_bus, "sh_cmt", \
  156. idx, cmt##idx##_resources, \
  157. ARRAY_SIZE(cmt##idx##_resources), \
  158. &cmt##idx##_platform_data, \
  159. sizeof(struct sh_timer_config))
  160. void __init r8a7790_add_dt_devices(void)
  161. {
  162. r8a7790_register_scif(SCIFA0);
  163. r8a7790_register_scif(SCIFA1);
  164. r8a7790_register_scif(SCIFB0);
  165. r8a7790_register_scif(SCIFB1);
  166. r8a7790_register_scif(SCIFB2);
  167. r8a7790_register_scif(SCIFA2);
  168. r8a7790_register_scif(SCIF0);
  169. r8a7790_register_scif(SCIF1);
  170. r8a7790_register_scif(HSCIF0);
  171. r8a7790_register_scif(HSCIF1);
  172. r8a7790_register_cmt(00);
  173. }
  174. void __init r8a7790_add_standard_devices(void)
  175. {
  176. r8a7790_add_dt_devices();
  177. r8a7790_register_irqc(0);
  178. r8a7790_register_thermal();
  179. }
  180. #define MODEMR 0xe6160060
  181. u32 __init r8a7790_read_mode_pins(void)
  182. {
  183. void __iomem *modemr = ioremap_nocache(MODEMR, 4);
  184. u32 mode;
  185. BUG_ON(!modemr);
  186. mode = ioread32(modemr);
  187. iounmap(modemr);
  188. return mode;
  189. }
  190. #define CNTCR 0
  191. #define CNTFID0 0x20
  192. void __init r8a7790_timer_init(void)
  193. {
  194. #ifdef CONFIG_ARM_ARCH_TIMER
  195. u32 mode = r8a7790_read_mode_pins();
  196. void __iomem *base;
  197. int extal_mhz = 0;
  198. u32 freq;
  199. /* At Linux boot time the r8a7790 arch timer comes up
  200. * with the counter disabled. Moreover, it may also report
  201. * a potentially incorrect fixed 13 MHz frequency. To be
  202. * correct these registers need to be updated to use the
  203. * frequency EXTAL / 2 which can be determined by the MD pins.
  204. */
  205. switch (mode & (MD(14) | MD(13))) {
  206. case 0:
  207. extal_mhz = 15;
  208. break;
  209. case MD(13):
  210. extal_mhz = 20;
  211. break;
  212. case MD(14):
  213. extal_mhz = 26;
  214. break;
  215. case MD(13) | MD(14):
  216. extal_mhz = 30;
  217. break;
  218. }
  219. /* The arch timer frequency equals EXTAL / 2 */
  220. freq = extal_mhz * (1000000 / 2);
  221. /* Remap "armgcnt address map" space */
  222. base = ioremap(0xe6080000, PAGE_SIZE);
  223. /* Update registers with correct frequency */
  224. iowrite32(freq, base + CNTFID0);
  225. asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
  226. /* make sure arch timer is started by setting bit 0 of CNTCR */
  227. iowrite32(1, base + CNTCR);
  228. iounmap(base);
  229. #endif /* CONFIG_ARM_ARCH_TIMER */
  230. clocksource_of_init();
  231. }
  232. void __init r8a7790_init_delay(void)
  233. {
  234. #ifndef CONFIG_ARM_ARCH_TIMER
  235. shmobile_setup_delay(1300, 2, 4); /* Cortex-A15 @ 1300MHz */
  236. #endif
  237. }
  238. #ifdef CONFIG_USE_OF
  239. static const char *r8a7790_boards_compat_dt[] __initdata = {
  240. "renesas,r8a7790",
  241. NULL,
  242. };
  243. DT_MACHINE_START(R8A7790_DT, "Generic R8A7790 (Flattened Device Tree)")
  244. .init_early = r8a7790_init_delay,
  245. .init_time = r8a7790_timer_init,
  246. .dt_compat = r8a7790_boards_compat_dt,
  247. MACHINE_END
  248. #endif /* CONFIG_USE_OF */