camera:add ov7675 driver, add ov5642 A3907 AF firmware, fix ov5642 AF may be fail
[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 #define _CONS(a,b) a##b
26 #define CONS(a,b) _CONS(a,b)
27
28 #define __STR(x) #x
29 #define _STR(x) __STR(x)
30 #define STR(x) _STR(x)
31
32 /* Sensor Driver Configuration */
33 #define SENSOR_NAME ov5642
34 #define SENSOR_V4L2_IDENT V4L2_IDENT_OV5642
35 #define SENSOR_ID 0x5642
36 #define SENSOR_MIN_WIDTH    176
37 #define SENSOR_MIN_HEIGHT   144
38 #define SENSOR_MAX_WIDTH    2592
39 #define SENSOR_MAX_HEIGHT   1944
40 #define SENSOR_INIT_WIDTH       640                     /* Sensor pixel size for sensor_init_data array */
41 #define SENSOR_INIT_HEIGHT  480
42 #define SENSOR_INIT_WINSEQADR sensor_vga
43 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_UYVY
44
45 #define CONFIG_SENSOR_WhiteBalance      1
46 #define CONFIG_SENSOR_Brightness        0
47 #define CONFIG_SENSOR_Contrast      0
48 #define CONFIG_SENSOR_Saturation    0
49 #define CONFIG_SENSOR_Effect        1
50 #define CONFIG_SENSOR_Scene         1
51 #define CONFIG_SENSOR_DigitalZoom   0
52 #define CONFIG_SENSOR_Exposure      0
53 #define CONFIG_SENSOR_Flash         0
54 #define CONFIG_SENSOR_Mirror        0
55 #define CONFIG_SENSOR_Flip          0
56 #ifdef CONFIG_OV5642_AUTOFOCUS
57 #define CONFIG_SENSOR_Focus         1
58 #include "ov5642_af_firmware.c"
59 #else
60 #define CONFIG_SENSOR_Focus         0
61 #endif
62
63 #define CONFIG_SENSOR_I2C_SPEED     300000       /* Hz */
64
65 #define CONFIG_SENSOR_TR      1
66 #define CONFIG_SENSOR_DEBUG       1
67
68 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
69 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
70
71 #define MIN(x,y)   ((x<y) ? x: y)
72 #define MAX(x,y)    ((x>y) ? x: y)
73
74 #if (CONFIG_SENSOR_TR)
75         #define SENSOR_TR(format, ...)      printk(format, ## __VA_ARGS__)
76         #if (CONFIG_SENSOR_DEBUG)
77         #define SENSOR_DG(format, ...)      printk(format, ## __VA_ARGS__)
78         #else
79         #define SENSOR_DG(format, ...)
80         #endif
81 #else
82         #define SENSOR_TR(format, ...)
83 #endif
84
85 #define SENSOR_BUS_PARAM  (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
86                           SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |\
87                           SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ)
88
89 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
90 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
91 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
92 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
93 #define COLOR_TEMPERATURE_OFFICE_DN     3500
94 #define COLOR_TEMPERATURE_OFFICE_UP     5000
95 #define COLOR_TEMPERATURE_HOME_DN       2500
96 #define COLOR_TEMPERATURE_HOME_UP       3500
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 640X480 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,0x30},
793         {0x3a10,0x28},
794         {0x3a1b,0x30},
795         {0x3a1e,0x28},
796         {0x3a11,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     {0x0000,0x00}
807
808 };
809 /* 2592X1944 QSXGA */
810 static struct reginfo sensor_qsxga[] =
811 {
812     {0x0000 ,0x00}
813 };
814 /* 2048*1536 QXGA */
815 static struct reginfo sensor_qxga[] =
816 {
817     {0x0000 ,0x00}
818 };
819
820 /* 1600X1200 UXGA */
821 static struct reginfo sensor_uxga[] =
822 {
823     {0x0000 ,0x00}
824 };
825
826 /* 1280X1024 SXGA */
827 static struct reginfo sensor_sxga[] =
828 {
829         {0x0000,0x00}
830 };
831
832 /* 800X600 SVGA*/
833 static struct reginfo sensor_svga[] =
834 {
835         {0x3800 ,0x1 },
836         {0x3801 ,0x50},
837         {0x3802 ,0x0 },
838         {0x3803 ,0x8 },
839         {0x3804 ,0x5 },
840         {0x3805 ,0x0 },
841         {0x3806 ,0x3 },
842         {0x3807 ,0xc0},
843         {0x3808 ,0x3 },
844         {0x3809 ,0x20},
845         {0x380a ,0x2 },
846         {0x380b ,0x58},
847         {0x380c ,0xc },
848         {0x380d ,0x80},
849         {0x380e ,0x3 },
850         {0x380f ,0xe8},
851         {0x5001 ,0x7f},
852         {0x5680 ,0x0 },
853         {0x5681 ,0x0 },
854         {0x5682 ,0x5 },
855         {0x5683 ,0x0 },
856         {0x5684 ,0x0 },
857         {0x5685 ,0x0 },
858         {0x5686 ,0x3 },
859         {0x5687 ,0xc0},
860         {0x5687 ,0xc0},
861         {0x3815 ,0x02},
862         {0x0000,0x00}
863 };
864
865 /* 640X480 VGA */
866 static struct reginfo sensor_vga[] =
867 {
868     {0x0000,0x00}
869 };
870
871 /* 352X288 CIF */
872 static struct reginfo sensor_cif[] =
873 {
874         {0x3800 ,0x1 },
875         {0x3801 ,0x50},
876         {0x3802 ,0x0 },
877         {0x3803 ,0x8 },
878         {0x3804 ,0x4 },
879         {0x3805 ,0x96},
880         {0x3806 ,0x3 },
881         {0x3807 ,0xc0},
882         {0x3808 ,0x1 },
883         {0x3809 ,0x60},
884         {0x380a ,0x1 },
885         {0x380b ,0x20},
886         {0x380c ,0xc },
887         {0x380d ,0x80},
888         {0x380e ,0x3 },
889         {0x380f ,0xe8},
890         {0x5001 ,0x7f},
891         {0x5680 ,0x0 },
892         {0x5681 ,0x0 },
893         {0x5682 ,0x4 },
894         {0x5683 ,0x96},
895         {0x5684 ,0x0 },
896         {0x5685 ,0x0 },
897         {0x5686 ,0x3 },
898         {0x5687 ,0xc0},
899     {0x0000,0x00}
900 };
901
902 /* 320*240 QVGA */
903 static  struct reginfo sensor_qvga[] =
904 {
905         {0x0000,0x00}
906 };
907
908 /* 176X144 QCIF*/
909 static struct reginfo sensor_qcif[] =
910 {
911         {0x3800 ,0x1 },
912         {0x3801 ,0x50},
913         {0x3802 ,0x0 },
914         {0x3803 ,0x8 },
915         {0x3804 ,0x4 },
916         {0x3805 ,0x96},
917         {0x3806 ,0x3 },
918         {0x3807 ,0xc0},
919         {0x3808 ,0x0 },
920         {0x3809 ,0xb0},
921         {0x380a ,0x0 },
922         {0x380b ,0x90},
923         {0x380c ,0xc },
924         {0x380d ,0x80},
925         {0x380e ,0x3 },
926         {0x380f ,0xe8},
927         {0x5001 ,0x7f},
928         {0x5680 ,0x0 },
929         {0x5681 ,0x0 },
930         {0x5682 ,0x4 },
931         {0x5683 ,0x96},
932         {0x5684 ,0x0 },
933         {0x5685 ,0x0 },
934         {0x5686 ,0x3 },
935         {0x5687 ,0xc0},
936         {0x0000,0x00}
937 };
938 #if 0
939 /* 160X120 QQVGA*/
940 static struct reginfo ov2655_qqvga[] =
941 {
942
943     {0x300E, 0x34},
944     {0x3011, 0x01},
945     {0x3012, 0x10},
946     {0x302a, 0x02},
947     {0x302b, 0xE6},
948     {0x306f, 0x14},
949     {0x3362, 0x90},
950
951     {0x3070, 0x5d},
952     {0x3072, 0x5d},
953     {0x301c, 0x07},
954     {0x301d, 0x07},
955
956     {0x3020, 0x01},
957     {0x3021, 0x18},
958     {0x3022, 0x00},
959     {0x3023, 0x06},
960     {0x3024, 0x06},
961     {0x3025, 0x58},
962     {0x3026, 0x02},
963     {0x3027, 0x61},
964     {0x3088, 0x00},
965     {0x3089, 0xa0},
966     {0x308a, 0x00},
967     {0x308b, 0x78},
968     {0x3316, 0x64},
969     {0x3317, 0x25},
970     {0x3318, 0x80},
971     {0x3319, 0x08},
972     {0x331a, 0x0a},
973     {0x331b, 0x07},
974     {0x331c, 0x80},
975     {0x331d, 0x38},
976     {0x3100, 0x00},
977     {0x3302, 0x11},
978
979     {0x0, 0x0},
980 };
981
982
983
984 static  struct reginfo ov2655_Sharpness_auto[] =
985 {
986     {0x3306, 0x00},
987 };
988
989 static  struct reginfo ov2655_Sharpness1[] =
990 {
991     {0x3306, 0x08},
992     {0x3371, 0x00},
993 };
994
995 static  struct reginfo ov2655_Sharpness2[][3] =
996 {
997     //Sharpness 2
998     {0x3306, 0x08},
999     {0x3371, 0x01},
1000 };
1001
1002 static  struct reginfo ov2655_Sharpness3[] =
1003 {
1004     //default
1005     {0x3306, 0x08},
1006     {0x332d, 0x02},
1007 };
1008 static  struct reginfo ov2655_Sharpness4[]=
1009 {
1010     //Sharpness 4
1011     {0x3306, 0x08},
1012     {0x332d, 0x03},
1013 };
1014
1015 static  struct reginfo ov2655_Sharpness5[] =
1016 {
1017     //Sharpness 5
1018     {0x3306, 0x08},
1019     {0x332d, 0x04},
1020 };
1021 #endif
1022
1023 static  struct reginfo sensor_ClrFmt_YUYV[]=
1024 {
1025     {0x4300, 0x30},
1026     {0x0000, 0x00}
1027 };
1028
1029 static  struct reginfo sensor_ClrFmt_UYVY[]=
1030 {
1031     {0x4300, 0x32},
1032     {0x0000, 0x00}
1033 };
1034
1035
1036 #if CONFIG_SENSOR_WhiteBalance
1037 static  struct reginfo sensor_WhiteB_Auto[]=
1038 {
1039     {0x3406,0x00},
1040         {0x5183,0x80},
1041         {0x5191,0xff},
1042         {0x5192,0x00},
1043         {0x0000,0x00}
1044 };
1045 /* Cloudy Colour Temperature : 6500K - 8000K  */
1046 static  struct reginfo sensor_WhiteB_Cloudy[]=
1047 {
1048     {0x3406, 0x01},
1049     {0x3400, 0x07},
1050     {0x3401, 0x88},
1051     {0x3402, 0x04},
1052     {0x3403, 0x00},
1053     {0x3404, 0x05},
1054     {0x3405, 0x00},
1055     {0x0000, 0x00}
1056 };
1057 /* ClearDay Colour Temperature : 5000K - 6500K  */
1058 static  struct reginfo sensor_WhiteB_ClearDay[]=
1059 {
1060     //Sunny
1061     {0x3406, 0x01},
1062     {0x3400, 0x07},
1063     {0x3401, 0x32},
1064     {0x3402, 0x04},
1065     {0x3403, 0x00},
1066     {0x3404, 0x05},
1067     {0x3405, 0x36},
1068     {0x0000, 0x00}
1069 };
1070 /* Office Colour Temperature : 3500K - 5000K  */
1071 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
1072 {
1073     //Office
1074     {0x3406, 0x01},
1075     {0x3400, 0x06},
1076     {0x3401, 0x13},
1077     {0x3402, 0x04},
1078     {0x3403, 0x00},
1079     {0x3404, 0x07},
1080     {0x3405, 0xe2},
1081     {0x0000, 0x00}
1082
1083 };
1084 /* Home Colour Temperature : 2500K - 3500K  */
1085 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
1086 {
1087     //Home
1088     {0x3406, 0x01},
1089     {0x3400, 0x04},
1090     {0x3401, 0x88},
1091     {0x3402, 0x04},
1092     {0x3403, 0x00},
1093     {0x3404, 0x08},
1094     {0x3405, 0xb6},
1095     {0x0000, 0x00}
1096 };
1097 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1098     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1099 };
1100 #endif
1101
1102 #if CONFIG_SENSOR_Brightness
1103 static  struct reginfo sensor_Brightness0[]=
1104 {
1105     {0x0000, 0x00}
1106 };
1107
1108 static  struct reginfo sensor_Brightness1[]=
1109 {
1110     {0x0000, 0x00}
1111 };
1112
1113 static  struct reginfo sensor_Brightness2[]=
1114 {
1115     {0x0000, 0x00}
1116 };
1117
1118 static  struct reginfo sensor_Brightness3[]=
1119 {
1120     {0x0000, 0x00}
1121 };
1122
1123 static  struct reginfo sensor_Brightness4[]=
1124 {
1125     {0x0000, 0x00}
1126 };
1127
1128 static  struct reginfo sensor_Brightness5[]=
1129 {
1130     {0x0000, 0x00}
1131 };
1132 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1133     sensor_Brightness4, sensor_Brightness5,NULL,
1134 };
1135
1136 #endif
1137
1138 #if CONFIG_SENSOR_Effect
1139 static  struct reginfo sensor_Effect_Normal[] =
1140 {
1141     {0x5001, 0x7f},
1142         {0x5580, 0x00},
1143     {0x0000, 0x00}
1144 };
1145
1146 static  struct reginfo sensor_Effect_WandB[] =
1147 {
1148     {0x5001, 0xff},
1149         {0x5580, 0x18},
1150         {0x5585, 0x80},
1151         {0x5586, 0x80},
1152     {0x0000, 0x00}
1153 };
1154
1155 static  struct reginfo sensor_Effect_Sepia[] =
1156 {
1157     {0x5001, 0xff},
1158         {0x5580, 0x18},
1159         {0x5585, 0x40},
1160         {0x5586, 0xa0},
1161     {0x0000, 0x00}
1162 };
1163
1164 static  struct reginfo sensor_Effect_Negative[] =
1165 {
1166     //Negative
1167     {0x5001, 0xff},
1168         {0x5580, 0x40},
1169         {0x0000, 0x00}
1170 };
1171 static  struct reginfo sensor_Effect_Bluish[] =
1172 {
1173     // Bluish
1174     {0x5001, 0xff},
1175         {0x5580, 0x18},
1176         {0x5585, 0xa0},
1177         {0x5586, 0x40},
1178     {0x0000, 0x00}
1179 };
1180
1181 static  struct reginfo sensor_Effect_Green[] =
1182 {
1183     //  Greenish
1184     {0x5001, 0xff},
1185         {0x5580, 0x18},
1186         {0x5585, 0x60},
1187         {0x5586, 0x60},
1188     {0x0000, 0x00}
1189 };
1190 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1191     sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1192 };
1193 #endif
1194 #if CONFIG_SENSOR_Exposure
1195 static  struct reginfo sensor_Exposure0[]=
1196 {
1197     {0x0000, 0x00}
1198 };
1199
1200 static  struct reginfo sensor_Exposure1[]=
1201 {
1202     {0x0000, 0x00}
1203 };
1204
1205 static  struct reginfo sensor_Exposure2[]=
1206 {
1207     {0x0000, 0x00}
1208 };
1209
1210 static  struct reginfo sensor_Exposure3[]=
1211 {
1212     {0x0000, 0x00}
1213 };
1214
1215 static  struct reginfo sensor_Exposure4[]=
1216 {
1217     {0x0000, 0x00}
1218 };
1219
1220 static  struct reginfo sensor_Exposure5[]=
1221 {
1222     {0x0000, 0x00}
1223 };
1224
1225 static  struct reginfo sensor_Exposure6[]=
1226 {
1227     {0x0000, 0x00}
1228 };
1229
1230 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1231     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1232 };
1233 #endif
1234 #if CONFIG_SENSOR_Saturation
1235 static  struct reginfo sensor_Saturation0[]=
1236 {
1237     {0x0000, 0x00}
1238 };
1239
1240 static  struct reginfo sensor_Saturation1[]=
1241 {
1242     {0x0000, 0x00}
1243 };
1244
1245 static  struct reginfo sensor_Saturation2[]=
1246 {
1247     {0x0000, 0x00}
1248 };
1249 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1250
1251 #endif
1252 #if CONFIG_SENSOR_Contrast
1253 static  struct reginfo sensor_Contrast0[]=
1254 {
1255     {0x0000, 0x00}
1256 };
1257
1258 static  struct reginfo sensor_Contrast1[]=
1259 {
1260     {0x0000, 0x00}
1261 };
1262
1263 static  struct reginfo sensor_Contrast2[]=
1264 {
1265     {0x0000, 0x00}
1266 };
1267
1268 static  struct reginfo sensor_Contrast3[]=
1269 {
1270     {0x0000, 0x00}
1271 };
1272
1273 static  struct reginfo sensor_Contrast4[]=
1274 {
1275     {0x0000, 0x00}
1276 };
1277
1278
1279 static  struct reginfo sensor_Contrast5[]=
1280 {
1281     {0x0000, 0x00}
1282 };
1283
1284 static  struct reginfo sensor_Contrast6[]=
1285 {
1286     {0x0000, 0x00}
1287 };
1288 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1289     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1290 };
1291
1292 #endif
1293 #if CONFIG_SENSOR_Mirror
1294 static  struct reginfo sensor_MirrorOn[]=
1295 {
1296     {0x0000, 0x00}
1297 };
1298
1299 static  struct reginfo sensor_MirrorOff[]=
1300 {
1301     {0x0000, 0x00}
1302 };
1303 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1304 #endif
1305 #if CONFIG_SENSOR_Flip
1306 static  struct reginfo sensor_FlipOn[]=
1307 {
1308     {0x0000, 0x00}
1309 };
1310
1311 static  struct reginfo sensor_FlipOff[]=
1312 {
1313     {0x0000, 0x00}
1314 };
1315 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1316
1317 #endif
1318 #if CONFIG_SENSOR_Scene
1319 static  struct reginfo sensor_SceneAuto[] =
1320 {
1321         {0x3a00, 0x78},
1322         {0x3a03, 0x7D},
1323         {0x0000, 0x00}
1324 };
1325
1326 static  struct reginfo sensor_SceneNight[] =
1327 {
1328
1329     //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk
1330     {0x3011, 0x08},
1331     {0x3012, 0x00},
1332     {0x3010, 0x10},
1333     {0x460c, 0x22},
1334     {0x380c, 0x0c},
1335     {0x380d, 0x80},
1336     {0x3a00, 0x7c},
1337     {0x3a08, 0x09},
1338     {0x3a09, 0x60},
1339     {0x3a0a, 0x07},
1340     {0x3a0b, 0xd0},
1341     {0x3a0d, 0x08},
1342     {0x3a0e, 0x06},
1343     {0x3a03, 0xfa},
1344     {0x0000, 0x00}
1345
1346 };
1347 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1348
1349 #endif
1350 #if CONFIG_SENSOR_DigitalZoom
1351 static struct reginfo sensor_Zoom0[] =
1352 {
1353     {0x0, 0x0},
1354 };
1355
1356 static struct reginfo sensor_Zoom1[] =
1357 {
1358      {0x0, 0x0},
1359 };
1360
1361 static struct reginfo sensor_Zoom2[] =
1362 {
1363     {0x0, 0x0},
1364 };
1365
1366
1367 static struct reginfo sensor_Zoom3[] =
1368 {
1369     {0x0, 0x0},
1370 };
1371 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
1372 #endif
1373 static const struct v4l2_querymenu sensor_menus[] =
1374 {
1375         #if CONFIG_SENSOR_WhiteBalance
1376     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
1377     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
1378     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
1379     #endif
1380
1381         #if CONFIG_SENSOR_Effect
1382     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
1383     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
1384     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},
1385     #endif
1386
1387         #if CONFIG_SENSOR_Scene
1388     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
1389     #endif
1390
1391         #if CONFIG_SENSOR_Flash
1392     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
1393     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
1394     #endif
1395 };
1396
1397 static const struct v4l2_queryctrl sensor_controls[] =
1398 {
1399         #if CONFIG_SENSOR_WhiteBalance
1400     {
1401         .id             = V4L2_CID_DO_WHITE_BALANCE,
1402         .type           = V4L2_CTRL_TYPE_MENU,
1403         .name           = "White Balance Control",
1404         .minimum        = 0,
1405         .maximum        = 4,
1406         .step           = 1,
1407         .default_value = 0,
1408     },
1409     #endif
1410
1411         #if CONFIG_SENSOR_Brightness
1412         {
1413         .id             = V4L2_CID_BRIGHTNESS,
1414         .type           = V4L2_CTRL_TYPE_INTEGER,
1415         .name           = "Brightness Control",
1416         .minimum        = -3,
1417         .maximum        = 2,
1418         .step           = 1,
1419         .default_value = 0,
1420     },
1421     #endif
1422
1423         #if CONFIG_SENSOR_Effect
1424         {
1425         .id             = V4L2_CID_EFFECT,
1426         .type           = V4L2_CTRL_TYPE_MENU,
1427         .name           = "Effect Control",
1428         .minimum        = 0,
1429         .maximum        = 5,
1430         .step           = 1,
1431         .default_value = 0,
1432     },
1433         #endif
1434
1435         #if CONFIG_SENSOR_Exposure
1436         {
1437         .id             = V4L2_CID_EXPOSURE,
1438         .type           = V4L2_CTRL_TYPE_INTEGER,
1439         .name           = "Exposure Control",
1440         .minimum        = 0,
1441         .maximum        = 6,
1442         .step           = 1,
1443         .default_value = 0,
1444     },
1445         #endif
1446
1447         #if CONFIG_SENSOR_Saturation
1448         {
1449         .id             = V4L2_CID_SATURATION,
1450         .type           = V4L2_CTRL_TYPE_INTEGER,
1451         .name           = "Saturation Control",
1452         .minimum        = 0,
1453         .maximum        = 2,
1454         .step           = 1,
1455         .default_value = 0,
1456     },
1457     #endif
1458
1459         #if CONFIG_SENSOR_Contrast
1460         {
1461         .id             = V4L2_CID_CONTRAST,
1462         .type           = V4L2_CTRL_TYPE_INTEGER,
1463         .name           = "Contrast Control",
1464         .minimum        = -3,
1465         .maximum        = 3,
1466         .step           = 1,
1467         .default_value = 0,
1468     },
1469         #endif
1470
1471         #if CONFIG_SENSOR_Mirror
1472         {
1473         .id             = V4L2_CID_HFLIP,
1474         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1475         .name           = "Mirror Control",
1476         .minimum        = 0,
1477         .maximum        = 1,
1478         .step           = 1,
1479         .default_value = 1,
1480     },
1481     #endif
1482
1483         #if CONFIG_SENSOR_Flip
1484         {
1485         .id             = V4L2_CID_VFLIP,
1486         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1487         .name           = "Flip Control",
1488         .minimum        = 0,
1489         .maximum        = 1,
1490         .step           = 1,
1491         .default_value = 1,
1492     },
1493     #endif
1494
1495         #if CONFIG_SENSOR_Scene
1496     {
1497         .id             = V4L2_CID_SCENE,
1498         .type           = V4L2_CTRL_TYPE_MENU,
1499         .name           = "Scene Control",
1500         .minimum        = 0,
1501         .maximum        = 1,
1502         .step           = 1,
1503         .default_value = 0,
1504     },
1505     #endif
1506
1507         #if CONFIG_SENSOR_DigitalZoom
1508     {
1509         .id             = V4L2_CID_ZOOM_RELATIVE,
1510         .type           = V4L2_CTRL_TYPE_INTEGER,
1511         .name           = "DigitalZoom Control",
1512         .minimum        = -1,
1513         .maximum        = 1,
1514         .step           = 1,
1515         .default_value = 0,
1516     }, {
1517         .id             = V4L2_CID_ZOOM_ABSOLUTE,
1518         .type           = V4L2_CTRL_TYPE_INTEGER,
1519         .name           = "DigitalZoom Control",
1520         .minimum        = 0,
1521         .maximum        = 3,
1522         .step           = 1,
1523         .default_value = 0,
1524     },
1525     #endif
1526
1527         #ifdef CONFIG_SENSOR_Focus
1528         {
1529         .id             = V4L2_CID_FOCUS_RELATIVE,
1530         .type           = V4L2_CTRL_TYPE_INTEGER,
1531         .name           = "Focus Control",
1532         .minimum        = -1,
1533         .maximum        = 1,
1534         .step           = 1,
1535         .default_value = 0,
1536     }, {
1537         .id             = V4L2_CID_FOCUS_ABSOLUTE,
1538         .type           = V4L2_CTRL_TYPE_INTEGER,
1539         .name           = "Focus Control",
1540         .minimum        = 0,
1541         .maximum        = 255,
1542         .step           = 1,
1543         .default_value = 125,
1544     },
1545         {
1546         .id             = V4L2_CID_FOCUS_AUTO,
1547         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1548         .name           = "Focus Control",
1549         .minimum        = 0,
1550         .maximum        = 1,
1551         .step           = 1,
1552         .default_value = 0,
1553     },{
1554         .id             = V4L2_CID_FOCUS_CONTINUOUS,
1555         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1556         .name           = "Focus Control",
1557         .minimum        = 0,
1558         .maximum        = 1,
1559         .step           = 1,
1560         .default_value = 0,
1561     },
1562     #endif
1563
1564         #if CONFIG_SENSOR_Flash
1565         {
1566         .id             = V4L2_CID_FLASH,
1567         .type           = V4L2_CTRL_TYPE_MENU,
1568         .name           = "Flash Control",
1569         .minimum        = 0,
1570         .maximum        = 3,
1571         .step           = 1,
1572         .default_value = 0,
1573     },
1574         #endif
1575 };
1576
1577 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1578 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1579 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1580 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1581 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1582 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1583 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1584 static int sensor_resume(struct soc_camera_device *icd);
1585 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1586 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1587
1588 static struct soc_camera_ops sensor_ops =
1589 {
1590     .suspend                     = sensor_suspend,
1591     .resume                       = sensor_resume,
1592     .set_bus_param              = sensor_set_bus_param,
1593     .query_bus_param    = sensor_query_bus_param,
1594     .controls           = sensor_controls,
1595     .menus                         = sensor_menus,
1596     .num_controls               = ARRAY_SIZE(sensor_controls),
1597     .num_menus          = ARRAY_SIZE(sensor_menus),
1598 };
1599
1600 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1601         { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1602         .colorspace = _colorspace }
1603
1604 #define JPG_FMT(_name, _depth, _fourcc) \
1605         COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1606
1607 static const struct soc_camera_data_format sensor_colour_formats[] = {
1608         JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1609         JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1610 };
1611
1612 typedef struct sensor_info_priv_s
1613 {
1614     int whiteBalance;
1615     int brightness;
1616     int contrast;
1617     int saturation;
1618     int effect;
1619     int scene;
1620     int digitalzoom;
1621     int focus;
1622         int auto_focus;
1623     int flash;
1624     int exposure;
1625     unsigned char mirror;                                        /* HFLIP */
1626     unsigned char flip;                                          /* VFLIP */
1627     unsigned int winseqe_cur_addr;
1628         unsigned int pixfmt;
1629         unsigned int funmodule_state;
1630 } sensor_info_priv_t;
1631
1632 struct sensor
1633 {
1634     struct v4l2_subdev subdev;
1635     struct i2c_client *client;
1636     sensor_info_priv_t info_priv;
1637     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1638 };
1639
1640 static struct sensor* to_sensor(const struct i2c_client *client)
1641 {
1642     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1643 }
1644
1645 /* sensor register write */
1646 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
1647 {
1648     int err,cnt;
1649     u8 buf[3];
1650     struct i2c_msg msg[1];
1651
1652     buf[0] = reg >> 8;
1653     buf[1] = reg & 0xFF;
1654     buf[2] = val;
1655
1656     msg->addr = client->addr;
1657     msg->flags = client->flags;
1658     msg->buf = buf;
1659     msg->len = sizeof(buf);
1660     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1661     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1662
1663     cnt = 1;
1664     err = -EAGAIN;
1665
1666     while ((cnt--) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1667         err = i2c_transfer(client->adapter, msg, 1);
1668
1669         if (err >= 0) {
1670             return 0;
1671         } else {
1672             SENSOR_TR("\n %s write reg failed, try to write again!\n",SENSOR_NAME_STRING());
1673             udelay(10);
1674         }
1675     }
1676
1677     return err;
1678 }
1679
1680 /* sensor register read */
1681 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
1682 {
1683     int err,cnt;
1684     u8 buf[2];
1685     struct i2c_msg msg[2];
1686
1687     buf[0] = reg >> 8;
1688     buf[1] = reg & 0xFF;
1689
1690     msg[0].addr = client->addr;
1691     msg[0].flags = client->flags;
1692     msg[0].buf = buf;
1693     msg[0].len = sizeof(buf);
1694     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
1695     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1696
1697     msg[1].addr = client->addr;
1698     msg[1].flags = client->flags|I2C_M_RD;
1699     msg[1].buf = buf;
1700     msg[1].len = 1;
1701     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
1702     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1703
1704     cnt = 1;
1705     err = -EAGAIN;
1706     while ((cnt--) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1707         err = i2c_transfer(client->adapter, msg, 2);
1708
1709         if (err >= 0) {
1710             *val = buf[0];
1711             return 0;
1712         } else {
1713                 SENSOR_TR("\n %s read reg failed, try to read again! reg:0x%x \n",SENSOR_NAME_STRING(),(unsigned int)val);
1714             udelay(10);
1715         }
1716     }
1717
1718     return err;
1719 }
1720
1721 /* write a array of registers  */
1722 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1723 {
1724     int err, cnt;
1725     int i = 0;
1726
1727         cnt = 0;
1728     while (regarray[i].reg != 0)
1729     {
1730         err = sensor_write(client, regarray[i].reg, regarray[i].val);
1731         if (err < 0)
1732         {
1733             if (cnt-- > 0) {
1734                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1735                                 i = 0;
1736                                 continue;
1737             } else {
1738                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1739                 return -EPERM;
1740             }
1741         }
1742         i++;
1743     }
1744     return 0;
1745 }
1746 #if CONFIG_SENSOR_Focus
1747 struct af_cmdinfo
1748 {
1749         char cmd_tag;
1750         char cmd_para[4];
1751         char validate_bit;
1752 };
1753 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
1754 {
1755         int i;
1756         char read_tag=0xff,cnt;
1757
1758         if (cmdinfo) {
1759                 if (cmdinfo->validate_bit & 0x80) {
1760                         if (sensor_write(client, CMD_TAG_Reg, cmdinfo->cmd_tag)) {
1761                                 SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
1762                                 goto sensor_af_cmdset_err;
1763                         }
1764                         SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,cmdinfo->cmd_tag);
1765                 }
1766                 for (i=0; i<4; i++) {
1767                         if (cmdinfo->validate_bit & (1<<i)) {
1768                                 if (sensor_write(client, CMD_PARA0_Reg-i, cmdinfo->cmd_para[i])) {
1769                                         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]);
1770                                         goto sensor_af_cmdset_err;
1771                                 }
1772                                 SENSOR_TR("%s write CMD_PARA_Reg(main:0x%x para%d:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,i,cmdinfo->cmd_para[i]);
1773                         }
1774                 }
1775         } else {
1776                 if (sensor_write(client, CMD_TAG_Reg, 0xff)) {
1777                         SENSOR_TR("%s write CMD_TAG_Reg(main:0x%x no tag) error!\n",SENSOR_NAME_STRING(),cmd_main);
1778                         goto sensor_af_cmdset_err;
1779                 }
1780                 SENSOR_DG("%s write CMD_TAG_Reg(main:0x%x no tag) success!\n",SENSOR_NAME_STRING(),cmd_main);
1781         }
1782
1783         if (sensor_write(client, CMD_MAIN_Reg, cmd_main)) {
1784                 SENSOR_TR("%s write CMD_MAIN_Reg(main:0x%x) error!\n",SENSOR_NAME_STRING(),cmd_main);
1785                 goto sensor_af_cmdset_err;
1786         }
1787
1788         cnt = 0;
1789         do
1790         {
1791                 msleep(5);
1792                 if (sensor_read(client,CMD_TAG_Reg,&read_tag)){
1793                    SENSOR_TR("%s[%d] read TAG failed\n",SENSOR_NAME_STRING(),__LINE__);
1794                    break;
1795                 }
1796     } while((read_tag != 0x00)&& (cnt++<100));
1797
1798         SENSOR_DG("%s write CMD_MAIN_Reg(main:0x%x read tag:0x%x) success!\n",SENSOR_NAME_STRING(),cmd_main,read_tag);
1799         return 0;
1800 sensor_af_cmdset_err:
1801         return -1;
1802 }
1803
1804 static int sensor_af_idlechk(struct i2c_client *client)
1805 {
1806         int ret = 0;
1807         char state,cnt;
1808
1809         cnt = 0;
1810         do
1811         {
1812                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1813                 if (ret != 0){
1814                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1815                    ret = -1;
1816                    goto sensor_af_idlechk_end;
1817                 }
1818
1819                 if (state != S_IDLE) {
1820                         sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
1821                         msleep(1);
1822                         cnt++;
1823                 }
1824     } while((state != S_IDLE)&& (cnt<100));
1825
1826         ret = (state == S_IDLE) ? 0 : -1;
1827
1828 sensor_af_idlechk_end:
1829         return ret;
1830 }
1831
1832 static int sensor_af_single(struct i2c_client *client)
1833 {
1834         int ret = 0;
1835         char state,cnt;
1836
1837         if (sensor_af_idlechk(client))
1838                 goto sensor_af_single_end;
1839
1840         if (sensor_af_cmdset(client, SingleFocus_Cmd, NULL)) {
1841                 SENSOR_TR("%s single focus mode set error!\n",SENSOR_NAME_STRING());
1842                 ret = -1;
1843                 goto sensor_af_single_end;
1844         }
1845
1846         cnt = 0;
1847     do
1848     {
1849         if (cnt != 0) {
1850                         msleep(1);
1851         }
1852         cnt++;
1853                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1854                 if (ret != 0){
1855                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1856                    ret = -1;
1857                    goto sensor_af_single_end;
1858                 }
1859     }while((state == S_FOCUSING) && (cnt<100));
1860
1861         if (state != S_FOCUSED) {
1862         SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
1863                 ret = -1;
1864                 goto sensor_af_single_end;
1865     }
1866
1867         sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
1868 sensor_af_single_end:
1869         return ret;
1870 }
1871
1872 static int sensor_af_const(struct i2c_client *client)
1873 {
1874         int ret = 0;
1875
1876         if (sensor_af_idlechk(client))
1877                 goto sensor_af_const_end;
1878
1879         if (sensor_af_cmdset(client, ConstFocus_Cmd, NULL)) {
1880                 SENSOR_TR("%s const focus mode set error!\n",SENSOR_NAME_STRING());
1881                 ret = -1;
1882                 goto sensor_af_const_end;
1883         }
1884 sensor_af_const_end:
1885         return ret;
1886 }
1887 static int sensor_af_pause2capture(struct i2c_client *client)
1888 {
1889         int ret = 0;
1890         char state,cnt;
1891
1892         if (sensor_af_cmdset(client, PauseFocus_Cmd, NULL)) {
1893                 SENSOR_TR("%s pause focus mode set error!\n",SENSOR_NAME_STRING());
1894                 ret = -1;
1895                 goto sensor_af_pause_end;
1896         }
1897
1898         cnt = 0;
1899     do
1900     {
1901         if (cnt != 0) {
1902                         msleep(1);
1903         }
1904         cnt++;
1905                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1906                 if (ret != 0){
1907                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1908                    ret = -1;
1909                    goto sensor_af_pause_end;
1910                 }
1911     }while((state != S_CAPTURE) && (cnt<100));
1912
1913         if (state != S_CAPTURE) {
1914         SENSOR_TR("%s[%d] focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),__LINE__,state);
1915                 ret = -1;
1916                 goto sensor_af_pause_end;
1917     }
1918 sensor_af_pause_end:
1919         return ret;
1920 }
1921 static int sensor_af_zoneupdate(struct i2c_client *client)
1922 {
1923         int ret = 0;
1924
1925         if (sensor_af_idlechk(client))
1926                 goto sensor_af_zoneupdate_end;
1927
1928         if (sensor_af_cmdset(client, UpdateZone_Cmd, NULL)) {
1929                 SENSOR_TR("%s update zone fail!\n",SENSOR_NAME_STRING());
1930                 ret = -1;
1931                 goto sensor_af_zoneupdate_end;
1932         }
1933
1934 sensor_af_zoneupdate_end:
1935         return ret;
1936 }
1937 static int sensor_af_init(struct i2c_client *client)
1938 {
1939         int ret = 0;
1940         char state,cnt;
1941
1942         ret = sensor_write_array(client, sensor_af_firmware);
1943     if (ret != 0) {
1944        SENSOR_TR("%s Download firmware failed\n",SENSOR_NAME_STRING());
1945        ret = -1;
1946            goto sensor_af_init_end;
1947     }
1948
1949         cnt = 0;
1950     do
1951     {
1952         if (cnt != 0) {
1953                         msleep(1);
1954         }
1955         cnt++;
1956                 ret = sensor_read(client, STA_FOCUS_Reg, &state);
1957                 if (ret != 0){
1958                    SENSOR_TR("%s[%d] read focus_status failed\n",SENSOR_NAME_STRING(),__LINE__);
1959                    ret = -1;
1960                    goto sensor_af_init_end;
1961                 }
1962     }while((state == S_STARTUP) && (cnt<100));
1963
1964     if (state != S_IDLE) {
1965         SENSOR_TR("%s focus state(0x%x) is error!\n",SENSOR_NAME_STRING(),state);
1966                 ret = -1;
1967                 goto sensor_af_init_end;
1968     }
1969
1970         if (sensor_af_single(client)) {
1971                 ret = -1;
1972                 goto sensor_af_init_end;
1973         }
1974
1975 sensor_af_init_end:
1976         SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
1977         return ret;
1978 }
1979 #endif
1980 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1981 {
1982     struct i2c_client *client = sd->priv;
1983     struct soc_camera_device *icd = client->dev.platform_data;
1984     struct sensor *sensor = to_sensor(client);
1985         const struct v4l2_queryctrl *qctrl;
1986     char value;
1987     int ret,pid = 0;
1988
1989     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1990
1991     /* soft reset */
1992     ret = sensor_write(client, 0x3008, 0x80);
1993     if (ret != 0) {
1994         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1995         ret = -ENODEV;
1996                 goto sensor_INIT_ERR;
1997     }
1998
1999     mdelay(5);  //delay 5 microseconds
2000         /* check if it is an sensor sensor */
2001     ret = sensor_read(client, 0x300a, &value);
2002     if (ret != 0) {
2003         SENSOR_TR("read chip id high byte failed\n");
2004         ret = -ENODEV;
2005         goto sensor_INIT_ERR;
2006     }
2007
2008     pid |= (value << 8);
2009
2010     ret = sensor_read(client, 0x300b, &value);
2011     if (ret != 0) {
2012         SENSOR_TR("read chip id low byte failed\n");
2013         ret = -ENODEV;
2014         goto sensor_INIT_ERR;
2015     }
2016
2017     pid |= (value & 0xff);
2018     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2019     if (pid == SENSOR_ID) {
2020         sensor->model = SENSOR_V4L2_IDENT;
2021     } else {
2022         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2023         ret = -ENODEV;
2024         goto sensor_INIT_ERR;
2025     }
2026
2027     ret = sensor_write_array(client, sensor_init_data);
2028     if (ret != 0)
2029     {
2030         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2031         goto sensor_INIT_ERR;
2032     }
2033
2034     icd->user_width = SENSOR_INIT_WIDTH;
2035     icd->user_height = SENSOR_INIT_HEIGHT;
2036     sensor->info_priv.winseqe_cur_addr  = (int)SENSOR_INIT_WINSEQADR;
2037         sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
2038
2039     /* sensor sensor information for initialization  */
2040         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2041         if (qctrl)
2042         sensor->info_priv.whiteBalance = qctrl->default_value;
2043         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2044         if (qctrl)
2045         sensor->info_priv.brightness = qctrl->default_value;
2046         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2047         if (qctrl)
2048         sensor->info_priv.effect = qctrl->default_value;
2049         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2050         if (qctrl)
2051         sensor->info_priv.exposure = qctrl->default_value;
2052
2053         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2054         if (qctrl)
2055         sensor->info_priv.saturation = qctrl->default_value;
2056         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2057         if (qctrl)
2058         sensor->info_priv.contrast = qctrl->default_value;
2059         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2060         if (qctrl)
2061         sensor->info_priv.mirror = qctrl->default_value;
2062         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2063         if (qctrl)
2064         sensor->info_priv.flip = qctrl->default_value;
2065         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2066         if (qctrl)
2067         sensor->info_priv.scene = qctrl->default_value;
2068         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2069         if (qctrl)
2070         sensor->info_priv.digitalzoom = qctrl->default_value;
2071
2072     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
2073         #if CONFIG_SENSOR_Focus
2074         if (sensor_af_init(client)) {
2075                 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
2076         } else {
2077                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
2078                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2079                 if (qctrl)
2080                 sensor->info_priv.focus = qctrl->default_value;
2081
2082         }
2083         #endif
2084
2085         #if CONFIG_SENSOR_Flash
2086         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2087         if (qctrl)
2088         sensor->info_priv.flash = qctrl->default_value;
2089     #endif
2090
2091     SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,icd->user_width,icd->user_height);
2092
2093     return 0;
2094 sensor_INIT_ERR:
2095     return ret;
2096 }
2097 static int sensor_deactivate(struct v4l2_subdev *sd)
2098 {
2099         struct i2c_client *client = sd->priv;
2100
2101         SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2102
2103         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2104     sensor_write(client, 0x3017, 0x00);  // FREX,VSYNC,HREF,PCLK,D9-D6
2105         sensor_write(client, 0x3018, 0x03);  // D5-D0
2106         sensor_write(client,0x3019,0X00);    // STROBE,SDA
2107
2108         return 0;
2109 }
2110 static  struct reginfo sensor_power_down_sequence[]=
2111 {
2112     {0x00,0x00}
2113 };
2114 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2115 {
2116     int ret;
2117     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2118     struct soc_camera_link *icl;
2119
2120
2121     if (pm_msg.event == PM_EVENT_SUSPEND)
2122     {
2123         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2124         ret = sensor_write_array(client, sensor_power_down_sequence) ;
2125         if (ret != 0)
2126         {
2127             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2128             return ret;
2129         }
2130         else
2131         {
2132             icl = to_soc_camera_link(icd);
2133             if (icl->power) {
2134                 ret = icl->power(icd->pdev, 0);
2135                 if (ret < 0) {
2136                                     SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2137                     return -EINVAL;
2138                 }
2139             }
2140         }
2141     }
2142     else
2143     {
2144         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2145         return -EINVAL;
2146     }
2147     return 0;
2148 }
2149
2150 static int sensor_resume(struct soc_camera_device *icd)
2151 {
2152     struct soc_camera_link *icl;
2153     int ret;
2154
2155     icl = to_soc_camera_link(icd);
2156     if (icl->power) {
2157         ret = icl->power(icd->pdev, 1);
2158         if (ret < 0) {
2159                         SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2160             return -EINVAL;
2161         }
2162     }
2163
2164         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2165
2166     return 0;
2167
2168 }
2169
2170 static int sensor_set_bus_param(struct soc_camera_device *icd,
2171                                 unsigned long flags)
2172 {
2173
2174     return 0;
2175 }
2176
2177 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2178 {
2179     struct soc_camera_link *icl = to_soc_camera_link(icd);
2180     unsigned long flags = SENSOR_BUS_PARAM;
2181
2182     return soc_camera_apply_sensor_flags(icl, flags);
2183 }
2184
2185 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2186 {
2187     struct i2c_client *client = sd->priv;
2188     struct soc_camera_device *icd = client->dev.platform_data;
2189     struct sensor *sensor = to_sensor(client);
2190     struct v4l2_pix_format *pix = &f->fmt.pix;
2191
2192     pix->width          = icd->user_width;
2193     pix->height         = icd->user_height;
2194     pix->pixelformat    = sensor->info_priv.pixfmt;
2195     pix->field          = V4L2_FIELD_NONE;
2196     pix->colorspace             = V4L2_COLORSPACE_JPEG;
2197
2198     return 0;
2199 }
2200 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2201 {
2202     struct i2c_client *client = sd->priv;
2203     struct sensor *sensor = to_sensor(client);
2204     struct v4l2_pix_format *pix = &f->fmt.pix;
2205     struct reginfo *winseqe_set_addr=NULL;
2206     int ret = 0, set_w,set_h;
2207
2208         if (sensor->info_priv.pixfmt != pix->pixelformat) {
2209                 switch (pix->pixelformat)
2210                 {
2211                         case V4L2_PIX_FMT_YUYV:
2212                         {
2213                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
2214                                 break;
2215                         }
2216                         case V4L2_PIX_FMT_UYVY:
2217                         {
2218                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
2219                                 break;
2220                         }
2221                         default:
2222                                 break;
2223                 }
2224                 if (winseqe_set_addr != NULL) {
2225             sensor_write_array(client, winseqe_set_addr);
2226                         sensor->info_priv.pixfmt = pix->pixelformat;
2227
2228                         SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
2229                 } else {
2230                         SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
2231                 }
2232         }
2233
2234     set_w = pix->width;
2235     set_h = pix->height;
2236
2237         if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2238         {
2239                 winseqe_set_addr = sensor_qcif;
2240         set_w = 176;
2241         set_h = 144;
2242         }
2243         else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2244     {
2245         winseqe_set_addr = sensor_qvga;
2246         set_w = 320;
2247         set_h = 240;
2248     }
2249     else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2250     {
2251         winseqe_set_addr = sensor_cif;
2252         set_w = 352;
2253         set_h = 288;
2254     }
2255     else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2256     {
2257         winseqe_set_addr = sensor_vga;
2258         set_w = 640;
2259         set_h = 480;
2260     }
2261     else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2262     {
2263         winseqe_set_addr = sensor_svga;
2264         set_w = 800;
2265         set_h = 600;
2266     }
2267     else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2268     {
2269         winseqe_set_addr = sensor_sxga;
2270         set_w = 1280;
2271         set_h = 1024;
2272     }
2273     else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2274     {
2275         winseqe_set_addr = sensor_uxga;
2276         set_w = 1600;
2277         set_h = 1200;
2278     }
2279         else if (((set_w <= 2048) && (set_h <= 1536)) && sensor_qxga[0].reg)
2280     {
2281         winseqe_set_addr = sensor_qxga;
2282         set_w = 2048;
2283         set_h = 1536;
2284     }
2285         else if (((set_w <= 2592) && (set_h <= 1944)) && sensor_qsxga[0].reg)
2286     {
2287         winseqe_set_addr = sensor_qsxga;
2288         set_w = 2592;
2289         set_h = 1944;
2290     }
2291     else
2292     {
2293         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */
2294         set_w = SENSOR_INIT_WIDTH;
2295         set_h = SENSOR_INIT_HEIGHT;
2296                 ret = -1;
2297                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
2298     }
2299
2300     if ((int)winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr)
2301     {
2302         ret |= sensor_write_array(client, winseqe_set_addr);
2303         if (ret != 0) {
2304             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2305             goto sensor_s_fmt_end;
2306         }
2307
2308         sensor->info_priv.winseqe_cur_addr  = (int)winseqe_set_addr;
2309         //#if CONFIG_SENSOR_Focus
2310                 //sensor_af_zoneupdate(client);
2311                 //#endif
2312
2313
2314         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2315     }
2316     else
2317     {
2318         SENSOR_TR("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2319     }
2320
2321         pix->width = set_w;
2322         pix->height = set_h;
2323 sensor_s_fmt_end:
2324     return ret;
2325 }
2326
2327 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
2328 {
2329     struct v4l2_pix_format *pix = &f->fmt.pix;
2330     bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
2331         pix->pixelformat == V4L2_PIX_FMT_YUYV;
2332
2333     /*
2334     * With Bayer format enforce even side lengths, but let the user play
2335     * with the starting pixel
2336     */
2337
2338     if (pix->height > SENSOR_MAX_HEIGHT)
2339         pix->height = SENSOR_MAX_HEIGHT;
2340     else if (pix->height < SENSOR_MIN_HEIGHT)
2341         pix->height = SENSOR_MIN_HEIGHT;
2342     else if (bayer)
2343         pix->height = ALIGN(pix->height, 2);
2344
2345     if (pix->width > SENSOR_MAX_WIDTH)
2346         pix->width = SENSOR_MAX_WIDTH;
2347     else if (pix->width < SENSOR_MIN_WIDTH)
2348         pix->width = SENSOR_MIN_WIDTH;
2349     else if (bayer)
2350         pix->width = ALIGN(pix->width, 2);
2351
2352     return 0;
2353 }
2354
2355  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2356 {
2357     struct i2c_client *client = sd->priv;
2358
2359     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2360         return -EINVAL;
2361
2362     if (id->match.addr != client->addr)
2363         return -ENODEV;
2364
2365     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
2366     id->revision = 0;
2367
2368     return 0;
2369 }
2370 #if CONFIG_SENSOR_Brightness
2371 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2372 {
2373     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2374
2375     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2376     {
2377         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2378         {
2379             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2380             {
2381                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2382                 return -EINVAL;
2383             }
2384             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2385             return 0;
2386         }
2387     }
2388         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2389     return -EINVAL;
2390 }
2391 #endif
2392 #if CONFIG_SENSOR_Effect
2393 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2394 {
2395     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2396
2397     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2398     {
2399         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2400         {
2401             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2402             {
2403                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2404                 return -EINVAL;
2405             }
2406             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2407             return 0;
2408         }
2409     }
2410         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2411     return -EINVAL;
2412 }
2413 #endif
2414 #if CONFIG_SENSOR_Exposure
2415 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2416 {
2417     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2418
2419     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2420     {
2421         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2422         {
2423             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2424             {
2425                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2426                 return -EINVAL;
2427             }
2428             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2429             return 0;
2430         }
2431     }
2432         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2433     return -EINVAL;
2434 }
2435 #endif
2436 #if CONFIG_SENSOR_Saturation
2437 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2438 {
2439     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2440
2441     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2442     {
2443         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2444         {
2445             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2446             {
2447                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2448                 return -EINVAL;
2449             }
2450             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2451             return 0;
2452         }
2453     }
2454     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2455     return -EINVAL;
2456 }
2457 #endif
2458 #if CONFIG_SENSOR_Contrast
2459 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2460 {
2461     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2462
2463     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2464     {
2465         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2466         {
2467             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2468             {
2469                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2470                 return -EINVAL;
2471             }
2472             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2473             return 0;
2474         }
2475     }
2476     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2477     return -EINVAL;
2478 }
2479 #endif
2480 #if CONFIG_SENSOR_Mirror
2481 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2482 {
2483     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2484
2485     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2486     {
2487         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2488         {
2489             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2490             {
2491                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2492                 return -EINVAL;
2493             }
2494             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2495             return 0;
2496         }
2497     }
2498     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2499     return -EINVAL;
2500 }
2501 #endif
2502 #if CONFIG_SENSOR_Flip
2503 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2504 {
2505     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2506
2507     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2508     {
2509         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2510         {
2511             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2512             {
2513                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2514                 return -EINVAL;
2515             }
2516             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2517             return 0;
2518         }
2519     }
2520     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2521     return -EINVAL;
2522 }
2523 #endif
2524 #if CONFIG_SENSOR_Scene
2525 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2526 {
2527     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2528
2529     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2530     {
2531         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2532         {
2533             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2534             {
2535                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2536                 return -EINVAL;
2537             }
2538             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2539             return 0;
2540         }
2541     }
2542     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2543     return -EINVAL;
2544 }
2545 #endif
2546 #if CONFIG_SENSOR_WhiteBalance
2547 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2548 {
2549     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2550
2551     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2552     {
2553         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2554         {
2555             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2556             {
2557                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2558                 return -EINVAL;
2559             }
2560             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2561             return 0;
2562         }
2563     }
2564         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2565     return -EINVAL;
2566 }
2567 #endif
2568 #if CONFIG_SENSOR_DigitalZoom
2569 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2570 {
2571     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2572     struct sensor *sensor = to_sensor(client);
2573         const struct v4l2_queryctrl *qctrl_info;
2574     int digitalzoom_cur, digitalzoom_total;
2575
2576         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2577         if (qctrl_info)
2578                 return -EINVAL;
2579
2580     digitalzoom_cur = sensor->info_priv.digitalzoom;
2581     digitalzoom_total = qctrl_info->maximum;
2582
2583     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2584     {
2585         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2586         return -EINVAL;
2587     }
2588
2589     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2590     {
2591         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2592         return -EINVAL;
2593     }
2594
2595     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2596     {
2597         *value = digitalzoom_total - digitalzoom_cur;
2598     }
2599
2600     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2601     {
2602         *value = 0 - digitalzoom_cur;
2603     }
2604
2605     digitalzoom_cur += *value;
2606
2607     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2608     {
2609         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2610         {
2611             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2612             return -EINVAL;
2613         }
2614         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2615         return 0;
2616     }
2617
2618     return -EINVAL;
2619 }
2620 #endif
2621 #if CONFIG_SENSOR_Focus
2622 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2623 {
2624         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2625     struct sensor *sensor = to_sensor(client);
2626         const struct v4l2_queryctrl *qctrl_info;
2627         struct af_cmdinfo cmdinfo;
2628         int ret = 0;
2629
2630         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2631         if (!qctrl_info)
2632                 return -EINVAL;
2633
2634         if (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) {
2635                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2636
2637                         if (sensor_af_idlechk(client))
2638                                 goto sensor_set_focus_absolute_end;
2639
2640                         cmdinfo.cmd_tag = StepFocus_Spec_Tag;
2641                         cmdinfo.cmd_para[0] = value;
2642                         cmdinfo.validate_bit = 0x81;
2643                         ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2644                         //ret |= sensor_af_cmdset(client, ReturnIdle_Cmd, NULL);
2645                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2646                 } else {
2647                         ret = -EINVAL;
2648                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2649                 }
2650         } else {
2651                 ret = -EACCES;
2652                 SENSOR_TR("\n %s..%s AF module state is error!\n",SENSOR_NAME_STRING(),__FUNCTION__);
2653         }
2654
2655 sensor_set_focus_absolute_end:
2656         return ret;
2657 }
2658 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2659 {
2660         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2661         struct sensor *sensor = to_sensor(client);
2662         const struct v4l2_queryctrl *qctrl_info;
2663         struct af_cmdinfo cmdinfo;
2664         int ret = 0;
2665
2666         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2667         if (!qctrl_info)
2668                 return -EINVAL;
2669
2670         if (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) {
2671                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2672
2673                         if (sensor_af_idlechk(client))
2674                                 goto sensor_set_focus_relative_end;
2675
2676                         if (value > 0) {
2677                                 cmdinfo.cmd_tag = StepFocus_Near_Tag;
2678                         } else if (value < 0) {
2679                                 cmdinfo.cmd_tag = StepFocus_Far_Tag;
2680                         }
2681                         cmdinfo.validate_bit = 0x80;
2682                         ret = sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo);
2683
2684                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2685                 } else {
2686                         ret = -EINVAL;
2687                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2688                 }
2689         } else {
2690                 ret = -EACCES;
2691                 SENSOR_TR("\n %s..%s AF module state is error!\n",SENSOR_NAME_STRING(),__FUNCTION__);
2692         }
2693 sensor_set_focus_relative_end:
2694         return ret;
2695 }
2696
2697 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2698 {
2699         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2700         struct sensor *sensor = to_sensor(client);
2701         int ret = 0;
2702
2703         if (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) {
2704                 switch (value)
2705                 {
2706                         case SENSOR_AF_MODE_AUTO:
2707                         {
2708                                 ret = sensor_af_single(client);
2709                                 break;
2710                         }
2711
2712                         case SENSOR_AF_MODE_MACRO:
2713                         {
2714                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2715                                 break;
2716                         }
2717
2718                         case SENSOR_AF_MODE_INFINITY:
2719                         {
2720                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2721                                 break;
2722                         }
2723
2724                         case SENSOR_AF_MODE_CONTINUOUS:
2725                         {
2726                                 ret = sensor_af_const(client);
2727                                 break;
2728                         }
2729                         default:
2730                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2731                                 break;
2732
2733                 }
2734
2735                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2736         } else {
2737                 ret = -EACCES;
2738                 SENSOR_TR("\n %s..%s AF module state is error!\n",SENSOR_NAME_STRING(),__FUNCTION__);
2739         }
2740
2741         return ret;
2742 }
2743 #endif
2744 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2745 {
2746     struct i2c_client *client = sd->priv;
2747     struct sensor *sensor = to_sensor(client);
2748     const struct v4l2_queryctrl *qctrl;
2749
2750     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2751
2752     if (!qctrl)
2753     {
2754         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2755         return -EINVAL;
2756     }
2757
2758     switch (ctrl->id)
2759     {
2760         case V4L2_CID_BRIGHTNESS:
2761             {
2762                 ctrl->value = sensor->info_priv.brightness;
2763                 break;
2764             }
2765         case V4L2_CID_SATURATION:
2766             {
2767                 ctrl->value = sensor->info_priv.saturation;
2768                 break;
2769             }
2770         case V4L2_CID_CONTRAST:
2771             {
2772                 ctrl->value = sensor->info_priv.contrast;
2773                 break;
2774             }
2775         case V4L2_CID_DO_WHITE_BALANCE:
2776             {
2777                 ctrl->value = sensor->info_priv.whiteBalance;
2778                 break;
2779             }
2780         case V4L2_CID_EXPOSURE:
2781             {
2782                 ctrl->value = sensor->info_priv.exposure;
2783                 break;
2784             }
2785         case V4L2_CID_HFLIP:
2786             {
2787                 ctrl->value = sensor->info_priv.mirror;
2788                 break;
2789             }
2790         case V4L2_CID_VFLIP:
2791             {
2792                 ctrl->value = sensor->info_priv.flip;
2793                 break;
2794             }
2795         default :
2796                 break;
2797     }
2798     return 0;
2799 }
2800
2801
2802
2803 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2804 {
2805     struct i2c_client *client = sd->priv;
2806     struct sensor *sensor = to_sensor(client);
2807     struct soc_camera_device *icd = client->dev.platform_data;
2808     const struct v4l2_queryctrl *qctrl;
2809
2810
2811     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2812
2813     if (!qctrl)
2814     {
2815         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2816         return -EINVAL;
2817     }
2818
2819     switch (ctrl->id)
2820     {
2821 #if CONFIG_SENSOR_Brightness
2822         case V4L2_CID_BRIGHTNESS:
2823             {
2824                 if (ctrl->value != sensor->info_priv.brightness)
2825                 {
2826                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2827                     {
2828                         return -EINVAL;
2829                     }
2830                     sensor->info_priv.brightness = ctrl->value;
2831                 }
2832                 break;
2833             }
2834 #endif
2835 #if CONFIG_SENSOR_Exposure
2836         case V4L2_CID_EXPOSURE:
2837             {
2838                 if (ctrl->value != sensor->info_priv.exposure)
2839                 {
2840                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2841                     {
2842                         return -EINVAL;
2843                     }
2844                     sensor->info_priv.exposure = ctrl->value;
2845                 }
2846                 break;
2847             }
2848 #endif
2849 #if CONFIG_SENSOR_Saturation
2850         case V4L2_CID_SATURATION:
2851             {
2852                 if (ctrl->value != sensor->info_priv.saturation)
2853                 {
2854                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2855                     {
2856                         return -EINVAL;
2857                     }
2858                     sensor->info_priv.saturation = ctrl->value;
2859                 }
2860                 break;
2861             }
2862 #endif
2863 #if CONFIG_SENSOR_Contrast
2864         case V4L2_CID_CONTRAST:
2865             {
2866                 if (ctrl->value != sensor->info_priv.contrast)
2867                 {
2868                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2869                     {
2870                         return -EINVAL;
2871                     }
2872                     sensor->info_priv.contrast = ctrl->value;
2873                 }
2874                 break;
2875             }
2876 #endif
2877 #if CONFIG_SENSOR_WhiteBalance
2878         case V4L2_CID_DO_WHITE_BALANCE:
2879             {
2880                 if (ctrl->value != sensor->info_priv.whiteBalance)
2881                 {
2882                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2883                     {
2884                         return -EINVAL;
2885                     }
2886                     sensor->info_priv.whiteBalance = ctrl->value;
2887                 }
2888                 break;
2889             }
2890 #endif
2891 #if CONFIG_SENSOR_Mirror
2892         case V4L2_CID_HFLIP:
2893             {
2894                 if (ctrl->value != sensor->info_priv.mirror)
2895                 {
2896                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2897                         return -EINVAL;
2898                     sensor->info_priv.mirror = ctrl->value;
2899                 }
2900                 break;
2901             }
2902 #endif
2903 #if CONFIG_SENSOR_Flip
2904         case V4L2_CID_VFLIP:
2905             {
2906                 if (ctrl->value != sensor->info_priv.flip)
2907                 {
2908                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2909                         return -EINVAL;
2910                     sensor->info_priv.flip = ctrl->value;
2911                 }
2912                 break;
2913             }
2914 #endif
2915         default:
2916             break;
2917     }
2918
2919     return 0;
2920 }
2921 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2922 {
2923     const struct v4l2_queryctrl *qctrl;
2924     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2925     struct sensor *sensor = to_sensor(client);
2926
2927     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2928
2929     if (!qctrl)
2930     {
2931         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2932         return -EINVAL;
2933     }
2934
2935     switch (ext_ctrl->id)
2936     {
2937         case V4L2_CID_SCENE:
2938             {
2939                 ext_ctrl->value = sensor->info_priv.scene;
2940                 break;
2941             }
2942         case V4L2_CID_EFFECT:
2943             {
2944                 ext_ctrl->value = sensor->info_priv.effect;
2945                 break;
2946             }
2947         case V4L2_CID_ZOOM_ABSOLUTE:
2948             {
2949                 ext_ctrl->value = sensor->info_priv.digitalzoom;
2950                 break;
2951             }
2952         case V4L2_CID_ZOOM_RELATIVE:
2953             {
2954                 return -EINVAL;
2955             }
2956         case V4L2_CID_FOCUS_ABSOLUTE:
2957             {
2958                 return -EINVAL;
2959             }
2960         case V4L2_CID_FOCUS_RELATIVE:
2961             {
2962                 return -EINVAL;
2963             }
2964         case V4L2_CID_FLASH:
2965             {
2966                 ext_ctrl->value = sensor->info_priv.flash;
2967                 break;
2968             }
2969         default :
2970             break;
2971     }
2972     return 0;
2973 }
2974 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2975 {
2976     const struct v4l2_queryctrl *qctrl;
2977     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2978     struct sensor *sensor = to_sensor(client);
2979     int val_offset;
2980
2981     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2982
2983     if (!qctrl)
2984     {
2985         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2986         return -EINVAL;
2987     }
2988
2989         val_offset = 0;
2990     switch (ext_ctrl->id)
2991     {
2992 #if CONFIG_SENSOR_Scene
2993         case V4L2_CID_SCENE:
2994             {
2995                 if (ext_ctrl->value != sensor->info_priv.scene)
2996                 {
2997                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2998                         return -EINVAL;
2999                     sensor->info_priv.scene = ext_ctrl->value;
3000                 }
3001                 break;
3002             }
3003 #endif
3004 #if CONFIG_SENSOR_Effect
3005         case V4L2_CID_EFFECT:
3006             {
3007                 if (ext_ctrl->value != sensor->info_priv.effect)
3008                 {
3009                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3010                         return -EINVAL;
3011                     sensor->info_priv.effect= ext_ctrl->value;
3012                 }
3013                 break;
3014             }
3015 #endif
3016 #if CONFIG_SENSOR_DigitalZoom
3017         case V4L2_CID_ZOOM_ABSOLUTE:
3018             {
3019                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3020                     return -EINVAL;
3021
3022                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3023                 {
3024                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3025
3026                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3027                         return -EINVAL;
3028                     sensor->info_priv.digitalzoom += val_offset;
3029
3030                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
3031                 }
3032
3033                 break;
3034             }
3035         case V4L2_CID_ZOOM_RELATIVE:
3036             {
3037                 if (ext_ctrl->value)
3038                 {
3039                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3040                         return -EINVAL;
3041                     sensor->info_priv.digitalzoom += ext_ctrl->value;
3042
3043                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3044                 }
3045                 break;
3046             }
3047 #endif
3048 #if CONFIG_SENSOR_Focus
3049         case V4L2_CID_FOCUS_ABSOLUTE:
3050             {
3051                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3052                     return -EINVAL;
3053
3054                                 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
3055                                         if (ext_ctrl->value == qctrl->minimum) {
3056                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
3057                                         } else if (ext_ctrl->value == qctrl->maximum) {
3058                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
3059                                         } else {
3060                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
3061                                         }
3062                                 }
3063
3064                 break;
3065             }
3066         case V4L2_CID_FOCUS_RELATIVE:
3067             {
3068                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3069                     return -EINVAL;
3070
3071                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
3072                 break;
3073             }
3074                 case V4L2_CID_FOCUS_AUTO:
3075                         {
3076                                 if (ext_ctrl->value == 1) {
3077                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
3078                                                 return -EINVAL;
3079                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
3080                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
3081                                         if (ext_ctrl->value == 0)
3082                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3083                                 }
3084                                 break;
3085                         }
3086                 case V4L2_CID_FOCUS_CONTINUOUS:
3087                         {
3088                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3089                                         if (ext_ctrl->value == 1) {
3090                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3091                                                         return -EINVAL;
3092                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3093                                         }
3094                                 } else {
3095                                         if (ext_ctrl->value == 0)
3096                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3097                                 }
3098                                 break;
3099                         }
3100 #endif
3101 #if CONFIG_SENSOR_Flash
3102         case V4L2_CID_FLASH:
3103             {
3104                 sensor->info_priv.flash = ext_ctrl->value;
3105
3106                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3107                 break;
3108             }
3109 #endif
3110         default:
3111             break;
3112     }
3113
3114     return 0;
3115 }
3116
3117 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3118 {
3119     struct i2c_client *client = sd->priv;
3120     struct soc_camera_device *icd = client->dev.platform_data;
3121     int i, error_cnt=0, error_idx=-1;
3122
3123
3124     for (i=0; i<ext_ctrl->count; i++) {
3125         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3126             error_cnt++;
3127             error_idx = i;
3128         }
3129     }
3130
3131     if (error_cnt > 1)
3132         error_idx = ext_ctrl->count;
3133
3134     if (error_idx != -1) {
3135         ext_ctrl->error_idx = error_idx;
3136         return -EINVAL;
3137     } else {
3138         return 0;
3139     }
3140 }
3141
3142 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3143 {
3144     struct i2c_client *client = sd->priv;
3145     struct soc_camera_device *icd = client->dev.platform_data;
3146     int i, error_cnt=0, error_idx=-1;
3147
3148     for (i=0; i<ext_ctrl->count; i++) {
3149         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3150             error_cnt++;
3151             error_idx = i;
3152         }
3153     }
3154
3155     if (error_cnt > 1)
3156         error_idx = ext_ctrl->count;
3157
3158     if (error_idx != -1) {
3159         ext_ctrl->error_idx = error_idx;
3160         return -EINVAL;
3161     } else {
3162         return 0;
3163     }
3164 }
3165
3166 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3167  * this wasn't our capture interface, so, we wait for the right one */
3168 static int sensor_video_probe(struct soc_camera_device *icd,
3169                                struct i2c_client *client)
3170 {
3171     char value;
3172     int ret,pid = 0;
3173     struct sensor *sensor = to_sensor(client);
3174
3175     /* We must have a parent by now. And it cannot be a wrong one.
3176      * So this entire test is completely redundant. */
3177     if (!icd->dev.parent ||
3178             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3179                 return -ENODEV;
3180
3181     /* soft reset */
3182     ret = sensor_write(client, 0x3012, 0x80);
3183     if (ret != 0)
3184     {
3185         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3186         return -ENODEV;
3187     }
3188     mdelay(5);          //delay 5 microseconds
3189
3190     /* check if it is an sensor sensor */
3191     ret = sensor_read(client, 0x300a, &value);
3192     if (ret != 0) {
3193         SENSOR_TR("read chip id high byte failed\n");
3194         ret = -ENODEV;
3195         goto sensor_video_probe_err;
3196     }
3197
3198     pid |= (value << 8);
3199
3200     ret = sensor_read(client, 0x300b, &value);
3201     if (ret != 0) {
3202         SENSOR_TR("read chip id low byte failed\n");
3203         ret = -ENODEV;
3204         goto sensor_video_probe_err;
3205     }
3206
3207     pid |= (value & 0xff);
3208     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3209     if (pid == SENSOR_ID) {
3210         sensor->model = SENSOR_V4L2_IDENT;
3211     } else {
3212         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3213         ret = -ENODEV;
3214         goto sensor_video_probe_err;
3215     }
3216
3217     icd->formats = sensor_colour_formats;
3218     icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
3219
3220     return 0;
3221
3222 sensor_video_probe_err:
3223
3224     return ret;
3225 }
3226 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3227 {
3228         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3229         switch (cmd)
3230         {
3231                 case RK29_CAM_SUBDEV_DEACTIVATE:
3232                 {
3233                         sensor_deactivate(sd);
3234                         break;
3235                 }
3236                 default:
3237                         break;
3238         }
3239
3240         return 0;
3241
3242 }
3243
3244 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3245         .init           = sensor_init,
3246         .g_ctrl         = sensor_g_control,
3247         .s_ctrl         = sensor_s_control,
3248         .g_ext_ctrls          = sensor_g_ext_controls,
3249         .s_ext_ctrls          = sensor_s_ext_controls,
3250         .g_chip_ident   = sensor_g_chip_ident,
3251         .ioctl = sensor_ioctl,
3252 };
3253
3254 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3255         .s_fmt          = sensor_s_fmt,
3256         .g_fmt          = sensor_g_fmt,
3257         .try_fmt        = sensor_try_fmt,
3258 };
3259
3260 static struct v4l2_subdev_ops sensor_subdev_ops = {
3261         .core   = &sensor_subdev_core_ops,
3262         .video = &sensor_subdev_video_ops,
3263 };
3264
3265 static int sensor_probe(struct i2c_client *client,
3266                          const struct i2c_device_id *did)
3267 {
3268     struct sensor *sensor;
3269     struct soc_camera_device *icd = client->dev.platform_data;
3270     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3271     struct soc_camera_link *icl;
3272     int ret;
3273
3274     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3275     if (!icd) {
3276         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3277         return -EINVAL;
3278     }
3279
3280     icl = to_soc_camera_link(icd);
3281     if (!icl) {
3282         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3283         return -EINVAL;
3284     }
3285
3286     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3287         dev_warn(&adapter->dev,
3288                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3289         return -EIO;
3290     }
3291
3292     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3293     if (!sensor)
3294         return -ENOMEM;
3295
3296     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3297
3298     /* Second stage probe - when a capture adapter is there */
3299     icd->ops            = &sensor_ops;
3300     icd->y_skip_top             = 0;
3301
3302     ret = sensor_video_probe(icd, client);
3303     if (ret) {
3304         icd->ops = NULL;
3305         i2c_set_clientdata(client, NULL);
3306         kfree(sensor);
3307     }
3308     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3309     return ret;
3310 }
3311
3312 static int sensor_remove(struct i2c_client *client)
3313 {
3314     struct sensor *sensor = to_sensor(client);
3315     struct soc_camera_device *icd = client->dev.platform_data;
3316
3317     icd->ops = NULL;
3318     i2c_set_clientdata(client, NULL);
3319     client->driver = NULL;
3320     kfree(sensor);
3321
3322     return 0;
3323 }
3324
3325 static const struct i2c_device_id sensor_id[] = {
3326         {SENSOR_NAME_STRING(), 0 },
3327         { }
3328 };
3329 MODULE_DEVICE_TABLE(i2c, sensor_id);
3330
3331 static struct i2c_driver sensor_i2c_driver = {
3332         .driver = {
3333                 .name = SENSOR_NAME_STRING(),
3334         },
3335         .probe          = sensor_probe,
3336         .remove         = sensor_remove,
3337         .id_table       = sensor_id,
3338 };
3339
3340 static int __init sensor_mod_init(void)
3341 {
3342     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3343     return i2c_add_driver(&sensor_i2c_driver);
3344 }
3345
3346 static void __exit sensor_mod_exit(void)
3347 {
3348     i2c_del_driver(&sensor_i2c_driver);
3349 }
3350
3351 device_initcall_sync(sensor_mod_init);
3352 module_exit(sensor_mod_exit);
3353
3354 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3355 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3356 MODULE_LICENSE("GPL");
3357