camera: add v4l2_subdev_core_ops ioctl function in sensor driver, and all sensor...
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / ov2655.c
1 /*
2 o* Driver for MT9M001 CMOS Image Sensor from Micron
3  *
4  * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk29_camera.h>
23
24 #define _CONS(a,b) a##b
25 #define CONS(a,b) _CONS(a,b)
26
27 #define __STR(x) #x
28 #define _STR(x) __STR(x)
29 #define STR(x) _STR(x)
30
31 /* Sensor Driver Configuration */
32 #define SENSOR_NAME ov2655
33 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2655
34 #define SENSOR_ID 0x2656
35 #define SENSOR_MIN_WIDTH    176
36 #define SENSOR_MIN_HEIGHT   144
37 #define SENSOR_MAX_WIDTH    1600
38 #define SENSOR_MAX_HEIGHT   1200
39 #define SENSOR_INIT_WIDTH       640                     /* Sensor pixel size for sensor_init_data array */
40 #define SENSOR_INIT_HEIGHT  480
41 #define SENSOR_INIT_WINSEQADR sensor_vga
42 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_UYVY
43
44 #define CONFIG_SENSOR_WhiteBalance      1
45 #define CONFIG_SENSOR_Brightness        0
46 #define CONFIG_SENSOR_Contrast      0
47 #define CONFIG_SENSOR_Saturation    0
48 #define CONFIG_SENSOR_Effect        1
49 #define CONFIG_SENSOR_Scene         1
50 #define CONFIG_SENSOR_DigitalZoom   0
51 #define CONFIG_SENSOR_Focus         0
52 #define CONFIG_SENSOR_Exposure      0
53 #define CONFIG_SENSOR_Flash         0
54 #define CONFIG_SENSOR_Mirror        0
55 #define CONFIG_SENSOR_Flip          0
56
57 #define CONFIG_SENSOR_I2C_SPEED     400000       /* Hz */
58
59 #define CONFIG_SENSOR_TR      1
60 #define CONFIG_SENSOR_DEBUG       1
61
62 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
63 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
64
65 #define MIN(x,y)   ((x<y) ? x: y)
66 #define MAX(x,y)    ((x>y) ? x: y)
67
68 #if (CONFIG_SENSOR_TR)
69         #define SENSOR_TR(format, ...)      printk(format, ## __VA_ARGS__)
70         #if (CONFIG_SENSOR_DEBUG)
71         #define SENSOR_DG(format, ...)      printk(format, ## __VA_ARGS__)
72         #else
73         #define SENSOR_DG(format, ...)
74         #endif
75 #else
76         #define SENSOR_TR(format, ...)
77 #endif
78
79 #define SENSOR_BUS_PARAM  (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
80                           SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
81                           SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ)
82
83 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
84 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
85 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
86 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
87 #define COLOR_TEMPERATURE_OFFICE_DN     3500
88 #define COLOR_TEMPERATURE_OFFICE_UP     5000
89 #define COLOR_TEMPERATURE_HOME_DN       2500
90 #define COLOR_TEMPERATURE_HOME_UP       3500
91
92 struct reginfo
93 {
94     u16 reg;
95     u8 val;
96 };
97
98 /* init 352X288 SVGA */
99 static struct reginfo sensor_init_data[] =
100 {
101     {0x308c, 0x80},
102     {0x308d, 0x0e},
103     {0x360b, 0x00},
104     {0x30b0, 0xff},
105     {0x30b1, 0xff},
106     {0x30b2, 0x24},
107
108     {0x300e, 0x34},
109     {0x300f, 0xa6},
110     {0x3010, 0x81},
111     {0x3082, 0x01},
112     {0x30f4, 0x01},
113     {0x3090, 0x3b},//0x33},
114     {0x3091, 0xc0},
115     {0x30ac, 0x42},
116
117     {0x30d1, 0x08},
118     {0x30a8, 0x56},
119     {0x3015, 0x03},
120     {0x3093, 0x00},
121     {0x307e, 0xe5},
122     {0x3079, 0x00},
123     {0x30aa, 0x42},
124     {0x3017, 0x40},
125     {0x30f3, 0x82},
126     {0x306a, 0x0c},
127     {0x306d, 0x00},
128     {0x336a, 0x3c},
129     {0x3076, 0x6a},
130     {0x30d9, 0x8c},
131     {0x3016, 0x82},
132     {0x3601, 0x30},
133     {0x304e, 0x88},
134     {0x30f1, 0x82},
135     {0x306f, 0x14},
136
137     {0x3012, 0x10},
138     {0x3011, 0x01},
139     {0x302a, 0x02},
140     {0x302b, 0xE6},
141     {0x3028, 0x07},
142     {0x3029, 0x93},
143
144     {0x3391, 0x06},
145     {0x3394, 0x38},
146     {0x3395, 0x38},
147
148     {0x3015, 0x02},
149     {0x302d, 0x00},
150     {0x302e, 0x00},
151
152     {0x3013, 0xf7},
153     {0x3018, 0x80},
154     {0x3019, 0x70},
155     {0x301a, 0xd4},
156
157     {0x30af, 0x00},
158     {0x3048, 0x1f},
159     {0x3049, 0x4e},
160     {0x304a, 0x20},
161     {0x304f, 0x20},
162     {0x304b, 0x02},
163     {0x304c, 0x00},
164     {0x304d, 0x02},
165     {0x304f, 0x20},
166     {0x30a3, 0x10},
167     {0x3013, 0xf7},
168     {0x3014, 0x84},
169     {0x3071, 0x00},
170     {0x3070, 0x5d},
171     {0x3073, 0x00},
172     {0x3072, 0x5d},
173     {0x301c, 0x07},
174     {0x301d, 0x07},
175     {0x304d, 0x42},
176     {0x304a, 0x40},
177     {0x304f, 0x40},
178     {0x3095, 0x07},
179     {0x3096, 0x16},
180     {0x3097, 0x1d},
181
182     {0x3020, 0x01},
183     {0x3021, 0x18},
184     {0x3022, 0x00},
185     {0x3023, 0x06},
186     {0x3024, 0x06},
187     {0x3025, 0x58},
188     {0x3026, 0x02},
189     {0x3027, 0x61},
190     {0x3088, 0x02},//{0x3088, 0x01},
191     {0x3089, 0x88},//{0x3089, 0x68},
192     {0x308A, 0x01},//{0x308a, 0x01},
193     {0x308B, 0xe0},//{0x308b, 0x20},
194
195     {0x3316, 0x64},
196     {0x3317, 0x25},
197     {0x3318, 0x80},
198     {0x3319, 0x08},
199
200         {0x331A, 0x28},//{0x331a, 0x16},
201     {0x331B, 0x1e},//{0x331b, 0x12},
202     {0x331c, 0x08},
203     {0x331d, 0x38},
204     {0x3100, 0x00},
205
206     {0x3320, 0xfa},
207     {0x3321, 0x11},
208     {0x3322, 0x92},
209     {0x3323, 0x01},
210     {0x3324, 0x97},
211     {0x3325, 0x02},
212     {0x3326, 0xff},
213     {0x3327, 0x0c},
214     {0x3328, 0x10},
215     {0x3329, 0x10},
216     {0x332a, 0x58},
217     {0x332b, 0x56},
218     {0x332c, 0xbe},
219     {0x332d, 0xe1},
220     {0x332e, 0x3a},
221     {0x332f, 0x36},
222     {0x3330, 0x4d},
223     {0x3331, 0x44},
224     {0x3332, 0xf8},
225     {0x3333, 0x0a},
226     {0x3334, 0xf0},
227     {0x3335, 0xf0},
228     {0x3336, 0xf0},
229     {0x3337, 0x40},
230     {0x3338, 0x40},
231     {0x3339, 0x40},
232     {0x333a, 0x00},
233     {0x333b, 0x00},
234
235     {0x3380, 0x28},
236     {0x3381, 0x48},
237     {0x3382, 0x10},
238     {0x3383, 0x22},
239     {0x3384, 0xc0},
240     {0x3385, 0xe2},
241     {0x3386, 0xe2},
242     {0x3387, 0xf2},
243     {0x3388, 0x10},
244     {0x3389, 0x98},
245     {0x338a, 0x00},
246
247     {0x3340, 0x04},
248     {0x3341, 0x07},
249     {0x3342, 0x19},
250     {0x3343, 0x34},
251     {0x3344, 0x4a},
252     {0x3345, 0x5a},
253     {0x3346, 0x67},
254     {0x3347, 0x71},
255     {0x3348, 0x7c},
256     {0x3349, 0x8c},
257     {0x334a, 0x9b},
258     {0x334b, 0xa9},
259     {0x334c, 0xc0},
260     {0x334d, 0xd5},
261     {0x334e, 0xe8},
262     {0x334f, 0x20},
263
264     {0x3350, 0x37},//0x33},
265     {0x3351, 0x27},//0x28},
266     {0x3352, 0x00},
267     {0x3353, 0x16},
268     {0x3354, 0x00},
269     {0x3355, 0x85},
270     {0x3356, 0x35},
271     {0x3357, 0x28},
272     {0x3358, 0x00},
273     {0x3359, 0x13},
274     {0x335a, 0x00},
275     {0x335b, 0x85},
276     {0x335c, 0x37},//0x34},
277     {0x335d, 0x28},
278     {0x335e, 0x00},
279     {0x335f, 0x13},
280     {0x3360, 0x00},
281     {0x3361, 0x85},
282     {0x3363, 0x70},
283     {0x3364, 0x7f},
284     {0x3365, 0x00},
285     {0x3366, 0x00},
286     {0x3362, 0x90},
287
288     {0x3301, 0xff},
289     {0x338B, 0x11},
290     {0x338c, 0x10},
291     {0x338d, 0x40},
292
293     {0x3370, 0xd0},
294     {0x3371, 0x00},
295     {0x3372, 0x00},
296     {0x3373, 0x30},
297     {0x3374, 0x10},
298     {0x3375, 0x10},
299     {0x3376, 0x04},
300     {0x3377, 0x00},
301     {0x3378, 0x04},
302     {0x3379, 0x80},
303
304     {0x3069, 0x84},
305     {0x307c, 0x13},//0x10},
306     {0x3087, 0x02},
307
308     {0x3300, 0xfc},
309     {0x3302, 0x11},
310     {0x3400, 0x02},
311     {0x3606, 0x20},
312     {0x3601, 0x30},
313     {0x30f3, 0x83},
314     {0x304e, 0x88},
315
316     {0x30aa, 0x72},
317     {0x30a3, 0x80},
318     {0x30a1, 0x41},
319
320     {0x3086, 0x0f},
321     {0x3086, 0x00},
322
323     {0x0, 0x0}   //end flag
324
325 };
326
327 /* 1600X1200 UXGA */
328 static struct reginfo sensor_uxga[] =
329 {
330
331     {0x300E, 0x34},
332     {0x3011, 0x01},
333     {0x3012, 0x00},
334     {0x302a, 0x05},
335     {0x302b, 0xCB},
336     {0x306f, 0x54},
337     {0x3362, 0x80},
338
339     {0x3070, 0x5d},
340     {0x3072, 0x5d},
341     {0x301c, 0x0f},
342     {0x301d, 0x0f},
343
344     {0x3020, 0x01},
345     {0x3021, 0x18},
346     {0x3022, 0x00},
347     {0x3023, 0x0A},
348     {0x3024, 0x06},
349     {0x3025, 0x58},
350     {0x3026, 0x04},
351     {0x3027, 0xbc},
352     {0x3088, 0x06},
353     {0x3089, 0x40},
354     {0x308A, 0x04},
355     {0x308B, 0xB0},
356     {0x3316, 0x64},
357     {0x3317, 0x4B},
358     {0x3318, 0x00},
359     {0x3319, 0x6C},
360     {0x331A, 0x64},
361     {0x331B, 0x4B},
362     {0x331C, 0x00},
363     {0x331D, 0x6C},
364     {0x3302, 0x01},
365
366     {0x0, 0x0},
367 };
368
369 /* 1280X1024 SXGA */
370 static struct reginfo sensor_sxga[] =
371 {
372     {0x300E, 0x34},
373     {0x3011, 0x01},
374     {0x3012, 0x00},
375     {0x302a, 0x05},
376     {0x302b, 0xCB},
377     {0x306f, 0x54},
378     {0x3362, 0x80},
379
380     {0x3070, 0x5d},
381     {0x3072, 0x5d},
382     {0x301c, 0x0f},
383     {0x301d, 0x0f},
384
385     {0x3020, 0x01},
386     {0x3021, 0x18},
387     {0x3022, 0x00},
388     {0x3023, 0x0A},
389     {0x3024, 0x06},
390     {0x3025, 0x58},
391     {0x3026, 0x04},
392     {0x3027, 0xbc},
393     {0x3088, 0x05},
394     {0x3089, 0x00},
395     {0x308A, 0x04},
396     {0x308B, 0x00},
397     {0x3316, 0x64},
398     {0x3317, 0x4B},
399     {0x3318, 0x00},
400     {0x3319, 0x6C},
401     {0x331A, 0x50},
402     {0x331B, 0x40},
403     {0x331C, 0x00},
404     {0x331D, 0x6C},
405     {0x3302, 0x11},
406
407     {0x0, 0x0},
408 };
409
410 /* 800X600 SVGA*/
411 static struct reginfo sensor_svga[] =
412 {
413     {0x300E, 0x34},
414     {0x3011, 0x01},
415     {0x3012, 0x10},
416     {0x302a, 0x02},
417     {0x302b, 0xE6},
418     {0x306f, 0x14},
419     {0x3362, 0x90},
420
421     {0x3070, 0x5d},
422     {0x3072, 0x5d},
423     {0x301c, 0x07},
424     {0x301d, 0x07},
425
426     {0x3020, 0x01},
427     {0x3021, 0x18},
428     {0x3022, 0x00},
429     {0x3023, 0x06},
430     {0x3024, 0x06},
431     {0x3025, 0x58},
432     {0x3026, 0x02},
433     {0x3027, 0x5E},
434     {0x3088, 0x03},
435     {0x3089, 0x20},
436     {0x308A, 0x02},
437     {0x308B, 0x58},
438     {0x3316, 0x64},
439     {0x3317, 0x25},
440     {0x3318, 0x80},
441     {0x3319, 0x08},
442     {0x331A, 0x64},
443     {0x331B, 0x4B},
444     {0x331C, 0x00},
445     {0x331D, 0x38},
446     {0x3302, 0x11},
447
448     {0x0, 0x0},
449 };
450
451 /* 640X480 VGA */
452 static struct reginfo sensor_vga[] =
453 {
454     {0x300E, 0x34},
455     {0x3011, 0x01},
456     {0x3012, 0x10},
457     {0x302a, 0x02},
458     {0x302b, 0xE6},
459     {0x306f, 0x14},
460     {0x3362, 0x90},
461
462     {0x3070, 0x5D},
463     {0x3072, 0x5D},
464     {0x301c, 0x07},
465     {0x301d, 0x07},
466
467     {0x3020, 0x01},
468     {0x3021, 0x18},
469     {0x3022, 0x00},
470     {0x3023, 0x06},
471     {0x3024, 0x06},
472     {0x3025, 0x58},
473     {0x3026, 0x02},
474     {0x3027, 0x61},
475     {0x3088, 0x02},
476     {0x3089, 0x88},
477     {0x308A, 0x01},
478     {0x308B, 0xe0},
479     {0x3316, 0x64},
480     {0x3317, 0x25},
481     {0x3318, 0x80},
482     {0x3319, 0x08},
483     {0x331A, 0x28},
484     {0x331B, 0x1e},
485     {0x331C, 0x08},
486     {0x331D, 0x38},
487     {0x3302, 0x11},
488
489     {0x0, 0x0},
490 };
491
492 /* 352X288 CIF */
493 static struct reginfo sensor_cif[] =
494 {
495     {0x300E, 0x34},
496     {0x3011, 0x01},
497     {0x3012, 0x10},
498     {0x302a, 0x02},
499     {0x302b, 0xE6},
500     {0x306f, 0x14},
501     {0x3362, 0x90},
502     {0x3070, 0x5d},
503     {0x3072, 0x5d},
504     {0x301c, 0x07},
505     {0x301d, 0x07},
506     {0x3020, 0x01},
507     {0x3021, 0x18},
508     {0x3022, 0x00},
509     {0x3023, 0x06},
510     { 0x3024, 0x06},
511     {0x3025, 0x58},
512     {0x3026, 0x02},
513     {0x3027, 0x61},
514     {0x3088, 0x01},
515     {0x3089, 0x68},
516     {0x308a, 0x01},
517     {0x308b, 0x20},
518     {0x3316, 0x64},
519     {0x3317, 0x25},
520     {0x3318, 0x80},
521     {0x3319, 0x08},
522     {0x331a, 0x16},
523     {0x331b, 0x12},
524     {0x331c, 0x08},
525     {0x331d, 0x38},
526     {0x3100, 0x00},
527     {0x3302, 0x11},
528
529     {0x0, 0x0},
530 };
531
532 /* 320*240 QVGA */
533 static  struct reginfo sensor_qvga[] =
534 {
535     {0x300E, 0x34},
536     {0x3011, 0x01},
537     {0x3012, 0x10},
538     {0x302a, 0x02},
539     {0x302b, 0xE6},
540     {0x306f, 0x14},
541     {0x3362, 0x90},
542
543     {0x3070, 0x5D},
544     {0x3072, 0x5D},
545     {0x301c, 0x07},
546     {0x301d, 0x07},
547
548     {0x3020, 0x01},
549     {0x3021, 0x18},
550     {0x3022, 0x00},
551     {0x3023, 0x06},
552     {0x3024, 0x06},
553     {0x3025, 0x58},
554     {0x3026, 0x02},
555     {0x3027, 0x61},
556     {0x3088, 0x01},
557     {0x3089, 0x40},
558     {0x308A, 0x00},
559     {0x308B, 0xf0},
560     {0x3316, 0x64},
561     {0x3317, 0x25},
562     {0x3318, 0x80},
563     {0x3319, 0x08},
564     {0x331A, 0x14},
565     {0x331B, 0x0f},
566     {0x331C, 0x00},
567     {0x331D, 0x38},
568     {0x3302, 0x11},
569
570     {0x0, 0x0},
571 };
572
573 /* 176X144 QCIF*/
574 static struct reginfo sensor_qcif[] =
575 {
576         {0x300E, 0x34},
577     {0x3011, 0x01},
578     {0x3012, 0x10},
579     {0x302a, 0x02},
580     {0x302b, 0xE6},
581     {0x306f, 0x14},
582     {0x3362, 0x90},
583     {0x3070, 0x5d},
584     {0x3072, 0x5d},
585     {0x301c, 0x07},
586     {0x301d, 0x07},
587     {0x3020, 0x01},
588     {0x3021, 0x18},
589     {0x3022, 0x00},
590     {0x3023, 0x06},
591     {0x3024, 0x06},
592     {0x3025, 0x58},
593     {0x3026, 0x02},
594     {0x3027, 0x61},
595     {0x3088, 0x00},
596     {0x3089, 0xb8},
597     {0x308a, 0x00},
598     {0x308b, 0x90},
599     {0x3316, 0x64},
600     {0x3317, 0x25},
601     {0x3318, 0x80},
602     {0x3319, 0x08},
603     {0x331a, 0x16},
604     {0x331b, 0x12},
605     {0x331c, 0x08},
606     {0x331d, 0x38},
607     {0x3100, 0x00},
608     {0x3302, 0x11},
609
610     {0x0, 0x0},
611 };
612 #if 0
613 /* 160X120 QQVGA*/
614 static struct reginfo ov2655_qqvga[] =
615 {
616
617     {0x300E, 0x34},
618     {0x3011, 0x01},
619     {0x3012, 0x10},
620     {0x302a, 0x02},
621     {0x302b, 0xE6},
622     {0x306f, 0x14},
623     {0x3362, 0x90},
624
625     {0x3070, 0x5d},
626     {0x3072, 0x5d},
627     {0x301c, 0x07},
628     {0x301d, 0x07},
629
630     {0x3020, 0x01},
631     {0x3021, 0x18},
632     {0x3022, 0x00},
633     {0x3023, 0x06},
634     {0x3024, 0x06},
635     {0x3025, 0x58},
636     {0x3026, 0x02},
637     {0x3027, 0x61},
638     {0x3088, 0x00},
639     {0x3089, 0xa0},
640     {0x308a, 0x00},
641     {0x308b, 0x78},
642     {0x3316, 0x64},
643     {0x3317, 0x25},
644     {0x3318, 0x80},
645     {0x3319, 0x08},
646     {0x331a, 0x0a},
647     {0x331b, 0x07},
648     {0x331c, 0x80},
649     {0x331d, 0x38},
650     {0x3100, 0x00},
651     {0x3302, 0x11},
652
653     {0x0, 0x0},
654 };
655
656
657
658 static  struct reginfo ov2655_Sharpness_auto[] =
659 {
660     {0x3306, 0x00},
661 };
662
663 static  struct reginfo ov2655_Sharpness1[] =
664 {
665     {0x3306, 0x08},
666     {0x3371, 0x00},
667 };
668
669 static  struct reginfo ov2655_Sharpness2[][3] =
670 {
671     //Sharpness 2
672     {0x3306, 0x08},
673     {0x3371, 0x01},
674 };
675
676 static  struct reginfo ov2655_Sharpness3[] =
677 {
678     //default
679     {0x3306, 0x08},
680     {0x332d, 0x02},
681 };
682 static  struct reginfo ov2655_Sharpness4[]=
683 {
684     //Sharpness 4
685     {0x3306, 0x08},
686     {0x332d, 0x03},
687 };
688
689 static  struct reginfo ov2655_Sharpness5[] =
690 {
691     //Sharpness 5
692     {0x3306, 0x08},
693     {0x332d, 0x04},
694 };
695 #endif
696
697 static  struct reginfo sensor_ClrFmt_YUYV[]=
698 {
699     {0x3400, 0x00},
700     {0x0000, 0x00}
701 };
702
703 static  struct reginfo sensor_ClrFmt_UYVY[]=
704 {
705     {0x3400, 0x02},
706     {0x0000, 0x00}
707 };
708
709 #if CONFIG_SENSOR_WhiteBalance
710 static  struct reginfo sensor_WhiteB_Auto[]=
711 {
712     {0x3306, 0x00},  //AWB auto, bit[1]:0,auto
713     {0x0000, 0x00}
714 };
715 /* Cloudy Colour Temperature : 6500K - 8000K  */
716 static  struct reginfo sensor_WhiteB_Cloudy[]=
717 {
718     {0x3306, 0x82},
719     {0x3337, 0x68},
720     {0x3338, 0x40},
721     {0x3339, 0x4e},
722     {0x0000, 0x00}
723 };
724 /* ClearDay Colour Temperature : 5000K - 6500K  */
725 static  struct reginfo sensor_WhiteB_ClearDay[]=
726 {
727     //Sunny
728     {0x3306, 0x02}, //AWB off
729     {0x3337, 0x5e},
730     {0x3338, 0x40},
731     {0x3339, 0x46},
732     {0x0000, 0x00}
733 };
734 /* Office Colour Temperature : 3500K - 5000K  */
735 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
736 {
737     //Office
738     {0x3306, 0x02},
739     {0x3337, 0x52},
740     {0x3338, 0x40},
741     {0x3339, 0x58},
742     {0x0000, 0x00}
743
744 };
745 /* Home Colour Temperature : 2500K - 3500K  */
746 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
747 {
748     //Home
749     {0x3306, 0x02},
750     {0x3337, 0x44},
751     {0x3338, 0x40},
752     {0x3339, 0x70},
753     {0x0000, 0x00}
754 };
755 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
756     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
757 };
758 #endif
759
760 #if CONFIG_SENSOR_Brightness
761 static  struct reginfo sensor_Brightness0[]=
762 {
763     // Brightness -2
764     {0x3301, 0xff},//bit[7]:1, enable SDE
765     {0x3391, 0x04},
766     {0x3390, 0x49},
767     {0x339a, 0x20},
768     {0x0000, 0x00}
769 };
770
771 static  struct reginfo sensor_Brightness1[]=
772 {
773     // Brightness -1
774     {0x3301, 0xff},//bit[7]:1, enable SDE
775     {0x3391, 0x04},
776     {0x3390, 0x49},
777     {0x339a, 0x10},
778     {0x0000, 0x00}
779 };
780
781 static  struct reginfo sensor_Brightness2[]=
782 {
783     //  Brightness 0
784     {0x3301, 0xff},//bit[7]:1, enable SDE
785     {0x3391, 0x00},
786     {0x3390, 0x41},
787     {0x339a, 0x00},
788     {0x0000, 0x00}
789 };
790
791 static  struct reginfo sensor_Brightness3[]=
792 {
793     // Brightness +1
794     {0x3301, 0xff},//bit[7]:1, enable SDE
795     {0x3391, 0x04},
796     {0x3390, 0x41},
797     {0x339a, 0x10},
798     {0x0000, 0x00}
799 };
800
801 static  struct reginfo sensor_Brightness4[]=
802 {
803     //  Brightness +2
804     {0x3301, 0xff},//bit[7]:1, enable SDE
805     {0x3391, 0x04},
806     {0x3390, 0x41},
807     {0x339a, 0x20},
808     {0x0000, 0x00}
809 };
810
811 static  struct reginfo sensor_Brightness5[]=
812 {
813     //  Brightness +3
814     {0x3301, 0xff},//bit[7]:1, enable SDE
815     {0x3391, 0x04}, //bit[2] enable
816     {0x3390, 0x41}, //bit[3] sign of brightness
817     {0x339a, 0x30},
818     {0x0000, 0x00}
819 };
820 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
821     sensor_Brightness4, sensor_Brightness5,NULL,
822 };
823
824 #endif
825
826 #if CONFIG_SENSOR_Effect
827 static  struct reginfo sensor_Effect_Normal[] =
828 {
829     {0x3391, 0x00},
830     {0x0000, 0x00}
831 };
832
833 static  struct reginfo sensor_Effect_WandB[] =
834 {
835     {0x3391, 0x20},
836     {0x0000, 0x00}
837 };
838
839 static  struct reginfo sensor_Effect_Sepia[] =
840 {
841     {0x3391, 0x18},
842     {0x3396, 0x40},
843     {0x3397, 0xa6},
844     {0x0000, 0x00}
845 };
846
847 static  struct reginfo sensor_Effect_Negative[] =
848 {
849     //Negative
850     {0x3391, 0x40}, //bit[6] negative
851     {0x0000, 0x00}
852 };
853 static  struct reginfo sensor_Effect_Bluish[] =
854 {
855     // Bluish
856     {0x3391, 0x18},
857     {0x3396, 0xa0},
858     {0x3397, 0x40},
859     {0x0000, 0x00}
860 };
861
862 static  struct reginfo sensor_Effect_Green[] =
863 {
864     //  Greenish
865     {0x3391, 0x18},
866     {0x3396, 0x60},
867     {0x3397, 0x60},
868     {0x0000, 0x00}
869 };
870 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
871     sensor_Effect_Bluish, sensor_Effect_Green,NULL,
872 };
873 #endif
874 #if CONFIG_SENSOR_Exposure
875 static  struct reginfo sensor_Exposure0[]=
876 {
877     //-3
878     {0x3047, 0x05},
879     {0x3018, 0x40},
880     {0x3019, 0x30},
881     {0x301a, 0x71},
882     {0x0000, 0x00}
883 };
884
885 static  struct reginfo sensor_Exposure1[]=
886 {
887     //-2
888     {0x3047, 0x05},
889     {0x3018, 0x5a},
890     {0x3019, 0x4a},
891     {0x301a, 0xc2},
892     {0x0000, 0x00}
893 };
894
895 static  struct reginfo sensor_Exposure2[]=
896 {
897     //-0.3EV
898     {0x3047, 0x05},
899     {0x3018, 0x6a},
900     {0x3019, 0x5a},
901     {0x301a, 0xd4},
902     {0x0000, 0x00}
903 };
904
905 static  struct reginfo sensor_Exposure3[]=
906 {
907     //default
908     {0x3047, 0x05},
909     {0x3018, 0x78},
910     {0x3019, 0x68},
911     {0x301a, 0xd4},
912     {0x0000, 0x00}
913 };
914
915 static  struct reginfo sensor_Exposure4[]=
916 {
917     // 1
918     {0x3047, 0x05},
919     {0x3018, 0x88},
920     {0x3019, 0x78},
921     {0x301a, 0xd5},
922     {0x0000, 0x00}
923 };
924
925 static  struct reginfo sensor_Exposure5[]=
926 {
927     // 2
928     {0x3047, 0x05},
929     {0x3018, 0xa8},
930     {0x3019, 0x98},
931     {0x301a, 0xe6},
932     {0x0000, 0x00}
933 };
934
935 static  struct reginfo sensor_Exposure6[]=
936 {
937     // 3
938     {0x3047, 0x05},
939     {0x3018, 0xc8},
940     {0x3019, 0xb8},
941     {0x301a, 0xf7},
942     {0x0000, 0x00}
943 };
944
945 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
946     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
947 };
948 #endif
949 #if CONFIG_SENSOR_Saturation
950 static  struct reginfo sensor_Saturation0[]=
951 {
952     {0x3301, 0xff},//bit[7]:1, enable SDE
953     {0x3391, 0x02},
954     {0x3394, 0x40},
955     {0x3395, 0x40},
956     {0x0000, 0x00}
957 };
958
959 static  struct reginfo sensor_Saturation1[]=
960 {
961     {0x3301, 0xff},//bit[7]:1, enable SDE
962     {0x3391, 0x02},
963     {0x3394, 0x50},
964     {0x3395, 0x50},
965     {0x0000, 0x00}
966 };
967
968 static  struct reginfo sensor_Saturation2[]=
969 {
970     {0x3301, 0xff},//bit[7]:1, enable SDE
971     {0x3391, 0x02}, //enable color saturation
972     {0x3394, 0x70},
973     {0x3395, 0x70},
974     {0x0000, 0x00}
975 };
976 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
977
978 #endif
979 #if CONFIG_SENSOR_Contrast
980 static  struct reginfo sensor_Contrast0[]=
981 {
982     //Contrast -3
983     {0x3301, 0xff},//bit[7]:1, enable SDE
984     {0x3391, 0x04},
985     {0x3390, 0x45},
986     {0x3398, 0x18},
987     {0x3399, 0x18},
988     {0x0000, 0x00}
989 };
990
991 static  struct reginfo sensor_Contrast1[]=
992 {
993     //Contrast -2
994     {0x3301, 0xff},//bit[7]:1, enable SDE
995     {0x3391, 0x04},
996     {0x3390, 0x45},
997     {0x3398, 0x18},
998     {0x3399, 0x18},
999     {0x0000, 0x00}
1000 };
1001
1002 static  struct reginfo sensor_Contrast2[]=
1003 {
1004     // Contrast -1
1005     {0x3301, 0xff},//bit[7]:1, enable SDE
1006     {0x3391, 0x04},
1007     {0x3390, 0x45},
1008     {0x3398, 0x1c},
1009     {0x3399, 0x1c},
1010     {0x0000, 0x00}
1011 };
1012
1013 static  struct reginfo sensor_Contrast3[]=
1014 {
1015     //Contrast 0
1016     {0x3301, 0xff},//bit[7]:1, enable SDE
1017     {0x3391, 0x00},
1018     {0x3390, 0x41},
1019     {0x3398, 0x20},
1020     {0x3399, 0x20},
1021     {0x0000, 0x00}
1022 };
1023
1024 static  struct reginfo sensor_Contrast4[]=
1025 {
1026     //Contrast +1
1027     {0x3301, 0xff},//bit[7]:1, enable SDE
1028     {0x3391, 0x04},
1029     {0x3390, 0x45},
1030     {0x3398, 0x24},
1031     {0x3399, 0x24},
1032     {0x0000, 0x00}
1033 };
1034
1035
1036 static  struct reginfo sensor_Contrast5[]=
1037 {
1038     //Contrast +2
1039     {0x3301, 0xff},//bit[7]:1, enable SDE
1040     {0x3391, 0x04},
1041     {0x3390, 0x45},
1042     {0x3398, 0x28},
1043     {0x3399, 0x28},
1044     {0x0000, 0x00}
1045 };
1046
1047 static  struct reginfo sensor_Contrast6[]=
1048 {
1049     //Contrast +3
1050     {0x3301, 0xff},//bit[7]:1, enable SDE
1051     {0x3391, 0x04}, //bit[2] enable contrast/brightness
1052     {0x3390, 0x45}, //bit[2] Yoffset sign
1053     {0x3398, 0x2c},
1054     {0x3399, 0x2c},
1055     {0x0000, 0x00}
1056 };
1057 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1058     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1059 };
1060
1061 #endif
1062 #if CONFIG_SENSOR_Mirror
1063 static  struct reginfo sensor_MirrorOn[]=
1064 {
1065     {0x3069, 0x84},
1066     {0x307c, 0x13},
1067     {0x3087, 0x02},
1068     {0x0000, 0x00}
1069 };
1070
1071 static  struct reginfo sensor_MirrorOff[]=
1072 {
1073     {0x3069, 0x84},
1074     {0x307c, 0x10},
1075     {0x3087, 0x02},
1076     {0x0000, 0x00}
1077 };
1078 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1079 #endif
1080 #if CONFIG_SENSOR_Flip
1081 static  struct reginfo sensor_FlipOn[]=
1082 {
1083     {0x300e, 0x34},
1084     {0x300f, 0xa6},
1085     {0x3010, 0x81},
1086     {0x3082, 0x01},
1087     {0x30f4, 0x01},
1088     {0x3090, 0x3b},
1089     {0x3091, 0xc0},
1090     {0x30ac, 0x42},
1091     {0x0000, 0x00}
1092 };
1093
1094 static  struct reginfo sensor_FlipOff[]=
1095 {
1096     {0x300e, 0x34},
1097     {0x300f, 0xa6},
1098     {0x3010, 0x81},
1099     {0x3082, 0x01},
1100     {0x30f4, 0x01},
1101     {0x3090, 0x33},
1102     {0x3091, 0xc0},
1103     {0x30ac, 0x42},
1104     {0x0000, 0x00}
1105 };
1106 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1107
1108 #endif
1109 #if CONFIG_SENSOR_Scene
1110 static  struct reginfo sensor_SceneAuto[] =
1111 {
1112 #if 0                           /* ddl@rock-chips.com : */
1113     {0x3014, 0x04},
1114     {0x3015, 0x00},
1115     {0x302e, 0x00},
1116     {0x302d, 0x00},
1117     {0x0000, 0x00}
1118 #else
1119     {0x3014, 0x84},
1120     {0x3015, 0x02},
1121     {0x302e, 0x00},
1122     {0x302d, 0x00},
1123     {0x0000, 0x00}
1124 #endif
1125 };
1126
1127 static  struct reginfo sensor_SceneNight[] =
1128 {
1129 #if 1
1130     //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1131     {0x300e, 0x34},
1132     {0x3011, 0x00},
1133     {0x302c, 0x00},
1134     {0x3071, 0x00},
1135     {0x3070, 0xb9},
1136     {0x301c, 0x02},
1137     {0x3073, 0x00},
1138     {0x3072, 0x9a},
1139     {0x301d, 0x03},
1140     {0x3014, 0x0c},
1141     {0x3015, 0x50},//add 5 dummy frame
1142     {0x302e, 0x00},
1143     {0x302d, 0x00},
1144     {0x0000, 0x00}
1145 #else
1146     //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1147     {0x300e, 0x34},
1148     {0x3011, 0x01},
1149     {0x302c, 0x00},
1150     {0x3071, 0x00},
1151     {0x3070, 0x5d},
1152     {0x301c, 0x05},
1153     {0x3073, 0x00},
1154     {0x3072, 0x4d},
1155     {0x301d, 0x07},
1156     {0x3014, 0x0c},
1157     {0x3015, 0x50},
1158     {0x302e, 0x00},
1159     {0x302d, 0x00},
1160 #endif
1161 };
1162 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1163
1164 #endif
1165 #if CONFIG_SENSOR_DigitalZoom
1166 static struct reginfo sensor_Zoom0[] =
1167 {
1168     {0x0, 0x0},
1169 };
1170
1171 static struct reginfo sensor_Zoom1[] =
1172 {
1173      {0x0, 0x0},
1174 };
1175
1176 static struct reginfo sensor_Zoom2[] =
1177 {
1178     {0x0, 0x0},
1179 };
1180
1181
1182 static struct reginfo sensor_Zoom3[] =
1183 {
1184     {0x0, 0x0},
1185 };
1186 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1187 #endif
1188 static const struct v4l2_querymenu sensor_menus[] =
1189 {
1190         #if CONFIG_SENSOR_WhiteBalance
1191     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
1192     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
1193     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
1194     #endif
1195
1196         #if CONFIG_SENSOR_Effect
1197     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
1198     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
1199     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},
1200     #endif
1201
1202         #if CONFIG_SENSOR_Scene
1203     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
1204     #endif
1205
1206         #if CONFIG_SENSOR_Flash
1207     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
1208     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
1209     #endif
1210 };
1211
1212 static const struct v4l2_queryctrl sensor_controls[] =
1213 {
1214         #if CONFIG_SENSOR_WhiteBalance
1215     {
1216         .id             = V4L2_CID_DO_WHITE_BALANCE,
1217         .type           = V4L2_CTRL_TYPE_MENU,
1218         .name           = "White Balance Control",
1219         .minimum        = 0,
1220         .maximum        = 4,
1221         .step           = 1,
1222         .default_value = 0,
1223     },
1224     #endif
1225
1226         #if CONFIG_SENSOR_Brightness
1227         {
1228         .id             = V4L2_CID_BRIGHTNESS,
1229         .type           = V4L2_CTRL_TYPE_INTEGER,
1230         .name           = "Brightness Control",
1231         .minimum        = -3,
1232         .maximum        = 2,
1233         .step           = 1,
1234         .default_value = 0,
1235     },
1236     #endif
1237
1238         #if CONFIG_SENSOR_Effect
1239         {
1240         .id             = V4L2_CID_EFFECT,
1241         .type           = V4L2_CTRL_TYPE_MENU,
1242         .name           = "Effect Control",
1243         .minimum        = 0,
1244         .maximum        = 5,
1245         .step           = 1,
1246         .default_value = 0,
1247     },
1248         #endif
1249
1250         #if CONFIG_SENSOR_Exposure
1251         {
1252         .id             = V4L2_CID_EXPOSURE,
1253         .type           = V4L2_CTRL_TYPE_INTEGER,
1254         .name           = "Exposure Control",
1255         .minimum        = 0,
1256         .maximum        = 6,
1257         .step           = 1,
1258         .default_value = 0,
1259     },
1260         #endif
1261
1262         #if CONFIG_SENSOR_Saturation
1263         {
1264         .id             = V4L2_CID_SATURATION,
1265         .type           = V4L2_CTRL_TYPE_INTEGER,
1266         .name           = "Saturation Control",
1267         .minimum        = 0,
1268         .maximum        = 2,
1269         .step           = 1,
1270         .default_value = 0,
1271     },
1272     #endif
1273
1274         #if CONFIG_SENSOR_Contrast
1275         {
1276         .id             = V4L2_CID_CONTRAST,
1277         .type           = V4L2_CTRL_TYPE_INTEGER,
1278         .name           = "Contrast Control",
1279         .minimum        = -3,
1280         .maximum        = 3,
1281         .step           = 1,
1282         .default_value = 0,
1283     },
1284         #endif
1285
1286         #if CONFIG_SENSOR_Mirror
1287         {
1288         .id             = V4L2_CID_HFLIP,
1289         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1290         .name           = "Mirror Control",
1291         .minimum        = 0,
1292         .maximum        = 1,
1293         .step           = 1,
1294         .default_value = 1,
1295     },
1296     #endif
1297
1298         #if CONFIG_SENSOR_Flip
1299         {
1300         .id             = V4L2_CID_VFLIP,
1301         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1302         .name           = "Flip Control",
1303         .minimum        = 0,
1304         .maximum        = 1,
1305         .step           = 1,
1306         .default_value = 1,
1307     },
1308     #endif
1309
1310         #if CONFIG_SENSOR_Scene
1311     {
1312         .id             = V4L2_CID_SCENE,
1313         .type           = V4L2_CTRL_TYPE_MENU,
1314         .name           = "Scene Control",
1315         .minimum        = 0,
1316         .maximum        = 1,
1317         .step           = 1,
1318         .default_value = 0,
1319     },
1320     #endif
1321
1322         #if CONFIG_SENSOR_DigitalZoom
1323     {
1324         .id             = V4L2_CID_ZOOM_RELATIVE,
1325         .type           = V4L2_CTRL_TYPE_INTEGER,
1326         .name           = "DigitalZoom Control",
1327         .minimum        = -1,
1328         .maximum        = 1,
1329         .step           = 1,
1330         .default_value = 0,
1331     }, {
1332         .id             = V4L2_CID_ZOOM_ABSOLUTE,
1333         .type           = V4L2_CTRL_TYPE_INTEGER,
1334         .name           = "DigitalZoom Control",
1335         .minimum        = 0,
1336         .maximum        = 3,
1337         .step           = 1,
1338         .default_value = 0,
1339     },
1340     #endif
1341
1342         #if CONFIG_SENSOR_Focus
1343         {
1344         .id             = V4L2_CID_FOCUS_RELATIVE,
1345         .type           = V4L2_CTRL_TYPE_INTEGER,
1346         .name           = "Focus Control",
1347         .minimum        = -1,
1348         .maximum        = 1,
1349         .step           = 1,
1350         .default_value = 0,
1351     }, {
1352         .id             = V4L2_CID_FOCUS_ABSOLUTE,
1353         .type           = V4L2_CTRL_TYPE_INTEGER,
1354         .name           = "Focus Control",
1355         .minimum        = 0,
1356         .maximum        = 255,
1357         .step           = 1,
1358         .default_value = 125,
1359     },
1360     #endif
1361
1362         #if CONFIG_SENSOR_Flash
1363         {
1364         .id             = V4L2_CID_FLASH,
1365         .type           = V4L2_CTRL_TYPE_MENU,
1366         .name           = "Flash Control",
1367         .minimum        = 0,
1368         .maximum        = 3,
1369         .step           = 1,
1370         .default_value = 0,
1371     },
1372         #endif
1373 };
1374
1375 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1376 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1377 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1378 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1379 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1380 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1381 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1382 static int sensor_resume(struct soc_camera_device *icd);
1383 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1384 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1385
1386 static struct soc_camera_ops sensor_ops =
1387 {
1388     .suspend                     = sensor_suspend,
1389     .resume                       = sensor_resume,
1390     .set_bus_param              = sensor_set_bus_param,
1391     .query_bus_param    = sensor_query_bus_param,
1392     .controls           = sensor_controls,
1393     .menus                         = sensor_menus,
1394     .num_controls               = ARRAY_SIZE(sensor_controls),
1395     .num_menus          = ARRAY_SIZE(sensor_menus),
1396 };
1397
1398 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1399         { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1400         .colorspace = _colorspace }
1401
1402 #define JPG_FMT(_name, _depth, _fourcc) \
1403         COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1404
1405 static const struct soc_camera_data_format sensor_colour_formats[] = {
1406         JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1407         JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1408 };
1409
1410 typedef struct sensor_info_priv_s
1411 {
1412     int whiteBalance;
1413     int brightness;
1414     int contrast;
1415     int saturation;
1416     int effect;
1417     int scene;
1418     int digitalzoom;
1419     int focus;
1420     int flash;
1421     int exposure;
1422     unsigned char mirror;                                        /* HFLIP */
1423     unsigned char flip;                                          /* VFLIP */
1424     unsigned int winseqe_cur_addr;
1425         unsigned int pixfmt;
1426
1427 } sensor_info_priv_t;
1428
1429 struct sensor
1430 {
1431     struct v4l2_subdev subdev;
1432     struct i2c_client *client;
1433     sensor_info_priv_t info_priv;
1434     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1435 };
1436
1437 static struct sensor* to_sensor(const struct i2c_client *client)
1438 {
1439     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1440 }
1441
1442 /* sensor register write */
1443 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1444 {
1445     int err,cnt;
1446     u8 buf[3];
1447     struct i2c_msg msg[1];
1448
1449     buf[0] = reg >> 8;
1450     buf[1] = reg & 0xFF;
1451     buf[2] = val;
1452
1453     msg->addr = client->addr;
1454     msg->flags = client->flags;
1455     msg->buf = buf;
1456     msg->len = sizeof(buf);
1457     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1458     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1459
1460     cnt = 1;
1461     err = -EAGAIN;
1462
1463     while ((cnt--) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1464         err = i2c_transfer(client->adapter, msg, 1);
1465
1466         if (err >= 0) {
1467             return 0;
1468         } else {
1469             SENSOR_TR("\n %s write reg failed, try to write again!\n",SENSOR_NAME_STRING());
1470             udelay(10);
1471         }
1472     }
1473
1474     return err;
1475 }
1476
1477 /* sensor register read */
1478 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1479 {
1480     int err,cnt;
1481     u8 buf[2];
1482     struct i2c_msg msg[2];
1483
1484     buf[0] = reg >> 8;
1485     buf[1] = reg & 0xFF;
1486
1487     msg[0].addr = client->addr;
1488     msg[0].flags = client->flags;
1489     msg[0].buf = buf;
1490     msg[0].len = sizeof(buf);
1491     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
1492     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1493
1494     msg[1].addr = client->addr;
1495     msg[1].flags = client->flags|I2C_M_RD;
1496     msg[1].buf = buf;
1497     msg[1].len = 1;
1498     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
1499     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1500
1501     cnt = 1;
1502     err = -EAGAIN;
1503     while ((cnt--) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1504         err = i2c_transfer(client->adapter, msg, 2);
1505
1506         if (err >= 0) {
1507             *val = buf[0];
1508             return 0;
1509         } else {
1510                 SENSOR_TR("\n %s read reg failed, try to read again! reg:0x%x \n",SENSOR_NAME_STRING(),(unsigned int)val);
1511             udelay(10);
1512         }
1513     }
1514
1515     return err;
1516 }
1517
1518 /* write a array of registers  */
1519 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1520 {
1521     int err, cnt;
1522     int i = 0;
1523
1524         cnt = 0;
1525     while (regarray[i].reg != 0)
1526     {
1527         err = sensor_write(client, regarray[i].reg, regarray[i].val);
1528         if (err < 0)
1529         {
1530             if (cnt-- > 0) {
1531                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1532                                 i = 0;
1533                                 continue;
1534             } else {
1535                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1536                 return -EPERM;
1537             }
1538         }
1539         i++;
1540     }
1541     return 0;
1542 }
1543
1544 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1545 {
1546     struct i2c_client *client = sd->priv;
1547     struct soc_camera_device *icd = client->dev.platform_data;
1548     struct sensor *sensor = to_sensor(client);
1549         const struct v4l2_queryctrl *qctrl;
1550     char value;
1551     int ret,pid = 0;
1552
1553     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1554
1555     /* soft reset */
1556     ret = sensor_write(client, 0x3012, 0x80);
1557     if (ret != 0)
1558     {
1559         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1560         ret = -ENODEV;
1561                 goto sensor_INIT_ERR;
1562     }
1563
1564     mdelay(5);  //delay 5 microseconds
1565         /* check if it is an sensor sensor */
1566     ret = sensor_read(client, 0x300a, &value);
1567     if (ret != 0) {
1568         SENSOR_TR("read chip id high byte failed\n");
1569         ret = -ENODEV;
1570         goto sensor_INIT_ERR;
1571     }
1572
1573     pid |= (value << 8);
1574
1575     ret = sensor_read(client, 0x300b, &value);
1576     if (ret != 0) {
1577         SENSOR_TR("read chip id low byte failed\n");
1578         ret = -ENODEV;
1579         goto sensor_INIT_ERR;
1580     }
1581
1582     pid |= (value & 0xff);
1583     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1584     if (pid == SENSOR_ID) {
1585         sensor->model = SENSOR_V4L2_IDENT;
1586     } else {
1587         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1588         ret = -ENODEV;
1589         goto sensor_INIT_ERR;
1590     }
1591
1592     ret = sensor_write_array(client, sensor_init_data);
1593     if (ret != 0)
1594     {
1595         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1596         goto sensor_INIT_ERR;
1597     }
1598
1599     icd->user_width = SENSOR_INIT_WIDTH;
1600     icd->user_height = SENSOR_INIT_HEIGHT;
1601     sensor->info_priv.winseqe_cur_addr  = (int)SENSOR_INIT_WINSEQADR;
1602         sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1603
1604     /* sensor sensor information for initialization  */
1605         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1606         if (qctrl)
1607         sensor->info_priv.whiteBalance = qctrl->default_value;
1608         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1609         if (qctrl)
1610         sensor->info_priv.brightness = qctrl->default_value;
1611         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1612         if (qctrl)
1613         sensor->info_priv.effect = qctrl->default_value;
1614         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1615         if (qctrl)
1616         sensor->info_priv.exposure = qctrl->default_value;
1617
1618         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1619         if (qctrl)
1620         sensor->info_priv.saturation = qctrl->default_value;
1621         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1622         if (qctrl)
1623         sensor->info_priv.contrast = qctrl->default_value;
1624         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1625         if (qctrl)
1626         sensor->info_priv.mirror = qctrl->default_value;
1627         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1628         if (qctrl)
1629         sensor->info_priv.flip = qctrl->default_value;
1630         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1631         if (qctrl)
1632         sensor->info_priv.scene = qctrl->default_value;
1633         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1634         if (qctrl)
1635         sensor->info_priv.digitalzoom = qctrl->default_value;
1636
1637     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
1638         #if CONFIG_SENSOR_Focus
1639     sensor_set_focus();
1640     qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1641         if (qctrl)
1642         sensor->info_priv.focus = qctrl->default_value;
1643         #endif
1644
1645         #if CONFIG_SENSOR_Flash
1646         sensor_set_flash();
1647         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1648         if (qctrl)
1649         sensor->info_priv.flash = qctrl->default_value;
1650     #endif
1651
1652     SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,icd->user_width,icd->user_height);
1653
1654     return 0;
1655 sensor_INIT_ERR:
1656     return ret;
1657 }
1658
1659 static int sensor_deactivate(struct v4l2_subdev *sd)
1660 {
1661         struct i2c_client *client = sd->priv;
1662
1663         SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1664
1665         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1666     sensor_write(client, 0x30b0, 0x00);
1667         sensor_write(client, 0x30b1, 0x00);
1668
1669         return 0;
1670 }
1671
1672 static  struct reginfo sensor_power_down_sequence[]=
1673 {
1674     {0x30ab, 0x00},
1675     {0x30ad, 0x0a},
1676     {0x30ae,0x27},
1677     {0x363b,0x01},
1678     {0x00,0x00}
1679 };
1680 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1681 {
1682     int ret;
1683     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1684     struct soc_camera_link *icl;
1685
1686
1687     if (pm_msg.event == PM_EVENT_SUSPEND)
1688     {
1689         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1690         ret = sensor_write_array(client, sensor_power_down_sequence) ;
1691         if (ret != 0)
1692         {
1693             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1694             return ret;
1695         }
1696         else
1697         {
1698             icl = to_soc_camera_link(icd);
1699             if (icl->power) {
1700                 ret = icl->power(icd->pdev, 0);
1701                 if (ret < 0) {
1702                                     SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1703                     return -EINVAL;
1704                 }
1705             }
1706         }
1707     }
1708     else
1709     {
1710         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1711         return -EINVAL;
1712     }
1713     return 0;
1714 }
1715
1716 static int sensor_resume(struct soc_camera_device *icd)
1717 {
1718     struct soc_camera_link *icl;
1719     int ret;
1720
1721     icl = to_soc_camera_link(icd);
1722     if (icl->power) {
1723         ret = icl->power(icd->pdev, 1);
1724         if (ret < 0) {
1725                         SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1726             return -EINVAL;
1727         }
1728     }
1729
1730         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1731
1732     return 0;
1733
1734 }
1735
1736 static int sensor_set_bus_param(struct soc_camera_device *icd,
1737                                 unsigned long flags)
1738 {
1739
1740     return 0;
1741 }
1742
1743 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1744 {
1745     struct soc_camera_link *icl = to_soc_camera_link(icd);
1746     unsigned long flags = SENSOR_BUS_PARAM;
1747
1748     return soc_camera_apply_sensor_flags(icl, flags);
1749 }
1750
1751 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1752 {
1753     struct i2c_client *client = sd->priv;
1754     struct soc_camera_device *icd = client->dev.platform_data;
1755     struct sensor *sensor = to_sensor(client);
1756     struct v4l2_pix_format *pix = &f->fmt.pix;
1757
1758     pix->width          = icd->user_width;
1759     pix->height         = icd->user_height;
1760     pix->pixelformat    = sensor->info_priv.pixfmt;
1761     pix->field          = V4L2_FIELD_NONE;
1762     pix->colorspace             = V4L2_COLORSPACE_JPEG;
1763
1764     return 0;
1765 }
1766 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1767 {
1768     struct i2c_client *client = sd->priv;
1769     struct sensor *sensor = to_sensor(client);
1770     struct v4l2_pix_format *pix = &f->fmt.pix;
1771     struct reginfo *winseqe_set_addr=NULL;
1772     int ret, set_w,set_h;
1773
1774         if (sensor->info_priv.pixfmt != pix->pixelformat) {
1775                 switch (pix->pixelformat)
1776                 {
1777                         case V4L2_PIX_FMT_YUYV:
1778                         {
1779                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
1780                                 break;
1781                         }
1782                         case V4L2_PIX_FMT_UYVY:
1783                         {
1784                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
1785                                 break;
1786                         }
1787                         default:
1788                                 break;
1789                 }
1790                 if (winseqe_set_addr != NULL) {
1791             sensor_write_array(client, winseqe_set_addr);
1792                         sensor->info_priv.pixfmt = pix->pixelformat;
1793
1794                         SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1795                 } else {
1796                         SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1797                 }
1798         }
1799
1800     set_w = pix->width;
1801     set_h = pix->height;
1802
1803         if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
1804         {
1805                 winseqe_set_addr = sensor_qcif;
1806         set_w = 176;
1807         set_h = 144;
1808         }
1809         else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
1810     {
1811         winseqe_set_addr = sensor_qvga;
1812         set_w = 320;
1813         set_h = 240;
1814     }
1815     else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
1816     {
1817         winseqe_set_addr = sensor_cif;
1818         set_w = 352;
1819         set_h = 288;
1820     }
1821     else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
1822     {
1823         winseqe_set_addr = sensor_vga;
1824         set_w = 640;
1825         set_h = 480;
1826     }
1827     else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
1828     {
1829         winseqe_set_addr = sensor_svga;
1830         set_w = 800;
1831         set_h = 600;
1832     }
1833     else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
1834     {
1835         winseqe_set_addr = sensor_sxga;
1836         set_w = 1280;
1837         set_h = 1024;
1838     }
1839     else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
1840     {
1841         winseqe_set_addr = sensor_uxga;
1842         set_w = 1600;
1843         set_h = 1200;
1844     }
1845     else
1846     {
1847         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */
1848         set_w = SENSOR_INIT_WIDTH;
1849         set_h = SENSOR_INIT_HEIGHT;
1850
1851                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1852     }
1853
1854     if ((int)winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr)
1855     {
1856         ret = sensor_write_array(client, winseqe_set_addr);
1857         if (ret != 0)
1858         {
1859             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1860             return ret;
1861         }
1862
1863         sensor->info_priv.winseqe_cur_addr  = (int)winseqe_set_addr;
1864         //mdelay(250);
1865
1866         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1867     }
1868     else
1869     {
1870         SENSOR_TR("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
1871     }
1872
1873     return 0;
1874 }
1875
1876 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1877 {
1878     struct v4l2_pix_format *pix = &f->fmt.pix;
1879     bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1880         pix->pixelformat == V4L2_PIX_FMT_YUYV;
1881
1882     /*
1883     * With Bayer format enforce even side lengths, but let the user play
1884     * with the starting pixel
1885     */
1886
1887     if (pix->height > SENSOR_MAX_HEIGHT)
1888         pix->height = SENSOR_MAX_HEIGHT;
1889     else if (pix->height < SENSOR_MIN_HEIGHT)
1890         pix->height = SENSOR_MIN_HEIGHT;
1891     else if (bayer)
1892         pix->height = ALIGN(pix->height, 2);
1893
1894     if (pix->width > SENSOR_MAX_WIDTH)
1895         pix->width = SENSOR_MAX_WIDTH;
1896     else if (pix->width < SENSOR_MIN_WIDTH)
1897         pix->width = SENSOR_MIN_WIDTH;
1898     else if (bayer)
1899         pix->width = ALIGN(pix->width, 2);
1900
1901     return 0;
1902 }
1903
1904  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1905 {
1906     struct i2c_client *client = sd->priv;
1907
1908     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1909         return -EINVAL;
1910
1911     if (id->match.addr != client->addr)
1912         return -ENODEV;
1913
1914     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
1915     id->revision = 0;
1916
1917     return 0;
1918 }
1919 #if CONFIG_SENSOR_Brightness
1920 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1921 {
1922     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1923
1924     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1925     {
1926         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
1927         {
1928             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
1929             {
1930                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1931                 return -EINVAL;
1932             }
1933             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1934             return 0;
1935         }
1936     }
1937         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1938     return -EINVAL;
1939 }
1940 #endif
1941 #if CONFIG_SENSOR_Effect
1942 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1943 {
1944     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1945
1946     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1947     {
1948         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
1949         {
1950             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
1951             {
1952                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1953                 return -EINVAL;
1954             }
1955             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1956             return 0;
1957         }
1958     }
1959         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1960     return -EINVAL;
1961 }
1962 #endif
1963 #if CONFIG_SENSOR_Exposure
1964 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1965 {
1966     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1967
1968     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1969     {
1970         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
1971         {
1972             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
1973             {
1974                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1975                 return -EINVAL;
1976             }
1977             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
1978             return 0;
1979         }
1980     }
1981         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
1982     return -EINVAL;
1983 }
1984 #endif
1985 #if CONFIG_SENSOR_Saturation
1986 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
1987 {
1988     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1989
1990     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
1991     {
1992         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
1993         {
1994             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
1995             {
1996                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
1997                 return -EINVAL;
1998             }
1999             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2000             return 0;
2001         }
2002     }
2003     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2004     return -EINVAL;
2005 }
2006 #endif
2007 #if CONFIG_SENSOR_Contrast
2008 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2009 {
2010     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2011
2012     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2013     {
2014         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2015         {
2016             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2017             {
2018                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2019                 return -EINVAL;
2020             }
2021             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2022             return 0;
2023         }
2024     }
2025     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2026     return -EINVAL;
2027 }
2028 #endif
2029 #if CONFIG_SENSOR_Mirror
2030 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2031 {
2032     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2033
2034     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2035     {
2036         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2037         {
2038             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2039             {
2040                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2041                 return -EINVAL;
2042             }
2043             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2044             return 0;
2045         }
2046     }
2047     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2048     return -EINVAL;
2049 }
2050 #endif
2051 #if CONFIG_SENSOR_Flip
2052 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2053 {
2054     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2055
2056     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2057     {
2058         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2059         {
2060             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2061             {
2062                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2063                 return -EINVAL;
2064             }
2065             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2066             return 0;
2067         }
2068     }
2069     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2070     return -EINVAL;
2071 }
2072 #endif
2073 #if CONFIG_SENSOR_Scene
2074 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2075 {
2076     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2077
2078     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2079     {
2080         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2081         {
2082             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2083             {
2084                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2085                 return -EINVAL;
2086             }
2087             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2088             return 0;
2089         }
2090     }
2091     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2092     return -EINVAL;
2093 }
2094 #endif
2095 #if CONFIG_SENSOR_WhiteBalance
2096 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2097 {
2098     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2099
2100     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2101     {
2102         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2103         {
2104             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2105             {
2106                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2107                 return -EINVAL;
2108             }
2109             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2110             return 0;
2111         }
2112     }
2113         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2114     return -EINVAL;
2115 }
2116 #endif
2117 #if CONFIG_SENSOR_DigitalZoom
2118 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2119 {
2120     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2121     struct sensor *sensor = to_sensor(client);
2122         const struct v4l2_queryctrl *qctrl_info;
2123     int digitalzoom_cur, digitalzoom_total;
2124
2125         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2126         if (qctrl_info)
2127                 return -EINVAL;
2128
2129     digitalzoom_cur = sensor->info_priv.digitalzoom;
2130     digitalzoom_total = qctrl_info->maximum;
2131
2132     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2133     {
2134         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2135         return -EINVAL;
2136     }
2137
2138     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2139     {
2140         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2141         return -EINVAL;
2142     }
2143
2144     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2145     {
2146         *value = digitalzoom_total - digitalzoom_cur;
2147     }
2148
2149     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2150     {
2151         *value = 0 - digitalzoom_cur;
2152     }
2153
2154     digitalzoom_cur += *value;
2155
2156     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2157     {
2158         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2159         {
2160             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2161             return -EINVAL;
2162         }
2163         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2164         return 0;
2165     }
2166
2167     return -EINVAL;
2168 }
2169 #endif
2170 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2171 {
2172     struct i2c_client *client = sd->priv;
2173     struct sensor *sensor = to_sensor(client);
2174     const struct v4l2_queryctrl *qctrl;
2175
2176     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2177
2178     if (!qctrl)
2179     {
2180         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2181         return -EINVAL;
2182     }
2183
2184     switch (ctrl->id)
2185     {
2186         case V4L2_CID_BRIGHTNESS:
2187             {
2188                 ctrl->value = sensor->info_priv.brightness;
2189                 break;
2190             }
2191         case V4L2_CID_SATURATION:
2192             {
2193                 ctrl->value = sensor->info_priv.saturation;
2194                 break;
2195             }
2196         case V4L2_CID_CONTRAST:
2197             {
2198                 ctrl->value = sensor->info_priv.contrast;
2199                 break;
2200             }
2201         case V4L2_CID_DO_WHITE_BALANCE:
2202             {
2203                 ctrl->value = sensor->info_priv.whiteBalance;
2204                 break;
2205             }
2206         case V4L2_CID_EXPOSURE:
2207             {
2208                 ctrl->value = sensor->info_priv.exposure;
2209                 break;
2210             }
2211         case V4L2_CID_HFLIP:
2212             {
2213                 ctrl->value = sensor->info_priv.mirror;
2214                 break;
2215             }
2216         case V4L2_CID_VFLIP:
2217             {
2218                 ctrl->value = sensor->info_priv.flip;
2219                 break;
2220             }
2221         default :
2222                 break;
2223     }
2224     return 0;
2225 }
2226
2227
2228
2229 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2230 {
2231     struct i2c_client *client = sd->priv;
2232     struct sensor *sensor = to_sensor(client);
2233     struct soc_camera_device *icd = client->dev.platform_data;
2234     const struct v4l2_queryctrl *qctrl;
2235
2236
2237     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2238
2239     if (!qctrl)
2240     {
2241         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2242         return -EINVAL;
2243     }
2244
2245     switch (ctrl->id)
2246     {
2247 #if CONFIG_SENSOR_Brightness
2248         case V4L2_CID_BRIGHTNESS:
2249             {
2250                 if (ctrl->value != sensor->info_priv.brightness)
2251                 {
2252                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2253                     {
2254                         return -EINVAL;
2255                     }
2256                     sensor->info_priv.brightness = ctrl->value;
2257                 }
2258                 break;
2259             }
2260 #endif
2261 #if CONFIG_SENSOR_Exposure
2262         case V4L2_CID_EXPOSURE:
2263             {
2264                 if (ctrl->value != sensor->info_priv.exposure)
2265                 {
2266                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2267                     {
2268                         return -EINVAL;
2269                     }
2270                     sensor->info_priv.exposure = ctrl->value;
2271                 }
2272                 break;
2273             }
2274 #endif
2275 #if CONFIG_SENSOR_Saturation
2276         case V4L2_CID_SATURATION:
2277             {
2278                 if (ctrl->value != sensor->info_priv.saturation)
2279                 {
2280                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2281                     {
2282                         return -EINVAL;
2283                     }
2284                     sensor->info_priv.saturation = ctrl->value;
2285                 }
2286                 break;
2287             }
2288 #endif
2289 #if CONFIG_SENSOR_Contrast
2290         case V4L2_CID_CONTRAST:
2291             {
2292                 if (ctrl->value != sensor->info_priv.contrast)
2293                 {
2294                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2295                     {
2296                         return -EINVAL;
2297                     }
2298                     sensor->info_priv.contrast = ctrl->value;
2299                 }
2300                 break;
2301             }
2302 #endif
2303 #if CONFIG_SENSOR_WhiteBalance
2304         case V4L2_CID_DO_WHITE_BALANCE:
2305             {
2306                 if (ctrl->value != sensor->info_priv.whiteBalance)
2307                 {
2308                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2309                     {
2310                         return -EINVAL;
2311                     }
2312                     sensor->info_priv.whiteBalance = ctrl->value;
2313                 }
2314                 break;
2315             }
2316 #endif
2317 #if CONFIG_SENSOR_Mirror
2318         case V4L2_CID_HFLIP:
2319             {
2320                 if (ctrl->value != sensor->info_priv.mirror)
2321                 {
2322                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2323                         return -EINVAL;
2324                     sensor->info_priv.mirror = ctrl->value;
2325                 }
2326                 break;
2327             }
2328 #endif
2329 #if CONFIG_SENSOR_Flip
2330         case V4L2_CID_VFLIP:
2331             {
2332                 if (ctrl->value != sensor->info_priv.flip)
2333                 {
2334                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2335                         return -EINVAL;
2336                     sensor->info_priv.flip = ctrl->value;
2337                 }
2338                 break;
2339             }
2340 #endif
2341         default:
2342             break;
2343     }
2344
2345     return 0;
2346 }
2347 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2348 {
2349     const struct v4l2_queryctrl *qctrl;
2350     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2351     struct sensor *sensor = to_sensor(client);
2352
2353     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2354
2355     if (!qctrl)
2356     {
2357         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2358         return -EINVAL;
2359     }
2360
2361     switch (ext_ctrl->id)
2362     {
2363         case V4L2_CID_SCENE:
2364             {
2365                 ext_ctrl->value = sensor->info_priv.scene;
2366                 break;
2367             }
2368         case V4L2_CID_EFFECT:
2369             {
2370                 ext_ctrl->value = sensor->info_priv.effect;
2371                 break;
2372             }
2373         case V4L2_CID_ZOOM_ABSOLUTE:
2374             {
2375                 ext_ctrl->value = sensor->info_priv.digitalzoom;
2376                 break;
2377             }
2378         case V4L2_CID_ZOOM_RELATIVE:
2379             {
2380                 return -EINVAL;
2381             }
2382         case V4L2_CID_FOCUS_ABSOLUTE:
2383             {
2384                 ext_ctrl->value = sensor->info_priv.focus;
2385                 break;
2386             }
2387         case V4L2_CID_FOCUS_RELATIVE:
2388             {
2389                 return -EINVAL;
2390             }
2391         case V4L2_CID_FLASH:
2392             {
2393                 ext_ctrl->value = sensor->info_priv.flash;
2394                 break;
2395             }
2396         default :
2397             break;
2398     }
2399     return 0;
2400 }
2401 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2402 {
2403     const struct v4l2_queryctrl *qctrl;
2404     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2405     struct sensor *sensor = to_sensor(client);
2406     int val_offset;
2407
2408     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2409
2410     if (!qctrl)
2411     {
2412         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2413         return -EINVAL;
2414     }
2415
2416         val_offset = 0;
2417     switch (ext_ctrl->id)
2418     {
2419 #if CONFIG_SENSOR_Scene
2420         case V4L2_CID_SCENE:
2421             {
2422                 if (ext_ctrl->value != sensor->info_priv.scene)
2423                 {
2424                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2425                         return -EINVAL;
2426                     sensor->info_priv.scene = ext_ctrl->value;
2427                 }
2428                 break;
2429             }
2430 #endif
2431 #if CONFIG_SENSOR_Effect
2432         case V4L2_CID_EFFECT:
2433             {
2434                 if (ext_ctrl->value != sensor->info_priv.effect)
2435                 {
2436                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2437                         return -EINVAL;
2438                     sensor->info_priv.effect= ext_ctrl->value;
2439                 }
2440                 break;
2441             }
2442 #endif
2443 #if CONFIG_SENSOR_DigitalZoom
2444         case V4L2_CID_ZOOM_ABSOLUTE:
2445             {
2446                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2447                     return -EINVAL;
2448
2449                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2450                 {
2451                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2452
2453                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2454                         return -EINVAL;
2455                     sensor->info_priv.digitalzoom += val_offset;
2456
2457                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
2458                 }
2459
2460                 break;
2461             }
2462         case V4L2_CID_ZOOM_RELATIVE:
2463             {
2464                 if (ext_ctrl->value)
2465                 {
2466                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2467                         return -EINVAL;
2468                     sensor->info_priv.digitalzoom += ext_ctrl->value;
2469
2470                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2471                 }
2472                 break;
2473             }
2474 #endif
2475 #if CONFIG_SENSOR_Focus
2476         case V4L2_CID_FOCUS_ABSOLUTE:
2477             {
2478                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2479                     return -EINVAL;
2480
2481                 if (ext_ctrl->value != sensor->info_priv.focus)
2482                 {
2483                     val_offset = ext_ctrl->value -sensor->info_priv.focus;
2484
2485                     sensor->info_priv.focus += val_offset;
2486                 }
2487
2488                 break;
2489             }
2490         case V4L2_CID_FOCUS_RELATIVE:
2491             {
2492                 if (ext_ctrl->value)
2493                 {
2494                     sensor->info_priv.focus += ext_ctrl->value;
2495
2496                     SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
2497                 }
2498                 break;
2499             }
2500 #endif
2501 #if CONFIG_SENSOR_Flash
2502         case V4L2_CID_FLASH:
2503             {
2504                 sensor->info_priv.flash = ext_ctrl->value;
2505
2506                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2507                 break;
2508             }
2509 #endif
2510         default:
2511             break;
2512     }
2513
2514     return 0;
2515 }
2516
2517 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2518 {
2519     struct i2c_client *client = sd->priv;
2520     struct soc_camera_device *icd = client->dev.platform_data;
2521     int i, error_cnt=0, error_idx=-1;
2522
2523
2524     for (i=0; i<ext_ctrl->count; i++) {
2525         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2526             error_cnt++;
2527             error_idx = i;
2528         }
2529     }
2530
2531     if (error_cnt > 1)
2532         error_idx = ext_ctrl->count;
2533
2534     if (error_idx != -1) {
2535         ext_ctrl->error_idx = error_idx;
2536         return -EINVAL;
2537     } else {
2538         return 0;
2539     }
2540 }
2541
2542 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2543 {
2544     struct i2c_client *client = sd->priv;
2545     struct soc_camera_device *icd = client->dev.platform_data;
2546     int i, error_cnt=0, error_idx=-1;
2547
2548
2549     for (i=0; i<ext_ctrl->count; i++) {
2550         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2551             error_cnt++;
2552             error_idx = i;
2553         }
2554     }
2555
2556     if (error_cnt > 1)
2557         error_idx = ext_ctrl->count;
2558
2559     if (error_idx != -1) {
2560         ext_ctrl->error_idx = error_idx;
2561         return -EINVAL;
2562     } else {
2563         return 0;
2564     }
2565 }
2566
2567 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2568  * this wasn't our capture interface, so, we wait for the right one */
2569 static int sensor_video_probe(struct soc_camera_device *icd,
2570                                struct i2c_client *client)
2571 {
2572     char value;
2573     int ret,pid = 0;
2574     struct sensor *sensor = to_sensor(client);
2575
2576     /* We must have a parent by now. And it cannot be a wrong one.
2577      * So this entire test is completely redundant. */
2578     if (!icd->dev.parent ||
2579             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2580                 return -ENODEV;
2581
2582     /* soft reset */
2583     ret = sensor_write(client, 0x3012, 0x80);
2584     if (ret != 0)
2585     {
2586         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
2587         return -ENODEV;
2588     }
2589     mdelay(5);          //delay 5 microseconds
2590
2591     /* check if it is an sensor sensor */
2592     ret = sensor_read(client, 0x300a, &value);
2593     if (ret != 0) {
2594         SENSOR_TR("read chip id high byte failed\n");
2595         ret = -ENODEV;
2596         goto sensor_video_probe_err;
2597     }
2598
2599     pid |= (value << 8);
2600
2601     ret = sensor_read(client, 0x300b, &value);
2602     if (ret != 0) {
2603         SENSOR_TR("read chip id low byte failed\n");
2604         ret = -ENODEV;
2605         goto sensor_video_probe_err;
2606     }
2607
2608     pid |= (value & 0xff);
2609     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2610     if (pid == SENSOR_ID) {
2611         sensor->model = SENSOR_V4L2_IDENT;
2612     } else {
2613         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2614         ret = -ENODEV;
2615         goto sensor_video_probe_err;
2616     }
2617
2618     icd->formats = sensor_colour_formats;
2619     icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2620
2621     return 0;
2622
2623 sensor_video_probe_err:
2624
2625     return ret;
2626 }
2627 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2628 {
2629         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2630         switch (cmd)
2631         {
2632                 case RK29_CAM_SUBDEV_DEACTIVATE:
2633                 {
2634                         sensor_deactivate(sd);
2635                         break;
2636                 }
2637                 default:
2638                         break;
2639         }
2640
2641         return 0;
2642
2643 }
2644 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2645         .init           = sensor_init,
2646         .g_ctrl         = sensor_g_control,
2647         .s_ctrl         = sensor_s_control,
2648         .g_ext_ctrls          = sensor_g_ext_controls,
2649         .s_ext_ctrls          = sensor_s_ext_controls,
2650         .g_chip_ident   = sensor_g_chip_ident,
2651         .ioctl = sensor_ioctl,
2652 };
2653
2654 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2655         .s_fmt          = sensor_s_fmt,
2656         .g_fmt          = sensor_g_fmt,
2657         .try_fmt        = sensor_try_fmt,
2658 };
2659
2660 static struct v4l2_subdev_ops sensor_subdev_ops = {
2661         .core   = &sensor_subdev_core_ops,
2662         .video = &sensor_subdev_video_ops,
2663 };
2664
2665 static int sensor_probe(struct i2c_client *client,
2666                          const struct i2c_device_id *did)
2667 {
2668     struct sensor *sensor;
2669     struct soc_camera_device *icd = client->dev.platform_data;
2670     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2671     struct soc_camera_link *icl;
2672     int ret;
2673
2674     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2675     if (!icd) {
2676         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2677         return -EINVAL;
2678     }
2679
2680     icl = to_soc_camera_link(icd);
2681     if (!icl) {
2682         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2683         return -EINVAL;
2684     }
2685
2686     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2687         dev_warn(&adapter->dev,
2688                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
2689         return -EIO;
2690     }
2691
2692     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
2693     if (!sensor)
2694         return -ENOMEM;
2695
2696     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
2697
2698     /* Second stage probe - when a capture adapter is there */
2699     icd->ops            = &sensor_ops;
2700     icd->y_skip_top             = 0;
2701
2702     ret = sensor_video_probe(icd, client);
2703     if (ret) {
2704         icd->ops = NULL;
2705         i2c_set_clientdata(client, NULL);
2706         kfree(sensor);
2707     }
2708     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
2709     return ret;
2710 }
2711
2712 static int sensor_remove(struct i2c_client *client)
2713 {
2714     struct sensor *sensor = to_sensor(client);
2715     struct soc_camera_device *icd = client->dev.platform_data;
2716
2717     icd->ops = NULL;
2718     i2c_set_clientdata(client, NULL);
2719     client->driver = NULL;
2720     kfree(sensor);
2721
2722     return 0;
2723 }
2724
2725 static const struct i2c_device_id sensor_id[] = {
2726         {SENSOR_NAME_STRING(), 0 },
2727         { }
2728 };
2729 MODULE_DEVICE_TABLE(i2c, sensor_id);
2730
2731 static struct i2c_driver sensor_i2c_driver = {
2732         .driver = {
2733                 .name = SENSOR_NAME_STRING(),
2734         },
2735         .probe          = sensor_probe,
2736         .remove         = sensor_remove,
2737         .id_table       = sensor_id,
2738 };
2739
2740 static int __init sensor_mod_init(void)
2741 {
2742     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
2743     return i2c_add_driver(&sensor_i2c_driver);
2744 }
2745
2746 static void __exit sensor_mod_exit(void)
2747 {
2748     i2c_del_driver(&sensor_i2c_driver);
2749 }
2750
2751 device_initcall_sync(sensor_mod_init);
2752 module_exit(sensor_mod_exit);
2753
2754 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
2755 MODULE_AUTHOR("ddl <kernel@rock-chips>");
2756 MODULE_LICENSE("GPL");
2757