setup-r8a7779.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * r8a7779 processor support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 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/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/delay.h>
  27. #include <linux/input.h>
  28. #include <linux/io.h>
  29. #include <linux/serial_sci.h>
  30. #include <linux/sh_intc.h>
  31. #include <linux/sh_timer.h>
  32. #include <mach/hardware.h>
  33. #include <mach/irqs.h>
  34. #include <mach/r8a7779.h>
  35. #include <mach/common.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/time.h>
  39. #include <asm/mach/map.h>
  40. #include <asm/hardware/cache-l2x0.h>
  41. static struct map_desc r8a7779_io_desc[] __initdata = {
  42. /* 2M entity map for 0xf0000000 (MPCORE) */
  43. {
  44. .virtual = 0xf0000000,
  45. .pfn = __phys_to_pfn(0xf0000000),
  46. .length = SZ_2M,
  47. .type = MT_DEVICE_NONSHARED
  48. },
  49. /* 16M entity map for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */
  50. {
  51. .virtual = 0xfe000000,
  52. .pfn = __phys_to_pfn(0xfe000000),
  53. .length = SZ_16M,
  54. .type = MT_DEVICE_NONSHARED
  55. },
  56. };
  57. void __init r8a7779_map_io(void)
  58. {
  59. iotable_init(r8a7779_io_desc, ARRAY_SIZE(r8a7779_io_desc));
  60. }
  61. static struct resource r8a7779_pfc_resources[] = {
  62. [0] = {
  63. .start = 0xfffc0000,
  64. .end = 0xfffc023b,
  65. .flags = IORESOURCE_MEM,
  66. },
  67. [1] = {
  68. .start = 0xffc40000,
  69. .end = 0xffc46fff,
  70. .flags = IORESOURCE_MEM,
  71. }
  72. };
  73. static struct platform_device r8a7779_pfc_device = {
  74. .name = "pfc-r8a7779",
  75. .id = -1,
  76. .resource = r8a7779_pfc_resources,
  77. .num_resources = ARRAY_SIZE(r8a7779_pfc_resources),
  78. };
  79. void __init r8a7779_pinmux_init(void)
  80. {
  81. platform_device_register(&r8a7779_pfc_device);
  82. }
  83. static struct plat_sci_port scif0_platform_data = {
  84. .mapbase = 0xffe40000,
  85. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  86. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  87. .scbrr_algo_id = SCBRR_ALGO_2,
  88. .type = PORT_SCIF,
  89. .irqs = SCIx_IRQ_MUXED(gic_iid(0x78)),
  90. };
  91. static struct platform_device scif0_device = {
  92. .name = "sh-sci",
  93. .id = 0,
  94. .dev = {
  95. .platform_data = &scif0_platform_data,
  96. },
  97. };
  98. static struct plat_sci_port scif1_platform_data = {
  99. .mapbase = 0xffe41000,
  100. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  101. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  102. .scbrr_algo_id = SCBRR_ALGO_2,
  103. .type = PORT_SCIF,
  104. .irqs = SCIx_IRQ_MUXED(gic_iid(0x79)),
  105. };
  106. static struct platform_device scif1_device = {
  107. .name = "sh-sci",
  108. .id = 1,
  109. .dev = {
  110. .platform_data = &scif1_platform_data,
  111. },
  112. };
  113. static struct plat_sci_port scif2_platform_data = {
  114. .mapbase = 0xffe42000,
  115. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  116. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  117. .scbrr_algo_id = SCBRR_ALGO_2,
  118. .type = PORT_SCIF,
  119. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7a)),
  120. };
  121. static struct platform_device scif2_device = {
  122. .name = "sh-sci",
  123. .id = 2,
  124. .dev = {
  125. .platform_data = &scif2_platform_data,
  126. },
  127. };
  128. static struct plat_sci_port scif3_platform_data = {
  129. .mapbase = 0xffe43000,
  130. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  131. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  132. .scbrr_algo_id = SCBRR_ALGO_2,
  133. .type = PORT_SCIF,
  134. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7b)),
  135. };
  136. static struct platform_device scif3_device = {
  137. .name = "sh-sci",
  138. .id = 3,
  139. .dev = {
  140. .platform_data = &scif3_platform_data,
  141. },
  142. };
  143. static struct plat_sci_port scif4_platform_data = {
  144. .mapbase = 0xffe44000,
  145. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  146. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  147. .scbrr_algo_id = SCBRR_ALGO_2,
  148. .type = PORT_SCIF,
  149. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7c)),
  150. };
  151. static struct platform_device scif4_device = {
  152. .name = "sh-sci",
  153. .id = 4,
  154. .dev = {
  155. .platform_data = &scif4_platform_data,
  156. },
  157. };
  158. static struct plat_sci_port scif5_platform_data = {
  159. .mapbase = 0xffe45000,
  160. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  161. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  162. .scbrr_algo_id = SCBRR_ALGO_2,
  163. .type = PORT_SCIF,
  164. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7d)),
  165. };
  166. static struct platform_device scif5_device = {
  167. .name = "sh-sci",
  168. .id = 5,
  169. .dev = {
  170. .platform_data = &scif5_platform_data,
  171. },
  172. };
  173. /* TMU */
  174. static struct sh_timer_config tmu00_platform_data = {
  175. .name = "TMU00",
  176. .channel_offset = 0x4,
  177. .timer_bit = 0,
  178. .clockevent_rating = 200,
  179. };
  180. static struct resource tmu00_resources[] = {
  181. [0] = {
  182. .name = "TMU00",
  183. .start = 0xffd80008,
  184. .end = 0xffd80013,
  185. .flags = IORESOURCE_MEM,
  186. },
  187. [1] = {
  188. .start = gic_iid(0x40),
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. };
  192. static struct platform_device tmu00_device = {
  193. .name = "sh_tmu",
  194. .id = 0,
  195. .dev = {
  196. .platform_data = &tmu00_platform_data,
  197. },
  198. .resource = tmu00_resources,
  199. .num_resources = ARRAY_SIZE(tmu00_resources),
  200. };
  201. static struct sh_timer_config tmu01_platform_data = {
  202. .name = "TMU01",
  203. .channel_offset = 0x10,
  204. .timer_bit = 1,
  205. .clocksource_rating = 200,
  206. };
  207. static struct resource tmu01_resources[] = {
  208. [0] = {
  209. .name = "TMU01",
  210. .start = 0xffd80014,
  211. .end = 0xffd8001f,
  212. .flags = IORESOURCE_MEM,
  213. },
  214. [1] = {
  215. .start = gic_iid(0x41),
  216. .flags = IORESOURCE_IRQ,
  217. },
  218. };
  219. static struct platform_device tmu01_device = {
  220. .name = "sh_tmu",
  221. .id = 1,
  222. .dev = {
  223. .platform_data = &tmu01_platform_data,
  224. },
  225. .resource = tmu01_resources,
  226. .num_resources = ARRAY_SIZE(tmu01_resources),
  227. };
  228. /* I2C */
  229. static struct resource rcar_i2c0_res[] = {
  230. {
  231. .start = 0xffc70000,
  232. .end = 0xffc70fff,
  233. .flags = IORESOURCE_MEM,
  234. }, {
  235. .start = gic_iid(0x6f),
  236. .flags = IORESOURCE_IRQ,
  237. },
  238. };
  239. static struct platform_device i2c0_device = {
  240. .name = "i2c-rcar",
  241. .id = 0,
  242. .resource = rcar_i2c0_res,
  243. .num_resources = ARRAY_SIZE(rcar_i2c0_res),
  244. };
  245. static struct resource rcar_i2c1_res[] = {
  246. {
  247. .start = 0xffc71000,
  248. .end = 0xffc71fff,
  249. .flags = IORESOURCE_MEM,
  250. }, {
  251. .start = gic_iid(0x72),
  252. .flags = IORESOURCE_IRQ,
  253. },
  254. };
  255. static struct platform_device i2c1_device = {
  256. .name = "i2c-rcar",
  257. .id = 1,
  258. .resource = rcar_i2c1_res,
  259. .num_resources = ARRAY_SIZE(rcar_i2c1_res),
  260. };
  261. static struct resource rcar_i2c2_res[] = {
  262. {
  263. .start = 0xffc72000,
  264. .end = 0xffc72fff,
  265. .flags = IORESOURCE_MEM,
  266. }, {
  267. .start = gic_iid(0x70),
  268. .flags = IORESOURCE_IRQ,
  269. },
  270. };
  271. static struct platform_device i2c2_device = {
  272. .name = "i2c-rcar",
  273. .id = 2,
  274. .resource = rcar_i2c2_res,
  275. .num_resources = ARRAY_SIZE(rcar_i2c2_res),
  276. };
  277. static struct resource rcar_i2c3_res[] = {
  278. {
  279. .start = 0xffc73000,
  280. .end = 0xffc73fff,
  281. .flags = IORESOURCE_MEM,
  282. }, {
  283. .start = gic_iid(0x71),
  284. .flags = IORESOURCE_IRQ,
  285. },
  286. };
  287. static struct platform_device i2c3_device = {
  288. .name = "i2c-rcar",
  289. .id = 3,
  290. .resource = rcar_i2c3_res,
  291. .num_resources = ARRAY_SIZE(rcar_i2c3_res),
  292. };
  293. static struct platform_device *r8a7779_devices_dt[] __initdata = {
  294. &scif0_device,
  295. &scif1_device,
  296. &scif2_device,
  297. &scif3_device,
  298. &scif4_device,
  299. &scif5_device,
  300. &tmu00_device,
  301. &tmu01_device,
  302. };
  303. static struct platform_device *r8a7779_late_devices[] __initdata = {
  304. &i2c0_device,
  305. &i2c1_device,
  306. &i2c2_device,
  307. &i2c3_device,
  308. };
  309. void __init r8a7779_add_standard_devices(void)
  310. {
  311. #ifdef CONFIG_CACHE_L2X0
  312. /* Early BRESP enable, Shared attribute override enable, 64K*16way */
  313. l2x0_init(IOMEM(0xf0100000), 0x40470000, 0x82000fff);
  314. #endif
  315. r8a7779_pm_init();
  316. r8a7779_init_pm_domains();
  317. platform_add_devices(r8a7779_devices_dt,
  318. ARRAY_SIZE(r8a7779_devices_dt));
  319. platform_add_devices(r8a7779_late_devices,
  320. ARRAY_SIZE(r8a7779_late_devices));
  321. }
  322. /* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
  323. void __init __weak r8a7779_register_twd(void) { }
  324. void __init r8a7779_earlytimer_init(void)
  325. {
  326. r8a7779_clock_init();
  327. shmobile_earlytimer_init();
  328. r8a7779_register_twd();
  329. }
  330. void __init r8a7779_add_early_devices(void)
  331. {
  332. early_platform_add_devices(r8a7779_devices_dt,
  333. ARRAY_SIZE(r8a7779_devices_dt));
  334. /* Early serial console setup is not included here due to
  335. * memory map collisions. The SCIF serial ports in r8a7779
  336. * are difficult to entity map 1:1 due to collision with the
  337. * virtual memory range used by the coherent DMA code on ARM.
  338. *
  339. * Anyone wanting to debug early can remove UPF_IOREMAP from
  340. * the sh-sci serial console platform data, adjust mapbase
  341. * to a static M:N virt:phys mapping that needs to be added to
  342. * the mappings passed with iotable_init() above.
  343. *
  344. * Then add a call to shmobile_setup_console() from this function.
  345. *
  346. * As a final step pass earlyprint=sh-sci.2,115200 on the kernel
  347. * command line in case of the marzen board.
  348. */
  349. }
  350. #ifdef CONFIG_USE_OF
  351. void __init r8a7779_init_delay(void)
  352. {
  353. shmobile_setup_delay(1000, 2, 4); /* Cortex-A9 @ 1000MHz */
  354. }
  355. static const struct of_dev_auxdata r8a7779_auxdata_lookup[] __initconst = {
  356. {},
  357. };
  358. void __init r8a7779_add_standard_devices_dt(void)
  359. {
  360. /* clocks are setup late during boot in the case of DT */
  361. r8a7779_clock_init();
  362. platform_add_devices(r8a7779_devices_dt,
  363. ARRAY_SIZE(r8a7779_devices_dt));
  364. of_platform_populate(NULL, of_default_bus_match_table,
  365. r8a7779_auxdata_lookup, NULL);
  366. }
  367. static const char *r8a7779_compat_dt[] __initdata = {
  368. "renesas,r8a7779",
  369. NULL,
  370. };
  371. DT_MACHINE_START(R8A7779_DT, "Generic R8A7779 (Flattened Device Tree)")
  372. .map_io = r8a7779_map_io,
  373. .init_early = r8a7779_init_delay,
  374. .nr_irqs = NR_IRQS_LEGACY,
  375. .init_irq = r8a7779_init_irq_dt,
  376. .init_machine = r8a7779_add_standard_devices_dt,
  377. .init_time = shmobile_timer_init,
  378. .dt_compat = r8a7779_compat_dt,
  379. MACHINE_END
  380. #endif /* CONFIG_USE_OF */