setup-r8a7778.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * r8a7778 processor support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Copyright (C) 2013 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  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/io.h>
  23. #include <linux/irqchip/arm-gic.h>
  24. #include <linux/of.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/platform_data/dma-rcar-hpbdma.h>
  27. #include <linux/platform_data/gpio-rcar.h>
  28. #include <linux/platform_data/irq-renesas-intc-irqpin.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/irqchip.h>
  31. #include <linux/serial_sci.h>
  32. #include <linux/sh_timer.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/usb/phy.h>
  35. #include <linux/usb/hcd.h>
  36. #include <linux/usb/ehci_pdriver.h>
  37. #include <linux/usb/ohci_pdriver.h>
  38. #include <linux/dma-mapping.h>
  39. #include <mach/irqs.h>
  40. #include <mach/r8a7778.h>
  41. #include <mach/common.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/hardware/cache-l2x0.h>
  44. /* SCIF */
  45. #define SCIF_INFO(baseaddr, irq) \
  46. { \
  47. .mapbase = baseaddr, \
  48. .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
  49. .scscr = SCSCR_RE | SCSCR_TE | SCSCR_CKE1, \
  50. .scbrr_algo_id = SCBRR_ALGO_2, \
  51. .type = PORT_SCIF, \
  52. .irqs = SCIx_IRQ_MUXED(irq), \
  53. }
  54. static struct plat_sci_port scif_platform_data[] __initdata = {
  55. SCIF_INFO(0xffe40000, gic_iid(0x66)),
  56. SCIF_INFO(0xffe41000, gic_iid(0x67)),
  57. SCIF_INFO(0xffe42000, gic_iid(0x68)),
  58. SCIF_INFO(0xffe43000, gic_iid(0x69)),
  59. SCIF_INFO(0xffe44000, gic_iid(0x6a)),
  60. SCIF_INFO(0xffe45000, gic_iid(0x6b)),
  61. };
  62. /* TMU */
  63. static struct resource sh_tmu0_resources[] __initdata = {
  64. DEFINE_RES_MEM(0xffd80008, 12),
  65. DEFINE_RES_IRQ(gic_iid(0x40)),
  66. };
  67. static struct sh_timer_config sh_tmu0_platform_data __initdata = {
  68. .name = "TMU00",
  69. .channel_offset = 0x4,
  70. .timer_bit = 0,
  71. .clockevent_rating = 200,
  72. };
  73. static struct resource sh_tmu1_resources[] __initdata = {
  74. DEFINE_RES_MEM(0xffd80014, 12),
  75. DEFINE_RES_IRQ(gic_iid(0x41)),
  76. };
  77. static struct sh_timer_config sh_tmu1_platform_data __initdata = {
  78. .name = "TMU01",
  79. .channel_offset = 0x10,
  80. .timer_bit = 1,
  81. .clocksource_rating = 200,
  82. };
  83. #define r8a7778_register_tmu(idx) \
  84. platform_device_register_resndata( \
  85. &platform_bus, "sh_tmu", idx, \
  86. sh_tmu##idx##_resources, \
  87. ARRAY_SIZE(sh_tmu##idx##_resources), \
  88. &sh_tmu##idx##_platform_data, \
  89. sizeof(sh_tmu##idx##_platform_data))
  90. int r8a7778_usb_phy_power(bool enable)
  91. {
  92. static struct usb_phy *phy = NULL;
  93. int ret = 0;
  94. if (!phy)
  95. phy = usb_get_phy(USB_PHY_TYPE_USB2);
  96. if (IS_ERR(phy)) {
  97. pr_err("kernel doesn't have usb phy driver\n");
  98. return PTR_ERR(phy);
  99. }
  100. if (enable)
  101. ret = usb_phy_init(phy);
  102. else
  103. usb_phy_shutdown(phy);
  104. return ret;
  105. }
  106. /* USB */
  107. static int usb_power_on(struct platform_device *pdev)
  108. {
  109. int ret = r8a7778_usb_phy_power(true);
  110. if (ret)
  111. return ret;
  112. pm_runtime_enable(&pdev->dev);
  113. pm_runtime_get_sync(&pdev->dev);
  114. return 0;
  115. }
  116. static void usb_power_off(struct platform_device *pdev)
  117. {
  118. if (r8a7778_usb_phy_power(false))
  119. return;
  120. pm_runtime_put_sync(&pdev->dev);
  121. pm_runtime_disable(&pdev->dev);
  122. }
  123. static int ehci_init_internal_buffer(struct usb_hcd *hcd)
  124. {
  125. /*
  126. * Below are recommended values from the datasheet;
  127. * see [USB :: Setting of EHCI Internal Buffer].
  128. */
  129. /* EHCI IP internal buffer setting */
  130. iowrite32(0x00ff0040, hcd->regs + 0x0094);
  131. /* EHCI IP internal buffer enable */
  132. iowrite32(0x00000001, hcd->regs + 0x009C);
  133. return 0;
  134. }
  135. static struct usb_ehci_pdata ehci_pdata __initdata = {
  136. .power_on = usb_power_on,
  137. .power_off = usb_power_off,
  138. .power_suspend = usb_power_off,
  139. .pre_setup = ehci_init_internal_buffer,
  140. };
  141. static struct resource ehci_resources[] __initdata = {
  142. DEFINE_RES_MEM(0xffe70000, 0x400),
  143. DEFINE_RES_IRQ(gic_iid(0x4c)),
  144. };
  145. static struct usb_ohci_pdata ohci_pdata __initdata = {
  146. .power_on = usb_power_on,
  147. .power_off = usb_power_off,
  148. .power_suspend = usb_power_off,
  149. };
  150. static struct resource ohci_resources[] __initdata = {
  151. DEFINE_RES_MEM(0xffe70400, 0x400),
  152. DEFINE_RES_IRQ(gic_iid(0x4c)),
  153. };
  154. #define USB_PLATFORM_INFO(hci) \
  155. static struct platform_device_info hci##_info __initdata = { \
  156. .parent = &platform_bus, \
  157. .name = #hci "-platform", \
  158. .id = -1, \
  159. .res = hci##_resources, \
  160. .num_res = ARRAY_SIZE(hci##_resources), \
  161. .data = &hci##_pdata, \
  162. .size_data = sizeof(hci##_pdata), \
  163. .dma_mask = DMA_BIT_MASK(32), \
  164. }
  165. USB_PLATFORM_INFO(ehci);
  166. USB_PLATFORM_INFO(ohci);
  167. /* PFC/GPIO */
  168. static struct resource pfc_resources[] __initdata = {
  169. DEFINE_RES_MEM(0xfffc0000, 0x118),
  170. };
  171. #define R8A7778_GPIO(idx) \
  172. static struct resource r8a7778_gpio##idx##_resources[] __initdata = { \
  173. DEFINE_RES_MEM(0xffc40000 + 0x1000 * (idx), 0x30), \
  174. DEFINE_RES_IRQ(gic_iid(0x87)), \
  175. }; \
  176. \
  177. static struct gpio_rcar_config r8a7778_gpio##idx##_platform_data __initdata = { \
  178. .gpio_base = 32 * (idx), \
  179. .irq_base = GPIO_IRQ_BASE(idx), \
  180. .number_of_pins = 32, \
  181. .pctl_name = "pfc-r8a7778", \
  182. }
  183. R8A7778_GPIO(0);
  184. R8A7778_GPIO(1);
  185. R8A7778_GPIO(2);
  186. R8A7778_GPIO(3);
  187. R8A7778_GPIO(4);
  188. #define r8a7778_register_gpio(idx) \
  189. platform_device_register_resndata( \
  190. &platform_bus, "gpio_rcar", idx, \
  191. r8a7778_gpio##idx##_resources, \
  192. ARRAY_SIZE(r8a7778_gpio##idx##_resources), \
  193. &r8a7778_gpio##idx##_platform_data, \
  194. sizeof(r8a7778_gpio##idx##_platform_data))
  195. void __init r8a7778_pinmux_init(void)
  196. {
  197. platform_device_register_simple(
  198. "pfc-r8a7778", -1,
  199. pfc_resources,
  200. ARRAY_SIZE(pfc_resources));
  201. r8a7778_register_gpio(0);
  202. r8a7778_register_gpio(1);
  203. r8a7778_register_gpio(2);
  204. r8a7778_register_gpio(3);
  205. r8a7778_register_gpio(4);
  206. };
  207. /* I2C */
  208. static struct resource i2c_resources[] __initdata = {
  209. /* I2C0 */
  210. DEFINE_RES_MEM(0xffc70000, 0x1000),
  211. DEFINE_RES_IRQ(gic_iid(0x63)),
  212. /* I2C1 */
  213. DEFINE_RES_MEM(0xffc71000, 0x1000),
  214. DEFINE_RES_IRQ(gic_iid(0x6e)),
  215. /* I2C2 */
  216. DEFINE_RES_MEM(0xffc72000, 0x1000),
  217. DEFINE_RES_IRQ(gic_iid(0x6c)),
  218. /* I2C3 */
  219. DEFINE_RES_MEM(0xffc73000, 0x1000),
  220. DEFINE_RES_IRQ(gic_iid(0x6d)),
  221. };
  222. static void __init r8a7778_register_i2c(int id)
  223. {
  224. BUG_ON(id < 0 || id > 3);
  225. platform_device_register_simple(
  226. "i2c-rcar", id,
  227. i2c_resources + (2 * id), 2);
  228. }
  229. /* HSPI */
  230. static struct resource hspi_resources[] __initdata = {
  231. /* HSPI0 */
  232. DEFINE_RES_MEM(0xfffc7000, 0x18),
  233. DEFINE_RES_IRQ(gic_iid(0x5f)),
  234. /* HSPI1 */
  235. DEFINE_RES_MEM(0xfffc8000, 0x18),
  236. DEFINE_RES_IRQ(gic_iid(0x74)),
  237. /* HSPI2 */
  238. DEFINE_RES_MEM(0xfffc6000, 0x18),
  239. DEFINE_RES_IRQ(gic_iid(0x75)),
  240. };
  241. static void __init r8a7778_register_hspi(int id)
  242. {
  243. BUG_ON(id < 0 || id > 2);
  244. platform_device_register_simple(
  245. "sh-hspi", id,
  246. hspi_resources + (2 * id), 2);
  247. }
  248. void __init r8a7778_add_dt_devices(void)
  249. {
  250. int i;
  251. #ifdef CONFIG_CACHE_L2X0
  252. void __iomem *base = ioremap_nocache(0xf0100000, 0x1000);
  253. if (base) {
  254. /*
  255. * Early BRESP enable, Shared attribute override enable, 64K*16way
  256. * don't call iounmap(base)
  257. */
  258. l2x0_init(base, 0x40470000, 0x82000fff);
  259. }
  260. #endif
  261. for (i = 0; i < ARRAY_SIZE(scif_platform_data); i++)
  262. platform_device_register_data(&platform_bus, "sh-sci", i,
  263. &scif_platform_data[i],
  264. sizeof(struct plat_sci_port));
  265. r8a7778_register_tmu(0);
  266. r8a7778_register_tmu(1);
  267. }
  268. /* HPB-DMA */
  269. /* Asynchronous mode register (ASYNCMDR) bits */
  270. #define HPB_DMAE_ASYNCMDR_ASMD22_MASK BIT(2) /* SDHI0 */
  271. #define HPB_DMAE_ASYNCMDR_ASMD22_SINGLE BIT(2) /* SDHI0 */
  272. #define HPB_DMAE_ASYNCMDR_ASMD22_MULTI 0 /* SDHI0 */
  273. #define HPB_DMAE_ASYNCMDR_ASMD21_MASK BIT(1) /* SDHI0 */
  274. #define HPB_DMAE_ASYNCMDR_ASMD21_SINGLE BIT(1) /* SDHI0 */
  275. #define HPB_DMAE_ASYNCMDR_ASMD21_MULTI 0 /* SDHI0 */
  276. static const struct hpb_dmae_slave_config hpb_dmae_slaves[] = {
  277. {
  278. .id = HPBDMA_SLAVE_SDHI0_TX,
  279. .addr = 0xffe4c000 + 0x30,
  280. .dcr = HPB_DMAE_DCR_SPDS_16BIT |
  281. HPB_DMAE_DCR_DMDL |
  282. HPB_DMAE_DCR_DPDS_16BIT,
  283. .rstr = HPB_DMAE_ASYNCRSTR_ASRST21 |
  284. HPB_DMAE_ASYNCRSTR_ASRST22 |
  285. HPB_DMAE_ASYNCRSTR_ASRST23,
  286. .mdr = HPB_DMAE_ASYNCMDR_ASMD21_MULTI,
  287. .mdm = HPB_DMAE_ASYNCMDR_ASMD21_MASK,
  288. .port = 0x0D0C,
  289. .flags = HPB_DMAE_SET_ASYNC_RESET | HPB_DMAE_SET_ASYNC_MODE,
  290. .dma_ch = 21,
  291. }, {
  292. .id = HPBDMA_SLAVE_SDHI0_RX,
  293. .addr = 0xffe4c000 + 0x30,
  294. .dcr = HPB_DMAE_DCR_SMDL |
  295. HPB_DMAE_DCR_SPDS_16BIT |
  296. HPB_DMAE_DCR_DPDS_16BIT,
  297. .rstr = HPB_DMAE_ASYNCRSTR_ASRST21 |
  298. HPB_DMAE_ASYNCRSTR_ASRST22 |
  299. HPB_DMAE_ASYNCRSTR_ASRST23,
  300. .mdr = HPB_DMAE_ASYNCMDR_ASMD22_MULTI,
  301. .mdm = HPB_DMAE_ASYNCMDR_ASMD22_MASK,
  302. .port = 0x0D0C,
  303. .flags = HPB_DMAE_SET_ASYNC_RESET | HPB_DMAE_SET_ASYNC_MODE,
  304. .dma_ch = 22,
  305. },
  306. };
  307. static const struct hpb_dmae_channel hpb_dmae_channels[] = {
  308. HPB_DMAE_CHANNEL(0x7e, HPBDMA_SLAVE_SDHI0_TX), /* ch. 21 */
  309. HPB_DMAE_CHANNEL(0x7e, HPBDMA_SLAVE_SDHI0_RX), /* ch. 22 */
  310. };
  311. static struct hpb_dmae_pdata dma_platform_data __initdata = {
  312. .slaves = hpb_dmae_slaves,
  313. .num_slaves = ARRAY_SIZE(hpb_dmae_slaves),
  314. .channels = hpb_dmae_channels,
  315. .num_channels = ARRAY_SIZE(hpb_dmae_channels),
  316. .ts_shift = {
  317. [XMIT_SZ_8BIT] = 0,
  318. [XMIT_SZ_16BIT] = 1,
  319. [XMIT_SZ_32BIT] = 2,
  320. },
  321. .num_hw_channels = 39,
  322. };
  323. static struct resource hpb_dmae_resources[] __initdata = {
  324. /* Channel registers */
  325. DEFINE_RES_MEM(0xffc08000, 0x1000),
  326. /* Common registers */
  327. DEFINE_RES_MEM(0xffc09000, 0x170),
  328. /* Asynchronous reset registers */
  329. DEFINE_RES_MEM(0xffc00300, 4),
  330. /* Asynchronous mode registers */
  331. DEFINE_RES_MEM(0xffc00400, 4),
  332. /* IRQ for DMA channels */
  333. DEFINE_RES_NAMED(gic_iid(0x7b), 5, NULL, IORESOURCE_IRQ),
  334. };
  335. static void __init r8a7778_register_hpb_dmae(void)
  336. {
  337. platform_device_register_resndata(&platform_bus, "hpb-dma-engine", -1,
  338. hpb_dmae_resources,
  339. ARRAY_SIZE(hpb_dmae_resources),
  340. &dma_platform_data,
  341. sizeof(dma_platform_data));
  342. }
  343. void __init r8a7778_add_standard_devices(void)
  344. {
  345. r8a7778_add_dt_devices();
  346. r8a7778_register_i2c(0);
  347. r8a7778_register_i2c(1);
  348. r8a7778_register_i2c(2);
  349. r8a7778_register_i2c(3);
  350. r8a7778_register_hspi(0);
  351. r8a7778_register_hspi(1);
  352. r8a7778_register_hspi(2);
  353. r8a7778_register_hpb_dmae();
  354. }
  355. void __init r8a7778_init_late(void)
  356. {
  357. platform_device_register_full(&ehci_info);
  358. platform_device_register_full(&ohci_info);
  359. }
  360. static struct renesas_intc_irqpin_config irqpin_platform_data __initdata = {
  361. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  362. .sense_bitfield_width = 2,
  363. };
  364. static struct resource irqpin_resources[] __initdata = {
  365. DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */
  366. DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */
  367. DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */
  368. DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */
  369. DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */
  370. DEFINE_RES_IRQ(gic_iid(0x3b)), /* IRQ0 */
  371. DEFINE_RES_IRQ(gic_iid(0x3c)), /* IRQ1 */
  372. DEFINE_RES_IRQ(gic_iid(0x3d)), /* IRQ2 */
  373. DEFINE_RES_IRQ(gic_iid(0x3e)), /* IRQ3 */
  374. };
  375. void __init r8a7778_init_irq_extpin_dt(int irlm)
  376. {
  377. void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE);
  378. unsigned long tmp;
  379. if (!icr0) {
  380. pr_warn("r8a7778: unable to setup external irq pin mode\n");
  381. return;
  382. }
  383. tmp = ioread32(icr0);
  384. if (irlm)
  385. tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */
  386. else
  387. tmp &= ~(1 << 23); /* IRL mode - not supported */
  388. tmp |= (1 << 21); /* LVLMODE = 1 */
  389. iowrite32(tmp, icr0);
  390. iounmap(icr0);
  391. }
  392. void __init r8a7778_init_irq_extpin(int irlm)
  393. {
  394. r8a7778_init_irq_extpin_dt(irlm);
  395. if (irlm)
  396. platform_device_register_resndata(
  397. &platform_bus, "renesas_intc_irqpin", -1,
  398. irqpin_resources, ARRAY_SIZE(irqpin_resources),
  399. &irqpin_platform_data, sizeof(irqpin_platform_data));
  400. }
  401. void __init r8a7778_init_delay(void)
  402. {
  403. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  404. }
  405. #ifdef CONFIG_USE_OF
  406. #define INT2SMSKCR0 0x82288 /* 0xfe782288 */
  407. #define INT2SMSKCR1 0x8228c /* 0xfe78228c */
  408. #define INT2NTSR0 0x00018 /* 0xfe700018 */
  409. #define INT2NTSR1 0x0002c /* 0xfe70002c */
  410. void __init r8a7778_init_irq_dt(void)
  411. {
  412. void __iomem *base = ioremap_nocache(0xfe700000, 0x00100000);
  413. BUG_ON(!base);
  414. irqchip_init();
  415. /* route all interrupts to ARM */
  416. __raw_writel(0x73ffffff, base + INT2NTSR0);
  417. __raw_writel(0xffffffff, base + INT2NTSR1);
  418. /* unmask all known interrupts in INTCS2 */
  419. __raw_writel(0x08330773, base + INT2SMSKCR0);
  420. __raw_writel(0x00311110, base + INT2SMSKCR1);
  421. iounmap(base);
  422. }
  423. static const char *r8a7778_compat_dt[] __initdata = {
  424. "renesas,r8a7778",
  425. NULL,
  426. };
  427. DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)")
  428. .init_early = r8a7778_init_delay,
  429. .init_irq = r8a7778_init_irq_dt,
  430. .dt_compat = r8a7778_compat_dt,
  431. .init_late = r8a7778_init_late,
  432. MACHINE_END
  433. #endif /* CONFIG_USE_OF */