2 * Driver for OV5642 CMOS Image Sensor from OmniVision
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/hardirq.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <plat/rk_camera.h>
27 module_param(debug, int, S_IRUGO|S_IWUSR);
29 #define dprintk(level, fmt, arg...) do { \
31 printk(KERN_WARNING fmt , ## arg); } while (0)
33 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
34 #define SENSOR_DG(format, ...) dprintk(0, format, ## __VA_ARGS__)
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
43 #define MIN(x,y) ((x<y) ? x: y)
44 #define MAX(x,y) ((x>y) ? x: y)
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME mt9m112
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9M112
49 #define SENSOR_ID SEQUENCE_END
50 #define SENSOR_ID_REG SEQUENCE_END
51 #define SENSOR_RESET_REG SEQUENCE_END
52 #define SENSOR_RESET_VAL SEQUENCE_END
53 #define SENSOR_RESET_REG_LEN WORD_LEN
54 #define SENSOR_MIN_WIDTH 640
55 #define SENSOR_MIN_HEIGHT 480
56 #define SENSOR_MAX_WIDTH 1280
57 #define SENSOR_MAX_HEIGHT 1024
58 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
59 #define SENSOR_INIT_HEIGHT 480
60 #define SENSOR_INIT_WINSEQADR sensor_vga
61 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_UYVY
63 #define CONFIG_SENSOR_WhiteBalance 0
64 #define CONFIG_SENSOR_Brightness 0
65 #define CONFIG_SENSOR_Contrast 0
66 #define CONFIG_SENSOR_Saturation 0
67 #define CONFIG_SENSOR_Effect 0
68 #define CONFIG_SENSOR_Scene 0
69 #define CONFIG_SENSOR_DigitalZoom 0
70 #define CONFIG_SENSOR_Exposure 0
71 #define CONFIG_SENSOR_Flash 0
72 #define CONFIG_SENSOR_Mirror 0
73 #define CONFIG_SENSOR_Flip 0
74 #define CONFIG_SENSOR_Focus 0
77 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
78 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
79 #define CONFIG_SENSOR_I2C_NOSCHED 0
80 #define CONFIG_SENSOR_I2C_RDWRCHK 0
83 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
84 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
85 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
87 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
88 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
89 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
90 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
91 #define COLOR_TEMPERATURE_OFFICE_DN 3500
92 #define COLOR_TEMPERATURE_OFFICE_UP 5000
93 #define COLOR_TEMPERATURE_HOME_DN 2500
94 #define COLOR_TEMPERATURE_HOME_UP 3500
96 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
97 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
99 #define SENSOR_AF_IS_ERR (0x00<<0)
100 #define SENSOR_AF_IS_OK (0x01<<0)
102 #if CONFIG_SENSOR_Focus
103 #define SENSOR_AF_MODE_INFINITY 0
104 #define SENSOR_AF_MODE_MACRO 1
105 #define SENSOR_AF_MODE_FIXED 2
106 #define SENSOR_AF_MODE_AUTO 3
107 #define SENSOR_AF_MODE_CONTINUOUS 4
108 #define SENSOR_AF_MODE_CLOSE 5
111 /* init 640X480 VGA */
112 static struct reginfo sensor_init_data[] =
116 //0x20, 0x0103, // mirror
128 {0xCB, 0x0001}, // PROGRAM_ADVANCE
129 {0xCC, 0x0004}, // PROGRAM_SELECT
130 {0xD2, 0x0000}, // DEFAULT_CONFIG
135 //[Lens Correction 05/16/08 11:19:07]
136 {0x80, 0x000A }, //LENS_CORRECT_CONTROL
137 {0x81, 0xED0F }, //LENS_ADJ_VERT_RED_0
138 {0x82, 0xF8F1 }, //LENS_ADJ_VERT_RED_1_2
139 {0x83, 0x00FD }, //LENS_ADJ_VERT_RED_3_4
140 {0x84, 0xEF0D }, //LENS_ADJ_VERT_GREEN_0
141 {0x85, 0xF9F3 }, //LENS_ADJ_VERT_GREEN_1_2
142 {0x86, 0x00FD }, //LENS_ADJ_VERT_GREEN_3_4
143 {0x87, 0xF30C }, //LENS_ADJ_VERT_BLUE_0
144 {0x88, 0xF9F3 }, //LENS_ADJ_VERT_BLUE_1_2
145 {0x89, 0x00FD }, //LENS_ADJ_VERT_BLUE_3_4
146 {0x8A, 0xE616 }, //LENS_ADJ_HORIZ_RED_0
147 {0x8B, 0xF5F0 }, //LENS_ADJ_HORIZ_RED_1_2
148 {0x8C, 0xFDF9 }, //LENS_ADJ_HORIZ_RED_3_4
149 {0x8D, 0x0002 }, //LENS_ADJ_HORIZ_RED_5
150 {0x8E, 0xE714 }, //LENS_ADJ_HORIZ_GREEN_0
151 {0x8F, 0xF5F1 }, //LENS_ADJ_HORIZ_GREEN_1_2
152 {0x90, 0xFEFA }, //LENS_ADJ_HORIZ_GREEN_3_4
153 {0x91, 0x0001} , //LENS_ADJ_HORIZ_GREEN_5
154 {0x92, 0xE913} , //LENS_ADJ_HORIZ_BLUE_0
155 {0x93, 0xF7F2 }, //LENS_ADJ_HORIZ_BLUE_1_2
156 {0x94, 0xFEFB }, //LENS_ADJ_HORIZ_BLUE_3_4
157 {0x95, 0x0002} , //LENS_ADJ_HORIZ_BLUE_5
158 {0xB6, 0x0904} , //LENS_ADJ_VERT_RED_5_6
159 {0xB7, 0x1E0C }, //LENS_ADJ_VERT_RED_7_8
160 {0xB8, 0x0904 }, //LENS_ADJ_VERT_GREEN_5_6
161 {0xB9, 0x1B0A} , //LENS_ADJ_VERT_GREEN_7_8
162 {0xBA, 0x0704} , //LENS_ADJ_VERT_BLUE_5_6
163 {0xBB, 0x1A0A} , //LENS_ADJ_VERT_BLUE_7_8
164 {0xBC, 0x0906 }, //LENS_ADJ_HORIZ_RED_6_7
165 {0xBD, 0x1410} , //LENS_ADJ_HORIZ_RED_8_9
166 {0xBE, 0x0026 }, //LENS_ADJ_HORIZ_RED_10
167 {0xBF, 0x0806}, //LENS_ADJ_HORIZ_GREEN_6_7
168 {0xC0, 0x110E} , //LENS_ADJ_HORIZ_GREEN_8_9
169 {0xC1, 0x0024} , //LENS_ADJ_HORIZ_GREEN_10
170 {0xC2, 0x0A05} , //LENS_ADJ_HORIZ_BLUE_6_7
171 {0xC3, 0x100F} , //LENS_ADJ_HORIZ_BLUE_8_9
172 {0xC4, 0x0027} , //LENS_ADJ_HORIZ_BLUE_10
173 {0x06, 0x640e}, //LENS_CORRECTION
188 {0x37, 0x0080},//0x0300,
190 {0x2e, 0x0c44},//0x0c30, //
191 //0x39, 0x03D2, // AE Line size Context A d:6A6
192 //0x3A, 0x03D2, // AE Line size Context B d:6A6
193 //0x3B, 0x055B, // AE shutter delay limit Context A
194 //0x3C, 0x055B, // AE shutter delay limit Context B
195 {0x57, 0x2CA}, // Context A Flicker full frame time (60Hz)
196 {0x58, 0x2CA}, //0x01E9, // Context A Flicker full frame time (50Hz)
197 {0x59, 0x2CA}, // Context B Flicker full frame time (60Hz)
198 {0x5A, 0x2CA}, //0x01E9, // Context B Flicker full frame time (50Hz)
199 {0x5C, 0x0E0A}, // 60Hz Flicker Search Range
200 {0x5D, 0x120E}, // 50Hz Flicker Search Range
201 {0x64, 0x5E1C}, // Flicker parameter
207 /* 720p 15fps @ 1280x720 */
209 static struct reginfo sensor_720p[]=
214 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
216 static struct reginfo sensor_1080p[]=
221 /* 2592X1944 QSXGA */
222 static struct reginfo sensor_qsxga[] =
227 static struct reginfo sensor_qxga[] =
233 static struct reginfo sensor_uxga[] =
238 static struct reginfo sensor_sxga[] =
240 {SEQUENCE_PROPERTY,SEQUENCE_CAPTURE},
244 static struct reginfo sensor_xga[] =
250 static struct reginfo sensor_svga[] =
256 static struct reginfo sensor_vga[] =
260 //0x20, 0x0103, // mirror
272 {0xCB, 0x0001}, // PROGRAM_ADVANCE
273 {0xCC, 0x0004}, // PROGRAM_SELECT
274 {0xD2, 0x0000}, // DEFAULT_CONFIG
279 //[Lens Correction 05/16/08 11:19:07]
280 {0x80, 0x000A }, //LENS_CORRECT_CONTROL
281 {0x81, 0xED0F }, //LENS_ADJ_VERT_RED_0
282 {0x82, 0xF8F1 }, //LENS_ADJ_VERT_RED_1_2
283 {0x83, 0x00FD }, //LENS_ADJ_VERT_RED_3_4
284 {0x84, 0xEF0D }, //LENS_ADJ_VERT_GREEN_0
285 {0x85, 0xF9F3 }, //LENS_ADJ_VERT_GREEN_1_2
286 {0x86, 0x00FD }, //LENS_ADJ_VERT_GREEN_3_4
287 {0x87, 0xF30C }, //LENS_ADJ_VERT_BLUE_0
288 {0x88, 0xF9F3 }, //LENS_ADJ_VERT_BLUE_1_2
289 {0x89, 0x00FD }, //LENS_ADJ_VERT_BLUE_3_4
290 {0x8A, 0xE616 }, //LENS_ADJ_HORIZ_RED_0
291 {0x8B, 0xF5F0 }, //LENS_ADJ_HORIZ_RED_1_2
292 {0x8C, 0xFDF9 }, //LENS_ADJ_HORIZ_RED_3_4
293 {0x8D, 0x0002 }, //LENS_ADJ_HORIZ_RED_5
294 {0x8E, 0xE714 }, //LENS_ADJ_HORIZ_GREEN_0
295 {0x8F, 0xF5F1 }, //LENS_ADJ_HORIZ_GREEN_1_2
296 {0x90, 0xFEFA }, //LENS_ADJ_HORIZ_GREEN_3_4
297 {0x91, 0x0001} , //LENS_ADJ_HORIZ_GREEN_5
298 {0x92, 0xE913} , //LENS_ADJ_HORIZ_BLUE_0
299 {0x93, 0xF7F2 }, //LENS_ADJ_HORIZ_BLUE_1_2
300 {0x94, 0xFEFB }, //LENS_ADJ_HORIZ_BLUE_3_4
301 {0x95, 0x0002} , //LENS_ADJ_HORIZ_BLUE_5
302 {0xB6, 0x0904} , //LENS_ADJ_VERT_RED_5_6
303 {0xB7, 0x1E0C }, //LENS_ADJ_VERT_RED_7_8
304 {0xB8, 0x0904 }, //LENS_ADJ_VERT_GREEN_5_6
305 {0xB9, 0x1B0A} , //LENS_ADJ_VERT_GREEN_7_8
306 {0xBA, 0x0704} , //LENS_ADJ_VERT_BLUE_5_6
307 {0xBB, 0x1A0A} , //LENS_ADJ_VERT_BLUE_7_8
308 {0xBC, 0x0906 }, //LENS_ADJ_HORIZ_RED_6_7
309 {0xBD, 0x1410} , //LENS_ADJ_HORIZ_RED_8_9
310 {0xBE, 0x0026 }, //LENS_ADJ_HORIZ_RED_10
311 {0xBF, 0x0806}, //LENS_ADJ_HORIZ_GREEN_6_7
312 {0xC0, 0x110E} , //LENS_ADJ_HORIZ_GREEN_8_9
313 {0xC1, 0x0024} , //LENS_ADJ_HORIZ_GREEN_10
314 {0xC2, 0x0A05} , //LENS_ADJ_HORIZ_BLUE_6_7
315 {0xC3, 0x100F} , //LENS_ADJ_HORIZ_BLUE_8_9
316 {0xC4, 0x0027} , //LENS_ADJ_HORIZ_BLUE_10
317 {0x06, 0x640e}, //LENS_CORRECTION
332 {0x37, 0x0080},//0x0300,
334 {0x2e, 0x0c44},//0x0c30, //
335 //0x39, 0x03D2, // AE Line size Context A d:6A6
336 //0x3A, 0x03D2, // AE Line size Context B d:6A6
337 //0x3B, 0x055B, // AE shutter delay limit Context A
338 //0x3C, 0x055B, // AE shutter delay limit Context B
339 {0x57, 0x2CA}, // Context A Flicker full frame time (60Hz)
340 {0x58, 0x2CA}, //0x01E9, // Context A Flicker full frame time (50Hz)
341 {0x59, 0x2CA}, // Context B Flicker full frame time (60Hz)
342 {0x5A, 0x2CA}, //0x01E9, // Context B Flicker full frame time (50Hz)
343 {0x5C, 0x0E0A}, // 60Hz Flicker Search Range
344 {0x5D, 0x120E}, // 50Hz Flicker Search Range
345 {0x64, 0x5E1C}, // Flicker parameter
351 static struct reginfo sensor_cif[] =
357 static struct reginfo sensor_qvga[] =
363 static struct reginfo sensor_qcif[] =
369 static struct reginfo ov2655_qqvga[] =
413 static struct reginfo ov2655_Sharpness_auto[] =
418 static struct reginfo ov2655_Sharpness1[] =
424 static struct reginfo ov2655_Sharpness2[][3] =
431 static struct reginfo ov2655_Sharpness3[] =
437 static struct reginfo ov2655_Sharpness4[]=
444 static struct reginfo ov2655_Sharpness5[] =
451 static struct reginfo sensor_Preview2Capture[]=
455 {0xCB, 0x0001}, // PROGRAM_ADVANCE
456 {0xCC, 0x0004}, // PROGRAM_SELECT
457 {0xD2, 0x007f}, // DEFAULT_CONFIG
461 static struct reginfo sensor_Capture2Preview[]=
465 {0xCB, 0x0001}, // PROGRAM_ADVANCE
466 {0xCC, 0x0004}, // PROGRAM_SELECT
467 {0xD2, 0x0000}, // DEFAULT_CONFIG
470 static struct reginfo sensor_ClrFmt_YUYV[]=
475 static struct reginfo sensor_ClrFmt_UYVY[]=
481 #if CONFIG_SENSOR_WhiteBalance
482 static struct reginfo sensor_WhiteB_Auto[]=
487 /* Cloudy Colour Temperature : 6500K - 8000K */
488 static struct reginfo sensor_WhiteB_Cloudy[]=
492 /* ClearDay Colour Temperature : 5000K - 6500K */
493 static struct reginfo sensor_WhiteB_ClearDay[]=
497 /* Office Colour Temperature : 3500K - 5000K */
498 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
502 /* Home Colour Temperature : 2500K - 3500K */
503 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
507 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
508 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
512 #if CONFIG_SENSOR_Brightness
513 static struct reginfo sensor_Brightness0[]=
518 static struct reginfo sensor_Brightness1[]=
523 static struct reginfo sensor_Brightness2[]=
528 static struct reginfo sensor_Brightness3[]=
533 static struct reginfo sensor_Brightness4[]=
538 static struct reginfo sensor_Brightness5[]=
542 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
543 sensor_Brightness4, sensor_Brightness5,NULL,
548 #if CONFIG_SENSOR_Effect
549 static struct reginfo sensor_Effect_Normal[] =
554 static struct reginfo sensor_Effect_WandB[] =
559 static struct reginfo sensor_Effect_Sepia[] =
564 static struct reginfo sensor_Effect_Negative[] =
568 static struct reginfo sensor_Effect_Bluish[] =
573 static struct reginfo sensor_Effect_Green[] =
578 static struct reginfo sensor_Effect_Solarize[] =
582 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_Negative,sensor_Effect_Sepia,
583 sensor_Effect_Solarize,NULL,
586 #if CONFIG_SENSOR_Exposure
587 static struct reginfo sensor_Exposure0[]=
592 static struct reginfo sensor_Exposure1[]=
597 static struct reginfo sensor_Exposure2[]=
602 static struct reginfo sensor_Exposure3[]=
607 static struct reginfo sensor_Exposure4[]=
612 static struct reginfo sensor_Exposure5[]=
617 static struct reginfo sensor_Exposure6[]=
622 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
623 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
626 #if CONFIG_SENSOR_Saturation
627 static struct reginfo sensor_Saturation0[]=
632 static struct reginfo sensor_Saturation1[]=
637 static struct reginfo sensor_Saturation2[]=
641 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
644 #if CONFIG_SENSOR_Contrast
645 static struct reginfo sensor_Contrast0[]=
650 static struct reginfo sensor_Contrast1[]=
655 static struct reginfo sensor_Contrast2[]=
660 static struct reginfo sensor_Contrast3[]=
665 static struct reginfo sensor_Contrast4[]=
671 static struct reginfo sensor_Contrast5[]=
676 static struct reginfo sensor_Contrast6[]=
680 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
681 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
685 #if CONFIG_SENSOR_Mirror
686 static struct reginfo sensor_MirrorOn[]=
691 static struct reginfo sensor_MirrorOff[]=
695 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
697 #if CONFIG_SENSOR_Flip
698 static struct reginfo sensor_FlipOn[]=
703 static struct reginfo sensor_FlipOff[]=
707 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
710 #if CONFIG_SENSOR_Scene
711 static struct reginfo sensor_SceneAuto[] =
716 static struct reginfo sensor_SceneNight[] =
720 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
723 #if CONFIG_SENSOR_DigitalZoom
724 static struct reginfo sensor_Zoom0[] =
729 static struct reginfo sensor_Zoom1[] =
734 static struct reginfo sensor_Zoom2[] =
740 static struct reginfo sensor_Zoom3[] =
744 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
746 static const struct v4l2_querymenu sensor_menus[] =
748 #if CONFIG_SENSOR_WhiteBalance
749 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
750 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
751 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
754 #if CONFIG_SENSOR_Effect
755 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "negative", .reserved = 0,},
756 { .id = V4L2_CID_EFFECT, .index = 2, .name = "sepia", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "solarize", .reserved = 0,},
759 #if CONFIG_SENSOR_Scene
760 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
763 #if CONFIG_SENSOR_Flash
764 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
765 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
769 static const struct v4l2_queryctrl sensor_controls[] =
771 #if CONFIG_SENSOR_WhiteBalance
773 .id = V4L2_CID_DO_WHITE_BALANCE,
774 .type = V4L2_CTRL_TYPE_MENU,
775 .name = "White Balance Control",
783 #if CONFIG_SENSOR_Brightness
785 .id = V4L2_CID_BRIGHTNESS,
786 .type = V4L2_CTRL_TYPE_INTEGER,
787 .name = "Brightness Control",
795 #if CONFIG_SENSOR_Effect
797 .id = V4L2_CID_EFFECT,
798 .type = V4L2_CTRL_TYPE_MENU,
799 .name = "Effect Control",
807 #if CONFIG_SENSOR_Exposure
809 .id = V4L2_CID_EXPOSURE,
810 .type = V4L2_CTRL_TYPE_INTEGER,
811 .name = "Exposure Control",
819 #if CONFIG_SENSOR_Saturation
821 .id = V4L2_CID_SATURATION,
822 .type = V4L2_CTRL_TYPE_INTEGER,
823 .name = "Saturation Control",
831 #if CONFIG_SENSOR_Contrast
833 .id = V4L2_CID_CONTRAST,
834 .type = V4L2_CTRL_TYPE_INTEGER,
835 .name = "Contrast Control",
843 #if CONFIG_SENSOR_Mirror
845 .id = V4L2_CID_HFLIP,
846 .type = V4L2_CTRL_TYPE_BOOLEAN,
847 .name = "Mirror Control",
855 #if CONFIG_SENSOR_Flip
857 .id = V4L2_CID_VFLIP,
858 .type = V4L2_CTRL_TYPE_BOOLEAN,
859 .name = "Flip Control",
867 #if CONFIG_SENSOR_Scene
869 .id = V4L2_CID_SCENE,
870 .type = V4L2_CTRL_TYPE_MENU,
871 .name = "Scene Control",
879 #if CONFIG_SENSOR_DigitalZoom
881 .id = V4L2_CID_ZOOM_RELATIVE,
882 .type = V4L2_CTRL_TYPE_INTEGER,
883 .name = "DigitalZoom Control",
889 .id = V4L2_CID_ZOOM_ABSOLUTE,
890 .type = V4L2_CTRL_TYPE_INTEGER,
891 .name = "DigitalZoom Control",
899 #if CONFIG_SENSOR_Focus
901 .id = V4L2_CID_FOCUS_RELATIVE,
902 .type = V4L2_CTRL_TYPE_INTEGER,
903 .name = "Focus Control",
909 .id = V4L2_CID_FOCUS_ABSOLUTE,
910 .type = V4L2_CTRL_TYPE_INTEGER,
911 .name = "Focus Control",
915 .default_value = 125,
918 .id = V4L2_CID_FOCUS_AUTO,
919 .type = V4L2_CTRL_TYPE_BOOLEAN,
920 .name = "Focus Control",
926 .id = V4L2_CID_FOCUS_CONTINUOUS,
927 .type = V4L2_CTRL_TYPE_BOOLEAN,
928 .name = "Focus Control",
936 #if CONFIG_SENSOR_Flash
938 .id = V4L2_CID_FLASH,
939 .type = V4L2_CTRL_TYPE_MENU,
940 .name = "Flash Control",
949 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
950 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
951 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
952 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
953 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
954 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
955 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
956 static int sensor_resume(struct soc_camera_device *icd);
957 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
958 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
959 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
960 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
961 static int sensor_deactivate(struct i2c_client *client);
963 static struct soc_camera_ops sensor_ops =
965 .suspend = sensor_suspend,
966 .resume = sensor_resume,
967 .set_bus_param = sensor_set_bus_param,
968 .query_bus_param = sensor_query_bus_param,
969 .controls = sensor_controls,
970 .menus = sensor_menus,
971 .num_controls = ARRAY_SIZE(sensor_controls),
972 .num_menus = ARRAY_SIZE(sensor_menus),
975 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
976 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
977 .colorspace = _colorspace }
979 #define JPG_FMT(_name, _depth, _fourcc) \
980 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
982 static const struct soc_camera_data_format sensor_colour_formats[] = {
983 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
984 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
986 enum sensor_work_state
988 sensor_work_ready = 0,
993 struct i2c_client *client;
994 struct delayed_work dwork;
995 enum sensor_work_state state;
998 typedef struct sensor_info_priv_s
1012 unsigned char mirror; /* HFLIP */
1013 unsigned char flip; /* VFLIP */
1020 struct reginfo *winseqe_cur_addr;
1021 unsigned int pixfmt;
1022 unsigned int enable;
1023 unsigned int funmodule_state;
1024 } sensor_info_priv_t;
1028 struct sensor_parameter
1030 unsigned short int preview_maxlines;
1031 unsigned short int preview_exposure;
1032 unsigned short int preview_line_width;
1033 unsigned short int preview_gain;
1035 unsigned short int capture_framerate;
1036 unsigned short int preview_framerate;
1041 struct v4l2_subdev subdev;
1042 struct i2c_client *client;
1043 sensor_info_priv_t info_priv;
1044 struct sensor_parameter parameter;
1045 struct workqueue_struct *sensor_wq;
1046 struct sensor_work sensor_wk;
1047 struct mutex wq_lock;
1048 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1049 #if CONFIG_SENSOR_I2C_NOSCHED
1050 atomic_t tasklock_cnt;
1052 struct rk29camera_platform_data *sensor_io_request;
1055 static struct sensor* to_sensor(const struct i2c_client *client)
1057 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1060 static int sensor_task_lock(struct i2c_client *client, int lock)
1062 #if CONFIG_SENSOR_I2C_NOSCHED
1064 struct sensor *sensor = to_sensor(client);
1067 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1068 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1069 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1073 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1074 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1075 goto sensor_task_lock_err;
1080 atomic_add(1, &sensor->tasklock_cnt);
1082 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1083 atomic_sub(1, &sensor->tasklock_cnt);
1085 if (atomic_read(&sensor->tasklock_cnt) == 0)
1091 sensor_task_lock_err:
1095 /* sensor register write */
1096 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1100 struct i2c_msg msg[1];
1102 switch (reg_info->reg)
1104 case SEQUENCE_WAIT_MS:
1107 mdelay(reg_info->val);
1109 msleep(reg_info->val);
1113 case SEQUENCE_WAIT_US:
1115 udelay(reg_info->val);
1119 case SEQUENCE_PROPERTY:
1125 buf[0] = reg_info->reg & 0xFF;
1126 buf[1] = reg_info->val >> 8;
1127 buf[2] = reg_info->val & 0xFF;
1129 msg->addr = client->addr;
1130 msg->flags = client->flags;
1132 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1133 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1138 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1139 err = i2c_transfer(client->adapter, msg, 1);
1144 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg_info->reg, reg_info->val);
1153 /* sensor register read */
1154 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1158 struct i2c_msg msg[2];
1160 buf[0] = reg & 0xFF;
1162 msg[0].addr = client->addr;
1163 msg[0].flags = client->flags;
1165 msg[0].len = sizeof(buf);
1166 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1167 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1169 msg[1].addr = client->addr;
1170 msg[1].flags = client->flags|I2C_M_RD;
1173 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1174 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1178 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1179 err = i2c_transfer(client->adapter, msg, 2);
1185 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1193 /* write a array of registers */
1194 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1198 #if CONFIG_SENSOR_I2C_RDWRCHK
1203 if (sensor_task_lock(client, 1) < 0)
1204 goto sensor_write_array_end;
1205 while (regarray[i].reg != SEQUENCE_END) {
1206 err = sensor_write(client, ®array[i]);
1210 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1214 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1216 goto sensor_write_array_end;
1219 #if CONFIG_SENSOR_I2C_RDWRCHK
1220 sensor_read(client, regarray[i].reg, &valchk);
1221 if (valchk != regarray[i].val)
1222 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1229 sensor_write_array_end:
1230 sensor_task_lock(client,0);
1233 #if CONFIG_SENSOR_I2C_RDWRCHK
1234 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1242 while (regarray[i].reg != SEQUENCE_END)
1244 sensor_read(client, regarray[i].reg, &valchk);
1245 if (valchk != regarray[i].val)
1246 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1253 #if CONFIG_SENSOR_Focus
1254 static struct reginfo sensor_af_init0[] =
1256 {SEQUENCE_END, 0x00}
1258 static struct reginfo sensor_af_init1[] =
1260 {SEQUENCE_END, 0x00}
1264 static struct reginfo sensor_af_trigger[] =
1266 {SEQUENCE_END, 0x00}
1268 static int sensor_af_single(struct i2c_client *client)
1272 ret = sensor_write_array(client, sensor_af_trigger);
1274 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1276 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1277 sensor_af_single_end:
1281 static int sensor_af_const(struct i2c_client *client)
1285 sensor_af_const_end:
1289 static int sensor_af_zoneupdate(struct i2c_client *client)
1293 sensor_af_zoneupdate_end:
1297 static int sensor_af_init(struct i2c_client *client)
1301 ret = sensor_write_array(client, sensor_af_init0);
1303 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1305 if (sensor_af_zoneupdate(client) == 0) {
1306 ret = sensor_write_array(client, sensor_af_init1);
1308 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1317 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1319 struct soc_camera_link *icl = to_soc_camera_link(icd);
1325 case Sensor_PowerDown:
1327 if (icl->powerdown) {
1328 ret = icl->powerdown(icd->pdev, on);
1329 if (ret == RK29_CAM_IO_SUCCESS) {
1333 icl->reset(icd->pdev);
1335 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1337 goto sensor_power_end;
1344 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1345 struct sensor *sensor = to_sensor(client);
1347 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1348 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1354 SENSOR_TR("%s power cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
1362 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1364 struct i2c_client *client = sd->priv;
1365 struct soc_camera_device *icd = client->dev.platform_data;
1366 struct sensor *sensor = to_sensor(client);
1367 const struct v4l2_queryctrl *qctrl;
1370 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1372 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1374 goto sensor_INIT_ERR;
1378 if (sensor_task_lock(client,1)<0)
1379 goto sensor_INIT_ERR;
1381 #if (SENSOR_RESET_REG != SEQUENCE_END)
1382 struct reginfo reg_info;
1383 reg_info.reg = SENSOR_RESET_REG;
1384 reg_info.val = SENSOR_RESET_VAL;
1385 reg_info.reg_len = SENSOR_RESET_REG_LEN;
1386 ret = sensor_write(client, ®_info);
1388 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1390 goto sensor_INIT_ERR;
1393 mdelay(5); //delay 5 microseconds
1396 /* check if it is an sensor sensor */
1397 #if (SENSOR_ID_REG != SEQUENCE_END)
1398 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1400 SENSOR_TR("read chip id failed\n");
1402 goto sensor_INIT_ERR;
1405 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1409 if (pid == SENSOR_ID) {
1410 sensor->model = SENSOR_V4L2_IDENT;
1412 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1414 goto sensor_INIT_ERR;
1417 ret = sensor_write_array(client, sensor_init_data);
1420 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1421 goto sensor_INIT_ERR;
1423 sensor_task_lock(client,0);
1424 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1425 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1426 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1427 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1428 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1429 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1431 /* sensor sensor information for initialization */
1432 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1434 sensor->info_priv.whiteBalance = qctrl->default_value;
1435 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1437 sensor->info_priv.brightness = qctrl->default_value;
1438 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1440 sensor->info_priv.effect = qctrl->default_value;
1441 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1443 sensor->info_priv.exposure = qctrl->default_value;
1445 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1447 sensor->info_priv.saturation = qctrl->default_value;
1448 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1450 sensor->info_priv.contrast = qctrl->default_value;
1451 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1453 sensor->info_priv.mirror = qctrl->default_value;
1454 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1456 sensor->info_priv.flip = qctrl->default_value;
1457 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1459 sensor->info_priv.scene = qctrl->default_value;
1460 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1462 sensor->info_priv.digitalzoom = qctrl->default_value;
1464 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1465 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1467 sensor->info_priv.focus = qctrl->default_value;
1468 #if CONFIG_SENSOR_Focus
1469 if (sensor_af_init(client) < 0) {
1470 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1471 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1473 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1474 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1477 #if CONFIG_SENSOR_Flash
1478 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1480 sensor->info_priv.flash = qctrl->default_value;
1482 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),((val == 0)?__FUNCTION__:"sensor_reinit"),icd->user_width,icd->user_height);
1486 sensor_task_lock(client,0);
1487 sensor_deactivate(client);
1490 static int sensor_deactivate(struct i2c_client *client)
1492 struct soc_camera_device *icd = client->dev.platform_data;
1494 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1496 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1499 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1500 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1501 icd->user_width = SENSOR_INIT_WIDTH;
1502 icd->user_height = SENSOR_INIT_HEIGHT;
1506 static struct reginfo sensor_power_down_sequence[]=
1510 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1513 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1515 if (pm_msg.event == PM_EVENT_SUSPEND) {
1516 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1517 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1519 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1522 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1524 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1529 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1536 static int sensor_resume(struct soc_camera_device *icd)
1540 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1542 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1546 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1550 static int sensor_set_bus_param(struct soc_camera_device *icd,
1551 unsigned long flags)
1557 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1559 struct soc_camera_link *icl = to_soc_camera_link(icd);
1560 unsigned long flags = SENSOR_BUS_PARAM;
1562 return soc_camera_apply_sensor_flags(icl, flags);
1565 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1567 struct i2c_client *client = sd->priv;
1568 struct soc_camera_device *icd = client->dev.platform_data;
1569 struct sensor *sensor = to_sensor(client);
1570 struct v4l2_pix_format *pix = &f->fmt.pix;
1572 pix->width = icd->user_width;
1573 pix->height = icd->user_height;
1574 pix->pixelformat = sensor->info_priv.pixfmt;
1575 pix->field = V4L2_FIELD_NONE;
1576 pix->colorspace = V4L2_COLORSPACE_JPEG;
1580 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
1584 if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
1586 } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
1588 } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
1590 } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
1592 } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
1597 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1601 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
1605 if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
1607 } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
1612 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1615 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1617 struct reginfo *winseqe_set_addr = NULL;
1619 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1620 winseqe_set_addr = sensor_qcif;
1623 } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1624 winseqe_set_addr = sensor_qvga;
1627 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1628 winseqe_set_addr = sensor_cif;
1631 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1632 winseqe_set_addr = sensor_vga;
1635 } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1636 winseqe_set_addr = sensor_svga;
1639 } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1640 winseqe_set_addr = sensor_xga;
1643 } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1644 winseqe_set_addr = sensor_720p;
1647 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1648 winseqe_set_addr = sensor_sxga;
1651 } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1652 winseqe_set_addr = sensor_uxga;
1655 } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1656 winseqe_set_addr = sensor_1080p;
1659 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1660 winseqe_set_addr = sensor_qxga;
1663 } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1664 winseqe_set_addr = sensor_qsxga;
1669 return winseqe_set_addr;
1672 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1674 struct i2c_client *client = sd->priv;
1675 struct sensor *sensor = to_sensor(client);
1676 struct v4l2_pix_format *pix = &f->fmt.pix;
1677 struct reginfo *winseqe_set_addr=NULL;
1678 int ret = 0, set_w,set_h;
1680 if (sensor->info_priv.pixfmt != pix->pixelformat) {
1681 switch (pix->pixelformat)
1683 case V4L2_PIX_FMT_YUYV:
1685 winseqe_set_addr = sensor_ClrFmt_YUYV;
1688 case V4L2_PIX_FMT_UYVY:
1690 winseqe_set_addr = sensor_ClrFmt_UYVY;
1696 if (winseqe_set_addr != NULL) {
1697 sensor_write_array(client, winseqe_set_addr);
1698 sensor->info_priv.pixfmt = pix->pixelformat;
1700 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1702 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1707 set_h = pix->height;
1709 winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1711 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1712 ret |= sensor_write_array(client, winseqe_set_addr);
1714 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1715 goto sensor_s_fmt_end;
1717 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
1718 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1719 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1721 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1722 sensor->info_priv.preview_w = pix->width;
1723 sensor->info_priv.preview_h = pix->height;
1727 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1728 ret |= sensor_write_array(client, sensor_Preview2Capture);
1730 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
1731 goto sensor_s_fmt_end;
1733 sensor->info_priv.capture_w = set_w;
1734 sensor->info_priv.capture_h = set_h;
1735 sensor->info_priv.snap2preview = true;
1736 } else if (sensor->info_priv.snap2preview == true) {
1737 if (winseqe_set_addr || ((sensor->info_priv.preview_w == pix->width) && (sensor->info_priv.preview_h == pix->height))) {
1738 ret |= sensor_write_array(client, sensor_Capture2Preview);
1740 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
1741 goto sensor_s_fmt_end;
1743 sensor->info_priv.preview_w = pix->width;
1744 sensor->info_priv.preview_h = pix->height;
1745 sensor->info_priv.snap2preview = false;
1747 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1752 pix->height = set_h;
1757 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1760 struct v4l2_pix_format *pix = &f->fmt.pix;
1761 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1762 pix->pixelformat == V4L2_PIX_FMT_YUYV;
1765 * With Bayer format enforce even side lengths, but let the user play
1766 * with the starting pixel
1769 if (pix->height > SENSOR_MAX_HEIGHT)
1770 pix->height = SENSOR_MAX_HEIGHT;
1771 else if (pix->height < SENSOR_MIN_HEIGHT)
1772 pix->height = SENSOR_MIN_HEIGHT;
1774 pix->height = ALIGN(pix->height, 2);
1776 if (pix->width > SENSOR_MAX_WIDTH)
1777 pix->width = SENSOR_MAX_WIDTH;
1778 else if (pix->width < SENSOR_MIN_WIDTH)
1779 pix->width = SENSOR_MIN_WIDTH;
1781 pix->width = ALIGN(pix->width, 2);
1783 if (sensor_fmt_catch(pix->width, pix->height, &pix->width, &pix->height) == NULL) {
1791 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1793 struct i2c_client *client = sd->priv;
1795 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1798 if (id->match.addr != client->addr)
1801 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
1806 #if CONFIG_SENSOR_Brightness
1807 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1809 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1811 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1813 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1815 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1817 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1820 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1824 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1828 #if CONFIG_SENSOR_Effect
1829 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1831 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1833 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1835 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1837 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1839 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1842 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1846 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1850 #if CONFIG_SENSOR_Exposure
1851 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1853 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1855 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1857 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1859 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1861 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1864 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1868 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1872 #if CONFIG_SENSOR_Saturation
1873 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1875 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1877 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1879 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1881 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1883 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1886 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1890 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1894 #if CONFIG_SENSOR_Contrast
1895 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1897 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1899 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1901 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
1903 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
1905 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1908 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1912 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1916 #if CONFIG_SENSOR_Mirror
1917 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1919 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1921 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1923 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
1925 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
1927 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1930 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1934 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1938 #if CONFIG_SENSOR_Flip
1939 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1941 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1943 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1945 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
1947 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
1949 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1952 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1956 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1960 #if CONFIG_SENSOR_Scene
1961 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1963 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1965 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1967 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
1969 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
1971 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1974 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1978 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1982 #if CONFIG_SENSOR_WhiteBalance
1983 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1985 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1987 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1989 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
1991 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
1993 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1996 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2000 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2004 #if CONFIG_SENSOR_DigitalZoom
2005 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2007 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2008 struct sensor *sensor = to_sensor(client);
2009 const struct v4l2_queryctrl *qctrl_info;
2010 int digitalzoom_cur, digitalzoom_total;
2012 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2016 digitalzoom_cur = sensor->info_priv.digitalzoom;
2017 digitalzoom_total = qctrl_info->maximum;
2019 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2021 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2025 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2027 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2031 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2033 *value = digitalzoom_total - digitalzoom_cur;
2036 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2038 *value = 0 - digitalzoom_cur;
2041 digitalzoom_cur += *value;
2043 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2045 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2047 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2050 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2057 #if CONFIG_SENSOR_Focus
2058 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2060 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2061 struct sensor *sensor = to_sensor(client);
2062 const struct v4l2_queryctrl *qctrl_info;
2065 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2069 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2070 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2072 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2075 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2079 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2080 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2083 sensor_set_focus_absolute_end:
2086 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2088 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2089 struct sensor *sensor = to_sensor(client);
2090 const struct v4l2_queryctrl *qctrl_info;
2093 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2097 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2098 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2100 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2103 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2107 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2108 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2110 sensor_set_focus_relative_end:
2114 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2116 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2117 struct sensor *sensor = to_sensor(client);
2120 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2123 case SENSOR_AF_MODE_AUTO:
2125 ret = sensor_af_single(client);
2129 case SENSOR_AF_MODE_MACRO:
2131 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2135 case SENSOR_AF_MODE_INFINITY:
2137 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2141 case SENSOR_AF_MODE_CONTINUOUS:
2143 ret = sensor_af_const(client);
2147 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2152 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2155 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2156 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2162 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2164 struct i2c_client *client = sd->priv;
2165 struct sensor *sensor = to_sensor(client);
2166 const struct v4l2_queryctrl *qctrl;
2168 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2172 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2178 case V4L2_CID_BRIGHTNESS:
2180 ctrl->value = sensor->info_priv.brightness;
2183 case V4L2_CID_SATURATION:
2185 ctrl->value = sensor->info_priv.saturation;
2188 case V4L2_CID_CONTRAST:
2190 ctrl->value = sensor->info_priv.contrast;
2193 case V4L2_CID_DO_WHITE_BALANCE:
2195 ctrl->value = sensor->info_priv.whiteBalance;
2198 case V4L2_CID_EXPOSURE:
2200 ctrl->value = sensor->info_priv.exposure;
2203 case V4L2_CID_HFLIP:
2205 ctrl->value = sensor->info_priv.mirror;
2208 case V4L2_CID_VFLIP:
2210 ctrl->value = sensor->info_priv.flip;
2221 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2223 struct i2c_client *client = sd->priv;
2224 struct sensor *sensor = to_sensor(client);
2225 struct soc_camera_device *icd = client->dev.platform_data;
2226 const struct v4l2_queryctrl *qctrl;
2229 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2233 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2239 #if CONFIG_SENSOR_Brightness
2240 case V4L2_CID_BRIGHTNESS:
2242 if (ctrl->value != sensor->info_priv.brightness)
2244 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2248 sensor->info_priv.brightness = ctrl->value;
2253 #if CONFIG_SENSOR_Exposure
2254 case V4L2_CID_EXPOSURE:
2256 if (ctrl->value != sensor->info_priv.exposure)
2258 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2262 sensor->info_priv.exposure = ctrl->value;
2267 #if CONFIG_SENSOR_Saturation
2268 case V4L2_CID_SATURATION:
2270 if (ctrl->value != sensor->info_priv.saturation)
2272 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2276 sensor->info_priv.saturation = ctrl->value;
2281 #if CONFIG_SENSOR_Contrast
2282 case V4L2_CID_CONTRAST:
2284 if (ctrl->value != sensor->info_priv.contrast)
2286 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2290 sensor->info_priv.contrast = ctrl->value;
2295 #if CONFIG_SENSOR_WhiteBalance
2296 case V4L2_CID_DO_WHITE_BALANCE:
2298 if (ctrl->value != sensor->info_priv.whiteBalance)
2300 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2304 sensor->info_priv.whiteBalance = ctrl->value;
2309 #if CONFIG_SENSOR_Mirror
2310 case V4L2_CID_HFLIP:
2312 if (ctrl->value != sensor->info_priv.mirror)
2314 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2316 sensor->info_priv.mirror = ctrl->value;
2321 #if CONFIG_SENSOR_Flip
2322 case V4L2_CID_VFLIP:
2324 if (ctrl->value != sensor->info_priv.flip)
2326 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2328 sensor->info_priv.flip = ctrl->value;
2339 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2341 const struct v4l2_queryctrl *qctrl;
2342 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2343 struct sensor *sensor = to_sensor(client);
2345 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2349 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2353 switch (ext_ctrl->id)
2355 case V4L2_CID_SCENE:
2357 ext_ctrl->value = sensor->info_priv.scene;
2360 case V4L2_CID_EFFECT:
2362 ext_ctrl->value = sensor->info_priv.effect;
2365 case V4L2_CID_ZOOM_ABSOLUTE:
2367 ext_ctrl->value = sensor->info_priv.digitalzoom;
2370 case V4L2_CID_ZOOM_RELATIVE:
2374 case V4L2_CID_FOCUS_ABSOLUTE:
2378 case V4L2_CID_FOCUS_RELATIVE:
2382 case V4L2_CID_FLASH:
2384 ext_ctrl->value = sensor->info_priv.flash;
2392 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2394 const struct v4l2_queryctrl *qctrl;
2395 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2396 struct sensor *sensor = to_sensor(client);
2399 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2403 SENSOR_TR("\n %s ioctrl id = 0x%x is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2408 switch (ext_ctrl->id)
2410 #if CONFIG_SENSOR_Scene
2411 case V4L2_CID_SCENE:
2413 if (ext_ctrl->value != sensor->info_priv.scene)
2415 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2417 sensor->info_priv.scene = ext_ctrl->value;
2422 #if CONFIG_SENSOR_Effect
2423 case V4L2_CID_EFFECT:
2425 if (ext_ctrl->value != sensor->info_priv.effect)
2427 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2429 sensor->info_priv.effect= ext_ctrl->value;
2434 #if CONFIG_SENSOR_DigitalZoom
2435 case V4L2_CID_ZOOM_ABSOLUTE:
2437 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2440 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2442 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2444 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2446 sensor->info_priv.digitalzoom += val_offset;
2448 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2453 case V4L2_CID_ZOOM_RELATIVE:
2455 if (ext_ctrl->value)
2457 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2459 sensor->info_priv.digitalzoom += ext_ctrl->value;
2461 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2466 #if CONFIG_SENSOR_Focus
2467 case V4L2_CID_FOCUS_ABSOLUTE:
2469 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2472 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2473 if (ext_ctrl->value == qctrl->minimum) {
2474 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2475 } else if (ext_ctrl->value == qctrl->maximum) {
2476 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2478 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2484 case V4L2_CID_FOCUS_RELATIVE:
2486 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2489 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2492 case V4L2_CID_FOCUS_AUTO:
2494 if (ext_ctrl->value == 1) {
2495 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2497 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2498 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2499 if (ext_ctrl->value == 0)
2500 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2504 case V4L2_CID_FOCUS_CONTINUOUS:
2506 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2507 if (ext_ctrl->value == 1) {
2508 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2510 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2513 if (ext_ctrl->value == 0)
2514 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2519 #if CONFIG_SENSOR_Flash
2520 case V4L2_CID_FLASH:
2522 sensor->info_priv.flash = ext_ctrl->value;
2524 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2535 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2537 struct i2c_client *client = sd->priv;
2538 struct soc_camera_device *icd = client->dev.platform_data;
2539 int i, error_cnt=0, error_idx=-1;
2542 for (i=0; i<ext_ctrl->count; i++) {
2543 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2550 error_idx = ext_ctrl->count;
2552 if (error_idx != -1) {
2553 ext_ctrl->error_idx = error_idx;
2560 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2562 struct i2c_client *client = sd->priv;
2563 struct soc_camera_device *icd = client->dev.platform_data;
2564 int i, error_cnt=0, error_idx=-1;
2566 for (i=0; i<ext_ctrl->count; i++) {
2567 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2574 error_idx = ext_ctrl->count;
2576 if (error_idx != -1) {
2577 ext_ctrl->error_idx = error_idx;
2584 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2586 struct i2c_client *client = sd->priv;
2587 struct sensor *sensor = to_sensor(client);
2590 sensor->info_priv.enable = 1;
2591 } else if (enable == 0) {
2592 sensor->info_priv.enable = 0;
2595 sensor_s_stream_end:
2599 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2600 * this wasn't our capture interface, so, we wait for the right one */
2601 static int sensor_video_probe(struct soc_camera_device *icd,
2602 struct i2c_client *client)
2605 struct sensor *sensor = to_sensor(client);
2607 /* We must have a parent by now. And it cannot be a wrong one.
2608 * So this entire test is completely redundant. */
2609 if (!icd->dev.parent ||
2610 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2613 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2615 goto sensor_video_probe_err;
2619 #if (SENSOR_RESET_REG != SEQUENCE_END)
2620 struct reginfo reg_info;
2621 reg_info.reg = SENSOR_RESET_REG;
2622 reg_info.val = SENSOR_RESET_VAL;
2623 reg_info.reg_len = SENSOR_RESET_REG_LEN;
2624 ret = sensor_write(client, ®_info);
2626 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2628 goto sensor_video_probe_err;
2631 mdelay(5); //delay 5 microseconds
2634 /* check if it is an sensor sensor */
2635 #if (SENSOR_ID_REG != SEQUENCE_END)
2636 ret = sensor_read(client, SENSOR_ID_REG, &pid);
2638 SENSOR_TR("read chip id failed\n");
2640 goto sensor_video_probe_err;
2643 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2648 if (pid == SENSOR_ID) {
2649 sensor->model = SENSOR_V4L2_IDENT;
2651 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2653 goto sensor_video_probe_err;
2656 icd->formats = sensor_colour_formats;
2657 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2661 sensor_video_probe_err:
2665 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2667 struct i2c_client *client = sd->priv;
2668 struct sensor *sensor = to_sensor(client);
2670 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2673 case RK29_CAM_SUBDEV_DEACTIVATE:
2675 sensor_deactivate(client);
2678 case RK29_CAM_SUBDEV_IOREQUEST:
2680 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2685 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2694 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2695 .init = sensor_init,
2696 .g_ctrl = sensor_g_control,
2697 .s_ctrl = sensor_s_control,
2698 .g_ext_ctrls = sensor_g_ext_controls,
2699 .s_ext_ctrls = sensor_s_ext_controls,
2700 .g_chip_ident = sensor_g_chip_ident,
2701 .ioctl = sensor_ioctl,
2704 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2705 .s_fmt = sensor_s_fmt,
2706 .g_fmt = sensor_g_fmt,
2707 .try_fmt = sensor_try_fmt,
2708 .s_stream = sensor_s_stream,
2711 static struct v4l2_subdev_ops sensor_subdev_ops = {
2712 .core = &sensor_subdev_core_ops,
2713 .video = &sensor_subdev_video_ops,
2716 static int sensor_probe(struct i2c_client *client,
2717 const struct i2c_device_id *did)
2719 struct sensor *sensor;
2720 struct soc_camera_device *icd = client->dev.platform_data;
2721 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2722 struct soc_camera_link *icl;
2725 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2727 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2731 icl = to_soc_camera_link(icd);
2733 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2737 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2738 dev_warn(&adapter->dev,
2739 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2743 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2747 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2749 /* Second stage probe - when a capture adapter is there */
2750 icd->ops = &sensor_ops;
2751 icd->y_skip_top = 0;
2752 #if CONFIG_SENSOR_I2C_NOSCHED
2753 atomic_set(&sensor->tasklock_cnt,0);
2756 ret = sensor_video_probe(icd, client);
2759 i2c_set_clientdata(client, NULL);
2763 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2767 static int sensor_remove(struct i2c_client *client)
2769 struct sensor *sensor = to_sensor(client);
2770 struct soc_camera_device *icd = client->dev.platform_data;
2772 #if CONFIG_SENSOR_Focus
2773 if (sensor->sensor_wq) {
2774 destroy_workqueue(sensor->sensor_wq);
2775 sensor->sensor_wq = NULL;
2780 i2c_set_clientdata(client, NULL);
2781 client->driver = NULL;
2787 static const struct i2c_device_id sensor_id[] = {
2788 {SENSOR_NAME_STRING(), 0 },
2791 MODULE_DEVICE_TABLE(i2c, sensor_id);
2793 static struct i2c_driver sensor_i2c_driver = {
2795 .name = SENSOR_NAME_STRING(),
2797 .probe = sensor_probe,
2798 .remove = sensor_remove,
2799 .id_table = sensor_id,
2802 static int __init sensor_mod_init(void)
2804 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2805 return i2c_add_driver(&sensor_i2c_driver);
2808 static void __exit sensor_mod_exit(void)
2810 i2c_del_driver(&sensor_i2c_driver);
2813 device_initcall_sync(sensor_mod_init);
2814 module_exit(sensor_mod_exit);
2816 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2817 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2818 MODULE_LICENSE("GPL");