3 o* Driver for MT9M001 CMOS Image Sensor from Micron
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/videodev2.h>
13 #include <linux/slab.h>
14 #include <linux/i2c.h>
15 #include <linux/log2.h>
16 #include <linux/platform_device.h>
17 #include <linux/delay.h>
18 #include <linux/circ_buf.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 <mach/rk_camera.h>
24 #include <linux/vmalloc.h>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(1, 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 RK_CAM_SENSOR_SIV120B
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_SIV120B
49 #define SENSOR_ID 0x12
50 #define SENSOR_MIN_WIDTH 640//176
51 #define SENSOR_MIN_HEIGHT 480//144
52 #define SENSOR_MAX_WIDTH 640
53 #define SENSOR_MAX_HEIGHT 480
54 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT sensor_init_height
56 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
57 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
58 #define SENSOR_BUS_PARAM sensor_init_busparam
60 #define CONFIG_SENSOR_WhiteBalance 0
61 #define CONFIG_SENSOR_Brightness 0
62 #define CONFIG_SENSOR_Contrast 0
63 #define CONFIG_SENSOR_Saturation 0
64 #define CONFIG_SENSOR_Effect 1
65 #define CONFIG_SENSOR_Scene 0
66 #define CONFIG_SENSOR_DigitalZoom 0
67 #define CONFIG_SENSOR_Focus 0
68 #define CONFIG_SENSOR_Exposure 0
69 #define CONFIG_SENSOR_Flash 0
70 #define CONFIG_SENSOR_Mirror 0
71 #define CONFIG_SENSOR_Flip 0
73 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
74 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
75 #define CONFIG_SENSOR_I2C_NOSCHED 0
76 #define CONFIG_SENSOR_I2C_RDWRCHK 0
78 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
79 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
80 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
81 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
82 #define COLOR_TEMPERATURE_OFFICE_DN 3500
83 #define COLOR_TEMPERATURE_OFFICE_UP 5000
84 #define COLOR_TEMPERATURE_HOME_DN 2500
85 #define COLOR_TEMPERATURE_HOME_UP 3500
87 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
88 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
90 #define SENSOR_AF_IS_ERR (0x00<<0)
91 #define SENSOR_AF_IS_OK (0x01<<0)
92 #define SENSOR_INIT_IS_ERR (0x00<<28)
93 #define SENSOR_INIT_IS_OK (0x01<<28)
100 static s32 sensor_init_width = 0;
101 static s32 sensor_init_height = 0;
102 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
103 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
104 static struct reginfo* sensor_init_data_p = NULL;
105 static struct reginfo* sensor_init_winseq_p = NULL;
106 static struct reginfo* sensor_init_winseq_board = NULL;
107 /* init 640X480 VGA */
108 static struct reginfo sensor_init_data[] =
113 {0x13,0x17}, // #anti_black sun
114 {0x16,0xcf}, // #0xb6
116 {0x20,0x00}, // #P_BNKT
117 {0x21,0x01}, // #P_HBNKT
118 {0x22,0x01}, // #P_ROWFIL
119 {0x23,0x01}, // #P_VBNKT
121 {0x40,0x00}, // #0x8b
122 {0x41,0x00}, // #0x96
123 {0x42,0x00}, // #0xda
124 {0x43,0x00}, // #0x83
128 {0x11,0x14}, // # 6fps at lowlux
129 {0x12,0x78}, // # D65 target 0x74
130 {0x13,0x78}, // # CWF target 0x74
131 {0x14,0x78}, // # A target 0x74
134 {0x40,0x50}, // # Max x8
136 {0x41,0x20}, // #AG_TOP1 0x28
137 {0x42,0x20}, // #AG_TOP0 0x28
138 {0x43,0x00}, // #AG_MIN1 0x08
139 {0x44,0x00}, // #AG_MIN0 0x08
140 {0x45,0x00}, // #G50_dec 0x09
141 {0x46,0x0a}, // #G33_dec 0x17
142 {0x47,0x10}, // #G25_dec 0x1d
143 {0x48,0x13}, // #G20_dec 0x21
144 {0x49,0x15}, // #G12_dec 0x23
145 {0x4a,0x18}, // #G09_dec 0x24
146 {0x4b,0x1a}, // #G06_dec 0x26
147 {0x4c,0x1d}, // #G03_dec 0x27
148 {0x4d,0x20}, // #G100_inc 0x27
149 {0x4e,0x10}, // #G50_inc 0x1a
150 {0x4f,0x0a}, // #G33_inc 0x14
151 {0x50,0x08}, // #G25_inc 0x11
152 {0x51,0x06}, // #G20_inc 0x0f
153 {0x52,0x05}, // #G12_inc 0x0d
154 {0x53,0x04}, // #G09_inc 0x0c
155 {0x54,0x02}, // #G06_inc 0x0a
156 {0x55,0x01}, // #G03_inc 0x09
165 {0x15,0xfe}, // # R gain Top
166 {0x16,0x70}, // # R gain bottom 0x80
167 {0x17,0xea}, // # B gain Top
168 {0x18,0x80}, // # B gain bottom
169 {0x19,0xa0}, // # Cr top value
170 {0x1a,0x60}, // # Cr bottom value
171 {0x1b,0xa0}, // # Cb top value
172 {0x1c,0x60}, // # Cb bottom value
175 {0x20,0xe8}, // # AWB luminous top value
176 {0x21,0x20}, // # AWB luminous bottom value
181 {0x27,0x10}, // # ST for outdoor enable
182 {0x28,0x1a}, // # ST for outdoor disable
183 {0x29,0xb8}, // # AWB R gain at outdoor
184 {0x2a,0x94}, // # AWB B gain at outdoor
212 {0x63,0x98}, // # R D30 to D20
213 {0x64,0xa8}, // # B D30 to D20
214 {0x65,0x98}, // # R D20 to D30
215 {0x66,0xa8}, // # B D20 to D30
216 {0x67,0xc8}, // # R D65 to D30
217 {0x68,0x9f}, // # B D65 to D30
218 {0x69,0xc8}, // # R D30 to D65
219 {0x6a,0x9f}, // # B D30 to D65
228 //ading Register Setting
235 {0x46,0x11}, // # left R gain[7:4], right R gain[3:0]
236 {0x47,0x23}, // # top R gain[7:4], bottom R gain[3:0]
237 {0x48,0x10}, // # left Gr gain[7:4], right Gr gain[3:0]
238 {0x49,0x12}, // # top Gr gain[7:4], bottom Gr gain[3:0]
239 {0x4a,0x01}, // # left Gb gain[7:4], right Gb gain[3:0]
240 {0x4b,0x12}, // # top Gb gain[7:4], bottom Gb gain[3:0]
241 {0x4c,0x00}, // # left B gain[7:4], right B gain[3:0]
242 {0x4d,0x11}, // # top B gain[7:4], bottom B gain[3:0]
243 {0x4e,0x04}, // # X-axis center high[3:2], Y-axis center high[1:0]
244 {0x4f,0x50}, // # X-axis center low[7:0]
245 {0x50,0xf6}, // # Y-axis center low[7:0]
246 {0x51,0x80}, // # Shading Center Gain
247 {0x52,0x00}, // # Shading R Offset
248 {0x53,0x00}, // # Shading Gr Offset
249 {0x54,0x00}, // # Shading Gb Offset
250 {0x55,0x00}, // # Shading B Offset
255 {0x32,0xA }, // #0x10
256 {0x33,0x1E}, // #0x27
257 {0x34,0x42}, // #0x48
258 {0x35,0x5E}, // #0x62
259 {0x36,0x74}, // #0x77
260 {0x37,0x86}, // #0x88
261 {0x38,0x96}, // #0x97
262 {0x39,0xA4}, // #0xA5
263 {0x3a,0xB1}, // #0xB2
264 {0x3b,0xC8}, // #0xC9
265 {0x3c,0xDC}, // #0xDB
266 {0x3d,0xEF}, // #0xED
267 {0x3e,0xF8}, // #0xF7
268 {0x3f,0xFF}, // #0xFF
270 //lor matrix (D65) - Daylight
271 {0x71,0x3b}, // #0x3a
272 {0x72,0xca}, // #0xc9
273 {0x73,0xfb}, // #0xfe
274 {0x74,0x0f}, // #0x10
275 {0x75,0x22}, // #0x23
276 {0x76,0x0f}, // #0x0b
277 {0x77,0xf7}, // #0xfb
278 {0x78,0xc7}, // #0xce
279 {0x79,0x42}, // #0x38
281 //lor matrix (D30) - CWF
282 {0x7a,0x3b}, // #0x39
283 {0x7b,0xcb}, // #0xcd
284 {0x7c,0xfa}, // #0xfa
285 {0x7d,0x0e}, // #0x0a
286 {0x7e,0x21}, // #0x29
287 {0x7f,0x11}, // #0x0c
288 {0x80,0xf4}, // #0xf5
289 {0x81,0xc4}, // #0xc7
290 {0x82,0x48}, // #0x44
292 //lor matrix (D20) - A
293 {0x83,0x3a}, // #0x3a
294 {0x84,0xcd}, // #0xcc
295 {0x85,0xf9}, // #0xfa
296 {0x86,0x15}, // #0xfe
297 {0x87,0x26}, // #0x3a
298 {0x88,0x05}, // #0x08
299 {0x89,0xed}, // #0xf9
300 {0x8a,0xbb}, // #0xc3
301 {0x8b,0x57}, // #0x44
304 {0x17,0xC8}, // # DPCNRCTRL
305 {0x18,0x18}, // # DPTHR
306 {0x19,0x48}, // # [7:6] G DP Number Thr @ Dark | [5:0] DPTHRMIN
307 {0x1A,0x48}, // # [7:6] G DP Number Thr @ Normal | [5:0] DPTHRMAX
308 {0x1B,0x24}, // # DPTHRSLP( [7:4] @ Normal | [3:0] @ Dark )
309 {0x1C,0x00}, // # NRTHR
310 {0x1D,0x48}, // # [7:6] C DP Number Thr @ Dark | [5:0] NRTHRMIN 0x48
311 {0x1E,0x48}, // # [7:6] C DP Number Thr @ Normal | [5:0] NRTHRMAX
312 {0x1F,0x68}, // # NRTHRSLP( [7:4] @ Normal | [3:0] @ Dark ) 0x20
313 {0x20,0x04}, // # IllumiInfo STRTNOR
314 {0x21,0x0f}, // # IllumiInfo STRTDRK
316 {0x56,0x10}, // # lowlux shading enable
317 {0x57,0x92}, // # lowlux shading
318 {0x58,0x00}, // # lowlux shading on
321 {0x90,0x18}, // # upper gain
322 {0x91,0x18}, // # down gain
323 {0x92,0x04}, // # upper coring value
324 {0x96,0x04}, // # down coring value
326 {0x9f,0x10}, // # Yeugain
327 {0xa0,0x10}, // # Yedgain9
328 {0xa9,0x12}, // # Cr saturation
329 {0xaa,0x12}, // # Cb saturation
330 {0xb9,0x10}, // # 0x13 lowlux color
331 {0xba,0x20}, // # 0x10 lowlux color
333 {0xdd,0x4f}, // # ENHCTRL5
334 {0xde,0xba}, // # NOIZCTRL
367 /* 640X480 VGA @30fps for both preview & capture. */
368 static struct reginfo sensor_vga[] =
386 static struct reginfo sensor_cif[] =
392 static struct reginfo sensor_qvga[] =
398 static struct reginfo sensor_qcif[] =
403 static struct reginfo sensor_ClrFmt_YUYV[]=
409 static struct reginfo sensor_ClrFmt_UYVY[]=
416 #if CONFIG_SENSOR_WhiteBalance
417 static struct reginfo sensor_WhiteB_Auto[]=
419 {0x84, 0x6C}, //Contrast 4
443 {0x0f, 0x4a}, //Saturation 3
455 {0x4f, 0x2e}, //Brightness 3
469 /* Cloudy Colour Temperature : 6500K - 8000K */
470 static struct reginfo sensor_WhiteB_Cloudy[]=
472 {0x7C,0x04}, //Contrast 5
506 {0x4f,0x3a}, //Saturation 4
512 {0x4f, 0x2e}, //Brightness 3
525 /* ClearDay Colour Temperature : 5000K - 6500K */
526 static struct reginfo sensor_WhiteB_ClearDay[]=
529 {0x7C,0x04}, //Contrast 5
563 {0x4f,0x3a}, //Saturation 4
569 {0x4f, 0x2e}, //Brightness 3
582 /* Office Colour Temperature : 3500K - 5000K */
583 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
586 {0x84, 0x6C}, //Contrast 4
610 {0x0f, 0x4a}, //Saturation 3
622 {0x4f, 0x2e}, //Brightness 3
638 /* Home Colour Temperature : 2500K - 3500K */
639 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
642 {0x84, 0x6C}, //Contrast 4
666 {0x0f, 0x4a}, //Saturation 3
678 {0x4f, 0x2e}, //Brightness 3
691 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
692 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
696 #if CONFIG_SENSOR_Brightness
697 static struct reginfo sensor_Brightness0[]=
700 {0x3301, 0xff},//bit[7]:1, enable SDE
707 static struct reginfo sensor_Brightness1[]=
710 {0x3301, 0xff},//bit[7]:1, enable SDE
717 static struct reginfo sensor_Brightness2[]=
720 {0x3301, 0xff},//bit[7]:1, enable SDE
727 static struct reginfo sensor_Brightness3[]=
730 {0x3301, 0xff},//bit[7]:1, enable SDE
737 static struct reginfo sensor_Brightness4[]=
740 {0x3301, 0xff},//bit[7]:1, enable SDE
747 static struct reginfo sensor_Brightness5[]=
750 {0x3301, 0xff},//bit[7]:1, enable SDE
751 {0x3391, 0x04}, //bit[2] enable
752 {0x3390, 0x41}, //bit[3] sign of brightness
756 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
757 sensor_Brightness4, sensor_Brightness5,NULL,
762 #if CONFIG_SENSOR_Effect
763 static struct reginfo sensor_Effect_Normal[] =
772 static struct reginfo sensor_Effect_WandB[] =
782 static struct reginfo sensor_Effect_Sepia[] =
791 static struct reginfo sensor_Effect_Negative[] =
801 static struct reginfo sensor_Effect_Bluish[] =
811 static struct reginfo sensor_Effect_Green[] =
820 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
821 /*sensor_Effect_Bluish,*/ sensor_Effect_Green,NULL,
824 #if CONFIG_SENSOR_Exposure
825 static struct reginfo sensor_Exposure0[]=
830 static struct reginfo sensor_Exposure1[]=
835 static struct reginfo sensor_Exposure2[]=
840 static struct reginfo sensor_Exposure3[]=
845 static struct reginfo sensor_Exposure4[]=
850 static struct reginfo sensor_Exposure5[]=
855 static struct reginfo sensor_Exposure6[]=
860 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
861 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
864 #if CONFIG_SENSOR_Saturation
865 static struct reginfo sensor_Saturation0[]=
870 static struct reginfo sensor_Saturation1[]=
875 static struct reginfo sensor_Saturation2[]=
879 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
882 #if CONFIG_SENSOR_Contrast
883 static struct reginfo sensor_Contrast0[]=
888 static struct reginfo sensor_Contrast1[]=
893 static struct reginfo sensor_Contrast2[]=
898 static struct reginfo sensor_Contrast3[]=
903 static struct reginfo sensor_Contrast4[]=
909 static struct reginfo sensor_Contrast5[]=
914 static struct reginfo sensor_Contrast6[]=
918 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
919 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
923 #if CONFIG_SENSOR_Mirror
924 static struct reginfo sensor_MirrorOn[]=
929 static struct reginfo sensor_MirrorOff[]=
933 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
935 #if CONFIG_SENSOR_Flip
936 static struct reginfo sensor_FlipOn[]=
941 static struct reginfo sensor_FlipOff[]=
945 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
948 #if CONFIG_SENSOR_Scene
949 static struct reginfo sensor_SceneAuto[] =
954 static struct reginfo sensor_SceneNight[] =
958 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
961 #if CONFIG_SENSOR_DigitalZoom
962 static struct reginfo sensor_Zoom0[] =
967 static struct reginfo sensor_Zoom1[] =
972 static struct reginfo sensor_Zoom2[] =
978 static struct reginfo sensor_Zoom3[] =
982 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
984 static const struct v4l2_querymenu sensor_menus[] =
986 #if CONFIG_SENSOR_WhiteBalance
987 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
988 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
989 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
992 #if CONFIG_SENSOR_Effect
993 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
994 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
995 /* { .id = V4L2_CID_EFFECT, .index = 4, .name = "posterize", .reserved = 0,} ,*/{ .id = V4L2_CID_EFFECT, .index = 4, .name = "aqua", .reserved = 0,},
998 #if CONFIG_SENSOR_Scene
999 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1002 #if CONFIG_SENSOR_Flash
1003 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1004 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1008 static const struct v4l2_queryctrl sensor_controls[] =
1010 #if CONFIG_SENSOR_WhiteBalance
1012 .id = V4L2_CID_DO_WHITE_BALANCE,
1013 .type = V4L2_CTRL_TYPE_MENU,
1014 .name = "White Balance Control",
1022 #if CONFIG_SENSOR_Brightness
1024 .id = V4L2_CID_BRIGHTNESS,
1025 .type = V4L2_CTRL_TYPE_INTEGER,
1026 .name = "Brightness Control",
1034 #if CONFIG_SENSOR_Effect
1036 .id = V4L2_CID_EFFECT,
1037 .type = V4L2_CTRL_TYPE_MENU,
1038 .name = "Effect Control",
1046 #if CONFIG_SENSOR_Exposure
1048 .id = V4L2_CID_EXPOSURE,
1049 .type = V4L2_CTRL_TYPE_INTEGER,
1050 .name = "Exposure Control",
1058 #if CONFIG_SENSOR_Saturation
1060 .id = V4L2_CID_SATURATION,
1061 .type = V4L2_CTRL_TYPE_INTEGER,
1062 .name = "Saturation Control",
1070 #if CONFIG_SENSOR_Contrast
1072 .id = V4L2_CID_CONTRAST,
1073 .type = V4L2_CTRL_TYPE_INTEGER,
1074 .name = "Contrast Control",
1082 #if CONFIG_SENSOR_Mirror
1084 .id = V4L2_CID_HFLIP,
1085 .type = V4L2_CTRL_TYPE_BOOLEAN,
1086 .name = "Mirror Control",
1094 #if CONFIG_SENSOR_Flip
1096 .id = V4L2_CID_VFLIP,
1097 .type = V4L2_CTRL_TYPE_BOOLEAN,
1098 .name = "Flip Control",
1106 #if CONFIG_SENSOR_Scene
1108 .id = V4L2_CID_SCENE,
1109 .type = V4L2_CTRL_TYPE_MENU,
1110 .name = "Scene Control",
1118 #if CONFIG_SENSOR_DigitalZoom
1120 .id = V4L2_CID_ZOOM_RELATIVE,
1121 .type = V4L2_CTRL_TYPE_INTEGER,
1122 .name = "DigitalZoom Control",
1128 .id = V4L2_CID_ZOOM_ABSOLUTE,
1129 .type = V4L2_CTRL_TYPE_INTEGER,
1130 .name = "DigitalZoom Control",
1138 #if CONFIG_SENSOR_Focus
1140 .id = V4L2_CID_FOCUS_RELATIVE,
1141 .type = V4L2_CTRL_TYPE_INTEGER,
1142 .name = "Focus Control",
1148 .id = V4L2_CID_FOCUS_ABSOLUTE,
1149 .type = V4L2_CTRL_TYPE_INTEGER,
1150 .name = "Focus Control",
1154 .default_value = 125,
1158 #if CONFIG_SENSOR_Flash
1160 .id = V4L2_CID_FLASH,
1161 .type = V4L2_CTRL_TYPE_MENU,
1162 .name = "Flash Control",
1171 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1172 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1173 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1174 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1175 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1176 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1177 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1178 static int sensor_resume(struct soc_camera_device *icd);
1179 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1180 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1181 #if CONFIG_SENSOR_Effect
1182 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1184 #if CONFIG_SENSOR_WhiteBalance
1185 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1187 static int sensor_deactivate(struct i2c_client *client);
1189 static struct soc_camera_ops sensor_ops =
1191 .suspend = sensor_suspend,
1192 .resume = sensor_resume,
1193 .set_bus_param = sensor_set_bus_param,
1194 .query_bus_param = sensor_query_bus_param,
1195 .controls = sensor_controls,
1196 .menus = sensor_menus,
1197 .num_controls = ARRAY_SIZE(sensor_controls),
1198 .num_menus = ARRAY_SIZE(sensor_menus),
1201 /* only one fixed colorspace per pixelcode */
1202 struct sensor_datafmt {
1203 enum v4l2_mbus_pixelcode code;
1204 enum v4l2_colorspace colorspace;
1207 /* Find a data format by a pixel code in an array */
1208 static const struct sensor_datafmt *sensor_find_datafmt(
1209 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1213 for (i = 0; i < n; i++)
1214 if (fmt[i].code == code)
1220 static const struct sensor_datafmt sensor_colour_fmts[] = {
1221 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1222 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1225 typedef struct sensor_info_priv_s
1239 unsigned char mirror; /* HFLIP */
1240 unsigned char flip; /* VFLIP */
1241 unsigned int winseqe_cur_addr;
1242 struct sensor_datafmt fmt;
1243 unsigned int funmodule_state;
1245 } sensor_info_priv_t;
1249 struct v4l2_subdev subdev;
1250 struct i2c_client *client;
1251 sensor_info_priv_t info_priv;
1252 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1253 #if CONFIG_SENSOR_I2C_NOSCHED
1254 atomic_t tasklock_cnt;
1256 struct rkcamera_platform_data *sensor_io_request;
1257 struct rkcamera_gpio_res *sensor_gpio_res;
1260 static struct sensor* to_sensor(const struct i2c_client *client)
1262 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1265 static int sensor_task_lock(struct i2c_client *client, int lock)
1267 #if CONFIG_SENSOR_I2C_NOSCHED
1269 struct sensor *sensor = to_sensor(client);
1272 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1273 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1274 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1278 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1279 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1280 goto sensor_task_lock_err;
1285 atomic_add(1, &sensor->tasklock_cnt);
1287 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1288 atomic_sub(1, &sensor->tasklock_cnt);
1290 if (atomic_read(&sensor->tasklock_cnt) == 0)
1295 sensor_task_lock_err:
1303 /* sensor register write */
1304 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)
1308 struct i2c_msg msg[1];
1310 buf[0] = reg & 0xFF;
1313 msg->addr = client->addr;
1314 msg->flags = client->flags;
1316 msg->len = sizeof(buf);
1317 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1318 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1323 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1324 err = i2c_transfer(client->adapter, msg, 1);
1329 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1337 /* sensor register read */
1338 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)
1343 struct i2c_msg msg[2];
1345 //buf[0] = reg >> 8;
1347 buf[1] = reg & 0xFF;
1349 msg[0].addr = client->addr;
1350 msg[0].flags = client->flags;
1352 msg[0].len = sizeof(buf);
1353 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1354 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1356 msg[1].addr = client->addr;
1357 msg[1].flags = client->flags|I2C_M_RD;
1360 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1361 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1365 while ((cnt--) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1366 err = i2c_transfer(client->adapter, msg, 2);
1372 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1380 /* write a array of registers */
1382 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1387 while (regarray[i].reg != 0)
1389 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1392 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1400 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1405 while (regarray[i].reg != 0)
1407 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1410 SENSOR_TR("%s..write failed current i = %d\n", SENSOR_NAME_STRING(),i);
1413 err = sensor_read(client, regarray[i].reg, &val_read);
1414 SENSOR_TR("%s..reg[0x%x]=0x%x,0x%x\n", SENSOR_NAME_STRING(),regarray[i].reg, val_read, regarray[i].val);
1420 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1422 struct soc_camera_link *icl = to_soc_camera_link(icd);
1425 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1428 case Sensor_PowerDown:
1430 if (icl->powerdown) {
1431 ret = icl->powerdown(icd->pdev, on);
1432 if (ret == RK_CAM_IO_SUCCESS) {
1436 icl->reset(icd->pdev);
1438 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1440 goto sensor_power_end;
1447 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1448 struct sensor *sensor = to_sensor(client);
1450 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1451 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1457 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1465 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1467 struct i2c_client *client = v4l2_get_subdevdata(sd);
1468 struct soc_camera_device *icd = client->dev.platform_data;
1469 struct sensor *sensor = to_sensor(client);
1470 const struct v4l2_queryctrl *qctrl;
1471 const struct sensor_datafmt *fmt;
1473 int ret,pid = 0,i = 0,j=0;
1474 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1475 sensor_init_data_p = sensor_init_data;
1476 sensor_init_winseq_p = sensor_vga;
1477 sensor_init_width = 640;
1478 sensor_init_height = 480;
1479 if (tmp_plat_data != NULL) {
1480 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1481 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1482 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1486 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1487 //user has defined the init data
1489 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1490 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1491 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1492 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1494 sensor_init_data_p = sensor_init_data;
1496 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1497 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1500 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1501 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1502 if(sensor_init_winseq_board)
1504 vfree(sensor_init_winseq_board);
1505 sensor_init_winseq_board = NULL;
1507 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1508 if(!sensor_init_winseq_board)
1509 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1510 for(j = 0;j< tmp_winseq_size;j++){
1511 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1512 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1514 sensor_init_winseq_p = sensor_init_winseq_board;
1516 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1517 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1519 //init width,height,bus,pixelcode
1520 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1521 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1522 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1523 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1524 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1525 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1526 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1527 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1529 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1531 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1533 goto sensor_INIT_ERR;
1537 if (sensor_task_lock(client,1)<0)
1538 goto sensor_INIT_ERR;
1539 // ret = sensor_write(client, 0x12, 0x80);
1542 // SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1544 // goto sensor_INIT_ERR;
1547 // mdelay(5); //delay 5 microseconds
1549 for(i = 0; i < sizeof(sensor_init_data)/2;i++){
1551 // ret = sensor_write(client, sensor_init_data + i*2, sensor_init_data + i*2 + 1);
1552 // printk("write to reg[0x%x] 0x%x\n",sensor_init_data[i].reg,sensor_init_data[i].val);
1553 ret = sensor_write(client, sensor_init_data_p[i].reg, sensor_init_data_p[i].val);
1554 //ret = sensor_write_array(client, sensor_init_data);
1557 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1558 goto sensor_INIT_ERR;
1560 // sensor_read(client,sensor_init_data[i].reg,&tmp);
1561 // printk("read from reg[0x%x] 0x%x\n",sensor_init_data[i].reg,tmp);
1563 sensor_task_lock(client,0);
1565 sensor->info_priv.winseqe_cur_addr = (int)SENSOR_INIT_WINSEQADR;
1566 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1568 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1570 goto sensor_INIT_ERR;
1572 sensor->info_priv.fmt = *fmt;
1574 /* sensor sensor information for initialization */
1575 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1577 sensor->info_priv.whiteBalance = qctrl->default_value;
1578 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1580 sensor->info_priv.brightness = qctrl->default_value;
1581 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1583 sensor->info_priv.effect = qctrl->default_value;
1584 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1586 sensor->info_priv.exposure = qctrl->default_value;
1588 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1590 sensor->info_priv.saturation = qctrl->default_value;
1591 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1593 sensor->info_priv.contrast = qctrl->default_value;
1594 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1596 sensor->info_priv.mirror = qctrl->default_value;
1597 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1599 sensor->info_priv.flip = qctrl->default_value;
1600 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1602 sensor->info_priv.scene = qctrl->default_value;
1603 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1605 sensor->info_priv.digitalzoom = qctrl->default_value;
1607 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1608 #if CONFIG_SENSOR_Focus
1610 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1612 sensor->info_priv.focus = qctrl->default_value;
1615 #if CONFIG_SENSOR_Flash
1616 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1618 sensor->info_priv.flash = qctrl->default_value;
1621 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);
1622 sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
1625 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1626 sensor_task_lock(client,0);
1627 sensor_deactivate(client);
1631 static int sensor_deactivate(struct i2c_client *client)
1633 struct soc_camera_device *icd = client->dev.platform_data;
1634 struct sensor *sensor = to_sensor(client);
1636 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1638 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1639 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1641 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1642 icd->user_width = SENSOR_INIT_WIDTH;
1643 icd->user_height = SENSOR_INIT_HEIGHT;
1645 sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
1648 static struct reginfo sensor_power_down_sequence[]=
1652 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1655 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1658 if (pm_msg.event == PM_EVENT_SUSPEND) {
1659 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1660 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1662 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1665 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1667 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1672 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1678 static int sensor_resume(struct soc_camera_device *icd)
1682 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1684 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1688 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1694 static int sensor_set_bus_param(struct soc_camera_device *icd,
1695 unsigned long flags)
1701 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1703 struct soc_camera_link *icl = to_soc_camera_link(icd);
1704 unsigned long flags = SENSOR_BUS_PARAM;
1706 return soc_camera_apply_sensor_flags(icl, flags);
1709 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1711 struct i2c_client *client = v4l2_get_subdevdata(sd);
1712 struct soc_camera_device *icd = client->dev.platform_data;
1713 struct sensor *sensor = to_sensor(client);
1715 mf->width = icd->user_width;
1716 mf->height = icd->user_height;
1717 mf->code = sensor->info_priv.fmt.code;
1718 mf->colorspace = sensor->info_priv.fmt.colorspace;
1719 mf->field = V4L2_FIELD_NONE;
1723 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1727 if ((mf->width == 1024) && (mf->height == 768)) {
1729 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1731 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1733 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1735 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1740 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1744 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1748 if ((mf->width == 1280) && (mf->height == 720)) {
1750 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1755 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1758 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1760 struct i2c_client *client = v4l2_get_subdevdata(sd);
1761 struct sensor *sensor = to_sensor(client);
1762 const struct sensor_datafmt *fmt;
1763 struct reginfo *winseqe_set_addr=NULL;
1765 int ret=0, set_w,set_h,i;
1767 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1768 ARRAY_SIZE(sensor_colour_fmts));
1771 goto sensor_s_fmt_end;
1774 if (sensor->info_priv.fmt.code != mf->code) {
1777 case V4L2_MBUS_FMT_YUYV8_2X8:
1779 winseqe_set_addr = sensor_ClrFmt_YUYV;
1780 sensor_read(client, 0x3a, &readval);
1781 sensor_write(client,0x3a, readval&0xf7);
1782 sensor_read(client,0x3d,&readval);
1783 sensor_write(client,0x3d,readval&0xfe);
1786 case V4L2_MBUS_FMT_UYVY8_2X8:
1788 winseqe_set_addr = sensor_ClrFmt_UYVY;
1789 sensor_read(client, 0x3a, &readval);
1790 sensor_write(client,0x3a, readval|0x08);
1791 sensor_read(client,0x3d,&readval);
1792 sensor_write(client,0x3d,readval&0xfe);
1798 if (winseqe_set_addr != NULL) {
1799 sensor_write_array(client, winseqe_set_addr);
1800 sensor->info_priv.fmt.code = mf->code;
1801 sensor->info_priv.fmt.colorspace= mf->colorspace;
1802 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1804 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1811 if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1813 winseqe_set_addr = sensor_qcif;
1817 else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1819 winseqe_set_addr = sensor_qvga;
1823 else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1825 winseqe_set_addr = sensor_cif;
1829 else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1831 winseqe_set_addr = sensor_vga;
1837 winseqe_set_addr = SENSOR_INIT_WINSEQADR; /* ddl@rock-chips.com : Sensor output smallest size if isn't support app */
1838 set_w = SENSOR_INIT_WIDTH;
1839 set_h = SENSOR_INIT_HEIGHT;
1840 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1843 if ((int)winseqe_set_addr != sensor->info_priv.winseqe_cur_addr)
1845 printk("sizeof(winseqe_set_addr) %d\n",sizeof(winseqe_set_addr));
1846 for(i = 0; i < sizeof(winseqe_set_addr)/2;i++){
1847 ret |= sensor_write(client, winseqe_set_addr[i].reg, winseqe_set_addr[i].val);
1848 //ret |= sensor_write_array(client, winseqe_set_addr);
1850 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1851 goto sensor_s_fmt_end;
1854 sensor->info_priv.winseqe_cur_addr = (int)winseqe_set_addr;
1857 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1861 SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1871 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1873 struct i2c_client *client = v4l2_get_subdevdata(sd);
1874 struct sensor *sensor = to_sensor(client);
1875 const struct sensor_datafmt *fmt;
1878 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1879 ARRAY_SIZE(sensor_colour_fmts));
1881 fmt = &sensor->info_priv.fmt;
1882 mf->code = fmt->code;
1885 if (mf->height > SENSOR_MAX_HEIGHT)
1886 mf->height = SENSOR_MAX_HEIGHT;
1887 else if (mf->height < SENSOR_MIN_HEIGHT)
1888 mf->height = SENSOR_MIN_HEIGHT;
1890 if (mf->width > SENSOR_MAX_WIDTH)
1891 mf->width = SENSOR_MAX_WIDTH;
1892 else if (mf->width < SENSOR_MIN_WIDTH)
1893 mf->width = SENSOR_MIN_WIDTH;
1895 mf->colorspace = fmt->colorspace;
1899 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1901 struct i2c_client *client = v4l2_get_subdevdata(sd);
1903 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1906 if (id->match.addr != client->addr)
1909 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV9650 identifier */
1914 #if CONFIG_SENSOR_Brightness
1915 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1917 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1919 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1921 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1923 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1925 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1928 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1932 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1936 #if CONFIG_SENSOR_Effect
1937 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1939 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1941 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1943 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1946 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1948 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1952 printk("value %d qctrl->minimum %d ",value, qctrl->minimum);
1953 printk("sizeof(sensor_EffectSeqe) %d\n",sizeof(sensor_EffectSeqe));
1954 printk("sizeof(sensor_EffectSeqe[%d]) %d\n",value - qctrl->minimum,sizeof(sensor_EffectSeqe[value - qctrl->minimum]));
1955 for(i = 0; i < 4; i++) {
1956 printk("sensor_EffectSeqe[%d][%d].reg 0x%x sensor_EffectSeqe[%d][%d].val 0x%x \n",
1957 value - qctrl->minimum, i, sensor_EffectSeqe[value - qctrl->minimum][i].reg,value - qctrl->minimum, i,sensor_EffectSeqe[value - qctrl->minimum][i].val);
1958 sensor_write(client, sensor_EffectSeqe[value - qctrl->minimum][i].reg, sensor_EffectSeqe[value - qctrl->minimum][i].val);
1963 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1967 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1971 #if CONFIG_SENSOR_Exposure
1972 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1974 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1976 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1978 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1980 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1982 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1985 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1989 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1993 #if CONFIG_SENSOR_Saturation
1994 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1996 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1998 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2000 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2002 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2004 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2007 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2011 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2015 #if CONFIG_SENSOR_Contrast
2016 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2018 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2020 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2022 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2024 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2026 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2029 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2033 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2037 #if CONFIG_SENSOR_Mirror
2038 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2040 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2042 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2044 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2046 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2048 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2051 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2055 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2059 #if CONFIG_SENSOR_Flip
2060 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2062 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2064 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2066 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2068 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2070 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2073 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2077 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2081 #if CONFIG_SENSOR_Scene
2082 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2084 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2086 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2088 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2090 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2092 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2095 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2099 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2103 #if CONFIG_SENSOR_WhiteBalance
2104 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2106 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2108 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2110 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2112 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2114 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2117 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2121 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2125 #if CONFIG_SENSOR_DigitalZoom
2126 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2128 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2129 struct sensor *sensor = to_sensor(client);
2130 const struct v4l2_queryctrl *qctrl_info;
2131 int digitalzoom_cur, digitalzoom_total;
2133 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2137 digitalzoom_cur = sensor->info_priv.digitalzoom;
2138 digitalzoom_total = qctrl_info->maximum;
2140 if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2142 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2146 if ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2148 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2152 if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
2154 value = digitalzoom_total - digitalzoom_cur;
2157 if ((value < 0) && ((digitalzoom_cur + value) < 0))
2159 value = 0 - digitalzoom_cur;
2162 digitalzoom_cur += value;
2164 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2166 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2168 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2171 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2178 #if CONFIG_SENSOR_Flash
2179 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2181 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2182 if (value == 3) { /* ddl@rock-chips.com: torch */
2183 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2185 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2187 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2191 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2196 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2198 struct i2c_client *client = v4l2_get_subdevdata(sd);
2199 struct sensor *sensor = to_sensor(client);
2200 const struct v4l2_queryctrl *qctrl;
2202 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2206 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2212 case V4L2_CID_BRIGHTNESS:
2214 ctrl->value = sensor->info_priv.brightness;
2217 case V4L2_CID_SATURATION:
2219 ctrl->value = sensor->info_priv.saturation;
2222 case V4L2_CID_CONTRAST:
2224 ctrl->value = sensor->info_priv.contrast;
2227 case V4L2_CID_DO_WHITE_BALANCE:
2229 ctrl->value = sensor->info_priv.whiteBalance;
2232 case V4L2_CID_EXPOSURE:
2234 ctrl->value = sensor->info_priv.exposure;
2237 case V4L2_CID_HFLIP:
2239 ctrl->value = sensor->info_priv.mirror;
2242 case V4L2_CID_VFLIP:
2244 ctrl->value = sensor->info_priv.flip;
2255 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2257 struct i2c_client *client = v4l2_get_subdevdata(sd);
2258 struct sensor *sensor = to_sensor(client);
2259 struct soc_camera_device *icd = client->dev.platform_data;
2260 const struct v4l2_queryctrl *qctrl;
2263 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2267 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2273 #if CONFIG_SENSOR_Brightness
2274 case V4L2_CID_BRIGHTNESS:
2276 if (ctrl->value != sensor->info_priv.brightness)
2278 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2282 sensor->info_priv.brightness = ctrl->value;
2287 #if CONFIG_SENSOR_Exposure
2288 case V4L2_CID_EXPOSURE:
2290 if (ctrl->value != sensor->info_priv.exposure)
2292 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2296 sensor->info_priv.exposure = ctrl->value;
2301 #if CONFIG_SENSOR_Saturation
2302 case V4L2_CID_SATURATION:
2304 if (ctrl->value != sensor->info_priv.saturation)
2306 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2310 sensor->info_priv.saturation = ctrl->value;
2315 #if CONFIG_SENSOR_Contrast
2316 case V4L2_CID_CONTRAST:
2318 if (ctrl->value != sensor->info_priv.contrast)
2320 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2324 sensor->info_priv.contrast = ctrl->value;
2329 #if CONFIG_SENSOR_WhiteBalance
2330 case V4L2_CID_DO_WHITE_BALANCE:
2332 if (ctrl->value != sensor->info_priv.whiteBalance)
2334 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2338 sensor->info_priv.whiteBalance = ctrl->value;
2343 #if CONFIG_SENSOR_Mirror
2344 case V4L2_CID_HFLIP:
2346 if (ctrl->value != sensor->info_priv.mirror)
2348 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2350 sensor->info_priv.mirror = ctrl->value;
2355 #if CONFIG_SENSOR_Flip
2356 case V4L2_CID_VFLIP:
2358 if (ctrl->value != sensor->info_priv.flip)
2360 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2362 sensor->info_priv.flip = ctrl->value;
2373 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2375 const struct v4l2_queryctrl *qctrl;
2376 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2377 struct sensor *sensor = to_sensor(client);
2379 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2383 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2387 switch (ext_ctrl->id)
2389 case V4L2_CID_SCENE:
2391 ext_ctrl->value = sensor->info_priv.scene;
2394 case V4L2_CID_EFFECT:
2396 ext_ctrl->value = sensor->info_priv.effect;
2399 case V4L2_CID_ZOOM_ABSOLUTE:
2401 ext_ctrl->value = sensor->info_priv.digitalzoom;
2404 case V4L2_CID_ZOOM_RELATIVE:
2408 case V4L2_CID_FOCUS_ABSOLUTE:
2410 ext_ctrl->value = sensor->info_priv.focus;
2413 case V4L2_CID_FOCUS_RELATIVE:
2417 case V4L2_CID_FLASH:
2419 ext_ctrl->value = sensor->info_priv.flash;
2427 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2429 const struct v4l2_queryctrl *qctrl;
2430 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2431 struct sensor *sensor = to_sensor(client);
2434 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2438 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2443 switch (ext_ctrl->id)
2445 #if CONFIG_SENSOR_Scene
2446 case V4L2_CID_SCENE:
2448 if (ext_ctrl->value != sensor->info_priv.scene)
2450 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2452 sensor->info_priv.scene = ext_ctrl->value;
2457 #if CONFIG_SENSOR_Effect
2458 case V4L2_CID_EFFECT:
2460 if (ext_ctrl->value != sensor->info_priv.effect)
2462 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2464 sensor->info_priv.effect= ext_ctrl->value;
2469 #if CONFIG_SENSOR_DigitalZoom
2470 case V4L2_CID_ZOOM_ABSOLUTE:
2472 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2475 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2477 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2479 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2481 sensor->info_priv.digitalzoom += val_offset;
2483 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2488 case V4L2_CID_ZOOM_RELATIVE:
2490 if (ext_ctrl->value)
2492 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2494 sensor->info_priv.digitalzoom += ext_ctrl->value;
2496 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2501 #if CONFIG_SENSOR_Focus
2502 case V4L2_CID_FOCUS_ABSOLUTE:
2504 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2507 if (ext_ctrl->value != sensor->info_priv.focus)
2509 val_offset = ext_ctrl->value -sensor->info_priv.focus;
2511 sensor->info_priv.focus += val_offset;
2516 case V4L2_CID_FOCUS_RELATIVE:
2518 if (ext_ctrl->value)
2520 sensor->info_priv.focus += ext_ctrl->value;
2522 SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2527 #if CONFIG_SENSOR_Flash
2528 case V4L2_CID_FLASH:
2530 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2532 sensor->info_priv.flash = ext_ctrl->value;
2534 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2545 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2547 struct i2c_client *client = v4l2_get_subdevdata(sd);
2548 struct soc_camera_device *icd = client->dev.platform_data;
2549 int i, error_cnt=0, error_idx=-1;
2552 for (i=0; i<ext_ctrl->count; i++) {
2553 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2560 error_idx = ext_ctrl->count;
2562 if (error_idx != -1) {
2563 ext_ctrl->error_idx = error_idx;
2570 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2572 struct i2c_client *client = v4l2_get_subdevdata(sd);
2573 struct soc_camera_device *icd = client->dev.platform_data;
2574 int i, error_cnt=0, error_idx=-1;
2577 for (i=0; i<ext_ctrl->count; i++) {
2578 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2585 error_idx = ext_ctrl->count;
2587 if (error_idx != -1) {
2588 ext_ctrl->error_idx = error_idx;
2595 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2596 * this wasn't our capture interface, so, we wait for the right one */
2597 static int sensor_video_probe(struct soc_camera_device *icd,
2598 struct i2c_client *client)
2602 struct sensor *sensor = to_sensor(client);
2604 /* We must have a parent by now. And it cannot be a wrong one.
2605 * So this entire test is completely redundant. */
2606 if (!icd->dev.parent ||
2607 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2610 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2612 goto sensor_video_probe_err;
2616 // ret = sensor_write(client, 0x12, 0x80);
2619 // SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2622 mdelay(50); //delay 5 microseconds
2624 /* check if it is an sensor sensor */
2625 ret = sensor_read(client, 0x01, &pid);
2627 SENSOR_TR("%s read chip id high byte failed\n",SENSOR_NAME_STRING());
2629 goto sensor_video_probe_err;
2632 SENSOR_DG("\n %s pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2633 if (pid == SENSOR_ID) {
2634 sensor->model = SENSOR_V4L2_IDENT;
2636 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2638 goto sensor_video_probe_err;
2643 sensor_video_probe_err:
2648 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2650 struct i2c_client *client = v4l2_get_subdevdata(sd);
2651 struct soc_camera_device *icd = client->dev.platform_data;
2652 struct sensor *sensor = to_sensor(client);
2654 #if CONFIG_SENSOR_Flash
2658 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2661 case RK_CAM_SUBDEV_DEACTIVATE:
2663 sensor_deactivate(client);
2667 case RK_CAM_SUBDEV_IOREQUEST:
2669 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
2670 if (sensor->sensor_io_request != NULL) {
2671 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2672 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2673 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2674 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2675 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2676 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2679 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2681 goto sensor_ioctl_end;
2683 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2685 #if CONFIG_SENSOR_Flash
2686 if (sensor->sensor_gpio_res) {
2687 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2688 for (i = 0; i < icd->ops->num_controls; i++) {
2689 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2690 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2693 sensor->info_priv.flash = 0xff;
2694 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2702 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2710 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2711 enum v4l2_mbus_pixelcode *code)
2713 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2716 *code = sensor_colour_fmts[index].code;
2719 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2720 .init = sensor_init,
2721 .g_ctrl = sensor_g_control,
2722 .s_ctrl = sensor_s_control,
2723 .g_ext_ctrls = sensor_g_ext_controls,
2724 .s_ext_ctrls = sensor_s_ext_controls,
2725 .g_chip_ident = sensor_g_chip_ident,
2726 .ioctl = sensor_ioctl,
2729 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2730 .s_mbus_fmt = sensor_s_fmt,
2731 .g_mbus_fmt = sensor_g_fmt,
2732 .try_mbus_fmt = sensor_try_fmt,
2733 .enum_mbus_fmt = sensor_enum_fmt,
2736 static struct v4l2_subdev_ops sensor_subdev_ops = {
2737 .core = &sensor_subdev_core_ops,
2738 .video = &sensor_subdev_video_ops,
2741 static int sensor_probe(struct i2c_client *client,
2742 const struct i2c_device_id *did)
2744 struct sensor *sensor;
2745 struct soc_camera_device *icd = client->dev.platform_data;
2746 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2747 struct soc_camera_link *icl;
2750 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2752 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2756 icl = to_soc_camera_link(icd);
2758 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2762 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2763 dev_warn(&adapter->dev,
2764 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2768 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2772 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2774 /* Second stage probe - when a capture adapter is there */
2775 icd->ops = &sensor_ops;
2776 sensor->info_priv.fmt = sensor_colour_fmts[0];
2777 #if CONFIG_SENSOR_I2C_NOSCHED
2778 atomic_set(&sensor->tasklock_cnt,0);
2781 ret = sensor_video_probe(icd, client);
2784 i2c_set_clientdata(client, NULL);
2788 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2792 static int sensor_remove(struct i2c_client *client)
2794 struct sensor *sensor = to_sensor(client);
2795 struct soc_camera_device *icd = client->dev.platform_data;
2798 i2c_set_clientdata(client, NULL);
2799 client->driver = NULL;
2805 static const struct i2c_device_id sensor_id[] = {
2806 {SENSOR_NAME_STRING(), 0 },
2809 MODULE_DEVICE_TABLE(i2c, sensor_id);
2811 static struct i2c_driver sensor_i2c_driver = {
2813 .name = SENSOR_NAME_STRING(),
2815 .probe = sensor_probe,
2816 .remove = sensor_remove,
2817 .id_table = sensor_id,
2820 static int __init sensor_mod_init(void)
2822 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2823 return i2c_add_driver(&sensor_i2c_driver);
2826 static void __exit sensor_mod_exit(void)
2828 i2c_del_driver(&sensor_i2c_driver);
2831 device_initcall_sync(sensor_mod_init);
2832 module_exit(sensor_mod_exit);
2834 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2835 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2836 MODULE_LICENSE("GPL");