Full support for Ginger Console
[linux-ginger.git] / arch / arm / mach-omap2 / board-zoom2-camera.c
blob1ba2982a10a0a9f4967dc92b59f6d309f0ebaa47
1 /*
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>
18 #include <linux/mm.h>
20 #include <linux/regulator/consumer.h>
22 #include <asm/io.h>
24 #include <mach/gpio.h>
25 #ifdef CONFIG_OMAP_PM_SRF
26 #include <mach/omap-pm.h>
27 #endif
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)
67 #endif
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)
74 #endif
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;
82 if (!cam_inited) {
83 printk(KERN_ERR "MT9P012: Unable to control board GPIOs!\n");
84 return -EFAULT;
87 switch (power) {
88 case V4L2_POWER_ON:
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);
93 break;
94 case V4L2_POWER_OFF:
95 printk(KERN_DEBUG "lv8093_lens_power_set(OFF)\n");
96 break;
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);
100 break;
102 previous_pwr = power;
103 return 0;
106 static int lv8093_lens_set_prv_data(void *priv)
108 struct omap34xxcam_hw_config *hwc = priv;
110 hwc->dev_index = 2;
111 hwc->dev_minor = 5;
112 hwc->dev_type = OMAP34XXCAM_SLAVE_LENS;
113 return 0;
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,
120 #endif
122 #if defined(CONFIG_VIDEO_IMX046) || defined(CONFIG_VIDEO_IMX046_MODULE)
124 static struct omap34xxcam_sensor_config imx046_hwc = {
125 .sensor_isp = 0,
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;
135 hwc->dev_index = 2;
136 hwc->dev_minor = 5;
137 hwc->dev_type = OMAP34XXCAM_SLAVE_SENSOR;
139 return 0;
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,
146 .strobe = 0x0,
147 .prestrobe = 0x0,
148 .shutter = 0x0,
149 .wenlog = ISPCCDC_CFG_WENLOG_AND,
150 .wait_hs_vs = 2,
151 .u.csi.crc = 0x0,
152 .u.csi.mode = 0x0,
153 .u.csi.edge = 0x0,
154 .u.csi.signalling = 0x0,
155 .u.csi.strobe_clock_inv = 0x0,
156 .u.csi.vs_edge = 0x0,
157 .u.csi.channel = 0x0,
158 .u.csi.vpclk = 0x2,
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;
171 int err = 0;
173 if (!cam_inited) {
174 printk(KERN_ERR "MT9P012: Unable to control board GPIOs!\n");
175 return -EFAULT;
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);
196 switch (power) {
197 case V4L2_POWER_ON:
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);
206 #endif
208 isp_csi2_reset();
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);
243 udelay(100);
245 /* have to put sensor to reset to guarantee detection */
246 gpio_set_value(IMX046_RESET_GPIO, 0);
247 udelay(1500);
249 /* nRESET is active LOW. set HIGH to release reset */
250 gpio_set_value(IMX046_RESET_GPIO, 1);
251 udelay(300);
253 break;
254 case V4L2_POWER_OFF:
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);
266 #endif
267 break;
268 case V4L2_POWER_STANDBY:
269 printk(KERN_DEBUG "imx046_sensor_power_set(STANDBY)\n");
270 isp_csi2_complexio_power(ISP_CSI2_POWER_OFF);
271 /*TODO*/
272 #ifdef CONFIG_OMAP_PM_SRF
273 omap_pm_set_min_bus_tput(vdev->cam->isp, OCP_INITIATOR_AGENT, 0);
274 #endif
275 break;
278 /* Save powerstate to know what was before calling POWER_ON. */
279 previous_power = power;
280 return err;
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,
301 #endif
303 static int zoom2_cam_probe(struct platform_device *pdev)
305 int ret = 0;
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);
311 ret = -ENODEV;
312 goto err;
315 if (gpio_request(IMX046_RESET_GPIO, "imx046_rst") != 0) {
316 dev_err(&pdev->dev, "Could not request GPIO %d",
317 IMX046_RESET_GPIO);
318 ret = -ENODEV;
319 goto err_freegpio1;
322 if (gpio_request(LV8093_PS_GPIO, "lv8093_ps") != 0) {
323 dev_err(&pdev->dev, "Could not request GPIO %d",
324 LV8093_PS_GPIO);
325 ret = -ENODEV;
326 goto err_freegpio2;
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);
334 cam_inited = 1;
335 zoom2cam_dev = &pdev->dev;
336 return 0;
338 err_freegpio2:
339 gpio_free(IMX046_RESET_GPIO);
340 err_freegpio1:
341 gpio_free(IMX046_STANDBY_GPIO);
342 err:
343 cam_inited = 0;
344 return ret;
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);
359 return 0;
362 static int zoom2_cam_suspend(struct device *dev)
364 return 0;
367 static int zoom2_cam_resume(struct device *dev)
369 return 0;
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,
380 .driver = {
381 .name = "zoom2_cam",
382 .pm = &zoom2_cam_pm_ops,
386 void __init zoom2_cam_init(void)
388 cam_inited = 0;
389 platform_driver_register(&zoom2_cam_driver);