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