mach-imx27_visstrim_m10.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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_info.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. TVP5150_RSTN | GPIO_GPIO | GPIO_OUT,
  113. TVP5150_PWDN | GPIO_GPIO | GPIO_OUT,
  114. PB10_PF_CSI_D0,
  115. PB11_PF_CSI_D1,
  116. PB12_PF_CSI_D2,
  117. PB13_PF_CSI_D3,
  118. PB14_PF_CSI_D4,
  119. PB15_PF_CSI_MCLK,
  120. PB16_PF_CSI_PIXCLK,
  121. PB17_PF_CSI_D5,
  122. PB18_PF_CSI_D6,
  123. PB19_PF_CSI_D7,
  124. PB20_PF_CSI_VSYNC,
  125. PB21_PF_CSI_HSYNC,
  126. /* mother board version */
  127. MOTHERBOARD_BIT2 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  128. MOTHERBOARD_BIT1 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  129. MOTHERBOARD_BIT0 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  130. /* expansion board version */
  131. EXPBOARD_BIT2 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  132. EXPBOARD_BIT1 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  133. EXPBOARD_BIT0 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
  134. };
  135. static struct gpio visstrim_m10_version_gpios[] = {
  136. { EXPBOARD_BIT0, GPIOF_IN, "exp-version-0" },
  137. { EXPBOARD_BIT1, GPIOF_IN, "exp-version-1" },
  138. { EXPBOARD_BIT2, GPIOF_IN, "exp-version-2" },
  139. { MOTHERBOARD_BIT0, GPIOF_IN, "mother-version-0" },
  140. { MOTHERBOARD_BIT1, GPIOF_IN, "mother-version-1" },
  141. { MOTHERBOARD_BIT2, GPIOF_IN, "mother-version-2" },
  142. };
  143. static const struct gpio visstrim_m10_gpios[] __initconst = {
  144. {
  145. .gpio = TVP5150_RSTN,
  146. .flags = GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
  147. .label = "tvp5150_rstn",
  148. },
  149. {
  150. .gpio = TVP5150_PWDN,
  151. .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
  152. .label = "tvp5150_pwdn",
  153. },
  154. {
  155. .gpio = OTG_PHY_CS_GPIO,
  156. .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
  157. .label = "usbotg_cs",
  158. },
  159. };
  160. /* Camera */
  161. static int visstrim_camera_power(struct device *dev, int on)
  162. {
  163. gpio_set_value(TVP5150_PWDN, on);
  164. return 0;
  165. };
  166. static int visstrim_camera_reset(struct device *dev)
  167. {
  168. gpio_set_value(TVP5150_RSTN, 0);
  169. ndelay(500);
  170. gpio_set_value(TVP5150_RSTN, 1);
  171. return 0;
  172. };
  173. static struct i2c_board_info visstrim_i2c_camera = {
  174. I2C_BOARD_INFO("tvp5150", 0x5d),
  175. };
  176. static struct soc_camera_link iclink_tvp5150 = {
  177. .bus_id = 0,
  178. .board_info = &visstrim_i2c_camera,
  179. .i2c_adapter_id = 0,
  180. .power = visstrim_camera_power,
  181. .reset = visstrim_camera_reset,
  182. };
  183. static struct mx2_camera_platform_data visstrim_camera = {
  184. .flags = MX2_CAMERA_CCIR | MX2_CAMERA_CCIR_INTERLACE |
  185. MX2_CAMERA_PCLK_SAMPLE_RISING,
  186. .clk = 100000,
  187. };
  188. static phys_addr_t mx2_camera_base __initdata;
  189. #define MX2_CAMERA_BUF_SIZE SZ_8M
  190. static void __init visstrim_camera_init(void)
  191. {
  192. struct platform_device *pdev;
  193. int dma;
  194. gpio_set_value(TVP5150_PWDN, 1);
  195. ndelay(1);
  196. gpio_set_value(TVP5150_RSTN, 0);
  197. ndelay(500);
  198. gpio_set_value(TVP5150_RSTN, 1);
  199. ndelay(200000);
  200. pdev = imx27_add_mx2_camera(&visstrim_camera);
  201. if (IS_ERR(pdev))
  202. return;
  203. dma = dma_declare_coherent_memory(&pdev->dev,
  204. mx2_camera_base, mx2_camera_base,
  205. MX2_CAMERA_BUF_SIZE,
  206. DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
  207. if (!(dma & DMA_MEMORY_MAP))
  208. return;
  209. }
  210. static void __init visstrim_reserve(void)
  211. {
  212. /* reserve 4 MiB for mx2-camera */
  213. mx2_camera_base = memblock_alloc(MX2_CAMERA_BUF_SIZE,
  214. MX2_CAMERA_BUF_SIZE);
  215. memblock_free(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
  216. memblock_remove(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
  217. }
  218. /* GPIOs used as events for applications */
  219. static struct gpio_keys_button visstrim_gpio_keys[] = {
  220. {
  221. .type = EV_KEY,
  222. .code = KEY_RESTART,
  223. .gpio = (GPIO_PORTC + 15),
  224. .desc = "Default config",
  225. .active_low = 0,
  226. .wakeup = 1,
  227. },
  228. {
  229. .type = EV_KEY,
  230. .code = KEY_RECORD,
  231. .gpio = (GPIO_PORTF + 14),
  232. .desc = "Record",
  233. .active_low = 0,
  234. .wakeup = 1,
  235. },
  236. {
  237. .type = EV_KEY,
  238. .code = KEY_STOP,
  239. .gpio = (GPIO_PORTF + 13),
  240. .desc = "Stop",
  241. .active_low = 0,
  242. .wakeup = 1,
  243. }
  244. };
  245. static const struct gpio_keys_platform_data
  246. visstrim_gpio_keys_platform_data __initconst = {
  247. .buttons = visstrim_gpio_keys,
  248. .nbuttons = ARRAY_SIZE(visstrim_gpio_keys),
  249. };
  250. /* led */
  251. static const struct gpio_led visstrim_m10_leds[] __initconst = {
  252. {
  253. .name = "visstrim:ld0",
  254. .default_trigger = "nand-disk",
  255. .gpio = (GPIO_PORTC + 29),
  256. },
  257. {
  258. .name = "visstrim:ld1",
  259. .default_trigger = "nand-disk",
  260. .gpio = (GPIO_PORTC + 24),
  261. },
  262. {
  263. .name = "visstrim:ld2",
  264. .default_trigger = "nand-disk",
  265. .gpio = (GPIO_PORTC + 28),
  266. },
  267. {
  268. .name = "visstrim:ld3",
  269. .default_trigger = "nand-disk",
  270. .gpio = (GPIO_PORTC + 25),
  271. },
  272. };
  273. static const struct gpio_led_platform_data visstrim_m10_led_data __initconst = {
  274. .leds = visstrim_m10_leds,
  275. .num_leds = ARRAY_SIZE(visstrim_m10_leds),
  276. };
  277. /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
  278. static int visstrim_m10_sdhc1_init(struct device *dev,
  279. irq_handler_t detect_irq, void *data)
  280. {
  281. int ret;
  282. ret = request_irq(SDHC1_IRQ, detect_irq, IRQF_TRIGGER_FALLING,
  283. "mmc-detect", data);
  284. return ret;
  285. }
  286. static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
  287. {
  288. free_irq(SDHC1_IRQ, data);
  289. }
  290. static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
  291. .init = visstrim_m10_sdhc1_init,
  292. .exit = visstrim_m10_sdhc1_exit,
  293. };
  294. /* Visstrim_SM10 NOR flash */
  295. static struct physmap_flash_data visstrim_m10_flash_data = {
  296. .width = 2,
  297. };
  298. static struct resource visstrim_m10_flash_resource = {
  299. .start = 0xc0000000,
  300. .end = 0xc0000000 + SZ_64M - 1,
  301. .flags = IORESOURCE_MEM,
  302. };
  303. static struct platform_device visstrim_m10_nor_mtd_device = {
  304. .name = "physmap-flash",
  305. .id = 0,
  306. .dev = {
  307. .platform_data = &visstrim_m10_flash_data,
  308. },
  309. .num_resources = 1,
  310. .resource = &visstrim_m10_flash_resource,
  311. };
  312. static struct platform_device *platform_devices[] __initdata = {
  313. &visstrim_m10_nor_mtd_device,
  314. };
  315. /* Visstrim_M10 uses UART0 as console */
  316. static const struct imxuart_platform_data uart_pdata __initconst = {
  317. .flags = IMXUART_HAVE_RTSCTS,
  318. };
  319. /* I2C */
  320. static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
  321. .bitrate = 100000,
  322. };
  323. static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
  324. .gpio_base = 240, /* After MX27 internal GPIOs */
  325. .invert = 0,
  326. };
  327. static struct aic32x4_pdata visstrim_m10_aic32x4_pdata = {
  328. .power_cfg = AIC32X4_PWR_MICBIAS_2075_LDOIN |
  329. AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE |
  330. AIC32X4_PWR_AIC32X4_LDO_ENABLE |
  331. AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36 |
  332. AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED,
  333. .micpga_routing = AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K |
  334. AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K,
  335. .swapdacs = false,
  336. };
  337. static struct i2c_board_info visstrim_m10_i2c_devices[] = {
  338. {
  339. I2C_BOARD_INFO("pca9555", 0x20),
  340. .platform_data = &visstrim_m10_pca9555_pdata,
  341. },
  342. {
  343. I2C_BOARD_INFO("tlv320aic32x4", 0x18),
  344. .platform_data = &visstrim_m10_aic32x4_pdata,
  345. },
  346. {
  347. I2C_BOARD_INFO("m41t00", 0x68),
  348. }
  349. };
  350. /* USB OTG */
  351. static int otg_phy_init(struct platform_device *pdev)
  352. {
  353. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
  354. }
  355. static const struct mxc_usbh_platform_data
  356. visstrim_m10_usbotg_pdata __initconst = {
  357. .init = otg_phy_init,
  358. .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
  359. };
  360. /* SSI */
  361. static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
  362. .flags = IMX_SSI_DMA | IMX_SSI_SYN,
  363. };
  364. static void __init visstrim_m10_revision(void)
  365. {
  366. int exp_version = 0;
  367. int mo_version = 0;
  368. int ret;
  369. ret = gpio_request_array(visstrim_m10_version_gpios,
  370. ARRAY_SIZE(visstrim_m10_version_gpios));
  371. if (ret) {
  372. pr_err("Failed to request version gpios");
  373. return;
  374. }
  375. /* Get expansion board version (negative logic) */
  376. exp_version |= !gpio_get_value(EXPBOARD_BIT2) << 2;
  377. exp_version |= !gpio_get_value(EXPBOARD_BIT1) << 1;
  378. exp_version |= !gpio_get_value(EXPBOARD_BIT0);
  379. /* Get mother board version (negative logic) */
  380. mo_version |= !gpio_get_value(MOTHERBOARD_BIT2) << 2;
  381. mo_version |= !gpio_get_value(MOTHERBOARD_BIT1) << 1;
  382. mo_version |= !gpio_get_value(MOTHERBOARD_BIT0);
  383. system_rev = 0x27000;
  384. system_rev |= (mo_version << 4);
  385. system_rev |= exp_version;
  386. }
  387. static void __init visstrim_m10_board_init(void)
  388. {
  389. int ret;
  390. imx27_soc_init();
  391. visstrim_m10_revision();
  392. ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
  393. ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
  394. if (ret)
  395. pr_err("Failed to setup pins (%d)\n", ret);
  396. ret = gpio_request_array(visstrim_m10_gpios,
  397. ARRAY_SIZE(visstrim_m10_gpios));
  398. if (ret)
  399. pr_err("Failed to request gpios (%d)\n", ret);
  400. imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
  401. imx27_add_imx_uart0(&uart_pdata);
  402. imx27_add_imx_i2c(0, &visstrim_m10_i2c_data);
  403. imx27_add_imx_i2c(1, &visstrim_m10_i2c_data);
  404. i2c_register_board_info(0, visstrim_m10_i2c_devices,
  405. ARRAY_SIZE(visstrim_m10_i2c_devices));
  406. imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
  407. imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
  408. imx27_add_fec(NULL);
  409. imx_add_gpio_keys(&visstrim_gpio_keys_platform_data);
  410. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  411. imx_add_platform_device("mx27vis", 0, NULL, 0, NULL, 0);
  412. platform_device_register_resndata(NULL, "soc-camera-pdrv", 0, NULL, 0,
  413. &iclink_tvp5150, sizeof(iclink_tvp5150));
  414. gpio_led_register_device(0, &visstrim_m10_led_data);
  415. visstrim_camera_init();
  416. }
  417. static void __init visstrim_m10_timer_init(void)
  418. {
  419. mx27_clocks_init((unsigned long)25000000);
  420. }
  421. static struct sys_timer visstrim_m10_timer = {
  422. .init = visstrim_m10_timer_init,
  423. };
  424. MACHINE_START(IMX27_VISSTRIM_M10, "Vista Silicon Visstrim_M10")
  425. .atag_offset = 0x100,
  426. .reserve = visstrim_reserve,
  427. .map_io = mx27_map_io,
  428. .init_early = imx27_init_early,
  429. .init_irq = mx27_init_irq,
  430. .handle_irq = imx27_handle_irq,
  431. .timer = &visstrim_m10_timer,
  432. .init_machine = visstrim_m10_board_init,
  433. .restart = mxc_restart,
  434. MACHINE_END