camera driver v0.2.1 for RK30
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / sid130B.c
1 /*\r
2 o* Driver for MT9M001 CMOS Image Sensor from Micron\r
3  *\r
4  * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>\r
5  *\r
6  * This program is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License version 2 as\r
8  * published by the Free Software Foundation.\r
9  */\r
10 \r
11 #include <linux/videodev2.h>\r
12 #include <linux/slab.h>\r
13 #include <linux/i2c.h>\r
14 #include <linux/log2.h>\r
15 #include <linux/platform_device.h>\r
16 #include <linux/delay.h>\r
17 #include <linux/circ_buf.h>\r
18 #include <linux/miscdevice.h>\r
19 #include <media/v4l2-common.h>\r
20 #include <media/v4l2-chip-ident.h>\r
21 #include <media/soc_camera.h>\r
22 #include <mach/rk_camera.h>\r
23 #include <linux/vmalloc.h>\r
24 static int debug;\r
25 module_param(debug, int, S_IRUGO|S_IWUSR);\r
26 \r
27 #define dprintk(level, fmt, arg...) do {                        \\r
28         if (debug >= level)                                     \\r
29         printk(KERN_WARNING fmt , ## arg); } while (0)\r
30 \r
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)\r
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)\r
33 \r
34 \r
35 #define _CONS(a,b) a##b\r
36 #define CONS(a,b) _CONS(a,b)\r
37 \r
38 #define __STR(x) #x\r
39 #define _STR(x) __STR(x)\r
40 #define STR(x) _STR(x)\r
41 \r
42 #define MIN(x,y)   ((x<y) ? x: y)\r
43 #define MAX(x,y)    ((x>y) ? x: y)\r
44 \r
45 /* Sensor Driver Configuration */\r
46 #define SENSOR_NAME sid130B\r
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_SID130B\r
48 #define SENSOR_ID 0x1B\r
49 #define SENSOR_MIN_WIDTH    176\r
50 #define SENSOR_MIN_HEIGHT   144\r
51 #define SENSOR_MAX_WIDTH    1600\r
52 #define SENSOR_MAX_HEIGHT   1200\r
53 #define SENSOR_INIT_WIDTH       sensor_init_width                       /* Sensor pixel size for sensor_init_data array */\r
54 #define SENSOR_INIT_HEIGHT  sensor_init_height\r
55 #define SENSOR_INIT_WINSEQADR  sensor_init_winseq_p\r
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode\r
57 #define SENSOR_BUS_PARAM  sensor_init_busparam\r
58 \r
59 #define CONFIG_SENSOR_WhiteBalance 1\r
60 #define CONFIG_SENSOR_Brightness        0\r
61 #define CONFIG_SENSOR_Contrast      0\r
62 #define CONFIG_SENSOR_Saturation    0\r
63 #define CONFIG_SENSOR_Effect        1\r
64 #define CONFIG_SENSOR_Scene         0\r
65 #define CONFIG_SENSOR_DigitalZoom   0\r
66 #define CONFIG_SENSOR_Focus         0\r
67 #define CONFIG_SENSOR_Exposure      0\r
68 #define CONFIG_SENSOR_Flash         0\r
69 #define CONFIG_SENSOR_Mirror        0\r
70 #define CONFIG_SENSOR_Flip          0\r
71 \r
72 #define CONFIG_SENSOR_I2C_SPEED     80000       /* Hz */\r
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */\r
74 #define CONFIG_SENSOR_I2C_NOSCHED   0\r
75 #define CONFIG_SENSOR_I2C_RDWRCHK   0\r
76 \r
77 #define COLOR_TEMPERATURE_CLOUDY_DN  6500\r
78 #define COLOR_TEMPERATURE_CLOUDY_UP    8000\r
79 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000\r
80 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500\r
81 #define COLOR_TEMPERATURE_OFFICE_DN     3500\r
82 #define COLOR_TEMPERATURE_OFFICE_UP     5000\r
83 #define COLOR_TEMPERATURE_HOME_DN       2500\r
84 #define COLOR_TEMPERATURE_HOME_UP       3500\r
85 \r
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))\r
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)\r
88 \r
89 #define SENSOR_AF_IS_ERR    (0x00<<0)\r
90 #define SENSOR_AF_IS_OK         (0x01<<0)\r
91 #define SENSOR_INIT_IS_ERR   (0x00<<28)\r
92 #define SENSOR_INIT_IS_OK    (0x01<<28)\r
93 \r
94 struct reginfo\r
95 {\r
96     u8 reg;\r
97     u8 val;\r
98 };\r
99 \r
100 static s32 sensor_init_width = 0;\r
101 static s32 sensor_init_height = 0;\r
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);\r
103 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;\r
104 static struct reginfo* sensor_init_data_p = NULL;\r
105 static struct reginfo* sensor_init_winseq_p = NULL;\r
106 static struct reginfo* sensor_init_winseq_board = NULL;\r
107 /* init 800*600 SVGA */\r
108 static struct reginfo sensor_init_data[] =\r
109 {\r
110        {0x00,  0x00},  \r
111         {0x04,  0x00},  //Group A 0x10\r
112         {0x05,  0x0F},  //UXGA Output\r
113         {0x06,  0x86}, \r
114         {0x07,  0x08}, \r
115 \r
116 \r
117         {0x08,  0xa2},  //PLL off\r
118         {0x09,  0x12},  \r
119         {0x0A,  0x12},  \r
120         {0x10,  0x17},  \r
121         {0x11,  0x01}, \r
122         {0x12,  0x8A}, \r
123         {0x13,  0x1a}, \r
124         {0x14,  0x27}, \r
125         {0x15,  0x22}, \r
126 \r
127         {0x17,  0xCb},  \r
128         {0x18,  0x38},  \r
129         \r
130         {0x40,  0x0f}, \r
131         {0x41,  0x17}, \r
132         {0x42,  0x52}, \r
133         {0x43,  0x80}, \r
134         {0x44,  0x00}, \r
135         {0x45,  0x00}, \r
136 \r
137 //Flicker - 50Hz  - Still mode ,     \r
138         {0x00,  0x00}, \r
139         {0x20,  0x00}, \r
140         {0x21,  0x02}, \r
141         {0x23,  0x29},//15}, \r
142         {0x00,  0x01}, \r
143         {0x35,  0x50},//3c}, \r
144 \r
145 //Flicker - 50Hz - Preview mode 24MHz MCLK\r
146         {0x00,  0x00}, \r
147         {0x24,  0x00}, \r
148         {0x25,  0xe6},//10}, \r
149         {0x27,  0x0d},//4b}, \r
150         {0x00,  0x01}, \r
151         {0x34,  0x80},//64}, \r
152 \r
153 \r
154 //AE Block \r
155         {0x00,  0x01}, \r
156         {0x10,  0x00}, \r
157         {0x11,  0x0a}, //.0c\r
158         {0x12,  0x78}, \r
159         {0x13,  0x78}, \r
160         {0x14,  0x78}, \r
161         {0x17,  0xC4}, \r
162         {0x1c,  0x05},    \r
163 \r
164         {0x36,  0x28},  //26\r
165 \r
166         {0x40,  0x40},  //Max Again  //anyuan\r
167         //{0x41,  0x20}, \r
168         //{0x42,  0x20}, \r
169         //{0x43,  0x00}, \r
170         //{0x44,  0x00}, \r
171         //{0x45,  0x01}, \r
172         //{0x46,  0x1c}, \r
173         //{0x47,  0x11}, \r
174         //{0x48,  0x15}, \r
175         //{0x49,  0x17}, \r
176         //{0x4A,  0x1a}, \r
177         //{0x4B,  0x1c}, \r
178         //{0x4C,  0x1e}, \r
179         //{0x4D,  0x1e}, \r
180         //{0x4E,  0x0f}, \r
181         //{0x4F,  0x09}, \r
182         //{0x50,  0x07}, \r
183         //{0x51,  0x05}, \r
184         //{0x52,  0x04}, \r
185         //{0x53,  0x03}, \r
186         //{0x54,  0x02}, \r
187         //{0x55,  0x01}, \r
188         //{0x66,  0x00}, \r
189         //{0x67,  0x00}, \r
190         //{0x68,  0x00}, \r
191         //{0x69,  0x00}, \r
192         //{0x6a,  0x00}, \r
193         //{0x6b,  0x00},\r
194 \r
195         {0x70,  0xc4}, \r
196         {0x73,  0x22}, \r
197         {0x74,  0x07}, \r
198         {0x77,  0xd0}, \r
199         {0x78,  0xd8}, \r
200         {0x79,  0x70}, \r
201   //\r
202         {0x90,  0x00}, \r
203         {0x92,  0x0c}, //0bank 0x11 °ú µ¿ÀÏ \r
204         {0x95,  0x40},  //0 bank 0x40 °ú µ¿ÀÏ  \r
205         //AWB Block\r
206 \r
207         {0x00,  0x02}, \r
208         {0x10,  0xD3}, \r
209         {0x11,  0x11}, \r
210         {0x13,  0x7e}, \r
211         {0x14,  0x7c}, \r
212         {0x15,  0xee}, \r
213         {0x16,  0x80}, \r
214         {0x17,  0xd0}, \r
215         {0x18,  0x80}, \r
216         {0x19,  0x98}, \r
217         {0x1A,  0x68}, \r
218         {0x1B,  0x98}, \r
219         {0x1C,  0x68}, \r
220         {0x1D,  0x90}, \r
221         {0x1E,  0x74}, \r
222         {0x20,  0xF0}, \r
223         {0x21,  0x85}, \r
224         {0x22,  0xB4}, \r
225         {0x23,  0x20}, \r
226         {0x25,  0x20}, \r
227         {0x26,  0x05}, \r
228         {0x27,  0x78}, \r
229         {0x28,  0xd8}, \r
230         {0x29,  0xb8}, \r
231         {0x2A,  0x88}, \r
232         {0x30,  0x00}, \r
233         {0x31,  0x10}, \r
234         {0x32,  0x00}, \r
235         {0x33,  0x10}, \r
236         {0x34,  0x06}, \r
237         {0x35,  0x30}, \r
238         {0x36,  0x04}, \r
239         {0x37,  0xA0}, \r
240         {0x40,  0x01}, \r
241         {0x41,  0x04}, \r
242         {0x42,  0x08}, \r
243         {0x43,  0x10}, \r
244         {0x44,  0x13}, \r
245         {0x45,  0x6B}, \r
246         {0x46,  0x82},  \r
247 \r
248 \r
249 \r
250 //CMA change  -D65~A\r
251         {0x53,  0xa1},  //AWB R Gain for D30 to D20\r
252         {0x54,  0xc0},  //AWB B Gain for D30 to D20\r
253         {0x55,  0xa1},  //AWB R Gain for D20 to D30\r
254         {0x56,  0xc0},  //AWB B Gain for D20 to D30\r
255         {0x57,  0xc8},  //AWB R Gain for D65 to D30\r
256         {0x58,  0xa0},  //AWB B Gain for D65 to D30\r
257         {0x59,  0xc8},  //AWB R Gain for D30 to D65\r
258         {0x5A,  0xa0},  //AWB B Gain for D30 to D65\r
259 \r
260   {0x64,  0x00},\r
261   {0x65,  0x00},\r
262   {0x66,  0x00},\r
263   {0x67,  0x00},\r
264   {0x68,  0xa5},\r
265   {0x69,  0xb4},\r
266   {0x6a,  0xb3},\r
267   {0x6b,  0xac},\r
268   {0x6c,  0xb7},\r
269   {0x6d,  0x98},\r
270   {0x6e,  0xba},\r
271   {0x6f,  0x90},\r
272   \r
273   {0x70,  0xbf},\r
274   {0x71,  0x9b},\r
275   {0x72,  0xce},\r
276   {0x73,  0x8c},\r
277   {0x74,  0x7f},\r
278   {0x75,  0x8c},\r
279   {0x76,  0xad},\r
280   {0x77,  0xba},\r
281   {0x78,  0x8f},\r
282   {0x79,  0x9a},\r
283   {0x7A,  0xa3},\r
284   {0x7B,  0xac},\r
285   {0x7C,  0xa0},\r
286   {0x7D,  0xa9},\r
287   {0x7E,  0x95},\r
288   {0x7F,  0xac},\r
289   {0x80,  0xad},\r
290   {0x81,  0xbc},\r
291   {0x82,  0x98},\r
292   {0x83,  0xa4},\r
293   {0x84,  0x00},\r
294   {0x85,  0x00},\r
295   {0x86,  0x00},\r
296   {0x87,  0x00},\r
297   {0x88,  0xc9},\r
298   {0x89,  0xd5},\r
299   {0x8a,  0x70},\r
300   {0x8b,  0x7b},\r
301   {0x8c,  0xd0},\r
302   {0x8d,  0xe5},\r
303   {0x8e,  0x58},\r
304   {0x8f,  0x70},\r
305     \r
306         {0xB4,  0x05},  \r
307         {0xB5,  0x0F},  \r
308         {0xB6,  0x06},  \r
309         {0xB7,  0x06},  \r
310         {0xB8,  0x40},  \r
311         {0xB9,  0x10},  \r
312         {0xBA,  0x06},  \r
313 \r
314 //IDP\r
315         {0x00,  0x03}, \r
316         {0x10,  0xFF}, \r
317         {0x11,  0x1D}, \r
318         {0x12,  0x1D}, \r
319         {0x13,  0xFF}, \r
320         {0x14,  0x00}, \r
321         {0x15,  0xc0}, \r
322 \r
323 //DPC\r
324         {0x30,  0x88},  //DPCNRCTRL\r
325         {0x31,  0x14},  //DPTHR @ AGAIN = 00\r
326         {0x32,  0x10},  //DPTHR @ AGAIN = 20\r
327         {0x33,  0x0c},  //DPTHR @ AGAIN = 40\r
328         {0x34,  0x08},  //DPTHR @ AGAIN = 60\r
329         {0x35,  0x04},  //DPTHR @ AGAIN = 80\r
330         {0x36,  0x44},  //DPTHVRNG\r
331         {0x37,  0x66},  //DPNUMBER\r
332         {0x38,  0x00},  //0x00  // NRTHR0 @ AGAIN = 00\r
333         {0x39,  0x04},  //0x0C  // NRTHR1 @ AGAIN = 20\r
334         {0x3A,  0x04},  //0x18  // NRTHR2 @ AGAIN = 40\r
335         {0x3B,  0x2c},  //0x30  // NRTHR3 @ AGAIN = 60\r
336         {0x3C,  0x3c},  //                 NRTHR4 @ AGAIN = 80\r
337         {0x3D,  0x04},  //NRTHVRNG0 @ AGAIN = 00\r
338         {0x3E,  0x04},  //NRTHVRNG1 @ AGAIN = 20\r
339         {0x3F,  0x04},  //NRTHVRNG2 @ AGAIN = 40\r
340         {0x40,  0x2c},  //NRTHVRNG3 @ AGAIN = 60\r
341         {0x41,  0x3c},  //NRTHVRNG4 @ AGAIN = 80\r
342         {0x42,  0xff},  //NRTHVRNGMAX\r
343         {0x43,  0x40},  //NRTHRWGT\r
344         {0x44,  0x40},  //BASELVL\r
345         {0x45,  0x06},  //SHUMAXH\r
346         {0x46,  0x40},  //SHUMAXL\r
347         {0x47,  0x30},  //ILLUMITHDRK\r
348 \r
349 // shading\r
350         {0x50,  0x0a},  //0x00      \r
351         {0x51,  0x20},  //0x45  \r
352         {0x52,  0x12},  //0x24      \r
353         {0x53,  0x12},  //0x24 \r
354                                       \r
355         {0x54,  0x22},  //0x00      \r
356         {0x55,  0x18},  //0x40  \r
357         {0x56,  0x08},  //0x10      \r
358         {0x57,  0x10},  //0x20 \r
359                                         \r
360         {0x58,  0x22},  //0x00      \r
361         {0x59,  0x18},  //0x40  \r
362         {0x5A,  0x08},  //0x10      \r
363         {0x5B,  0x10},  //0x20 \r
364                                        \r
365         {0x5C,  0x25},  //0x04      \r
366         {0x5D,  0x1a},  //0x55  \r
367         {0x5E,  0x12},  //0x25    \r
368         {0x5F,  0x10},  //0x20 \r
369              \r
370         {0x60,  0x32},  //0x32                   \r
371         {0x61,  0x20},  //20//\r
372         {0x62,  0x58},  //67\r
373 //      {0x63,  0x89 //8c R Center start gain\r
374 //      {0x66,  0x79 //B Center start gain   73               \r
375         {0x6B,  0x00}, //01 //01                 \r
376         {0x6C,  0x01}, //22                   \r
377         {0x6D,  0x23}, //22                   \r
378         {0x6E,  0x55}, //55                   \r
379         {0x6F,  0x55}, //77                   \r
380         {0x70,  0x55}, //65                   \r
381         {0x71,  0x00}, //01 //AB (6)               \r
382         {0x72,  0x01}, //23     (5)             \r
383         {0x73,  0x23}, //33     (4)            \r
384         {0x74,  0x44}, //45     (3)             \r
385         {0x75,  0x45}, //55     (2)               \r
386         {0x76,  0x66}, //55     (1)             \r
387         {0x77,  0x00}, //01 //AB (6)                 \r
388         {0x78,  0x01}, //23     (5)              \r
389         {0x79,  0x23}, //33     (4)              \r
390         {0x7A,  0x44}, //45     (3)              \r
391         {0x7B,  0x45}, //55     (2)                \r
392         {0x7C,  0x66}, //55     (1)              \r
393         {0x7D,  0x00}, //00    //00                   \r
394         {0x7E,  0x00}, //00    //00                   \r
395         {0x7F,  0x12}, //11    //12                   \r
396         {0x80,  0x33}, //33    //33 //44               \r
397         {0x81,  0x44}, //33    //33 //44                  \r
398         {0x82,  0x55}, //22    //44 //45 \r
399         //{0x83,  0x14}, \r
400         //{0x84,  0x0f}, \r
401 \r
402         {0x94,0x02},\r
403         {0x95,0x80},\r
404         {0x96,0x01},\r
405         {0x97,0xe0}, \r
406 \r
407 //Interpolation\r
408         {0xA0,  0x3F},\r
409         {0xA1,  0x05},\r
410         {0xA2,  0xB7},\r
411         {0xA3,  0xB7},\r
412         {0xA4,  0x04},\r
413         {0xA5,  0xFF},\r
414         {0xA6,  0x04},\r
415         {0xA7,  0xFF},\r
416         {0xA8,  0x00},\r
417         {0xA9,  0x00},\r
418         {0xAA,  0x00},\r
419         {0xAB,  0x00},\r
420         {0xAC,  0x60},\r
421         {0xAD,  0x18},\r
422         {0xAE,  0x10},\r
423         {0xAF,  0x20},\r
424         {0xB0,  0x08},\r
425         {0xB1,  0x00},\r
426 \r
427 //Color Matrix for D65\r
428 #if 0\r
429         {0xC0,  0x2F}, // CMASB D20 or D30 or Dark Condition Color Matrix Selection\r
430         {0xC1,  0x66}, \r
431         {0xC2,  0xd4}, \r
432         {0xC3,  0x05}, \r
433         {0xC4,  0xf0}, \r
434         {0xC5,  0x5a}, \r
435         {0xC6,  0xf5}, \r
436         {0xC7,  0xf9}, \r
437         {0xC8,  0xbf}, \r
438         {0xC9,  0x88}, \r
439         {0xCA,  0xa0}, \r
440         {0xCB,  0x50}, \r
441         {0xCC,  0xe2}, \r
442         {0xCD,  0x00}, \r
443         {0xCE,  0x00}, \r
444 #else\r
445 {0xC0,  0x2F}, // CMASB D20 or D30 or Dark Condition Color Matrix Selection\r
446 {0xC1,  0x71}, \r
447 {0xC2,  0xcc}, \r
448 {0xC3,  0x01}, \r
449 {0xC4,  0xe8}, \r
450 {0xC5,  0x68}, \r
451 {0xC6,  0xef}, \r
452 {0xC7,  0xfa}, \r
453 {0xC8,  0xc6}, \r
454 {0xC9,  0x7e}, \r
455 {0xCA,  0xec}, \r
456 {0xCB,  0x67}, \r
457 {0xCC,  0x34}, \r
458 {0xCD,  0x3a}, \r
459 {0xCE,  0x08},\r
460 \r
461 #endif\r
462 //Color Matrix for CWF\r
463         {0xD0,  0x2F}, \r
464         {0xD1,  0x66}, \r
465         {0xD2,  0xd4}, \r
466         {0xD3,  0x05}, \r
467         {0xD4,  0xf0}, \r
468         {0xD5,  0x5a}, \r
469         {0xD6,  0xf5}, \r
470         {0xD7,  0xe9}, \r
471         {0xD8,  0xbf}, \r
472         {0xD9,  0x88},\r
473         {0xDA,  0xa0}, \r
474         {0xDB,  0x50}, \r
475         {0xDC,  0xe2}, \r
476         {0xDD,  0x00}, \r
477         {0xDE,  0x00}, \r
478 \r
479 //Color Matrix for A\r
480         {0xE0,  0x2F}, \r
481         {0xE1,  0x6e}, \r
482         {0xE2,  0xc7}, \r
483         {0xE3,  0x0d}, \r
484         {0xE4,  0xe3}, \r
485         {0xE5,  0x61}, \r
486         {0xE6,  0xfa}, \r
487         {0xE7,  0xe5}, \r
488         {0xE8,  0xcb}, \r
489         {0xE9,  0x8e}, \r
490         {0xEA,  0xc4}, \r
491         {0xEB,  0x04}, \r
492         {0xEC,  0xf3}, \r
493         {0xED,  0xdd}, \r
494         {0xEE,  0x06}, \r
495 \r
496 //IDP 4\r
497         {0x00,  0x04}, \r
498 \r
499 //Gamma - r   \r
500         {0x10,  0x00}, \r
501         {0x11,  0x04}, \r
502         {0x12,  0x10},\r
503         {0x13,  0x20},\r
504         {0x14,  0x40},\r
505         {0x15,  0x5c},\r
506         {0x16,  0x74},\r
507         {0x17,  0x84},\r
508         {0x18,  0x98},\r
509         {0x19,  0xa4},\r
510         {0x1A,  0xb0},\r
511         {0x1B,  0xc8},\r
512         {0x1C,  0xdc},\r
513         {0x1D,  0xf0},\r
514         {0x1E,  0xf8},\r
515         {0x1F,  0xFF},\r
516                         \r
517 //Gamma - G             \r
518         {0x20,  0x00}, \r
519         {0x21,  0x04}, \r
520         {0x22,  0x10},\r
521         {0x23,  0x20},\r
522         {0x24,  0x40},\r
523         {0x25,  0x5c},\r
524         {0x26,  0x74},\r
525         {0x27,  0x84},\r
526         {0x28,  0x98},\r
527         {0x29,  0xa4},\r
528         {0x2A,  0xb0},\r
529         {0x2B,  0xc8},\r
530         {0x2C,  0xdc},\r
531         {0x2D,  0xf0},\r
532         {0x2E,  0xf8},\r
533         {0x2F,  0xFF},\r
534                         \r
535 //Gamma - B             \r
536         {0x30,  0x00}, \r
537         {0x31,  0x04}, \r
538         {0x32,  0x10},\r
539         {0x33,  0x20},\r
540         {0x34,  0x40},\r
541         {0x35,  0x5c},\r
542         {0x36,  0x74},\r
543         {0x37,  0x84},\r
544         {0x38,  0x98},\r
545         {0x39,  0xa4},\r
546         {0x3A,  0xb0},\r
547         {0x3B,  0xc8},\r
548         {0x3C,  0xdc},\r
549         {0x3D,  0xf0},\r
550         {0x3E,  0xf8},\r
551         {0x3F,  0xFF},\r
552 \r
553 //DARK GAMMA\r
554         {0x40,  0x00}, \r
555         {0x41,  0x0b}, \r
556         {0x42,  0x15},\r
557         {0x43,  0x29},\r
558         {0x44,  0x47},\r
559         {0x45,  0x5D},\r
560         {0x46,  0x72},\r
561         {0x47,  0x83},\r
562         {0x48,  0x92},\r
563         {0x49,  0xA0},\r
564         {0x4A,  0xac},\r
565         {0x4B,  0xc6},\r
566         {0x4C,  0xdA},\r
567         {0x4D,  0xeC},\r
568         {0x4E,  0xf6},\r
569         {0x4F,  0xFF},\r
570   \r
571         {0x50,  0x00}, //DARK GAMMA on/off\r
572         \r
573 //CSC                   \r
574         {0x60,  0x33}, \r
575         {0x61,  0x20}, \r
576         {0x62,  0xE4}, \r
577         {0x63,  0xFA}, \r
578         {0x64,  0x13}, \r
579         {0x65,  0x25}, \r
580         {0x66,  0x07}, \r
581         {0x67,  0xF5}, \r
582         {0x68,  0xEA}, \r
583         {0x69,  0x20}, \r
584         {0x6A,  0xC8}, \r
585         {0x6B,  0xC4}, \r
586         {0x6C,  0x84}, \r
587         {0x6D,  0x04}, \r
588         {0x6E,  0x0C}, \r
589         {0x6F,  0x00}, \r
590                         \r
591 //Edge                  \r
592 // {0x70,  0x00},\r
593 // {0x71,  0x18},\r
594 // {0x72,  0x18},\r
595 // {0x73,  0x04},\r
596 // {0x74,  0x08},\r
597 // {0x76,  0x20},\r
598 // {0x77,  0x04},\r
599 // {0x78,  0x08},\r
600 // {0x7a,  0x20},\r
601 // {0x7d,  0x08},\r
602 // {0X7e,  0x30},\r
603 \r
604         {0x80,  0x22}, \r
605         {0x81,  0x14}, \r
606         {0x82,  0x14}, \r
607         {0x83,  0x04}, \r
608         {0x84,  0x06}, \r
609         {0x85,  0x06}, \r
610         {0x87,  0x04},\r
611         {0x88,  0x10},\r
612         {0x89,  0x06},\r
613         {0X90,  0x06},\r
614         {0x91,  0x03},\r
615         {0x93,  0xe0},\r
616 \r
617 //Cr/Cb Coring\r
618         {0x94,  0x00}, \r
619         {0x95,  0x00}, \r
620         {0x96,  0x4C}, \r
621         {0x97,  0x76}, \r
622         {0x9A,  0xf5}, \r
623 \r
624         {0xA1,  0x08},   //@ 0\r
625         {0xA2,  0x10},   //@ 20\r
626         {0xA3,  0x16},   //@ 40\r
627         {0xA4,  0x20},   //@ 60\r
628         {0xA5,  0x30},   //@ 80\r
629         {0xA6,  0xa0}, \r
630         {0xA7,  0x06}, \r
631         {0xA8,  0x40}, \r
632 \r
633         {0xA9,  0x38}, \r
634         {0xAa,  0x35}, \r
635 \r
636         {0xAc,  0xff}, \r
637         {0xAd,  0x09}, \r
638         {0xAe,  0x96}, \r
639         {0xAf,  0x18}, \r
640 \r
641         {0xB2,  0x38},   //color suppression start\r
642         {0xB3,  0x53}, \r
643         {0xB6,  0x00}, \r
644         \r
645 //Color Saturation\r
646         {0xBC, 0x10}, \r
647         {0xBD, 0x10}, \r
648         {0xBE, 0x10}, \r
649         {0xBF, 0x10}, \r
650         {0xc0, 0x10}, \r
651         {0xc1, 0x10},   \r
652         {0xc2, 0x10}, \r
653         {0xc3, 0x10}, \r
654         {0xc4, 0x10}, \r
655         {0xc5, 0x10}, \r
656 \r
657         {0xcc, 0x04}, \r
658         {0xcd, 0x40}, \r
659         {0xce, 0x00}, \r
660                       \r
661 //IDP 3                 \r
662         {0x00,  0x05}, \r
663                         \r
664 //Memory                \r
665         {0x40,  0x15}, \r
666         {0x41,  0x28}, \r
667         {0x42,  0x04}, \r
668         {0x43,  0x15}, \r
669         {0x44,  0x28}, \r
670         {0x45,  0x04}, \r
671         {0x46,  0x15}, \r
672         {0x47,  0x28}, \r
673         {0x48,  0x04}, \r
674                         \r
675 //Knee                  \r
676         {0x90,  0xca},  //\r
677         {0x91,  0x81},  //knee function selection/knee point H\r
678         {0x92,  0x00},  //knee point L\r
679         {0x93,  0x50},  //Knee gain\r
680         {0x94,  0x41},  //[6:4]knee start H/[2:0]Knee END H\r
681         {0x95,  0x7e},  //knee start L\r
682         {0x96,  0x48},  //knee END L\r
683                         \r
684 //ADG                   \r
685         {0x99,  0xC0}, \r
686         {0xA0,  0x10}, \r
687         {0xA1,  0x22}, \r
688         {0xA2,  0x36}, \r
689         {0xA3,  0x49}, \r
690         {0xA4,  0x5D}, \r
691         {0xA5,  0x70}, \r
692         {0xA6,  0x82}, \r
693         {0xA7,  0x94}, \r
694         {0xA8,  0xA5}, \r
695         {0xA9,  0xB5}, \r
696         {0xAA,  0xC3}, \r
697         {0xAB,  0xD1}, \r
698         {0xAC,  0xDE}, \r
699         {0xAD,  0xEA}, \r
700         {0xAE,  0xF5}, \r
701         {0xAF,  0xFF}, \r
702                         \r
703 //YXGMA                 \r
704         {0xB0,  0xc0},  //YGMACTRL\r
705         {0xB1,  0x04},  //YGMASLOP\r
706         {0xB8,  0x0f},  //DRKTHR1\r
707         {0xB9,  0x10},  //DRKTHR2\r
708         //{0xBA,  0x38},  //DRKTHR3\r
709         //{0xBB,  0x39},  //DRKTHR4\r
710         {0xC0,  0x03}, \r
711         {0xC1,  0x0E}, \r
712         {0xC2,  0x16}, \r
713         {0xC3,  0x24}, \r
714         {0xC4,  0x3F}, \r
715         {0xC5,  0x56}, \r
716         {0xC6,  0x6A}, \r
717         {0xC7,  0x7C}, \r
718         {0xC8,  0x8C}, \r
719         {0xC9,  0x98}, \r
720         {0xCA,  0xA2}, \r
721         {0xCB,  0xB8}, \r
722         {0xCC,  0xCD}, \r
723         {0xCD,  0xE2}, \r
724         {0xCE,  0xF0}, \r
725         {0xCF,  0xFF}, \r
726 \r
727 \r
728 // edge value adjustment\r
729         {0xe0,  0x81}, \r
730         {0xe1,  0x83}, \r
731         {0xe2,  0x07}, \r
732         {0xe3,  0x0c}, \r
733         {0xe4,  0x14}, \r
734         {0xe5,  0x1c}, \r
735 \r
736 \r
737 //Sensor on\r
738         {0x00,  0x00}, \r
739         {0x03,  0xc5}, \r
740         {0x00,  0x01}, \r
741         {0x10,  0x84}, \r
742         {0x00,  0x02}, \r
743         {0x10,  0xd3}, \r
744         {0xff,  0xff}, \r
745 \r
746 \r
747 };\r
748 \r
749 /* 1600X1200 UXGA */\r
750 static struct reginfo sensor_uxga[] =\r
751 {\r
752    {0x00,0x00},\r
753    {0x04,0x10},\r
754    {0x05,0x8f},\r
755    {0x00,0x03},\r
756    {0x94,0x06},\r
757    {0x95,0x40},\r
758    {0x96,0x04},\r
759    {0x97,0xb0}, \r
760    {0xff, 0xff},\r
761 };\r
762 \r
763 /* 1280X1024 SXGA */\r
764 static struct reginfo sensor_sxga[] =\r
765 {\r
766        {0x00,0x00},\r
767        {0x04,0x10},\r
768        {0x05,0x8b},\r
769         {0x00,0x03},\r
770         {0x94,0x05},\r
771         {0x95,0x00},\r
772         {0x96,0x04},\r
773         {0x97,0x00}, \r
774         {0xff, 0xff}, \r
775 };\r
776 static struct reginfo sensor_xga[] =\r
777 {\r
778         {0xff, 0xff}\r
779 };\r
780 /* 800X600 SVGA*/\r
781 static struct reginfo sensor_svga[] =\r
782 {\r
783     {0x00,0x03},\r
784     {0x94,0x03},\r
785     {0x95,0x20},\r
786     {0x96,0x02},\r
787     {0x97,0x58}, \r
788     {0xff, 0xff}\r
789 };\r
790 \r
791 /* 640X480 VGA */\r
792 static struct reginfo sensor_vga[] =\r
793 {\r
794       {0x00,0x00},\r
795       {0x04,0x00},\r
796       {0x05,0x0f},\r
797       {0x00,0x03},\r
798       {0x94,0x02}, //0x02\r
799       {0x95,0x80}, //0x80\r
800       {0x96,0x01},//0x01\r
801       {0x97,0xe0}, //0xe0\r
802       {0xff, 0xff}, \r
803 };\r
804 \r
805 /* 352X288 CIF */\r
806 static struct reginfo sensor_cif[] =\r
807 {\r
808     {0x00,0x03},\r
809     {0x94,0x01},\r
810     {0x95,0x60},\r
811     {0x96,0x01},\r
812     {0x97,0x20}, \r
813     {0xff, 0xff}, \r
814 };\r
815 \r
816 /* 320*240 QVGA */\r
817 static  struct reginfo sensor_qvga[] =\r
818 {\r
819        {0x00,0x03},\r
820        {0x94,0x01},\r
821        {0x95,0x40},\r
822        {0x96,0x00},\r
823        {0x97,0xf0}, \r
824        {0xff, 0xff}, \r
825 };\r
826 \r
827 /* 176X144 QCIF*/\r
828 static struct reginfo sensor_qcif[] =\r
829 {\r
830        {0x00,0x03},\r
831        {0x94,0x00},\r
832        {0x95,0xB0},\r
833        {0x96,0x00},\r
834        {0x97,0x90}, \r
835        {0xff, 0xff},\r
836 };\r
837 \r
838 static  struct reginfo sensor_ClrFmt_YUYV[]=\r
839 {\r
840     {0xff, 0xff}\r
841 };\r
842 \r
843 static  struct reginfo sensor_ClrFmt_UYVY[]=\r
844 {\r
845     {0xff, 0xff}\r
846 };\r
847 \r
848 #if CONFIG_SENSOR_WhiteBalance\r
849 static  struct reginfo sensor_WhiteB_Auto[]={\r
850     {0x00, 0x02},\r
851     {0x10, 0xd3},\r
852     {0xff, 0xff}\r
853 };\r
854 /* Cloudy Colour Temperature : 6500K - 8000K  */\r
855 static  struct reginfo sensor_WhiteB_Cloudy[]=\r
856 {\r
857     {0x00, 0x02},\r
858     {0x10, 0x00},\r
859     {0x50, 0xd0},\r
860     {0x51, 0x88},\r
861     {0xff, 0xff}\r
862 };\r
863 /* ClearDay Colour Temperature : 5000K - 6500K  */\r
864 static  struct reginfo sensor_WhiteB_ClearDay[]=\r
865 {\r
866     {0x00, 0x02},\r
867     {0x10, 0x00},\r
868     {0x50, 0xaa},\r
869     {0x51, 0x90},\r
870     {0xff, 0xff}\r
871 \r
872 };\r
873 /* Office Colour Temperature : 3500K - 5000K  */\r
874 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=\r
875 {\r
876     {0x00, 0x02},\r
877     {0x10, 0x00},\r
878     {0x50, 0xc2},\r
879     {0x51, 0x9e},\r
880     {0xff, 0xff}\r
881 };\r
882 /* Home Colour Temperature : 2500K - 3500K  */\r
883 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=\r
884 {\r
885     {0x00, 0x02},\r
886     {0x10, 0x00},\r
887     {0x50, 0xaa},\r
888     {0x51, 0xbe},\r
889     {0xff, 0xff}\r
890 };\r
891 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,\r
892     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,\r
893 };\r
894 #endif\r
895 \r
896 #if CONFIG_SENSOR_Brightness\r
897 static  struct reginfo sensor_Brightness0[]=\r
898 {\r
899     // Brightness -2\r
900     {0x00, 0x04},\r
901     {0xb6, 0xa0},\r
902     {0xff, 0xff}\r
903 \r
904 };\r
905 \r
906 static  struct reginfo sensor_Brightness1[]=\r
907 {\r
908     // Brightness -1\r
909     {0x00, 0x04},\r
910     {0xb6, 0x90},\r
911     {0xff, 0xff}\r
912 \r
913 };\r
914 \r
915 static  struct reginfo sensor_Brightness2[]=\r
916 {\r
917     //  Brightness 0\r
918     {0x00, 0x04},\r
919     {0xb6, 0x00},\r
920     {0xff, 0xff}\r
921 \r
922 };\r
923 \r
924 static  struct reginfo sensor_Brightness3[]=\r
925 {\r
926     // Brightness +1\r
927    {0x00, 0x04},\r
928    {0xb6, 0x10},\r
929    {0xff, 0xff}\r
930 \r
931 };\r
932 \r
933 static  struct reginfo sensor_Brightness4[]=\r
934 {\r
935     //  Brightness +2\r
936    {0x00, 0x04},\r
937    {0xb6, 0x20},\r
938    {0xff, 0xff}\r
939 \r
940 };\r
941 \r
942 static  struct reginfo sensor_Brightness5[]=\r
943 {\r
944    {0x00, 0x04},\r
945    {0xb6, 0x30},\r
946    {0xff, 0xff}\r
947 };\r
948 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,\r
949     sensor_Brightness4, sensor_Brightness5,NULL,\r
950 };\r
951 \r
952 #endif\r
953 \r
954 #if CONFIG_SENSOR_Effect\r
955 static  struct reginfo sensor_Effect_Normal[] =\r
956 {\r
957     {0x00, 0x04},\r
958     {0xd9, 0x00},\r
959     {0xff, 0xff}\r
960 };\r
961 \r
962 static  struct reginfo sensor_Effect_WandB[] =\r
963 {\r
964     {0x00, 0x04},\r
965     {0xd9, 0x40},\r
966     {0x00, 0x00},\r
967     {0xff, 0xff}\r
968 };\r
969 \r
970 static  struct reginfo sensor_Effect_Sepia[] =\r
971 {\r
972     {0x00, 0x04},\r
973     {0xd9, 0x80},\r
974     {0xda, 0x60},\r
975     {0xdb, 0xa0},\r
976     {0xff, 0xff}\r
977 };\r
978 \r
979 static  struct reginfo sensor_Effect_Negative[] =\r
980 {\r
981    {0x00, 0x04},\r
982    {0xd9, 0x20},\r
983    {0xff, 0xff}\r
984 };\r
985 static  struct reginfo sensor_Effect_Bluish[] =\r
986 {\r
987     // Bluish\r
988     {0x00, 0x04},\r
989     {0xd9, 0x80},\r
990     {0xda, 0xc0},\r
991     {0xdb, 0x60},\r
992     {0xff, 0xff}\r
993 };\r
994 \r
995 static  struct reginfo sensor_Effect_Green[] =\r
996 {\r
997     //  Greenish\r
998     {0x00, 0x04},\r
999     {0xd9, 0x80},\r
1000     {0xda, 0x50},\r
1001     {0xdb, 0x50},\r
1002     {0xff, 0xff}\r
1003 };\r
1004 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,\r
1005     sensor_Effect_Bluish, sensor_Effect_Green,NULL,\r
1006 };\r
1007 #endif\r
1008 #if CONFIG_SENSOR_Exposure\r
1009 static  struct reginfo sensor_Exposure0[]=\r
1010 {\r
1011     //-3\r
1012    {0xff, 0xff}\r
1013 };\r
1014 \r
1015 static  struct reginfo sensor_Exposure1[]=\r
1016 {\r
1017     //-2\r
1018     {0xff, 0xff}\r
1019 };\r
1020 \r
1021 static  struct reginfo sensor_Exposure2[]=\r
1022 {\r
1023     //-0.3EV\r
1024    {0xff, 0xff}\r
1025 };\r
1026 \r
1027 static  struct reginfo sensor_Exposure3[]=\r
1028 {\r
1029     //default\r
1030   {0xff, 0xff}\r
1031 };\r
1032 \r
1033 static  struct reginfo sensor_Exposure4[]=\r
1034 {\r
1035     // 1\r
1036   {0xff, 0xff}\r
1037 };\r
1038 \r
1039 static  struct reginfo sensor_Exposure5[]=\r
1040 {\r
1041     // 2\r
1042   {0xff, 0xff}\r
1043 };\r
1044 \r
1045 static  struct reginfo sensor_Exposure6[]=\r
1046 {\r
1047     // 3\r
1048    {0xff, 0xff}\r
1049 };\r
1050 \r
1051 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,\r
1052     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,\r
1053 };\r
1054 #endif\r
1055 #if CONFIG_SENSOR_Saturation\r
1056 static  struct reginfo sensor_Saturation0[]=\r
1057 {\r
1058     {0xff, 0xff}\r
1059 };\r
1060 \r
1061 static  struct reginfo sensor_Saturation1[]=\r
1062 {\r
1063    {0xff, 0xff}\r
1064 };\r
1065 \r
1066 static  struct reginfo sensor_Saturation2[]=\r
1067 {\r
1068   {0xff, 0xff}\r
1069 };\r
1070 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};\r
1071 \r
1072 #endif\r
1073 #if CONFIG_SENSOR_Contrast\r
1074 static  struct reginfo sensor_Contrast0[]=\r
1075 {\r
1076     {0xff, 0xff}\r
1077 };\r
1078 \r
1079 static  struct reginfo sensor_Contrast1[]=\r
1080 {\r
1081    {0xff, 0xff}\r
1082 };\r
1083 \r
1084 static  struct reginfo sensor_Contrast2[]=\r
1085 {\r
1086     {0xff, 0xff}\r
1087 };\r
1088 \r
1089 static  struct reginfo sensor_Contrast3[]=\r
1090 {\r
1091     {0xff, 0xff}\r
1092 };\r
1093 \r
1094 static  struct reginfo sensor_Contrast4[]=\r
1095 {\r
1096    {0xff, 0xff}\r
1097 };\r
1098 \r
1099 \r
1100 static  struct reginfo sensor_Contrast5[]=\r
1101 {\r
1102     {0xff, 0xff}\r
1103 };\r
1104 \r
1105 static  struct reginfo sensor_Contrast6[]=\r
1106 {\r
1107     {0xff, 0xff}\r
1108 };\r
1109 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,\r
1110     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,\r
1111 };\r
1112 \r
1113 #endif\r
1114 #if CONFIG_SENSOR_Mirror\r
1115 static  struct reginfo sensor_MirrorOn[]=\r
1116 {\r
1117     {0xff, 0xff}\r
1118 };\r
1119 \r
1120 static  struct reginfo sensor_MirrorOff[]=\r
1121 {\r
1122      {0xff, 0xff}\r
1123 };\r
1124 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};\r
1125 #endif\r
1126 #if CONFIG_SENSOR_Flip\r
1127 static  struct reginfo sensor_FlipOn[]=\r
1128 {\r
1129     {0xff, 0xff}\r
1130 };\r
1131 \r
1132 static  struct reginfo sensor_FlipOff[]=\r
1133 {\r
1134      {0xff, 0xff}\r
1135 };\r
1136 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};\r
1137 \r
1138 #endif\r
1139 #if CONFIG_SENSOR_Scene\r
1140 static  struct reginfo sensor_SceneAuto[] =\r
1141 {\r
1142    {0x00, 0x01},\r
1143    {0x11, 0x0a},\r
1144    {0x00, 0x04},\r
1145    {0xb6, 0x00},\r
1146    {0xff, 0xff}\r
1147 };\r
1148 \r
1149 static  struct reginfo sensor_SceneNight[] =\r
1150 {\r
1151    {0x00, 0x01},\r
1152    {0x11, 0x14},\r
1153    {0x00, 0x04},\r
1154    {0xb6, 0x10},\r
1155    {0xff, 0xff}\r
1156 };\r
1157 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};\r
1158 \r
1159 #endif\r
1160 #if CONFIG_SENSOR_DigitalZoom\r
1161 static struct reginfo sensor_Zoom0[] =\r
1162 {\r
1163     {0xff, 0xff}\r
1164 };\r
1165 \r
1166 static struct reginfo sensor_Zoom1[] =\r
1167 {\r
1168      {0xff, 0xff}\r
1169 };\r
1170 \r
1171 static struct reginfo sensor_Zoom2[] =\r
1172 {\r
1173     {0xff, 0xff}\r
1174 };\r
1175 \r
1176 \r
1177 static struct reginfo sensor_Zoom3[] =\r
1178 {\r
1179     {0xff, 0xff}\r
1180 };\r
1181 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};\r
1182 #endif\r
1183 static const struct v4l2_querymenu sensor_menus[] =\r
1184 {\r
1185         #if CONFIG_SENSOR_WhiteBalance\r
1186     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},\r
1187     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},\r
1188     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},\r
1189     #endif\r
1190 \r
1191         #if CONFIG_SENSOR_Effect\r
1192     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},\r
1193     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},\r
1194     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},\r
1195     #endif\r
1196 \r
1197         #if CONFIG_SENSOR_Scene\r
1198     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},\r
1199     #endif\r
1200 \r
1201         #if CONFIG_SENSOR_Flash\r
1202     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},\r
1203     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},\r
1204     #endif\r
1205 };\r
1206 \r
1207 static const struct v4l2_queryctrl sensor_controls[] =\r
1208 {\r
1209         #if CONFIG_SENSOR_WhiteBalance\r
1210     {\r
1211         .id             = V4L2_CID_DO_WHITE_BALANCE,\r
1212         .type           = V4L2_CTRL_TYPE_MENU,\r
1213         .name           = "White Balance Control",\r
1214         .minimum        = 0,\r
1215         .maximum        = 4,\r
1216         .step           = 1,\r
1217         .default_value = 0,\r
1218     },\r
1219     #endif\r
1220 \r
1221         #if CONFIG_SENSOR_Brightness\r
1222         {\r
1223         .id             = V4L2_CID_BRIGHTNESS,\r
1224         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1225         .name           = "Brightness Control",\r
1226         .minimum        = -3,\r
1227         .maximum        = 2,\r
1228         .step           = 1,\r
1229         .default_value = 0,\r
1230     },\r
1231     #endif\r
1232 \r
1233         #if CONFIG_SENSOR_Effect\r
1234         {\r
1235         .id             = V4L2_CID_EFFECT,\r
1236         .type           = V4L2_CTRL_TYPE_MENU,\r
1237         .name           = "Effect Control",\r
1238         .minimum        = 0,\r
1239         .maximum        = 5,\r
1240         .step           = 1,\r
1241         .default_value = 0,\r
1242     },\r
1243         #endif\r
1244 \r
1245         #if CONFIG_SENSOR_Exposure\r
1246         {\r
1247         .id             = V4L2_CID_EXPOSURE,\r
1248         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1249         .name           = "Exposure Control",\r
1250         .minimum        = 0,\r
1251         .maximum        = 6,\r
1252         .step           = 1,\r
1253         .default_value = 0,\r
1254     },\r
1255         #endif\r
1256 \r
1257         #if CONFIG_SENSOR_Saturation\r
1258         {\r
1259         .id             = V4L2_CID_SATURATION,\r
1260         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1261         .name           = "Saturation Control",\r
1262         .minimum        = 0,\r
1263         .maximum        = 2,\r
1264         .step           = 1,\r
1265         .default_value = 0,\r
1266     },\r
1267     #endif\r
1268 \r
1269         #if CONFIG_SENSOR_Contrast\r
1270         {\r
1271         .id             = V4L2_CID_CONTRAST,\r
1272         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1273         .name           = "Contrast Control",\r
1274         .minimum        = -3,\r
1275         .maximum        = 3,\r
1276         .step           = 1,\r
1277         .default_value = 0,\r
1278     },\r
1279         #endif\r
1280 \r
1281         #if CONFIG_SENSOR_Mirror\r
1282         {\r
1283         .id             = V4L2_CID_HFLIP,\r
1284         .type           = V4L2_CTRL_TYPE_BOOLEAN,\r
1285         .name           = "Mirror Control",\r
1286         .minimum        = 0,\r
1287         .maximum        = 1,\r
1288         .step           = 1,\r
1289         .default_value = 1,\r
1290     },\r
1291     #endif\r
1292 \r
1293         #if CONFIG_SENSOR_Flip\r
1294         {\r
1295         .id             = V4L2_CID_VFLIP,\r
1296         .type           = V4L2_CTRL_TYPE_BOOLEAN,\r
1297         .name           = "Flip Control",\r
1298         .minimum        = 0,\r
1299         .maximum        = 1,\r
1300         .step           = 1,\r
1301         .default_value = 1,\r
1302     },\r
1303     #endif\r
1304 \r
1305         #if CONFIG_SENSOR_Scene\r
1306     {\r
1307         .id             = V4L2_CID_SCENE,\r
1308         .type           = V4L2_CTRL_TYPE_MENU,\r
1309         .name           = "Scene Control",\r
1310         .minimum        = 0,\r
1311         .maximum        = 1,\r
1312         .step           = 1,\r
1313         .default_value = 0,\r
1314     },\r
1315     #endif\r
1316 \r
1317         #if CONFIG_SENSOR_DigitalZoom\r
1318     {\r
1319         .id             = V4L2_CID_ZOOM_RELATIVE,\r
1320         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1321         .name           = "DigitalZoom Control",\r
1322         .minimum        = -1,\r
1323         .maximum        = 1,\r
1324         .step           = 1,\r
1325         .default_value = 0,\r
1326     }, {\r
1327         .id             = V4L2_CID_ZOOM_ABSOLUTE,\r
1328         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1329         .name           = "DigitalZoom Control",\r
1330         .minimum        = 0,\r
1331         .maximum        = 3,\r
1332         .step           = 1,\r
1333         .default_value = 0,\r
1334     },\r
1335     #endif\r
1336 \r
1337         #if CONFIG_SENSOR_Focus\r
1338         {\r
1339         .id             = V4L2_CID_FOCUS_RELATIVE,\r
1340         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1341         .name           = "Focus Control",\r
1342         .minimum        = -1,\r
1343         .maximum        = 1,\r
1344         .step           = 1,\r
1345         .default_value = 0,\r
1346     }, {\r
1347         .id             = V4L2_CID_FOCUS_ABSOLUTE,\r
1348         .type           = V4L2_CTRL_TYPE_INTEGER,\r
1349         .name           = "Focus Control",\r
1350         .minimum        = 0,\r
1351         .maximum        = 255,\r
1352         .step           = 1,\r
1353         .default_value = 125,\r
1354     },\r
1355     #endif\r
1356 \r
1357         #if CONFIG_SENSOR_Flash\r
1358         {\r
1359         .id             = V4L2_CID_FLASH,\r
1360         .type           = V4L2_CTRL_TYPE_MENU,\r
1361         .name           = "Flash Control",\r
1362         .minimum        = 0,\r
1363         .maximum        = 3,\r
1364         .step           = 1,\r
1365         .default_value = 0,\r
1366     },\r
1367         #endif\r
1368 };\r
1369 \r
1370 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);\r
1371 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);\r
1372 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);\r
1373 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);\r
1374 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);\r
1375 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);\r
1376 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);\r
1377 static int sensor_resume(struct soc_camera_device *icd);\r
1378 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);\r
1379 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);\r
1380 #if CONFIG_SENSOR_Effect\r
1381 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);\r
1382 #endif\r
1383 #if CONFIG_SENSOR_WhiteBalance\r
1384 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);\r
1385 #endif\r
1386 static int sensor_deactivate(struct i2c_client *client);\r
1387 \r
1388 static struct soc_camera_ops sensor_ops =\r
1389 {\r
1390     .suspend                     = sensor_suspend,\r
1391     .resume                       = sensor_resume,\r
1392     .set_bus_param              = sensor_set_bus_param,\r
1393     .query_bus_param    = sensor_query_bus_param,\r
1394     .controls           = sensor_controls,\r
1395     .menus                         = sensor_menus,\r
1396     .num_controls               = ARRAY_SIZE(sensor_controls),\r
1397     .num_menus          = ARRAY_SIZE(sensor_menus),\r
1398 };\r
1399 \r
1400 /* only one fixed colorspace per pixelcode */\r
1401 struct sensor_datafmt {\r
1402         enum v4l2_mbus_pixelcode code;\r
1403         enum v4l2_colorspace colorspace;\r
1404 };\r
1405 \r
1406 /* Find a data format by a pixel code in an array */\r
1407 static const struct sensor_datafmt *sensor_find_datafmt(\r
1408         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,\r
1409         int n)\r
1410 {\r
1411         int i;\r
1412         for (i = 0; i < n; i++)\r
1413                 if (fmt[i].code == code)\r
1414                         return fmt + i;\r
1415 \r
1416         return NULL;\r
1417 }\r
1418 \r
1419 static const struct sensor_datafmt sensor_colour_fmts[] = {\r
1420     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},\r
1421     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     \r
1422 };\r
1423 \r
1424 typedef struct sensor_info_priv_s\r
1425 {\r
1426     int whiteBalance;\r
1427     int brightness;\r
1428     int contrast;\r
1429     int saturation;\r
1430     int effect;\r
1431     int scene;\r
1432     int digitalzoom;\r
1433     int focus;\r
1434     int flash;\r
1435     int exposure;\r
1436         bool snap2preview;\r
1437         bool video2preview;\r
1438     unsigned char mirror;                                        /* HFLIP */\r
1439     unsigned char flip;                                          /* VFLIP */\r
1440     unsigned int winseqe_cur_addr;\r
1441         struct sensor_datafmt fmt;\r
1442     unsigned int funmodule_state;\r
1443 } sensor_info_priv_t;\r
1444 \r
1445 struct sensor\r
1446 {\r
1447     struct v4l2_subdev subdev;\r
1448     struct i2c_client *client;\r
1449     sensor_info_priv_t info_priv;\r
1450     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */\r
1451 #if CONFIG_SENSOR_I2C_NOSCHED\r
1452         atomic_t tasklock_cnt;\r
1453 #endif\r
1454         struct rkcamera_platform_data *sensor_io_request;\r
1455     struct rkcamera_gpio_res *sensor_gpio_res;\r
1456 };\r
1457 \r
1458 static struct sensor* to_sensor(const struct i2c_client *client)\r
1459 {\r
1460     return container_of(i2c_get_clientdata(client), struct sensor, subdev);\r
1461 }\r
1462 \r
1463 static int sensor_task_lock(struct i2c_client *client, int lock)\r
1464 {\r
1465 #if CONFIG_SENSOR_I2C_NOSCHED\r
1466         int cnt = 3;\r
1467     struct sensor *sensor = to_sensor(client);\r
1468 \r
1469         if (lock) {\r
1470                 if (atomic_read(&sensor->tasklock_cnt) == 0) {\r
1471                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {\r
1472                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());\r
1473                                 msleep(35);\r
1474                                 cnt--;\r
1475                         }\r
1476                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {\r
1477                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());\r
1478                                 goto sensor_task_lock_err;\r
1479                         }\r
1480                         preempt_disable();\r
1481                 }\r
1482 \r
1483                 atomic_add(1, &sensor->tasklock_cnt);\r
1484         } else {\r
1485                 if (atomic_read(&sensor->tasklock_cnt) > 0) {\r
1486                         atomic_sub(1, &sensor->tasklock_cnt);\r
1487 \r
1488                         if (atomic_read(&sensor->tasklock_cnt) == 0)\r
1489                                 preempt_enable();\r
1490                 }\r
1491         }\r
1492         return 0;\r
1493 sensor_task_lock_err:\r
1494         return -1;  \r
1495 #else\r
1496     return 0;\r
1497 #endif\r
1498 \r
1499 }\r
1500 \r
1501 /* sensor register write */\r
1502 static int sensor_write(struct i2c_client *client, u8 reg, u8 val)\r
1503 {\r
1504     int err,cnt;\r
1505     u8 buf[2];\r
1506     struct i2c_msg msg[1];\r
1507 \r
1508     //buf[0] = reg >> 8;\r
1509     buf[0] = reg & 0xFF;\r
1510     buf[1] = val;\r
1511 \r
1512     msg->addr = client->addr;\r
1513     msg->flags = client->flags;\r
1514     msg->buf = buf;\r
1515     msg->len = sizeof(buf);\r
1516     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */\r
1517     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */\r
1518 \r
1519     cnt = 3;\r
1520     err = -EAGAIN;\r
1521 \r
1522     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */\r
1523         err = i2c_transfer(client->adapter, msg, 1);\r
1524 \r
1525         if (err >= 0) {\r
1526             return 0;\r
1527         } else {\r
1528             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);\r
1529             udelay(10);\r
1530         }\r
1531     }\r
1532 \r
1533     return err;\r
1534 }\r
1535 \r
1536 /* sensor register read */\r
1537 static int sensor_read(struct i2c_client *client, u8 reg, u8 *val)\r
1538 {\r
1539     int err,cnt;\r
1540     u8 buf[1];\r
1541     struct i2c_msg msg[2];\r
1542 \r
1543    // buf[0] = reg >> 8;\r
1544     buf[0] = reg & 0xFF;\r
1545 \r
1546     msg[0].addr = client->addr;\r
1547     msg[0].flags = client->flags;\r
1548     msg[0].buf = buf;\r
1549     msg[0].len = sizeof(buf);\r
1550     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */\r
1551     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */\r
1552 \r
1553     msg[1].addr = client->addr;\r
1554     msg[1].flags = client->flags|I2C_M_RD;\r
1555     msg[1].buf = buf;\r
1556     msg[1].len = 1;\r
1557     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */\r
1558     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */\r
1559 \r
1560     cnt = 3;\r
1561     err = -EAGAIN;\r
1562     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */\r
1563         err = i2c_transfer(client->adapter, msg, 2);\r
1564 \r
1565         if (err >= 0) {\r
1566             *val = buf[0];\r
1567             return 0;\r
1568         } else {\r
1569                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);\r
1570             udelay(10);\r
1571         }\r
1572     }\r
1573 \r
1574     return err;\r
1575 }\r
1576 \r
1577 /* write a array of registers  */\r
1578 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)\r
1579 {\r
1580     int err = 0, cnt;\r
1581     int i = 0;\r
1582 #if CONFIG_SENSOR_I2C_RDWRCHK    \r
1583         char valchk;\r
1584 #endif\r
1585 \r
1586         cnt = 0;\r
1587         if (sensor_task_lock(client, 1) < 0)\r
1588                 goto sensor_write_array_end;\r
1589     while (regarray[i].reg != 0xff)\r
1590     {\r
1591         err = sensor_write(client, regarray[i].reg, regarray[i].val);\r
1592         if (err < 0)\r
1593         {\r
1594             if (cnt-- > 0) {\r
1595                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);\r
1596                                 i = 0;\r
1597                                 continue;\r
1598             } else {\r
1599                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());\r
1600                 err = -EPERM;\r
1601                                 goto sensor_write_array_end;\r
1602             }\r
1603         } else {\r
1604         #if CONFIG_SENSOR_I2C_RDWRCHK\r
1605                         sensor_read(client, regarray[i].reg, &valchk);\r
1606                         if (valchk != regarray[i].val)\r
1607                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);\r
1608                 #endif\r
1609         }\r
1610         i++;\r
1611     }\r
1612 \r
1613 sensor_write_array_end:\r
1614         sensor_task_lock(client,0);\r
1615         return err;\r
1616 }\r
1617 #if CONFIG_SENSOR_I2C_RDWRCHK\r
1618 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)\r
1619 {\r
1620     int cnt;\r
1621     int i = 0;\r
1622         char valchk;\r
1623 \r
1624         cnt = 0;\r
1625         valchk = 0;\r
1626     while (regarray[i].reg != 0xff)\r
1627     {\r
1628                 sensor_read(client, regarray[i].reg, &valchk);\r
1629                 if (valchk != regarray[i].val)\r
1630                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);\r
1631 \r
1632         i++;\r
1633     }\r
1634     return 0;\r
1635 }\r
1636 #endif\r
1637 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)\r
1638 {\r
1639         struct soc_camera_link *icl = to_soc_camera_link(icd);\r
1640         int ret = 0;\r
1641 \r
1642     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);\r
1643         switch (cmd)\r
1644         {\r
1645                 case Sensor_PowerDown:\r
1646                 {\r
1647                         if (icl->powerdown) {\r
1648                                 ret = icl->powerdown(icd->pdev, on);\r
1649                                 if (ret == RK_CAM_IO_SUCCESS) {\r
1650                                         if (on == 0) {\r
1651                                                 mdelay(2);\r
1652                                                 if (icl->reset)\r
1653                                                         icl->reset(icd->pdev);\r
1654                                         }\r
1655                                 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {\r
1656                                         ret = -ENODEV;\r
1657                                         goto sensor_power_end;\r
1658                                 }\r
1659                         }\r
1660                         break;\r
1661                 }\r
1662                 case Sensor_Flash:\r
1663                 {\r
1664                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
1665                 struct sensor *sensor = to_sensor(client);\r
1666 \r
1667                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {\r
1668                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);\r
1669                         }\r
1670             break;\r
1671                 }\r
1672                 default:\r
1673                 {\r
1674                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);\r
1675                         break;\r
1676                 }\r
1677         }\r
1678 sensor_power_end:\r
1679         return ret;\r
1680 }\r
1681 static int sensor_init(struct v4l2_subdev *sd, u32 val)\r
1682 {\r
1683     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
1684     struct soc_camera_device *icd = client->dev.platform_data;\r
1685     struct sensor *sensor = to_sensor(client);\r
1686         const struct v4l2_queryctrl *qctrl;\r
1687     const struct sensor_datafmt *fmt;\r
1688     char value;\r
1689     int ret,pid = 0,i = 0,j=0;\r
1690     struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;\r
1691     sensor_init_data_p = sensor_init_data;\r
1692         sensor_init_winseq_p = sensor_vga;\r
1693         sensor_init_width = 640;\r
1694         sensor_init_height = 480;\r
1695         if (tmp_plat_data != NULL) { \r
1696                 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){\r
1697                         if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&\r
1698                                 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))\r
1699                                         break;\r
1700                         }\r
1701                 }\r
1702         if(tmp_plat_data  && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){\r
1703         //user has defined the init data\r
1704                 //init reg\r
1705                 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){\r
1706                         for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){\r
1707                                 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;\r
1708                                 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;\r
1709                                 }\r
1710                         sensor_init_data_p = sensor_init_data;\r
1711                         }\r
1712                 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){\r
1713                         sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);\r
1714                         }\r
1715                 //init winseq\r
1716                 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){\r
1717                         int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;\r
1718                         if(sensor_init_winseq_board)\r
1719                                 {\r
1720                                 vfree(sensor_init_winseq_board);\r
1721                                 sensor_init_winseq_board = NULL;\r
1722                                 }\r
1723                         sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);\r
1724                         if(!sensor_init_winseq_board)\r
1725                                 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);\r
1726                         for(j = 0;j< tmp_winseq_size;j++){\r
1727                                 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;\r
1728                                 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;\r
1729                                 }\r
1730                         sensor_init_winseq_p = sensor_init_winseq_board;\r
1731                         }\r
1732                 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){\r
1733                         sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);\r
1734                         }\r
1735                 //init width,height,bus,pixelcode\r
1736                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)\r
1737                         sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;\r
1738                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)\r
1739                         sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;\r
1740                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)\r
1741                         sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;\r
1742                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)\r
1743                         sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;\r
1744         }\r
1745     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);\r
1746 \r
1747      if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {\r
1748           ret = -ENODEV;\r
1749           goto sensor_INIT_ERR;\r
1750      }\r
1751      msleep(100);\r
1752 #if 0\r
1753     /* soft reset */\r
1754         if (sensor_task_lock(client,1)<0)\r
1755                 goto sensor_INIT_ERR;\r
1756     ret = sensor_write(client, 0x3012, 0x80);\r
1757     if (ret != 0)\r
1758     {\r
1759         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());\r
1760         ret = -ENODEV;\r
1761                 goto sensor_INIT_ERR;\r
1762     }\r
1763 \r
1764     mdelay(5);  //delay 5 microseconds\r
1765         /* check if it is an sensor sensor */\r
1766     ret = sensor_read(client, 0x300a, &value);\r
1767     if (ret != 0) {\r
1768         SENSOR_TR("read chip id high byte failed\n");\r
1769         ret = -ENODEV;\r
1770         goto sensor_INIT_ERR;\r
1771     }\r
1772 \r
1773     pid |= (value << 8);\r
1774 \r
1775     ret = sensor_read(client, 0x300b, &value);\r
1776     if (ret != 0) {\r
1777         SENSOR_TR("read chip id low byte failed\n");\r
1778         ret = -ENODEV;\r
1779         goto sensor_INIT_ERR;\r
1780     }\r
1781 \r
1782     pid |= (value & 0xff);\r
1783     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
1784     if (pid == SENSOR_ID) {\r
1785         sensor->model = SENSOR_V4L2_IDENT;\r
1786     } else {\r
1787         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
1788         ret = -ENODEV;\r
1789         goto sensor_INIT_ERR;\r
1790     }\r
1791 #endif\r
1792 #if 0\r
1793    sensor_read(client,0x01,&value);\r
1794     pid = (value & 0xff);\r
1795     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
1796     if (pid == SENSOR_ID) {\r
1797         sensor->model = SENSOR_V4L2_IDENT;\r
1798     } else {\r
1799         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
1800         ret = -ENODEV;\r
1801         goto sensor_INIT_ERR;\r
1802     }\r
1803 #endif\r
1804     ret = sensor_write_array(client, sensor_init_data_p);\r
1805     if (ret != 0)\r
1806     {\r
1807         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());\r
1808         goto sensor_INIT_ERR;\r
1809     }\r
1810     sensor_task_lock(client,0);\r
1811     sensor->info_priv.winseqe_cur_addr  = (int)SENSOR_INIT_WINSEQADR;\r
1812     fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));\r
1813     if (!fmt) {\r
1814         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());\r
1815         ret = -EINVAL;\r
1816         goto sensor_INIT_ERR;\r
1817     }\r
1818         sensor->info_priv.fmt = *fmt;\r
1819 \r
1820     /* sensor sensor information for initialization  */\r
1821         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
1822         if (qctrl)\r
1823         sensor->info_priv.whiteBalance = qctrl->default_value;\r
1824         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);\r
1825         if (qctrl)\r
1826         sensor->info_priv.brightness = qctrl->default_value;\r
1827         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
1828         if (qctrl)\r
1829         sensor->info_priv.effect = qctrl->default_value;\r
1830         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);\r
1831         if (qctrl)\r
1832         sensor->info_priv.exposure = qctrl->default_value;\r
1833 \r
1834         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);\r
1835         if (qctrl)\r
1836         sensor->info_priv.saturation = qctrl->default_value;\r
1837         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);\r
1838         if (qctrl)\r
1839         sensor->info_priv.contrast = qctrl->default_value;\r
1840         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);\r
1841         if (qctrl)\r
1842         sensor->info_priv.mirror = qctrl->default_value;\r
1843         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);\r
1844         if (qctrl)\r
1845         sensor->info_priv.flip = qctrl->default_value;\r
1846         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);\r
1847         if (qctrl)\r
1848         sensor->info_priv.scene = qctrl->default_value;\r
1849         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);\r
1850         if (qctrl)\r
1851         sensor->info_priv.digitalzoom = qctrl->default_value;\r
1852 \r
1853     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */\r
1854         #if CONFIG_SENSOR_Focus\r
1855     sensor_set_focus();\r
1856     qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);\r
1857         if (qctrl)\r
1858         sensor->info_priv.focus = qctrl->default_value;\r
1859         #endif\r
1860 \r
1861         #if CONFIG_SENSOR_Flash\r
1862         sensor_set_flash();\r
1863         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);\r
1864         if (qctrl)\r
1865         sensor->info_priv.flash = qctrl->default_value;\r
1866     #endif\r
1867 \r
1868     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);\r
1869     sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;\r
1870     return 0;\r
1871 sensor_INIT_ERR:\r
1872     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;\r
1873         sensor_task_lock(client,0);\r
1874         sensor_deactivate(client);\r
1875     return ret;\r
1876 }\r
1877 \r
1878 static int sensor_deactivate(struct i2c_client *client)\r
1879 {\r
1880         struct soc_camera_device *icd = client->dev.platform_data;\r
1881     struct sensor *sensor = to_sensor(client);\r
1882     \r
1883         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);\r
1884 \r
1885         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */\r
1886         \r
1887         sensor_ioctrl(icd, Sensor_PowerDown, 1);\r
1888 \r
1889         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */\r
1890         icd->user_width = SENSOR_INIT_WIDTH;\r
1891     icd->user_height = SENSOR_INIT_HEIGHT;\r
1892         msleep(100);\r
1893 \r
1894     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;\r
1895         return 0;\r
1896 }\r
1897 \r
1898 static  struct reginfo sensor_power_down_sequence[]=\r
1899 {\r
1900     {0xff,0xff}\r
1901 };\r
1902 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)\r
1903 {\r
1904     int ret;\r
1905     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
1906 \r
1907     if (pm_msg.event == PM_EVENT_SUSPEND) {\r
1908         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());\r
1909         ret = sensor_write_array(client, sensor_power_down_sequence) ;\r
1910         if (ret != 0) {\r
1911             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);\r
1912             return ret;\r
1913         } else {\r
1914             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);\r
1915             if (ret < 0) {\r
1916                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());\r
1917                 return -EINVAL;\r
1918             }\r
1919         }\r
1920     } else {\r
1921         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());\r
1922         return -EINVAL;\r
1923     }\r
1924     return 0;\r
1925 }\r
1926 \r
1927 static int sensor_resume(struct soc_camera_device *icd)\r
1928 {\r
1929         int ret;\r
1930 \r
1931     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);\r
1932     if (ret < 0) {\r
1933                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());\r
1934         return -EINVAL;\r
1935     }\r
1936 \r
1937         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());\r
1938 \r
1939     return 0;\r
1940 \r
1941 }\r
1942 \r
1943 static int sensor_set_bus_param(struct soc_camera_device *icd,\r
1944                                 unsigned long flags)\r
1945 {\r
1946 \r
1947     return 0;\r
1948 }\r
1949 \r
1950 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)\r
1951 {\r
1952     struct soc_camera_link *icl = to_soc_camera_link(icd);\r
1953     unsigned long flags = SENSOR_BUS_PARAM;\r
1954 \r
1955     return soc_camera_apply_sensor_flags(icl, flags);\r
1956 }\r
1957 \r
1958 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1959 {\r
1960     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
1961     struct soc_camera_device *icd = client->dev.platform_data;\r
1962     struct sensor *sensor = to_sensor(client);\r
1963 \r
1964     mf->width   = icd->user_width;\r
1965         mf->height      = icd->user_height;\r
1966         mf->code        = sensor->info_priv.fmt.code;\r
1967         mf->colorspace  = sensor->info_priv.fmt.colorspace;\r
1968         mf->field       = V4L2_FIELD_NONE;\r
1969 \r
1970     return 0;\r
1971 }\r
1972 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1973 {\r
1974     bool ret = false;\r
1975 \r
1976         if ((mf->width == 1024) && (mf->height == 768)) {\r
1977                 ret = true;\r
1978         } else if ((mf->width == 1280) && (mf->height == 1024)) {\r
1979                 ret = true;\r
1980         } else if ((mf->width == 1600) && (mf->height == 1200)) {\r
1981                 ret = true;\r
1982         } else if ((mf->width == 2048) && (mf->height == 1536)) {\r
1983                 ret = true;\r
1984         } else if ((mf->width == 2592) && (mf->height == 1944)) {\r
1985                 ret = true;\r
1986         }\r
1987 \r
1988         if (ret == true)\r
1989                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);\r
1990         return ret;\r
1991 }\r
1992 \r
1993 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1994 {\r
1995     bool ret = false;\r
1996 \r
1997         if ((mf->width == 1280) && (mf->height == 720)) {\r
1998                 ret = true;\r
1999         } else if ((mf->width == 1920) && (mf->height == 1080)) {\r
2000                 ret = true;\r
2001         }\r
2002 \r
2003         if (ret == true)\r
2004                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);\r
2005         return ret;\r
2006 }\r
2007 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
2008 {\r
2009     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2010     struct sensor *sensor = to_sensor(client);\r
2011     const struct sensor_datafmt *fmt;\r
2012         const struct v4l2_queryctrl *qctrl;\r
2013         struct soc_camera_device *icd = client->dev.platform_data;\r
2014     struct reginfo *winseqe_set_addr=NULL;\r
2015     int ret=0, set_w,set_h;\r
2016 \r
2017         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,\r
2018                                    ARRAY_SIZE(sensor_colour_fmts));\r
2019         if (!fmt) {\r
2020         ret = -EINVAL;\r
2021         goto sensor_s_fmt_end;\r
2022     }\r
2023 \r
2024         if (sensor->info_priv.fmt.code != mf->code) {\r
2025                 switch (mf->code)\r
2026                 {\r
2027                         case V4L2_MBUS_FMT_YUYV8_2X8:\r
2028                         {\r
2029                                 winseqe_set_addr = sensor_ClrFmt_YUYV;\r
2030                                 break;\r
2031                         }\r
2032                         case V4L2_MBUS_FMT_UYVY8_2X8:\r
2033                         {\r
2034                                 winseqe_set_addr = sensor_ClrFmt_UYVY;\r
2035                                 break;\r
2036                         }\r
2037                         default:\r
2038                                 break;\r
2039                 }\r
2040                 if (winseqe_set_addr != NULL) {\r
2041             sensor_write_array(client, winseqe_set_addr);\r
2042                         sensor->info_priv.fmt.code = mf->code;\r
2043             sensor->info_priv.fmt.colorspace= mf->colorspace;            \r
2044                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);\r
2045                 } else {\r
2046                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);\r
2047                 }\r
2048         }\r
2049 \r
2050     set_w = mf->width;\r
2051     set_h = mf->height;\r
2052 \r
2053         if (((set_w <= 176) && (set_h <= 144)) &&( sensor_qcif[0].reg!=0xff))\r
2054         {\r
2055                 winseqe_set_addr = sensor_qcif;\r
2056         set_w = 176;\r
2057         set_h = 144;\r
2058         }\r
2059         else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=0xff))\r
2060     {\r
2061         winseqe_set_addr = sensor_qvga;\r
2062         set_w = 320;\r
2063         set_h = 240;\r
2064     }\r
2065     else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=0xff))\r
2066     {\r
2067         winseqe_set_addr = sensor_cif;\r
2068         set_w = 352;\r
2069         set_h = 288;\r
2070     }\r
2071     else if (((set_w <= 640) && (set_h <= 480)) &&( sensor_vga[0].reg!=0xff))\r
2072     {\r
2073         winseqe_set_addr = sensor_vga;\r
2074         set_w =640;\r
2075         set_h = 480;\r
2076     }\r
2077     else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=0xff))\r
2078     {\r
2079         winseqe_set_addr = sensor_svga;\r
2080         set_w = 800;\r
2081         set_h = 600;\r
2082     }\r
2083         else if (((set_w <= 1024) && (set_h <= 768)) &&( sensor_xga[0].reg!=0xff))\r
2084     {\r
2085         winseqe_set_addr = sensor_xga;\r
2086         set_w = 1024;\r
2087         set_h = 768;\r
2088     }\r
2089     else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=0xff))\r
2090     {\r
2091         winseqe_set_addr = sensor_sxga;\r
2092         set_w = 1280;\r
2093         set_h = 1024;\r
2094     }\r
2095     else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=0xff))\r
2096     {\r
2097         winseqe_set_addr = sensor_uxga;\r
2098         set_w = 1600;\r
2099         set_h = 1200;\r
2100     }\r
2101     else\r
2102     {\r
2103         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */\r
2104         set_w = SENSOR_INIT_WIDTH;\r
2105         set_h = SENSOR_INIT_HEIGHT;             \r
2106                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);\r
2107     }\r
2108 \r
2109     if ((int)winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) {\r
2110         #if CONFIG_SENSOR_Flash\r
2111         if (sensor_fmt_capturechk(sd,f) == true) {      /* ddl@rock-chips.com : Capture */\r
2112             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {\r
2113                 sensor_ioctrl(icd, Sensor_Flash, Flash_On);\r
2114                 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());\r
2115             }           \r
2116         } else {                                        /* ddl@rock-chips.com : Video */\r
2117             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {\r
2118                 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);\r
2119                 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());\r
2120             }\r
2121         }\r
2122         #endif\r
2123         ret |= sensor_write_array(client, winseqe_set_addr);\r
2124         if (ret != 0) {\r
2125             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());\r
2126             #if CONFIG_SENSOR_Flash\r
2127             if (sensor_fmt_capturechk(sd,f) == true) {\r
2128                 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {\r
2129                     sensor_ioctrl(icd, Sensor_Flash, Flash_Off);\r
2130                     SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());\r
2131                 }\r
2132             }\r
2133             #endif\r
2134             goto sensor_s_fmt_end;\r
2135         }\r
2136 \r
2137         sensor->info_priv.winseqe_cur_addr  = (int)winseqe_set_addr;\r
2138 \r
2139                 if (sensor_fmt_capturechk(sd,mf) == true) {                                 /* ddl@rock-chips.com : Capture */\r
2140         #if CONFIG_SENSOR_Effect\r
2141                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
2142                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);\r
2143         #endif\r
2144         #if CONFIG_SENSOR_WhiteBalance\r
2145                         if (sensor->info_priv.whiteBalance != 0) {\r
2146                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
2147                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);\r
2148                         }\r
2149         #endif\r
2150                         sensor->info_priv.snap2preview = true;\r
2151                 } else if (sensor_fmt_videochk(sd,mf) == true) {                        /* ddl@rock-chips.com : Video */\r
2152                 #if CONFIG_SENSOR_Effect\r
2153                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
2154                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);\r
2155         #endif\r
2156         #if CONFIG_SENSOR_WhiteBalance\r
2157                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
2158                         sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);\r
2159         #endif\r
2160                         sensor->info_priv.video2preview = true;\r
2161                 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {\r
2162                 #if CONFIG_SENSOR_Effect\r
2163                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
2164                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);\r
2165         #endif\r
2166         #if CONFIG_SENSOR_WhiteBalance\r
2167                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
2168                         sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);\r
2169         #endif\r
2170                         sensor->info_priv.video2preview = false;\r
2171                         sensor->info_priv.snap2preview = false;\r
2172                 }\r
2173         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);\r
2174     }\r
2175     else\r
2176     {\r
2177         SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);\r
2178     }\r
2179 \r
2180         mf->width = set_w;\r
2181     mf->height = set_h;\r
2182 \r
2183 sensor_s_fmt_end:\r
2184     return ret;\r
2185 }\r
2186 \r
2187 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
2188 {\r
2189     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2190     struct sensor *sensor = to_sensor(client);\r
2191     const struct sensor_datafmt *fmt;\r
2192     int ret = 0;\r
2193    \r
2194         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,\r
2195                                    ARRAY_SIZE(sensor_colour_fmts));\r
2196         if (fmt == NULL) {\r
2197                 fmt = &sensor->info_priv.fmt;\r
2198         mf->code = fmt->code;\r
2199         } \r
2200 \r
2201     if (mf->height > SENSOR_MAX_HEIGHT)\r
2202         mf->height = SENSOR_MAX_HEIGHT;\r
2203     else if (mf->height < SENSOR_MIN_HEIGHT)\r
2204         mf->height = SENSOR_MIN_HEIGHT;\r
2205 \r
2206     if (mf->width > SENSOR_MAX_WIDTH)\r
2207         mf->width = SENSOR_MAX_WIDTH;\r
2208     else if (mf->width < SENSOR_MIN_WIDTH)\r
2209         mf->width = SENSOR_MIN_WIDTH;\r
2210 \r
2211     mf->colorspace = fmt->colorspace;\r
2212     \r
2213     return ret;\r
2214 }\r
2215 \r
2216  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)\r
2217 {\r
2218     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2219 \r
2220     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)\r
2221         return -EINVAL;\r
2222 \r
2223     if (id->match.addr != client->addr)\r
2224         return -ENODEV;\r
2225 \r
2226     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */\r
2227     id->revision = 0;\r
2228 \r
2229     return 0;\r
2230 }\r
2231 #if CONFIG_SENSOR_Brightness\r
2232 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2233 {\r
2234     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2235 \r
2236     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2237     {\r
2238         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)\r
2239         {\r
2240             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)\r
2241             {\r
2242                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2243                 return -EINVAL;\r
2244             }\r
2245             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2246             return 0;\r
2247         }\r
2248     }\r
2249         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2250     return -EINVAL;\r
2251 }\r
2252 #endif\r
2253 #if CONFIG_SENSOR_Effect\r
2254 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2255 {\r
2256     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2257 \r
2258     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2259     {\r
2260         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)\r
2261         {\r
2262             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)\r
2263             {\r
2264                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2265                 return -EINVAL;\r
2266             }\r
2267             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2268             return 0;\r
2269         }\r
2270     }\r
2271         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2272     return -EINVAL;\r
2273 }\r
2274 #endif\r
2275 #if CONFIG_SENSOR_Exposure\r
2276 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2277 {\r
2278     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2279 \r
2280     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2281     {\r
2282         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)\r
2283         {\r
2284             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)\r
2285             {\r
2286                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2287                 return -EINVAL;\r
2288             }\r
2289             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2290             return 0;\r
2291         }\r
2292     }\r
2293         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2294     return -EINVAL;\r
2295 }\r
2296 #endif\r
2297 #if CONFIG_SENSOR_Saturation\r
2298 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2299 {\r
2300     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2301 \r
2302     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2303     {\r
2304         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)\r
2305         {\r
2306             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)\r
2307             {\r
2308                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2309                 return -EINVAL;\r
2310             }\r
2311             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2312             return 0;\r
2313         }\r
2314     }\r
2315     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2316     return -EINVAL;\r
2317 }\r
2318 #endif\r
2319 #if CONFIG_SENSOR_Contrast\r
2320 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2321 {\r
2322     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2323 \r
2324     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2325     {\r
2326         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)\r
2327         {\r
2328             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)\r
2329             {\r
2330                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2331                 return -EINVAL;\r
2332             }\r
2333             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2334             return 0;\r
2335         }\r
2336     }\r
2337     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2338     return -EINVAL;\r
2339 }\r
2340 #endif\r
2341 #if CONFIG_SENSOR_Mirror\r
2342 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2343 {\r
2344     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2345 \r
2346     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2347     {\r
2348         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)\r
2349         {\r
2350             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)\r
2351             {\r
2352                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2353                 return -EINVAL;\r
2354             }\r
2355             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2356             return 0;\r
2357         }\r
2358     }\r
2359     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2360     return -EINVAL;\r
2361 }\r
2362 #endif\r
2363 #if CONFIG_SENSOR_Flip\r
2364 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2365 {\r
2366     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2367 \r
2368     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2369     {\r
2370         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)\r
2371         {\r
2372             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)\r
2373             {\r
2374                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2375                 return -EINVAL;\r
2376             }\r
2377             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2378             return 0;\r
2379         }\r
2380     }\r
2381     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2382     return -EINVAL;\r
2383 }\r
2384 #endif\r
2385 #if CONFIG_SENSOR_Scene\r
2386 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2387 {\r
2388     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2389 \r
2390     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2391     {\r
2392         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)\r
2393         {\r
2394             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)\r
2395             {\r
2396                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2397                 return -EINVAL;\r
2398             }\r
2399             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2400             return 0;\r
2401         }\r
2402     }\r
2403     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2404     return -EINVAL;\r
2405 }\r
2406 #endif\r
2407 #if CONFIG_SENSOR_WhiteBalance\r
2408 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2409 {\r
2410     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2411 \r
2412     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2413     {\r
2414         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)\r
2415         {\r
2416             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)\r
2417             {\r
2418                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2419                 return -EINVAL;\r
2420             }\r
2421             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2422             return 0;\r
2423         }\r
2424     }\r
2425         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2426     return -EINVAL;\r
2427 }\r
2428 #endif\r
2429 #if CONFIG_SENSOR_DigitalZoom\r
2430 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2431 {\r
2432     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2433     struct sensor *sensor = to_sensor(client);\r
2434         const struct v4l2_queryctrl *qctrl_info;\r
2435     int digitalzoom_cur, digitalzoom_total;\r
2436 \r
2437         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);\r
2438         if (qctrl_info)\r
2439                 return -EINVAL;\r
2440 \r
2441     digitalzoom_cur = sensor->info_priv.digitalzoom;\r
2442     digitalzoom_total = qctrl_info->maximum;\r
2443 \r
2444     if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))\r
2445     {\r
2446         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);\r
2447         return -EINVAL;\r
2448     }\r
2449 \r
2450     if  ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))\r
2451     {\r
2452         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);\r
2453         return -EINVAL;\r
2454     }\r
2455 \r
2456     if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))\r
2457     {\r
2458         value = digitalzoom_total - digitalzoom_cur;\r
2459     }\r
2460 \r
2461     if ((value < 0) && ((digitalzoom_cur + value) < 0))\r
2462     {\r
2463         value = 0 - digitalzoom_cur;\r
2464     }\r
2465 \r
2466     digitalzoom_cur += value;\r
2467 \r
2468     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)\r
2469     {\r
2470         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)\r
2471         {\r
2472             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2473             return -EINVAL;\r
2474         }\r
2475         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2476         return 0;\r
2477     }\r
2478 \r
2479     return -EINVAL;\r
2480 }\r
2481 #endif\r
2482 #if CONFIG_SENSOR_Flash\r
2483 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2484 {    \r
2485     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {\r
2486         if (value == 3) {       /* ddl@rock-chips.com: torch */\r
2487             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */\r
2488         } else {\r
2489             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);\r
2490         }\r
2491         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2492         return 0;\r
2493     }\r
2494     \r
2495         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2496     return -EINVAL;\r
2497 }\r
2498 #endif\r
2499 \r
2500 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)\r
2501 {\r
2502     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2503     struct sensor *sensor = to_sensor(client);\r
2504     const struct v4l2_queryctrl *qctrl;\r
2505 \r
2506     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);\r
2507 \r
2508     if (!qctrl)\r
2509     {\r
2510         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);\r
2511         return -EINVAL;\r
2512     }\r
2513 \r
2514     switch (ctrl->id)\r
2515     {\r
2516         case V4L2_CID_BRIGHTNESS:\r
2517             {\r
2518                 ctrl->value = sensor->info_priv.brightness;\r
2519                 break;\r
2520             }\r
2521         case V4L2_CID_SATURATION:\r
2522             {\r
2523                 ctrl->value = sensor->info_priv.saturation;\r
2524                 break;\r
2525             }\r
2526         case V4L2_CID_CONTRAST:\r
2527             {\r
2528                 ctrl->value = sensor->info_priv.contrast;\r
2529                 break;\r
2530             }\r
2531         case V4L2_CID_DO_WHITE_BALANCE:\r
2532             {\r
2533                 ctrl->value = sensor->info_priv.whiteBalance;\r
2534                 break;\r
2535             }\r
2536         case V4L2_CID_EXPOSURE:\r
2537             {\r
2538                 ctrl->value = sensor->info_priv.exposure;\r
2539                 break;\r
2540             }\r
2541         case V4L2_CID_HFLIP:\r
2542             {\r
2543                 ctrl->value = sensor->info_priv.mirror;\r
2544                 break;\r
2545             }\r
2546         case V4L2_CID_VFLIP:\r
2547             {\r
2548                 ctrl->value = sensor->info_priv.flip;\r
2549                 break;\r
2550             }\r
2551         default :\r
2552                 break;\r
2553     }\r
2554     return 0;\r
2555 }\r
2556 \r
2557 \r
2558 \r
2559 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)\r
2560 {\r
2561     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2562     struct sensor *sensor = to_sensor(client);\r
2563     struct soc_camera_device *icd = client->dev.platform_data;\r
2564     const struct v4l2_queryctrl *qctrl;\r
2565 \r
2566 \r
2567     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);\r
2568 \r
2569     if (!qctrl)\r
2570     {\r
2571         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);\r
2572         return -EINVAL;\r
2573     }\r
2574 \r
2575     switch (ctrl->id)\r
2576     {\r
2577 #if CONFIG_SENSOR_Brightness\r
2578         case V4L2_CID_BRIGHTNESS:\r
2579             {\r
2580                 if (ctrl->value != sensor->info_priv.brightness)\r
2581                 {\r
2582                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)\r
2583                     {\r
2584                         return -EINVAL;\r
2585                     }\r
2586                     sensor->info_priv.brightness = ctrl->value;\r
2587                 }\r
2588                 break;\r
2589             }\r
2590 #endif\r
2591 #if CONFIG_SENSOR_Exposure\r
2592         case V4L2_CID_EXPOSURE:\r
2593             {\r
2594                 if (ctrl->value != sensor->info_priv.exposure)\r
2595                 {\r
2596                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)\r
2597                     {\r
2598                         return -EINVAL;\r
2599                     }\r
2600                     sensor->info_priv.exposure = ctrl->value;\r
2601                 }\r
2602                 break;\r
2603             }\r
2604 #endif\r
2605 #if CONFIG_SENSOR_Saturation\r
2606         case V4L2_CID_SATURATION:\r
2607             {\r
2608                 if (ctrl->value != sensor->info_priv.saturation)\r
2609                 {\r
2610                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)\r
2611                     {\r
2612                         return -EINVAL;\r
2613                     }\r
2614                     sensor->info_priv.saturation = ctrl->value;\r
2615                 }\r
2616                 break;\r
2617             }\r
2618 #endif\r
2619 #if CONFIG_SENSOR_Contrast\r
2620         case V4L2_CID_CONTRAST:\r
2621             {\r
2622                 if (ctrl->value != sensor->info_priv.contrast)\r
2623                 {\r
2624                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)\r
2625                     {\r
2626                         return -EINVAL;\r
2627                     }\r
2628                     sensor->info_priv.contrast = ctrl->value;\r
2629                 }\r
2630                 break;\r
2631             }\r
2632 #endif\r
2633 #if CONFIG_SENSOR_WhiteBalance\r
2634         case V4L2_CID_DO_WHITE_BALANCE:\r
2635             {\r
2636                 if (ctrl->value != sensor->info_priv.whiteBalance)\r
2637                 {\r
2638                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)\r
2639                     {\r
2640                         return -EINVAL;\r
2641                     }\r
2642                     sensor->info_priv.whiteBalance = ctrl->value;\r
2643                 }\r
2644                 break;\r
2645             }\r
2646 #endif\r
2647 #if CONFIG_SENSOR_Mirror\r
2648         case V4L2_CID_HFLIP:\r
2649             {\r
2650                 if (ctrl->value != sensor->info_priv.mirror)\r
2651                 {\r
2652                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)\r
2653                         return -EINVAL;\r
2654                     sensor->info_priv.mirror = ctrl->value;\r
2655                 }\r
2656                 break;\r
2657             }\r
2658 #endif\r
2659 #if CONFIG_SENSOR_Flip\r
2660         case V4L2_CID_VFLIP:\r
2661             {\r
2662                 if (ctrl->value != sensor->info_priv.flip)\r
2663                 {\r
2664                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)\r
2665                         return -EINVAL;\r
2666                     sensor->info_priv.flip = ctrl->value;\r
2667                 }\r
2668                 break;\r
2669             }\r
2670 #endif\r
2671         default:\r
2672             break;\r
2673     }\r
2674 \r
2675     return 0;\r
2676 }\r
2677 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)\r
2678 {\r
2679     const struct v4l2_queryctrl *qctrl;\r
2680     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2681     struct sensor *sensor = to_sensor(client);\r
2682 \r
2683     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);\r
2684 \r
2685     if (!qctrl)\r
2686     {\r
2687         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);\r
2688         return -EINVAL;\r
2689     }\r
2690 \r
2691     switch (ext_ctrl->id)\r
2692     {\r
2693         case V4L2_CID_SCENE:\r
2694             {\r
2695                 ext_ctrl->value = sensor->info_priv.scene;\r
2696                 break;\r
2697             }\r
2698         case V4L2_CID_EFFECT:\r
2699             {\r
2700                 ext_ctrl->value = sensor->info_priv.effect;\r
2701                 break;\r
2702             }\r
2703         case V4L2_CID_ZOOM_ABSOLUTE:\r
2704             {\r
2705                 ext_ctrl->value = sensor->info_priv.digitalzoom;\r
2706                 break;\r
2707             }\r
2708         case V4L2_CID_ZOOM_RELATIVE:\r
2709             {\r
2710                 return -EINVAL;\r
2711             }\r
2712         case V4L2_CID_FOCUS_ABSOLUTE:\r
2713             {\r
2714                 ext_ctrl->value = sensor->info_priv.focus;\r
2715                 break;\r
2716             }\r
2717         case V4L2_CID_FOCUS_RELATIVE:\r
2718             {\r
2719                 return -EINVAL;\r
2720             }\r
2721         case V4L2_CID_FLASH:\r
2722             {\r
2723                 ext_ctrl->value = sensor->info_priv.flash;\r
2724                 break;\r
2725             }\r
2726         default :\r
2727             break;\r
2728     }\r
2729     return 0;\r
2730 }\r
2731 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)\r
2732 {\r
2733     const struct v4l2_queryctrl *qctrl;\r
2734     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2735     struct sensor *sensor = to_sensor(client);\r
2736     int val_offset;\r
2737 \r
2738     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);\r
2739 \r
2740     if (!qctrl)\r
2741     {\r
2742         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);\r
2743         return -EINVAL;\r
2744     }\r
2745 \r
2746         val_offset = 0;\r
2747     switch (ext_ctrl->id)\r
2748     {\r
2749 #if CONFIG_SENSOR_Scene\r
2750         case V4L2_CID_SCENE:\r
2751             {\r
2752                 if (ext_ctrl->value != sensor->info_priv.scene)\r
2753                 {\r
2754                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)\r
2755                         return -EINVAL;\r
2756                     sensor->info_priv.scene = ext_ctrl->value;\r
2757                 }\r
2758                 break;\r
2759             }\r
2760 #endif\r
2761 #if CONFIG_SENSOR_Effect\r
2762         case V4L2_CID_EFFECT:\r
2763             {\r
2764                 if (ext_ctrl->value != sensor->info_priv.effect)\r
2765                 {\r
2766                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)\r
2767                         return -EINVAL;\r
2768                     sensor->info_priv.effect= ext_ctrl->value;\r
2769                 }\r
2770                 break;\r
2771             }\r
2772 #endif\r
2773 #if CONFIG_SENSOR_DigitalZoom\r
2774         case V4L2_CID_ZOOM_ABSOLUTE:\r
2775             {\r
2776                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))\r
2777                     return -EINVAL;\r
2778 \r
2779                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)\r
2780                 {\r
2781                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;\r
2782 \r
2783                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)\r
2784                         return -EINVAL;\r
2785                     sensor->info_priv.digitalzoom += val_offset;\r
2786 \r
2787                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);\r
2788                 }\r
2789 \r
2790                 break;\r
2791             }\r
2792         case V4L2_CID_ZOOM_RELATIVE:\r
2793             {\r
2794                 if (ext_ctrl->value)\r
2795                 {\r
2796                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)\r
2797                         return -EINVAL;\r
2798                     sensor->info_priv.digitalzoom += ext_ctrl->value;\r
2799 \r
2800                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);\r
2801                 }\r
2802                 break;\r
2803             }\r
2804 #endif\r
2805 #if CONFIG_SENSOR_Focus\r
2806         case V4L2_CID_FOCUS_ABSOLUTE:\r
2807             {\r
2808                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))\r
2809                     return -EINVAL;\r
2810 \r
2811                 if (ext_ctrl->value != sensor->info_priv.focus)\r
2812                 {\r
2813                     val_offset = ext_ctrl->value -sensor->info_priv.focus;\r
2814 \r
2815                     sensor->info_priv.focus += val_offset;\r
2816                 }\r
2817 \r
2818                 break;\r
2819             }\r
2820         case V4L2_CID_FOCUS_RELATIVE:\r
2821             {\r
2822                 if (ext_ctrl->value)\r
2823                 {\r
2824                     sensor->info_priv.focus += ext_ctrl->value;\r
2825 \r
2826                     SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);\r
2827                 }\r
2828                 break;\r
2829             }\r
2830 #endif\r
2831 #if CONFIG_SENSOR_Flash\r
2832         case V4L2_CID_FLASH:\r
2833             {\r
2834                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)\r
2835                     return -EINVAL;\r
2836                 sensor->info_priv.flash = ext_ctrl->value;\r
2837 \r
2838                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);\r
2839                 break;\r
2840             }\r
2841 #endif\r
2842         default:\r
2843             break;\r
2844     }\r
2845 \r
2846     return 0;\r
2847 }\r
2848 \r
2849 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)\r
2850 {\r
2851     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2852     struct soc_camera_device *icd = client->dev.platform_data;\r
2853     int i, error_cnt=0, error_idx=-1;\r
2854 \r
2855 \r
2856     for (i=0; i<ext_ctrl->count; i++) {\r
2857         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {\r
2858             error_cnt++;\r
2859             error_idx = i;\r
2860         }\r
2861     }\r
2862 \r
2863     if (error_cnt > 1)\r
2864         error_idx = ext_ctrl->count;\r
2865 \r
2866     if (error_idx != -1) {\r
2867         ext_ctrl->error_idx = error_idx;\r
2868         return -EINVAL;\r
2869     } else {\r
2870         return 0;\r
2871     }\r
2872 }\r
2873 \r
2874 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)\r
2875 {\r
2876     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2877     struct soc_camera_device *icd = client->dev.platform_data;\r
2878     int i, error_cnt=0, error_idx=-1;\r
2879 \r
2880 \r
2881     for (i=0; i<ext_ctrl->count; i++) {\r
2882         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {\r
2883             error_cnt++;\r
2884             error_idx = i;\r
2885         }\r
2886     }\r
2887 \r
2888     if (error_cnt > 1)\r
2889         error_idx = ext_ctrl->count;\r
2890 \r
2891     if (error_idx != -1) {\r
2892         ext_ctrl->error_idx = error_idx;\r
2893         return -EINVAL;\r
2894     } else {\r
2895         return 0;\r
2896     }\r
2897 }\r
2898 \r
2899 /* Interface active, can use i2c. If it fails, it can indeed mean, that\r
2900  * this wasn't our capture interface, so, we wait for the right one */\r
2901 static int sensor_video_probe(struct soc_camera_device *icd,\r
2902                                struct i2c_client *client)\r
2903 {\r
2904     int ret;\r
2905     \r
2906 \r
2907     /* We must have a parent by now. And it cannot be a wrong one.\r
2908      * So this entire test is completely redundant. */\r
2909     if (!icd->dev.parent ||\r
2910             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)\r
2911                 return -ENODEV;\r
2912 \r
2913         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {\r
2914                 ret = -ENODEV;\r
2915                 goto sensor_video_probe_err;\r
2916         }\r
2917 #if 0\r
2918     /* soft reset */\r
2919     ret = sensor_write(client, 0x3012, 0x80);\r
2920     if (ret != 0)\r
2921     {\r
2922         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());\r
2923         return -ENODEV;\r
2924     }\r
2925     mdelay(5);          //delay 5 microseconds\r
2926 \r
2927     /* check if it is an sensor sensor */\r
2928     ret = sensor_read(client, 0x300a, &value);\r
2929     if (ret != 0) {\r
2930         SENSOR_TR("read chip id high byte failed\n");\r
2931         ret = -ENODEV;\r
2932         goto sensor_video_probe_err;\r
2933     }\r
2934 \r
2935     \r
2936     ret = sensor_read(client, 0x01, &value);\r
2937     if (ret != 0) {\r
2938         SENSOR_TR("read chip id low byte failed\n");\r
2939         ret = -ENODEV;\r
2940         goto sensor_video_probe_err;\r
2941     }\r
2942 \r
2943     pid = (value & 0xff);\r
2944     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
2945     if (pid == SENSOR_ID) {\r
2946         sensor->model = SENSOR_V4L2_IDENT;\r
2947     } else {\r
2948         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
2949         ret = -ENODEV;\r
2950         goto sensor_video_probe_err;\r
2951     }\r
2952 #endif\r
2953 \r
2954     return 0;\r
2955 \r
2956 sensor_video_probe_err:\r
2957 \r
2958     return ret;\r
2959 }\r
2960 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)\r
2961 {\r
2962         struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2963     struct soc_camera_device *icd = client->dev.platform_data;\r
2964     struct sensor *sensor = to_sensor(client);\r
2965     int ret = 0;\r
2966 #if CONFIG_SENSOR_Flash \r
2967     int i;\r
2968 #endif\r
2969     \r
2970         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);\r
2971         switch (cmd)\r
2972         {\r
2973                 case RK_CAM_SUBDEV_DEACTIVATE:\r
2974                 {\r
2975                         sensor_deactivate(client);\r
2976                         break;\r
2977                 }\r
2978 \r
2979                 case RK_CAM_SUBDEV_IOREQUEST:\r
2980                 {\r
2981                         sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;           \r
2982             if (sensor->sensor_io_request != NULL) { \r
2983                 if (sensor->sensor_io_request->gpio_res[0].dev_name && \r
2984                     (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {\r
2985                     sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];\r
2986                 } else if (sensor->sensor_io_request->gpio_res[1].dev_name && \r
2987                     (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {\r
2988                     sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];\r
2989                 }\r
2990             } else {\r
2991                 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);\r
2992                 ret = -EINVAL;\r
2993                 goto sensor_ioctl_end;\r
2994             }\r
2995             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control \r
2996                for this project */\r
2997             #if CONFIG_SENSOR_Flash     \r
2998                 if (sensor->sensor_gpio_res) { \r
2999                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {\r
3000                     for (i = 0; i < icd->ops->num_controls; i++) {\r
3001                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {\r
3002                                         memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                       \r
3003                                 }\r
3004                     }\r
3005                     sensor->info_priv.flash = 0xff;\r
3006                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());\r
3007                 }\r
3008                 }\r
3009             #endif\r
3010                         break;\r
3011                 }\r
3012                 default:\r
3013                 {\r
3014                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);\r
3015                         break;\r
3016                 }\r
3017         }\r
3018 sensor_ioctl_end:\r
3019         return ret;\r
3020 \r
3021 }\r
3022 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,\r
3023                             enum v4l2_mbus_pixelcode *code)\r
3024 {\r
3025         if (index >= ARRAY_SIZE(sensor_colour_fmts))\r
3026                 return -EINVAL;\r
3027 \r
3028         *code = sensor_colour_fmts[index].code;\r
3029         return 0;\r
3030 }\r
3031 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {\r
3032         .init           = sensor_init,\r
3033         .g_ctrl         = sensor_g_control,\r
3034         .s_ctrl         = sensor_s_control,\r
3035         .g_ext_ctrls          = sensor_g_ext_controls,\r
3036         .s_ext_ctrls          = sensor_s_ext_controls,\r
3037         .g_chip_ident   = sensor_g_chip_ident,\r
3038         .ioctl = sensor_ioctl,\r
3039 };\r
3040 \r
3041 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {\r
3042         .s_mbus_fmt     = sensor_s_fmt,\r
3043         .g_mbus_fmt     = sensor_g_fmt,\r
3044         .try_mbus_fmt   = sensor_try_fmt,\r
3045         .enum_mbus_fmt  = sensor_enum_fmt,\r
3046 };\r
3047 \r
3048 static struct v4l2_subdev_ops sensor_subdev_ops = {\r
3049         .core   = &sensor_subdev_core_ops,\r
3050         .video = &sensor_subdev_video_ops,\r
3051 };\r
3052 \r
3053 static int sensor_probe(struct i2c_client *client,\r
3054                          const struct i2c_device_id *did)\r
3055 {\r
3056     struct sensor *sensor;\r
3057     struct soc_camera_device *icd = client->dev.platform_data;\r
3058     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);\r
3059     struct soc_camera_link *icl;\r
3060     int ret;\r
3061 \r
3062     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);\r
3063     if (!icd) {\r
3064         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());\r
3065         return -EINVAL;\r
3066     }\r
3067 \r
3068     icl = to_soc_camera_link(icd);\r
3069     if (!icl) {\r
3070         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());\r
3071         return -EINVAL;\r
3072     }\r
3073 \r
3074     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {\r
3075         dev_warn(&adapter->dev,\r
3076                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");\r
3077         return -EIO;\r
3078     }\r
3079 \r
3080     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);\r
3081     if (!sensor)\r
3082         return -ENOMEM;\r
3083 \r
3084     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);\r
3085 \r
3086     /* Second stage probe - when a capture adapter is there */\r
3087     icd->ops            = &sensor_ops;\r
3088     sensor->info_priv.fmt = sensor_colour_fmts[0];\r
3089         #if CONFIG_SENSOR_I2C_NOSCHED\r
3090         atomic_set(&sensor->tasklock_cnt,0);\r
3091         #endif\r
3092 \r
3093     ret = sensor_video_probe(icd, client);\r
3094     if (ret < 0) {\r
3095         icd->ops = NULL;\r
3096         i2c_set_clientdata(client, NULL);\r
3097         kfree(sensor);\r
3098                 sensor = NULL;\r
3099     }\r
3100     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);\r
3101     return ret;\r
3102 }\r
3103 \r
3104 static int sensor_remove(struct i2c_client *client)\r
3105 {\r
3106     struct sensor *sensor = to_sensor(client);\r
3107     struct soc_camera_device *icd = client->dev.platform_data;\r
3108 \r
3109     icd->ops = NULL;\r
3110     i2c_set_clientdata(client, NULL);\r
3111     client->driver = NULL;\r
3112     kfree(sensor);\r
3113         sensor = NULL;\r
3114     return 0;\r
3115 }\r
3116 \r
3117 static const struct i2c_device_id sensor_id[] = {\r
3118         {SENSOR_NAME_STRING(), 0 },\r
3119         { }\r
3120 };\r
3121 MODULE_DEVICE_TABLE(i2c, sensor_id);\r
3122 \r
3123 static struct i2c_driver sensor_i2c_driver = {\r
3124         .driver = {\r
3125                 .name = SENSOR_NAME_STRING(),\r
3126         },\r
3127         .probe          = sensor_probe,\r
3128         .remove         = sensor_remove,\r
3129         .id_table       = sensor_id,\r
3130 };\r
3131 \r
3132 static int __init sensor_mod_init(void)\r
3133 {\r
3134     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());\r
3135     return i2c_add_driver(&sensor_i2c_driver);\r
3136 }\r
3137 \r
3138 static void __exit sensor_mod_exit(void)\r
3139 {\r
3140     i2c_del_driver(&sensor_i2c_driver);\r
3141 }\r
3142 \r
3143 device_initcall_sync(sensor_mod_init);\r
3144 module_exit(sensor_mod_exit);\r
3145 \r
3146 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));\r
3147 MODULE_AUTHOR("ddl <kernel@rock-chips>");\r
3148 MODULE_LICENSE("GPL");