setup-r8a7779.c 22 KB

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