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