setup-r8a7778.c 12 KB

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