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