board-marzen.c 9.9 KB

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