mach-imx27_visstrim_m10.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 <linux/memblock.h>
  34. #include <media/soc_camera.h>
  35. #include <sound/tlv320aic32x4.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/time.h>
  39. #include <mach/common.h>
  40. #include <mach/iomux-mx27.h>
  41. #include "devices-imx27.h"
  42. #define TVP5150_RSTN (GPIO_PORTC + 18)
  43. #define TVP5150_PWDN (GPIO_PORTC + 19)
  44. #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
  45. #define SDHC1_IRQ IRQ_GPIOB(25)
  46. static const int visstrim_m10_pins[] __initconst = {
  47. /* UART1 (console) */
  48. PE12_PF_UART1_TXD,
  49. PE13_PF_UART1_RXD,
  50. PE14_PF_UART1_CTS,
  51. PE15_PF_UART1_RTS,
  52. /* FEC */
  53. PD0_AIN_FEC_TXD0,
  54. PD1_AIN_FEC_TXD1,
  55. PD2_AIN_FEC_TXD2,
  56. PD3_AIN_FEC_TXD3,
  57. PD4_AOUT_FEC_RX_ER,
  58. PD5_AOUT_FEC_RXD1,
  59. PD6_AOUT_FEC_RXD2,
  60. PD7_AOUT_FEC_RXD3,
  61. PD8_AF_FEC_MDIO,
  62. PD9_AIN_FEC_MDC,
  63. PD10_AOUT_FEC_CRS,
  64. PD11_AOUT_FEC_TX_CLK,
  65. PD12_AOUT_FEC_RXD0,
  66. PD13_AOUT_FEC_RX_DV,
  67. PD14_AOUT_FEC_RX_CLK,
  68. PD15_AOUT_FEC_COL,
  69. PD16_AIN_FEC_TX_ER,
  70. PF23_AIN_FEC_TX_EN,
  71. /* SSI1 */
  72. PC20_PF_SSI1_FS,
  73. PC21_PF_SSI1_RXD,
  74. PC22_PF_SSI1_TXD,
  75. PC23_PF_SSI1_CLK,
  76. /* SDHC1 */
  77. PE18_PF_SD1_D0,
  78. PE19_PF_SD1_D1,
  79. PE20_PF_SD1_D2,
  80. PE21_PF_SD1_D3,
  81. PE22_PF_SD1_CMD,
  82. PE23_PF_SD1_CLK,
  83. /* Both I2Cs */
  84. PD17_PF_I2C_DATA,
  85. PD18_PF_I2C_CLK,
  86. PC5_PF_I2C2_SDA,
  87. PC6_PF_I2C2_SCL,
  88. /* USB OTG */
  89. OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
  90. PC9_PF_USBOTG_DATA0,
  91. PC11_PF_USBOTG_DATA1,
  92. PC10_PF_USBOTG_DATA2,
  93. PC13_PF_USBOTG_DATA3,
  94. PC12_PF_USBOTG_DATA4,
  95. PC7_PF_USBOTG_DATA5,
  96. PC8_PF_USBOTG_DATA6,
  97. PE25_PF_USBOTG_DATA7,
  98. PE24_PF_USBOTG_CLK,
  99. PE2_PF_USBOTG_DIR,
  100. PE0_PF_USBOTG_NXT,
  101. PE1_PF_USBOTG_STP,
  102. PB23_PF_USB_PWR,
  103. PB24_PF_USB_OC,
  104. /* CSI */
  105. PB10_PF_CSI_D0,
  106. PB11_PF_CSI_D1,
  107. PB12_PF_CSI_D2,
  108. PB13_PF_CSI_D3,
  109. PB14_PF_CSI_D4,
  110. PB15_PF_CSI_MCLK,
  111. PB16_PF_CSI_PIXCLK,
  112. PB17_PF_CSI_D5,
  113. PB18_PF_CSI_D6,
  114. PB19_PF_CSI_D7,
  115. PB20_PF_CSI_VSYNC,
  116. PB21_PF_CSI_HSYNC,
  117. };
  118. /* Camera */
  119. static int visstrim_camera_power(struct device *dev, int on)
  120. {
  121. gpio_set_value(TVP5150_PWDN, on);
  122. return 0;
  123. };
  124. static int visstrim_camera_reset(struct device *dev)
  125. {
  126. gpio_set_value(TVP5150_RSTN, 0);
  127. ndelay(500);
  128. gpio_set_value(TVP5150_RSTN, 1);
  129. return 0;
  130. };
  131. static struct i2c_board_info visstrim_i2c_camera = {
  132. I2C_BOARD_INFO("tvp5150", 0x5d),
  133. };
  134. static struct soc_camera_link iclink_tvp5150 = {
  135. .bus_id = 0,
  136. .board_info = &visstrim_i2c_camera,
  137. .i2c_adapter_id = 0,
  138. .power = visstrim_camera_power,
  139. .reset = visstrim_camera_reset,
  140. };
  141. static struct mx2_camera_platform_data visstrim_camera = {
  142. .flags = MX2_CAMERA_CCIR | MX2_CAMERA_CCIR_INTERLACE |
  143. MX2_CAMERA_SWAP16 | MX2_CAMERA_PCLK_SAMPLE_RISING,
  144. .clk = 100000,
  145. };
  146. static phys_addr_t mx2_camera_base __initdata;
  147. #define MX2_CAMERA_BUF_SIZE SZ_8M
  148. static void __init visstrim_camera_init(void)
  149. {
  150. struct platform_device *pdev;
  151. int dma;
  152. /* Initialize tvp5150 gpios */
  153. mxc_gpio_mode(TVP5150_RSTN | GPIO_GPIO | GPIO_OUT);
  154. mxc_gpio_mode(TVP5150_PWDN | GPIO_GPIO | GPIO_OUT);
  155. gpio_set_value(TVP5150_RSTN, 1);
  156. gpio_set_value(TVP5150_PWDN, 0);
  157. ndelay(1);
  158. gpio_set_value(TVP5150_PWDN, 1);
  159. ndelay(1);
  160. gpio_set_value(TVP5150_RSTN, 0);
  161. ndelay(500);
  162. gpio_set_value(TVP5150_RSTN, 1);
  163. ndelay(200000);
  164. pdev = imx27_add_mx2_camera(&visstrim_camera);
  165. if (IS_ERR(pdev))
  166. return;
  167. dma = dma_declare_coherent_memory(&pdev->dev,
  168. mx2_camera_base, mx2_camera_base,
  169. MX2_CAMERA_BUF_SIZE,
  170. DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
  171. if (!(dma & DMA_MEMORY_MAP))
  172. return;
  173. }
  174. static void __init visstrim_reserve(void)
  175. {
  176. /* reserve 4 MiB for mx2-camera */
  177. mx2_camera_base = memblock_alloc(MX2_CAMERA_BUF_SIZE,
  178. MX2_CAMERA_BUF_SIZE);
  179. memblock_free(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
  180. memblock_remove(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
  181. }
  182. /* GPIOs used as events for applications */
  183. static struct gpio_keys_button visstrim_gpio_keys[] = {
  184. {
  185. .type = EV_KEY,
  186. .code = KEY_RESTART,
  187. .gpio = (GPIO_PORTC + 15),
  188. .desc = "Default config",
  189. .active_low = 0,
  190. .wakeup = 1,
  191. },
  192. {
  193. .type = EV_KEY,
  194. .code = KEY_RECORD,
  195. .gpio = (GPIO_PORTF + 14),
  196. .desc = "Record",
  197. .active_low = 0,
  198. .wakeup = 1,
  199. },
  200. {
  201. .type = EV_KEY,
  202. .code = KEY_STOP,
  203. .gpio = (GPIO_PORTF + 13),
  204. .desc = "Stop",
  205. .active_low = 0,
  206. .wakeup = 1,
  207. }
  208. };
  209. static const struct gpio_keys_platform_data
  210. visstrim_gpio_keys_platform_data __initconst = {
  211. .buttons = visstrim_gpio_keys,
  212. .nbuttons = ARRAY_SIZE(visstrim_gpio_keys),
  213. };
  214. /* led */
  215. static const struct gpio_led visstrim_m10_leds[] __initconst = {
  216. {
  217. .name = "visstrim:ld0",
  218. .default_trigger = "nand-disk",
  219. .gpio = (GPIO_PORTC + 29),
  220. },
  221. {
  222. .name = "visstrim:ld1",
  223. .default_trigger = "nand-disk",
  224. .gpio = (GPIO_PORTC + 24),
  225. },
  226. {
  227. .name = "visstrim:ld2",
  228. .default_trigger = "nand-disk",
  229. .gpio = (GPIO_PORTC + 28),
  230. },
  231. {
  232. .name = "visstrim:ld3",
  233. .default_trigger = "nand-disk",
  234. .gpio = (GPIO_PORTC + 25),
  235. },
  236. };
  237. static const struct gpio_led_platform_data visstrim_m10_led_data __initconst = {
  238. .leds = visstrim_m10_leds,
  239. .num_leds = ARRAY_SIZE(visstrim_m10_leds),
  240. };
  241. /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
  242. static int visstrim_m10_sdhc1_init(struct device *dev,
  243. irq_handler_t detect_irq, void *data)
  244. {
  245. int ret;
  246. ret = request_irq(SDHC1_IRQ, detect_irq, IRQF_TRIGGER_FALLING,
  247. "mmc-detect", data);
  248. return ret;
  249. }
  250. static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
  251. {
  252. free_irq(SDHC1_IRQ, data);
  253. }
  254. static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
  255. .init = visstrim_m10_sdhc1_init,
  256. .exit = visstrim_m10_sdhc1_exit,
  257. };
  258. /* Visstrim_SM10 NOR flash */
  259. static struct physmap_flash_data visstrim_m10_flash_data = {
  260. .width = 2,
  261. };
  262. static struct resource visstrim_m10_flash_resource = {
  263. .start = 0xc0000000,
  264. .end = 0xc0000000 + SZ_64M - 1,
  265. .flags = IORESOURCE_MEM,
  266. };
  267. static struct platform_device visstrim_m10_nor_mtd_device = {
  268. .name = "physmap-flash",
  269. .id = 0,
  270. .dev = {
  271. .platform_data = &visstrim_m10_flash_data,
  272. },
  273. .num_resources = 1,
  274. .resource = &visstrim_m10_flash_resource,
  275. };
  276. static struct platform_device *platform_devices[] __initdata = {
  277. &visstrim_m10_nor_mtd_device,
  278. };
  279. /* Visstrim_M10 uses UART0 as console */
  280. static const struct imxuart_platform_data uart_pdata __initconst = {
  281. .flags = IMXUART_HAVE_RTSCTS,
  282. };
  283. /* I2C */
  284. static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
  285. .bitrate = 100000,
  286. };
  287. static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
  288. .gpio_base = 240, /* After MX27 internal GPIOs */
  289. .invert = 0,
  290. };
  291. static struct aic32x4_pdata visstrim_m10_aic32x4_pdata = {
  292. .power_cfg = AIC32X4_PWR_MICBIAS_2075_LDOIN |
  293. AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE |
  294. AIC32X4_PWR_AIC32X4_LDO_ENABLE |
  295. AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36 |
  296. AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED,
  297. .micpga_routing = AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K |
  298. AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K,
  299. .swapdacs = false,
  300. };
  301. static struct i2c_board_info visstrim_m10_i2c_devices[] = {
  302. {
  303. I2C_BOARD_INFO("pca9555", 0x20),
  304. .platform_data = &visstrim_m10_pca9555_pdata,
  305. },
  306. {
  307. I2C_BOARD_INFO("tlv320aic32x4", 0x18),
  308. .platform_data = &visstrim_m10_aic32x4_pdata,
  309. },
  310. {
  311. I2C_BOARD_INFO("m41t00", 0x68),
  312. }
  313. };
  314. /* USB OTG */
  315. static int otg_phy_init(struct platform_device *pdev)
  316. {
  317. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  318. mdelay(10);
  319. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
  320. }
  321. static const struct mxc_usbh_platform_data
  322. visstrim_m10_usbotg_pdata __initconst = {
  323. .init = otg_phy_init,
  324. .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
  325. };
  326. /* SSI */
  327. static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
  328. .flags = IMX_SSI_DMA | IMX_SSI_SYN,
  329. };
  330. static void __init visstrim_m10_board_init(void)
  331. {
  332. int ret;
  333. imx27_soc_init();
  334. ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
  335. ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
  336. if (ret)
  337. pr_err("Failed to setup pins (%d)\n", ret);
  338. imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
  339. imx27_add_imx_uart0(&uart_pdata);
  340. imx27_add_imx_i2c(0, &visstrim_m10_i2c_data);
  341. imx27_add_imx_i2c(1, &visstrim_m10_i2c_data);
  342. i2c_register_board_info(0, visstrim_m10_i2c_devices,
  343. ARRAY_SIZE(visstrim_m10_i2c_devices));
  344. imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
  345. imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
  346. imx27_add_fec(NULL);
  347. imx_add_gpio_keys(&visstrim_gpio_keys_platform_data);
  348. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  349. imx_add_platform_device("mx27vis", 0, NULL, 0, NULL, 0);
  350. platform_device_register_resndata(NULL, "soc-camera-pdrv", 0, NULL, 0,
  351. &iclink_tvp5150, sizeof(iclink_tvp5150));
  352. gpio_led_register_device(0, &visstrim_m10_led_data);
  353. visstrim_camera_init();
  354. }
  355. static void __init visstrim_m10_timer_init(void)
  356. {
  357. mx27_clocks_init((unsigned long)25000000);
  358. }
  359. static struct sys_timer visstrim_m10_timer = {
  360. .init = visstrim_m10_timer_init,
  361. };
  362. MACHINE_START(IMX27_VISSTRIM_M10, "Vista Silicon Visstrim_M10")
  363. .atag_offset = 0x100,
  364. .reserve = visstrim_reserve,
  365. .map_io = mx27_map_io,
  366. .init_early = imx27_init_early,
  367. .init_irq = mx27_init_irq,
  368. .handle_irq = imx27_handle_irq,
  369. .timer = &visstrim_m10_timer,
  370. .init_machine = visstrim_m10_board_init,
  371. .restart = mxc_restart,
  372. MACHINE_END