camsys_drv: v0.0x16.0
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / hm5065_old.c
1 /*
2  * Driver for HM5065 CMOS Image Sensor from Himax
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 "hm5065.h"
24 //#include <linux/wine_sysinf.h>
25 struct reginfo
26 {
27     u16 reg;
28     u8 val;
29 };
30 static int debug=1;
31 module_param(debug, int, S_IRUGO|S_IWUSR);
32
33 #define dprintk(level, fmt, arg...) do {                        \
34         if (debug >= level)                                     \
35         printk(KERN_WARNING fmt , ## arg); } while (0)
36
37 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
38 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
39
40 #define _CONS(a,b) a##b
41 #define CONS(a,b) _CONS(a,b)
42
43 #define __STR(x) #x
44 #define _STR(x) __STR(x)
45 #define STR(x) _STR(x)
46
47 #define MIN(x,y)   ((x<y) ? x: y)
48 #define MAX(x,y)    ((x>y) ? x: y)
49
50 /* Sensor Driver Configuration */
51 #define SENSOR_NAME RK29_CAM_SENSOR_HM5065
52 #define SENSOR_V4L2_IDENT V4L2_IDENT_HM5065
53 #define SENSOR_ID 0x039E
54 #define SENSOR_MIN_WIDTH    176
55 #define SENSOR_MIN_HEIGHT   144
56 #define SENSOR_MAX_WIDTH    2592
57 #define SENSOR_MAX_HEIGHT   1944
58 #define SENSOR_INIT_WIDTH         800                   //640/* Sensor pixel size for sensor_init_data array */
59 #define SENSOR_INIT_HEIGHT  600   //480
60 #define SENSOR_INIT_WINSEQADR sensor_svga
61 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_YUYV8_2X8
62
63 #define CONFIG_SENSOR_WhiteBalance      1
64 #define CONFIG_SENSOR_Brightness        1
65 #define CONFIG_SENSOR_Contrast      1
66 #define CONFIG_SENSOR_Saturation    1
67 #define CONFIG_SENSOR_Effect        1
68 #define CONFIG_SENSOR_Scene         1
69 #define CONFIG_SENSOR_DigitalZoom   0
70 #define CONFIG_SENSOR_Exposure      0
71 #define CONFIG_SENSOR_Flash         1
72 #define CONFIG_SENSOR_Mirror        0
73 #define CONFIG_SENSOR_Flip          0
74 #define CONFIG_SENSOR_Focus         1
75
76 #define CONFIG_SENSOR_I2C_SPEED    100000       /* Hz */
77 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
78 #define CONFIG_SENSOR_I2C_NOSCHED   0
79 #define CONFIG_SENSOR_I2C_RDWRCHK   0
80
81 #define CONFIG_SENSOR_WRITE_REGS  1
82 #define WRITE_REGS_NUM 3
83
84 #define SENSOR_BUS_PARAM  (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
85                           SOCAM_HSYNC_ACTIVE_HIGH| SOCAM_VSYNC_ACTIVE_LOW |\
86                           SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ)
87
88 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
89 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
90 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
91 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
92 #define COLOR_TEMPERATURE_OFFICE_DN     3500
93 #define COLOR_TEMPERATURE_OFFICE_UP     5000
94 #define COLOR_TEMPERATURE_HOME_DN       2500
95 #define COLOR_TEMPERATURE_HOME_UP       3500
96
97 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
98 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
99
100 #define SENSOR_AF_IS_ERR    (0x00<<0)
101 #define SENSOR_AF_IS_OK         (0x01<<0)
102 #define SENSOR_INIT_IS_ERR   (0x00<<28)
103 #define SENSOR_INIT_IS_OK    (0x01<<28)
104
105 #if CONFIG_SENSOR_Focus
106 /*#define SENSOR_AF_MODE_INFINITY    0
107 #define SENSOR_AF_MODE_MACRO       1
108 #define SENSOR_AF_MODE_FIXED       2
109 #define SENSOR_AF_MODE_AUTO        3
110 #define SENSOR_AF_MODE_CONTINUOUS  4
111 #define SENSOR_AF_MODE_CLOSE       5*/
112 #define SENSOR_AF_MODE_AUTO        0
113 #define SENSOR_AF_MODE_CLOSE       1
114 #define SENSOR_AF_MODE_CONTINUOUS  2
115 #endif
116
117 #if CONFIG_SENSOR_Focus
118 /* hm5065 VCM Command and Status Registers */
119 #define AF_TARGETPOS_REG_H         0x0700
120 #define AF_TARGETPOS_REG_L         0x0701
121
122 #define AF_MODES_REG               0x070A
123 #define AF_AUTOCMDS_REG            0x070b
124 #define AF_LENSPOS_REG_H           0x06F0
125 #define AF_LENSPOS_REG_L           0x06F1
126 #define AF_MANUCMDS_REG            0x070c
127 #define AF_FINISHCHK_REG           0x07ae   //[0]: false    [1] : true
128
129 #define FACE_LC                    0x0714   //[0] : focus , [1] : AE Â\93\84Ó
130 #define FACE_START_XH              0x0715
131 #define FACE_START_XL              0x0716
132 #define FACE_SIZE_XH               0x0717
133 #define FACE_SIZE_XL               0x0718
134 #define FACE_START_YH              0x0719
135 #define FACE_START_YL              0x071A
136 #define FACE_SIZE_YH               0x071B
137 #define FACE_SIZE_YL               0x071C
138
139
140 #define AF_ZONE0_WEIGHT            0x0808
141 #define AF_ZONE1_WEIGHT            0x0809
142 #define AF_ZONE2_WEIGHT            0x080A
143 #define AF_ZONE3_WEIGHT            0x080B
144 #define AF_ZONE4_WEIGHT            0x080C
145 #define AF_ZONE5_WEIGHT            0x080D
146 #define AF_ZONE6_WEIGHT            0x080E
147
148 #endif
149
150 //flash off in fixed time to prevent from too hot , zyc
151 struct  flash_timer{
152     struct soc_camera_device *icd;
153         struct hrtimer timer;
154 };
155 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
156
157 static struct  flash_timer flash_off_timer;
158 //for user defined if user want to customize the series , zyc
159 #ifdef CONFIG_HM5065_USER_DEFINED_SERIES
160 #include "hm5065_user_series.c"
161 #else
162
163
164 static struct reginfo sensor_init_data[] =
165 {
166 #if 1
167         {0xffff,0x01},    // 2013-03-01 Start new patch 
168         {0x9000,0x03}, 
169         {0xA000,0x90}, 
170         {0xA001,0x0C}, 
171         {0xA002,0x56}, 
172         {0xA003,0xE0}, 
173         {0xA004,0xFE}, 
174         {0xA005,0xA3}, 
175         {0xA006,0xE0}, 
176         {0xA007,0xFF}, 
177         {0xA008,0x12}, 
178         {0xA009,0x42}, 
179         {0xA00A,0x85}, 
180         {0xA00B,0x90}, 
181         {0xA00C,0x01}, 
182         {0xA00D,0xB7}, 
183         {0xA00E,0xEE}, 
184         {0xA00F,0xF0}, 
185         {0xA010,0xFC}, 
186         {0xA011,0xA3}, 
187         {0xA012,0xEF}, 
188         {0xA013,0xF0}, 
189         {0xA014,0xFD}, 
190         {0xA015,0x90}, 
191         {0xA016,0x06}, 
192         {0xA017,0x05}, 
193         {0xA018,0xE0}, 
194         {0xA019,0x75}, 
195         {0xA01A,0xF0}, 
196         {0xA01B,0x02}, 
197         {0xA01C,0xA4}, 
198         {0xA01D,0x2D}, 
199         {0xA01E,0xFF}, 
200         {0xA01F,0xE5}, 
201         {0xA020,0xF0}, 
202         {0xA021,0x3C}, 
203         {0xA022,0xFE}, 
204         {0xA023,0xAB}, 
205         {0xA024,0x07}, 
206         {0xA025,0xFA}, 
207         {0xA026,0x33}, 
208         {0xA027,0x95}, 
209         {0xA028,0xE0}, 
210         {0xA029,0xF9}, 
211         {0xA02A,0xF8}, 
212         {0xA02B,0x90}, 
213         {0xA02C,0x0B}, 
214         {0xA02D,0x4B}, 
215         {0xA02E,0xE0}, 
216         {0xA02F,0xFE}, 
217         {0xA030,0xA3}, 
218         {0xA031,0xE0}, 
219         {0xA032,0xFF}, 
220         {0xA033,0xEE}, 
221         {0xA034,0x33}, 
222         {0xA035,0x95}, 
223         {0xA036,0xE0}, 
224         {0xA037,0xFD}, 
225         {0xA038,0xFC}, 
226         {0xA039,0x12}, 
227         {0xA03A,0x0C}, 
228         {0xA03B,0x7B}, 
229         {0xA03C,0x90}, 
230         {0xA03D,0x01}, 
231         {0xA03E,0xB9}, 
232         {0xA03F,0x12}, 
233         {0xA040,0x0E}, 
234         {0xA041,0x05}, 
235         {0xA042,0x90}, 
236         {0xA043,0x01}, 
237         {0xA044,0xB9}, 
238         {0xA045,0xE0}, 
239         {0xA046,0xFC}, 
240         {0xA047,0xA3}, 
241         {0xA048,0xE0}, 
242         {0xA049,0xFD}, 
243         {0xA04A,0xA3}, 
244         {0xA04B,0xE0}, 
245         {0xA04C,0xFE}, 
246         {0xA04D,0xA3}, 
247         {0xA04E,0xE0}, 
248         {0xA04F,0xFF}, 
249         {0xA050,0x78}, 
250         {0xA051,0x08}, 
251         {0xA052,0x12}, 
252         {0xA053,0x0D}, 
253         {0xA054,0xBF}, 
254         {0xA055,0xA8}, 
255         {0xA056,0x04}, 
256         {0xA057,0xA9}, 
257         {0xA058,0x05}, 
258         {0xA059,0xAA}, 
259         {0xA05A,0x06}, 
260         {0xA05B,0xAB}, 
261         {0xA05C,0x07}, 
262         {0xA05D,0x90}, 
263         {0xA05E,0x0B}, 
264         {0xA05F,0x49}, 
265         {0xA060,0xE0}, 
266         {0xA061,0xFE}, 
267         {0xA062,0xA3}, 
268         {0xA063,0xE0}, 
269         {0xA064,0xFF}, 
270         {0xA065,0xEE}, 
271         {0xA066,0x33}, 
272         {0xA067,0x95}, 
273         {0xA068,0xE0}, 
274         {0xA069,0xFD}, 
275         {0xA06A,0xFC}, 
276         {0xA06B,0xC3}, 
277         {0xA06C,0xEF}, 
278         {0xA06D,0x9B}, 
279         {0xA06E,0xFF}, 
280         {0xA06F,0xEE}, 
281         {0xA070,0x9A}, 
282         {0xA071,0xFE}, 
283         {0xA072,0xED}, 
284         {0xA073,0x99}, 
285         {0xA074,0xFD}, 
286         {0xA075,0xEC}, 
287         {0xA076,0x98}, 
288         {0xA077,0xFC}, 
289         {0xA078,0x78}, 
290         {0xA079,0x01}, 
291         {0xA07A,0x12}, 
292         {0xA07B,0x0D}, 
293         {0xA07C,0xBF}, 
294         {0xA07D,0x90}, 
295         {0xA07E,0x0C}, 
296         {0xA07F,0x4A}, 
297         {0xA080,0xE0}, 
298         {0xA081,0xFC}, 
299         {0xA082,0xA3}, 
300         {0xA083,0xE0}, 
301         {0xA084,0xF5}, 
302         {0xA085,0x82}, 
303         {0xA086,0x8C}, 
304         {0xA087,0x83}, 
305         {0xA088,0xC0}, 
306         {0xA089,0x83}, 
307         {0xA08A,0xC0}, 
308         {0xA08B,0x82}, 
309         {0xA08C,0x90}, 
310         {0xA08D,0x0B}, 
311         {0xA08E,0x48}, 
312         {0xA08F,0xE0}, 
313         {0xA090,0xD0}, 
314         {0xA091,0x82}, 
315         {0xA092,0xD0}, 
316         {0xA093,0x83}, 
317         {0xA094,0x75}, 
318         {0xA095,0xF0}, 
319         {0xA096,0x02}, 
320         {0xA097,0x12}, 
321         {0xA098,0x0E}, 
322         {0xA099,0x45}, 
323         {0xA09A,0xEE}, 
324         {0xA09B,0xF0}, 
325         {0xA09C,0xA3}, 
326         {0xA09D,0xEF}, 
327         {0xA09E,0xF0}, 
328         {0xA09F,0x02}, 
329         {0xA0A0,0xBA}, 
330         {0xA0A1,0xD8}, 
331         {0xA0A2,0x90}, 
332         {0xA0A3,0x30}, 
333         {0xA0A4,0x18}, 
334         {0xA0A5,0xe4}, 
335         {0xA0A6,0xf0}, 
336         {0xA0A7,0x74}, 
337         {0xA0A8,0x3f}, 
338         {0xA0A9,0xf0}, 
339         {0xA0AA,0x22}, 
340         {0xA0BF,0x90}, 
341         {0xA0C0,0x00}, 
342         {0xA0C1,0x5E}, 
343         {0xA0C2,0xE0}, 
344         {0xA0C3,0xFF}, 
345         {0xA0C4,0x70}, 
346         {0xA0C5,0x20}, 
347         {0xA0C6,0x90}, 
348         {0xA0C7,0x47}, 
349         {0xA0C8,0x04}, 
350         {0xA0C9,0x74}, 
351         {0xA0CA,0x0A}, 
352         {0xA0CB,0xF0}, 
353         {0xA0CC,0xA3}, 
354         {0xA0CD,0x74}, 
355         {0xA0CE,0x30}, 
356         {0xA0CF,0xF0}, 
357         {0xA0D0,0x90}, 
358         {0xA0D1,0x47}, 
359         {0xA0D2,0x0C}, 
360         {0xA0D3,0x74}, 
361         {0xA0D4,0x07}, 
362         {0xA0D5,0xF0}, 
363         {0xA0D6,0xA3}, 
364         {0xA0D7,0x74}, 
365         {0xA0D8,0xA8}, 
366         {0xA0D9,0xF0}, 
367         {0xA0DA,0x90}, 
368         {0xA0DB,0x47}, 
369         {0xA0DC,0xA4}, 
370         {0xA0DD,0x74}, 
371         {0xA0DE,0x01}, 
372         {0xA0DF,0xF0}, 
373         {0xA0E0,0x90}, 
374         {0xA0E1,0x47}, 
375         {0xA0E2,0xA8}, 
376         {0xA0E3,0xF0}, 
377         {0xA0E4,0x80}, 
378         {0xA0E5,0x50}, 
379         {0xA0E6,0xEF}, 
380         {0xA0E7,0x64}, 
381         {0xA0E8,0x01}, 
382         {0xA0E9,0x60}, 
383         {0xA0EA,0x04}, 
384         {0xA0EB,0xEF}, 
385         {0xA0EC,0xB4}, 
386         {0xA0ED,0x03}, 
387         {0xA0EE,0x20}, 
388         {0xA0EF,0x90}, 
389         {0xA0F0,0x47}, 
390         {0xA0F1,0x04}, 
391         {0xA0F2,0x74}, 
392         {0xA0F3,0x05}, 
393         {0xA0F4,0xF0}, 
394         {0xA0F5,0xA3}, 
395         {0xA0F6,0x74}, 
396         {0xA0F7,0x18}, 
397         {0xA0F8,0xF0}, 
398         {0xA0F9,0x90}, 
399         {0xA0FA,0x47}, 
400         {0xA0FB,0x0C}, 
401         {0xA0FC,0x74}, 
402         {0xA0FD,0x03}, 
403         {0xA0FE,0xF0}, 
404         {0xA0FF,0xA3}, 
405         {0xA100,0x74}, 
406         {0xA101,0xD4}, 
407         {0xA102,0xF0}, 
408         {0xA103,0x90}, 
409         {0xA104,0x47}, 
410         {0xA105,0xA4}, 
411         {0xA106,0x74}, 
412         {0xA107,0x02}, 
413         {0xA108,0xF0}, 
414         {0xA109,0x90}, 
415         {0xA10A,0x47}, 
416         {0xA10B,0xA8}, 
417         {0xA10C,0xF0}, 
418         {0xA10D,0x80}, 
419         {0xA10E,0x27}, 
420         {0xA10F,0xEF}, 
421         {0xA110,0x64}, 
422         {0xA111,0x02}, 
423         {0xA112,0x60}, 
424         {0xA113,0x04}, 
425         {0xA114,0xEF}, 
426         {0xA115,0xB4}, 
427         {0xA116,0x04}, 
428         {0xA117,0x1E}, 
429         {0xA118,0x90}, 
430         {0xA119,0x47}, 
431         {0xA11A,0x04}, 
432         {0xA11B,0x74}, 
433         {0xA11C,0x02}, 
434         {0xA11D,0xF0}, 
435         {0xA11E,0xA3}, 
436         {0xA11F,0x74}, 
437         {0xA120,0x8C}, 
438         {0xA121,0xF0}, 
439         {0xA122,0x90}, 
440         {0xA123,0x47}, 
441         {0xA124,0x0C}, 
442         {0xA125,0x74}, 
443         {0xA126,0x01}, 
444         {0xA127,0xF0}, 
445         {0xA128,0xA3}, 
446         {0xA129,0x74}, 
447         {0xA12A,0xEA}, 
448         {0xA12B,0xF0}, 
449         {0xA12C,0x90}, 
450         {0xA12D,0x47}, 
451         {0xA12E,0xA4}, 
452         {0xA12F,0x74}, 
453         {0xA130,0x04}, 
454         {0xA131,0xF0}, 
455         {0xA132,0x90}, 
456         {0xA133,0x47}, 
457         {0xA134,0xA8}, 
458         {0xA135,0xF0}, 
459         {0xA136,0x22}, 
460         {0xA137,0x74}, 
461         {0xA138,0x04}, 
462         {0xA139,0xF0}, 
463         {0xA13A,0xA3}, 
464         {0xA13B,0x74}, 
465         {0xA13C,0x20}, 
466         {0xA13D,0xF0}, 
467         {0xA13E,0xE4}, 
468         {0xA13F,0xF5}, 
469         {0xA140,0x22}, 
470         {0xA141,0xE5}, 
471         {0xA142,0x22}, 
472         {0xA143,0xC3}, 
473         {0xA144,0x94}, 
474         {0xA145,0x40}, 
475         {0xA146,0x40}, 
476         {0xA147,0x03}, 
477         {0xA148,0x02}, 
478         {0xA149,0xF1}, 
479         {0xA14A,0xFD}, 
480         {0xA14B,0x90}, 
481         {0xA14C,0x0A}, 
482         {0xA14D,0xBA}, 
483         {0xA14E,0xE0}, 
484         {0xA14F,0xFE}, 
485         {0xA150,0xA3}, 
486         {0xA151,0xE0}, 
487         {0xA152,0xFF}, 
488         {0xA153,0xF5}, 
489         {0xA154,0x82}, 
490         {0xA155,0x8E}, 
491         {0xA156,0x83}, 
492         {0xA157,0xE0}, 
493         {0xA158,0x54}, 
494         {0xA159,0x70}, 
495         {0xA15A,0xFD}, 
496         {0xA15B,0xC4}, 
497         {0xA15C,0x54}, 
498         {0xA15D,0x0F}, 
499         {0xA15E,0xFD}, 
500         {0xA15F,0x90}, 
501         {0xA160,0x0A}, 
502         {0xA161,0xBC}, 
503         {0xA162,0xE0}, 
504         {0xA163,0xFA}, 
505         {0xA164,0xA3}, 
506         {0xA165,0xE0}, 
507         {0xA166,0xF5}, 
508         {0xA167,0x82}, 
509         {0xA168,0x8A}, 
510         {0xA169,0x83}, 
511         {0xA16A,0xED}, 
512         {0xA16B,0xF0}, 
513         {0xA16C,0x90}, 
514         {0xA16D,0x0A}, 
515         {0xA16E,0xBD}, 
516         {0xA16F,0xE0}, 
517         {0xA170,0x04}, 
518         {0xA171,0xF0}, 
519         {0xA172,0x70}, 
520         {0xA173,0x06}, 
521         {0xA174,0x90}, 
522         {0xA175,0x0A}, 
523         {0xA176,0xBC}, 
524         {0xA177,0xE0}, 
525         {0xA178,0x04}, 
526         {0xA179,0xF0}, 
527         {0xA17A,0x8F}, 
528         {0xA17B,0x82}, 
529         {0xA17C,0x8E}, 
530         {0xA17D,0x83}, 
531         {0xA17E,0xA3}, 
532         {0xA17F,0xE0}, 
533         {0xA180,0xFF}, 
534         {0xA181,0x90}, 
535         {0xA182,0x0A}, 
536         {0xA183,0xBC}, 
537         {0xA184,0xE0}, 
538         {0xA185,0xFC}, 
539         {0xA186,0xA3}, 
540         {0xA187,0xE0}, 
541         {0xA188,0xF5}, 
542         {0xA189,0x82}, 
543         {0xA18A,0x8C}, 
544         {0xA18B,0x83}, 
545         {0xA18C,0xEF}, 
546         {0xA18D,0xF0}, 
547         {0xA18E,0x90}, 
548         {0xA18F,0x0A}, 
549         {0xA190,0xBD}, 
550         {0xA191,0xE0}, 
551         {0xA192,0x04}, 
552         {0xA193,0xF0}, 
553         {0xA194,0x70}, 
554         {0xA195,0x06}, 
555         {0xA196,0x90}, 
556         {0xA197,0x0A}, 
557         {0xA198,0xBC}, 
558         {0xA199,0xE0}, 
559         {0xA19A,0x04}, 
560         {0xA19B,0xF0}, 
561         {0xA19C,0x90}, 
562         {0xA19D,0x0A}, 
563         {0xA19E,0xBA}, 
564         {0xA19F,0xE0}, 
565         {0xA1A0,0xFE}, 
566         {0xA1A1,0xA3}, 
567         {0xA1A2,0xE0}, 
568         {0xA1A3,0xFF}, 
569         {0xA1A4,0xF5}, 
570         {0xA1A5,0x82}, 
571         {0xA1A6,0x8E}, 
572         {0xA1A7,0x83}, 
573         {0xA1A8,0xE0}, 
574         {0xA1A9,0x54}, 
575         {0xA1AA,0x07}, 
576         {0xA1AB,0xFD}, 
577         {0xA1AC,0x90}, 
578         {0xA1AD,0x0A}, 
579         {0xA1AE,0xBC}, 
580         {0xA1AF,0xE0}, 
581         {0xA1B0,0xFA}, 
582         {0xA1B1,0xA3}, 
583         {0xA1B2,0xE0}, 
584         {0xA1B3,0xF5}, 
585         {0xA1B4,0x82}, 
586         {0xA1B5,0x8A}, 
587         {0xA1B6,0x83}, 
588         {0xA1B7,0xED}, 
589         {0xA1B8,0xF0}, 
590         {0xA1B9,0x90}, 
591         {0xA1BA,0x0A}, 
592         {0xA1BB,0xBD}, 
593         {0xA1BC,0xE0}, 
594         {0xA1BD,0x04}, 
595         {0xA1BE,0xF0}, 
596         {0xA1BF,0x70}, 
597         {0xA1C0,0x06}, 
598         {0xA1C1,0x90}, 
599         {0xA1C2,0x0A}, 
600         {0xA1C3,0xBC}, 
601         {0xA1C4,0xE0}, 
602         {0xA1C5,0x04}, 
603         {0xA1C6,0xF0}, 
604         {0xA1C7,0x8F}, 
605         {0xA1C8,0x82}, 
606         {0xA1C9,0x8E}, 
607         {0xA1CA,0x83}, 
608         {0xA1CB,0xA3}, 
609         {0xA1CC,0xA3}, 
610         {0xA1CD,0xE0}, 
611         {0xA1CE,0xFF}, 
612         {0xA1CF,0x90}, 
613         {0xA1D0,0x0A}, 
614         {0xA1D1,0xBC}, 
615         {0xA1D2,0xE0}, 
616         {0xA1D3,0xFC}, 
617         {0xA1D4,0xA3}, 
618         {0xA1D5,0xE0}, 
619         {0xA1D6,0xF5}, 
620         {0xA1D7,0x82}, 
621         {0xA1D8,0x8C}, 
622         {0xA1D9,0x83}, 
623         {0xA1DA,0xEF}, 
624         {0xA1DB,0xF0}, 
625         {0xA1DC,0x90}, 
626         {0xA1DD,0x0A}, 
627         {0xA1DE,0xBD}, 
628         {0xA1DF,0xE0}, 
629         {0xA1E0,0x04}, 
630         {0xA1E1,0xF0}, 
631         {0xA1E2,0x70}, 
632         {0xA1E3,0x06}, 
633         {0xA1E4,0x90}, 
634         {0xA1E5,0x0A}, 
635         {0xA1E6,0xBC}, 
636         {0xA1E7,0xE0}, 
637         {0xA1E8,0x04}, 
638         {0xA1E9,0xF0}, 
639         {0xA1EA,0x90}, 
640         {0xA1EB,0x0A}, 
641         {0xA1EC,0xBB}, 
642         {0xA1ED,0xE0}, 
643         {0xA1EE,0x24}, 
644         {0xA1EF,0x03}, 
645         {0xA1F0,0xF0}, 
646         {0xA1F1,0x90}, 
647         {0xA1F2,0x0A}, 
648         {0xA1F3,0xBA}, 
649         {0xA1F4,0xE0}, 
650         {0xA1F5,0x34}, 
651         {0xA1F6,0x00}, 
652         {0xA1F7,0xF0}, 
653         {0xA1F8,0x05}, 
654         {0xA1F9,0x22}, 
655         {0xA1FA,0x02}, 
656         {0xA1FB,0xF1}, 
657         {0xA1FC,0x41}, 
658         {0xA1FD,0x90}, 
659         {0xA1FE,0x0A}, 
660         {0xA1FF,0xBA}, 
661         {0xA200,0x74}, 
662         {0xA201,0x0E}, 
663         {0xA202,0xF0}, 
664         {0xA203,0xA3}, 
665         {0xA204,0x74}, 
666         {0xA205,0xDC}, 
667         {0xA206,0xF0}, 
668         {0xA207,0xA3}, 
669         {0xA208,0x74}, 
670         {0xA209,0x05}, 
671         {0xA20A,0xF0}, 
672         {0xA20B,0xA3}, 
673         {0xA20C,0x74}, 
674         {0xA20D,0x61}, 
675         {0xA20E,0xF0}, 
676         {0xA20F,0x90}, 
677         {0xA210,0x0A}, 
678         {0xA211,0xBA}, 
679         {0xA212,0xE0}, 
680         {0xA213,0xFE}, 
681         {0xA214,0xA3}, 
682         {0xA215,0xE0}, 
683         {0xA216,0xAA}, 
684         {0xA217,0x06}, 
685         {0xA218,0xF9}, 
686         {0xA219,0x7B}, 
687         {0xA21A,0x01}, 
688         {0xA21B,0xC0}, 
689         {0xA21C,0x02}, 
690         {0xA21D,0xA3}, 
691         {0xA21E,0xE0}, 
692         {0xA21F,0xFE}, 
693         {0xA220,0xA3}, 
694         {0xA221,0xE0}, 
695         {0xA222,0xAA}, 
696         {0xA223,0x06}, 
697         {0xA224,0xF8}, 
698         {0xA225,0xAC}, 
699         {0xA226,0x02}, 
700         {0xA227,0x7D}, 
701         {0xA228,0x01}, 
702         {0xA229,0xD0}, 
703         {0xA22A,0x02}, 
704         {0xA22B,0x7E}, 
705         {0xA22C,0x00}, 
706         {0xA22D,0x7F}, 
707         {0xA22E,0x04}, 
708         {0xA22F,0x12}, 
709         {0xA230,0x0F}, 
710         {0xA231,0x6F}, 
711         {0xA232,0x02}, 
712         {0xA233,0x66}, 
713         {0xA234,0xD9}, 
714         {0xA235,0x90}, 
715         {0xA236,0x07}, 
716         {0xA237,0xD0}, 
717         {0xA238,0x02}, 
718         {0xA239,0xA2}, 
719         {0xA23A,0x69}, 
720         {0xA240,0x02}, 
721         {0xA241,0x21}, 
722         {0xA242,0x7F}, 
723         {0xA243,0x02}, 
724         {0xA244,0x21}, 
725         {0xA245,0xF4}, 
726         {0xA246,0x02}, 
727         {0xA247,0xA6}, 
728         {0xA248,0x15}, 
729         {0xA249,0x60}, 
730         {0xA24A,0x0A}, 
731         {0xA24B,0xEF}, 
732         {0xA24C,0xB4}, 
733         {0xA24D,0x01}, 
734         {0xA24E,0x16}, 
735         {0xA24F,0x90}, 
736         {0xA250,0x00}, 
737         {0xA251,0x5D}, 
738         {0xA252,0xE0}, 
739         {0xA253,0x70}, 
740         {0xA254,0x10}, 
741         {0xA255,0x12}, 
742         {0xA256,0x26}, 
743         {0xA257,0xC8}, 
744         {0xA258,0x90}, 
745         {0xA259,0x00}, 
746         {0xA25A,0x11}, 
747         {0xA25B,0x74}, 
748         {0xA25C,0x30}, 
749         {0xA25D,0xF0}, 
750         {0xA25E,0x90}, 
751         {0xA25F,0x00}, 
752         {0xA260,0x10}, 
753         {0xA261,0x74}, 
754         {0xA262,0x01}, 
755         {0xA263,0xF0}, 
756         {0xA264,0x22}, 
757         {0xA265,0x12}, 
758         {0xA266,0x25}, 
759         {0xA267,0xA8}, 
760         {0xA268,0x02}, 
761         {0xA269,0x29}, 
762         {0xA26A,0xFC}, 
763         {0xA26B,0x44}, 
764         {0xA26C,0x18}, 
765         {0xA26D,0xF0}, 
766         {0xA26E,0x90}, 
767         {0xA26F,0x72}, 
768         {0xA270,0x18}, 
769         {0xA271,0xE0}, 
770         {0xA272,0x44}, 
771         {0xA273,0x18}, 
772         {0xA274,0xF0}, 
773         {0xA275,0x00}, 
774         {0xA276,0x00}, 
775         {0xA277,0x00}, 
776         {0xA278,0x00}, 
777         {0xA279,0x00}, 
778         {0xA27A,0x00}, 
779         {0xA27B,0x90}, 
780         {0xA27C,0x72}, 
781         {0xA27D,0x08}, 
782         {0xA27E,0xE0}, 
783         {0xA27F,0x44}, 
784         {0xA280,0x10}, 
785         {0xA281,0xF0}, 
786         {0xA282,0x90}, 
787         {0xA283,0x72}, 
788         {0xA284,0x14}, 
789         {0xA285,0xE0}, 
790         {0xA286,0x54}, 
791         {0xA287,0xFD}, 
792         {0xA288,0xF0}, 
793         {0xA289,0x22}, 
794         {0xA29B,0xF0}, 
795         {0xA29C,0xD3}, 
796         {0xA29D,0x90}, 
797         {0xA29E,0x07}, 
798         {0xA29F,0x91}, 
799         {0xA2A0,0xE0}, 
800         {0xA2A1,0x94}, 
801         {0xA2A2,0x21}, 
802         {0xA2A3,0x90}, 
803         {0xA2A4,0x07}, 
804         {0xA2A5,0x90}, 
805         {0xA2A6,0xE0}, 
806         {0xA2A7,0x64}, 
807         {0xA2A8,0x80}, 
808         {0xA2A9,0x94}, 
809         {0xA2AA,0x81}, 
810         {0xA2AB,0x40}, 
811         {0xA2AC,0x08}, 
812         {0xA2AD,0x90}, 
813         {0xA2AE,0x07}, 
814         {0xA2AF,0xCB}, 
815         {0xA2B0,0x74}, 
816         {0xA2B1,0xFF}, 
817         {0xA2B2,0xF0}, 
818         {0xA2B3,0x80}, 
819         {0xA2B4,0x06}, 
820         {0xA2B5,0x90}, 
821         {0xA2B6,0x07}, 
822         {0xA2B7,0xCB}, 
823         {0xA2B8,0x74}, 
824         {0xA2B9,0x01}, 
825         {0xA2BA,0xF0}, 
826         {0xA2BB,0x02}, 
827         {0xA2BC,0xB5}, 
828         {0xA2BD,0xC3}, 
829         {0xA2BE,0x90}, 
830         {0xA2BF,0x08}, 
831         {0xA2C0,0x34}, 
832         {0xA2C1,0xE0}, 
833         {0xA2C2,0xFC}, 
834         {0xA2C3,0xA3}, 
835         {0xA2C4,0xE0}, 
836         {0xA2C5,0xFD}, 
837         {0xA2C6,0xA3}, 
838         {0xA2C7,0xE0}, 
839         {0xA2C8,0xFE}, 
840         {0xA2C9,0xA3}, 
841         {0xA2CA,0xE0}, 
842         {0xA2CB,0xFF}, 
843         {0xA2CC,0x90}, 
844         {0xA2CD,0x07}, 
845         {0xA2CE,0xD0}, 
846         {0xA2CF,0xE0}, 
847         {0xA2D0,0xF8}, 
848         {0xA2D1,0xA3}, 
849         {0xA2D2,0xE0}, 
850         {0xA2D3,0xF9}, 
851         {0xA2D4,0xA3}, 
852         {0xA2D5,0xE0}, 
853         {0xA2D6,0xFA}, 
854         {0xA2D7,0xA3}, 
855         {0xA2D8,0xE0}, 
856         {0xA2D9,0xFB}, 
857         {0xA2DA,0xD3}, 
858         {0xA2DB,0x12}, 
859         {0xA2DC,0x0D}, 
860         {0xA2DD,0xAE}, 
861         {0xA2DE,0x40}, 
862         {0xA2DF,0x0B}, 
863         {0xA2E0,0x12}, 
864         {0xA2E1,0xB5}, 
865         {0xA2E2,0x49}, 
866         {0xA2E3,0x90}, 
867         {0xA2E4,0x07}, 
868         {0xA2E5,0xA4}, 
869         {0xA2E6,0x74}, 
870         {0xA2E7,0x02}, 
871         {0xA2E8,0xF0}, 
872         {0xA2E9,0x80}, 
873         {0xA2EA,0x09}, 
874         {0xA2EB,0x12}, 
875         {0xA2EC,0xB7}, 
876         {0xA2ED,0x51}, 
877         {0xA2EE,0x90}, 
878         {0xA2EF,0x07}, 
879         {0xA2F0,0xA4}, 
880         {0xA2F1,0x74}, 
881         {0xA2F2,0x05}, 
882         {0xA2F3,0xF0}, 
883         {0xA2F4,0x02}, 
884         {0xA2F5,0xA2}, 
885         {0xA2F6,0xDA}, 
886         {0xA2F7,0x90}, 
887         {0xA2F8,0x0E}, 
888         {0xA2F9,0xE0}, 
889         {0xA2FA,0xE0}, 
890         {0xA2FB,0xFD}, 
891         {0xA2FC,0xA3}, 
892         {0xA2FD,0xE0}, 
893         {0xA2FE,0x90}, 
894         {0xA2FF,0x02}, 
895         {0xA300,0xA2}, 
896         {0xA301,0xCD}, 
897         {0xA302,0xF0}, 
898         {0xA303,0xA3}, 
899         {0xA304,0xED}, 
900         {0xA305,0xF0}, 
901         {0xA306,0x90}, 
902         {0xA307,0x0E}, 
903         {0xA308,0xE2}, 
904         {0xA309,0xE0}, 
905         {0xA30A,0xFD}, 
906         {0xA30B,0xA3}, 
907         {0xA30C,0xE0}, 
908         {0xA30D,0x90}, 
909         {0xA30E,0x02}, 
910         {0xA30F,0xA8}, 
911         {0xA310,0xCD}, 
912         {0xA311,0xF0}, 
913         {0xA312,0xA3}, 
914         {0xA313,0xED}, 
915         {0xA314,0xF0}, 
916         {0xA315,0xE4}, 
917         {0xA316,0x90}, 
918         {0xA317,0x06}, 
919         {0xA318,0x38}, 
920         {0xA319,0xF0}, 
921         {0xA31A,0x02}, 
922         {0xA31B,0x67}, 
923         {0xA31C,0x63}, 
924         {0xA31D,0x90}, 
925         {0xA31E,0x0E}, 
926         {0xA31F,0xE8}, 
927         {0xA320,0xE0}, 
928         {0xA321,0x90}, 
929         {0xA322,0x02}, 
930         {0xA323,0x62}, 
931         {0xA324,0xF0}, 
932         {0xA325,0x90}, 
933         {0xA326,0x0E}, 
934         {0xA327,0xE9}, 
935         {0xA328,0xE0}, 
936         {0xA329,0x90}, 
937         {0xA32A,0x02}, 
938         {0xA32B,0x63}, 
939         {0xA32C,0xF0}, 
940         {0xA32D,0x02}, 
941         {0xA32E,0x67}, 
942         {0xA32F,0x1F}, 
943         {0xA33B,0x90}, 
944         {0xA33C,0x0E}, 
945         {0xA33D,0x14}, 
946         {0xA33E,0xE0}, 
947         {0xA33F,0xFE}, 
948         {0xA340,0xA3}, 
949         {0xA341,0xE0}, 
950         {0xA342,0xFF}, 
951         {0xA343,0x90}, 
952         {0xA344,0x06}, 
953         {0xA345,0xD9}, 
954         {0xA346,0xEE}, 
955         {0xA347,0xF0}, 
956         {0xA348,0xA3}, 
957         {0xA349,0xEF}, 
958         {0xA34A,0xF0}, 
959         {0xA34B,0x90}, 
960         {0xA34C,0x0E}, 
961         {0xA34D,0x18}, 
962         {0xA34E,0xE0}, 
963         {0xA34F,0xFD}, 
964         {0xA350,0x7C}, 
965         {0xA351,0x00}, 
966         {0xA352,0xC3}, 
967         {0xA353,0xEF}, 
968         {0xA354,0x9D}, 
969         {0xA355,0xEE}, 
970         {0xA356,0x9C}, 
971         {0xA357,0x50}, 
972         {0xA358,0x09}, 
973         {0xA359,0xE4}, 
974         {0xA35A,0x90}, 
975         {0xA35B,0x06}, 
976         {0xA35C,0xD7}, 
977         {0xA35D,0xF0}, 
978         {0xA35E,0xA3}, 
979         {0xA35F,0xF0}, 
980         {0xA360,0x80}, 
981         {0xA361,0x13}, 
982         {0xA362,0xC3}, 
983         {0xA363,0x90}, 
984         {0xA364,0x06}, 
985         {0xA365,0xDA}, 
986         {0xA366,0xE0}, 
987         {0xA367,0x9D}, 
988         {0xA368,0xFE}, 
989         {0xA369,0x90}, 
990         {0xA36A,0x06}, 
991         {0xA36B,0xD9}, 
992         {0xA36C,0xE0}, 
993         {0xA36D,0x9C}, 
994         {0xA36E,0x90}, 
995         {0xA36F,0x06}, 
996         {0xA370,0xD7}, 
997         {0xA371,0xF0}, 
998         {0xA372,0xA3}, 
999         {0xA373,0xCE}, 
1000         {0xA374,0xF0}, 
1001         {0xA375,0x90}, 
1002         {0xA376,0x0E}, 
1003         {0xA377,0x18}, 
1004         {0xA378,0xE0}, 
1005         {0xA379,0xF9}, 
1006         {0xA37A,0xFF}, 
1007         {0xA37B,0x90}, 
1008         {0xA37C,0x06}, 
1009         {0xA37D,0xC2}, 
1010         {0xA37E,0xE0}, 
1011         {0xA37F,0xFC}, 
1012         {0xA380,0xA3}, 
1013         {0xA381,0xE0}, 
1014         {0xA382,0xFD}, 
1015         {0xA383,0xC3}, 
1016         {0xA384,0x9F}, 
1017         {0xA385,0xFF}, 
1018         {0xA386,0xEC}, 
1019         {0xA387,0x94}, 
1020         {0xA388,0x00}, 
1021         {0xA389,0xFE}, 
1022         {0xA38A,0x90}, 
1023         {0xA38B,0x0E}, 
1024         {0xA38C,0x16}, 
1025         {0xA38D,0xE0}, 
1026         {0xA38E,0xFA}, 
1027         {0xA38F,0xA3}, 
1028         {0xA390,0xE0}, 
1029         {0xA391,0xFB}, 
1030         {0xA392,0xD3}, 
1031         {0xA393,0x9F}, 
1032         {0xA394,0xEA}, 
1033         {0xA395,0x9E}, 
1034         {0xA396,0x40}, 
1035         {0xA397,0x0A}, 
1036         {0xA398,0x90}, 
1037         {0xA399,0x06}, 
1038         {0xA39A,0xD5}, 
1039         {0xA39B,0xEC}, 
1040         {0xA39C,0xF0}, 
1041         {0xA39D,0xA3}, 
1042         {0xA39E,0xED}, 
1043         {0xA39F,0xF0}, 
1044         {0xA3A0,0x80}, 
1045         {0xA3A1,0x0E}, 
1046         {0xA3A2,0xE9}, 
1047         {0xA3A3,0x7E}, 
1048         {0xA3A4,0x00}, 
1049         {0xA3A5,0x2B}, 
1050         {0xA3A6,0xFF}, 
1051         {0xA3A7,0xEE}, 
1052         {0xA3A8,0x3A}, 
1053         {0xA3A9,0x90}, 
1054         {0xA3AA,0x06}, 
1055         {0xA3AB,0xD5}, 
1056         {0xA3AC,0xF0}, 
1057         {0xA3AD,0xA3}, 
1058         {0xA3AE,0xEF}, 
1059         {0xA3AF,0xF0}, 
1060         {0xA3B0,0xE9}, 
1061         {0xA3B1,0xFB}, 
1062         {0xA3B2,0x7A}, 
1063         {0xA3B3,0x00}, 
1064         {0xA3B4,0x90}, 
1065         {0xA3B5,0x0E}, 
1066         {0xA3B6,0x15}, 
1067         {0xA3B7,0xE0}, 
1068         {0xA3B8,0x2B}, 
1069         {0xA3B9,0xFE}, 
1070         {0xA3BA,0x90}, 
1071         {0xA3BB,0x0E}, 
1072         {0xA3BC,0x14}, 
1073         {0xA3BD,0xE0}, 
1074         {0xA3BE,0x3A}, 
1075         {0xA3BF,0x90}, 
1076         {0xA3C0,0x06}, 
1077         {0xA3C1,0xE1}, 
1078         {0xA3C2,0xF0}, 
1079         {0xA3C3,0xA3}, 
1080         {0xA3C4,0xCE}, 
1081         {0xA3C5,0xF0}, 
1082         {0xA3C6,0xC3}, 
1083         {0xA3C7,0x90}, 
1084         {0xA3C8,0x0E}, 
1085         {0xA3C9,0x17}, 
1086         {0xA3CA,0xE0}, 
1087         {0xA3CB,0x9B}, 
1088         {0xA3CC,0xFE}, 
1089         {0xA3CD,0x90}, 
1090         {0xA3CE,0x0E}, 
1091         {0xA3CF,0x16}, 
1092         {0xA3D0,0x02}, 
1093         {0xA3D1,0x20}, 
1094         {0xA3D2,0xD5}, 
1095         {0xA3D3,0x90}, 
1096         {0xA3d4,0x0E}, 
1097         {0xA3d5,0xE4}, 
1098         {0xA3d6,0xE0}, 
1099         {0xA3d7,0x90}, 
1100         {0xA3d8,0x02}, 
1101         {0xA3d9,0x66}, 
1102         {0xA3da,0xF0}, 
1103         {0xA3DB,0x90}, 
1104         {0xA3dc,0x0E}, 
1105         {0xA3dd,0xE5}, 
1106         {0xA3de,0xE0}, 
1107         {0xA3df,0x90}, 
1108         {0xA3e0,0x02}, 
1109         {0xA3e1,0x64}, 
1110         {0xA3e2,0xF0}, 
1111         {0xA3e3,0x90}, 
1112         {0xA3e4,0x0E}, 
1113         {0xA3e5,0xE6}, 
1114         {0xA3e6,0xE0}, 
1115         {0xA3e7,0x90}, 
1116         {0xA3e8,0x02}, 
1117         {0xA3e9,0x65}, 
1118         {0xA3ea,0xF0}, 
1119         {0xA3eb,0x02}, 
1120         {0xA3ec,0x67}, 
1121         {0xA3ed,0xA5}, 
1122         {0xA3f0,0x12}, 
1123         {0xA3f1,0x47}, 
1124         {0xA3f2,0x59}, 
1125         {0xA3f3,0x90}, 
1126         {0xA3f4,0x00}, 
1127         {0xA3f5,0xB5}, 
1128         {0xA3f6,0xE0}, 
1129         {0xA3f7,0xB4}, 
1130         {0xA3f8,0x02}, 
1131         {0xA3f9,0x03}, 
1132         {0xA3fa,0x12}, 
1133         {0xA3fb,0x47}, 
1134         {0xA3fc,0x59}, 
1135         {0xA3fd,0x02}, 
1136         {0xA3fe,0xC5}, 
1137         {0xA3ff,0xC3}, 
1138         {0xA400,0x90}, 
1139         {0xA401,0x00}, 
1140         {0xA402,0x3D}, 
1141         {0xA403,0xF0}, 
1142         {0xA404,0x90}, 
1143         {0xA405,0x00}, 
1144         {0xA406,0x84}, 
1145         {0xA407,0xE0}, 
1146         {0xA408,0xFE}, 
1147         {0xA409,0x90}, 
1148         {0xA40A,0x00}, 
1149         {0xA40B,0x3E}, 
1150         {0xA40C,0xF0}, 
1151         {0xA40D,0xEF}, 
1152         {0xA40E,0x70}, 
1153         {0xA40F,0x03}, 
1154         {0xA410,0xEE}, 
1155         {0xA411,0x60}, 
1156         {0xA412,0x04}, 
1157         {0xA413,0x7F}, 
1158         {0xA414,0x01}, 
1159         {0xA415,0x80}, 
1160         {0xA416,0x02}, 
1161         {0xA417,0x7F}, 
1162         {0xA418,0x00}, 
1163         {0xA419,0x90}, 
1164         {0xA41A,0x00}, 
1165         {0xA41B,0x3F}, 
1166         {0xA41C,0xEF}, 
1167         {0xA41D,0xF0}, 
1168         {0xA41E,0x02}, 
1169         {0xA41F,0x89}, 
1170         {0xA420,0xD3}, 
1171         {0xA421,0x90}, 
1172         {0xA422,0x00}, 
1173         {0xA423,0x12}, 
1174         {0xA424,0xE0}, 
1175         {0xA425,0xFF}, 
1176         {0xA426,0x70}, 
1177         {0xA427,0x0C}, 
1178         {0xA428,0x90}, 
1179         {0xA429,0x00}, 
1180         {0xA42A,0x46}, 
1181         {0xA42B,0xE0}, 
1182         {0xA42C,0xC3}, 
1183         {0xA42D,0x94}, 
1184         {0xA42E,0x07}, 
1185         {0xA42F,0x40}, 
1186         {0xA430,0x03}, 
1187         {0xA431,0x75}, 
1188         {0xA432,0x2E}, 
1189         {0xA433,0x02}, 
1190         {0xA434,0xEF}, 
1191         {0xA435,0xB4}, 
1192         {0xA436,0x01}, 
1193         {0xA437,0x0C}, 
1194         {0xA438,0x90}, 
1195         {0xA439,0x00}, 
1196         {0xA43A,0x66}, 
1197         {0xA43B,0xE0}, 
1198         {0xA43C,0xC3}, 
1199         {0xA43D,0x94}, 
1200         {0xA43E,0x07}, 
1201         {0xA43F,0x40}, 
1202         {0xA440,0x03}, 
1203         {0xA441,0x75}, 
1204         {0xA442,0x2E}, 
1205         {0xA443,0x02}, 
1206         {0xA444,0x02}, 
1207         {0xA445,0xA7}, 
1208         {0xA446,0x9E}, 
1209         {0xA447,0xC3}, 
1210         {0xA448,0x90}, 
1211         {0xA449,0x0B}, 
1212         {0xA44A,0x8F}, 
1213         {0xA44B,0xE0}, 
1214         {0xA44C,0x94}, 
1215         {0xA44D,0x00}, 
1216         {0xA44E,0x90}, 
1217         {0xA44F,0x0B}, 
1218         {0xA450,0x8E}, 
1219         {0xA451,0xE0}, 
1220         {0xA452,0x94}, 
1221         {0xA453,0x41}, 
1222         {0xA454,0x40}, 
1223         {0xA455,0x22}, 
1224         {0xA456,0x90}, 
1225         {0xA457,0x0B}, 
1226         {0xA458,0x91}, 
1227         {0xA459,0xE0}, 
1228         {0xA45A,0x94}, 
1229         {0xA45B,0x00}, 
1230         {0xA45C,0x90}, 
1231         {0xA45D,0x0B}, 
1232         {0xA45E,0x90}, 
1233         {0xA45F,0xE0}, 
1234         {0xA460,0x94}, 
1235         {0xA461,0x41}, 
1236         {0xA462,0x40}, 
1237         {0xA463,0x14}, 
1238         {0xA464,0x90}, 
1239         {0xA465,0x0B}, 
1240         {0xA466,0x93}, 
1241         {0xA467,0xE0}, 
1242         {0xA468,0x94}, 
1243         {0xA469,0x00}, 
1244         {0xA46A,0x90}, 
1245         {0xA46B,0x0B}, 
1246         {0xA46C,0x92}, 
1247         {0xA46D,0xE0}, 
1248         {0xA46E,0x94}, 
1249         {0xA46F,0x41}, 
1250         {0xA470,0x40}, 
1251         {0xA471,0x06}, 
1252         {0xA472,0x90}, 
1253         {0xA473,0x01}, 
1254         {0xA474,0xA4}, 
1255         {0xA475,0x02}, 
1256         {0xA476,0x86}, 
1257         {0xA477,0x57}, 
1258         {0xA478,0x02}, 
1259         {0xA479,0x86}, 
1260         {0xA47A,0x5C}, 
1261         {0xA500,0xF5}, 
1262         {0xA501,0x3B}, 
1263         {0xA502,0x90}, 
1264         {0xA503,0x06}, 
1265         {0xA504,0x6C}, 
1266         {0xA505,0xE0}, 
1267         {0xA506,0xFF}, 
1268         {0xA507,0xE5}, 
1269         {0xA508,0x3B}, 
1270         {0xA509,0xC3}, 
1271         {0xA50A,0x9F}, 
1272         {0xA50B,0x40}, 
1273         {0xA50C,0x03}, 
1274         {0xA50D,0x02}, 
1275         {0xA50E,0xF6}, 
1276         {0xA50F,0x0E}, 
1277         {0xA510,0x90}, 
1278         {0xA511,0x0B}, 
1279         {0xA512,0xC6}, 
1280         {0xA513,0xE0}, 
1281         {0xA514,0x14}, 
1282         {0xA515,0x60}, 
1283         {0xA516,0x3C}, 
1284         {0xA517,0x14}, 
1285         {0xA518,0x60}, 
1286         {0xA519,0x6B}, 
1287         {0xA51A,0x24}, 
1288         {0xA51B,0x02}, 
1289         {0xA51C,0x60}, 
1290         {0xA51D,0x03}, 
1291         {0xA51E,0x02}, 
1292         {0xA51F,0xF5}, 
1293         {0xA520,0xB5}, 
1294         {0xA521,0x90}, 
1295         {0xA522,0x0A}, 
1296         {0xA523,0x9A}, 
1297         {0xA524,0xE0}, 
1298         {0xA525,0xFB}, 
1299         {0xA526,0xA3}, 
1300         {0xA527,0xE0}, 
1301         {0xA528,0xFA}, 
1302         {0xA529,0xA3}, 
1303         {0xA52A,0xE0}, 
1304         {0xA52B,0xF9}, 
1305         {0xA52C,0x85}, 
1306         {0xA52D,0x3B}, 
1307         {0xA52E,0x82}, 
1308         {0xA52F,0x75}, 
1309         {0xA530,0x83}, 
1310         {0xA531,0x00}, 
1311         {0xA532,0x12}, 
1312         {0xA533,0x0A}, 
1313         {0xA534,0xB8}, 
1314         {0xA535,0xFF}, 
1315         {0xA536,0x74}, 
1316         {0xA537,0xAB}, 
1317         {0xA538,0x25}, 
1318         {0xA539,0x3B}, 
1319         {0xA53A,0xF5}, 
1320         {0xA53B,0x82}, 
1321         {0xA53C,0xE4}, 
1322         {0xA53D,0x34}, 
1323         {0xA53E,0x0A}, 
1324         {0xA53F,0xF5}, 
1325         {0xA540,0x83}, 
1326         {0xA541,0xE0}, 
1327         {0xA542,0xFD}, 
1328         {0xA543,0xC3}, 
1329         {0xA544,0xEF}, 
1330         {0xA545,0x9D}, 
1331         {0xA546,0xFE}, 
1332         {0xA547,0xE4}, 
1333         {0xA548,0x94}, 
1334         {0xA549,0x00}, 
1335         {0xA54A,0x90}, 
1336         {0xA54B,0x0B}, 
1337         {0xA54C,0xCA}, 
1338         {0xA54D,0xF0}, 
1339         {0xA54E,0xA3}, 
1340         {0xA54F,0xCE}, 
1341         {0xA550,0xF0}, 
1342         {0xA551,0x80}, 
1343         {0xA552,0x62}, 
1344         {0xA553,0x90}, 
1345         {0xA554,0x0A}, 
1346         {0xA555,0x9A}, 
1347         {0xA556,0xE0}, 
1348         {0xA557,0xFB}, 
1349         {0xA558,0xA3}, 
1350         {0xA559,0xE0}, 
1351         {0xA55A,0xFA}, 
1352         {0xA55B,0xA3}, 
1353         {0xA55C,0xE0}, 
1354         {0xA55D,0xF9}, 
1355         {0xA55E,0x85}, 
1356         {0xA55F,0x3B}, 
1357         {0xA560,0x82}, 
1358         {0xA561,0x75}, 
1359         {0xA562,0x83}, 
1360         {0xA563,0x00}, 
1361         {0xA564,0x12}, 
1362         {0xA565,0x0A}, 
1363         {0xA566,0xB8}, 
1364         {0xA567,0xFF}, 
1365         {0xA568,0x74}, 
1366         {0xA569,0x9D}, 
1367         {0xA56A,0x25}, 
1368         {0xA56B,0x3B}, 
1369         {0xA56C,0xF5}, 
1370         {0xA56D,0x82}, 
1371         {0xA56E,0xE4}, 
1372         {0xA56F,0x34}, 
1373         {0xA570,0x0A}, 
1374         {0xA571,0xF5}, 
1375         {0xA572,0x83}, 
1376         {0xA573,0xE0}, 
1377         {0xA574,0xFD}, 
1378         {0xA575,0xC3}, 
1379         {0xA576,0xEF}, 
1380         {0xA577,0x9D}, 
1381         {0xA578,0xFE}, 
1382         {0xA579,0xE4}, 
1383         {0xA57A,0x94}, 
1384         {0xA57B,0x00}, 
1385         {0xA57C,0x90}, 
1386         {0xA57D,0x0B}, 
1387         {0xA57E,0xCA}, 
1388         {0xA57F,0xF0}, 
1389         {0xA580,0xA3}, 
1390         {0xA581,0xCE}, 
1391         {0xA582,0xF0}, 
1392         {0xA583,0x80}, 
1393         {0xA584,0x30}, 
1394         {0xA585,0x90}, 
1395         {0xA586,0x0A}, 
1396         {0xA587,0x9A}, 
1397         {0xA588,0xE0}, 
1398         {0xA589,0xFB}, 
1399         {0xA58A,0xA3}, 
1400         {0xA58B,0xE0}, 
1401         {0xA58C,0xFA}, 
1402         {0xA58D,0xA3}, 
1403         {0xA58E,0xE0}, 
1404         {0xA58F,0xF9}, 
1405         {0xA590,0x85}, 
1406         {0xA591,0x3B}, 
1407         {0xA592,0x82}, 
1408         {0xA593,0x75}, 
1409         {0xA594,0x83}, 
1410         {0xA595,0x00}, 
1411         {0xA596,0x12}, 
1412         {0xA597,0x0A}, 
1413         {0xA598,0xB8}, 
1414         {0xA599,0xFF}, 
1415         {0xA59A,0x74}, 
1416         {0xA59B,0xA4}, 
1417         {0xA59C,0x25}, 
1418         {0xA59D,0x3B}, 
1419         {0xA59E,0xF5}, 
1420         {0xA59F,0x82}, 
1421         {0xA5A0,0xE4}, 
1422         {0xA5A1,0x34}, 
1423         {0xA5A2,0x0A}, 
1424         {0xA5A3,0xF5}, 
1425         {0xA5A4,0x83}, 
1426         {0xA5A5,0xE0}, 
1427         {0xA5A6,0xFD}, 
1428         {0xA5A7,0xC3}, 
1429         {0xA5A8,0xEF}, 
1430         {0xA5A9,0x9D}, 
1431         {0xA5AA,0xFE}, 
1432         {0xA5AB,0xE4}, 
1433         {0xA5AC,0x94}, 
1434         {0xA5AD,0x00}, 
1435         {0xA5AE,0x90}, 
1436         {0xA5AF,0x0B}, 
1437         {0xA5B0,0xCA}, 
1438         {0xA5B1,0xF0}, 
1439         {0xA5B2,0xA3}, 
1440         {0xA5B3,0xCE}, 
1441         {0xA5B4,0xF0}, 
1442         {0xA5B5,0x90}, 
1443         {0xA5B6,0x07}, 
1444         {0xA5B7,0x83}, 
1445         {0xA5B8,0xE0}, 
1446         {0xA5B9,0xFF}, 
1447         {0xA5BA,0x7E}, 
1448         {0xA5BB,0x00}, 
1449         {0xA5BC,0x90}, 
1450         {0xA5BD,0x0D}, 
1451         {0xA5BE,0xF6}, 
1452         {0xA5BF,0xEE}, 
1453         {0xA5C0,0xF0}, 
1454         {0xA5C1,0xA3}, 
1455         {0xA5C2,0xEF}, 
1456         {0xA5C3,0xF0}, 
1457         {0xA5C4,0x90}, 
1458         {0xA5C5,0x0B}, 
1459         {0xA5C6,0xCA}, 
1460         {0xA5C7,0xE0}, 
1461         {0xA5C8,0xFC}, 
1462         {0xA5C9,0xA3}, 
1463         {0xA5CA,0xE0}, 
1464         {0xA5CB,0xFD}, 
1465         {0xA5CC,0xD3}, 
1466         {0xA5CD,0x9F}, 
1467         {0xA5CE,0x74}, 
1468         {0xA5CF,0x80}, 
1469         {0xA5D0,0xF8}, 
1470         {0xA5D1,0xEC}, 
1471         {0xA5D2,0x64}, 
1472         {0xA5D3,0x80}, 
1473         {0xA5D4,0x98}, 
1474         {0xA5D5,0x40}, 
1475         {0xA5D6,0x0C}, 
1476         {0xA5D7,0x90}, 
1477         {0xA5D8,0x0B}, 
1478         {0xA5D9,0xC8}, 
1479         {0xA5DA,0xE0}, 
1480         {0xA5DB,0x04}, 
1481         {0xA5DC,0xF0}, 
1482         {0xA5DD,0xA3}, 
1483         {0xA5DE,0xE0}, 
1484         {0xA5DF,0x04}, 
1485         {0xA5E0,0xF0}, 
1486         {0xA5E1,0x80}, 
1487         {0xA5E2,0x26}, 
1488         {0xA5E3,0x90}, 
1489         {0xA5E4,0x0D}, 
1490         {0xA5E5,0xF6}, 
1491         {0xA5E6,0xE0}, 
1492         {0xA5E7,0xFE}, 
1493         {0xA5E8,0xA3}, 
1494         {0xA5E9,0xE0}, 
1495         {0xA5EA,0xFF}, 
1496         {0xA5EB,0xC3}, 
1497         {0xA5EC,0xE4}, 
1498         {0xA5ED,0x9F}, 
1499         {0xA5EE,0xFF}, 
1500         {0xA5EF,0xE4}, 
1501         {0xA5F0,0x9E}, 
1502         {0xA5F1,0xFE}, 
1503         {0xA5F2,0xC3}, 
1504         {0xA5F3,0xED}, 
1505         {0xA5F4,0x9F}, 
1506         {0xA5F5,0xEE}, 
1507         {0xA5F6,0x64}, 
1508         {0xA5F7,0x80}, 
1509         {0xA5F8,0xF8}, 
1510         {0xA5F9,0xEC}, 
1511         {0xA5FA,0x64}, 
1512         {0xA5FB,0x80}, 
1513         {0xA5FC,0x98}, 
1514         {0xA5FD,0x50}, 
1515         {0xA5FE,0x0A}, 
1516         {0xA5FF,0x90}, 
1517         {0xA600,0x0B}, 
1518         {0xA601,0xC8}, 
1519         {0xA602,0xE0}, 
1520         {0xA603,0x14}, 
1521         {0xA604,0xF0}, 
1522         {0xA605,0xA3}, 
1523         {0xA606,0xE0}, 
1524         {0xA607,0x04}, 
1525         {0xA608,0xF0}, 
1526         {0xA609,0x05}, 
1527         {0xA60A,0x3B}, 
1528         {0xA60B,0x02}, 
1529         {0xA60C,0xF5}, 
1530         {0xA60D,0x02}, 
1531         {0xA60E,0x90}, 
1532         {0xA60F,0x08}, 
1533         {0xA610,0x58}, 
1534         {0xA611,0x02}, 
1535         {0xA612,0x9D}, 
1536         {0xA613,0x50}, 
1537         {0x9006,0xBA}, 
1538         {0x9007,0x75}, 
1539         {0x9008,0x00}, 
1540         {0x9009,0x00}, 
1541         {0x900A,0x02}, 
1542         {0x900D,0x01}, 
1543         {0x900E,0xA2}, 
1544         {0x900F,0x8F}, 
1545         {0x9010,0x00}, 
1546         {0x9011,0xCB}, 
1547         {0x9012,0x03}, 
1548         {0x9016,0xE6}, 
1549         {0x9017,0x6B}, 
1550         {0x9018,0x02}, 
1551         {0x9019,0x6B}, 
1552         {0x901A,0x02}, 
1553         {0x901D,0x01}, 
1554         {0x901E,0xAC}, 
1555         {0x901F,0x70}, 
1556         {0x9020,0x00}, 
1557         {0x9021,0xC5}, 
1558         {0x9022,0x03}, 
1559         {0x9026,0x9C}, 
1560         {0x9027,0x5B}, 
1561         {0x9028,0x00}, 
1562         {0x9029,0xBF}, 
1563         {0x902A,0x02}, 
1564         {0x902E,0x60}, 
1565         {0x902F,0x1C}, 
1566         {0x9030,0x01}, 
1567         {0x9031,0x37}, 
1568         {0x9032,0x02}, 
1569         {0x9035,0x01}, 
1570         {0x9036,0xBA}, 
1571         {0x9037,0x70}, 
1572         {0x9038,0x00}, 
1573         {0x9039,0x00}, 
1574         {0x903A,0x03}, 
1575         {0x903E,0x21}, 
1576         {0x903F,0x3F}, 
1577         {0x9040,0x02}, 
1578         {0x9041,0x40}, 
1579         {0x9042,0x02}, 
1580         {0x9046,0x21}, 
1581         {0x9047,0xEA}, 
1582         {0x9048,0x02}, 
1583         {0x9049,0x43}, 
1584         {0x904A,0x02}, 
1585         {0x904E,0xA6}, 
1586         {0x904F,0x12}, 
1587         {0x9050,0x02}, 
1588         {0x9051,0x46}, 
1589         {0x9052,0x02}, 
1590         {0x9056,0x29}, 
1591         {0x9057,0xE3}, 
1592         {0x9058,0x02}, 
1593         {0x9059,0x49}, 
1594         {0x905A,0x02}, 
1595         {0x905D,0x01}, 
1596         {0x905E,0x9C}, 
1597         {0x905F,0x6E}, 
1598         {0x9060,0x05}, 
1599         {0x9061,0x00}, 
1600         {0x9062,0x02}, 
1601         {0x9065,0x01}, 
1602         {0x9066,0xA2}, 
1603         {0x9067,0x66}, 
1604         {0x9068,0x02}, 
1605         {0x9069,0x35}, 
1606         {0x906A,0x02}, 
1607         {0x906D,0x01}, 
1608         {0x906E,0xB5}, 
1609         {0x906F,0xC2}, 
1610         {0x9070,0x02}, 
1611         {0x9071,0x9B}, 
1612         {0x9072,0x02}, 
1613         {0x9075,0x01}, 
1614         {0x9076,0xA2}, 
1615         {0x9077,0xD4}, 
1616         {0x9078,0x02}, 
1617         {0x9079,0xBE}, 
1618         {0x907A,0x02}, 
1619         {0x907D,0x01}, 
1620         {0x907E,0xB7}, 
1621         {0x907F,0xEA}, 
1622         {0x9080,0x00}, 
1623         {0x9081,0x02}, 
1624         {0x9082,0x03}, 
1625         {0x9086,0x67}, 
1626         {0x9087,0x31}, 
1627         {0x9088,0x02}, 
1628         {0x9089,0xF7}, 
1629         {0x908A,0x02}, 
1630         {0x908E,0x66}, 
1631         {0x908F,0xED}, 
1632         {0x9090,0x03}, 
1633         {0x9091,0x1D}, 
1634         {0x9092,0x02}, 
1635         {0x9096,0x67}, 
1636         {0x9097,0x73}, 
1637         {0x9098,0x03}, 
1638         {0x9099,0xD3}, 
1639         {0x909A,0x02}, 
1640         {0x909E,0x20}, 
1641         {0x909F,0x40}, 
1642         {0x90A0,0x03}, 
1643         {0x90A1,0x3B}, 
1644         {0x90A2,0x02}, 
1645         {0x90A6,0xC5}, 
1646         {0x90A7,0xC0}, 
1647         {0x90A8,0x03}, 
1648         {0x90A9,0xF0}, 
1649         {0x90AA,0x02}, 
1650         {0x90AE,0x41}, 
1651         {0x90AF,0xB3}, 
1652         {0x90B0,0x00}, 
1653         {0x90B1,0xA2}, 
1654         {0x90B2,0x02}, 
1655         {0x90B6,0x44}, 
1656         {0x90B7,0xBA}, 
1657         {0x90B8,0x00}, 
1658         {0x90B9,0xF0}, 
1659         {0x90BA,0x03}, 
1660         {0x90BE,0x89}, 
1661         {0x90BF,0x99}, 
1662         {0x90C0,0x04}, 
1663         {0x90C1,0x00}, 
1664         {0x90C2,0x02}, 
1665         {0x90C6,0xA7}, 
1666         {0x90C7,0x91}, 
1667         {0x90C8,0x04}, 
1668         {0x90C9,0x21}, 
1669         {0x90CA,0x02}, 
1670         {0x90CE,0x3A}, 
1671         {0x90CF,0x51}, 
1672         {0x90D0,0x00}, 
1673         {0x90D1,0xA2}, 
1674         {0x90D2,0x02}, 
1675         {0x90D6,0x86}, 
1676         {0x90D7,0x54}, 
1677         {0x90D8,0x04}, 
1678         {0x90D9,0x47}, 
1679         {0x90DA,0x02}, 
1680         {0x9000,0x01}, 
1681         {0xffff,0x00},   // 2013-03-01 end
1682         {SEQUENCE_END, 0x00}
1683 #endif 
1684 };
1685 static struct reginfo sensor_init_data1[] =
1686 {
1687 {0x0009,0x16}, //10
1688 {0x0085,0x00}, 
1689 {0x0040,0x00},
1690 {0x0016,0x00},
1691 {0x0046,0x00},
1692 {0x0041,0x00},
1693 {0x00B5,0x02},
1694 {0x7101,0x44},
1695 {0x00ED,0x0A},
1696 {0x00EE,0x1E},
1697 {0x00B3,0x80},
1698 {0x7104,0x00},
1699 {0x7105,0x80},
1700 {0x019C,0x4B},
1701 {0x019D,0x20},
1702 {0x0129,0x00},
1703 {0x0130,0x00},
1704 {0x0083,0x01},
1705 {0x0084,0x01},
1706 {0x01A1,0x80},
1707 {0x01A2,0x80},
1708 {0x01A3,0x80},
1709 {0x01A0,0x01},
1710 {0x0021,0x00},
1711 {0x0022,0x01},
1712
1713 {0x0040,0x00}, //00
1714 {0x0060,0x00},
1715 {0x0013,0x00},
1716 {0x0041,0x00},//00:5M 03:SVGA
1717
1718 {0x0061,0x00},
1719 {0x0046,0x02},
1720 {0x0066,0x02},
1721 {0x0012,0x00},
1722 {0x7102,0x09},
1723 {0x7103,0x00},
1724 {0x7158,0x00},
1725 {0x00E8,0x01},
1726 {0x7000,0x2C},
1727 {0x5200,0x01},
1728 {0x7000,0x0C},
1729 {0x0143,0x5F},
1730 {0x0144,0x0D},
1731 {0x02C2,0x00},
1732 {0x02C3,0xC0},
1733 {0x015E,0x40},
1734 {0x015F,0x00},
1735 {0x0390,0x01},
1736 {0x0391,0x00},
1737 {0x0392,0x00},
1738 {0x03A0,0x14},
1739 {0x03A1,0x00},
1740 {0x03A2,0x5A},
1741 {0x03A3,0xEE},
1742 {0x03A4,0x69},
1743 {0x03A5,0x49},
1744 {0x03A6,0x3E},
1745 {0x03A7,0x00},
1746 {0x03A8,0x39},
1747 {0x03A9,0x33},
1748 {0x03B0,0x60},
1749 {0x03B1,0x00},
1750 {0x03B2,0x5A},
1751 {0x03B3,0xEE},
1752 {0x03B4,0x69},
1753 {0x03B5,0x49},
1754 {0x03B6,0x3E},
1755 {0x03B7,0x00},
1756 {0x03B8,0x3D},
1757 {0x03B9,0x20},
1758 {0x03C0,0x10},
1759 {0x03C1,0x00},
1760 {0x03C2,0x5A},
1761 {0x03C3,0xEE},
1762 {0x03C4,0x69},
1763 {0x03C5,0x49},
1764 {0x03C6,0x3A},
1765 {0x03C7,0x80},
1766 {0x03D0,0x64},
1767 {0x03D1,0x00},
1768 {0x03D2,0x5A},
1769 {0x03D3,0xEE},
1770 {0x03D4,0x69},
1771 {0x03D5,0x49},
1772 {0x03D6,0x34},
1773 {0x03D7,0xD1},
1774 {0x004C,0x08},
1775 {0x006C,0x08},
1776 {0x0350,0x00},
1777 {0x0351,0x5A},
1778 {0x0352,0xEE},
1779 {0x0353,0x69},
1780 {0x0354,0x49},
1781 {0x0355,0x39},
1782 {0x0356,0x6D},
1783 {0x0357,0x19},
1784 {0x0358,0x00},
1785 {0x0359,0x3C},
1786 {0x035A,0x5A},
1787 {0x035B,0xEE},
1788 {0x035C,0x69},
1789 {0x035D,0x49},
1790 {0x035E,0x39},
1791 {0x035F,0x85},
1792 {0x0049,0x14},
1793 {0x004A,0x0D},
1794 {0x0069,0x14},
1795 {0x006A,0x0D},
1796 {0x0090,0x00},
1797 {0x0091,0x5A},
1798 {0x0092,0xEE},
1799 {0x0093,0x3E},
1800 {0x0094,0x00},
1801 {0x0095,0x69},
1802 {0x0096,0x49},
1803 {0x0097,0x39},
1804 {0x0098,0xCF},
1805 {0x00A0,0x00},
1806 {0x00A1,0x5A},
1807 {0x00A2,0xEE},
1808 {0x00A3,0x3E},
1809 {0x00A4,0x00},
1810 {0x00A5,0x69},
1811 {0x00A6,0x49},
1812 {0x00A7,0x3B},
1813 {0x00A8,0x80},
1814 #if 0 // 03-06 old LSC
1815 {0x0420,0x00},
1816 {0x0421,0x09},
1817 {0x0422,0xff},
1818 {0x0423,0x9e},
1819 {0x0424,0x00},
1820 {0x0425,0x89},
1821 {0x0426,0x00},
1822 {0x0427,0xab},
1823 {0x0428,0xff},
1824 {0x0429,0xe9},
1825 {0x042a,0xff},
1826 {0x042b,0x8b},
1827 {0x042c,0x00},
1828 {0x042d,0x73},
1829 {0x042e,0xff},
1830 {0x042f,0xb6},
1831 {0x0430,0x00},
1832 {0x0431,0x54},
1833 {0x0432,0xff},
1834 {0x0433,0x43},
1835 {0x0434,0x01},
1836 {0x0435,0x04},
1837 {0x0436,0x01},
1838 {0x0437,0x34},
1839 {0x0438,0xff},
1840 {0x0439,0x7c},
1841 {0x043a,0xfe},
1842 {0x043b,0xd2},
1843 {0x043c,0x00},
1844 {0x043d,0x63},
1845 {0x043e,0xff},
1846 {0x043f,0x15},
1847 {0x0450,0x00},
1848 {0x0451,0x3b},
1849 {0x0452,0xff},
1850 {0x0453,0x98},
1851 {0x0454,0x00},
1852 {0x0455,0x6f},
1853 {0x0456,0x00},
1854 {0x0457,0x93},
1855 {0x0458,0xff},
1856 {0x0459,0xad},
1857 {0x045a,0xff},
1858 {0x045b,0x87},
1859 {0x045c,0x00},
1860 {0x045d,0x52},
1861 {0x045e,0xff},
1862 {0x045f,0xa7},
1863 {0x0440,0xff},
1864 {0x0441,0xfd},
1865 {0x0442,0xff},
1866 {0x0443,0x6c},
1867 {0x0444,0x00},
1868 {0x0445,0x90},
1869 {0x0446,0x00},
1870 {0x0447,0xa1},
1871 {0x0448,0x00},
1872 {0x0449,0x02},
1873 {0x044a,0xff},
1874 {0x044b,0x48},
1875 {0x044c,0x00},
1876 {0x044d,0x5b},
1877 {0x044e,0xff},
1878 {0x044f,0xb4},
1879 {0x0460,0xff},
1880 {0x0461,0x69},
1881 {0x0462,0xff},
1882 {0x0463,0xbb},
1883 {0x0464,0x00},
1884 {0x0465,0x84},
1885 {0x0466,0x00},
1886 {0x0467,0xa3},
1887 {0x0468,0x00},
1888 {0x0469,0x0e},
1889 {0x046a,0x00},
1890 {0x046b,0x76},
1891 {0x046c,0xff},
1892 {0x046d,0xaf},
1893 {0x046e,0xff},
1894 {0x046f,0xf5},
1895 {0x0470,0xff},
1896 {0x0471,0x8a},
1897 {0x0472,0xff},
1898 {0x0473,0x5a},
1899 {0x0474,0x00},
1900 {0x0475,0xef},
1901 {0x0476,0x01},
1902 {0x0477,0x16},
1903 {0x0478,0xff},
1904 {0x0479,0xd4},
1905 {0x047a,0x00},
1906 {0x047b,0x02},
1907 {0x047c,0x00},
1908 {0x047d,0x2c},
1909 {0x047e,0xff},
1910 {0x047f,0x95},
1911 {0x0490,0xff},
1912 {0x0491,0x9b},
1913 {0x0492,0xff},
1914 {0x0493,0x91},
1915 {0x0494,0x00},
1916 {0x0495,0x6f},
1917 {0x0496,0x00},
1918 {0x0497,0x95},
1919 {0x0498,0xff},
1920 {0x0499,0xd5},
1921 {0x049a,0x01},
1922 {0x049b,0x20},
1923 {0x049c,0xff},
1924 {0x049d,0xfb},
1925 {0x049e,0xff},
1926 {0x049f,0xe1},
1927 {0x0480,0xff},
1928 {0x0481,0x5a},
1929 {0x0482,0xff},
1930 {0x0483,0x91},
1931 {0x0484,0x00},
1932 {0x0485,0x8c},
1933 {0x0486,0x00},
1934 {0x0487,0x9f},
1935 {0x0488,0x00},
1936 {0x0489,0x29},
1937 {0x048a,0x00},
1938 {0x048b,0x53},
1939 {0x048c,0xff},
1940 {0x048d,0x80},
1941 {0x048e,0xff},
1942 {0x048f,0xf7},
1943 {0x04a0,0xff},
1944 {0x04a1,0x6c},
1945 {0x04a2,0xff},
1946 {0x04a3,0xb9},
1947 {0x04a4,0x00},
1948 {0x04a5,0x81},
1949 {0x04a6,0x00},
1950 {0x04a7,0x93},
1951 {0x04a8,0x00},
1952 {0x04a9,0x1c},
1953 {0x04aa,0x00},
1954 {0x04ab,0x39},
1955 {0x04ac,0xff},
1956 {0x04ad,0x9f},
1957 {0x04ae,0x00},
1958 {0x04af,0x0e},
1959 {0x04b0,0xff},
1960 {0x04b1,0xe0},
1961 {0x04b2,0xff},
1962 {0x04b3,0x7b},
1963 {0x04b4,0x00},
1964 {0x04b5,0xaa},
1965 {0x04b6,0x00},
1966 {0x04b7,0xc8},
1967 {0x04b8,0xff},
1968 {0x04b9,0xe1},
1969 {0x04ba,0x00},
1970 {0x04bb,0x0e},
1971 {0x04bc,0x00},
1972 {0x04bd,0x0b},
1973 {0x04be,0xff},
1974 {0x04bf,0xff},
1975 {0x04d0,0xff},
1976 {0x04d1,0xac},
1977 {0x04d2,0xff},
1978 {0x04d3,0x93},
1979 {0x04d4,0x00},
1980 {0x04d5,0x64},
1981 {0x04d6,0x00},
1982 {0x04d7,0x83},
1983 {0x04d8,0xff},
1984 {0x04d9,0xdb},
1985 {0x04da,0x00},
1986 {0x04db,0xa8},
1987 {0x04dc,0xff},
1988 {0x04dd,0xf5},
1989 {0x04de,0x00},
1990 {0x04df,0x15},
1991 {0x04c0,0xff},
1992 {0x04c1,0x5d},
1993 {0x04c2,0xff},
1994 {0x04c3,0x9c},
1995 {0x04c4,0x00},
1996 {0x04c5,0x82},
1997 {0x04c6,0x00},
1998 {0x04c7,0x96},
1999 {0x04c8,0x00},
2000 {0x04c9,0x33},
2001 {0x04ca,0x00},
2002 {0x04cb,0x07},
2003 {0x04cc,0xff},
2004 {0x04cd,0x71},
2005 {0x04ce,0x00},
2006 {0x04cf,0x11},
2007 {0x04e0,0xff},
2008 {0x04e1,0x6d},
2009 {0x04e2,0xff},
2010 {0x04e3,0xb8},
2011 {0x04e4,0x00},
2012 {0x04e5,0x84},
2013 {0x04e6,0x00},
2014 {0x04e7,0x96},
2015 {0x04e8,0xff},
2016 {0x04e9,0xc0},
2017 {0x04ea,0x00},
2018 {0x04eb,0x6d},
2019 {0x04ec,0xff},
2020 {0x04ed,0xbb},
2021 {0x04ee,0x00},
2022 {0x04ef,0x00},
2023 {0x04f0,0xff},
2024 {0x04f1,0xe0},
2025 {0x04f2,0xff},
2026 {0x04f3,0x95},
2027 {0x04f4,0x00},
2028 {0x04f5,0xa7},
2029 {0x04f6,0x00},
2030 {0x04f7,0xc8},
2031 {0x04f8,0xff},
2032 {0x04f9,0xde},
2033 {0x04fa,0x00},
2034 {0x04fb,0x7e},
2035 {0x04fc,0x00},
2036 {0x04fd,0x36},
2037 {0x04fe,0x00},
2038 {0x04ff,0x10},
2039 {0x0510,0xff},
2040 {0x0511,0xc1},
2041 {0x0512,0xff},
2042 {0x0513,0x9f},
2043 {0x0514,0x00},
2044 {0x0515,0x6a},
2045 {0x0516,0x00},
2046 {0x0517,0x89},
2047 {0x0518,0xff},
2048 {0x0519,0xdc},
2049 {0x051a,0x00},
2050 {0x051b,0x55},
2051 {0x051c,0x00},
2052 {0x051d,0x09},
2053 {0x051e,0x00},
2054 {0x051f,0x0d},
2055 {0x0500,0xff},
2056 {0x0501,0x60},
2057 {0x0502,0xff},
2058 {0x0503,0x9e},
2059 {0x0504,0x00},
2060 {0x0505,0x81},
2061 {0x0506,0x00},
2062 {0x0507,0x9c},
2063 {0x0508,0xff},
2064 {0x0509,0xc0},
2065 {0x050a,0x00},
2066 {0x050b,0x40},
2067 {0x050c,0xff},
2068 {0x050d,0x8e},
2069 {0x050e,0x00},
2070 {0x050f,0x00},
2071 {0x0561,0x0e},
2072 {0x0562,0x01},
2073 {0x0563,0x01},
2074 {0x0564,0x06},
2075 #endif // LSC end 
2076 #if 1  //new LSC start - 0306
2077 {0x0420,0x00},
2078 {0x0421,0x26},
2079 {0x0422,0xff},
2080 {0x0423,0x03},
2081 {0x0424,0x00},
2082 {0x0425,0x63},
2083 {0x0426,0x00},
2084 {0x0427,0x8e},
2085 {0x0428,0xff},
2086 {0x0429,0xf3},
2087 {0x042A,0x00},
2088 {0x042B,0x26},
2089 {0x042C,0xff},
2090 {0x042D,0xc8},
2091 {0x042E,0xff},
2092 {0x042F,0x5f},
2093 {0x0430,0x00},
2094 {0x0431,0x10}, 
2095 {0x0432,0xfe},
2096 {0x0433,0xcf}, 
2097 {0x0434,0x00},
2098 {0x0435,0xc2}, 
2099 {0x0436,0x00},
2100 {0x0437,0xf2}, 
2101 {0x0438,0xff},
2102 {0x0439,0xd0}, 
2103 {0x043A,0x00},
2104 {0x043B,0xa1}, 
2105 {0x043C,0x00},
2106 {0x043D,0x2f}, 
2107 {0x043E,0xfe},
2108 {0x043F,0xdc},
2109 {0x0450,0x00},
2110 {0x0451,0x36},  
2111 {0x0452,0xff},
2112 {0x0453,0x60},  
2113 {0x0454,0x00},
2114 {0x0455,0x43},  
2115 {0x0456,0x00},
2116 {0x0457,0x6b},  
2117 {0x0458,0xff},
2118 {0x0459,0xdf},  
2119 {0x045A,0x00},
2120 {0x045B,0x83},  
2121 {0x045C,0xff},
2122 {0x045D,0xeb},  
2123 {0x045E,0xff},
2124 {0x045F,0x5f},
2125 {0x0440,0x00},
2126 {0x0441,0x36},        
2127 {0x0442,0xff},
2128 {0x0443,0x3e},        
2129 {0x0444,0x00},
2130 {0x0445,0x6d},        
2131 {0x0446,0x00},
2132 {0x0447,0x87},        
2133 {0x0448,0x00},
2134 {0x0449,0x0f},        
2135 {0x044A,0xff},
2136 {0x044B,0xd3},        
2137 {0x044C,0x00},
2138 {0x044D,0x18},        
2139 {0x044E,0xff},
2140 {0x044F,0x4f},
2141 {0x0561,0x08},
2142 {0x0460,0x00},
2143 {0x0461,0x22},
2144 {0x0462,0xff},
2145 {0x0463,0x0a},
2146 {0x0464,0x00},
2147 {0x0465,0x63},
2148 {0x0466,0x00},
2149 {0x0467,0x8b},
2150 {0x0468,0xff},
2151 {0x0469,0xf9},
2152 {0x046A,0x00},
2153 {0x046B,0x17},
2154 {0x046C,0xff},
2155 {0x046D,0xbd},
2156 {0x046E,0xff},
2157 {0x046F,0x65},
2158 {0x0470,0x00},
2159 {0x0471,0x15}, 
2160 {0x0472,0xfe},
2161 {0x0473,0xd7}, 
2162 {0x0474,0x00},
2163 {0x0475,0xb6}, 
2164 {0x0476,0x00},
2165 {0x0477,0xe5}, 
2166 {0x0478,0xff},
2167 {0x0479,0xd0}, 
2168 {0x047A,0x00},
2169 {0x047B,0xb2}, 
2170 {0x047C,0x00},
2171 {0x047D,0x2c}, 
2172 {0x047E,0xfe},
2173 {0x047F,0xe6},
2174 {0x0490,0x00},
2175 {0x0491,0x2b},  
2176 {0x0492,0xff},
2177 {0x0493,0x71},  
2178 {0x0494,0x00},
2179 {0x0495,0x43},  
2180 {0x0496,0x00},
2181 {0x0497,0x69},  
2182 {0x0498,0xff},
2183 {0x0499,0xd7},  
2184 {0x049A,0x00},
2185 {0x049B,0x59},  
2186 {0x049C,0xff},
2187 {0x049D,0xde},  
2188 {0x049E,0xff},
2189 {0x049F,0x76},                                    
2190 {0x0480,0x00},
2191 {0x0481,0x38},        
2192 {0x0482,0xff},
2193 {0x0483,0x3a},        
2194 {0x0484,0x00},
2195 {0x0485,0x6b},        
2196 {0x0486,0x00},
2197 {0x0487,0x86},        
2198 {0x0488,0x00},
2199 {0x0489,0x14},        
2200 {0x048A,0xff},
2201 {0x048B,0xd7},        
2202 {0x048C,0x00},
2203 {0x048D,0x13},        
2204 {0x048E,0xff},
2205 {0x048F,0x58},
2206 {0x0562,0x08},
2207 {0x04A0,0x00},
2208 {0x04A1,0x17},
2209 {0x04A2,0xff},
2210 {0x04A3,0x2e},
2211 {0x04A4,0x00},
2212 {0x04A5,0x5d},
2213 {0x04A6,0x00},
2214 {0x04A7,0x7a},
2215 {0x04A8,0xff},
2216 {0x04A9,0xf9},
2217 {0x04AA,0xff},
2218 {0x04AB,0xc0},
2219 {0x04AC,0xff},
2220 {0x04AD,0xc7},
2221 {0x04AE,0xff},
2222 {0x04AF,0x7d},
2223 {0x04B0,0x00},
2224 {0x04B1,0x13}, 
2225 {0x04B2,0xff},
2226 {0x04B3,0x45}, 
2227 {0x04B4,0x00},
2228 {0x04B5,0x70}, 
2229 {0x04B6,0x00},
2230 {0x04B7,0x96}, 
2231 {0x04B8,0xff},
2232 {0x04B9,0xde}, 
2233 {0x04BA,0x00},
2234 {0x04BB,0x17}, 
2235 {0x04BC,0x00},
2236 {0x04BD,0x23}, 
2237 {0x04BE,0xff},
2238 {0x04BF,0x46},
2239 {0x04D0,0x00},
2240 {0x04D1,0x17},  
2241 {0x04D2,0xff},
2242 {0x04D3,0x99},  
2243 {0x04D4,0x00},
2244 {0x04D5,0x3d},  
2245 {0x04D6,0x00},
2246 {0x04D7,0x5f},  
2247 {0x04D8,0xff},
2248 {0x04D9,0xd1},  
2249 {0x04DA,0xff},
2250 {0x04DB,0xe2},  
2251 {0x04DC,0xff},
2252 {0x04DD,0xc6},  
2253 {0x04DE,0xff},
2254 {0x04DF,0x9c},                                    
2255 {0x04C0,0x00},
2256 {0x04C1,0x32},        
2257 {0x04C2,0xff},
2258 {0x04C3,0x4e},        
2259 {0x04C4,0x00},
2260 {0x04C5,0x5e},        
2261 {0x04C6,0x00},
2262 {0x04C7,0x7c},        
2263 {0x04C8,0x00},
2264 {0x04C9,0x17},        
2265 {0x04CA,0xff},
2266 {0x04CB,0x9b},        
2267 {0x04CC,0x00},
2268 {0x04CD,0x06},        
2269 {0x04CE,0xff},
2270 {0x04CF,0x70},
2271 {0x0563,0x05},
2272 {0x04E0,0x00},
2273 {0x04E1,0x11},
2274 {0x04E2,0xff},
2275 {0x04E3,0x20},
2276 {0x04E4,0x00},
2277 {0x04E5,0x5f},
2278 {0x04E6,0x00},
2279 {0x04E7,0x7b},
2280 {0x04E8,0x00},
2281 {0x04E9,0x02},
2282 {0x04EA,0xff},
2283 {0x04EB,0xf1},
2284 {0x04EC,0xff},
2285 {0x04ED,0xb7},
2286 {0x04EE,0xff},
2287 {0x04EF,0x7b},
2288 {0x04F0,0x00},
2289 {0x04F1,0x1c}, 
2290 {0x04F2,0xff},
2291 {0x04F3,0x08}, 
2292 {0x04F4,0x00},
2293 {0x04F5,0x7e}, 
2294 {0x04F6,0x00},
2295 {0x04F7,0xac}, 
2296 {0x04F8,0xff},
2297 {0x04F9,0xeb}, 
2298 {0x04FA,0x00},
2299 {0x04FB,0x93}, 
2300 {0x04FC,0x00},
2301 {0x04FD,0x1b}, 
2302 {0x04FE,0xff},
2303 {0x04FF,0x11}, 
2304 {0x0510,0xff},
2305 {0x0511,0xfe},  
2306 {0x0512,0xff},
2307 {0x0513,0x8e},  
2308 {0x0514,0x00},
2309 {0x0515,0x4a},  
2310 {0x0516,0x00},
2311 {0x0517,0x6e},  
2312 {0x0518,0xff},
2313 {0x0519,0xbb},  
2314 {0x051A,0xff},
2315 {0x051B,0xcc},  
2316 {0x051C,0xff},
2317 {0x051D,0x9a},  
2318 {0x051E,0xff},
2319 {0x051F,0xa2},  
2320 {0x0500,0x00},
2321 {0x0501,0x30},        
2322 {0x0502,0xff},
2323 {0x0503,0x36},        
2324 {0x0504,0x00},
2325 {0x0505,0x5d},        
2326 {0x0506,0x00},
2327 {0x0507,0x81},        
2328 {0x0508,0x00},
2329 {0x0509,0x1f},        
2330 {0x050A,0xff},
2331 {0x050B,0xd4},        
2332 {0x050C,0xff},
2333 {0x050D,0xfe},        
2334 {0x050E,0xff},
2335 {0x050F,0x75},
2336 {0x0564,0x00},
2337 #endif //new LSC end
2338 {0x0324,0x39},
2339 {0x0325,0xAE},
2340 {0x0326,0x3A},
2341 {0x0327,0x29},
2342 {0x0328,0x3B},
2343 {0x0329,0x0A},
2344 {0x032A,0x3B},
2345 {0x032B,0x62},
2346 {0x0320,0x01},
2347 {0x0321,0x04},
2348 {0x0322,0x01},
2349 {0x0323,0x01},
2350 {0x0330,0x01},
2351 {0x0384,0x00},
2352 {0x0337,0x01},
2353 {0x03EC,0x39},
2354 {0x03ED,0x85},
2355 {0x03FC,0x3A},
2356 {0x03FD,0x14},
2357 {0x040C,0x3A},
2358 {0x040D,0xF6},
2359 {0x041C,0x3B},
2360 {0x041D,0x9A},
2361 {0x03E0,0xB6},
2362 {0x03E1,0x04},
2363 {0x03E2,0xBB},
2364 {0x03E3,0xE9},
2365 {0x03E4,0xBC},
2366 {0x03E5,0x70},
2367 {0x03E6,0x37},
2368 {0x03E7,0x02},
2369 {0x03E8,0xBC},
2370 {0x03E9,0x00},
2371 {0x03EA,0xBF},
2372 {0x03EB,0x12},
2373 {0x03F0,0xBA},
2374 {0x03F1,0x7B},
2375 {0x03F2,0xBA},
2376 {0x03F3,0x83},
2377 {0x03F4,0xBB},
2378 {0x03F5,0xBC},
2379 {0x03F6,0x38},
2380 {0x03F7,0x2D},
2381 {0x03F8,0xBB},
2382 {0x03F9,0x23},
2383 {0x03FA,0xBD},
2384 {0x03FB,0xAC},
2385 {0x0400,0xBE},
2386 {0x0401,0x96},
2387 {0x0402,0xB9},
2388 {0x0403,0xBE},
2389 {0x0404,0xBB},
2390 {0x0405,0x57},
2391 {0x0406,0x3A},
2392 {0x0407,0xBB},
2393 {0x0408,0xB3},
2394 {0x0409,0x17},
2395 {0x040A,0xBE},
2396 {0x040B,0x66},
2397 {0x0410,0xBB},
2398 {0x0411,0x2A},
2399 {0x0412,0xBA},
2400 {0x0413,0x00},
2401 {0x0414,0xBB},
2402 {0x0415,0x10},
2403 {0x0416,0xB8},
2404 {0x0417,0xCD},
2405 {0x0418,0xB7},
2406 {0x0419,0x5C},
2407 {0x041A,0xBB},
2408 {0x041B,0x6C},
2409 {0x01f8,0x3c},
2410 {0x01f9,0x00},
2411 {0x01fa,0x00},
2412 {0x02a2,0x3e},
2413 {0x02a3,0x00},
2414 {0x02a4,0x3e},
2415 {0x02a5,0x00},
2416 {0x02a6,0x3e},
2417 {0x02a7,0x00},
2418 {0x02a8,0x3e},
2419 {0x02a9,0x00},
2420 {0x056c,0x42},
2421 {0x056d,0x00},
2422 {0x056e,0x42},
2423 {0x056f,0x00},
2424 {0x0570,0x42},
2425 {0x0571,0x00},
2426 {0x0572,0x42},
2427 {0x0573,0x00},
2428 {0x0081,0x55},  //6E->55
2429 {0x0588,0x00},
2430 {0x0589,0x5A},
2431 {0x058A,0xEE},
2432 {0x058B,0x69},
2433 {0x058C,0x49},
2434 {0x058D,0x3D},
2435 {0x058E,0x3D},
2436 {0x0080,0x6C},
2437 {0x0082,0x5A},
2438 {0x0010,0x01},  
2439
2440         {SEQUENCE_END, 0x00}
2441 };
2442
2443 static struct reginfo sensor_init_data2[] =
2444 {
2445 {0x4708,0x00},
2446 {0x4709,0x00},
2447 {0x4710,0x00},
2448 {0x4711,0x00},
2449 //AF intial setting
2450 #if 0
2451 {0x065A,0x00},
2452 {0x06C9,0x01},
2453 {0x06CD,0x01},
2454 {0x06CE,0xBD},
2455 {0x06CF,0x00},
2456 {0x06D0,0x93},
2457 {0x06D1,0x02},
2458 {0x06D2,0x30},
2459 {0x06D3,0xD4},
2460 {0x06D4,0x01},
2461 {0x06DB,0x59},
2462 {0x06DC,0x0D},
2463 {0x0730,0x00},
2464 {0x0731,0x00},
2465 {0x0732,0x03},
2466 {0x0733,0xFF},
2467 {0x0734,0x03},
2468 {0x0735,0xff},
2469 {0x0755,0x01},
2470 {0x0756,0x00},//03->00
2471 {0x075B,0x01},//00
2472 {0x075E,0x00},
2473 {0x0764,0x01},
2474 {0x0766,0x01},//00
2475 {0x0768,0x01},
2476 {0x076A,0x00},//01
2477 {0x0758,0x01},
2478 {0x075C,0x01},
2479 {0x0770,0x98},
2480 {0x0771,0x19},
2481 {0x0772,0x1B},
2482 {0x0774,0x01},
2483 {0x0775,0x4A},
2484 {0x0777,0x00},
2485 {0x0778,0x45},
2486 {0x0779,0x00},
2487 {0x077A,0x02},
2488 {0x077D,0x01},
2489 {0x077E,0x03},
2490 {0x0783,0x10},
2491 {0x0785,0x14},
2492 {0x0846,0x06},
2493 {0x0847,0x05},
2494 #endif // old af @ vcm end -03-06
2495 #if 1 //03-06 new af @ vcm
2496 {0x0659,0x01},
2497 {0x065A,0x00},
2498 {0x06C9,0x01},
2499 {0x06CD,0x01},
2500 {0x06CE,0xBD},
2501 {0x06CF,0x00},
2502 {0x06D0,0x93},
2503 {0x06D1,0x02},
2504 {0x06D2,0x30},
2505 {0x06D3,0xD4},
2506 {0x06D4,0x01},
2507 {0x06DB,0x59},
2508 {0x06DC,0x0d},
2509 {0x0730,0x00},
2510 {0x0731,0x00},
2511 {0x0732,0x03},
2512 {0x0733,0xFF},
2513 {0x0734,0x03},
2514 {0x0735,0x70},
2515 {0x0755,0x01},
2516 {0x0756,0x00},
2517 {0x075A,0x00},
2518 {0x075B,0x01},
2519 {0x075E,0x00},
2520 {0x0764,0x01},
2521 {0x0766,0x01},
2522 {0x0768,0x01},
2523 {0x076A,0x00},
2524 {0x0758,0x01},
2525 {0x075C,0x01},
2526 {0x0770,0x98},
2527 {0x0771,0x19},
2528 {0x0772,0x1B},
2529 {0x0774,0x01},
2530 {0x0775,0x4a},
2531 {0x0777,0x00},
2532 {0x0778,0x45},
2533 {0x0779,0x00},
2534 {0x077A,0x02},
2535 {0x077D,0x01},
2536 {0x077E,0x03},
2537 {0x0783,0x10},
2538 {0x0785,0x14},
2539 {0x0788,0x04},
2540 {0x0846,0x06},
2541 {0x0847,0x05},
2542 #endif
2543 {0xC41A,0x05},
2544 {0xC423,0x11},
2545 {0xC427,0x11},
2546 {0x300B,0x09},
2547
2548 {0x7000,0x08}, 
2549 {0x5200,0x09}, 
2550 {0x00B2,0x50}, 
2551 {0x00B3,0x80}, 
2552 {0x00B5,0x01}, 
2553 {0x0030,0x14}, 
2554 {0x0040,0x01}, //AB2
2555 {0x0041,0x03}, //SVGA mode
2556
2557 {0x0010,0x01},
2558
2559         {SEQUENCE_END, 0x00}
2560 };  //sensor_init_data2 end
2561
2562
2563
2564 /* 720p 15fps @ 1280x720 */
2565
2566 static struct reginfo sensor_720p[]=
2567 {
2568         
2569         {SEQUENCE_END, 0x00}
2570 };
2571
2572 /*      1080p, 0x15fps, 0xyuv @1920x1080 */
2573
2574 static struct reginfo sensor_1080p[]=
2575 {
2576
2577         {SEQUENCE_END, 0x00}
2578 };
2579
2580 /* 2592X1944 QSXGA */
2581 static struct reginfo sensor_qsxga[] =
2582 {
2583         
2584 //{0x0010,0x02},
2585
2586 {0x7000,0x08},
2587 {0x5200,0x09},
2588 //{0x00B2,0x50},
2589 //{0x00B3,0x80},
2590 //{0x00B5,0x02},
2591 //{0x0030,0x11},
2592 {0x0040,0x00},
2593 {0x0041,0x00},
2594 {0x0010,0x01},
2595
2596         {SEQUENCE_END, 0x00}
2597 };
2598 /* 2048*1536 QXGA */
2599 static struct reginfo sensor_qxga[] =
2600 {
2601         {SEQUENCE_END, 0x00}
2602 };
2603
2604 /* 1600X1200 UXGA */
2605 static struct reginfo sensor_uxga[] =
2606 {
2607 #if 0
2608 {0x7000,0x08},
2609 {0x5200,0x09},
2610 //{0x00B2,0x50},
2611 //{0x00B3,0x80},
2612 //{0x00B5,0x02},
2613 //{0x0030,0x14},
2614 {0x0040,0x00},
2615 {0x0041,0x01},
2616 {0x0010,0x01},
2617 #endif
2618         {SEQUENCE_END, 0x00}
2619 };
2620
2621 /* 1280X1024 SXGA */
2622 static struct reginfo sensor_sxga[] =
2623 {
2624 #if 0
2625 {0x7000,0x08},
2626 {0x5200,0x09},
2627 //{0x00B2,0x50},
2628 //{0x00B3,0x80},
2629 //{0x00B5,0x02},
2630 //{0x0030,0x14},
2631 {0x0040,0x00},
2632 {0x0041,0x02},
2633 {0x0010,0x01},
2634 #endif
2635         {SEQUENCE_END, 0x00}
2636 };
2637 /* 1024X768 XGA */
2638 static struct reginfo sensor_xga[] =
2639 {
2640 #if 0
2641 {0x7000,0x08},
2642 {0x5200,0x09},
2643 //{0x00B2,0x50},
2644 //{0x00B3,0x80},
2645 //{0x00B5,0x02},
2646 //{0x0030,0x11},
2647 {0x0040,0x01},
2648 {0x0041,0x0a},
2649 {0x0042,0x05},
2650 {0x0043,0x00},
2651 {0x0044,0x03},
2652 {0x0045,0x20},
2653 {0x0010,0x01},
2654 #endif
2655         {SEQUENCE_END, 0x00}
2656 };
2657 /* 800X600 SVGA*/
2658 static struct reginfo sensor_svga[] =
2659 {
2660 //{0x0010,0x02},
2661
2662 //{0x7000,0x08},
2663 //{0x5200,0x09},
2664 //{0x00B2,0x50},
2665 //{0x00B3,0x80},
2666 //{0x00B5,0x02},
2667 //{0x0030,0x14},
2668 {0x0040,0x01},
2669 {0x0041,0x03},
2670
2671 {0x00ed,0x0A},
2672 {0x00ee,0x1E},
2673
2674 //{0x0010,0x01},
2675         
2676         {SEQUENCE_END, 0x00}
2677 };
2678
2679 /* 640X480 VGA */
2680 static struct reginfo sensor_vga[] =
2681 {
2682         
2683
2684 {0x7000,0x08},
2685 {0x5200,0x09},
2686 {0x0040,0x01},
2687 {0x0041,0x04},
2688 {0x00ed,0x1E},
2689 {0x00ee,0x1E},
2690 {0x331e,0x00},
2691
2692         {SEQUENCE_END, 0x00}
2693 };
2694 /* 352X288 CIF */
2695 static struct reginfo sensor_cif[] =
2696 {
2697
2698         {SEQUENCE_END, 0x00}
2699 };
2700
2701 /* 320*240 QVGA */
2702 static  struct reginfo sensor_qvga[] =
2703 {
2704
2705         {SEQUENCE_END, 0x00}
2706 };
2707
2708 /* 176X144 QCIF*/
2709 static struct reginfo sensor_qcif[] =
2710 {
2711
2712         {SEQUENCE_END, 0x00}
2713 };
2714 #endif
2715 static  struct reginfo sensor_ClrFmt_YUYV[]=
2716 {
2717
2718         {SEQUENCE_END, 0x00}
2719 };
2720
2721 static  struct reginfo sensor_ClrFmt_UYVY[]=
2722 {
2723
2724         {SEQUENCE_END, 0x00}
2725 };
2726
2727
2728 #if CONFIG_SENSOR_WhiteBalance
2729 static  struct reginfo sensor_WhiteB_Auto[]=
2730 {
2731         {0x01A0,0x01},
2732         {SEQUENCE_END, 0x00}
2733 };
2734 /* Cloudy Colour Temperature : 6500K - 8000K  */
2735 static  struct reginfo sensor_WhiteB_Cloudy[]=
2736 {
2737         {0x01A0,0x04},
2738         {SEQUENCE_END, 0x00}
2739 };
2740 /* ClearDay Colour Temperature : 5000K - 6500K  */
2741 static  struct reginfo sensor_WhiteB_ClearDay[]=
2742 {
2743         {0x01A0,0x05},
2744         {SEQUENCE_END, 0x00}
2745 };
2746 /* Office Colour Temperature : 3500K - 5000K  */
2747 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
2748 {
2749         {0x01A0,0x07},
2750         {SEQUENCE_END, 0x00}
2751 };
2752 /* Home Colour Temperature : 2500K - 3500K  */
2753 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
2754 {
2755         {0x01A0,0x08},
2756         {SEQUENCE_END, 0x00}
2757 };
2758 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
2759     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
2760 };
2761 #endif
2762
2763 #if CONFIG_SENSOR_Brightness
2764 static  struct reginfo sensor_Brightness0[]=
2765 {
2766         {0x082,0x34},
2767         {SEQUENCE_END, 0x00}
2768 };
2769 static  struct reginfo sensor_Brightness1[]=
2770 {
2771         {0x082,0x44},
2772         {SEQUENCE_END, 0x00}
2773 };
2774
2775 static  struct reginfo sensor_Brightness2[]=
2776 {
2777         {0x082,0x54},
2778         {SEQUENCE_END, 0x00}
2779 };
2780 static  struct reginfo sensor_Brightness3[]=
2781 {
2782         {0x082,0x64},
2783         {SEQUENCE_END, 0x00}
2784 };
2785 static  struct reginfo sensor_Brightness4[]=
2786 {
2787         {0x082,0x74},
2788         {SEQUENCE_END, 0x00}
2789 };
2790
2791 static  struct reginfo sensor_Brightness5[]=
2792 {
2793         {0x082,0x84},
2794         {SEQUENCE_END, 0x00}
2795 };
2796 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
2797     sensor_Brightness4, sensor_Brightness5,NULL,
2798 };
2799
2800 #endif
2801
2802 #if CONFIG_SENSOR_Effect
2803 static  struct reginfo sensor_Effect_Normal[] =
2804 {
2805         {0x0380,0x0},
2806         {0x0381,0x0},
2807         {0x0382,0x0},
2808         {0x0384,0x0},
2809         {SEQUENCE_END, 0x00}
2810 };
2811 static  struct reginfo sensor_Effect_WandB[] =
2812 {
2813         {0x0380,0x0},
2814         {0x0381,0x0},
2815         {0x0382,0x0},
2816         {0x0384,0x5},
2817         {SEQUENCE_END, 0x00}
2818 };
2819 static  struct reginfo sensor_Effect_Sepia[] =
2820 {
2821         {0x0380,0x0},
2822         {0x0381,0x0},
2823         {0x0382,0x0},
2824         {0x0384,0x6},
2825         {SEQUENCE_END, 0x00}
2826 };
2827
2828 static  struct reginfo sensor_Effect_Negative[] =
2829 {
2830     //Negative
2831         {0x0380,0x0},
2832         {0x0381,0x0},
2833         {0x0382,0x0},
2834         {0x0384,0x8},
2835         {SEQUENCE_END, 0x00}
2836 };static  struct reginfo sensor_Effect_Bluish[] =
2837 {
2838     // Bluish
2839 {0x0380,0x0},
2840         {0x0381,0x0},
2841         {0x0382,0x0},
2842         {0x0384,0x4},
2843         {SEQUENCE_END, 0x00}
2844 };
2845
2846 static  struct reginfo sensor_Effect_Green[] =
2847 {
2848     //  Greenish
2849         {0x0380,0x0},
2850         {0x0381,0x0},
2851         {0x0382,0x0},
2852         {0x0384,0x3},
2853         {SEQUENCE_END, 0x00}
2854 };
2855 /*static  struct reginfo sensor_Effect_Reddish[] =
2856 {
2857     //  Greenish
2858
2859         {SEQUENCE_END, 0x00}
2860 };*/
2861
2862 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Negative,sensor_Effect_Sepia,
2863     sensor_Effect_Bluish, sensor_Effect_Green,NULL,
2864 };
2865 #endif
2866 #if CONFIG_SENSOR_Exposure
2867 static  struct reginfo sensor_Exposure0[]=
2868 {
2869         {SEQUENCE_END, 0x00}
2870 };
2871 static  struct reginfo sensor_Exposure1[]=
2872 {
2873         {SEQUENCE_END, 0x00}
2874 };
2875 static  struct reginfo sensor_Exposure2[]=
2876 {
2877         {SEQUENCE_END, 0x00}
2878 };
2879
2880 static  struct reginfo sensor_Exposure3[]=
2881 {
2882         {SEQUENCE_END, 0x00}
2883 };
2884 static  struct reginfo sensor_Exposure4[]=
2885 {
2886         {SEQUENCE_END, 0x00}
2887 };
2888 static  struct reginfo sensor_Exposure5[]=
2889 {
2890         {SEQUENCE_END, 0x00}
2891 };
2892 static  struct reginfo sensor_Exposure6[]=
2893 {
2894         {SEQUENCE_END, 0x00}
2895 };
2896 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
2897     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
2898 };
2899 #endif
2900 #if CONFIG_SENSOR_Saturation
2901 static  struct reginfo sensor_Saturation0[]=
2902 {
2903         {0x081,0x34},
2904         {SEQUENCE_END, 0x00}
2905 };
2906
2907 static  struct reginfo sensor_Saturation1[]=
2908 {
2909         {0x081,0x44},
2910         {SEQUENCE_END, 0x00}
2911 };
2912
2913 static  struct reginfo sensor_Saturation2[]=
2914 {
2915         {0x081,0x54},
2916         {SEQUENCE_END, 0x00}
2917 };
2918 static  struct reginfo sensor_Saturation3[]=
2919 {
2920         {0x081,0x64},
2921         {SEQUENCE_END, 0x00}
2922 };
2923
2924 static  struct reginfo sensor_Saturation4[]=
2925 {
2926         {0x081,0x74},
2927         {SEQUENCE_END, 0x00}
2928 };
2929 static  struct reginfo sensor_Saturation5[]=
2930 {
2931         {0x081,0x84},
2932         {SEQUENCE_END, 0x00}
2933 };
2934
2935 static  struct reginfo sensor_Saturation6[]=
2936 {
2937         {0x081,0x94},
2938         {SEQUENCE_END, 0x00}
2939 };
2940 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2,sensor_Saturation3, sensor_Saturation4, sensor_Saturation5,sensor_Saturation6, NULL,};
2941
2942 #endif
2943 #if CONFIG_SENSOR_Contrast
2944 static  struct reginfo sensor_Contrast0[]=
2945 {
2946         {0x080,0x34},
2947         {SEQUENCE_END, 0x00}
2948 };
2949
2950 static  struct reginfo sensor_Contrast1[]=
2951 {
2952         {0x080,0x44},
2953         {SEQUENCE_END, 0x00}
2954 };
2955 static  struct reginfo sensor_Contrast2[]=
2956 {
2957         {0x080,0x54},
2958         {SEQUENCE_END, 0x00}
2959 };
2960
2961 static  struct reginfo sensor_Contrast3[]=
2962 {
2963         {0x080,0x64},
2964         {SEQUENCE_END, 0x00}
2965 };
2966
2967 static  struct reginfo sensor_Contrast4[]=
2968 {
2969         {0x080,0x74},
2970         {SEQUENCE_END, 0x00}
2971 };
2972
2973
2974 static  struct reginfo sensor_Contrast5[]=
2975 {
2976         {0x080,0x84},
2977         {SEQUENCE_END, 0x00}
2978 };
2979
2980 static  struct reginfo sensor_Contrast6[]=
2981 {
2982         {0x080,0x94},
2983         {SEQUENCE_END, 0x00}
2984 };
2985 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
2986     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
2987 };
2988
2989 #endif
2990 #if CONFIG_SENSOR_Mirror
2991 static  struct reginfo sensor_MirrorOn[]=
2992 {
2993         {SEQUENCE_END, 0x00}
2994 };
2995 static  struct reginfo sensor_MirrorOff[]=
2996 {
2997         {SEQUENCE_END, 0x00}
2998 };
2999 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
3000 #endif
3001 #if CONFIG_SENSOR_Flip
3002 static  struct reginfo sensor_FlipOn[]=
3003 {
3004         {SEQUENCE_END, 0x00}
3005 };
3006
3007 static  struct reginfo sensor_FlipOff[]=
3008 {
3009         {SEQUENCE_END, 0x00}
3010 };
3011 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
3012
3013 #endif
3014 #if CONFIG_SENSOR_Scene
3015 static  struct reginfo sensor_SceneAuto[] =
3016 {
3017
3018         {SEQUENCE_END, 0x00}
3019 };
3020 static  struct reginfo sensor_SceneNight[] =
3021 {
3022     //15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mzh pclk
3023         
3024         {SEQUENCE_END, 0x00}
3025 };
3026 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
3027
3028 #endif
3029 #if CONFIG_SENSOR_DigitalZoom
3030 static struct reginfo sensor_Zoom0[] =
3031 {
3032         {SEQUENCE_END, 0x00}
3033 };
3034 static struct reginfo sensor_Zoom1[] =
3035 {
3036         {SEQUENCE_END, 0x00}
3037 };
3038
3039 static struct reginfo sensor_Zoom2[] =
3040 {
3041         {SEQUENCE_END, 0x00}
3042 };
3043
3044
3045 static struct reginfo sensor_Zoom3[] =
3046 {
3047         {SEQUENCE_END, 0x00}
3048 };
3049 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
3050 #endif
3051 static const struct v4l2_querymenu sensor_menus[] =
3052 {
3053         #if CONFIG_SENSOR_WhiteBalance
3054     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
3055     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
3056     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
3057     #endif
3058
3059         #if CONFIG_SENSOR_Effect
3060     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
3061     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
3062     { .id = V4L2_CID_EFFECT,  .index = 4, .name = "posterize", .reserved = 0,} ,{ .id = V4L2_CID_EFFECT,  .index = 5,  .name = "aqua", .reserved = 0,},
3063     #endif
3064
3065         #if CONFIG_SENSOR_Scene
3066     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
3067     #endif
3068
3069         #if CONFIG_SENSOR_Flash
3070     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
3071     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
3072     #endif
3073 };
3074
3075 static  struct v4l2_queryctrl sensor_controls[] =
3076 {
3077         #if CONFIG_SENSOR_WhiteBalance
3078     {
3079         .id             = V4L2_CID_DO_WHITE_BALANCE,
3080         .type           = V4L2_CTRL_TYPE_MENU,
3081         .name           = "White Balance Control",
3082         .minimum        = 0,
3083         .maximum        = 4,
3084         .step           = 1,
3085         .default_value = 0,
3086     },
3087     #endif
3088
3089         #if CONFIG_SENSOR_Brightness
3090         {
3091         .id             = V4L2_CID_BRIGHTNESS,
3092         .type           = V4L2_CTRL_TYPE_INTEGER,
3093         .name           = "Brightness Control",
3094         .minimum        = -3,
3095         .maximum        = 2,
3096         .step           = 1,
3097         .default_value = 0,
3098     },
3099     #endif
3100
3101         #if CONFIG_SENSOR_Effect
3102         {
3103         .id             = V4L2_CID_EFFECT,
3104         .type           = V4L2_CTRL_TYPE_MENU,
3105         .name           = "Effect Control",
3106         .minimum        = 0,
3107         .maximum        = 5,
3108         .step           = 1,
3109         .default_value = 0,
3110     },
3111         #endif
3112
3113         #if CONFIG_SENSOR_Exposure
3114         {
3115         .id             = V4L2_CID_EXPOSURE,
3116         .type           = V4L2_CTRL_TYPE_INTEGER,
3117         .name           = "Exposure Control",
3118         .minimum        = 0,
3119         .maximum        = 6,
3120         .step           = 1,
3121         .default_value = 0,
3122     },
3123         #endif
3124
3125         #if CONFIG_SENSOR_Saturation
3126         {
3127         .id             = V4L2_CID_SATURATION,
3128         .type           = V4L2_CTRL_TYPE_INTEGER,
3129         .name           = "Saturation Control",
3130         .minimum        = 0,
3131         .maximum        = 2,
3132         .step           = 1,
3133         .default_value = 0,
3134     },
3135     #endif
3136
3137         #if CONFIG_SENSOR_Contrast
3138         {
3139         .id             = V4L2_CID_CONTRAST,
3140         .type           = V4L2_CTRL_TYPE_INTEGER,
3141         .name           = "Contrast Control",
3142         .minimum        = -3,
3143         .maximum        = 3,
3144         .step           = 1,
3145         .default_value = 0,
3146     },
3147         #endif
3148
3149         #if CONFIG_SENSOR_Mirror
3150         {
3151         .id             = V4L2_CID_HFLIP,
3152         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3153         .name           = "Mirror Control",
3154         .minimum        = 0,
3155         .maximum        = 1,
3156         .step           = 1,
3157         .default_value = 1,
3158     },
3159     #endif
3160
3161         #if CONFIG_SENSOR_Flip
3162         {
3163         .id             = V4L2_CID_VFLIP,
3164         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3165         .name           = "Flip Control",
3166         .minimum        = 0,
3167         .maximum        = 1,
3168         .step           = 1,
3169         .default_value = 1,
3170     },
3171     #endif
3172
3173         #if CONFIG_SENSOR_Scene
3174     {
3175         .id             = V4L2_CID_SCENE,
3176         .type           = V4L2_CTRL_TYPE_MENU,
3177         .name           = "Scene Control",
3178         .minimum        = 0,
3179         .maximum        = 1,
3180         .step           = 1,
3181         .default_value = 0,
3182     },
3183     #endif
3184
3185         #if CONFIG_SENSOR_DigitalZoom
3186     {
3187         .id             = V4L2_CID_ZOOM_RELATIVE,
3188         .type           = V4L2_CTRL_TYPE_INTEGER,
3189         .name           = "DigitalZoom Control",
3190         .minimum        = -1,
3191         .maximum        = 1,
3192         .step           = 1,
3193         .default_value = 0,
3194     }, {
3195         .id             = V4L2_CID_ZOOM_ABSOLUTE,
3196         .type           = V4L2_CTRL_TYPE_INTEGER,
3197         .name           = "DigitalZoom Control",
3198         .minimum        = 0,
3199         .maximum        = 3,
3200         .step           = 1,
3201         .default_value = 0,
3202     },
3203     #endif
3204
3205         #if CONFIG_SENSOR_Focus
3206         /*{
3207         .id             = V4L2_CID_FOCUS_RELATIVE,
3208         .type           = V4L2_CTRL_TYPE_INTEGER,
3209         .name           = "Focus Control",
3210         .minimum        = -1,
3211         .maximum        = 1,
3212         .step           = 1,
3213         .default_value = 0,
3214     }, {
3215         .id             = V4L2_CID_FOCUS_ABSOLUTE,
3216         .type           = V4L2_CTRL_TYPE_INTEGER,
3217         .name           = "Focus Control",
3218         .minimum        = 0,
3219         .maximum        = 255,
3220         .step           = 1,
3221         .default_value = 125,
3222     },*/
3223         {
3224         .id             = V4L2_CID_FOCUSZONE,
3225         .type           = V4L2_CTRL_TYPE_INTEGER,
3226         .name           = "FocusZone Control",
3227         .minimum        = -1,
3228         .maximum        = 1,
3229         .step           = 1,
3230         .default_value = 0,
3231     },{
3232         .id             = V4L2_CID_FOCUS_AUTO,
3233         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3234         .name           = "Focus Control",
3235         .minimum        = 0,
3236         .maximum        = 1,
3237         .step           = 1,
3238         .default_value = 0,
3239     },{
3240         .id             = V4L2_CID_FOCUS_CONTINUOUS,
3241         .type           = V4L2_CTRL_TYPE_BOOLEAN,
3242         .name           = "Focus Control",
3243         .minimum        = 0,
3244         .maximum        = 1,
3245         .step           = 1,
3246         .default_value = 0,
3247     },
3248     #endif
3249
3250         #if CONFIG_SENSOR_Flash
3251         {
3252         .id             = V4L2_CID_FLASH,
3253         .type           = V4L2_CTRL_TYPE_MENU,
3254         .name           = "Flash Control",
3255         .minimum        = 0,
3256         .maximum        = 3,
3257         .step           = 1,
3258         .default_value = 0,
3259     },
3260         #endif
3261 };
3262
3263 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
3264 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
3265 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
3266 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
3267 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
3268 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
3269 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
3270 static int sensor_resume(struct soc_camera_device *icd);
3271 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
3272 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
3273 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
3274 #if CONFIG_SENSOR_WhiteBalance
3275 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
3276 #endif
3277 static int sensor_deactivate(struct i2c_client *client);
3278 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
3279 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf);
3280
3281 static struct soc_camera_ops sensor_ops =
3282 {
3283     .suspend                     = sensor_suspend,
3284     .resume                       = sensor_resume,
3285     .set_bus_param              = sensor_set_bus_param,
3286     .query_bus_param    = sensor_query_bus_param,
3287     .controls           = sensor_controls,
3288     .menus                         = sensor_menus,
3289     .num_controls               = ARRAY_SIZE(sensor_controls),
3290     .num_menus          = ARRAY_SIZE(sensor_menus),
3291 };
3292 /* only one fixed colorspace per pixelcode */
3293 struct sensor_datafmt {
3294         enum v4l2_mbus_pixelcode code;
3295         enum v4l2_colorspace colorspace;
3296 };
3297
3298 /* Find a data format by a pixel code in an array */
3299 static const struct sensor_datafmt *sensor_find_datafmt(
3300         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
3301         int n)
3302 {
3303         int i;
3304         for (i = 0; i < n; i++)
3305                 if (fmt[i].code == code)
3306                         return fmt + i;
3307
3308         return NULL;
3309 }
3310
3311 static const struct sensor_datafmt sensor_colour_fmts[] = {
3312     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
3313     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
3314 };
3315 enum sensor_wq_cmd
3316 {
3317     WqCmd_af_init,
3318     WqCmd_af_single,
3319     WqCmd_af_special_pos,
3320     WqCmd_af_far_pos,
3321     WqCmd_af_near_pos,
3322     WqCmd_af_continues,
3323     WqCmd_af_continues_pause,
3324     WqCmd_af_return_idle,
3325 };
3326 enum sensor_wq_result
3327 {
3328     WqRet_success = 0,
3329     WqRet_fail = -1,
3330     WqRet_inval = -2
3331 };
3332 struct sensor_work
3333 {
3334         struct i2c_client *client;
3335         struct delayed_work dwork;
3336         enum sensor_wq_cmd cmd;
3337     wait_queue_head_t done;
3338     enum sensor_wq_result result;
3339     bool wait;
3340     int var;    
3341     int zone_pos[4];
3342 };
3343
3344 typedef struct sensor_info_priv_s
3345 {
3346     int whiteBalance;
3347     int brightness;
3348     int contrast;
3349     int saturation;
3350     int effect;
3351     int scene;
3352     int digitalzoom;
3353     int focus;
3354         int auto_focus;
3355         int affm_reinit;
3356     int flash;
3357     int exposure;
3358         bool snap2preview;
3359         bool video2preview;
3360     unsigned char mirror;                                        /* HFLIP */
3361     unsigned char flip;                                          /* VFLIP */
3362     struct reginfo *winseqe_cur_addr;
3363         struct sensor_datafmt fmt;
3364         unsigned int enable;
3365         unsigned int funmodule_state;
3366 } sensor_info_priv_t;
3367
3368
3369
3370 struct sensor_parameter
3371 {
3372     char af_pos[2];
3373 };
3374
3375 struct sensor
3376 {
3377     struct v4l2_subdev subdev;
3378     struct i2c_client *client;
3379     sensor_info_priv_t info_priv;
3380         struct sensor_parameter parameter;
3381         struct workqueue_struct *sensor_wq;
3382         struct mutex wq_lock;
3383     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
3384 #if CONFIG_SENSOR_I2C_NOSCHED
3385         atomic_t tasklock_cnt;
3386 #endif
3387         struct rk29camera_platform_data *sensor_io_request;
3388     struct rk29camera_gpio_res *sensor_gpio_res;
3389 };
3390
3391 static struct sensor* to_sensor(const struct i2c_client *client)
3392 {
3393     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
3394 }
3395
3396 static int sensor_task_lock(struct i2c_client *client, int lock)
3397 {
3398 #if CONFIG_SENSOR_I2C_NOSCHED
3399         int cnt = 3;
3400     struct sensor *sensor = to_sensor(client);
3401
3402         if (lock) {
3403                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
3404                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
3405                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
3406                                 msleep(35);
3407                                 cnt--;
3408                         }
3409                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
3410                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
3411                                 goto sensor_task_lock_err;
3412                         }
3413                         preempt_disable();
3414                 }
3415
3416                 atomic_add(1, &sensor->tasklock_cnt);
3417         } else {
3418                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
3419                         atomic_sub(1, &sensor->tasklock_cnt);
3420
3421                         if (atomic_read(&sensor->tasklock_cnt) == 0)
3422                                 preempt_enable();
3423                 }
3424         }
3425         return 0;
3426 sensor_task_lock_err:
3427         return -1;   
3428 #else
3429     return 0;
3430 #endif
3431
3432 }
3433
3434
3435 #if CONFIG_SENSOR_WRITE_REGS
3436 static int sensor_write_regs(struct i2c_client *client,  u8 *reg_info, int num)
3437 {
3438         int err=0,cnt;
3439         struct i2c_msg msg[1];
3440
3441         msg->len = num; 
3442         msg->addr = client->addr;       
3443         msg->flags = client->flags;     
3444         msg->buf = reg_info;    
3445         msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */      
3446         msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */   
3447
3448         
3449         cnt= 3; 
3450         err = -EAGAIN;
3451         
3452         while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */             
3453                 err = i2c_transfer(client->adapter, msg, 1);            
3454                 if (err >= 0) {                     
3455                         return 0;               
3456                 } else {                            
3457                         SENSOR_TR("\n %s write reg failed, try to write again!\n",      SENSOR_NAME_STRING());                      
3458                         udelay(10);     
3459                 }       
3460         }
3461         
3462         return err;
3463
3464 }
3465
3466 #endif
3467
3468
3469
3470
3471 /* sensor register write */
3472 static int sensor_write(struct i2c_client *client, u16 reg, u8 val)
3473 {
3474     int err,cnt;
3475     u8 buf[3];
3476     struct i2c_msg msg[1];
3477
3478     buf[0] = reg >> 8;
3479     buf[1] = reg & 0xFF;
3480     buf[2] = val;
3481
3482     msg->addr = client->addr;
3483     msg->flags = client->flags;
3484     msg->buf = buf;
3485     msg->len = sizeof(buf);
3486     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
3487     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
3488
3489     cnt = 3;
3490     err = -EAGAIN;
3491
3492     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
3493         err = i2c_transfer(client->adapter, msg, 1);
3494
3495         if (err >= 0) {
3496             return 0;
3497         } else {
3498             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
3499             udelay(10);
3500         }
3501     }
3502
3503     return err;
3504 }
3505
3506 /* sensor register read */
3507 static int sensor_read(struct i2c_client *client, u16 reg, u8 *val)
3508 {
3509     int err,cnt;
3510     u8 buf[2];
3511     struct i2c_msg msg[2];
3512
3513     buf[0] = reg >> 8;
3514     buf[1] = reg & 0xFF;
3515
3516     msg[0].addr = client->addr;
3517     msg[0].flags = client->flags;
3518     msg[0].buf = buf;
3519     msg[0].len = sizeof(buf);
3520     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
3521     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
3522
3523     msg[1].addr = client->addr;
3524     msg[1].flags = client->flags|I2C_M_RD;
3525     msg[1].buf = buf;
3526     msg[1].len = 1;
3527     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
3528     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
3529
3530     cnt = 3;
3531     err = -EAGAIN;
3532     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
3533         err = i2c_transfer(client->adapter, msg, 2);
3534
3535         if (err >= 0) {
3536             *val = buf[0];
3537             return 0;
3538         } else {
3539                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
3540             udelay(10);
3541         }
3542     }
3543
3544     return err;
3545 }
3546
3547 /* write a array of registers  */
3548 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
3549 {
3550     int err = 0, cnt;
3551     int i = 0;
3552 #if CONFIG_SENSOR_Focus
3553         struct sensor *sensor = to_sensor(client);
3554 #endif
3555 #if CONFIG_SENSOR_I2C_RDWRCHK
3556         char valchk;
3557 #endif
3558 #if CONFIG_SENSOR_WRITE_REGS    
3559         int j = 0, reg_num;
3560         u8 *ptemp, *phead;
3561         int reg_length;
3562 #endif
3563
3564         cnt = 0;
3565         if (sensor_task_lock(client, 1) < 0)
3566                 goto sensor_write_array_end;
3567     while (regarray[i].reg != SEQUENCE_END) {
3568         
3569         #if 0
3570         if ((regarray == sensor_af_firmware) && (sensor->info_priv.enable == 0)) {
3571                         SENSOR_DG("%s disable, Download af firmware terminated!\n",SENSOR_NAME_STRING());
3572                         err = -EINVAL;
3573                         goto sensor_write_array_end;
3574         }
3575                 #endif
3576
3577 #if CONFIG_SENSOR_WRITE_REGS
3578         
3579                 j = i;          
3580                 reg_num = 2;    
3581                 reg_length = 0x0001;
3582                                                 
3583                 while((regarray[i].reg + reg_length) == regarray[i+1].reg) {            
3584                         i++;                    
3585                         reg_num++;
3586                         if(reg_num >= WRITE_REGS_NUM)
3587                                 break;
3588                 }
3589                 
3590                 if(reg_num > 2) {                       
3591                         
3592                         int size_num;
3593                         size_num = reg_num + 1;
3594                         
3595                         ptemp = phead = (u8*)kmalloc((size_num+10)*sizeof(u8),GFP_KERNEL);
3596                         if (!phead) {
3597                                 SENSOR_DG("-------------write registers allocate memory fail!!!\n");
3598                 i = j;
3599                 err = sensor_write(client, regarray[i].reg, regarray[i].val); 
3600                         } else {                        
3601                         *phead = regarray[j].reg >> 8;                  
3602                         *(ptemp+1) = regarray[j].reg & 0xFF;
3603                         ptemp += 2;                             
3604                         for( ; reg_num > 0; reg_num --, j++) {
3605                                 *ptemp ++ = regarray[j].val;
3606                         }
3607                         
3608                         ptemp = phead;                  
3609                         err = sensor_write_regs(client, ptemp,size_num);                        
3610                         kfree(phead);   
3611                         }
3612                 }else{
3613                         err = sensor_write(client, regarray[i].reg, regarray[i].val);
3614                 }       
3615 #else
3616                 err = sensor_write(client, regarray[i].reg, regarray[i].val);        
3617 #endif
3618         if (err < 0)
3619         {
3620             if (cnt-- > 0) {
3621                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
3622                                 i = 0;
3623                                 continue;
3624             } else {
3625                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
3626                 err = -EPERM;
3627                                 goto sensor_write_array_end;
3628             }
3629         } else {
3630         #if CONFIG_SENSOR_I2C_RDWRCHK
3631                         sensor_read(client, regarray[i].reg, &valchk);
3632                         if (valchk != regarray[i].val)
3633                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
3634                 #endif
3635         }
3636         i++; 
3637     }
3638
3639         #if CONFIG_SENSOR_Focus
3640         if (((regarray->reg == SEQUENCE_PROPERTY) && (regarray->val == SEQUENCE_INIT))
3641                 || (regarray == sensor_init_data)) {
3642                 sensor->info_priv.affm_reinit = 1;
3643         }
3644         #endif
3645
3646 sensor_write_array_end:
3647         sensor_task_lock(client,0);
3648     return err;
3649 }
3650 #if CONFIG_SENSOR_I2C_RDWRCHK
3651 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
3652 {
3653     int cnt;
3654     int i = 0;
3655         char valchk;
3656
3657         cnt = 0;
3658         valchk = 0;
3659     while (regarray[i].reg != 0)
3660     {
3661                 sensor_read(client, regarray[i].reg, &valchk);
3662                 if (valchk != regarray[i].val)
3663                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
3664
3665         i++;
3666     }
3667     return 0;
3668 }
3669 #endif
3670 #if CONFIG_SENSOR_Focus
3671 struct af_cmdinfo
3672 {
3673         char cmd_tag;
3674         char cmd_para[4];
3675         char validate_bit;
3676 };
3677 static int sensor_af_cmdset(struct i2c_client *client, int cmd_main, struct af_cmdinfo *cmdinfo)
3678 {
3679
3680         return 0;
3681 sensor_af_cmdset_err:
3682         return -1;
3683 }
3684
3685 static int sensor_af_idlechk(struct i2c_client *client)
3686 {
3687         int ret = 0;
3688
3689     sensor_write(client,0x070A, 0x00);
3690     sensor_write(client,0x0700, 0x03);
3691     sensor_write(client,0x0701, 0xFF);  
3692     sensor_write(client,0x070C, 0x00);
3693     sensor_write(client,0x070C, 0x07);
3694     
3695 sensor_af_idlechk_end:
3696         return ret;
3697 }
3698 static int sensor_af_touch_zone(struct i2c_client *client, int *zone_pos)
3699 {
3700         int ret = 0;
3701     int xstart,ystart;
3702     
3703     *zone_pos += 1000;
3704     *(zone_pos+1) += 1000;
3705     *(zone_pos+2) += 1000;
3706     *(zone_pos+3) += 1000;
3707
3708     xstart = ((*zone_pos + *(zone_pos+2))>>1)*800/2000;
3709     ystart = ((*(zone_pos+1) + *(zone_pos+3))>>1)*600/2000;
3710
3711     if (xstart>0xa0) {
3712         xstart -= 0xa0;
3713     } else {
3714         xstart = 0;
3715     }
3716
3717     if (ystart>0xa0) {
3718         ystart -= 0xa0;
3719     } else {
3720         ystart = 0;
3721     }
3722     
3723     ret |= sensor_write(client, AF_ZONE0_WEIGHT,0x01);
3724     ret |= sensor_write(client, AF_ZONE1_WEIGHT,0x00); 
3725     ret |= sensor_write(client, AF_ZONE2_WEIGHT,0x00);
3726     ret |= sensor_write(client, AF_ZONE3_WEIGHT,0x00);  
3727     ret |= sensor_write(client, AF_ZONE4_WEIGHT,0x00);    
3728     ret |= sensor_write(client, AF_ZONE5_WEIGHT,0x00);
3729     ret |= sensor_write(client, AF_ZONE6_WEIGHT,0x00);    
3730     ret |= sensor_write(client, FACE_LC,0x03); 
3731
3732     ret |= sensor_write(client, FACE_START_XH, ((xstart&0xff00)>>8));
3733     ret |= sensor_write(client, FACE_START_XL, xstart&0xff);
3734     ret |= sensor_write(client, FACE_START_YH, ((ystart&0xff00)>>8));
3735     ret |= sensor_write(client, FACE_START_YL, ystart&0xff);    
3736
3737     ret |= sensor_write(client, FACE_SIZE_XH, 0x01);
3738         ret |= sensor_write(client, FACE_SIZE_XL, 0x40);
3739         ret |= sensor_write(client, FACE_SIZE_YH, 0x01);
3740         ret |= sensor_write(client, FACE_SIZE_YL, 0x40);
3741
3742     SENSOR_DG("%s touch focus zone at (%d,%d)\n",SENSOR_NAME_STRING(), xstart,ystart);
3743     msleep(10);
3744 sensor_af_zone_end:
3745     return ret;
3746 }
3747 static int sensor_af_single(struct i2c_client *client)
3748 {
3749         int ret = 0;
3750         char state,cnt=0;
3751     struct sensor *sensor = to_sensor(client);
3752     
3753         ret |= sensor_write(client,AF_MODES_REG,0x03);
3754     ret |= sensor_write(client,AF_AUTOCMDS_REG,0x01);
3755     msleep(200);
3756     ret |= sensor_write(client,AF_AUTOCMDS_REG,0x02);
3757
3758     do  {
3759         msleep(20);
3760         sensor_read(client,AF_FINISHCHK_REG,&state);
3761         cnt++;
3762     }while ((state != 1) && (cnt<100));
3763
3764     if (state == 1) {
3765         sensor_read(client, AF_LENSPOS_REG_H,&sensor->parameter.af_pos[0]);
3766         sensor_read(client, AF_LENSPOS_REG_L,&sensor->parameter.af_pos[1]);
3767     }
3768
3769     SENSOR_DG("%s single focus, state: %d cnt: %d\n",SENSOR_NAME_STRING(),state,cnt);
3770 sensor_af_single_end:
3771         return ret;
3772 }
3773
3774 static int sensor_af_const(struct i2c_client *client)
3775 {
3776         int ret = 0;
3777
3778     ret = sensor_write(client, AF_MODES_REG, 0x01);
3779
3780     SENSOR_DG("%s const focus\n",SENSOR_NAME_STRING());
3781         return ret;
3782 }
3783 static int sensor_af_const_pause (struct i2c_client *client)
3784 {
3785     int ret = 0;
3786     char status;
3787     struct sensor *sensor = to_sensor(client);
3788     
3789     sensor_read(client, 0x07ae, &status);
3790
3791     if (status == 1) {
3792         sensor_read(client, AF_LENSPOS_REG_H,&sensor->parameter.af_pos[0]);
3793         sensor_read(client, AF_LENSPOS_REG_L,&sensor->parameter.af_pos[1]);
3794     } else {
3795         sensor_af_single(client);
3796     }
3797
3798     SENSOR_DG("%s const focus pause\n",SENSOR_NAME_STRING());
3799     
3800 }
3801 static int sensor_af_special_pos (struct i2c_client *client)
3802 {
3803     struct sensor *sensor = to_sensor(client);
3804     char status=0;
3805     
3806     sensor_write(client,0x070A, 0x00);
3807         sensor_write(client,0x0734, sensor->parameter.af_pos[0]& 0xFF);
3808         sensor_write(client,0x0735, sensor->parameter.af_pos[1] & 0xFF);
3809         sensor_write(client,0x070C, 0x00);
3810         mdelay(100);
3811     sensor_write(client,0x070C, 0x05);
3812     return 0;
3813 }
3814
3815 static int sensor_af_init(struct i2c_client *client)
3816 {
3817         int ret = 0;
3818         char state,cnt;
3819
3820 sensor_af_init_end:
3821         SENSOR_DG("%s %s ret:0x%x \n",SENSOR_NAME_STRING(),__FUNCTION__,ret);
3822         return ret;
3823 }
3824
3825 static int sensor_af_downfirmware(struct i2c_client *client)
3826 {
3827         struct sensor *sensor = to_sensor(client);
3828         int ret=0;
3829     struct soc_camera_device *icd = client->dev.platform_data;
3830     struct v4l2_mbus_framefmt mf;
3831                 
3832         SENSOR_DG("%s %s Enter\n",SENSOR_NAME_STRING(), __FUNCTION__);
3833     
3834         if (sensor_af_init(client)) {
3835                 sensor->info_priv.funmodule_state &= (~SENSOR_AF_IS_OK);
3836                 ret = -1;
3837         } else {
3838                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
3839         
3840         mf.width = icd->user_width;
3841                 mf.height = icd->user_height;
3842         mf.code = sensor->info_priv.fmt.code;
3843         mf.colorspace = sensor->info_priv.fmt.colorspace;
3844         mf.field        = V4L2_FIELD_NONE;
3845         
3846         if (sensor_fmt_videochk(NULL, &mf) == true) {    /* ddl@rock-chips.com: focus mode fix const auto focus in video */
3847             ret = sensor_af_const(client);
3848         } else {
3849                 switch (sensor->info_priv.auto_focus)
3850                 {
3851                         case SENSOR_AF_MODE_AUTO:
3852                         {
3853                                 ret = sensor_af_single(client);
3854                                 break;
3855                         }
3856                         case SENSOR_AF_MODE_CLOSE:
3857                         {
3858                                 ret = 0;
3859                                 break;
3860                         }
3861                 case SENSOR_AF_MODE_CONTINUOUS:
3862                 {
3863                     ret = sensor_af_const(client);
3864                     break;
3865                 }
3866                         default:
3867                 {
3868                                 SENSOR_DG("%s focus mode(0x%x) is unkonwn\n",SENSOR_NAME_STRING(),sensor->info_priv.auto_focus);
3869                     goto sensor_af_downfirmware_end;
3870                         }
3871                 }
3872         }
3873                 SENSOR_DG("%s sensor_af_downfirmware set focus mode(0x%x) ret:0x%x\n",SENSOR_NAME_STRING(), sensor->info_priv.auto_focus,ret);
3874         }
3875
3876 sensor_af_downfirmware_end:
3877         
3878         return ret;
3879 }
3880 static void sensor_af_workqueue(struct work_struct *work)
3881 {
3882         struct sensor_work *sensor_work = container_of(work, struct sensor_work, dwork.work);
3883         struct i2c_client *client = sensor_work->client;
3884     struct sensor *sensor = to_sensor(client);
3885     struct af_cmdinfo cmdinfo;
3886     
3887     SENSOR_DG("%s %s Enter, cmd:0x%x \n",SENSOR_NAME_STRING(), __FUNCTION__,sensor_work->cmd);
3888     
3889     mutex_lock(&sensor->wq_lock);
3890     
3891     switch (sensor_work->cmd) 
3892     {
3893         case WqCmd_af_init:
3894         {
3895                 if (sensor_af_downfirmware(client) < 0) {
3896                         SENSOR_TR("%s Sensor_af_init is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3897                 }            
3898             break;
3899         }
3900         case WqCmd_af_single:
3901         {
3902             sensor_af_touch_zone(client,sensor_work->zone_pos);
3903             
3904             if (sensor_af_single(client) < 0) {
3905                         SENSOR_TR("%s Sensor_af_single is failed in sensor_af_workqueue!\n",SENSOR_NAME_STRING());
3906                 sensor_work->result = WqRet_fail;
3907                 } else {
3908                 sensor_work->result = WqRet_success;
3909                 }
3910             break;
3911         }
3912         
3913         case WqCmd_af_special_pos:
3914         {            
3915                         if (sensor_af_special_pos(client)< 0)
3916                sensor_work->result = WqRet_fail;
3917             else 
3918                sensor_work->result = WqRet_success;
3919             break;
3920         }
3921         #if 0 
3922         case WqCmd_af_near_pos:
3923         {            
3924             sensor_af_idlechk(client);
3925             cmdinfo.cmd_tag = StepFocus_Near_Tag;
3926             cmdinfo.validate_bit = 0x80;
3927                         if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3928                sensor_work->result = WqRet_fail;
3929             else 
3930                sensor_work->result = WqRet_success;
3931             break;
3932         }
3933         case WqCmd_af_far_pos:
3934         {
3935             sensor_af_idlechk(client);
3936                         cmdinfo.cmd_tag = StepFocus_Far_Tag;
3937                         cmdinfo.validate_bit = 0x80;
3938                         if (sensor_af_cmdset(client, StepMode_Cmd, &cmdinfo) < 0)
3939                sensor_work->result = WqRet_fail;
3940             else 
3941                sensor_work->result = WqRet_success;
3942             break;
3943         }
3944         #endif
3945         case WqCmd_af_continues:
3946         {
3947             if (sensor_af_const(client) < 0)
3948                sensor_work->result = WqRet_fail;
3949             else 
3950                sensor_work->result = WqRet_success;
3951             break;
3952         }
3953         case WqCmd_af_continues_pause:
3954         {
3955             if (sensor_af_const_pause(client) < 0)
3956                sensor_work->result = WqRet_fail;
3957             else 
3958                sensor_work->result = WqRet_success;
3959             break;
3960         }    
3961         case WqCmd_af_return_idle:
3962         {
3963             if (sensor_af_idlechk(client) < 0)
3964                sensor_work->result = WqRet_fail;
3965             else 
3966                sensor_work->result = WqRet_success;
3967             break;
3968         }  
3969         default:
3970             SENSOR_TR("Unknow command(%d) in %s af workqueue!",sensor_work->cmd,SENSOR_NAME_STRING());
3971             break;
3972     } 
3973 set_end:
3974     if (sensor_work->wait == false) {
3975         kfree((void*)sensor_work);
3976     } else {
3977         wake_up(&sensor_work->done); 
3978     }
3979     mutex_unlock(&sensor->wq_lock); 
3980     return;
3981 }
3982
3983 static int sensor_af_workqueue_set(struct soc_camera_device *icd, enum sensor_wq_cmd cmd, int var, bool wait, int *zone_pos)
3984 {
3985     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3986         struct sensor *sensor = to_sensor(client); 
3987     struct sensor_work *wk;
3988     int ret=0;
3989
3990     if (sensor->sensor_wq == NULL) { 
3991         ret = -EINVAL;
3992         goto sensor_af_workqueue_set_end;
3993     }
3994
3995     if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) != SENSOR_AF_IS_OK) {
3996         if (cmd != WqCmd_af_init) {
3997             SENSOR_TR("%s %s cmd(%d) ingore,because af module isn't ready!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3998             ret = -1;
3999             goto sensor_af_workqueue_set_end;
4000         }
4001     }
4002     
4003     wk = kzalloc(sizeof(struct sensor_work), GFP_KERNEL);
4004     if (wk) {
4005             wk->client = client;
4006             INIT_WORK(&(wk->dwork.work), sensor_af_workqueue);
4007         wk->cmd = cmd;
4008         wk->result = WqRet_inval;
4009         wk->wait = wait;
4010         wk->var = var;
4011         init_waitqueue_head(&wk->done);
4012
4013         if (zone_pos) {   
4014             if (*zone_pos || *(zone_pos+1) || *(zone_pos+2) || *(zone_pos+3)) {
4015                 memcpy(wk->zone_pos,zone_pos, sizeof(wk->zone_pos));
4016             }
4017         }
4018         
4019             queue_delayed_work(sensor->sensor_wq,&(wk->dwork),0);
4020         
4021         /* ddl@rock-chips.com: 
4022         * video_lock is been locked in v4l2_ioctl function, but auto focus may slow,
4023         * As a result any other ioctl calls will proceed very, very slowly since each call
4024         * will have to wait for the AF to finish. Camera preview is pause,because VIDIOC_QBUF 
4025         * and VIDIOC_DQBUF is sched. so unlock video_lock here.
4026         */
4027         if (wait == true) {
4028             mutex_unlock(&icd->video_lock);                     
4029             if (wait_event_timeout(wk->done, (wk->result != WqRet_inval), msecs_to_jiffies(2500)) == 0) {
4030                 SENSOR_TR("%s %s cmd(%d) is timeout!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);                        
4031             }
4032             ret = wk->result;
4033             kfree((void*)wk);
4034             mutex_lock(&icd->video_lock);  
4035         }
4036         
4037     } else {
4038         SENSOR_TR("%s %s cmd(%d) ingore,because struct sensor_work malloc failed!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4039         ret = -1;
4040     }
4041 sensor_af_workqueue_set_end:
4042     return ret;
4043 }
4044 #endif
4045 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
4046 {
4047         struct soc_camera_link *icl = to_soc_camera_link(icd);
4048         int ret = 0;
4049
4050     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
4051
4052         switch (cmd)
4053         {
4054                 #if 1 //derek
4055                 case Sensor_PowerDown:
4056                 {
4057                         if (icl->powerdown) {
4058                                 ret = icl->powerdown(icd->pdev, on);
4059                                 //printk("=============================<<<<222RK30_PIN1_PB7's value is %d\n",gpio_get_value(RK30_PIN1_PB7));
4060                                 if (ret == RK29_CAM_IO_SUCCESS) {
4061                                         if (on == 0) {
4062                                                 mdelay(2);
4063                                                 if (icl->reset)
4064                                                         icl->reset(icd->pdev);
4065                                                 
4066                                         }
4067                                 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
4068                                         ret = -ENODEV;
4069                                         goto sensor_power_end;
4070                                 }
4071                         }
4072                         break;
4073                 }
4074                 #endif
4075                 case Sensor_Flash:
4076                 {
4077                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4078                 struct sensor *sensor = to_sensor(client);
4079
4080                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
4081                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
4082                 if(on){
4083                     //flash off after 2 secs
4084                         hrtimer_cancel(&(flash_off_timer.timer));
4085                         hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
4086                     }
4087                         }
4088                         break;
4089                 }
4090                 default:
4091                 {
4092                         SENSOR_TR("%s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),cmd);
4093                         break;
4094                 }
4095         }
4096
4097 sensor_power_end:
4098         return ret;
4099 }
4100
4101 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
4102         struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
4103     sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
4104         SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
4105     return 0;
4106     
4107 }
4108
4109 static int sensor_init(struct v4l2_subdev *sd, u32 val)
4110 {
4111     struct i2c_client *client = v4l2_get_subdevdata(sd);
4112     struct soc_camera_device *icd = client->dev.platform_data;
4113     struct sensor *sensor = to_sensor(client);
4114         const struct v4l2_queryctrl *qctrl;
4115     const struct sensor_datafmt *fmt;
4116     char value;
4117     int ret,pid = 0;
4118
4119     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
4120 #if 1 //derek
4121         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
4122 //if (sensor_ioctrl(icd, Sensor_PowerDown, 1) < 0) {
4123                 ret = -ENODEV;
4124                 goto sensor_INIT_ERR;
4125         }
4126 #endif
4127     /* soft reset */
4128         if (sensor_task_lock(client,1)<0)
4129                 goto sensor_INIT_ERR;
4130   /* 
4131     ret = sensor_write(client, 0x3008, 0x80);
4132     if (ret != 0) {
4133         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
4134         ret = -ENODEV;
4135                 goto sensor_INIT_ERR;
4136     }
4137 */
4138     mdelay(5);  //delay 5 microseconds
4139         /* check if it is an sensor sensor */
4140
4141     ret = sensor_read(client, 0x0000, &value);
4142     if (ret != 0) {
4143         SENSOR_TR("read chip id high byte failed\n");
4144         ret = -ENODEV;
4145         goto sensor_INIT_ERR;
4146     }
4147     printk("jzw 5065:value=0x%02x\n",value);
4148     pid |= (value << 8);
4149
4150     ret = sensor_read(client, 0x0001, &value);
4151     if (ret != 0) {
4152         SENSOR_TR("read chip id low byte failed\n");
4153         ret = -ENODEV;
4154         goto sensor_INIT_ERR;
4155     }
4156      printk("jzw 506522:value=0x%02x\n",value);
4157     pid |= (value & 0xff);
4158     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
4159
4160     if (pid == SENSOR_ID) {
4161         sensor->model = SENSOR_V4L2_IDENT;
4162     } else {
4163         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4164         ret = -ENODEV;
4165         goto sensor_INIT_ERR;
4166     }
4167
4168     // 写两次init_date,尽量避免打开摄像头绿屏的问题,Edit by zhansb@20120524
4169     SENSOR_DG("write 1 time\n");
4170     ret = sensor_write_array(client, sensor_init_data);
4171     if (ret != 0) {
4172         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
4173         goto sensor_INIT_ERR;
4174     }
4175      msleep(200);
4176     ret = sensor_write_array(client, sensor_init_data1);
4177     if (ret != 0) {
4178         SENSOR_TR("error: %s initial1  failed\n",SENSOR_NAME_STRING());
4179         goto sensor_INIT_ERR;
4180     }
4181      msleep(200);
4182     ret = sensor_write_array(client, sensor_init_data2);
4183     if (ret != 0) {
4184         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
4185         goto sensor_INIT_ERR;
4186     }
4187          msleep(200);
4188 //   sensor_write(client, 0x070a, 0x01);         
4189     ret = sensor_read(client, 0x0010, &value);
4190     if (ret != 0) {
4191         ret = -ENODEV;
4192         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());           
4193         goto sensor_INIT_ERR;
4194     }
4195         printk("<<<<addr 0010 's value is %d\n",value);
4196
4197
4198
4199         sensor_task_lock(client,0);
4200     sensor->info_priv.winseqe_cur_addr  = SENSOR_INIT_WINSEQADR;
4201         fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
4202     if (!fmt) {
4203         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
4204         ret = -EINVAL;
4205         goto sensor_INIT_ERR;
4206     }
4207         sensor->info_priv.fmt = *fmt;
4208
4209 #if 1
4210     /* sensor sensor information for initialization  */
4211         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4212         if (qctrl)
4213         sensor->info_priv.whiteBalance = qctrl->default_value;
4214
4215         // 解决进摄像头后第一次拍的照片跟后续的拍的照片白平衡相差较大的问题,add by zhansb@120614
4216 #if CONFIG_SENSOR_WhiteBalance
4217     sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4218 #endif
4219         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
4220         if (qctrl)
4221         sensor->info_priv.brightness = qctrl->default_value;
4222         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4223         if (qctrl)
4224         sensor->info_priv.effect = qctrl->default_value;
4225         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
4226         if (qctrl)
4227         sensor->info_priv.exposure = qctrl->default_value;
4228
4229         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
4230         if (qctrl)
4231         sensor->info_priv.saturation = qctrl->default_value;
4232         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
4233         if (qctrl)
4234         sensor->info_priv.contrast = qctrl->default_value;
4235         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
4236         if (qctrl)
4237         sensor->info_priv.mirror = qctrl->default_value;
4238         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
4239         if (qctrl)
4240         sensor->info_priv.flip = qctrl->default_value;
4241         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
4242         if (qctrl)
4243         sensor->info_priv.scene = qctrl->default_value;
4244         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
4245         if (qctrl)
4246         sensor->info_priv.digitalzoom = qctrl->default_value;
4247
4248     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
4249         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
4250         if (qctrl)
4251         sensor->info_priv.focus = qctrl->default_value;
4252
4253         #if CONFIG_SENSOR_Flash
4254         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
4255         if (qctrl)
4256         sensor->info_priv.flash = qctrl->default_value;
4257     flash_off_timer.icd = icd;
4258         flash_off_timer.timer.function = flash_off_func;
4259     #endif
4260     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);
4261
4262     sensor->info_priv.funmodule_state = SENSOR_INIT_IS_OK;
4263 #endif     
4264     return 0;
4265 sensor_INIT_ERR:
4266     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4267         sensor_task_lock(client,0);
4268         sensor_deactivate(client); 
4269         printk("init error============================================================\n");
4270     return ret;
4271 }
4272 static int sensor_deactivate(struct i2c_client *client)
4273 {
4274         struct soc_camera_device *icd = client->dev.platform_data;
4275     struct sensor *sensor = to_sensor(client);
4276     
4277         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
4278
4279         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
4280     if (sensor->info_priv.funmodule_state & SENSOR_INIT_IS_OK) {
4281         
4282     } 
4283     #if 1 //derek
4284         sensor_ioctrl(icd, Sensor_PowerDown, 1);
4285     #endif
4286     
4287     msleep(100); 
4288         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
4289         icd->user_width = SENSOR_INIT_WIDTH;
4290     icd->user_height = SENSOR_INIT_HEIGHT;
4291     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
4292         return 0;
4293 }
4294
4295 static  struct reginfo sensor_power_down_sequence[]=
4296 {
4297     {0x00,0x00}
4298 };
4299
4300 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
4301 {
4302     int ret;
4303     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4304
4305     if (pm_msg.event == PM_EVENT_SUSPEND) {
4306         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
4307         ret = sensor_write_array(client, sensor_power_down_sequence) ;
4308         if (ret != 0) {
4309             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
4310             return ret;
4311         } else {
4312                 #if 0 //derek
4313             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
4314             if (ret < 0) {
4315                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
4316                 return -EINVAL;
4317             }
4318             #endif
4319         }
4320     } else {
4321         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
4322         return -EINVAL;
4323     }
4324
4325     return 0;
4326 }
4327
4328 static int sensor_resume(struct soc_camera_device *icd)
4329 {
4330         int ret;
4331 #if 0 //derek
4332     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
4333     if (ret < 0) {
4334                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
4335         return -EINVAL;
4336     }
4337 #endif
4338         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
4339         return 0;
4340 }
4341
4342 static int sensor_set_bus_param(struct soc_camera_device *icd,
4343                                 unsigned long flags)
4344 {
4345
4346     return 0;
4347 }
4348
4349 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
4350 {
4351     struct soc_camera_link *icl = to_soc_camera_link(icd);
4352     unsigned long flags = SENSOR_BUS_PARAM;
4353
4354     return soc_camera_apply_sensor_flags(icl, flags);
4355 }
4356
4357 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4358 {
4359     struct i2c_client *client = v4l2_get_subdevdata(sd);
4360     struct soc_camera_device *icd = client->dev.platform_data;
4361     struct sensor *sensor = to_sensor(client);
4362
4363     mf->width   = icd->user_width;
4364         mf->height      = icd->user_height;
4365         mf->code        = sensor->info_priv.fmt.code;
4366         mf->colorspace  = sensor->info_priv.fmt.colorspace;
4367         mf->field       = V4L2_FIELD_NONE;
4368
4369     return 0;
4370 }
4371 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4372 {   //capture mode
4373     bool ret = false;
4374
4375         if ((mf->width == 1024) && (mf->height == 768)) {
4376                 ret = true;
4377         } else if ((mf->width == 1280) && (mf->height == 1024)) {
4378                 ret = true;
4379         } else if ((mf->width == 1600) && (mf->height == 1200)) {
4380                 ret = true;
4381         } else if ((mf->width == 2048) && (mf->height == 1536)) {
4382                 ret = true;
4383         } else if ((mf->width == 2592) && (mf->height == 1944)) {
4384                 ret = true;
4385         }
4386
4387         if (ret == true)
4388                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
4389         return ret;
4390 }
4391
4392 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4393 {  // video mode
4394     bool ret = false;
4395
4396         if ((mf->width == 1280) && (mf->height == 720)) {
4397                 ret = true;
4398         } else if ((mf->width == 1920) && (mf->height == 1080)) {
4399                 ret = true;
4400         }
4401
4402         if (ret == true)
4403                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
4404         return ret;
4405 }
4406 static int sensor_s_fmt(struct v4l2_subdev *sd,struct v4l2_mbus_framefmt *mf)
4407 {
4408          char value,af_status=0,af_pos_h=0,af_pos_l=0;
4409     struct i2c_client *client = v4l2_get_subdevdata(sd);
4410     const struct sensor_datafmt *fmt;
4411     struct sensor *sensor = to_sensor(client);
4412         const struct v4l2_queryctrl *qctrl;
4413         struct soc_camera_device *icd = client->dev.platform_data;
4414     struct reginfo *winseqe_set_addr=NULL;
4415     int ret = 0, set_w,set_h;
4416         int i=0;
4417
4418     
4419         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4420                                    ARRAY_SIZE(sensor_colour_fmts));
4421         if (!fmt) {
4422         ret = -EINVAL;
4423         goto sensor_s_fmt_end;
4424     }
4425
4426         if (sensor->info_priv.fmt.code != mf->code) {
4427                 switch (mf->code)
4428                 {
4429                         case V4L2_MBUS_FMT_YUYV8_2X8:
4430                         {
4431                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
4432                                 break;
4433                         }
4434                         case V4L2_MBUS_FMT_UYVY8_2X8:
4435                         {
4436                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
4437                                 break;
4438                         }
4439                         default:
4440                                 break;
4441                 }
4442                 if (winseqe_set_addr != NULL) {
4443             sensor_write_array(client, winseqe_set_addr);
4444                         sensor->info_priv.fmt.code = mf->code;
4445             sensor->info_priv.fmt.colorspace= mf->colorspace;            
4446                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
4447                 } else {
4448                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
4449                 }
4450         }
4451
4452     set_w = mf->width;
4453     set_h = mf->height;    
4454                                 
4455         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
4456         {
4457                 winseqe_set_addr = sensor_qcif;
4458         set_w = 176;
4459         set_h = 144;
4460         }
4461         else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
4462     {
4463         winseqe_set_addr = sensor_qvga;
4464         set_w = 320;
4465         set_h = 240;
4466     }
4467     else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
4468     {
4469         winseqe_set_addr = sensor_cif;
4470         set_w = 352;
4471         set_h = 288;
4472     }
4473     else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
4474     {
4475         winseqe_set_addr = sensor_vga;
4476         set_w = 640;
4477         set_h = 480;
4478     }
4479     else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
4480     {   
4481         winseqe_set_addr = sensor_svga;
4482         set_w = 800;
4483         set_h = 600;
4484     }
4485         else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
4486     {
4487         winseqe_set_addr = sensor_xga;
4488         set_w = 1024;
4489         set_h = 768;
4490     }
4491         else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
4492     {
4493         winseqe_set_addr = sensor_720p;
4494         set_w = 1280;
4495         set_h = 720;
4496     }
4497     else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
4498     {
4499         winseqe_set_addr = sensor_sxga;
4500         set_w = 1280;
4501         set_h = 1024;
4502     }
4503     else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
4504     {
4505         winseqe_set_addr = sensor_uxga;
4506         set_w = 1600;
4507         set_h = 1200;
4508     }
4509     else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
4510     {
4511         winseqe_set_addr = sensor_1080p;
4512         set_w = 1920;
4513         set_h = 1080;
4514     }
4515         else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
4516     {
4517         winseqe_set_addr = sensor_qxga;
4518         set_w = 2048;
4519         set_h = 1536;
4520     }
4521         else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
4522     {
4523         
4524         winseqe_set_addr = sensor_qsxga;
4525         set_w = 2592;
4526         set_h = 1944;
4527     }
4528     else
4529     {
4530         winseqe_set_addr = SENSOR_INIT_WINSEQADR;               /* ddl@rock-chips.com : Sensor output smallest size if  isn't support app  */
4531         set_w = SENSOR_INIT_WIDTH;
4532         set_h = SENSOR_INIT_HEIGHT;
4533                 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
4534     }
4535     
4536     if (winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr)
4537     {
4538                 if (sensor_fmt_capturechk(sd,mf) == true) {                                     /* ddl@rock-chips.com : Capture */
4539         
4540                 #if CONFIG_SENSOR_Flash
4541             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4542                 sensor_ioctrl(icd, Sensor_Flash, Flash_On);
4543                 printk("%s flash on in capture!\n", SENSOR_NAME_STRING());
4544             }
4545         #endif
4546                 }else {                                        /* ddl@rock-chips.com : Video */
4547                 #if CONFIG_SENSOR_Flash 
4548             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4549                 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4550                 printk("%s flash off in preivew!\n", SENSOR_NAME_STRING());
4551             }
4552         #endif
4553         }
4554
4555         #if CONFIG_SENSOR_Focus
4556             if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS) {
4557                 sensor_af_workqueue_set(icd,WqCmd_af_continues_pause,0,true,NULL);    
4558             }
4559         #endif            
4560         
4561                 if ((sensor->info_priv.winseqe_cur_addr->reg == SEQUENCE_PROPERTY) && (sensor->info_priv.winseqe_cur_addr->val == SEQUENCE_INIT)) {
4562                         if (((winseqe_set_addr->reg == SEQUENCE_PROPERTY) && (winseqe_set_addr->val == SEQUENCE_NORMAL))
4563                                 || (winseqe_set_addr->reg != SEQUENCE_PROPERTY)) {
4564                                 ret |= sensor_write_array(client,sensor_init_data);
4565                                 SENSOR_DG("\n%s reinit ret:0x%x \n",SENSOR_NAME_STRING(), ret);
4566                         }
4567                 }
4568                 
4569         ret |= sensor_write_array(client, winseqe_set_addr);
4570         if (ret != 0) {
4571             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
4572             #if CONFIG_SENSOR_Flash
4573             if (sensor_fmt_capturechk(sd,mf) == true) {
4574                 if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
4575                     sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4576                     SENSOR_TR("%s Capture format set fail, flash off !\n", SENSOR_NAME_STRING());
4577                 }
4578             }
4579             #endif
4580             goto sensor_s_fmt_end;
4581         }
4582             sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
4583                 if (sensor_fmt_capturechk(sd,mf) == true) {                                 /* ddl@rock-chips.com : Capture */
4584         #if CONFIG_SENSOR_Focus
4585             sensor_af_workqueue_set(icd,WqCmd_af_special_pos,0,true,NULL);
4586         #endif
4587                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4588                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4589                         if (sensor->info_priv.whiteBalance != 0) {
4590                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4591                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4592                         }
4593                         sensor->info_priv.snap2preview = true;
4594                 } else if (sensor_fmt_videochk(sd,mf) == true) {                        /* ddl@rock-chips.com : Video */
4595                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4596                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4597
4598                         sensor->info_priv.video2preview = true;
4599                         
4600                 } else if ((sensor->info_priv.snap2preview == true) || (sensor->info_priv.video2preview == true)) {
4601                         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
4602                         sensor_set_effect(icd, qctrl,sensor->info_priv.effect);
4603
4604                         if (sensor->info_priv.snap2preview == true) {
4605                                 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
4606                                 sensor_set_whiteBalance(icd, qctrl,sensor->info_priv.whiteBalance);
4607                         }
4608             #if CONFIG_SENSOR_Focus
4609             if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_AUTO) {
4610                 sensor_af_workqueue_set(icd,WqCmd_af_return_idle,0,false,NULL);    
4611             } else if (sensor->info_priv.auto_focus == SENSOR_AF_MODE_CONTINUOUS) {
4612                 sensor_af_workqueue_set(icd,WqCmd_af_continues,0,false,NULL);    
4613             }
4614             #else   
4615             msleep(500);
4616             #endif
4617                         sensor->info_priv.video2preview = false;
4618                         sensor->info_priv.snap2preview = false;
4619                 }
4620         SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
4621     }
4622     else
4623     {                   // preview size @ video preview 
4624         SENSOR_DG("\n %s .. Current Format is validate. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),set_w,set_h);
4625     }
4626   
4627         mf->width = set_w;
4628         mf->height = set_h;
4629 sensor_s_fmt_end:
4630     return ret;
4631 }
4632
4633 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
4634 {
4635     struct i2c_client *client = v4l2_get_subdevdata(sd);
4636     struct sensor *sensor = to_sensor(client);
4637     const struct sensor_datafmt *fmt;
4638     int ret = 0,set_w,set_h;
4639    
4640         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
4641                                    ARRAY_SIZE(sensor_colour_fmts));
4642         if (fmt == NULL) {
4643                 fmt = &sensor->info_priv.fmt;
4644         mf->code = fmt->code;
4645         } 
4646
4647     if (mf->height > SENSOR_MAX_HEIGHT)
4648         mf->height = SENSOR_MAX_HEIGHT;
4649     else if (mf->height < SENSOR_MIN_HEIGHT)
4650         mf->height = SENSOR_MIN_HEIGHT;
4651
4652     if (mf->width > SENSOR_MAX_WIDTH)
4653         mf->width = SENSOR_MAX_WIDTH;
4654     else if (mf->width < SENSOR_MIN_WIDTH)
4655         mf->width = SENSOR_MIN_WIDTH;
4656
4657     set_w = mf->width;
4658     set_h = mf->height;
4659
4660         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
4661         {
4662         set_w = 176;
4663         set_h = 144;
4664         }
4665         else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
4666     {
4667         set_w = 320;
4668         set_h = 240;
4669     }
4670     else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
4671     {
4672         set_w = 352;
4673         set_h = 288;
4674     }
4675     else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
4676     {
4677         set_w = 640;
4678         set_h = 480;
4679     }
4680     else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
4681     {
4682         set_w = 800;
4683         set_h = 600;
4684     }
4685         else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
4686     {
4687         set_w = 1024;
4688         set_h = 768;
4689     }
4690         else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
4691     {
4692         set_w = 1280;
4693         set_h = 720;
4694     }
4695     else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
4696     {
4697         set_w = 1280;
4698         set_h = 1024;
4699     }
4700     else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
4701     {
4702         set_w = 1600;
4703         set_h = 1200;
4704     }
4705     else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
4706     {
4707         set_w = 1920;
4708         set_h = 1080;
4709     }
4710         else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
4711     {
4712         set_w = 2048;
4713         set_h = 1536;
4714     }
4715         else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
4716     {
4717         set_w = 2592;
4718         set_h = 1944;
4719     }
4720     else
4721     {
4722         set_w = SENSOR_INIT_WIDTH;
4723         set_h = SENSOR_INIT_HEIGHT;
4724     }
4725
4726     mf->width = set_w;
4727     mf->height = set_h;
4728     
4729     mf->colorspace = fmt->colorspace;
4730     
4731     return ret;
4732 }
4733
4734  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
4735 {
4736     struct i2c_client *client = v4l2_get_subdevdata(sd);
4737
4738     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
4739         return -EINVAL;
4740
4741     if (id->match.addr != client->addr)
4742         return -ENODEV;
4743
4744     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
4745     id->revision = 0;
4746
4747     return 0;
4748 }
4749 #if CONFIG_SENSOR_Brightness
4750 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4751 {
4752     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4753
4754     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4755     {
4756         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
4757         {
4758             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
4759             {
4760                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4761                 return -EINVAL;
4762             }
4763             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4764             return 0;
4765         }
4766     }
4767         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4768     return -EINVAL;
4769 }
4770 #endif
4771 #if CONFIG_SENSOR_Effect
4772 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4773 {
4774     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4775         
4776     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4777     {
4778         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
4779         {
4780             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
4781             {
4782                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4783                 return -EINVAL;
4784             }
4785             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4786             return 0;
4787         }
4788     }
4789         SENSOR_TR("\n%s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4790     return -EINVAL;
4791 }
4792 #endif
4793 #if CONFIG_SENSOR_Exposure
4794 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4795 {
4796     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4797
4798     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4799     {
4800         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
4801         {
4802             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
4803             {
4804                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4805                 return -EINVAL;
4806             }
4807             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4808             return 0;
4809         }
4810     }
4811         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4812     return -EINVAL;
4813 }
4814 #endif
4815 #if CONFIG_SENSOR_Saturation
4816 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4817 {
4818     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4819
4820     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4821     {
4822         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
4823         {
4824             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
4825             {
4826                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4827                 return -EINVAL;
4828             }
4829             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4830             return 0;
4831         }
4832     }
4833     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4834     return -EINVAL;
4835 }
4836 #endif
4837 #if CONFIG_SENSOR_Contrast
4838 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4839 {
4840     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4841
4842     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4843     {
4844         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
4845         {
4846             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
4847             {
4848                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4849                 return -EINVAL;
4850             }
4851             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4852             return 0;
4853         }
4854     }
4855     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4856     return -EINVAL;
4857 }
4858 #endif
4859 #if CONFIG_SENSOR_Mirror
4860 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4861 {
4862     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4863
4864     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4865     {
4866         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
4867         {
4868             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
4869             {
4870                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4871                 return -EINVAL;
4872             }
4873             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4874             return 0;
4875         }
4876     }
4877     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4878     return -EINVAL;
4879 }
4880 #endif
4881 #if CONFIG_SENSOR_Flip
4882 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4883 {
4884     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4885
4886     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4887     {
4888         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
4889         {
4890             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
4891             {
4892                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4893                 return -EINVAL;
4894             }
4895             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4896             return 0;
4897         }
4898     }
4899     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4900     return -EINVAL;
4901 }
4902 #endif
4903 #if CONFIG_SENSOR_Scene
4904 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4905 {
4906     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4907
4908     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4909     {
4910         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
4911         {
4912             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
4913             {
4914                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4915                 return -EINVAL;
4916             }
4917             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4918             return 0;
4919         }
4920     }
4921     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4922     return -EINVAL;
4923 }
4924 #endif
4925 #if CONFIG_SENSOR_WhiteBalance
4926 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4927 {
4928     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4929
4930     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
4931     {
4932         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
4933         {
4934             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
4935             {
4936                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4937                 return -EINVAL;
4938             }
4939             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4940             return 0;
4941         }
4942     }
4943         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4944     return -EINVAL;
4945 }
4946 #endif
4947 #if CONFIG_SENSOR_DigitalZoom
4948 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
4949 {
4950     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4951     struct sensor *sensor = to_sensor(client);
4952         const struct v4l2_queryctrl *qctrl_info;
4953     int digitalzoom_cur, digitalzoom_total;
4954
4955         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
4956         if (qctrl_info)
4957                 return -EINVAL;
4958
4959     digitalzoom_cur = sensor->info_priv.digitalzoom;
4960     digitalzoom_total = qctrl_info->maximum;
4961
4962     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
4963     {
4964         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
4965         return -EINVAL;
4966     }
4967
4968     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
4969     {
4970         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
4971         return -EINVAL;
4972     }
4973
4974     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
4975     {
4976         *value = digitalzoom_total - digitalzoom_cur;
4977     }
4978
4979     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
4980     {
4981         *value = 0 - digitalzoom_cur;
4982     }
4983
4984     digitalzoom_cur += *value;
4985
4986     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
4987     {
4988         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
4989         {
4990             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4991             return -EINVAL;
4992         }
4993         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
4994         return 0;
4995     }
4996
4997     return -EINVAL;
4998 }
4999 #endif
5000 #if CONFIG_SENSOR_Focus
5001 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5002 {
5003         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5004     struct sensor *sensor = to_sensor(client);
5005         const struct v4l2_queryctrl *qctrl_info;
5006         int ret = 0;
5007
5008         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
5009         if (!qctrl_info)
5010                 return -EINVAL;
5011     
5012         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5013                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
5014             ret = sensor_af_workqueue_set(icd, WqCmd_af_special_pos, value, true,NULL);
5015                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5016                 } else {
5017                         ret = -EINVAL;
5018                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5019                 }
5020         } else {
5021                 ret = -EACCES;
5022                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5023                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5024         }
5025
5026         return ret;
5027 }
5028 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5029 {
5030         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5031         struct sensor *sensor = to_sensor(client);
5032         const struct v4l2_queryctrl *qctrl_info;
5033         int ret = 0;
5034
5035         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
5036         if (!qctrl_info)
5037                 return -EINVAL;    
5038
5039         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
5040                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {            
5041             if (value > 0) {
5042                 ret = sensor_af_workqueue_set(icd, WqCmd_af_near_pos, 0, true,NULL);
5043             } else {
5044                 ret = sensor_af_workqueue_set(icd, WqCmd_af_far_pos, 0, true,NULL);
5045             }
5046                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5047                 } else {
5048                         ret = -EINVAL;
5049                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5050                 }
5051         } else {
5052                 ret = -EACCES;
5053                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5054                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5055         }
5056         return ret;
5057 }
5058
5059 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value, int *zone_pos)
5060 {
5061         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5062         struct sensor *sensor = to_sensor(client);
5063         int ret = 0;
5064     
5065         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)  && (sensor->info_priv.affm_reinit == 0)) {
5066                 switch (value)
5067                 {
5068                         case SENSOR_AF_MODE_AUTO:
5069                         {
5070                                 ret = sensor_af_workqueue_set(icd, WqCmd_af_single, 0, true, zone_pos);
5071                                 break;
5072                         }
5073
5074                         /*case SENSOR_AF_MODE_MACRO:
5075                         {
5076                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
5077                                 break;
5078                         }
5079
5080                         case SENSOR_AF_MODE_INFINITY:
5081                         {
5082                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
5083                                 break;
5084                         }
5085                         */
5086                         case SENSOR_AF_MODE_CONTINUOUS:
5087                         {
5088                                 ret = sensor_af_workqueue_set(icd, WqCmd_af_continues, 0, true,NULL);
5089                                 break;
5090                         }
5091                         default:
5092                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5093                                 break;
5094
5095                 }
5096
5097                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
5098         } else {
5099                 ret = -EACCES;
5100                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
5101                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
5102         }
5103
5104         return ret;
5105 }
5106 #endif
5107 #if CONFIG_SENSOR_Flash
5108 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
5109 {    
5110     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
5111         if (value == 3) {       /* ddl@rock-chips.com: torch */
5112             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
5113         } else {
5114             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
5115         }
5116         SENSOR_DG("%s..%s : %d\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
5117         return 0;
5118     }
5119     
5120         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
5121     return -EINVAL;
5122 }
5123 #endif
5124 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5125 {
5126     struct i2c_client *client = v4l2_get_subdevdata(sd);
5127     struct sensor *sensor = to_sensor(client);
5128     const struct v4l2_queryctrl *qctrl;
5129
5130     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5131
5132     if (!qctrl)
5133     {
5134         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5135         return -EINVAL;
5136     }
5137
5138     switch (ctrl->id)
5139     {
5140         case V4L2_CID_BRIGHTNESS:
5141             {
5142                 ctrl->value = sensor->info_priv.brightness;
5143                 break;
5144             }
5145         case V4L2_CID_SATURATION:
5146             {
5147                 ctrl->value = sensor->info_priv.saturation;
5148                 break;
5149             }
5150         case V4L2_CID_CONTRAST:
5151             {
5152                 ctrl->value = sensor->info_priv.contrast;
5153                 break;
5154             }
5155         case V4L2_CID_DO_WHITE_BALANCE:
5156             {
5157                 ctrl->value = sensor->info_priv.whiteBalance;
5158                 break;
5159             }
5160         case V4L2_CID_EXPOSURE:
5161             {
5162                 ctrl->value = sensor->info_priv.exposure;
5163                 break;
5164             }
5165         case V4L2_CID_HFLIP:
5166             {
5167                 ctrl->value = sensor->info_priv.mirror;
5168                 break;
5169             }
5170         case V4L2_CID_VFLIP:
5171             {
5172                 ctrl->value = sensor->info_priv.flip;
5173                 break;
5174             }
5175         default :
5176                 break;
5177     }
5178     return 0;
5179 }
5180
5181
5182
5183 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
5184 {
5185     struct i2c_client *client = v4l2_get_subdevdata(sd);
5186     struct sensor *sensor = to_sensor(client);
5187     struct soc_camera_device *icd = client->dev.platform_data;
5188     const struct v4l2_queryctrl *qctrl;
5189
5190
5191     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
5192
5193     if (!qctrl)
5194     {
5195         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
5196         return -EINVAL;
5197     }
5198
5199     switch (ctrl->id)
5200     {
5201 #if CONFIG_SENSOR_Brightness
5202         case V4L2_CID_BRIGHTNESS:
5203             {
5204                 if (ctrl->value != sensor->info_priv.brightness)
5205                 {
5206                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
5207                     {
5208                         return -EINVAL;
5209                     }
5210                     sensor->info_priv.brightness = ctrl->value;
5211                 }
5212                 break;
5213             }
5214 #endif
5215 #if CONFIG_SENSOR_Exposure
5216         case V4L2_CID_EXPOSURE:
5217             {
5218                 if (ctrl->value != sensor->info_priv.exposure)
5219                 {
5220                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
5221                     {
5222                         return -EINVAL;
5223                     }
5224                     sensor->info_priv.exposure = ctrl->value;
5225                 }
5226                 break;
5227             }
5228 #endif
5229 #if CONFIG_SENSOR_Saturation
5230         case V4L2_CID_SATURATION:
5231             {
5232                 if (ctrl->value != sensor->info_priv.saturation)
5233                 {
5234                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
5235                     {
5236                         return -EINVAL;
5237                     }
5238                     sensor->info_priv.saturation = ctrl->value;
5239                 }
5240                 break;
5241             }
5242 #endif
5243 #if CONFIG_SENSOR_Contrast
5244         case V4L2_CID_CONTRAST:
5245             {
5246                 if (ctrl->value != sensor->info_priv.contrast)
5247                 {
5248                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
5249                     {
5250                         return -EINVAL;
5251                     }
5252                     sensor->info_priv.contrast = ctrl->value;
5253                 }
5254                 break;
5255             }
5256 #endif
5257 #if CONFIG_SENSOR_WhiteBalance
5258         case V4L2_CID_DO_WHITE_BALANCE:
5259             {
5260                 if (ctrl->value != sensor->info_priv.whiteBalance)
5261                 {
5262                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
5263                     {
5264                         return -EINVAL;
5265                     }
5266                     sensor->info_priv.whiteBalance = ctrl->value;
5267                 }
5268                 break;
5269             }
5270 #endif
5271 #if CONFIG_SENSOR_Mirror
5272         case V4L2_CID_HFLIP:
5273             {
5274                 if (ctrl->value != sensor->info_priv.mirror)
5275                 {
5276                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
5277                         return -EINVAL;
5278                     sensor->info_priv.mirror = ctrl->value;
5279                 }
5280                 break;
5281             }
5282 #endif
5283 #if CONFIG_SENSOR_Flip
5284         case V4L2_CID_VFLIP:
5285             {
5286                 if (ctrl->value != sensor->info_priv.flip)
5287                 {
5288                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
5289                         return -EINVAL;
5290                     sensor->info_priv.flip = ctrl->value;
5291                 }
5292                 break;
5293             }
5294 #endif
5295         default:
5296             break;
5297     }
5298
5299     return 0;
5300 }
5301 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
5302 {
5303     const struct v4l2_queryctrl *qctrl;
5304     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5305     struct sensor *sensor = to_sensor(client);
5306
5307     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5308
5309     if (!qctrl)
5310     {
5311         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5312         return -EINVAL;
5313     }
5314
5315     switch (ext_ctrl->id)
5316     {
5317         case V4L2_CID_SCENE:
5318             {
5319                 ext_ctrl->value = sensor->info_priv.scene;
5320                 break;
5321             }
5322         case V4L2_CID_EFFECT:
5323             {
5324                 ext_ctrl->value = sensor->info_priv.effect;
5325                 break;
5326             }
5327         case V4L2_CID_ZOOM_ABSOLUTE:
5328             {
5329                 ext_ctrl->value = sensor->info_priv.digitalzoom;
5330                 break;
5331             }
5332         case V4L2_CID_ZOOM_RELATIVE:
5333             {
5334                 return -EINVAL;
5335             }
5336         case V4L2_CID_FOCUS_ABSOLUTE:
5337             {
5338                 return -EINVAL;
5339             }
5340         case V4L2_CID_FOCUS_RELATIVE:
5341             {
5342                 return -EINVAL;
5343             }
5344         case V4L2_CID_FLASH:
5345             {
5346                 ext_ctrl->value = sensor->info_priv.flash;
5347                 break;
5348             }
5349         default :
5350             break;
5351     }
5352     return 0;
5353 }
5354 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
5355 {
5356     const struct v4l2_queryctrl *qctrl;
5357     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
5358     struct sensor *sensor = to_sensor(client);
5359     int val_offset,ret;
5360
5361     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
5362
5363     if (!qctrl)
5364     {
5365         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
5366         return -EINVAL;
5367     }
5368
5369         val_offset = 0;
5370     switch (ext_ctrl->id)
5371     {
5372 #if CONFIG_SENSOR_Scene
5373         case V4L2_CID_SCENE:
5374             {
5375                 if (ext_ctrl->value != sensor->info_priv.scene)
5376                 {
5377                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
5378                         return -EINVAL;
5379                     sensor->info_priv.scene = ext_ctrl->value;
5380                 }
5381                 break;
5382             }
5383 #endif
5384 #if CONFIG_SENSOR_Effect
5385         case V4L2_CID_EFFECT:
5386             {                
5387                 if (ext_ctrl->value != sensor->info_priv.effect)
5388                 {                    
5389                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
5390                         return -EINVAL;
5391                     sensor->info_priv.effect= ext_ctrl->value;
5392                 }
5393                 break;
5394             }
5395 #endif
5396 #if CONFIG_SENSOR_DigitalZoom
5397         case V4L2_CID_ZOOM_ABSOLUTE:
5398             {
5399                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5400                     return -EINVAL;
5401
5402                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
5403                 {
5404                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
5405
5406                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
5407                         return -EINVAL;
5408                     sensor->info_priv.digitalzoom += val_offset;
5409
5410                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
5411                 }
5412
5413                 break;
5414             }
5415         case V4L2_CID_ZOOM_RELATIVE:
5416             {
5417                 if (ext_ctrl->value)
5418                 {
5419                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
5420                         return -EINVAL;
5421                     sensor->info_priv.digitalzoom += ext_ctrl->value;
5422
5423                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
5424                 }
5425                 break;
5426             }
5427 #endif
5428 #if CONFIG_SENSOR_Focus
5429         case V4L2_CID_FOCUS_ABSOLUTE:
5430             {
5431                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5432                     return -EINVAL;
5433
5434                 break;
5435             }
5436         case V4L2_CID_FOCUS_RELATIVE:
5437             {
5438                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
5439                     return -EINVAL;
5440
5441                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
5442                 break;
5443             }
5444                 case V4L2_CID_FOCUS_AUTO:
5445                         {
5446                 printk("AF: %d\n",ext_ctrl->value);
5447                                 if (ext_ctrl->value) {
5448                     if ((ext_ctrl->value==1) || (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus)) {
5449                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO,ext_ctrl->rect) != 0) {
5450                                                 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5451                                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5452                                                 }
5453                                                 return -EINVAL;
5454                                         }
5455                     }
5456                     if (ext_ctrl->value == 1)
5457                                             sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
5458                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
5459                                         if (ext_ctrl->value == 0)
5460                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5461                                 } 
5462                                 break;
5463                         }
5464                 case V4L2_CID_FOCUS_CONTINUOUS:
5465                         {
5466                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
5467                                         if (ext_ctrl->value == 1) {
5468                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS,NULL) != 0) {
5469                                                 if(0 == (sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)) {
5470                                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5471                                                 }
5472                                                 return -EINVAL;
5473                                                 }
5474                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
5475                                         }
5476                                 } else {
5477                                         if (ext_ctrl->value == 0)
5478                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
5479                                 }
5480                                 break;
5481                         }
5482 #endif
5483 #if CONFIG_SENSOR_Flash
5484         case V4L2_CID_FLASH:
5485             {
5486                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
5487                     return -EINVAL;
5488                 sensor->info_priv.flash = ext_ctrl->value;
5489
5490                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
5491                 break;
5492             }
5493 #endif
5494         default:
5495             break;
5496     }
5497
5498     return 0;
5499 }
5500
5501 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5502 {
5503     struct i2c_client *client = v4l2_get_subdevdata(sd);
5504     struct soc_camera_device *icd = client->dev.platform_data;
5505     int i, error_cnt=0, error_idx=-1;
5506
5507
5508     for (i=0; i<ext_ctrl->count; i++) {
5509         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5510             error_cnt++;
5511             error_idx = i;
5512         }
5513     }
5514
5515     if (error_cnt > 1)
5516         error_idx = ext_ctrl->count;
5517
5518     if (error_idx != -1) {
5519         ext_ctrl->error_idx = error_idx;
5520         return -EINVAL;
5521     } else {
5522         return 0;
5523     }
5524 }
5525
5526 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
5527 {
5528     struct i2c_client *client = v4l2_get_subdevdata(sd);
5529     struct soc_camera_device *icd = client->dev.platform_data;
5530     int i, error_cnt=0, error_idx=-1;
5531
5532     for (i=0; i<ext_ctrl->count; i++) {
5533         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
5534             error_cnt++;
5535             error_idx = i;
5536         }
5537     }
5538
5539     if (error_cnt > 1)
5540         error_idx = ext_ctrl->count;
5541
5542     if (error_idx != -1) {
5543         ext_ctrl->error_idx = error_idx;
5544         return -EINVAL;
5545     } else {
5546         return 0;
5547     }
5548 }
5549
5550 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
5551 {
5552         struct i2c_client *client = v4l2_get_subdevdata(sd);
5553     struct sensor *sensor = to_sensor(client);
5554         #if CONFIG_SENSOR_Focus
5555         struct soc_camera_device *icd = client->dev.platform_data;
5556         struct v4l2_mbus_framefmt mf;
5557         #endif
5558     
5559         if (enable == 1) {
5560                 sensor->info_priv.enable = 1;
5561                 #if CONFIG_SENSOR_Focus
5562                 mf.width        = icd->user_width;
5563         mf.height       = icd->user_height;
5564         mf.code = sensor->info_priv.fmt.code;
5565         mf.colorspace   = sensor->info_priv.fmt.colorspace;
5566         mf.field        = V4L2_FIELD_NONE;
5567                 /* If auto focus firmware haven't download success, must download firmware again when in video or preview stream on */
5568                 if (sensor_fmt_capturechk(sd, &mf) == false) {
5569                         if ((sensor->info_priv.affm_reinit == 1) || ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)==0)) {
5570                 sensor_af_workqueue_set(icd, WqCmd_af_init, 0, false,NULL);
5571                                 sensor->info_priv.affm_reinit = 0;
5572                         }
5573                 }
5574                 #endif
5575         } else if (enable == 0) {
5576             sensor->info_priv.enable = 0;
5577                 #if CONFIG_SENSOR_Focus 
5578         flush_workqueue(sensor->sensor_wq);
5579                 #endif
5580         }
5581         return 0;
5582 }
5583
5584 /* Interface active, can use i2c. If it fails, it can indeed mean, that
5585  * this wasn't our capture interface, so, we wait for the right one */
5586 static int sensor_video_probe(struct soc_camera_device *icd,
5587                                struct i2c_client *client)
5588 {
5589     char value;
5590     int ret,pid = 0;
5591     struct sensor *sensor = to_sensor(client);
5592
5593     /* We must have a parent by now. And it cannot be a wrong one.
5594      * So this entire test is completely redundant. */
5595     if (!icd->dev.parent ||
5596             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
5597                 return -ENODEV;
5598 #if 1 //derek
5599         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
5600                 ret = -ENODEV;
5601                 goto sensor_video_probe_err;
5602         }
5603 #endif  
5604     /* soft reset */
5605     /*
5606     ret = sensor_write(client, 0x3008, 0x80);
5607     if (ret != 0) {
5608         SENSOR_TR("soft reset %s failed\n",SENSOR_NAME_STRING());
5609         ret = -ENODEV;
5610                 goto sensor_video_probe_err;
5611     }
5612     mdelay(5);          //delay 5 microseconds
5613 */
5614     printk("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
5615     mdelay(5000); //jzw modify
5616
5617     
5618     /* check if it is an sensor sensor */
5619     ret = sensor_read(client, 0x0000, &value);
5620     if (ret != 0) {
5621         SENSOR_TR("read chip id high byte failed\n");
5622         ret = -ENODEV;
5623         goto sensor_video_probe_err;
5624     }
5625     printk("jzw:%s:0x%02x\n",__FUNCTION__,value);
5626     pid |= (value << 8);
5627
5628     ret = sensor_read(client, 0x0001, &value);
5629     if (ret != 0) {
5630         SENSOR_TR("read chip id low byte failed\n");
5631         ret = -ENODEV;
5632         goto sensor_video_probe_err;
5633     }
5634      printk("jzw:%s:0x%02x\n",__FUNCTION__,value);
5635     pid |= (value & 0xff);
5636     SENSOR_DG("\n %s  pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5637     if (pid == SENSOR_ID) {
5638         sensor->model = SENSOR_V4L2_IDENT;
5639     } else {
5640         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
5641         ret = -ENODEV;
5642         goto sensor_video_probe_err;
5643     }
5644
5645     return 0;
5646
5647 sensor_video_probe_err:
5648     return ret;
5649 }
5650 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
5651 {
5652         struct i2c_client *client = v4l2_get_subdevdata(sd);
5653     struct soc_camera_device *icd = client->dev.platform_data;
5654     struct sensor *sensor = to_sensor(client);
5655     int ret = 0,i;
5656
5657         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5658         switch (cmd)
5659         {
5660                 case RK29_CAM_SUBDEV_DEACTIVATE:
5661                 {
5662                         sensor_deactivate(client);
5663                         break;
5664                 }
5665                 case RK29_CAM_SUBDEV_IOREQUEST:
5666                 {
5667             sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;           
5668             if (sensor->sensor_io_request != NULL) { 
5669                 sensor->sensor_gpio_res = NULL;
5670                 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
5671                     if (sensor->sensor_io_request->gpio_res[i].dev_name && 
5672                         (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
5673                         sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
5674                     }
5675                 }
5676                 if (sensor->sensor_gpio_res == NULL) {
5677                     SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
5678                     ret = -EINVAL;
5679                     goto sensor_ioctl_end;
5680                 }
5681             } else {
5682                 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
5683                 ret = -EINVAL;
5684                 goto sensor_ioctl_end;
5685             }
5686             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
5687                for this project */
5688             #if CONFIG_SENSOR_Flash     
5689                 if (sensor->sensor_gpio_res) {
5690                 printk("flash io:%d\n",sensor->sensor_gpio_res->gpio_flash);
5691                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
5692                     for (i = 0; i < icd->ops->num_controls; i++) {
5693                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
5694                                         //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));  
5695                               sensor_controls[i].id=0xffff;                             
5696                                 }
5697                     }
5698                     sensor->info_priv.flash = 0xff;
5699                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
5700                 }else{ //two cameras are the same,need to deal diffrently ,zyc
5701                     for (i = 0; i < icd->ops->num_controls; i++) {
5702                            if(0xffff == icd->ops->controls[i].id){
5703                               sensor_controls[i].id=V4L2_CID_FLASH;
5704                            }               
5705                     }
5706                 }
5707                 }
5708             #endif
5709                         break;
5710                 }
5711                 default:
5712                 {
5713                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
5714                         break;
5715                 }
5716         }
5717
5718 sensor_ioctl_end:
5719         return ret;
5720
5721 }
5722 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
5723                             enum v4l2_mbus_pixelcode *code)
5724 {
5725         if (index >= ARRAY_SIZE(sensor_colour_fmts))
5726                 return -EINVAL;
5727
5728         *code = sensor_colour_fmts[index].code;
5729         return 0;
5730 }
5731 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
5732         .init           = sensor_init,
5733         .g_ctrl         = sensor_g_control,
5734         .s_ctrl         = sensor_s_control,
5735         .g_ext_ctrls          = sensor_g_ext_controls,
5736         .s_ext_ctrls          = sensor_s_ext_controls,
5737         .g_chip_ident   = sensor_g_chip_ident,
5738         .ioctl = sensor_ioctl,
5739 };
5740
5741 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
5742         .s_mbus_fmt     = sensor_s_fmt,
5743         .g_mbus_fmt     = sensor_g_fmt,
5744         .try_mbus_fmt   = sensor_try_fmt,
5745         .enum_mbus_fmt  = sensor_enum_fmt,
5746         .s_stream   = sensor_s_stream,
5747 };
5748
5749 static struct v4l2_subdev_ops sensor_subdev_ops = {
5750         .core   = &sensor_subdev_core_ops,
5751         .video = &sensor_subdev_video_ops,
5752 };
5753
5754 static int sensor_probe(struct i2c_client *client,
5755                          const struct i2c_device_id *did)
5756 {
5757     struct sensor *sensor;
5758     struct soc_camera_device *icd = client->dev.platform_data;
5759     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
5760     struct soc_camera_link *icl;
5761     int ret;
5762
5763     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
5764     if (!icd) {
5765         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
5766         return -EINVAL;
5767     }
5768
5769     icl = to_soc_camera_link(icd);
5770     if (!icl) {
5771         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
5772         return -EINVAL;
5773     }
5774
5775     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
5776         dev_warn(&adapter->dev,
5777                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
5778         return -EIO;
5779     }
5780
5781     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
5782     if (!sensor)
5783         return -ENOMEM;
5784
5785     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
5786
5787     /* Second stage probe - when a capture adapter is there */
5788     icd->ops            = &sensor_ops;
5789     sensor->info_priv.fmt = sensor_colour_fmts[0];
5790         #if CONFIG_SENSOR_I2C_NOSCHED
5791         atomic_set(&sensor->tasklock_cnt,0);
5792         #endif
5793
5794     ret = sensor_video_probe(icd, client);
5795     if (ret < 0) {
5796         icd->ops = NULL;
5797         i2c_set_clientdata(client, NULL);
5798         kfree(sensor);
5799                 sensor = NULL;
5800     } else {
5801                 #if CONFIG_SENSOR_Focus
5802                 sensor->sensor_wq = create_workqueue(SENSOR_NAME_STRING(_af_workqueue));
5803                 if (sensor->sensor_wq == NULL)
5804                         SENSOR_TR("%s create fail!", SENSOR_NAME_STRING(_af_workqueue));
5805                 mutex_init(&sensor->wq_lock);
5806                 #endif
5807     }
5808         hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
5809     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
5810     return ret;
5811 }
5812
5813 static int sensor_remove(struct i2c_client *client)
5814 {
5815     struct sensor *sensor = to_sensor(client);
5816     struct soc_camera_device *icd = client->dev.platform_data;
5817
5818         #if CONFIG_SENSOR_Focus
5819         if (sensor->sensor_wq) {
5820                 destroy_workqueue(sensor->sensor_wq);
5821                 sensor->sensor_wq = NULL;
5822         }
5823         #endif
5824
5825     icd->ops = NULL;
5826     i2c_set_clientdata(client, NULL);
5827     client->driver = NULL;
5828     kfree(sensor);
5829         sensor = NULL;
5830     return 0;
5831 }
5832
5833 static const struct i2c_device_id sensor_id[] = {
5834         {SENSOR_NAME_STRING(), 0 },
5835         { }
5836 };
5837 MODULE_DEVICE_TABLE(i2c, sensor_id);
5838
5839 static struct i2c_driver sensor_i2c_driver = {
5840         .driver = {
5841                 .name = SENSOR_NAME_STRING(),
5842         },
5843         .probe          = sensor_probe,
5844         .remove         = sensor_remove,
5845         .id_table       = sensor_id,
5846 };
5847
5848 static int __init sensor_mod_init(void)
5849 {
5850    // if (!tcsi_get_value(WESI_CAMERA_HM5065)) //add by caixx
5851    //     return 0;
5852
5853     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
5854     return i2c_add_driver(&sensor_i2c_driver);
5855 }
5856
5857 static void __exit sensor_mod_exit(void)
5858 {
5859     //if (!tcsi_get_value(WESI_CAMERA_HM5065)) //add by caixx
5860    //     return;
5861
5862     i2c_del_driver(&sensor_i2c_driver);
5863 }
5864
5865 device_initcall_sync(sensor_mod_init);
5866 module_exit(sensor_mod_exit);
5867
5868 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
5869 MODULE_AUTHOR("ddl <kernel@rock-chips>");
5870 MODULE_LICENSE("GPL");