mach-mx27_3ds.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 <linux/spi/l4f00242t03.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/time.h>
  34. #include <mach/hardware.h>
  35. #include <mach/common.h>
  36. #include <mach/iomux-mx27.h>
  37. #include <mach/ulpi.h>
  38. #include <mach/irqs.h>
  39. #include <mach/3ds_debugboard.h>
  40. #include "devices-imx27.h"
  41. #define SD1_EN_GPIO IMX_GPIO_NR(2, 25)
  42. #define OTG_PHY_RESET_GPIO IMX_GPIO_NR(2, 23)
  43. #define SPI2_SS0 IMX_GPIO_NR(4, 21)
  44. #define EXPIO_PARENT_INT gpio_to_irq(IMX_GPIO_NR(3, 28))
  45. #define PMIC_INT IMX_GPIO_NR(3, 14)
  46. #define SPI1_SS0 IMX_GPIO_NR(4, 28)
  47. #define SD1_CD IMX_GPIO_NR(2, 26)
  48. #define LCD_RESET IMX_GPIO_NR(1, 3)
  49. #define LCD_ENABLE IMX_GPIO_NR(1, 31)
  50. static const int mx27pdk_pins[] __initconst = {
  51. /* UART1 */
  52. PE12_PF_UART1_TXD,
  53. PE13_PF_UART1_RXD,
  54. PE14_PF_UART1_CTS,
  55. PE15_PF_UART1_RTS,
  56. /* FEC */
  57. PD0_AIN_FEC_TXD0,
  58. PD1_AIN_FEC_TXD1,
  59. PD2_AIN_FEC_TXD2,
  60. PD3_AIN_FEC_TXD3,
  61. PD4_AOUT_FEC_RX_ER,
  62. PD5_AOUT_FEC_RXD1,
  63. PD6_AOUT_FEC_RXD2,
  64. PD7_AOUT_FEC_RXD3,
  65. PD8_AF_FEC_MDIO,
  66. PD9_AIN_FEC_MDC,
  67. PD10_AOUT_FEC_CRS,
  68. PD11_AOUT_FEC_TX_CLK,
  69. PD12_AOUT_FEC_RXD0,
  70. PD13_AOUT_FEC_RX_DV,
  71. PD14_AOUT_FEC_RX_CLK,
  72. PD15_AOUT_FEC_COL,
  73. PD16_AIN_FEC_TX_ER,
  74. PF23_AIN_FEC_TX_EN,
  75. /* SDHC1 */
  76. PE18_PF_SD1_D0,
  77. PE19_PF_SD1_D1,
  78. PE20_PF_SD1_D2,
  79. PE21_PF_SD1_D3,
  80. PE22_PF_SD1_CMD,
  81. PE23_PF_SD1_CLK,
  82. SD1_EN_GPIO | GPIO_GPIO | GPIO_OUT,
  83. /* OTG */
  84. OTG_PHY_RESET_GPIO | GPIO_GPIO | GPIO_OUT,
  85. PC7_PF_USBOTG_DATA5,
  86. PC8_PF_USBOTG_DATA6,
  87. PC9_PF_USBOTG_DATA0,
  88. PC10_PF_USBOTG_DATA2,
  89. PC11_PF_USBOTG_DATA1,
  90. PC12_PF_USBOTG_DATA4,
  91. PC13_PF_USBOTG_DATA3,
  92. PE0_PF_USBOTG_NXT,
  93. PE1_PF_USBOTG_STP,
  94. PE2_PF_USBOTG_DIR,
  95. PE24_PF_USBOTG_CLK,
  96. PE25_PF_USBOTG_DATA7,
  97. /* CSPI1 */
  98. PD31_PF_CSPI1_MOSI,
  99. PD30_PF_CSPI1_MISO,
  100. PD29_PF_CSPI1_SCLK,
  101. PD25_PF_CSPI1_RDY,
  102. SPI1_SS0 | GPIO_GPIO | GPIO_OUT,
  103. /* CSPI2 */
  104. PD22_PF_CSPI2_SCLK,
  105. PD23_PF_CSPI2_MISO,
  106. PD24_PF_CSPI2_MOSI,
  107. SPI2_SS0 | GPIO_GPIO | GPIO_OUT,
  108. /* I2C1 */
  109. PD17_PF_I2C_DATA,
  110. PD18_PF_I2C_CLK,
  111. /* PMIC INT */
  112. PMIC_INT | GPIO_GPIO | GPIO_IN,
  113. /* LCD */
  114. PA5_PF_LSCLK,
  115. PA6_PF_LD0,
  116. PA7_PF_LD1,
  117. PA8_PF_LD2,
  118. PA9_PF_LD3,
  119. PA10_PF_LD4,
  120. PA11_PF_LD5,
  121. PA12_PF_LD6,
  122. PA13_PF_LD7,
  123. PA14_PF_LD8,
  124. PA15_PF_LD9,
  125. PA16_PF_LD10,
  126. PA17_PF_LD11,
  127. PA18_PF_LD12,
  128. PA19_PF_LD13,
  129. PA20_PF_LD14,
  130. PA21_PF_LD15,
  131. PA22_PF_LD16,
  132. PA23_PF_LD17,
  133. PA28_PF_HSYNC,
  134. PA29_PF_VSYNC,
  135. PA30_PF_CONTRAST,
  136. LCD_ENABLE | GPIO_GPIO | GPIO_OUT,
  137. LCD_RESET | GPIO_GPIO | GPIO_OUT,
  138. };
  139. static const struct imxuart_platform_data uart_pdata __initconst = {
  140. .flags = IMXUART_HAVE_RTSCTS,
  141. };
  142. /*
  143. * Matrix keyboard
  144. */
  145. static const uint32_t mx27_3ds_keymap[] = {
  146. KEY(0, 0, KEY_UP),
  147. KEY(0, 1, KEY_DOWN),
  148. KEY(1, 0, KEY_RIGHT),
  149. KEY(1, 1, KEY_LEFT),
  150. KEY(1, 2, KEY_ENTER),
  151. KEY(2, 0, KEY_F6),
  152. KEY(2, 1, KEY_F8),
  153. KEY(2, 2, KEY_F9),
  154. KEY(2, 3, KEY_F10),
  155. };
  156. static const struct matrix_keymap_data mx27_3ds_keymap_data __initconst = {
  157. .keymap = mx27_3ds_keymap,
  158. .keymap_size = ARRAY_SIZE(mx27_3ds_keymap),
  159. };
  160. static int mx27_3ds_sdhc1_init(struct device *dev, irq_handler_t detect_irq,
  161. void *data)
  162. {
  163. return request_irq(gpio_to_irq(SD1_CD), detect_irq,
  164. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, "sdhc1-card-detect", data);
  165. }
  166. static void mx27_3ds_sdhc1_exit(struct device *dev, void *data)
  167. {
  168. free_irq(gpio_to_irq(SD1_CD), data);
  169. }
  170. static const struct imxmmc_platform_data sdhc1_pdata __initconst = {
  171. .init = mx27_3ds_sdhc1_init,
  172. .exit = mx27_3ds_sdhc1_exit,
  173. };
  174. static void mx27_3ds_sdhc1_enable_level_translator(void)
  175. {
  176. /* Turn on TXB0108 OE pin */
  177. gpio_request(SD1_EN_GPIO, "sd1_enable");
  178. gpio_direction_output(SD1_EN_GPIO, 1);
  179. }
  180. static int otg_phy_init(void)
  181. {
  182. gpio_request(OTG_PHY_RESET_GPIO, "usb-otg-reset");
  183. gpio_direction_output(OTG_PHY_RESET_GPIO, 0);
  184. mdelay(1);
  185. gpio_set_value(OTG_PHY_RESET_GPIO, 1);
  186. return 0;
  187. }
  188. static int mx27_3ds_otg_init(struct platform_device *pdev)
  189. {
  190. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
  191. }
  192. static struct mxc_usbh_platform_data otg_pdata __initdata = {
  193. .init = mx27_3ds_otg_init,
  194. .portsc = MXC_EHCI_MODE_ULPI,
  195. };
  196. static const struct fsl_usb2_platform_data otg_device_pdata __initconst = {
  197. .operating_mode = FSL_USB2_DR_DEVICE,
  198. .phy_mode = FSL_USB2_PHY_ULPI,
  199. };
  200. static int otg_mode_host;
  201. static int __init mx27_3ds_otg_mode(char *options)
  202. {
  203. if (!strcmp(options, "host"))
  204. otg_mode_host = 1;
  205. else if (!strcmp(options, "device"))
  206. otg_mode_host = 0;
  207. else
  208. pr_info("otg_mode neither \"host\" nor \"device\". "
  209. "Defaulting to device\n");
  210. return 0;
  211. }
  212. __setup("otg_mode=", mx27_3ds_otg_mode);
  213. /* Regulators */
  214. static struct regulator_init_data gpo_init = {
  215. .constraints = {
  216. .boot_on = 1,
  217. .always_on = 1,
  218. }
  219. };
  220. static struct regulator_consumer_supply vmmc1_consumers[] = {
  221. REGULATOR_SUPPLY("lcd_2v8", NULL),
  222. };
  223. static struct regulator_init_data vmmc1_init = {
  224. .constraints = {
  225. .min_uV = 2800000,
  226. .max_uV = 2800000,
  227. .apply_uV = 1,
  228. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  229. REGULATOR_CHANGE_STATUS,
  230. },
  231. .num_consumer_supplies = ARRAY_SIZE(vmmc1_consumers),
  232. .consumer_supplies = vmmc1_consumers,
  233. };
  234. static struct regulator_consumer_supply vgen_consumers[] = {
  235. REGULATOR_SUPPLY("vdd_lcdio", NULL),
  236. };
  237. static struct regulator_init_data vgen_init = {
  238. .constraints = {
  239. .min_uV = 1800000,
  240. .max_uV = 1800000,
  241. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
  242. },
  243. .num_consumer_supplies = ARRAY_SIZE(vgen_consumers),
  244. .consumer_supplies = vgen_consumers,
  245. };
  246. static struct mc13xxx_regulator_init_data mx27_3ds_regulators[] = {
  247. {
  248. .id = MC13783_REG_VMMC1,
  249. .init_data = &vmmc1_init,
  250. }, {
  251. .id = MC13783_REG_VGEN,
  252. .init_data = &vgen_init,
  253. }, {
  254. .id = MC13783_REG_GPO1, /* Turn on 1.8V */
  255. .init_data = &gpo_init,
  256. }, {
  257. .id = MC13783_REG_GPO3, /* Turn on 3.3V */
  258. .init_data = &gpo_init,
  259. },
  260. };
  261. /* MC13783 */
  262. static struct mc13xxx_platform_data mc13783_pdata = {
  263. .regulators = {
  264. .regulators = mx27_3ds_regulators,
  265. .num_regulators = ARRAY_SIZE(mx27_3ds_regulators),
  266. },
  267. .flags = MC13783_USE_REGULATOR | MC13783_USE_TOUCHSCREEN |
  268. MC13783_USE_RTC,
  269. };
  270. /* SPI */
  271. static int spi1_chipselect[] = {SPI1_SS0};
  272. static const struct spi_imx_master spi1_pdata __initconst = {
  273. .chipselect = spi1_chipselect,
  274. .num_chipselect = ARRAY_SIZE(spi1_chipselect),
  275. };
  276. static int spi2_chipselect[] = {SPI2_SS0};
  277. static const struct spi_imx_master spi2_pdata __initconst = {
  278. .chipselect = spi2_chipselect,
  279. .num_chipselect = ARRAY_SIZE(spi2_chipselect),
  280. };
  281. static struct imx_fb_videomode mx27_3ds_modes[] = {
  282. { /* 480x640 @ 60 Hz */
  283. .mode = {
  284. .name = "Epson-VGA",
  285. .refresh = 60,
  286. .xres = 480,
  287. .yres = 640,
  288. .pixclock = 41701,
  289. .left_margin = 20,
  290. .right_margin = 41,
  291. .upper_margin = 10,
  292. .lower_margin = 5,
  293. .hsync_len = 20,
  294. .vsync_len = 10,
  295. .sync = FB_SYNC_OE_ACT_HIGH |
  296. FB_SYNC_CLK_INVERT,
  297. .vmode = FB_VMODE_NONINTERLACED,
  298. .flag = 0,
  299. },
  300. .bpp = 16,
  301. .pcr = 0xFAC08B82,
  302. },
  303. };
  304. static const struct imx_fb_platform_data mx27_3ds_fb_data __initconst = {
  305. .mode = mx27_3ds_modes,
  306. .num_modes = ARRAY_SIZE(mx27_3ds_modes),
  307. .pwmr = 0x00A903FF,
  308. .lscr1 = 0x00120300,
  309. .dmacr = 0x00020010,
  310. };
  311. /* LCD */
  312. static struct l4f00242t03_pdata mx27_3ds_lcd_pdata = {
  313. .reset_gpio = LCD_RESET,
  314. .data_enable_gpio = LCD_ENABLE,
  315. .core_supply = "lcd_2v8",
  316. .io_supply = "vdd_lcdio",
  317. };
  318. static struct spi_board_info mx27_3ds_spi_devs[] __initdata = {
  319. {
  320. .modalias = "mc13783",
  321. .max_speed_hz = 1000000,
  322. .bus_num = 1,
  323. .chip_select = 0, /* SS0 */
  324. .platform_data = &mc13783_pdata,
  325. .irq = gpio_to_irq(PMIC_INT),
  326. .mode = SPI_CS_HIGH,
  327. }, {
  328. .modalias = "l4f00242t03",
  329. .max_speed_hz = 5000000,
  330. .bus_num = 0,
  331. .chip_select = 0, /* SS0 */
  332. .platform_data = &mx27_3ds_lcd_pdata,
  333. },
  334. };
  335. static const struct imxi2c_platform_data mx27_3ds_i2c0_data __initconst = {
  336. .bitrate = 100000,
  337. };
  338. static void __init mx27pdk_init(void)
  339. {
  340. imx27_soc_init();
  341. mxc_gpio_setup_multiple_pins(mx27pdk_pins, ARRAY_SIZE(mx27pdk_pins),
  342. "mx27pdk");
  343. mx27_3ds_sdhc1_enable_level_translator();
  344. imx27_add_imx_uart0(&uart_pdata);
  345. imx27_add_fec(NULL);
  346. imx27_add_imx_keypad(&mx27_3ds_keymap_data);
  347. imx27_add_mxc_mmc(0, &sdhc1_pdata);
  348. imx27_add_imx2_wdt(NULL);
  349. otg_phy_init();
  350. if (otg_mode_host) {
  351. otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
  352. ULPI_OTG_DRVVBUS_EXT);
  353. if (otg_pdata.otg)
  354. imx27_add_mxc_ehci_otg(&otg_pdata);
  355. }
  356. if (!otg_mode_host)
  357. imx27_add_fsl_usb2_udc(&otg_device_pdata);
  358. imx27_add_spi_imx1(&spi2_pdata);
  359. imx27_add_spi_imx0(&spi1_pdata);
  360. spi_register_board_info(mx27_3ds_spi_devs,
  361. ARRAY_SIZE(mx27_3ds_spi_devs));
  362. if (mxc_expio_init(MX27_CS5_BASE_ADDR, EXPIO_PARENT_INT))
  363. pr_warn("Init of the debugboard failed, all devices on the debugboard are unusable.\n");
  364. imx27_add_imx_i2c(0, &mx27_3ds_i2c0_data);
  365. imx27_add_imx_fb(&mx27_3ds_fb_data);
  366. }
  367. static void __init mx27pdk_timer_init(void)
  368. {
  369. mx27_clocks_init(26000000);
  370. }
  371. static struct sys_timer mx27pdk_timer = {
  372. .init = mx27pdk_timer_init,
  373. };
  374. MACHINE_START(MX27_3DS, "Freescale MX27PDK")
  375. /* maintainer: Freescale Semiconductor, Inc. */
  376. .boot_params = MX27_PHYS_OFFSET + 0x100,
  377. .map_io = mx27_map_io,
  378. .init_early = imx27_init_early,
  379. .init_irq = mx27_init_irq,
  380. .timer = &mx27pdk_timer,
  381. .init_machine = mx27pdk_init,
  382. MACHINE_END