setup-r8a7779.c 21 KB

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