rk312x camera : oneframe v0.1.9,pingpong v0.1.9
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / ov2659.c
1
2 #include "generic_sensor.h"
3 #include <linux/moduleparam.h>
4 /*
5 *      Driver Version Note
6 *v0.0.1: this driver is compatible with generic_sensor
7 *v0.1.1:
8 *        add sensor_focus_af_const_pause_usr_cb;
9 */
10 static int version = KERNEL_VERSION(0,1,3);
11 module_param(version, int, S_IRUGO);
12
13 static int debug;
14 module_param(debug, int, S_IRUGO|S_IWUSR);
15
16 #define dprintk(level, fmt, arg...) do {                        \
17         if (debug >= level)                                     \
18         printk(KERN_WARNING fmt , ## arg); } while (0)
19 #define debug_printk(format, ...) dprintk(1, format, ## __VA_ARGS__)  
20 /* Sensor Driver Configuration Begin */
21 #define SENSOR_NAME RK29_CAM_SENSOR_OV2659
22 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV2659
23 #define SENSOR_ID 0x2656
24 #define SENSOR_BUS_PARAM                     (V4L2_MBUS_MASTER |\
25                                              V4L2_MBUS_PCLK_SAMPLE_RISING|V4L2_MBUS_HSYNC_ACTIVE_HIGH| V4L2_MBUS_VSYNC_ACTIVE_LOW|\
26                                              V4L2_MBUS_DATA_ACTIVE_HIGH  |SOCAM_MCLK_24MHZ)
27 #define SENSOR_PREVIEW_W                     800
28 #define SENSOR_PREVIEW_H                     600
29 #define SENSOR_PREVIEW_FPS                   15000     // 15fps 
30 #define SENSOR_FULLRES_L_FPS                 7500      // 7.5fps
31 #define SENSOR_FULLRES_H_FPS                 7500      // 7.5fps
32 #define SENSOR_720P_FPS                      0
33 #define SENSOR_1080P_FPS                     0
34
35 #define SENSOR_REGISTER_LEN                  2         // sensor register address bytes
36 #define SENSOR_VALUE_LEN                     1         // sensor register value bytes
37                                     
38 static unsigned int SensorConfiguration = (CFG_WhiteBalance|CFG_Effect|CFG_Scene);
39 static unsigned int SensorChipID[] = {SENSOR_ID};
40 /* Sensor Driver Configuration End */
41
42
43 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
44 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
45
46 #define SensorRegVal(a,b) CONS4(SensorReg,SENSOR_REGISTER_LEN,Val,SENSOR_VALUE_LEN)(a,b)
47 #define sensor_write(client,reg,v) CONS4(sensor_write_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
48 #define sensor_read(client,reg,v) CONS4(sensor_read_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))
49 #define sensor_write_array generic_sensor_write_array
50
51 struct sensor_parameter
52 {
53         unsigned int PreviewDummyPixels;
54         unsigned int CaptureDummyPixels;
55         unsigned int preview_exposure;
56         unsigned short int preview_line_width;
57         unsigned short int preview_gain;
58
59         unsigned short int PreviewPclk;
60         unsigned short int CapturePclk;
61         char awb[6];
62 };
63
64 struct specific_sensor{
65         struct generic_sensor common_sensor;
66         //define user data below
67         struct sensor_parameter parameter;
68
69 };
70
71 /*
72 *  The follow setting need been filled.
73 *  
74 *  Must Filled:
75 *  sensor_init_data :               Sensor initial setting;
76 *  sensor_fullres_lowfps_data :     Sensor full resolution setting with best auality, recommand for video;
77 *  sensor_preview_data :            Sensor preview resolution setting, recommand it is vga or svga;
78 *  sensor_softreset_data :          Sensor software reset register;
79 *  sensor_check_id_data :           Sensir chip id register;
80 *
81 *  Optional filled:
82 *  sensor_fullres_highfps_data:     Sensor full resolution setting with high framerate, recommand for video;
83 *  sensor_720p:                     Sensor 720p setting, it is for video;
84 *  sensor_1080p:                    Sensor 1080p setting, it is for video;
85 *
86 *  :::::WARNING:::::
87 *  The SensorEnd which is the setting end flag must be filled int the last of each setting;
88 */
89
90 /* Sensor initial setting */
91 static struct rk_sensor_reg sensor_init_data[] ={
92         {0x3000, 0x0f},
93         {0x3001, 0xff},
94         {0x3002, 0xff},
95         //{0x0100, 0x01},       //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array
96         {0x3633, 0x3d},
97         {0x3620, 0x02},
98         {0x3631, 0x11},
99         {0x3612, 0x04},
100         {0x3630, 0x20},
101         {0x4702, 0x02},
102         {0x370c, 0x34},
103         {0x3004, 0x10},
104         {0x3005, 0x18},
105         {0x3800, 0x00},
106         {0x3801, 0x00},
107         {0x3802, 0x00},
108         {0x3803, 0x00},
109         {0x3804, 0x06},
110         {0x3805, 0x5f},
111         {0x3806, 0x04},
112         {0x3807, 0xb7},
113         {0x3808, 0x03},
114         {0x3809, 0x20},
115         {0x380a, 0x02},
116         {0x380b, 0x58},
117         {0x380c, 0x05},
118         {0x380d, 0x14},
119         {0x380e, 0x02},
120         {0x380f, 0x68},
121         {0x3811, 0x08},
122         {0x3813, 0x02},
123         {0x3814, 0x31},
124         {0x3815, 0x31},
125         {0x3a02, 0x02},
126         {0x3a03, 0x68},
127         {0x3a08, 0x00},
128         {0x3a09, 0x5c},
129         {0x3a0a, 0x00},
130         {0x3a0b, 0x4d},
131         {0x3a0d, 0x08},
132         {0x3a0e, 0x06},
133         {0x3a14, 0x02},
134         {0x3a15, 0x28},
135                 {0x4708, 0x01},
136         {0x3623, 0x00},
137         {0x3634, 0x76},
138         {0x3701, 0x44},
139         {0x3702, 0x18},
140         {0x3703, 0x24},
141         {0x3704, 0x24},
142         {0x3705, 0x0c},
143         {0x3820, 0x81},
144         {0x3821, 0x01},
145         {0x370a, 0x52},
146         {0x4608, 0x00},
147         {0x4609, 0x80},
148         {0x4300, 0x32},
149         {0x5086, 0x02},
150         {0x5000, 0xfb},
151         {0x5001, 0x1f},
152         {0x5002, 0x00},
153         {0x5025, 0x0e},
154         {0x5026, 0x18},
155         {0x5027, 0x34},
156         {0x5028, 0x4c},
157         {0x5029, 0x62},
158         {0x502a, 0x74},
159         {0x502b, 0x85},
160         {0x502c, 0x92},
161         {0x502d, 0x9e},
162         {0x502e, 0xb2},
163         {0x502f, 0xc0},
164         {0x5030, 0xcc},
165         {0x5031, 0xe0},
166         {0x5032, 0xee},
167         {0x5033, 0xf6},
168         {0x5034, 0x11},
169         {0x5070, 0x1c},
170         {0x5071, 0x5b},
171         {0x5072, 0x05},
172         {0x5073, 0x20},
173         {0x5074, 0x94},
174         {0x5075, 0xb4},
175         {0x5076, 0xb4},
176         {0x5077, 0xaf},
177         {0x5078, 0x05},
178         {0x5079, 0x98},
179         {0x507a, 0x21},
180         {0x5035, 0x6a},
181         {0x5036, 0x11},
182         {0x5037, 0x92},
183         {0x5038, 0x21},
184         
185         {0x5039, 0xe1},
186         {0x503a, 0x01},
187         {0x503c, 0x05},
188         {0x503d, 0x08},
189         {0x503e, 0x08},
190         {0x503f, 0x64},
191         {0x5040, 0x58},
192         {0x5041, 0x2a},
193         {0x5042, 0xc5},
194         {0x5043, 0x2e},
195         {0x5044, 0x3a},
196         {0x5045, 0x3c},
197         {0x5046, 0x44},
198         {0x5047, 0xf8},
199         {0x5048, 0x08},
200         {0x5049, 0x70},
201         {0x504a, 0xf0},
202         {0x504b, 0xf0},
203         {0x500c, 0x03},
204         {0x500d, 0x20},
205         {0x500e, 0x02},
206         {0x500f, 0x5c},
207         {0x5010, 0x48},
208         {0x5011, 0x00},
209         {0x5012, 0x66},
210         {0x5013, 0x03},
211         {0x5014, 0x30},
212         {0x5015, 0x02},
213         {0x5016, 0x7c},
214         {0x5017, 0x40},
215         {0x5018, 0x00},
216         {0x5019, 0x66},
217         {0x501a, 0x03},
218         {0x501b, 0x10},
219         {0x501c, 0x02},
220         {0x501d, 0x7c},
221         {0x501e, 0x3a},
222         {0x501f, 0x00},
223         {0x5020, 0x66},
224         {0x506e, 0x44},
225         {0x5064, 0x08},
226         {0x5065, 0x10},
227         {0x5066, 0x12},
228         {0x5067, 0x02},
229         {0x506c, 0x08},
230         {0x506d, 0x10},
231         {0x506f, 0xa6},
232         {0x5068, 0x08},
233         
234         
235         {0x5069, 0x10},
236         {0x506a, 0x04},
237         {0x506b, 0x12},
238         {0x507e, 0x40},
239         {0x507f, 0x20},
240         {0x507b, 0x02},
241         {0x507a, 0x01},
242         {0x5084, 0x0c},
243         {0x5085, 0x3e},
244         {0x5005, 0x80},
245         {0x3a0f, 0x30},
246         {0x3a10, 0x28},
247         {0x3a1b, 0x32},
248         {0x3a1e, 0x26},
249         {0x3a11, 0x60},
250         {0x3a1f, 0x14},
251         {0x5060, 0x69},
252         {0x5061, 0x7d},
253         {0x5062, 0x7d},
254         {0x5063, 0x69},
255         {0x3004, 0x20},
256         {0x0100, 0x01},
257         SensorEnd
258 };
259 /* Senor full resolution setting: recommand for capture */
260 static struct rk_sensor_reg sensor_fullres_lowfps_data[] ={
261
262         {0x3503,0x03}, 
263         {0x506e,0x44},  
264         {0x5064,0x08},  
265         {0x5065,0x10},
266         {0x5066,0x18},  // zenghaihui 20110920 16
267         {0x5067,0x10},
268         {0x506c,0x08},
269         {0x506d,0x10},  
270         {0x506f,0xa6},  
271         {0x5068,0x08},
272         {0x5069,0x10},  
273         {0x506a,0x08},
274         {0x506b,0x28},
275         {0x5084,0x14},//0c
276         {0x5085,0x3c},//34      
277         {0x5005,0x80}, 
278
279
280
281         {0x5066, 0x3c},                 
282         {0x5067, 0x1a}, 
283         {0x506a, 0x0e},    
284         {0x506b, 0x2e},    
285
286         {0x3800, 0x00}, 
287         {0x3801, 0x00}, 
288         {0x3802, 0x00}, 
289         {0x3803, 0x00}, 
290         {0x3804, 0x06}, 
291         {0x3805, 0x5f}, 
292         {0x3806, 0x04}, 
293         {0x3807, 0xbb}, 
294         {0x3808, 0x06}, 
295         {0x3809, 0x40}, 
296         {0x380a, 0x04}, 
297         {0x380b, 0xb0}, 
298         {0x3811, 0x10}, 
299         {0x3813, 0x06}, 
300         {0x3814, 0x11}, 
301         {0x3815, 0x11}, 
302
303         {0x3623, 0x00}, 
304         {0x3634, 0x44}, 
305         {0x3701, 0x44}, 
306         {0x3208, 0xa2}, 
307         {0x3705, 0x18},          
308         {0x3820, 0x80}, 
309         {0x3821, 0x00}, 
310
311         {0x3003, 0x80},//10fps 
312         {0x3004, 0x20}, //10             
313         {0x3005, 0x18}, 
314         {0x3006, 0x0d}, 
315
316         {0x380c, 0x07}, 
317         {0x380d, 0x9f}, 
318         {0x380e, 0x04}, 
319         {0x380f, 0xd0}, 
320
321         {0x370a, 0x12}, 
322         {0x4608, 0x00}, 
323         {0x4609, 0x80}, 
324         {0x5002, 0x00}, 
325
326         {0x3a08, 0x00}, 
327         {0x3a09, 0x3e},//7b 
328         {0x3a0e, 0x13},//0a 
329
330         {0x3a0a, 0x00}, 
331         {0x3a0b, 0x3e},//7b                             
332         {0x3a0d, 0x13},//0a             
333
334         {0x4003, 0x88},
335         SensorEnd
336 };
337 /* Senor full resolution setting: recommand for video */
338 static struct rk_sensor_reg sensor_fullres_highfps_data[] ={
339         SensorEnd
340 };
341 /* Preview resolution setting*/
342 static struct rk_sensor_reg sensor_preview_data[] =
343 {
344         {0x0100, 0x00},    //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
345         {0x3800, 0x00},
346         {0x3801, 0x00},
347         {0x3802, 0x00},
348         {0x3803, 0x00},
349         {0x3804, 0x06},
350         {0x3805, 0x5f},
351         {0x3806, 0x04},
352         {0x3807, 0xb7},
353         {0x3808, 0x03},
354         {0x3809, 0x20},
355         {0x380a, 0x02},
356         {0x380b, 0x58},
357         {0x380c, 0x05},
358         {0x380d, 0x14},
359         {0x380e, 0x02},
360         {0x380f, 0x68},
361         {0x3811, 0x08},
362         {0x3813, 0x02},
363         {0x3814, 0x31},
364         {0x3815, 0x31},
365         {0x3a02, 0x02},
366         {0x3a03, 0x68},
367         {0x3a08, 0x00},
368         {0x3a09, 0x5c},
369         {0x3a0a, 0x00},
370         {0x3a0b, 0x4d},
371         {0x3a0d, 0x08},
372         {0x3a0e, 0x06},
373         {0x3a14, 0x02},
374         {0x3a15, 0x28},
375         {0x3623, 0x00},
376         {0x3634, 0x76},
377         {0x3701, 0x44},
378         {0x3702, 0x18},
379         {0x3703, 0x24},
380         {0x3704, 0x24},
381         {0x3705, 0x0c},
382         {0x3820, 0x81},
383         {0x3821, 0x01},
384         {0x370a, 0x52},
385         {0x4608, 0x00},
386         {0x4609, 0x80},
387         {0x5002, 0x10},
388         {0x3005, 0x18},
389         {0x3004, 0x20},
390         {0x3503,0x00},
391         {0x0100, 0x01},         //software wake
392
393         SensorEnd
394 };
395 /* 1280x720 */
396 static struct rk_sensor_reg sensor_720p[]={
397         SensorEnd
398 };
399
400 /* 1920x1080 */
401 static struct rk_sensor_reg sensor_1080p[]={
402         SensorEnd
403 };
404
405
406 static struct rk_sensor_reg sensor_softreset_data[]={
407     SensorRegVal(0x0103,0x01),
408         SensorEnd
409 };
410
411 static struct rk_sensor_reg sensor_check_id_data[]={
412     SensorRegVal(0x300a,0),
413     SensorRegVal(0x300b,0),
414         SensorEnd
415 };
416 /*
417 *  The following setting must been filled, if the function is turn on by CONFIG_SENSOR_xxxx
418 */
419 static struct rk_sensor_reg sensor_WhiteB_Auto[]=
420 {
421         {0x3406, 0x00},  //AWB auto, bit[1]:0,auto
422         SensorEnd
423 };
424 /* Cloudy Colour Temperature : 6500K - 8000K  */
425 static  struct rk_sensor_reg sensor_WhiteB_Cloudy[]=
426 {
427         {0x3406, 0x01},
428         {0x3400, 0x07},
429         {0x3401, 0x08},
430         {0x3402, 0x04},
431         {0x3403, 0x00},
432         {0x3404, 0x05},
433         {0x3405, 0x00},
434         SensorEnd
435 };
436 /* ClearDay Colour Temperature : 5000K - 6500K  */
437 static  struct rk_sensor_reg sensor_WhiteB_ClearDay[]=
438 {
439         //Sunny
440         {0x3406, 0x01},
441         {0x3400, 0x07},
442         {0x3401, 0x02},
443         {0x3402, 0x04},
444         {0x3403, 0x00},
445         {0x3404, 0x05},
446         {0x3405, 0x15},
447         SensorEnd
448 };
449 /* Office Colour Temperature : 3500K - 5000K  */
450 static  struct rk_sensor_reg sensor_WhiteB_TungstenLamp1[]=
451 {
452         //Office
453         {0x3406, 0x01},
454         {0x3400, 0x06},
455         {0x3401, 0x2a},
456         {0x3402, 0x04},
457         {0x3403, 0x00},
458         {0x3404, 0x07},
459         {0x3405, 0x24},
460         SensorEnd
461
462 };
463 /* Home Colour Temperature : 2500K - 3500K      */
464 static  struct rk_sensor_reg sensor_WhiteB_TungstenLamp2[]=
465 {
466         //Home
467         {0x3406, 0x01},
468         {0x3400, 0x04},
469         {0x3401, 0x58},
470         {0x3402, 0x04},
471         {0x3403, 0x00},
472         {0x3404, 0x07},
473         {0x3405, 0x24},
474         SensorEnd
475 };
476 static struct rk_sensor_reg *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
477         sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
478 };
479
480 static  struct rk_sensor_reg sensor_Brightness0[]=
481 {
482         // Brightness -2
483         SensorEnd
484 };
485
486 static  struct rk_sensor_reg sensor_Brightness1[]=
487 {
488         // Brightness -1
489
490         SensorEnd
491 };
492
493 static  struct rk_sensor_reg sensor_Brightness2[]=
494 {
495         //      Brightness 0
496
497         SensorEnd
498 };
499
500 static  struct rk_sensor_reg sensor_Brightness3[]=
501 {
502         // Brightness +1
503
504         SensorEnd
505 };
506
507 static  struct rk_sensor_reg sensor_Brightness4[]=
508 {
509         //      Brightness +2
510
511         SensorEnd
512 };
513
514 static  struct rk_sensor_reg sensor_Brightness5[]=
515 {
516         //      Brightness +3
517
518         SensorEnd
519 };
520 static struct rk_sensor_reg *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
521         sensor_Brightness4, sensor_Brightness5,NULL,
522 };
523
524 static  struct rk_sensor_reg sensor_Effect_Normal[] =
525 {
526         {0x507b, 0x00},
527         SensorEnd
528 };
529
530 static  struct rk_sensor_reg sensor_Effect_WandB[] =
531 {
532         {0x507b, 0x20},
533         SensorEnd
534 };
535
536 static  struct rk_sensor_reg sensor_Effect_Sepia[] =
537 {
538         {0x507b, 0x18},
539         {0x507e, 0x40},
540         {0x507f, 0xa0},
541         SensorEnd
542 };
543
544 static  struct rk_sensor_reg sensor_Effect_Negative[] =
545 {
546         //Negative
547         {0x507b, 0x40}, //bit[6] negative
548         SensorEnd
549 };
550 static  struct rk_sensor_reg sensor_Effect_Bluish[] =
551 {
552         // Bluish
553         {0x507b, 0x18},
554         {0x507e, 0xa0},
555         {0x507f, 0x40},
556         SensorEnd
557 };
558
559 static  struct rk_sensor_reg sensor_Effect_Green[] =
560 {
561         //      Greenish
562         {0x507b, 0x18},
563         {0x507e, 0x60},
564         {0x507f, 0x60},
565         SensorEnd
566 };
567 static struct rk_sensor_reg *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
568         sensor_Effect_Bluish, sensor_Effect_Green,NULL,
569 };
570
571 static  struct rk_sensor_reg sensor_Exposure0[]=
572 {
573         SensorEnd
574 };
575
576 static  struct rk_sensor_reg sensor_Exposure1[]=
577 {
578         SensorEnd
579 };
580
581 static  struct rk_sensor_reg sensor_Exposure2[]=
582 {
583         SensorEnd
584 };
585
586 static  struct rk_sensor_reg sensor_Exposure3[]=
587 {
588         SensorEnd
589 };
590
591 static  struct rk_sensor_reg sensor_Exposure4[]=
592 {
593         SensorEnd
594 };
595
596 static  struct rk_sensor_reg sensor_Exposure5[]=
597 {
598         SensorEnd
599 };
600
601 static  struct rk_sensor_reg sensor_Exposure6[]=
602 {
603         SensorEnd
604 };
605
606 static struct rk_sensor_reg *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
607         sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
608 };
609
610 static  struct rk_sensor_reg sensor_Saturation0[]=
611 {
612         SensorEnd
613 };
614
615 static  struct rk_sensor_reg sensor_Saturation1[]=
616 {
617         SensorEnd
618 };
619
620 static  struct rk_sensor_reg sensor_Saturation2[]=
621 {
622         SensorEnd
623 };
624 static struct rk_sensor_reg *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
625
626 static  struct rk_sensor_reg sensor_Contrast0[]=
627 {
628         SensorEnd
629 };
630
631 static  struct rk_sensor_reg sensor_Contrast1[]=
632 {
633         SensorEnd
634 };
635
636 static  struct rk_sensor_reg sensor_Contrast2[]=
637 {
638         SensorEnd
639 };
640
641 static  struct rk_sensor_reg sensor_Contrast3[]=
642 {
643         SensorEnd
644 };
645
646 static  struct rk_sensor_reg sensor_Contrast4[]=
647 {
648         SensorEnd
649 };
650
651
652 static  struct rk_sensor_reg sensor_Contrast5[]=
653 {
654         SensorEnd
655 };
656
657 static  struct rk_sensor_reg sensor_Contrast6[]=
658 {
659         SensorEnd
660 };
661 static struct rk_sensor_reg *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
662         sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
663 };
664 static  struct rk_sensor_reg sensor_SceneAuto[] =
665 {
666         {0x3a00, 0x78},
667         SensorEnd
668 };
669
670 static  struct rk_sensor_reg sensor_SceneNight[] =
671 {
672         {0x3003, 0x80},
673         {0x3004, 0x20},
674         {0x3005, 0x18},
675         {0x3006, 0x0d},
676         {0x3a00, 0x7c},
677         {0x3a02 ,0x07},
678         {0x3a03 ,0x38},
679         {0x3a14 ,0x07},
680         {0x3a15 ,0x38},
681         SensorEnd
682 };
683 static struct rk_sensor_reg *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
684
685 static struct rk_sensor_reg sensor_Zoom0[] =
686 {
687         SensorEnd
688 };
689
690 static struct rk_sensor_reg sensor_Zoom1[] =
691 {
692         SensorEnd
693 };
694
695 static struct rk_sensor_reg sensor_Zoom2[] =
696 {
697         SensorEnd
698 };
699
700
701 static struct rk_sensor_reg sensor_Zoom3[] =
702 {
703         SensorEnd
704 };
705 static struct rk_sensor_reg *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
706
707 /*
708 * User could be add v4l2_querymenu in sensor_controls by new_usr_v4l2menu
709 */
710 static struct v4l2_querymenu sensor_menus[] =
711 {
712 };
713 /*
714 * User could be add v4l2_queryctrl in sensor_controls by new_user_v4l2ctrl
715 */
716 static struct sensor_v4l2ctrl_usr_s sensor_controls[] =
717 {
718 };
719
720 //MUST define the current used format as the first item   
721 static struct rk_sensor_datafmt sensor_colour_fmts[] = {
722         {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
723         {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG} 
724 };
725 //static struct soc_camera_ops sensor_ops;//yzm
726
727
728 /*
729 **********************************************************
730 * Following is local code:
731
732 * Please codeing your program here 
733 **********************************************************
734 */
735 static int sensor_parameter_record(struct i2c_client *client)
736 {
737         u8 ret_l,ret_m,ret_h;
738         int tp_l,tp_m,tp_h;
739         
740         struct generic_sensor *sensor = to_generic_sensor(client);
741         struct specific_sensor *spsensor = to_specific_sensor(sensor);
742
743         sensor_read(client,0x3a00, &ret_l);
744         sensor_write(client,0x3a00, ret_l&0xfb);
745
746         sensor_write(client,0x3503,0x07);       //stop AE/AG
747
748         sensor_read(client,0x3500,&ret_h);
749         sensor_read(client,0x3501, &ret_m);
750         sensor_read(client,0x3502, &ret_l);
751         tp_l = ret_l;
752         tp_m = ret_m;
753         tp_h = ret_h;
754         spsensor->parameter.preview_exposure = ((tp_h<<12) & 0xF000) | ((tp_m<<4) & 0x0FF0) | ((tp_l>>4) & 0x0F);
755         
756         //Read back AGC Gain for preview
757         sensor_read(client,0x350b, &ret_l);
758         spsensor->parameter.preview_gain = ret_l;
759
760         spsensor->parameter.CapturePclk = 24000;
761         spsensor->parameter.PreviewPclk = 24000;
762         spsensor->parameter.PreviewDummyPixels = 0;
763         spsensor->parameter.CaptureDummyPixels = 0;
764         SENSOR_DG("Read 0x350b=0x%02x  PreviewExposure:%d 0x3500=0x%02x  0x3501=0x%02x 0x3502=0x%02x",
765                   ret_l,spsensor->parameter.preview_exposure,tp_h, tp_m, tp_l);
766         return 0;
767 }
768 #define OV2659_FULL_PERIOD_PIXEL_NUMS  (1940)  // default pixel#(w/o dummy pixels) in UXGA mode
769 #define OV2659_FULL_PERIOD_LINE_NUMS   (1238)  // default line#(w/o dummy lines) in UXGA mode
770 #define OV2659_PV_PERIOD_PIXEL_NUMS   (970)  // default pixel#(w/o dummy pixels) in SVGA mode
771 #define OV2659_PV_PERIOD_LINE_NUMS        (618)   // default line#(w/o dummy lines) in SVGA mode
772
773 /* SENSOR EXPOSURE LINE LIMITATION */
774 #define OV2659_FULL_EXPOSURE_LIMITATION   (1236)
775 #define OV2659_PV_EXPOSURE_LIMITATION     (618)
776
777 // SENSOR UXGA SIZE
778 #define OV2659_IMAGE_SENSOR_FULL_WIDTH    (1600)
779 #define OV2659_IMAGE_SENSOR_FULL_HEIGHT   (1200)
780
781 #define OV2659_FULL_GRAB_WIDTH                          (OV2659_IMAGE_SENSOR_FULL_WIDTH - 16)
782 #define OV2659_FULL_GRAB_HEIGHT                         (OV2659_IMAGE_SENSOR_FULL_HEIGHT - 12)
783 static void OV2659SetDummy(struct i2c_client *client,unsigned int dummy_pixels, unsigned int dummy_lines)
784 {
785         unsigned char val;
786         unsigned int temp_reg1, temp_reg2;
787         unsigned int temp_reg;
788         
789         if (dummy_pixels > 0)
790         {
791                 sensor_read(client,0x380D,&val);        // HTS[b7~b0]
792                 temp_reg1 = val;
793                 sensor_read(client,0x380C,&val);        // HTS[b15~b8]
794                 temp_reg2 = val;
795                 temp_reg = (temp_reg1 & 0xFF) | (temp_reg2 << 8);
796         
797                 temp_reg += dummy_pixels;
798         
799                 sensor_write(client,0x380D,(temp_reg&0xFF));             //HTS[7:0]
800                 sensor_write(client,0x380C,((temp_reg&0xFF00)>>8));  //HTS[15:8]
801         }
802
803         if (dummy_lines > 0)
804         {
805                 sensor_read(client,0x380F,&val);        // VTS[b7~b0]
806                 temp_reg1 = val;
807                 sensor_read(client,0x380E,&val);        // VTS[b15~b8]
808                 temp_reg2 = val;
809                 temp_reg = (temp_reg1 & 0xFF) | (temp_reg2 << 8);
810         
811                 temp_reg += dummy_lines;
812         
813                 sensor_write(client,0x380F,(temp_reg&0xFF));             //VTS[7:0]
814                 sensor_write(client,0x380E,((temp_reg&0xFF00)>>8));  //VTS[15:8]
815         }
816 }        /* OV2659_set_dummy */
817
818 static void OV2659WriteShutter(struct i2c_client *client,bool is_preview, unsigned int shutter)
819 {
820         unsigned int extra_exposure_lines = 0;
821
822         if (shutter < 1)
823         {
824                 shutter = 1;
825         }
826         
827         if (is_preview) 
828         {
829                 if (shutter <= OV2659_PV_EXPOSURE_LIMITATION) 
830                 {
831                         extra_exposure_lines = 0;
832                 }
833                 else 
834                 {
835                         extra_exposure_lines=shutter - OV2659_PV_EXPOSURE_LIMITATION;
836                 }
837                 
838         }
839         else 
840         {
841                 if (shutter <= OV2659_FULL_EXPOSURE_LIMITATION) 
842                 {
843                         extra_exposure_lines = 0;
844                 }
845                 else 
846                 {
847                         extra_exposure_lines = shutter - OV2659_FULL_EXPOSURE_LIMITATION;
848                 }
849                 
850         }
851         
852         //AEC PK EXPOSURE
853         shutter*=16;
854         sensor_write(client,0x3502, (shutter & 0x00FF));                   //AEC[7:0]
855         sensor_write(client,0x3501, ((shutter & 0x0FF00) >>8));  //AEC[15:8]
856         sensor_write(client,0x3500, ((shutter & 0xFF0000) >> 16));      
857         
858         if(extra_exposure_lines>0)
859         {
860                 // set extra exposure line [aec add vts]
861                 sensor_write(client,0x3507, extra_exposure_lines & 0xFF);                  // EXVTS[b7~b0]
862                 sensor_write(client,0x3506, (extra_exposure_lines & 0xFF00) >> 8); // EXVTS[b15~b8]
863         }
864         else
865         {
866                 // set extra exposure line [aec add vts]
867                 sensor_write(client,0x3507, 0x00);                      // EXVTS[b7~b0]
868                 sensor_write(client,0x3506, 0x00); // EXVTS[b15~b8]
869         }
870         
871 }        /* OV2659_write_shutter */
872 static int sensor_ae_transfer(struct i2c_client *client)
873 {
874         unsigned int prev_line_len,cap_line_len,shutter;
875         struct generic_sensor *sensor = to_generic_sensor(client);
876         struct specific_sensor *spsensor = to_specific_sensor(sensor);
877
878         mdelay(100);
879         shutter = spsensor->parameter.preview_exposure;
880
881         OV2659SetDummy(client,600,0);   
882         
883         prev_line_len = OV2659_PV_PERIOD_PIXEL_NUMS + spsensor->parameter.PreviewDummyPixels;
884         cap_line_len = OV2659_FULL_PERIOD_PIXEL_NUMS + spsensor->parameter.CaptureDummyPixels;
885         shutter = (shutter * spsensor->parameter.CapturePclk) / spsensor->parameter.PreviewPclk;
886         shutter = (shutter * prev_line_len) / cap_line_len;
887         shutter*=2;
888
889         OV2659WriteShutter(client,0,shutter);
890         
891         
892         return 0;
893 }
894 /*
895 **********************************************************
896 * Following is callback
897 * If necessary, you could coding these callback
898 **********************************************************
899 */
900 /*
901 * the function is called in open sensor  
902 */
903 static int sensor_activate_cb(struct i2c_client *client)
904 {
905     u8 reg_val;
906
907     SENSOR_DG("%s",__FUNCTION__);
908         
909         sensor_read(client,0x3000,&reg_val);
910         sensor_write(client, 0x3000, reg_val|0x03);
911         sensor_write(client, 0x3001, 0xff);
912         sensor_read(client,0x3002,&reg_val);
913         sensor_write(client, 0x3002, reg_val|0xe0);
914         
915         return 0;
916 }
917 /*
918 * the function is called in close sensor
919 */
920 static int sensor_deactivate_cb(struct i2c_client *client)
921 {
922         u8 reg_val;
923         struct generic_sensor *sensor = to_generic_sensor(client);
924
925     SENSOR_DG("%s",__FUNCTION__);
926     
927         /* ddl@rock-chips.com : all sensor output pin must switch into Hi-Z */
928         if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
929                 sensor_read(client,0x3000,&reg_val);
930                 sensor_write(client, 0x3000, reg_val&0xfc);
931                 sensor_write(client, 0x3001, 0x00);
932                 sensor_read(client,0x3002,&reg_val);
933                 sensor_write(client, 0x3002, reg_val&0x1f);
934         }
935         
936         return 0;
937 }
938 /*
939 * the function is called before sensor register setting in VIDIOC_S_FMT  
940 */
941 static int sensor_s_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
942 {
943     if (capture) {
944         sensor_parameter_record(client);
945     }
946
947     return 0;
948 }
949 /*
950 * the function is called after sensor register setting finished in VIDIOC_S_FMT  
951 */
952 static int sensor_s_fmt_cb_bh (struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)
953 {
954     if (capture) {
955         sensor_ae_transfer(client);
956     }
957     return 0;
958 }
959 static int sensor_try_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf)
960 {
961         return 0;
962 }
963
964 static int sensor_softrest_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
965 {
966         
967         return 0;
968 }
969 static int sensor_check_id_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)
970 {
971         return 0;
972 }
973
974 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
975 {
976         //struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
977                 
978         if (pm_msg.event == PM_EVENT_SUSPEND) {
979                 SENSOR_DG("Suspend");
980                 
981         } else {
982                 SENSOR_TR("pm_msg.event(0x%x) != PM_EVENT_SUSPEND\n",pm_msg.event);
983                 return -EINVAL;
984         }
985         return 0;
986 }
987
988 static int sensor_resume(struct soc_camera_device *icd)
989 {
990
991         SENSOR_DG("Resume");
992
993         return 0;
994
995 }
996 static int sensor_mirror_cb (struct i2c_client *client, int mirror)
997 {
998         char val;
999         int err = 0;
1000     
1001     SENSOR_DG("mirror: %d",mirror);
1002         if (mirror) {
1003                 err = sensor_read(client, 0x3821, &val);
1004                 if (err == 0) {
1005                         val |= 0x06;
1006                         err = sensor_write(client, 0x3821, val);
1007                 }
1008         } else {
1009                 err = sensor_read(client, 0x3821, &val);
1010                 if (err == 0) {
1011                         val &= 0xf9;
1012                         err = sensor_write(client, 0x3821, val);
1013                 }
1014         }
1015
1016         return err;    
1017 }
1018 /*
1019 * the function is v4l2 control V4L2_CID_HFLIP callback  
1020 */
1021 static int sensor_v4l2ctrl_mirror_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info, 
1022                                                      struct v4l2_ext_control *ext_ctrl)
1023 {
1024         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1025
1026     if (sensor_mirror_cb(client,ext_ctrl->value) != 0)
1027                 SENSOR_TR("sensor_mirror failed, value:0x%x",ext_ctrl->value);
1028         
1029         SENSOR_DG("sensor_mirror success, value:0x%x",ext_ctrl->value);
1030         return 0;
1031 }
1032
1033 static int sensor_flip_cb(struct i2c_client *client, int flip)
1034 {
1035         char val;
1036         int err = 0;    
1037
1038     SENSOR_DG("flip: %d",flip);
1039         if (flip) {
1040                 err = sensor_read(client, 0x3820, &val);
1041                 if (err == 0) {
1042                         val |= 0x06;
1043                         err = sensor_write(client, 0x3820, val);
1044                 }
1045         } else {
1046                 err = sensor_read(client, 0x3820, &val);
1047                 if (err == 0) {
1048                         val &= 0xf9;
1049                         err = sensor_write(client, 0x3820, val);
1050                 }
1051         }
1052
1053         return err;    
1054 }
1055 /*
1056 * the function is v4l2 control V4L2_CID_VFLIP callback  
1057 */
1058 static int sensor_v4l2ctrl_flip_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info, 
1059                                                      struct v4l2_ext_control *ext_ctrl)
1060 {
1061         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1062
1063     if (sensor_flip_cb(client,ext_ctrl->value) != 0)
1064                 SENSOR_TR("sensor_flip failed, value:0x%x",ext_ctrl->value);
1065         
1066         SENSOR_DG("sensor_flip success, value:0x%x",ext_ctrl->value);
1067         return 0;
1068 }
1069 /*
1070 * the functions are focus callbacks
1071 */
1072 static int sensor_focus_init_usr_cb(struct i2c_client *client){
1073         return 0;
1074 }
1075
1076 static int sensor_focus_af_single_usr_cb(struct i2c_client *client){
1077         return 0;
1078 }
1079
1080 static int sensor_focus_af_near_usr_cb(struct i2c_client *client){
1081         return 0;
1082 }
1083
1084 static int sensor_focus_af_far_usr_cb(struct i2c_client *client){
1085         return 0;
1086 }
1087
1088 static int sensor_focus_af_specialpos_usr_cb(struct i2c_client *client,int pos){
1089         return 0;
1090 }
1091
1092 static int sensor_focus_af_const_usr_cb(struct i2c_client *client){
1093         return 0;
1094 }
1095 static int sensor_focus_af_const_pause_usr_cb(struct i2c_client *client)
1096 {
1097     return 0;
1098 }
1099 static int sensor_focus_af_close_usr_cb(struct i2c_client *client){
1100         return 0;
1101 }
1102
1103 static int sensor_focus_af_zoneupdate_usr_cb(struct i2c_client *client, int *zone_tm_pos)
1104 {
1105     return 0;
1106 }
1107
1108 /*
1109 face defect call back
1110 */
1111 static int      sensor_face_detect_usr_cb(struct i2c_client *client,int on){
1112         return 0;
1113 }
1114
1115 /*
1116 *   The function can been run in sensor_init_parametres which run in sensor_probe, so user can do some
1117 * initialization in the function. 
1118 */
1119 static void sensor_init_parameters_user(struct specific_sensor* spsensor,struct soc_camera_device *icd)
1120 {
1121         debug_printk( "/$$$$$$$$$$$$$$$$$$$$$$//n Here I am: %s:%i-------%s()\n", __FILE__, __LINE__,__FUNCTION__);
1122     return;
1123 }
1124
1125 /*
1126 * :::::WARNING:::::
1127 * It is not allowed to modify the following code
1128 */
1129 #if 1
1130 sensor_init_parameters_default_code();
1131
1132 sensor_v4l2_struct_initialization();
1133
1134 sensor_probe_default_code();
1135
1136 sensor_remove_default_code();
1137 #endif
1138 sensor_driver_default_module_code();
1139