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