setup-r8a7778.c 11 KB

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