mach-mx27_3ds.c 13 KB

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