setup-r8a7779.c 25 KB

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