setup-r8a7778.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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[] __initdata = {
  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[] __initdata = {
  63. DEFINE_RES_MEM(0xffd80008, 12),
  64. DEFINE_RES_IRQ(gic_iid(0x40)),
  65. };
  66. static struct sh_timer_config sh_tmu0_platform_data __initdata = {
  67. .name = "TMU00",
  68. .channel_offset = 0x4,
  69. .timer_bit = 0,
  70. .clockevent_rating = 200,
  71. };
  72. static struct resource sh_tmu1_resources[] __initdata = {
  73. DEFINE_RES_MEM(0xffd80014, 12),
  74. DEFINE_RES_IRQ(gic_iid(0x41)),
  75. };
  76. static struct sh_timer_config sh_tmu1_platform_data __initdata = {
  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. int r8a7778_usb_phy_power(bool enable)
  90. {
  91. static struct usb_phy *phy = NULL;
  92. int ret = 0;
  93. if (!phy)
  94. phy = usb_get_phy(USB_PHY_TYPE_USB2);
  95. if (IS_ERR(phy)) {
  96. pr_err("kernel doesn't have usb phy driver\n");
  97. return PTR_ERR(phy);
  98. }
  99. if (enable)
  100. ret = usb_phy_init(phy);
  101. else
  102. usb_phy_shutdown(phy);
  103. return ret;
  104. }
  105. /* USB */
  106. static int usb_power_on(struct platform_device *pdev)
  107. {
  108. int ret = r8a7778_usb_phy_power(true);
  109. if (ret)
  110. return ret;
  111. pm_runtime_enable(&pdev->dev);
  112. pm_runtime_get_sync(&pdev->dev);
  113. return 0;
  114. }
  115. static void usb_power_off(struct platform_device *pdev)
  116. {
  117. if (r8a7778_usb_phy_power(false))
  118. return;
  119. pm_runtime_put_sync(&pdev->dev);
  120. pm_runtime_disable(&pdev->dev);
  121. }
  122. static int ehci_init_internal_buffer(struct usb_hcd *hcd)
  123. {
  124. /*
  125. * Below are recommended values from the datasheet;
  126. * see [USB :: Setting of EHCI Internal Buffer].
  127. */
  128. /* EHCI IP internal buffer setting */
  129. iowrite32(0x00ff0040, hcd->regs + 0x0094);
  130. /* EHCI IP internal buffer enable */
  131. iowrite32(0x00000001, hcd->regs + 0x009C);
  132. return 0;
  133. }
  134. static struct usb_ehci_pdata ehci_pdata __initdata = {
  135. .power_on = usb_power_on,
  136. .power_off = usb_power_off,
  137. .power_suspend = usb_power_off,
  138. .pre_setup = ehci_init_internal_buffer,
  139. };
  140. static struct resource ehci_resources[] __initdata = {
  141. DEFINE_RES_MEM(0xffe70000, 0x400),
  142. DEFINE_RES_IRQ(gic_iid(0x4c)),
  143. };
  144. static struct usb_ohci_pdata ohci_pdata __initdata = {
  145. .power_on = usb_power_on,
  146. .power_off = usb_power_off,
  147. .power_suspend = usb_power_off,
  148. };
  149. static struct resource ohci_resources[] __initdata = {
  150. DEFINE_RES_MEM(0xffe70400, 0x400),
  151. DEFINE_RES_IRQ(gic_iid(0x4c)),
  152. };
  153. #define USB_PLATFORM_INFO(hci) \
  154. static struct platform_device_info hci##_info __initdata = { \
  155. .parent = &platform_bus, \
  156. .name = #hci "-platform", \
  157. .id = -1, \
  158. .res = hci##_resources, \
  159. .num_res = ARRAY_SIZE(hci##_resources), \
  160. .data = &hci##_pdata, \
  161. .size_data = sizeof(hci##_pdata), \
  162. .dma_mask = DMA_BIT_MASK(32), \
  163. }
  164. USB_PLATFORM_INFO(ehci);
  165. USB_PLATFORM_INFO(ohci);
  166. /* Ether */
  167. static struct resource ether_resources[] __initdata = {
  168. DEFINE_RES_MEM(0xfde00000, 0x400),
  169. DEFINE_RES_IRQ(gic_iid(0x89)),
  170. };
  171. void __init r8a7778_add_ether_device(struct sh_eth_plat_data *pdata)
  172. {
  173. platform_device_register_resndata(&platform_bus, "r8a777x-ether", -1,
  174. ether_resources,
  175. ARRAY_SIZE(ether_resources),
  176. pdata, sizeof(*pdata));
  177. }
  178. /* PFC/GPIO */
  179. static struct resource pfc_resources[] __initdata = {
  180. DEFINE_RES_MEM(0xfffc0000, 0x118),
  181. };
  182. #define R8A7778_GPIO(idx) \
  183. static struct resource r8a7778_gpio##idx##_resources[] __initdata = { \
  184. DEFINE_RES_MEM(0xffc40000 + 0x1000 * (idx), 0x30), \
  185. DEFINE_RES_IRQ(gic_iid(0x87)), \
  186. }; \
  187. \
  188. static struct gpio_rcar_config r8a7778_gpio##idx##_platform_data __initdata = { \
  189. .gpio_base = 32 * (idx), \
  190. .irq_base = GPIO_IRQ_BASE(idx), \
  191. .number_of_pins = 32, \
  192. .pctl_name = "pfc-r8a7778", \
  193. }
  194. R8A7778_GPIO(0);
  195. R8A7778_GPIO(1);
  196. R8A7778_GPIO(2);
  197. R8A7778_GPIO(3);
  198. R8A7778_GPIO(4);
  199. #define r8a7778_register_gpio(idx) \
  200. platform_device_register_resndata( \
  201. &platform_bus, "gpio_rcar", idx, \
  202. r8a7778_gpio##idx##_resources, \
  203. ARRAY_SIZE(r8a7778_gpio##idx##_resources), \
  204. &r8a7778_gpio##idx##_platform_data, \
  205. sizeof(r8a7778_gpio##idx##_platform_data))
  206. void __init r8a7778_pinmux_init(void)
  207. {
  208. platform_device_register_simple(
  209. "pfc-r8a7778", -1,
  210. pfc_resources,
  211. ARRAY_SIZE(pfc_resources));
  212. r8a7778_register_gpio(0);
  213. r8a7778_register_gpio(1);
  214. r8a7778_register_gpio(2);
  215. r8a7778_register_gpio(3);
  216. r8a7778_register_gpio(4);
  217. };
  218. /* I2C */
  219. static struct resource i2c_resources[] __initdata = {
  220. /* I2C0 */
  221. DEFINE_RES_MEM(0xffc70000, 0x1000),
  222. DEFINE_RES_IRQ(gic_iid(0x63)),
  223. /* I2C1 */
  224. DEFINE_RES_MEM(0xffc71000, 0x1000),
  225. DEFINE_RES_IRQ(gic_iid(0x6e)),
  226. /* I2C2 */
  227. DEFINE_RES_MEM(0xffc72000, 0x1000),
  228. DEFINE_RES_IRQ(gic_iid(0x6c)),
  229. /* I2C3 */
  230. DEFINE_RES_MEM(0xffc73000, 0x1000),
  231. DEFINE_RES_IRQ(gic_iid(0x6d)),
  232. };
  233. static void __init r8a7778_register_i2c(int id)
  234. {
  235. BUG_ON(id < 0 || id > 3);
  236. platform_device_register_simple(
  237. "i2c-rcar", id,
  238. i2c_resources + (2 * id), 2);
  239. }
  240. /* HSPI */
  241. static struct resource hspi_resources[] __initdata = {
  242. /* HSPI0 */
  243. DEFINE_RES_MEM(0xfffc7000, 0x18),
  244. DEFINE_RES_IRQ(gic_iid(0x5f)),
  245. /* HSPI1 */
  246. DEFINE_RES_MEM(0xfffc8000, 0x18),
  247. DEFINE_RES_IRQ(gic_iid(0x74)),
  248. /* HSPI2 */
  249. DEFINE_RES_MEM(0xfffc6000, 0x18),
  250. DEFINE_RES_IRQ(gic_iid(0x75)),
  251. };
  252. void __init r8a7778_register_hspi(int id)
  253. {
  254. BUG_ON(id < 0 || id > 2);
  255. platform_device_register_simple(
  256. "sh-hspi", id,
  257. hspi_resources + (2 * id), 2);
  258. }
  259. /* VIN */
  260. #define R8A7778_VIN(idx) \
  261. static struct resource vin##idx##_resources[] __initdata = { \
  262. DEFINE_RES_MEM(0xffc50000 + 0x1000 * (idx), 0x1000), \
  263. DEFINE_RES_IRQ(gic_iid(0x5a)), \
  264. }; \
  265. \
  266. static struct platform_device_info vin##idx##_info __initdata = { \
  267. .parent = &platform_bus, \
  268. .name = "r8a7778-vin", \
  269. .id = idx, \
  270. .res = vin##idx##_resources, \
  271. .num_res = ARRAY_SIZE(vin##idx##_resources), \
  272. .dma_mask = DMA_BIT_MASK(32), \
  273. }
  274. R8A7778_VIN(0);
  275. R8A7778_VIN(1);
  276. static struct platform_device_info *vin_info_table[] __initdata = {
  277. &vin0_info,
  278. &vin1_info,
  279. };
  280. void __init r8a7778_add_vin_device(int id, struct rcar_vin_platform_data *pdata)
  281. {
  282. BUG_ON(id < 0 || id > 1);
  283. vin_info_table[id]->data = pdata;
  284. vin_info_table[id]->size_data = sizeof(*pdata);
  285. platform_device_register_full(vin_info_table[id]);
  286. }
  287. void __init r8a7778_add_dt_devices(void)
  288. {
  289. int i;
  290. #ifdef CONFIG_CACHE_L2X0
  291. void __iomem *base = ioremap_nocache(0xf0100000, 0x1000);
  292. if (base) {
  293. /*
  294. * Early BRESP enable, Shared attribute override enable, 64K*16way
  295. * don't call iounmap(base)
  296. */
  297. l2x0_init(base, 0x40470000, 0x82000fff);
  298. }
  299. #endif
  300. for (i = 0; i < ARRAY_SIZE(scif_platform_data); i++)
  301. platform_device_register_data(&platform_bus, "sh-sci", i,
  302. &scif_platform_data[i],
  303. sizeof(struct plat_sci_port));
  304. r8a7778_register_tmu(0);
  305. r8a7778_register_tmu(1);
  306. }
  307. void __init r8a7778_add_standard_devices(void)
  308. {
  309. r8a7778_add_dt_devices();
  310. r8a7778_register_i2c(0);
  311. r8a7778_register_i2c(1);
  312. r8a7778_register_i2c(2);
  313. r8a7778_register_i2c(3);
  314. r8a7778_register_hspi(0);
  315. r8a7778_register_hspi(1);
  316. r8a7778_register_hspi(2);
  317. }
  318. void __init r8a7778_init_late(void)
  319. {
  320. platform_device_register_full(&ehci_info);
  321. platform_device_register_full(&ohci_info);
  322. }
  323. static struct renesas_intc_irqpin_config irqpin_platform_data __initdata = {
  324. .irq_base = irq_pin(0), /* IRQ0 -> IRQ3 */
  325. .sense_bitfield_width = 2,
  326. };
  327. static struct resource irqpin_resources[] __initdata = {
  328. DEFINE_RES_MEM(0xfe78001c, 4), /* ICR1 */
  329. DEFINE_RES_MEM(0xfe780010, 4), /* INTPRI */
  330. DEFINE_RES_MEM(0xfe780024, 4), /* INTREQ */
  331. DEFINE_RES_MEM(0xfe780044, 4), /* INTMSK0 */
  332. DEFINE_RES_MEM(0xfe780064, 4), /* INTMSKCLR0 */
  333. DEFINE_RES_IRQ(gic_iid(0x3b)), /* IRQ0 */
  334. DEFINE_RES_IRQ(gic_iid(0x3c)), /* IRQ1 */
  335. DEFINE_RES_IRQ(gic_iid(0x3d)), /* IRQ2 */
  336. DEFINE_RES_IRQ(gic_iid(0x3e)), /* IRQ3 */
  337. };
  338. void __init r8a7778_init_irq_extpin(int irlm)
  339. {
  340. void __iomem *icr0 = ioremap_nocache(0xfe780000, PAGE_SIZE);
  341. unsigned long tmp;
  342. if (!icr0) {
  343. pr_warn("r8a7778: unable to setup external irq pin mode\n");
  344. return;
  345. }
  346. tmp = ioread32(icr0);
  347. if (irlm)
  348. tmp |= 1 << 23; /* IRQ0 -> IRQ3 as individual pins */
  349. else
  350. tmp &= ~(1 << 23); /* IRL mode - not supported */
  351. tmp |= (1 << 21); /* LVLMODE = 1 */
  352. iowrite32(tmp, icr0);
  353. iounmap(icr0);
  354. if (irlm)
  355. platform_device_register_resndata(
  356. &platform_bus, "renesas_intc_irqpin", -1,
  357. irqpin_resources, ARRAY_SIZE(irqpin_resources),
  358. &irqpin_platform_data, sizeof(irqpin_platform_data));
  359. }
  360. void __init r8a7778_init_delay(void)
  361. {
  362. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  363. }
  364. #ifdef CONFIG_USE_OF
  365. #define INT2SMSKCR0 0x82288 /* 0xfe782288 */
  366. #define INT2SMSKCR1 0x8228c /* 0xfe78228c */
  367. #define INT2NTSR0 0x00018 /* 0xfe700018 */
  368. #define INT2NTSR1 0x0002c /* 0xfe70002c */
  369. void __init r8a7778_init_irq_dt(void)
  370. {
  371. void __iomem *base = ioremap_nocache(0xfe700000, 0x00100000);
  372. BUG_ON(!base);
  373. irqchip_init();
  374. /* route all interrupts to ARM */
  375. __raw_writel(0x73ffffff, base + INT2NTSR0);
  376. __raw_writel(0xffffffff, base + INT2NTSR1);
  377. /* unmask all known interrupts in INTCS2 */
  378. __raw_writel(0x08330773, base + INT2SMSKCR0);
  379. __raw_writel(0x00311110, base + INT2SMSKCR1);
  380. iounmap(base);
  381. }
  382. static const char *r8a7778_compat_dt[] __initdata = {
  383. "renesas,r8a7778",
  384. NULL,
  385. };
  386. DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)")
  387. .init_early = r8a7778_init_delay,
  388. .init_irq = r8a7778_init_irq_dt,
  389. .dt_compat = r8a7778_compat_dt,
  390. .init_late = r8a7778_init_late,
  391. MACHINE_END
  392. #endif /* CONFIG_USE_OF */