Full support for Ginger Console
[linux-ginger.git] / arch / arm / mach-omap2 / board-3430sdp-camera.c
blob5b768270692a40999a3a0c85d9f6e4a8618baf51
1 /*
2 * linux/arch/arm/mach-omap2/board-3430sdp.c
4 * Copyright (C) 2007 Texas Instruments
6 * Modified from mach-omap2/board-generic.c
8 * Initial code: Syed Mohammed Khasim
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/clk.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/mm.h>
20 #include <linux/regulator/consumer.h>
22 #include <asm/io.h>
24 #include <mach/mux.h>
25 #include <mach/gpio.h>
26 #ifdef CONFIG_OMAP_PM_SRF
27 #include <mach/omap-pm.h>
28 #endif
30 static int cam_inited;
32 static struct device *camkit_dev;
34 #include <media/v4l2-int-device.h>
35 #include <../drivers/media/video/omap34xxcam.h>
36 #include <../drivers/media/video/isp/ispreg.h>
37 #define DEBUG_BASE 0x08000000
39 #define REG_SDP3430_FPGA_GPIO_2 (0x50)
40 #define FPGA_SPR_GPIO1_3v3 (0x1 << 14)
41 #define FPGA_GPIO6_DIR_CTRL (0x1 << 6)
43 #define CAMKITV3_USE_XCLKA 0
44 #define CAMKITV3_USE_XCLKB 1
46 #define CAMKITV3_RESET_GPIO 98
48 /* Sensor specific GPIO signals */
49 #define MT9P012_STANDBY_GPIO 58
50 #define OV3640_STANDBY_GPIO 55
51 #define TPS61059_TORCH_EN_GPIO 56
52 #define TPS61059_FLASH_STROBE_GPIO 126
54 static struct regulator *sdp3430_mt9p012_reg;
55 static struct regulator *sdp3430_dw9710_reg;
56 static struct regulator *sdp3430_ov3640_reg;
58 #if defined(CONFIG_VIDEO_MT9P012) || defined(CONFIG_VIDEO_MT9P012_MODULE)
59 #include <media/mt9p012.h>
60 static enum v4l2_power mt9p012_previous_power = V4L2_POWER_OFF;
62 #define MT9P012_BIGGEST_FRAME_BYTE_SIZE PAGE_ALIGN(2592 * 1944 * 2)
64 #ifdef CONFIG_VIDEO_DW9710
65 #include <media/dw9710.h>
66 #define is_dw9710_enabled() 1
67 #else
68 #define is_dw9710_enabled() 0
69 #endif /* CONFIG_VIDEO_DW9710 */
71 #if defined(CONFIG_VIDEO_TPS61059) || defined(CONFIG_VIDEO_TPS61059_MODULE)
72 #include <media/tps61059.h>
73 #define is_tps61059_enabled() 1
74 #else
75 #define is_tps61059_enabled() 0
76 #endif /* CONFIG_VIDEO_TPS61059 || CONFIG_VIDEO_TPS61059_MODULE */
78 #define is_mt9p012_enabled() 1
79 #else /* CONFIG_VIDEO_MT9P012 || CONFIG_VIDEO_MT9P012_MODULE */
80 #define is_mt9p012_enabled() 0
81 #define is_dw9710_enabled() 0
82 #define is_tps61059_enabled() 0
83 #endif /* CONFIG_VIDEO_MT9P012 || CONFIG_VIDEO_MT9P012_MODULE */
85 #if defined(CONFIG_VIDEO_OV3640) || defined(CONFIG_VIDEO_OV3640_MODULE)
86 #include <media/ov3640.h>
87 #include <../drivers/media/video/isp/ispcsi2.h>
88 #define OV3640_CSI2_CLOCK_POLARITY 0 /* +/- pin order */
89 #define OV3640_CSI2_DATA0_POLARITY 0 /* +/- pin order */
90 #define OV3640_CSI2_DATA1_POLARITY 0 /* +/- pin order */
91 #define OV3640_CSI2_CLOCK_LANE 1 /* Clock lane position: 1 */
92 #define OV3640_CSI2_DATA0_LANE 2 /* Data0 lane position: 2 */
93 #define OV3640_CSI2_DATA1_LANE 3 /* Data1 lane position: 3 */
94 #define OV3640_CSI2_PHY_THS_TERM 4
95 #define OV3640_CSI2_PHY_THS_SETTLE 14
96 #define OV3640_CSI2_PHY_TCLK_TERM 0
97 #define OV3640_CSI2_PHY_TCLK_MISS 1
98 #define OV3640_CSI2_PHY_TCLK_SETTLE 14
100 #define OV3640_BIGGEST_FRAME_BYTE_SIZE PAGE_ALIGN(2048 * 1536 * 2)
101 #define is_ov3640_enabled() 1
102 #else
103 #define is_ov3640_enabled() 0
104 #endif /* CONFIG_VIDEO_OV3640 || CONFIG_VIDEO_OV3640_MODULE */
106 #if defined(CONFIG_VIDEO_MT9P012) || defined(CONFIG_VIDEO_MT9P012_MODULE) || \
107 defined(CONFIG_VIDEO_OV3640) || defined(CONFIG_VIDEO_OV3640_MODULE) || \
108 defined(CONFIG_VIDEO_DW9710)
110 static void enable_fpga_vio_1v8(u8 enable)
112 void __iomem *fpga_map_addr;
113 u16 reg_val;
115 fpga_map_addr = ioremap(DEBUG_BASE, 4096);
116 reg_val = readw(fpga_map_addr + REG_SDP3430_FPGA_GPIO_2);
118 /* Ensure that the SPR_GPIO1_3v3 is 0 - powered off.. 1 is on */
119 if (reg_val & FPGA_SPR_GPIO1_3v3) {
120 reg_val |= FPGA_SPR_GPIO1_3v3;
121 reg_val |= FPGA_GPIO6_DIR_CTRL; /* output mode */
122 writew(reg_val, fpga_map_addr + REG_SDP3430_FPGA_GPIO_2);
123 /* give a few milli sec to settle down
124 * Let the sensor also settle down.. if required..
126 if (enable)
127 mdelay(10);
130 if (enable) {
131 reg_val |= FPGA_SPR_GPIO1_3v3 | FPGA_GPIO6_DIR_CTRL;
132 writew(reg_val, fpga_map_addr + REG_SDP3430_FPGA_GPIO_2);
134 iounmap(fpga_map_addr);
135 /* Vrise time for the voltage - should be less than 1 ms */
136 mdelay(1);
138 #endif
140 #if defined(CONFIG_VIDEO_MT9P012) || defined(CONFIG_VIDEO_MT9P012_MODULE)
141 #ifdef CONFIG_VIDEO_DW9710
142 static int dw9710_lens_power_set(enum v4l2_power power)
144 if (!cam_inited) {
145 printk(KERN_ERR "DW9710: Unable to control board GPIOs!\n");
146 return -EFAULT;
149 /* The power change depends on MT9P012 powerup GPIO, so if we request a
150 * power state different from sensor, we should return error
152 if ((mt9p012_previous_power != V4L2_POWER_OFF) &&
153 (power != mt9p012_previous_power))
154 return -EIO;
156 * Plug regulator consumer to respective VAUX supply
157 * if not done before.
159 if (!sdp3430_dw9710_reg) {
160 sdp3430_dw9710_reg = regulator_get(camkit_dev, "vaux2_2");
161 if (IS_ERR(sdp3430_dw9710_reg)) {
162 dev_err(camkit_dev, "vaux2_2 regulator missing\n");
163 return PTR_ERR(sdp3430_dw9710_reg);
167 if (!sdp3430_dw9710_reg) {
168 sdp3430_dw9710_reg = regulator_get(camkit_dev, "vaux2_2");
169 if (IS_ERR(sdp3430_dw9710_reg)) {
170 dev_err(camkit_dev, "vaux2_2 regulator missing\n");
171 return PTR_ERR(sdp3430_dw9710_reg);
175 switch (power) {
176 case V4L2_POWER_OFF:
177 /* Power Down Sequence */
178 if (regulator_is_enabled(sdp3430_dw9710_reg))
179 regulator_disable(sdp3430_dw9710_reg);
180 enable_fpga_vio_1v8(0);
181 break;
182 case V4L2_POWER_ON:
183 /* STANDBY_GPIO is active HIGH for set LOW to release */
184 gpio_set_value(MT9P012_STANDBY_GPIO, 1);
186 /* nRESET is active LOW. set HIGH to release reset */
187 gpio_set_value(CAMKITV3_RESET_GPIO, 1);
189 /* turn on digital power */
190 enable_fpga_vio_1v8(1);
192 /* turn on analog power */
193 regulator_enable(sdp3430_dw9710_reg);
195 /* out of standby */
196 gpio_set_value(MT9P012_STANDBY_GPIO, 0);
197 udelay(1000);
199 /* have to put sensor to reset to guarantee detection */
200 gpio_set_value(CAMKITV3_RESET_GPIO, 0);
202 udelay(1500);
204 /* nRESET is active LOW. set HIGH to release reset */
205 gpio_set_value(CAMKITV3_RESET_GPIO, 1);
206 /* give sensor sometime to get out of the reset.
207 * Datasheet says 2400 xclks. At 6 MHz, 400 usec is
208 * enough
210 udelay(300);
211 break;
212 case V4L2_POWER_STANDBY:
213 break;
215 return 0;
218 static int dw9710_lens_set_prv_data(void *priv)
220 struct omap34xxcam_hw_config *hwc = priv;
222 hwc->dev_index = 0;
223 hwc->dev_minor = 0;
224 hwc->dev_type = OMAP34XXCAM_SLAVE_LENS;
226 return 0;
229 struct dw9710_platform_data sdp3430_dw9710_platform_data = {
230 .power_set = dw9710_lens_power_set,
231 .priv_data_set = dw9710_lens_set_prv_data,
233 #endif
235 #if defined(CONFIG_VIDEO_TPS61059) || defined(CONFIG_VIDEO_TPS61059_MODULE)
236 static void tps61059_flash_on(void)
238 gpio_set_value(TPS61059_TORCH_EN_GPIO, 1);
239 gpio_set_value(TPS61059_FLASH_STROBE_GPIO, 1);
242 static void tps61059_flash_off(void)
244 gpio_set_value(TPS61059_FLASH_STROBE_GPIO, 0);
245 gpio_set_value(TPS61059_TORCH_EN_GPIO, 0);
248 static void tps61059_s_torch_intensity(u32 value)
250 if (value > 0) {
251 /* Torch mode, light immediately on, duration indefinite */
252 gpio_set_value(TPS61059_TORCH_EN_GPIO, 1);
253 } else {
254 /* Torch mode off */
255 gpio_set_value(TPS61059_TORCH_EN_GPIO, 0);
259 static int tps61059_set_prv_data(void *priv)
261 struct omap34xxcam_hw_config *hwc = priv;
263 hwc->dev_index = 0;
264 hwc->dev_minor = 0;
265 hwc->dev_type = OMAP34XXCAM_SLAVE_FLASH;
267 return 0;
270 struct tps61059_platform_data sdp3430_tps61059_data = {
271 .flash_on = tps61059_flash_on,
272 .flash_off = tps61059_flash_off,
273 .s_torch_intensity = tps61059_s_torch_intensity,
274 .priv_data_set = tps61059_set_prv_data,
277 #endif
279 static struct omap34xxcam_sensor_config cam_hwc = {
280 .sensor_isp = 0,
281 .capture_mem = MT9P012_BIGGEST_FRAME_BYTE_SIZE * 4,
282 .ival_default = { 1, 10 },
285 static int mt9p012_sensor_set_prv_data(struct v4l2_int_device *s, void *priv)
287 struct omap34xxcam_hw_config *hwc = priv;
289 hwc->u.sensor.sensor_isp = cam_hwc.sensor_isp;
290 hwc->u.sensor.capture_mem = cam_hwc.capture_mem;
291 hwc->dev_index = 0;
292 hwc->dev_minor = 0;
293 hwc->dev_type = OMAP34XXCAM_SLAVE_SENSOR;
294 return 0;
297 static struct isp_interface_config mt9p012_if_config = {
298 .ccdc_par_ser = ISP_PARLL,
299 .dataline_shift = 0x1,
300 .hsvs_syncdetect = ISPCTRL_SYNC_DETECT_VSRISE,
301 .strobe = 0x0,
302 .prestrobe = 0x0,
303 .shutter = 0x0,
304 .prev_sph = 2,
305 .prev_slv = 0,
306 .wenlog = ISPCCDC_CFG_WENLOG_AND,
307 .wait_hs_vs = 2,
308 .u.par.par_bridge = 0x0,
309 .u.par.par_clk_pol = 0x0,
312 static int mt9p012_sensor_power_set(struct v4l2_int_device *s,
313 enum v4l2_power power)
315 struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
317 if (!cam_inited) {
318 printk(KERN_ERR "MT9P012: Unable to control board GPIOs!\n");
319 return -EFAULT;
323 * Plug regulator consumer to respective VAUX supply
324 * if not done before.
326 if (!sdp3430_mt9p012_reg) {
327 sdp3430_mt9p012_reg = regulator_get(camkit_dev, "vaux2_1");
328 if (IS_ERR(sdp3430_mt9p012_reg)) {
329 dev_err(camkit_dev, "vaux2_1 regulator missing\n");
330 return PTR_ERR(sdp3430_mt9p012_reg);
334 switch (power) {
335 case V4L2_POWER_OFF:
336 /* Power Down Sequence */
337 if (regulator_is_enabled(sdp3430_mt9p012_reg))
338 regulator_disable(sdp3430_mt9p012_reg);
339 enable_fpga_vio_1v8(0);
341 #ifdef CONFIG_OMAP_PM_SRF
342 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 0);
343 #endif
344 break;
345 case V4L2_POWER_ON:
347 #ifdef CONFIG_OMAP_PM_SRF
348 /* Through-put requirement:
349 * 2592 x 1944 x 2Bpp x 11fps x 3 memory ops = 324770 KByte/s
351 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 324770);
352 #endif
354 if (mt9p012_previous_power == V4L2_POWER_OFF) {
355 /* Power Up Sequence */
356 isp_configure_interface(vdev->cam->isp,
357 &mt9p012_if_config);
359 /* set to output mode */
360 gpio_direction_output(MT9P012_STANDBY_GPIO, true);
361 /* set to output mode */
362 gpio_direction_output(CAMKITV3_RESET_GPIO, true);
364 /* STANDBY_GPIO is active HIGH for set LOW to release */
365 gpio_set_value(MT9P012_STANDBY_GPIO, 1);
367 /* nRESET is active LOW. set HIGH to release reset */
368 gpio_set_value(CAMKITV3_RESET_GPIO, 1);
370 /* turn on digital power */
371 enable_fpga_vio_1v8(1);
373 /* turn on analog power */
374 regulator_enable(sdp3430_mt9p012_reg);
377 /* out of standby */
378 gpio_set_value(MT9P012_STANDBY_GPIO, 0);
379 udelay(1000);
381 if (mt9p012_previous_power == V4L2_POWER_OFF) {
382 /* have to put sensor to reset to guarantee detection */
383 gpio_set_value(CAMKITV3_RESET_GPIO, 0);
385 udelay(1500);
387 /* nRESET is active LOW. set HIGH to release reset */
388 gpio_set_value(CAMKITV3_RESET_GPIO, 1);
389 /* give sensor sometime to get out of the reset.
390 * Datasheet says 2400 xclks. At 6 MHz, 400 usec is
391 * enough
393 udelay(300);
395 break;
396 case V4L2_POWER_STANDBY:
397 /* stand by */
398 gpio_set_value(MT9P012_STANDBY_GPIO, 1);
399 #ifdef CONFIG_OMAP_PM_SRF
400 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 0);
401 #endif
402 break;
404 /* Save powerstate to know what was before calling POWER_ON. */
405 mt9p012_previous_power = power;
406 return 0;
409 static u32 mt9p012_sensor_set_xclk(struct v4l2_int_device *s, u32 xclkfreq)
411 struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
413 return isp_set_xclk(vdev->cam->isp, xclkfreq, CAMKITV3_USE_XCLKA);
416 struct mt9p012_platform_data sdp3430_mt9p012_platform_data = {
417 .power_set = mt9p012_sensor_power_set,
418 .priv_data_set = mt9p012_sensor_set_prv_data,
419 .set_xclk = mt9p012_sensor_set_xclk,
422 #endif
424 #if defined(CONFIG_VIDEO_OV3640) || defined(CONFIG_VIDEO_OV3640_MODULE)
426 static struct omap34xxcam_sensor_config ov3640_hwc = {
427 .sensor_isp = 0,
428 .capture_mem = OV3640_BIGGEST_FRAME_BYTE_SIZE * 2,
429 .ival_default = { 1, 15 },
432 static struct isp_interface_config ov3640_if_config = {
433 .ccdc_par_ser = ISP_CSIA,
434 .dataline_shift = 0x0,
435 .hsvs_syncdetect = ISPCTRL_SYNC_DETECT_VSRISE,
436 .strobe = 0x0,
437 .prestrobe = 0x0,
438 .shutter = 0x0,
439 .prev_sph = 2,
440 .prev_slv = 0,
441 .wenlog = ISPCCDC_CFG_WENLOG_AND,
442 .wait_hs_vs = 2,
443 .u.csi.crc = 0x0,
444 .u.csi.mode = 0x0,
445 .u.csi.edge = 0x0,
446 .u.csi.signalling = 0x0,
447 .u.csi.strobe_clock_inv = 0x0,
448 .u.csi.vs_edge = 0x0,
449 .u.csi.channel = 0x1,
450 .u.csi.vpclk = 0x1,
451 .u.csi.data_start = 0x0,
452 .u.csi.data_size = 0x0,
453 .u.csi.format = V4L2_PIX_FMT_SGRBG10,
456 static int ov3640_sensor_set_prv_data(struct v4l2_int_device *s, void *priv)
458 struct omap34xxcam_hw_config *hwc = priv;
460 hwc->u.sensor.sensor_isp = ov3640_hwc.sensor_isp;
461 hwc->u.sensor.capture_mem = ov3640_hwc.capture_mem;
462 hwc->dev_index = 1;
463 hwc->dev_minor = 4;
464 hwc->dev_type = OMAP34XXCAM_SLAVE_SENSOR;
465 return 0;
468 static int ov3640_sensor_power_set(struct v4l2_int_device *s,
469 enum v4l2_power power)
471 struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
472 struct isp_csi2_lanes_cfg lanecfg;
473 struct isp_csi2_phy_cfg phyconfig;
474 static enum v4l2_power previous_power = V4L2_POWER_OFF;
476 if (!cam_inited) {
477 printk(KERN_ERR "OV3640: Unable to control board GPIOs!\n");
478 return -EFAULT;
482 * Plug regulator consumer to respective VAUX supply
483 * if not done before.
485 if (!sdp3430_ov3640_reg) {
486 #if defined(CONFIG_VIDEO_OV3640_CSI2)
487 sdp3430_ov3640_reg = regulator_get(camkit_dev, "vaux4_1");
488 if (IS_ERR(sdp3430_ov3640_reg)) {
489 dev_err(camkit_dev, "vaux4_1 regulator missing\n");
490 return PTR_ERR(sdp3430_ov3640_reg);
492 #else
493 sdp3430_ov3640_reg = regulator_get(camkit_dev, "vaux2_3");
494 if (IS_ERR(sdp3430_ov3640_reg)) {
495 dev_err(camkit_dev, "vaux2_3 regulator missing\n");
496 return PTR_ERR(sdp3430_ov3640_reg);
498 #endif
501 switch (power) {
502 case V4L2_POWER_ON:
503 #ifdef CONFIG_OMAP_PM_SRF
504 /* Through-put requirement:
505 * 2048 x 1536 x 2Bpp x 7.5fps x 3 memory ops = 138240 KByte/s
507 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 138240);
508 #endif
509 if (previous_power == V4L2_POWER_OFF)
510 isp_csi2_reset();
512 lanecfg.clk.pol = OV3640_CSI2_CLOCK_POLARITY;
513 lanecfg.clk.pos = OV3640_CSI2_CLOCK_LANE;
514 lanecfg.data[0].pol = OV3640_CSI2_DATA0_POLARITY;
515 lanecfg.data[0].pos = OV3640_CSI2_DATA0_LANE;
516 lanecfg.data[1].pol = OV3640_CSI2_DATA1_POLARITY;
517 lanecfg.data[1].pos = OV3640_CSI2_DATA1_LANE;
518 lanecfg.data[2].pol = 0;
519 lanecfg.data[2].pos = 0;
520 lanecfg.data[3].pol = 0;
521 lanecfg.data[3].pos = 0;
522 isp_csi2_complexio_lanes_config(&lanecfg);
523 isp_csi2_complexio_lanes_update(true);
525 phyconfig.ths_term = OV3640_CSI2_PHY_THS_TERM;
526 phyconfig.ths_settle = OV3640_CSI2_PHY_THS_SETTLE;
527 phyconfig.tclk_term = OV3640_CSI2_PHY_TCLK_TERM;
528 phyconfig.tclk_miss = OV3640_CSI2_PHY_TCLK_MISS;
529 phyconfig.tclk_settle = OV3640_CSI2_PHY_TCLK_SETTLE;
530 isp_csi2_phy_config(&phyconfig);
531 isp_csi2_phy_update(true);
533 isp_configure_interface(vdev->cam->isp, &ov3640_if_config);
535 if (previous_power == V4L2_POWER_OFF) {
536 /* turn on analog power */
537 regulator_enable(sdp3430_ov3640_reg);
538 udelay(100);
540 /* Turn ON Omnivision sensor */
541 gpio_set_value(CAMKITV3_RESET_GPIO, 1);
542 gpio_set_value(OV3640_STANDBY_GPIO, 0);
543 udelay(100);
545 /* RESET Omnivision sensor */
546 gpio_set_value(CAMKITV3_RESET_GPIO, 0);
547 udelay(100);
548 gpio_set_value(CAMKITV3_RESET_GPIO, 1);
550 /* Wait 10 ms */
551 mdelay(10);
552 enable_fpga_vio_1v8(1);
553 udelay(100);
555 break;
556 case V4L2_POWER_OFF:
557 /* Power Down Sequence */
558 isp_csi2_complexio_power(ISP_CSI2_POWER_OFF);
559 if (regulator_is_enabled(sdp3430_ov3640_reg))
560 regulator_disable(sdp3430_ov3640_reg);
561 enable_fpga_vio_1v8(0);
562 #ifdef CONFIG_OMAP_PM_SRF
563 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 0);
564 #endif
565 break;
566 case V4L2_POWER_STANDBY:
567 #ifdef CONFIG_OMAP_PM_SRF
568 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 0);
569 #endif
570 break;
572 previous_power = power;
573 return 0;
576 static u32 ov3640_sensor_set_xclk(struct v4l2_int_device *s, u32 xclkfreq)
578 struct omap34xxcam_videodev *vdev = s->u.slave->master->priv;
580 return isp_set_xclk(vdev->cam->isp, xclkfreq, CAMKITV3_USE_XCLKB);
583 struct ov3640_platform_data sdp3430_ov3640_platform_data = {
584 .power_set = ov3640_sensor_power_set,
585 .priv_data_set = ov3640_sensor_set_prv_data,
586 .set_xclk = ov3640_sensor_set_xclk,
589 #endif
591 static int sdp3430_camkit_probe(struct platform_device *pdev)
593 int ret = 0;
595 if (!is_mt9p012_enabled() && !is_ov3640_enabled())
596 return -ENODEV;
598 /* Request and configure shared gpio pins for both cameras */
599 if (is_mt9p012_enabled() || is_ov3640_enabled()) {
600 if (gpio_request(CAMKITV3_RESET_GPIO,
601 "camkitv3_reset_gpio") != 0) {
602 dev_err(&pdev->dev, "Could not request GPIO %d",
603 CAMKITV3_RESET_GPIO);
604 ret = -ENODEV;
605 goto err;
607 gpio_direction_output(CAMKITV3_RESET_GPIO, false);
610 /* Request and configure shared gpio pins for primary camera */
611 if (is_mt9p012_enabled()) {
612 if (gpio_request(MT9P012_STANDBY_GPIO,
613 "mt9p012_standby_gpio")) {
614 dev_err(&pdev->dev,
615 "Could not request GPIO %d for MT9P012\n",
616 MT9P012_STANDBY_GPIO);
617 ret = -ENODEV;
618 goto err_freegpio1;
621 gpio_direction_output(MT9P012_STANDBY_GPIO, false);
623 if (is_tps61059_enabled()) {
624 /* Configure pin MUX for GPIO 126 for TPS61059 flash */
625 omap_cfg_reg(D25_34XX_GPIO126_OUT);
627 if (gpio_request(TPS61059_TORCH_EN_GPIO,
628 "tps61059_torch_en_gpio")) {
629 dev_err(&pdev->dev,
630 "Could not request GPIO %d for"
631 " TPS61059\n",
632 TPS61059_TORCH_EN_GPIO);
633 ret = -ENODEV;
634 goto err_freegpio2;
637 if (gpio_request(TPS61059_FLASH_STROBE_GPIO,
638 "tps61059_flash_strobe_gpio")) {
639 dev_err(&pdev->dev,
640 "Could not request GPIO %d for"
641 " TPS61059\n",
642 TPS61059_FLASH_STROBE_GPIO);
643 ret = -ENODEV;
644 goto err_freegpio3;
646 gpio_direction_output(TPS61059_TORCH_EN_GPIO, false);
647 gpio_direction_output(TPS61059_FLASH_STROBE_GPIO,
648 false);
652 /* Request and configure shared gpio pins for secondary camera */
653 if (is_ov3640_enabled()) {
654 if (gpio_request(OV3640_STANDBY_GPIO,
655 "ov3640_standby_gpio") != 0) {
656 dev_err(&pdev->dev, "Could not request GPIO %d",
657 OV3640_STANDBY_GPIO);
658 ret = -ENODEV;
659 goto err_freegpio4;
661 gpio_direction_output(OV3640_STANDBY_GPIO, false);
664 cam_inited = 1;
665 camkit_dev = &pdev->dev;
666 return 0;
668 err_freegpio4:
669 if (is_mt9p012_enabled() && is_tps61059_enabled())
670 gpio_free(TPS61059_FLASH_STROBE_GPIO);
671 err_freegpio3:
672 if (is_mt9p012_enabled() && is_tps61059_enabled())
673 gpio_free(TPS61059_TORCH_EN_GPIO);
674 err_freegpio2:
675 if (is_mt9p012_enabled())
676 gpio_free(MT9P012_STANDBY_GPIO);
677 err_freegpio1:
678 if (is_mt9p012_enabled() || is_ov3640_enabled())
679 gpio_free(CAMKITV3_RESET_GPIO);
680 err:
681 cam_inited = 0;
682 return ret;
685 static int sdp3430_camkit_remove(struct platform_device *pdev)
687 /* Primary camera resources */
688 if (is_mt9p012_enabled()) {
689 /* Free Regulators */
690 if (is_dw9710_enabled()) {
691 if (regulator_is_enabled(sdp3430_dw9710_reg))
692 regulator_disable(sdp3430_dw9710_reg);
693 regulator_put(sdp3430_dw9710_reg);
696 if (regulator_is_enabled(sdp3430_mt9p012_reg))
697 regulator_disable(sdp3430_mt9p012_reg);
698 regulator_put(sdp3430_mt9p012_reg);
700 /* Free GPIOs */
701 if (is_tps61059_enabled()) {
702 gpio_free(TPS61059_FLASH_STROBE_GPIO);
703 gpio_free(TPS61059_TORCH_EN_GPIO);
705 gpio_free(MT9P012_STANDBY_GPIO);
708 /* Secondary camera resources */
709 if (is_ov3640_enabled()) {
710 /* Free Regulators */
711 if (regulator_is_enabled(sdp3430_ov3640_reg))
712 regulator_disable(sdp3430_ov3640_reg);
713 regulator_put(sdp3430_ov3640_reg);
715 /* Free GPIOs */
716 gpio_free(OV3640_STANDBY_GPIO);
719 /* Shared resources to free */
720 if (is_mt9p012_enabled() || is_ov3640_enabled())
721 gpio_free(CAMKITV3_RESET_GPIO);
722 return 0;
725 static int sdp3430_camkit_suspend(struct device *dev)
727 return 0;
730 static int sdp3430_camkit_resume(struct device *dev)
732 return 0;
735 static struct dev_pm_ops sdp3430_camkit_pm_ops = {
736 .suspend = sdp3430_camkit_suspend,
737 .resume = sdp3430_camkit_resume,
740 static struct platform_driver sdp3430_camkit_driver = {
741 .probe = sdp3430_camkit_probe,
742 .remove = sdp3430_camkit_remove,
743 .driver = {
744 .name = "sdp3430_camkit",
745 .pm = &sdp3430_camkit_pm_ops,
749 void __init sdp3430_cam_init(void)
751 cam_inited = 0;
752 platform_driver_register(&sdp3430_camkit_driver);