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