mach-mx27_3ds.c 10 KB

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