setup-r8a7778.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * r8a7778 processor support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. * Copyright (C) 2013 Cogent Embedded, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/io.h>
  23. #include <linux/irqchip/arm-gic.h>
  24. #include <linux/of.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/platform_data/gpio-rcar.h>
  27. #include <linux/platform_data/irq-renesas-intc-irqpin.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/irqchip.h>
  30. #include <linux/serial_sci.h>
  31. #include <linux/sh_timer.h>
  32. #include <mach/irqs.h>
  33. #include <mach/r8a7778.h>
  34. #include <mach/common.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/hardware/cache-l2x0.h>
  37. /* SCIF */
  38. #define SCIF_INFO(baseaddr, irq) \
  39. { \
  40. .mapbase = baseaddr, \
  41. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
  42. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1, \
  43. .scbrr_algo_id = SCBRR_ALGO_2, \
  44. .type = PORT_SCIF, \
  45. .irqs = SCIx_IRQ_MUXED(irq), \
  46. }
  47. static struct plat_sci_port scif_platform_data[] = {
  48. SCIF_INFO(0xffe40000, gic_iid(0x66)),
  49. SCIF_INFO(0xffe41000, gic_iid(0x67)),
  50. SCIF_INFO(0xffe42000, gic_iid(0x68)),
  51. SCIF_INFO(0xffe43000, gic_iid(0x69)),
  52. SCIF_INFO(0xffe44000, gic_iid(0x6a)),
  53. SCIF_INFO(0xffe45000, gic_iid(0x6b)),
  54. };
  55. /* TMU */
  56. static struct resource sh_tmu0_resources[] = {
  57. DEFINE_RES_MEM(0xffd80008, 12),
  58. DEFINE_RES_IRQ(gic_iid(0x40)),
  59. };
  60. static struct sh_timer_config sh_tmu0_platform_data = {
  61. .name = "TMU00",
  62. .channel_offset = 0x4,
  63. .timer_bit = 0,
  64. .clockevent_rating = 200,
  65. };
  66. static struct resource sh_tmu1_resources[] = {
  67. DEFINE_RES_MEM(0xffd80014, 12),
  68. DEFINE_RES_IRQ(gic_iid(0x41)),
  69. };
  70. static struct sh_timer_config sh_tmu1_platform_data = {
  71. .name = "TMU01",
  72. .channel_offset = 0x10,
  73. .timer_bit = 1,
  74. .clocksource_rating = 200,
  75. };
  76. #define r8a7778_register_tmu(idx) \
  77. platform_device_register_resndata( \
  78. &platform_bus, "sh_tmu", idx, \
  79. sh_tmu##idx##_resources, \
  80. ARRAY_SIZE(sh_tmu##idx##_resources), \
  81. &sh_tmu##idx##_platform_data, \
  82. sizeof(sh_tmu##idx##_platform_data))
  83. /* Ether */
  84. static struct resource ether_resources[] = {
  85. DEFINE_RES_MEM(0xfde00000, 0x400),
  86. DEFINE_RES_IRQ(gic_iid(0x89)),
  87. };
  88. void __init r8a7778_add_ether_device(struct sh_eth_plat_data *pdata)
  89. {
  90. platform_device_register_resndata(&platform_bus, "sh_eth", -1,
  91. ether_resources,
  92. ARRAY_SIZE(ether_resources),
  93. pdata, sizeof(*pdata));
  94. }
  95. /* PFC/GPIO */
  96. static struct resource pfc_resources[] = {
  97. DEFINE_RES_MEM(0xfffc0000, 0x118),
  98. };
  99. #define R8A7778_GPIO(idx) \
  100. static struct resource r8a7778_gpio##idx##_resources[] = { \
  101. DEFINE_RES_MEM(0xffc40000 + 0x1000 * (idx), 0x30), \
  102. DEFINE_RES_IRQ(gic_iid(0x87)), \
  103. }; \
  104. \
  105. static struct gpio_rcar_config r8a7778_gpio##idx##_platform_data = { \
  106. .gpio_base = 32 * (idx), \
  107. .irq_base = GPIO_IRQ_BASE(idx), \
  108. .number_of_pins = 32, \
  109. .pctl_name = "pfc-r8a7778", \
  110. }
  111. R8A7778_GPIO(0);
  112. R8A7778_GPIO(1);
  113. R8A7778_GPIO(2);
  114. R8A7778_GPIO(3);
  115. R8A7778_GPIO(4);
  116. #define r8a7778_register_gpio(idx) \
  117. platform_device_register_resndata( \
  118. &platform_bus, "gpio_rcar", idx, \
  119. r8a7778_gpio##idx##_resources, \
  120. ARRAY_SIZE(r8a7778_gpio##idx##_resources), \
  121. &r8a7778_gpio##idx##_platform_data, \
  122. sizeof(r8a7778_gpio##idx##_platform_data))
  123. void __init r8a7778_pinmux_init(void)
  124. {
  125. platform_device_register_simple(
  126. "pfc-r8a7778", -1,
  127. pfc_resources,
  128. ARRAY_SIZE(pfc_resources));
  129. r8a7778_register_gpio(0);
  130. r8a7778_register_gpio(1);
  131. r8a7778_register_gpio(2);
  132. r8a7778_register_gpio(3);
  133. r8a7778_register_gpio(4);
  134. };
  135. /* SDHI */
  136. static struct resource sdhi_resources[] = {
  137. /* SDHI0 */
  138. DEFINE_RES_MEM(0xFFE4C000, 0x100),
  139. DEFINE_RES_IRQ(gic_iid(0x77)),
  140. /* SDHI1 */
  141. DEFINE_RES_MEM(0xFFE4D000, 0x100),
  142. DEFINE_RES_IRQ(gic_iid(0x78)),
  143. /* SDHI2 */
  144. DEFINE_RES_MEM(0xFFE4F000, 0x100),
  145. DEFINE_RES_IRQ(gic_iid(0x76)),
  146. };
  147. void __init r8a7778_sdhi_init(int id,
  148. struct sh_mobile_sdhi_info *info)
  149. {
  150. BUG_ON(id < 0 || id > 2);
  151. platform_device_register_resndata(
  152. &platform_bus, "sh_mobile_sdhi", id,
  153. sdhi_resources + (2 * id), 2,
  154. info, sizeof(*info));
  155. }
  156. void __init r8a7778_add_standard_devices(void)
  157. {
  158. int i;
  159. #ifdef CONFIG_CACHE_L2X0
  160. void __iomem *base = ioremap_nocache(0xf0100000, 0x1000);
  161. if (base) {
  162. /*
  163. * Early BRESP enable, Shared attribute override enable, 64K*16way
  164. * don't call iounmap(base)
  165. */
  166. l2x0_init(base, 0x40470000, 0x82000fff);
  167. }
  168. #endif
  169. for (i = 0; i < ARRAY_SIZE(scif_platform_data); i++)
  170. platform_device_register_data(&platform_bus, "sh-sci", i,
  171. &scif_platform_data[i],
  172. sizeof(struct plat_sci_port));
  173. r8a7778_register_tmu(0);
  174. r8a7778_register_tmu(1);
  175. }
  176. static struct renesas_intc_irqpin_config irqpin_platform_data = {
  177. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  178. .sense_bitfield_width = 2,
  179. };
  180. static struct resource irqpin_resources[] = {
  181. DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */
  182. DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */
  183. DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */
  184. DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */
  185. DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */
  186. DEFINE_RES_IRQ(gic_iid(0x3b)), /* IRQ0 */
  187. DEFINE_RES_IRQ(gic_iid(0x3c)), /* IRQ1 */
  188. DEFINE_RES_IRQ(gic_iid(0x3d)), /* IRQ2 */
  189. DEFINE_RES_IRQ(gic_iid(0x3e)), /* IRQ3 */
  190. };
  191. void __init r8a7778_init_irq_extpin(int irlm)
  192. {
  193. void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE);
  194. unsigned long tmp;
  195. if (!icr0) {
  196. pr_warn("r8a7778: unable to setup external irq pin mode\n");
  197. return;
  198. }
  199. tmp = ioread32(icr0);
  200. if (irlm)
  201. tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */
  202. else
  203. tmp &= ~(1 << 23); /* IRL mode - not supported */
  204. tmp |= (1 << 21); /* LVLMODE = 1 */
  205. iowrite32(tmp, icr0);
  206. iounmap(icr0);
  207. if (irlm)
  208. platform_device_register_resndata(
  209. &platform_bus, "renesas_intc_irqpin", -1,
  210. irqpin_resources, ARRAY_SIZE(irqpin_resources),
  211. &irqpin_platform_data, sizeof(irqpin_platform_data));
  212. }
  213. #define INT2SMSKCR0 0x82288 /* 0xfe782288 */
  214. #define INT2SMSKCR1 0x8228c /* 0xfe78228c */
  215. #define INT2NTSR0 0x00018 /* 0xfe700018 */
  216. #define INT2NTSR1 0x0002c /* 0xfe70002c */
  217. static void __init r8a7778_init_irq_common(void)
  218. {
  219. void __iomem *base = ioremap_nocache(0xfe700000, 0x00100000);
  220. BUG_ON(!base);
  221. /* route all interrupts to ARM */
  222. __raw_writel(0x73ffffff, base + INT2NTSR0);
  223. __raw_writel(0xffffffff, base + INT2NTSR1);
  224. /* unmask all known interrupts in INTCS2 */
  225. __raw_writel(0x08330773, base + INT2SMSKCR0);
  226. __raw_writel(0x00311110, base + INT2SMSKCR1);
  227. iounmap(base);
  228. }
  229. void __init r8a7778_init_irq(void)
  230. {
  231. void __iomem *gic_dist_base;
  232. void __iomem *gic_cpu_base;
  233. gic_dist_base = ioremap_nocache(0xfe438000, PAGE_SIZE);
  234. gic_cpu_base = ioremap_nocache(0xfe430000, PAGE_SIZE);
  235. BUG_ON(!gic_dist_base || !gic_cpu_base);
  236. /* use GIC to handle interrupts */
  237. gic_init(0, 29, gic_dist_base, gic_cpu_base);
  238. r8a7778_init_irq_common();
  239. }
  240. void __init r8a7778_init_delay(void)
  241. {
  242. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  243. }
  244. #ifdef CONFIG_USE_OF
  245. void __init r8a7778_init_irq_dt(void)
  246. {
  247. irqchip_init();
  248. r8a7778_init_irq_common();
  249. }
  250. static const struct of_dev_auxdata r8a7778_auxdata_lookup[] __initconst = {
  251. {},
  252. };
  253. void __init r8a7778_add_standard_devices_dt(void)
  254. {
  255. of_platform_populate(NULL, of_default_bus_match_table,
  256. r8a7778_auxdata_lookup, NULL);
  257. }
  258. static const char *r8a7778_compat_dt[] __initdata = {
  259. "renesas,r8a7778",
  260. NULL,
  261. };
  262. DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)")
  263. .init_early = r8a7778_init_delay,
  264. .init_irq = r8a7778_init_irq_dt,
  265. .init_machine = r8a7778_add_standard_devices_dt,
  266. .init_time = shmobile_timer_init,
  267. .dt_compat = r8a7778_compat_dt,
  268. MACHINE_END
  269. #endif /* CONFIG_USE_OF */