camera rk30:commit v0.2.6,support two cif controls.
[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 <plat/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 RK29_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 /* init 800*600 SVGA */
101 static struct reginfo sensor_init_data[] =
102 {
103     {0x0101 , 0x00},
104         {0x0103 , 0x00}, 
105         {0x0105 , 0x00},
106         {0x0106 , 0xF0},
107         {0x0107 , 0x00},
108         {0x0108 , 0x1C},
109         {0x0109 , 0x01},
110         {0x010A , 0x00},
111         {0x010B , 0x00},
112         {0x010C , 0x00},
113         {0x010D , 0x08},
114         {0x010E , 0x00},
115         {0x010F , 0x08},
116         {0x0110 , 0x06},
117         {0x0111 , 0x40},
118         {0x0112 , 0x04},
119         {0x0113 , 0xB0},
120 {0x0114 , 0x00},
121         {0x0115 , 0x00},
122         {0x0116 , 0x02},
123         {0x0117 , 0x00},
124 {0x0118 , 0x67},
125         {0x0119 , 0x02},
126         {0x011A , 0x04},
127         {0x011B , 0x01},
128 {0x011C , 0x01},
129 {0x011D , 0x02},
130 {0x011E , 0x00},
131 {0x011F , 0x00},
132 {0x0120 , 0x1C},
133 {0x0121 , 0x00},
134 {0x0122 , 0x04},
135 {0x0123 , 0x00},
136 {0x0124 , 0x00},
137 {0x0125 , 0x00},
138 {0x0126 , 0x00},
139 {0x0127 , 0x00},
140 {0x0128 , 0x00},
141 {0x0200 , 0x00},
142 {0x0201 , 0x00},
143 {0x0202 , 0x40},
144 {0x0203 , 0x00},
145 {0x0204 , 0x03},
146 {0x0205 , 0x1F},
147 {0x0206 , 0x0B},
148 {0x0207 , 0x20},
149 {0x0208 , 0x00},
150 {0x0209 , 0x2A},
151 {0x020A , 0x01},
152 {0x020B , 0x48},
153 {0x020C , 0x64},
154 {0x020D , 0xC8},
155 {0x020E , 0xBC},
156 {0x020F , 0x08},
157 {0x0210 , 0xD6},
158 {0x0211 , 0x00},
159 {0x0212 , 0x20},
160 {0x0213 , 0x81},
161 {0x0214 , 0x15},
162 {0x0215 , 0x00},
163 {0x0216 , 0x00},
164 {0x0217 , 0x00},
165 {0x0218 , 0x46},
166 {0x0219 , 0x30},
167 {0x021A , 0x03},
168 {0x021B , 0x28},
169 {0x021C , 0x02},
170 {0x021D , 0x60},
171 {0x021E , 0x00},
172 {0x021F , 0x00},
173 {0x0220 , 0x08},
174 {0x0221 , 0x08},
175 {0x0222 , 0x04},
176 {0x0223 , 0x00},
177 {0x0224 , 0x1F},
178 {0x0225 , 0x1E},
179 {0x0226 , 0x18},
180 {0x0227 , 0x1D},
181 {0x0228 , 0x1F},
182 {0x0229 , 0x1F},
183 {0x022A , 0x01},
184 {0x022B , 0x04},
185 {0x022C , 0x05},
186 {0x022D , 0x05},
187 {0x022E , 0x04},
188 {0x022F , 0x03},
189 {0x0230 , 0x02},
190 {0x0231 , 0x1F},
191 {0x0232 , 0x1A},
192 {0x0233 , 0x19},
193 {0x0234 , 0x19},
194 {0x0235 , 0x1B},
195 {0x0236 , 0x1F},
196 {0x0237 , 0x04},
197 {0x0238 , 0xEE},
198 {0x0239 , 0xFF},
199 {0x023A , 0x00},
200 {0x023B , 0x00},
201 {0x023C , 0x00},
202 {0x023D , 0x00},
203 {0x023E , 0x00},
204 {0x023F , 0x00},
205 {0x0240 , 0x00},
206 {0x0241 , 0x00},
207 {0x0242 , 0x00},
208 {0x0243 , 0x21},
209 {0x0244 , 0x42},
210 {0x0245 , 0x53},
211 {0x0246 , 0x54},
212 {0x0247 , 0x54},
213 {0x0248 , 0x54},
214 {0x0249 , 0x33},
215 {0x024A , 0x11},
216 {0x024B , 0x00},
217 {0x024C , 0x00},
218 {0x024D , 0xFF},
219 {0x024E , 0xEE},
220 {0x024F , 0xDD},
221 {0x0250 , 0x00},
222 {0x0251 , 0x00},
223 {0x0252 , 0x00},
224 {0x0253 , 0x00},
225 {0x0254 , 0x00},
226 {0x0255 , 0x00},
227 {0x0256 , 0x00},
228 {0x0257 , 0x00},
229 {0x0258 , 0x00},
230 {0x0259 , 0x00},
231 {0x025A , 0x00},
232 {0x025B , 0x00},
233 {0x025C , 0x00},
234 {0x025D , 0x00},
235 {0x025E , 0x00},
236 {0x025F , 0x00},
237 {0x0260 , 0x00},
238 {0x0261 , 0x00},
239 {0x0262 , 0x00},
240 {0x0263 , 0x00},
241 {0x0264 , 0x00},
242 {0x0265 , 0x00},
243 {0x0266 , 0x00},
244 {0x0267 , 0x00},
245 {0x0268 , 0x8F},
246 {0x0269 , 0xA3},
247 {0x026A , 0xB4},
248 {0x026B , 0x90},
249 {0x026C , 0x00},
250 {0x026D , 0xD0},
251 {0x026E , 0x60},
252 {0x026F , 0xA0},
253 {0x0270 , 0x40},
254 {0x0300 , 0x81},
255 {0x0301 , 0x80},
256 {0x0302 , 0x22},
257 {0x0303 , 0x06},
258 {0x0304 , 0x03},
259 {0x0305 , 0x83},
260 {0x0306 , 0x00},
261 {0x0307 , 0x22},
262 {0x0308 , 0x00},
263 {0x0309 , 0x55},
264 {0x030A , 0x55},
265 {0x030B , 0x55},
266 {0x030C , 0x54},
267 {0x030D , 0x1F},
268 {0x030E , 0x13},
269 {0x030F , 0x10},
270 {0x0310 , 0x04},
271 {0x0311 , 0xFF},
272 {0x0312 , 0x08},
273 {0x0313 , 0x28},
274 {0x0314 , 0x66},
275 {0x0315 , 0x16},
276 {0x0316 , 0x26},
277 {0x0317 , 0x02},
278 {0x0318 , 0x08},
279 {0x0319 , 0x0C},
280 {0x031A , 0x81},
281 {0x031B , 0x00},
282 {0x031C , 0x3D},
283 {0x031D , 0x00},
284 {0x031E , 0xF9},
285 {0x031F , 0x00},
286 {0x0320 , 0x24},
287 {0x0321 , 0x14},
288 {0x0322 , 0x1A},
289 {0x0323 , 0x24},
290 {0x0324 , 0x08},
291 {0x0325 , 0xF0},
292 {0x0326 , 0x30}, 
293 {0x0327 , 0x17},
294 {0x0328 , 0x11},
295 {0x0329 , 0x22},
296 {0x032A , 0x2F},
297 {0x032B , 0x21},
298 {0x032C , 0xDA},
299 {0x032D , 0x10},
300 {0x032E , 0xEA},
301 {0x032F , 0x18},
302 {0x0330 , 0x29},
303 {0x0331 , 0x25},
304 {0x0332 , 0x12},
305 {0x0333 , 0x0F},
306 {0x0334 , 0xE0},
307 {0x0335 , 0x13},
308 {0x0336 , 0xFF},
309 {0x0337 , 0x20},
310 {0x0338 , 0x46},
311 {0x0339 , 0x04},
312 {0x033A , 0x04},
313 {0x033B , 0xFF},
314 {0x033C , 0x01},
315 {0x033D , 0x00},
316 {0x033E , 0x03},
317 {0x033F , 0x28},
318 {0x0340 , 0x02},
319 {0x0341 , 0x60},
320 {0x0342 , 0xAC},
321 {0x0343 , 0x97},
322 {0x0344 , 0x7F},
323 {0x0400 , 0xE8},
324 {0x0401 , 0x40},
325 {0x0402 , 0x00},
326 {0x0403 , 0x00},
327 {0x0404 , 0xF8},
328 {0x0405 , 0x03},
329 {0x0406 , 0x03},
330 {0x0407 , 0x85},
331 {0x0408 , 0x44},
332 {0x0409 , 0x1F},
333 {0x040A , 0x40},
334 {0x040B , 0x33},
335 {0x040C , 0xA0},
336 {0x040D , 0x00},
337 {0x040E , 0x00},
338 {0x040F , 0x00},
339 {0x0410 , 0x0D},
340 {0x0411 , 0x0D},
341 {0x0412 , 0x0C},
342 {0x0413 , 0x04},
343 {0x0414 , 0x00},
344 {0x0415 , 0x00},
345 {0x0416 , 0x07},
346 {0x0417 , 0x09},
347 {0x0418 , 0x16},
348 {0x0419 , 0x14},
349 {0x041A , 0x11},
350 {0x041B , 0x14},
351 {0x041C , 0x07},
352 {0x041D , 0x07},
353 {0x041E , 0x06},
354 {0x041F , 0x02},
355 {0x0420 , 0x42},
356 {0x0421 , 0x42},
357 {0x0422 , 0x47},
358 {0x0423 , 0x39},
359 {0x0424 , 0x3E},
360 {0x0425 , 0x4D},
361 {0x0426 , 0x46},
362 {0x0427 , 0x3A},
363 {0x0428 , 0x21},
364 {0x0429 , 0x21},
365 {0x042A , 0x26},
366 {0x042B , 0x1C},
367 {0x042C , 0x25},
368 {0x042D , 0x25},
369 {0x042E , 0x28},
370 {0x042F , 0x20},
371 {0x0430 , 0x3E},
372 {0x0431 , 0x3E},
373 {0x0432 , 0x33},
374 {0x0433 , 0x2E},
375 {0x0434 , 0x54},
376 {0x0435 , 0x53},
377 {0x0436 , 0x3C},
378 {0x0437 , 0x51},
379 {0x0438 , 0x2B},
380 {0x0439 , 0x2B},
381 {0x043A , 0x38},
382 {0x043B , 0x22},
383 {0x043C , 0x3B},
384 {0x043D , 0x3B},
385 {0x043E , 0x31},
386 {0x043F , 0x37},
387 {0x0440 , 0x00},
388 {0x0441 , 0x4B},
389 {0x0442 , 0x00},
390 {0x0443 , 0x00},
391 {0x0444 , 0x31},
392 {0x0445 , 0x00},
393 {0x0446 , 0x00},
394 {0x0447 , 0x00},
395 {0x0448 , 0x00},
396 {0x0449 , 0x00},
397 {0x044A , 0x00},
398 {0x044D , 0xE0},
399 {0x044E , 0x05},
400 {0x044F , 0x07},
401 {0x0450 , 0x00},
402 {0x0451 , 0x00},
403 {0x0452 , 0x00},
404 {0x0453 , 0x00},
405 {0x0454 , 0x00},
406 {0x0455 , 0x00},
407 {0x0456 , 0x00},
408 {0x0457 , 0x00},
409 {0x0458 , 0x00},
410 {0x0459 , 0x00},
411 {0x045A , 0x00},
412 {0x045B , 0x00},
413 {0x045C , 0x00},
414 {0x045D , 0x00},
415 {0x045E , 0x00},
416 {0x045F , 0x00},
417 {0x0460 , 0x80},
418 {0x0461 , 0x10},
419 {0x0462 , 0x10},
420 {0x0463 , 0x10},
421 {0x0464 , 0x08},
422 {0x0465 , 0x08},
423 {0x0466 , 0x11},
424 {0x0467 , 0x09},
425 {0x0468 , 0x23},
426 {0x0469 , 0x2A},
427 {0x046A , 0x2A},
428 {0x046B , 0x47},
429 {0x046C , 0x52},
430 {0x046D , 0x42},
431 {0x046E , 0x36},
432 {0x046F , 0x46},
433 {0x0470 , 0x3A},
434 {0x0471 , 0x32},
435 {0x0472 , 0x32},
436 {0x0473 , 0x38},
437 {0x0474 , 0x3D},
438 {0x0475 , 0x2F},
439 {0x0476 , 0x29},
440 {0x0477 , 0x48},
441 {0x0600 , 0x00},
442 {0x0601 , 0x24},
443 {0x0602 , 0x45},
444 {0x0603 , 0x0E},
445 {0x0604 , 0x14},
446 {0x0605 , 0x2F},
447 {0x0606 , 0x01},
448 {0x0607 , 0x0E},
449 {0x0608 , 0x0E},
450 {0x0609 , 0x37},
451 {0x060A , 0x18},
452 {0x060B , 0xA0},
453 {0x060C , 0x20},
454 {0x060D , 0x07},
455 {0x060E , 0x47},
456 {0x060F , 0x90},
457 {0x0610 , 0x06},
458 {0x0611 , 0x0C},
459 {0x0612 , 0x28},
460 {0x0613 , 0x13},
461 {0x0614 , 0x0B},
462 {0x0615 , 0x10},
463 {0x0616 , 0x14},
464 {0x0617 , 0x19},
465 {0x0618 , 0x52},
466 {0x0619 , 0xA0},
467 {0x061A , 0x11},
468 {0x061B , 0x33},
469 {0x061C , 0x56},
470 {0x061D , 0x20},
471 {0x061E , 0x28},
472 {0x061F , 0x2B},
473 {0x0620 , 0x22},
474 {0x0621 , 0x11},
475 {0x0622 , 0x75},
476 {0x0623 , 0x49},
477 {0x0624 , 0x6E},
478 {0x0625 , 0x80},
479 {0x0626 , 0x02},
480 {0x0627 , 0x0C},
481 {0x0628 , 0x51},
482 {0x0629 , 0x25},
483 {0x062A , 0x01},
484 {0x062B , 0x3D},
485 {0x062C , 0x04},
486 {0x062D , 0x01},
487 {0x062E , 0x0C},
488 {0x062F , 0x2C},
489 {0x0630 , 0x0D},
490 {0x0631 , 0x14},
491 {0x0632 , 0x12},
492 {0x0633 , 0x34},
493 {0x0634 , 0x00},
494 {0x0635 , 0x00},
495 {0x0636 , 0x00},
496 {0x0637 , 0xB1},
497 {0x0638 , 0x22},
498 {0x0639 , 0x32},
499 {0x063A , 0x0E},
500 {0x063B , 0x18},
501 {0x063C , 0x88},
502 {0x0640 , 0xB2},
503 {0x0641 , 0xC0},
504 {0x0642 , 0x01},
505 {0x0643 , 0x26},
506 {0x0644 , 0x13},
507 {0x0645 , 0x88},
508 {0x0646 , 0x64},
509 {0x0647 , 0x00},
510 {0x0681 , 0x1B},
511 {0x0682 , 0xA0},
512 {0x0683 , 0x28},
513 {0x0684 , 0x00},
514 {0x0685 , 0xB0},
515 {0x0686 , 0x6F},
516 {0x0687 , 0x33},
517 {0x0688 , 0x1F},
518 {0x0689 , 0x44},
519 {0x068A , 0xA8},
520 {0x068B , 0x44},
521 {0x068C , 0x08},
522 {0x068D , 0x08},
523 {0x068E , 0x00},
524 {0x068F , 0x00},
525 {0x0690 , 0x01},
526 {0x0691 , 0x00},
527 {0x0692 , 0x01},
528 {0x0693 , 0x00},
529 {0x0694 , 0x00},
530 {0x0695 , 0x00},
531 {0x0696 , 0x00},
532 {0x0697 , 0x00},
533 {0x0698 , 0x2A},
534 {0x0699 , 0x80},
535 {0x069A , 0x1F},
536 {0x069B , 0x00},
537 {0x069C , 0x02},
538 {0x069D , 0xF5},
539 {0x069E , 0x03},
540 {0x069F , 0x6D},
541 {0x06A0 , 0x0C},
542 {0x06A1 , 0xB8},
543 {0x06A2 , 0x0D},
544 {0x06A3 , 0x74},
545 {0x06A4 , 0x00},
546 {0x06A5 , 0x2F},
547 {0x06A6 , 0x00},
548 {0x06A7 , 0x2F},
549 {0x0F00 , 0x00},
550 {0x0F01 , 0x00},
551 {0x0100 , 0x01},
552 {0x0102 , 0x02},
553 {0x0104 , 0x03},
554 {0x0101 , 0x02},
555
556 ///////////////////////////
557 {0x020B , 0x48},
558 {0x020C , 0x64},
559 {0x040A , 0x40},
560 {0x040B , 0x33},
561 {0x0109 , 0x00},
562 {0x010A , 0x04},
563 {0x010B , 0x03},
564 #if 0
565 {0x0110 , 0x02},
566 {0x0111 , 0x80},
567 {0x0112 , 0x01},
568 {0x0113 , 0xe0},
569 #else
570 {0x0110, 0x03},
571 {0x0111, 0x20},
572 {0x0112, 0x02},
573 {0x0113, 0x58},
574
575 #endif
576 {0x0116 , 0x02},
577 {0x0118 , 0x40},
578 {0x0119 , 0x01},
579 {0x011a , 0x04},
580 {0x011B , 0x00},
581 {0x0313 , 0x35},
582 {0x0314 , 0x36},
583 {0x0315 , 0x16},
584
585 };
586         
587
588
589 /* 1600X1200 UXGA */
590 static struct reginfo sensor_uxga[] = 
591 {
592     {0x010c , 0x00},
593         {0x010d , 0x08},
594         {0x010e , 0x00},
595         {0x010f , 0x08},
596         {0x010a , 0x00},
597         {0x0110 , 0x06},
598         {0x0111 , 0x40},
599         {0x0112 , 0x04},
600         {0x0113 , 0xb0},
601         {0x0, 0x0},
602 };
603
604         
605
606 /* 1280X1024 SXGA */
607 static struct reginfo sensor_sxga[] =
608 {
609     {0x010c , 0x00},
610         {0x010d , 0xa8},
611         {0x010e , 0x00},
612         {0x010f , 0x60},
613         {0x010a , 0x00},
614         {0x0110 , 0x05},
615         {0x0111 , 0x00},
616         {0x0112 , 0x04},
617         {0x0113 , 0x00}, 
618         {0x00, 0x00},
619 };
620
621 /* 800X600 SVGA*/
622 static struct reginfo sensor_svga[] =
623 {       
624 #if 0   
625         {0x0101, 0x00},
626         {0x0103, 0x00},
627         {0x0105, 0x00},
628         {0x0106, 0xF0},
629         {0x0107, 0x00},
630         {0x0108, 0x1C},
631         {0x0109, 0x01},
632         {0x010A, 0x00},
633         {0x010B, 0x00},
634         {0x010C, 0x00},
635         {0x010D, 0x08},
636         {0x010E, 0x00},
637         {0x010F, 0x08},
638         {0x0110, 0x06},
639         {0x0111, 0x40},
640         {0x0112, 0x04},
641         {0x0113, 0xB0},
642         {0x0114, 0x04},
643         {0x0115, 0x00},
644         {0x0116, 0x02},
645         {0x0117, 0x00},
646         {0x0118, 0x40},
647         {0x0119, 0x02},
648         {0x011A, 0x04},
649         {0x011B, 0x01},
650         {0x011C, 0x00},
651         {0x011D, 0x01},
652         {0x011E, 0x36},
653         {0x011F, 0x00},
654         {0x0120, 0x1C},
655         {0x0121, 0x00},
656         {0x0122, 0x04},
657         {0x0123, 0x00},
658         {0x0124, 0x00},
659         {0x0125, 0x00},
660         {0x0126, 0x00},
661         {0x0127, 0x00},
662         {0x0128, 0x00},
663         {0x0200, 0x1f},
664         {0x0201, 0x0c},
665         {0x0202, 0x38},
666         {0x0203, 0x00},
667         {0x0204, 0x03},
668         {0x0205, 0x1F},
669         {0x0206, 0x0B},
670         {0x0207, 0x20},
671         {0x0208, 0x00},
672         {0x0209, 0x2A},
673         {0x020A, 0x01},
674         {0x020B, 0x28},
675         {0x020C, 0x44},
676         {0x020D, 0xC8},
677         {0x020E, 0xBC},
678         {0x020F, 0x08},
679         {0x0210, 0xD6},
680         {0x0211, 0x00},
681         {0x0212, 0x20},
682         {0x0213, 0x81},
683         {0x0214, 0x15},
684         {0x0215, 0x00},
685         {0x0216, 0x00},
686         {0x0217, 0x00},
687         {0x0218, 0x46},
688         {0x0219, 0x30},
689         {0x021A, 0x03},
690         {0x021B, 0x28},
691         {0x021C, 0x02},
692         {0x021D, 0x60},
693         {0x021E, 0x00},
694         {0x021F, 0x00},
695         {0x0220, 0x08},
696         {0x0221, 0x08},
697         {0x0222, 0x04},
698         {0x0223, 0x00},
699         {0x0224, 0x1F},
700         {0x0225, 0x1E},
701         {0x0226, 0x18},
702         {0x0227, 0x1D},
703         {0x0228, 0x1F},
704         {0x0229, 0x1F},
705         {0x022A, 0x01},
706         {0x022B, 0x04},
707         {0x022C, 0x05},
708         {0x022D, 0x05},
709         {0x022E, 0x04},
710         {0x022F, 0x03},
711         {0x0230, 0x02},
712         {0x0231, 0x1F},
713         {0x0232, 0x1A},
714         {0x0233, 0x19},
715         {0x0234, 0x19},
716         {0x0235, 0x1B},
717         {0x0236, 0x1F},
718         {0x0237, 0x04},
719         {0x0238, 0xEE},
720         {0x0239, 0xFF},
721         {0x023A, 0x00},
722         {0x023B, 0x00},
723         {0x023C, 0x00},
724         {0x023D, 0x00},
725         {0x023E, 0x00},
726         {0x023F, 0x00},
727         {0x0240, 0x00},
728         {0x0241, 0x00},
729         {0x0242, 0x00},
730         {0x0243, 0x21},
731         {0x0244, 0x42},
732         {0x0245, 0x53},
733         {0x0246, 0x54},
734         {0x0247, 0x54},
735         {0x0248, 0x54},
736         {0x0249, 0x33},
737         {0x024A, 0x11},
738         {0x024B, 0x00},
739         {0x024C, 0x00},
740         {0x024D, 0xFF},
741         {0x024E, 0xEE},
742         {0x024F, 0xDD},
743         {0x0250, 0x00},
744         {0x0251, 0x00},
745         {0x0252, 0x00},
746         {0x0253, 0x00},
747         {0x0254, 0x00},
748         {0x0255, 0x00},
749         {0x0256, 0x00},
750         {0x0257, 0x00},
751         {0x0258, 0x00},
752         {0x0259, 0x00},
753         {0x025A, 0x00},
754         {0x025B, 0x00},
755         {0x025C, 0x00},
756         {0x025D, 0x00},
757         {0x025E, 0x00},
758         {0x025F, 0x00},
759         {0x0260, 0x00},
760         {0x0261, 0x00},
761         {0x0262, 0x00},
762         {0x0263, 0x00},
763         {0x0264, 0x00},
764         {0x0265, 0x00},
765         {0x0266, 0x00},
766         {0x0267, 0x00},
767         {0x0268, 0x8F},
768         {0x0269, 0xA3},
769         {0x026A, 0xB4},
770         {0x026B, 0x90},
771         {0x026C, 0x00},
772         {0x026D, 0xD0},
773         {0x026E, 0x60},
774         {0x026F, 0xA0},
775         {0x0270, 0x40},
776         {0x0300, 0x81},
777         {0x0301, 0x80},
778         {0x0302, 0x22},
779         {0x0303, 0x06},
780         {0x0304, 0x03},
781         {0x0305, 0x83},
782         {0x0306, 0x00},
783         {0x0307, 0x22},
784         {0x0308, 0x00},
785         {0x0309, 0x55},
786         {0x030A, 0x55},
787         {0x030B, 0x55},
788         {0x030C, 0x54},
789         {0x030D, 0x1F},
790         {0x030E, 0x0A},
791         {0x030F, 0x10},
792         {0x0310, 0x04},
793         {0x0311, 0xFF},
794         {0x0312, 0x08},
795         {0x0313, 0x35},
796         {0x0314, 0x36},
797         {0x0315, 0x15},
798         {0x0316, 0x26},
799         {0x0317, 0x02},
800         {0x0318, 0x08},
801         {0x0319, 0x0C},
802         {0x031A, 0x81},
803         {0x031B, 0x00},
804         {0x031C, 0x3D},
805         {0x031D, 0x00},
806         {0x031E, 0xF9},
807         {0x031F, 0x00},
808         {0x0320, 0x24},
809         {0x0321, 0x14},
810         {0x0322, 0x1A},
811         {0x0323, 0x24},
812         {0x0324, 0x08},
813         {0x0325, 0xF0},
814         {0x0326, 0x30},
815         {0x0327, 0x17},
816         {0x0328, 0x11},
817         {0x0329, 0x22},
818         {0x032A, 0x2F},
819         {0x032B, 0x21},
820         {0x032C, 0xDA},
821         {0x032D, 0x10},
822         {0x032E, 0xEA},
823         {0x032F, 0x18},
824         {0x0330, 0x29},
825         {0x0331, 0x25},
826         {0x0332, 0x12},
827         {0x0333, 0x0F},
828         {0x0334, 0xE0},
829         {0x0335, 0x13},
830         {0x0336, 0xFF},
831         {0x0337, 0x20},
832         {0x0338, 0x46},
833         {0x0339, 0x04},
834         {0x033A, 0x04},
835         {0x033B, 0xFF},
836         {0x033C, 0x01},
837         {0x033D, 0x00},
838         {0x033E, 0x03},
839         {0x033F, 0x28},
840         {0x0340, 0x02},
841         {0x0341, 0x60},
842         {0x0342, 0xAC},
843         {0x0343, 0x97},
844         {0x0344, 0x7F},
845         {0x0400, 0xE8},
846         {0x0401, 0x40},
847         {0x0402, 0x00},
848         {0x0403, 0x00},
849         {0x0404, 0xF8},
850         {0x0405, 0x03},
851         {0x0406, 0x03},
852         {0x0407, 0x85},
853         {0x0408, 0x44},
854         {0x0409, 0x1F},
855         {0x040A, 0x40},
856         {0x040B, 0x33},
857         {0x040C, 0xA0},
858         {0x040D, 0x00},
859         {0x040E, 0x00},
860         {0x040F, 0x00},
861         {0x0410, 0x0D},
862         {0x0411, 0x0D},
863         {0x0412, 0x0C},
864         {0x0413, 0x04},
865         {0x0414, 0x00},
866         {0x0415, 0x00},
867         {0x0416, 0x07},
868         {0x0417, 0x09},
869         {0x0418, 0x16},
870         {0x0419, 0x14},
871         {0x041A, 0x11},
872         {0x041B, 0x14},
873         {0x041C, 0x07},
874         {0x041D, 0x07},
875         {0x041E, 0x06},
876         {0x041F, 0x02},
877         {0x0420, 0x42},
878         {0x0421, 0x42},
879         {0x0422, 0x47},
880         {0x0423, 0x39},
881         {0x0424, 0x3E},
882         {0x0425, 0x4D},
883         {0x0426, 0x46},
884         {0x0427, 0x3A},
885         {0x0428, 0x21},
886         {0x0429, 0x21},
887         {0x042A, 0x26},
888         {0x042B, 0x1C},
889         {0x042C, 0x25},
890         {0x042D, 0x25},
891         {0x042E, 0x28},
892         {0x042F, 0x20},
893         {0x0430, 0x3E},
894         {0x0431, 0x3E},
895         {0x0432, 0x33},
896         {0x0433, 0x2E},
897         {0x0434, 0x54},
898         {0x0435, 0x53},
899         {0x0436, 0x3C},
900         {0x0437, 0x51},
901         {0x0438, 0x2B},
902         {0x0439, 0x2B},
903         {0x043A, 0x38},
904         {0x043B, 0x22},
905         {0x043C, 0x3B},
906         {0x043D, 0x3B},
907         {0x043E, 0x31},
908         {0x043F, 0x37},
909         {0x0440, 0x00},
910         {0x0441, 0x4B},
911         {0x0442, 0x00},
912         {0x0443, 0x00},
913         {0x0444, 0x31},
914         {0x0445, 0x00},
915         {0x0446, 0x00},
916         {0x0447, 0x00},
917         {0x0448, 0x00},
918         {0x0449, 0x00},
919         {0x044A, 0x00},
920         {0x044D, 0xE0},
921         {0x044E, 0x05},
922         {0x044F, 0x07},
923         {0x0450, 0x00},
924         {0x0451, 0x00},
925         {0x0452, 0x00},
926         {0x0453, 0x00},
927         {0x0454, 0x00},
928         {0x0455, 0x00},
929         {0x0456, 0x00},
930         {0x0457, 0x00},
931         {0x0458, 0x00},
932         {0x0459, 0x00},
933         {0x045A, 0x00},
934         {0x045B, 0x00},
935         {0x045C, 0x00},
936         {0x045D, 0x00},
937         {0x045E, 0x00},
938         {0x045F, 0x00},
939         {0x0460, 0x80},
940         {0x0461, 0x10},
941         {0x0462, 0x10},
942         {0x0463, 0x10},
943         {0x0464, 0x08},
944         {0x0465, 0x08},
945         {0x0466, 0x11},
946         {0x0467, 0x09},
947         {0x0468, 0x23},
948         {0x0469, 0x2A},
949         {0x046A, 0x2A},
950         {0x046B, 0x47},
951         {0x046C, 0x52},
952         {0x046D, 0x42},
953         {0x046E, 0x36},
954         {0x046F, 0x46},
955         {0x0470, 0x3A},
956         {0x0471, 0x32},
957         {0x0472, 0x32},
958         {0x0473, 0x38},
959         {0x0474, 0x3D},
960         {0x0475, 0x2F},
961         {0x0476, 0x29},
962         {0x0477, 0x48},
963         {0x0600, 0x00},
964         {0x0601, 0x24},
965         {0x0602, 0x45},
966         {0x0603, 0x0E},
967         {0x0604, 0x14},
968         {0x0605, 0x2F},
969         {0x0606, 0x01},
970         {0x0607, 0x0E},
971         {0x0608, 0x0E},
972         {0x0609, 0x37},
973         {0x060A, 0x18},
974         {0x060B, 0xA0},
975         {0x060C, 0x20},
976         {0x060D, 0x07},
977         {0x060E, 0x47},
978         {0x060F, 0x90},
979         {0x0610, 0x06},
980         {0x0611, 0x0C},
981         {0x0612, 0x28},
982         {0x0613, 0x13},
983         {0x0614, 0x0B},
984         {0x0615, 0x10},
985         {0x0616, 0x14},
986         {0x0617, 0x19},
987         {0x0618, 0x52},
988         {0x0619, 0xA0},
989         {0x061A, 0x11},
990         {0x061B, 0x33},
991         {0x061C, 0x56},
992         {0x061D, 0x20},
993         {0x061E, 0x28},
994         {0x061F, 0x2B},
995         {0x0620, 0x22},
996         {0x0621, 0x11},
997         {0x0622, 0x75},
998         {0x0623, 0x49},
999         {0x0624, 0x6E},
1000         {0x0625, 0x80},
1001         {0x0626, 0x02},
1002         {0x0627, 0x0C},
1003         {0x0628, 0x51},
1004         {0x0629, 0x25},
1005         {0x062A, 0x01},
1006         {0x062B, 0x3D},
1007         {0x062C, 0x04},
1008         {0x062D, 0x01},
1009         {0x062E, 0x0C},
1010         {0x062F, 0x2C},
1011         {0x0630, 0x0D},
1012         {0x0631, 0x14},
1013         {0x0632, 0x12},
1014         {0x0633, 0x34},
1015         {0x0634, 0x00},
1016         {0x0635, 0x00},
1017         {0x0636, 0x00},
1018         {0x0637, 0xB1},
1019         {0x0638, 0x22},
1020         {0x0639, 0x32},
1021         {0x063A, 0x0E},
1022         {0x063B, 0x18},
1023         {0x063C, 0x88},
1024         {0x0640, 0xB2},
1025         {0x0641, 0xC0},
1026         {0x0642, 0x01},
1027         {0x0643, 0x26},
1028         {0x0644, 0x13},
1029         {0x0645, 0x88},
1030         {0x0646, 0x64},
1031         {0x0647, 0x00},
1032         {0x0681, 0x1B},
1033         {0x0682, 0xA0},
1034         {0x0683, 0x28},
1035         {0x0684, 0x00},
1036         {0x0685, 0xB0},
1037         {0x0686, 0x6F},
1038         {0x0687, 0x33},
1039         {0x0688, 0x1F},
1040         {0x0689, 0x44},
1041         {0x068A, 0xA8},
1042         {0x068B, 0x44},
1043         {0x068C, 0x08},
1044         {0x068D, 0x08},
1045         {0x068E, 0x00},
1046         {0x068F, 0x00},
1047         {0x0690, 0x01},
1048         {0x0691, 0x00},
1049         {0x0692, 0x01},
1050         {0x0693, 0x00},
1051         {0x0694, 0x00},
1052         {0x0695, 0x00},
1053         {0x0696, 0x00},
1054         {0x0697, 0x00},
1055         {0x0698, 0x2A},
1056         {0x0699, 0x80},
1057         {0x069A, 0x1F},
1058         {0x069B, 0x00},
1059         {0x069C, 0x02},
1060         {0x069D, 0xF5},
1061         {0x069E, 0x03},
1062         {0x069F, 0x6D},
1063         {0x06A0, 0x0C},
1064         {0x06A1, 0xB8},
1065         {0x06A2, 0x0D},
1066         {0x06A3, 0x74},
1067         {0x06A4, 0x00},
1068         {0x06A5, 0x2F},
1069         {0x06A6, 0x00},
1070         {0x06A7, 0x2F},
1071         {0x0F00, 0x00},
1072         {0x0F01, 0x00},
1073         {0x0100, 0x01},
1074         {0x0102, 0x02},
1075         {0x0104, 0x03},
1076 #endif
1077         {0x020B, 0x48},
1078         {0x020C, 0x64},
1079         {0x040A, 0x40},
1080         {0x040B, 0x33},
1081         {0x010c , 0x00},
1082         {0x010d , 0x08},
1083         {0x010e , 0x00},
1084         {0x010f , 0x08},
1085         {0x010a , 0x00},
1086         {0x0109, 0x00},
1087         {0x010A, 0x04},
1088         {0x010B, 0x03},
1089         {0x0110, 0x03},
1090         {0x0111, 0x20},
1091         {0x0112, 0x02},
1092         {0x0113, 0x58},
1093         {0x0116, 0x02},
1094         {0x0118, 0x40},
1095         {0x0119, 0x02},
1096         {0x011a, 0x04},
1097         {0x011B, 0x01},
1098         {0x0, 0x0},
1099 };
1100         
1101         
1102
1103 /* 640X480 VGA */
1104 static struct reginfo sensor_vga[] =
1105 {
1106    {0x020B , 0x48},
1107    {0x020C , 0x64},
1108    {0x040A , 0x40},
1109    {0x040B , 0x33},
1110    {0x0109 , 0x00},
1111    {0x010A , 0x04},
1112    {0x010B , 0x03},
1113    {0x010c , 0x00},
1114    {0x010d , 0xa8},
1115    {0x010e , 0x00},
1116    {0x010f , 0x60},
1117    {0x010a , 0x04},
1118    #if 1
1119    {0x0110 , 0x02},
1120    {0x0111 , 0x80},
1121    {0x0112 , 0x01},
1122    {0x0113 , 0xe0},
1123    #else
1124    {0x0110, 0x03},
1125    {0x0111, 0x20},
1126    {0x0112, 0x02},
1127    {0x0113, 0x58},
1128    #endif
1129    {0x0116 , 0x02},
1130    {0x0118 , 0x40},
1131    {0x0119 , 0x01},
1132    {0x011a , 0x04},
1133    {0x011B , 0x00},
1134    {0x0313 , 0x35},
1135    {0x0314 , 0x36},
1136    {0x0315 , 0x16}, 
1137    {0x0, 0x0},
1138 };
1139
1140 /* 352X288 CIF */
1141 static struct reginfo sensor_cif[] =
1142 {
1143     {0x0, 0x0},
1144 };
1145
1146 /* 320*240 QVGA */
1147 static  struct reginfo sensor_qvga[] =
1148 {
1149     
1150
1151     {0x0, 0x0},
1152 };
1153
1154 /* 176X144 QCIF*/
1155 static struct reginfo sensor_qcif[] =
1156 {
1157         
1158     {0x0, 0x0},
1159 };
1160 #if 0
1161 /* 160X120 QQVGA*/
1162 static struct reginfo gt2005_qqvga[] =
1163 {
1164
1165     {0x300E, 0x34},
1166     {0x3011, 0x01},
1167     {0x3012, 0x10},
1168     {0x302a, 0x02},
1169     {0x302b, 0xE6},
1170     {0x306f, 0x14},
1171     {0x3362, 0x90},
1172
1173     {0x3070, 0x5d},
1174     {0x3072, 0x5d},
1175     {0x301c, 0x07},
1176     {0x301d, 0x07},
1177
1178     {0x3020, 0x01},
1179     {0x3021, 0x18},
1180     {0x3022, 0x00},
1181     {0x3023, 0x06},
1182     {0x3024, 0x06},
1183     {0x3025, 0x58},
1184     {0x3026, 0x02},
1185     {0x3027, 0x61},
1186     {0x3088, 0x00},
1187     {0x3089, 0xa0},
1188     {0x308a, 0x00},
1189     {0x308b, 0x78},
1190     {0x3316, 0x64},
1191     {0x3317, 0x25},
1192     {0x3318, 0x80},
1193     {0x3319, 0x08},
1194     {0x331a, 0x0a},
1195     {0x331b, 0x07},
1196     {0x331c, 0x80},
1197     {0x331d, 0x38},
1198     {0x3100, 0x00},
1199     {0x3302, 0x11},
1200
1201     {0x0, 0x0},
1202 };
1203
1204
1205
1206 static  struct reginfo gt2005_Sharpness_auto[] =
1207 {
1208     {0x3306, 0x00},
1209 };
1210
1211 static  struct reginfo gt2005_Sharpness1[] =
1212 {
1213     {0x3306, 0x08},
1214     {0x3371, 0x00},
1215 };
1216
1217 static  struct reginfo gt2005_Sharpness2[][3] =
1218 {
1219     //Sharpness 2
1220     {0x3306, 0x08},
1221     {0x3371, 0x01},
1222 };
1223
1224 static  struct reginfo gt2005_Sharpness3[] =
1225 {
1226     //default
1227     {0x3306, 0x08},
1228     {0x332d, 0x02},
1229 };
1230 static  struct reginfo gt2005_Sharpness4[]=
1231 {
1232     //Sharpness 4
1233     {0x3306, 0x08},
1234     {0x332d, 0x03},
1235 };
1236
1237 static  struct reginfo gt2005_Sharpness5[] =
1238 {
1239     //Sharpness 5
1240     {0x3306, 0x08},
1241     {0x332d, 0x04},
1242 };
1243 #endif
1244
1245 static  struct reginfo sensor_ClrFmt_YUYV[]=
1246 {
1247     //{0x3400, 0x00},
1248     {0x0000, 0x00}
1249 };
1250
1251 static  struct reginfo sensor_ClrFmt_UYVY[]=
1252 {
1253     //{0x3400, 0x02},
1254     {0x0000, 0x00}
1255 };
1256
1257 #if CONFIG_SENSOR_WhiteBalance
1258 static  struct reginfo sensor_WhiteB_Auto[]=
1259 {
1260     {0x3306, 0x00},  //AWB auto, bit[1]:0,auto
1261     {0x0000, 0x00}
1262 };
1263 /* Cloudy Colour Temperature : 6500K - 8000K  */
1264 static  struct reginfo sensor_WhiteB_Cloudy[]=
1265 {
1266     {0x3306, 0x82},
1267     {0x3337, 0x68},
1268     {0x3338, 0x40},
1269     {0x3339, 0x4e},
1270     {0x0000, 0x00}
1271 };
1272 /* ClearDay Colour Temperature : 5000K - 6500K  */
1273 static  struct reginfo sensor_WhiteB_ClearDay[]=
1274 {
1275     //Sunny
1276     {0x3306, 0x02}, //AWB off
1277     {0x3337, 0x5e},
1278     {0x3338, 0x40},
1279     {0x3339, 0x46},
1280     {0x0000, 0x00}
1281 };
1282 /* Office Colour Temperature : 3500K - 5000K  */
1283 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
1284 {
1285     //Office
1286     {0x3306, 0x02},
1287     {0x3337, 0x52},
1288     {0x3338, 0x40},
1289     {0x3339, 0x58},
1290     {0x0000, 0x00}
1291
1292 };
1293 /* Home Colour Temperature : 2500K - 3500K  */
1294 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
1295 {
1296     //Home
1297     {0x3306, 0x02},
1298     {0x3337, 0x44},
1299     {0x3338, 0x40},
1300     {0x3339, 0x70},
1301     {0x0000, 0x00}
1302 };
1303 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1304     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1305 };
1306 #endif
1307
1308 #if CONFIG_SENSOR_Brightness
1309 static  struct reginfo sensor_Brightness0[]=
1310 {
1311     // Brightness -2
1312     {0x3301, 0xff},//bit[7]:1, enable SDE
1313     {0x3391, 0x04},
1314     {0x3390, 0x49},
1315     {0x339a, 0x20},
1316     {0x0000, 0x00}
1317 };
1318
1319 static  struct reginfo sensor_Brightness1[]=
1320 {
1321     // Brightness -1
1322     {0x3301, 0xff},//bit[7]:1, enable SDE
1323     {0x3391, 0x04},
1324     {0x3390, 0x49},
1325     {0x339a, 0x10},
1326     {0x0000, 0x00}
1327 };
1328
1329 static  struct reginfo sensor_Brightness2[]=
1330 {
1331     //  Brightness 0
1332     {0x3301, 0xff},//bit[7]:1, enable SDE
1333     {0x3391, 0x00},
1334     {0x3390, 0x41},
1335     {0x339a, 0x00},
1336     {0x0000, 0x00}
1337 };
1338
1339 static  struct reginfo sensor_Brightness3[]=
1340 {
1341     // Brightness +1
1342     {0x3301, 0xff},//bit[7]:1, enable SDE
1343     {0x3391, 0x04},
1344     {0x3390, 0x41},
1345     {0x339a, 0x10},
1346     {0x0000, 0x00}
1347 };
1348
1349 static  struct reginfo sensor_Brightness4[]=
1350 {
1351     //  Brightness +2
1352     {0x3301, 0xff},//bit[7]:1, enable SDE
1353     {0x3391, 0x04},
1354     {0x3390, 0x41},
1355     {0x339a, 0x20},
1356     {0x0000, 0x00}
1357 };
1358
1359 static  struct reginfo sensor_Brightness5[]=
1360 {
1361     //  Brightness +3
1362     {0x3301, 0xff},//bit[7]:1, enable SDE
1363     {0x3391, 0x04}, //bit[2] enable
1364     {0x3390, 0x41}, //bit[3] sign of brightness
1365     {0x339a, 0x30},
1366     {0x0000, 0x00}
1367 };
1368 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1369     sensor_Brightness4, sensor_Brightness5,NULL,
1370 };
1371
1372 #endif
1373
1374 #if CONFIG_SENSOR_Effect
1375 static  struct reginfo sensor_Effect_Normal[] =
1376 {
1377     {0x3391, 0x00},
1378     {0x0000, 0x00}
1379 };
1380
1381 static  struct reginfo sensor_Effect_WandB[] =
1382 {
1383     {0x3391, 0x20},
1384     {0x0000, 0x00}
1385 };
1386
1387 static  struct reginfo sensor_Effect_Sepia[] =
1388 {
1389     {0x3391, 0x18},
1390     {0x3396, 0x40},
1391     {0x3397, 0xa6},
1392     {0x0000, 0x00}
1393 };
1394
1395 static  struct reginfo sensor_Effect_Negative[] =
1396 {
1397     //Negative
1398     {0x3391, 0x40}, //bit[6] negative
1399     {0x0000, 0x00}
1400 };
1401 static  struct reginfo sensor_Effect_Bluish[] =
1402 {
1403     // Bluish
1404     {0x3391, 0x18},
1405     {0x3396, 0xa0},
1406     {0x3397, 0x40},
1407     {0x0000, 0x00}
1408 };
1409
1410 static  struct reginfo sensor_Effect_Green[] =
1411 {
1412     //  Greenish
1413     {0x3391, 0x18},
1414     {0x3396, 0x60},
1415     {0x3397, 0x60},
1416     {0x0000, 0x00}
1417 };
1418 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
1419     sensor_Effect_Bluish, sensor_Effect_Green,NULL,
1420 };
1421 #endif
1422 #if CONFIG_SENSOR_Exposure
1423 static  struct reginfo sensor_Exposure0[]=
1424 {
1425     //-3
1426     {0x3047, 0x05},
1427     {0x3018, 0x40},
1428     {0x3019, 0x30},
1429     {0x301a, 0x71},
1430     {0x0000, 0x00}
1431 };
1432
1433 static  struct reginfo sensor_Exposure1[]=
1434 {
1435     //-2
1436     {0x3047, 0x05},
1437     {0x3018, 0x5a},
1438     {0x3019, 0x4a},
1439     {0x301a, 0xc2},
1440     {0x0000, 0x00}
1441 };
1442
1443 static  struct reginfo sensor_Exposure2[]=
1444 {
1445     //-0.3EV
1446     {0x3047, 0x05},
1447     {0x3018, 0x6a},
1448     {0x3019, 0x5a},
1449     {0x301a, 0xd4},
1450     {0x0000, 0x00}
1451 };
1452
1453 static  struct reginfo sensor_Exposure3[]=
1454 {
1455     //default
1456     {0x3047, 0x05},
1457     {0x3018, 0x78},
1458     {0x3019, 0x68},
1459     {0x301a, 0xd4},
1460     {0x0000, 0x00}
1461 };
1462
1463 static  struct reginfo sensor_Exposure4[]=
1464 {
1465     // 1
1466     {0x3047, 0x05},
1467     {0x3018, 0x88},
1468     {0x3019, 0x78},
1469     {0x301a, 0xd5},
1470     {0x0000, 0x00}
1471 };
1472
1473 static  struct reginfo sensor_Exposure5[]=
1474 {
1475     // 2
1476     {0x3047, 0x05},
1477     {0x3018, 0xa8},
1478     {0x3019, 0x98},
1479     {0x301a, 0xe6},
1480     {0x0000, 0x00}
1481 };
1482
1483 static  struct reginfo sensor_Exposure6[]=
1484 {
1485     // 3
1486     {0x3047, 0x05},
1487     {0x3018, 0xc8},
1488     {0x3019, 0xb8},
1489     {0x301a, 0xf7},
1490     {0x0000, 0x00}
1491 };
1492
1493 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1494     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1495 };
1496 #endif
1497 #if CONFIG_SENSOR_Saturation
1498 static  struct reginfo sensor_Saturation0[]=
1499 {
1500     {0x3301, 0xff},//bit[7]:1, enable SDE
1501     {0x3391, 0x02},
1502     {0x3394, 0x40},
1503     {0x3395, 0x40},
1504     {0x0000, 0x00}
1505 };
1506
1507 static  struct reginfo sensor_Saturation1[]=
1508 {
1509     {0x3301, 0xff},//bit[7]:1, enable SDE
1510     {0x3391, 0x02},
1511     {0x3394, 0x50},
1512     {0x3395, 0x50},
1513     {0x0000, 0x00}
1514 };
1515
1516 static  struct reginfo sensor_Saturation2[]=
1517 {
1518     {0x3301, 0xff},//bit[7]:1, enable SDE
1519     {0x3391, 0x02}, //enable color saturation
1520     {0x3394, 0x70},
1521     {0x3395, 0x70},
1522     {0x0000, 0x00}
1523 };
1524 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1525
1526 #endif
1527 #if CONFIG_SENSOR_Contrast
1528 static  struct reginfo sensor_Contrast0[]=
1529 {
1530     //Contrast -3
1531     {0x3301, 0xff},//bit[7]:1, enable SDE
1532     {0x3391, 0x04},
1533     {0x3390, 0x45},
1534     {0x3398, 0x18},
1535     {0x3399, 0x18},
1536     {0x0000, 0x00}
1537 };
1538
1539 static  struct reginfo sensor_Contrast1[]=
1540 {
1541     //Contrast -2
1542     {0x3301, 0xff},//bit[7]:1, enable SDE
1543     {0x3391, 0x04},
1544     {0x3390, 0x45},
1545     {0x3398, 0x18},
1546     {0x3399, 0x18},
1547     {0x0000, 0x00}
1548 };
1549
1550 static  struct reginfo sensor_Contrast2[]=
1551 {
1552     // Contrast -1
1553     {0x3301, 0xff},//bit[7]:1, enable SDE
1554     {0x3391, 0x04},
1555     {0x3390, 0x45},
1556     {0x3398, 0x1c},
1557     {0x3399, 0x1c},
1558     {0x0000, 0x00}
1559 };
1560
1561 static  struct reginfo sensor_Contrast3[]=
1562 {
1563     //Contrast 0
1564     {0x3301, 0xff},//bit[7]:1, enable SDE
1565     {0x3391, 0x00},
1566     {0x3390, 0x41},
1567     {0x3398, 0x20},
1568     {0x3399, 0x20},
1569     {0x0000, 0x00}
1570 };
1571
1572 static  struct reginfo sensor_Contrast4[]=
1573 {
1574     //Contrast +1
1575     {0x3301, 0xff},//bit[7]:1, enable SDE
1576     {0x3391, 0x04},
1577     {0x3390, 0x45},
1578     {0x3398, 0x24},
1579     {0x3399, 0x24},
1580     {0x0000, 0x00}
1581 };
1582
1583
1584 static  struct reginfo sensor_Contrast5[]=
1585 {
1586     //Contrast +2
1587     {0x3301, 0xff},//bit[7]:1, enable SDE
1588     {0x3391, 0x04},
1589     {0x3390, 0x45},
1590     {0x3398, 0x28},
1591     {0x3399, 0x28},
1592     {0x0000, 0x00}
1593 };
1594
1595 static  struct reginfo sensor_Contrast6[]=
1596 {
1597     //Contrast +3
1598     {0x3301, 0xff},//bit[7]:1, enable SDE
1599     {0x3391, 0x04}, //bit[2] enable contrast/brightness
1600     {0x3390, 0x45}, //bit[2] Yoffset sign
1601     {0x3398, 0x2c},
1602     {0x3399, 0x2c},
1603     {0x0000, 0x00}
1604 };
1605 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1606     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1607 };
1608
1609 #endif
1610 #if CONFIG_SENSOR_Mirror
1611 static  struct reginfo sensor_MirrorOn[]=
1612 {
1613     {0x3069, 0x84},
1614     {0x307c, 0x13},
1615     {0x3087, 0x02},
1616     {0x0000, 0x00}
1617 };
1618
1619 static  struct reginfo sensor_MirrorOff[]=
1620 {
1621     {0x3069, 0x84},
1622     {0x307c, 0x10},
1623     {0x3087, 0x02},
1624     {0x0000, 0x00}
1625 };
1626 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1627 #endif
1628 #if CONFIG_SENSOR_Flip
1629 static  struct reginfo sensor_FlipOn[]=
1630 {
1631     {0x300e, 0x34},
1632     {0x300f, 0xa6},
1633     {0x3010, 0x81},
1634     {0x3082, 0x01},
1635     {0x30f4, 0x01},
1636     {0x3090, 0x3b},
1637     {0x3091, 0xc0},
1638     {0x30ac, 0x42},
1639     {0x0000, 0x00}
1640 };
1641
1642 static  struct reginfo sensor_FlipOff[]=
1643 {
1644     {0x300e, 0x34},
1645     {0x300f, 0xa6},
1646     {0x3010, 0x81},
1647     {0x3082, 0x01},
1648     {0x30f4, 0x01},
1649     {0x3090, 0x33},
1650     {0x3091, 0xc0},
1651     {0x30ac, 0x42},
1652     {0x0000, 0x00}
1653 };
1654 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1655
1656 #endif
1657 #if CONFIG_SENSOR_Scene
1658 static  struct reginfo sensor_SceneAuto[] =
1659 {
1660 #if 0                           /* ddl@rock-chips.com : */
1661     {0x3014, 0x04},
1662     {0x3015, 0x00},
1663     {0x302e, 0x00},
1664     {0x302d, 0x00},
1665     {0x0000, 0x00}
1666 #else
1667     {0x3014, 0x84},
1668     {0x3015, 0x02},
1669     {0x302e, 0x00},
1670     {0x302d, 0x00},
1671     {0x0000, 0x00}
1672 #endif
1673 };
1674
1675 static  struct reginfo sensor_SceneNight[] =
1676 {
1677 #if 1
1678     //30fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,36Mzh pclk
1679     {0x300e, 0x34},
1680     {0x3011, 0x00},
1681     {0x302c, 0x00},
1682     {0x3071, 0x00},
1683     {0x3070, 0xb9},
1684     {0x301c, 0x02},
1685     {0x3073, 0x00},
1686     {0x3072, 0x9a},
1687     {0x301d, 0x03},
1688     {0x3014, 0x0c},
1689     {0x3015, 0x50},//add 5 dummy frame
1690     {0x302e, 0x00},
1691     {0x302d, 0x00},
1692     {0x0000, 0x00}
1693 #else
1694     //15fps ~ 5fps night mode for 60/50Hz light environment, 24Mhz clock input,18Mhz pclk
1695     {0x300e, 0x34},
1696     {0x3011, 0x01},
1697     {0x302c, 0x00},
1698     {0x3071, 0x00},
1699     {0x3070, 0x5d},
1700     {0x301c, 0x05},
1701     {0x3073, 0x00},
1702     {0x3072, 0x4d},
1703     {0x301d, 0x07},
1704     {0x3014, 0x0c},
1705     {0x3015, 0x50},
1706     {0x302e, 0x00},
1707     {0x302d, 0x00},
1708 #endif
1709 };
1710 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1711
1712 #endif
1713 #if CONFIG_SENSOR_DigitalZoom
1714 static struct reginfo sensor_Zoom0[] =
1715 {
1716     {0x0, 0x0},
1717 };
1718
1719 static struct reginfo sensor_Zoom1[] =
1720 {
1721      {0x0, 0x0},
1722 };
1723
1724 static struct reginfo sensor_Zoom2[] =
1725 {
1726     {0x0, 0x0},
1727 };
1728
1729
1730 static struct reginfo sensor_Zoom3[] =
1731 {
1732     {0x0, 0x0},
1733 };
1734 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL,};
1735 #endif
1736 static const struct v4l2_querymenu sensor_menus[] =
1737 {
1738         #if CONFIG_SENSOR_WhiteBalance
1739     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
1740     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
1741     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
1742     #endif
1743
1744         #if CONFIG_SENSOR_Effect
1745     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
1746     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
1747     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},
1748     #endif
1749
1750         #if CONFIG_SENSOR_Scene
1751     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
1752     #endif
1753
1754         #if CONFIG_SENSOR_Flash
1755     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
1756     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
1757     #endif
1758 };
1759
1760 static const struct v4l2_queryctrl sensor_controls[] =
1761 {
1762         #if CONFIG_SENSOR_WhiteBalance
1763     {
1764         .id             = V4L2_CID_DO_WHITE_BALANCE,
1765         .type           = V4L2_CTRL_TYPE_MENU,
1766         .name           = "White Balance Control",
1767         .minimum        = 0,
1768         .maximum        = 4,
1769         .step           = 1,
1770         .default_value = 0,
1771     },
1772     #endif
1773
1774         #if CONFIG_SENSOR_Brightness
1775         {
1776         .id             = V4L2_CID_BRIGHTNESS,
1777         .type           = V4L2_CTRL_TYPE_INTEGER,
1778         .name           = "Brightness Control",
1779         .minimum        = -3,
1780         .maximum        = 2,
1781         .step           = 1,
1782         .default_value = 0,
1783     },
1784     #endif
1785
1786         #if CONFIG_SENSOR_Effect
1787         {
1788         .id             = V4L2_CID_EFFECT,
1789         .type           = V4L2_CTRL_TYPE_MENU,
1790         .name           = "Effect Control",
1791         .minimum        = 0,
1792         .maximum        = 5,
1793         .step           = 1,
1794         .default_value = 0,
1795     },
1796         #endif
1797
1798         #if CONFIG_SENSOR_Exposure
1799         {
1800         .id             = V4L2_CID_EXPOSURE,
1801         .type           = V4L2_CTRL_TYPE_INTEGER,
1802         .name           = "Exposure Control",
1803         .minimum        = 0,
1804         .maximum        = 6,
1805         .step           = 1,
1806         .default_value = 0,
1807     },
1808         #endif
1809
1810         #if CONFIG_SENSOR_Saturation
1811         {
1812         .id             = V4L2_CID_SATURATION,
1813         .type           = V4L2_CTRL_TYPE_INTEGER,
1814         .name           = "Saturation Control",
1815         .minimum        = 0,
1816         .maximum        = 2,
1817         .step           = 1,
1818         .default_value = 0,
1819     },
1820     #endif
1821
1822         #if CONFIG_SENSOR_Contrast
1823         {
1824         .id             = V4L2_CID_CONTRAST,
1825         .type           = V4L2_CTRL_TYPE_INTEGER,
1826         .name           = "Contrast Control",
1827         .minimum        = -3,
1828         .maximum        = 3,
1829         .step           = 1,
1830         .default_value = 0,
1831     },
1832         #endif
1833
1834         #if CONFIG_SENSOR_Mirror
1835         {
1836         .id             = V4L2_CID_HFLIP,
1837         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1838         .name           = "Mirror Control",
1839         .minimum        = 0,
1840         .maximum        = 1,
1841         .step           = 1,
1842         .default_value = 1,
1843     },
1844     #endif
1845
1846         #if CONFIG_SENSOR_Flip
1847         {
1848         .id             = V4L2_CID_VFLIP,
1849         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1850         .name           = "Flip Control",
1851         .minimum        = 0,
1852         .maximum        = 1,
1853         .step           = 1,
1854         .default_value = 1,
1855     },
1856     #endif
1857
1858         #if CONFIG_SENSOR_Scene
1859     {
1860         .id             = V4L2_CID_SCENE,
1861         .type           = V4L2_CTRL_TYPE_MENU,
1862         .name           = "Scene Control",
1863         .minimum        = 0,
1864         .maximum        = 1,
1865         .step           = 1,
1866         .default_value = 0,
1867     },
1868     #endif
1869
1870         #if CONFIG_SENSOR_DigitalZoom
1871     {
1872         .id             = V4L2_CID_ZOOM_RELATIVE,
1873         .type           = V4L2_CTRL_TYPE_INTEGER,
1874         .name           = "DigitalZoom Control",
1875         .minimum        = -1,
1876         .maximum        = 1,
1877         .step           = 1,
1878         .default_value = 0,
1879     }, {
1880         .id             = V4L2_CID_ZOOM_ABSOLUTE,
1881         .type           = V4L2_CTRL_TYPE_INTEGER,
1882         .name           = "DigitalZoom Control",
1883         .minimum        = 0,
1884         .maximum        = 3,
1885         .step           = 1,
1886         .default_value = 0,
1887     },
1888     #endif
1889
1890         #if CONFIG_SENSOR_Focus
1891         {
1892         .id             = V4L2_CID_FOCUS_RELATIVE,
1893         .type           = V4L2_CTRL_TYPE_INTEGER,
1894         .name           = "Focus Control",
1895         .minimum        = -1,
1896         .maximum        = 1,
1897         .step           = 1,
1898         .default_value = 0,
1899     }, {
1900         .id             = V4L2_CID_FOCUS_ABSOLUTE,
1901         .type           = V4L2_CTRL_TYPE_INTEGER,
1902         .name           = "Focus Control",
1903         .minimum        = 0,
1904         .maximum        = 255,
1905         .step           = 1,
1906         .default_value = 125,
1907     },
1908     #endif
1909
1910         #if CONFIG_SENSOR_Flash
1911         {
1912         .id             = V4L2_CID_FLASH,
1913         .type           = V4L2_CTRL_TYPE_MENU,
1914         .name           = "Flash Control",
1915         .minimum        = 0,
1916         .maximum        = 3,
1917         .step           = 1,
1918         .default_value = 0,
1919     },
1920         #endif
1921 };
1922
1923 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1924 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1925 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1926 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1927 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1928 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1929 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1930 static int sensor_resume(struct soc_camera_device *icd);
1931 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1932 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1933 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1934 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1935 static int sensor_deactivate(struct i2c_client *client);
1936
1937 static struct soc_camera_ops sensor_ops =
1938 {
1939     .suspend                     = sensor_suspend,
1940     .resume                       = sensor_resume,
1941     .set_bus_param              = sensor_set_bus_param,
1942     .query_bus_param    = sensor_query_bus_param,
1943     .controls           = sensor_controls,
1944     .menus                         = sensor_menus,
1945     .num_controls               = ARRAY_SIZE(sensor_controls),
1946     .num_menus          = ARRAY_SIZE(sensor_menus),
1947 };
1948
1949 /* only one fixed colorspace per pixelcode */
1950 struct sensor_datafmt {
1951         enum v4l2_mbus_pixelcode code;
1952         enum v4l2_colorspace colorspace;
1953 };
1954
1955 /* Find a data format by a pixel code in an array */
1956 static const struct sensor_datafmt *sensor_find_datafmt(
1957         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1958         int n)
1959 {
1960         int i;
1961         for (i = 0; i < n; i++)
1962                 if (fmt[i].code == code)
1963                         return fmt + i;
1964
1965         return NULL;
1966 }
1967
1968 static const struct sensor_datafmt sensor_colour_fmts[] = {
1969     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1970     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
1971 };
1972
1973 typedef struct sensor_info_priv_s
1974 {
1975     int whiteBalance;
1976     int brightness;
1977     int contrast;
1978     int saturation;
1979     int effect;
1980     int scene;
1981     int digitalzoom;
1982     int focus;
1983     int flash;
1984     int exposure;
1985         bool snap2preview;
1986         bool video2preview;
1987     unsigned char mirror;                                        /* HFLIP */
1988     unsigned char flip;                                          /* VFLIP */
1989     unsigned int winseqe_cur_addr;
1990     struct sensor_datafmt fmt;
1991     unsigned int funmodule_state;
1992 } sensor_info_priv_t;
1993
1994 struct sensor
1995 {
1996     struct v4l2_subdev subdev;
1997     struct i2c_client *client;
1998     sensor_info_priv_t info_priv;
1999     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2000 #if CONFIG_SENSOR_I2C_NOSCHED
2001         atomic_t tasklock_cnt;
2002 #endif
2003         struct rk29camera_platform_data *sensor_io_request;
2004     struct rk29camera_gpio_res *sensor_gpio_res;
2005 };
2006
2007 static struct sensor* to_sensor(const struct i2c_client *client)
2008 {
2009     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2010 }
2011
2012 static int sensor_task_lock(struct i2c_client *client, int lock)
2013 {
2014 #if CONFIG_SENSOR_I2C_NOSCHED
2015         int cnt = 3;
2016     struct sensor *sensor = to_sensor(client);
2017
2018         if (lock) {
2019                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2020                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2021                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2022                                 msleep(35);
2023                                 cnt--;
2024                         }
2025                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2026                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2027                                 goto sensor_task_lock_err;
2028                         }
2029                         preempt_disable();
2030                 }
2031
2032                 atomic_add(1, &sensor->tasklock_cnt);
2033         } else {
2034                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2035                         atomic_sub(1, &sensor->tasklock_cnt);
2036
2037                         if (atomic_read(&sensor->tasklock_cnt) == 0)
2038                                 preempt_enable();
2039                 }
2040         }
2041         return 0;
2042 sensor_task_lock_err:
2043         return -1; 
2044 #else
2045     return 0;
2046 #endif
2047
2048 }
2049
2050 /* sensor register write */
2051 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
2052 {
2053     int err,cnt;
2054     u8 buf[3];
2055     struct i2c_msg msg[1];
2056
2057     buf[0] = reg >> 8;
2058     buf[1] = reg & 0xFF;
2059     buf[2] = val;
2060
2061     msg->addr = client->addr;
2062     msg->flags = client->flags;
2063     msg->buf = buf;
2064     msg->len = sizeof(buf);
2065     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
2066     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2067
2068     cnt = 3;
2069     err = -EAGAIN;
2070
2071     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2072         err = i2c_transfer(client->adapter, msg, 1);
2073
2074         if (err >= 0) {
2075             return 0;
2076         } else {
2077                 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
2078             udelay(10);
2079         }
2080     }
2081
2082     return err;
2083 }
2084
2085 /* sensor register read */
2086 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
2087 {
2088     int err,cnt;
2089     u8 buf[2];
2090     struct i2c_msg msg[2];
2091
2092     buf[0] = reg >> 8;
2093     buf[1] = reg & 0xFF;
2094
2095     msg[0].addr = client->addr;
2096     msg[0].flags = client->flags;
2097     msg[0].buf = buf;
2098     msg[0].len = sizeof(buf);
2099     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
2100     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2101
2102     msg[1].addr = client->addr;
2103     msg[1].flags = client->flags|I2C_M_RD;
2104     msg[1].buf = buf;
2105     msg[1].len = 1;
2106     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
2107     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2108
2109     cnt = 3;
2110     err = -EAGAIN;
2111     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2112         err = i2c_transfer(client->adapter, msg, 2);
2113
2114         if (err >= 0) {
2115             *val = buf[0];
2116             return 0;
2117         } else {
2118                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2119             udelay(10);
2120         }
2121     }
2122
2123     return err;
2124 }
2125
2126 /* write a array of registers  */
2127 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2128 {
2129     int err = 0, cnt;
2130     int i = 0;
2131 #if CONFIG_SENSOR_I2C_RDWRCHK    
2132         char valchk;
2133 #endif
2134
2135         cnt = 0;
2136         if (sensor_task_lock(client, 1) < 0)
2137                 goto sensor_write_array_end;
2138
2139     while (regarray[i].reg != 0)
2140     {
2141         err = sensor_write(client, regarray[i].reg, regarray[i].val);
2142         if (err < 0)
2143         {
2144             if (cnt-- > 0) {
2145                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2146                                 i = 0;
2147                                 continue;
2148             } else {
2149                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2150                 err = -EPERM;
2151                                 goto sensor_write_array_end;
2152             }
2153         } else {
2154         #if CONFIG_SENSOR_I2C_RDWRCHK
2155                         sensor_read(client, regarray[i].reg, &valchk);
2156                         if (valchk != regarray[i].val)
2157                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2158                 #endif
2159         }
2160         i++;
2161     }
2162
2163 sensor_write_array_end:
2164         sensor_task_lock(client,0);
2165         return err;
2166 }
2167
2168 #if CONFIG_SENSOR_I2C_RDWRCHK
2169 static int sensor_check_array(struct i2c_client *client, struct reginfo *regarray)
2170 {
2171   int ret;
2172   int i = 0,j=0;  
2173   u8 value;
2174   
2175   SENSOR_DG("%s >>>>>>>>>>>>>>>>>>>>>>\n",__FUNCTION__);
2176   while(regarray[i].reg != 0)
2177   {
2178      ret = sensor_read(client,regarray[i].reg,&value);
2179          if(ret !=0)
2180          {
2181           SENSOR_TR("read value failed\n");
2182
2183          }
2184          if(regarray[i].val != value)
2185          {
2186           SENSOR_DG("%s reg[0x%x] check err,writte :0x%x  read:0x%x\n",__FUNCTION__,regarray[i].reg,regarray[i].val,value);
2187          }
2188          else
2189           j++;
2190          
2191          i++;
2192   }
2193   if(i==j)
2194          SENSOR_DG("%s check success\n",__FUNCTION__);
2195         
2196   return 0;
2197 }
2198 #endif
2199 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2200 {
2201         struct soc_camera_link *icl = to_soc_camera_link(icd);
2202         int ret = 0;
2203
2204     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2205         switch (cmd)
2206         {
2207                 case Sensor_PowerDown:
2208                 {
2209                         if (icl->powerdown) {
2210                                 ret = icl->powerdown(icd->pdev, on);
2211                                 if (ret == RK29_CAM_IO_SUCCESS) {
2212                                         if (on == 0) {
2213                                                 mdelay(2);
2214                                                 if (icl->reset)
2215                                                         icl->reset(icd->pdev);
2216                                         }
2217                                 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2218                                         ret = -ENODEV;
2219                                         goto sensor_power_end;
2220                                 }
2221                         }
2222                         break;
2223                 }
2224                 case Sensor_Flash:
2225                 {
2226                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2227                 struct sensor *sensor = to_sensor(client);
2228
2229                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2230                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2231                         }
2232             break;
2233                 }
2234                 default:
2235                 {
2236                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2237                         break;
2238                 }
2239         }
2240 sensor_power_end:
2241         return ret;
2242 }
2243 static s32 sensor_init_width = 640;
2244 static s32 sensor_init_height = 480;
2245 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);
2246 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
2247 static struct reginfo* sensor_init_data_p = NULL;
2248 static struct reginfo* sensor_init_winseq_p = NULL;
2249 static struct reginfo* sensor_init_winseq_board = NULL;
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 rk29camera_platform_data* tmp_plat_data =(struct rk29camera_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 && (u32)tmp_plat_data != 1) { 
2266                 for(i = 0;i < RK_CAM_NUM;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  && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && 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 RK29_CAM_SUBDEV_DEACTIVATE:
3523                 {
3524                         sensor_deactivate(client);
3525                         break;
3526                 }
3527
3528                 case RK29_CAM_SUBDEV_IOREQUEST:
3529                 {
3530                         sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;                       
3531                         if (sensor->sensor_io_request != NULL) { 
3532                         int j = 0;
3533                         for(j = 0;j < RK_CAM_NUM;j++){
3534                                         if (sensor->sensor_io_request->gpio_res[j].dev_name && 
3535                                                 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
3536                                                 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
3537                                 break;
3538                                           } 
3539                         }
3540                         if(j == RK_CAM_NUM){
3541                                 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3542                                 ret = -EINVAL;
3543                                 goto sensor_ioctl_end;
3544                                 }
3545                                 }
3546             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
3547                for this project */
3548             #if CONFIG_SENSOR_Flash     
3549                 if (sensor->sensor_gpio_res) {
3550                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3551                     for (i = 0; i < icd->ops->num_controls; i++) {
3552                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3553                                         memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                       
3554                                 }
3555                     }
3556                     sensor->info_priv.flash = 0xff;
3557                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3558                 }
3559                 }
3560             #endif
3561                         break;
3562                 }
3563                 default:
3564                 {
3565                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3566                         break;
3567                 }
3568         }
3569 sensor_ioctl_end:
3570         return ret;
3571
3572 }
3573 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3574                             enum v4l2_mbus_pixelcode *code)
3575 {
3576         if (index >= ARRAY_SIZE(sensor_colour_fmts))
3577                 return -EINVAL;
3578
3579         *code = sensor_colour_fmts[index].code;
3580         return 0;
3581 }
3582 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3583         .init           = sensor_init,
3584         .g_ctrl         = sensor_g_control,
3585         .s_ctrl         = sensor_s_control,
3586         .g_ext_ctrls          = sensor_g_ext_controls,
3587         .s_ext_ctrls          = sensor_s_ext_controls,
3588         .g_chip_ident   = sensor_g_chip_ident,
3589         .ioctl = sensor_ioctl,
3590 };
3591
3592 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3593         .s_mbus_fmt     = sensor_s_fmt,
3594         .g_mbus_fmt     = sensor_g_fmt,
3595         .try_mbus_fmt   = sensor_try_fmt,
3596         .enum_mbus_fmt  = sensor_enum_fmt,
3597 };
3598
3599 static struct v4l2_subdev_ops sensor_subdev_ops = {
3600         .core   = &sensor_subdev_core_ops,
3601         .video = &sensor_subdev_video_ops,
3602 };
3603
3604 static int sensor_probe(struct i2c_client *client,
3605                          const struct i2c_device_id *did)
3606 {
3607     struct sensor *sensor;
3608     struct soc_camera_device *icd = client->dev.platform_data;
3609     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3610     struct soc_camera_link *icl;
3611     int ret;
3612
3613     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3614     if (!icd) {
3615         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3616         return -EINVAL;
3617     }
3618
3619     icl = to_soc_camera_link(icd);
3620     if (!icl) {
3621         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3622         return -EINVAL;
3623     }
3624
3625     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3626         dev_warn(&adapter->dev,
3627                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3628         return -EIO;
3629     }
3630
3631     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3632     if (!sensor)
3633         return -ENOMEM;
3634
3635     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3636
3637     /* Second stage probe - when a capture adapter is there */
3638     icd->ops            = &sensor_ops;
3639
3640     sensor->info_priv.fmt = sensor_colour_fmts[0];
3641     
3642         #if CONFIG_SENSOR_I2C_NOSCHED
3643         atomic_set(&sensor->tasklock_cnt,0);
3644         #endif
3645
3646     ret = sensor_video_probe(icd, client);
3647     if (ret < 0) {
3648         icd->ops = NULL;
3649         i2c_set_clientdata(client, NULL);
3650         kfree(sensor);
3651                 sensor = NULL;
3652     }
3653     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3654     return ret;
3655 }
3656
3657 static int sensor_remove(struct i2c_client *client)
3658 {
3659     struct sensor *sensor = to_sensor(client);
3660     struct soc_camera_device *icd = client->dev.platform_data;
3661
3662     icd->ops = NULL;
3663     i2c_set_clientdata(client, NULL);
3664     client->driver = NULL;
3665     kfree(sensor);
3666
3667     return 0;
3668 }
3669
3670 static const struct i2c_device_id sensor_id[] = {
3671         {SENSOR_NAME_STRING(), 0 },
3672         { }
3673 };
3674 MODULE_DEVICE_TABLE(i2c, sensor_id);
3675
3676 static struct i2c_driver sensor_i2c_driver = {
3677         .driver = {
3678                 .name = SENSOR_NAME_STRING(),
3679         },
3680         .probe          = sensor_probe,
3681         .remove         = sensor_remove,
3682         .id_table       = sensor_id,
3683 };
3684
3685 static int __init sensor_mod_init(void)
3686 {
3687     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3688     return i2c_add_driver(&sensor_i2c_driver);
3689 }
3690
3691 static void __exit sensor_mod_exit(void)
3692 {
3693     i2c_del_driver(&sensor_i2c_driver);
3694 }
3695
3696 device_initcall_sync(sensor_mod_init);
3697 module_exit(sensor_mod_exit);
3698
3699 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3700 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3701 MODULE_LICENSE("GPL");
3702