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