mach-imx27_visstrim_m10.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 <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_alloc(MX2_CAMERA_BUF_SIZE,
  201. MX2_CAMERA_BUF_SIZE);
  202. memblock_free(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
  203. memblock_remove(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
  204. }
  205. /* GPIOs used as events for applications */
  206. static struct gpio_keys_button visstrim_gpio_keys[] = {
  207. {
  208. .type = EV_KEY,
  209. .code = KEY_RESTART,
  210. .gpio = (GPIO_PORTC + 15),
  211. .desc = "Default config",
  212. .active_low = 0,
  213. .wakeup = 1,
  214. },
  215. {
  216. .type = EV_KEY,
  217. .code = KEY_RECORD,
  218. .gpio = (GPIO_PORTF + 14),
  219. .desc = "Record",
  220. .active_low = 0,
  221. .wakeup = 1,
  222. },
  223. {
  224. .type = EV_KEY,
  225. .code = KEY_STOP,
  226. .gpio = (GPIO_PORTF + 13),
  227. .desc = "Stop",
  228. .active_low = 0,
  229. .wakeup = 1,
  230. }
  231. };
  232. static const struct gpio_keys_platform_data
  233. visstrim_gpio_keys_platform_data __initconst = {
  234. .buttons = visstrim_gpio_keys,
  235. .nbuttons = ARRAY_SIZE(visstrim_gpio_keys),
  236. };
  237. /* led */
  238. static const struct gpio_led visstrim_m10_leds[] __initconst = {
  239. {
  240. .name = "visstrim:ld0",
  241. .default_trigger = "nand-disk",
  242. .gpio = (GPIO_PORTC + 29),
  243. },
  244. {
  245. .name = "visstrim:ld1",
  246. .default_trigger = "nand-disk",
  247. .gpio = (GPIO_PORTC + 24),
  248. },
  249. {
  250. .name = "visstrim:ld2",
  251. .default_trigger = "nand-disk",
  252. .gpio = (GPIO_PORTC + 28),
  253. },
  254. {
  255. .name = "visstrim:ld3",
  256. .default_trigger = "nand-disk",
  257. .gpio = (GPIO_PORTC + 25),
  258. },
  259. };
  260. static const struct gpio_led_platform_data visstrim_m10_led_data __initconst = {
  261. .leds = visstrim_m10_leds,
  262. .num_leds = ARRAY_SIZE(visstrim_m10_leds),
  263. };
  264. /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
  265. static int visstrim_m10_sdhc1_init(struct device *dev,
  266. irq_handler_t detect_irq, void *data)
  267. {
  268. int ret;
  269. ret = request_irq(SDHC1_IRQ, detect_irq, IRQF_TRIGGER_FALLING,
  270. "mmc-detect", data);
  271. return ret;
  272. }
  273. static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
  274. {
  275. free_irq(SDHC1_IRQ, data);
  276. }
  277. static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
  278. .init = visstrim_m10_sdhc1_init,
  279. .exit = visstrim_m10_sdhc1_exit,
  280. };
  281. /* Visstrim_SM10 NOR flash */
  282. static struct physmap_flash_data visstrim_m10_flash_data = {
  283. .width = 2,
  284. };
  285. static struct resource visstrim_m10_flash_resource = {
  286. .start = 0xc0000000,
  287. .end = 0xc0000000 + SZ_64M - 1,
  288. .flags = IORESOURCE_MEM,
  289. };
  290. static struct platform_device visstrim_m10_nor_mtd_device = {
  291. .name = "physmap-flash",
  292. .id = 0,
  293. .dev = {
  294. .platform_data = &visstrim_m10_flash_data,
  295. },
  296. .num_resources = 1,
  297. .resource = &visstrim_m10_flash_resource,
  298. };
  299. static struct platform_device *platform_devices[] __initdata = {
  300. &visstrim_m10_nor_mtd_device,
  301. };
  302. /* Visstrim_M10 uses UART0 as console */
  303. static const struct imxuart_platform_data uart_pdata __initconst = {
  304. .flags = IMXUART_HAVE_RTSCTS,
  305. };
  306. /* I2C */
  307. static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
  308. .bitrate = 100000,
  309. };
  310. static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
  311. .gpio_base = 240, /* After MX27 internal GPIOs */
  312. .invert = 0,
  313. };
  314. static struct aic32x4_pdata visstrim_m10_aic32x4_pdata = {
  315. .power_cfg = AIC32X4_PWR_MICBIAS_2075_LDOIN |
  316. AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE |
  317. AIC32X4_PWR_AIC32X4_LDO_ENABLE |
  318. AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36 |
  319. AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED,
  320. .micpga_routing = AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K |
  321. AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K,
  322. .swapdacs = false,
  323. };
  324. static struct i2c_board_info visstrim_m10_i2c_devices[] = {
  325. {
  326. I2C_BOARD_INFO("pca9555", 0x20),
  327. .platform_data = &visstrim_m10_pca9555_pdata,
  328. },
  329. {
  330. I2C_BOARD_INFO("tlv320aic32x4", 0x18),
  331. .platform_data = &visstrim_m10_aic32x4_pdata,
  332. },
  333. {
  334. I2C_BOARD_INFO("m41t00", 0x68),
  335. }
  336. };
  337. /* USB OTG */
  338. static int otg_phy_init(struct platform_device *pdev)
  339. {
  340. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  341. mdelay(10);
  342. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
  343. }
  344. static const struct mxc_usbh_platform_data
  345. visstrim_m10_usbotg_pdata __initconst = {
  346. .init = otg_phy_init,
  347. .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
  348. };
  349. /* SSI */
  350. static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
  351. .flags = IMX_SSI_DMA | IMX_SSI_SYN,
  352. };
  353. static void __init visstrim_m10_revision(void)
  354. {
  355. int exp_version = 0;
  356. int mo_version = 0;
  357. int ret;
  358. ret = gpio_request_array(visstrim_m10_version_gpios,
  359. ARRAY_SIZE(visstrim_m10_version_gpios));
  360. if (ret) {
  361. pr_err("Failed to request version gpios");
  362. return;
  363. }
  364. /* Get expansion board version (negative logic) */
  365. exp_version |= !gpio_get_value(EXPBOARD_BIT2) << 2;
  366. exp_version |= !gpio_get_value(EXPBOARD_BIT1) << 1;
  367. exp_version |= !gpio_get_value(EXPBOARD_BIT0);
  368. /* Get mother board version (negative logic) */
  369. mo_version |= !gpio_get_value(MOTHERBOARD_BIT2) << 2;
  370. mo_version |= !gpio_get_value(MOTHERBOARD_BIT1) << 1;
  371. mo_version |= !gpio_get_value(MOTHERBOARD_BIT0);
  372. system_rev = 0x27000;
  373. system_rev |= (mo_version << 4);
  374. system_rev |= exp_version;
  375. }
  376. static void __init visstrim_m10_board_init(void)
  377. {
  378. int ret;
  379. imx27_soc_init();
  380. visstrim_m10_revision();
  381. ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
  382. ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
  383. if (ret)
  384. pr_err("Failed to setup pins (%d)\n", ret);
  385. imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
  386. imx27_add_imx_uart0(&uart_pdata);
  387. imx27_add_imx_i2c(0, &visstrim_m10_i2c_data);
  388. imx27_add_imx_i2c(1, &visstrim_m10_i2c_data);
  389. i2c_register_board_info(0, visstrim_m10_i2c_devices,
  390. ARRAY_SIZE(visstrim_m10_i2c_devices));
  391. imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
  392. imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
  393. imx27_add_fec(NULL);
  394. imx_add_gpio_keys(&visstrim_gpio_keys_platform_data);
  395. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  396. imx_add_platform_device("mx27vis", 0, NULL, 0, NULL, 0);
  397. platform_device_register_resndata(NULL, "soc-camera-pdrv", 0, NULL, 0,
  398. &iclink_tvp5150, sizeof(iclink_tvp5150));
  399. gpio_led_register_device(0, &visstrim_m10_led_data);
  400. visstrim_camera_init();
  401. }
  402. static void __init visstrim_m10_timer_init(void)
  403. {
  404. mx27_clocks_init((unsigned long)25000000);
  405. }
  406. static struct sys_timer visstrim_m10_timer = {
  407. .init = visstrim_m10_timer_init,
  408. };
  409. MACHINE_START(IMX27_VISSTRIM_M10, "Vista Silicon Visstrim_M10")
  410. .atag_offset = 0x100,
  411. .reserve = visstrim_reserve,
  412. .map_io = mx27_map_io,
  413. .init_early = imx27_init_early,
  414. .init_irq = mx27_init_irq,
  415. .handle_irq = imx27_handle_irq,
  416. .timer = &visstrim_m10_timer,
  417. .init_machine = visstrim_m10_board_init,
  418. .restart = mxc_restart,
  419. MACHINE_END