setup-r8a7779.c 21 KB

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