setup-r8a7779.c 12 KB

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