setup-r8a7779.c 12 KB

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