setup-r8a7779.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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/irqchip.h>
  26. #include <linux/irqchip/arm-gic.h>
  27. #include <linux/of_platform.h>
  28. #include <linux/platform_data/dma-rcar-hpbdma.h>
  29. #include <linux/platform_data/gpio-rcar.h>
  30. #include <linux/platform_data/irq-renesas-intc-irqpin.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/delay.h>
  33. #include <linux/input.h>
  34. #include <linux/io.h>
  35. #include <linux/serial_sci.h>
  36. #include <linux/sh_timer.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/usb/otg.h>
  39. #include <linux/usb/hcd.h>
  40. #include <linux/usb/ehci_pdriver.h>
  41. #include <linux/usb/ohci_pdriver.h>
  42. #include <linux/pm_runtime.h>
  43. #include <mach/irqs.h>
  44. #include <mach/r8a7779.h>
  45. #include <mach/common.h>
  46. #include <asm/mach-types.h>
  47. #include <asm/mach/arch.h>
  48. #include <asm/mach/time.h>
  49. #include <asm/mach/map.h>
  50. #include <asm/hardware/cache-l2x0.h>
  51. static struct map_desc r8a7779_io_desc[] __initdata = {
  52. /* 2M entity map for 0xf0000000 (MPCORE) */
  53. {
  54. .virtual = 0xf0000000,
  55. .pfn = __phys_to_pfn(0xf0000000),
  56. .length = SZ_2M,
  57. .type = MT_DEVICE_NONSHARED
  58. },
  59. /* 16M entity map for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */
  60. {
  61. .virtual = 0xfe000000,
  62. .pfn = __phys_to_pfn(0xfe000000),
  63. .length = SZ_16M,
  64. .type = MT_DEVICE_NONSHARED
  65. },
  66. };
  67. void __init r8a7779_map_io(void)
  68. {
  69. iotable_init(r8a7779_io_desc, ARRAY_SIZE(r8a7779_io_desc));
  70. }
  71. /* IRQ */
  72. #define INT2SMSKCR0 IOMEM(0xfe7822a0)
  73. #define INT2SMSKCR1 IOMEM(0xfe7822a4)
  74. #define INT2SMSKCR2 IOMEM(0xfe7822a8)
  75. #define INT2SMSKCR3 IOMEM(0xfe7822ac)
  76. #define INT2SMSKCR4 IOMEM(0xfe7822b0)
  77. #define INT2NTSR0 IOMEM(0xfe700060)
  78. #define INT2NTSR1 IOMEM(0xfe700064)
  79. static struct renesas_intc_irqpin_config irqpin0_platform_data __initdata = {
  80. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  81. .sense_bitfield_width = 2,
  82. };
  83. static struct resource irqpin0_resources[] __initdata = {
  84. DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */
  85. DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */
  86. DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */
  87. DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */
  88. DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */
  89. DEFINE_RES_IRQ(gic_spi(27)), /* IRQ0 */
  90. DEFINE_RES_IRQ(gic_spi(28)), /* IRQ1 */
  91. DEFINE_RES_IRQ(gic_spi(29)), /* IRQ2 */
  92. DEFINE_RES_IRQ(gic_spi(30)), /* IRQ3 */
  93. };
  94. void __init r8a7779_init_irq_extpin(int irlm)
  95. {
  96. void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE);
  97. u32 tmp;
  98. if (!icr0) {
  99. pr_warn("r8a7779: unable to setup external irq pin mode\n");
  100. return;
  101. }
  102. tmp = ioread32(icr0);
  103. if (irlm)
  104. tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */
  105. else
  106. tmp &= ~(1 << 23); /* IRL mode - not supported */
  107. tmp |= (1 << 21); /* LVLMODE = 1 */
  108. iowrite32(tmp, icr0);
  109. iounmap(icr0);
  110. if (irlm)
  111. platform_device_register_resndata(
  112. &platform_bus, "renesas_intc_irqpin", -1,
  113. irqpin0_resources, ARRAY_SIZE(irqpin0_resources),
  114. &irqpin0_platform_data, sizeof(irqpin0_platform_data));
  115. }
  116. /* PFC/GPIO */
  117. static struct resource r8a7779_pfc_resources[] = {
  118. DEFINE_RES_MEM(0xfffc0000, 0x023c),
  119. };
  120. static struct platform_device r8a7779_pfc_device = {
  121. .name = "pfc-r8a7779",
  122. .id = -1,
  123. .resource = r8a7779_pfc_resources,
  124. .num_resources = ARRAY_SIZE(r8a7779_pfc_resources),
  125. };
  126. #define R8A7779_GPIO(idx, npins) \
  127. static struct resource r8a7779_gpio##idx##_resources[] = { \
  128. DEFINE_RES_MEM(0xffc40000 + (0x1000 * (idx)), 0x002c), \
  129. DEFINE_RES_IRQ(gic_iid(0xad + (idx))), \
  130. }; \
  131. \
  132. static struct gpio_rcar_config r8a7779_gpio##idx##_platform_data = { \
  133. .gpio_base = 32 * (idx), \
  134. .irq_base = 0, \
  135. .number_of_pins = npins, \
  136. .pctl_name = "pfc-r8a7779", \
  137. }; \
  138. \
  139. static struct platform_device r8a7779_gpio##idx##_device = { \
  140. .name = "gpio_rcar", \
  141. .id = idx, \
  142. .resource = r8a7779_gpio##idx##_resources, \
  143. .num_resources = ARRAY_SIZE(r8a7779_gpio##idx##_resources), \
  144. .dev = { \
  145. .platform_data = &r8a7779_gpio##idx##_platform_data, \
  146. }, \
  147. }
  148. R8A7779_GPIO(0, 32);
  149. R8A7779_GPIO(1, 32);
  150. R8A7779_GPIO(2, 32);
  151. R8A7779_GPIO(3, 32);
  152. R8A7779_GPIO(4, 32);
  153. R8A7779_GPIO(5, 32);
  154. R8A7779_GPIO(6, 9);
  155. static struct platform_device *r8a7779_pinctrl_devices[] __initdata = {
  156. &r8a7779_pfc_device,
  157. &r8a7779_gpio0_device,
  158. &r8a7779_gpio1_device,
  159. &r8a7779_gpio2_device,
  160. &r8a7779_gpio3_device,
  161. &r8a7779_gpio4_device,
  162. &r8a7779_gpio5_device,
  163. &r8a7779_gpio6_device,
  164. };
  165. void __init r8a7779_pinmux_init(void)
  166. {
  167. platform_add_devices(r8a7779_pinctrl_devices,
  168. ARRAY_SIZE(r8a7779_pinctrl_devices));
  169. }
  170. static struct plat_sci_port scif0_platform_data = {
  171. .mapbase = 0xffe40000,
  172. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  173. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  174. .scbrr_algo_id = SCBRR_ALGO_2,
  175. .type = PORT_SCIF,
  176. .irqs = SCIx_IRQ_MUXED(gic_iid(0x78)),
  177. };
  178. static struct platform_device scif0_device = {
  179. .name = "sh-sci",
  180. .id = 0,
  181. .dev = {
  182. .platform_data = &scif0_platform_data,
  183. },
  184. };
  185. static struct plat_sci_port scif1_platform_data = {
  186. .mapbase = 0xffe41000,
  187. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  188. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  189. .scbrr_algo_id = SCBRR_ALGO_2,
  190. .type = PORT_SCIF,
  191. .irqs = SCIx_IRQ_MUXED(gic_iid(0x79)),
  192. };
  193. static struct platform_device scif1_device = {
  194. .name = "sh-sci",
  195. .id = 1,
  196. .dev = {
  197. .platform_data = &scif1_platform_data,
  198. },
  199. };
  200. static struct plat_sci_port scif2_platform_data = {
  201. .mapbase = 0xffe42000,
  202. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  203. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  204. .scbrr_algo_id = SCBRR_ALGO_2,
  205. .type = PORT_SCIF,
  206. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7a)),
  207. };
  208. static struct platform_device scif2_device = {
  209. .name = "sh-sci",
  210. .id = 2,
  211. .dev = {
  212. .platform_data = &scif2_platform_data,
  213. },
  214. };
  215. static struct plat_sci_port scif3_platform_data = {
  216. .mapbase = 0xffe43000,
  217. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  218. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  219. .scbrr_algo_id = SCBRR_ALGO_2,
  220. .type = PORT_SCIF,
  221. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7b)),
  222. };
  223. static struct platform_device scif3_device = {
  224. .name = "sh-sci",
  225. .id = 3,
  226. .dev = {
  227. .platform_data = &scif3_platform_data,
  228. },
  229. };
  230. static struct plat_sci_port scif4_platform_data = {
  231. .mapbase = 0xffe44000,
  232. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  233. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  234. .scbrr_algo_id = SCBRR_ALGO_2,
  235. .type = PORT_SCIF,
  236. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7c)),
  237. };
  238. static struct platform_device scif4_device = {
  239. .name = "sh-sci",
  240. .id = 4,
  241. .dev = {
  242. .platform_data = &scif4_platform_data,
  243. },
  244. };
  245. static struct plat_sci_port scif5_platform_data = {
  246. .mapbase = 0xffe45000,
  247. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
  248. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1,
  249. .scbrr_algo_id = SCBRR_ALGO_2,
  250. .type = PORT_SCIF,
  251. .irqs = SCIx_IRQ_MUXED(gic_iid(0x7d)),
  252. };
  253. static struct platform_device scif5_device = {
  254. .name = "sh-sci",
  255. .id = 5,
  256. .dev = {
  257. .platform_data = &scif5_platform_data,
  258. },
  259. };
  260. /* TMU */
  261. static struct sh_timer_config tmu00_platform_data = {
  262. .name = "TMU00",
  263. .channel_offset = 0x4,
  264. .timer_bit = 0,
  265. .clockevent_rating = 200,
  266. };
  267. static struct resource tmu00_resources[] = {
  268. [0] = {
  269. .name = "TMU00",
  270. .start = 0xffd80008,
  271. .end = 0xffd80013,
  272. .flags = IORESOURCE_MEM,
  273. },
  274. [1] = {
  275. .start = gic_iid(0x40),
  276. .flags = IORESOURCE_IRQ,
  277. },
  278. };
  279. static struct platform_device tmu00_device = {
  280. .name = "sh_tmu",
  281. .id = 0,
  282. .dev = {
  283. .platform_data = &tmu00_platform_data,
  284. },
  285. .resource = tmu00_resources,
  286. .num_resources = ARRAY_SIZE(tmu00_resources),
  287. };
  288. static struct sh_timer_config tmu01_platform_data = {
  289. .name = "TMU01",
  290. .channel_offset = 0x10,
  291. .timer_bit = 1,
  292. .clocksource_rating = 200,
  293. };
  294. static struct resource tmu01_resources[] = {
  295. [0] = {
  296. .name = "TMU01",
  297. .start = 0xffd80014,
  298. .end = 0xffd8001f,
  299. .flags = IORESOURCE_MEM,
  300. },
  301. [1] = {
  302. .start = gic_iid(0x41),
  303. .flags = IORESOURCE_IRQ,
  304. },
  305. };
  306. static struct platform_device tmu01_device = {
  307. .name = "sh_tmu",
  308. .id = 1,
  309. .dev = {
  310. .platform_data = &tmu01_platform_data,
  311. },
  312. .resource = tmu01_resources,
  313. .num_resources = ARRAY_SIZE(tmu01_resources),
  314. };
  315. /* I2C */
  316. static struct resource rcar_i2c0_res[] = {
  317. {
  318. .start = 0xffc70000,
  319. .end = 0xffc70fff,
  320. .flags = IORESOURCE_MEM,
  321. }, {
  322. .start = gic_iid(0x6f),
  323. .flags = IORESOURCE_IRQ,
  324. },
  325. };
  326. static struct platform_device i2c0_device = {
  327. .name = "i2c-rcar",
  328. .id = 0,
  329. .resource = rcar_i2c0_res,
  330. .num_resources = ARRAY_SIZE(rcar_i2c0_res),
  331. };
  332. static struct resource rcar_i2c1_res[] = {
  333. {
  334. .start = 0xffc71000,
  335. .end = 0xffc71fff,
  336. .flags = IORESOURCE_MEM,
  337. }, {
  338. .start = gic_iid(0x72),
  339. .flags = IORESOURCE_IRQ,
  340. },
  341. };
  342. static struct platform_device i2c1_device = {
  343. .name = "i2c-rcar",
  344. .id = 1,
  345. .resource = rcar_i2c1_res,
  346. .num_resources = ARRAY_SIZE(rcar_i2c1_res),
  347. };
  348. static struct resource rcar_i2c2_res[] = {
  349. {
  350. .start = 0xffc72000,
  351. .end = 0xffc72fff,
  352. .flags = IORESOURCE_MEM,
  353. }, {
  354. .start = gic_iid(0x70),
  355. .flags = IORESOURCE_IRQ,
  356. },
  357. };
  358. static struct platform_device i2c2_device = {
  359. .name = "i2c-rcar",
  360. .id = 2,
  361. .resource = rcar_i2c2_res,
  362. .num_resources = ARRAY_SIZE(rcar_i2c2_res),
  363. };
  364. static struct resource rcar_i2c3_res[] = {
  365. {
  366. .start = 0xffc73000,
  367. .end = 0xffc73fff,
  368. .flags = IORESOURCE_MEM,
  369. }, {
  370. .start = gic_iid(0x71),
  371. .flags = IORESOURCE_IRQ,
  372. },
  373. };
  374. static struct platform_device i2c3_device = {
  375. .name = "i2c-rcar",
  376. .id = 3,
  377. .resource = rcar_i2c3_res,
  378. .num_resources = ARRAY_SIZE(rcar_i2c3_res),
  379. };
  380. static struct resource sata_resources[] = {
  381. [0] = {
  382. .name = "rcar-sata",
  383. .start = 0xfc600000,
  384. .end = 0xfc601fff,
  385. .flags = IORESOURCE_MEM,
  386. },
  387. [1] = {
  388. .start = gic_iid(0x84),
  389. .flags = IORESOURCE_IRQ,
  390. },
  391. };
  392. static struct platform_device sata_device = {
  393. .name = "sata_rcar",
  394. .id = -1,
  395. .resource = sata_resources,
  396. .num_resources = ARRAY_SIZE(sata_resources),
  397. .dev = {
  398. .dma_mask = &sata_device.dev.coherent_dma_mask,
  399. .coherent_dma_mask = DMA_BIT_MASK(32),
  400. },
  401. };
  402. /* USB */
  403. static struct usb_phy *phy;
  404. static int usb_power_on(struct platform_device *pdev)
  405. {
  406. if (IS_ERR(phy))
  407. return PTR_ERR(phy);
  408. pm_runtime_enable(&pdev->dev);
  409. pm_runtime_get_sync(&pdev->dev);
  410. usb_phy_init(phy);
  411. return 0;
  412. }
  413. static void usb_power_off(struct platform_device *pdev)
  414. {
  415. if (IS_ERR(phy))
  416. return;
  417. usb_phy_shutdown(phy);
  418. pm_runtime_put_sync(&pdev->dev);
  419. pm_runtime_disable(&pdev->dev);
  420. }
  421. static int ehci_init_internal_buffer(struct usb_hcd *hcd)
  422. {
  423. /*
  424. * Below are recommended values from the datasheet;
  425. * see [USB :: Setting of EHCI Internal Buffer].
  426. */
  427. /* EHCI IP internal buffer setting */
  428. iowrite32(0x00ff0040, hcd->regs + 0x0094);
  429. /* EHCI IP internal buffer enable */
  430. iowrite32(0x00000001, hcd->regs + 0x009C);
  431. return 0;
  432. }
  433. static struct usb_ehci_pdata ehcix_pdata = {
  434. .power_on = usb_power_on,
  435. .power_off = usb_power_off,
  436. .power_suspend = usb_power_off,
  437. .pre_setup = ehci_init_internal_buffer,
  438. };
  439. static struct resource ehci0_resources[] = {
  440. [0] = {
  441. .start = 0xffe70000,
  442. .end = 0xffe70400 - 1,
  443. .flags = IORESOURCE_MEM,
  444. },
  445. [1] = {
  446. .start = gic_iid(0x4c),
  447. .flags = IORESOURCE_IRQ,
  448. },
  449. };
  450. static struct platform_device ehci0_device = {
  451. .name = "ehci-platform",
  452. .id = 0,
  453. .dev = {
  454. .dma_mask = &ehci0_device.dev.coherent_dma_mask,
  455. .coherent_dma_mask = 0xffffffff,
  456. .platform_data = &ehcix_pdata,
  457. },
  458. .num_resources = ARRAY_SIZE(ehci0_resources),
  459. .resource = ehci0_resources,
  460. };
  461. static struct resource ehci1_resources[] = {
  462. [0] = {
  463. .start = 0xfff70000,
  464. .end = 0xfff70400 - 1,
  465. .flags = IORESOURCE_MEM,
  466. },
  467. [1] = {
  468. .start = gic_iid(0x4d),
  469. .flags = IORESOURCE_IRQ,
  470. },
  471. };
  472. static struct platform_device ehci1_device = {
  473. .name = "ehci-platform",
  474. .id = 1,
  475. .dev = {
  476. .dma_mask = &ehci1_device.dev.coherent_dma_mask,
  477. .coherent_dma_mask = 0xffffffff,
  478. .platform_data = &ehcix_pdata,
  479. },
  480. .num_resources = ARRAY_SIZE(ehci1_resources),
  481. .resource = ehci1_resources,
  482. };
  483. static struct usb_ohci_pdata ohcix_pdata = {
  484. .power_on = usb_power_on,
  485. .power_off = usb_power_off,
  486. .power_suspend = usb_power_off,
  487. };
  488. static struct resource ohci0_resources[] = {
  489. [0] = {
  490. .start = 0xffe70400,
  491. .end = 0xffe70800 - 1,
  492. .flags = IORESOURCE_MEM,
  493. },
  494. [1] = {
  495. .start = gic_iid(0x4c),
  496. .flags = IORESOURCE_IRQ,
  497. },
  498. };
  499. static struct platform_device ohci0_device = {
  500. .name = "ohci-platform",
  501. .id = 0,
  502. .dev = {
  503. .dma_mask = &ohci0_device.dev.coherent_dma_mask,
  504. .coherent_dma_mask = 0xffffffff,
  505. .platform_data = &ohcix_pdata,
  506. },
  507. .num_resources = ARRAY_SIZE(ohci0_resources),
  508. .resource = ohci0_resources,
  509. };
  510. static struct resource ohci1_resources[] = {
  511. [0] = {
  512. .start = 0xfff70400,
  513. .end = 0xfff70800 - 1,
  514. .flags = IORESOURCE_MEM,
  515. },
  516. [1] = {
  517. .start = gic_iid(0x4d),
  518. .flags = IORESOURCE_IRQ,
  519. },
  520. };
  521. static struct platform_device ohci1_device = {
  522. .name = "ohci-platform",
  523. .id = 1,
  524. .dev = {
  525. .dma_mask = &ohci1_device.dev.coherent_dma_mask,
  526. .coherent_dma_mask = 0xffffffff,
  527. .platform_data = &ohcix_pdata,
  528. },
  529. .num_resources = ARRAY_SIZE(ohci1_resources),
  530. .resource = ohci1_resources,
  531. };
  532. /* Ether */
  533. static struct resource ether_resources[] __initdata = {
  534. {
  535. .start = 0xfde00000,
  536. .end = 0xfde003ff,
  537. .flags = IORESOURCE_MEM,
  538. }, {
  539. .start = gic_iid(0xb4),
  540. .flags = IORESOURCE_IRQ,
  541. },
  542. };
  543. #define R8A7779_VIN(idx) \
  544. static struct resource vin##idx##_resources[] __initdata = { \
  545. DEFINE_RES_MEM(0xffc50000 + 0x1000 * (idx), 0x1000), \
  546. DEFINE_RES_IRQ(gic_iid(0x5f + (idx))), \
  547. }; \
  548. \
  549. static struct platform_device_info vin##idx##_info __initdata = { \
  550. .parent = &platform_bus, \
  551. .name = "r8a7779-vin", \
  552. .id = idx, \
  553. .res = vin##idx##_resources, \
  554. .num_res = ARRAY_SIZE(vin##idx##_resources), \
  555. .dma_mask = DMA_BIT_MASK(32), \
  556. }
  557. R8A7779_VIN(0);
  558. R8A7779_VIN(1);
  559. R8A7779_VIN(2);
  560. R8A7779_VIN(3);
  561. static struct platform_device_info *vin_info_table[] __initdata = {
  562. &vin0_info,
  563. &vin1_info,
  564. &vin2_info,
  565. &vin3_info,
  566. };
  567. /* HPB-DMA */
  568. /* Asynchronous mode register bits */
  569. #define HPB_DMAE_ASYNCMDR_ASMD43_MASK BIT(23) /* MMC1 */
  570. #define HPB_DMAE_ASYNCMDR_ASMD43_SINGLE BIT(23) /* MMC1 */
  571. #define HPB_DMAE_ASYNCMDR_ASMD43_MULTI 0 /* MMC1 */
  572. #define HPB_DMAE_ASYNCMDR_ASBTMD43_MASK BIT(22) /* MMC1 */
  573. #define HPB_DMAE_ASYNCMDR_ASBTMD43_BURST BIT(22) /* MMC1 */
  574. #define HPB_DMAE_ASYNCMDR_ASBTMD43_NBURST 0 /* MMC1 */
  575. #define HPB_DMAE_ASYNCMDR_ASMD24_MASK BIT(21) /* MMC0 */
  576. #define HPB_DMAE_ASYNCMDR_ASMD24_SINGLE BIT(21) /* MMC0 */
  577. #define HPB_DMAE_ASYNCMDR_ASMD24_MULTI 0 /* MMC0 */
  578. #define HPB_DMAE_ASYNCMDR_ASBTMD24_MASK BIT(20) /* MMC0 */
  579. #define HPB_DMAE_ASYNCMDR_ASBTMD24_BURST BIT(20) /* MMC0 */
  580. #define HPB_DMAE_ASYNCMDR_ASBTMD24_NBURST 0 /* MMC0 */
  581. #define HPB_DMAE_ASYNCMDR_ASMD41_MASK BIT(19) /* SDHI3 */
  582. #define HPB_DMAE_ASYNCMDR_ASMD41_SINGLE BIT(19) /* SDHI3 */
  583. #define HPB_DMAE_ASYNCMDR_ASMD41_MULTI 0 /* SDHI3 */
  584. #define HPB_DMAE_ASYNCMDR_ASBTMD41_MASK BIT(18) /* SDHI3 */
  585. #define HPB_DMAE_ASYNCMDR_ASBTMD41_BURST BIT(18) /* SDHI3 */
  586. #define HPB_DMAE_ASYNCMDR_ASBTMD41_NBURST 0 /* SDHI3 */
  587. #define HPB_DMAE_ASYNCMDR_ASMD40_MASK BIT(17) /* SDHI3 */
  588. #define HPB_DMAE_ASYNCMDR_ASMD40_SINGLE BIT(17) /* SDHI3 */
  589. #define HPB_DMAE_ASYNCMDR_ASMD40_MULTI 0 /* SDHI3 */
  590. #define HPB_DMAE_ASYNCMDR_ASBTMD40_MASK BIT(16) /* SDHI3 */
  591. #define HPB_DMAE_ASYNCMDR_ASBTMD40_BURST BIT(16) /* SDHI3 */
  592. #define HPB_DMAE_ASYNCMDR_ASBTMD40_NBURST 0 /* SDHI3 */
  593. #define HPB_DMAE_ASYNCMDR_ASMD39_MASK BIT(15) /* SDHI3 */
  594. #define HPB_DMAE_ASYNCMDR_ASMD39_SINGLE BIT(15) /* SDHI3 */
  595. #define HPB_DMAE_ASYNCMDR_ASMD39_MULTI 0 /* SDHI3 */
  596. #define HPB_DMAE_ASYNCMDR_ASBTMD39_MASK BIT(14) /* SDHI3 */
  597. #define HPB_DMAE_ASYNCMDR_ASBTMD39_BURST BIT(14) /* SDHI3 */
  598. #define HPB_DMAE_ASYNCMDR_ASBTMD39_NBURST 0 /* SDHI3 */
  599. #define HPB_DMAE_ASYNCMDR_ASMD27_MASK BIT(13) /* SDHI2 */
  600. #define HPB_DMAE_ASYNCMDR_ASMD27_SINGLE BIT(13) /* SDHI2 */
  601. #define HPB_DMAE_ASYNCMDR_ASMD27_MULTI 0 /* SDHI2 */
  602. #define HPB_DMAE_ASYNCMDR_ASBTMD27_MASK BIT(12) /* SDHI2 */
  603. #define HPB_DMAE_ASYNCMDR_ASBTMD27_BURST BIT(12) /* SDHI2 */
  604. #define HPB_DMAE_ASYNCMDR_ASBTMD27_NBURST 0 /* SDHI2 */
  605. #define HPB_DMAE_ASYNCMDR_ASMD26_MASK BIT(11) /* SDHI2 */
  606. #define HPB_DMAE_ASYNCMDR_ASMD26_SINGLE BIT(11) /* SDHI2 */
  607. #define HPB_DMAE_ASYNCMDR_ASMD26_MULTI 0 /* SDHI2 */
  608. #define HPB_DMAE_ASYNCMDR_ASBTMD26_MASK BIT(10) /* SDHI2 */
  609. #define HPB_DMAE_ASYNCMDR_ASBTMD26_BURST BIT(10) /* SDHI2 */
  610. #define HPB_DMAE_ASYNCMDR_ASBTMD26_NBURST 0 /* SDHI2 */
  611. #define HPB_DMAE_ASYNCMDR_ASMD25_MASK BIT(9) /* SDHI2 */
  612. #define HPB_DMAE_ASYNCMDR_ASMD25_SINGLE BIT(9) /* SDHI2 */
  613. #define HPB_DMAE_ASYNCMDR_ASMD25_MULTI 0 /* SDHI2 */
  614. #define HPB_DMAE_ASYNCMDR_ASBTMD25_MASK BIT(8) /* SDHI2 */
  615. #define HPB_DMAE_ASYNCMDR_ASBTMD25_BURST BIT(8) /* SDHI2 */
  616. #define HPB_DMAE_ASYNCMDR_ASBTMD25_NBURST 0 /* SDHI2 */
  617. #define HPB_DMAE_ASYNCMDR_ASMD23_MASK BIT(7) /* SDHI0 */
  618. #define HPB_DMAE_ASYNCMDR_ASMD23_SINGLE BIT(7) /* SDHI0 */
  619. #define HPB_DMAE_ASYNCMDR_ASMD23_MULTI 0 /* SDHI0 */
  620. #define HPB_DMAE_ASYNCMDR_ASBTMD23_MASK BIT(6) /* SDHI0 */
  621. #define HPB_DMAE_ASYNCMDR_ASBTMD23_BURST BIT(6) /* SDHI0 */
  622. #define HPB_DMAE_ASYNCMDR_ASBTMD23_NBURST 0 /* SDHI0 */
  623. #define HPB_DMAE_ASYNCMDR_ASMD22_MASK BIT(5) /* SDHI0 */
  624. #define HPB_DMAE_ASYNCMDR_ASMD22_SINGLE BIT(5) /* SDHI0 */
  625. #define HPB_DMAE_ASYNCMDR_ASMD22_MULTI 0 /* SDHI0 */
  626. #define HPB_DMAE_ASYNCMDR_ASBTMD22_MASK BIT(4) /* SDHI0 */
  627. #define HPB_DMAE_ASYNCMDR_ASBTMD22_BURST BIT(4) /* SDHI0 */
  628. #define HPB_DMAE_ASYNCMDR_ASBTMD22_NBURST 0 /* SDHI0 */
  629. #define HPB_DMAE_ASYNCMDR_ASMD21_MASK BIT(3) /* SDHI0 */
  630. #define HPB_DMAE_ASYNCMDR_ASMD21_SINGLE BIT(3) /* SDHI0 */
  631. #define HPB_DMAE_ASYNCMDR_ASMD21_MULTI 0 /* SDHI0 */
  632. #define HPB_DMAE_ASYNCMDR_ASBTMD21_MASK BIT(2) /* SDHI0 */
  633. #define HPB_DMAE_ASYNCMDR_ASBTMD21_BURST BIT(2) /* SDHI0 */
  634. #define HPB_DMAE_ASYNCMDR_ASBTMD21_NBURST 0 /* SDHI0 */
  635. #define HPB_DMAE_ASYNCMDR_ASMD20_MASK BIT(1) /* SDHI1 */
  636. #define HPB_DMAE_ASYNCMDR_ASMD20_SINGLE BIT(1) /* SDHI1 */
  637. #define HPB_DMAE_ASYNCMDR_ASMD20_MULTI 0 /* SDHI1 */
  638. #define HPB_DMAE_ASYNCMDR_ASBTMD20_MASK BIT(0) /* SDHI1 */
  639. #define HPB_DMAE_ASYNCMDR_ASBTMD20_BURST BIT(0) /* SDHI1 */
  640. #define HPB_DMAE_ASYNCMDR_ASBTMD20_NBURST 0 /* SDHI1 */
  641. static const struct hpb_dmae_slave_config hpb_dmae_slaves[] = {
  642. {
  643. .id = HPBDMA_SLAVE_SDHI0_TX,
  644. .addr = 0xffe4c000 + 0x30,
  645. .dcr = HPB_DMAE_DCR_SPDS_16BIT |
  646. HPB_DMAE_DCR_DMDL |
  647. HPB_DMAE_DCR_DPDS_16BIT,
  648. .rstr = HPB_DMAE_ASYNCRSTR_ASRST21 |
  649. HPB_DMAE_ASYNCRSTR_ASRST22 |
  650. HPB_DMAE_ASYNCRSTR_ASRST23,
  651. .mdr = HPB_DMAE_ASYNCMDR_ASMD21_SINGLE |
  652. HPB_DMAE_ASYNCMDR_ASBTMD21_NBURST,
  653. .mdm = HPB_DMAE_ASYNCMDR_ASMD21_MASK |
  654. HPB_DMAE_ASYNCMDR_ASBTMD21_MASK,
  655. .port = 0x0D0C,
  656. .flags = HPB_DMAE_SET_ASYNC_RESET | HPB_DMAE_SET_ASYNC_MODE,
  657. .dma_ch = 21,
  658. }, {
  659. .id = HPBDMA_SLAVE_SDHI0_RX,
  660. .addr = 0xffe4c000 + 0x30,
  661. .dcr = HPB_DMAE_DCR_SMDL |
  662. HPB_DMAE_DCR_SPDS_16BIT |
  663. HPB_DMAE_DCR_DPDS_16BIT,
  664. .rstr = HPB_DMAE_ASYNCRSTR_ASRST21 |
  665. HPB_DMAE_ASYNCRSTR_ASRST22 |
  666. HPB_DMAE_ASYNCRSTR_ASRST23,
  667. .mdr = HPB_DMAE_ASYNCMDR_ASMD22_SINGLE |
  668. HPB_DMAE_ASYNCMDR_ASBTMD22_NBURST,
  669. .mdm = HPB_DMAE_ASYNCMDR_ASMD22_MASK |
  670. HPB_DMAE_ASYNCMDR_ASBTMD22_MASK,
  671. .port = 0x0D0C,
  672. .flags = HPB_DMAE_SET_ASYNC_RESET | HPB_DMAE_SET_ASYNC_MODE,
  673. .dma_ch = 22,
  674. },
  675. };
  676. static const struct hpb_dmae_channel hpb_dmae_channels[] = {
  677. HPB_DMAE_CHANNEL(0x93, HPBDMA_SLAVE_SDHI0_TX), /* ch. 21 */
  678. HPB_DMAE_CHANNEL(0x93, HPBDMA_SLAVE_SDHI0_RX), /* ch. 22 */
  679. };
  680. static struct hpb_dmae_pdata dma_platform_data __initdata = {
  681. .slaves = hpb_dmae_slaves,
  682. .num_slaves = ARRAY_SIZE(hpb_dmae_slaves),
  683. .channels = hpb_dmae_channels,
  684. .num_channels = ARRAY_SIZE(hpb_dmae_channels),
  685. .ts_shift = {
  686. [XMIT_SZ_8BIT] = 0,
  687. [XMIT_SZ_16BIT] = 1,
  688. [XMIT_SZ_32BIT] = 2,
  689. },
  690. .num_hw_channels = 44,
  691. };
  692. static struct resource hpb_dmae_resources[] __initdata = {
  693. /* Channel registers */
  694. DEFINE_RES_MEM(0xffc08000, 0x1000),
  695. /* Common registers */
  696. DEFINE_RES_MEM(0xffc09000, 0x170),
  697. /* Asynchronous reset registers */
  698. DEFINE_RES_MEM(0xffc00300, 4),
  699. /* Asynchronous mode registers */
  700. DEFINE_RES_MEM(0xffc00400, 4),
  701. /* IRQ for DMA channels */
  702. DEFINE_RES_NAMED(gic_iid(0x8e), 12, NULL, IORESOURCE_IRQ),
  703. };
  704. static void __init r8a7779_register_hpb_dmae(void)
  705. {
  706. platform_device_register_resndata(&platform_bus, "hpb-dma-engine", -1,
  707. hpb_dmae_resources,
  708. ARRAY_SIZE(hpb_dmae_resources),
  709. &dma_platform_data,
  710. sizeof(dma_platform_data));
  711. }
  712. static struct platform_device *r8a7779_devices_dt[] __initdata = {
  713. &scif0_device,
  714. &scif1_device,
  715. &scif2_device,
  716. &scif3_device,
  717. &scif4_device,
  718. &scif5_device,
  719. &tmu00_device,
  720. &tmu01_device,
  721. };
  722. static struct platform_device *r8a7779_standard_devices[] __initdata = {
  723. &i2c0_device,
  724. &i2c1_device,
  725. &i2c2_device,
  726. &i2c3_device,
  727. &sata_device,
  728. };
  729. void __init r8a7779_add_standard_devices(void)
  730. {
  731. #ifdef CONFIG_CACHE_L2X0
  732. /* Early BRESP enable, Shared attribute override enable, 64K*16way */
  733. l2x0_init(IOMEM(0xf0100000), 0x40470000, 0x82000fff);
  734. #endif
  735. r8a7779_pm_init();
  736. r8a7779_init_pm_domains();
  737. platform_add_devices(r8a7779_devices_dt,
  738. ARRAY_SIZE(r8a7779_devices_dt));
  739. platform_add_devices(r8a7779_standard_devices,
  740. ARRAY_SIZE(r8a7779_standard_devices));
  741. r8a7779_register_hpb_dmae();
  742. }
  743. void __init r8a7779_add_ether_device(struct sh_eth_plat_data *pdata)
  744. {
  745. platform_device_register_resndata(&platform_bus, "r8a777x-ether", -1,
  746. ether_resources,
  747. ARRAY_SIZE(ether_resources),
  748. pdata, sizeof(*pdata));
  749. }
  750. void __init r8a7779_add_vin_device(int id, struct rcar_vin_platform_data *pdata)
  751. {
  752. BUG_ON(id < 0 || id > 3);
  753. vin_info_table[id]->data = pdata;
  754. vin_info_table[id]->size_data = sizeof(*pdata);
  755. platform_device_register_full(vin_info_table[id]);
  756. }
  757. /* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
  758. void __init __weak r8a7779_register_twd(void) { }
  759. void __init r8a7779_earlytimer_init(void)
  760. {
  761. r8a7779_clock_init();
  762. r8a7779_register_twd();
  763. shmobile_earlytimer_init();
  764. }
  765. void __init r8a7779_add_early_devices(void)
  766. {
  767. early_platform_add_devices(r8a7779_devices_dt,
  768. ARRAY_SIZE(r8a7779_devices_dt));
  769. /* Early serial console setup is not included here due to
  770. * memory map collisions. The SCIF serial ports in r8a7779
  771. * are difficult to entity map 1:1 due to collision with the
  772. * virtual memory range used by the coherent DMA code on ARM.
  773. *
  774. * Anyone wanting to debug early can remove UPF_IOREMAP from
  775. * the sh-sci serial console platform data, adjust mapbase
  776. * to a static M:N virt:phys mapping that needs to be added to
  777. * the mappings passed with iotable_init() above.
  778. *
  779. * Then add a call to shmobile_setup_console() from this function.
  780. *
  781. * As a final step pass earlyprint=sh-sci.2,115200 on the kernel
  782. * command line in case of the marzen board.
  783. */
  784. }
  785. static struct platform_device *r8a7779_late_devices[] __initdata = {
  786. &ehci0_device,
  787. &ehci1_device,
  788. &ohci0_device,
  789. &ohci1_device,
  790. };
  791. void __init r8a7779_init_late(void)
  792. {
  793. /* get USB PHY */
  794. phy = usb_get_phy(USB_PHY_TYPE_USB2);
  795. shmobile_init_late();
  796. platform_add_devices(r8a7779_late_devices,
  797. ARRAY_SIZE(r8a7779_late_devices));
  798. }
  799. #ifdef CONFIG_USE_OF
  800. static int r8a7779_set_wake(struct irq_data *data, unsigned int on)
  801. {
  802. return 0; /* always allow wakeup */
  803. }
  804. void __init r8a7779_init_irq_dt(void)
  805. {
  806. gic_arch_extn.irq_set_wake = r8a7779_set_wake;
  807. irqchip_init();
  808. /* route all interrupts to ARM */
  809. __raw_writel(0xffffffff, INT2NTSR0);
  810. __raw_writel(0x3fffffff, INT2NTSR1);
  811. /* unmask all known interrupts in INTCS2 */
  812. __raw_writel(0xfffffff0, INT2SMSKCR0);
  813. __raw_writel(0xfff7ffff, INT2SMSKCR1);
  814. __raw_writel(0xfffbffdf, INT2SMSKCR2);
  815. __raw_writel(0xbffffffc, INT2SMSKCR3);
  816. __raw_writel(0x003fee3f, INT2SMSKCR4);
  817. }
  818. void __init r8a7779_init_delay(void)
  819. {
  820. shmobile_setup_delay(1000, 2, 4); /* Cortex-A9 @ 1000MHz */
  821. }
  822. void __init r8a7779_add_standard_devices_dt(void)
  823. {
  824. /* clocks are setup late during boot in the case of DT */
  825. r8a7779_clock_init();
  826. platform_add_devices(r8a7779_devices_dt,
  827. ARRAY_SIZE(r8a7779_devices_dt));
  828. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  829. }
  830. static const char *r8a7779_compat_dt[] __initdata = {
  831. "renesas,r8a7779",
  832. NULL,
  833. };
  834. DT_MACHINE_START(R8A7779_DT, "Generic R8A7779 (Flattened Device Tree)")
  835. .map_io = r8a7779_map_io,
  836. .init_early = r8a7779_init_delay,
  837. .nr_irqs = NR_IRQS_LEGACY,
  838. .init_irq = r8a7779_init_irq_dt,
  839. .init_machine = r8a7779_add_standard_devices_dt,
  840. .init_late = r8a7779_init_late,
  841. .dt_compat = r8a7779_compat_dt,
  842. MACHINE_END
  843. #endif /* CONFIG_USE_OF */