mach-imx27_visstrim_m10.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /*
  2. * mach-imx27_visstrim_m10.c
  3. *
  4. * Copyright 2010 Javier Martin <javier.martin@vista-silicon.com>
  5. *
  6. * Based on mach-pcm038.c, mach-pca100.c, mach-mx27ads.c and others.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. * MA 02110-1301, USA.
  22. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/platform_device.h>
  25. #include <linux/mtd/physmap.h>
  26. #include <linux/i2c.h>
  27. #include <linux/i2c/pca953x.h>
  28. #include <linux/input.h>
  29. #include <linux/gpio.h>
  30. #include <linux/delay.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/leds.h>
  33. #include <media/soc_camera.h>
  34. #include <sound/tlv320aic32x4.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/time.h>
  38. #include <asm/memblock.h>
  39. #include <asm/system.h>
  40. #include <mach/common.h>
  41. #include <mach/iomux-mx27.h>
  42. #include "devices-imx27.h"
  43. #define TVP5150_RSTN (GPIO_PORTC + 18)
  44. #define TVP5150_PWDN (GPIO_PORTC + 19)
  45. #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
  46. #define SDHC1_IRQ IRQ_GPIOB(25)
  47. #define MOTHERBOARD_BIT2 (GPIO_PORTD + 31)
  48. #define MOTHERBOARD_BIT1 (GPIO_PORTD + 30)
  49. #define MOTHERBOARD_BIT0 (GPIO_PORTD + 29)
  50. #define EXPBOARD_BIT2 (GPIO_PORTD + 25)
  51. #define EXPBOARD_BIT1 (GPIO_PORTD + 27)
  52. #define EXPBOARD_BIT0 (GPIO_PORTD + 28)
  53. static const int visstrim_m10_pins[] __initconst = {
  54. /* UART1 (console) */
  55. PE12_PF_UART1_TXD,
  56. PE13_PF_UART1_RXD,
  57. PE14_PF_UART1_CTS,
  58. PE15_PF_UART1_RTS,
  59. /* FEC */
  60. PD0_AIN_FEC_TXD0,
  61. PD1_AIN_FEC_TXD1,
  62. PD2_AIN_FEC_TXD2,
  63. PD3_AIN_FEC_TXD3,
  64. PD4_AOUT_FEC_RX_ER,
  65. PD5_AOUT_FEC_RXD1,
  66. PD6_AOUT_FEC_RXD2,
  67. PD7_AOUT_FEC_RXD3,
  68. PD8_AF_FEC_MDIO,
  69. PD9_AIN_FEC_MDC,
  70. PD10_AOUT_FEC_CRS,
  71. PD11_AOUT_FEC_TX_CLK,
  72. PD12_AOUT_FEC_RXD0,
  73. PD13_AOUT_FEC_RX_DV,
  74. PD14_AOUT_FEC_RX_CLK,
  75. PD15_AOUT_FEC_COL,
  76. PD16_AIN_FEC_TX_ER,
  77. PF23_AIN_FEC_TX_EN,
  78. /* SSI1 */
  79. PC20_PF_SSI1_FS,
  80. PC21_PF_SSI1_RXD,
  81. PC22_PF_SSI1_TXD,
  82. PC23_PF_SSI1_CLK,
  83. /* SDHC1 */
  84. PE18_PF_SD1_D0,
  85. PE19_PF_SD1_D1,
  86. PE20_PF_SD1_D2,
  87. PE21_PF_SD1_D3,
  88. PE22_PF_SD1_CMD,
  89. PE23_PF_SD1_CLK,
  90. /* Both I2Cs */
  91. PD17_PF_I2C_DATA,
  92. PD18_PF_I2C_CLK,
  93. PC5_PF_I2C2_SDA,
  94. PC6_PF_I2C2_SCL,
  95. /* USB OTG */
  96. OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
  97. PC9_PF_USBOTG_DATA0,
  98. PC11_PF_USBOTG_DATA1,
  99. PC10_PF_USBOTG_DATA2,
  100. PC13_PF_USBOTG_DATA3,
  101. PC12_PF_USBOTG_DATA4,
  102. PC7_PF_USBOTG_DATA5,
  103. PC8_PF_USBOTG_DATA6,
  104. PE25_PF_USBOTG_DATA7,
  105. PE24_PF_USBOTG_CLK,
  106. PE2_PF_USBOTG_DIR,
  107. PE0_PF_USBOTG_NXT,
  108. PE1_PF_USBOTG_STP,
  109. PB23_PF_USB_PWR,
  110. PB24_PF_USB_OC,
  111. /* CSI */
  112. PB10_PF_CSI_D0,
  113. PB11_PF_CSI_D1,
  114. PB12_PF_CSI_D2,
  115. PB13_PF_CSI_D3,
  116. PB14_PF_CSI_D4,
  117. PB15_PF_CSI_MCLK,
  118. PB16_PF_CSI_PIXCLK,
  119. PB17_PF_CSI_D5,
  120. PB18_PF_CSI_D6,
  121. PB19_PF_CSI_D7,
  122. PB20_PF_CSI_VSYNC,
  123. PB21_PF_CSI_HSYNC,
  124. /* mother board version */
  125. MOTHERBOARD_BIT2 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  126. MOTHERBOARD_BIT1 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  127. MOTHERBOARD_BIT0 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  128. /* expansion board version */
  129. EXPBOARD_BIT2 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  130. EXPBOARD_BIT1 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  131. EXPBOARD_BIT0 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  132. };
  133. static struct gpio visstrim_m10_version_gpios[] = {
  134. { EXPBOARD_BIT0, GPIOF_IN, "exp-version-0" },
  135. { EXPBOARD_BIT1, GPIOF_IN, "exp-version-1" },
  136. { EXPBOARD_BIT2, GPIOF_IN, "exp-version-2" },
  137. { MOTHERBOARD_BIT0, GPIOF_IN, "mother-version-0" },
  138. { MOTHERBOARD_BIT1, GPIOF_IN, "mother-version-1" },
  139. { MOTHERBOARD_BIT2, GPIOF_IN, "mother-version-2" },
  140. };
  141. /* Camera */
  142. static int visstrim_camera_power(struct device *dev, int on)
  143. {
  144. gpio_set_value(TVP5150_PWDN, on);
  145. return 0;
  146. };
  147. static int visstrim_camera_reset(struct device *dev)
  148. {
  149. gpio_set_value(TVP5150_RSTN, 0);
  150. ndelay(500);
  151. gpio_set_value(TVP5150_RSTN, 1);
  152. return 0;
  153. };
  154. static struct i2c_board_info visstrim_i2c_camera = {
  155. I2C_BOARD_INFO("tvp5150", 0x5d),
  156. };
  157. static struct soc_camera_link iclink_tvp5150 = {
  158. .bus_id = 0,
  159. .board_info = &visstrim_i2c_camera,
  160. .i2c_adapter_id = 0,
  161. .power = visstrim_camera_power,
  162. .reset = visstrim_camera_reset,
  163. };
  164. static struct mx2_camera_platform_data visstrim_camera = {
  165. .flags = MX2_CAMERA_CCIR | MX2_CAMERA_CCIR_INTERLACE |
  166. MX2_CAMERA_PCLK_SAMPLE_RISING,
  167. .clk = 100000,
  168. };
  169. static phys_addr_t mx2_camera_base __initdata;
  170. #define MX2_CAMERA_BUF_SIZE SZ_8M
  171. static void __init visstrim_camera_init(void)
  172. {
  173. struct platform_device *pdev;
  174. int dma;
  175. /* Initialize tvp5150 gpios */
  176. mxc_gpio_mode(TVP5150_RSTN | GPIO_GPIO | GPIO_OUT);
  177. mxc_gpio_mode(TVP5150_PWDN | GPIO_GPIO | GPIO_OUT);
  178. gpio_set_value(TVP5150_RSTN, 1);
  179. gpio_set_value(TVP5150_PWDN, 0);
  180. ndelay(1);
  181. gpio_set_value(TVP5150_PWDN, 1);
  182. ndelay(1);
  183. gpio_set_value(TVP5150_RSTN, 0);
  184. ndelay(500);
  185. gpio_set_value(TVP5150_RSTN, 1);
  186. ndelay(200000);
  187. pdev = imx27_add_mx2_camera(&visstrim_camera);
  188. if (IS_ERR(pdev))
  189. return;
  190. dma = dma_declare_coherent_memory(&pdev->dev,
  191. mx2_camera_base, mx2_camera_base,
  192. MX2_CAMERA_BUF_SIZE,
  193. DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
  194. if (!(dma & DMA_MEMORY_MAP))
  195. return;
  196. }
  197. static void __init visstrim_reserve(void)
  198. {
  199. /* reserve 4 MiB for mx2-camera */
  200. mx2_camera_base = memblock_steal(MX2_CAMERA_BUF_SIZE,
  201. MX2_CAMERA_BUF_SIZE);
  202. }
  203. /* GPIOs used as events for applications */
  204. static struct gpio_keys_button visstrim_gpio_keys[] = {
  205. {
  206. .type = EV_KEY,
  207. .code = KEY_RESTART,
  208. .gpio = (GPIO_PORTC + 15),
  209. .desc = "Default config",
  210. .active_low = 0,
  211. .wakeup = 1,
  212. },
  213. {
  214. .type = EV_KEY,
  215. .code = KEY_RECORD,
  216. .gpio = (GPIO_PORTF + 14),
  217. .desc = "Record",
  218. .active_low = 0,
  219. .wakeup = 1,
  220. },
  221. {
  222. .type = EV_KEY,
  223. .code = KEY_STOP,
  224. .gpio = (GPIO_PORTF + 13),
  225. .desc = "Stop",
  226. .active_low = 0,
  227. .wakeup = 1,
  228. }
  229. };
  230. static const struct gpio_keys_platform_data
  231. visstrim_gpio_keys_platform_data __initconst = {
  232. .buttons = visstrim_gpio_keys,
  233. .nbuttons = ARRAY_SIZE(visstrim_gpio_keys),
  234. };
  235. /* led */
  236. static const struct gpio_led visstrim_m10_leds[] __initconst = {
  237. {
  238. .name = "visstrim:ld0",
  239. .default_trigger = "nand-disk",
  240. .gpio = (GPIO_PORTC + 29),
  241. },
  242. {
  243. .name = "visstrim:ld1",
  244. .default_trigger = "nand-disk",
  245. .gpio = (GPIO_PORTC + 24),
  246. },
  247. {
  248. .name = "visstrim:ld2",
  249. .default_trigger = "nand-disk",
  250. .gpio = (GPIO_PORTC + 28),
  251. },
  252. {
  253. .name = "visstrim:ld3",
  254. .default_trigger = "nand-disk",
  255. .gpio = (GPIO_PORTC + 25),
  256. },
  257. };
  258. static const struct gpio_led_platform_data visstrim_m10_led_data __initconst = {
  259. .leds = visstrim_m10_leds,
  260. .num_leds = ARRAY_SIZE(visstrim_m10_leds),
  261. };
  262. /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
  263. static int visstrim_m10_sdhc1_init(struct device *dev,
  264. irq_handler_t detect_irq, void *data)
  265. {
  266. int ret;
  267. ret = request_irq(SDHC1_IRQ, detect_irq, IRQF_TRIGGER_FALLING,
  268. "mmc-detect", data);
  269. return ret;
  270. }
  271. static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
  272. {
  273. free_irq(SDHC1_IRQ, data);
  274. }
  275. static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
  276. .init = visstrim_m10_sdhc1_init,
  277. .exit = visstrim_m10_sdhc1_exit,
  278. };
  279. /* Visstrim_SM10 NOR flash */
  280. static struct physmap_flash_data visstrim_m10_flash_data = {
  281. .width = 2,
  282. };
  283. static struct resource visstrim_m10_flash_resource = {
  284. .start = 0xc0000000,
  285. .end = 0xc0000000 + SZ_64M - 1,
  286. .flags = IORESOURCE_MEM,
  287. };
  288. static struct platform_device visstrim_m10_nor_mtd_device = {
  289. .name = "physmap-flash",
  290. .id = 0,
  291. .dev = {
  292. .platform_data = &visstrim_m10_flash_data,
  293. },
  294. .num_resources = 1,
  295. .resource = &visstrim_m10_flash_resource,
  296. };
  297. static struct platform_device *platform_devices[] __initdata = {
  298. &visstrim_m10_nor_mtd_device,
  299. };
  300. /* Visstrim_M10 uses UART0 as console */
  301. static const struct imxuart_platform_data uart_pdata __initconst = {
  302. .flags = IMXUART_HAVE_RTSCTS,
  303. };
  304. /* I2C */
  305. static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
  306. .bitrate = 100000,
  307. };
  308. static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
  309. .gpio_base = 240, /* After MX27 internal GPIOs */
  310. .invert = 0,
  311. };
  312. static struct aic32x4_pdata visstrim_m10_aic32x4_pdata = {
  313. .power_cfg = AIC32X4_PWR_MICBIAS_2075_LDOIN |
  314. AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE |
  315. AIC32X4_PWR_AIC32X4_LDO_ENABLE |
  316. AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36 |
  317. AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED,
  318. .micpga_routing = AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K |
  319. AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K,
  320. .swapdacs = false,
  321. };
  322. static struct i2c_board_info visstrim_m10_i2c_devices[] = {
  323. {
  324. I2C_BOARD_INFO("pca9555", 0x20),
  325. .platform_data = &visstrim_m10_pca9555_pdata,
  326. },
  327. {
  328. I2C_BOARD_INFO("tlv320aic32x4", 0x18),
  329. .platform_data = &visstrim_m10_aic32x4_pdata,
  330. },
  331. {
  332. I2C_BOARD_INFO("m41t00", 0x68),
  333. }
  334. };
  335. /* USB OTG */
  336. static int otg_phy_init(struct platform_device *pdev)
  337. {
  338. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  339. mdelay(10);
  340. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
  341. }
  342. static const struct mxc_usbh_platform_data
  343. visstrim_m10_usbotg_pdata __initconst = {
  344. .init = otg_phy_init,
  345. .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
  346. };
  347. /* SSI */
  348. static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
  349. .flags = IMX_SSI_DMA | IMX_SSI_SYN,
  350. };
  351. static void __init visstrim_m10_revision(void)
  352. {
  353. int exp_version = 0;
  354. int mo_version = 0;
  355. int ret;
  356. ret = gpio_request_array(visstrim_m10_version_gpios,
  357. ARRAY_SIZE(visstrim_m10_version_gpios));
  358. if (ret) {
  359. pr_err("Failed to request version gpios");
  360. return;
  361. }
  362. /* Get expansion board version (negative logic) */
  363. exp_version |= !gpio_get_value(EXPBOARD_BIT2) << 2;
  364. exp_version |= !gpio_get_value(EXPBOARD_BIT1) << 1;
  365. exp_version |= !gpio_get_value(EXPBOARD_BIT0);
  366. /* Get mother board version (negative logic) */
  367. mo_version |= !gpio_get_value(MOTHERBOARD_BIT2) << 2;
  368. mo_version |= !gpio_get_value(MOTHERBOARD_BIT1) << 1;
  369. mo_version |= !gpio_get_value(MOTHERBOARD_BIT0);
  370. system_rev = 0x27000;
  371. system_rev |= (mo_version << 4);
  372. system_rev |= exp_version;
  373. }
  374. static void __init visstrim_m10_board_init(void)
  375. {
  376. int ret;
  377. imx27_soc_init();
  378. visstrim_m10_revision();
  379. ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
  380. ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
  381. if (ret)
  382. pr_err("Failed to setup pins (%d)\n", ret);
  383. imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
  384. imx27_add_imx_uart0(&uart_pdata);
  385. imx27_add_imx_i2c(0, &visstrim_m10_i2c_data);
  386. imx27_add_imx_i2c(1, &visstrim_m10_i2c_data);
  387. i2c_register_board_info(0, visstrim_m10_i2c_devices,
  388. ARRAY_SIZE(visstrim_m10_i2c_devices));
  389. imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
  390. imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
  391. imx27_add_fec(NULL);
  392. imx_add_gpio_keys(&visstrim_gpio_keys_platform_data);
  393. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  394. imx_add_platform_device("mx27vis", 0, NULL, 0, NULL, 0);
  395. platform_device_register_resndata(NULL, "soc-camera-pdrv", 0, NULL, 0,
  396. &iclink_tvp5150, sizeof(iclink_tvp5150));
  397. gpio_led_register_device(0, &visstrim_m10_led_data);
  398. visstrim_camera_init();
  399. }
  400. static void __init visstrim_m10_timer_init(void)
  401. {
  402. mx27_clocks_init((unsigned long)25000000);
  403. }
  404. static struct sys_timer visstrim_m10_timer = {
  405. .init = visstrim_m10_timer_init,
  406. };
  407. MACHINE_START(IMX27_VISSTRIM_M10, "Vista Silicon Visstrim_M10")
  408. .atag_offset = 0x100,
  409. .reserve = visstrim_reserve,
  410. .map_io = mx27_map_io,
  411. .init_early = imx27_init_early,
  412. .init_irq = mx27_init_irq,
  413. .handle_irq = imx27_handle_irq,
  414. .timer = &visstrim_m10_timer,
  415. .init_machine = visstrim_m10_board_init,
  416. .restart = mxc_restart,
  417. MACHINE_END