2 * linux/arch/arm/mach-omap2/board-zoom2-camera.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>
20 #include <linux/regulator/consumer.h>
24 #include <mach/gpio.h>
25 #ifdef CONFIG_OMAP_PM_SRF
26 #include <mach/omap-pm.h>
29 static int cam_inited
;
31 static struct device
*zoom2cam_dev
;
33 #include <media/v4l2-int-device.h>
34 #include <../drivers/media/video/omap34xxcam.h>
35 #include <../drivers/media/video/isp/ispreg.h>
36 #define DEBUG_BASE 0x08000000
38 #define REG_SDP3430_FPGA_GPIO_2 (0x50)
39 #define FPGA_SPR_GPIO1_3v3 (0x1 << 14)
40 #define FPGA_GPIO6_DIR_CTRL (0x1 << 6)
42 #define CAMZOOM2_USE_XCLKB 1
44 /* Sensor specific GPIO signals */
45 #define IMX046_RESET_GPIO 98
46 #define IMX046_STANDBY_GPIO 58
47 #define LV8093_PS_GPIO 7
49 static struct regulator
*zoom2_imx046_reg1
;
50 static struct regulator
*zoom2_imx046_reg2
;
52 #if defined(CONFIG_VIDEO_IMX046) || defined(CONFIG_VIDEO_IMX046_MODULE)
53 #include <media/imx046.h>
54 #include <../drivers/media/video/isp/ispcsi2.h>
55 #define IMX046_CSI2_CLOCK_POLARITY 0 /* +/- pin order */
56 #define IMX046_CSI2_DATA0_POLARITY 0 /* +/- pin order */
57 #define IMX046_CSI2_DATA1_POLARITY 0 /* +/- pin order */
58 #define IMX046_CSI2_CLOCK_LANE 1 /* Clock lane position: 1 */
59 #define IMX046_CSI2_DATA0_LANE 2 /* Data0 lane position: 2 */
60 #define IMX046_CSI2_DATA1_LANE 3 /* Data1 lane position: 3 */
61 #define IMX046_CSI2_PHY_THS_TERM 2
62 #define IMX046_CSI2_PHY_THS_SETTLE 23
63 #define IMX046_CSI2_PHY_TCLK_TERM 0
64 #define IMX046_CSI2_PHY_TCLK_MISS 1
65 #define IMX046_CSI2_PHY_TCLK_SETTLE 14
66 #define IMX046_BIGGEST_FRAME_BYTE_SIZE PAGE_ALIGN(3280 * 2464 * 2)
69 #ifdef CONFIG_VIDEO_LV8093
70 #include <media/lv8093.h>
71 /* GPIO7 is connected to lens PS pin through inverter */
72 #define LV8093_PWR_OFF 1
73 #define LV8093_PWR_ON (!LV8093_PWR_OFF)
77 #ifdef CONFIG_VIDEO_LV8093
78 static int lv8093_lens_power_set(enum v4l2_power power
)
80 static enum v4l2_power previous_pwr
= V4L2_POWER_OFF
;
83 printk(KERN_ERR
"MT9P012: Unable to control board GPIOs!\n");
89 printk(KERN_DEBUG
"lv8093_lens_power_set(ON)\n");
90 if (previous_pwr
== V4L2_POWER_OFF
)
91 gpio_set_value(LV8093_PS_GPIO
, LV8093_PWR_OFF
);
92 gpio_set_value(LV8093_PS_GPIO
, LV8093_PWR_ON
);
95 printk(KERN_DEBUG
"lv8093_lens_power_set(OFF)\n");
97 case V4L2_POWER_STANDBY
:
98 printk(KERN_DEBUG
"lv8093_lens_power_set(STANDBY)\n");
99 gpio_set_value(LV8093_PS_GPIO
, LV8093_PWR_OFF
);
102 previous_pwr
= power
;
106 static int lv8093_lens_set_prv_data(void *priv
)
108 struct omap34xxcam_hw_config
*hwc
= priv
;
112 hwc
->dev_type
= OMAP34XXCAM_SLAVE_LENS
;
116 struct lv8093_platform_data zoom2_lv8093_platform_data
= {
117 .power_set
= lv8093_lens_power_set
,
118 .priv_data_set
= lv8093_lens_set_prv_data
,
122 #if defined(CONFIG_VIDEO_IMX046) || defined(CONFIG_VIDEO_IMX046_MODULE)
124 static struct omap34xxcam_sensor_config imx046_hwc
= {
126 .capture_mem
= IMX046_BIGGEST_FRAME_BYTE_SIZE
* 2,
127 .ival_default
= { 1, 10 },
130 static int imx046_sensor_set_prv_data(struct v4l2_int_device
*s
, void *priv
)
132 struct omap34xxcam_hw_config
*hwc
= priv
;
134 hwc
->u
.sensor
.sensor_isp
= imx046_hwc
.sensor_isp
;
137 hwc
->dev_type
= OMAP34XXCAM_SLAVE_SENSOR
;
142 static struct isp_interface_config imx046_if_config
= {
143 .ccdc_par_ser
= ISP_CSIA
,
144 .dataline_shift
= 0x0,
145 .hsvs_syncdetect
= ISPCTRL_SYNC_DETECT_VSRISE
,
149 .wenlog
= ISPCCDC_CFG_WENLOG_AND
,
154 .u
.csi
.signalling
= 0x0,
155 .u
.csi
.strobe_clock_inv
= 0x0,
156 .u
.csi
.vs_edge
= 0x0,
157 .u
.csi
.channel
= 0x0,
159 .u
.csi
.data_start
= 0x0,
160 .u
.csi
.data_size
= 0x0,
161 .u
.csi
.format
= V4L2_PIX_FMT_SGRBG10
,
165 static int imx046_sensor_power_set(struct v4l2_int_device
*s
, enum v4l2_power power
)
167 struct omap34xxcam_videodev
*vdev
= s
->u
.slave
->master
->priv
;
168 struct isp_csi2_lanes_cfg lanecfg
;
169 struct isp_csi2_phy_cfg phyconfig
;
170 static enum v4l2_power previous_power
= V4L2_POWER_OFF
;
174 printk(KERN_ERR
"MT9P012: Unable to control board GPIOs!\n");
179 * Plug regulator consumer to respective VAUX supply
180 * if not done before.
182 if (!zoom2_imx046_reg1
&& !zoom2_imx046_reg2
) {
183 zoom2_imx046_reg1
= regulator_get(zoom2cam_dev
, "vaux2_1");
184 if (IS_ERR(zoom2_imx046_reg1
)) {
185 dev_err(zoom2cam_dev
, "vaux2_1 regulator missing\n");
186 return PTR_ERR(zoom2_imx046_reg1
);
188 zoom2_imx046_reg2
= regulator_get(zoom2cam_dev
, "vaux4_1");
189 if (IS_ERR(zoom2_imx046_reg2
)) {
190 dev_err(zoom2cam_dev
, "vaux4_1 regulator missing\n");
191 regulator_put(zoom2_imx046_reg1
);
192 return PTR_ERR(zoom2_imx046_reg2
);
198 /* Power Up Sequence */
199 printk(KERN_DEBUG
"imx046_sensor_power_set(ON)\n");
201 /* Through-put requirement:
202 * 3280 x 2464 x 2Bpp x 7.5fps x 3 memory ops = 355163 KByte/s
204 #ifdef CONFIG_OMAP_PM_SRF
205 omap_pm_set_min_bus_tput(vdev
->cam
->isp
, OCP_INITIATOR_AGENT
, 355163);
210 lanecfg
.clk
.pol
= IMX046_CSI2_CLOCK_POLARITY
;
211 lanecfg
.clk
.pos
= IMX046_CSI2_CLOCK_LANE
;
212 lanecfg
.data
[0].pol
= IMX046_CSI2_DATA0_POLARITY
;
213 lanecfg
.data
[0].pos
= IMX046_CSI2_DATA0_LANE
;
214 lanecfg
.data
[1].pol
= IMX046_CSI2_DATA1_POLARITY
;
215 lanecfg
.data
[1].pos
= IMX046_CSI2_DATA1_LANE
;
216 lanecfg
.data
[2].pol
= 0;
217 lanecfg
.data
[2].pos
= 0;
218 lanecfg
.data
[3].pol
= 0;
219 lanecfg
.data
[3].pos
= 0;
220 isp_csi2_complexio_lanes_config(&lanecfg
);
221 isp_csi2_complexio_lanes_update(true);
223 isp_csi2_ctrl_config_ecc_enable(true);
225 phyconfig
.ths_term
= IMX046_CSI2_PHY_THS_TERM
;
226 phyconfig
.ths_settle
= IMX046_CSI2_PHY_THS_SETTLE
;
227 phyconfig
.tclk_term
= IMX046_CSI2_PHY_TCLK_TERM
;
228 phyconfig
.tclk_miss
= IMX046_CSI2_PHY_TCLK_MISS
;
229 phyconfig
.tclk_settle
= IMX046_CSI2_PHY_TCLK_SETTLE
;
230 isp_csi2_phy_config(&phyconfig
);
231 isp_csi2_phy_update(true);
233 isp_configure_interface(vdev
->cam
->isp
, &imx046_if_config
);
235 if (previous_power
== V4L2_POWER_OFF
) {
236 /* nRESET is active LOW. set HIGH to release reset */
237 gpio_set_value(IMX046_RESET_GPIO
, 1);
240 /* turn on analog power */
241 regulator_enable(zoom2_imx046_reg1
);
242 regulator_enable(zoom2_imx046_reg2
);
245 /* have to put sensor to reset to guarantee detection */
246 gpio_set_value(IMX046_RESET_GPIO
, 0);
249 /* nRESET is active LOW. set HIGH to release reset */
250 gpio_set_value(IMX046_RESET_GPIO
, 1);
255 printk(KERN_DEBUG
"imx046_sensor_power_set(OFF)\n");
256 /* Power Down Sequence */
257 isp_csi2_complexio_power(ISP_CSI2_POWER_OFF
);
259 if (regulator_is_enabled(zoom2_imx046_reg1
))
260 regulator_disable(zoom2_imx046_reg1
);
261 if (regulator_is_enabled(zoom2_imx046_reg2
))
262 regulator_disable(zoom2_imx046_reg2
);
264 #ifdef CONFIG_OMAP_PM_SRF
265 omap_pm_set_min_bus_tput(vdev
->cam
->isp
, OCP_INITIATOR_AGENT
, 0);
268 case V4L2_POWER_STANDBY
:
269 printk(KERN_DEBUG
"imx046_sensor_power_set(STANDBY)\n");
270 isp_csi2_complexio_power(ISP_CSI2_POWER_OFF
);
272 #ifdef CONFIG_OMAP_PM_SRF
273 omap_pm_set_min_bus_tput(vdev
->cam
->isp
, OCP_INITIATOR_AGENT
, 0);
278 /* Save powerstate to know what was before calling POWER_ON. */
279 previous_power
= power
;
283 static u32
imx046_sensor_set_xclk(struct v4l2_int_device
*s
, u32 xclkfreq
)
285 struct omap34xxcam_videodev
*vdev
= s
->u
.slave
->master
->priv
;
287 return isp_set_xclk(vdev
->cam
->isp
, xclkfreq
, CAMZOOM2_USE_XCLKB
);
290 struct imx046_platform_data zoom2_imx046_platform_data
= {
291 .power_set
= imx046_sensor_power_set
,
292 .priv_data_set
= imx046_sensor_set_prv_data
,
293 .set_xclk
= imx046_sensor_set_xclk
,
294 .csi2_lane_count
= isp_csi2_complexio_lanes_count
,
295 .csi2_cfg_vp_out_ctrl
= isp_csi2_ctrl_config_vp_out_ctrl
,
296 .csi2_ctrl_update
= isp_csi2_ctrl_update
,
297 .csi2_cfg_virtual_id
= isp_csi2_ctx_config_virtual_id
,
298 .csi2_ctx_update
= isp_csi2_ctx_update
,
299 .csi2_calc_phy_cfg0
= isp_csi2_calc_phy_cfg0
,
303 static int zoom2_cam_probe(struct platform_device
*pdev
)
307 /* Request and configure gpio pins */
308 if (gpio_request(IMX046_STANDBY_GPIO
, "imx046_standby_gpio") != 0) {
309 dev_err(&pdev
->dev
, "Could not request GPIO %d",
310 IMX046_STANDBY_GPIO
);
315 if (gpio_request(IMX046_RESET_GPIO
, "imx046_rst") != 0) {
316 dev_err(&pdev
->dev
, "Could not request GPIO %d",
322 if (gpio_request(LV8093_PS_GPIO
, "lv8093_ps") != 0) {
323 dev_err(&pdev
->dev
, "Could not request GPIO %d",
329 /* set to output mode */
330 gpio_direction_output(IMX046_STANDBY_GPIO
, true);
331 gpio_direction_output(IMX046_RESET_GPIO
, true);
332 gpio_direction_output(LV8093_PS_GPIO
, true);
335 zoom2cam_dev
= &pdev
->dev
;
339 gpio_free(IMX046_RESET_GPIO
);
341 gpio_free(IMX046_STANDBY_GPIO
);
347 static int zoom2_cam_remove(struct platform_device
*pdev
)
349 if (regulator_is_enabled(zoom2_imx046_reg1
))
350 regulator_disable(zoom2_imx046_reg1
);
351 regulator_put(zoom2_imx046_reg1
);
352 if (regulator_is_enabled(zoom2_imx046_reg2
))
353 regulator_disable(zoom2_imx046_reg2
);
354 regulator_put(zoom2_imx046_reg2
);
356 gpio_free(IMX046_STANDBY_GPIO
);
357 gpio_free(IMX046_RESET_GPIO
);
358 gpio_free(LV8093_PS_GPIO
);
362 static int zoom2_cam_suspend(struct device
*dev
)
367 static int zoom2_cam_resume(struct device
*dev
)
372 static struct dev_pm_ops zoom2_cam_pm_ops
= {
373 .suspend
= zoom2_cam_suspend
,
374 .resume
= zoom2_cam_resume
,
377 static struct platform_driver zoom2_cam_driver
= {
378 .probe
= zoom2_cam_probe
,
379 .remove
= zoom2_cam_remove
,
382 .pm
= &zoom2_cam_pm_ops
,
386 void __init
zoom2_cam_init(void)
389 platform_driver_register(&zoom2_cam_driver
);