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