camera driver v0.2.1 for RK30
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / gt2005.c
1 /*
2 o* Driver for MT9M001 CMOS Image Sensor from Micron
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/rk_camera.h>
23 #include <linux/vmalloc.h>
24 static int debug;
25 module_param(debug, int, S_IRUGO|S_IWUSR);
26
27 #define dprintk(level, fmt, arg...) do {                        \
28         if (debug >= level)                                     \
29         printk(KERN_WARNING fmt , ## arg); } while (0)
30
31 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
32 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
33
34
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
37
38 #define __STR(x) #x
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
41
42 #define MIN(x,y)   ((x<y) ? x: y)
43 #define MAX(x,y)    ((x>y) ? x: y)
44
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK_CAM_SENSOR_GT2005
47 #define SENSOR_V4L2_IDENT  V4L2_IDENT_GT2005
48 #define SENSOR_ID 0x5138
49 #define SENSOR_MIN_WIDTH    640
50 #define SENSOR_MIN_HEIGHT   480
51 #define SENSOR_MAX_WIDTH    1600
52 #define SENSOR_MAX_HEIGHT   1200
53 #define SENSOR_INIT_WIDTH       sensor_init_width                       /* Sensor pixel size for sensor_init_data array */
54 #define SENSOR_INIT_HEIGHT  sensor_init_height
55 #define SENSOR_INIT_WINSEQADR  sensor_init_winseq_p
56 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
57 #define SENSOR_BUS_PARAM  sensor_init_busparam
58
59 #define CONFIG_SENSOR_WhiteBalance      1
60 #define CONFIG_SENSOR_Brightness        0
61 #define CONFIG_SENSOR_Contrast      0
62 #define CONFIG_SENSOR_Saturation    0
63 #define CONFIG_SENSOR_Effect        1
64 #define CONFIG_SENSOR_Scene         1
65 #define CONFIG_SENSOR_DigitalZoom   0
66 #define CONFIG_SENSOR_Focus         0
67 #define CONFIG_SENSOR_Exposure      0
68 #define CONFIG_SENSOR_Flash         0
69 #define CONFIG_SENSOR_Mirror        0
70 #define CONFIG_SENSOR_Flip          0
71
72 #define CONFIG_SENSOR_I2C_SPEED     250000       /* Hz */
73 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
74 #define CONFIG_SENSOR_I2C_NOSCHED   0
75 #define CONFIG_SENSOR_I2C_RDWRCHK   0
76
77 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
78 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
79 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
80 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
81 #define COLOR_TEMPERATURE_OFFICE_DN     3500
82 #define COLOR_TEMPERATURE_OFFICE_UP     5000
83 #define COLOR_TEMPERATURE_HOME_DN       2500
84 #define COLOR_TEMPERATURE_HOME_UP       3500
85
86 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
87 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
88
89 #define SENSOR_AF_IS_ERR    (0x00<<0)
90 #define SENSOR_AF_IS_OK         (0x01<<0)
91 #define SENSOR_INIT_IS_ERR   (0x00<<28)
92 #define SENSOR_INIT_IS_OK    (0x01<<28)
93
94 struct reginfo
95 {
96     u16 reg;
97     u8 val;
98 };
99
100 static s32 sensor_init_width = 0;
101 static s32 sensor_init_height = 0;
102 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ);
103 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
104 static struct reginfo* sensor_init_data_p = NULL;
105 static struct reginfo* sensor_init_winseq_p = NULL;
106 static struct reginfo* sensor_init_winseq_board = NULL;
107 /* init 800*600 SVGA */
108 static struct reginfo sensor_init_data[] =
109 {
110     {0x0101 , 0x00},
111         {0x0103 , 0x00}, 
112         {0x0105 , 0x00},
113         {0x0106 , 0xF0},
114         {0x0107 , 0x00},
115         {0x0108 , 0x1C},
116         {0x0109 , 0x01},
117         {0x010A , 0x00},
118         {0x010B , 0x00},
119         {0x010C , 0x00},
120         {0x010D , 0x08},
121         {0x010E , 0x00},
122         {0x010F , 0x08},
123         {0x0110 , 0x06},
124         {0x0111 , 0x40},
125         {0x0112 , 0x04},
126         {0x0113 , 0xB0},
127 {0x0114 , 0x00},
128         {0x0115 , 0x00},
129         {0x0116 , 0x02},
130         {0x0117 , 0x00},
131 {0x0118 , 0x67},
132         {0x0119 , 0x02},
133         {0x011A , 0x04},
134         {0x011B , 0x01},
135 {0x011C , 0x01},
136 {0x011D , 0x02},
137 {0x011E , 0x00},
138 {0x011F , 0x00},
139 {0x0120 , 0x1C},
140 {0x0121 , 0x00},
141 {0x0122 , 0x04},
142 {0x0123 , 0x00},
143 {0x0124 , 0x00},
144 {0x0125 , 0x00},
145 {0x0126 , 0x00},
146 {0x0127 , 0x00},
147 {0x0128 , 0x00},
148 {0x0200 , 0x00},
149 {0x0201 , 0x00},
150 {0x0202 , 0x40},
151 {0x0203 , 0x00},
152 {0x0204 , 0x03},
153 {0x0205 , 0x1F},
154 {0x0206 , 0x0B},
155 {0x0207 , 0x20},
156 {0x0208 , 0x00},
157 {0x0209 , 0x2A},
158 {0x020A , 0x01},
159 {0x020B , 0x48},
160 {0x020C , 0x64},
161 {0x020D , 0xC8},
162 {0x020E , 0xBC},
163 {0x020F , 0x08},
164 {0x0210 , 0xD6},
165 {0x0211 , 0x00},
166 {0x0212 , 0x20},
167 {0x0213 , 0x81},
168 {0x0214 , 0x15},
169 {0x0215 , 0x00},
170 {0x0216 , 0x00},
171 {0x0217 , 0x00},
172 {0x0218 , 0x46},
173 {0x0219 , 0x30},
174 {0x021A , 0x03},
175 {0x021B , 0x28},
176 {0x021C , 0x02},
177 {0x021D , 0x60},
178 {0x021E , 0x00},
179 {0x021F , 0x00},
180 {0x0220 , 0x08},
181 {0x0221 , 0x08},
182 {0x0222 , 0x04},
183 {0x0223 , 0x00},
184 {0x0224 , 0x1F},
185 {0x0225 , 0x1E},
186 {0x0226 , 0x18},
187 {0x0227 , 0x1D},
188 {0x0228 , 0x1F},
189 {0x0229 , 0x1F},
190 {0x022A , 0x01},
191 {0x022B , 0x04},
192 {0x022C , 0x05},
193 {0x022D , 0x05},
194 {0x022E , 0x04},
195 {0x022F , 0x03},
196 {0x0230 , 0x02},
197 {0x0231 , 0x1F},
198 {0x0232 , 0x1A},
199 {0x0233 , 0x19},
200 {0x0234 , 0x19},
201 {0x0235 , 0x1B},
202 {0x0236 , 0x1F},
203 {0x0237 , 0x04},
204 {0x0238 , 0xEE},
205 {0x0239 , 0xFF},
206 {0x023A , 0x00},
207 {0x023B , 0x00},
208 {0x023C , 0x00},
209 {0x023D , 0x00},
210 {0x023E , 0x00},
211 {0x023F , 0x00},
212 {0x0240 , 0x00},
213 {0x0241 , 0x00},
214 {0x0242 , 0x00},
215 {0x0243 , 0x21},
216 {0x0244 , 0x42},
217 {0x0245 , 0x53},
218 {0x0246 , 0x54},
219 {0x0247 , 0x54},
220 {0x0248 , 0x54},
221 {0x0249 , 0x33},
222 {0x024A , 0x11},
223 {0x024B , 0x00},
224 {0x024C , 0x00},
225 {0x024D , 0xFF},
226 {0x024E , 0xEE},
227 {0x024F , 0xDD},
228 {0x0250 , 0x00},
229 {0x0251 , 0x00},
230 {0x0252 , 0x00},
231 {0x0253 , 0x00},
232 {0x0254 , 0x00},
233 {0x0255 , 0x00},
234 {0x0256 , 0x00},
235 {0x0257 , 0x00},
236 {0x0258 , 0x00},
237 {0x0259 , 0x00},
238 {0x025A , 0x00},
239 {0x025B , 0x00},
240 {0x025C , 0x00},
241 {0x025D , 0x00},
242 {0x025E , 0x00},
243 {0x025F , 0x00},
244 {0x0260 , 0x00},
245 {0x0261 , 0x00},
246 {0x0262 , 0x00},
247 {0x0263 , 0x00},
248 {0x0264 , 0x00},
249 {0x0265 , 0x00},
250 {0x0266 , 0x00},
251 {0x0267 , 0x00},
252 {0x0268 , 0x8F},
253 {0x0269 , 0xA3},
254 {0x026A , 0xB4},
255 {0x026B , 0x90},
256 {0x026C , 0x00},
257 {0x026D , 0xD0},
258 {0x026E , 0x60},
259 {0x026F , 0xA0},
260 {0x0270 , 0x40},
261 {0x0300 , 0x81},
262 {0x0301 , 0x80},
263 {0x0302 , 0x22},
264 {0x0303 , 0x06},
265 {0x0304 , 0x03},
266 {0x0305 , 0x83},
267 {0x0306 , 0x00},
268 {0x0307 , 0x22},
269 {0x0308 , 0x00},
270 {0x0309 , 0x55},
271 {0x030A , 0x55},
272 {0x030B , 0x55},
273 {0x030C , 0x54},
274 {0x030D , 0x1F},
275 {0x030E , 0x13},
276 {0x030F , 0x10},
277 {0x0310 , 0x04},
278 {0x0311 , 0xFF},
279 {0x0312 , 0x08},
280 {0x0313 , 0x28},
281 {0x0314 , 0x66},
282 {0x0315 , 0x16},
283 {0x0316 , 0x26},
284 {0x0317 , 0x02},
285 {0x0318 , 0x08},
286 {0x0319 , 0x0C},
287 {0x031A , 0x81},
288 {0x031B , 0x00},
289 {0x031C , 0x3D},
290 {0x031D , 0x00},
291 {0x031E , 0xF9},
292 {0x031F , 0x00},
293 {0x0320 , 0x24},
294 {0x0321 , 0x14},
295 {0x0322 , 0x1A},
296 {0x0323 , 0x24},
297 {0x0324 , 0x08},
298 {0x0325 , 0xF0},
299 {0x0326 , 0x30}, 
300 {0x0327 , 0x17},
301 {0x0328 , 0x11},
302 {0x0329 , 0x22},
303 {0x032A , 0x2F},
304 {0x032B , 0x21},
305 {0x032C , 0xDA},
306 {0x032D , 0x10},
307 {0x032E , 0xEA},
308 {0x032F , 0x18},
309 {0x0330 , 0x29},
310 {0x0331 , 0x25},
311 {0x0332 , 0x12},
312 {0x0333 , 0x0F},
313 {0x0334 , 0xE0},
314 {0x0335 , 0x13},
315 {0x0336 , 0xFF},
316 {0x0337 , 0x20},
317 {0x0338 , 0x46},
318 {0x0339 , 0x04},
319 {0x033A , 0x04},
320 {0x033B , 0xFF},
321 {0x033C , 0x01},
322 {0x033D , 0x00},
323 {0x033E , 0x03},
324 {0x033F , 0x28},
325 {0x0340 , 0x02},
326 {0x0341 , 0x60},
327 {0x0342 , 0xAC},
328 {0x0343 , 0x97},
329 {0x0344 , 0x7F},
330 {0x0400 , 0xE8},
331 {0x0401 , 0x40},
332 {0x0402 , 0x00},
333 {0x0403 , 0x00},
334 {0x0404 , 0xF8},
335 {0x0405 , 0x03},
336 {0x0406 , 0x03},
337 {0x0407 , 0x85},
338 {0x0408 , 0x44},
339 {0x0409 , 0x1F},
340 {0x040A , 0x40},
341 {0x040B , 0x33},
342 {0x040C , 0xA0},
343 {0x040D , 0x00},
344 {0x040E , 0x00},
345 {0x040F , 0x00},
346 {0x0410 , 0x0D},
347 {0x0411 , 0x0D},
348 {0x0412 , 0x0C},
349 {0x0413 , 0x04},
350 {0x0414 , 0x00},
351 {0x0415 , 0x00},
352 {0x0416 , 0x07},
353 {0x0417 , 0x09},
354 {0x0418 , 0x16},
355 {0x0419 , 0x14},
356 {0x041A , 0x11},
357 {0x041B , 0x14},
358 {0x041C , 0x07},
359 {0x041D , 0x07},
360 {0x041E , 0x06},
361 {0x041F , 0x02},
362 {0x0420 , 0x42},
363 {0x0421 , 0x42},
364 {0x0422 , 0x47},
365 {0x0423 , 0x39},
366 {0x0424 , 0x3E},
367 {0x0425 , 0x4D},
368 {0x0426 , 0x46},
369 {0x0427 , 0x3A},
370 {0x0428 , 0x21},
371 {0x0429 , 0x21},
372 {0x042A , 0x26},
373 {0x042B , 0x1C},
374 {0x042C , 0x25},
375 {0x042D , 0x25},
376 {0x042E , 0x28},
377 {0x042F , 0x20},
378 {0x0430 , 0x3E},
379 {0x0431 , 0x3E},
380 {0x0432 , 0x33},
381 {0x0433 , 0x2E},
382 {0x0434 , 0x54},
383 {0x0435 , 0x53},
384 {0x0436 , 0x3C},
385 {0x0437 , 0x51},
386 {0x0438 , 0x2B},
387 {0x0439 , 0x2B},
388 {0x043A , 0x38},
389 {0x043B , 0x22},
390 {0x043C , 0x3B},
391 {0x043D , 0x3B},
392 {0x043E , 0x31},
393 {0x043F , 0x37},
394 {0x0440 , 0x00},
395 {0x0441 , 0x4B},
396 {0x0442 , 0x00},
397 {0x0443 , 0x00},
398 {0x0444 , 0x31},
399 {0x0445 , 0x00},
400 {0x0446 , 0x00},
401 {0x0447 , 0x00},
402 {0x0448 , 0x00},
403 {0x0449 , 0x00},
404 {0x044A , 0x00},
405 {0x044D , 0xE0},
406 {0x044E , 0x05},
407 {0x044F , 0x07},
408 {0x0450 , 0x00},
409 {0x0451 , 0x00},
410 {0x0452 , 0x00},
411 {0x0453 , 0x00},
412 {0x0454 , 0x00},
413 {0x0455 , 0x00},
414 {0x0456 , 0x00},
415 {0x0457 , 0x00},
416 {0x0458 , 0x00},
417 {0x0459 , 0x00},
418 {0x045A , 0x00},
419 {0x045B , 0x00},
420 {0x045C , 0x00},
421 {0x045D , 0x00},
422 {0x045E , 0x00},
423 {0x045F , 0x00},
424 {0x0460 , 0x80},
425 {0x0461 , 0x10},
426 {0x0462 , 0x10},
427 {0x0463 , 0x10},
428 {0x0464 , 0x08},
429 {0x0465 , 0x08},
430 {0x0466 , 0x11},
431 {0x0467 , 0x09},
432 {0x0468 , 0x23},
433 {0x0469 , 0x2A},
434 {0x046A , 0x2A},
435 {0x046B , 0x47},
436 {0x046C , 0x52},
437 {0x046D , 0x42},
438 {0x046E , 0x36},
439 {0x046F , 0x46},
440 {0x0470 , 0x3A},
441 {0x0471 , 0x32},
442 {0x0472 , 0x32},
443 {0x0473 , 0x38},
444 {0x0474 , 0x3D},
445 {0x0475 , 0x2F},
446 {0x0476 , 0x29},
447 {0x0477 , 0x48},
448 {0x0600 , 0x00},
449 {0x0601 , 0x24},
450 {0x0602 , 0x45},
451 {0x0603 , 0x0E},
452 {0x0604 , 0x14},
453 {0x0605 , 0x2F},
454 {0x0606 , 0x01},
455 {0x0607 , 0x0E},
456 {0x0608 , 0x0E},
457 {0x0609 , 0x37},
458 {0x060A , 0x18},
459 {0x060B , 0xA0},
460 {0x060C , 0x20},
461 {0x060D , 0x07},
462 {0x060E , 0x47},
463 {0x060F , 0x90},
464 {0x0610 , 0x06},
465 {0x0611 , 0x0C},
466 {0x0612 , 0x28},
467 {0x0613 , 0x13},
468 {0x0614 , 0x0B},
469 {0x0615 , 0x10},
470 {0x0616 , 0x14},
471 {0x0617 , 0x19},
472 {0x0618 , 0x52},
473 {0x0619 , 0xA0},
474 {0x061A , 0x11},
475 {0x061B , 0x33},
476 {0x061C , 0x56},
477 {0x061D , 0x20},
478 {0x061E , 0x28},
479 {0x061F , 0x2B},
480 {0x0620 , 0x22},
481 {0x0621 , 0x11},
482 {0x0622 , 0x75},
483 {0x0623 , 0x49},
484 {0x0624 , 0x6E},
485 {0x0625 , 0x80},
486 {0x0626 , 0x02},
487 {0x0627 , 0x0C},
488 {0x0628 , 0x51},
489 {0x0629 , 0x25},
490 {0x062A , 0x01},
491 {0x062B , 0x3D},
492 {0x062C , 0x04},
493 {0x062D , 0x01},
494 {0x062E , 0x0C},
495 {0x062F , 0x2C},
496 {0x0630 , 0x0D},
497 {0x0631 , 0x14},
498 {0x0632 , 0x12},
499 {0x0633 , 0x34},
500 {0x0634 , 0x00},
501 {0x0635 , 0x00},
502 {0x0636 , 0x00},
503 {0x0637 , 0xB1},
504 {0x0638 , 0x22},
505 {0x0639 , 0x32},
506 {0x063A , 0x0E},
507 {0x063B , 0x18},
508 {0x063C , 0x88},
509 {0x0640 , 0xB2},
510 {0x0641 , 0xC0},
511 {0x0642 , 0x01},
512 {0x0643 , 0x26},
513 {0x0644 , 0x13},
514 {0x0645 , 0x88},
515 {0x0646 , 0x64},
516 {0x0647 , 0x00},
517 {0x0681 , 0x1B},
518 {0x0682 , 0xA0},
519 {0x0683 , 0x28},
520 {0x0684 , 0x00},
521 {0x0685 , 0xB0},
522 {0x0686 , 0x6F},
523 {0x0687 , 0x33},
524 {0x0688 , 0x1F},
525 {0x0689 , 0x44},
526 {0x068A , 0xA8},
527 {0x068B , 0x44},
528 {0x068C , 0x08},
529 {0x068D , 0x08},
530 {0x068E , 0x00},
531 {0x068F , 0x00},
532 {0x0690 , 0x01},
533 {0x0691 , 0x00},
534 {0x0692 , 0x01},
535 {0x0693 , 0x00},
536 {0x0694 , 0x00},
537 {0x0695 , 0x00},
538 {0x0696 , 0x00},
539 {0x0697 , 0x00},
540 {0x0698 , 0x2A},
541 {0x0699 , 0x80},
542 {0x069A , 0x1F},
543 {0x069B , 0x00},
544 {0x069C , 0x02},
545 {0x069D , 0xF5},
546 {0x069E , 0x03},
547 {0x069F , 0x6D},
548 {0x06A0 , 0x0C},
549 {0x06A1 , 0xB8},
550 {0x06A2 , 0x0D},
551 {0x06A3 , 0x74},
552 {0x06A4 , 0x00},
553 {0x06A5 , 0x2F},
554 {0x06A6 , 0x00},
555 {0x06A7 , 0x2F},
556 {0x0F00 , 0x00},
557 {0x0F01 , 0x00},
558 {0x0100 , 0x01},
559 {0x0102 , 0x02},
560 {0x0104 , 0x03},
561 {0x0101 , 0x02},
562
563 ///////////////////////////
564 {0x020B , 0x48},
565 {0x020C , 0x64},
566 {0x040A , 0x40},
567 {0x040B , 0x33},
568 {0x0109 , 0x00},
569 {0x010A , 0x04},
570 {0x010B , 0x03},
571 #if 0
572 {0x0110 , 0x02},
573 {0x0111 , 0x80},
574 {0x0112 , 0x01},
575 {0x0113 , 0xe0},
576 #else
577 {0x0110, 0x03},
578 {0x0111, 0x20},
579 {0x0112, 0x02},
580 {0x0113, 0x58},
581
582 #endif
583 {0x0116 , 0x02},
584 {0x0118 , 0x40},
585 {0x0119 , 0x01},
586 {0x011a , 0x04},
587 {0x011B , 0x00},
588 {0x0313 , 0x35},
589 {0x0314 , 0x36},
590 {0x0315 , 0x16},
591
592 };
593         
594
595
596 /* 1600X1200 UXGA */
597 static struct reginfo sensor_uxga[] = 
598 {
599     {0x010c , 0x00},
600         {0x010d , 0x08},
601         {0x010e , 0x00},
602         {0x010f , 0x08},
603         {0x010a , 0x00},
604         {0x0110 , 0x06},
605         {0x0111 , 0x40},
606         {0x0112 , 0x04},
607         {0x0113 , 0xb0},
608         {0x0, 0x0},
609 };
610
611         
612
613 /* 1280X1024 SXGA */
614 static struct reginfo sensor_sxga[] =
615 {
616     {0x010c , 0x00},
617         {0x010d , 0xa8},
618         {0x010e , 0x00},
619         {0x010f , 0x60},
620         {0x010a , 0x00},
621         {0x0110 , 0x05},
622         {0x0111 , 0x00},
623         {0x0112 , 0x04},
624         {0x0113 , 0x00}, 
625         {0x00, 0x00},
626 };
627
628 /* 800X600 SVGA*/
629 static struct reginfo sensor_svga[] =
630 {       
631 #if 0   
632         {0x0101, 0x00},
633         {0x0103, 0x00},
634         {0x0105, 0x00},
635         {0x0106, 0xF0},
636         {0x0107, 0x00},
637         {0x0108, 0x1C},
638         {0x0109, 0x01},
639         {0x010A, 0x00},
640         {0x010B, 0x00},
641         {0x010C, 0x00},
642         {0x010D, 0x08},
643         {0x010E, 0x00},
644         {0x010F, 0x08},
645         {0x0110, 0x06},
646         {0x0111, 0x40},
647         {0x0112, 0x04},
648         {0x0113, 0xB0},
649         {0x0114, 0x04},
650         {0x0115, 0x00},
651         {0x0116, 0x02},
652         {0x0117, 0x00},
653         {0x0118, 0x40},
654         {0x0119, 0x02},
655         {0x011A, 0x04},
656         {0x011B, 0x01},
657         {0x011C, 0x00},
658         {0x011D, 0x01},
659         {0x011E, 0x36},
660         {0x011F, 0x00},
661         {0x0120, 0x1C},
662         {0x0121, 0x00},
663         {0x0122, 0x04},
664         {0x0123, 0x00},
665         {0x0124, 0x00},
666         {0x0125, 0x00},
667         {0x0126, 0x00},
668         {0x0127, 0x00},
669         {0x0128, 0x00},
670         {0x0200, 0x1f},
671         {0x0201, 0x0c},
672         {0x0202, 0x38},
673         {0x0203, 0x00},
674         {0x0204, 0x03},
675         {0x0205, 0x1F},
676         {0x0206, 0x0B},
677         {0x0207, 0x20},
678         {0x0208, 0x00},
679         {0x0209, 0x2A},
680         {0x020A, 0x01},
681         {0x020B, 0x28},
682         {0x020C, 0x44},
683         {0x020D, 0xC8},
684         {0x020E, 0xBC},
685         {0x020F, 0x08},
686         {0x0210, 0xD6},
687         {0x0211, 0x00},
688         {0x0212, 0x20},
689         {0x0213, 0x81},
690         {0x0214, 0x15},
691         {0x0215, 0x00},
692         {0x0216, 0x00},
693         {0x0217, 0x00},
694         {0x0218, 0x46},
695         {0x0219, 0x30},
696         {0x021A, 0x03},
697         {0x021B, 0x28},
698         {0x021C, 0x02},
699         {0x021D, 0x60},
700         {0x021E, 0x00},
701         {0x021F, 0x00},
702         {0x0220, 0x08},
703         {0x0221, 0x08},
704         {0x0222, 0x04},
705         {0x0223, 0x00},
706         {0x0224, 0x1F},
707         {0x0225, 0x1E},
708         {0x0226, 0x18},
709         {0x0227, 0x1D},
710         {0x0228, 0x1F},
711         {0x0229, 0x1F},
712         {0x022A, 0x01},
713         {0x022B, 0x04},
714         {0x022C, 0x05},
715         {0x022D, 0x05},
716         {0x022E, 0x04},
717         {0x022F, 0x03},
718         {0x0230, 0x02},
719         {0x0231, 0x1F},
720         {0x0232, 0x1A},
721         {0x0233, 0x19},
722         {0x0234, 0x19},
723         {0x0235, 0x1B},
724         {0x0236, 0x1F},
725         {0x0237, 0x04},
726         {0x0238, 0xEE},
727         {0x0239, 0xFF},
728         {0x023A, 0x00},
729         {0x023B, 0x00},
730         {0x023C, 0x00},
731         {0x023D, 0x00},
732         {0x023E, 0x00},
733         {0x023F, 0x00},
734         {0x0240, 0x00},
735         {0x0241, 0x00},
736         {0x0242, 0x00},
737         {0x0243, 0x21},
738         {0x0244, 0x42},
739         {0x0245, 0x53},
740         {0x0246, 0x54},
741         {0x0247, 0x54},
742         {0x0248, 0x54},
743         {0x0249, 0x33},
744         {0x024A, 0x11},
745         {0x024B, 0x00},
746         {0x024C, 0x00},
747         {0x024D, 0xFF},
748         {0x024E, 0xEE},
749         {0x024F, 0xDD},
750         {0x0250, 0x00},
751         {0x0251, 0x00},
752         {0x0252, 0x00},
753         {0x0253, 0x00},
754         {0x0254, 0x00},
755         {0x0255, 0x00},
756         {0x0256, 0x00},
757         {0x0257, 0x00},
758         {0x0258, 0x00},
759         {0x0259, 0x00},
760         {0x025A, 0x00},
761         {0x025B, 0x00},
762         {0x025C, 0x00},
763         {0x025D, 0x00},
764         {0x025E, 0x00},
765         {0x025F, 0x00},
766         {0x0260, 0x00},
767         {0x0261, 0x00},
768         {0x0262, 0x00},
769         {0x0263, 0x00},
770         {0x0264, 0x00},
771         {0x0265, 0x00},
772         {0x0266, 0x00},
773         {0x0267, 0x00},
774         {0x0268, 0x8F},
775         {0x0269, 0xA3},
776         {0x026A, 0xB4},
777         {0x026B, 0x90},
778         {0x026C, 0x00},
779         {0x026D, 0xD0},
780         {0x026E, 0x60},
781         {0x026F, 0xA0},
782         {0x0270, 0x40},
783         {0x0300, 0x81},
784         {0x0301, 0x80},
785         {0x0302, 0x22},
786         {0x0303, 0x06},
787         {0x0304, 0x03},
788         {0x0305, 0x83},
789         {0x0306, 0x00},
790         {0x0307, 0x22},
791         {0x0308, 0x00},
792         {0x0309, 0x55},
793         {0x030A, 0x55},
794         {0x030B, 0x55},
795         {0x030C, 0x54},
796         {0x030D, 0x1F},
797         {0x030E, 0x0A},
798         {0x030F, 0x10},
799         {0x0310, 0x04},
800         {0x0311, 0xFF},
801         {0x0312, 0x08},
802         {0x0313, 0x35},
803         {0x0314, 0x36},
804         {0x0315, 0x15},
805         {0x0316, 0x26},
806         {0x0317, 0x02},
807         {0x0318, 0x08},
808         {0x0319, 0x0C},
809         {0x031A, 0x81},
810         {0x031B, 0x00},
811         {0x031C, 0x3D},
812         {0x031D, 0x00},
813         {0x031E, 0xF9},
814         {0x031F, 0x00},
815         {0x0320, 0x24},
816         {0x0321, 0x14},
817         {0x0322, 0x1A},
818         {0x0323, 0x24},
819         {0x0324, 0x08},
820         {0x0325, 0xF0},
821         {0x0326, 0x30},
822         {0x0327, 0x17},
823         {0x0328, 0x11},
824         {0x0329, 0x22},
825         {0x032A, 0x2F},
826         {0x032B, 0x21},
827         {0x032C, 0xDA},
828         {0x032D, 0x10},
829         {0x032E, 0xEA},
830         {0x032F, 0x18},
831         {0x0330, 0x29},
832         {0x0331, 0x25},
833         {0x0332, 0x12},
834         {0x0333, 0x0F},
835         {0x0334, 0xE0},
836         {0x0335, 0x13},
837         {0x0336, 0xFF},
838         {0x0337, 0x20},
839         {0x0338, 0x46},
840         {0x0339, 0x04},
841         {0x033A, 0x04},
842         {0x033B, 0xFF},
843         {0x033C, 0x01},
844         {0x033D, 0x00},
845         {0x033E, 0x03},
846         {0x033F, 0x28},
847         {0x0340, 0x02},
848         {0x0341, 0x60},
849         {0x0342, 0xAC},
850         {0x0343, 0x97},
851         {0x0344, 0x7F},
852         {0x0400, 0xE8},
853         {0x0401, 0x40},
854         {0x0402, 0x00},
855         {0x0403, 0x00},
856         {0x0404, 0xF8},
857         {0x0405, 0x03},
858         {0x0406, 0x03},
859         {0x0407, 0x85},
860         {0x0408, 0x44},
861         {0x0409, 0x1F},
862         {0x040A, 0x40},
863         {0x040B, 0x33},
864         {0x040C, 0xA0},
865         {0x040D, 0x00},
866         {0x040E, 0x00},
867         {0x040F, 0x00},
868         {0x0410, 0x0D},
869         {0x0411, 0x0D},
870         {0x0412, 0x0C},
871         {0x0413, 0x04},
872         {0x0414, 0x00},
873         {0x0415, 0x00},
874         {0x0416, 0x07},
875         {0x0417, 0x09},
876         {0x0418, 0x16},
877         {0x0419, 0x14},
878         {0x041A, 0x11},
879         {0x041B, 0x14},
880         {0x041C, 0x07},
881         {0x041D, 0x07},
882         {0x041E, 0x06},
883         {0x041F, 0x02},
884         {0x0420, 0x42},
885         {0x0421, 0x42},
886         {0x0422, 0x47},
887         {0x0423, 0x39},
888         {0x0424, 0x3E},
889         {0x0425, 0x4D},
890         {0x0426, 0x46},
891         {0x0427, 0x3A},
892         {0x0428, 0x21},
893         {0x0429, 0x21},
894         {0x042A, 0x26},
895         {0x042B, 0x1C},
896         {0x042C, 0x25},
897         {0x042D, 0x25},
898         {0x042E, 0x28},
899         {0x042F, 0x20},
900         {0x0430, 0x3E},
901         {0x0431, 0x3E},
902         {0x0432, 0x33},
903         {0x0433, 0x2E},
904         {0x0434, 0x54},
905         {0x0435, 0x53},
906         {0x0436, 0x3C},
907         {0x0437, 0x51},
908         {0x0438, 0x2B},
909         {0x0439, 0x2B},
910         {0x043A, 0x38},
911         {0x043B, 0x22},
912         {0x043C, 0x3B},
913         {0x043D, 0x3B},
914         {0x043E, 0x31},
915         {0x043F, 0x37},
916         {0x0440, 0x00},
917         {0x0441, 0x4B},
918         {0x0442, 0x00},
919         {0x0443, 0x00},
920         {0x0444, 0x31},
921         {0x0445, 0x00},
922         {0x0446, 0x00},
923         {0x0447, 0x00},
924         {0x0448, 0x00},
925         {0x0449, 0x00},
926         {0x044A, 0x00},
927         {0x044D, 0xE0},
928         {0x044E, 0x05},
929         {0x044F, 0x07},
930         {0x0450, 0x00},
931         {0x0451, 0x00},
932         {0x0452, 0x00},
933         {0x0453, 0x00},
934         {0x0454, 0x00},
935         {0x0455, 0x00},
936         {0x0456, 0x00},
937         {0x0457, 0x00},
938         {0x0458, 0x00},
939         {0x0459, 0x00},
940         {0x045A, 0x00},
941         {0x045B, 0x00},
942         {0x045C, 0x00},
943         {0x045D, 0x00},
944         {0x045E, 0x00},
945         {0x045F, 0x00},
946         {0x0460, 0x80},
947         {0x0461, 0x10},
948         {0x0462, 0x10},
949         {0x0463, 0x10},
950         {0x0464, 0x08},
951         {0x0465, 0x08},
952         {0x0466, 0x11},
953         {0x0467, 0x09},
954         {0x0468, 0x23},
955         {0x0469, 0x2A},
956         {0x046A, 0x2A},
957         {0x046B, 0x47},
958         {0x046C, 0x52},
959         {0x046D, 0x42},
960         {0x046E, 0x36},
961         {0x046F, 0x46},
962         {0x0470, 0x3A},
963         {0x0471, 0x32},
964         {0x0472, 0x32},
965         {0x0473, 0x38},
966         {0x0474, 0x3D},
967         {0x0475, 0x2F},
968         {0x0476, 0x29},
969         {0x0477, 0x48},
970         {0x0600, 0x00},
971         {0x0601, 0x24},
972         {0x0602, 0x45},
973         {0x0603, 0x0E},
974         {0x0604, 0x14},
975         {0x0605, 0x2F},
976         {0x0606, 0x01},
977         {0x0607, 0x0E},
978         {0x0608, 0x0E},
979         {0x0609, 0x37},
980         {0x060A, 0x18},
981         {0x060B, 0xA0},
982         {0x060C, 0x20},
983         {0x060D, 0x07},
984         {0x060E, 0x47},
985         {0x060F, 0x90},
986         {0x0610, 0x06},
987         {0x0611, 0x0C},
988         {0x0612, 0x28},
989         {0x0613, 0x13},
990         {0x0614, 0x0B},
991         {0x0615, 0x10},
992         {0x0616, 0x14},
993         {0x0617, 0x19},
994         {0x0618, 0x52},
995         {0x0619, 0xA0},
996         {0x061A, 0x11},
997         {0x061B, 0x33},
998         {0x061C, 0x56},
999         {0x061D, 0x20},
1000         {0x061E, 0x28},
1001         {0x061F, 0x2B},
1002         {0x0620, 0x22},
1003         {0x0621, 0x11},
1004         {0x0622, 0x75},
1005         {0x0623, 0x49},
1006         {0x0624, 0x6E},
1007         {0x0625, 0x80},
1008         {0x0626, 0x02},
1009         {0x0627, 0x0C},
1010         {0x0628, 0x51},
1011         {0x0629, 0x25},
1012         {0x062A, 0x01},
1013         {0x062B, 0x3D},
1014         {0x062C, 0x04},
1015         {0x062D, 0x01},
1016         {0x062E, 0x0C},
1017         {0x062F, 0x2C},
1018         {0x0630, 0x0D},
1019         {0x0631, 0x14},
1020         {0x0632, 0x12},
1021         {0x0633, 0x34},
1022         {0x0634, 0x00},
1023         {0x0635, 0x00},
1024         {0x0636, 0x00},
1025         {0x0637, 0xB1},
1026         {0x0638, 0x22},
1027         {0x0639, 0x32},
1028         {0x063A, 0x0E},
1029         {0x063B, 0x18},
1030         {0x063C, 0x88},
1031         {0x0640, 0xB2},
1032         {0x0641, 0xC0},
1033         {0x0642, 0x01},
1034         {0x0643, 0x26},
1035         {0x0644, 0x13},
1036         {0x0645, 0x88},
1037         {0x0646, 0x64},
1038         {0x0647, 0x00},
1039         {0x0681, 0x1B},
1040         {0x0682, 0xA0},
1041         {0x0683, 0x28},
1042         {0x0684, 0x00},
1043         {0x0685, 0xB0},
1044         {0x0686, 0x6F},
1045         {0x0687, 0x33},
1046         {0x0688, 0x1F},
1047         {0x0689, 0x44},
1048         {0x068A, 0xA8},
1049         {0x068B, 0x44},
1050         {0x068C, 0x08},
1051         {0x068D, 0x08},
1052         {0x068E, 0x00},
1053         {0x068F, 0x00},
1054         {0x0690, 0x01},
1055         {0x0691, 0x00},
1056         {0x0692, 0x01},
1057         {0x0693, 0x00},
1058         {0x0694, 0x00},
1059         {0x0695, 0x00},
1060         {0x0696, 0x00},
1061         {0x0697, 0x00},
1062         {0x0698, 0x2A},
1063         {0x0699, 0x80},
1064         {0x069A, 0x1F},
1065         {0x069B, 0x00},
1066         {0x069C, 0x02},
1067         {0x069D, 0xF5},
1068         {0x069E, 0x03},
1069         {0x069F, 0x6D},
1070         {0x06A0, 0x0C},
1071         {0x06A1, 0xB8},
1072         {0x06A2, 0x0D},
1073         {0x06A3, 0x74},
1074         {0x06A4, 0x00},
1075         {0x06A5, 0x2F},
1076         {0x06A6, 0x00},
1077         {0x06A7, 0x2F},
1078         {0x0F00, 0x00},
1079         {0x0F01, 0x00},
1080         {0x0100, 0x01},
1081         {0x0102, 0x02},
1082         {0x0104, 0x03},
1083 #endif
1084         {0x020B, 0x48},
1085         {0x020C, 0x64},
1086         {0x040A, 0x40},
1087         {0x040B, 0x33},
1088         {0x010c , 0x00},
1089         {0x010d , 0x08},
1090         {0x010e , 0x00},
1091         {0x010f , 0x08},
1092         {0x010a , 0x00},
1093         {0x0109, 0x00},
1094         {0x010A, 0x04},
1095         {0x010B, 0x03},
1096         {0x0110, 0x03},
1097         {0x0111, 0x20},
1098         {0x0112, 0x02},
1099         {0x0113, 0x58},
1100         {0x0116, 0x02},
1101         {0x0118, 0x40},
1102         {0x0119, 0x02},
1103         {0x011a, 0x04},
1104         {0x011B, 0x01},
1105         {0x0, 0x0},
1106 };
1107         
1108         
1109
1110 /* 640X480 VGA */
1111 static struct reginfo sensor_vga[] =
1112 {
1113    {0x020B , 0x48},
1114    {0x020C , 0x64},
1115    {0x040A , 0x40},
1116    {0x040B , 0x33},
1117    {0x0109 , 0x00},
1118    {0x010A , 0x04},
1119    {0x010B , 0x03},
1120    {0x010c , 0x00},
1121    {0x010d , 0xa8},
1122    {0x010e , 0x00},
1123    {0x010f , 0x60},
1124    {0x010a , 0x04},
1125    #if 1
1126    {0x0110 , 0x02},
1127    {0x0111 , 0x80},
1128    {0x0112 , 0x01},
1129    {0x0113 , 0xe0},
1130    #else
1131    {0x0110, 0x03},
1132    {0x0111, 0x20},
1133    {0x0112, 0x02},
1134    {0x0113, 0x58},
1135    #endif
1136    {0x0116 , 0x02},
1137    {0x0118 , 0x40},
1138    {0x0119 , 0x01},
1139    {0x011a , 0x04},
1140    {0x011B , 0x00},
1141    {0x0313 , 0x35},
1142    {0x0314 , 0x36},
1143    {0x0315 , 0x16}, 
1144    {0x0, 0x0},
1145 };
1146
1147 /* 352X288 CIF */
1148 static struct reginfo sensor_cif[] =
1149 {
1150     {0x0, 0x0},
1151 };
1152
1153 /* 320*240 QVGA */
1154 static  struct reginfo sensor_qvga[] =
1155 {
1156     
1157
1158     {0x0, 0x0},
1159 };
1160
1161 /* 176X144 QCIF*/
1162 static struct reginfo sensor_qcif[] =
1163 {
1164         
1165     {0x0, 0x0},
1166 };
1167 #if 0
1168 /* 160X120 QQVGA*/
1169 static struct reginfo gt2005_qqvga[] =
1170 {
1171
1172     {0x300E, 0x34},
1173     {0x3011, 0x01},
1174     {0x3012, 0x10},
1175     {0x302a, 0x02},
1176     {0x302b, 0xE6},
1177     {0x306f, 0x14},
1178     {0x3362, 0x90},
1179
1180     {0x3070, 0x5d},
1181     {0x3072, 0x5d},
1182     {0x301c, 0x07},
1183     {0x301d, 0x07},
1184
1185     {0x3020, 0x01},
1186     {0x3021, 0x18},
1187     {0x3022, 0x00},
1188     {0x3023, 0x06},
1189     {0x3024, 0x06},
1190     {0x3025, 0x58},
1191     {0x3026, 0x02},
1192     {0x3027, 0x61},
1193     {0x3088, 0x00},
1194     {0x3089, 0xa0},
1195     {0x308a, 0x00},
1196     {0x308b, 0x78},
1197     {0x3316, 0x64},
1198     {0x3317, 0x25},
1199     {0x3318, 0x80},
1200     {0x3319, 0x08},
1201     {0x331a, 0x0a},
1202     {0x331b, 0x07},
1203     {0x331c, 0x80},
1204     {0x331d, 0x38},
1205     {0x3100, 0x00},
1206     {0x3302, 0x11},
1207
1208     {0x0, 0x0},
1209 };
1210
1211
1212
1213 static  struct reginfo gt2005_Sharpness_auto[] =
1214 {
1215     {0x3306, 0x00},
1216 };
1217
1218 static  struct reginfo gt2005_Sharpness1[] =
1219 {
1220     {0x3306, 0x08},
1221     {0x3371, 0x00},
1222 };
1223
1224 static  struct reginfo gt2005_Sharpness2[][3] =
1225 {
1226     //Sharpness 2
1227     {0x3306, 0x08},
1228     {0x3371, 0x01},
1229 };
1230
1231 static  struct reginfo gt2005_Sharpness3[] =
1232 {
1233     //default
1234     {0x3306, 0x08},
1235     {0x332d, 0x02},
1236 };
1237 static  struct reginfo gt2005_Sharpness4[]=
1238 {
1239     //Sharpness 4
1240     {0x3306, 0x08},
1241     {0x332d, 0x03},
1242 };
1243
1244 static  struct reginfo gt2005_Sharpness5[] =
1245 {
1246     //Sharpness 5
1247     {0x3306, 0x08},
1248     {0x332d, 0x04},
1249 };
1250 #endif
1251
1252 static  struct reginfo sensor_ClrFmt_YUYV[]=
1253 {
1254     //{0x3400, 0x00},
1255     {0x0000, 0x00}
1256 };
1257
1258 static  struct reginfo sensor_ClrFmt_UYVY[]=
1259 {
1260     //{0x3400, 0x02},
1261     {0x0000, 0x00}
1262 };
1263
1264 #if CONFIG_SENSOR_WhiteBalance
1265 static  struct reginfo sensor_WhiteB_Auto[]=
1266 {
1267     {0x3306, 0x00},  //AWB auto, bit[1]:0,auto
1268     {0x0000, 0x00}
1269 };
1270 /* Cloudy Colour Temperature : 6500K - 8000K  */
1271 static  struct reginfo sensor_WhiteB_Cloudy[]=
1272 {
1273     {0x3306, 0x82},
1274     {0x3337, 0x68},
1275     {0x3338, 0x40},
1276     {0x3339, 0x4e},
1277     {0x0000, 0x00}
1278 };
1279 /* ClearDay Colour Temperature : 5000K - 6500K  */
1280 static  struct reginfo sensor_WhiteB_ClearDay[]=
1281 {
1282     //Sunny
1283     {0x3306, 0x02}, //AWB off
1284     {0x3337, 0x5e},
1285     {0x3338, 0x40},
1286     {0x3339, 0x46},
1287     {0x0000, 0x00}
1288 };
1289 /* Office Colour Temperature : 3500K - 5000K  */
1290 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
1291 {
1292     //Office
1293     {0x3306, 0x02},
1294     {0x3337, 0x52},
1295     {0x3338, 0x40},
1296     {0x3339, 0x58},
1297     {0x0000, 0x00}
1298
1299 };
1300 /* Home Colour Temperature : 2500K - 3500K  */
1301 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
1302 {
1303     //Home
1304     {0x3306, 0x02},
1305     {0x3337, 0x44},
1306     {0x3338, 0x40},
1307     {0x3339, 0x70},
1308     {0x0000, 0x00}
1309 };
1310 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1311     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1312 };
1313 #endif
1314
1315 #if CONFIG_SENSOR_Brightness
1316 static  struct reginfo sensor_Brightness0[]=
1317 {
1318     // Brightness -2
1319     {0x3301, 0xff},//bit[7]:1, enable SDE
1320     {0x3391, 0x04},
1321     {0x3390, 0x49},
1322     {0x339a, 0x20},
1323     {0x0000, 0x00}
1324 };
1325
1326 static  struct reginfo sensor_Brightness1[]=
1327 {
1328     // Brightness -1
1329     {0x3301, 0xff},//bit[7]:1, enable SDE
1330     {0x3391, 0x04},
1331     {0x3390, 0x49},
1332     {0x339a, 0x10},
1333     {0x0000, 0x00}
1334 };
1335
1336 static  struct reginfo sensor_Brightness2[]=
1337 {
1338     //  Brightness 0
1339     {0x3301, 0xff},//bit[7]:1, enable SDE
1340     {0x3391, 0x00},
1341     {0x3390, 0x41},
1342     {0x339a, 0x00},
1343     {0x0000, 0x00}
1344 };
1345
1346 static  struct reginfo sensor_Brightness3[]=
1347 {
1348     // Brightness +1
1349     {0x3301, 0xff},//bit[7]:1, enable SDE
1350     {0x3391, 0x04},
1351     {0x3390, 0x41},
1352     {0x339a, 0x10},
1353     {0x0000, 0x00}
1354 };
1355
1356 static  struct reginfo sensor_Brightness4[]=
1357 {
1358     //  Brightness +2
1359     {0x3301, 0xff},//bit[7]:1, enable SDE
1360     {0x3391, 0x04},
1361     {0x3390, 0x41},
1362     {0x339a, 0x20},
1363     {0x0000, 0x00}
1364 };
1365
1366 static  struct reginfo sensor_Brightness5[]=
1367 {
1368     //  Brightness +3
1369     {0x3301, 0xff},//bit[7]:1, enable SDE
1370     {0x3391, 0x04}, //bit[2] enable
1371     {0x3390, 0x41}, //bit[3] sign of brightness
1372     {0x339a, 0x30},
1373     {0x0000, 0x00}
1374 };
1375 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1376     sensor_Brightness4, sensor_Brightness5,NULL,
1377 };
1378
1379 #endif
1380
1381 #if CONFIG_SENSOR_Effect
1382 static  struct reginfo sensor_Effect_Normal[] =
1383 {
1384     {0x3391, 0x00},
1385     {0x0000, 0x00}
1386 };
1387
1388 static  struct reginfo sensor_Effect_WandB[] =
1389 {
1390     {0x3391, 0x20},
1391     {0x0000, 0x00}
1392 };
1393
1394 static  struct reginfo sensor_Effect_Sepia[] =
1395 {
1396     {0x3391, 0x18},
1397     {0x3396, 0x40},
1398     {0x3397, 0xa6},
1399     {0x0000, 0x00}
1400 };
1401
1402 static  struct reginfo sensor_Effect_Negative[] =
1403 {
1404     //Negative
1405     {0x3391, 0x40}, //bit[6] negative
1406     {0x0000, 0x00}
1407 };
1408 static  struct reginfo sensor_Effect_Bluish[] =
1409 {
1410     // Bluish
1411     {0x3391, 0x18},
1412     {0x3396, 0xa0},
1413     {0x3397, 0x40},
1414     {0x0000, 0x00}
1415 };
1416
1417 static  struct reginfo sensor_Effect_Green[] =
1418 {
1419     //  Greenish
1420     {0x3391, 0x18},
1421     {0x3396, 0x60},
1422     {0x3397, 0x60},
1423     {0x0000, 0x00}
1424 };
1425 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1426     sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1427 };
1428 #endif
1429 #if CONFIG_SENSOR_Exposure
1430 static  struct reginfo sensor_Exposure0[]=
1431 {
1432     //-3
1433     {0x3047, 0x05},
1434     {0x3018, 0x40},
1435     {0x3019, 0x30},
1436     {0x301a, 0x71},
1437     {0x0000, 0x00}
1438 };
1439
1440 static  struct reginfo sensor_Exposure1[]=
1441 {
1442     //-2
1443     {0x3047, 0x05},
1444     {0x3018, 0x5a},
1445     {0x3019, 0x4a},
1446     {0x301a, 0xc2},
1447     {0x0000, 0x00}
1448 };
1449
1450 static  struct reginfo sensor_Exposure2[]=
1451 {
1452     //-0.3EV
1453     {0x3047, 0x05},
1454     {0x3018, 0x6a},
1455     {0x3019, 0x5a},
1456     {0x301a, 0xd4},
1457     {0x0000, 0x00}
1458 };
1459
1460 static  struct reginfo sensor_Exposure3[]=
1461 {
1462     //default
1463     {0x3047, 0x05},
1464     {0x3018, 0x78},
1465     {0x3019, 0x68},
1466     {0x301a, 0xd4},
1467     {0x0000, 0x00}
1468 };
1469
1470 static  struct reginfo sensor_Exposure4[]=
1471 {
1472     // 1
1473     {0x3047, 0x05},
1474     {0x3018, 0x88},
1475     {0x3019, 0x78},
1476     {0x301a, 0xd5},
1477     {0x0000, 0x00}
1478 };
1479
1480 static  struct reginfo sensor_Exposure5[]=
1481 {
1482     // 2
1483     {0x3047, 0x05},
1484     {0x3018, 0xa8},
1485     {0x3019, 0x98},
1486     {0x301a, 0xe6},
1487     {0x0000, 0x00}
1488 };
1489
1490 static  struct reginfo sensor_Exposure6[]=
1491 {
1492     // 3
1493     {0x3047, 0x05},
1494     {0x3018, 0xc8},
1495     {0x3019, 0xb8},
1496     {0x301a, 0xf7},
1497     {0x0000, 0x00}
1498 };
1499
1500 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1501     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1502 };
1503 #endif
1504 #if CONFIG_SENSOR_Saturation
1505 static  struct reginfo sensor_Saturation0[]=
1506 {
1507     {0x3301, 0xff},//bit[7]:1, enable SDE
1508     {0x3391, 0x02},
1509     {0x3394, 0x40},
1510     {0x3395, 0x40},
1511     {0x0000, 0x00}
1512 };
1513
1514 static  struct reginfo sensor_Saturation1[]=
1515 {
1516     {0x3301, 0xff},//bit[7]:1, enable SDE
1517     {0x3391, 0x02},
1518     {0x3394, 0x50},
1519     {0x3395, 0x50},
1520     {0x0000, 0x00}
1521 };
1522
1523 static  struct reginfo sensor_Saturation2[]=
1524 {
1525     {0x3301, 0xff},//bit[7]:1, enable SDE
1526     {0x3391, 0x02}, //enable color saturation
1527     {0x3394, 0x70},
1528     {0x3395, 0x70},
1529     {0x0000, 0x00}
1530 };
1531 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1532
1533 #endif
1534 #if CONFIG_SENSOR_Contrast
1535 static  struct reginfo sensor_Contrast0[]=
1536 {
1537     //Contrast -3
1538     {0x3301, 0xff},//bit[7]:1, enable SDE
1539     {0x3391, 0x04},
1540     {0x3390, 0x45},
1541     {0x3398, 0x18},
1542     {0x3399, 0x18},
1543     {0x0000, 0x00}
1544 };
1545
1546 static  struct reginfo sensor_Contrast1[]=
1547 {
1548     //Contrast -2
1549     {0x3301, 0xff},//bit[7]:1, enable SDE
1550     {0x3391, 0x04},
1551     {0x3390, 0x45},
1552     {0x3398, 0x18},
1553     {0x3399, 0x18},
1554     {0x0000, 0x00}
1555 };
1556
1557 static  struct reginfo sensor_Contrast2[]=
1558 {
1559     // Contrast -1
1560     {0x3301, 0xff},//bit[7]:1, enable SDE
1561     {0x3391, 0x04},
1562     {0x3390, 0x45},
1563     {0x3398, 0x1c},
1564     {0x3399, 0x1c},
1565     {0x0000, 0x00}
1566 };
1567
1568 static  struct reginfo sensor_Contrast3[]=
1569 {
1570     //Contrast 0
1571     {0x3301, 0xff},//bit[7]:1, enable SDE
1572     {0x3391, 0x00},
1573     {0x3390, 0x41},
1574     {0x3398, 0x20},
1575     {0x3399, 0x20},
1576     {0x0000, 0x00}
1577 };
1578
1579 static  struct reginfo sensor_Contrast4[]=
1580 {
1581     //Contrast +1
1582     {0x3301, 0xff},//bit[7]:1, enable SDE
1583     {0x3391, 0x04},
1584     {0x3390, 0x45},
1585     {0x3398, 0x24},
1586     {0x3399, 0x24},
1587     {0x0000, 0x00}
1588 };
1589
1590
1591 static  struct reginfo sensor_Contrast5[]=
1592 {
1593     //Contrast +2
1594     {0x3301, 0xff},//bit[7]:1, enable SDE
1595     {0x3391, 0x04},
1596     {0x3390, 0x45},
1597     {0x3398, 0x28},
1598     {0x3399, 0x28},
1599     {0x0000, 0x00}
1600 };
1601
1602 static  struct reginfo sensor_Contrast6[]=
1603 {
1604     //Contrast +3
1605     {0x3301, 0xff},//bit[7]:1, enable SDE
1606     {0x3391, 0x04}, //bit[2] enable contrast/brightness
1607     {0x3390, 0x45}, //bit[2] Yoffset sign
1608     {0x3398, 0x2c},
1609     {0x3399, 0x2c},
1610     {0x0000, 0x00}
1611 };
1612 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1613     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1614 };
1615
1616 #endif
1617 #if CONFIG_SENSOR_Mirror
1618 static  struct reginfo sensor_MirrorOn[]=
1619 {
1620     {0x3069, 0x84},
1621     {0x307c, 0x13},
1622     {0x3087, 0x02},
1623     {0x0000, 0x00}
1624 };
1625
1626 static  struct reginfo sensor_MirrorOff[]=
1627 {
1628     {0x3069, 0x84},
1629     {0x307c, 0x10},
1630     {0x3087, 0x02},
1631     {0x0000, 0x00}
1632 };
1633 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1634 #endif
1635 #if CONFIG_SENSOR_Flip
1636 static  struct reginfo sensor_FlipOn[]=
1637 {
1638     {0x300e, 0x34},
1639     {0x300f, 0xa6},
1640     {0x3010, 0x81},
1641     {0x3082, 0x01},
1642     {0x30f4, 0x01},
1643     {0x3090, 0x3b},
1644     {0x3091, 0xc0},
1645     {0x30ac, 0x42},
1646     {0x0000, 0x00}
1647 };
1648
1649 static  struct reginfo sensor_FlipOff[]=
1650 {
1651     {0x300e, 0x34},
1652     {0x300f, 0xa6},
1653     {0x3010, 0x81},
1654     {0x3082, 0x01},
1655     {0x30f4, 0x01},
1656     {0x3090, 0x33},
1657     {0x3091, 0xc0},
1658     {0x30ac, 0x42},
1659     {0x0000, 0x00}
1660 };
1661 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1662
1663 #endif
1664 #if CONFIG_SENSOR_Scene
1665 static  struct reginfo sensor_SceneAuto[] =
1666 {
1667 #if 0                           /* ddl@rock-chips.com : */
1668     {0x3014, 0x04},
1669     {0x3015, 0x00},
1670     {0x302e, 0x00},
1671     {0x302d, 0x00},
1672     {0x0000, 0x00}
1673 #else
1674     {0x3014, 0x84},
1675     {0x3015, 0x02},
1676     {0x302e, 0x00},
1677     {0x302d, 0x00},
1678     {0x0000, 0x00}
1679 #endif
1680 };
1681
1682 static  struct reginfo sensor_SceneNight[] =
1683 {
1684 #if 1
1685     //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1686     {0x300e, 0x34},
1687     {0x3011, 0x00},
1688     {0x302c, 0x00},
1689     {0x3071, 0x00},
1690     {0x3070, 0xb9},
1691     {0x301c, 0x02},
1692     {0x3073, 0x00},
1693     {0x3072, 0x9a},
1694     {0x301d, 0x03},
1695     {0x3014, 0x0c},
1696     {0x3015, 0x50},//add 5 dummy frame
1697     {0x302e, 0x00},
1698     {0x302d, 0x00},
1699     {0x0000, 0x00}
1700 #else
1701     //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1702     {0x300e, 0x34},
1703     {0x3011, 0x01},
1704     {0x302c, 0x00},
1705     {0x3071, 0x00},
1706     {0x3070, 0x5d},
1707     {0x301c, 0x05},
1708     {0x3073, 0x00},
1709     {0x3072, 0x4d},
1710     {0x301d, 0x07},
1711     {0x3014, 0x0c},
1712     {0x3015, 0x50},
1713     {0x302e, 0x00},
1714     {0x302d, 0x00},
1715 #endif
1716 };
1717 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1718
1719 #endif
1720 #if CONFIG_SENSOR_DigitalZoom
1721 static struct reginfo sensor_Zoom0[] =
1722 {
1723     {0x0, 0x0},
1724 };
1725
1726 static struct reginfo sensor_Zoom1[] =
1727 {
1728      {0x0, 0x0},
1729 };
1730
1731 static struct reginfo sensor_Zoom2[] =
1732 {
1733     {0x0, 0x0},
1734 };
1735
1736
1737 static struct reginfo sensor_Zoom3[] =
1738 {
1739     {0x0, 0x0},
1740 };
1741 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1742 #endif
1743 static const struct v4l2_querymenu sensor_menus[] =
1744 {
1745         #if CONFIG_SENSOR_WhiteBalance
1746     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
1747     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
1748     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
1749     #endif
1750
1751         #if CONFIG_SENSOR_Effect
1752     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
1753     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
1754     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},
1755     #endif
1756
1757         #if CONFIG_SENSOR_Scene
1758     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
1759     #endif
1760
1761         #if CONFIG_SENSOR_Flash
1762     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
1763     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
1764     #endif
1765 };
1766
1767 static const struct v4l2_queryctrl sensor_controls[] =
1768 {
1769         #if CONFIG_SENSOR_WhiteBalance
1770     {
1771         .id             = V4L2_CID_DO_WHITE_BALANCE,
1772         .type           = V4L2_CTRL_TYPE_MENU,
1773         .name           = "White Balance Control",
1774         .minimum        = 0,
1775         .maximum        = 4,
1776         .step           = 1,
1777         .default_value = 0,
1778     },
1779     #endif
1780
1781         #if CONFIG_SENSOR_Brightness
1782         {
1783         .id             = V4L2_CID_BRIGHTNESS,
1784         .type           = V4L2_CTRL_TYPE_INTEGER,
1785         .name           = "Brightness Control",
1786         .minimum        = -3,
1787         .maximum        = 2,
1788         .step           = 1,
1789         .default_value = 0,
1790     },
1791     #endif
1792
1793         #if CONFIG_SENSOR_Effect
1794         {
1795         .id             = V4L2_CID_EFFECT,
1796         .type           = V4L2_CTRL_TYPE_MENU,
1797         .name           = "Effect Control",
1798         .minimum        = 0,
1799         .maximum        = 5,
1800         .step           = 1,
1801         .default_value = 0,
1802     },
1803         #endif
1804
1805         #if CONFIG_SENSOR_Exposure
1806         {
1807         .id             = V4L2_CID_EXPOSURE,
1808         .type           = V4L2_CTRL_TYPE_INTEGER,
1809         .name           = "Exposure Control",
1810         .minimum        = 0,
1811         .maximum        = 6,
1812         .step           = 1,
1813         .default_value = 0,
1814     },
1815         #endif
1816
1817         #if CONFIG_SENSOR_Saturation
1818         {
1819         .id             = V4L2_CID_SATURATION,
1820         .type           = V4L2_CTRL_TYPE_INTEGER,
1821         .name           = "Saturation Control",
1822         .minimum        = 0,
1823         .maximum        = 2,
1824         .step           = 1,
1825         .default_value = 0,
1826     },
1827     #endif
1828
1829         #if CONFIG_SENSOR_Contrast
1830         {
1831         .id             = V4L2_CID_CONTRAST,
1832         .type           = V4L2_CTRL_TYPE_INTEGER,
1833         .name           = "Contrast Control",
1834         .minimum        = -3,
1835         .maximum        = 3,
1836         .step           = 1,
1837         .default_value = 0,
1838     },
1839         #endif
1840
1841         #if CONFIG_SENSOR_Mirror
1842         {
1843         .id             = V4L2_CID_HFLIP,
1844         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1845         .name           = "Mirror Control",
1846         .minimum        = 0,
1847         .maximum        = 1,
1848         .step           = 1,
1849         .default_value = 1,
1850     },
1851     #endif
1852
1853         #if CONFIG_SENSOR_Flip
1854         {
1855         .id             = V4L2_CID_VFLIP,
1856         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1857         .name           = "Flip Control",
1858         .minimum        = 0,
1859         .maximum        = 1,
1860         .step           = 1,
1861         .default_value = 1,
1862     },
1863     #endif
1864
1865         #if CONFIG_SENSOR_Scene
1866     {
1867         .id             = V4L2_CID_SCENE,
1868         .type           = V4L2_CTRL_TYPE_MENU,
1869         .name           = "Scene Control",
1870         .minimum        = 0,
1871         .maximum        = 1,
1872         .step           = 1,
1873         .default_value = 0,
1874     },
1875     #endif
1876
1877         #if CONFIG_SENSOR_DigitalZoom
1878     {
1879         .id             = V4L2_CID_ZOOM_RELATIVE,
1880         .type           = V4L2_CTRL_TYPE_INTEGER,
1881         .name           = "DigitalZoom Control",
1882         .minimum        = -1,
1883         .maximum        = 1,
1884         .step           = 1,
1885         .default_value = 0,
1886     }, {
1887         .id             = V4L2_CID_ZOOM_ABSOLUTE,
1888         .type           = V4L2_CTRL_TYPE_INTEGER,
1889         .name           = "DigitalZoom Control",
1890         .minimum        = 0,
1891         .maximum        = 3,
1892         .step           = 1,
1893         .default_value = 0,
1894     },
1895     #endif
1896
1897         #if CONFIG_SENSOR_Focus
1898         {
1899         .id             = V4L2_CID_FOCUS_RELATIVE,
1900         .type           = V4L2_CTRL_TYPE_INTEGER,
1901         .name           = "Focus Control",
1902         .minimum        = -1,
1903         .maximum        = 1,
1904         .step           = 1,
1905         .default_value = 0,
1906     }, {
1907         .id             = V4L2_CID_FOCUS_ABSOLUTE,
1908         .type           = V4L2_CTRL_TYPE_INTEGER,
1909         .name           = "Focus Control",
1910         .minimum        = 0,
1911         .maximum        = 255,
1912         .step           = 1,
1913         .default_value = 125,
1914     },
1915     #endif
1916
1917         #if CONFIG_SENSOR_Flash
1918         {
1919         .id             = V4L2_CID_FLASH,
1920         .type           = V4L2_CTRL_TYPE_MENU,
1921         .name           = "Flash Control",
1922         .minimum        = 0,
1923         .maximum        = 3,
1924         .step           = 1,
1925         .default_value = 0,
1926     },
1927         #endif
1928 };
1929
1930 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1931 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1932 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1933 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1934 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1935 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1936 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1937 static int sensor_resume(struct soc_camera_device *icd);
1938 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1939 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1940 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1941 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1942 static int sensor_deactivate(struct i2c_client *client);
1943
1944 static struct soc_camera_ops sensor_ops =
1945 {
1946     .suspend                     = sensor_suspend,
1947     .resume                       = sensor_resume,
1948     .set_bus_param              = sensor_set_bus_param,
1949     .query_bus_param    = sensor_query_bus_param,
1950     .controls           = sensor_controls,
1951     .menus                         = sensor_menus,
1952     .num_controls               = ARRAY_SIZE(sensor_controls),
1953     .num_menus          = ARRAY_SIZE(sensor_menus),
1954 };
1955
1956 /* only one fixed colorspace per pixelcode */
1957 struct sensor_datafmt {
1958         enum v4l2_mbus_pixelcode code;
1959         enum v4l2_colorspace colorspace;
1960 };
1961
1962 /* Find a data format by a pixel code in an array */
1963 static const struct sensor_datafmt *sensor_find_datafmt(
1964         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1965         int n)
1966 {
1967         int i;
1968         for (i = 0; i < n; i++)
1969                 if (fmt[i].code == code)
1970                         return fmt + i;
1971
1972         return NULL;
1973 }
1974
1975 static const struct sensor_datafmt sensor_colour_fmts[] = {
1976     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1977     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
1978 };
1979
1980 typedef struct sensor_info_priv_s
1981 {
1982     int whiteBalance;
1983     int brightness;
1984     int contrast;
1985     int saturation;
1986     int effect;
1987     int scene;
1988     int digitalzoom;
1989     int focus;
1990     int flash;
1991     int exposure;
1992         bool snap2preview;
1993         bool video2preview;
1994     unsigned char mirror;                                        /* HFLIP */
1995     unsigned char flip;                                          /* VFLIP */
1996     unsigned int winseqe_cur_addr;
1997     struct sensor_datafmt fmt;
1998     unsigned int funmodule_state;
1999 } sensor_info_priv_t;
2000
2001 struct sensor
2002 {
2003     struct v4l2_subdev subdev;
2004     struct i2c_client *client;
2005     sensor_info_priv_t info_priv;
2006     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2007 #if CONFIG_SENSOR_I2C_NOSCHED
2008         atomic_t tasklock_cnt;
2009 #endif
2010         struct rkcamera_platform_data *sensor_io_request;
2011     struct rkcamera_gpio_res *sensor_gpio_res;
2012 };
2013
2014 static struct sensor* to_sensor(const struct i2c_client *client)
2015 {
2016     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2017 }
2018
2019 static int sensor_task_lock(struct i2c_client *client, int lock)
2020 {
2021 #if CONFIG_SENSOR_I2C_NOSCHED
2022         int cnt = 3;
2023     struct sensor *sensor = to_sensor(client);
2024
2025         if (lock) {
2026                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2027                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2028                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2029                                 msleep(35);
2030                                 cnt--;
2031                         }
2032                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2033                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2034                                 goto sensor_task_lock_err;
2035                         }
2036                         preempt_disable();
2037                 }
2038
2039                 atomic_add(1, &sensor->tasklock_cnt);
2040         } else {
2041                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2042                         atomic_sub(1, &sensor->tasklock_cnt);
2043
2044                         if (atomic_read(&sensor->tasklock_cnt) == 0)
2045                                 preempt_enable();
2046                 }
2047         }
2048         return 0;
2049 sensor_task_lock_err:
2050         return -1; 
2051 #else
2052     return 0;
2053 #endif
2054
2055 }
2056
2057 /* sensor register write */
2058 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2059 {
2060     int err,cnt;
2061     u8 buf[3];
2062     struct i2c_msg msg[1];
2063
2064     buf[0] = reg >> 8;
2065     buf[1] = reg & 0xFF;
2066     buf[2] = val;
2067
2068     msg->addr = client->addr;
2069     msg->flags = client->flags;
2070     msg->buf = buf;
2071     msg->len = sizeof(buf);
2072     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
2073     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2074
2075     cnt = 3;
2076     err = -EAGAIN;
2077
2078     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2079         err = i2c_transfer(client->adapter, msg, 1);
2080
2081         if (err >= 0) {
2082             return 0;
2083         } else {
2084                 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2085             udelay(10);
2086         }
2087     }
2088
2089     return err;
2090 }
2091
2092 /* sensor register read */
2093 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2094 {
2095     int err,cnt;
2096     u8 buf[2];
2097     struct i2c_msg msg[2];
2098
2099     buf[0] = reg >> 8;
2100     buf[1] = reg & 0xFF;
2101
2102     msg[0].addr = client->addr;
2103     msg[0].flags = client->flags;
2104     msg[0].buf = buf;
2105     msg[0].len = sizeof(buf);
2106     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
2107     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2108
2109     msg[1].addr = client->addr;
2110     msg[1].flags = client->flags|I2C_M_RD;
2111     msg[1].buf = buf;
2112     msg[1].len = 1;
2113     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
2114     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2115
2116     cnt = 3;
2117     err = -EAGAIN;
2118     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2119         err = i2c_transfer(client->adapter, msg, 2);
2120
2121         if (err >= 0) {
2122             *val = buf[0];
2123             return 0;
2124         } else {
2125                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2126             udelay(10);
2127         }
2128     }
2129
2130     return err;
2131 }
2132
2133 /* write a array of registers  */
2134 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2135 {
2136     int err = 0, cnt;
2137     int i = 0;
2138 #if CONFIG_SENSOR_I2C_RDWRCHK    
2139         char valchk;
2140 #endif
2141
2142         cnt = 0;
2143         if (sensor_task_lock(client, 1) < 0)
2144                 goto sensor_write_array_end;
2145
2146     while (regarray[i].reg != 0)
2147     {
2148         err = sensor_write(client, regarray[i].reg, regarray[i].val);
2149         if (err < 0)
2150         {
2151             if (cnt-- > 0) {
2152                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2153                                 i = 0;
2154                                 continue;
2155             } else {
2156                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2157                 err = -EPERM;
2158                                 goto sensor_write_array_end;
2159             }
2160         } else {
2161         #if CONFIG_SENSOR_I2C_RDWRCHK
2162                         sensor_read(client, regarray[i].reg, &valchk);
2163                         if (valchk != regarray[i].val)
2164                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2165                 #endif
2166         }
2167         i++;
2168     }
2169
2170 sensor_write_array_end:
2171         sensor_task_lock(client,0);
2172         return err;
2173 }
2174
2175 #if CONFIG_SENSOR_I2C_RDWRCHK
2176 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
2177 {
2178   int ret;
2179   int i = 0,j=0;  
2180   u8 value;
2181   
2182   SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
2183   while(regarray[i].reg != 0)
2184   {
2185      ret = sensor_read(client,regarray[i].reg,&value);
2186          if(ret !=0)
2187          {
2188           SENSOR_TR("read value failed\n");
2189
2190          }
2191          if(regarray[i].val != value)
2192          {
2193           SENSOR_DG("%s reg[0x%x] check err,writte :0x%x  read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
2194          }
2195          else
2196           j++;
2197          
2198          i++;
2199   }
2200   if(i==j)
2201          SENSOR_DG("%s check success\n",__FUNCTION__);
2202         
2203   return 0;
2204 }
2205 #endif
2206 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
2207 {
2208         struct soc_camera_link *icl = to_soc_camera_link(icd);
2209         int ret = 0;
2210
2211     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2212         switch (cmd)
2213         {
2214                 case Sensor_PowerDown:
2215                 {
2216                         if (icl->powerdown) {
2217                                 ret = icl->powerdown(icd->pdev, on);
2218                                 if (ret == RK_CAM_IO_SUCCESS) {
2219                                         if (on == 0) {
2220                                                 mdelay(2);
2221                                                 if (icl->reset)
2222                                                         icl->reset(icd->pdev);
2223                                         }
2224                                 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
2225                                         ret = -ENODEV;
2226                                         goto sensor_power_end;
2227                                 }
2228                         }
2229                         break;
2230                 }
2231                 case Sensor_Flash:
2232                 {
2233                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2234                 struct sensor *sensor = to_sensor(client);
2235
2236                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2237                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2238                         }
2239             break;
2240                 }
2241                 default:
2242                 {
2243                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2244                         break;
2245                 }
2246         }
2247 sensor_power_end:
2248         return ret;
2249 }
2250
2251 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2252 {
2253     struct i2c_client *client = v4l2_get_subdevdata(sd);
2254     struct soc_camera_device *icd = client->dev.platform_data;
2255     struct sensor *sensor = to_sensor(client);
2256         const struct v4l2_queryctrl *qctrl;
2257     const struct sensor_datafmt *fmt;
2258     char value;
2259     int ret,pid = 0,i = 0,j=0;
2260     struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
2261     sensor_init_data_p = sensor_init_data;
2262         sensor_init_winseq_p = sensor_svga;
2263         sensor_init_width = 640;
2264         sensor_init_height = 480;
2265         if (tmp_plat_data != NULL) { 
2266                 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
2267                         if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
2268                                 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
2269                                         break;
2270                         }
2271                 }
2272         if(tmp_plat_data  && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
2273         //user has defined the init data
2274                 //init reg
2275                 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
2276                         for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
2277                                 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
2278                                 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
2279                                 }
2280                         sensor_init_data_p = sensor_init_data;
2281                         }
2282                 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
2283                         sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
2284                         }
2285                 //init winseq
2286                 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
2287                         int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
2288                         if(sensor_init_winseq_board)
2289                                 {
2290                                 vfree(sensor_init_winseq_board);
2291                                 sensor_init_winseq_board = NULL;
2292                                 }
2293                         sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
2294                         if(!sensor_init_winseq_board)
2295                                 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
2296                         for(j = 0;j< tmp_winseq_size;j++){
2297                                 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
2298                                 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
2299                                 }
2300                         sensor_init_winseq_p = sensor_init_winseq_board;
2301                         }
2302                 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
2303                         sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
2304                         }
2305                 //init width,height,bus,pixelcode
2306                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
2307                         sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
2308                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
2309                         sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
2310                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
2311                         sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
2312                 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
2313                         sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
2314         }
2315     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2316
2317         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2318                 ret = -ENODEV;
2319                 goto sensor_INIT_ERR;
2320         }
2321
2322     /* soft reset */
2323         if (sensor_task_lock(client,1)<0)
2324                 goto sensor_INIT_ERR;
2325    /* ret = sensor_write(client, 0x3012, 0x80);
2326     if (ret != 0)
2327     {
2328         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2329         ret = -ENODEV;
2330                 goto sensor_INIT_ERR;
2331     }
2332
2333     mdelay(5); */ //delay 5 microseconds
2334         /* check if it is an sensor sensor */
2335     ret = sensor_read(client, 0x0000, &value);
2336     if (ret != 0) {
2337         SENSOR_TR("read chip id high byte failed\n");
2338         ret = -ENODEV;
2339         goto sensor_INIT_ERR;
2340     }
2341
2342     pid |= (value << 8);
2343
2344     ret = sensor_read(client, 0x0001, &value);
2345     if (ret != 0) {
2346         SENSOR_TR("read chip id low byte failed\n");
2347         ret = -ENODEV;
2348         goto sensor_INIT_ERR;
2349     }
2350
2351     pid |= (value & 0xff);
2352     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2353     if (pid == SENSOR_ID) {
2354         sensor->model = SENSOR_V4L2_IDENT;
2355     } else {
2356         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2357         ret = -ENODEV;
2358         goto sensor_INIT_ERR;
2359     }
2360
2361     ret = sensor_write_array(client, sensor_init_data_p);
2362     if (ret != 0)
2363     {
2364         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2365         goto sensor_INIT_ERR;
2366     }
2367         sensor_task_lock(client,0);
2368     
2369     sensor->info_priv.winseqe_cur_addr  = (int)SENSOR_INIT_WINSEQADR;
2370     fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2371     if (!fmt) {
2372         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2373         ret = -EINVAL;
2374         goto sensor_INIT_ERR;
2375     }
2376         sensor->info_priv.fmt = *fmt;
2377
2378     /* sensor sensor information for initialization  */
2379         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2380         if (qctrl)
2381         sensor->info_priv.whiteBalance = qctrl->default_value;
2382         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
2383         if (qctrl)
2384         sensor->info_priv.brightness = qctrl->default_value;
2385         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2386         if (qctrl)
2387         sensor->info_priv.effect = qctrl->default_value;
2388         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
2389         if (qctrl)
2390         sensor->info_priv.exposure = qctrl->default_value;
2391
2392         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
2393         if (qctrl)
2394         sensor->info_priv.saturation = qctrl->default_value;
2395         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
2396         if (qctrl)
2397         sensor->info_priv.contrast = qctrl->default_value;
2398         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
2399         if (qctrl)
2400         sensor->info_priv.mirror = qctrl->default_value;
2401         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
2402         if (qctrl)
2403         sensor->info_priv.flip = qctrl->default_value;
2404         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
2405         if (qctrl)
2406         sensor->info_priv.scene = qctrl->default_value;
2407         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2408         if (qctrl)
2409         sensor->info_priv.digitalzoom = qctrl->default_value;
2410
2411     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
2412         #if CONFIG_SENSOR_Focus
2413     sensor_set_focus();
2414     qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2415         if (qctrl)
2416         sensor->info_priv.focus = qctrl->default_value;
2417         #endif
2418
2419         #if CONFIG_SENSOR_Flash 
2420         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
2421         if (qctrl)
2422         sensor->info_priv.flash = qctrl->default_value;
2423     #endif
2424
2425     SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),((val == 0)?__FUNCTION__:"sensor_reinit"),icd->user_width,icd->user_height);
2426     sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
2427     return 0;
2428 sensor_INIT_ERR:
2429     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2430         sensor_task_lock(client,0);
2431         sensor_deactivate(client);
2432     return ret;
2433 }
2434
2435 static int sensor_deactivate(struct i2c_client *client)
2436 {
2437         struct soc_camera_device *icd = client->dev.platform_data;
2438
2439     struct sensor *sensor = to_sensor(client);
2440         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
2441
2442         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
2443     if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
2444     sensor_write(client, 0x30b0, 0x00);
2445         sensor_write(client, 0x30b1, 0x00);
2446     }
2447         sensor_ioctrl(icd, Sensor_PowerDown, 1);
2448     msleep(100); 
2449
2450         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
2451         icd->user_width = SENSOR_INIT_WIDTH;
2452     icd->user_height = SENSOR_INIT_HEIGHT;
2453     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
2454         
2455         return 0;
2456 }
2457
2458 static  struct reginfo sensor_power_down_sequence[]=
2459 {
2460     {0x30ab, 0x00},
2461     {0x30ad, 0x0a},
2462     {0x30ae,0x27},
2463     {0x363b,0x01},
2464     {0x00,0x00}
2465 };
2466 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
2467 {
2468     int ret;
2469     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2470
2471     if (pm_msg.event == PM_EVENT_SUSPEND) {
2472         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
2473         ret = sensor_write_array(client, sensor_power_down_sequence) ;
2474         if (ret != 0) {
2475             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
2476             return ret;
2477         } else {
2478             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
2479             if (ret < 0) {
2480                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
2481                 return -EINVAL;
2482             }
2483         }
2484     } else {
2485         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2486         return -EINVAL;
2487     }
2488     return 0;
2489 }
2490
2491 static int sensor_resume(struct soc_camera_device *icd)
2492 {
2493         int ret;
2494
2495     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2496     if (ret < 0) {
2497                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2498         return -EINVAL;
2499     }
2500
2501         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2502
2503     return 0;
2504
2505 }
2506
2507 static int sensor_set_bus_param(struct soc_camera_device *icd,
2508                                 unsigned long flags)
2509 {
2510
2511     return 0;
2512 }
2513
2514 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2515 {
2516     struct soc_camera_link *icl = to_soc_camera_link(icd);
2517     unsigned long flags = SENSOR_BUS_PARAM;
2518
2519     return soc_camera_apply_sensor_flags(icl, flags);
2520 }
2521
2522 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2523 {
2524     struct i2c_client *client = v4l2_get_subdevdata(sd);
2525     struct soc_camera_device *icd = client->dev.platform_data;
2526     struct sensor *sensor = to_sensor(client);
2527
2528     mf->width   = icd->user_width;
2529         mf->height      = icd->user_height;
2530         mf->code        = sensor->info_priv.fmt.code;
2531         mf->colorspace  = sensor->info_priv.fmt.colorspace;
2532         mf->field       = V4L2_FIELD_NONE;
2533
2534     return 0;
2535 }
2536 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2537 {
2538     bool ret = false;
2539
2540         if ((mf->width == 1024) && (mf->height == 768)) {
2541                 ret = true;
2542         } else if ((mf->width == 1280) && (mf->height == 1024)) {
2543                 ret = true;
2544         } else if ((mf->width == 1600) && (mf->height == 1200)) {
2545                 ret = true;
2546         } else if ((mf->width == 2048) && (mf->height == 1536)) {
2547                 ret = true;
2548         } else if ((mf->width == 2592) && (mf->height == 1944)) {
2549                 ret = true;
2550         }
2551
2552         if (ret == true)
2553                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2554         return ret;
2555 }
2556
2557 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2558 {
2559     bool ret = false;
2560
2561         if ((mf->width == 1280) && (mf->height == 720)) {
2562                 ret = true;
2563         } else if ((mf->width == 1920) && (mf->height == 1080)) {
2564                 ret = true;
2565         }
2566
2567         if (ret == true)
2568                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2569         return ret;
2570 }
2571 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2572 {
2573     struct i2c_client *client = v4l2_get_subdevdata(sd);
2574     const struct sensor_datafmt *fmt;
2575     struct sensor *sensor = to_sensor(client);
2576         const struct v4l2_queryctrl *qctrl;
2577         struct soc_camera_device *icd = client->dev.platform_data;
2578     struct reginfo *winseqe_set_addr=NULL;
2579     int ret=0, set_w,set_h;
2580
2581         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2582                                    ARRAY_SIZE(sensor_colour_fmts));
2583         if (!fmt) {
2584         ret = -EINVAL;
2585         goto sensor_s_fmt_end;
2586     }
2587
2588         if (sensor->info_priv.fmt.code != mf->code) {
2589                 switch (mf->code)
2590                 {
2591                         case V4L2_MBUS_FMT_YUYV8_2X8:
2592                         {
2593                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
2594                                 break;
2595                         }
2596                         case V4L2_MBUS_FMT_UYVY8_2X8:
2597                         {
2598                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
2599                                 break;
2600                         }
2601                         default:
2602                                 break;
2603                 }
2604                 if (winseqe_set_addr != NULL) {
2605             sensor_write_array(client, winseqe_set_addr);
2606                         sensor->info_priv.fmt.code = mf->code;
2607             sensor->info_priv.fmt.colorspace= mf->colorspace;            
2608                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2609                 } else {
2610                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2611                 }
2612         }
2613
2614     set_w = mf->width;
2615     set_h = mf->height;
2616
2617         if (((set_w <= 176) && (set_h <= 144)) && sensor_qcif[0].reg)
2618         {
2619                 winseqe_set_addr = sensor_qcif;
2620         set_w = 176;
2621         set_h = 144;
2622         }
2623         else if (((set_w <= 320) && (set_h <= 240)) && sensor_qvga[0].reg)
2624     {
2625         winseqe_set_addr = sensor_qvga;
2626         set_w = 320;
2627         set_h = 240;
2628     }
2629     else if (((set_w <= 352) && (set_h<= 288)) && sensor_cif[0].reg)
2630     {
2631         winseqe_set_addr = sensor_cif;
2632         set_w = 352;
2633         set_h = 288;
2634     }
2635     else if (((set_w <= 640) && (set_h <= 480)) && sensor_vga[0].reg)
2636     {
2637         winseqe_set_addr = sensor_vga;
2638         set_w = 640;
2639         set_h = 480;
2640     }
2641     else if (((set_w <= 800) && (set_h <= 600)) && sensor_svga[0].reg)
2642     {
2643         winseqe_set_addr = sensor_svga;
2644         set_w = 800;
2645         set_h = 600;
2646     }
2647     else if (((set_w <= 1280) && (set_h <= 1024)) && sensor_sxga[0].reg)
2648     {
2649         winseqe_set_addr = sensor_sxga;
2650         set_w = 1280;
2651         set_h = 1024;
2652     }
2653     else if (((set_w <= 1600) && (set_h <= 1200)) && sensor_uxga[0].reg)
2654     {
2655         winseqe_set_addr = sensor_uxga;
2656         set_w = 1600;
2657         set_h = 1200;
2658     }
2659     else
2660     {
2661         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */
2662         set_w = SENSOR_INIT_WIDTH;
2663         set_h = SENSOR_INIT_HEIGHT;
2664                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2665     }
2666
2667     if ((int)winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) {
2668         #if CONFIG_SENSOR_Flash
2669         if (sensor_fmt_capturechk(sd,mf) == true) {      /* ddl@rock-chips.com : Capture */
2670             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2671                 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
2672                 SENSOR_DG("%s flash on in capture!\n", SENSOR_NAME_STRING());
2673             }           
2674         } else {                                        /* ddl@rock-chips.com : Video */
2675             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2676                 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2677                 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
2678             }
2679         }
2680         #endif
2681         ret |= sensor_write_array(client, winseqe_set_addr);
2682         if (ret != 0) {
2683             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2684             #if CONFIG_SENSOR_Flash
2685             if (sensor_fmt_capturechk(sd,mf) == true) {
2686                 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
2687                     sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2688                     SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
2689                 }
2690             }
2691             #endif
2692             goto sensor_s_fmt_end;
2693         }
2694
2695         sensor->info_priv.winseqe_cur_addr  = (int)winseqe_set_addr;
2696
2697                 if (sensor_fmt_capturechk(sd,mf) == true) {                                 /* ddl@rock-chips.com : Capture */
2698                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2699                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2700                         if (sensor->info_priv.whiteBalance != 0) {
2701                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2702                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2703                         }
2704                         sensor->info_priv.snap2preview = true;
2705                 } else if (sensor_fmt_videochk(sd,mf) == true) {                        /* ddl@rock-chips.com : Video */
2706                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2707                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2708                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2709                         sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2710                         sensor->info_priv.video2preview = true;
2711                 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
2712                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
2713                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
2714                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
2715                         sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
2716             msleep(600);
2717                         sensor->info_priv.video2preview = false;
2718                         sensor->info_priv.snap2preview = false;
2719                 }
2720
2721         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2722     }
2723     else
2724     {
2725         SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
2726     }
2727
2728         mf->width = set_w;
2729     mf->height = set_h;
2730
2731 sensor_s_fmt_end:
2732     return ret;
2733 }
2734
2735 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2736 {
2737     struct i2c_client *client = v4l2_get_subdevdata(sd);
2738     struct sensor *sensor = to_sensor(client);
2739     const struct sensor_datafmt *fmt;
2740     int ret = 0;
2741    
2742         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2743                                    ARRAY_SIZE(sensor_colour_fmts));
2744         if (fmt == NULL) {
2745                 fmt = &sensor->info_priv.fmt;
2746         mf->code = fmt->code;
2747         } 
2748
2749     if (mf->height > SENSOR_MAX_HEIGHT)
2750         mf->height = SENSOR_MAX_HEIGHT;
2751     else if (mf->height < SENSOR_MIN_HEIGHT)
2752         mf->height = SENSOR_MIN_HEIGHT;
2753
2754     if (mf->width > SENSOR_MAX_WIDTH)
2755         mf->width = SENSOR_MAX_WIDTH;
2756     else if (mf->width < SENSOR_MIN_WIDTH)
2757         mf->width = SENSOR_MIN_WIDTH;
2758
2759     mf->colorspace = fmt->colorspace;
2760     
2761     return ret;
2762 }
2763
2764  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2765 {
2766     struct i2c_client *client = v4l2_get_subdevdata(sd);
2767
2768     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2769         return -EINVAL;
2770
2771     if (id->match.addr != client->addr)
2772         return -ENODEV;
2773
2774     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return gt2005  identifier */
2775     id->revision = 0;
2776
2777     return 0;
2778 }
2779 #if CONFIG_SENSOR_Brightness
2780 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2781 {
2782     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2783
2784     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2785     {
2786         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2787         {
2788             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2789             {
2790                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2791                 return -EINVAL;
2792             }
2793             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2794             return 0;
2795         }
2796     }
2797         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2798     return -EINVAL;
2799 }
2800 #endif
2801 #if CONFIG_SENSOR_Effect
2802 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2803 {
2804     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2805
2806     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2807     {
2808         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2809         {
2810             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2811             {
2812                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2813                 return -EINVAL;
2814             }
2815             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2816             return 0;
2817         }
2818     }
2819         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2820     return -EINVAL;
2821 }
2822 #endif
2823 #if CONFIG_SENSOR_Exposure
2824 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2825 {
2826     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2827
2828     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2829     {
2830         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2831         {
2832             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2833             {
2834                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2835                 return -EINVAL;
2836             }
2837             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2838             return 0;
2839         }
2840     }
2841         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2842     return -EINVAL;
2843 }
2844 #endif
2845 #if CONFIG_SENSOR_Saturation
2846 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2847 {
2848     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2849
2850     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2851     {
2852         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2853         {
2854             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2855             {
2856                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2857                 return -EINVAL;
2858             }
2859             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2860             return 0;
2861         }
2862     }
2863     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2864     return -EINVAL;
2865 }
2866 #endif
2867 #if CONFIG_SENSOR_Contrast
2868 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2869 {
2870     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2871
2872     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2873     {
2874         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2875         {
2876             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2877             {
2878                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2879                 return -EINVAL;
2880             }
2881             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2882             return 0;
2883         }
2884     }
2885     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2886     return -EINVAL;
2887 }
2888 #endif
2889 #if CONFIG_SENSOR_Mirror
2890 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2891 {
2892     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2893
2894     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2895     {
2896         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2897         {
2898             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2899             {
2900                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2901                 return -EINVAL;
2902             }
2903             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2904             return 0;
2905         }
2906     }
2907     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2908     return -EINVAL;
2909 }
2910 #endif
2911 #if CONFIG_SENSOR_Flip
2912 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2913 {
2914     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2915
2916     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2917     {
2918         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2919         {
2920             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2921             {
2922                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2923                 return -EINVAL;
2924             }
2925             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2926             return 0;
2927         }
2928     }
2929     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2930     return -EINVAL;
2931 }
2932 #endif
2933 #if CONFIG_SENSOR_Scene
2934 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2935 {
2936     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2937
2938     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2939     {
2940         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2941         {
2942             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2943             {
2944                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2945                 return -EINVAL;
2946             }
2947             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2948             return 0;
2949         }
2950     }
2951     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2952     return -EINVAL;
2953 }
2954 #endif
2955 #if CONFIG_SENSOR_WhiteBalance
2956 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2957 {
2958     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2959
2960     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2961     {
2962         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2963         {
2964             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2965             {
2966                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2967                 return -EINVAL;
2968             }
2969             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2970             return 0;
2971         }
2972     }
2973         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2974     return -EINVAL;
2975 }
2976 #endif
2977 #if CONFIG_SENSOR_DigitalZoom
2978 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2979 {
2980     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2981     struct sensor *sensor = to_sensor(client);
2982         const struct v4l2_queryctrl *qctrl_info;
2983     int digitalzoom_cur, digitalzoom_total;
2984
2985         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2986         if (qctrl_info)
2987                 return -EINVAL;
2988
2989     digitalzoom_cur = sensor->info_priv.digitalzoom;
2990     digitalzoom_total = qctrl_info->maximum;
2991
2992     if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
2993     {
2994         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2995         return -EINVAL;
2996     }
2997
2998     if  ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2999     {
3000         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3001         return -EINVAL;
3002     }
3003
3004     if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
3005     {
3006         value = digitalzoom_total - digitalzoom_cur;
3007     }
3008
3009     if ((value < 0) && ((digitalzoom_cur + value) < 0))
3010     {
3011         value = 0 - digitalzoom_cur;
3012     }
3013
3014     digitalzoom_cur += value;
3015
3016     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
3017     {
3018         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
3019         {
3020             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3021             return -EINVAL;
3022         }
3023         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3024         return 0;
3025     }
3026
3027     return -EINVAL;
3028 }
3029 #endif
3030 #if CONFIG_SENSOR_Flash
3031 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3032 {    
3033     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
3034         if (value == 3) {       /* ddl@rock-chips.com: torch */
3035             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
3036         } else {
3037             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3038         }
3039         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3040         return 0;
3041     }
3042     
3043         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3044     return -EINVAL;
3045 }
3046 #endif
3047
3048 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3049 {
3050     struct i2c_client *client = v4l2_get_subdevdata(sd);
3051     struct sensor *sensor = to_sensor(client);
3052     const struct v4l2_queryctrl *qctrl;
3053
3054     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3055
3056     if (!qctrl)
3057     {
3058         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3059         return -EINVAL;
3060     }
3061
3062     switch (ctrl->id)
3063     {
3064         case V4L2_CID_BRIGHTNESS:
3065             {
3066                 ctrl->value = sensor->info_priv.brightness;
3067                 break;
3068             }
3069         case V4L2_CID_SATURATION:
3070             {
3071                 ctrl->value = sensor->info_priv.saturation;
3072                 break;
3073             }
3074         case V4L2_CID_CONTRAST:
3075             {
3076                 ctrl->value = sensor->info_priv.contrast;
3077                 break;
3078             }
3079         case V4L2_CID_DO_WHITE_BALANCE:
3080             {
3081                 ctrl->value = sensor->info_priv.whiteBalance;
3082                 break;
3083             }
3084         case V4L2_CID_EXPOSURE:
3085             {
3086                 ctrl->value = sensor->info_priv.exposure;
3087                 break;
3088             }
3089         case V4L2_CID_HFLIP:
3090             {
3091                 ctrl->value = sensor->info_priv.mirror;
3092                 break;
3093             }
3094         case V4L2_CID_VFLIP:
3095             {
3096                 ctrl->value = sensor->info_priv.flip;
3097                 break;
3098             }
3099         default :
3100                 break;
3101     }
3102     return 0;
3103 }
3104
3105
3106
3107 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
3108 {
3109     struct i2c_client *client = v4l2_get_subdevdata(sd);
3110     struct sensor *sensor = to_sensor(client);
3111     struct soc_camera_device *icd = client->dev.platform_data;
3112     const struct v4l2_queryctrl *qctrl;
3113
3114
3115     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
3116
3117     if (!qctrl)
3118     {
3119         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
3120         return -EINVAL;
3121     }
3122
3123     switch (ctrl->id)
3124     {
3125 #if CONFIG_SENSOR_Brightness
3126         case V4L2_CID_BRIGHTNESS:
3127             {
3128                 if (ctrl->value != sensor->info_priv.brightness)
3129                 {
3130                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
3131                     {
3132                         return -EINVAL;
3133                     }
3134                     sensor->info_priv.brightness = ctrl->value;
3135                 }
3136                 break;
3137             }
3138 #endif
3139 #if CONFIG_SENSOR_Exposure
3140         case V4L2_CID_EXPOSURE:
3141             {
3142                 if (ctrl->value != sensor->info_priv.exposure)
3143                 {
3144                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
3145                     {
3146                         return -EINVAL;
3147                     }
3148                     sensor->info_priv.exposure = ctrl->value;
3149                 }
3150                 break;
3151             }
3152 #endif
3153 #if CONFIG_SENSOR_Saturation
3154         case V4L2_CID_SATURATION:
3155             {
3156                 if (ctrl->value != sensor->info_priv.saturation)
3157                 {
3158                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
3159                     {
3160                         return -EINVAL;
3161                     }
3162                     sensor->info_priv.saturation = ctrl->value;
3163                 }
3164                 break;
3165             }
3166 #endif
3167 #if CONFIG_SENSOR_Contrast
3168         case V4L2_CID_CONTRAST:
3169             {
3170                 if (ctrl->value != sensor->info_priv.contrast)
3171                 {
3172                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
3173                     {
3174                         return -EINVAL;
3175                     }
3176                     sensor->info_priv.contrast = ctrl->value;
3177                 }
3178                 break;
3179             }
3180 #endif
3181 #if CONFIG_SENSOR_WhiteBalance
3182         case V4L2_CID_DO_WHITE_BALANCE:
3183             {
3184                 if (ctrl->value != sensor->info_priv.whiteBalance)
3185                 {
3186                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
3187                     {
3188                         return -EINVAL;
3189                     }
3190                     sensor->info_priv.whiteBalance = ctrl->value;
3191                 }
3192                 break;
3193             }
3194 #endif
3195 #if CONFIG_SENSOR_Mirror
3196         case V4L2_CID_HFLIP:
3197             {
3198                 if (ctrl->value != sensor->info_priv.mirror)
3199                 {
3200                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
3201                         return -EINVAL;
3202                     sensor->info_priv.mirror = ctrl->value;
3203                 }
3204                 break;
3205             }
3206 #endif
3207 #if CONFIG_SENSOR_Flip
3208         case V4L2_CID_VFLIP:
3209             {
3210                 if (ctrl->value != sensor->info_priv.flip)
3211                 {
3212                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
3213                         return -EINVAL;
3214                     sensor->info_priv.flip = ctrl->value;
3215                 }
3216                 break;
3217             }
3218 #endif
3219         default:
3220             break;
3221     }
3222
3223     return 0;
3224 }
3225 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
3226 {
3227     const struct v4l2_queryctrl *qctrl;
3228     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3229     struct sensor *sensor = to_sensor(client);
3230
3231     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3232
3233     if (!qctrl)
3234     {
3235         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3236         return -EINVAL;
3237     }
3238
3239     switch (ext_ctrl->id)
3240     {
3241         case V4L2_CID_SCENE:
3242             {
3243                 ext_ctrl->value = sensor->info_priv.scene;
3244                 break;
3245             }
3246         case V4L2_CID_EFFECT:
3247             {
3248                 ext_ctrl->value = sensor->info_priv.effect;
3249                 break;
3250             }
3251         case V4L2_CID_ZOOM_ABSOLUTE:
3252             {
3253                 ext_ctrl->value = sensor->info_priv.digitalzoom;
3254                 break;
3255             }
3256         case V4L2_CID_ZOOM_RELATIVE:
3257             {
3258                 return -EINVAL;
3259             }
3260         case V4L2_CID_FOCUS_ABSOLUTE:
3261             {
3262                 ext_ctrl->value = sensor->info_priv.focus;
3263                 break;
3264             }
3265         case V4L2_CID_FOCUS_RELATIVE:
3266             {
3267                 return -EINVAL;
3268             }
3269         case V4L2_CID_FLASH:
3270             {
3271                 ext_ctrl->value = sensor->info_priv.flash;
3272                 break;
3273             }
3274         default :
3275             break;
3276     }
3277     return 0;
3278 }
3279 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
3280 {
3281     const struct v4l2_queryctrl *qctrl;
3282     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3283     struct sensor *sensor = to_sensor(client);
3284     int val_offset;
3285
3286     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
3287
3288     if (!qctrl)
3289     {
3290         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
3291         return -EINVAL;
3292     }
3293
3294         val_offset = 0;
3295     switch (ext_ctrl->id)
3296     {
3297 #if CONFIG_SENSOR_Scene
3298         case V4L2_CID_SCENE:
3299             {
3300                 if (ext_ctrl->value != sensor->info_priv.scene)
3301                 {
3302                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
3303                         return -EINVAL;
3304                     sensor->info_priv.scene = ext_ctrl->value;
3305                 }
3306                 break;
3307             }
3308 #endif
3309 #if CONFIG_SENSOR_Effect
3310         case V4L2_CID_EFFECT:
3311             {
3312                 if (ext_ctrl->value != sensor->info_priv.effect)
3313                 {
3314                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
3315                         return -EINVAL;
3316                     sensor->info_priv.effect= ext_ctrl->value;
3317                 }
3318                 break;
3319             }
3320 #endif
3321 #if CONFIG_SENSOR_DigitalZoom
3322         case V4L2_CID_ZOOM_ABSOLUTE:
3323             {
3324                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3325                     return -EINVAL;
3326
3327                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
3328                 {
3329                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
3330
3331                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
3332                         return -EINVAL;
3333                     sensor->info_priv.digitalzoom += val_offset;
3334
3335                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
3336                 }
3337
3338                 break;
3339             }
3340         case V4L2_CID_ZOOM_RELATIVE:
3341             {
3342                 if (ext_ctrl->value)
3343                 {
3344                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
3345                         return -EINVAL;
3346                     sensor->info_priv.digitalzoom += ext_ctrl->value;
3347
3348                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
3349                 }
3350                 break;
3351             }
3352 #endif
3353 #if CONFIG_SENSOR_Focus
3354         case V4L2_CID_FOCUS_ABSOLUTE:
3355             {
3356                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
3357                     return -EINVAL;
3358
3359                 if (ext_ctrl->value != sensor->info_priv.focus)
3360                 {
3361                     val_offset = ext_ctrl->value -sensor->info_priv.focus;
3362
3363                     sensor->info_priv.focus += val_offset;
3364                 }
3365
3366                 break;
3367             }
3368         case V4L2_CID_FOCUS_RELATIVE:
3369             {
3370                 if (ext_ctrl->value)
3371                 {
3372                     sensor->info_priv.focus += ext_ctrl->value;
3373
3374                     SENSOR_DG("%s focus is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.focus);
3375                 }
3376                 break;
3377             }
3378 #endif
3379 #if CONFIG_SENSOR_Flash
3380         case V4L2_CID_FLASH:
3381             {
3382                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3383                     return -EINVAL;
3384                 sensor->info_priv.flash = ext_ctrl->value;
3385
3386                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3387                 break;
3388             }
3389 #endif
3390         default:
3391             break;
3392     }
3393
3394     return 0;
3395 }
3396
3397 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3398 {
3399     struct i2c_client *client = v4l2_get_subdevdata(sd);
3400     struct soc_camera_device *icd = client->dev.platform_data;
3401     int i, error_cnt=0, error_idx=-1;
3402
3403
3404     for (i=0; i<ext_ctrl->count; i++) {
3405         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3406             error_cnt++;
3407             error_idx = i;
3408         }
3409     }
3410
3411     if (error_cnt > 1)
3412         error_idx = ext_ctrl->count;
3413
3414     if (error_idx != -1) {
3415         ext_ctrl->error_idx = error_idx;
3416         return -EINVAL;
3417     } else {
3418         return 0;
3419     }
3420 }
3421
3422 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3423 {
3424     struct i2c_client *client = v4l2_get_subdevdata(sd);
3425     struct soc_camera_device *icd = client->dev.platform_data;
3426     int i, error_cnt=0, error_idx=-1;
3427
3428
3429     for (i=0; i<ext_ctrl->count; i++) {
3430         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3431             error_cnt++;
3432             error_idx = i;
3433         }
3434     }
3435
3436     if (error_cnt > 1)
3437         error_idx = ext_ctrl->count;
3438
3439     if (error_idx != -1) {
3440         ext_ctrl->error_idx = error_idx;
3441         return -EINVAL;
3442     } else {
3443         return 0;
3444     }
3445 }
3446
3447 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3448  * this wasn't our capture interface, so, we wait for the right one */
3449 static int sensor_video_probe(struct soc_camera_device *icd,
3450                                struct i2c_client *client)
3451 {
3452     char value;
3453     int ret,pid = 0;
3454     struct sensor *sensor = to_sensor(client);
3455
3456     /* We must have a parent by now. And it cannot be a wrong one.
3457      * So this entire test is completely redundant. */
3458     if (!icd->dev.parent ||
3459             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3460                 return -ENODEV;
3461
3462         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3463                 ret = -ENODEV;
3464                 goto sensor_video_probe_err;
3465         }
3466
3467     /* soft reset */
3468    /* ret = sensor_write(client, 0x3012, 0x80);
3469     if (ret != 0)
3470     {
3471         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
3472         return -ENODEV;
3473     }
3474     mdelay(5);      */    //delay 5 microseconds
3475
3476     /* check if it is an sensor sensor */
3477     ret = sensor_read(client, 0x0000, &value);
3478     if (ret != 0) {
3479         SENSOR_TR("read chip id high byte failed\n");
3480         ret = -ENODEV;
3481         goto sensor_video_probe_err;
3482     }
3483
3484     pid |= (value << 8);
3485
3486     ret = sensor_read(client, 0x0001, &value);
3487     if (ret != 0) {
3488         SENSOR_TR("read chip id low byte failed\n");
3489         ret = -ENODEV;
3490         goto sensor_video_probe_err;
3491     }
3492
3493     pid |= (value & 0xff);
3494     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3495     if (pid == SENSOR_ID) {
3496         sensor->model = SENSOR_V4L2_IDENT;
3497     } else {
3498         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3499         ret = -ENODEV;
3500         goto sensor_video_probe_err;
3501     }
3502
3503     return 0;
3504
3505 sensor_video_probe_err:
3506
3507     return ret;
3508 }
3509 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3510 {
3511         struct i2c_client *client = v4l2_get_subdevdata(sd);
3512     struct soc_camera_device *icd = client->dev.platform_data;
3513     struct sensor *sensor = to_sensor(client);
3514 #if CONFIG_SENSOR_Flash
3515     int i;
3516 #endif
3517     int ret = 0;
3518     
3519         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3520         switch (cmd)
3521         {
3522                 case RK_CAM_SUBDEV_DEACTIVATE:
3523                 {
3524                         sensor_deactivate(client);
3525                         break;
3526                 }
3527
3528                 case RK_CAM_SUBDEV_IOREQUEST:
3529                 {
3530                         sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;           
3531             if (sensor->sensor_io_request != NULL) { 
3532                 if (sensor->sensor_io_request->gpio_res[0].dev_name && 
3533                     (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
3534                     sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
3535                 } else if (sensor->sensor_io_request->gpio_res[1].dev_name && 
3536                     (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
3537                     sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
3538                 }
3539             } else {
3540                 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3541                 ret = -EINVAL;
3542                 goto sensor_ioctl_end;
3543             }
3544             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
3545                for this project */
3546             #if CONFIG_SENSOR_Flash     
3547                 if (sensor->sensor_gpio_res) {
3548                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3549                     for (i = 0; i < icd->ops->num_controls; i++) {
3550                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3551                                         memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                       
3552                                 }
3553                     }
3554                     sensor->info_priv.flash = 0xff;
3555                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3556                 }
3557                 }
3558             #endif
3559                         break;
3560                 }
3561                 default:
3562                 {
3563                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3564                         break;
3565                 }
3566         }
3567 sensor_ioctl_end:
3568         return ret;
3569
3570 }
3571 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3572                             enum v4l2_mbus_pixelcode *code)
3573 {
3574         if (index >= ARRAY_SIZE(sensor_colour_fmts))
3575                 return -EINVAL;
3576
3577         *code = sensor_colour_fmts[index].code;
3578         return 0;
3579 }
3580 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3581         .init           = sensor_init,
3582         .g_ctrl         = sensor_g_control,
3583         .s_ctrl         = sensor_s_control,
3584         .g_ext_ctrls          = sensor_g_ext_controls,
3585         .s_ext_ctrls          = sensor_s_ext_controls,
3586         .g_chip_ident   = sensor_g_chip_ident,
3587         .ioctl = sensor_ioctl,
3588 };
3589
3590 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3591         .s_mbus_fmt     = sensor_s_fmt,
3592         .g_mbus_fmt     = sensor_g_fmt,
3593         .try_mbus_fmt   = sensor_try_fmt,
3594         .enum_mbus_fmt  = sensor_enum_fmt,
3595 };
3596
3597 static struct v4l2_subdev_ops sensor_subdev_ops = {
3598         .core   = &sensor_subdev_core_ops,
3599         .video = &sensor_subdev_video_ops,
3600 };
3601
3602 static int sensor_probe(struct i2c_client *client,
3603                          const struct i2c_device_id *did)
3604 {
3605     struct sensor *sensor;
3606     struct soc_camera_device *icd = client->dev.platform_data;
3607     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3608     struct soc_camera_link *icl;
3609     int ret;
3610
3611     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3612     if (!icd) {
3613         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3614         return -EINVAL;
3615     }
3616
3617     icl = to_soc_camera_link(icd);
3618     if (!icl) {
3619         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3620         return -EINVAL;
3621     }
3622
3623     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3624         dev_warn(&adapter->dev,
3625                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3626         return -EIO;
3627     }
3628
3629     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3630     if (!sensor)
3631         return -ENOMEM;
3632
3633     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3634
3635     /* Second stage probe - when a capture adapter is there */
3636     icd->ops            = &sensor_ops;
3637
3638     sensor->info_priv.fmt = sensor_colour_fmts[0];
3639     
3640         #if CONFIG_SENSOR_I2C_NOSCHED
3641         atomic_set(&sensor->tasklock_cnt,0);
3642         #endif
3643
3644     ret = sensor_video_probe(icd, client);
3645     if (ret < 0) {
3646         icd->ops = NULL;
3647         i2c_set_clientdata(client, NULL);
3648         kfree(sensor);
3649                 sensor = NULL;
3650     }
3651     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3652     return ret;
3653 }
3654
3655 static int sensor_remove(struct i2c_client *client)
3656 {
3657     struct sensor *sensor = to_sensor(client);
3658     struct soc_camera_device *icd = client->dev.platform_data;
3659
3660     icd->ops = NULL;
3661     i2c_set_clientdata(client, NULL);
3662     client->driver = NULL;
3663     kfree(sensor);
3664
3665     return 0;
3666 }
3667
3668 static const struct i2c_device_id sensor_id[] = {
3669         {SENSOR_NAME_STRING(), 0 },
3670         { }
3671 };
3672 MODULE_DEVICE_TABLE(i2c, sensor_id);
3673
3674 static struct i2c_driver sensor_i2c_driver = {
3675         .driver = {
3676                 .name = SENSOR_NAME_STRING(),
3677         },
3678         .probe          = sensor_probe,
3679         .remove         = sensor_remove,
3680         .id_table       = sensor_id,
3681 };
3682
3683 static int __init sensor_mod_init(void)
3684 {
3685     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3686     return i2c_add_driver(&sensor_i2c_driver);
3687 }
3688
3689 static void __exit sensor_mod_exit(void)
3690 {
3691     i2c_del_driver(&sensor_i2c_driver);
3692 }
3693
3694 device_initcall_sync(sensor_mod_init);
3695 module_exit(sensor_mod_exit);
3696
3697 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3698 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3699 MODULE_LICENSE("GPL");
3700