mach-imx27_visstrim_m10.c 12 KB

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