mach-mx31_3ds.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. /*
  41. * This file contains the board-specific initialization routines.
  42. */
  43. static int mx31_3ds_pins[] = {
  44. /* UART1 */
  45. MX31_PIN_CTS1__CTS1,
  46. MX31_PIN_RTS1__RTS1,
  47. MX31_PIN_TXD1__TXD1,
  48. MX31_PIN_RXD1__RXD1,
  49. IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
  50. /* SPI 1 */
  51. MX31_PIN_CSPI2_SCLK__SCLK,
  52. MX31_PIN_CSPI2_MOSI__MOSI,
  53. MX31_PIN_CSPI2_MISO__MISO,
  54. MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
  55. MX31_PIN_CSPI2_SS0__SS0,
  56. MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
  57. /* MC13783 IRQ */
  58. IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
  59. /* USB OTG reset */
  60. IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
  61. /* USB OTG */
  62. MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
  63. MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
  64. MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
  65. MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
  66. MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
  67. MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
  68. MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
  69. MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
  70. MX31_PIN_USBOTG_CLK__USBOTG_CLK,
  71. MX31_PIN_USBOTG_DIR__USBOTG_DIR,
  72. MX31_PIN_USBOTG_NXT__USBOTG_NXT,
  73. MX31_PIN_USBOTG_STP__USBOTG_STP,
  74. /*Keyboard*/
  75. MX31_PIN_KEY_ROW0_KEY_ROW0,
  76. MX31_PIN_KEY_ROW1_KEY_ROW1,
  77. MX31_PIN_KEY_ROW2_KEY_ROW2,
  78. MX31_PIN_KEY_COL0_KEY_COL0,
  79. MX31_PIN_KEY_COL1_KEY_COL1,
  80. MX31_PIN_KEY_COL2_KEY_COL2,
  81. MX31_PIN_KEY_COL3_KEY_COL3,
  82. /* USB Host 2 */
  83. IOMUX_MODE(MX31_PIN_USBH2_CLK, IOMUX_CONFIG_FUNC),
  84. IOMUX_MODE(MX31_PIN_USBH2_DIR, IOMUX_CONFIG_FUNC),
  85. IOMUX_MODE(MX31_PIN_USBH2_NXT, IOMUX_CONFIG_FUNC),
  86. IOMUX_MODE(MX31_PIN_USBH2_STP, IOMUX_CONFIG_FUNC),
  87. IOMUX_MODE(MX31_PIN_USBH2_DATA0, IOMUX_CONFIG_FUNC),
  88. IOMUX_MODE(MX31_PIN_USBH2_DATA1, IOMUX_CONFIG_FUNC),
  89. IOMUX_MODE(MX31_PIN_PC_VS2, IOMUX_CONFIG_ALT1),
  90. IOMUX_MODE(MX31_PIN_PC_BVD1, IOMUX_CONFIG_ALT1),
  91. IOMUX_MODE(MX31_PIN_PC_BVD2, IOMUX_CONFIG_ALT1),
  92. IOMUX_MODE(MX31_PIN_PC_RST, IOMUX_CONFIG_ALT1),
  93. IOMUX_MODE(MX31_PIN_IOIS16, IOMUX_CONFIG_ALT1),
  94. IOMUX_MODE(MX31_PIN_PC_RW_B, IOMUX_CONFIG_ALT1),
  95. /* USB Host2 reset */
  96. IOMUX_MODE(MX31_PIN_USB_BYP, IOMUX_CONFIG_GPIO),
  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 mc13783_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 mc13783_platform_data mc13783_pdata __initdata = {
  146. .regulators = mx31_3ds_regulators,
  147. .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
  148. .flags = MC13783_USE_REGULATOR | MC13783_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_host2_init(struct platform_device *pdev)
  221. {
  222. int err;
  223. mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, USB_PAD_CFG);
  224. mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, USB_PAD_CFG);
  225. mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, USB_PAD_CFG);
  226. mxc_iomux_set_pad(MX31_PIN_USBH2_STP, USB_PAD_CFG);
  227. mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, USB_PAD_CFG);
  228. mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, USB_PAD_CFG);
  229. mxc_iomux_set_pad(MX31_PIN_PC_VS2, USB_PAD_CFG);
  230. mxc_iomux_set_pad(MX31_PIN_PC_BVD1, USB_PAD_CFG);
  231. mxc_iomux_set_pad(MX31_PIN_PC_BVD2, USB_PAD_CFG);
  232. mxc_iomux_set_pad(MX31_PIN_PC_RST, USB_PAD_CFG);
  233. mxc_iomux_set_pad(MX31_PIN_IOIS16, USB_PAD_CFG);
  234. mxc_iomux_set_pad(MX31_PIN_PC_RW_B, USB_PAD_CFG);
  235. err = gpio_request(USBH2_RST_B, "usbh2-reset");
  236. if (err) {
  237. pr_err("Failed to request the USB Host 2 reset gpio\n");
  238. return err;
  239. }
  240. err = gpio_direction_output(USBH2_RST_B, 0);
  241. if (err) {
  242. pr_err("Failed to drive the USB Host 2 reset gpio\n");
  243. goto usbotg_free_reset;
  244. }
  245. mdelay(1);
  246. gpio_set_value(USBH2_RST_B, 1);
  247. return 0;
  248. usbotg_free_reset:
  249. gpio_free(USBH2_RST_B);
  250. return err;
  251. }
  252. #if defined(CONFIG_USB_ULPI)
  253. static struct mxc_usbh_platform_data otg_pdata __initdata = {
  254. .portsc = MXC_EHCI_MODE_ULPI,
  255. .flags = MXC_EHCI_POWER_PINS_ENABLED,
  256. };
  257. static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
  258. .init = mx31_3ds_host2_init,
  259. .portsc = MXC_EHCI_MODE_ULPI,
  260. .flags = MXC_EHCI_POWER_PINS_ENABLED,
  261. };
  262. #endif
  263. static const struct fsl_usb2_platform_data usbotg_pdata __initconst = {
  264. .operating_mode = FSL_USB2_DR_DEVICE,
  265. .phy_mode = FSL_USB2_PHY_ULPI,
  266. };
  267. static int otg_mode_host;
  268. static int __init mx31_3ds_otg_mode(char *options)
  269. {
  270. if (!strcmp(options, "host"))
  271. otg_mode_host = 1;
  272. else if (!strcmp(options, "device"))
  273. otg_mode_host = 0;
  274. else
  275. pr_info("otg_mode neither \"host\" nor \"device\". "
  276. "Defaulting to device\n");
  277. return 0;
  278. }
  279. __setup("otg_mode=", mx31_3ds_otg_mode);
  280. static const struct imxuart_platform_data uart_pdata __initconst = {
  281. .flags = IMXUART_HAVE_RTSCTS,
  282. };
  283. /*
  284. * Set up static virtual mappings.
  285. */
  286. static void __init mx31_3ds_map_io(void)
  287. {
  288. mx31_map_io();
  289. }
  290. /*!
  291. * Board specific initialization.
  292. */
  293. static void __init mxc_board_init(void)
  294. {
  295. mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
  296. "mx31_3ds");
  297. imx31_add_imx_uart0(&uart_pdata);
  298. imx31_add_mxc_nand(&mx31_3ds_nand_board_info);
  299. imx31_add_spi_imx1(&spi1_pdata);
  300. spi_register_board_info(mx31_3ds_spi_devs,
  301. ARRAY_SIZE(mx31_3ds_spi_devs));
  302. imx31_add_imx_keypad(&mx31_3ds_keymap_data);
  303. mx31_3ds_usbotg_init();
  304. #if defined(CONFIG_USB_ULPI)
  305. if (otg_mode_host) {
  306. otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
  307. ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
  308. imx31_add_mxc_ehci_otg(&otg_pdata);
  309. }
  310. usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
  311. ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
  312. imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
  313. #endif
  314. if (!otg_mode_host)
  315. imx31_add_fsl_usb2_udc(&usbotg_pdata);
  316. if (mxc_expio_init(MX31_CS5_BASE_ADDR, EXPIO_PARENT_INT))
  317. printk(KERN_WARNING "Init of the debug board failed, all "
  318. "devices on the debug board are unusable.\n");
  319. imx31_add_imx2_wdt(NULL);
  320. }
  321. static void __init mx31_3ds_timer_init(void)
  322. {
  323. mx31_clocks_init(26000000);
  324. }
  325. static struct sys_timer mx31_3ds_timer = {
  326. .init = mx31_3ds_timer_init,
  327. };
  328. /*
  329. * The following uses standard kernel macros defined in arch.h in order to
  330. * initialize __mach_desc_MX31_3DS data structure.
  331. */
  332. MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
  333. /* Maintainer: Freescale Semiconductor, Inc. */
  334. .boot_params = MX3x_PHYS_OFFSET + 0x100,
  335. .map_io = mx31_3ds_map_io,
  336. .init_irq = mx31_init_irq,
  337. .init_machine = mxc_board_init,
  338. .timer = &mx31_3ds_timer,
  339. MACHINE_END