UPSTREAM: drm/rockchip: support non-iommu buffer path
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / sp2518.c
1 \r
2 #include "generic_sensor.h"\r
3 /*
4 *      Driver Version Note\r
5 *v0.0.1: this driver is compatible with generic_sensor\r
6 *v0.1.1:\r
7 *        add sensor_focus_af_const_pause_usr_cb;\r
8 */\r
9 static int version = KERNEL_VERSION(0,1,1);\r
10 module_param(version, int, S_IRUGO);\r
11 \r
12 \r
13 \r
14 static int debug;\r
15 module_param(debug, int, S_IRUGO|S_IWUSR);\r
16 \r
17 #define dprintk(level, fmt, arg...) do {                        \\r
18         if (debug > level)                                      \\r
19         printk(KERN_WARNING fmt , ## arg); } while (0)\r
20 \r
21 /* Sensor Driver Configuration Begin */\r
22 #define SENSOR_NAME RK29_CAM_SENSOR_SP2518\r
23 #define SENSOR_V4L2_IDENT V4L2_IDENT_SP2518\r
24 #define SENSOR_ID 0x53\r
25 #define SENSOR_BUS_PARAM                     (V4L2_MBUS_MASTER |\\r
26                                                                                                                          V4L2_MBUS_PCLK_SAMPLE_RISING|V4L2_MBUS_HSYNC_ACTIVE_HIGH| V4L2_MBUS_VSYNC_ACTIVE_HIGH|\\r
27                                                                                                                          V4L2_MBUS_DATA_ACTIVE_HIGH  |SOCAM_MCLK_24MHZ)\r
28 #define SENSOR_PREVIEW_W                     800\r
29 #define SENSOR_PREVIEW_H                     600\r
30 #define SENSOR_PREVIEW_FPS                   15000     // 15fps \r
31 #define SENSOR_FULLRES_L_FPS                 7500      // 7.5fps\r
32 #define SENSOR_FULLRES_H_FPS                 7500      // 7.5fps\r
33 #define SENSOR_720P_FPS                      0\r
34 #define SENSOR_1080P_FPS                     0\r
35 \r
36 #define SENSOR_REGISTER_LEN                  1         // sensor register address bytes\r
37 #define SENSOR_VALUE_LEN                     1         // sensor register value bytes\r
38 \r
39 static unsigned int SensorConfiguration = (CFG_WhiteBalance|CFG_Effect|CFG_Scene);\r
40 static unsigned int SensorChipID[] = {SENSOR_ID};\r
41 /* Sensor Driver Configuration End */\r
42 \r
43 \r
44 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))\r
45 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)\r
46 \r
47 #define SensorRegVal(a,b) CONS4(SensorReg,SENSOR_REGISTER_LEN,Val,SENSOR_VALUE_LEN)(a,b)\r
48 #define sensor_write(client,reg,v) CONS4(sensor_write_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))\r
49 #define sensor_read(client,reg,v) CONS4(sensor_read_reg,SENSOR_REGISTER_LEN,val,SENSOR_VALUE_LEN)(client,(reg),(v))\r
50 #define sensor_write_array generic_sensor_write_array\r
51 \r
52 struct sensor_parameter\r
53 {\r
54         unsigned int PreviewDummyPixels;\r
55         unsigned int CaptureDummyPixels;\r
56         unsigned int preview_exposure;\r
57         unsigned short int preview_line_width;\r
58         unsigned short int preview_gain;\r
59 \r
60         unsigned short int PreviewPclk;\r
61         unsigned short int CapturePclk;\r
62         char awb[6];\r
63 };\r
64 \r
65 struct specific_sensor{\r
66         struct generic_sensor common_sensor;\r
67         //define user data below\r
68         struct sensor_parameter parameter;\r
69 \r
70 };\r
71 \r
72 /*\r
73 * Local define\r
74 */\r
75 //AE
76 #define  SP2518_P0_0xf7  0x80//78\r
77 #define  SP2518_P0_0xf8  0x74//6e\r
78 #define  SP2518_P0_0xf9  0x80//74\r
79 #define  SP2518_P0_0xfa  0x74//6a\r
80 //HEQ\r
81 #define  SP2518_P0_0xdd  0x80\r
82 #define  SP2518_P0_0xde  0x95\r
83 //auto lum
84 #define SP2518_NORMAL_Y0ffset     0x10  //0x0f   modify by sp_yjp,20120813
85 #define SP2518_LOWLIGHT_Y0ffset  0x20\r
86 \r
87 /*\r
88 *  The follow setting need been filled.\r
89 *  \r
90 *  Must Filled:\r
91 *  sensor_init_data :               Sensor initial setting;\r
92 *  sensor_fullres_lowfps_data :     Sensor full resolution setting with best auality, recommand for video;\r
93 *  sensor_preview_data :            Sensor preview resolution setting, recommand it is vga or svga;\r
94 *  sensor_softreset_data :          Sensor software reset register;\r
95 *  sensor_check_id_data :           Sensir chip id register;\r
96 *\r
97 *  Optional filled:\r
98 *  sensor_fullres_highfps_data:     Sensor full resolution setting with high framerate, recommand for video;\r
99 *  sensor_720p:                     Sensor 720p setting, it is for video;\r
100 *  sensor_1080p:                    Sensor 1080p setting, it is for video;\r
101 *\r
102 *  :::::WARNING:::::\r
103 *  The SensorEnd which is the setting end flag must be filled int the last of each setting;\r
104 */\r
105 \r
106 /* Sensor initial setting */\r
107 static struct rk_sensor_reg sensor_init_data[] = {\r
108         {0xfd,0x00},
109         {0x1b,0x1a},//maximum drv ability //0x02 modify by sp_yjp,20120809
110         {0x0e,0x01},
111
112         {0x0f,0x2f},
113         {0x10,0x2e},
114         {0x11,0x00},
115         {0x12,0x4f},
116         {0x14,0x40},// 0x20 zch 20120920
117         {0x16,0x02},
118         {0x17,0x10},
119         {0x1a,0x1f},
120         {0x1e,0x81},
121         {0x21,0x00},
122         {0x22,0x1b},
123         {0x25,0x10},
124         {0x26,0x25},
125         {0x27,0x6d},
126         {0x2c,0x23},//31 Ronlus remove balck dot0x45},
127         {0x2d,0x75},
128         {0x2e,0x38},//sxga 0x18
129
130         {0x31,0x10},//mirror upside down
131         {0x44,0x03},
132         {0x6f,0x00},
133         {0xa0,0x04},
134         {0x5f,0x01},
135         {0x32,0x00},
136         {0xfd,0x01},
137         {0x2c,0x00},
138         {0x2d,0x00},
139         {0xfd,0x00},
140         {0xfb,0x83},
141         {0xf4,0x09},
142         //Pregain
143         {0xfd,0x01},
144         {0xc6,0x90},
145         {0xc7,0x90},
146         {0xc8,0x90},
147         {0xc9,0x90},
148         //blacklevel
149         {0xfd,0x00},
150         {0x65,0x08},
151         {0x66,0x08},
152         {0x67,0x08},
153         {0x68,0x08},
154
155         //bpc
156         {0x46,0xff},
157         //rpc
158         {0xfd,0x00},
159         {0xe0,0x6c},
160         {0xe1,0x54},
161         {0xe2,0x48},
162         {0xe3,0x40},
163         {0xe4,0x40},
164         {0xe5,0x3e},
165         {0xe6,0x3e},
166         {0xe8,0x3a},
167         {0xe9,0x3a},
168         {0xea,0x3a},
169         {0xeb,0x38},
170         {0xf5,0x38},
171         {0xf6,0x38},
172         {0xfd,0x01},
173         {0x94,0xc0},//f8
174         {0x95,0x38},
175         {0x9c,0x6c},
176         {0x9d,0x38},    
177         #if 0
178         ///SP2518 UXGA 24MEclk 3±¶Æµ 1·ÖƵ 50Hz fix 10fps
179         {0xfd , 0x00},
180         {0x03 , 0x03},
181         {0x04 , 0x66},
182         {0x05 , 0x00},
183         {0x06 , 0x8b},
184         {0x07 , 0x00},
185         {0x08 , 0x8b},
186         {0x09 , 0x01},
187         {0x0a , 0x3b},
188         {0x2f , 0x00},
189         {0x30 , 0x08},
190         {0xf0 , 0x91},
191         {0xf1 , 0x00},
192         {0xfd , 0x01},
193         {0x90 , 0x0a},
194         {0x92 , 0x01},
195         {0x98 , 0x91},
196         {0x99 , 0x00},
197         {0x9a , 0x01},
198         {0x9b , 0x00},
199         ///Status 
200         {0xfd , 0x01},
201         {0xce , 0xaa},
202         {0xcf , 0x05},
203         {0xd0 , 0xaa},
204         {0xd1 , 0x05},
205         {0xd7 , 0x93},//8d
206         {0xd8 , 0x00},
207         {0xd9 , 0x97},//91
208         {0xda , 0x00},
209         {0xfd , 0x00},
210         #endif
211         
212         #if 1
213         /*24*3pll 13-13fps 50hz*/
214                 
215         {0xfd,0x00},
216         {0x03,0x03},
217         {0x04,0xf6},
218         {0x05,0x00},
219         {0x06,0x00},
220         {0x07,0x00},
221         {0x08,0x00},
222         {0x09,0x00},
223         {0x0a,0x8b},
224         {0x2f,0x00},
225         {0x30,0x08},
226         {0xf0,0xa9},
227         {0xf1,0x00},
228         {0xfd,0x01},
229         {0x90,0x07},
230         {0x92,0x01},
231         {0x98,0xa9},
232         {0x99,0x00},
233         {0x9a,0x01},
234         {0x9b,0x00},
235         {0xfd,0x01},
236         {0xce,0x9f},
237         {0xcf,0x04},
238         {0xd0,0x9f},
239         {0xd1,0x04},
240         {0xd7,0xa5},
241         {0xd8,0x00},
242         {0xd9,0xa9},
243         {0xda,0x00},
244         {0xfd,0x00},
245
246         #endif
247
248         {0xfd,0x01},
249         {0xca,0x30},//mean dummy2low
250         {0xcb,0x50},//mean low2dummy
251         {0xcc,0xc0},//f8;rpc low
252         {0xcd,0xc0},//rpc dummy
253         {0xd5,0x80},//mean normal2dummy
254         {0xd6,0x90},//mean dummy2normal
255         {0xfd,0x00},  
256         
257         //lens shading 
258         {0xfd,0x00},
259         {0xa1,0x20},
260         {0xa2,0x20},
261         {0xa3,0x20},
262         {0xa4,0xff},
263         {0xa5,0x80},
264         {0xa6,0x80},
265         {0xfd,0x01},
266         {0x64,0x1e},//28
267         {0x65,0x1c},//25
268         {0x66,0x1c},//2a
269         {0x67,0x16},//25
270         {0x68,0x1c},//25
271         {0x69,0x1c},//29
272         {0x6a,0x1a},//28
273         {0x6b,0x16},//20
274         {0x6c,0x1a},//22
275         {0x6d,0x1a},//22
276         {0x6e,0x1a},//22
277         {0x6f,0x16},//1c
278         {0xb8,0x04},//0a
279         {0xb9,0x13},//0a
280         {0xba,0x00},//23
281         {0xbb,0x03},//14
282         {0xbc,0x03},//08
283         {0xbd,0x11},//08
284         {0xbe,0x00},//12
285         {0xbf,0x02},//00
286         {0xc0,0x04},//05
287         {0xc1,0x0e},//05
288         {0xc2,0x00},//18
289         {0xc3,0x05},//08   
290         //raw filter
291         {0xfd,0x01},
292         {0xde,0x0f},
293         {0xfd,0x00},
294         {0x57,0x08},//raw_dif_thr
295         {0x58,0x08},//a
296         {0x56,0x08},//a
297         {0x59,0x10},
298
299         {0x5a,0xa0},//raw_rb_fac_outdoor
300         {0xc4,0xa0},//60raw_rb_fac_indoor
301         {0x43,0xa0},//40raw_rb_fac_dummy  
302         {0xad,0x40},//raw_rb_fac_low  
303
304         {0x4f,0xa0},//raw_gf_fac_outdoor
305         {0xc3,0xa0},//60raw_gf_fac_indoor
306         {0x3f,0xa0},//40raw_gf_fac_dummy
307         {0x42,0x40},//raw_gf_fac_low
308         {0xc2,0x15},
309
310         {0xb6,0x80},//raw_gflt_fac_outdoor
311         {0xb7,0x80},//60raw_gflt_fac_normal
312         {0xb8,0x40},//40raw_gflt_fac_dummy
313         {0xb9,0x20},//raw_gflt_fac_low
314
315         {0xfd,0x01},
316         {0x50,0x0c},//raw_grgb_thr
317         {0x51,0x0c},
318         {0x52,0x10},
319         {0x53,0x10},
320         {0xfd,0x00},    
321         // awb1
322         {0xfd,0x01},
323         {0x11,0x10},
324         {0x12,0x1f},
325         {0x16,0x1c},
326         {0x18,0x00},
327         {0x19,0x00},
328         {0x1b,0x96},
329         {0x1a,0x9a},//95
330         {0x1e,0x2f},
331         {0x1f,0x29},
332         {0x20,0xff},
333         {0x22,0xff},  
334         {0x28,0xce},
335         {0x29,0x8a},
336         {0xfd,0x00},
337         {0xe7,0x03},
338         {0xe7,0x00},
339         {0xfd,0x01},
340         {0x2a,0xf0},
341         {0x2b,0x10},
342         {0x2e,0x04},
343         {0x2f,0x18},
344         {0x21,0x60},
345         {0x23,0x60},
346         {0x8b,0xab},
347         {0x8f,0x12},
348         //awb2
349         {0xfd,0x01},
350         {0x1a,0x80},
351         {0x1b,0x80},
352         {0x43,0x80},
353     //outdoor\r
354     {0x00,0xd4},\r
355     {0x01,0xb0},\r
356     {0x02,0x90},\r
357     {0x03,0x78},\r
358         //d65
359         {0x35,0xd6},//d6;b0
360         {0x36,0xf0},//f0;d1;e9
361         {0x37,0x7a},//8a;70
362         {0x38,0x9a},//dc;9a;af
363         //indoor
364         {0x39,0xab},
365         {0x3a,0xca},
366         {0x3b,0xa3},
367         {0x3c,0xc1},
368         //f
369         {0x31,0x82},//7d
370         {0x32,0xa5},//a0;74
371         {0x33,0xd6},//d2
372         {0x34,0xec},//e8
373         {0x3d,0xa5},//a7;88
374         {0x3e,0xc2},//be;bb
375         {0x3f,0xa7},//b3;ad
376         {0x40,0xc5},//c5;d0
377         //Color Correction                                
378         {0xfd,0x01},
379         {0x1c,0xc0},
380         {0x1d,0x95},
381         {0xa0,0xa6},//b8 
382         {0xa1,0xda},//;d5
383         {0xa2,0x00},//;f2
384         {0xa3,0x06},//;e8
385         {0xa4,0xb2},//;95
386         {0xa5,0xc7},//;03
387         {0xa6,0x00},//;f2
388         {0xa7,0xce},//;c4
389         {0xa8,0xb2},//;ca
390         {0xa9,0x0c},//;3c
391         {0xaa,0x30},//;03
392         {0xab,0x0c},//;0f
393         {0xac,0xc0},//b8 
394         {0xad,0xc0},//d5
395         {0xae,0x00},//f2
396         {0xaf,0xf2},//e8
397         {0xb0,0xa6},//95
398         {0xb1,0xe8},//03
399         {0xb2,0x00},//f2
400         {0xb3,0xe7},//c4
401         {0xb4,0x99},//ca
402         {0xb5,0x0c},//3c
403         {0xb6,0x33},//03
404         {0xb7,0x0c},//0f
405         //Saturation
406         {0xfd,0x00},
407         {0xbf,0x01},
408         {0xbe,0xbb},
409         {0xc0,0xb0},
410         {0xc1,0xf0},
411         
412     {0xd3,0x77},\r
413     {0xd4,0x77},\r
414     {0xd6,0x77},\r
415     {0xd7,0x77},\r
416     {0xd8,0x77},\r
417     {0xd9,0x77},\r
418     {0xda,0x77},\r
419     {0xdb,0x77},\r
420         //uv_dif
421         {0xfd,0x00},
422         {0xf3,0x03},
423         {0xb0,0x00},
424         {0xb1,0x23},
425         //gamma1
426         {0xfd,0x00},//
427         {0x8b,0x0 },//0 ;0      
428         {0x8c,0xA },//14;A 
429         {0x8d,0x13},//24;13
430         {0x8e,0x25},//3a;25
431         {0x8f,0x43},//59;43
432         {0x90,0x5D},//6f;5D
433         {0x91,0x74},//84;74
434         {0x92,0x88},//95;88
435         {0x93,0x9A},//a3;9A
436         {0x94,0xA9},//b1;A9
437         {0x95,0xB5},//be;B5
438         {0x96,0xC0},//c7;C0
439         {0x97,0xCA},//d1;CA
440         {0x98,0xD4},//d9;D4
441         {0x99,0xDD},//e1;DD
442         {0x9a,0xE6},//e9;E6
443         {0x9b,0xEF},//f1;EF
444         {0xfd,0x01},//01;01
445         {0x8d,0xF7},//f9;F7
446         {0x8e,0xFF},//ff;FF
447         //gamma2   
448         {0xfd,0x00},//
449         {0x78,0x0 },//0   
450         {0x79,0xA },//14
451         {0x7a,0x13},//24
452         {0x7b,0x25},//3a
453         {0x7c,0x43},//59
454         {0x7d,0x5D},//6f
455         {0x7e,0x74},//84
456         {0x7f,0x88},//95
457         {0x80,0x9A},//a3
458         {0x81,0xA9},//b1
459         {0x82,0xB5},//be
460         {0x83,0xC0},//c7
461         {0x84,0xCA},//d1
462         {0x85,0xD4},//d9
463         {0x86,0xDD},//e1
464         {0x87,0xE6},//e9
465         {0x88,0xEF},//f1
466         {0x89,0xF7},//f9
467         {0x8a,0xFF},//ff
468  /*//¹â°ß¹ý¶ÈºÃ
469  //gamma1
470         {0xfd,0x00},
471         {0x8b,0x00},
472         {0x8c,0x14},
473         {0x8d,0x24},
474         {0x8e,0x3A},
475         {0x8f,0x59},
476         {0x90,0x70},
477         {0x91,0x85},
478         {0x92,0x96},
479         {0x93,0xA6},
480         {0x94,0xB3},
481         {0x95,0xBE},
482         {0x96,0xC9},
483         {0x97,0xD2},
484         {0x98,0xDB},
485         {0x99,0xE3},
486         {0x9a,0xEB},
487         {0x9b,0xF2},
488         {0xfd,0x01},
489         {0x8d,0xF9},
490         {0x8e,0xFF},
491         //gamma2   
492         {0xfd,0x00},
493         {0x78,0x00},
494         {0x79,0x14},
495         {0x7a,0x24},
496         {0x7b,0x3A},
497         {0x7c,0x59},
498         {0x7d,0x70},
499         {0x7e,0x85},
500         {0x7f,0x96},
501         {0x80,0xA6},
502         {0x81,0xB3},
503         {0x82,0xBE},
504         {0x83,0xC9},
505         {0x84,0xD2},
506         {0x85,0xDB},
507         {0x86,0xE3},
508         {0x87,0xEB},
509         {0x88,0xF2},
510         {0x89,0xF9},
511         {0x8a,0xFF},    
512 */
513         //gamma_ae  
514         {0xfd,0x01},
515         {0x96,0x46},
516         {0x97,0x14},
517         {0x9f,0x06},
518         //HEQ
519         {0xfd,0x00},//
520         {0xdd,SP2518_P0_0xdd},//0x80       
521         {0xde,SP2518_P0_0xde},//a0      
522         {0xdf,0x80},//
523         //Ytarget 
524         {0xfd,0x00},// 
525         {0xec,0x70},//6a
526         {0xed,0x86},//7c
527         {0xee,0x70},//65
528         {0xef,0x86},//78
529         {0xf7,0x80},//78
530         {0xf8,0x74},//6e
531         {0xf9,0x80},//74
532         {0xfa,0x74},//6a 
533         //sharpen
534         {0xfd,0x01},
535         {0xdf,0x0f},
536         {0xe5,0x10},
537         {0xe7,0x10},
538         {0xe8,0x20},
539         {0xec,0x20},
540         {0xe9,0x20},
541         {0xed,0x20},
542         {0xea,0x10},
543         {0xef,0x10},
544         {0xeb,0x10},
545         {0xf0,0x10},
546         //;gw
547         {0xfd,0x01},//
548         {0x70,0x76},//
549         {0x7b,0x40},//
550         {0x81,0x30},//
551         //;Y_offset
552         {0xfd,0x00},
553         {0xb2,0X10},
554         {0xb3,0x1f},
555         {0xb4,0x30},
556         {0xb5,0x50},
557         //;CNR
558         {0xfd,0x00},
559         {0x5b,0x20},
560         {0x61,0x80},
561         {0x77,0x80},
562         {0xca,0x80},
563         //;YNR  
564         {0xab,0x00},
565         {0xac,0x02},
566         {0xae,0x08},
567         {0xaf,0x20},
568         {0xfd,0x00},
569         {0x31,0x10},
570         {0x32,0x0d},
571         {0x33,0xcf},//ef
572         {0x34,0x7f},//3f
573         
574         {0x35,0x40},//3        
575         
576         {0x1b,0x1a},
577         {0xe7,0x03},
578         {0xe7,0x00},\r
579         \r
580         //SVGA
581         {0xfd,0x00},    
582
583         {0x47,0x00},
584         {0x48,0x00},
585         {0x49,0x04},
586         {0x4a,0xb0},
587         
588         {0x4b,0x00},
589         {0x4c,0x00},    
590         {0x4d,0x06},
591         {0x4e,0x40},    
592         {0xfd,0x01},
593         {0x06,0x00},
594         {0x07,0x40},
595         {0x08,0x00},
596         {0x09,0x40},
597         {0x0a,0x02},    //600
598         {0x0b,0x58},
599         {0x0c,0x03},    //800
600         {0x0d,0x20},
601         {0x0e,0x01},
602         {0xfd,0x00},    \r
603         {0x5d,0x0e},    //vsync delay\r
604         \r
605         SensorEnd\r
606 };\r
607 /* Senor full resolution setting: recommand for capture */\r
608 static struct rk_sensor_reg sensor_fullres_lowfps_data[] ={\r
609 \r
610         {0xfd,0x00},    
611         {0x47,0x00},
612         {0x48,0x00},
613         {0x49,0x04},
614         {0x4a,0xb0},
615         
616         {0x4b,0x00},
617         {0x4c,0x00},    
618         {0x4d,0x06},
619         {0x4e,0x40},    
620
621         {0xfd,0x01},
622         {0x0e,0x00},
623         {0xfd,0x00},\r
624         SensorEnd\r
625 };\r
626 /* Senor full resolution setting: recommand for video */\r
627 static struct rk_sensor_reg sensor_fullres_highfps_data[] ={\r
628         SensorEnd\r
629 };\r
630 /* Preview resolution setting*/\r
631 static struct rk_sensor_reg sensor_preview_data[] =\r
632 {\r
633         {0xfd,0x00},\r
634         {0x47,0x00},
635         {0x48,0x00},
636         {0x49,0x04},
637         {0x4a,0xb0},    \r
638         {0x4b,0x00},
639         {0x4c,0x00},    
640         {0x4d,0x06},
641         {0x4e,0x40},    
642         {0xfd,0x01},
643         {0x06,0x00},
644         {0x07,0x40},
645         {0x08,0x00},
646         {0x09,0x40},
647         {0x0a,0x02},    //600
648         {0x0b,0x58},
649         {0x0c,0x03},    //800
650         {0x0d,0x20},
651         {0x0e,0x01},
652         {0xfd,0x00},\r
653 \r
654         SensorEnd\r
655 };\r
656 /* 1280x720 */\r
657 static struct rk_sensor_reg sensor_720p[]={\r
658         SensorEnd\r
659 };\r
660 \r
661 /* 1920x1080 */\r
662 static struct rk_sensor_reg sensor_1080p[]={\r
663         SensorEnd\r
664 };\r
665 \r
666 \r
667 static struct rk_sensor_reg sensor_softreset_data[]={\r
668         SensorEnd\r
669 };\r
670 \r
671 static struct rk_sensor_reg sensor_check_id_data[]={\r
672     SensorRegVal(0x02,0),\r
673         SensorEnd\r
674 };\r
675 /*\r
676 *  The following setting must been filled, if the function is turn on by CONFIG_SENSOR_xxxx\r
677 */\r
678 static struct rk_sensor_reg sensor_WhiteB_Auto[]=\r
679 {\r
680     {0xfd, 0x01}, \r
681         {0x28, 0xce},
682         {0x29, 0x8a},
683         {0xfd, 0x00},
684         {0x32, 0x0d},
685         {0xfd, 0x00},\r
686         SensorEnd\r
687 };\r
688 /* Cloudy Colour Temperature : 6500K - 8000K  */\r
689 static  struct rk_sensor_reg sensor_WhiteB_Cloudy[]=\r
690 {\r
691         {0xfd,0x00},\r
692         {0x32,0x05},
693         {0xfd,0x01},
694         {0x28,0xe2},
695         {0x29,0x82},
696         {0xfd,0x00},    
697         {0xfd,0x00},\r
698         SensorEnd\r
699 };\r
700 /* ClearDay Colour Temperature : 5000K - 6500K  */\r
701 static  struct rk_sensor_reg sensor_WhiteB_ClearDay[]=\r
702 {\r
703         {0xfd,0x00},\r
704         {0x32,0x05},
705         {0xfd,0x01},
706         {0x28,0xc1},
707         {0x29,0x88},
708         {0xfd,0x00},    
709         {0xfd,0x00},\r
710         SensorEnd\r
711 };\r
712 /* Office Colour Temperature : 3500K - 5000K  */\r
713 static  struct rk_sensor_reg sensor_WhiteB_TungstenLamp1[]=\r
714 {\r
715         {0xfd,0x00},\r
716         {0x32,0x05},
717         {0xfd,0x01},
718         {0x28,0x7b},
719         {0x29,0xd3},
720         {0xfd,0x00},
721         {0xfd,0x00},\r
722         SensorEnd\r
723 \r
724 };\r
725 /* Home Colour Temperature : 2500K - 3500K      */\r
726 static  struct rk_sensor_reg sensor_WhiteB_TungstenLamp2[]=\r
727 {\r
728         //Home\r
729         {0x3406, 0x01},\r
730         {0x3400, 0x04},\r
731         {0x3401, 0x58},\r
732         {0x3402, 0x04},\r
733         {0x3403, 0x00},\r
734         {0x3404, 0x07},\r
735         {0x3405, 0x24},\r
736         SensorEnd\r
737 };\r
738 static struct rk_sensor_reg *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,\r
739         sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,\r
740 };\r
741 \r
742 static  struct rk_sensor_reg sensor_Brightness0[]=\r
743 {\r
744         // Brightness -2\r
745         SensorEnd\r
746 };\r
747 \r
748 static  struct rk_sensor_reg sensor_Brightness1[]=\r
749 {\r
750         // Brightness -1\r
751 \r
752         SensorEnd\r
753 };\r
754 \r
755 static  struct rk_sensor_reg sensor_Brightness2[]=\r
756 {\r
757         //      Brightness 0\r
758 \r
759         SensorEnd\r
760 };\r
761 \r
762 static  struct rk_sensor_reg sensor_Brightness3[]=\r
763 {\r
764         // Brightness +1\r
765 \r
766         SensorEnd\r
767 };\r
768 \r
769 static  struct rk_sensor_reg sensor_Brightness4[]=\r
770 {\r
771         //      Brightness +2\r
772 \r
773         SensorEnd\r
774 };\r
775 \r
776 static  struct rk_sensor_reg sensor_Brightness5[]=\r
777 {\r
778         //      Brightness +3\r
779 \r
780         SensorEnd\r
781 };\r
782 static struct rk_sensor_reg *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,\r
783         sensor_Brightness4, sensor_Brightness5,NULL,\r
784 };\r
785 \r
786 static  struct rk_sensor_reg sensor_Effect_Normal[] =\r
787 {\r
788         {0xfd, 0x00},\r
789         {0x62, 0x00},
790         {0x63, 0x80},
791         {0x64, 0x80},\r
792         SensorEnd\r
793 };\r
794 \r
795 static  struct rk_sensor_reg sensor_Effect_WandB[] =\r
796 {\r
797         {0xfd, 0x00},\r
798         {0x62, 0x20},
799         {0x63, 0x80},
800         {0x64, 0x80},\r
801         SensorEnd\r
802 };\r
803 \r
804 static  struct rk_sensor_reg sensor_Effect_Sepia[] =\r
805 {\r
806         {0xfd, 0x00},\r
807         {0x62, 0x10},
808         {0x63, 0xb0},
809         {0x64, 0x40},\r
810         SensorEnd\r
811 };\r
812 \r
813 static  struct rk_sensor_reg sensor_Effect_Negative[] =\r
814 {\r
815         {0xfd, 0x00},\r
816         {0x62, 0x04},
817         {0x63, 0x80},
818         {0x64, 0x80},\r
819         SensorEnd\r
820 };\r
821 static  struct rk_sensor_reg sensor_Effect_Bluish[] =\r
822 {\r
823         {0xfd, 0x00},\r
824         {0x62, 0x10},
825         {0x63, 0x80},
826         {0x64, 0xb0},\r
827         SensorEnd\r
828 };\r
829 \r
830 static  struct rk_sensor_reg sensor_Effect_Green[] =\r
831 {\r
832         {0xfd, 0x00},\r
833         {0x62, 0x10},
834         {0x63, 0x50},
835         {0x64, 0x50},\r
836         SensorEnd\r
837 };\r
838 static struct rk_sensor_reg *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,\r
839         sensor_Effect_Bluish, sensor_Effect_Green,NULL,\r
840 };\r
841 \r
842 static  struct rk_sensor_reg sensor_Exposure0[]=\r
843 {\r
844         SensorEnd\r
845 };\r
846 \r
847 static  struct rk_sensor_reg sensor_Exposure1[]=\r
848 {\r
849         SensorEnd\r
850 };\r
851 \r
852 static  struct rk_sensor_reg sensor_Exposure2[]=\r
853 {\r
854         SensorEnd\r
855 };\r
856 \r
857 static  struct rk_sensor_reg sensor_Exposure3[]=\r
858 {\r
859         SensorEnd\r
860 };\r
861 \r
862 static  struct rk_sensor_reg sensor_Exposure4[]=\r
863 {\r
864         SensorEnd\r
865 };\r
866 \r
867 static  struct rk_sensor_reg sensor_Exposure5[]=\r
868 {\r
869         SensorEnd\r
870 };\r
871 \r
872 static  struct rk_sensor_reg sensor_Exposure6[]=\r
873 {\r
874         SensorEnd\r
875 };\r
876 \r
877 static struct rk_sensor_reg *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,\r
878         sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,\r
879 };\r
880 \r
881 static  struct rk_sensor_reg sensor_Saturation0[]=\r
882 {\r
883         SensorEnd\r
884 };\r
885 \r
886 static  struct rk_sensor_reg sensor_Saturation1[]=\r
887 {\r
888         SensorEnd\r
889 };\r
890 \r
891 static  struct rk_sensor_reg sensor_Saturation2[]=\r
892 {\r
893         SensorEnd\r
894 };\r
895 static struct rk_sensor_reg *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};\r
896 \r
897 static  struct rk_sensor_reg sensor_Contrast0[]=\r
898 {\r
899         SensorEnd\r
900 };\r
901 \r
902 static  struct rk_sensor_reg sensor_Contrast1[]=\r
903 {\r
904         SensorEnd\r
905 };\r
906 \r
907 static  struct rk_sensor_reg sensor_Contrast2[]=\r
908 {\r
909         SensorEnd\r
910 };\r
911 \r
912 static  struct rk_sensor_reg sensor_Contrast3[]=\r
913 {\r
914         SensorEnd\r
915 };\r
916 \r
917 static  struct rk_sensor_reg sensor_Contrast4[]=\r
918 {\r
919         SensorEnd\r
920 };\r
921 \r
922 \r
923 static  struct rk_sensor_reg sensor_Contrast5[]=\r
924 {\r
925         SensorEnd\r
926 };\r
927 \r
928 static  struct rk_sensor_reg sensor_Contrast6[]=\r
929 {\r
930         SensorEnd\r
931 };\r
932 static struct rk_sensor_reg *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,\r
933         sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,\r
934 };\r
935 static  struct rk_sensor_reg sensor_SceneAuto[] =\r
936 {\r
937         {0xfd, 0x00},\r
938         {0xb2,SP2518_NORMAL_Y0ffset},
939         {0xb3,0x1f},
940
941         //SP2518 UXGA 24MEclk 3PLL 50Hz fix13fps
942                 
943         {0xfd,0x00},
944         {0x03,0x03},
945         {0x04,0xf6},
946         {0x05,0x00},
947         {0x06,0x00},
948         {0x07,0x00},
949         {0x08,0x00},
950         {0x09,0x00},
951         {0x0a,0x8b},
952         {0x2f,0x00},
953         {0x30,0x08},
954         {0xf0,0xa9},
955         {0xf1,0x00},
956         {0xfd,0x01},
957         {0x90,0x07},
958         {0x92,0x01},
959         {0x98,0xa9},
960         {0x99,0x00},
961         {0x9a,0x01},
962         {0x9b,0x00},
963         {0xfd,0x01},
964         {0xce,0x9f},
965         {0xcf,0x04},
966         {0xd0,0x9f},
967         {0xd1,0x04},
968         {0xd7,0xa5},
969         {0xd8,0x00},
970         {0xd9,0xa9},
971         {0xda,0x00},
972         {0xfd,0x00},\r
973         SensorEnd\r
974 };\r
975 \r
976 static  struct rk_sensor_reg sensor_SceneNight[] =\r
977 {\r
978         {0xfd,0x00},\r
979         {0xb2,SP2518_LOWLIGHT_Y0ffset},
980         {0xb3,0x1f},
981
982         //SP2518 UXGA 24MEclk 3PLL 50Hz fix 6fps
983         {0xfd , 0x00},
984         {0x03 , 0x01},
985         {0x04 , 0xfe},
986         {0x05 , 0x00},
987         {0x06 , 0x6d},
988         {0x07 , 0x00},
989         {0x08 , 0x6d},
990         {0x09 , 0x04},
991         {0x0a , 0xa8},
992         {0xf0 , 0x55},
993         {0xf1 , 0x00},
994         {0xfd , 0x01},
995         {0x90 , 0x10},
996         {0x92 , 0x01},
997         {0x98 , 0x55},
998         {0x99 , 0x00},
999         {0x9a , 0x01},
1000         {0x9b , 0x00},
1001         ///Status   
1002         {0xfd , 0x01},
1003         {0xce , 0x50},
1004         {0xcf , 0x05},
1005         {0xd0 , 0x50},
1006         {0xd1 , 0x05},
1007         {0xd7 , 0x57},//51
1008         {0xd8 , 0x00},
1009         {0xd9 , 0x5b},//55
1010         {0xda , 0x00},\r
1011          
1012         {0xfd,0x00},\r
1013         SensorEnd\r
1014 };\r
1015 static struct rk_sensor_reg *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};\r
1016 \r
1017 static struct rk_sensor_reg sensor_Zoom0[] =\r
1018 {\r
1019         SensorEnd\r
1020 };\r
1021 \r
1022 static struct rk_sensor_reg sensor_Zoom1[] =\r
1023 {\r
1024         SensorEnd\r
1025 };\r
1026 \r
1027 static struct rk_sensor_reg sensor_Zoom2[] =\r
1028 {\r
1029         SensorEnd\r
1030 };\r
1031 \r
1032 \r
1033 static struct rk_sensor_reg sensor_Zoom3[] =\r
1034 {\r
1035         SensorEnd\r
1036 };\r
1037 static struct rk_sensor_reg *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};\r
1038 \r
1039 /*\r
1040 * User could be add v4l2_querymenu in sensor_controls by new_usr_v4l2menu\r
1041 */\r
1042 static struct v4l2_querymenu sensor_menus[] =\r
1043 {\r
1044 };\r
1045 /*\r
1046 * User could be add v4l2_queryctrl in sensor_controls by new_user_v4l2ctrl\r
1047 */\r
1048 static struct sensor_v4l2ctrl_usr_s sensor_controls[] =\r
1049 {\r
1050 };\r
1051 \r
1052 //MUST define the current used format as the first item   \r
1053 static struct rk_sensor_datafmt sensor_colour_fmts[] = {\r
1054         {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG} \r
1055 };\r
1056 /*static struct soc_camera_ops sensor_ops;*/\r
1057 \r
1058 \r
1059 /*\r
1060 **********************************************************\r
1061 * Following is local code:\r
1062\r
1063 * Please codeing your program here \r
1064 **********************************************************\r
1065 */\r
1066 \r
1067 /*\r
1068 **********************************************************\r
1069 * Following is callback\r
1070 * If necessary, you could coding these callback\r
1071 **********************************************************\r
1072 */\r
1073 /*\r
1074 * the function is called in open sensor  \r
1075 */\r
1076 static int sensor_activate_cb(struct i2c_client *client)\r
1077 {\r
1078 \r
1079     SENSOR_DG("%s",__FUNCTION__);       \r
1080 \r
1081         \r
1082         return 0;\r
1083 }\r
1084 /*\r
1085 * the function is called in close sensor\r
1086 */\r
1087 static int sensor_deactivate_cb(struct i2c_client *client)\r
1088 {\r
1089         //struct generic_sensor *sensor = to_generic_sensor(client);\r
1090 \r
1091     SENSOR_DG("%s",__FUNCTION__);\r
1092     \r
1093         return 0;\r
1094 }\r
1095 /*\r
1096 * the function is called before sensor register setting in VIDIOC_S_FMT  \r
1097 */\r
1098 static int sensor_s_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)\r
1099 {\r
1100     return 0;\r
1101 }\r
1102 /*\r
1103 * the function is called after sensor register setting finished in VIDIOC_S_FMT  \r
1104 */\r
1105 static int sensor_s_fmt_cb_bh (struct i2c_client *client,struct v4l2_mbus_framefmt *mf, bool capture)\r
1106 {\r
1107     return 0;\r
1108 }\r
1109 static int sensor_softrest_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)\r
1110 {\r
1111         \r
1112         return 0;\r
1113 }\r
1114 static int sensor_check_id_usr_cb(struct i2c_client *client,struct rk_sensor_reg *series)\r
1115 {\r
1116         return 0;\r
1117 }\r
1118 static int sensor_try_fmt_cb_th(struct i2c_client *client,struct v4l2_mbus_framefmt *mf)
1119 {
1120         return 0;
1121 }
1122
1123 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)\r
1124 {\r
1125         //struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
1126                 \r
1127         if (pm_msg.event == PM_EVENT_SUSPEND) {\r
1128                 SENSOR_DG("Suspend");\r
1129                 \r
1130         } else {\r
1131                 SENSOR_TR("pm_msg.event(0x%x) != PM_EVENT_SUSPEND\n",pm_msg.event);\r
1132                 return -EINVAL;\r
1133         }\r
1134         return 0;\r
1135 }\r
1136 \r
1137 static int sensor_resume(struct soc_camera_device *icd)\r
1138 {\r
1139 \r
1140         SENSOR_DG("Resume");\r
1141 \r
1142         return 0;\r
1143 \r
1144 }\r
1145 static int sensor_mirror_cb (struct i2c_client *client, int mirror)\r
1146 {\r
1147         int err = 0;\r
1148     \r
1149     SENSOR_DG("mirror: %d",mirror);\r
1150         \r
1151 \r
1152         return err;    \r
1153 }\r
1154 /*\r
1155 * the function is v4l2 control V4L2_CID_HFLIP callback  \r
1156 */\r
1157 static int sensor_v4l2ctrl_mirror_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info, \r
1158                                                      struct v4l2_ext_control *ext_ctrl)\r
1159 {\r
1160         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
1161 \r
1162     if (sensor_mirror_cb(client,ext_ctrl->value) != 0)\r
1163                 SENSOR_TR("sensor_mirror failed, value:0x%x",ext_ctrl->value);\r
1164         \r
1165         SENSOR_DG("sensor_mirror success, value:0x%x",ext_ctrl->value);\r
1166         return 0;\r
1167 }\r
1168 \r
1169 static int sensor_flip_cb(struct i2c_client *client, int flip)\r
1170 {\r
1171         int err = 0;    \r
1172 \r
1173     SENSOR_DG("flip: %d",flip);\r
1174         \r
1175         return err;    \r
1176 }\r
1177 /*\r
1178 * the function is v4l2 control V4L2_CID_VFLIP callback  \r
1179 */\r
1180 static int sensor_v4l2ctrl_flip_cb(struct soc_camera_device *icd, struct sensor_v4l2ctrl_info_s *ctrl_info, \r
1181                                                      struct v4l2_ext_control *ext_ctrl)\r
1182 {\r
1183         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));\r
1184 \r
1185     if (sensor_flip_cb(client,ext_ctrl->value) != 0)\r
1186                 SENSOR_TR("sensor_flip failed, value:0x%x",ext_ctrl->value);\r
1187         \r
1188         SENSOR_DG("sensor_flip success, value:0x%x",ext_ctrl->value);\r
1189         return 0;\r
1190 }\r
1191 /*\r
1192 * the functions are focus callbacks\r
1193 */\r
1194 static int sensor_focus_init_usr_cb(struct i2c_client *client){\r
1195         return 0;\r
1196 }\r
1197 \r
1198 static int sensor_focus_af_single_usr_cb(struct i2c_client *client){\r
1199         return 0;\r
1200 }\r
1201 \r
1202 static int sensor_focus_af_near_usr_cb(struct i2c_client *client){\r
1203         return 0;\r
1204 }\r
1205 \r
1206 static int sensor_focus_af_far_usr_cb(struct i2c_client *client){\r
1207         return 0;\r
1208 }\r
1209 \r
1210 static int sensor_focus_af_specialpos_usr_cb(struct i2c_client *client,int pos){\r
1211         return 0;\r
1212 }\r
1213 \r
1214 static int sensor_focus_af_const_usr_cb(struct i2c_client *client){\r
1215         return 0;\r
1216 }\r
1217 static int sensor_focus_af_const_pause_usr_cb(struct i2c_client *client)
1218 {
1219     return 0;
1220 }\r
1221 static int sensor_focus_af_close_usr_cb(struct i2c_client *client){\r
1222         return 0;\r
1223 }\r
1224 \r
1225 static int sensor_focus_af_zoneupdate_usr_cb(struct i2c_client *client, int *zone_tm_pos)\r
1226 {\r
1227         return 0;\r
1228 }\r
1229 \r
1230 /*\r
1231 face defect call back\r
1232 */\r
1233 static int      sensor_face_detect_usr_cb(struct i2c_client *client,int on){\r
1234         return 0;\r
1235 }\r
1236 \r
1237 /*\r
1238 *   The function can been run in sensor_init_parametres which run in sensor_probe, so user can do some\r
1239 * initialization in the function. \r
1240 */\r
1241 static void sensor_init_parameters_user(struct specific_sensor* spsensor,struct soc_camera_device *icd)\r
1242 {\r
1243     return;\r
1244 }\r
1245 \r
1246 /*\r
1247 * :::::WARNING:::::\r
1248 * It is not allowed to modify the following code\r
1249 */\r
1250 \r
1251 sensor_init_parameters_default_code();\r
1252 \r
1253 sensor_v4l2_struct_initialization();\r
1254 \r
1255 sensor_probe_default_code();\r
1256 \r
1257 sensor_remove_default_code();\r
1258 \r
1259 sensor_driver_default_module_code();\r
1260 \r
1261 \r