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