mx31moboard-marxbot.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (C) 2009 Valentin Longchamp, EPFL Mobots group
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/i2c.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/types.h>
  26. #include <mach/common.h>
  27. #include <mach/hardware.h>
  28. #include <mach/imx-uart.h>
  29. #include <mach/iomux-mx3.h>
  30. #include <mach/mmc.h>
  31. #include <media/soc_camera.h>
  32. #include "devices.h"
  33. static unsigned int marxbot_pins[] = {
  34. /* SDHC2 */
  35. MX31_PIN_PC_PWRON__SD2_DATA3, MX31_PIN_PC_VS1__SD2_DATA2,
  36. MX31_PIN_PC_READY__SD2_DATA1, MX31_PIN_PC_WAIT_B__SD2_DATA0,
  37. MX31_PIN_PC_CD2_B__SD2_CLK, MX31_PIN_PC_CD1_B__SD2_CMD,
  38. MX31_PIN_ATA_DIOR__GPIO3_28, MX31_PIN_ATA_DIOW__GPIO3_29,
  39. /* CSI */
  40. MX31_PIN_CSI_D6__CSI_D6, MX31_PIN_CSI_D7__CSI_D7,
  41. MX31_PIN_CSI_D8__CSI_D8, MX31_PIN_CSI_D9__CSI_D9,
  42. MX31_PIN_CSI_D10__CSI_D10, MX31_PIN_CSI_D11__CSI_D11,
  43. MX31_PIN_CSI_D12__CSI_D12, MX31_PIN_CSI_D13__CSI_D13,
  44. MX31_PIN_CSI_D14__CSI_D14, MX31_PIN_CSI_D15__CSI_D15,
  45. MX31_PIN_CSI_HSYNC__CSI_HSYNC, MX31_PIN_CSI_MCLK__CSI_MCLK,
  46. MX31_PIN_CSI_PIXCLK__CSI_PIXCLK, MX31_PIN_CSI_VSYNC__CSI_VSYNC,
  47. MX31_PIN_CSI_D4__GPIO3_4, MX31_PIN_CSI_D5__GPIO3_5,
  48. MX31_PIN_GPIO3_0__GPIO3_0, MX31_PIN_GPIO3_1__GPIO3_1,
  49. MX31_PIN_TXD2__GPIO1_28,
  50. /* dsPIC resets */
  51. MX31_PIN_STXD5__GPIO1_21, MX31_PIN_SRXD5__GPIO1_22,
  52. /*battery detection */
  53. MX31_PIN_LCS0__GPIO3_23,
  54. };
  55. #define SDHC2_CD IOMUX_TO_GPIO(MX31_PIN_ATA_DIOR)
  56. #define SDHC2_WP IOMUX_TO_GPIO(MX31_PIN_ATA_DIOW)
  57. static int marxbot_sdhc2_get_ro(struct device *dev)
  58. {
  59. return !gpio_get_value(SDHC2_WP);
  60. }
  61. static int marxbot_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
  62. void *data)
  63. {
  64. int ret;
  65. ret = gpio_request(SDHC2_CD, "sdhc-detect");
  66. if (ret)
  67. return ret;
  68. gpio_direction_input(SDHC2_CD);
  69. ret = gpio_request(SDHC2_WP, "sdhc-wp");
  70. if (ret)
  71. goto err_gpio_free;
  72. gpio_direction_input(SDHC2_WP);
  73. ret = request_irq(gpio_to_irq(SDHC2_CD), detect_irq,
  74. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  75. "sdhc2-card-detect", data);
  76. if (ret)
  77. goto err_gpio_free_2;
  78. return 0;
  79. err_gpio_free_2:
  80. gpio_free(SDHC2_WP);
  81. err_gpio_free:
  82. gpio_free(SDHC2_CD);
  83. return ret;
  84. }
  85. static void marxbot_sdhc2_exit(struct device *dev, void *data)
  86. {
  87. free_irq(gpio_to_irq(SDHC2_CD), data);
  88. gpio_free(SDHC2_WP);
  89. gpio_free(SDHC2_CD);
  90. }
  91. static struct imxmmc_platform_data sdhc2_pdata = {
  92. .get_ro = marxbot_sdhc2_get_ro,
  93. .init = marxbot_sdhc2_init,
  94. .exit = marxbot_sdhc2_exit,
  95. };
  96. #define TRSLAT_RST_B IOMUX_TO_GPIO(MX31_PIN_STXD5)
  97. #define DSPICS_RST_B IOMUX_TO_GPIO(MX31_PIN_SRXD5)
  98. static void dspics_resets_init(void)
  99. {
  100. if (!gpio_request(TRSLAT_RST_B, "translator-rst")) {
  101. gpio_direction_output(TRSLAT_RST_B, 1);
  102. gpio_export(TRSLAT_RST_B, false);
  103. }
  104. if (!gpio_request(DSPICS_RST_B, "dspics-rst")) {
  105. gpio_direction_output(DSPICS_RST_B, 1);
  106. gpio_export(DSPICS_RST_B, false);
  107. }
  108. }
  109. static struct spi_board_info marxbot_spi_board_info[] __initdata = {
  110. {
  111. .modalias = "spidev",
  112. .max_speed_hz = 300000,
  113. .bus_num = 1,
  114. .chip_select = 1, /* according spi1_cs[] ! */
  115. },
  116. };
  117. #define TURRETCAM_POWER IOMUX_TO_GPIO(MX31_PIN_GPIO3_1)
  118. #define BASECAM_POWER IOMUX_TO_GPIO(MX31_PIN_CSI_D5)
  119. #define TURRETCAM_RST_B IOMUX_TO_GPIO(MX31_PIN_GPIO3_0)
  120. #define BASECAM_RST_B IOMUX_TO_GPIO(MX31_PIN_CSI_D4)
  121. #define CAM_CHOICE IOMUX_TO_GPIO(MX31_PIN_TXD2)
  122. static int marxbot_basecam_power(struct device *dev, int on)
  123. {
  124. gpio_set_value(BASECAM_POWER, !on);
  125. return 0;
  126. }
  127. static int marxbot_basecam_reset(struct device *dev)
  128. {
  129. gpio_set_value(BASECAM_RST_B, 0);
  130. udelay(100);
  131. gpio_set_value(BASECAM_RST_B, 1);
  132. return 0;
  133. }
  134. static struct i2c_board_info marxbot_i2c_devices[] = {
  135. {
  136. I2C_BOARD_INFO("mt9t031", 0x5d),
  137. },
  138. };
  139. static struct soc_camera_link base_iclink = {
  140. .bus_id = 0, /* Must match with the camera ID */
  141. .power = marxbot_basecam_power,
  142. .reset = marxbot_basecam_reset,
  143. .board_info = &marxbot_i2c_devices[0],
  144. .i2c_adapter_id = 0,
  145. .module_name = "mt9t031",
  146. };
  147. static struct platform_device marxbot_camera[] = {
  148. {
  149. .name = "soc-camera-pdrv",
  150. .id = 0,
  151. .dev = {
  152. .platform_data = &base_iclink,
  153. },
  154. },
  155. };
  156. static struct platform_device *marxbot_cameras[] __initdata = {
  157. &marxbot_camera[0],
  158. };
  159. static int __init marxbot_cam_init(void)
  160. {
  161. int ret = gpio_request(CAM_CHOICE, "cam-choice");
  162. if (ret)
  163. return ret;
  164. gpio_direction_output(CAM_CHOICE, 1);
  165. ret = gpio_request(BASECAM_RST_B, "basecam-reset");
  166. if (ret)
  167. return ret;
  168. gpio_direction_output(BASECAM_RST_B, 1);
  169. ret = gpio_request(BASECAM_POWER, "basecam-standby");
  170. if (ret)
  171. return ret;
  172. gpio_direction_output(BASECAM_POWER, 0);
  173. ret = gpio_request(TURRETCAM_RST_B, "turretcam-reset");
  174. if (ret)
  175. return ret;
  176. gpio_direction_output(TURRETCAM_RST_B, 1);
  177. ret = gpio_request(TURRETCAM_POWER, "turretcam-standby");
  178. if (ret)
  179. return ret;
  180. gpio_direction_output(TURRETCAM_POWER, 0);
  181. return 0;
  182. }
  183. /*
  184. * system init for baseboard usage. Will be called by mx31moboard init.
  185. */
  186. void __init mx31moboard_marxbot_init(void)
  187. {
  188. printk(KERN_INFO "Initializing mx31marxbot peripherals\n");
  189. mxc_iomux_setup_multiple_pins(marxbot_pins, ARRAY_SIZE(marxbot_pins),
  190. "marxbot");
  191. dspics_resets_init();
  192. mxc_register_device(&mxcsdhc_device1, &sdhc2_pdata);
  193. spi_register_board_info(marxbot_spi_board_info,
  194. ARRAY_SIZE(marxbot_spi_board_info));
  195. marxbot_cam_init();
  196. platform_add_devices(marxbot_cameras, ARRAY_SIZE(marxbot_cameras));
  197. /* battery present pin */
  198. gpio_request(IOMUX_TO_GPIO(MX31_PIN_LCS0), "bat-present");
  199. gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_LCS0));
  200. gpio_export(IOMUX_TO_GPIO(MX31_PIN_LCS0), false);
  201. }