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