mach-mx31_3ds.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/types.h>
  16. #include <linux/init.h>
  17. #include <linux/clk.h>
  18. #include <linux/irq.h>
  19. #include <linux/gpio.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mfd/mc13783.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/regulator/machine.h>
  24. #include <linux/usb/otg.h>
  25. #include <linux/usb/ulpi.h>
  26. #include <mach/hardware.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/time.h>
  30. #include <asm/memory.h>
  31. #include <asm/mach/map.h>
  32. #include <mach/common.h>
  33. #include <mach/iomux-mx3.h>
  34. #include <mach/3ds_debugboard.h>
  35. #include <mach/ulpi.h>
  36. #include "devices-imx31.h"
  37. #include "devices.h"
  38. /* CPLD IRQ line for external uart, external ethernet etc */
  39. #define EXPIO_PARENT_INT IOMUX_TO_IRQ(MX31_PIN_GPIO1_1)
  40. static int mx31_3ds_pins[] = {
  41. /* UART1 */
  42. MX31_PIN_CTS1__CTS1,
  43. MX31_PIN_RTS1__RTS1,
  44. MX31_PIN_TXD1__TXD1,
  45. MX31_PIN_RXD1__RXD1,
  46. IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
  47. /* SPI 1 */
  48. MX31_PIN_CSPI2_SCLK__SCLK,
  49. MX31_PIN_CSPI2_MOSI__MOSI,
  50. MX31_PIN_CSPI2_MISO__MISO,
  51. MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
  52. MX31_PIN_CSPI2_SS0__SS0,
  53. MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
  54. /* MC13783 IRQ */
  55. IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
  56. /* USB OTG reset */
  57. IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
  58. /* USB OTG */
  59. MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
  60. MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
  61. MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
  62. MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
  63. MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
  64. MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
  65. MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
  66. MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
  67. MX31_PIN_USBOTG_CLK__USBOTG_CLK,
  68. MX31_PIN_USBOTG_DIR__USBOTG_DIR,
  69. MX31_PIN_USBOTG_NXT__USBOTG_NXT,
  70. MX31_PIN_USBOTG_STP__USBOTG_STP,
  71. /*Keyboard*/
  72. MX31_PIN_KEY_ROW0_KEY_ROW0,
  73. MX31_PIN_KEY_ROW1_KEY_ROW1,
  74. MX31_PIN_KEY_ROW2_KEY_ROW2,
  75. MX31_PIN_KEY_COL0_KEY_COL0,
  76. MX31_PIN_KEY_COL1_KEY_COL1,
  77. MX31_PIN_KEY_COL2_KEY_COL2,
  78. MX31_PIN_KEY_COL3_KEY_COL3,
  79. /* USB Host 2 */
  80. IOMUX_MODE(MX31_PIN_USBH2_CLK, IOMUX_CONFIG_FUNC),
  81. IOMUX_MODE(MX31_PIN_USBH2_DIR, IOMUX_CONFIG_FUNC),
  82. IOMUX_MODE(MX31_PIN_USBH2_NXT, IOMUX_CONFIG_FUNC),
  83. IOMUX_MODE(MX31_PIN_USBH2_STP, IOMUX_CONFIG_FUNC),
  84. IOMUX_MODE(MX31_PIN_USBH2_DATA0, IOMUX_CONFIG_FUNC),
  85. IOMUX_MODE(MX31_PIN_USBH2_DATA1, IOMUX_CONFIG_FUNC),
  86. IOMUX_MODE(MX31_PIN_PC_VS2, IOMUX_CONFIG_ALT1),
  87. IOMUX_MODE(MX31_PIN_PC_BVD1, IOMUX_CONFIG_ALT1),
  88. IOMUX_MODE(MX31_PIN_PC_BVD2, IOMUX_CONFIG_ALT1),
  89. IOMUX_MODE(MX31_PIN_PC_RST, IOMUX_CONFIG_ALT1),
  90. IOMUX_MODE(MX31_PIN_IOIS16, IOMUX_CONFIG_ALT1),
  91. IOMUX_MODE(MX31_PIN_PC_RW_B, IOMUX_CONFIG_ALT1),
  92. /* USB Host2 reset */
  93. IOMUX_MODE(MX31_PIN_USB_BYP, IOMUX_CONFIG_GPIO),
  94. /* I2C1 */
  95. MX31_PIN_I2C_CLK__I2C1_SCL,
  96. MX31_PIN_I2C_DAT__I2C1_SDA,
  97. };
  98. /*
  99. * Matrix keyboard
  100. */
  101. static const uint32_t mx31_3ds_keymap[] = {
  102. KEY(0, 0, KEY_UP),
  103. KEY(0, 1, KEY_DOWN),
  104. KEY(1, 0, KEY_RIGHT),
  105. KEY(1, 1, KEY_LEFT),
  106. KEY(1, 2, KEY_ENTER),
  107. KEY(2, 0, KEY_F6),
  108. KEY(2, 1, KEY_F8),
  109. KEY(2, 2, KEY_F9),
  110. KEY(2, 3, KEY_F10),
  111. };
  112. static const struct matrix_keymap_data mx31_3ds_keymap_data __initconst = {
  113. .keymap = mx31_3ds_keymap,
  114. .keymap_size = ARRAY_SIZE(mx31_3ds_keymap),
  115. };
  116. /* Regulators */
  117. static struct regulator_init_data pwgtx_init = {
  118. .constraints = {
  119. .boot_on = 1,
  120. .always_on = 1,
  121. },
  122. };
  123. static struct regulator_init_data gpo_init = {
  124. .constraints = {
  125. .boot_on = 1,
  126. .always_on = 1,
  127. }
  128. };
  129. static struct mc13xxx_regulator_init_data mx31_3ds_regulators[] = {
  130. {
  131. .id = MC13783_REG_PWGT1SPI, /* Power Gate for ARM core. */
  132. .init_data = &pwgtx_init,
  133. }, {
  134. .id = MC13783_REG_PWGT2SPI, /* Power Gate for L2 Cache. */
  135. .init_data = &pwgtx_init,
  136. }, {
  137. .id = MC13783_REG_GPO1, /* Turn on 1.8V */
  138. .init_data = &gpo_init,
  139. }, {
  140. .id = MC13783_REG_GPO3, /* Turn on 3.3V */
  141. .init_data = &gpo_init,
  142. },
  143. };
  144. /* MC13783 */
  145. static struct mc13xxx_platform_data mc13783_pdata __initdata = {
  146. .regulators = mx31_3ds_regulators,
  147. .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
  148. .flags = MC13XXX_USE_REGULATOR | MC13XXX_USE_TOUCHSCREEN
  149. };
  150. /* SPI */
  151. static int spi1_internal_chipselect[] = {
  152. MXC_SPI_CS(0),
  153. MXC_SPI_CS(2),
  154. };
  155. static const struct spi_imx_master spi1_pdata __initconst = {
  156. .chipselect = spi1_internal_chipselect,
  157. .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
  158. };
  159. static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
  160. {
  161. .modalias = "mc13783",
  162. .max_speed_hz = 1000000,
  163. .bus_num = 1,
  164. .chip_select = 1, /* SS2 */
  165. .platform_data = &mc13783_pdata,
  166. .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
  167. .mode = SPI_CS_HIGH,
  168. },
  169. };
  170. /*
  171. * NAND Flash
  172. */
  173. static const struct mxc_nand_platform_data
  174. mx31_3ds_nand_board_info __initconst = {
  175. .width = 1,
  176. .hw_ecc = 1,
  177. #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
  178. .flash_bbt = 1,
  179. #endif
  180. };
  181. /*
  182. * USB OTG
  183. */
  184. #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
  185. PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
  186. #define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
  187. #define USBH2_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_BYP)
  188. static int mx31_3ds_usbotg_init(void)
  189. {
  190. int err;
  191. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
  192. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
  193. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
  194. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
  195. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
  196. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
  197. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
  198. mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
  199. mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
  200. mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
  201. mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
  202. mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
  203. err = gpio_request(USBOTG_RST_B, "otgusb-reset");
  204. if (err) {
  205. pr_err("Failed to request the USB OTG reset gpio\n");
  206. return err;
  207. }
  208. err = gpio_direction_output(USBOTG_RST_B, 0);
  209. if (err) {
  210. pr_err("Failed to drive the USB OTG reset gpio\n");
  211. goto usbotg_free_reset;
  212. }
  213. mdelay(1);
  214. gpio_set_value(USBOTG_RST_B, 1);
  215. return 0;
  216. usbotg_free_reset:
  217. gpio_free(USBOTG_RST_B);
  218. return err;
  219. }
  220. static int mx31_3ds_otg_init(struct platform_device *pdev)
  221. {
  222. return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
  223. }
  224. static int mx31_3ds_host2_init(struct platform_device *pdev)
  225. {
  226. int err;
  227. mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, USB_PAD_CFG);
  228. mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, USB_PAD_CFG);
  229. mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, USB_PAD_CFG);
  230. mxc_iomux_set_pad(MX31_PIN_USBH2_STP, USB_PAD_CFG);
  231. mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, USB_PAD_CFG);
  232. mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, USB_PAD_CFG);
  233. mxc_iomux_set_pad(MX31_PIN_PC_VS2, USB_PAD_CFG);
  234. mxc_iomux_set_pad(MX31_PIN_PC_BVD1, USB_PAD_CFG);
  235. mxc_iomux_set_pad(MX31_PIN_PC_BVD2, USB_PAD_CFG);
  236. mxc_iomux_set_pad(MX31_PIN_PC_RST, USB_PAD_CFG);
  237. mxc_iomux_set_pad(MX31_PIN_IOIS16, USB_PAD_CFG);
  238. mxc_iomux_set_pad(MX31_PIN_PC_RW_B, USB_PAD_CFG);
  239. err = gpio_request(USBH2_RST_B, "usbh2-reset");
  240. if (err) {
  241. pr_err("Failed to request the USB Host 2 reset gpio\n");
  242. return err;
  243. }
  244. err = gpio_direction_output(USBH2_RST_B, 0);
  245. if (err) {
  246. pr_err("Failed to drive the USB Host 2 reset gpio\n");
  247. goto usbotg_free_reset;
  248. }
  249. mdelay(1);
  250. gpio_set_value(USBH2_RST_B, 1);
  251. mdelay(10);
  252. return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
  253. usbotg_free_reset:
  254. gpio_free(USBH2_RST_B);
  255. return err;
  256. }
  257. static struct mxc_usbh_platform_data otg_pdata __initdata = {
  258. .init = mx31_3ds_otg_init,
  259. .portsc = MXC_EHCI_MODE_ULPI,
  260. };
  261. static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
  262. .init = mx31_3ds_host2_init,
  263. .portsc = MXC_EHCI_MODE_ULPI,
  264. };
  265. static const struct fsl_usb2_platform_data usbotg_pdata __initconst = {
  266. .operating_mode = FSL_USB2_DR_DEVICE,
  267. .phy_mode = FSL_USB2_PHY_ULPI,
  268. };
  269. static int otg_mode_host;
  270. static int __init mx31_3ds_otg_mode(char *options)
  271. {
  272. if (!strcmp(options, "host"))
  273. otg_mode_host = 1;
  274. else if (!strcmp(options, "device"))
  275. otg_mode_host = 0;
  276. else
  277. pr_info("otg_mode neither \"host\" nor \"device\". "
  278. "Defaulting to device\n");
  279. return 0;
  280. }
  281. __setup("otg_mode=", mx31_3ds_otg_mode);
  282. static const struct imxuart_platform_data uart_pdata __initconst = {
  283. .flags = IMXUART_HAVE_RTSCTS,
  284. };
  285. static const struct imxi2c_platform_data mx31_3ds_i2c0_data __initconst = {
  286. .bitrate = 100000,
  287. };
  288. static void __init mx31_3ds_init(void)
  289. {
  290. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  291. "mx31_3ds");
  292. imx31_add_imx_uart0(&uart_pdata);
  293. imx31_add_mxc_nand(&mx31_3ds_nand_board_info);
  294. imx31_add_spi_imx1(&spi1_pdata);
  295. spi_register_board_info(mx31_3ds_spi_devs,
  296. ARRAY_SIZE(mx31_3ds_spi_devs));
  297. imx31_add_imx_keypad(&mx31_3ds_keymap_data);
  298. mx31_3ds_usbotg_init();
  299. if (otg_mode_host) {
  300. otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
  301. ULPI_OTG_DRVVBUS_EXT);
  302. if (otg_pdata.otg)
  303. imx31_add_mxc_ehci_otg(&otg_pdata);
  304. }
  305. usbh2_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
  306. ULPI_OTG_DRVVBUS_EXT);
  307. if (usbh2_pdata.otg)
  308. imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
  309. if (!otg_mode_host)
  310. imx31_add_fsl_usb2_udc(&usbotg_pdata);
  311. if (mxc_expio_init(MX31_CS5_BASE_ADDR, EXPIO_PARENT_INT))
  312. printk(KERN_WARNING "Init of the debug board failed, all "
  313. "devices on the debug board are unusable.\n");
  314. imx31_add_imx2_wdt(NULL);
  315. imx31_add_imx_i2c0(&mx31_3ds_i2c0_data);
  316. }
  317. static void __init mx31_3ds_timer_init(void)
  318. {
  319. mx31_clocks_init(26000000);
  320. }
  321. static struct sys_timer mx31_3ds_timer = {
  322. .init = mx31_3ds_timer_init,
  323. };
  324. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  325. /* Maintainer: Freescale Semiconductor, Inc. */
  326. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  327. .map_io = mx31_map_io,
  328. .init_early = imx31_init_early,
  329. .init_irq = mx31_init_irq,
  330. .timer = &mx31_3ds_timer,
  331. .init_machine = mx31_3ds_init,
  332. MACHINE_END