camera driver v0.2.1 for RK30
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / ov5642.c
1 /*
2  * Driver for OV5642 CMOS Image Sensor from OmniVision
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 <mach/rk_camera.h>
23 #include <linux/vmalloc.h>
24 #include "ov5642.h"
25
26 static int debug;
27 module_param(debug, int, S_IRUGO|S_IWUSR);
28
29 #define dprintk(level, fmt, arg...) do {                        \
30         if (debug >= level)                                     \
31         printk(KERN_WARNING fmt , ## arg); } while (0)
32
33 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
34 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
38
39 #define __STR(x) #x
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
42
43 #define MIN(x,y)   ((x<y) ? x: y)
44 #define MAX(x,y)    ((x>y) ? x: y)
45
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK_CAM_SENSOR_OV5642
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV5642
49 #define SENSOR_ID 0x5642
50 #define SENSOR_MIN_WIDTH    176
51 #define SENSOR_MIN_HEIGHT   144
52 #define SENSOR_MAX_WIDTH    2592
53 #define SENSOR_MAX_HEIGHT   1944
54 #define SENSOR_INIT_WIDTH       sensor_init_width                       /* Sensor pixel size for sensor_init_data array */
55 #define SENSOR_INIT_HEIGHT  sensor_init_height
56 #define SENSOR_INIT_WINSEQADR  sensor_init_winseq_p
57 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
58 #define SENSOR_BUS_PARAM  sensor_init_busparam
59
60 #define CONFIG_SENSOR_WhiteBalance      1
61 #define CONFIG_SENSOR_Brightness        0
62 #define CONFIG_SENSOR_Contrast      0
63 #define CONFIG_SENSOR_Saturation    0
64 #define CONFIG_SENSOR_Effect        1
65 #define CONFIG_SENSOR_Scene         1
66 #define CONFIG_SENSOR_DigitalZoom   0
67 #define CONFIG_SENSOR_Exposure      0
68 #define CONFIG_SENSOR_Flash         1
69 #define CONFIG_SENSOR_Mirror        0
70 #define CONFIG_SENSOR_Flip          0
71 #ifdef CONFIG_OV5642_AUTOFOCUS
72 #define CONFIG_SENSOR_Focus         1
73 #include "ov5642_af_firmware.c"
74 #else
75 #define CONFIG_SENSOR_Focus         0
76 #endif
77
78 #define CONFIG_SENSOR_I2C_SPEED     250000       /* Hz */
79 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
80 #define CONFIG_SENSOR_I2C_NOSCHED   0
81 #define CONFIG_SENSOR_I2C_RDWRCHK   0
82
83 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
84 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
85 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
86 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
87 #define COLOR_TEMPERATURE_OFFICE_DN     3500
88 #define COLOR_TEMPERATURE_OFFICE_UP     5000
89 #define COLOR_TEMPERATURE_HOME_DN       2500
90 #define COLOR_TEMPERATURE_HOME_UP       3500
91
92 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
93 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
94
95 #define SENSOR_AF_IS_ERR    (0x00<<0)
96 #define SENSOR_AF_IS_OK         (0x01<<0)
97 #define SENSOR_INIT_IS_ERR   (0x00<<28)
98 #define SENSOR_INIT_IS_OK    (0x01<<28)
99
100 #if CONFIG_SENSOR_Focus
101 #define SENSOR_AF_MODE_INFINITY    0
102 #define SENSOR_AF_MODE_MACRO       1
103 #define SENSOR_AF_MODE_FIXED       2
104 #define SENSOR_AF_MODE_AUTO        3
105 #define SENSOR_AF_MODE_CONTINUOUS  4
106 #define SENSOR_AF_MODE_CLOSE       5
107 #endif
108
109 #if CONFIG_SENSOR_Focus
110 /* ov5642 VCM Command and Status Registers */
111 #define CMD_MAIN_Reg      0x3024
112 #define CMD_TAG_Reg       0x3025
113 #define CMD_PARA0_Reg     0x5085
114 #define CMD_PARA1_Reg     0x5084
115 #define CMD_PARA2_Reg     0x5083
116 #define CMD_PARA3_Reg     0x5082
117 #define STA_ZONE_Reg      0x3026
118 #define STA_FOCUS_Reg     0x3027
119
120 /* ov5642 VCM Command  */
121 #define OverlayEn_Cmd     0x01
122 #define OverlayDis_Cmd    0x02
123 #define SingleFocus_Cmd   0x03
124 #define ConstFocus_Cmd    0x04
125 #define StepMode_Cmd      0x05
126 #define PauseFocus_Cmd    0x06
127 #define ReturnIdle_Cmd    0x08
128 #define SetZone_Cmd       0x10
129 #define UpdateZone_Cmd    0x12
130 #define SetMotor_Cmd      0x20
131
132 /* ov5642 Focus State */
133 #define S_FIRWRE          0xFF
134 #define S_STARTUP         0xfa
135 #define S_ERROR           0xfe
136 #define S_DRVICERR        0xee
137 #define S_IDLE            0x00
138 #define S_FOCUSING        0x01
139 #define S_FOCUSED         0x02
140 #define S_CAPTURE         0x12
141 #define S_STEP            0x20
142
143 /* ov5642 Zone State */
144 #define Zone_Is_Focused(a, zone_val)    (zone_val&(1<<(a-3)))
145 #define Zone_Get_ID(zone_val)           (zone_val&0x03)
146
147 #define Zone_CenterMode   0x01
148 #define Zone_5xMode       0x02
149 #define Zone_5PlusMode    0x03
150 #define Zone_4fMode       0x04
151
152 #define ZoneSel_Auto      0x0b
153 #define ZoneSel_SemiAuto  0x0c
154 #define ZoneSel_Manual    0x0d
155 #define ZoneSel_Rotate    0x0e
156
157 /* ov5642 Step Focus Commands */
158 #define StepFocus_Near_Tag       0x01
159 #define StepFocus_Far_Tag        0x02
160 #define StepFocus_Furthest_Tag   0x03
161 #define StepFocus_Nearest_Tag    0x04
162 #define StepFocus_Spec_Tag       0x10
163 #endif
164
165 static s32 sensor_init_height = 0;
166 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ);
167 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
168 static struct reginfo* sensor_init_data_p = NULL;
169 static struct reginfo* sensor_init_winseq_p = NULL;
170 static struct reginfo* sensor_init_winseq_board = NULL;
171 /* init 800X600 SVGA */
172 static struct reginfo sensor_init_data[] =
173 {
174     {0x3103 , 0x93},
175     {0x3008 , 0x82},
176     {0x3017 , 0x7f},
177     {0x3018 , 0xfc},
178     {0x3810 , 0xc2},
179     {0x3615 , 0xf0},
180     {0x3000 , 0x00},
181     {0x3001 , 0x00},
182     {0x3002 , 0x00},
183     {0x3003 , 0x00},
184     {0x3000 , 0xf8},
185     {0x3001 , 0x48},
186     {0x3002 , 0x5c},
187     {0x3003 , 0x02},
188     {0x3004 , 0x07},
189     {0x3005 , 0xb7},
190     {0x3006 , 0x43},
191     {0x3007 , 0x37},
192     {0x3011 , 0x08},
193     {0x3010 , 0x10},
194     {0x460c , 0x22},
195     {0x3815 , 0x04},
196     {0x370d , 0x06},
197     {0x370c , 0xa0},
198     {0x3602 , 0xfc},
199     {0x3612 , 0xff},
200     {0x3634 , 0xc0},
201     {0x3613 , 0x00},
202     {0x3605 , 0x7c},
203     {0x3621 , 0x09},
204     {0x3622 , 0x00},
205     {0x3604 , 0x40},
206     {0x3603 , 0xa7},
207     {0x3603 , 0x27},
208     {0x4000 , 0x21},
209     {0x401d , 0x02},
210     {0x3600 , 0x54},
211     {0x3605 , 0x04},
212     {0x3606 , 0x3f},
213     {0x3c01 , 0x80},
214     {0x5000 , 0x4f},
215     {0x5020 , 0x04},
216     {0x5181 , 0x79},
217     {0x5182 , 0x00},
218     {0x5185 , 0x22},
219     {0x5197 , 0x01},
220     {0x5001 , 0xff},
221     {0x5500 , 0x0a},
222     {0x5504 , 0x00},
223     {0x5505 , 0x7f},
224     {0x5080 , 0x08},
225     {0x300e , 0x18},
226     {0x4610 , 0x00},
227     {0x471d , 0x05},
228     {0x4708 , 0x06},
229     {0x3710 , 0x10},
230     {0x3632 , 0x41},
231     {0x3702 , 0x40},
232     {0x3620 , 0x37},
233     {0x3631 , 0x01},
234     {0x3808 , 0x02},
235     {0x3809 , 0x80},
236     {0x380a , 0x01},
237     {0x380b , 0xe0},
238     {0x380e , 0x07},
239     {0x380f , 0xd0},
240     {0x501f , 0x00},
241     {0x5000 , 0x4f},
242     {0x4300 , 0x32},   //UYVY
243     {0x3503 , 0x07},
244     {0x3501 , 0x73},
245     {0x3502 , 0x80},
246     {0x350b , 0x00},
247     {0x3503 , 0x07},
248     {0x3824 , 0x11},
249     {0x3501 , 0x1e},
250     {0x3502 , 0x80},
251     {0x350b , 0x7f},
252     {0x380c , 0x0c},
253     {0x380d , 0x80},
254     {0x380e , 0x03},
255     {0x380f , 0xe8},
256     {0x3a0d , 0x04},
257     {0x3a0e , 0x03},
258     {0x3818 , 0xc1},
259     {0x3705 , 0xdb},
260     {0x370a , 0x81},
261     {0x3801 , 0x80},
262     {0x3621 , 0xc7},
263     {0x3801 , 0x50},
264     {0x3803 , 0x08},
265     {0x3827 , 0x08},
266     {0x3810 , 0xc0},
267     {0x3804 , 0x05},
268     {0x3805 , 0x00},
269     {0x5682 , 0x05},
270     {0x5683 , 0x00},
271     {0x3806 , 0x03},
272     {0x3807 , 0xc0},
273     {0x5686 , 0x03},
274     {0x5687 , 0xc0},
275     {0x3a00 , 0x78},
276     {0x3a1a , 0x04},
277     {0x3a13 , 0x30},
278     {0x3a18 , 0x00},
279     {0x3a19 , 0x7c},
280     {0x3a08 , 0x12},
281     {0x3a09 , 0xc0},
282     {0x3a0a , 0x0f},
283     {0x3a0b , 0xa0},
284     {0x3004 , 0xff},
285     {0x350c , 0x07},
286     {0x350d , 0xd0},
287     {0x3500 , 0x00},
288     {0x3501 , 0x00},
289     {0x3502 , 0x00},
290     {0x350a , 0x00},
291     {0x350b , 0x00},
292     {0x3503 , 0x00},
293     {0x528a , 0x02},
294     {0x528b , 0x04},
295     {0x528c , 0x08},
296     {0x528d , 0x08},
297     {0x528e , 0x08},
298     {0x528f , 0x10},
299     {0x5290 , 0x10},
300     {0x5292 , 0x00},
301     {0x5293 , 0x02},
302     {0x5294 , 0x00},
303     {0x5295 , 0x02},
304     {0x5296 , 0x00},
305     {0x5297 , 0x02},
306     {0x5298 , 0x00},
307     {0x5299 , 0x02},
308     {0x529a , 0x00},
309     {0x529b , 0x02},
310     {0x529c , 0x00},
311     {0x529d , 0x02},
312     {0x529e , 0x00},
313     {0x529f , 0x02},
314     {0x3a0f , 0x3c},
315     {0x3a10 , 0x30},
316     {0x3a1b , 0x3c},
317     {0x3a1e , 0x30},
318     {0x3a11 , 0x70},
319     {0x3a1f , 0x10},
320     {0x3030 , 0x0b},
321     {0x3a02 , 0x00},
322     {0x3a03 , 0x7d},
323     {0x3a04 , 0x00},
324     {0x3a14 , 0x00},
325     {0x3a15 , 0x7d},
326     {0x3a16 , 0x00},
327     {0x3a00 , 0x78},
328     {0x3a08 , 0x09},
329     {0x3a09 , 0x60},
330     {0x3a0a , 0x07},
331     {0x3a0b , 0xd0},
332     {0x3a0d , 0x08},
333     {0x3a0e , 0x06},
334     {0x5193 , 0x70},
335     {0x3620 , 0x57},
336     {0x3703 , 0x98},
337     {0x3704 , 0x1c},
338     {0x589b , 0x04},
339     {0x589a , 0xc5},
340     {0x528a , 0x00},
341     {0x528b , 0x02},
342     {0x528c , 0x08},
343     {0x528d , 0x10},
344     {0x528e , 0x20},
345     {0x528f , 0x28},
346     {0x5290 , 0x30},
347     {0x5292 , 0x00},
348     {0x5293 , 0x00},
349     {0x5294 , 0x00},
350     {0x5295 , 0x02},
351     {0x5296 , 0x00},
352     {0x5297 , 0x08},
353     {0x5298 , 0x00},
354     {0x5299 , 0x10},
355     {0x529a , 0x00},
356     {0x529b , 0x20},
357     {0x529c , 0x00},
358     {0x529d , 0x28},
359     {0x529e , 0x00},
360     {0x529f , 0x30},
361     {0x5282 , 0x00},
362     {0x5300 , 0x00},
363     {0x5301 , 0x20},
364     {0x5302 , 0x00},
365     {0x5303 , 0x7c},
366     {0x530c , 0x00},
367     {0x530d , 0x0c},
368     {0x530e , 0x20},
369     {0x530f , 0x80},
370     {0x5310 , 0x20},
371     {0x5311 , 0x80},
372     {0x5308 , 0x20},
373     {0x5309 , 0x40},
374     {0x5304 , 0x00},
375     {0x5305 , 0x30},
376     {0x5306 , 0x00},
377     {0x5307 , 0x80},
378     {0x5314 , 0x08},
379     {0x5315 , 0x20},
380     {0x5319 , 0x30},
381     {0x5316 , 0x10},
382     {0x5317 , 0x08},
383     {0x5318 , 0x02},
384     {0x5380 , 0x01},
385     {0x5381 , 0x00},
386     {0x5382 , 0x00},
387     {0x5383 , 0x4e},
388     {0x5384 , 0x00},
389     {0x5385 , 0x0f},
390     {0x5386 , 0x00},
391     {0x5387 , 0x00},
392     {0x5388 , 0x01},
393     {0x5389 , 0x15},
394     {0x538a , 0x00},
395     {0x538b , 0x31},
396     {0x538c , 0x00},
397     {0x538d , 0x00},
398     {0x538e , 0x00},
399     {0x538f , 0x0f},
400     {0x5390 , 0x00},
401     {0x5391 , 0xab},
402     {0x5392 , 0x00},
403     {0x5393 , 0xa2},
404     {0x5394 , 0x08},
405     {0x5480 , 0x14},
406     {0x5481 , 0x21},
407     {0x5482 , 0x36},
408     {0x5483 , 0x57},
409     {0x5484 , 0x65},
410     {0x5485 , 0x71},
411     {0x5486 , 0x7d},
412     {0x5487 , 0x87},
413     {0x5488 , 0x91},
414     {0x5489 , 0x9a},
415     {0x548a , 0xaa},
416     {0x548b , 0xb8},
417     {0x548c , 0xcd},
418     {0x548d , 0xdd},
419     {0x548e , 0xea},
420     {0x548f , 0x10},
421     {0x5490 , 0x05},
422     {0x5491 , 0x00},
423     {0x5492 , 0x04},
424     {0x5493 , 0x20},
425     {0x5494 , 0x03},
426     {0x5495 , 0x60},
427     {0x5496 , 0x02},
428     {0x5497 , 0xb8},
429     {0x5498 , 0x02},
430     {0x5499 , 0x86},
431     {0x549a , 0x02},
432     {0x549b , 0x5b},
433     {0x549c , 0x02},
434     {0x549d , 0x3b},
435     {0x549e , 0x02},
436     {0x549f , 0x1c},
437     {0x54a0 , 0x02},
438     {0x54a1 , 0x04},
439     {0x54a2 , 0x01},
440     {0x54a3 , 0xed},
441     {0x54a4 , 0x01},
442     {0x54a5 , 0xc5},
443     {0x54a6 , 0x01},
444     {0x54a7 , 0xa5},
445     {0x54a8 , 0x01},
446     {0x54a9 , 0x6c},
447     {0x54aa , 0x01},
448     {0x54ab , 0x41},
449     {0x54ac , 0x01},
450     {0x54ad , 0x20},
451     {0x54ae , 0x00},
452     {0x54af , 0x16},
453     {0x3406 , 0x00},
454     {0x5192 , 0x04},
455     {0x5191 , 0xf8},
456     {0x5193 , 0x70},
457     {0x5194 , 0xf0},
458     {0x5195 , 0xf0},
459     {0x518d , 0x3d},
460     {0x518f , 0x54},
461     {0x518e , 0x3d},
462     {0x5190 , 0x54},
463     {0x518b , 0xc0},
464     {0x518c , 0xbd},
465     {0x5187 , 0x18},
466     {0x5188 , 0x18},
467     {0x5189 , 0x6e},
468     {0x518a , 0x68},
469     {0x5186 , 0x1c},
470     {0x5181 , 0x50},
471     {0x5184 , 0x25},
472     {0x5182 , 0x11},
473     {0x5183 , 0x14},
474     {0x5184 , 0x25},
475     {0x5185 , 0x24},
476     {0x5025 , 0x82},
477     {0x3a0f , 0x7e},
478     {0x3a10 , 0x72},
479     {0x3a1b , 0x80},
480     {0x3a1e , 0x70},
481     {0x3a11 , 0xd0},
482     {0x3a1f , 0x40},
483     {0x5583 , 0x40},
484     {0x5584 , 0x40},
485     {0x5580 , 0x02},
486     {0x3633 , 0x07},
487     {0x3702 , 0x10},
488     {0x3703 , 0xb2},
489     {0x3704 , 0x18},
490     {0x370b , 0x40},
491     {0x370d , 0x02},
492     {0x3620 , 0x52},
493     {0x3c00 , 0x04},
494
495         {0x5001,0xFF},
496         {0x5583,0x50},
497         {0x5584,0x50},
498         {0x5580,0x02},
499         {0x3c01,0x80},
500         {0x3c00,0x04},
501         {0x5800,0x27},
502         {0x5801,0x22},
503         {0x5802,0x1b},
504         {0x5803,0x17},
505         {0x5804,0x16},
506         {0x5805,0x18},
507         {0x5806,0x20},
508         {0x5807,0x20},
509         {0x5808,0x1b},
510         {0x5809,0x15},
511         {0x580a,0x0f},
512         {0x580b,0x0d},
513         {0x580c,0x0d},
514         {0x580d,0x0e},
515         {0x580e,0x11},
516         {0x580f,0x18},
517         {0x5810,0x10},
518         {0x5811,0x0d},
519         {0x5812,0x08},
520         {0x5813,0x05},
521         {0x5814,0x04},
522         {0x5815,0x06},
523         {0x5816,0x09},
524         {0x5817,0x0e},
525         {0x5818,0x0d},
526         {0x5819,0x09},
527         {0x581a,0x03},
528         {0x581b,0x00},
529         {0x581c,0x00},
530         {0x581d,0x01},
531         {0x581e,0x05},
532         {0x581f,0x0b},
533         {0x5820,0x0d},
534         {0x5821,0x09},
535         {0x5822,0x03},
536         {0x5823,0x00},
537         {0x5824,0x00},
538         {0x5825,0x01},
539         {0x5826,0x05},
540         {0x5827,0x0b},
541         {0x5828,0x10},
542         {0x5829,0x0c},
543         {0x582a,0x08},
544         {0x582b,0x04},
545         {0x582c,0x03},
546         {0x582d,0x05},
547         {0x582e,0x09},
548         {0x582f,0x0e},
549         {0x5830,0x1b},
550         {0x5831,0x14},
551         {0x5832,0x0f},
552         {0x5833,0x0c},
553         {0x5834,0x0c},
554         {0x5835,0x0d},
555         {0x5836,0x10},
556         {0x5837,0x19},
557         {0x5838,0x25},
558         {0x5839,0x23},
559         {0x583a,0x1a},
560         {0x583b,0x16},
561         {0x583c,0x15},
562         {0x583d,0x18},
563         {0x583e,0x1f},
564         {0x583f,0x25},
565         {0x5840,0x10},
566         {0x5841,0x0e},
567         {0x5842,0x0e},
568         {0x5843,0x0e},
569         {0x5844,0x0f},
570         {0x5845,0x0a},
571         {0x5846,0x08},
572         {0x5847,0x0f},
573         {0x5848,0x0f},
574         {0x5849,0x0f},
575         {0x584a,0x0c},
576         {0x584b,0x0f},
577         {0x584c,0x09},
578         {0x584d,0x10},
579         {0x584e,0x11},
580         {0x584f,0x10},
581         {0x5850,0x0f},
582         {0x5851,0x0e},
583         {0x5852,0x08},
584         {0x5853,0x10},
585         {0x5854,0x10},
586         {0x5855,0x10},
587         {0x5856,0x0e},
588         {0x5857,0x0e},
589         {0x5858,0x0a},
590         {0x5859,0x0e},
591         {0x585a,0x0e},
592         {0x585b,0x0e},
593         {0x585c,0x0e},
594         {0x585d,0x0d},
595         {0x585e,0x08},
596         {0x585f,0x0b},
597         {0x5860,0x0a},
598         {0x5861,0x0a},
599         {0x5862,0x09},
600         {0x5863,0x0d},
601         {0x5864,0x13},
602         {0x5865,0x0e},
603         {0x5866,0x10},
604         {0x5867,0x10},
605         {0x5868,0x0e},
606         {0x5869,0x11},
607         {0x586a,0x12},
608         {0x586b,0x10},
609         {0x586c,0x10},
610         {0x586d,0x10},
611         {0x586e,0x10},
612         {0x586f,0x11},
613         {0x5870,0x15},
614         {0x5871,0x10},
615         {0x5872,0x10},
616         {0x5873,0x10},
617         {0x5874,0x11},
618         {0x5875,0x11},
619         {0x5876,0x14},
620         {0x5877,0x0f},
621         {0x5878,0x10},
622         {0x5879,0x10},
623         {0x587a,0x10},
624         {0x587b,0x11},
625         {0x587c,0x12},
626         {0x587d,0x0f},
627         {0x587e,0x0f},
628         {0x587f,0x10},
629         {0x5880,0x10},
630         {0x5881,0x0f},
631         {0x5882,0x12},
632         {0x5883,0x0e},
633         {0x5884,0x10},
634         {0x5885,0x10},
635         {0x5886,0x0e},
636         {0x5887,0x0e},
637         {0x5180,0xff},
638         {0x5181,0x52},
639         {0x5182,0x11},
640         {0x5183,0x14},
641         {0x5184,0x25},
642         {0x5185,0x24},
643         {0x5186,0x14},
644         {0x5187,0x14},
645         {0x5188,0x14},
646         {0x5189,0x6c},
647         {0x518a,0x60},
648         {0x518b,0xbd},
649         {0x518c,0x9c},
650         {0x518d,0x3d},
651         {0x518e,0x34},
652         {0x518f,0x57},
653         {0x5190,0x4a},
654         {0x5191,0xf8},
655         {0x5192,0x04},
656         {0x5193,0x70},
657         {0x5194,0xf0},
658         {0x5195,0xf0},
659         {0x5196,0x03},
660         {0x5197,0x01},
661         {0x5198,0x04},
662         {0x5199,0x00},
663         {0x519a,0x04},
664         {0x519b,0x35},
665         {0x519c,0x08},
666         {0x519d,0xb8},
667         {0x519e,0xa0},
668         {0x528a,0x00},
669         {0x528b,0x01},
670         {0x528c,0x04},
671         {0x528d,0x08},
672         {0x528e,0x10},
673         {0x528f,0x20},
674         {0x5290,0x30},
675         {0x5292,0x00},
676         {0x5293,0x00},
677         {0x5294,0x00},
678         {0x5295,0x01},
679         {0x5296,0x00},
680         {0x5297,0x04},
681         {0x5298,0x00},
682         {0x5299,0x08},
683         {0x529a,0x00},
684         {0x529b,0x10},
685         {0x529c,0x00},
686         {0x529d,0x20},
687         {0x529e,0x00},
688         {0x529f,0x30},
689         {0x5282,0x00},
690         {0x5300,0x00},
691         {0x5301,0x20},
692         {0x5302,0x00},
693         {0x5303,0x7c},
694         {0x530c,0x00},
695         {0x530d,0x10},
696         {0x530e,0x20},
697         {0x530f,0x80},
698         {0x5310,0x20},
699         {0x5311,0x80},
700         {0x5308,0x20},
701         {0x5309,0x40},
702         {0x5304,0x00},
703         {0x5305,0x30},
704         {0x5306,0x00},
705         {0x5307,0x80},
706         {0x5314,0x08},
707         {0x5315,0x20},
708         {0x5319,0x30},
709         {0x5316,0x10},
710         {0x5317,0x00},
711         {0x5318,0x02},
712         {0x5380,0x01},
713         {0x5381,0x00},
714         {0x5382,0x00},
715         {0x5383,0x1f},
716         {0x5384,0x00},
717         {0x5385,0x06},
718         {0x5386,0x00},
719         {0x5387,0x00},
720         {0x5388,0x00},
721         {0x5389,0xE1},
722         {0x538A,0x00},
723         {0x538B,0x2B},
724         {0x538C,0x00},
725         {0x538D,0x00},
726         {0x538E,0x00},
727         {0x538F,0x10},
728         {0x5390,0x00},
729         {0x5391,0xB3},
730         {0x5392,0x00},
731         {0x5393,0xA6},
732         {0x5394,0x08},
733         {0x5480,0x14},
734         {0x5481,0x21},
735         {0x5482,0x36},
736         {0x5483,0x57},
737         {0x5484,0x65},
738         {0x5485,0x71},
739         {0x5486,0x7D},
740         {0x5487,0x87},
741         {0x5488,0x91},
742         {0x5489,0x9A},
743         {0x548A,0xAA},
744         {0x548B,0xB8},
745         {0x548C,0xCD},
746         {0x548D,0xDD},
747         {0x548E,0xEA},
748         {0x548F,0x1d},
749         {0x5490,0x05},
750         {0x5491,0x00},
751         {0x5492,0x04},
752         {0x5493,0x20},
753         {0x5494,0x03},
754         {0x5495,0x60},
755         {0x5496,0x02},
756         {0x5497,0xB8},
757         {0x5498,0x02},
758         {0x5499,0x86},
759         {0x549A,0x02},
760         {0x549B,0x5B},
761         {0x549C,0x02},
762         {0x549D,0x3B},
763         {0x549E,0x02},
764         {0x549F,0x1C},
765         {0x54A0,0x02},
766         {0x54A1,0x04},
767         {0x54A2,0x01},
768         {0x54A3,0xED},
769         {0x54A4,0x01},
770         {0x54A5,0xC5},
771         {0x54A6,0x01},
772         {0x54A7,0xA5},
773         {0x54A8,0x01},
774         {0x54A9,0x6C},
775         {0x54AA,0x01},
776         {0x54AB,0x41},
777         {0x54AC,0x01},
778         {0x54AD,0x20},
779         {0x54AE,0x00},
780         {0x54AF,0x16},
781         {0x54B0,0x01},
782         {0x54B1,0x20},
783         {0x54B2,0x00},
784         {0x54B3,0x10},
785         {0x54B4,0x00},
786         {0x54B5,0xf0},
787         {0x54B6,0x00},
788         {0x54B7,0xDF},
789         {0x5402,0x3f},
790         {0x5403,0x00},
791         {0x5500,0x10},
792         {0x5502,0x00},
793         {0x5503,0x06},
794         {0x5504,0x00},
795         {0x5505,0x7f},
796         {0x5025,0x80},
797         {0x3a0f,0x48},//0x30
798         {0x3a10,0x38},//0x28
799         {0x3a1b,0x50},//0x30
800         {0x3a1e,0x30},//0x28
801         {0x3a11,0x71},//0x61
802         {0x3a1f,0x10},
803         {0x5688,0xfd},
804         {0x5689,0xdf},
805         {0x568a,0xfe},
806         {0x568b,0xef},
807         {0x568c,0xfe},
808         {0x568d,0xef},
809         {0x568e,0xaa},
810         {0x568f,0xaa},
811
812         {0x3800 ,0x1 },
813         {0x3801 ,0x50},
814         {0x3802 ,0x0 },
815         {0x3803 ,0x8 },
816         {0x3804 ,0x5 },
817         {0x3805 ,0x0 },
818         {0x3806 ,0x3 },
819         {0x3807 ,0xc0},
820         {0x3808 ,0x3 },
821         {0x3809 ,0x20},
822         {0x380a ,0x2 },
823         {0x380b ,0x58},
824         {0x380c ,0xc },
825         {0x380d ,0x80},
826         {0x380e ,0x3 },
827         {0x380f ,0xe8},
828         {0x5001 ,0x7f},
829         {0x5680 ,0x0 },
830         {0x5681 ,0x0 },
831         {0x5682 ,0x5 },
832         {0x5683 ,0x0 },
833         {0x5684 ,0x0 },
834         {0x5685 ,0x0 },
835         {0x5686 ,0x3 },
836         {0x5687 ,0xc0},
837         {0x5687 ,0xc0},
838         {0x3815 ,0x02},
839         {0x3503 ,0x00},
840
841     {0x0000,0x00}
842
843 };
844
845 /* 720p 15fps @ 1280x720 */
846
847 static struct reginfo sensor_720p[]=
848 {
849 #if 0
850         {SEQUENCE_PROPERTY, SEQUENCE_INIT},
851         {0x3103, 0x93   },
852         {0x3008, 0x82   },
853         {0x3017, 0x7f   },
854         {0x3018, 0xfc   },
855         {0x3810, 0xc2   },
856         {0x3615, 0xf0   },
857         {0x3000, 0x00   },
858         {0x3001, 0x00   },
859         {0x3002, 0x00   },
860         {0x3003, 0x00   },
861         {0x3004, 0xff   },
862         {0x3030, 0x2b   },
863         {0x3011, 0x08   },
864         {0x3010, 0x10   },
865         {0x3604, 0x60   },
866         {0x3622, 0x60   },
867         {0x3621, 0x09   },
868         {0x3709, 0x00   },
869         {0x4000, 0x21   },
870         {0x401d, 0x22   },
871         {0x3600, 0x54   },
872         {0x3605, 0x04   },
873         {0x3606, 0x3f   },
874         {0x3c01, 0x80   },
875         {0x300d, 0x22   },
876         {0x3623, 0x22   },
877         {0x5000, 0x4f   },
878         {0x5020, 0x04   },
879         {0x5181, 0x79   },
880         {0x5182, 0x00   },
881         {0x5185, 0x22   },
882         {0x5197, 0x01   },
883         {0x5500, 0x0a   },
884         {0x5504, 0x00   },
885         {0x5505, 0x7f   },
886         {0x5080, 0x08   },
887         {0x300e, 0x18   },
888         {0x4610, 0x00   },
889         {0x471d, 0x05   },
890         {0x4708, 0x06   },
891         {0x370c, 0xa0   },
892         {0x3808, 0x0a   },
893         {0x3809, 0x20   },
894         {0x380a, 0x07   },
895         {0x380b, 0x98   },
896         {0x380c, 0x0c   },
897         {0x380d, 0x80   },
898         {0x380e, 0x07   },
899         {0x380f, 0xd0   },
900         {0x5687, 0x94   },
901         {0x501f, 0x00   },
902         {0x5000, 0x4f   },
903         {0x5001, 0xcf   },
904         {0x4300, 0x30   },
905         {0x460b, 0x35   },
906         {0x471d, 0x00   },
907         {0x3002, 0x0c   },
908         {0x3002, 0x00   },
909         {0x4713, 0x03   },
910         {0x471c, 0x50   },
911         {0x4721, 0x02   },
912         {0x4402, 0x90   },
913         {0x460c, 0x22   },
914         {0x3815, 0x44   },
915         {0x3503, 0x07   },
916         {0x3501, 0x73   },
917         {0x3502, 0x80   },
918         {0x350b, 0x00   },
919         {0x3818, 0xc8   },
920         {0x3801, 0x88   },
921         {0x3824, 0x11   },
922         {0x3a00, 0x78   },
923         {0x3a1a, 0x04   },
924         {0x3a13, 0x30   },
925         {0x3a18, 0x00   },
926         {0x3a19, 0x7c   },
927         {0x3a08, 0x12   },
928         {0x3a09, 0xc0   },
929         {0x3a0a, 0x0f   },
930         {0x3a0b, 0xa0   },
931         {0x350c, 0x07   },
932         {0x350d, 0xd0   },
933         {0x3a0d, 0x08   },
934         {0x3a0e, 0x06   },
935         {0x3500, 0x00   },
936         {0x3501, 0x00   },
937         {0x3502, 0x00   },
938         {0x350a, 0x00   },
939         {0x350b, 0x00   },
940         {0x3503, 0x00   },
941         {0x3a0f, 0x3c   },
942         {0x3a10, 0x32   },
943         {0x3a1b, 0x3c   },
944         {0x3a1e, 0x32   },
945         {0x3a11, 0x80   },
946         {0x3a1f, 0x20   },
947         {0x3030, 0x2b   },
948         {0x3a02, 0x00   },
949         {0x3a03, 0x7d   },
950         {0x3a04, 0x00   },
951         {0x3a14, 0x00   },
952         {0x3a15, 0x7d   },
953         {0x3a16, 0x00   },
954         {0x3a00, 0x78   },
955         {0x3a08, 0x09   },
956         {0x3a09, 0x60   },
957         {0x3a0a, 0x07   },
958         {0x3a0b, 0xd0   },
959         {0x3a0d, 0x10   },
960         {0x3a0e, 0x0d   },
961         {0x4407, 0x04   },
962         {0x5193, 0x70   },
963         {0x589b, 0x00   },
964         {0x589a, 0xc0   },
965         {0x401e, 0x20   },
966         {0x4001, 0x42   },
967         {0x401c, 0x06   },
968         {0x3825, 0xac   },
969         {0x3827, 0x0c   },
970         {0x528a, 0x01   },
971         {0x528b, 0x04   },
972         {0x528c, 0x08   },
973         {0x528d, 0x10   },
974         {0x528e, 0x20   },
975         {0x528f, 0x28   },
976         {0x5290, 0x30   },
977         {0x5292, 0x00   },
978         {0x5293, 0x01   },
979         {0x5294, 0x00   },
980         {0x5295, 0x04   },
981         {0x5296, 0x00   },
982         {0x5297, 0x08   },
983         {0x5298, 0x00   },
984         {0x5299, 0x10   },
985         {0x529a, 0x00   },
986         {0x529b, 0x20   },
987         {0x529c, 0x00   },
988         {0x529d, 0x28   },
989         {0x529e, 0x00   },
990         {0x529f, 0x30   },
991         {0x5282, 0x00   },
992         {0x5300, 0x00   },
993         {0x5301, 0x20   },
994         {0x5302, 0x00   },
995         {0x5303, 0x7c   },
996         {0x530c, 0x00   },
997         {0x530d, 0x0c   },
998         {0x530e, 0x20   },
999         {0x530f, 0x80   },
1000         {0x5310, 0x20   },
1001         {0x5311, 0x80   },
1002         {0x5308, 0x20   },
1003         {0x5309, 0x40   },
1004         {0x5304, 0x00   },
1005         {0x5305, 0x30   },
1006         {0x5306, 0x00   },
1007         {0x5307, 0x80   },
1008         {0x5314, 0x08   },
1009         {0x5315, 0x20   },
1010         {0x5319, 0x30   },
1011         {0x5316, 0x10   },
1012         {0x5317, 0x00   },
1013         {0x5318, 0x02   },
1014         {0x5380, 0x01   },
1015         {0x5381, 0x00   },
1016         {0x5382, 0x00   },
1017         {0x5383, 0x4e   },
1018         {0x5384, 0x00   },
1019         {0x5385, 0x0f   },
1020         {0x5386, 0x00   },
1021         {0x5387, 0x00   },
1022         {0x5388, 0x01   },
1023         {0x5389, 0x15   },
1024         {0x538a, 0x00   },
1025         {0x538b, 0x31   },
1026         {0x538c, 0x00   },
1027         {0x538d, 0x00   },
1028         {0x538e, 0x00   },
1029         {0x538f, 0x0f   },
1030         {0x5390, 0x00   },
1031         {0x5391, 0xab   },
1032         {0x5392, 0x00   },
1033         {0x5393, 0xa2   },
1034         {0x5394, 0x08   },
1035         {0x5480, 0x14   },
1036         {0x5481, 0x21   },
1037         {0x5482, 0x36   },
1038         {0x5483, 0x57   },
1039         {0x5484, 0x65   },
1040         {0x5485, 0x71   },
1041         {0x5486, 0x7d   },
1042         {0x5487, 0x87   },
1043         {0x5488, 0x91   },
1044         {0x5489, 0x9a   },
1045         {0x548a, 0xaa   },
1046         {0x548b, 0xb8   },
1047         {0x548c, 0xcd   },
1048         {0x548d, 0xdd   },
1049         {0x548e, 0xea   },
1050         {0x548f, 0x1d   },
1051         {0x5490, 0x05   },
1052         {0x5491, 0x00   },
1053         {0x5492, 0x04   },
1054         {0x5493, 0x20   },
1055         {0x5494, 0x03   },
1056         {0x5495, 0x60   },
1057         {0x5496, 0x02   },
1058         {0x5497, 0xb8   },
1059         {0x5498, 0x02   },
1060         {0x5499, 0x86   },
1061         {0x549a, 0x02   },
1062         {0x549b, 0x5b   },
1063         {0x549c, 0x02   },
1064         {0x549d, 0x3b   },
1065         {0x549e, 0x02   },
1066         {0x549f, 0x1c   },
1067         {0x54a0, 0x02   },
1068         {0x54a1, 0x04   },
1069         {0x54a2, 0x01   },
1070         {0x54a3, 0xed   },
1071         {0x54a4, 0x01   },
1072         {0x54a5, 0xc5   },
1073         {0x54a6, 0x01   },
1074         {0x54a7, 0xa5   },
1075         {0x54a8, 0x01   },
1076         {0x54a9, 0x6c   },
1077         {0x54aa, 0x01   },
1078         {0x54ab, 0x41   },
1079         {0x54ac, 0x01   },
1080         {0x54ad, 0x20   },
1081         {0x54ae, 0x00   },
1082         {0x54af, 0x16   },
1083         {0x54b0, 0x01   },
1084         {0x54b1, 0x20   },
1085         {0x54b2, 0x00   },
1086         {0x54b3, 0x10   },
1087         {0x54b4, 0x00   },
1088         {0x54b5, 0xf0   },
1089         {0x54b6, 0x00   },
1090         {0x54b7, 0xdf   },
1091         {0x5402, 0x3f   },
1092         {0x5403, 0x00   },
1093         {0x3406, 0x00   },
1094         {0x5180, 0xff   },
1095         {0x5181, 0x52   },
1096         {0x5182, 0x11   },
1097         {0x5183, 0x14   },
1098         {0x5184, 0x25   },
1099         {0x5185, 0x24   },
1100         {0x5186, 0x06   },
1101         {0x5187, 0x08   },
1102         {0x5188, 0x08   },
1103         {0x5189, 0x7c   },
1104         {0x518a, 0x60   },
1105         {0x518b, 0xb2   },
1106         {0x518c, 0xb2   },
1107         {0x518d, 0x44   },
1108         {0x518e, 0x3d   },
1109         {0x518f, 0x58   },
1110         {0x5190, 0x46   },
1111         {0x5191, 0xf8   },
1112         {0x5192, 0x04   },
1113         {0x5193, 0x70   },
1114         {0x5194, 0xf0   },
1115         {0x5195, 0xf0   },
1116         {0x5196, 0x03   },
1117         {0x5197, 0x01   },
1118         {0x5198, 0x04   },
1119         {0x5199, 0x12   },
1120         {0x519a, 0x04   },
1121         {0x519b, 0x00   },
1122         {0x519c, 0x06   },
1123         {0x519d, 0x82   },
1124         {0x519e, 0x00   },
1125         {0x5025, 0x80   },
1126         {0x3a0f, 0x38   },
1127         {0x3a10, 0x30   },
1128         {0x3a1b, 0x3a   },
1129         {0x3a1e, 0x2e   },
1130         {0x3a11, 0x60   },
1131         {0x3a1f, 0x10   },
1132         {0x5688, 0xa6   },
1133         {0x5689, 0x6a   },
1134         {0x568a, 0xea   },
1135         {0x568b, 0xae   },
1136         {0x568c, 0xa6   },
1137         {0x568d, 0x6a   },
1138         {0x568e, 0x62   },
1139         {0x568f, 0x26   },
1140         {0x5583, 0x40   },
1141         {0x5584, 0x40   },
1142         {0x5580, 0x02   },
1143         {0x5000, 0xcf   },
1144         {0x5800, 0x27   },
1145         {0x5801, 0x19   },
1146         {0x5802, 0x12   },
1147         {0x5803, 0x0f   },
1148         {0x5804, 0x10   },
1149         {0x5805, 0x15   },
1150         {0x5806, 0x1e   },
1151         {0x5807, 0x2f   },
1152         {0x5808, 0x15   },
1153         {0x5809, 0x0d   },
1154         {0x580a, 0x0a   },
1155         {0x580b, 0x09   },
1156         {0x580c, 0x0a   },
1157         {0x580d, 0x0c   },
1158         {0x580e, 0x12   },
1159         {0x580f, 0x19   },
1160         {0x5810, 0x0b   },
1161         {0x5811, 0x07   },
1162         {0x5812, 0x04   },
1163         {0x5813, 0x03   },
1164         {0x5814, 0x03   },
1165         {0x5815, 0x06   },
1166         {0x5816, 0x0a   },
1167         {0x5817, 0x0f   },
1168         {0x5818, 0x0a   },
1169         {0x5819, 0x05   },
1170         {0x581a, 0x01   },
1171         {0x581b, 0x00   },
1172         {0x581c, 0x00   },
1173         {0x581d, 0x03   },
1174         {0x581e, 0x08   },
1175         {0x581f, 0x0c   },
1176         {0x5820, 0x0a   },
1177         {0x5821, 0x05   },
1178         {0x5822, 0x01   },
1179         {0x5823, 0x00   },
1180         {0x5824, 0x00   },
1181         {0x5825, 0x03   },
1182         {0x5826, 0x08   },
1183         {0x5827, 0x0c   },
1184         {0x5828, 0x0e   },
1185         {0x5829, 0x08   },
1186         {0x582a, 0x06   },
1187         {0x582b, 0x04   },
1188         {0x582c, 0x05   },
1189         {0x582d, 0x07   },
1190         {0x582e, 0x0b   },
1191         {0x582f, 0x12   },
1192         {0x5830, 0x18   },
1193         {0x5831, 0x10   },
1194         {0x5832, 0x0c   },
1195         {0x5833, 0x0a   },
1196         {0x5834, 0x0b   },
1197         {0x5835, 0x0e   },
1198         {0x5836, 0x15   },
1199         {0x5837, 0x19   },
1200         {0x5838, 0x32   },
1201         {0x5839, 0x1f   },
1202         {0x583a, 0x18   },
1203         {0x583b, 0x16   },
1204         {0x583c, 0x17   },
1205         {0x583d, 0x1e   },
1206         {0x583e, 0x26   },
1207         {0x583f, 0x53   },
1208         {0x5840, 0x10   },
1209         {0x5841, 0x0f   },
1210         {0x5842, 0x0d   },
1211         {0x5843, 0x0c   },
1212         {0x5844, 0x0e   },
1213         {0x5845, 0x09   },
1214         {0x5846, 0x11   },
1215         {0x5847, 0x10   },
1216         {0x5848, 0x10   },
1217         {0x5849, 0x10   },
1218         {0x584a, 0x10   },
1219         {0x584b, 0x0e   },
1220         {0x584c, 0x10   },
1221         {0x584d, 0x10   },
1222         {0x584e, 0x11   },
1223         {0x584f, 0x10   },
1224         {0x5850, 0x0f   },
1225         {0x5851, 0x0c   },
1226         {0x5852, 0x0f   },
1227         {0x5853, 0x10   },
1228         {0x5854, 0x10   },
1229         {0x5855, 0x0f   },
1230         {0x5856, 0x0e   },
1231         {0x5857, 0x0b   },
1232         {0x5858, 0x10   },
1233         {0x5859, 0x0d   },
1234         {0x585a, 0x0d   },
1235         {0x585b, 0x0c   },
1236         {0x585c, 0x0c   },
1237         {0x585d, 0x0c   },
1238         {0x585e, 0x0b   },
1239         {0x585f, 0x0c   },
1240         {0x5860, 0x0c   },
1241         {0x5861, 0x0c   },
1242         {0x5862, 0x0d   },
1243         {0x5863, 0x08   },
1244         {0x5864, 0x11   },
1245         {0x5865, 0x18   },
1246         {0x5866, 0x18   },
1247         {0x5867, 0x19   },
1248         {0x5868, 0x17   },
1249         {0x5869, 0x19   },
1250         {0x586a, 0x16   },
1251         {0x586b, 0x13   },
1252         {0x586c, 0x13   },
1253         {0x586d, 0x12   },
1254         {0x586e, 0x13   },
1255         {0x586f, 0x16   },
1256         {0x5870, 0x14   },
1257         {0x5871, 0x12   },
1258         {0x5872, 0x10   },
1259         {0x5873, 0x11   },
1260         {0x5874, 0x11   },
1261         {0x5875, 0x16   },
1262         {0x5876, 0x14   },
1263         {0x5877, 0x11   },
1264         {0x5878, 0x10   },
1265         {0x5879, 0x0f   },
1266         {0x587a, 0x10   },
1267         {0x587b, 0x14   },
1268         {0x587c, 0x13   },
1269         {0x587d, 0x12   },
1270         {0x587e, 0x11   },
1271         {0x587f, 0x11   },
1272         {0x5880, 0x12   },
1273         {0x5881, 0x15   },
1274         {0x5882, 0x14   },
1275         {0x5883, 0x15   },
1276         {0x5884, 0x15   },
1277         {0x5885, 0x15   },
1278         {0x5886, 0x13   },
1279         {0x5887, 0x17   },
1280         {0x3710, 0x10   },
1281         {0x3632, 0x51   },
1282         {0x3702, 0x10   },
1283         {0x3703, 0xb2   },
1284         {0x3704, 0x18   },
1285         {0x370b, 0x40   },
1286         {0x370d, 0x03   },
1287         {0x3631, 0x01   },
1288         {0x3632, 0x52   },
1289         {0x3606, 0x24   },
1290         {0x3620, 0x96   },
1291         {0x5785, 0x07   },
1292         {0x3a13, 0x30   },
1293         {0x3600, 0x52   },
1294         {0x3604, 0x48   },
1295         {0x3606, 0x1b   },
1296         {0x370d, 0x0b   },
1297         {0x370f, 0xc0   },
1298         {0x3709, 0x01   },
1299         {0x3823, 0x00   },
1300         {0x5007, 0x00   },
1301         {0x5009, 0x00   },
1302         {0x5011, 0x00   },
1303         {0x5013, 0x00   },
1304         {0x519e, 0x00   },
1305         {0x5086, 0x00   },
1306         {0x5087, 0x00   },
1307         {0x5088, 0x00   },
1308         {0x5089, 0x00   },
1309         {0x302b, 0x00   },
1310         {0x3503, 0x07   },
1311         {0x3011, 0x10   },//15fps 0x08  // 10fps: 0x05
1312         {0x350c, 0x02   },
1313         {0x350d, 0xe4   },
1314         {0x3621, 0xc9   },
1315         {0x370a, 0x81   },
1316         {0x3803, 0x08   },
1317         {0x3804, 0x05   },
1318         {0x3805, 0x00   },
1319         {0x3806, 0x02   },
1320         {0x3807, 0xd0   },
1321         {0x3808, 0x05   },
1322         {0x3809, 0x00   },
1323         {0x380a, 0x02   },
1324         {0x380b, 0xd0   },
1325         {0x380c, 0x08   },
1326         {0x380d, 0x72   },
1327         {0x380e, 0x02   },
1328         {0x380f, 0xe4   },
1329         {0x3810, 0xc0   },
1330         {0x3818, 0xc9   },
1331         {0x381c, 0x10   },
1332         {0x381d, 0xa0   },
1333         {0x381e, 0x05   },
1334         {0x381f, 0xb0   },
1335         {0x3820, 0x00   },
1336         {0x3821, 0x00   },
1337         {0x3824, 0x11   },
1338         {0x3a08, 0x1b   },
1339         {0x3a09, 0xc0   },
1340         {0x3a0a, 0x17   },
1341         {0x3a0b, 0x20   },
1342         {0x3a0d, 0x02   },
1343         {0x3a0e, 0x01   },
1344         {0x3c00, 0x04   },
1345         {0x401c, 0x04   },
1346         {0x5682, 0x05   },
1347         {0x5683, 0x00   },
1348         {0x5686, 0x02   },
1349         {0x5687, 0xcc   },
1350         {0x5001, 0x7f   },
1351         {0x589b, 0x06   },
1352         {0x589a, 0xc5   },
1353         {0x3503, 0x00   },
1354
1355         {0x3010, 0x30   },
1356
1357         {0x460c, 0x20   },
1358         {0x460b, 0x37   },
1359         {0x471c, 0xd0   },
1360         {0x471d, 0x05   },
1361         {0x3815, 0x01   },
1362         {0x3818, 0xc1   },
1363         {0x501f, 0x00   },
1364         {0x4300, 0x32   }, // 0x30---> 0x32, set yuv
1365         {0x3002, 0x1c   },
1366         {0x3819, 0x80   },
1367         {0x5002, 0xe0   },
1368 #elif 1
1369                 //{0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
1370         {0x3819,0x81},
1371         {0x3000,0xf8},
1372         {0x3001,0x48},
1373         {0x3002,0x5c},
1374         {0x3003,0x02},
1375         {0x3005,0xb7},
1376         {0x3006,0x43},
1377         {0x3007,0x37},
1378         {0x350c,0x02},
1379         {0x350d,0xe4},
1380         {0x3602,0xfc},
1381         {0x3612,0xff},
1382         {0x3613,0x00},
1383         {0x3621,0xc9},
1384         {0x3622,0x00},
1385         {0x3623,0x22},
1386         {0x3604,0x40},
1387         {0x3705,0xdb},
1388         {0x370a,0x81},
1389         {0x3801,0x50},
1390         {0x3803,0x08},
1391         {0x3804,0x05},
1392         {0x3805,0x00},
1393         {0x3806,0x02},
1394         {0x3807,0xd0},
1395         {0x3808,0x05},
1396         {0x3809,0x00},
1397         {0x380a,0x02},
1398         {0x380b,0xd0},
1399         {0x380c,0x08},
1400         {0x380d,0x72},
1401         {0x380e,0x02},
1402         {0x380f,0xe4},
1403         {0x3810,0xc0},
1404         {0x3818,0xc1},
1405         {0x381c,0x10},
1406         {0x381d,0xa0},
1407         {0x381e,0x05},
1408         {0x381f,0xb0},
1409         {0x3820,0x00},
1410         {0x3821,0x00},
1411         {0x3824,0x11},
1412         {0x3825,0xb4},
1413         {0x3826,0x00},
1414         {0x3827,0x08},
1415         {0x3011,0x08},
1416         {0x3c01,0x80},
1417         {0x3c01,0x00},
1418         {0x3c00,0x00},
1419         {0x3a08,0x0d},
1420         {0x3a09,0xe0},
1421         {0x3a0a,0x0b},
1422         {0x3a0b,0x90},
1423         {0x3a0d,0x04},
1424         {0x3a0e,0x03},
1425         {0x3a11,0x70},
1426         {0x3a10,0x30},
1427         {0x3a1b,0x3c},
1428         {0x3a1e,0x30},
1429         {0x3a1f,0x10},
1430         {0x401c,0x04},
1431         {0x5682,0x05},
1432         {0x5683,0x00},
1433         {0x5686,0x02},
1434         {0x5687,0xcc},
1435         {0x5001,0x7f},
1436         {0x589b,0x06},
1437         {0x589a,0xc5},
1438         {0x3503,0x00},
1439         {0x3010,0x10},
1440         {0x460c,0x22},
1441         {0x460b,0x37},
1442         {0x471c,0xd0},
1443         {0x471d,0x05},
1444         {0x3815,0x01},
1445         {0x3818,0xc1},
1446         {0x501f,0x00},
1447         {0x4300,0x32},
1448         {0x3002,0x1c},
1449         {0x3819,0x80},
1450                 //{0x3008,0x02},                        //software wake
1451 #endif
1452         {0x0000 ,0x00}
1453
1454 };
1455
1456 /*      1080p, 0x15fps, 0xyuv @1920x1080 */
1457
1458 static struct reginfo sensor_1080p[]=
1459 {
1460 #if 0
1461         {SEQUENCE_PROPERTY, SEQUENCE_INIT},
1462         { 0x3103, 0x93  },
1463         { 0x3008, 0x82  },
1464         { 0x3017, 0x7f  },
1465         { 0x3018, 0xfc  },
1466         { 0x3810, 0xc2  },
1467         { 0x3615, 0xf0  },
1468         { 0x3000, 0x00  },
1469         { 0x3001, 0x00  },
1470         { 0x3002, 0x00  },
1471         { 0x3003, 0x00  },
1472         { 0x3004, 0xff  },
1473         { 0x3030, 0x2b  },
1474         { 0x3011, 0x05  },   //10 fps 0x05    //15fps 0x08
1475         { 0x3010, 0x10  },
1476         { 0x3604, 0x60  },
1477         { 0x3622, 0x60  },
1478         { 0x3621, 0x09  },
1479         { 0x3709, 0x00  },
1480         { 0x4000, 0x21  },
1481         { 0x401d, 0x22  },
1482         { 0x3600, 0x54  },
1483         { 0x3605, 0x04  },
1484         { 0x3606, 0x3f  },
1485         { 0x3c01, 0x80  },
1486         { 0x300d, 0x22  },
1487         { 0x3623, 0x22  },
1488         { 0x5000, 0x4f  },
1489         { 0x5020, 0x04  },
1490         { 0x5181, 0x79  },
1491         { 0x5182, 0x00  },
1492         { 0x5185, 0x22  },
1493         { 0x5197, 0x01  },
1494         { 0x5500, 0x0a  },
1495         { 0x5504, 0x00  },
1496         { 0x5505, 0x7f  },
1497         { 0x5080, 0x08  },
1498         { 0x300e, 0x18  },
1499         { 0x4610, 0x00  },
1500         { 0x471d, 0x05  },
1501         { 0x4708, 0x06  },
1502         { 0x370c, 0xa0  },
1503         { 0x3808, 0x0a  },
1504         { 0x3809, 0x20  },
1505         { 0x380a, 0x07  },
1506         { 0x380b, 0x98  },
1507         { 0x380c, 0x0c  },
1508         { 0x380d, 0x80  },
1509         { 0x380e, 0x07  },
1510         { 0x380f, 0xd0  },
1511         { 0x5687, 0x94  },
1512         { 0x501f, 0x00  },
1513         { 0x5000, 0x4f  },
1514         { 0x5001, 0xcf  },
1515         { 0x4300, 0x30  },
1516         { 0x460b, 0x35  },
1517         { 0x471d, 0x00  },
1518         { 0x3002, 0x0c  },
1519         { 0x3002, 0x00  },
1520         { 0x4713, 0x03  },
1521         { 0x471c, 0x50  },
1522         { 0x4721, 0x02  },
1523         { 0x4402, 0x90  },
1524         { 0x460c, 0x22  },
1525         { 0x3815, 0x44  },
1526         { 0x3503, 0x07  },
1527         { 0x3501, 0x73  },
1528         { 0x3502, 0x80  },
1529         { 0x350b, 0x00  },
1530         { 0x3818, 0xc8  },
1531         { 0x3801, 0x88  },
1532         { 0x3824, 0x11  },
1533         { 0x3a00, 0x78  },
1534         { 0x3a1a, 0x04  },
1535         { 0x3a13, 0x30  },
1536         { 0x3a18, 0x00  },
1537         { 0x3a19, 0x7c  },
1538         { 0x3a08, 0x12  },
1539         { 0x3a09, 0xc0  },
1540         { 0x3a0a, 0x0f  },
1541         { 0x3a0b, 0xa0  },
1542         { 0x350c, 0x07  },
1543         { 0x350d, 0xd0  },
1544         { 0x3a0d, 0x08  },
1545         { 0x3a0e, 0x06  },
1546         { 0x3500, 0x00  },
1547         { 0x3501, 0x00  },
1548         { 0x3502, 0x00  },
1549         { 0x350a, 0x00  },
1550         { 0x350b, 0x00  },
1551         { 0x3503, 0x00  },
1552         { 0x3a0f, 0x3c  },
1553         { 0x3a10, 0x32  },
1554         { 0x3a1b, 0x3c  },
1555         { 0x3a1e, 0x32  },
1556         { 0x3a11, 0x80  },
1557         { 0x3a1f, 0x20  },
1558         { 0x3030, 0x2b  },
1559         { 0x3a02, 0x00  },
1560         { 0x3a03, 0x7d  },
1561         { 0x3a04, 0x00  },
1562         { 0x3a14, 0x00  },
1563         { 0x3a15, 0x7d  },
1564         { 0x3a16, 0x00  },
1565         { 0x3a00, 0x78  },
1566         { 0x3a08, 0x09  },
1567         { 0x3a09, 0x60  },
1568         { 0x3a0a, 0x07  },
1569         { 0x3a0b, 0xd0  },
1570         { 0x3a0d, 0x10  },
1571         { 0x3a0e, 0x0d  },
1572         { 0x4407, 0x04  },
1573         { 0x5193, 0x70  },
1574         { 0x589b, 0x00  },
1575         { 0x589a, 0xc0  },
1576         { 0x401e, 0x20  },
1577         { 0x4001, 0x42  },
1578         { 0x401c, 0x06  },
1579         { 0x3825, 0xac  },
1580         { 0x3827, 0x0c  },
1581         { 0x528a, 0x01  },
1582         { 0x528b, 0x04  },
1583         { 0x528c, 0x08  },
1584         { 0x528d, 0x10  },
1585         { 0x528e, 0x20  },
1586         { 0x528f, 0x28  },
1587         { 0x5290, 0x30  },
1588         { 0x5292, 0x00  },
1589         { 0x5293, 0x01  },
1590         { 0x5294, 0x00  },
1591         { 0x5295, 0x04  },
1592         { 0x5296, 0x00  },
1593         { 0x5297, 0x08  },
1594         { 0x5298, 0x00  },
1595         { 0x5299, 0x10  },
1596         { 0x529a, 0x00  },
1597         { 0x529b, 0x20  },
1598         { 0x529c, 0x00  },
1599         { 0x529d, 0x28  },
1600         { 0x529e, 0x00  },
1601         { 0x529f, 0x30  },
1602         { 0x5282, 0x00  },
1603         { 0x5300, 0x00  },
1604         { 0x5301, 0x20  },
1605         { 0x5302, 0x00  },
1606         { 0x5303, 0x7c  },
1607         { 0x530c, 0x00  },
1608         { 0x530d, 0x0c  },
1609         { 0x530e, 0x20  },
1610         { 0x530f, 0x80  },
1611         { 0x5310, 0x20  },
1612         { 0x5311, 0x80  },
1613         { 0x5308, 0x20  },
1614         { 0x5309, 0x40  },
1615         { 0x5304, 0x00  },
1616         { 0x5305, 0x30  },
1617         { 0x5306, 0x00  },
1618         { 0x5307, 0x80  },
1619         { 0x5314, 0x08  },
1620         { 0x5315, 0x20  },
1621         { 0x5319, 0x30  },
1622         { 0x5316, 0x10  },
1623         { 0x5317, 0x00  },
1624         { 0x5318, 0x02  },
1625         { 0x5380, 0x01  },
1626         { 0x5381, 0x00  },
1627         { 0x5382, 0x00  },
1628         { 0x5383, 0x4e  },
1629         { 0x5384, 0x00  },
1630         { 0x5385, 0x0f  },
1631         { 0x5386, 0x00  },
1632         { 0x5387, 0x00  },
1633         { 0x5388, 0x01  },
1634         { 0x5389, 0x15  },
1635         { 0x538a, 0x00  },
1636         { 0x538b, 0x31  },
1637         { 0x538c, 0x00  },
1638         { 0x538d, 0x00  },
1639         { 0x538e, 0x00  },
1640         { 0x538f, 0x0f  },
1641         { 0x5390, 0x00  },
1642         { 0x5391, 0xab  },
1643         { 0x5392, 0x00  },
1644         { 0x5393, 0xa2  },
1645         { 0x5394, 0x08  },
1646         { 0x5480, 0x14  },
1647         { 0x5481, 0x21  },
1648         { 0x5482, 0x36  },
1649         { 0x5483, 0x57  },
1650         { 0x5484, 0x65  },
1651         { 0x5485, 0x71  },
1652         { 0x5486, 0x7d  },
1653         { 0x5487, 0x87  },
1654         { 0x5488, 0x91  },
1655         { 0x5489, 0x9a  },
1656         { 0x548a, 0xaa  },
1657         { 0x548b, 0xb8  },
1658         { 0x548c, 0xcd  },
1659         { 0x548d, 0xdd  },
1660         { 0x548e, 0xea  },
1661         { 0x548f, 0x1d  },
1662         { 0x5490, 0x05  },
1663         { 0x5491, 0x00  },
1664         { 0x5492, 0x04  },
1665         { 0x5493, 0x20  },
1666         { 0x5494, 0x03  },
1667         { 0x5495, 0x60  },
1668         { 0x5496, 0x02  },
1669         { 0x5497, 0xb8  },
1670         { 0x5498, 0x02  },
1671         { 0x5499, 0x86  },
1672         { 0x549a, 0x02  },
1673         { 0x549b, 0x5b  },
1674         { 0x549c, 0x02  },
1675         { 0x549d, 0x3b  },
1676         { 0x549e, 0x02  },
1677         { 0x549f, 0x1c  },
1678         { 0x54a0, 0x02  },
1679         { 0x54a1, 0x04  },
1680         { 0x54a2, 0x01  },
1681         { 0x54a3, 0xed  },
1682         { 0x54a4, 0x01  },
1683         { 0x54a5, 0xc5  },
1684         { 0x54a6, 0x01  },
1685         { 0x54a7, 0xa5  },
1686         { 0x54a8, 0x01  },
1687         { 0x54a9, 0x6c  },
1688         { 0x54aa, 0x01  },
1689         { 0x54ab, 0x41  },
1690         { 0x54ac, 0x01  },
1691         { 0x54ad, 0x20  },
1692         { 0x54ae, 0x00  },
1693         { 0x54af, 0x16  },
1694         { 0x54b0, 0x01  },
1695         { 0x54b1, 0x20  },
1696         { 0x54b2, 0x00  },
1697         { 0x54b3, 0x10  },
1698         { 0x54b4, 0x00  },
1699         { 0x54b5, 0xf0  },
1700         { 0x54b6, 0x00  },
1701         { 0x54b7, 0xdf  },
1702         { 0x5402, 0x3f  },
1703         { 0x5403, 0x00  },
1704         { 0x3406, 0x00  },
1705         { 0x5180, 0xff  },
1706         { 0x5181, 0x52  },
1707         { 0x5182, 0x11  },
1708         { 0x5183, 0x14  },
1709         { 0x5184, 0x25  },
1710         { 0x5185, 0x24  },
1711         { 0x5186, 0x06  },
1712         { 0x5187, 0x08  },
1713         { 0x5188, 0x08  },
1714         { 0x5189, 0x7c  },
1715         { 0x518a, 0x60  },
1716         { 0x518b, 0xb2  },
1717         { 0x518c, 0xb2  },
1718         { 0x518d, 0x44  },
1719         { 0x518e, 0x3d  },
1720         { 0x518f, 0x58  },
1721         { 0x5190, 0x46  },
1722         { 0x5191, 0xf8  },
1723         { 0x5192, 0x04  },
1724         { 0x5193, 0x70  },
1725         { 0x5194, 0xf0  },
1726         { 0x5195, 0xf0  },
1727         { 0x5196, 0x03  },
1728         { 0x5197, 0x01  },
1729         { 0x5198, 0x04  },
1730         { 0x5199, 0x12  },
1731         { 0x519a, 0x04  },
1732         { 0x519b, 0x00  },
1733         { 0x519c, 0x06  },
1734         { 0x519d, 0x82  },
1735         { 0x519e, 0x00  },
1736         { 0x5025, 0x80  },
1737         { 0x3a0f, 0x38  },
1738         { 0x3a10, 0x30  },
1739         { 0x3a1b, 0x3a  },
1740         { 0x3a1e, 0x2e  },
1741         { 0x3a11, 0x60  },
1742         { 0x3a1f, 0x10  },
1743         { 0x5688, 0xa6  },
1744         { 0x5689, 0x6a  },
1745         { 0x568a, 0xea  },
1746         { 0x568b, 0xae  },
1747         { 0x568c, 0xa6  },
1748         { 0x568d, 0x6a  },
1749         { 0x568e, 0x62  },
1750         { 0x568f, 0x26  },
1751         { 0x5583, 0x40  },
1752         { 0x5584, 0x40  },
1753         { 0x5580, 0x02  },
1754         { 0x5000, 0xcf  },
1755         { 0x5800, 0x27  },
1756         { 0x5801, 0x19  },
1757         { 0x5802, 0x12  },
1758         { 0x5803, 0x0f  },
1759         { 0x5804, 0x10  },
1760         { 0x5805, 0x15  },
1761         { 0x5806, 0x1e  },
1762         { 0x5807, 0x2f  },
1763         { 0x5808, 0x15  },
1764         { 0x5809, 0x0d  },
1765         { 0x580a, 0x0a  },
1766         { 0x580b, 0x09  },
1767         { 0x580c, 0x0a  },
1768         { 0x580d, 0x0c  },
1769         { 0x580e, 0x12  },
1770         { 0x580f, 0x19  },
1771         { 0x5810, 0x0b  },
1772         { 0x5811, 0x07  },
1773         { 0x5812, 0x04  },
1774         { 0x5813, 0x03  },
1775         { 0x5814, 0x03  },
1776         { 0x5815, 0x06  },
1777         { 0x5816, 0x0a  },
1778         { 0x5817, 0x0f  },
1779         { 0x5818, 0x0a  },
1780         { 0x5819, 0x05  },
1781         { 0x581a, 0x01  },
1782         { 0x581b, 0x00  },
1783         { 0x581c, 0x00  },
1784         { 0x581d, 0x03  },
1785         { 0x581e, 0x08  },
1786         { 0x581f, 0x0c  },
1787         { 0x5820, 0x0a  },
1788         { 0x5821, 0x05  },
1789         { 0x5822, 0x01  },
1790         { 0x5823, 0x00  },
1791         { 0x5824, 0x00  },
1792         { 0x5825, 0x03  },
1793         { 0x5826, 0x08  },
1794         { 0x5827, 0x0c  },
1795         { 0x5828, 0x0e  },
1796         { 0x5829, 0x08  },
1797         { 0x582a, 0x06  },
1798         { 0x582b, 0x04  },
1799         { 0x582c, 0x05  },
1800         { 0x582d, 0x07  },
1801         { 0x582e, 0x0b  },
1802         { 0x582f, 0x12  },
1803         { 0x5830, 0x18  },
1804         { 0x5831, 0x10  },
1805         { 0x5832, 0x0c  },
1806         { 0x5833, 0x0a  },
1807         { 0x5834, 0x0b  },
1808         { 0x5835, 0x0e  },
1809         { 0x5836, 0x15  },
1810         { 0x5837, 0x19  },
1811         { 0x5838, 0x32  },
1812         { 0x5839, 0x1f  },
1813         { 0x583a, 0x18  },
1814         { 0x583b, 0x16  },
1815         { 0x583c, 0x17  },
1816         { 0x583d, 0x1e  },
1817         { 0x583e, 0x26  },
1818         { 0x583f, 0x53  },
1819         { 0x5840, 0x10  },
1820         { 0x5841, 0x0f  },
1821         { 0x5842, 0x0d  },
1822         { 0x5843, 0x0c  },
1823         { 0x5844, 0x0e  },
1824         { 0x5845, 0x09  },
1825         { 0x5846, 0x11  },
1826         { 0x5847, 0x10  },
1827         { 0x5848, 0x10  },
1828         { 0x5849, 0x10  },
1829         { 0x584a, 0x10  },
1830         { 0x584b, 0x0e  },
1831         { 0x584c, 0x10  },
1832         { 0x584d, 0x10  },
1833         { 0x584e, 0x11  },
1834         { 0x584f, 0x10  },
1835         { 0x5850, 0x0f  },
1836         { 0x5851, 0x0c  },
1837         { 0x5852, 0x0f  },
1838         { 0x5853, 0x10  },
1839         { 0x5854, 0x10  },
1840         { 0x5855, 0x0f  },
1841         { 0x5856, 0x0e  },
1842         { 0x5857, 0x0b  },
1843         { 0x5858, 0x10  },
1844         { 0x5859, 0x0d  },
1845         { 0x585a, 0x0d  },
1846         { 0x585b, 0x0c  },
1847         { 0x585c, 0x0c  },
1848         { 0x585d, 0x0c  },
1849         { 0x585e, 0x0b  },
1850         { 0x585f, 0x0c  },
1851         { 0x5860, 0x0c  },
1852         { 0x5861, 0x0c  },
1853         { 0x5862, 0x0d  },
1854         { 0x5863, 0x08  },
1855         { 0x5864, 0x11  },
1856         { 0x5865, 0x18  },
1857         { 0x5866, 0x18  },
1858         { 0x5867, 0x19  },
1859         { 0x5868, 0x17  },
1860         { 0x5869, 0x19  },
1861         { 0x586a, 0x16  },
1862         { 0x586b, 0x13  },
1863         { 0x586c, 0x13  },
1864         { 0x586d, 0x12  },
1865         { 0x586e, 0x13  },
1866         { 0x586f, 0x16  },
1867         { 0x5870, 0x14  },
1868         { 0x5871, 0x12  },
1869         { 0x5872, 0x10  },
1870         { 0x5873, 0x11  },
1871         { 0x5874, 0x11  },
1872         { 0x5875, 0x16  },
1873         { 0x5876, 0x14  },
1874         { 0x5877, 0x11  },
1875         { 0x5878, 0x10  },
1876         { 0x5879, 0x0f  },
1877         { 0x587a, 0x10  },
1878         { 0x587b, 0x14  },
1879         { 0x587c, 0x13  },
1880         { 0x587d, 0x12  },
1881         { 0x587e, 0x11  },
1882         { 0x587f, 0x11  },
1883         { 0x5880, 0x12  },
1884         { 0x5881, 0x15  },
1885         { 0x5882, 0x14  },
1886         { 0x5883, 0x15  },
1887         { 0x5884, 0x15  },
1888         { 0x5885, 0x15  },
1889         { 0x5886, 0x13  },
1890         { 0x5887, 0x17  },
1891         { 0x3710, 0x10  },
1892         { 0x3632, 0x51  },
1893         { 0x3702, 0x10  },
1894         { 0x3703, 0xb2  },
1895         { 0x3704, 0x18  },
1896         { 0x370b, 0x40  },
1897         { 0x370d, 0x03  },
1898         { 0x3631, 0x01  },
1899         { 0x3632, 0x52  },
1900         { 0x3606, 0x24  },
1901         { 0x3620, 0x96  },
1902         { 0x5785, 0x07  },
1903         { 0x3a13, 0x30  },
1904         { 0x3600, 0x52  },
1905         { 0x3604, 0x48  },
1906         { 0x3606, 0x1b  },
1907         { 0x370d, 0x0b  },
1908         { 0x370f, 0xc0  },
1909         { 0x3709, 0x01  },
1910         { 0x3823, 0x00  },
1911         { 0x5007, 0x00  },
1912         { 0x5009, 0x00  },
1913         { 0x5011, 0x00  },
1914         { 0x5013, 0x00  },
1915         { 0x519e, 0x00  },
1916         { 0x5086, 0x00  },
1917         { 0x5087, 0x00  },
1918         { 0x5088, 0x00  },
1919         { 0x5089, 0x00  },
1920         { 0x302b, 0x00  },
1921         { 0x3503, 0x07  },
1922         { 0x3011, 0x07  },   //10 fps 0x05    //15fps 0x07
1923         { 0x350c, 0x04  },
1924         { 0x350d, 0x58  },
1925         { 0x3801, 0x8a  },
1926         { 0x3803, 0x0a  },
1927         { 0x3804, 0x07  },
1928         { 0x3805, 0x80  },
1929         { 0x3806, 0x04  },
1930         { 0x3807, 0x39  },//0x3a
1931         { 0x3808, 0x07  },
1932         { 0x3809, 0x80  },
1933         { 0x380a, 0x04  },
1934         { 0x380b, 0x38  },
1935         { 0x380c, 0x09  },
1936         { 0x380d, 0xd6  },
1937         { 0x380e, 0x04  },
1938         { 0x380f, 0x58  },
1939         { 0x381c, 0x11  },
1940         { 0x381d, 0xba  },
1941         { 0x381e, 0x04  },
1942         { 0x381f, 0x48  },
1943         { 0x3820, 0x04  },
1944         { 0x3821, 0x18  },
1945         { 0x3c01, 0x80  },
1946         { 0x3c00, 0x04  },
1947         { 0x3a08, 0x14  },
1948         { 0x3a09, 0xe0  },
1949         { 0x3a0a, 0x11  },
1950         { 0x3a0b, 0x60  },
1951         { 0x3a0d, 0x04  },
1952         { 0x3a0e, 0x03  },
1953         { 0x5682, 0x07  },
1954         { 0x5683, 0x60  },
1955         { 0x5686, 0x04  },
1956         { 0x5687, 0x1c  },
1957         { 0x5001, 0x7f  },
1958         { 0x3503, 0x00  },
1959         { 0x3010, 0x10  },
1960
1961         { 0x460c, 0x20  },
1962         { 0x460b, 0x37  },
1963         { 0x471c, 0xd0  },
1964         { 0x471d, 0x05  },
1965         { 0x3815, 0x01  },
1966         { 0x3818, 0xc0  },
1967         { 0x501f, 0x00  },
1968         { 0x4300, 0x32  }, // set yuv, 0x30--> 0x32
1969         { 0x3002, 0x1c  },
1970         { 0x3819, 0x80  },
1971         { 0x5002, 0xe0  },
1972 #else
1973                 //{0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
1974         {0x3819,0x81},
1975         {0x3000,0xf8},
1976         {0x3001,0x48},
1977         {0x3002,0x5c},
1978         {0x3003,0x02},
1979         {0x3005,0xb7},
1980         {0x3006,0x43},
1981         {0x3007,0x37},
1982         {0x350c,0x04},
1983         {0x350d,0x58},
1984         {0x3602,0xe4},
1985         {0x3612,0xac},
1986         {0x3613,0x44},
1987         {0x3621,0x09},
1988         {0x3622,0x00},//60},
1989         {0x3623,0x22},
1990         {0x3604,0x40},//48},
1991         {0x3705,0xda},
1992         {0x370a,0x80},
1993         {0x3801,0x8a},
1994         {0x3803,0x0a},
1995         {0x3804,0x07},
1996         {0x3805,0x80},
1997         {0x3806,0x04},
1998         {0x3807,0x39},
1999         {0x3808,0x07},
2000         {0x3809,0x80},
2001         {0x380a,0x04},
2002         {0x380b,0x38},
2003         {0x380c,0x09},
2004         {0x380d,0xd6},
2005         {0x380e,0x04},
2006         {0x380f,0x58},
2007         {0x3810,0xc2},
2008         {0x3818,0xc0},
2009         {0x381c,0x11},
2010         {0x381d,0xba},
2011         {0x381e,0x04},
2012         {0x381f,0x48},
2013         {0x3820,0x04},
2014         {0x3821,0x18},
2015         {0x3824,0x11},
2016         {0x3825,0xac},
2017         {0x3826,0x00},
2018         {0x3827,0x0c},
2019                 { 0x3011, 0x07  },   //10 fps 0x05    //15fps 0x08
2020                 { 0x3c01, 0x80  },
2021                 { 0x3c00, 0x04  },
2022         {0x3a08,0x14},  //0x05
2023         {0x3a09,0xe0},  //0xf5
2024         {0x3a0a,0x11},  //0x04
2025         {0x3a0b,0x60},  //0xf6
2026         {0x3a0d,0x04},  //0x0b
2027         {0x3a0e,0x03},  //0x0d
2028         {0x3a10,0x30},
2029         {0x3a1b,0x3c},
2030         {0x3a1e,0x30},
2031         {0x3a11,0x70},
2032         {0x3a1f,0x10},
2033         {0x401c,0x06},
2034         {0x5682,0x07},
2035         {0x5683,0x60},
2036         {0x5686,0x04},
2037         {0x5687,0x1c},
2038         {0x5001,0x7f},
2039         {0x589b,0x00},
2040         {0x589a,0xc0},
2041         {0x3503,0x00},
2042         {0x3010,0x30},
2043         {0x460c,0x22},
2044         {0x460b,0x37},
2045         {0x471c,0xd0},
2046         {0x471d,0x05},
2047         {0x3815,0x01},
2048         {0x3818,0xc0},
2049         {0x501f,0x00},
2050         {0x4300,0x32},
2051         {0x3002,0x1c},
2052         {0x3819,0x80},
2053                 //{0x3008,0x02},                        //software wake
2054 #endif
2055         { 0x0000, 0x00  }
2056 };
2057
2058 /* 2592X1944 QSXGA */
2059 static struct reginfo sensor_qsxga[] =
2060 {
2061                 {0x3008,0x42}, //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2062         //{0x3503 , 0x7 },
2063         {0x3000 , 0x0 },
2064         {0x3001 , 0x0 },
2065         {0x3002 , 0x0 },
2066         {0x3003 , 0x0 },
2067         {0x3005 , 0xff},
2068         {0x3006 , 0xff},
2069         {0x3007 , 0x3f},
2070         {0x350c , 0x7 },
2071         {0x350d , 0xd0},
2072         {0x3602 , 0xe4},
2073         {0x3612 , 0xac},
2074         {0x3613 , 0x44},
2075         {0x3621 , 0x27},
2076         {0x3622 , 0x8 },
2077         {0x3623 , 0x22},
2078         {0x3604 , 0x60},
2079         {0x3705 , 0xda},
2080         {0x370a , 0x80},
2081         {0x3801 , 0x8a},
2082         {0x3803 , 0xa },
2083         {0x3804 , 0xa },
2084         {0x3805 , 0x20},
2085         {0x3806 , 0x7 },
2086         {0x3807 , 0x98},
2087         {0x3808 , 0xa },
2088         {0x3809 , 0x20},
2089         {0x380a , 0x7 },
2090         {0x380b , 0x98},
2091         {0x380c , 0xc },
2092         {0x380d , 0x80},
2093         {0x380e , 0x7 },
2094         {0x380f , 0xd0},
2095         {0x3810 , 0xc2},
2096         {0x3815 , 0x1 },
2097         {0x3818 , 0xc0},
2098         {0x3824 , 0x1 },
2099         {0x3827 , 0xa },
2100         {0x3a00 , 0x78},
2101         {0x3a0d , 0x10},
2102         {0x3a0e , 0xd },
2103         {0x3a10 , 0x32},
2104         {0x3a1b , 0x40},
2105         {0x3a1e , 0x2e},
2106         {0x3a11 , 0xd0},
2107         {0x3a1f , 0x40},
2108         {0x3a00 , 0x78},
2109         {0x460b , 0x37},
2110         {0x471d , 0x5 },
2111         {0x4713 , 0x2 },
2112         {0x471c , 0xd0},
2113         {0x5682 , 0xa },
2114         {0x5683 , 0x20},
2115         {0x5686 , 0x7 },
2116         {0x5687 , 0x98},
2117         {0x5001 , 0x1 },
2118         {0x589b , 0x0 },
2119         {0x589a , 0xc0},
2120         {0x4407 , 0xc },
2121         {0x589b , 0x0 },
2122         {0x589a , 0xc0},
2123         {0x3002 , 0x0 },
2124         {0x3002 , 0x0 },
2125         {0x3503 , 0x0 },
2126         {0x3010 , 0x10},
2127         {0x3009 , 0x1 },
2128         {0x300a , 0x56},
2129                 {0x3008,0x02},                  //software wake
2130     {0x0000 ,0x00}
2131 };
2132 /* 2048*1536 QXGA */
2133 static struct reginfo sensor_qxga[] =
2134 {
2135                 {0x3008,0x42},   //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2136         //{0x3503 , 0x7 },
2137         {0x3000 , 0x0 },
2138         {0x3001 , 0x0 },
2139         {0x3002 , 0x0 },
2140         {0x3003 , 0x0 },
2141         {0x3005 , 0xff},
2142         {0x3006 , 0xff},
2143         {0x3007 , 0x3f},
2144         {0x350c , 0x7 },
2145         {0x350d , 0xd0},
2146         {0x3602 , 0xe4},
2147         {0x3612 , 0xac},
2148         {0x3613 , 0x44},
2149         {0x3621 , 0x27},
2150         {0x3622 , 0x8 },
2151         {0x3623 , 0x22},
2152         {0x3604 , 0x60},
2153         {0x3705 , 0xda},
2154         {0x370a , 0x80},
2155         {0x3801 , 0x8a},
2156         {0x3803 , 0xa },
2157         {0x3804 , 0xa },
2158         {0x3805 , 0x20},
2159         {0x3806 , 0x7 },
2160         {0x3807 , 0x98},
2161         {0x3808 , 0xa },
2162         {0x3809 , 0x20},
2163         {0x380a , 0x7 },
2164         {0x380b , 0x98},
2165         {0x380c , 0xc },
2166         {0x380d , 0x80},
2167         {0x380e , 0x7 },
2168         {0x380f , 0xd0},
2169         {0x3810 , 0xc2},
2170         {0x3815 , 0x1 },
2171         {0x3818 , 0xc0},
2172         {0x3824 , 0x1 },
2173         {0x3827 , 0xa },
2174         {0x3a00 , 0x78},
2175         {0x3a0d , 0x10},
2176         {0x3a0e , 0xd },
2177         {0x3a10 , 0x32},
2178         {0x3a1b , 0x40},
2179         {0x3a1e , 0x2e},
2180         {0x3a11 , 0xd0},
2181         {0x3a1f , 0x40},
2182         {0x3a00 , 0x78},
2183         {0x460b , 0x37},
2184         {0x471d , 0x5 },
2185         {0x4713 , 0x2 },
2186         {0x471c , 0xd0},
2187         {0x5682 , 0xa },
2188         {0x5683 , 0x20},
2189         {0x5686 , 0x7 },
2190         {0x5687 , 0x98},
2191         {0x5001 , 0x1 },
2192         {0x589b , 0x0 },
2193         {0x589a , 0xc0},
2194         {0x4407 , 0xc },
2195         {0x589b , 0x0 },
2196         {0x589a , 0xc0},
2197         {0x3002 , 0x0 },
2198         {0x3002 , 0x0 },
2199         {0x3503 , 0x0 },
2200         {0x3010 , 0x10},
2201         {0x3009 , 0x1 },
2202         {0x300a , 0x56},
2203
2204         {0x3800 ,0x1 },
2205         {0x3801 ,0x8A},
2206         {0x3802 ,0x0 },
2207         {0x3803 ,0xA },
2208         {0x3804 ,0xA },
2209         {0x3805 ,0x20},
2210         {0x3806 ,0x7 },
2211         {0x3807 ,0x98},
2212         {0x3808 ,0x8 },
2213         {0x3809 ,0x0 },
2214         {0x380a ,0x6 },
2215         {0x380b ,0x0 },
2216         {0x380c ,0xc },
2217         {0x380d ,0x80},
2218         {0x380e ,0x7 },
2219         {0x380f ,0xd0},
2220         {0x5001 ,0x7f},
2221         {0x5680 ,0x0 },
2222         {0x5681 ,0x0 },
2223         {0x5682 ,0xA },
2224         {0x5683 ,0x20},
2225         {0x5684 ,0x0 },
2226         {0x5685 ,0x0 },
2227         {0x5686 ,0x7 },
2228         {0x5687 ,0x98},
2229                 {0x3008,0x02},   //software wake
2230     {0x0000 ,0x00}
2231 };
2232
2233 /* 1600X1200 UXGA */
2234 static struct reginfo sensor_uxga[] =
2235 {
2236                 {0x3008,0x42},   //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2237         //{0x3503 , 0x7 },
2238         {0x3000 , 0x0 },
2239         {0x3001 , 0x0 },
2240         {0x3002 , 0x0 },
2241         {0x3003 , 0x0 },
2242         {0x3005 , 0xff},
2243         {0x3006 , 0xff},
2244         {0x3007 , 0x3f},
2245         {0x350c , 0x7 },
2246         {0x350d , 0xd0},
2247         {0x3602 , 0xe4},
2248         {0x3612 , 0xac},
2249         {0x3613 , 0x44},
2250         {0x3621 , 0x27},
2251         {0x3622 , 0x8 },
2252         {0x3623 , 0x22},
2253         {0x3604 , 0x60},
2254         {0x3705 , 0xda},
2255         {0x370a , 0x80},
2256         {0x3801 , 0x8a},
2257         {0x3803 , 0xa },
2258         {0x3804 , 0xa },
2259         {0x3805 , 0x20},
2260         {0x3806 , 0x7 },
2261         {0x3807 , 0x98},
2262         {0x3808 , 0xa },
2263         {0x3809 , 0x20},
2264         {0x380a , 0x7 },
2265         {0x380b , 0x98},
2266         {0x380c , 0xc },
2267         {0x380d , 0x80},
2268         {0x380e , 0x7 },
2269         {0x380f , 0xd0},
2270         {0x3810 , 0xc2},
2271         {0x3815 , 0x1 },
2272         {0x3818 , 0xc0},
2273         {0x3824 , 0x1 },
2274         {0x3827 , 0xa },
2275         {0x3a00 , 0x78},
2276         {0x3a0d , 0x10},
2277         {0x3a0e , 0xd },
2278         {0x3a10 , 0x32},
2279         {0x3a1b , 0x40},
2280         {0x3a1e , 0x2e},
2281         {0x3a11 , 0xd0},
2282         {0x3a1f , 0x40},
2283         {0x3a00 , 0x78},
2284         {0x460b , 0x37},
2285         {0x471d , 0x5 },
2286         {0x4713 , 0x2 },
2287         {0x471c , 0xd0},
2288         {0x5682 , 0xa },
2289         {0x5683 , 0x20},
2290         {0x5686 , 0x7 },
2291         {0x5687 , 0x98},
2292         {0x5001 , 0x1 },
2293         {0x589b , 0x0 },
2294         {0x589a , 0xc0},
2295         {0x4407 , 0xc },
2296         {0x589b , 0x0 },
2297         {0x589a , 0xc0},
2298         {0x3002 , 0x0 },
2299         {0x3002 , 0x0 },
2300         {0x3503 , 0x0 },
2301         {0x3010 , 0x10},
2302         {0x3009 , 0x1 },
2303         {0x300a , 0x56},
2304
2305         {0x3800 ,0x1 },
2306         {0x3801 ,0x8A},
2307         {0x3802 ,0x0 },
2308         {0x3803 ,0xA },
2309         {0x3804 ,0xA },
2310         {0x3805 ,0x20},
2311         {0x3806 ,0x7 },
2312         {0x3807 ,0x98},
2313         {0x3808 ,0x6 },
2314         {0x3809 ,0x40},
2315         {0x380a ,0x4 },
2316         {0x380b ,0xb0},
2317         {0x380c ,0xc },
2318         {0x380d ,0x80},
2319         {0x380e ,0x7 },
2320         {0x380f ,0xd0},
2321         {0x5001 ,0x7f},
2322         {0x5680 ,0x0 },
2323         {0x5681 ,0x0 },
2324         {0x5682 ,0xA },
2325         {0x5683 ,0x20},
2326         {0x5684 ,0x0 },
2327         {0x5685 ,0x0 },
2328         {0x5686 ,0x7 },
2329         {0x5687 ,0x98},
2330                 {0x3008,0x02},   //software wake
2331     {0x0000 ,0x00}
2332 };
2333 /* 1280X1024 SXGA */
2334 static struct reginfo sensor_sxga[] =
2335 {
2336         {0x0000,0x00}
2337 };
2338 /*  1024X768 XGA */
2339 static struct reginfo sensor_xga[] =
2340 {
2341                 {0x3008,0x42},   //software sleep : Sensor vsync singal may not output if haven't sleep the sensor when transfer the array,
2342         //{0x3503 , 0x7 },
2343         {0x3000 , 0x0 },
2344         {0x3001 , 0x0 },
2345         {0x3002 , 0x0 },
2346         {0x3003 , 0x0 },
2347         {0x3005 , 0xff},
2348         {0x3006 , 0xff},
2349         {0x3007 , 0x3f},
2350         {0x350c , 0x7 },
2351         {0x350d , 0xd0},
2352         {0x3602 , 0xe4},
2353         {0x3612 , 0xac},
2354         {0x3613 , 0x44},
2355         {0x3621 , 0x27},
2356         {0x3622 , 0x8 },
2357         {0x3623 , 0x22},
2358         {0x3604 , 0x60},
2359         {0x3705 , 0xda},
2360         {0x370a , 0x80},
2361         {0x3801 , 0x8a},
2362         {0x3803 , 0xa },
2363         {0x3804 , 0xa },
2364         {0x3805 , 0x20},
2365         {0x3806 , 0x7 },
2366         {0x3807 , 0x98},
2367         {0x3808 , 0xa },
2368         {0x3809 , 0x20},
2369         {0x380a , 0x7 },
2370         {0x380b , 0x98},
2371         {0x380c , 0xc },
2372         {0x380d , 0x80},
2373         {0x380e , 0x7 },
2374         {0x380f , 0xd0},
2375         {0x3810 , 0xc2},
2376         {0x3815 , 0x1 },
2377         {0x3818 , 0xc0},
2378         {0x3824 , 0x1 },
2379         {0x3827 , 0xa },
2380         {0x3a00 , 0x78},
2381         {0x3a0d , 0x10},
2382         {0x3a0e , 0xd },
2383         {0x3a10 , 0x32},
2384         {0x3a1b , 0x40},
2385         {0x3a1e , 0x2e},
2386         {0x3a11 , 0xd0},
2387         {0x3a1f , 0x40},
2388         {0x3a00 , 0x78},
2389         {0x460b , 0x37},
2390         {0x471d , 0x5 },
2391         {0x4713 , 0x2 },
2392         {0x471c , 0xd0},
2393         {0x5682 , 0xa },
2394         {0x5683 , 0x20},
2395         {0x5686 , 0x7 },
2396         {0x5687 , 0x98},
2397         {0x5001 , 0x1 },
2398         {0x589b , 0x0 },
2399         {0x589a , 0xc0},
2400         {0x4407 , 0xc },
2401         {0x589b , 0x0 },
2402         {0x589a , 0xc0},
2403         {0x3002 , 0x0 },
2404         {0x3002 , 0x0 },
2405         {0x3503 , 0x0 },
2406         {0x3010 , 0x10},
2407         {0x3009 , 0x1 },
2408         {0x300a , 0x56},
2409
2410         {0x3800 ,0x1 },
2411         {0x3801 ,0x8A},
2412         {0x3802 ,0x0 },
2413         {0x3803 ,0xA },
2414         {0x3804 ,0xA },
2415         {0x3805 ,0x20},
2416         {0x3806 ,0x7 },
2417         {0x3807 ,0x98},
2418         {0x3808 ,0x5 },
2419         {0x3809 ,0x0 },
2420         {0x380a ,0x4 },
2421         {0x380b ,0x0 },
2422         {0x380c ,0xc },
2423         {0x380d ,0x80},
2424         {0x380e ,0x7 },
2425         {0x380f ,0xd0},
2426         {0x5001 ,0x7f},
2427         {0x5680 ,0x0 },
2428         {0x5681 ,0x0 },
2429         {0x5682 ,0xA },
2430         {0x5683 ,0x20},
2431         {0x5684 ,0x0 },
2432         {0x5685 ,0x0 },
2433         {0x5686 ,0x7 },
2434         {0x5687 ,0x98},
2435                 {0x3008,0x02},   //software wake
2436         {0x0000,0x00}
2437 };
2438
2439 /* 800X600 SVGA*/
2440 static struct reginfo sensor_svga[] =
2441 {
2442
2443 {0x3819,0x81},
2444 {0x3000,0xf8},
2445 {0x3001,0x48},
2446 {0x3002,0x5c},
2447 {0x3003,0x02},
2448 {0x3005,0xb7},
2449 {0x3006,0x43},
2450 {0x3007,0x37},
2451 {0x350c,0x07},//03
2452 {0x350d,0xd0},//e8
2453 {0x3602,0xfc},
2454 {0x3612,0xff},
2455 {0x3613,0x00},
2456 {0x3621,0xc7},//87
2457 {0x3622,0x00},//60
2458 {0x3623,0x22},//01
2459 {0x3604,0x40},//48
2460 {0x3705,0xdb},
2461 {0x370a,0x81},
2462 {0x3801,0x50},
2463 {0x3803,0x08},
2464 {0x3804,0x05},
2465 {0x3805,0x00},
2466 {0x3806,0x03},
2467 {0x3807,0xc0},
2468 {0x3808,0x03},
2469 {0x3809,0x20},
2470 {0x380a,0x02},
2471 {0x380b,0x58},
2472 {0x380c,0x0c},
2473 {0x380d,0x80},
2474 {0x380e,0x03},
2475 {0x380f,0xe8},
2476 {0x3810,0x40},//c0
2477 {0x3815,0x02},
2478 {0x3818,0xc1},
2479 {0x381c,0x21},
2480 {0x381d,0x50},
2481 {0x381e,0x01},
2482 {0x381f,0x20},
2483 {0x3820,0x00},
2484 {0x3821,0x00},
2485 {0x3824,0x11},
2486 {0x3825,0xb4},
2487 {0x3826,0x00},
2488 {0x3827,0x08},
2489 {0x3a00,0x78},
2490         { 0x3011,  0x08 },
2491         { 0x3c01, 0x00  },
2492         { 0x3c00, 0x00  }, 
2493 {0x3a08,0x09},
2494 {0x3a09,0x60},
2495 {0x3a0a,0x07},
2496 {0x3a0b,0xd0},
2497 {0x3a0d,0x08},
2498 {0x3a0e,0x06},
2499 {0x3a10,0x30},
2500 {0x3a1b,0x3c},
2501 {0x3a1e,0x30},
2502 {0x3a11,0x70},
2503 {0x3a1f,0x10},
2504 {0x3010,0x10},
2505 {0x460b,0x37},
2506 {0x471d,0x05},
2507 {0x4713,0x02},
2508 {0x471c,0xd0},
2509 {0x501f,0x00},
2510 {0x4300,0x32},
2511 {0x3002,0x5c},
2512 {0x5682,0x05},
2513 {0x5683,0x00},
2514 {0x5686,0x03},
2515 {0x5687,0xc0},
2516 {0x5001,0x7f},
2517 {0x589b,0x04},
2518 {0x589a,0xc5},
2519 {0x4407,0x04},
2520 {0x3002,0x5c},
2521 {0x460c,0x22},
2522 {0x3815,0x03},
2523 {0x3000,0x00},
2524 {0x3819,0x80},
2525 {0x3503,0x00},
2526         {0x0000 ,0x00}
2527 };
2528
2529 /* 640X480 VGA */
2530 static struct reginfo sensor_vga[] =
2531 {
2532     {0x0000,0x00}
2533 };
2534
2535 /* 352X288 CIF */
2536 static struct reginfo sensor_cif[] =
2537 {
2538         {0x3800 ,0x1 },
2539         {0x3801 ,0x50},
2540         {0x3802 ,0x0 },
2541         {0x3803 ,0x8 },
2542         {0x3804 ,0x4 },
2543         {0x3805 ,0x96},
2544         {0x3806 ,0x3 },
2545         {0x3807 ,0xc0},
2546         {0x3808 ,0x1 },
2547         {0x3809 ,0x60},
2548         {0x380a ,0x1 },
2549         {0x380b ,0x20},
2550         {0x380c ,0xc },
2551         {0x380d ,0x80},
2552         {0x380e ,0x3 },
2553         {0x380f ,0xe8},
2554         {0x5001 ,0x7f},
2555         {0x5680 ,0x0 },
2556         {0x5681 ,0x0 },
2557         {0x5682 ,0x4 },
2558         {0x5683 ,0x96},
2559         {0x5684 ,0x0 },
2560         {0x5685 ,0x0 },
2561         {0x5686 ,0x3 },
2562         {0x5687 ,0xc0},
2563     {0x0000,0x00}
2564 };
2565
2566 /* 320*240 QVGA */
2567 static  struct reginfo sensor_qvga[] =
2568 {
2569         {0x0000,0x00}
2570 };
2571
2572 /* 176X144 QCIF*/
2573 static struct reginfo sensor_qcif[] =
2574 {
2575         {0x3800 ,0x1 },
2576         {0x3801 ,0x50},
2577         {0x3802 ,0x0 },
2578         {0x3803 ,0x8 },
2579         {0x3804 ,0x4 },
2580         {0x3805 ,0x96},
2581         {0x3806 ,0x3 },
2582         {0x3807 ,0xc0},
2583         {0x3808 ,0x0 },
2584         {0x3809 ,0xb0},
2585         {0x380a ,0x0 },
2586         {0x380b ,0x90},
2587         {0x380c ,0xc },
2588         {0x380d ,0x80},
2589         {0x380e ,0x3 },
2590         {0x380f ,0xe8},
2591         {0x5001 ,0x7f},
2592         {0x5680 ,0x0 },
2593         {0x5681 ,0x0 },
2594         {0x5682 ,0x4 },
2595         {0x5683 ,0x96},
2596         {0x5684 ,0x0 },
2597         {0x5685 ,0x0 },
2598         {0x5686 ,0x3 },
2599         {0x5687 ,0xc0},
2600         {0x0000,0x00}
2601 };
2602 #if 0
2603 /* 160X120 QQVGA*/
2604 static struct reginfo ov2655_qqvga[] =
2605 {
2606
2607     {0x300E, 0x34},
2608     {0x3011, 0x01},
2609     {0x3012, 0x10},
2610     {0x302a, 0x02},
2611     {0x302b, 0xE6},
2612     {0x306f, 0x14},
2613     {0x3362, 0x90},
2614
2615     {0x3070, 0x5d},
2616     {0x3072, 0x5d},
2617     {0x301c, 0x07},
2618     {0x301d, 0x07},
2619
2620     {0x3020, 0x01},
2621     {0x3021, 0x18},
2622     {0x3022, 0x00},
2623     {0x3023, 0x06},
2624     {0x3024, 0x06},
2625     {0x3025, 0x58},
2626     {0x3026, 0x02},
2627     {0x3027, 0x61},
2628     {0x3088, 0x00},
2629     {0x3089, 0xa0},
2630     {0x308a, 0x00},
2631     {0x308b, 0x78},
2632     {0x3316, 0x64},
2633     {0x3317, 0x25},
2634     {0x3318, 0x80},
2635     {0x3319, 0x08},
2636     {0x331a, 0x0a},
2637     {0x331b, 0x07},
2638     {0x331c, 0x80},
2639     {0x331d, 0x38},
2640     {0x3100, 0x00},
2641     {0x3302, 0x11},
2642
2643     {0x0, 0x0},
2644 };
2645
2646
2647
2648 static  struct reginfo ov2655_Sharpness_auto[] =
2649 {
2650     {0x3306, 0x00},
2651 };
2652
2653 static  struct reginfo ov2655_Sharpness1[] =
2654 {
2655     {0x3306, 0x08},
2656     {0x3371, 0x00},
2657 };
2658
2659 static  struct reginfo ov2655_Sharpness2[][3] =
2660 {
2661     //Sharpness 2
2662     {0x3306, 0x08},
2663     {0x3371, 0x01},
2664 };
2665
2666 static  struct reginfo ov2655_Sharpness3[] =
2667 {
2668     //default
2669     {0x3306, 0x08},
2670     {0x332d, 0x02},
2671 };
2672 static  struct reginfo ov2655_Sharpness4[]=
2673 {
2674     //Sharpness 4
2675     {0x3306, 0x08},
2676     {0x332d, 0x03},
2677 };
2678
2679 static  struct reginfo ov2655_Sharpness5[] =
2680 {
2681     //Sharpness 5
2682     {0x3306, 0x08},
2683     {0x332d, 0x04},
2684 };
2685 #endif
2686
2687 static  struct reginfo sensor_ClrFmt_YUYV[]=
2688 {
2689     {0x4300, 0x30},
2690     {0x0000, 0x00}
2691 };
2692
2693 static  struct reginfo sensor_ClrFmt_UYVY[]=
2694 {
2695     {0x4300, 0x32},
2696     {0x0000, 0x00}
2697 };
2698
2699
2700 #if CONFIG_SENSOR_WhiteBalance
2701 static  struct reginfo sensor_WhiteB_Auto[]=
2702 {
2703     {0x3406 ,0x0 },
2704     {0x5192 ,0x04},
2705     {0x5191 ,0xf8},
2706     {0x518d ,0x26},
2707     {0x518f ,0x42},
2708     {0x518e ,0x2b},
2709     {0x5190 ,0x42},
2710     {0x518b ,0xd0},
2711     {0x518c ,0xbd},
2712     {0x5187 ,0x18},
2713     {0x5188 ,0x18},
2714     {0x5189 ,0x56},
2715     {0x518a ,0x5c},
2716     {0x5186 ,0x1c},
2717     {0x5181 ,0x50},
2718     {0x5184 ,0x20},
2719     {0x5182 ,0x11},
2720     {0x5183 ,0x0 },
2721         {0x0000,0x00}
2722 };
2723 /* Cloudy Colour Temperature : 6500K - 8000K  */
2724 static  struct reginfo sensor_WhiteB_Cloudy[]=
2725 {
2726     {0x3406, 0x01},
2727     {0x3400, 0x07},
2728     {0x3401, 0x88},
2729     {0x3402, 0x04},
2730     {0x3403, 0x00},
2731     {0x3404, 0x05},
2732     {0x3405, 0x00},
2733     {0x0000, 0x00}
2734 };
2735 /* ClearDay Colour Temperature : 5000K - 6500K  */
2736 static  struct reginfo sensor_WhiteB_ClearDay[]=
2737 {
2738     //Sunny
2739     {0x3406, 0x01},
2740     {0x3400, 0x07},
2741     {0x3401, 0x32},
2742     {0x3402, 0x04},
2743     {0x3403, 0x00},
2744     {0x3404, 0x05},
2745     {0x3405, 0x36},
2746     {0x0000, 0x00}
2747 };
2748 /* Office Colour Temperature : 3500K - 5000K  */
2749 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
2750 {
2751     //Office
2752     {0x3406, 0x01},
2753     {0x3400, 0x06},
2754     {0x3401, 0x13},
2755     {0x3402, 0x04},
2756     {0x3403, 0x00},
2757     {0x3404, 0x07},
2758     {0x3405, 0xe2},
2759     {0x0000, 0x00}
2760
2761 };
2762 /* Home Colour Temperature : 2500K - 3500K  */
2763 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
2764 {
2765     //Home
2766     {0x3406, 0x01},
2767     {0x3400, 0x04},
2768     {0x3401, 0x88},
2769     {0x3402, 0x04},
2770     {0x3403, 0x00},
2771     {0x3404, 0x08},
2772     {0x3405, 0xb6},
2773     {0x0000, 0x00}
2774 };
2775 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
2776     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
2777 };
2778 #endif
2779
2780 #if CONFIG_SENSOR_Brightness
2781 static  struct reginfo sensor_Brightness0[]=
2782 {
2783     {0x0000, 0x00}
2784 };
2785
2786 static  struct reginfo sensor_Brightness1[]=
2787 {
2788     {0x0000, 0x00}
2789 };
2790
2791 static  struct reginfo sensor_Brightness2[]=
2792 {
2793     {0x0000, 0x00}
2794 };
2795
2796 static  struct reginfo sensor_Brightness3[]=
2797 {
2798     {0x0000, 0x00}
2799 };
2800
2801 static  struct reginfo sensor_Brightness4[]=
2802 {
2803     {0x0000, 0x00}
2804 };
2805
2806 static  struct reginfo sensor_Brightness5[]=
2807 {
2808     {0x0000, 0x00}
2809 };
2810 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
2811     sensor_Brightness4, sensor_Brightness5,NULL,
2812 };
2813
2814 #endif
2815
2816 #if CONFIG_SENSOR_Effect
2817 static  struct reginfo sensor_Effect_Normal[] =
2818 {
2819     {0x5001, 0x7f},
2820         {0x5580, 0x00},
2821     {0x0000, 0x00}
2822 };
2823
2824 static  struct reginfo sensor_Effect_WandB[] =
2825 {
2826     {0x5001, 0xff},
2827         {0x5580, 0x18},
2828         {0x5585, 0x80},
2829         {0x5586, 0x80},
2830     {0x0000, 0x00}
2831 };
2832
2833 static  struct reginfo sensor_Effect_Sepia[] =
2834 {
2835     {0x5001, 0xff},
2836         {0x5580, 0x18},
2837         {0x5585, 0x40},
2838         {0x5586, 0xa0},
2839     {0x0000, 0x00}
2840 };
2841
2842 static  struct reginfo sensor_Effect_Negative[] =
2843 {
2844     //Negative
2845     {0x5001, 0xff},
2846         {0x5580, 0x40},
2847         {0x0000, 0x00}
2848 };
2849 static  struct reginfo sensor_Effect_Bluish[] =
2850 {
2851     // Bluish
2852     {0x5001, 0xff},
2853         {0x5580, 0x18},
2854         {0x5585, 0xa0},
2855         {0x5586, 0x40},
2856     {0x0000, 0x00}
2857 };
2858
2859 static  struct reginfo sensor_Effect_Green[] =
2860 {
2861     //  Greenish
2862     {0x5001, 0xff},
2863         {0x5580, 0x18},
2864         {0x5585, 0x60},
2865         {0x5586, 0x60},
2866     {0x0000, 0x00}
2867 };
2868 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
2869     sensor_Effect_Bluish, sensor_Effect_Green,NULL,
2870 };
2871 #endif
2872 #if CONFIG_SENSOR_Exposure
2873 static  struct reginfo sensor_Exposure0[]=
2874 {
2875     {0x0000, 0x00}
2876 };
2877
2878 static  struct reginfo sensor_Exposure1[]=
2879 {
2880     {0x0000, 0x00}
2881 };
2882
2883 static  struct reginfo sensor_Exposure2[]=
2884 {
2885     {0x0000, 0x00}
2886 };
2887
2888 static  struct reginfo sensor_Exposure3[]=
2889 {
2890     {0x0000, 0x00}
2891 };
2892
2893 static  struct reginfo sensor_Exposure4[]=
2894 {
2895     {0x0000, 0x00}
2896 };
2897
2898 static  struct reginfo sensor_Exposure5[]=
2899 {
2900     {0x0000, 0x00}
2901 };
2902
2903 static  struct reginfo sensor_Exposure6[]=
2904 {
2905     {0x0000, 0x00}
2906 };
2907
2908 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
2909     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
2910 };
2911 #endif
2912 #if CONFIG_SENSOR_Saturation
2913 static  struct reginfo sensor_Saturation0[]=
2914 {
2915     {0x0000, 0x00}
2916 };
2917
2918 static  struct reginfo sensor_Saturation1[]=
2919 {
2920     {0x0000, 0x00}
2921 };
2922
2923 static  struct reginfo sensor_Saturation2[]=
2924 {
2925     {0x0000, 0x00}
2926 };
2927 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
2928
2929 #endif
2930 #if CONFIG_SENSOR_Contrast
2931 static  struct reginfo sensor_Contrast0[]=
2932 {
2933     {0x0000, 0x00}
2934 };
2935
2936 static  struct reginfo sensor_Contrast1[]=
2937 {
2938     {0x0000, 0x00}
2939 };
2940
2941 static  struct reginfo sensor_Contrast2[]=
2942 {
2943     {0x0000, 0x00}
2944 };
2945
2946 static  struct reginfo sensor_Contrast3[]=
2947 {
2948     {0x0000, 0x00}
2949 };
2950
2951 static  struct reginfo sensor_Contrast4[]=
2952 {
2953     {0x0000, 0x00}
2954 };
2955
2956
2957 static  struct reginfo sensor_Contrast5[]=
2958 {
2959     {0x0000, 0x00}
2960 };
2961
2962 static  struct reginfo sensor_Contrast6[]=
2963 {
2964     {0x0000, 0x00}
2965 };
2966 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
2967     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
2968 };
2969
2970 #endif
2971 #if CONFIG_SENSOR_Mirror
2972 static  struct reginfo sensor_MirrorOn[]=
2973 {
2974     {0x0000, 0x00}
2975 };
2976
2977 static  struct reginfo sensor_MirrorOff[]=
2978 {
2979     {0x0000, 0x00}
2980 };
2981 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
2982 #endif
2983 #if CONFIG_SENSOR_Flip
2984 static  struct reginfo sensor_FlipOn[]=
2985 {
2986     {0x0000, 0x00}
2987 };
2988
2989 static  struct reginfo sensor_FlipOff[]=
2990 {
2991     {0x0000, 0x00}
2992 };
2993 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
2994
2995 #endif
2996 #if CONFIG_SENSOR_Scene
2997 static  struct reginfo sensor_SceneAuto[] =
2998 {
2999         {0x3a00, 0x78},
3000         {0x0000, 0x00}
3001 };
3002
3003 static  struct reginfo sensor_SceneNight[] =
3004 {
3005
3006     //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk
3007     {0x3011, 0x08},
3008     {0x3012, 0x00},
3009     {0x3010, 0x10},
3010     {0x460c, 0x22},
3011     {0x380c, 0x0c},
3012     {0x380d, 0x80},
3013     {0x3a00, 0x7c},
3014     {0x3a08, 0x09},
3015     {0x3a09, 0x60},
3016     {0x3a0a, 0x07},
3017     {0x3a0b, 0xd0},
3018     {0x3a0d, 0x08},
3019     {0x3a0e, 0x06},
3020     {0x3a03, 0xfa},
3021     {0x0000, 0x00}
3022
3023 };
3024 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
3025
3026 #endif
3027 #if CONFIG_SENSOR_DigitalZoom
3028 static struct reginfo sensor_Zoom0[] =
3029 {
3030     {0x0, 0x0},
3031 };
3032
3033 static struct reginfo sensor_Zoom1[] =
3034 {
3035      {0x0, 0x0},
3036 };
3037
3038 static struct reginfo sensor_Zoom2[] =
3039 {
3040     {0x0, 0x0},
3041 };
3042
3043
3044 static struct reginfo sensor_Zoom3[] =
3045 {
3046     {0x0, 0x0},
3047 };
3048 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
3049 #endif
3050 static const struct v4l2_querymenu sensor_menus[] =
3051 {
3052         #if CONFIG_SENSOR_WhiteBalance
3053     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
3054     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
3055     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
3056     #endif
3057
3058         #if CONFIG_SENSOR_Effect
3059     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
3060     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
3061     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},
3062     #endif
3063
3064         #if CONFIG_SENSOR_Scene
3065     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
3066     #endif
3067
3068         #if CONFIG_SENSOR_Flash
3069     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
3070     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
3071     #endif
3072 };
3073
3074 static const struct v4l2_queryctrl sensor_controls[] =
3075 {
3076         #if CONFIG_SENSOR_WhiteBalance
3077     {
3078         .id             = V4L2_CID_DO_WHITE_BALANCE,
3079         .type           = V4L2_CTRL_TYPE_MENU,
3080         .name           = "White Balance Control",
3081         .minimum        = 0,
3082         .maximum        = 4,
3083         .step           = 1,
3084         .default_value = 0,
3085     },
3086     #endif
3087
3088         #if CONFIG_SENSOR_Brightness
3089         {
3090         .id             = V4L2_CID_BRIGHTNESS,
3091         .type           = V4L2_CTRL_TYPE_INTEGER,
3092         .name           = "Brightness Control",
3093         .minimum        = -3,
3094         .maximum        = 2,
3095         .step           = 1,
3096         .default_value = 0,
3097     },
3098     #endif
3099
3100         #if CONFIG_SENSOR_Effect
3101         {
3102         .id             = V4L2_CID_EFFECT,
3103         .type           = V4L2_CTRL_TYPE_MENU,
3104         .name           = "Effect Control",
3105         .minimum        = 0,
3106         .maximum        = 5,
3107         .step           = 1,
3108         .default_value = 0,
3109     },
3110         #endif
3111
3112         #if CONFIG_SENSOR_Exposure
3113         {
3114         .id             = V4L2_CID_EXPOSURE,
3115         .type           = V4L2_CTRL_TYPE_INTEGER,
3116         .name           = "Exposure Control",
3117         .minimum        = 0,
3118         .maximum        = 6,
3119         .step           = 1,
3120         .default_value = 0,
3121     },
3122         #endif
3123
3124         #if CONFIG_SENSOR_Saturation
3125         {
3126         .id             = V4L2_CID_SATURATION,
3127         .type           = V4L2_CTRL_TYPE_INTEGER,
3128         .name           = "Saturation Control",
3129         .minimum        = 0,
3130         .maximum        = 2,
3131         .step           = 1,
3132         .default_value = 0,
3133     },
3134     #endif
3135
3136         #if CONFIG_SENSOR_Contrast
3137         {
3138         .id             = V4L2_CID_CONTRAST,
3139         .type           = V4L2_CTRL_TYPE_INTEGER,
3140         .name           = "Contrast Control",
3141         .minimum        = -3,
3142         .maximum        = 3,
3143         .step           = 1,
3144         .default_value = 0,
3145     },
3146         #endif
3147
3148         #if CONFIG_SENSOR_Mirror
3149         {
3150         .id             = V4L2_CID_HFLIP,
3151         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3152         .name           = "Mirror Control",
3153         .minimum        = 0,
3154         .maximum        = 1,
3155         .step           = 1,
3156         .default_value = 1,
3157     },
3158     #endif
3159
3160         #if CONFIG_SENSOR_Flip
3161         {
3162         .id             = V4L2_CID_VFLIP,
3163         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3164         .name           = "Flip Control",
3165         .minimum        = 0,
3166         .maximum        = 1,
3167         .step           = 1,
3168         .default_value = 1,
3169     },
3170     #endif
3171
3172         #if CONFIG_SENSOR_Scene
3173     {
3174         .id             = V4L2_CID_SCENE,
3175         .type           = V4L2_CTRL_TYPE_MENU,
3176         .name           = "Scene Control",
3177         .minimum        = 0,
3178         .maximum        = 1,
3179         .step           = 1,
3180         .default_value = 0,
3181     },
3182     #endif
3183
3184         #if CONFIG_SENSOR_DigitalZoom
3185     {
3186         .id             = V4L2_CID_ZOOM_RELATIVE,
3187         .type           = V4L2_CTRL_TYPE_INTEGER,
3188         .name           = "DigitalZoom Control",
3189         .minimum        = -1,
3190         .maximum        = 1,
3191         .step           = 1,
3192         .default_value = 0,
3193     }, {
3194         .id             = V4L2_CID_ZOOM_ABSOLUTE,
3195         .type           = V4L2_CTRL_TYPE_INTEGER,
3196         .name           = "DigitalZoom Control",
3197         .minimum        = 0,
3198         .maximum        = 3,
3199         .step           = 1,
3200         .default_value = 0,
3201     },
3202     #endif
3203
3204         #if CONFIG_SENSOR_Focus
3205         {
3206         .id             = V4L2_CID_FOCUS_RELATIVE,
3207         .type           = V4L2_CTRL_TYPE_INTEGER,
3208         .name           = "Focus Control",
3209         .minimum        = -1,
3210         .maximum        = 1,
3211         .step           = 1,
3212         .default_value = 0,
3213     }, {
3214         .id             = V4L2_CID_FOCUS_ABSOLUTE,
3215         .type           = V4L2_CTRL_TYPE_INTEGER,
3216         .name           = "Focus Control",
3217         .minimum        = 0,
3218         .maximum        = 255,
3219         .step           = 1,
3220         .default_value = 125,
3221     },
3222         {
3223         .id             = V4L2_CID_FOCUS_AUTO,
3224         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3225         .name           = "Focus Control",
3226         .minimum        = 0,
3227         .maximum        = 1,
3228         .step           = 1,
3229         .default_value = 0,
3230     },{
3231         .id             = V4L2_CID_FOCUS_CONTINUOUS,
3232         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3233         .name           = "Focus Control",
3234         .minimum        = 0,
3235         .maximum        = 1,
3236         .step           = 1,
3237         .default_value = 0,
3238     },
3239     #endif
3240
3241         #if CONFIG_SENSOR_Flash
3242         {
3243         .id             = V4L2_CID_FLASH,
3244         .type           = V4L2_CTRL_TYPE_MENU,
3245         .name           = "Flash Control",
3246         .minimum        = 0,
3247         .maximum        = 3,
3248         .step           = 1,
3249         .default_value = 0,
3250     },
3251         #endif
3252 };
3253
3254 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
3255 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
3256 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
3257 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
3258 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
3259 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
3260 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
3261 static int sensor_resume(struct soc_camera_device *icd);
3262 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
3263 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
3264 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
3265 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
3266 static int sensor_deactivate(struct i2c_client *client);
3267 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
3268 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
3269
3270 static struct soc_camera_ops sensor_ops =
3271 {
3272     .suspend                     = sensor_suspend,
3273     .resume                       = sensor_resume,
3274     .set_bus_param              = sensor_set_bus_param,
3275     .query_bus_param    = sensor_query_bus_param,
3276     .controls           = sensor_controls,
3277     .menus                         = sensor_menus,
3278     .num_controls               = ARRAY_SIZE(sensor_controls),
3279     .num_menus          = ARRAY_SIZE(sensor_menus),
3280 };
3281
3282 /* only one fixed colorspace per pixelcode */
3283 struct sensor_datafmt {
3284         enum v4l2_mbus_pixelcode code;
3285         enum v4l2_colorspace colorspace;
3286 };
3287
3288 /* Find a data format by a pixel code in an array */
3289 static const struct sensor_datafmt *sensor_find_datafmt(
3290         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
3291         int n)
3292 {
3293         int i;
3294         for (i = 0; i < n; i++)
3295                 if (fmt[i].code == code)
3296                         return fmt + i;
3297
3298         return NULL;
3299 }
3300
3301 static const struct sensor_datafmt sensor_colour_fmts[] = {
3302     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
3303     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
3304 };
3305 enum sensor_wq_cmd
3306 {
3307     WqCmd_af_init,
3308     WqCmd_af_single,
3309     WqCmd_af_special_pos,
3310     WqCmd_af_far_pos,
3311     WqCmd_af_near_pos,
3312     WqCmd_af_continues,
3313     WqCmd_af_update_zone
3314 };
3315 enum sensor_wq_result
3316 {
3317     WqRet_success = 0,
3318     WqRet_fail = -1,
3319     WqRet_inval = -2
3320 };
3321 struct sensor_work
3322 {
3323         struct i2c_client *client;
3324         struct delayed_work dwork;
3325         enum sensor_wq_cmd cmd;
3326     wait_queue_head_t done;
3327     enum sensor_wq_result result;
3328     bool wait;
3329     int var;    
3330 };
3331 typedef struct sensor_info_priv_s
3332 {
3333     int whiteBalance;
3334     int brightness;
3335     int contrast;
3336     int saturation;
3337     int effect;
3338     int scene;
3339     int digitalzoom;
3340     int focus;
3341         int auto_focus;
3342         int affm_reinit;
3343     int flash;
3344     int exposure;
3345     unsigned char mirror;                                        /* HFLIP */
3346     unsigned char flip;                                          /* VFLIP */
3347         bool snap2preview;
3348         bool video2preview;
3349     struct reginfo *winseqe_cur_addr;
3350         struct sensor_datafmt fmt;
3351         unsigned int enable;
3352         unsigned int funmodule_state;
3353 } sensor_info_priv_t;
3354
3355
3356
3357 struct sensor_parameter
3358 {
3359         unsigned short int preview_maxlines;
3360         unsigned short int preview_exposure;
3361         unsigned short int preview_line_width;
3362         unsigned short int preview_gain;
3363
3364         unsigned short int capture_framerate;
3365         unsigned short int preview_framerate;
3366 };
3367
3368 struct sensor
3369 {
3370     struct v4l2_subdev subdev;
3371     struct i2c_client *client;
3372     sensor_info_priv_t info_priv;
3373         struct sensor_parameter parameter;
3374         struct workqueue_struct *sensor_wq;
3375         struct mutex wq_lock;
3376     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
3377 #if CONFIG_SENSOR_I2C_NOSCHED
3378         atomic_t tasklock_cnt; 
3379 #endif
3380         struct rkcamera_platform_data *sensor_io_request;
3381     struct rkcamera_gpio_res *sensor_gpio_res;
3382 };
3383
3384 static struct sensor* to_sensor(const struct i2c_client *client)
3385 {
3386     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
3387 }
3388
3389 static int sensor_task_lock(struct i2c_client *client, int lock)
3390 {
3391 #if CONFIG_SENSOR_I2C_NOSCHED
3392         int cnt = 3;
3393     struct sensor *sensor = to_sensor(client);
3394
3395         if (lock) {
3396                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
3397                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
3398                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
3399                                 msleep(35);
3400                                 cnt--;
3401                         }
3402                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
3403                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
3404                                 goto sensor_task_lock_err;
3405                         }
3406                         preempt_disable();
3407                 }
3408
3409                 atomic_add(1, &sensor->tasklock_cnt);
3410         } else {
3411                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
3412                         atomic_sub(1, &sensor->tasklock_cnt);
3413
3414                         if (atomic_read(&sensor->tasklock_cnt) == 0)
3415                                 preempt_enable();
3416                 }
3417         }
3418         return 0;
3419 sensor_task_lock_err:
3420         return -1;   
3421 #else
3422     return 0;
3423 #endif
3424
3425 }
3426
3427 /* sensor register write */
3428 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
3429 {
3430     int err,cnt;
3431     u8 buf[3];
3432     struct i2c_msg msg[1];
3433
3434     buf[0] = reg >> 8;
3435     buf[1] = reg & 0xFF;
3436     buf[2] = val;
3437
3438     msg->addr = client->addr;
3439     msg->flags = client->flags;
3440     msg->buf = buf;
3441     msg->len = sizeof(buf);
3442     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
3443     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
3444
3445     cnt = 3;
3446     err = -EAGAIN;
3447
3448     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
3449         err = i2c_transfer(client->adapter, msg, 1);
3450
3451         if (err >= 0) {
3452             return 0;
3453         } else {
3454             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
3455             udelay(10);
3456         }
3457     }
3458
3459     return err;
3460 }
3461
3462 /* sensor register read */
3463 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
3464 {
3465     int err,cnt;
3466     u8 buf[2];
3467     struct i2c_msg msg[2];
3468
3469     buf[0] = reg >> 8;
3470     buf[1] = reg & 0xFF;
3471
3472     msg[0].addr = client->addr;
3473     msg[0].flags = client->flags;
3474     msg[0].buf = buf;
3475     msg[0].len = sizeof(buf);
3476     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
3477     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
3478
3479     msg[1].addr = client->addr;
3480     msg[1].flags = client->flags|I2C_M_RD;
3481     msg[1].buf = buf;
3482     msg[1].len = 1;
3483     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
3484     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
3485
3486     cnt = 3;
3487     err = -EAGAIN;
3488     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
3489         err = i2c_transfer(client->adapter, msg, 2);
3490
3491         if (err >= 0) {
3492             *val = buf[0];
3493             return 0;
3494         } else {
3495                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
3496             udelay(10);
3497         }
3498     }
3499
3500     return err;
3501 }
3502
3503 /* write a array of registers  */
3504 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
3505 {
3506     int err = 0, cnt;
3507     int i = 0;
3508 #if CONFIG_SENSOR_Focus
3509         struct sensor *sensor = to_sensor(client);
3510 #endif
3511 #if CONFIG_SENSOR_I2C_RDWRCHK
3512         char valchk;
3513 #endif
3514
3515         cnt = 0;
3516         if (sensor_task_lock(client, 1) < 0)
3517                 goto sensor_write_array_end;
3518     while (regarray[i].reg != 0)
3519     {
3520         #if CONFIG_SENSOR_Focus
3521         if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
3522                         SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
3523                         err = -EINVAL;
3524                         goto sensor_write_array_end;
3525         }
3526                 #endif
3527
3528         err = sensor_write(client, regarray[i].reg, regarray[i].val);
3529         if (err < 0)
3530         {
3531             if (cnt-- > 0) {
3532                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
3533                                 i = 0;
3534                                 continue;
3535             } else {
3536                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
3537                 err = -EPERM;
3538                                 goto sensor_write_array_end;
3539             }
3540         } else {
3541         #if CONFIG_SENSOR_I2C_RDWRCHK
3542                         sensor_read(client, regarray[i].reg, &valchk);
3543                         if (valchk != regarray[i].val)
3544                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
3545                 #endif
3546         }
3547
3548         i++;
3549     }
3550
3551         #if CONFIG_SENSOR_Focus
3552         if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
3553                 || (regarray == sensor_init_data)) {
3554                 sensor->info_priv.affm_reinit = 1;
3555         }
3556         #endif
3557
3558 sensor_write_array_end:
3559         sensor_task_lock(client,0);
3560     return err;
3561 }
3562 #if CONFIG_SENSOR_I2C_RDWRCHK
3563 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
3564 {
3565     int cnt;
3566     int i = 0;
3567         char valchk;
3568
3569         cnt = 0;
3570         valchk = 0;
3571     while (regarray[i].reg != 0)
3572     {
3573                 sensor_read(client, regarray[i].reg, &valchk);
3574                 if (valchk != regarray[i].val)
3575                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
3576
3577         i++;
3578     }
3579     return 0;
3580 }
3581 #endif
3582 #if CONFIG_SENSOR_Focus
3583 struct af_cmdinfo
3584 {
3585         char cmd_tag;
3586         char cmd_para[4];
3587         char validate_bit;
3588 };
3589 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
3590 {
3591         int i;
3592         char read_tag=0xff,cnt;
3593     struct sensor *sensor = to_sensor(client);
3594
3595     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3596         SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3597         goto sensor_af_cmdset_err;
3598     }
3599
3600         if (cmdinfo) {
3601                 if (cmdinfo->validate_bit & 0x80) {
3602                         if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
3603                                 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
3604                                 goto sensor_af_cmdset_err;
3605                         }
3606                         SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
3607                 }
3608                 for (i=0; i<4; i++) {
3609                         if (cmdinfo->validate_bit & (1<<i)) {
3610                                 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
3611                                         SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
3612                                         goto sensor_af_cmdset_err;
3613                                 }
3614                                 SENSOR_DG("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
3615                         }
3616                 }
3617         } else {
3618                 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
3619                         SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
3620                         goto sensor_af_cmdset_err;
3621                 }
3622                 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
3623         }
3624
3625         if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
3626                 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
3627                 goto sensor_af_cmdset_err;
3628         }
3629
3630         cnt = 0;
3631         do
3632         {
3633                 msleep(5);
3634                 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
3635                    SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
3636                    break;
3637                 }
3638     } while((read_tag != 0x00)&& (cnt++<100));
3639
3640         SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
3641         return 0;
3642 sensor_af_cmdset_err:
3643         return -1;
3644 }
3645
3646 static int sensor_af_idlechk(struct i2c_client *client)
3647 {
3648         int ret = 0;
3649         char state,cnt;
3650     struct sensor *sensor = to_sensor(client);
3651
3652     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3653         SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3654         ret = -1;
3655         goto sensor_af_idlechk_end;
3656     }
3657
3658         cnt = 0;
3659         do
3660         {
3661                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3662                 if (ret != 0){
3663                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3664                    ret = -1;
3665                    goto sensor_af_idlechk_end;
3666                 }
3667
3668                 if (state != S_IDLE) {
3669                         sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
3670                         msleep(1);
3671                         cnt++;
3672                 }
3673     } while((state != S_IDLE)&& (cnt<20));
3674
3675         ret = (state == S_IDLE) ? 0 : -1;
3676
3677 sensor_af_idlechk_end:
3678         return ret;
3679 }
3680
3681 static int sensor_af_single(struct i2c_client *client)
3682 {
3683         int ret = 0;
3684         char state,cnt;
3685     struct sensor *sensor = to_sensor(client);
3686
3687     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3688         SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3689         ret = -1;
3690         goto sensor_af_single_end;
3691     }
3692     
3693         if (sensor_af_idlechk(client))
3694                 goto sensor_af_single_end;
3695
3696         if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
3697                 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
3698                 ret = -1;
3699                 goto sensor_af_single_end;
3700         }
3701
3702         cnt = 0;
3703     do
3704     {
3705         if (cnt != 0) {
3706                         msleep(1);
3707         }
3708         cnt++;
3709                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3710                 if (ret != 0){
3711                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3712                    ret = -1;
3713                    goto sensor_af_single_end;
3714                 }
3715     }while((state == S_FOCUSING) && (cnt<100));
3716
3717         if (state != S_FOCUSED) {
3718         SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
3719                 ret = -1;
3720                 goto sensor_af_single_end;
3721     }
3722 sensor_af_single_end:
3723         return ret;
3724 }
3725
3726 static int sensor_af_const(struct i2c_client *client)
3727 {
3728         int ret = 0;
3729     struct sensor *sensor = to_sensor(client);
3730
3731     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3732         SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3733         ret = -1;
3734         goto sensor_af_const_end;
3735     }
3736     
3737         if (sensor_af_idlechk(client))
3738                 goto sensor_af_const_end;
3739
3740         if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
3741                 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
3742                 ret = -1;
3743                 goto sensor_af_const_end;
3744         }
3745 sensor_af_const_end:
3746         return ret;
3747 }
3748 static int sensor_af_pause2capture(struct i2c_client *client)
3749 {
3750         int ret = 0;
3751         char state,cnt;
3752     struct sensor *sensor = to_sensor(client);
3753
3754     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3755         SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3756         ret = -1;
3757         goto sensor_af_pause_end;
3758     }
3759     
3760         if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
3761                 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
3762                 ret = -1;
3763                 goto sensor_af_pause_end;
3764         }
3765
3766         cnt = 0;
3767     do
3768     {
3769         if (cnt != 0) {
3770                         msleep(1);
3771         }
3772         cnt++;
3773                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3774                 if (ret != 0){
3775                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3776                    ret = -1;
3777                    goto sensor_af_pause_end;
3778                 }
3779     }while((state != S_CAPTURE) && (cnt<100));
3780
3781         if (state != S_CAPTURE) {
3782         SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
3783                 ret = -1;
3784                 goto sensor_af_pause_end;
3785     }
3786 sensor_af_pause_end:
3787         return ret;
3788 }
3789 static int sensor_af_zoneupdate(struct i2c_client *client)
3790 {
3791         int ret = 0;
3792     struct sensor *sensor = to_sensor(client);
3793
3794     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) == 0) {
3795         SENSOR_TR("%s %s cancel,because auto focus firmware is invalidate!",SENSOR_NAME_STRING(), __FUNCTION__);
3796         ret = -1;
3797         goto sensor_af_zoneupdate_end;
3798     }
3799     
3800         if (sensor_af_idlechk(client))
3801                 goto sensor_af_zoneupdate_end;
3802
3803         if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
3804                 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
3805                 ret = -1;
3806                 goto sensor_af_zoneupdate_end;
3807         }
3808
3809 sensor_af_zoneupdate_end:
3810         return ret;
3811 }
3812 static int sensor_af_init(struct i2c_client *client)
3813 {
3814         int ret = 0;
3815         char state,cnt;
3816
3817         ret = sensor_write_array(client, sensor_af_firmware);
3818     if (ret != 0) {
3819        SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
3820        ret = -1;
3821            goto sensor_af_init_end;
3822     }
3823
3824         cnt = 0;
3825     do
3826     {
3827         if (cnt != 0) {
3828                         msleep(1);
3829         }
3830         cnt++;
3831                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
3832                 if (ret != 0){
3833                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
3834                    ret = -1;
3835                    goto sensor_af_init_end;
3836                 }
3837     }while((state == S_STARTUP) && (cnt<100));
3838
3839     if (state != S_IDLE) {
3840         SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
3841                 ret = -1;
3842                 goto sensor_af_init_end;
3843     }
3844
3845 sensor_af_init_end:
3846         SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
3847         return ret;
3848 }
3849
3850 static int sensor_af_downfirmware(struct i2c_client *client)
3851 {
3852         struct sensor *sensor = to_sensor(client);
3853         struct af_cmdinfo cmdinfo;
3854         int ret=0, focus_pos = 0xfe;
3855     struct soc_camera_device *icd = client->dev.platform_data;
3856     struct v4l2_mbus_framefmt mf;
3857                 
3858         SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
3859     
3860         if (sensor_af_init(client)) {
3861                 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
3862                 ret = -1;
3863         } else {
3864                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
3865         
3866         mf.width = icd->user_width;
3867                 mf.height = icd->user_height;
3868         mf.code = sensor->info_priv.fmt.code;
3869         mf.colorspace = sensor->info_priv.fmt.colorspace;
3870         mf.field        = V4L2_FIELD_NONE;
3871         if (sensor_fmt_videochk(NULL, &mf) == true) {    /* ddl@rock-chips.com: focus mode fix const auto focus in video */
3872             ret = sensor_af_const(client);
3873         } else {
3874                 switch (sensor->info_priv.auto_focus)
3875                 {
3876                         case SENSOR_AF_MODE_INFINITY:
3877                         {
3878                                 focus_pos = 0x00;
3879                         }
3880                         case SENSOR_AF_MODE_MACRO:
3881                         {
3882                                 if (focus_pos != 0x00)
3883                                         focus_pos = 0xff;
3884
3885                                 sensor_af_idlechk(client);
3886                                 cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3887                                 cmdinfo.cmd_para[0] = focus_pos;
3888                                 cmdinfo.validate_bit = 0x81;
3889                                 ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
3890                                 break;
3891                         }
3892                         case SENSOR_AF_MODE_AUTO:
3893                         {
3894                                 ret = sensor_af_single(client);
3895                                 break;
3896                         }
3897                         case SENSOR_AF_MODE_CONTINUOUS:
3898                         {
3899                                 ret = sensor_af_const(client);
3900                                 break;
3901                         }
3902                         case SENSOR_AF_MODE_CLOSE:
3903                         {
3904                                 ret = 0;
3905                                 break;
3906                         }
3907                         default:
3908                 {
3909                                 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
3910                     goto sensor_af_downfirmware_end;
3911                         }
3912                 }
3913         }
3914                 SENSOR_DG("%s sensor_af_downfirmware set focus mode(0x%x) ret:0x%x\n",SENSOR_NAME_STRING(), sensor->info_priv.auto_focus,ret);
3915         }
3916
3917 sensor_af_downfirmware_end:
3918         
3919         return ret;
3920 }
3921 static void sensor_af_workqueue(struct work_struct *work)
3922 {
3923         struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
3924         struct i2c_client *client = sensor_work->client;
3925     struct sensor *sensor = to_sensor(client);
3926     struct af_cmdinfo cmdinfo;
3927     
3928     SENSOR_DG("%s %s Enter, cmd:0x%x \n",SENSOR_NAME_STRING(), __FUNCTION__,sensor_work->cmd);
3929     
3930     mutex_lock(&sensor->wq_lock);
3931     switch (sensor_work->cmd) 
3932     {
3933         case WqCmd_af_init:
3934         {
3935                 if (sensor_af_downfirmware(client) < 0) {
3936                         SENSOR_TR("%s Sensor_af_init is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3937                 }            
3938             break;
3939         }
3940         case WqCmd_af_single:
3941         {
3942             if (sensor_af_single(client) < 0) {
3943                         SENSOR_TR("%s Sensor_af_single is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3944                 sensor_work->result = WqRet_fail;
3945                 } else {
3946                 sensor_work->result = WqRet_success;
3947                 }
3948             break;
3949         }
3950         case WqCmd_af_special_pos:
3951         {
3952             sensor_af_idlechk(client);
3953
3954                         cmdinfo.cmd_tag = StepFocus_Spec_Tag;
3955                         cmdinfo.cmd_para[0] = sensor_work->var;
3956                         cmdinfo.validate_bit = 0x81;
3957                         if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3958                sensor_work->result = WqRet_fail;
3959             else 
3960                sensor_work->result = WqRet_success;
3961             break;
3962         }
3963         case WqCmd_af_near_pos:
3964         {            
3965             sensor_af_idlechk(client);
3966             cmdinfo.cmd_tag = StepFocus_Near_Tag;
3967             cmdinfo.validate_bit = 0x80;
3968                         if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3969                sensor_work->result = WqRet_fail;
3970             else 
3971                sensor_work->result = WqRet_success;
3972             break;
3973         }
3974         case WqCmd_af_far_pos:
3975         {
3976             sensor_af_idlechk(client);
3977                         cmdinfo.cmd_tag = StepFocus_Far_Tag;
3978                         cmdinfo.validate_bit = 0x80;
3979                         if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3980                sensor_work->result = WqRet_fail;
3981             else 
3982                sensor_work->result = WqRet_success;
3983             break;
3984         }
3985         case WqCmd_af_continues:
3986         {
3987             if (sensor_af_const(client) < 0)
3988                sensor_work->result = WqRet_fail;
3989             else 
3990                sensor_work->result = WqRet_success;
3991             break;
3992         }
3993         case WqCmd_af_update_zone:
3994         {
3995             if (sensor_af_zoneupdate(client) < 0)
3996                sensor_work->result = WqRet_fail;
3997             else 
3998                sensor_work->result = WqRet_success;
3999             break;
4000         }
4001         default:
4002             SENSOR_TR("Unknow command(%d) in %s af workqueue!",sensor_work->cmd,SENSOR_NAME_STRING());
4003             break;
4004     } 
4005
4006     if (sensor_work->wait == false) {
4007         kfree((void*)sensor_work);
4008     } else {
4009         wake_up(&sensor_work->done); 
4010     }
4011     mutex_unlock(&sensor->wq_lock); 
4012     return;
4013 }
4014
4015 static int sensor_af_workqueue_set(struct soc_camera_device *icd, enum sensor_wq_cmd cmd, int var, bool wait)
4016 {
4017     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4018         struct sensor *sensor = to_sensor(client); 
4019     struct sensor_work *wk;
4020     int ret=0;
4021
4022     if (sensor->sensor_wq == NULL) { 
4023         ret = -EINVAL;
4024         goto sensor_af_workqueue_set_end;
4025     }
4026     
4027     wk = kzalloc(sizeof(struct sensor_work), GFP_KERNEL);
4028     if (wk) {
4029             wk->client = client;
4030             INIT_WORK(&(wk->dwork.work), sensor_af_workqueue);
4031         wk->cmd = cmd;
4032         wk->result = WqRet_inval;
4033         wk->wait = wait;
4034         wk->var = var;
4035         init_waitqueue_head(&wk->done);
4036         
4037             queue_delayed_work(sensor->sensor_wq,&(wk->dwork),0);
4038         
4039         /* ddl@rock-chips.com: 
4040         * video_lock is been locked in v4l2_ioctl function, but auto focus may slow,
4041         * As a result any other ioctl calls will proceed very, very slowly since each call
4042         * will have to wait for the AF to finish. Camera preview is pause,because VIDIOC_QBUF 
4043         * and VIDIOC_DQBUF is sched. so unlock video_lock here.
4044         */
4045         if (wait == true) {
4046             mutex_unlock(&icd->video_lock);                     
4047             if (wait_event_timeout(wk->done, (wk->result != WqRet_inval), msecs_to_jiffies(2500)) == 0) {
4048                 SENSOR_TR("%s %s cmd(%d) is timeout!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);                        
4049             }
4050             ret = wk->result;
4051             kfree((void*)wk);
4052             mutex_lock(&icd->video_lock);  
4053         }
4054         
4055     } else {
4056         SENSOR_TR("%s %s cmd(%d) ingore,because struct sensor_work malloc failed!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4057         ret = -1;
4058     }
4059 sensor_af_workqueue_set_end:
4060     return ret;
4061 }
4062 #endif
4063 static int sensor_parameter_record(struct i2c_client *client)
4064 {
4065         u8 ret_l,ret_m,ret_h;
4066         u8 tp_l,tp_m,tp_h;
4067         struct sensor *sensor = to_sensor(client);
4068
4069         sensor_write(client,0x3503,0x07);       //stop AE/AG
4070         sensor_write(client,0x3406,0x01);   //stop AWB
4071
4072         sensor_read(client,0x3500,&ret_h);
4073         sensor_read(client,0x3501, &ret_m);
4074         sensor_read(client,0x3502, &ret_l);
4075         tp_l = ret_l;
4076         tp_m = ret_m;
4077         tp_h = ret_h;
4078         SENSOR_DG(" %s Read 0x3500 = 0x%02x  0x3501 = 0x%02x 0x3502=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_m, ret_l);
4079         sensor->parameter.preview_exposure = (tp_h<<12)+(tp_m<<4)+(tp_l>>4);
4080         sensor_read(client,0x350c, &ret_h);
4081         sensor_read(client,0x350d, &ret_l);
4082         sensor->parameter.preview_line_width = ret_h & 0xff;
4083         sensor->parameter.preview_line_width = (sensor->parameter.preview_line_width << 8) +ret_l;
4084         //Read back AGC Gain for preview
4085         sensor_read(client,0x350b, &tp_l);
4086         sensor->parameter.preview_gain = tp_l;
4087
4088         sensor->parameter.capture_framerate = 900;
4089         sensor->parameter.preview_framerate = 1500;
4090
4091         SENSOR_DG(" %s Read 0x350c = 0x%02x  0x350d = 0x%02x 0x350b=0x%02x \n",SENSOR_NAME_STRING(), ret_h, ret_l, sensor->parameter.preview_gain);
4092         return 0;
4093 }
4094 static int sensor_ae_transfer(struct i2c_client *client)
4095 {
4096         u8  ExposureLow;
4097         u8  ExposureMid;
4098         u8  ExposureHigh;
4099         u16 ulCapture_Exposure;
4100         u32 ulCapture_Exposure_Gain;
4101         u16  iCapture_Gain;
4102         u8   Lines_10ms;
4103         bool m_60Hz = 0;
4104         u8  reg_l = 0,reg_h =0;
4105         u16 Preview_Maxlines;
4106         u8  Gain;
4107         u32  Capture_MaxLines;
4108         struct sensor *sensor = to_sensor(client);
4109
4110         Preview_Maxlines = sensor->parameter.preview_line_width;
4111         Gain = sensor->parameter.preview_gain;
4112         sensor_read(client,0x350c, &reg_h);
4113         sensor_read(client,0x350d, &reg_l);
4114         Capture_MaxLines = reg_h & 0xff;
4115         Capture_MaxLines = (Capture_MaxLines << 8) + reg_l;
4116
4117         if(m_60Hz== 1) {
4118                 Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/12000;
4119         } else {
4120                 Lines_10ms = sensor->parameter.capture_framerate * Capture_MaxLines/10000;
4121         }
4122
4123         if(Preview_Maxlines == 0)
4124                 Preview_Maxlines = 1;
4125
4126         ulCapture_Exposure =
4127                 (sensor->parameter.preview_exposure*(sensor->parameter.capture_framerate)*(Capture_MaxLines))/(((Preview_Maxlines)*(sensor->parameter.preview_framerate)));
4128         iCapture_Gain = (Gain & 0x0f) + 16;
4129         if (Gain & 0x10) {
4130                 iCapture_Gain = iCapture_Gain << 1;
4131         }
4132         if (Gain & 0x20) {
4133                 iCapture_Gain = iCapture_Gain << 1;
4134         }
4135         if (Gain & 0x40) {
4136                 iCapture_Gain = iCapture_Gain << 1;
4137         }
4138         if (Gain & 0x80) {
4139                 iCapture_Gain = iCapture_Gain << 1;
4140         }
4141         ulCapture_Exposure_Gain =(u32) (11 * ulCapture_Exposure * iCapture_Gain/5);   //0ld value 2.5, ½â¾ö¹ýÁÁ
4142         if(ulCapture_Exposure_Gain < Capture_MaxLines*16) {
4143                 ulCapture_Exposure = ulCapture_Exposure_Gain/16;
4144                 if (ulCapture_Exposure > Lines_10ms)
4145                 {
4146                         //ulCapture_Exposure *= 1.7;
4147                         ulCapture_Exposure /= Lines_10ms;
4148                         ulCapture_Exposure *= Lines_10ms;
4149                 }
4150         } else {
4151                 ulCapture_Exposure = Capture_MaxLines;
4152                 //ulCapture_Exposure_Gain *= 1.5;
4153         }
4154         if(ulCapture_Exposure == 0)
4155                 ulCapture_Exposure = 1;
4156         iCapture_Gain = (ulCapture_Exposure_Gain*2/ulCapture_Exposure + 1)/2;
4157         ExposureLow = ((unsigned char)ulCapture_Exposure)<<4;
4158         ExposureMid = (unsigned char)(ulCapture_Exposure >> 4) & 0xff;
4159         ExposureHigh = (unsigned char)(ulCapture_Exposure >> 12);
4160
4161         Gain = 0;
4162         if (iCapture_Gain > 31) {
4163                 Gain |= 0x10;
4164                 iCapture_Gain = iCapture_Gain >> 1;
4165         }
4166         if (iCapture_Gain > 31) {
4167                 Gain |= 0x20;
4168                 iCapture_Gain = iCapture_Gain >> 1;
4169         }
4170         if (iCapture_Gain > 31) {
4171                 Gain |= 0x40;
4172                 iCapture_Gain = iCapture_Gain >> 1;
4173         }
4174         if (iCapture_Gain > 31) {
4175                 Gain |= 0x80;
4176                 iCapture_Gain = iCapture_Gain >> 1;
4177         }
4178         if (iCapture_Gain > 16)
4179                 Gain |= ((iCapture_Gain -16) & 0x0f);
4180         if(Gain == 0x10)
4181                 Gain = 0x11;
4182         // write the gain and exposure to 0x350* registers
4183         //m_iWrite0x350b=Gain;
4184         sensor_write(client,0x350b, Gain);
4185         //m_iWrite0x3502=ExposureLow;
4186         sensor_write(client,0x3502, ExposureLow);
4187         //m_iWrite0x3501=ExposureMid;
4188         sensor_write(client,0x3501, ExposureMid);
4189         //m_iWrite0x3500=ExposureHigh;
4190         sensor_write(client,0x3500, ExposureHigh);
4191         // SendToFile("Gain = 0x%x\r\n", Gain);
4192         // SendToFile("ExposureLow = 0x%x\r\n", ExposureLow);
4193         // SendToFile("ExposureMid = 0x%x\r\n", ExposureMid);
4194         // SendToFile("ExposureHigh = 0x%x\r\n", ExposureHigh);
4195         //¼Ó³¤ÑÓʱ£¬±ÜÃâ°µ´¦ÅÄÕÕʱµÄÃ÷°µ·Ö½çÎÊÌâ
4196         //camera_timed_wait(200);
4197         //linzhk camera_timed_wait(500);
4198
4199         SENSOR_DG(" %s Write 0x350b = 0x%02x  0x3502 = 0x%02x 0x3501=0x%02x 0x3500 = 0x%02x\n",SENSOR_NAME_STRING(), Gain, ExposureLow, ExposureMid, ExposureHigh);
4200         mdelay(100);
4201         return 0;
4202 }
4203 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
4204 {
4205         struct soc_camera_link *icl = to_soc_camera_link(icd);
4206         int ret = 0;
4207
4208     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
4209
4210         switch (cmd)
4211         {
4212                 case Sensor_PowerDown:
4213                 {
4214                         if (icl->powerdown) {
4215                                 ret = icl->powerdown(icd->pdev, on);
4216                                 if (ret == RK_CAM_IO_SUCCESS) {
4217                                         if (on == 0) {
4218                                                 mdelay(2);
4219                                                 if (icl->reset)
4220                                                         icl->reset(icd->pdev);
4221                                         }
4222                                 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
4223                                         ret = -ENODEV;
4224                                         goto sensor_power_end;
4225                                 }
4226                         }
4227                         break;
4228                 }
4229                 case Sensor_Flash:
4230                 {
4231                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4232                 struct sensor *sensor = to_sensor(client);
4233
4234                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
4235                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
4236                         }
4237                         break;
4238                 }
4239                 default:
4240                 {
4241                         SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
4242                         break;
4243                 }
4244         }
4245
4246 sensor_power_end:
4247         return ret;
4248 }
4249 static int sensor_init(struct v4l2_subdev *sd, u32 val)
4250 {
4251     struct i2c_client *client = v4l2_get_subdevdata(sd);
4252     struct soc_camera_device *icd = client->dev.platform_data;
4253     struct sensor *sensor = to_sensor(client);
4254         const struct v4l2_queryctrl *qctrl;
4255     const struct sensor_datafmt *fmt;
4256     char value;
4257     int ret,pid = 0,i = 0,j=0;
4258     struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
4259     sensor_init_data_p = sensor_init_data;
4260         sensor_init_winseq_p = sensor_svga;
4261         sensor_init_width = 800;
4262         sensor_init_height = 600;
4263         if (tmp_plat_data != NULL) { 
4264                 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
4265                         if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
4266                                 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
4267                                         break;
4268                         }
4269                 }
4270         if(tmp_plat_data  && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
4271         //user has defined the init data
4272                 //init reg
4273                 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
4274                         for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
4275                                 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
4276                                 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
4277                                 }
4278                         sensor_init_data_p = sensor_init_data;
4279                         }
4280                 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
4281                         sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
4282                         }
4283                 //init winseq
4284                 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
4285                         int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
4286                         if(sensor_init_winseq_board)
4287                                 {
4288                                 vfree(sensor_init_winseq_board);
4289                                 sensor_init_winseq_board = NULL;
4290                                 }
4291                         sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
4292                         if(!sensor_init_winseq_board)
4293                                 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
4294                         for(j = 0;j< tmp_winseq_size;j++){
4295                                 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
4296                                 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
4297                                 }
4298                         sensor_init_winseq_p = sensor_init_winseq_board;
4299                         }
4300                 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
4301                         sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
4302                         }
4303                 //init width,height,bus,pixelcode
4304                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
4305                         sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
4306                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
4307                         sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
4308                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
4309                         sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
4310                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
4311                         sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
4312         }
4313     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
4314
4315         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
4316                 ret = -ENODEV;
4317                 goto sensor_INIT_ERR;
4318         }
4319
4320     /* soft reset */
4321         if (sensor_task_lock(client,1)<0)
4322                 goto sensor_INIT_ERR;
4323     ret = sensor_write(client, 0x3008, 0x80);
4324     if (ret != 0) {
4325         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
4326         ret = -ENODEV;
4327                 goto sensor_INIT_ERR;
4328     }
4329
4330     mdelay(5);  //delay 5 microseconds
4331         /* check if it is an sensor sensor */
4332     ret = sensor_read(client, 0x300a, &value);
4333     if (ret != 0) {
4334         SENSOR_TR("read chip id high byte failed\n");
4335         ret = -ENODEV;
4336         goto sensor_INIT_ERR;
4337     }
4338
4339     pid |= (value << 8);
4340
4341     ret = sensor_read(client, 0x300b, &value);
4342     if (ret != 0) {
4343         SENSOR_TR("read chip id low byte failed\n");
4344         ret = -ENODEV;
4345         goto sensor_INIT_ERR;
4346     }
4347
4348     pid |= (value & 0xff);
4349     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
4350
4351     if (pid == SENSOR_ID) {
4352         sensor->model = SENSOR_V4L2_IDENT;
4353     } else {
4354         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4355         ret = -ENODEV;
4356         goto sensor_INIT_ERR;
4357     }
4358
4359     ret = sensor_write_array(client, sensor_init_data_p);
4360     if (ret != 0)
4361     {
4362         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
4363         goto sensor_INIT_ERR;
4364     }
4365         sensor_task_lock(client,0);
4366     sensor->info_priv.winseqe_cur_addr  = SENSOR_INIT_WINSEQADR;
4367     fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
4368     if (!fmt) {
4369         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
4370         ret = -EINVAL;
4371         goto sensor_INIT_ERR;
4372     }
4373         sensor->info_priv.fmt = *fmt;
4374
4375     /* sensor sensor information for initialization  */
4376         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4377         if (qctrl)
4378         sensor->info_priv.whiteBalance = qctrl->default_value;
4379         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
4380         if (qctrl)
4381         sensor->info_priv.brightness = qctrl->default_value;
4382         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4383         if (qctrl)
4384         sensor->info_priv.effect = qctrl->default_value;
4385         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
4386         if (qctrl)
4387         sensor->info_priv.exposure = qctrl->default_value;
4388
4389         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
4390         if (qctrl)
4391         sensor->info_priv.saturation = qctrl->default_value;
4392         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
4393         if (qctrl)
4394         sensor->info_priv.contrast = qctrl->default_value;
4395         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
4396         if (qctrl)
4397         sensor->info_priv.mirror = qctrl->default_value;
4398         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
4399         if (qctrl)
4400         sensor->info_priv.flip = qctrl->default_value;
4401         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
4402         if (qctrl)
4403         sensor->info_priv.scene = qctrl->default_value;
4404         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
4405         if (qctrl)
4406         sensor->info_priv.digitalzoom = qctrl->default_value;
4407
4408     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
4409         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
4410         if (qctrl)
4411         sensor->info_priv.focus = qctrl->default_value;
4412
4413         #if CONFIG_SENSOR_Flash
4414         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
4415         if (qctrl)
4416         sensor->info_priv.flash = qctrl->default_value;
4417     #endif
4418     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);
4419
4420     sensor->info_priv.funmodule_state = SENSOR_INIT_IS_OK;
4421         
4422     return 0;
4423 sensor_INIT_ERR:
4424     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4425         sensor_task_lock(client,0);
4426         sensor_deactivate(client);
4427     return ret;
4428 }
4429 static int sensor_deactivate(struct i2c_client *client)
4430 {
4431         struct soc_camera_device *icd = client->dev.platform_data;
4432     struct sensor *sensor = to_sensor(client);
4433     
4434         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);    
4435     
4436         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
4437     if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
4438         sensor_task_lock(client, 1);
4439         sensor_write(client, 0x3017, 0x00);  // FREX,VSYNC,HREF,PCLK,D9-D6
4440         sensor_write(client, 0x3018, 0x03);  // D5-D0
4441         sensor_write(client,0x3019,0x00);    // STROBE,SDA
4442         sensor_task_lock(client, 0);
4443     } 
4444     sensor_ioctrl(icd, Sensor_PowerDown, 1);
4445     msleep(100); 
4446     
4447         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
4448         icd->user_width = SENSOR_INIT_WIDTH;
4449     icd->user_height = SENSOR_INIT_HEIGHT;
4450     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4451         return 0;
4452 }
4453 static  struct reginfo sensor_power_down_sequence[]=
4454 {
4455     {0x00,0x00}
4456 };
4457 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
4458 {
4459     int ret;
4460     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4461
4462     if (pm_msg.event == PM_EVENT_SUSPEND) {
4463         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
4464         ret = sensor_write_array(client, sensor_power_down_sequence) ;
4465         if (ret != 0) {
4466             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
4467             return ret;
4468         } else {
4469             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
4470             if (ret < 0) {
4471                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
4472                 return -EINVAL;
4473             }
4474         }
4475     } else {
4476         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
4477         return -EINVAL;
4478     }
4479
4480     return 0;
4481 }
4482
4483 static int sensor_resume(struct soc_camera_device *icd)
4484 {
4485         int ret;
4486
4487     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
4488     if (ret < 0) {
4489                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
4490         return -EINVAL;
4491     }
4492
4493         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
4494         return 0;
4495 }
4496
4497 static int sensor_set_bus_param(struct soc_camera_device *icd,
4498                                 unsigned long flags)
4499 {
4500
4501     return 0;
4502 }
4503
4504 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
4505 {
4506     struct soc_camera_link *icl = to_soc_camera_link(icd);
4507     unsigned long flags = SENSOR_BUS_PARAM;
4508
4509     return soc_camera_apply_sensor_flags(icl, flags);
4510 }
4511 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4512 {
4513     struct i2c_client *client = v4l2_get_subdevdata(sd);
4514     struct soc_camera_device *icd = client->dev.platform_data;
4515     struct sensor *sensor = to_sensor(client);
4516
4517     mf->width   = icd->user_width;
4518         mf->height      = icd->user_height;
4519         mf->code        = sensor->info_priv.fmt.code;
4520         mf->colorspace  = sensor->info_priv.fmt.colorspace;
4521         mf->field       = V4L2_FIELD_NONE;
4522
4523     return 0;
4524 }
4525 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4526 {
4527     bool ret = false;
4528
4529         if ((mf->width == 1024) && (mf->height == 768)) {
4530                 ret = true;
4531         } else if ((mf->width == 1280) && (mf->height == 1024)) {
4532                 ret = true;
4533         } else if ((mf->width == 1600) && (mf->height == 1200)) {
4534                 ret = true;
4535         } else if ((mf->width == 2048) && (mf->height == 1536)) {
4536                 ret = true;
4537         } else if ((mf->width == 2592) && (mf->height == 1944)) {
4538                 ret = true;
4539         }
4540
4541         if (ret == true)
4542                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
4543         return ret;
4544 }
4545
4546 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4547 {
4548     bool ret = false;
4549
4550         if ((mf->width == 1280) && (mf->height == 720)) {
4551                 ret = true;
4552         } else if ((mf->width == 1920) && (mf->height == 1080)) {
4553                 ret = true;
4554         }
4555
4556         if (ret == true)
4557                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
4558         return ret;
4559 }
4560 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4561 {
4562     struct i2c_client *client = v4l2_get_subdevdata(sd);
4563     const struct sensor_datafmt *fmt;
4564     struct sensor *sensor = to_sensor(client);
4565         const struct v4l2_queryctrl *qctrl;
4566         struct soc_camera_device *icd = client->dev.platform_data;
4567     struct reginfo *winseqe_set_addr=NULL;
4568     int ret = 0, set_w,set_h;
4569
4570         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4571                                    ARRAY_SIZE(sensor_colour_fmts));
4572         if (!fmt) {
4573         ret = -EINVAL;
4574         goto sensor_s_fmt_end;
4575     }
4576
4577         if (sensor->info_priv.fmt.code != mf->code) {
4578                 switch (mf->code)
4579                 {
4580                         case V4L2_MBUS_FMT_YUYV8_2X8:
4581                         {
4582                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
4583                                 break;
4584                         }
4585                         case V4L2_MBUS_FMT_UYVY8_2X8:
4586                         {
4587                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
4588                                 break;
4589                         }
4590                         default:
4591                                 break;
4592                 }
4593                 if (winseqe_set_addr != NULL) {
4594             sensor_write_array(client, winseqe_set_addr);
4595                         sensor->info_priv.fmt.code = mf->code;
4596             sensor->info_priv.fmt.colorspace= mf->colorspace;            
4597                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
4598                 } else {
4599                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
4600                 }
4601         }
4602
4603     set_w = mf->width;
4604     set_h = mf->height;
4605
4606         if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
4607         {
4608                 winseqe_set_addr = sensor_qcif;
4609         set_w = 176;
4610         set_h = 144;
4611         }
4612         else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
4613     {
4614         winseqe_set_addr = sensor_qvga;
4615         set_w = 320;
4616         set_h = 240;
4617     }
4618     else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
4619     {
4620         winseqe_set_addr = sensor_cif;
4621         set_w = 352;
4622         set_h = 288;
4623     }
4624     else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
4625     {
4626         winseqe_set_addr = sensor_vga;
4627         set_w = 640;
4628         set_h = 480;
4629     }
4630     else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
4631     {
4632         winseqe_set_addr = sensor_svga;
4633         set_w = 800;
4634         set_h = 600;
4635     }
4636         else if (((set_w <= 1024) && (set_h <= 768)) && sensor_xga[0].reg)
4637     {
4638         winseqe_set_addr = sensor_xga;
4639         set_w = 1024;
4640         set_h = 768;
4641     }
4642         else if (((set_w <= 1280) && (set_h <= 720)) && sensor_720p[0].reg)
4643     {
4644         winseqe_set_addr = sensor_720p;
4645         set_w = 1280;
4646         set_h = 720;
4647     }
4648     else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
4649     {
4650         winseqe_set_addr = sensor_sxga;
4651         set_w = 1280;
4652         set_h = 1024;
4653     }
4654     else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
4655     {
4656         winseqe_set_addr = sensor_uxga;
4657         set_w = 1600;
4658         set_h = 1200;
4659     }
4660     else if (((set_w <= 1920) && (set_h <= 1080)) && sensor_1080p[0].reg)
4661     {
4662         winseqe_set_addr = sensor_1080p;
4663         set_w = 1920;
4664         set_h = 1080;
4665     }
4666         else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
4667     {
4668         winseqe_set_addr = sensor_qxga;
4669         set_w = 2048;
4670         set_h = 1536;
4671     }
4672         else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
4673     {
4674         winseqe_set_addr = sensor_qsxga;
4675         set_w = 2592;
4676         set_h = 1944;
4677     }
4678     else
4679     {
4680         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */
4681         set_w = SENSOR_INIT_WIDTH;
4682         set_h = SENSOR_INIT_HEIGHT;
4683                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
4684     }
4685
4686     if (winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr)
4687     {
4688                 if (sensor_fmt_capturechk(sd,mf) == true) {                                     /* ddl@rock-chips.com : Capture */
4689                         sensor_parameter_record(client);
4690         #if CONFIG_SENSOR_Flash
4691             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4692                 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
4693                 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
4694             }
4695         #endif
4696                 }else {                                        /* ddl@rock-chips.com : Video */
4697                 #if CONFIG_SENSOR_Flash
4698             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4699                 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4700                 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
4701             }
4702         #endif
4703         }
4704
4705                 if ((sensor->info_priv.winseqe_cur_addr->reg == SEQUENCE_PROPERTY) && (sensor->info_priv.winseqe_cur_addr->val == SEQUENCE_INIT)) {
4706                         if (((winseqe_set_addr->reg == SEQUENCE_PROPERTY) && (winseqe_set_addr->val == SEQUENCE_NORMAL))
4707                                 || (winseqe_set_addr->reg != SEQUENCE_PROPERTY)) {
4708                                 ret |= sensor_write_array(client,sensor_init_data);
4709                                 SENSOR_DG("\n%s reinit ret:0x%x \n",SENSOR_NAME_STRING(), ret);
4710                         }
4711                 }
4712
4713         ret |= sensor_write_array(client, winseqe_set_addr);
4714         if (ret != 0) {
4715             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
4716             #if CONFIG_SENSOR_Flash
4717             if (sensor_fmt_capturechk(sd,mf) == true) {
4718                 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4719                     sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4720                     SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
4721                 }
4722             }
4723             #endif
4724             goto sensor_s_fmt_end;
4725         }
4726
4727         sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
4728
4729                 if (sensor_fmt_capturechk(sd,mf) == true) {                                 /* ddl@rock-chips.com : Capture */
4730                         sensor_ae_transfer(client);
4731                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4732                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4733                         if (sensor->info_priv.whiteBalance != 0) {
4734                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4735                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4736                         }
4737                         #if CONFIG_SENSOR_Focus
4738             if (sensor->info_priv.auto_focus != SENSOR_AF_MODE_INFINITY) {                      
4739                 if (sensor_af_workqueue_set(icd, WqCmd_af_update_zone,0,true) == 0) {
4740                     if ((sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) || 
4741                             (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS)) {
4742                             msleep(80);
4743                         sensor_af_workqueue_set(icd, WqCmd_af_single,0,false);
4744                         }
4745                         }
4746             }
4747             #endif
4748                         sensor->info_priv.snap2preview = true;
4749                 } else if (sensor_fmt_videochk(sd,mf) == true) {                        /* ddl@rock-chips.com : Video */
4750                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4751                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4752             #if CONFIG_SENSOR_Focus
4753             sensor->info_priv.affm_reinit = 1;
4754             #endif
4755                         sensor->info_priv.video2preview = true;
4756                 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
4757                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4758                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4759                         if (sensor->info_priv.snap2preview == true) {
4760                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4761                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4762                         }
4763             #if CONFIG_SENSOR_Focus   
4764             if (sensor->info_priv.auto_focus != SENSOR_AF_MODE_INFINITY) { 
4765                 /* ddl@rock-chips.com: The af operation is not necessary, if user don't care whether in focus after preview*/
4766                 if (sensor_af_workqueue_set(icd, WqCmd_af_update_zone,0,true) == 0) {
4767                     if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS) {
4768                         sensor_af_workqueue_set(icd, WqCmd_af_continues,0,false);
4769                         } else if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) {
4770                             msleep(100);
4771                         sensor_af_workqueue_set(icd, WqCmd_af_single,0,false);
4772                         }
4773                 }
4774                 
4775             } else {
4776                 msleep(600);    /* ddl@rock-chips.com : whitebalance auto must delay */
4777             }
4778             #endif
4779                         sensor->info_priv.video2preview = false;
4780                         sensor->info_priv.snap2preview = false;
4781                 }
4782
4783         
4784                 
4785         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
4786     }
4787     else
4788     {
4789         SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
4790     }
4791
4792         mf->width = set_w;
4793         mf->height = set_h;
4794 sensor_s_fmt_end:
4795     return ret;
4796 }
4797
4798 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4799 {
4800     struct i2c_client *client = v4l2_get_subdevdata(sd);
4801     struct sensor *sensor = to_sensor(client);
4802     const struct sensor_datafmt *fmt;
4803     int ret = 0;
4804    
4805         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4806                                    ARRAY_SIZE(sensor_colour_fmts));
4807         if (fmt == NULL) {
4808                 fmt = &sensor->info_priv.fmt;
4809         mf->code = fmt->code;
4810         } 
4811
4812     if (mf->height > SENSOR_MAX_HEIGHT)
4813         mf->height = SENSOR_MAX_HEIGHT;
4814     else if (mf->height < SENSOR_MIN_HEIGHT)
4815         mf->height = SENSOR_MIN_HEIGHT;
4816
4817     if (mf->width > SENSOR_MAX_WIDTH)
4818         mf->width = SENSOR_MAX_WIDTH;
4819     else if (mf->width < SENSOR_MIN_WIDTH)
4820         mf->width = SENSOR_MIN_WIDTH;
4821
4822     mf->colorspace = fmt->colorspace;
4823     
4824     return ret;
4825 }
4826
4827  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
4828 {
4829     struct i2c_client *client = v4l2_get_subdevdata(sd);
4830
4831     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
4832         return -EINVAL;
4833
4834     if (id->match.addr != client->addr)
4835         return -ENODEV;
4836
4837     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
4838     id->revision = 0;
4839
4840     return 0;
4841 }
4842 #if CONFIG_SENSOR_Brightness
4843 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4844 {
4845     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4846
4847     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4848     {
4849         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
4850         {
4851             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
4852             {
4853                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4854                 return -EINVAL;
4855             }
4856             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4857             return 0;
4858         }
4859     }
4860         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4861     return -EINVAL;
4862 }
4863 #endif
4864 #if CONFIG_SENSOR_Effect
4865 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4866 {
4867     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4868
4869     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4870     {
4871         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
4872         {
4873             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
4874             {
4875                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4876                 return -EINVAL;
4877             }
4878             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4879             return 0;
4880         }
4881     }
4882         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4883     return -EINVAL;
4884 }
4885 #endif
4886 #if CONFIG_SENSOR_Exposure
4887 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4888 {
4889     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4890
4891     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4892     {
4893         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
4894         {
4895             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
4896             {
4897                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4898                 return -EINVAL;
4899             }
4900             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4901             return 0;
4902         }
4903     }
4904         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4905     return -EINVAL;
4906 }
4907 #endif
4908 #if CONFIG_SENSOR_Saturation
4909 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4910 {
4911     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4912
4913     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4914     {
4915         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
4916         {
4917             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
4918             {
4919                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4920                 return -EINVAL;
4921             }
4922             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4923             return 0;
4924         }
4925     }
4926     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4927     return -EINVAL;
4928 }
4929 #endif
4930 #if CONFIG_SENSOR_Contrast
4931 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4932 {
4933     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4934
4935     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4936     {
4937         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
4938         {
4939             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
4940             {
4941                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4942                 return -EINVAL;
4943             }
4944             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4945             return 0;
4946         }
4947     }
4948     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4949     return -EINVAL;
4950 }
4951 #endif
4952 #if CONFIG_SENSOR_Mirror
4953 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4954 {
4955     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4956
4957     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4958     {
4959         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
4960         {
4961             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
4962             {
4963                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4964                 return -EINVAL;
4965             }
4966             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4967             return 0;
4968         }
4969     }
4970     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4971     return -EINVAL;
4972 }
4973 #endif
4974 #if CONFIG_SENSOR_Flip
4975 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4976 {
4977     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4978
4979     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4980     {
4981         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
4982         {
4983             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
4984             {
4985                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4986                 return -EINVAL;
4987             }
4988             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4989             return 0;
4990         }
4991     }
4992     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4993     return -EINVAL;
4994 }
4995 #endif
4996 #if CONFIG_SENSOR_Scene
4997 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4998 {
4999     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5000
5001     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5002     {
5003         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
5004         {
5005             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
5006             {
5007                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5008                 return -EINVAL;
5009             }
5010             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5011             return 0;
5012         }
5013     }
5014     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5015     return -EINVAL;
5016 }
5017 #endif
5018 #if CONFIG_SENSOR_WhiteBalance
5019 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5020 {
5021     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5022
5023     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
5024     {
5025         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
5026         {
5027             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
5028             {
5029                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5030                 return -EINVAL;
5031             }
5032             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5033             return 0;
5034         }
5035     }
5036         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5037     return -EINVAL;
5038 }
5039 #endif
5040 #if CONFIG_SENSOR_DigitalZoom
5041 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
5042 {
5043     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5044     struct sensor *sensor = to_sensor(client);
5045         const struct v4l2_queryctrl *qctrl_info;
5046     int digitalzoom_cur, digitalzoom_total;
5047
5048         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
5049         if (qctrl_info)
5050                 return -EINVAL;
5051
5052     digitalzoom_cur = sensor->info_priv.digitalzoom;
5053     digitalzoom_total = qctrl_info->maximum;
5054
5055     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
5056     {
5057         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
5058         return -EINVAL;
5059     }
5060
5061     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
5062     {
5063         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
5064         return -EINVAL;
5065     }
5066
5067     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
5068     {
5069         *value = digitalzoom_total - digitalzoom_cur;
5070     }
5071
5072     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
5073     {
5074         *value = 0 - digitalzoom_cur;
5075     }
5076
5077     digitalzoom_cur += *value;
5078
5079     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
5080     {
5081         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
5082         {
5083             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
5084             return -EINVAL;
5085         }
5086         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
5087         return 0;
5088     }
5089
5090     return -EINVAL;
5091 }
5092 #endif
5093 #if CONFIG_SENSOR_Focus
5094 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5095 {
5096         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5097     struct sensor *sensor = to_sensor(client);
5098         const struct v4l2_queryctrl *qctrl_info;
5099         int ret = 0;
5100
5101         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
5102         if (!qctrl_info)
5103                 return -EINVAL;
5104     
5105         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5106                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
5107             ret = sensor_af_workqueue_set(icd, WqCmd_af_special_pos, value, true);
5108                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5109                 } else {
5110                         ret = -EINVAL;
5111                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5112                 }
5113         } else {
5114                 ret = -EACCES;
5115                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5116                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5117         }
5118
5119         return ret;
5120 }
5121 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5122 {
5123         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5124         struct sensor *sensor = to_sensor(client);
5125         const struct v4l2_queryctrl *qctrl_info;
5126         int ret = 0;
5127
5128         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
5129         if (!qctrl_info)
5130                 return -EINVAL;    
5131
5132         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5133                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {            
5134             if (value > 0) {
5135                 ret = sensor_af_workqueue_set(icd, WqCmd_af_near_pos, 0, true);
5136             } else {
5137                 ret = sensor_af_workqueue_set(icd, WqCmd_af_far_pos, 0, true);
5138             }
5139                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5140                 } else {
5141                         ret = -EINVAL;
5142                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5143                 }
5144         } else {
5145                 ret = -EACCES;
5146                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5147                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5148         }
5149         return ret;
5150 }
5151
5152 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5153 {
5154         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5155         struct sensor *sensor = to_sensor(client); 
5156         int ret = 0;
5157
5158         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)  && (sensor->info_priv.affm_reinit == 0)) {
5159                 switch (value)
5160                 {
5161                         case SENSOR_AF_MODE_AUTO:
5162                         {
5163                                 ret = sensor_af_workqueue_set(icd, WqCmd_af_single, 0, true);
5164                                 break;
5165                         }
5166
5167                         case SENSOR_AF_MODE_MACRO:
5168                         {
5169                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
5170                                 break;
5171                         }
5172
5173                         case SENSOR_AF_MODE_INFINITY:
5174                         {
5175                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
5176                                 break;
5177                         }
5178
5179                         case SENSOR_AF_MODE_CONTINUOUS:
5180                         {
5181                                 ret = sensor_af_workqueue_set(icd, WqCmd_af_continues, 0, true);
5182                                 break;
5183                         }
5184                         default:
5185                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5186                                 break;
5187
5188                 }
5189
5190                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5191         } else {
5192                 ret = -EACCES;
5193                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5194                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5195         }
5196
5197         return ret;
5198 }
5199 #endif
5200
5201 #if CONFIG_SENSOR_Flash
5202 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5203 {    
5204     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
5205         if (value == 3) {       /* ddl@rock-chips.com: torch */
5206             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
5207         } else {
5208             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
5209         }
5210         SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5211         return 0;
5212     }
5213     
5214         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5215     return -EINVAL;
5216 }
5217 #endif
5218
5219 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5220 {
5221     struct i2c_client *client = v4l2_get_subdevdata(sd);
5222     struct sensor *sensor = to_sensor(client);
5223     const struct v4l2_queryctrl *qctrl;
5224
5225     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5226
5227     if (!qctrl)
5228     {
5229         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5230         return -EINVAL;
5231     }
5232
5233     switch (ctrl->id)
5234     {
5235         case V4L2_CID_BRIGHTNESS:
5236             {
5237                 ctrl->value = sensor->info_priv.brightness;
5238                 break;
5239             }
5240         case V4L2_CID_SATURATION:
5241             {
5242                 ctrl->value = sensor->info_priv.saturation;
5243                 break;
5244             }
5245         case V4L2_CID_CONTRAST:
5246             {
5247                 ctrl->value = sensor->info_priv.contrast;
5248                 break;
5249             }
5250         case V4L2_CID_DO_WHITE_BALANCE:
5251             {
5252                 ctrl->value = sensor->info_priv.whiteBalance;
5253                 break;
5254             }
5255         case V4L2_CID_EXPOSURE:
5256             {
5257                 ctrl->value = sensor->info_priv.exposure;
5258                 break;
5259             }
5260         case V4L2_CID_HFLIP:
5261             {
5262                 ctrl->value = sensor->info_priv.mirror;
5263                 break;
5264             }
5265         case V4L2_CID_VFLIP:
5266             {
5267                 ctrl->value = sensor->info_priv.flip;
5268                 break;
5269             }
5270         default :
5271                 break;
5272     }
5273     return 0;
5274 }
5275
5276
5277
5278 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5279 {
5280     struct i2c_client *client = v4l2_get_subdevdata(sd);
5281     struct sensor *sensor = to_sensor(client);
5282     struct soc_camera_device *icd = client->dev.platform_data;
5283     const struct v4l2_queryctrl *qctrl;
5284
5285
5286     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5287
5288     if (!qctrl)
5289     {
5290         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5291         return -EINVAL;
5292     }
5293
5294     switch (ctrl->id)
5295     {
5296 #if CONFIG_SENSOR_Brightness
5297         case V4L2_CID_BRIGHTNESS:
5298             {
5299                 if (ctrl->value != sensor->info_priv.brightness)
5300                 {
5301                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
5302                     {
5303                         return -EINVAL;
5304                     }
5305                     sensor->info_priv.brightness = ctrl->value;
5306                 }
5307                 break;
5308             }
5309 #endif
5310 #if CONFIG_SENSOR_Exposure
5311         case V4L2_CID_EXPOSURE:
5312             {
5313                 if (ctrl->value != sensor->info_priv.exposure)
5314                 {
5315                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
5316                     {
5317                         return -EINVAL;
5318                     }
5319                     sensor->info_priv.exposure = ctrl->value;
5320                 }
5321                 break;
5322             }
5323 #endif
5324 #if CONFIG_SENSOR_Saturation
5325         case V4L2_CID_SATURATION:
5326             {
5327                 if (ctrl->value != sensor->info_priv.saturation)
5328                 {
5329                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
5330                     {
5331                         return -EINVAL;
5332                     }
5333                     sensor->info_priv.saturation = ctrl->value;
5334                 }
5335                 break;
5336             }
5337 #endif
5338 #if CONFIG_SENSOR_Contrast
5339         case V4L2_CID_CONTRAST:
5340             {
5341                 if (ctrl->value != sensor->info_priv.contrast)
5342                 {
5343                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
5344                     {
5345                         return -EINVAL;
5346                     }
5347                     sensor->info_priv.contrast = ctrl->value;
5348                 }
5349                 break;
5350             }
5351 #endif
5352 #if CONFIG_SENSOR_WhiteBalance
5353         case V4L2_CID_DO_WHITE_BALANCE:
5354             {
5355                 if (ctrl->value != sensor->info_priv.whiteBalance)
5356                 {
5357                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
5358                     {
5359                         return -EINVAL;
5360                     }
5361                     sensor->info_priv.whiteBalance = ctrl->value;
5362                 }
5363                 break;
5364             }
5365 #endif
5366 #if CONFIG_SENSOR_Mirror
5367         case V4L2_CID_HFLIP:
5368             {
5369                 if (ctrl->value != sensor->info_priv.mirror)
5370                 {
5371                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
5372                         return -EINVAL;
5373                     sensor->info_priv.mirror = ctrl->value;
5374                 }
5375                 break;
5376             }
5377 #endif
5378 #if CONFIG_SENSOR_Flip
5379         case V4L2_CID_VFLIP:
5380             {
5381                 if (ctrl->value != sensor->info_priv.flip)
5382                 {
5383                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
5384                         return -EINVAL;
5385                     sensor->info_priv.flip = ctrl->value;
5386                 }
5387                 break;
5388             }
5389 #endif
5390         default:
5391             break;
5392     }
5393
5394     return 0;
5395 }
5396 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
5397 {
5398     const struct v4l2_queryctrl *qctrl;
5399     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5400     struct sensor *sensor = to_sensor(client);
5401
5402     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5403
5404     if (!qctrl)
5405     {
5406         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5407         return -EINVAL;
5408     }
5409
5410     switch (ext_ctrl->id)
5411     {
5412         case V4L2_CID_SCENE:
5413             {
5414                 ext_ctrl->value = sensor->info_priv.scene;
5415                 break;
5416             }
5417         case V4L2_CID_EFFECT:
5418             {
5419                 ext_ctrl->value = sensor->info_priv.effect;
5420                 break;
5421             }
5422         case V4L2_CID_ZOOM_ABSOLUTE:
5423             {
5424                 ext_ctrl->value = sensor->info_priv.digitalzoom;
5425                 break;
5426             }
5427         case V4L2_CID_ZOOM_RELATIVE:
5428             {
5429                 return -EINVAL;
5430             }
5431         case V4L2_CID_FOCUS_ABSOLUTE:
5432             {
5433                 return -EINVAL;
5434             }
5435         case V4L2_CID_FOCUS_RELATIVE:
5436             {
5437                 return -EINVAL;
5438             }
5439         case V4L2_CID_FLASH:
5440             {
5441                 ext_ctrl->value = sensor->info_priv.flash;
5442                 break;
5443             }
5444         default :
5445             break;
5446     }
5447     return 0;
5448 }
5449 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
5450 {
5451     const struct v4l2_queryctrl *qctrl;
5452     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5453     struct sensor *sensor = to_sensor(client);
5454     int val_offset,ret;
5455
5456     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5457
5458     if (!qctrl)
5459     {
5460         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5461         return -EINVAL;
5462     }
5463
5464         val_offset = 0;
5465     switch (ext_ctrl->id)
5466     {
5467 #if CONFIG_SENSOR_Scene
5468         case V4L2_CID_SCENE:
5469             {
5470                 if (ext_ctrl->value != sensor->info_priv.scene)
5471                 {
5472                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
5473                         return -EINVAL;
5474                     sensor->info_priv.scene = ext_ctrl->value;
5475                 }
5476                 break;
5477             }
5478 #endif
5479 #if CONFIG_SENSOR_Effect
5480         case V4L2_CID_EFFECT:
5481             {
5482                 if (ext_ctrl->value != sensor->info_priv.effect)
5483                 {
5484                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
5485                         return -EINVAL;
5486                     sensor->info_priv.effect= ext_ctrl->value;
5487                 }
5488                 break;
5489             }
5490 #endif
5491 #if CONFIG_SENSOR_DigitalZoom
5492         case V4L2_CID_ZOOM_ABSOLUTE:
5493             {
5494                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5495                     return -EINVAL;
5496
5497                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
5498                 {
5499                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
5500
5501                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
5502                         return -EINVAL;
5503                     sensor->info_priv.digitalzoom += val_offset;
5504
5505                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
5506                 }
5507
5508                 break;
5509             }
5510         case V4L2_CID_ZOOM_RELATIVE:
5511             {
5512                 if (ext_ctrl->value)
5513                 {
5514                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
5515                         return -EINVAL;
5516                     sensor->info_priv.digitalzoom += ext_ctrl->value;
5517
5518                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
5519                 }
5520                 break;
5521             }
5522 #endif
5523 #if CONFIG_SENSOR_Focus
5524         case V4L2_CID_FOCUS_ABSOLUTE:
5525             {
5526                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5527                     return -EINVAL;
5528
5529                 ret = sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value);
5530                                 if ((ret == 0) || (0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK))) {
5531                                         if (ext_ctrl->value == qctrl->minimum) {
5532                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
5533                                         } else if (ext_ctrl->value == qctrl->maximum) {
5534                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
5535                                         } else {
5536                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
5537                                         }
5538                                 }
5539
5540                 break;
5541             }
5542         case V4L2_CID_FOCUS_RELATIVE:
5543             {
5544                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5545                     return -EINVAL;
5546
5547                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
5548                 break;
5549             }
5550                 case V4L2_CID_FOCUS_AUTO:
5551                         {
5552                                 if (ext_ctrl->value == 1) {
5553                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0) {
5554                                                 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5555                                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5556                                                 }
5557                                                 return -EINVAL;
5558                                         }
5559                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5560                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
5561                                         if (ext_ctrl->value == 0)
5562                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5563                                 }
5564                                 break;
5565                         }
5566                 case V4L2_CID_FOCUS_CONTINUOUS:
5567                         {
5568                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
5569                                         if (ext_ctrl->value == 1) {
5570                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0) {
5571                                                         if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5572                                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5573                                                         }
5574                                                         return -EINVAL;
5575                                                 }
5576                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5577                                         }
5578                                 } else {
5579                                         if (ext_ctrl->value == 0)
5580                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5581                                 }
5582                                 break;
5583                         }
5584 #endif
5585 #if CONFIG_SENSOR_Flash
5586         case V4L2_CID_FLASH:
5587             {
5588                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
5589                     return -EINVAL;
5590                 sensor->info_priv.flash = ext_ctrl->value;
5591
5592                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
5593                 break;
5594             }
5595 #endif
5596         default:
5597             break;
5598     }
5599
5600     return 0;
5601 }
5602
5603 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5604 {
5605     struct i2c_client *client = v4l2_get_subdevdata(sd);
5606     struct soc_camera_device *icd = client->dev.platform_data;
5607     int i, error_cnt=0, error_idx=-1;
5608
5609
5610     for (i=0; i<ext_ctrl->count; i++) {
5611         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5612             error_cnt++;
5613             error_idx = i;
5614         }
5615     }
5616
5617     if (error_cnt > 1)
5618         error_idx = ext_ctrl->count;
5619
5620     if (error_idx != -1) {
5621         ext_ctrl->error_idx = error_idx;
5622         return -EINVAL;
5623     } else {
5624         return 0;
5625     }
5626 }
5627
5628 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5629 {
5630     struct i2c_client *client = v4l2_get_subdevdata(sd);
5631     struct soc_camera_device *icd = client->dev.platform_data;
5632     int i, error_cnt=0, error_idx=-1;
5633
5634     for (i=0; i<ext_ctrl->count; i++) {
5635         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5636             error_cnt++;
5637             error_idx = i;
5638         }
5639     }
5640
5641     if (error_cnt > 1)
5642         error_idx = ext_ctrl->count;
5643
5644     if (error_idx != -1) {
5645         ext_ctrl->error_idx = error_idx;
5646         return -EINVAL;
5647     } else {
5648         return 0;
5649     }
5650 }
5651
5652 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
5653 {
5654         struct i2c_client *client = v4l2_get_subdevdata(sd);
5655     struct sensor *sensor = to_sensor(client);
5656     #if CONFIG_SENSOR_Focus
5657         struct soc_camera_device *icd = client->dev.platform_data;
5658         struct v4l2_mbus_framefmt mf;
5659     #endif
5660
5661         if (enable == 1) {
5662                 sensor->info_priv.enable = 1;
5663                 #if CONFIG_SENSOR_Focus
5664         mf.width        = icd->user_width;
5665         mf.height       = icd->user_height;
5666         mf.code = sensor->info_priv.fmt.code;
5667         mf.colorspace   = sensor->info_priv.fmt.colorspace;
5668         mf.field        = V4L2_FIELD_NONE;
5669                 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
5670                 if (sensor_fmt_capturechk(sd, &mf) == false) {
5671                         if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {                                                  
5672                 sensor_af_workqueue_set(icd, WqCmd_af_init, 0, false);
5673                                 sensor->info_priv.affm_reinit = 0;
5674                         }
5675                 }
5676                 #endif
5677         } else if (enable == 0) {
5678                 sensor->info_priv.enable = 0;
5679                 #if CONFIG_SENSOR_Focus 
5680         flush_workqueue(sensor->sensor_wq);
5681                 #endif
5682         }
5683         return 0;
5684 }
5685
5686 /* Interface active, can use i2c. If it fails, it can indeed mean, that
5687  * this wasn't our capture interface, so, we wait for the right one */
5688 static int sensor_video_probe(struct soc_camera_device *icd,
5689                                struct i2c_client *client)
5690 {
5691     char value;
5692     int ret,pid = 0;
5693     struct sensor *sensor = to_sensor(client);
5694
5695     /* We must have a parent by now. And it cannot be a wrong one.
5696      * So this entire test is completely redundant. */
5697     if (!icd->dev.parent ||
5698             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
5699                 return -ENODEV;
5700
5701         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
5702                 ret = -ENODEV;
5703                 goto sensor_video_probe_err;
5704         }
5705     /* soft reset */
5706     ret = sensor_write(client, 0x3012, 0x80);
5707     if (ret != 0) {
5708         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
5709         ret = -ENODEV;
5710                 goto sensor_video_probe_err;
5711     }
5712     mdelay(5);          //delay 5 microseconds
5713
5714     /* check if it is an sensor sensor */
5715     ret = sensor_read(client, 0x300a, &value);
5716     if (ret != 0) {
5717         SENSOR_TR("read chip id high byte failed\n");
5718         ret = -ENODEV;
5719         goto sensor_video_probe_err;
5720     }
5721
5722     pid |= (value << 8);
5723
5724     ret = sensor_read(client, 0x300b, &value);
5725     if (ret != 0) {
5726         SENSOR_TR("read chip id low byte failed\n");
5727         ret = -ENODEV;
5728         goto sensor_video_probe_err;
5729     }
5730
5731     pid |= (value & 0xff);
5732     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5733     if (pid == SENSOR_ID) {
5734         sensor->model = SENSOR_V4L2_IDENT;
5735     } else {
5736         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5737         ret = -ENODEV;
5738         goto sensor_video_probe_err;
5739     }
5740
5741     return 0;
5742
5743 sensor_video_probe_err:
5744
5745     return ret;
5746 }
5747 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
5748 {
5749         struct i2c_client *client = v4l2_get_subdevdata(sd);
5750     struct soc_camera_device *icd = client->dev.platform_data;    
5751     struct sensor *sensor = to_sensor(client);
5752     int ret = 0,i;
5753     
5754         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5755         switch (cmd)
5756         {
5757                 case RK_CAM_SUBDEV_DEACTIVATE:
5758                 {
5759                         sensor_deactivate(client);
5760                         break;
5761                 }
5762                 case RK_CAM_SUBDEV_IOREQUEST:
5763                 {
5764                         sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;    
5765             
5766             if (sensor->sensor_io_request != NULL) { 
5767                 if (sensor->sensor_io_request->gpio_res[0].dev_name && 
5768                     (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
5769                     sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
5770                 } else if (sensor->sensor_io_request->gpio_res[1].dev_name && 
5771                     (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
5772                     sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];          
5773                 }
5774             } else {
5775                 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
5776                 ret = -EINVAL;
5777                 goto sensor_ioctl_end;
5778             }
5779             
5780             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
5781                for this project */
5782             #if CONFIG_SENSOR_Flash     
5783                 if (sensor->sensor_gpio_res) {
5784                 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
5785                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
5786                     for (i = 0; i < icd->ops->num_controls; i++) {
5787                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
5788                                         memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                       
5789                                 }
5790                     }
5791                     sensor->info_priv.flash = 0xff;
5792                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
5793                 }
5794                 }
5795             #endif
5796                         break;
5797                 }
5798                 default:
5799                 {
5800                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5801                         break;
5802                 }
5803         }
5804
5805 sensor_ioctl_end:
5806         return ret;
5807
5808 }
5809 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
5810                             enum v4l2_mbus_pixelcode *code)
5811 {
5812         if (index >= ARRAY_SIZE(sensor_colour_fmts))
5813                 return -EINVAL;
5814
5815         *code = sensor_colour_fmts[index].code;
5816         return 0;
5817 }
5818 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
5819         .init           = sensor_init,
5820         .g_ctrl         = sensor_g_control,
5821         .s_ctrl         = sensor_s_control,
5822         .g_ext_ctrls          = sensor_g_ext_controls,
5823         .s_ext_ctrls          = sensor_s_ext_controls,
5824         .g_chip_ident   = sensor_g_chip_ident,
5825         .ioctl = sensor_ioctl,
5826 };
5827
5828 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
5829         .s_mbus_fmt     = sensor_s_fmt,
5830         .g_mbus_fmt     = sensor_g_fmt,
5831         .try_mbus_fmt   = sensor_try_fmt,
5832         .enum_mbus_fmt  = sensor_enum_fmt,
5833         .s_stream   = sensor_s_stream,
5834 };
5835 static struct v4l2_subdev_ops sensor_subdev_ops = {
5836         .core   = &sensor_subdev_core_ops,
5837         .video = &sensor_subdev_video_ops,
5838 };
5839
5840 static int sensor_probe(struct i2c_client *client,
5841                          const struct i2c_device_id *did)
5842 {
5843     struct sensor *sensor;
5844     struct soc_camera_device *icd = client->dev.platform_data;
5845     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
5846     struct soc_camera_link *icl;
5847     int ret;
5848
5849     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
5850     if (!icd) {
5851         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
5852         return -EINVAL;
5853     }
5854
5855     icl = to_soc_camera_link(icd);
5856     if (!icl) {
5857         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
5858         return -EINVAL;
5859     }
5860
5861     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
5862         dev_warn(&adapter->dev,
5863                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
5864         return -EIO;
5865     }
5866
5867     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
5868     if (!sensor)
5869         return -ENOMEM;
5870
5871     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
5872
5873     /* Second stage probe - when a capture adapter is there */
5874     icd->ops            = &sensor_ops;
5875     sensor->info_priv.fmt = sensor_colour_fmts[0];
5876         #if CONFIG_SENSOR_I2C_NOSCHED
5877         atomic_set(&sensor->tasklock_cnt,0);
5878         #endif
5879
5880     ret = sensor_video_probe(icd, client);
5881     if (ret < 0) {
5882         icd->ops = NULL;
5883         i2c_set_clientdata(client, NULL);
5884         kfree(sensor);
5885                 sensor = NULL;
5886     } else {
5887                 #if CONFIG_SENSOR_Focus
5888                 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING(_af_workqueue));
5889                 if (sensor->sensor_wq == NULL)
5890                         SENSOR_TR("%s create fail!", SENSOR_NAME_STRING(_af_workqueue));
5891                 mutex_init(&sensor->wq_lock);
5892                 #endif
5893     }
5894
5895     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
5896     return ret;
5897 }
5898
5899 static int sensor_remove(struct i2c_client *client)
5900 {
5901     struct sensor *sensor = to_sensor(client);
5902     struct soc_camera_device *icd = client->dev.platform_data;
5903
5904         #if CONFIG_SENSOR_Focus
5905         if (sensor->sensor_wq) {
5906                 destroy_workqueue(sensor->sensor_wq);
5907                 sensor->sensor_wq = NULL;
5908         }
5909         #endif
5910
5911     icd->ops = NULL;
5912     i2c_set_clientdata(client, NULL);
5913     client->driver = NULL;
5914     kfree(sensor);
5915         sensor = NULL;
5916     return 0;
5917 }
5918
5919 static const struct i2c_device_id sensor_id[] = {
5920         {SENSOR_NAME_STRING(), 0 },
5921         { }
5922 };
5923 MODULE_DEVICE_TABLE(i2c, sensor_id);
5924
5925 static struct i2c_driver sensor_i2c_driver = {
5926         .driver = {
5927                 .name = SENSOR_NAME_STRING(),
5928         },
5929         .probe          = sensor_probe,
5930         .remove         = sensor_remove,
5931         .id_table       = sensor_id,
5932 };
5933
5934 static int __init sensor_mod_init(void)
5935 {
5936     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
5937     return i2c_add_driver(&sensor_i2c_driver);
5938 }
5939
5940 static void __exit sensor_mod_exit(void)
5941 {
5942     i2c_del_driver(&sensor_i2c_driver);
5943 }
5944
5945 device_initcall_sync(sensor_mod_init);
5946 module_exit(sensor_mod_exit);
5947
5948 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
5949 MODULE_AUTHOR("ddl <kernel@rock-chips>");
5950 MODULE_LICENSE("GPL");
5951