mach-mx27_3ds.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * Author: Fabio Estevam <fabio.estevam@freescale.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  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. /*
  17. * This machine is known as:
  18. * - i.MX27 3-Stack Development System
  19. * - i.MX27 Platform Development Kit (i.MX27 PDK)
  20. */
  21. #include <linux/platform_device.h>
  22. #include <linux/gpio.h>
  23. #include <linux/irq.h>
  24. #include <linux/usb/otg.h>
  25. #include <linux/usb/ulpi.h>
  26. #include <linux/delay.h>
  27. #include <linux/mfd/mc13783.h>
  28. #include <linux/spi/spi.h>
  29. #include <linux/regulator/machine.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/time.h>
  33. #include <mach/hardware.h>
  34. #include <mach/common.h>
  35. #include <mach/iomux-mx27.h>
  36. #include <mach/ulpi.h>
  37. #include <mach/irqs.h>
  38. #include <mach/3ds_debugboard.h>
  39. #include "devices-imx27.h"
  40. #define SD1_EN_GPIO (GPIO_PORTB + 25)
  41. #define OTG_PHY_RESET_GPIO (GPIO_PORTB + 23)
  42. #define SPI2_SS0 (GPIO_PORTD + 21)
  43. #define EXPIO_PARENT_INT (MXC_INTERNAL_IRQS + GPIO_PORTC + 28)
  44. static const int mx27pdk_pins[] __initconst = {
  45. /* UART1 */
  46. PE12_PF_UART1_TXD,
  47. PE13_PF_UART1_RXD,
  48. PE14_PF_UART1_CTS,
  49. PE15_PF_UART1_RTS,
  50. /* FEC */
  51. PD0_AIN_FEC_TXD0,
  52. PD1_AIN_FEC_TXD1,
  53. PD2_AIN_FEC_TXD2,
  54. PD3_AIN_FEC_TXD3,
  55. PD4_AOUT_FEC_RX_ER,
  56. PD5_AOUT_FEC_RXD1,
  57. PD6_AOUT_FEC_RXD2,
  58. PD7_AOUT_FEC_RXD3,
  59. PD8_AF_FEC_MDIO,
  60. PD9_AIN_FEC_MDC,
  61. PD10_AOUT_FEC_CRS,
  62. PD11_AOUT_FEC_TX_CLK,
  63. PD12_AOUT_FEC_RXD0,
  64. PD13_AOUT_FEC_RX_DV,
  65. PD14_AOUT_FEC_RX_CLK,
  66. PD15_AOUT_FEC_COL,
  67. PD16_AIN_FEC_TX_ER,
  68. PF23_AIN_FEC_TX_EN,
  69. /* SDHC1 */
  70. PE18_PF_SD1_D0,
  71. PE19_PF_SD1_D1,
  72. PE20_PF_SD1_D2,
  73. PE21_PF_SD1_D3,
  74. PE22_PF_SD1_CMD,
  75. PE23_PF_SD1_CLK,
  76. SD1_EN_GPIO | GPIO_GPIO | GPIO_OUT,
  77. /* OTG */
  78. OTG_PHY_RESET_GPIO | GPIO_GPIO | GPIO_OUT,
  79. PC7_PF_USBOTG_DATA5,
  80. PC8_PF_USBOTG_DATA6,
  81. PC9_PF_USBOTG_DATA0,
  82. PC10_PF_USBOTG_DATA2,
  83. PC11_PF_USBOTG_DATA1,
  84. PC12_PF_USBOTG_DATA4,
  85. PC13_PF_USBOTG_DATA3,
  86. PE0_PF_USBOTG_NXT,
  87. PE1_PF_USBOTG_STP,
  88. PE2_PF_USBOTG_DIR,
  89. PE24_PF_USBOTG_CLK,
  90. PE25_PF_USBOTG_DATA7,
  91. /* CSPI2 */
  92. PD22_PF_CSPI2_SCLK,
  93. PD23_PF_CSPI2_MISO,
  94. PD24_PF_CSPI2_MOSI,
  95. };
  96. static const struct imxuart_platform_data uart_pdata __initconst = {
  97. .flags = IMXUART_HAVE_RTSCTS,
  98. };
  99. /*
  100. * Matrix keyboard
  101. */
  102. static const uint32_t mx27_3ds_keymap[] = {
  103. KEY(0, 0, KEY_UP),
  104. KEY(0, 1, KEY_DOWN),
  105. KEY(1, 0, KEY_RIGHT),
  106. KEY(1, 1, KEY_LEFT),
  107. KEY(1, 2, KEY_ENTER),
  108. KEY(2, 0, KEY_F6),
  109. KEY(2, 1, KEY_F8),
  110. KEY(2, 2, KEY_F9),
  111. KEY(2, 3, KEY_F10),
  112. };
  113. static const struct matrix_keymap_data mx27_3ds_keymap_data __initconst = {
  114. .keymap = mx27_3ds_keymap,
  115. .keymap_size = ARRAY_SIZE(mx27_3ds_keymap),
  116. };
  117. static int mx27_3ds_sdhc1_init(struct device *dev, irq_handler_t detect_irq,
  118. void *data)
  119. {
  120. return request_irq(IRQ_GPIOB(26), detect_irq, IRQF_TRIGGER_FALLING |
  121. IRQF_TRIGGER_RISING, "sdhc1-card-detect", data);
  122. }
  123. static void mx27_3ds_sdhc1_exit(struct device *dev, void *data)
  124. {
  125. free_irq(IRQ_GPIOB(26), data);
  126. }
  127. static const struct imxmmc_platform_data sdhc1_pdata __initconst = {
  128. .init = mx27_3ds_sdhc1_init,
  129. .exit = mx27_3ds_sdhc1_exit,
  130. };
  131. static void mx27_3ds_sdhc1_enable_level_translator(void)
  132. {
  133. /* Turn on TXB0108 OE pin */
  134. gpio_request(SD1_EN_GPIO, "sd1_enable");
  135. gpio_direction_output(SD1_EN_GPIO, 1);
  136. }
  137. static int otg_phy_init(void)
  138. {
  139. gpio_request(OTG_PHY_RESET_GPIO, "usb-otg-reset");
  140. gpio_direction_output(OTG_PHY_RESET_GPIO, 0);
  141. mdelay(1);
  142. gpio_set_value(OTG_PHY_RESET_GPIO, 1);
  143. return 0;
  144. }
  145. #if defined(CONFIG_USB_ULPI)
  146. static struct mxc_usbh_platform_data otg_pdata __initdata = {
  147. .portsc = MXC_EHCI_MODE_ULPI,
  148. .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
  149. };
  150. #endif
  151. static const struct fsl_usb2_platform_data otg_device_pdata __initconst = {
  152. .operating_mode = FSL_USB2_DR_DEVICE,
  153. .phy_mode = FSL_USB2_PHY_ULPI,
  154. };
  155. static int otg_mode_host;
  156. static int __init mx27_3ds_otg_mode(char *options)
  157. {
  158. if (!strcmp(options, "host"))
  159. otg_mode_host = 1;
  160. else if (!strcmp(options, "device"))
  161. otg_mode_host = 0;
  162. else
  163. pr_info("otg_mode neither \"host\" nor \"device\". "
  164. "Defaulting to device\n");
  165. return 0;
  166. }
  167. __setup("otg_mode=", mx27_3ds_otg_mode);
  168. /* Regulators */
  169. static struct regulator_consumer_supply vmmc1_consumers[] = {
  170. REGULATOR_SUPPLY("lcd_2v8", NULL),
  171. };
  172. static struct regulator_init_data vmmc1_init = {
  173. .constraints = {
  174. .min_uV = 2800000,
  175. .max_uV = 2800000,
  176. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  177. },
  178. .num_consumer_supplies = ARRAY_SIZE(vmmc1_consumers),
  179. .consumer_supplies = vmmc1_consumers,
  180. };
  181. static struct regulator_consumer_supply vgen_consumers[] = {
  182. REGULATOR_SUPPLY("vdd_lcdio", NULL),
  183. };
  184. static struct regulator_init_data vgen_init = {
  185. .constraints = {
  186. .min_uV = 1800000,
  187. .max_uV = 1800000,
  188. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  189. },
  190. .num_consumer_supplies = ARRAY_SIZE(vgen_consumers),
  191. .consumer_supplies = vgen_consumers,
  192. };
  193. static struct mc13783_regulator_init_data mx27_3ds_regulators[] = {
  194. {
  195. .id = MC13783_REG_VMMC1,
  196. .init_data = &vmmc1_init,
  197. }, {
  198. .id = MC13783_REG_VGEN,
  199. .init_data = &vgen_init,
  200. },
  201. };
  202. /* MC13783 */
  203. static struct mc13783_platform_data mc13783_pdata __initdata = {
  204. .regulators = mx27_3ds_regulators,
  205. .num_regulators = ARRAY_SIZE(mx27_3ds_regulators),
  206. .flags = MC13783_USE_REGULATOR,
  207. };
  208. /* SPI */
  209. static int spi2_internal_chipselect[] = {SPI2_SS0};
  210. static const struct spi_imx_master spi2_pdata __initconst = {
  211. .chipselect = spi2_internal_chipselect,
  212. .num_chipselect = ARRAY_SIZE(spi2_internal_chipselect),
  213. };
  214. static struct spi_board_info mx27_3ds_spi_devs[] __initdata = {
  215. {
  216. .modalias = "mc13783",
  217. .max_speed_hz = 1000000,
  218. .bus_num = 1,
  219. .chip_select = 0, /* SS0 */
  220. .platform_data = &mc13783_pdata,
  221. .irq = IRQ_GPIOC(14),
  222. .mode = SPI_CS_HIGH,
  223. },
  224. };
  225. static void __init mx27pdk_init(void)
  226. {
  227. mxc_gpio_setup_multiple_pins(mx27pdk_pins, ARRAY_SIZE(mx27pdk_pins),
  228. "mx27pdk");
  229. mx27_3ds_sdhc1_enable_level_translator();
  230. imx27_add_imx_uart0(&uart_pdata);
  231. imx27_add_fec(NULL);
  232. imx27_add_imx_keypad(&mx27_3ds_keymap_data);
  233. imx27_add_mxc_mmc(0, &sdhc1_pdata);
  234. imx27_add_imx2_wdt(NULL);
  235. otg_phy_init();
  236. #if defined(CONFIG_USB_ULPI)
  237. if (otg_mode_host) {
  238. otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
  239. ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
  240. imx27_add_mxc_ehci_otg(&otg_pdata);
  241. }
  242. #endif
  243. if (!otg_mode_host)
  244. imx27_add_fsl_usb2_udc(&otg_device_pdata);
  245. imx27_add_spi_imx1(&spi2_pdata);
  246. spi_register_board_info(mx27_3ds_spi_devs,
  247. ARRAY_SIZE(mx27_3ds_spi_devs));
  248. if (mxc_expio_init(MX27_CS5_BASE_ADDR, EXPIO_PARENT_INT))
  249. pr_warn("Init of the debugboard failed, all devices on the debugboard are unusable.\n");
  250. }
  251. static void __init mx27pdk_timer_init(void)
  252. {
  253. mx27_clocks_init(26000000);
  254. }
  255. static struct sys_timer mx27pdk_timer = {
  256. .init = mx27pdk_timer_init,
  257. };
  258. MACHINE_START(MX27_3DS, "Freescale MX27PDK")
  259. /* maintainer: Freescale Semiconductor, Inc. */
  260. .boot_params = MX27_PHYS_OFFSET + 0x100,
  261. .map_io = mx27_map_io,
  262. .init_irq = mx27_init_irq,
  263. .init_machine = mx27pdk_init,
  264. .timer = &mx27pdk_timer,
  265. MACHINE_END