Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0-jb
[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 #ifdef 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     flash_off_timer.icd = icd;\r
1779         flash_off_timer.timer.function = flash_off_func;\r
1780     #endif\r
1781 \r
1782     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
1783     sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;\r
1784     return 0;\r
1785 sensor_INIT_ERR:\r
1786     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;\r
1787         sensor_task_lock(client,0);\r
1788         sensor_deactivate(client);\r
1789     return ret;\r
1790 }\r
1791 \r
1792 static int sensor_deactivate(struct i2c_client *client)\r
1793 {\r
1794         struct soc_camera_device *icd = client->dev.platform_data;\r
1795 \r
1796     struct sensor *sensor = to_sensor(client);\r
1797         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);\r
1798 \r
1799         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */\r
1800 #if 0   \r
1801         sensor_task_lock(client, 1);\r
1802     sensor_write(client, 0x3000, reg_val&0xfc);\r
1803         sensor_write(client, 0x3001, 0x00);\r
1804         sensor_task_lock(client, 0);\r
1805 #endif\r
1806         sensor_ioctrl(icd, Sensor_PowerDown, 1);\r
1807     msleep(100); \r
1808         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */\r
1809         icd->user_width = SENSOR_INIT_WIDTH;\r
1810     icd->user_height = SENSOR_INIT_HEIGHT;\r
1811     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;\r
1812         \r
1813         return 0;\r
1814 }\r
1815 \r
1816 static  struct reginfo sensor_power_down_sequence[]=\r
1817 {\r
1818     {0x00,0x00}\r
1819 };\r
1820 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)\r
1821 {\r
1822     int ret;\r
1823     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
1824 \r
1825     if (pm_msg.event == PM_EVENT_SUSPEND) {\r
1826         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());\r
1827         ret = sensor_write_array(client, sensor_power_down_sequence) ;\r
1828         if (ret != 0) {\r
1829             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);\r
1830             return ret;\r
1831         } else {\r
1832             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);\r
1833             if (ret < 0) {\r
1834                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());\r
1835                 return -EINVAL;\r
1836             }\r
1837         }\r
1838     } else {\r
1839         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());\r
1840         return -EINVAL;\r
1841     }\r
1842     return 0;\r
1843 }\r
1844 \r
1845 static int sensor_resume(struct soc_camera_device *icd)\r
1846 {\r
1847         int ret;\r
1848 \r
1849     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);\r
1850     if (ret < 0) {\r
1851                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());\r
1852         return -EINVAL;\r
1853     }\r
1854 \r
1855         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());\r
1856 \r
1857     return 0;\r
1858 \r
1859 }\r
1860 \r
1861 static int sensor_set_bus_param(struct soc_camera_device *icd,\r
1862                                 unsigned long flags)\r
1863 {\r
1864 \r
1865     return 0;\r
1866 }\r
1867 \r
1868 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)\r
1869 {\r
1870     struct soc_camera_link *icl = to_soc_camera_link(icd);\r
1871     unsigned long flags = SENSOR_BUS_PARAM;\r
1872 \r
1873     return soc_camera_apply_sensor_flags(icl, flags);\r
1874 }\r
1875 \r
1876 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1877 {\r
1878     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
1879     struct soc_camera_device *icd = client->dev.platform_data;\r
1880     struct sensor *sensor = to_sensor(client);\r
1881 \r
1882     mf->width   = icd->user_width;\r
1883         mf->height      = icd->user_height;\r
1884         mf->code        = sensor->info_priv.fmt.code;\r
1885         mf->colorspace  = sensor->info_priv.fmt.colorspace;\r
1886         mf->field       = V4L2_FIELD_NONE;\r
1887 \r
1888     return 0;\r
1889 }\r
1890 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1891 {\r
1892     bool ret = false;\r
1893 \r
1894         if ((mf->width == 1024) && (mf->height == 768)) {\r
1895                 ret = true;\r
1896         } else if ((mf->width == 1280) && (mf->height == 1024)) {\r
1897                 ret = true;\r
1898         } else if ((mf->width == 1600) && (mf->height == 1200)) {\r
1899                 ret = true;\r
1900         } else if ((mf->width == 2048) && (mf->height == 1536)) {\r
1901                 ret = true;\r
1902         } else if ((mf->width == 2592) && (mf->height == 1944)) {\r
1903                 ret = true;\r
1904         }\r
1905 \r
1906         if (ret == true)\r
1907                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);\r
1908         return ret;\r
1909 }\r
1910 \r
1911 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1912 {\r
1913     bool ret = false;\r
1914 \r
1915         if ((mf->width == 1280) && (mf->height == 720)) {\r
1916                 ret = true;\r
1917         } else if ((mf->width == 1920) && (mf->height == 1080)) {\r
1918                 ret = true;\r
1919         }\r
1920 \r
1921         if (ret == true)\r
1922                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);\r
1923         return ret;\r
1924 }\r
1925 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
1926 {\r
1927     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
1928     struct sensor *sensor = to_sensor(client);\r
1929     const struct sensor_datafmt *fmt;\r
1930         const struct v4l2_queryctrl *qctrl;\r
1931         struct soc_camera_device *icd = client->dev.platform_data;\r
1932     struct reginfo *winseqe_set_addr=NULL;\r
1933     int ret=0, set_w,set_h;\r
1934 \r
1935         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,\r
1936                                    ARRAY_SIZE(sensor_colour_fmts));\r
1937         if (!fmt) {\r
1938         ret = -EINVAL;\r
1939         goto sensor_s_fmt_end;\r
1940     }\r
1941 \r
1942         if (sensor->info_priv.fmt.code != mf->code) {\r
1943                 switch (mf->code)\r
1944                 {\r
1945                         case V4L2_MBUS_FMT_YUYV8_2X8:\r
1946                         {\r
1947                                 winseqe_set_addr = sensor_ClrFmt_YUYV;\r
1948                                 break;\r
1949                         }\r
1950                         case V4L2_MBUS_FMT_UYVY8_2X8:\r
1951                         {\r
1952                                 winseqe_set_addr = sensor_ClrFmt_UYVY;\r
1953                                 break;\r
1954                         }\r
1955                         default:\r
1956                                 break;\r
1957                 }\r
1958                 if (winseqe_set_addr != NULL) {\r
1959             sensor_write_array(client, winseqe_set_addr);\r
1960                         sensor->info_priv.fmt.code = mf->code;\r
1961             sensor->info_priv.fmt.colorspace= mf->colorspace;            \r
1962                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);\r
1963                 } else {\r
1964                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);\r
1965                 }\r
1966         }\r
1967 \r
1968     set_w = mf->width;\r
1969     set_h = mf->height;\r
1970 \r
1971         if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)\r
1972         {\r
1973                 winseqe_set_addr = sensor_qcif;\r
1974         set_w = 176;\r
1975         set_h = 144;\r
1976         }\r
1977         else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)\r
1978     {\r
1979         winseqe_set_addr = sensor_qvga;\r
1980         set_w = 320;\r
1981         set_h = 240;\r
1982     }\r
1983     else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)\r
1984     {\r
1985         winseqe_set_addr = sensor_cif;\r
1986         set_w = 352;\r
1987         set_h = 288;\r
1988     }\r
1989     else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)\r
1990     {\r
1991         winseqe_set_addr = sensor_vga;\r
1992         set_w = 640;\r
1993         set_h = 480;\r
1994     }\r
1995     else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)\r
1996     {\r
1997         winseqe_set_addr = sensor_svga;\r
1998         set_w = 800;\r
1999         set_h = 600;\r
2000     }\r
2001         else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)\r
2002     {\r
2003         winseqe_set_addr = sensor_xga;\r
2004         set_w = 1024;\r
2005         set_h = 768;\r
2006     }\r
2007     else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)\r
2008     {\r
2009         winseqe_set_addr = sensor_sxga;\r
2010         set_w = 1280;\r
2011         set_h = 1024;\r
2012     }\r
2013     else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)\r
2014     {\r
2015         winseqe_set_addr = sensor_uxga;\r
2016         set_w = 1600;\r
2017         set_h = 1200;\r
2018     }\r
2019     else\r
2020     {\r
2021         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */\r
2022         set_w = SENSOR_INIT_WIDTH;\r
2023         set_h = SENSOR_INIT_HEIGHT;\r
2024                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);\r
2025     }\r
2026 \r
2027     if ((int)winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) {\r
2028         #if CONFIG_SENSOR_Flash\r
2029         if (sensor_fmt_capturechk(sd,mf) == true) {      /* ddl@rock-chips.com : Capture */\r
2030             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {\r
2031                 sensor_ioctrl(icd, Sensor_Flash, Flash_On);\r
2032                 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());\r
2033             }           \r
2034         } else {                                        /* ddl@rock-chips.com : Video */\r
2035             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {\r
2036                 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);\r
2037                 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());\r
2038             }\r
2039         }\r
2040         #endif        \r
2041         ret |= sensor_write_array(client, winseqe_set_addr);\r
2042         if (ret != 0) {\r
2043             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());\r
2044             #if CONFIG_SENSOR_Flash\r
2045             if (sensor_fmt_capturechk(sd,mf) == true) {\r
2046                 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {\r
2047                     sensor_ioctrl(icd, Sensor_Flash, Flash_Off);\r
2048                     SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());\r
2049                 }\r
2050             }\r
2051             #endif\r
2052             goto sensor_s_fmt_end;\r
2053         }\r
2054 \r
2055         sensor->info_priv.winseqe_cur_addr  = (int)winseqe_set_addr;\r
2056 \r
2057                 if (sensor_fmt_capturechk(sd,mf) == true) {                                 /* ddl@rock-chips.com : Capture */\r
2058         #if CONFIG_SENSOR_Effect\r
2059                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
2060                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);\r
2061         #endif\r
2062         #if CONFIG_SENSOR_WhiteBalance\r
2063                         if (sensor->info_priv.whiteBalance != 0) {\r
2064                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
2065                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);\r
2066                         }\r
2067         #endif\r
2068                         sensor->info_priv.snap2preview = true;\r
2069                 } else if (sensor_fmt_videochk(sd,mf) == true) {                        /* ddl@rock-chips.com : Video */\r
2070                 #if CONFIG_SENSOR_Effect\r
2071                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
2072                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);\r
2073         #endif\r
2074         #if CONFIG_SENSOR_WhiteBalance\r
2075                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
2076                         sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);\r
2077         #endif\r
2078                         sensor->info_priv.video2preview = true;\r
2079                 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {\r
2080                 #if CONFIG_SENSOR_Effect\r
2081                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);\r
2082                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);\r
2083         #endif\r
2084         #if CONFIG_SENSOR_WhiteBalance    \r
2085                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);\r
2086                         sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);\r
2087         #endif    \r
2088                         sensor->info_priv.video2preview = false;            \r
2089                         sensor->info_priv.snap2preview = false;\r
2090                 }\r
2091         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);\r
2092     }\r
2093     else\r
2094     {\r
2095         SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);\r
2096     }\r
2097 \r
2098         mf->width = set_w;\r
2099     mf->height = set_h;\r
2100 \r
2101 sensor_s_fmt_end:\r
2102     return ret;\r
2103 }\r
2104 \r
2105 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)\r
2106 {\r
2107     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2108     struct sensor *sensor = to_sensor(client);\r
2109     const struct sensor_datafmt *fmt;\r
2110     int ret = 0,set_w,set_h;\r
2111    \r
2112         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,\r
2113                                    ARRAY_SIZE(sensor_colour_fmts));\r
2114         if (fmt == NULL) {\r
2115                 fmt = &sensor->info_priv.fmt;\r
2116         mf->code = fmt->code;\r
2117         } \r
2118 \r
2119     if (mf->height > SENSOR_MAX_HEIGHT)\r
2120         mf->height = SENSOR_MAX_HEIGHT;\r
2121     else if (mf->height < SENSOR_MIN_HEIGHT)\r
2122         mf->height = SENSOR_MIN_HEIGHT;\r
2123 \r
2124     if (mf->width > SENSOR_MAX_WIDTH)\r
2125         mf->width = SENSOR_MAX_WIDTH;\r
2126     else if (mf->width < SENSOR_MIN_WIDTH)\r
2127         mf->width = SENSOR_MIN_WIDTH;\r
2128 \r
2129     set_w = mf->width;\r
2130     set_h = mf->height;\r
2131 \r
2132         if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)\r
2133         {\r
2134         set_w = 176;\r
2135         set_h = 144;\r
2136         }\r
2137         else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)\r
2138     {\r
2139         set_w = 320;\r
2140         set_h = 240;\r
2141     }\r
2142     else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)\r
2143     {\r
2144         set_w = 352;\r
2145         set_h = 288;\r
2146     }\r
2147     else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)\r
2148     {\r
2149         set_w = 640;\r
2150         set_h = 480;\r
2151     }\r
2152     else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)\r
2153     {\r
2154         set_w = 800;\r
2155         set_h = 600;\r
2156     }\r
2157         else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)\r
2158     {\r
2159         set_w = 1024;\r
2160         set_h = 768;\r
2161     }\r
2162     else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)\r
2163     {\r
2164         set_w = 1280;\r
2165         set_h = 1024;\r
2166     }\r
2167     else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)\r
2168     {\r
2169         set_w = 1600;\r
2170         set_h = 1200;\r
2171     }\r
2172     else\r
2173     {\r
2174         set_w = SENSOR_INIT_WIDTH;\r
2175         set_h = SENSOR_INIT_HEIGHT;\r
2176     }\r
2177 \r
2178     mf->width = set_w;\r
2179     mf->height = set_h;\r
2180 \r
2181     mf->colorspace = fmt->colorspace;\r
2182     \r
2183     return ret;\r
2184 }\r
2185  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)\r
2186 {\r
2187     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2188 \r
2189     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)\r
2190         return -EINVAL;\r
2191 \r
2192     if (id->match.addr != client->addr)\r
2193         return -ENODEV;\r
2194 \r
2195     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */\r
2196     id->revision = 0;\r
2197 \r
2198     return 0;\r
2199 }\r
2200 #if CONFIG_SENSOR_Brightness\r
2201 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2202 {\r
2203     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2204 \r
2205     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2206     {\r
2207         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)\r
2208         {\r
2209             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)\r
2210             {\r
2211                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2212                 return -EINVAL;\r
2213             }\r
2214             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2215             return 0;\r
2216         }\r
2217     }\r
2218         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2219     return -EINVAL;\r
2220 }\r
2221 #endif\r
2222 #if CONFIG_SENSOR_Effect\r
2223 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2224 {\r
2225     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2226 \r
2227     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2228     {\r
2229         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)\r
2230         {\r
2231             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)\r
2232             {\r
2233                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2234                 return -EINVAL;\r
2235             }\r
2236             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2237             return 0;\r
2238         }\r
2239     }\r
2240         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2241     return -EINVAL;\r
2242 }\r
2243 #endif\r
2244 #if CONFIG_SENSOR_Exposure\r
2245 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2246 {\r
2247     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2248 \r
2249     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2250     {\r
2251         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)\r
2252         {\r
2253             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)\r
2254             {\r
2255                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2256                 return -EINVAL;\r
2257             }\r
2258             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2259             return 0;\r
2260         }\r
2261     }\r
2262         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2263     return -EINVAL;\r
2264 }\r
2265 #endif\r
2266 #if CONFIG_SENSOR_Saturation\r
2267 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2268 {\r
2269     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2270 \r
2271     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2272     {\r
2273         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)\r
2274         {\r
2275             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)\r
2276             {\r
2277                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2278                 return -EINVAL;\r
2279             }\r
2280             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2281             return 0;\r
2282         }\r
2283     }\r
2284     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2285     return -EINVAL;\r
2286 }\r
2287 #endif\r
2288 #if CONFIG_SENSOR_Contrast\r
2289 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2290 {\r
2291     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2292 \r
2293     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2294     {\r
2295         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)\r
2296         {\r
2297             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)\r
2298             {\r
2299                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2300                 return -EINVAL;\r
2301             }\r
2302             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2303             return 0;\r
2304         }\r
2305     }\r
2306     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2307     return -EINVAL;\r
2308 }\r
2309 #endif\r
2310 #if CONFIG_SENSOR_Mirror\r
2311 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2312 {\r
2313     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2314 \r
2315     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2316     {\r
2317         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)\r
2318         {\r
2319             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)\r
2320             {\r
2321                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2322                 return -EINVAL;\r
2323             }\r
2324             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2325             return 0;\r
2326         }\r
2327     }\r
2328     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2329     return -EINVAL;\r
2330 }\r
2331 #endif\r
2332 #if CONFIG_SENSOR_Flip\r
2333 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2334 {\r
2335     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2336 \r
2337     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2338     {\r
2339         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)\r
2340         {\r
2341             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)\r
2342             {\r
2343                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2344                 return -EINVAL;\r
2345             }\r
2346             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2347             return 0;\r
2348         }\r
2349     }\r
2350     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2351     return -EINVAL;\r
2352 }\r
2353 #endif\r
2354 #if CONFIG_SENSOR_Scene\r
2355 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2356 {\r
2357     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2358 \r
2359     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2360     {\r
2361         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)\r
2362         {\r
2363             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)\r
2364             {\r
2365                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2366                 return -EINVAL;\r
2367             }\r
2368             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2369             return 0;\r
2370         }\r
2371     }\r
2372     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2373     return -EINVAL;\r
2374 }\r
2375 #endif\r
2376 #if CONFIG_SENSOR_WhiteBalance\r
2377 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2378 {\r
2379     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2380 \r
2381     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))\r
2382     {\r
2383         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)\r
2384         {\r
2385             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)\r
2386             {\r
2387                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2388                 return -EINVAL;\r
2389             }\r
2390             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2391             return 0;\r
2392         }\r
2393     }\r
2394         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2395     return -EINVAL;\r
2396 }\r
2397 #endif\r
2398 #if CONFIG_SENSOR_DigitalZoom\r
2399 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)\r
2400 {\r
2401     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2402     struct sensor *sensor = to_sensor(client);\r
2403         const struct v4l2_queryctrl *qctrl_info;\r
2404     int digitalzoom_cur, digitalzoom_total;\r
2405 \r
2406         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);\r
2407         if (qctrl_info)\r
2408                 return -EINVAL;\r
2409 \r
2410     digitalzoom_cur = sensor->info_priv.digitalzoom;\r
2411     digitalzoom_total = qctrl_info->maximum;\r
2412 \r
2413     if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))\r
2414     {\r
2415         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);\r
2416         return -EINVAL;\r
2417     }\r
2418 \r
2419     if  ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))\r
2420     {\r
2421         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);\r
2422         return -EINVAL;\r
2423     }\r
2424 \r
2425     if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))\r
2426     {\r
2427         value = digitalzoom_total - digitalzoom_cur;\r
2428     }\r
2429 \r
2430     if ((value < 0) && ((digitalzoom_cur + value) < 0))\r
2431     {\r
2432         value = 0 - digitalzoom_cur;\r
2433     }\r
2434 \r
2435     digitalzoom_cur += value;\r
2436 \r
2437     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)\r
2438     {\r
2439         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)\r
2440         {\r
2441             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);\r
2442             return -EINVAL;\r
2443         }\r
2444         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2445         return 0;\r
2446     }\r
2447 \r
2448     return -EINVAL;\r
2449 }\r
2450 #endif\r
2451 #if CONFIG_SENSOR_Flash\r
2452 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)\r
2453 {    \r
2454     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {\r
2455         if (value == 3) {       /* ddl@rock-chips.com: torch */\r
2456             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */\r
2457         } else {\r
2458             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);\r
2459         }\r
2460         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);\r
2461         return 0;\r
2462     }\r
2463     \r
2464         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);\r
2465     return -EINVAL;\r
2466 }\r
2467 #endif\r
2468 \r
2469 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)\r
2470 {\r
2471     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2472     struct sensor *sensor = to_sensor(client);\r
2473     const struct v4l2_queryctrl *qctrl;\r
2474 \r
2475     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);\r
2476 \r
2477     if (!qctrl)\r
2478     {\r
2479         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);\r
2480         return -EINVAL;\r
2481     }\r
2482 \r
2483     switch (ctrl->id)\r
2484     {\r
2485         case V4L2_CID_BRIGHTNESS:\r
2486             {\r
2487                 ctrl->value = sensor->info_priv.brightness;\r
2488                 break;\r
2489             }\r
2490         case V4L2_CID_SATURATION:\r
2491             {\r
2492                 ctrl->value = sensor->info_priv.saturation;\r
2493                 break;\r
2494             }\r
2495         case V4L2_CID_CONTRAST:\r
2496             {\r
2497                 ctrl->value = sensor->info_priv.contrast;\r
2498                 break;\r
2499             }\r
2500         case V4L2_CID_DO_WHITE_BALANCE:\r
2501             {\r
2502                 ctrl->value = sensor->info_priv.whiteBalance;\r
2503                 break;\r
2504             }\r
2505         case V4L2_CID_EXPOSURE:\r
2506             {\r
2507                 ctrl->value = sensor->info_priv.exposure;\r
2508                 break;\r
2509             }\r
2510         case V4L2_CID_HFLIP:\r
2511             {\r
2512                 ctrl->value = sensor->info_priv.mirror;\r
2513                 break;\r
2514             }\r
2515         case V4L2_CID_VFLIP:\r
2516             {\r
2517                 ctrl->value = sensor->info_priv.flip;\r
2518                 break;\r
2519             }\r
2520         default :\r
2521                 break;\r
2522     }\r
2523     return 0;\r
2524 }\r
2525 \r
2526 \r
2527 \r
2528 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)\r
2529 {\r
2530     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2531     struct sensor *sensor = to_sensor(client);\r
2532     struct soc_camera_device *icd = client->dev.platform_data;\r
2533     const struct v4l2_queryctrl *qctrl;\r
2534 \r
2535 \r
2536     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);\r
2537 \r
2538     if (!qctrl)\r
2539     {\r
2540         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);\r
2541         return -EINVAL;\r
2542     }\r
2543 \r
2544     switch (ctrl->id)\r
2545     {\r
2546 #if CONFIG_SENSOR_Brightness\r
2547         case V4L2_CID_BRIGHTNESS:\r
2548             {\r
2549                 if (ctrl->value != sensor->info_priv.brightness)\r
2550                 {\r
2551                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)\r
2552                     {\r
2553                         return -EINVAL;\r
2554                     }\r
2555                     sensor->info_priv.brightness = ctrl->value;\r
2556                 }\r
2557                 break;\r
2558             }\r
2559 #endif\r
2560 #if CONFIG_SENSOR_Exposure\r
2561         case V4L2_CID_EXPOSURE:\r
2562             {\r
2563                 if (ctrl->value != sensor->info_priv.exposure)\r
2564                 {\r
2565                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)\r
2566                     {\r
2567                         return -EINVAL;\r
2568                     }\r
2569                     sensor->info_priv.exposure = ctrl->value;\r
2570                 }\r
2571                 break;\r
2572             }\r
2573 #endif\r
2574 #if CONFIG_SENSOR_Saturation\r
2575         case V4L2_CID_SATURATION:\r
2576             {\r
2577                 if (ctrl->value != sensor->info_priv.saturation)\r
2578                 {\r
2579                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)\r
2580                     {\r
2581                         return -EINVAL;\r
2582                     }\r
2583                     sensor->info_priv.saturation = ctrl->value;\r
2584                 }\r
2585                 break;\r
2586             }\r
2587 #endif\r
2588 #if CONFIG_SENSOR_Contrast\r
2589         case V4L2_CID_CONTRAST:\r
2590             {\r
2591                 if (ctrl->value != sensor->info_priv.contrast)\r
2592                 {\r
2593                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)\r
2594                     {\r
2595                         return -EINVAL;\r
2596                     }\r
2597                     sensor->info_priv.contrast = ctrl->value;\r
2598                 }\r
2599                 break;\r
2600             }\r
2601 #endif\r
2602 #if CONFIG_SENSOR_WhiteBalance\r
2603         case V4L2_CID_DO_WHITE_BALANCE:\r
2604             {\r
2605                 if (ctrl->value != sensor->info_priv.whiteBalance)\r
2606                 {\r
2607                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)\r
2608                     {\r
2609                         return -EINVAL;\r
2610                     }\r
2611                     sensor->info_priv.whiteBalance = ctrl->value;\r
2612                 }\r
2613                 break;\r
2614             }\r
2615 #endif\r
2616 #if CONFIG_SENSOR_Mirror\r
2617         case V4L2_CID_HFLIP:\r
2618             {\r
2619                 if (ctrl->value != sensor->info_priv.mirror)\r
2620                 {\r
2621                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)\r
2622                         return -EINVAL;\r
2623                     sensor->info_priv.mirror = ctrl->value;\r
2624                 }\r
2625                 break;\r
2626             }\r
2627 #endif\r
2628 #if CONFIG_SENSOR_Flip\r
2629         case V4L2_CID_VFLIP:\r
2630             {\r
2631                 if (ctrl->value != sensor->info_priv.flip)\r
2632                 {\r
2633                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)\r
2634                         return -EINVAL;\r
2635                     sensor->info_priv.flip = ctrl->value;\r
2636                 }\r
2637                 break;\r
2638             }\r
2639 #endif\r
2640         default:\r
2641             break;\r
2642     }\r
2643 \r
2644     return 0;\r
2645 }\r
2646 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)\r
2647 {\r
2648     const struct v4l2_queryctrl *qctrl;\r
2649     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2650     struct sensor *sensor = to_sensor(client);\r
2651 \r
2652     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);\r
2653 \r
2654     if (!qctrl)\r
2655     {\r
2656         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);\r
2657         return -EINVAL;\r
2658     }\r
2659 \r
2660     switch (ext_ctrl->id)\r
2661     {\r
2662         case V4L2_CID_SCENE:\r
2663             {\r
2664                 ext_ctrl->value = sensor->info_priv.scene;\r
2665                 break;\r
2666             }\r
2667         case V4L2_CID_EFFECT:\r
2668             {\r
2669                 ext_ctrl->value = sensor->info_priv.effect;\r
2670                 break;\r
2671             }\r
2672         case V4L2_CID_ZOOM_ABSOLUTE:\r
2673             {\r
2674                 ext_ctrl->value = sensor->info_priv.digitalzoom;\r
2675                 break;\r
2676             }\r
2677         case V4L2_CID_ZOOM_RELATIVE:\r
2678             {\r
2679                 return -EINVAL;\r
2680             }\r
2681         case V4L2_CID_FOCUS_ABSOLUTE:\r
2682             {\r
2683                 ext_ctrl->value = sensor->info_priv.focus;\r
2684                 break;\r
2685             }\r
2686         case V4L2_CID_FOCUS_RELATIVE:\r
2687             {\r
2688                 return -EINVAL;\r
2689             }\r
2690         case V4L2_CID_FLASH:\r
2691             {\r
2692                 ext_ctrl->value = sensor->info_priv.flash;\r
2693                 break;\r
2694             }\r
2695         default :\r
2696             break;\r
2697     }\r
2698     return 0;\r
2699 }\r
2700 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)\r
2701 {\r
2702     const struct v4l2_queryctrl *qctrl;\r
2703     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
2704     struct sensor *sensor = to_sensor(client);\r
2705     int val_offset;\r
2706 \r
2707     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);\r
2708 \r
2709     if (!qctrl)\r
2710     {\r
2711         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);\r
2712         return -EINVAL;\r
2713     }\r
2714 \r
2715         val_offset = 0;\r
2716     switch (ext_ctrl->id)\r
2717     {\r
2718 #if CONFIG_SENSOR_Scene\r
2719         case V4L2_CID_SCENE:\r
2720             {\r
2721                 if (ext_ctrl->value != sensor->info_priv.scene)\r
2722                 {\r
2723                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)\r
2724                         return -EINVAL;\r
2725                     sensor->info_priv.scene = ext_ctrl->value;\r
2726                 }\r
2727                 break;\r
2728             }\r
2729 #endif\r
2730 #if CONFIG_SENSOR_Effect\r
2731         case V4L2_CID_EFFECT:\r
2732             {\r
2733                 if (ext_ctrl->value != sensor->info_priv.effect)\r
2734                 {\r
2735                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)\r
2736                         return -EINVAL;\r
2737                     sensor->info_priv.effect= ext_ctrl->value;\r
2738                 }\r
2739                 break;\r
2740             }\r
2741 #endif\r
2742 #if CONFIG_SENSOR_DigitalZoom\r
2743         case V4L2_CID_ZOOM_ABSOLUTE:\r
2744             {\r
2745                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))\r
2746                     return -EINVAL;\r
2747 \r
2748                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)\r
2749                 {\r
2750                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;\r
2751 \r
2752                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)\r
2753                         return -EINVAL;\r
2754                     sensor->info_priv.digitalzoom += val_offset;\r
2755 \r
2756                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);\r
2757                 }\r
2758 \r
2759                 break;\r
2760             }\r
2761         case V4L2_CID_ZOOM_RELATIVE:\r
2762             {\r
2763                 if (ext_ctrl->value)\r
2764                 {\r
2765                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)\r
2766                         return -EINVAL;\r
2767                     sensor->info_priv.digitalzoom += ext_ctrl->value;\r
2768 \r
2769                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);\r
2770                 }\r
2771                 break;\r
2772             }\r
2773 #endif\r
2774 #if CONFIG_SENSOR_Focus\r
2775         case V4L2_CID_FOCUS_ABSOLUTE:\r
2776             {\r
2777                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))\r
2778                     return -EINVAL;\r
2779 \r
2780                 if (ext_ctrl->value != sensor->info_priv.focus)\r
2781                 {\r
2782                     val_offset = ext_ctrl->value -sensor->info_priv.focus;\r
2783 \r
2784                     sensor->info_priv.focus += val_offset;\r
2785                 }\r
2786 \r
2787                 break;\r
2788             }\r
2789         case V4L2_CID_FOCUS_RELATIVE:\r
2790             {\r
2791                 if (ext_ctrl->value)\r
2792                 {\r
2793                     sensor->info_priv.focus += ext_ctrl->value;\r
2794 \r
2795                     SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);\r
2796                 }\r
2797                 break;\r
2798             }\r
2799 #endif\r
2800 #if CONFIG_SENSOR_Flash\r
2801         case V4L2_CID_FLASH:\r
2802             {\r
2803                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)\r
2804                     return -EINVAL;\r
2805                 sensor->info_priv.flash = ext_ctrl->value;\r
2806 \r
2807                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);\r
2808                 break;\r
2809             }\r
2810 #endif\r
2811         default:\r
2812             break;\r
2813     }\r
2814 \r
2815     return 0;\r
2816 }\r
2817 \r
2818 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)\r
2819 {\r
2820     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2821     struct soc_camera_device *icd = client->dev.platform_data;\r
2822     int i, error_cnt=0, error_idx=-1;\r
2823 \r
2824 \r
2825     for (i=0; i<ext_ctrl->count; i++) {\r
2826         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {\r
2827             error_cnt++;\r
2828             error_idx = i;\r
2829         }\r
2830     }\r
2831 \r
2832     if (error_cnt > 1)\r
2833         error_idx = ext_ctrl->count;\r
2834 \r
2835     if (error_idx != -1) {\r
2836         ext_ctrl->error_idx = error_idx;\r
2837         return -EINVAL;\r
2838     } else {\r
2839         return 0;\r
2840     }\r
2841 }\r
2842 \r
2843 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)\r
2844 {\r
2845     struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2846     struct soc_camera_device *icd = client->dev.platform_data;\r
2847     int i, error_cnt=0, error_idx=-1;\r
2848 \r
2849 \r
2850     for (i=0; i<ext_ctrl->count; i++) {\r
2851         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {\r
2852             error_cnt++;\r
2853             error_idx = i;\r
2854         }\r
2855     }\r
2856 \r
2857     if (error_cnt > 1)\r
2858         error_idx = ext_ctrl->count;\r
2859 \r
2860     if (error_idx != -1) {\r
2861         ext_ctrl->error_idx = error_idx;\r
2862         return -EINVAL;\r
2863     } else {\r
2864         return 0;\r
2865     }\r
2866 }\r
2867 \r
2868 /* Interface active, can use i2c. If it fails, it can indeed mean, that\r
2869  * this wasn't our capture interface, so, we wait for the right one */\r
2870 static int sensor_video_probe(struct soc_camera_device *icd,\r
2871                                struct i2c_client *client)\r
2872 {\r
2873     char value;\r
2874     int ret,pid = 0;\r
2875     struct sensor *sensor = to_sensor(client);\r
2876 \r
2877     /* We must have a parent by now. And it cannot be a wrong one.\r
2878      * So this entire test is completely redundant. */\r
2879     if (!icd->dev.parent ||\r
2880             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)\r
2881                 return -ENODEV;\r
2882 \r
2883         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {\r
2884                 ret = -ENODEV;\r
2885                 goto sensor_video_probe_err;\r
2886         }\r
2887 \r
2888     /* soft reset */\r
2889     ret = sensor_write(client, 0xff, 0x1);\r
2890     if (ret != 0) {\r
2891         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());\r
2892         ret = -ENODEV;\r
2893                 goto sensor_video_probe_err;\r
2894     }\r
2895     mdelay(5);          //delay 5 microseconds\r
2896 \r
2897     /* check if it is an sensor sensor */\r
2898     ret = sensor_read(client, 0x0a, &value);\r
2899     if (ret != 0) {\r
2900         SENSOR_TR("read chip id high byte failed\n");\r
2901         ret = -ENODEV;\r
2902         goto sensor_video_probe_err;\r
2903     }\r
2904     pid = value << 8;\r
2905 \r
2906     ret = sensor_read(client, 0x0b, &value);\r
2907     if (ret != 0) {\r
2908         SENSOR_TR("read chip id low byte failed\n");\r
2909         ret = -ENODEV;\r
2910         goto sensor_video_probe_err;\r
2911     }\r
2912 \r
2913     pid |= (value & 0xff);\r
2914     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
2915 \r
2916     if ((pid == SENSOR_ID)||(pid == SENSOR_ID1)) {\r
2917         sensor->model = SENSOR_V4L2_IDENT;\r
2918     } else {\r
2919         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);\r
2920         ret = -ENODEV;\r
2921         goto sensor_video_probe_err;\r
2922     }\r
2923 \r
2924     return 0;\r
2925 \r
2926 sensor_video_probe_err:\r
2927 \r
2928     return ret;\r
2929 }\r
2930 \r
2931 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)\r
2932 {\r
2933         struct i2c_client *client = v4l2_get_subdevdata(sd);\r
2934     struct soc_camera_device *icd = client->dev.platform_data;  \r
2935     struct sensor *sensor = to_sensor(client);\r
2936     int ret = 0,i;\r
2937     \r
2938         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);\r
2939         switch (cmd)\r
2940         {\r
2941                 case RK29_CAM_SUBDEV_DEACTIVATE:\r
2942                 {\r
2943                         sensor_deactivate(client);\r
2944                         break;\r
2945                 }\r
2946 \r
2947                 case RK29_CAM_SUBDEV_IOREQUEST:\r
2948                 {\r
2949                         sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;           \r
2950             if (sensor->sensor_io_request != NULL) { \r
2951                 sensor->sensor_gpio_res = NULL;\r
2952                 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {\r
2953                     if (sensor->sensor_io_request->gpio_res[i].dev_name && \r
2954                         (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {\r
2955                         sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];\r
2956                     }\r
2957                 }\r
2958                 if (sensor->sensor_gpio_res == NULL) {\r
2959                     SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);\r
2960                     ret = -EINVAL;\r
2961                     goto sensor_ioctl_end;\r
2962                 }\r
2963             } else {\r
2964                 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);\r
2965                 ret = -EINVAL;\r
2966                 goto sensor_ioctl_end;\r
2967             }\r
2968             /* 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
2969                for this project */\r
2970             #if CONFIG_SENSOR_Flash     \r
2971                 if (sensor->sensor_gpio_res) { \r
2972                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {\r
2973                     for (i = 0; i < icd->ops->num_controls; i++) {\r
2974                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {\r
2975                                         //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));  \r
2976                               sensor_controls[i].id=0xffff;                             \r
2977                                 }\r
2978                     }\r
2979                     sensor->info_priv.flash = 0xff;\r
2980                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());\r
2981                 }else{ //two cameras are the same,need to deal diffrently ,zyc\r
2982                     for (i = 0; i < icd->ops->num_controls; i++) {\r
2983                            if(0xffff == icd->ops->controls[i].id){\r
2984                               sensor_controls[i].id=V4L2_CID_FLASH;\r
2985                            }               \r
2986                     }\r
2987                 }\r
2988                 }\r
2989             #endif\r
2990                         break;\r
2991                 }\r
2992                 default:\r
2993                 {\r
2994                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);\r
2995                         break;\r
2996                 }\r
2997         }\r
2998 \r
2999 sensor_ioctl_end:\r
3000         return ret;\r
3001 \r
3002 }\r
3003 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,\r
3004                             enum v4l2_mbus_pixelcode *code)\r
3005 {\r
3006         if (index >= ARRAY_SIZE(sensor_colour_fmts))\r
3007                 return -EINVAL;\r
3008 \r
3009         *code = sensor_colour_fmts[index].code;\r
3010         return 0;\r
3011 }\r
3012 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {\r
3013         .init           = sensor_init,\r
3014         .g_ctrl         = sensor_g_control,\r
3015         .s_ctrl         = sensor_s_control,\r
3016         .g_ext_ctrls          = sensor_g_ext_controls,\r
3017         .s_ext_ctrls          = sensor_s_ext_controls,\r
3018         .g_chip_ident   = sensor_g_chip_ident,\r
3019         .ioctl = sensor_ioctl,\r
3020 };\r
3021 \r
3022 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {\r
3023         .s_mbus_fmt     = sensor_s_fmt,\r
3024         .g_mbus_fmt     = sensor_g_fmt,\r
3025         .try_mbus_fmt   = sensor_try_fmt,\r
3026         .enum_mbus_fmt  = sensor_enum_fmt,\r
3027 };\r
3028 \r
3029 static struct v4l2_subdev_ops sensor_subdev_ops = {\r
3030         .core   = &sensor_subdev_core_ops,\r
3031         .video = &sensor_subdev_video_ops,\r
3032 };\r
3033 \r
3034 static int sensor_probe(struct i2c_client *client,\r
3035                          const struct i2c_device_id *did)\r
3036 {\r
3037     struct sensor *sensor;\r
3038     struct soc_camera_device *icd = client->dev.platform_data;\r
3039     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);\r
3040     struct soc_camera_link *icl;\r
3041     int ret;\r
3042 \r
3043     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);\r
3044     if (!icd) {\r
3045         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());\r
3046         return -EINVAL;\r
3047     }\r
3048 \r
3049     icl = to_soc_camera_link(icd);\r
3050     if (!icl) {\r
3051         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());\r
3052         return -EINVAL;\r
3053     }\r
3054 \r
3055     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {\r
3056         dev_warn(&adapter->dev,\r
3057                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");\r
3058         return -EIO;\r
3059     }\r
3060 \r
3061     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);\r
3062     if (!sensor)\r
3063         return -ENOMEM;\r
3064 \r
3065     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);\r
3066 \r
3067     /* Second stage probe - when a capture adapter is there */\r
3068     icd->ops            = &sensor_ops;\r
3069     sensor->info_priv.fmt = sensor_colour_fmts[0];\r
3070         #if CONFIG_SENSOR_I2C_NOSCHED\r
3071         atomic_set(&sensor->tasklock_cnt,0);\r
3072         #endif\r
3073 \r
3074     ret = sensor_video_probe(icd, client);\r
3075     if (ret < 0) {\r
3076         icd->ops = NULL;\r
3077         i2c_set_clientdata(client, NULL);\r
3078         kfree(sensor);\r
3079                 sensor = NULL;\r
3080     }\r
3081         hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);\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