board-marzen.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. * marzen board support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 Magnus Damm
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/delay.h>
  26. #include <linux/io.h>
  27. #include <linux/leds.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/pinctrl/machine.h>
  30. #include <linux/platform_data/gpio-rcar.h>
  31. #include <linux/regulator/fixed.h>
  32. #include <linux/regulator/machine.h>
  33. #include <linux/smsc911x.h>
  34. #include <linux/spi/spi.h>
  35. #include <linux/spi/sh_hspi.h>
  36. #include <linux/mmc/host.h>
  37. #include <linux/mmc/sh_mobile_sdhi.h>
  38. #include <linux/mfd/tmio.h>
  39. #include <linux/usb/otg.h>
  40. #include <linux/usb/ehci_pdriver.h>
  41. #include <linux/usb/ohci_pdriver.h>
  42. #include <linux/pm_runtime.h>
  43. #include <mach/hardware.h>
  44. #include <mach/r8a7779.h>
  45. #include <mach/common.h>
  46. #include <mach/irqs.h>
  47. #include <asm/mach-types.h>
  48. #include <asm/mach/arch.h>
  49. #include <asm/traps.h>
  50. /* Fixed 3.3V regulator to be used by SDHI0 */
  51. static struct regulator_consumer_supply fixed3v3_power_consumers[] = {
  52. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
  53. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
  54. };
  55. /* Dummy supplies, where voltage doesn't matter */
  56. static struct regulator_consumer_supply dummy_supplies[] = {
  57. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  58. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  59. };
  60. /* SMSC LAN89218 */
  61. static struct resource smsc911x_resources[] = {
  62. [0] = {
  63. .start = 0x18000000, /* ExCS0 */
  64. .end = 0x180000ff, /* A1->A7 */
  65. .flags = IORESOURCE_MEM,
  66. },
  67. [1] = {
  68. .start = irq_pin(1), /* IRQ 1 */
  69. .flags = IORESOURCE_IRQ,
  70. },
  71. };
  72. static struct smsc911x_platform_config smsc911x_platdata = {
  73. .flags = SMSC911X_USE_32BIT, /* 32-bit SW on 16-bit HW bus */
  74. .phy_interface = PHY_INTERFACE_MODE_MII,
  75. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  76. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  77. };
  78. static struct platform_device eth_device = {
  79. .name = "smsc911x",
  80. .id = -1,
  81. .dev = {
  82. .platform_data = &smsc911x_platdata,
  83. },
  84. .resource = smsc911x_resources,
  85. .num_resources = ARRAY_SIZE(smsc911x_resources),
  86. };
  87. static struct resource sdhi0_resources[] = {
  88. [0] = {
  89. .name = "sdhi0",
  90. .start = 0xffe4c000,
  91. .end = 0xffe4c0ff,
  92. .flags = IORESOURCE_MEM,
  93. },
  94. [1] = {
  95. .start = gic_iid(0x88),
  96. .flags = IORESOURCE_IRQ,
  97. },
  98. };
  99. static struct sh_mobile_sdhi_info sdhi0_platform_data = {
  100. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_HAS_IDLE_WAIT,
  101. .tmio_caps = MMC_CAP_SD_HIGHSPEED,
  102. };
  103. static struct platform_device sdhi0_device = {
  104. .name = "sh_mobile_sdhi",
  105. .num_resources = ARRAY_SIZE(sdhi0_resources),
  106. .resource = sdhi0_resources,
  107. .id = 0,
  108. .dev = {
  109. .platform_data = &sdhi0_platform_data,
  110. }
  111. };
  112. /* Thermal */
  113. static struct resource thermal_resources[] = {
  114. [0] = {
  115. .start = 0xFFC48000,
  116. .end = 0xFFC48038 - 1,
  117. .flags = IORESOURCE_MEM,
  118. },
  119. };
  120. static struct platform_device thermal_device = {
  121. .name = "rcar_thermal",
  122. .resource = thermal_resources,
  123. .num_resources = ARRAY_SIZE(thermal_resources),
  124. };
  125. /* HSPI */
  126. static struct resource hspi_resources[] = {
  127. [0] = {
  128. .start = 0xFFFC7000,
  129. .end = 0xFFFC7018 - 1,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. };
  133. static struct platform_device hspi_device = {
  134. .name = "sh-hspi",
  135. .id = 0,
  136. .resource = hspi_resources,
  137. .num_resources = ARRAY_SIZE(hspi_resources),
  138. };
  139. /* USB PHY */
  140. static struct resource usb_phy_resources[] = {
  141. [0] = {
  142. .start = 0xffe70000,
  143. .end = 0xffe70900 - 1,
  144. .flags = IORESOURCE_MEM,
  145. },
  146. [1] = {
  147. .start = 0xfff70000,
  148. .end = 0xfff70900 - 1,
  149. .flags = IORESOURCE_MEM,
  150. },
  151. };
  152. static struct platform_device usb_phy_device = {
  153. .name = "rcar_usb_phy",
  154. .resource = usb_phy_resources,
  155. .num_resources = ARRAY_SIZE(usb_phy_resources),
  156. };
  157. /* LEDS */
  158. static struct gpio_led marzen_leds[] = {
  159. {
  160. .name = "led2",
  161. .gpio = RCAR_GP_PIN(4, 29),
  162. .default_state = LEDS_GPIO_DEFSTATE_ON,
  163. }, {
  164. .name = "led3",
  165. .gpio = RCAR_GP_PIN(4, 30),
  166. .default_state = LEDS_GPIO_DEFSTATE_ON,
  167. }, {
  168. .name = "led4",
  169. .gpio = RCAR_GP_PIN(4, 31),
  170. .default_state = LEDS_GPIO_DEFSTATE_ON,
  171. },
  172. };
  173. static struct gpio_led_platform_data marzen_leds_pdata = {
  174. .leds = marzen_leds,
  175. .num_leds = ARRAY_SIZE(marzen_leds),
  176. };
  177. static struct platform_device leds_device = {
  178. .name = "leds-gpio",
  179. .id = 0,
  180. .dev = {
  181. .platform_data = &marzen_leds_pdata,
  182. },
  183. };
  184. static struct platform_device *marzen_devices[] __initdata = {
  185. &eth_device,
  186. &sdhi0_device,
  187. &thermal_device,
  188. &hspi_device,
  189. &usb_phy_device,
  190. &leds_device,
  191. };
  192. /* USB */
  193. static struct usb_phy *phy;
  194. static int usb_power_on(struct platform_device *pdev)
  195. {
  196. if (!phy)
  197. return -EIO;
  198. pm_runtime_enable(&pdev->dev);
  199. pm_runtime_get_sync(&pdev->dev);
  200. usb_phy_init(phy);
  201. return 0;
  202. }
  203. static void usb_power_off(struct platform_device *pdev)
  204. {
  205. if (!phy)
  206. return;
  207. usb_phy_shutdown(phy);
  208. pm_runtime_put_sync(&pdev->dev);
  209. pm_runtime_disable(&pdev->dev);
  210. }
  211. static struct usb_ehci_pdata ehcix_pdata = {
  212. .power_on = usb_power_on,
  213. .power_off = usb_power_off,
  214. .power_suspend = usb_power_off,
  215. };
  216. static struct resource ehci0_resources[] = {
  217. [0] = {
  218. .start = 0xffe70000,
  219. .end = 0xffe70400 - 1,
  220. .flags = IORESOURCE_MEM,
  221. },
  222. [1] = {
  223. .start = gic_iid(0x4c),
  224. .flags = IORESOURCE_IRQ,
  225. },
  226. };
  227. static struct platform_device ehci0_device = {
  228. .name = "ehci-platform",
  229. .id = 0,
  230. .dev = {
  231. .dma_mask = &ehci0_device.dev.coherent_dma_mask,
  232. .coherent_dma_mask = 0xffffffff,
  233. .platform_data = &ehcix_pdata,
  234. },
  235. .num_resources = ARRAY_SIZE(ehci0_resources),
  236. .resource = ehci0_resources,
  237. };
  238. static struct resource ehci1_resources[] = {
  239. [0] = {
  240. .start = 0xfff70000,
  241. .end = 0xfff70400 - 1,
  242. .flags = IORESOURCE_MEM,
  243. },
  244. [1] = {
  245. .start = gic_iid(0x4d),
  246. .flags = IORESOURCE_IRQ,
  247. },
  248. };
  249. static struct platform_device ehci1_device = {
  250. .name = "ehci-platform",
  251. .id = 1,
  252. .dev = {
  253. .dma_mask = &ehci1_device.dev.coherent_dma_mask,
  254. .coherent_dma_mask = 0xffffffff,
  255. .platform_data = &ehcix_pdata,
  256. },
  257. .num_resources = ARRAY_SIZE(ehci1_resources),
  258. .resource = ehci1_resources,
  259. };
  260. static struct usb_ohci_pdata ohcix_pdata = {
  261. .power_on = usb_power_on,
  262. .power_off = usb_power_off,
  263. .power_suspend = usb_power_off,
  264. };
  265. static struct resource ohci0_resources[] = {
  266. [0] = {
  267. .start = 0xffe70400,
  268. .end = 0xffe70800 - 1,
  269. .flags = IORESOURCE_MEM,
  270. },
  271. [1] = {
  272. .start = gic_iid(0x4c),
  273. .flags = IORESOURCE_IRQ,
  274. },
  275. };
  276. static struct platform_device ohci0_device = {
  277. .name = "ohci-platform",
  278. .id = 0,
  279. .dev = {
  280. .dma_mask = &ohci0_device.dev.coherent_dma_mask,
  281. .coherent_dma_mask = 0xffffffff,
  282. .platform_data = &ohcix_pdata,
  283. },
  284. .num_resources = ARRAY_SIZE(ohci0_resources),
  285. .resource = ohci0_resources,
  286. };
  287. static struct resource ohci1_resources[] = {
  288. [0] = {
  289. .start = 0xfff70400,
  290. .end = 0xfff70800 - 1,
  291. .flags = IORESOURCE_MEM,
  292. },
  293. [1] = {
  294. .start = gic_iid(0x4d),
  295. .flags = IORESOURCE_IRQ,
  296. },
  297. };
  298. static struct platform_device ohci1_device = {
  299. .name = "ohci-platform",
  300. .id = 1,
  301. .dev = {
  302. .dma_mask = &ohci1_device.dev.coherent_dma_mask,
  303. .coherent_dma_mask = 0xffffffff,
  304. .platform_data = &ohcix_pdata,
  305. },
  306. .num_resources = ARRAY_SIZE(ohci1_resources),
  307. .resource = ohci1_resources,
  308. };
  309. static struct platform_device *marzen_late_devices[] __initdata = {
  310. &ehci0_device,
  311. &ehci1_device,
  312. &ohci0_device,
  313. &ohci1_device,
  314. };
  315. static void __init marzen_init_late(void)
  316. {
  317. /* get usb phy */
  318. phy = usb_get_phy(USB_PHY_TYPE_USB2);
  319. shmobile_init_late();
  320. platform_add_devices(marzen_late_devices,
  321. ARRAY_SIZE(marzen_late_devices));
  322. }
  323. static const struct pinctrl_map marzen_pinctrl_map[] = {
  324. /* HSPI0 */
  325. PIN_MAP_MUX_GROUP_DEFAULT("sh-hspi.0", "pfc-r8a7779",
  326. "hspi0", "hspi0"),
  327. /* SCIF2 (CN18: DEBUG0) */
  328. PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-r8a7779",
  329. "scif2_data_c", "scif2"),
  330. /* SCIF4 (CN19: DEBUG1) */
  331. PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.4", "pfc-r8a7779",
  332. "scif4_data", "scif4"),
  333. /* SDHI0 */
  334. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
  335. "sdhi0_data4", "sdhi0"),
  336. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
  337. "sdhi0_ctrl", "sdhi0"),
  338. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
  339. "sdhi0_cd", "sdhi0"),
  340. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7779",
  341. "sdhi0_wp", "sdhi0"),
  342. /* SMSC */
  343. PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-r8a7779",
  344. "intc_irq1_b", "intc"),
  345. PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-r8a7779",
  346. "lbsc_ex_cs0", "lbsc"),
  347. /* USB0 */
  348. PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.0", "pfc-r8a7779",
  349. "usb0", "usb0"),
  350. /* USB1 */
  351. PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.0", "pfc-r8a7779",
  352. "usb1", "usb1"),
  353. /* USB2 */
  354. PIN_MAP_MUX_GROUP_DEFAULT("ehci-platform.1", "pfc-r8a7779",
  355. "usb2", "usb2"),
  356. };
  357. static void __init marzen_init(void)
  358. {
  359. regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
  360. ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
  361. regulator_register_fixed(1, dummy_supplies,
  362. ARRAY_SIZE(dummy_supplies));
  363. pinctrl_register_mappings(marzen_pinctrl_map,
  364. ARRAY_SIZE(marzen_pinctrl_map));
  365. r8a7779_pinmux_init();
  366. r8a7779_init_irq_extpin(1); /* IRQ1 as individual interrupt */
  367. r8a7779_add_standard_devices();
  368. platform_add_devices(marzen_devices, ARRAY_SIZE(marzen_devices));
  369. }
  370. MACHINE_START(MARZEN, "marzen")
  371. .smp = smp_ops(r8a7779_smp_ops),
  372. .map_io = r8a7779_map_io,
  373. .init_early = r8a7779_add_early_devices,
  374. .nr_irqs = NR_IRQS_LEGACY,
  375. .init_irq = r8a7779_init_irq,
  376. .init_machine = marzen_init,
  377. .init_late = marzen_init_late,
  378. .init_time = r8a7779_earlytimer_init,
  379. MACHINE_END