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