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