camera rk30:update to v0.x.10,wake up vb when cif have't receive data etc.
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / mt9p111.c
1 /*
2  * Driver for OV5642 CMOS Image Sensor from OmniVision
3  *
4  * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/hardirq.h>
19 #include <linux/miscdevice.h>
20 #include <asm/io.h>
21
22 #include <media/v4l2-common.h>
23 #include <media/v4l2-chip-ident.h>
24 #include <media/soc_camera.h>
25 #include <plat/rk_camera.h>
26 #include "mt9p111.h"
27
28 static int debug;
29 module_param(debug, int, S_IRUGO|S_IWUSR);
30
31 #define dprintk(level, fmt, arg...) do {                        \
32         if (debug >= level)                                     \
33         printk(KERN_WARNING fmt , ## arg); } while (0)
34
35 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
36 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
37
38 #define _CONS(a,b) a##b
39 #define CONS(a,b) _CONS(a,b)
40
41 #define __STR(x) #x
42 #define _STR(x) __STR(x)
43 #define STR(x) _STR(x)
44
45 #define MIN(x,y)   ((x<y) ? x: y)
46 #define MAX(x,y)    ((x>y) ? x: y)
47
48 /* Sensor Driver Configuration */
49 #define SENSOR_NAME RK29_CAM_SENSOR_MT9P111
50 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9P111
51 #define SENSOR_ID SEQUENCE_END
52 #define SENSOR_ID_REG SEQUENCE_END
53 #define SENSOR_RESET_REG 0x0010
54 #define SENSOR_RESET_VAL 0x0115
55 #define SENSOR_RESET_REG_LEN  WORD_LEN
56 #define SENSOR_MIN_WIDTH    176
57 #define SENSOR_MIN_HEIGHT   144
58 #define SENSOR_MAX_WIDTH    2592
59 #define SENSOR_MAX_HEIGHT   1944
60 #define SENSOR_INIT_WIDTH       640                     /* Sensor pixel size for sensor_init_data array */
61 #define SENSOR_INIT_HEIGHT  480
62 #define SENSOR_INIT_WINSEQADR sensor_vga
63 #define SENSOR_INIT_PIXFMT  V4L2_MBUS_FMT_UYVY8_2X8
64 #define YUV420_BUFFER_MAX_SIZE  7558272     /* 2592*1944*1.5*/ 
65
66 #define CONFIG_SENSOR_WhiteBalance      1
67 #define CONFIG_SENSOR_Brightness        0
68 #define CONFIG_SENSOR_Contrast      0
69 #define CONFIG_SENSOR_Saturation    0
70 #define CONFIG_SENSOR_Effect        1
71 #define CONFIG_SENSOR_Scene         1
72 #define CONFIG_SENSOR_DigitalZoom   0
73 #define CONFIG_SENSOR_Exposure      0
74 #define CONFIG_SENSOR_Flash         1
75 #define CONFIG_SENSOR_Mirror        0
76 #define CONFIG_SENSOR_Flip          1
77 #define CONFIG_SENSOR_Focus         1
78
79
80 #define CONFIG_SENSOR_I2C_SPEED     100000       /* Hz */
81 //#define CONFIG_SENSOR_I2C_SPEED   350000       /* Hz */
82    
83 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
84 #define CONFIG_SENSOR_I2C_NOSCHED   0
85 #define CONFIG_SENSOR_I2C_RDWRCHK   0
86
87
88 #define SENSOR_BUS_PARAM  (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|\
89                           SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH|\
90                           SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ)
91
92 #define COLOR_TEMPERATURE_CLOUDY_DN    6500
93 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
94 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
95 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
96 #define COLOR_TEMPERATURE_OFFICE_DN     3500
97 #define COLOR_TEMPERATURE_OFFICE_UP     5000
98 #define COLOR_TEMPERATURE_HOME_DN       2500
99 #define COLOR_TEMPERATURE_HOME_UP       3500
100
101 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
102 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
103
104 #define SENSOR_AF_IS_ERR    (0x00<<0)
105 #define SENSOR_AF_IS_OK         (0x01<<0)
106 #define SENSOR_INIT_IS_ERR   (0x00<<28)
107 #define SENSOR_INIT_IS_OK    (0x01<<28)
108
109
110
111 #if CONFIG_SENSOR_Focus
112 #define SENSOR_AF_MODE_INFINITY    0
113 #define SENSOR_AF_MODE_MACRO       1
114 #define SENSOR_AF_MODE_FIXED       2
115 #define SENSOR_AF_MODE_AUTO        3
116 #define SENSOR_AF_MODE_CONTINUOUS  4
117 #define SENSOR_AF_MODE_CLOSE       5
118 #endif
119
120 //flash off in fixed time to prevent from too hot , zyc
121 struct  flash_timer{
122     struct soc_camera_device *icd;
123         struct hrtimer timer;
124 };
125 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
126
127 static struct  flash_timer flash_off_timer;
128 //for user defined if user want to customize the series , zyc
129 #if CONFIG_MT9P111_USER_DEFINED_SERIES
130 #include "mt9p111_user_series.c"
131 #else
132
133 /* init 640X480 VGA */
134 static struct reginfo sensor_init_data[] =
135 {
136 //[Step2-PLL_Timing]
137 //for 24MHz input, VCO=MAX=768mhz  
138 { 0x0010, 0x0340, WORD_LEN, 0},
139 /*sovle problem that lack of pclk during one href*/
140 #if  ADJUST_PCLK_FRE_FALG
141 { 0x0012, 0x0080, WORD_LEN, 0},     //PCLK=85MHz
142 #else
143 { 0x0012, 0x0090, WORD_LEN, 0},     //PCLK=76MHz
144 #endif
145 { 0x0014, 0x2025, WORD_LEN, 0},
146 { 0x001E, 0x0565, WORD_LEN, 0},    // PAD_SLEW_PAD_CONFIG
147 { 0x0022, 0x0030, WORD_LEN, 0},   //0x01E0// VDD_DIS_COUNTER
148 #if   ADJUST_PCLK_FRE_FALG
149 { 0x002A, 0x7FFF, WORD_LEN, 0},  
150 #else
151 { 0x002A, 0x7F7E, WORD_LEN, 0},   //0x7F7F// PLL_P4_P5_P6_DIVIDERS By Hwang 20101104
152 #endif
153 { 0x002C, 0x0000, WORD_LEN, 0},         // PLL_P7_DIVIDER
154 { 0x002E, 0x0000, WORD_LEN, 0},         // SENSOR_CLOCK_DIVIDER
155 { 0x0018, 0x4008, WORD_LEN, 0},         // STANDBY_CONTROL_AND_STATUS
156 //////{ SEQUENCE_WAIT_MS,100,WORD_LEN, 0},
157 { SEQUENCE_WAIT_MS,20,WORD_LEN, 0},
158 //timing_settings
159 { 0x0010, 0x0340, WORD_LEN, 0},         // PLL_DIVIDERS
160 { 0x098E, 0x483A, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS [CAM_CORE_A_Y_ADDR_START]
161 { 0xC83A, 0x000C, WORD_LEN, 0},         // CAM_CORE_A_Y_ADDR_START
162 { 0xC83C, 0x0018, WORD_LEN, 0},         // CAM_CORE_A_X_ADDR_START
163 { 0xC83E, 0x07B1, WORD_LEN, 0},         // CAM_CORE_A_Y_ADDR_END
164 { 0xC840, 0x0A45, WORD_LEN, 0},         // CAM_CORE_A_X_ADDR_END
165 { 0xC842, 0x0001, WORD_LEN, 0},         // CAM_CORE_A_ROW_SPEED
166 { 0xC844, 0x0103, WORD_LEN, 0},         // CAM_CORE_A_SKIP_X_CORE
167 { 0xC846, 0x0103, WORD_LEN, 0},         // CAM_CORE_A_SKIP_Y_CORE
168 { 0xC848, 0x0103, WORD_LEN, 0},         // CAM_CORE_A_SKIP_X_PIPE
169 { 0xC84A, 0x0103, WORD_LEN, 0},         // CAM_CORE_A_SKIP_Y_PIPE
170 { 0xC84C, 0x00F6, WORD_LEN, 0},         // CAM_CORE_A_POWER_MODE
171 { 0xC84E, 0x0001, WORD_LEN, 0},         // CAM_CORE_A_BIN_MODE
172 /*lzg@rock-chips.com, FIH:preview image to be mirrored and flipped */
173 #if CONFIG_SENSOR_NONE_FLIP_MIRROR
174 { 0xC850, 0x00, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
175 #elif CONFIG_SENSOR_MIRROR
176 { 0xC850, 0x01, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
177 #elif CONFIG_SENSOR_FLIPE
178 { 0xC850, 0x02, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
179 #elif CONFIG_SENSOR_MIRROR_AND_FLIPE
180 { 0xC850, 0x03, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
181 #endif
182 { 0xC851, 0x00, BYTE_LEN, 0},       // CAM_CORE_A_PIXEL_ORDER
183 { 0xC852, 0x019C, WORD_LEN, 0},         // CAM_CORE_A_FINE_CORRECTION
184 { 0xC854, 0x0732, WORD_LEN, 0},         // CAM_CORE_A_FINE_ITMIN
185 { 0xC858, 0x0000, WORD_LEN, 0},         // CAM_CORE_A_COARSE_ITMIN
186 { 0xC85A, 0x0001, WORD_LEN, 0},         // CAM_CORE_A_COARSE_ITMAX_MARGIN
187 { 0xC85C, 0x0423, WORD_LEN, 0},         // CAM_CORE_A_MIN_FRAME_LENGTH_LINES
188 { 0xC85E, 0xFFFF, WORD_LEN, 0},         // CAM_CORE_A_MAX_FRAME_LENGTH_LINS
189 { 0xC860, 0x0423, WORD_LEN, 0},         // CAM_CORE_A_BASE_FRAME_LENGTH_LINES
190 { 0xC862, 0x1194, WORD_LEN, 0},         // CAM_CORE_A_MIN_LINE_LENGTH_PCLK
191 { 0xC864, 0xFFFE, WORD_LEN, 0},         // CAM_CORE_A_MAX_LINE_LENGTH_PCLK
192 { 0xC866, 0x7F7F, WORD_LEN, 0},         // CAM_CORE_A_P4_5_6_DIVIDER
193 { 0xC868, 0x0423, WORD_LEN, 0},         // CAM_CORE_A_FRAME_LENGTH_LINES
194 { 0xC86A, 0x1194, WORD_LEN, 0},         // CAM_CORE_A_LINE_LENGTH_PCK
195 { 0xC86C, 0x0518, WORD_LEN, 0},         // CAM_CORE_A_OUTPUT_SIZE_WIDTH
196 { 0xC86E, 0x03D4, WORD_LEN, 0},         // CAM_CORE_A_OUTPUT_SIZE_HEIGHT
197 { 0xC870, 0x0014, WORD_LEN, 0},         // CAM_CORE_A_RX_FIFO_TRIGGER_MARK
198 { 0xC858, 0x0003, WORD_LEN, 0},         // CAM_CORE_A_COARSE_ITMIN
199 { 0xC8B8, 0x0004, WORD_LEN, 0},         // CAM_OUTPUT_0_JPEG_CONTROL
200 { 0xC8AE, 0x0001, WORD_LEN, 0},         // CAM_OUTPUT_0_OUTPUT_FORMAT
201 { 0xC8AA, 0x0280, WORD_LEN, 0},         // CAM_OUTPUT_0_IMAGE_WIDTH
202 { 0xC8AC, 0x01E0, WORD_LEN, 0},         // CAM_OUTPUT_0_IMAGE_HEIGHT
203 { 0xC872, 0x0010, WORD_LEN, 0},         // CAM_CORE_B_Y_ADDR_START
204 { 0xC874, 0x001C, WORD_LEN, 0},         // CAM_CORE_B_X_ADDR_START
205 { 0xC876, 0x07AF, WORD_LEN, 0},         // CAM_CORE_B_Y_ADDR_END
206 { 0xC878, 0x0A43, WORD_LEN, 0},         // CAM_CORE_B_X_ADDR_END
207 { 0xC87A, 0x0001, WORD_LEN, 0},         // CAM_CORE_B_ROW_SPEED
208 { 0xC87C, 0x0101, WORD_LEN, 0},         // CAM_CORE_B_SKIP_X_CORE
209 { 0xC87E, 0x0101, WORD_LEN, 0},         // CAM_CORE_B_SKIP_Y_CORE
210 { 0xC880, 0x0101, WORD_LEN, 0},         // CAM_CORE_B_SKIP_X_PIPE
211 { 0xC882, 0x0101, WORD_LEN, 0},         // CAM_CORE_B_SKIP_Y_PIPE
212 { 0xC884, 0x00F2, WORD_LEN, 0},         // CAM_CORE_B_POWER_MODE
213 { 0xC886, 0x0000, WORD_LEN, 0},         // CAM_CORE_B_BIN_MODE
214 /*lzg@rock-chips.com, FIH:capture image to be mirrored and flipped */
215 #if CONFIG_SENSOR_NONE_FLIP_MIRROR
216 { 0xC888, 0x00, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
217 #elif CONFIG_SENSOR_MIRROR
218 { 0xC888, 0x01, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
219 #elif CONFIG_SENSOR_FLIPE
220 { 0xC888, 0x02, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
221 #elif CONFIG_SENSOR_MIRROR_AND_FLIPE
222 { 0xC888, 0x03, BYTE_LEN, 0},       // CAM_CORE_A_ORIENTATION
223 #endif
224 { 0xC889, 0x00, BYTE_LEN, 0},   // CAM_CORE_B_PIXEL_ORDER
225 { 0xC88A, 0x009C, WORD_LEN, 0},         // CAM_CORE_B_FINE_CORRECTION
226 { 0xC88C, 0x034A, WORD_LEN, 0},         // CAM_CORE_B_FINE_ITMIN
227 { 0xC890, 0x0000, WORD_LEN, 0},         // CAM_CORE_B_COARSE_ITMIN
228 { 0xC892, 0x0001, WORD_LEN, 0},         // CAM_CORE_B_COARSE_ITMAX_MARGIN                  
229 { 0xC894, 0x07EF, WORD_LEN, 0},         // CAM_CORE_B_MIN_FRAME_LENGTH_LINES
230 { 0xC896, 0xFFFF, WORD_LEN, 0},         // CAM_CORE_B_MAX_FRAME_LENGTH_LINES
231 { 0xC898, 0x082F, WORD_LEN, 0},         // CAM_CORE_B_BASE_FRAME_LENGTH_LINES
232 { 0xC89A, 0x1964, WORD_LEN, 0},         // CAM_CORE_B_MIN_LINE_LENGTH_PCLK
233 { 0xC89C, 0xFFFE, WORD_LEN, 0},         // CAM_CORE_B_MAX_LINE_LENGTH_PCLK
234 { 0xC89E, 0x7F7F, WORD_LEN, 0},         // CAM_CORE_B_P4_5_6_DIVIDER
235 { 0xC8A0, 0x07EF, WORD_LEN, 0},         // CAM_CORE_B_FRAME_LENGTH_LINES
236 { 0xC8A2, 0x1964, WORD_LEN, 0},         // CAM_CORE_B_LINE_LENGTH_PCK
237 { 0xC8A4, 0x0A28, WORD_LEN, 0},         // CAM_CORE_B_OUTPUT_SIZE_WIDTH
238 { 0xC8A6, 0x07A0, WORD_LEN, 0},         // CAM_CORE_B_OUTPUT_SIZE_HEIGHT
239 { 0xC8A8, 0x0124, WORD_LEN, 0},         // CAM_CORE_B_RX_FIFO_TRIGGER_MARK
240 { 0xC890, 0x0003, WORD_LEN, 0},         // CAM_CORE_B_COARSE_ITMIN
241 { 0xC8C0, 0x0A20, WORD_LEN, 0},         // CAM_OUTPUT_1_IMAGE_WIDTH
242 { 0xC8C2, 0x0798, WORD_LEN, 0},         // CAM_OUTPUT_1_IMAGE_HEIGHT
243 { 0xC89A, 0x1964, WORD_LEN, 0},         // CAM_CORE_B_MIN_LINE_LENGTH_PCLK
244 { 0xC8A2, 0x1964, WORD_LEN, 0},         // CAM_CORE_B_LINE_LENGTH_PCK
245 { 0xC8C4, 0x0001, WORD_LEN, 0},         // CAM_OUTPUT_1_OUTPUT_FORMAT
246 { 0xC8C6, 0x0000, WORD_LEN, 0},         // CAM_OUTPUT_1_OUTPUT_FORMAT_ORDER
247 { 0xC8CE, 0x0014, WORD_LEN, 0},         // CAM_OUTPUT_1_JPEG_CONTROL
248 { 0xD822, 0x4610, WORD_LEN, 0},         // JPEG_JPSS_CTRL_VAR
249 { 0x3330, 0x0000, WORD_LEN, 0},         // OUTPUT_FORMAT_TEST
250 { 0x098E, 0xA00E, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS
251 { 0xA00E, 0x32, BYTE_LEN, 0},   // FD_MAX_NUM_AUTOCOR_FUNC_VALUES_TO_CHECK
252 { 0xA010, 0x00CC, WORD_LEN, 0},         // FD_MIN_EXPECTED50HZ_FLICKER_PERIOD
253 { 0xA012, 0x00E0, WORD_LEN, 0},         // FD_MAX_EXPECTED50HZ_FLICKER_PERIOD
254 { 0xA014, 0x00A8, WORD_LEN, 0},         // FD_MIN_EXPECTED60HZ_FLICKER_PERIOD
255 { 0xA016, 0x00BC, WORD_LEN, 0},         // FD_MAX_EXPECTED60HZ_FLICKER_PERIOD
256 { 0xA018, 0x00D6, WORD_LEN, 0},         // FD_EXPECTED50HZ_FLICKER_PERIOD_IN_CONTEXT_A
257 { 0xA01A, 0x0075, WORD_LEN, 0},         // FD_EXPECTED50HZ_FLICKER_PERIOD_IN_CONTEXT_B
258 { 0xA01C, 0x00B2, WORD_LEN, 0},         // FD_EXPECTED60HZ_FLICKER_PERIOD_IN_CONTEXT_A
259 { 0xA01E, 0x0062, WORD_LEN, 0},         // FD_EXPECTED60HZ_FLICKER_PERIOD_IN_CONTEXT_B
260 { 0xA000, 0x10, BYTE_LEN, 0},   // FD_STATUS
261 { 0x8417, 0x02, BYTE_LEN, 0},   // SEQ_STATE_CFG_1_FD
262 { 0x8404, 0x06, BYTE_LEN, 0},   // SEQ_CMD
263 //////{ SEQUENCE_WAIT_MS,300, BYTE_LEN, 0},
264 { SEQUENCE_WAIT_MS,100, BYTE_LEN, 0},
265 //[Step3-Recommended]
266 //[k28a_rev3_FW_patch7]
267 //  k28a_rev03_patch07_CR30221_MCNEX_AWB_AFNOISE_YOFFSET_APGA_REV1
268 { 0x0982, 0x0000, WORD_LEN, 0},         // ACCESS_CTL_STAT
269 { 0x098A, 0x0000, WORD_LEN, 0},         // PHYSICAL_ADDRESS_ACCESS
270 { 0x886C, 0xC0F1, WORD_LEN, 0},
271 { 0x886E, 0xC5E1, WORD_LEN, 0},
272 { 0x8870, 0x246A, WORD_LEN, 0},
273 { 0x8872, 0x1280, WORD_LEN, 0},
274 { 0x8874, 0xC4E1, WORD_LEN, 0},
275 { 0x8876, 0xD20F, WORD_LEN, 0},
276 { 0x8878, 0x2069, WORD_LEN, 0},
277 { 0x887A, 0x0000, WORD_LEN, 0},
278 { 0x887C, 0x6A62, WORD_LEN, 0},
279 { 0x887E, 0x1303, WORD_LEN, 0},
280 { 0x8880, 0x0084, WORD_LEN, 0},
281 { 0x8882, 0x1734, WORD_LEN, 0},
282 { 0x8884, 0x7005, WORD_LEN, 0},
283 { 0x8886, 0xD801, WORD_LEN, 0},
284 { 0x8888, 0x8A41, WORD_LEN, 0},
285 { 0x888A, 0xD900, WORD_LEN, 0},
286 { 0x888C, 0x0D5A, WORD_LEN, 0},
287 { 0x888E, 0x0664, WORD_LEN, 0},
288 { 0x8890, 0x8B61, WORD_LEN, 0},
289 { 0x8892, 0xE80B, WORD_LEN, 0},
290 { 0x8894, 0x000D, WORD_LEN, 0},
291 { 0x8896, 0x0020, WORD_LEN, 0},
292 { 0x8898, 0xD508, WORD_LEN, 0},
293 { 0x889A, 0x1504, WORD_LEN, 0},
294 { 0x889C, 0x1400, WORD_LEN, 0},
295 { 0x889E, 0x7840, WORD_LEN, 0},
296 { 0x88A0, 0xD007, WORD_LEN, 0},
297 { 0x88A2, 0x0DFB, WORD_LEN, 0},
298 { 0x88A4, 0x9004, WORD_LEN, 0},
299 { 0x88A6, 0xC4C1, WORD_LEN, 0},
300 { 0x88A8, 0x2029, WORD_LEN, 0},
301 { 0x88AA, 0x0300, WORD_LEN, 0},
302 { 0x88AC, 0x0219, WORD_LEN, 0},
303 { 0x88AE, 0x06C4, WORD_LEN, 0},
304 { 0x88B0, 0xFF80, WORD_LEN, 0},
305 { 0x88B2, 0x08C8, WORD_LEN, 0},
306 { 0x88B4, 0xFF80, WORD_LEN, 0},
307 { 0x88B6, 0x086C, WORD_LEN, 0},
308 { 0x88B8, 0xFF80, WORD_LEN, 0},
309 { 0x88BA, 0x08C0, WORD_LEN, 0},
310 { 0x88BC, 0xFF80, WORD_LEN, 0},
311 { 0x88BE, 0x08C8, WORD_LEN, 0},
312 { 0x88C0, 0xFF80, WORD_LEN, 0},
313 { 0x88C2, 0x08D0, WORD_LEN, 0},
314 { 0x88C4, 0xFF80, WORD_LEN, 0},
315 { 0x88C6, 0x0978, WORD_LEN, 0},
316 { 0x88C8, 0x0007, WORD_LEN, 0},
317 { 0x88CA, 0x0001, WORD_LEN, 0},
318 { 0x88CC, 0x0000, WORD_LEN, 0},
319 { 0x88CE, 0x0000, WORD_LEN, 0},
320 { 0x88D0, 0xC0F1, WORD_LEN, 0},
321 { 0x88D2, 0x097E, WORD_LEN, 0},
322 { 0x88D4, 0x06E4, WORD_LEN, 0},
323 { 0x88D6, 0xDA14, WORD_LEN, 0},
324 { 0x88D8, 0xD0C8, WORD_LEN, 0},
325 { 0x88DA, 0xDE00, WORD_LEN, 0},
326 { 0x88DC, 0xD1C8, WORD_LEN, 0},
327 { 0x88DE, 0x2E41, WORD_LEN, 0},
328 { 0x88E0, 0x120C, WORD_LEN, 0},
329 { 0x88E2, 0xA895, WORD_LEN, 0},
330 { 0x88E4, 0xD5C7, WORD_LEN, 0},
331 { 0x88E6, 0xA8D4, WORD_LEN, 0},
332 { 0x88E8, 0xA8D6, WORD_LEN, 0},
333 { 0x88EA, 0x0F0A, WORD_LEN, 0},
334 { 0x88EC, 0x06A4, WORD_LEN, 0},
335 { 0x88EE, 0x2555, WORD_LEN, 0},
336 { 0x88F0, 0x1440, WORD_LEN, 0},
337 { 0x88F2, 0xD0C5, WORD_LEN, 0},
338 { 0x88F4, 0x2555, WORD_LEN, 0},
339 { 0x88F6, 0x1441, WORD_LEN, 0},
340 { 0x88F8, 0x77A9, WORD_LEN, 0},
341 { 0x88FA, 0xA515, WORD_LEN, 0},
342 { 0x88FC, 0xD0C3, WORD_LEN, 0},
343 { 0x88FE, 0xA020, WORD_LEN, 0},
344 { 0x8900, 0xD1C3, WORD_LEN, 0},
345 { 0x8902, 0x70E9, WORD_LEN, 0},
346 { 0x8904, 0x0EEE, WORD_LEN, 0},
347 { 0x8906, 0x06A4, WORD_LEN, 0},
348 { 0x8908, 0xDA44, WORD_LEN, 0},
349 { 0x890A, 0xD0C2, WORD_LEN, 0},
350 { 0x890C, 0xD1C2, WORD_LEN, 0},
351 { 0x890E, 0xA502, WORD_LEN, 0},
352 { 0x8910, 0xD0C2, WORD_LEN, 0},
353 { 0x8912, 0xA0E0, WORD_LEN, 0},
354 { 0x8914, 0xD0C2, WORD_LEN, 0},
355 { 0x8916, 0xB0CB, WORD_LEN, 0},
356 { 0x8918, 0x8900, WORD_LEN, 0},
357 { 0x891A, 0xDB08, WORD_LEN, 0},
358 { 0x891C, 0xDAF0, WORD_LEN, 0},
359 { 0x891E, 0x19B0, WORD_LEN, 0},
360 { 0x8920, 0x00C2, WORD_LEN, 0},
361 { 0x8922, 0xB8A6, WORD_LEN, 0},
362 { 0x8924, 0xA900, WORD_LEN, 0},
363 { 0x8926, 0xD851, WORD_LEN, 0},
364 { 0x8928, 0x19B2, WORD_LEN, 0},
365 { 0x892A, 0x0002, WORD_LEN, 0},
366 { 0x892C, 0xD852, WORD_LEN, 0},
367 { 0x892E, 0x19B3, WORD_LEN, 0},
368 { 0x8930, 0x0002, WORD_LEN, 0},
369 { 0x8932, 0xD855, WORD_LEN, 0},
370 { 0x8934, 0x19B6, WORD_LEN, 0},
371 { 0x8936, 0x0002, WORD_LEN, 0},
372 { 0x8938, 0xD856, WORD_LEN, 0},
373 { 0x893A, 0x19B7, WORD_LEN, 0},
374 { 0x893C, 0x0002, WORD_LEN, 0},
375 { 0x893E, 0xD896, WORD_LEN, 0},
376 { 0x8940, 0x19B8, WORD_LEN, 0},
377 { 0x8942, 0x0004, WORD_LEN, 0},
378 { 0x8944, 0xD814, WORD_LEN, 0},
379 { 0x8946, 0x19BA, WORD_LEN, 0},
380 { 0x8948, 0x0004, WORD_LEN, 0},
381 { 0x894A, 0xD805, WORD_LEN, 0},
382 { 0x894C, 0xB111, WORD_LEN, 0},
383 { 0x894E, 0x19B1, WORD_LEN, 0},
384 { 0x8950, 0x0082, WORD_LEN, 0},
385 { 0x8952, 0x19B4, WORD_LEN, 0},
386 { 0x8954, 0x00C2, WORD_LEN, 0},
387 { 0x8956, 0x19B5, WORD_LEN, 0},
388 { 0x8958, 0x0082, WORD_LEN, 0},
389 { 0x895A, 0xD1B2, WORD_LEN, 0},
390 { 0x895C, 0x2556, WORD_LEN, 0},
391 { 0x895E, 0x12C0, WORD_LEN, 0},
392 { 0x8960, 0x0E92, WORD_LEN, 0},
393 { 0x8962, 0x06A4, WORD_LEN, 0},
394 { 0x8964, 0xDA2C, WORD_LEN, 0},
395 { 0x8966, 0xD0B0, WORD_LEN, 0},
396 { 0x8968, 0x2556, WORD_LEN, 0},
397 { 0x896A, 0x12C1, WORD_LEN, 0},
398 { 0x896C, 0xA519, WORD_LEN, 0},
399 { 0x896E, 0xD0AF, WORD_LEN, 0},
400 { 0x8970, 0x0145, WORD_LEN, 0},
401 { 0x8972, 0x06E4, WORD_LEN, 0},
402 { 0x8974, 0xA020, WORD_LEN, 0},
403 { 0x8976, 0x78E0, WORD_LEN, 0},
404 { 0x8978, 0xC0F1, WORD_LEN, 0},
405 { 0x897A, 0xD0AD, WORD_LEN, 0},
406 { 0x897C, 0xD1AD, WORD_LEN, 0},
407 { 0x897E, 0xD2AE, WORD_LEN, 0},
408 { 0x8980, 0xA020, WORD_LEN, 0},
409 { 0x8982, 0x8A09, WORD_LEN, 0},
410 { 0x8984, 0x8A6A, WORD_LEN, 0},
411 { 0x8986, 0xB808, WORD_LEN, 0},
412 { 0x8988, 0x7865, WORD_LEN, 0},
413 { 0x898A, 0xB880, WORD_LEN, 0},
414 { 0x898C, 0x2841, WORD_LEN, 0},
415 { 0x898E, 0x020C, WORD_LEN, 0},
416 { 0x8990, 0xAA89, WORD_LEN, 0},
417 { 0x8992, 0xAA0A, WORD_LEN, 0},
418 { 0x8994, 0xD2A9, WORD_LEN, 0},
419 { 0x8996, 0x8A00, WORD_LEN, 0},
420 { 0x8998, 0x0809, WORD_LEN, 0},
421 { 0x899A, 0x01DE, WORD_LEN, 0},
422 { 0x899C, 0xB8A7, WORD_LEN, 0},
423 { 0x899E, 0xAA00, WORD_LEN, 0},
424 { 0x89A0, 0xDBFF, WORD_LEN, 0},
425 { 0x89A2, 0x2B41, WORD_LEN, 0},
426 { 0x89A4, 0x0200, WORD_LEN, 0},
427 { 0x89A6, 0xAA0C, WORD_LEN, 0},
428 { 0x89A8, 0x1228, WORD_LEN, 0},
429 { 0x89AA, 0x0080, WORD_LEN, 0},
430 { 0x89AC, 0xAA6D, WORD_LEN, 0},
431 { 0x89AE, 0x0815, WORD_LEN, 0},
432 { 0x89B0, 0x01DE, WORD_LEN, 0},
433 { 0x89B2, 0xB8A7, WORD_LEN, 0},
434 { 0x89B4, 0x1A28, WORD_LEN, 0},
435 { 0x89B6, 0x0002, WORD_LEN, 0},
436 { 0x89B8, 0x8123, WORD_LEN, 0},
437 { 0x89BA, 0x7960, WORD_LEN, 0},
438 { 0x89BC, 0x1228, WORD_LEN, 0},
439 { 0x89BE, 0x0080, WORD_LEN, 0},
440 { 0x89C0, 0xC0D1, WORD_LEN, 0},
441 { 0x89C2, 0x7EE0, WORD_LEN, 0},
442 { 0x89C4, 0xC0F1, WORD_LEN, 0},
443 { 0x89C6, 0x088E, WORD_LEN, 0},
444 { 0x89C8, 0x06E4, WORD_LEN, 0},
445 { 0x89CA, 0xDB03, WORD_LEN, 0},
446 { 0x89CC, 0xD29B, WORD_LEN, 0},
447 { 0x89CE, 0x8A2E, WORD_LEN, 0},
448 { 0x89D0, 0x8ACF, WORD_LEN, 0},
449 { 0x89D2, 0xB908, WORD_LEN, 0},
450 { 0x89D4, 0x79C5, WORD_LEN, 0},
451 { 0x89D6, 0xDD65, WORD_LEN, 0},
452 { 0x89D8, 0x094F, WORD_LEN, 0},
453 { 0x89DA, 0x00D1, WORD_LEN, 0},
454 { 0x89DC, 0xD90A, WORD_LEN, 0},
455 { 0x89DE, 0x1A24, WORD_LEN, 0},
456 { 0x89E0, 0x0042, WORD_LEN, 0},
457 { 0x89E2, 0x8A24, WORD_LEN, 0},
458 { 0x89E4, 0xE1E5, WORD_LEN, 0},
459 { 0x89E6, 0xF6C9, WORD_LEN, 0},
460 { 0x89E8, 0xD902, WORD_LEN, 0},
461 { 0x89EA, 0x2941, WORD_LEN, 0},
462 { 0x89EC, 0x0200, WORD_LEN, 0},
463 { 0x89EE, 0xAA0E, WORD_LEN, 0},
464 { 0x89F0, 0xAA2F, WORD_LEN, 0},
465 { 0x89F2, 0x70A9, WORD_LEN, 0},
466 { 0x89F4, 0xF014, WORD_LEN, 0},
467 { 0x89F6, 0xE1C8, WORD_LEN, 0},
468 { 0x89F8, 0x0036, WORD_LEN, 0},
469 { 0x89FA, 0x000B, WORD_LEN, 0},
470 { 0x89FC, 0xE0C8, WORD_LEN, 0},
471 { 0x89FE, 0x003A, WORD_LEN, 0},
472 { 0x8A00, 0x000A, WORD_LEN, 0},
473 { 0x8A02, 0xD901, WORD_LEN, 0},
474 { 0x8A04, 0x2941, WORD_LEN, 0},
475 { 0x8A06, 0x0200, WORD_LEN, 0},
476 { 0x8A08, 0xAA0E, WORD_LEN, 0},
477 { 0x8A0A, 0xAA2F, WORD_LEN, 0},
478 { 0x8A0C, 0xD848, WORD_LEN, 0},
479 { 0x8A0E, 0xF008, WORD_LEN, 0},
480 { 0x8A10, 0xD900, WORD_LEN, 0},
481 { 0x8A12, 0x2941, WORD_LEN, 0},
482 { 0x8A14, 0x0200, WORD_LEN, 0},
483 { 0x8A16, 0xAA0E, WORD_LEN, 0},
484 { 0x8A18, 0xAA2F, WORD_LEN, 0},
485 { 0x8A1A, 0xD820, WORD_LEN, 0},
486 { 0x8A1C, 0xD288, WORD_LEN, 0},
487 { 0x8A1E, 0x8A26, WORD_LEN, 0},
488 { 0x8A20, 0xB961, WORD_LEN, 0},
489 { 0x8A22, 0xAA26, WORD_LEN, 0},
490 { 0x8A24, 0xF00D, WORD_LEN, 0},
491 { 0x8A26, 0x091F, WORD_LEN, 0},
492 { 0x8A28, 0x0091, WORD_LEN, 0},
493 { 0x8A2A, 0x8A24, WORD_LEN, 0},
494 { 0x8A2C, 0xF1E5, WORD_LEN, 0},
495 { 0x8A2E, 0x0913, WORD_LEN, 0},
496 { 0x8A30, 0x0812, WORD_LEN, 0},
497 { 0x8A32, 0x08E1, WORD_LEN, 0},
498 { 0x8A34, 0x8812, WORD_LEN, 0},
499 { 0x8A36, 0x2B41, WORD_LEN, 0},
500 { 0x8A38, 0x0201, WORD_LEN, 0},
501 { 0x8A3A, 0xAA2E, WORD_LEN, 0},
502 { 0x8A3C, 0xAA6F, WORD_LEN, 0},
503 { 0x8A3E, 0x0081, WORD_LEN, 0},
504 { 0x8A40, 0x06C4, WORD_LEN, 0},
505 { 0x8A42, 0x09F7, WORD_LEN, 0},
506 { 0x8A44, 0x8051, WORD_LEN, 0},
507 { 0x8A46, 0x8A24, WORD_LEN, 0},
508 { 0x8A48, 0xF1F3, WORD_LEN, 0},
509 { 0x8A4A, 0x78E0, WORD_LEN, 0},
510 { 0x8A4C, 0xC0F1, WORD_LEN, 0},
511 { 0x8A4E, 0x0FFA, WORD_LEN, 0},
512 { 0x8A50, 0x0684, WORD_LEN, 0},
513 { 0x8A52, 0xD67A, WORD_LEN, 0},
514 { 0x8A54, 0x7508, WORD_LEN, 0},
515 { 0x8A56, 0x8E01, WORD_LEN, 0},
516 { 0x8A58, 0xD179, WORD_LEN, 0},
517 { 0x8A5A, 0x2046, WORD_LEN, 0},
518 { 0x8A5C, 0x00C0, WORD_LEN, 0},
519 { 0x8A5E, 0xAE01, WORD_LEN, 0},
520 { 0x8A60, 0x1145, WORD_LEN, 0},
521 { 0x8A62, 0x0080, WORD_LEN, 0},
522 { 0x8A64, 0x1146, WORD_LEN, 0},
523 { 0x8A66, 0x0082, WORD_LEN, 0},
524 { 0x8A68, 0xB808, WORD_LEN, 0},
525 { 0x8A6A, 0x7845, WORD_LEN, 0},
526 { 0x8A6C, 0x0817, WORD_LEN, 0},
527 { 0x8A6E, 0x001E, WORD_LEN, 0},
528 { 0x8A70, 0x8900, WORD_LEN, 0},
529 { 0x8A72, 0x8941, WORD_LEN, 0},
530 { 0x8A74, 0xB808, WORD_LEN, 0},
531 { 0x8A76, 0x7845, WORD_LEN, 0},
532 { 0x8A78, 0x080B, WORD_LEN, 0},
533 { 0x8A7A, 0x00DE, WORD_LEN, 0},
534 { 0x8A7C, 0x70A9, WORD_LEN, 0},
535 { 0x8A7E, 0xFFD2, WORD_LEN, 0},
536 { 0x8A80, 0x7508, WORD_LEN, 0},
537 { 0x8A82, 0x1604, WORD_LEN, 0},
538 { 0x8A84, 0x1090, WORD_LEN, 0},
539 { 0x8A86, 0x0D93, WORD_LEN, 0},
540 { 0x8A88, 0x1400, WORD_LEN, 0},
541 { 0x8A8A, 0x8EEA, WORD_LEN, 0},
542 { 0x8A8C, 0x8E0B, WORD_LEN, 0},
543 { 0x8A8E, 0x214A, WORD_LEN, 0},
544 { 0x8A90, 0x2040, WORD_LEN, 0},
545 { 0x8A92, 0x8E2D, WORD_LEN, 0},
546 { 0x8A94, 0xBF08, WORD_LEN, 0},
547 { 0x8A96, 0x7F05, WORD_LEN, 0},
548 { 0x8A98, 0x8E0C, WORD_LEN, 0},
549 { 0x8A9A, 0xB808, WORD_LEN, 0},
550 { 0x8A9C, 0x7825, WORD_LEN, 0},
551 { 0x8A9E, 0x7710, WORD_LEN, 0},
552 { 0x8AA0, 0x21C2, WORD_LEN, 0},
553 { 0x8AA2, 0x244C, WORD_LEN, 0},
554 { 0x8AA4, 0x081D, WORD_LEN, 0},
555 { 0x8AA6, 0x03E3, WORD_LEN, 0},
556 { 0x8AA8, 0xD9FF, WORD_LEN, 0},
557 { 0x8AAA, 0x2702, WORD_LEN, 0},
558 { 0x8AAC, 0x1002, WORD_LEN, 0},
559 { 0x8AAE, 0x2A05, WORD_LEN, 0},
560 { 0x8AB0, 0x037E, WORD_LEN, 0},
561 { 0x8AB2, 0x0876, WORD_LEN, 0},
562 { 0x8AB4, 0x06E4, WORD_LEN, 0},
563 { 0x8AB6, 0x702F, WORD_LEN, 0},
564 { 0x8AB8, 0x7810, WORD_LEN, 0},
565 { 0x8ABA, 0x7F02, WORD_LEN, 0},
566 { 0x8ABC, 0x7FF0, WORD_LEN, 0},
567 { 0x8ABE, 0xF00B, WORD_LEN, 0},
568 { 0x8AC0, 0x78E2, WORD_LEN, 0},
569 { 0x8AC2, 0x2805, WORD_LEN, 0},
570 { 0x8AC4, 0x037E, WORD_LEN, 0},
571 { 0x8AC6, 0x0862, WORD_LEN, 0},
572 { 0x8AC8, 0x06E4, WORD_LEN, 0},
573 { 0x8ACA, 0x702F, WORD_LEN, 0},
574 { 0x8ACC, 0x7810, WORD_LEN, 0},
575 { 0x8ACE, 0x671F, WORD_LEN, 0},
576 { 0x8AD0, 0x7FF0, WORD_LEN, 0},
577 { 0x8AD2, 0x7FEF, WORD_LEN, 0},
578 { 0x8AD4, 0x8E08, WORD_LEN, 0},
579 { 0x8AD6, 0xBF06, WORD_LEN, 0},
580 { 0x8AD8, 0xD15A, WORD_LEN, 0},
581 { 0x8ADA, 0xB8C3, WORD_LEN, 0},
582 { 0x8ADC, 0x78E5, WORD_LEN, 0},
583 { 0x8ADE, 0xB88F, WORD_LEN, 0},
584 { 0x8AE0, 0x1908, WORD_LEN, 0},
585 { 0x8AE2, 0x0024, WORD_LEN, 0},
586 { 0x8AE4, 0x2841, WORD_LEN, 0},
587 { 0x8AE6, 0x0201, WORD_LEN, 0},
588 { 0x8AE8, 0x1E26, WORD_LEN, 0},
589 { 0x8AEA, 0x1042, WORD_LEN, 0},
590 { 0x8AEC, 0x0D15, WORD_LEN, 0},
591 { 0x8AEE, 0x1423, WORD_LEN, 0},
592 { 0x8AF0, 0x1E27, WORD_LEN, 0},
593 { 0x8AF2, 0x1002, WORD_LEN, 0},
594 { 0x8AF4, 0x214C, WORD_LEN, 0},
595 { 0x8AF6, 0xA000, WORD_LEN, 0},
596 { 0x8AF8, 0x214A, WORD_LEN, 0},
597 { 0x8AFA, 0x2040, WORD_LEN, 0},
598 { 0x8AFC, 0x21C2, WORD_LEN, 0},
599 { 0x8AFE, 0x2442, WORD_LEN, 0},
600 { 0x8B00, 0x8E21, WORD_LEN, 0},
601 { 0x8B02, 0x214F, WORD_LEN, 0},
602 { 0x8B04, 0x0040, WORD_LEN, 0},
603 { 0x8B06, 0x090F, WORD_LEN, 0},
604 { 0x8B08, 0x2010, WORD_LEN, 0},
605 { 0x8B0A, 0x2145, WORD_LEN, 0},
606 { 0x8B0C, 0x0181, WORD_LEN, 0},
607 { 0x8B0E, 0xAE21, WORD_LEN, 0},
608 { 0x8B10, 0xF003, WORD_LEN, 0},
609 { 0x8B12, 0xB8A2, WORD_LEN, 0},
610 { 0x8B14, 0xAE01, WORD_LEN, 0},
611 { 0x8B16, 0x0BFA, WORD_LEN, 0},
612 { 0x8B18, 0xFFE3, WORD_LEN, 0},
613 { 0x8B1A, 0x70A9, WORD_LEN, 0},
614 { 0x8B1C, 0x0789, WORD_LEN, 0},
615 { 0x8B1E, 0x0684, WORD_LEN, 0},
616 { 0x8B20, 0xD149, WORD_LEN, 0},
617 { 0x8B22, 0xD24A, WORD_LEN, 0},
618 { 0x8B24, 0x11B2, WORD_LEN, 0},
619 { 0x8B26, 0x8903, WORD_LEN, 0},
620 { 0x8B28, 0x1252, WORD_LEN, 0},
621 { 0x8B2A, 0x0100, WORD_LEN, 0},
622 { 0x8B2C, 0x7B6F, WORD_LEN, 0},
623 { 0x8B2E, 0xB808, WORD_LEN, 0},
624 { 0x8B30, 0x2004, WORD_LEN, 0},
625 { 0x8B32, 0x0F80, WORD_LEN, 0},
626 { 0x8B34, 0x0000, WORD_LEN, 0},
627 { 0x8B36, 0xFF00, WORD_LEN, 0},
628 { 0x8B38, 0x7865, WORD_LEN, 0},
629 { 0x8B3A, 0x19B2, WORD_LEN, 0},
630 { 0x8B3C, 0x8024, WORD_LEN, 0},
631 { 0x8B3E, 0xD044, WORD_LEN, 0},
632 { 0x8B40, 0x8801, WORD_LEN, 0},
633 { 0x8B42, 0xB8E1, WORD_LEN, 0},
634 { 0x8B44, 0xD800, WORD_LEN, 0},
635 { 0x8B46, 0xF404, WORD_LEN, 0},
636 { 0x8B48, 0x1234, WORD_LEN, 0},
637 { 0x8B4A, 0x0080, WORD_LEN, 0},
638 { 0x8B4C, 0x1955, WORD_LEN, 0},
639 { 0x8B4E, 0x803C, WORD_LEN, 0},
640 { 0x8B50, 0x1233, WORD_LEN, 0},
641 { 0x8B52, 0x0080, WORD_LEN, 0},
642 { 0x8B54, 0xB802, WORD_LEN, 0},
643 { 0x8B56, 0x1957, WORD_LEN, 0},
644 { 0x8B58, 0x803C, WORD_LEN, 0},
645 { 0x8B5A, 0x1958, WORD_LEN, 0},
646 { 0x8B5C, 0x803C, WORD_LEN, 0},
647 { 0x8B5E, 0x1959, WORD_LEN, 0},
648 { 0x8B60, 0x803C, WORD_LEN, 0},
649 { 0x8B62, 0x195A, WORD_LEN, 0},
650 { 0x8B64, 0x803C, WORD_LEN, 0},
651 { 0x8B66, 0x7EE0, WORD_LEN, 0},
652 { 0x8B68, 0xC0F1, WORD_LEN, 0},
653 { 0x8B6A, 0x0EE6, WORD_LEN, 0},
654 { 0x8B6C, 0x0684, WORD_LEN, 0},
655 { 0x8B6E, 0xD523, WORD_LEN, 0},
656 { 0x8B70, 0x8D2C, WORD_LEN, 0},
657 { 0x8B72, 0x0983, WORD_LEN, 0},
658 { 0x8B74, 0x0010, WORD_LEN, 0},
659 { 0x8B76, 0xD236, WORD_LEN, 0},
660 { 0x8B78, 0x123A, WORD_LEN, 0},
661 { 0x8B7A, 0x0083, WORD_LEN, 0},
662 { 0x8B7C, 0x123B, WORD_LEN, 0},
663 { 0x8B7E, 0x008F, WORD_LEN, 0},
664 { 0x8B80, 0x8D55, WORD_LEN, 0},
665 { 0x8B82, 0xBB08, WORD_LEN, 0},
666 { 0x8B84, 0x7BE5, WORD_LEN, 0},
667 { 0x8B86, 0x8DF6, WORD_LEN, 0},
668 { 0x8B88, 0xBA08, WORD_LEN, 0},
669 { 0x8B8A, 0x7AE5, WORD_LEN, 0},
670 { 0x8B8C, 0x0B0D, WORD_LEN, 0},
671 { 0x8B8E, 0x00A3, WORD_LEN, 0},
672 { 0x8B90, 0x8DC5, WORD_LEN, 0},
673 { 0x8B92, 0x8D54, WORD_LEN, 0},
674 { 0x8B94, 0xAD45, WORD_LEN, 0},
675 { 0x8B96, 0xF026, WORD_LEN, 0},
676 { 0x8B98, 0x65DB, WORD_LEN, 0},
677 { 0x8B9A, 0x8B6D, WORD_LEN, 0},
678 { 0x8B9C, 0x0815, WORD_LEN, 0},
679 { 0x8B9E, 0x00E2, WORD_LEN, 0},
680 { 0x8BA0, 0x65DA, WORD_LEN, 0},
681 { 0x8BA2, 0x8A51, WORD_LEN, 0},
682 { 0x8BA4, 0x0A0D, WORD_LEN, 0},
683 { 0x8BA6, 0x0002, WORD_LEN, 0},
684 { 0x8BA8, 0xE683, WORD_LEN, 0},
685 { 0x8BAA, 0x22CA, WORD_LEN, 0},
686 { 0x8BAC, 0x038B, WORD_LEN, 0},
687 { 0x8BAE, 0xF69A, WORD_LEN, 0},
688 { 0x8BB0, 0xDA00, WORD_LEN, 0},
689 { 0x8BB2, 0xAD45, WORD_LEN, 0},
690 { 0x8BB4, 0x2540, WORD_LEN, 0},
691 { 0x8BB6, 0x1343, WORD_LEN, 0},
692 { 0x8BB8, 0xE180, WORD_LEN, 0},
693 { 0x8BBA, 0x2540, WORD_LEN, 0},
694 { 0x8BBC, 0x144F, WORD_LEN, 0},
695 { 0x8BBE, 0xF6D2, WORD_LEN, 0},
696 { 0x8BC0, 0x719F, WORD_LEN, 0},
697 { 0x8BC2, 0x78E0, WORD_LEN, 0},
698 { 0x8BC4, 0x20A8, WORD_LEN, 0},
699 { 0x8BC6, 0x0280, WORD_LEN, 0},
700 { 0x8BC8, 0x8B20, WORD_LEN, 0},
701 { 0x8BCA, 0x0813, WORD_LEN, 0},
702 { 0x8BCC, 0x0043, WORD_LEN, 0},
703 { 0x8BCE, 0xE201, WORD_LEN, 0},
704 { 0x8BD0, 0x7A4F, WORD_LEN, 0},
705 { 0x8BD2, 0xAD45, WORD_LEN, 0},
706 { 0x8BD4, 0xE301, WORD_LEN, 0},
707 { 0x8BD6, 0xE701, WORD_LEN, 0},
708 { 0x8BD8, 0xF004, WORD_LEN, 0},
709 { 0x8BDA, 0x8F20, WORD_LEN, 0},
710 { 0x8BDC, 0x09F3, WORD_LEN, 0},
711 { 0x8BDE, 0x8002, WORD_LEN, 0},
712 { 0x8BE0, 0xD01C, WORD_LEN, 0},
713 { 0x8BE2, 0x8800, WORD_LEN, 0},
714 { 0x8BE4, 0xE803, WORD_LEN, 0},
715 { 0x8BE6, 0x0E0F, WORD_LEN, 0},
716 { 0x8BE8, 0x1080, WORD_LEN, 0},
717 { 0x8BEA, 0xD008, WORD_LEN, 0},
718 { 0x8BEC, 0x8000, WORD_LEN, 0},
719 { 0x8BEE, 0x8002, WORD_LEN, 0},
720 { 0x8BF0, 0x7840, WORD_LEN, 0},
721 { 0x8BF2, 0x06C5, WORD_LEN, 0},
722 { 0x8BF4, 0x0684, WORD_LEN, 0},
723 { 0x8BF6, 0x78E0, WORD_LEN, 0},
724 { 0x8BF8, 0xFF80, WORD_LEN, 0},
725 { 0x8BFA, 0x0644, WORD_LEN, 0},
726 { 0x8BFC, 0x0000, WORD_LEN, 0},
727 { 0x8BFE, 0xF978, WORD_LEN, 0},
728 { 0x8C00, 0xFF80, WORD_LEN, 0},
729 { 0x8C02, 0x0E00, WORD_LEN, 0},
730 { 0x8C04, 0xFF80, WORD_LEN, 0},
731 { 0x8C06, 0x0B68, WORD_LEN, 0},
732 { 0x8C08, 0x8000, WORD_LEN, 0},
733 { 0x8C0A, 0x0164, WORD_LEN, 0},
734 { 0x8C0C, 0x0000, WORD_LEN, 0},
735 { 0x8C0E, 0xF9AC, WORD_LEN, 0},
736 { 0x8C10, 0xFF80, WORD_LEN, 0},
737 { 0x8C12, 0x0B20, WORD_LEN, 0},
738 { 0x8C14, 0xFF80, WORD_LEN, 0},
739 { 0x8C16, 0x0314, WORD_LEN, 0},
740 { 0x8C18, 0x8000, WORD_LEN, 0},
741 { 0x8C1A, 0x016C, WORD_LEN, 0},
742 { 0x8C1C, 0xFF80, WORD_LEN, 0},
743 { 0x8C1E, 0x0694, WORD_LEN, 0},
744 { 0x8C20, 0x0000, WORD_LEN, 0},
745 { 0x8C22, 0xF444, WORD_LEN, 0},
746 { 0x8C24, 0xFF80, WORD_LEN, 0},
747 { 0x8C26, 0x0C54, WORD_LEN, 0},
748 { 0x8C28, 0x8000, WORD_LEN, 0},
749 { 0x8C2A, 0x009C, WORD_LEN, 0},
750 { 0x8C2C, 0x8000, WORD_LEN, 0},
751 { 0x8C2E, 0x0008, WORD_LEN, 0},
752 { 0x8C30, 0xFF80, WORD_LEN, 0},
753 { 0x8C32, 0x0DF0, WORD_LEN, 0},
754 { 0x8C34, 0xFF80, WORD_LEN, 0},
755 { 0x8C36, 0x02CC, WORD_LEN, 0},
756 { 0x8C38, 0xFF80, WORD_LEN, 0},
757 { 0x8C3A, 0x0158, WORD_LEN, 0},
758 { 0x8C3C, 0xFF80, WORD_LEN, 0},
759 { 0x8C3E, 0x0290, WORD_LEN, 0},
760 { 0x8C40, 0xFF00, WORD_LEN, 0},
761 { 0x8C42, 0x0618, WORD_LEN, 0},
762 { 0x8C44, 0xFF00, WORD_LEN, 0},
763 { 0x8C46, 0x33CC, WORD_LEN, 0},
764 { 0x8C48, 0xFF80, WORD_LEN, 0},
765 { 0x8C4A, 0x0658, WORD_LEN, 0},
766 { 0x8C4C, 0xFF80, WORD_LEN, 0},
767 { 0x8C4E, 0x0250, WORD_LEN, 0},
768 { 0x8C50, 0x8000, WORD_LEN, 0},
769 { 0x8C52, 0x0168, WORD_LEN, 0},
770 { 0x8C54, 0xC0F1, WORD_LEN, 0},
771 { 0x8C56, 0x0DFE, WORD_LEN, 0},
772 { 0x8C58, 0x0684, WORD_LEN, 0},
773 { 0x8C5A, 0x17BC, WORD_LEN, 0},
774 { 0x8C5C, 0xF00E, WORD_LEN, 0},
775 { 0x8C5E, 0x8E01, WORD_LEN, 0},
776 { 0x8C60, 0xB8A4, WORD_LEN, 0},
777 { 0x8C62, 0xAE01, WORD_LEN, 0},
778 { 0x8C64, 0x8E09, WORD_LEN, 0},
779 { 0x8C66, 0xB8E0, WORD_LEN, 0},
780 { 0x8C68, 0xF29B, WORD_LEN, 0},
781 { 0x8C6A, 0x17E4, WORD_LEN, 0},
782 { 0x8C6C, 0xF00D, WORD_LEN, 0},
783 { 0x8C6E, 0x153A, WORD_LEN, 0},
784 { 0x8C70, 0x1080, WORD_LEN, 0},
785 { 0x8C72, 0x153B, WORD_LEN, 0},
786 { 0x8C74, 0x1081, WORD_LEN, 0},
787 { 0x8C76, 0xB808, WORD_LEN, 0},
788 { 0x8C78, 0x7825, WORD_LEN, 0},
789 { 0x8C7A, 0x16B8, WORD_LEN, 0},
790 { 0x8C7C, 0x1101, WORD_LEN, 0},
791 { 0x8C7E, 0x092D, WORD_LEN, 0},
792 { 0x8C80, 0x0003, WORD_LEN, 0},
793 { 0x8C82, 0x16B0, WORD_LEN, 0},
794 { 0x8C84, 0x1082, WORD_LEN, 0},
795 { 0x8C86, 0x1E3C, WORD_LEN, 0},
796 { 0x8C88, 0x1082, WORD_LEN, 0},
797 { 0x8C8A, 0x16B1, WORD_LEN, 0},
798 { 0x8C8C, 0x1082, WORD_LEN, 0},
799 { 0x8C8E, 0x1E3D, WORD_LEN, 0},
800 { 0x8C90, 0x1082, WORD_LEN, 0},
801 { 0x8C92, 0x16B4, WORD_LEN, 0},
802 { 0x8C94, 0x1082, WORD_LEN, 0},
803 { 0x8C96, 0x1E3E, WORD_LEN, 0},
804 { 0x8C98, 0x1082, WORD_LEN, 0},
805 { 0x8C9A, 0x16B5, WORD_LEN, 0},
806 { 0x8C9C, 0x1082, WORD_LEN, 0},
807 { 0x8C9E, 0x1E3F, WORD_LEN, 0},
808 { 0x8CA0, 0x1082, WORD_LEN, 0},
809 { 0x8CA2, 0x8E40, WORD_LEN, 0},
810 { 0x8CA4, 0xBAA6, WORD_LEN, 0},
811 { 0x8CA6, 0xAE40, WORD_LEN, 0},
812 { 0x8CA8, 0x098F, WORD_LEN, 0},
813 { 0x8CAA, 0x0022, WORD_LEN, 0},
814 { 0x8CAC, 0x16BA, WORD_LEN, 0},
815 { 0x8CAE, 0x1102, WORD_LEN, 0},
816 { 0x8CB0, 0x0A87, WORD_LEN, 0},
817 { 0x8CB2, 0x0003, WORD_LEN, 0},
818 { 0x8CB4, 0x16B2, WORD_LEN, 0},
819 { 0x8CB6, 0x1084, WORD_LEN, 0},
820 { 0x8CB8, 0x0F2E, WORD_LEN, 0},
821 { 0x8CBA, 0x0664, WORD_LEN, 0},
822 { 0x8CBC, 0x16B0, WORD_LEN, 0},
823 { 0x8CBE, 0x1083, WORD_LEN, 0},
824 { 0x8CC0, 0x1E3C, WORD_LEN, 0},
825 { 0x8CC2, 0x1002, WORD_LEN, 0},
826 { 0x8CC4, 0x153A, WORD_LEN, 0},
827 { 0x8CC6, 0x1080, WORD_LEN, 0},
828 { 0x8CC8, 0x153B, WORD_LEN, 0},
829 { 0x8CCA, 0x1081, WORD_LEN, 0},
830 { 0x8CCC, 0x16B3, WORD_LEN, 0},
831 { 0x8CCE, 0x1084, WORD_LEN, 0},
832 { 0x8CD0, 0xB808, WORD_LEN, 0},
833 { 0x8CD2, 0x7825, WORD_LEN, 0},
834 { 0x8CD4, 0x16B8, WORD_LEN, 0},
835 { 0x8CD6, 0x1101, WORD_LEN, 0},
836 { 0x8CD8, 0x16BA, WORD_LEN, 0},
837 { 0x8CDA, 0x1102, WORD_LEN, 0},
838 { 0x8CDC, 0x0F0A, WORD_LEN, 0},
839 { 0x8CDE, 0x0664, WORD_LEN, 0},
840 { 0x8CE0, 0x16B1, WORD_LEN, 0},
841 { 0x8CE2, 0x1083, WORD_LEN, 0},
842 { 0x8CE4, 0x1E3D, WORD_LEN, 0},
843 { 0x8CE6, 0x1002, WORD_LEN, 0},
844 { 0x8CE8, 0x153A, WORD_LEN, 0},
845 { 0x8CEA, 0x1080, WORD_LEN, 0},
846 { 0x8CEC, 0x153B, WORD_LEN, 0},
847 { 0x8CEE, 0x1081, WORD_LEN, 0},
848 { 0x8CF0, 0x16B6, WORD_LEN, 0},
849 { 0x8CF2, 0x1084, WORD_LEN, 0},
850 { 0x8CF4, 0xB808, WORD_LEN, 0},
851 { 0x8CF6, 0x7825, WORD_LEN, 0},
852 { 0x8CF8, 0x16B8, WORD_LEN, 0},
853 { 0x8CFA, 0x1101, WORD_LEN, 0},
854 { 0x8CFC, 0x16BA, WORD_LEN, 0},
855 { 0x8CFE, 0x1102, WORD_LEN, 0},
856 { 0x8D00, 0x0EE6, WORD_LEN, 0},
857 { 0x8D02, 0x0664, WORD_LEN, 0},
858 { 0x8D04, 0x16B4, WORD_LEN, 0},
859 { 0x8D06, 0x1083, WORD_LEN, 0},
860 { 0x8D08, 0x1E3E, WORD_LEN, 0},
861 { 0x8D0A, 0x1002, WORD_LEN, 0},
862 { 0x8D0C, 0x153A, WORD_LEN, 0},
863 { 0x8D0E, 0x1080, WORD_LEN, 0},
864 { 0x8D10, 0x153B, WORD_LEN, 0},
865 { 0x8D12, 0x1081, WORD_LEN, 0},
866 { 0x8D14, 0x16B7, WORD_LEN, 0},
867 { 0x8D16, 0x1084, WORD_LEN, 0},
868 { 0x8D18, 0xB808, WORD_LEN, 0},
869 { 0x8D1A, 0x7825, WORD_LEN, 0},
870 { 0x8D1C, 0x16B8, WORD_LEN, 0},
871 { 0x8D1E, 0x1101, WORD_LEN, 0},
872 { 0x8D20, 0x16BA, WORD_LEN, 0},
873 { 0x8D22, 0x1102, WORD_LEN, 0},
874 { 0x8D24, 0x0EC2, WORD_LEN, 0},
875 { 0x8D26, 0x0664, WORD_LEN, 0},
876 { 0x8D28, 0x16B5, WORD_LEN, 0},
877 { 0x8D2A, 0x1083, WORD_LEN, 0},
878 { 0x8D2C, 0x1E3F, WORD_LEN, 0},
879 { 0x8D2E, 0x1002, WORD_LEN, 0},
880 { 0x8D30, 0x8E00, WORD_LEN, 0},
881 { 0x8D32, 0xB8A6, WORD_LEN, 0},
882 { 0x8D34, 0xAE00, WORD_LEN, 0},
883 { 0x8D36, 0x153A, WORD_LEN, 0},
884 { 0x8D38, 0x1081, WORD_LEN, 0},
885 { 0x8D3A, 0x153B, WORD_LEN, 0},
886 { 0x8D3C, 0x1080, WORD_LEN, 0},
887 { 0x8D3E, 0xB908, WORD_LEN, 0},
888 { 0x8D40, 0x7905, WORD_LEN, 0},
889 { 0x8D42, 0x16BA, WORD_LEN, 0},
890 { 0x8D44, 0x1100, WORD_LEN, 0},
891 { 0x8D46, 0x085B, WORD_LEN, 0},
892 { 0x8D48, 0x0042, WORD_LEN, 0},
893 { 0x8D4A, 0xD018, WORD_LEN, 0},
894 { 0x8D4C, 0x9E31, WORD_LEN, 0},
895 { 0x8D4E, 0x904D, WORD_LEN, 0},
896 { 0x8D50, 0x0A2B, WORD_LEN, 0},
897 { 0x8D52, 0x0063, WORD_LEN, 0},
898 { 0x8D54, 0x8E00, WORD_LEN, 0},
899 { 0x8D56, 0x16B0, WORD_LEN, 0},
900 { 0x8D58, 0x1081, WORD_LEN, 0},
901 { 0x8D5A, 0x1E3C, WORD_LEN, 0},
902 { 0x8D5C, 0x1042, WORD_LEN, 0},
903 { 0x8D5E, 0x16B1, WORD_LEN, 0},
904 { 0x8D60, 0x1081, WORD_LEN, 0},
905 { 0x8D62, 0x1E3D, WORD_LEN, 0},
906 { 0x8D64, 0x1042, WORD_LEN, 0},
907 { 0x8D66, 0x16B4, WORD_LEN, 0},
908 { 0x8D68, 0x1081, WORD_LEN, 0},
909 { 0x8D6A, 0x1E3E, WORD_LEN, 0},
910 { 0x8D6C, 0x1042, WORD_LEN, 0},
911 { 0x8D6E, 0x16B5, WORD_LEN, 0},
912 { 0x8D70, 0x1081, WORD_LEN, 0},
913 { 0x8D72, 0x1E3F, WORD_LEN, 0},
914 { 0x8D74, 0x1042, WORD_LEN, 0},
915 { 0x8D76, 0xB886, WORD_LEN, 0},
916 { 0x8D78, 0xF012, WORD_LEN, 0},
917 { 0x8D7A, 0x16B2, WORD_LEN, 0},
918 { 0x8D7C, 0x1081, WORD_LEN, 0},
919 { 0x8D7E, 0xB8A6, WORD_LEN, 0},
920 { 0x8D80, 0x1E3C, WORD_LEN, 0},
921 { 0x8D82, 0x1042, WORD_LEN, 0},
922 { 0x8D84, 0x16B3, WORD_LEN, 0},
923 { 0x8D86, 0x1081, WORD_LEN, 0},
924 { 0x8D88, 0x1E3D, WORD_LEN, 0},
925 { 0x8D8A, 0x1042, WORD_LEN, 0},
926 { 0x8D8C, 0x16B6, WORD_LEN, 0},
927 { 0x8D8E, 0x1081, WORD_LEN, 0},
928 { 0x8D90, 0x1E3E, WORD_LEN, 0},
929 { 0x8D92, 0x1042, WORD_LEN, 0},
930 { 0x8D94, 0x16B7, WORD_LEN, 0},
931 { 0x8D96, 0x1081, WORD_LEN, 0},
932 { 0x8D98, 0x1E3F, WORD_LEN, 0},
933 { 0x8D9A, 0x1042, WORD_LEN, 0},
934 { 0x8D9C, 0xAE00, WORD_LEN, 0},
935 { 0x8D9E, 0x0D92, WORD_LEN, 0},
936 { 0x8DA0, 0x0184, WORD_LEN, 0},
937 { 0x8DA2, 0x051D, WORD_LEN, 0},
938 { 0x8DA4, 0x0684, WORD_LEN, 0},
939 { 0x8DA6, 0x78E0, WORD_LEN, 0},
940 { 0x8DA8, 0xFF80, WORD_LEN, 0},
941 { 0x8DAA, 0x050C, WORD_LEN, 0},
942 { 0x8DAC, 0xE280, WORD_LEN, 0},
943 { 0x8DAE, 0x24CA, WORD_LEN, 0},
944 { 0x8DB0, 0x7082, WORD_LEN, 0},
945 { 0x8DB2, 0x78E0, WORD_LEN, 0},
946 { 0x8DB4, 0x20E8, WORD_LEN, 0},
947 { 0x8DB6, 0x01A2, WORD_LEN, 0},
948 { 0x8DB8, 0x1002, WORD_LEN, 0},
949 { 0x8DBA, 0x0D02, WORD_LEN, 0},
950 { 0x8DBC, 0x1902, WORD_LEN, 0},
951 { 0x8DBE, 0x0094, WORD_LEN, 0},
952 { 0x8DC0, 0x7FE0, WORD_LEN, 0},
953 { 0x8DC2, 0x7028, WORD_LEN, 0},
954 { 0x8DC4, 0x7308, WORD_LEN, 0},
955 { 0x8DC6, 0x1000, WORD_LEN, 0},
956 { 0x8DC8, 0x0900, WORD_LEN, 0},
957 { 0x8DCA, 0x7904, WORD_LEN, 0},
958 { 0x8DCC, 0x7947, WORD_LEN, 0},
959 { 0x8DCE, 0x1B00, WORD_LEN, 0},
960 { 0x8DD0, 0x0064, WORD_LEN, 0},
961 { 0x8DD2, 0x7EE0, WORD_LEN, 0},
962 { 0x8DD4, 0xE280, WORD_LEN, 0},
963 { 0x8DD6, 0x24CA, WORD_LEN, 0},
964 { 0x8DD8, 0x7082, WORD_LEN, 0},
965 { 0x8DDA, 0x78E0, WORD_LEN, 0},
966 { 0x8DDC, 0x20E8, WORD_LEN, 0},
967 { 0x8DDE, 0x01A2, WORD_LEN, 0},
968 { 0x8DE0, 0x1102, WORD_LEN, 0},
969 { 0x8DE2, 0x0502, WORD_LEN, 0},
970 { 0x8DE4, 0x1802, WORD_LEN, 0},
971 { 0x8DE6, 0x00B4, WORD_LEN, 0},
972 { 0x8DE8, 0x7FE0, WORD_LEN, 0},
973 { 0x8DEA, 0x7028, WORD_LEN, 0},
974 { 0x8DEC, 0x0000, WORD_LEN, 0},
975 { 0x8DEE, 0x0000, WORD_LEN, 0},
976 { 0x8DF0, 0xFF80, WORD_LEN, 0},
977 { 0x8DF2, 0x0978, WORD_LEN, 0},
978 { 0x8DF4, 0xFF80, WORD_LEN, 0},
979 { 0x8DF6, 0x0A4C, WORD_LEN, 0},
980 { 0x8DF8, 0x0000, WORD_LEN, 0},
981 { 0x8DFA, 0x08DC, WORD_LEN, 0},
982 { 0x8DFC, 0x0000, WORD_LEN, 0},
983 { 0x8DFE, 0x0998, WORD_LEN, 0},
984 { 0x098E, 0x0016, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS
985 { 0x8016, 0x086C, WORD_LEN, 0},         // MON_ADDRESS_LO
986 { 0x8002, 0x0001, WORD_LEN, 0},         // MON_CMD
987 //POLL_{0x800A,0x00,!=0x07,DELAY=10,TIMEOUT=100 //Wait for the core ready
988 ////{ SEQUENCE_WAIT_MS,300, BYTE_LEN, 0},
989 { SEQUENCE_WAIT_MS,100, BYTE_LEN, 0},
990 //char_settings
991 { 0x30D4, 0x9080, WORD_LEN, 0},         // COLUMN_CORRECTION
992 { 0x316E, 0xC400, WORD_LEN, 0},         // DAC_ECL
993 { 0x305E, 0x10A0, WORD_LEN, 0},         // GLOBAL_GAIN
994 { 0x3E00, 0x0010, WORD_LEN, 0},         // SAMP_CONTROL
995 { 0x3E02, 0xED02, WORD_LEN, 0},         // SAMP_ADDR_EN
996 { 0x3E04, 0xC88C, WORD_LEN, 0},         // SAMP_RD1_SIG
997 { 0x3E06, 0xC88C, WORD_LEN, 0},         // SAMP_RD1_SIG_BOOST
998 { 0x3E08, 0x700A, WORD_LEN, 0},         // SAMP_RD1_RST
999 { 0x3E0A, 0x701E, WORD_LEN, 0},         // SAMP_RD1_RST_BOOST
1000 { 0x3E0C, 0x00FF, WORD_LEN, 0},         // SAMP_RST1_EN
1001 { 0x3E0E, 0x00FF, WORD_LEN, 0},         // SAMP_RST1_BOOST
1002 { 0x3E10, 0x00FF, WORD_LEN, 0},         // SAMP_RST1_CLOOP_SH
1003 { 0x3E12, 0x0000, WORD_LEN, 0},         // SAMP_RST_BOOST_SEQ
1004 { 0x3E14, 0xC78C, WORD_LEN, 0},         // SAMP_SAMP1_SIG
1005 { 0x3E16, 0x6E06, WORD_LEN, 0},         // SAMP_SAMP1_RST
1006 { 0x3E18, 0xA58C, WORD_LEN, 0},         // SAMP_TX_EN
1007 { 0x3E1A, 0xA58E, WORD_LEN, 0},         // SAMP_TX_BOOST
1008 { 0x3E1C, 0xA58E, WORD_LEN, 0},         // SAMP_TX_CLOOP_SH
1009 { 0x3E1E, 0xC0D0, WORD_LEN, 0},         // SAMP_TX_BOOST_SEQ
1010 { 0x3E20, 0xEB00, WORD_LEN, 0},         // SAMP_VLN_EN
1011 { 0x3E22, 0x00FF, WORD_LEN, 0},         // SAMP_VLN_HOLD
1012 { 0x3E24, 0xEB02, WORD_LEN, 0},         // SAMP_VCL_EN
1013 { 0x3E26, 0xEA02, WORD_LEN, 0},         // SAMP_COLCLAMP
1014 { 0x3E28, 0xEB0A, WORD_LEN, 0},         // SAMP_SH_VCL
1015 { 0x3E2A, 0xEC01, WORD_LEN, 0},         // SAMP_SH_VREF
1016 { 0x3E2C, 0xEB01, WORD_LEN, 0},         // SAMP_SH_VBST
1017 { 0x3E2E, 0x00FF, WORD_LEN, 0},         // SAMP_SPARE
1018 { 0x3E30, 0x00F3, WORD_LEN, 0},         // SAMP_READOUT
1019 { 0x3E32, 0x3DFA, WORD_LEN, 0},         // SAMP_RESET_DONE
1020 { 0x3E34, 0x00FF, WORD_LEN, 0},         // SAMP_VLN_CLAMP
1021 { 0x3E36, 0x00F3, WORD_LEN, 0},         // SAMP_ASC_INT
1022 { 0x3E38, 0x0000, WORD_LEN, 0},         // SAMP_RS_CLOOP_SH_R
1023 { 0x3E3A, 0xF802, WORD_LEN, 0},         // SAMP_RS_CLOOP_SH
1024 { 0x3E3C, 0x0FFF, WORD_LEN, 0},         // SAMP_RS_BOOST_SEQ
1025 { 0x3E3E, 0xEA10, WORD_LEN, 0},         // SAMP_TXLO_GND
1026 { 0x3E40, 0xEB05, WORD_LEN, 0},         // SAMP_VLN_PER_COL
1027 { 0x3E42, 0xE5C8, WORD_LEN, 0},         // SAMP_RD2_SIG
1028 { 0x3E44, 0xE5C8, WORD_LEN, 0},         // SAMP_RD2_SIG_BOOST
1029 { 0x3E46, 0x8C70, WORD_LEN, 0},         // SAMP_RD2_RST
1030 { 0x3E48, 0x8C71, WORD_LEN, 0},         // SAMP_RD2_RST_BOOST
1031 { 0x3E4A, 0x00FF, WORD_LEN, 0},         // SAMP_RST2_EN
1032 { 0x3E4C, 0x00FF, WORD_LEN, 0},         // SAMP_RST2_BOOST
1033 { 0x3E4E, 0x00FF, WORD_LEN, 0},         // SAMP_RST2_CLOOP_SH
1034 { 0x3E50, 0xE38D, WORD_LEN, 0},         // SAMP_SAMP2_SIG
1035 { 0x3E52, 0x8B0A, WORD_LEN, 0},         // SAMP_SAMP2_RST
1036 { 0x3E58, 0xEB0A, WORD_LEN, 0},         // SAMP_PIX_CLAMP_EN
1037 { 0x3E5C, 0x0A00, WORD_LEN, 0},         // SAMP_PIX_PULLUP_EN
1038 { 0x3E5E, 0x00FF, WORD_LEN, 0},         // SAMP_PIX_PULLDOWN_EN_R
1039 { 0x3E60, 0x00FF, WORD_LEN, 0},         // SAMP_PIX_PULLDOWN_EN_S
1040 { 0x3E90, 0x3C01, WORD_LEN, 0},         // RST_ADDR_EN
1041 { 0x3E92, 0x00FF, WORD_LEN, 0},         // RST_RST_EN
1042 { 0x3E94, 0x00FF, WORD_LEN, 0},         // RST_RST_BOOST
1043 { 0x3E96, 0x3C00, WORD_LEN, 0},         // RST_TX_EN
1044 { 0x3E98, 0x3C00, WORD_LEN, 0},         // RST_TX_BOOST
1045 { 0x3E9A, 0x3C00, WORD_LEN, 0},         // RST_TX_CLOOP_SH
1046 { 0x3E9C, 0xC0E0, WORD_LEN, 0},         // RST_TX_BOOST_SEQ
1047 { 0x3E9E, 0x00FF, WORD_LEN, 0},         // RST_RST_CLOOP_SH
1048 { 0x3EA0, 0x0000, WORD_LEN, 0},         // RST_RST_BOOST_SEQ
1049 { 0x3EA6, 0x3C00, WORD_LEN, 0},         // RST_PIX_PULLUP_EN
1050 { 0x3ED8, 0x3057, WORD_LEN, 0},         // DAC_LD_12_13
1051 { 0x316C, 0xB44F, WORD_LEN, 0},         // DAC_TXLO
1052 { 0x316E, 0xC6FF, WORD_LEN, 0},         // DAC_ECL
1053 { 0x3ED2, 0xEA0A, WORD_LEN, 0},         // DAC_LD_6_7
1054 { 0x3ED4, 0x00A3, WORD_LEN, 0},         // DAC_LD_8_9
1055 { 0x3EDC, 0x6020, WORD_LEN, 0},         // DAC_LD_16_17
1056 { 0x3EE6, 0xA541, WORD_LEN, 0},         // DAC_LD_26_27
1057 { 0x31E0, 0x0001, WORD_LEN, 0},         // PIX_DEF_ID
1058 { 0x3ED0, 0x2409, WORD_LEN, 0},         // DAC_LD_4_5
1059 //{ 0x3EDA, 0x6000      // DAC_LD_14_15  //
1060 { 0x3EDE, 0x0A49, WORD_LEN, 0},         // DAC_LD_18_19
1061 { 0x3EE0, 0x4910, WORD_LEN, 0},         // DAC_LD_20_21
1062 { 0x3EE2, 0x09D2, WORD_LEN, 0},         // DAC_LD_22_23
1063 { 0x30B6, 0x0008, WORD_LEN, 0},         // AUTOLR_CONTROL
1064 { 0x337C, 0x0006, WORD_LEN, 0},         // YUV_YCBCR_CONTROL
1065 { 0x3E1A, 0xA582, WORD_LEN, 0},         // SAMP_TX_BOOST
1066 { 0x3E2E, 0xEC05, WORD_LEN, 0},         // SAMP_SPARE
1067 { 0x3EE6, 0xA5C0, WORD_LEN, 0},         // DAC_LD_26_27
1068 { 0x316C, 0xB43F, WORD_LEN, 0},         // DAC_TXLO
1069 { 0x316E, 0xC6FF, WORD_LEN, 0},         // DAC_ECL
1070 //LOAD = Lens Correction 90% 04/29/10 12:58:28
1071 { 0x381C, 0x0000, WORD_LEN, 0},
1072 { 0xE02A, 0x0001, WORD_LEN, 0},         // IO_NV_MEM_COMMAND
1073   //  POLL  IO_NV_MEM_STATUS::IO_NVMEM_STAT_OTPM_AVAIL =>  0x00
1074 { SEQUENCE_WAIT_MS,100, BYTE_LEN, 0},
1075 { 0x3812, 0x2124, WORD_LEN, 0},
1076 //POLL_FIELD= IO_NV_MEM_STATUS, IO_NV_MEM_STATUS!=0xC1,DELAY=100,TIMEOUT=50 //5 sec
1077 { SEQUENCE_WAIT_MS,100, BYTE_LEN, 0},
1078 { 0xD004, 0x04, BYTE_LEN, 0},   // PGA_SOLUTION
1079 { 0xD006, 0x0008, WORD_LEN, 0},         // PGA_ZONE_ADDR_0
1080 { 0xD005, 0x00, BYTE_LEN, 0},   // PGA_CURRENT_ZONE
1081 { 0xD002, 0x8002, WORD_LEN, 0},         // PGA_ALGO
1082 { 0x3210, 0x49B8, WORD_LEN, 0},         // COLOR_PIPELINE_CONTROL
1083 //[Step5-AWB_CCM]
1084 //awb_setup
1085 { 0xAC02, 0x00FF , WORD_LEN, 0 },       // AWB_ALGO
1086 { 0xAC01, 0x7F, BYTE_LEN, 0 },  // AWB_MODE
1087 //preawb_params
1088 { 0xAC3C, 0x39, BYTE_LEN, 0 },  //42    // AWB_MIN_ACCEPTED_PRE_AWB_R2G_RATIO
1089 { 0xAC3D, 0x6E, BYTE_LEN, 0 },  //50    // AWB_MAX_ACCEPTED_PRE_AWB_R2G_RATIO
1090 { 0xAC3E, 0x28, BYTE_LEN, 0 },  //13    // AWB_MIN_ACCEPTED_PRE_AWB_B2G_RATIO
1091 { 0xAC3F, 0x6B, BYTE_LEN, 0 },  //5B    // AWB_MAX_ACCEPTED_PRE_AWB_B2G_RATIO
1092 { 0xAC40, 0x64, BYTE_LEN, 0 },  //52    // AWB_MIN_ACCEPTED_POST_AWB_R2G_RATIO
1093 { 0xAC41, 0x66, BYTE_LEN, 0 },  //56    // AWB_MAX_ACCEPTED_POST_AWB_R2G_RATIO
1094 { 0xAC42, 0x64, BYTE_LEN, 0 },  // AWB_MIN_ACCEPTED_POST_AWB_B2G_RATIO
1095 { 0xAC43, 0x66, BYTE_LEN, 0 },  // AWB_MAX_ACCEPTED_POST_AWB_B2G_RATIO
1096 //awb_patch
1097 { 0xACB0, 0x31, BYTE_LEN, 0 },  // AWB_RG_MIN
1098 { 0xACB1, 0x5B, BYTE_LEN, 0 },  //50    // AWB_RG_MAX
1099 { 0xACB4, 0x2A, BYTE_LEN, 0 },  //13    // AWB_BG_MIN
1100 { 0xACB5, 0x5B, BYTE_LEN, 0 },  // AWB_BG_MAX
1101 { 0xACB2, 0x42, BYTE_LEN, 0 },          // AWB_RG_MIN_BRIGHT
1102 { 0xACB3, 0x4B, BYTE_LEN, 0 },          // AWB_RG_MAX_BRIGHT
1103 { 0xACB6, 0x36, BYTE_LEN, 0 },          // AWB_BG_MIN_BRIGHT
1104 { 0xACB7, 0x42, BYTE_LEN, 0 },          // AWB_BG_MAX_BRIGHT
1105 { 0xACB8, 0x00D0, WORD_LEN, 0},         // 0x0100       // AWB_START_NUM_INT_LINES
1106 { 0xACBA, 0x0090, WORD_LEN, 0},         // B0   // AWB_END_NUM_INT_LINES
1107 //bright_DNP_patch
1108 { 0x098E, 0xAC09, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS
1109 { 0xAC09, 0x01, BYTE_LEN, 0},   // AWB_MODE_EX
1110 { 0xAC22, 0x0000, WORD_LEN, 0},         // AWB_SHARPNESS_TH
1111 //soc5140_ccm_settings
1112 { 0x098E, 0x2C46, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS [AWB_LEFT_CCM_0]
1113 { 0xAC46, 0x010F, WORD_LEN, 0},   //0x015F      // AWB_LEFT_CCM_0
1114 { 0xAC48, 0xFFAE, WORD_LEN, 0},   //0xFFC2      // AWB_LEFT_CCM_1
1115 { 0xAC4A, 0x0043, WORD_LEN, 0},   //0xFFDF      // AWB_LEFT_CCM_2
1116 { 0xAC4C, 0xFF7E, WORD_LEN, 0},   //0xFF7F      // AWB_LEFT_CCM_3
1117 { 0xAC4E, 0x01BD, WORD_LEN, 0},   //0x01BB      // AWB_LEFT_CCM_4
1118 { 0xAC50, 0xFFC5, WORD_LEN, 0},   //0xFFC6      // AWB_LEFT_CCM_5
1119 { 0xAC52, 0xFFE1, WORD_LEN, 0},   //0xFFC7      // AWB_LEFT_CCM_6
1120 { 0xAC54, 0xFF34, WORD_LEN, 0},   //0xFEFA      // AWB_LEFT_CCM_7
1121 { 0xAC56, 0x01EB, WORD_LEN, 0},   //0x023F      // AWB_LEFT_CCM_8
1122 { 0xAC58, 0x00A8, WORD_LEN, 0},         // AWB_LEFT_CCM_R2BRATIO
1123 { 0xAC5C, 0x0233, WORD_LEN, 0},         // AWB_RIGHT_CCM_0
1124 { 0xAC5E, 0xFF23, WORD_LEN, 0},         // AWB_RIGHT_CCM_1
1125 { 0xAC60, 0xFFAA, WORD_LEN, 0},         // AWB_RIGHT_CCM_2
1126 { 0xAC62, 0xFF91, WORD_LEN, 0},         // AWB_RIGHT_CCM_3
1127 { 0xAC64, 0x01AF, WORD_LEN, 0},         // AWB_RIGHT_CCM_4
1128 { 0xAC66, 0xFFBF, WORD_LEN, 0},         // AWB_RIGHT_CCM_5
1129 { 0xAC68, 0xFFE7, WORD_LEN, 0},         // AWB_RIGHT_CCM_6
1130 { 0xAC6A, 0xFF4C, WORD_LEN, 0},         // AWB_RIGHT_CCM_7
1131 { 0xAC6C, 0x01CE, WORD_LEN, 0},         // AWB_RIGHT_CCM_8
1132 { 0xAC6E, 0x005A, WORD_LEN, 0},         // AWB_RIGHT_CCM_R2BRATIO
1133 { 0xAC72, 0x004D, WORD_LEN, 0},         // AWB_LL_CCM_0
1134 { 0xAC74, 0x0096, WORD_LEN, 0},         // AWB_LL_CCM_1
1135 { 0xAC76, 0x001D, WORD_LEN, 0},         // AWB_LL_CCM_2
1136 { 0xAC78, 0x004D, WORD_LEN, 0},         // AWB_LL_CCM_3
1137 { 0xAC7A, 0x0096, WORD_LEN, 0},         // AWB_LL_CCM_4
1138 { 0xAC7C, 0x001D, WORD_LEN, 0},         // AWB_LL_CCM_5
1139 { 0xAC7E, 0x004D, WORD_LEN, 0},         // AWB_LL_CCM_6
1140 { 0xAC80, 0x0096, WORD_LEN, 0},         // AWB_LL_CCM_7
1141 { 0xAC82, 0x001D, WORD_LEN, 0},         // AWB_LL_CCM_8
1142 { 0xAC97, 0x80, BYTE_LEN, 0},   // AWB_LEFT_TINT_COEF_FOR_CCM_ROW_0
1143 { 0xAC98, 0x80, BYTE_LEN, 0},   // AWB_LEFT_TINT_COEF_FOR_CCM_ROW_1
1144 { 0xAC99, 0x74, BYTE_LEN, 0},   //0x64  // AWB_LEFT_TINT_COEF_FOR_CCM_ROW_2
1145 { 0xAC9A, 0x7D, BYTE_LEN, 0},   //0x76  // AWB_RIGHT_TINT_COEF_FOR_CCM_ROW_0
1146 { 0xAC9B, 0x80, BYTE_LEN, 0},   // AWB_RIGHT_TINT_COEF_FOR_CCM_ROW_1
1147 { 0xAC9C, 0x7D, BYTE_LEN, 0},   //0x78  // AWB_RIGHT_TINT_COEF_FOR_CCM_ROW_2
1148 { 0xB83E, 0x10, BYTE_LEN, 0},   // STAT_AWB_WINDOW_POS_X
1149 { 0xB83F, 0x10, BYTE_LEN, 0},   // STAT_AWB_WINDOW_POS_Y
1150 { 0xB840, 0xDF, BYTE_LEN, 0},   // STAT_AWB_WINDOW_SIZE_X
1151 { 0xB841, 0xCF, BYTE_LEN, 0},   // STAT_AWB_WINDOW_SIZE_Y
1152 //soc5140_weighted2D_awb_settings
1153 { 0xB842, 0x0034, WORD_LEN, 0},   //0x0032      // STAT_AWB_GRAY_CHECKER_OFFSET_X
1154 { 0xB844, 0x003C, WORD_LEN, 0},   //0x0038      // STAT_AWB_GRAY_CHECKER_OFFSET_Y
1155 { 0x3240, 0x0024, WORD_LEN, 0},         // AWB_XY_SCALE
1156 { 0x3242, 0x0000, WORD_LEN, 0},         // AWB_WEIGHT_R0
1157 { 0x3244, 0x0000, WORD_LEN, 0},         // AWB_WEIGHT_R1
1158 { 0x3246, 0x0000, WORD_LEN, 0},         // AWB_WEIGHT_R2
1159 { 0x3248, 0x7070, WORD_LEN, 0},         // AWB_WEIGHT_R3
1160 { 0x324A, 0x38E0, WORD_LEN, 0},         // AWB_WEIGHT_R4
1161 { 0x324C, 0x70E0, WORD_LEN, 0},         // AWB_WEIGHT_R5
1162 { 0x324E, 0x01B8, WORD_LEN, 0},         // AWB_WEIGHT_R6
1163 { 0x3250, 0x00AB, WORD_LEN, 0},         // AWB_WEIGHT_R7
1164 { 0xD80F, 0x04, BYTE_LEN, 0},   // JPEG_QSCALE_0
1165 { 0xD810, 0x08, BYTE_LEN, 0},   // JPEG_QSCALE_1
1166 { 0xC8D2, 0x04, BYTE_LEN, 0},   // CAM_OUTPUT_1_JPEG_QSCALE_0
1167 { 0xC8D3, 0x08, BYTE_LEN, 0},   // CAM_OUTPUT_1_JPEG_QSCALE_1
1168 { 0xC8BC, 0x04, BYTE_LEN, 0},   // CAM_OUTPUT_0_JPEG_QSCALE_0
1169 { 0xC8BD, 0x08, BYTE_LEN, 0},   // CAM_OUTPUT_0_JPEG_QSCALE_1
1170 //sys_settings
1171 { 0x301A, 0x10F4, WORD_LEN, 0},         // RESET_REGISTER
1172 { 0x301E, 0x0083, WORD_LEN, 0},         // DATA_PEDESTAL
1173 { 0x301A, 0x10FC, WORD_LEN, 0},         // RESET_REGISTER
1174 { 0xDC33, 0x20, BYTE_LEN, 0},   // SYS_FIRST_BLACK_LEVEL
1175 { 0xDC35, 0x04, BYTE_LEN, 0},   // SYS_UV_COLOR_BOOST
1176 { 0x326E, 0x0006, WORD_LEN, 0},         // LOW_PASS_YUV_FILTER
1177 { 0xDC37, 0x62, BYTE_LEN, 0},   // SYS_BRIGHT_COLORKILL
1178 { 0x35A4, 0x0596, WORD_LEN, 0},         // BRIGHT_COLOR_KILL_CONTROLS
1179 { 0x35A2, 0x009C, WORD_LEN, 0},         // DARK_COLOR_KILL_CONTROLS
1180 { 0x098E, 0x5C02, WORD_LEN, 0},         // MCU_ADDR
1181 { 0xDC02, 0x003E, WORD_LEN, 0},         // SYS_ALGO
1182 { 0xDC36, 0x34, BYTE_LEN, 0},   // SYS_DARK_COLOR_KILL
1183         // Refresh Mode - skip
1184 { 0xBC18, 0x00, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_0
1185 { 0xBC19, 0x11, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_1
1186 { 0xBC1A, 0x23, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_2
1187 { 0xBC1B, 0x3F, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_3
1188 { 0xBC1C, 0x67, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_4
1189 { 0xBC1D, 0x85, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_5
1190 { 0xBC1E, 0x9B, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_6
1191 { 0xBC1F, 0xAD, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_7
1192 { 0xBC20, 0xBB, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_8
1193 { 0xBC21, 0xC7, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_9
1194 { 0xBC22, 0xD1, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_10
1195 { 0xBC23, 0xDA, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_11
1196 { 0xBC24, 0xE1, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_12
1197 { 0xBC25, 0xE8, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_13
1198 { 0xBC26, 0xEE, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_14
1199 { 0xBC27, 0xF3, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_15
1200 { 0xBC28, 0xF7, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_16
1201 { 0xBC29, 0xFB, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_17
1202 { 0xBC2A, 0xFF, BYTE_LEN, 0},   // LL_GAMMA_CONTRAST_CURVE_18
1203 { 0xBC2B, 0x00, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_0
1204 { 0xBC2C, 0x0A, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_1
1205 { 0xBC2D, 0x1C, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_2
1206 { 0xBC2E, 0x36, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_3
1207 { 0xBC2F, 0x53, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_4
1208 { 0xBC30, 0x6F, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_5
1209 { 0xBC31, 0x86, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_6
1210 { 0xBC32, 0x99, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_7
1211 { 0xBC33, 0xAB, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_8
1212 { 0xBC34, 0xBB, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_9
1213 { 0xBC35, 0xC6, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_10
1214 { 0xBC36, 0xD0, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_11
1215 { 0xBC37, 0xD9, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_12
1216 { 0xBC38, 0xE2, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_13
1217 { 0xBC39, 0xE9, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_14
1218 { 0xBC3A, 0xEF, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_15
1219 { 0xBC3B, 0xF5, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_16
1220 { 0xBC3C, 0xFA, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_17
1221 { 0xBC3D, 0xFF, BYTE_LEN, 0},   // LL_GAMMA_NEUTRAL_CURVE_18
1222 { 0xBC3E, 0x00, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_0
1223 { 0xBC3F, 0x18, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_1
1224 { 0xBC40, 0x25, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_2
1225 { 0xBC41, 0x3A, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_3
1226 { 0xBC42, 0x59, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_4
1227 { 0xBC43, 0x70, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_5
1228 { 0xBC44, 0x81, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_6
1229 { 0xBC45, 0x90, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_7
1230 { 0xBC46, 0x9E, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_8
1231 { 0xBC47, 0xAB, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_9
1232 { 0xBC48, 0xB6, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_10
1233 { 0xBC49, 0xC1, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_11
1234 { 0xBC4A, 0xCB, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_12
1235 { 0xBC4B, 0xD5, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_13
1236 { 0xBC4C, 0xDE, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_14
1237 { 0xBC4D, 0xE7, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_15
1238 { 0xBC4E, 0xEF, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_16
1239 { 0xBC4F, 0xF7, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_17
1240 { 0xBC50, 0xFF, BYTE_LEN, 0},   // LL_GAMMA_NR_CURVE_18
1241 { 0xBC51, 0x04, BYTE_LEN, 0},   // LL_GAMMA_CURVE_SELECTOR
1242 //BM_dampening
1243 { 0xB801, 0xE0, BYTE_LEN, 0},   // STAT_MODE
1244 { 0xB862, 0x04, BYTE_LEN, 0},   // STAT_BMTRACKING_SPEED
1245 //AE
1246 { 0xB829, 0x02, BYTE_LEN, 0},   // STAT_LL_BRIGHTNESS_METRIC_DIVISOR
1247 { 0xB863, 0x02, BYTE_LEN, 0},   // STAT_BM_MUL
1248 { 0xB827, 0x0F, BYTE_LEN, 0},   // STAT_AE_EV_SHIFT
1249 { 0xA409, 0x4A, BYTE_LEN, 0},   // AE_RULE_BASE_TARGET
1250 { 0xA805, 0x06, BYTE_LEN, 0},   // AE_TRACK_GATE
1251 { 0xA80D, 0x08, BYTE_LEN, 0},
1252 { 0xA816, 0x0002, WORD_LEN, 0},         // AE_TRACK_MIN_INT_TIME_ROWS
1253 { 0xA401, 0x00, BYTE_LEN, 0},   // AE_RULE_MODE
1254 { 0xA80E, 0x06, BYTE_LEN, 0},   // AE_TRACK_MAX_BLACK_LEVEL
1255 //BM_GM_start_stop
1256 { 0xC8E6, 0x014C, WORD_LEN, 0},         // RESERVED_CAM_E6
1257 { 0xC8E8, 0x0040, WORD_LEN, 0},         // RESERVED_CAM_E8
1258 { 0xBC52, 0x00C8, WORD_LEN, 0},         // LL_START_BRIGHTNESS_METRIC
1259 { 0xBC54, 0x0A28, WORD_LEN, 0},         // LL_END_BRIGHTNESS_METRIC
1260 { 0xBC58, 0x0100, WORD_LEN, 0},   //0x0000      // LL_START_GAIN_METRIC
1261 { 0xBC5A, 0x0480, WORD_LEN, 0},   //0x1000      // LL_END_GAIN_METRIC
1262 { 0xBC5E, 0x0227, WORD_LEN, 0},         // LL_START_APERTURE_GAIN_BM
1263 { 0xBC60, 0x0540, WORD_LEN, 0},         // LL_END_APERTURE_GAIN_BM
1264 { 0xBC66, 0x0154, WORD_LEN, 0},         // LL_START_APERTURE_GM
1265 { 0xBC68, 0x07D0, WORD_LEN, 0},         // LL_END_APERTURE_GM
1266 { 0xBC86, 0x00C8, WORD_LEN, 0},         // LL_START_FFNR_GM
1267 { 0xBC88, 0x0420, WORD_LEN, 0},         // LL_END_FFNR_GM
1268 { 0xBCBC, 0x0040, WORD_LEN, 0},         // LL_SFFB_START_GAIN
1269 { 0xBCBE, 0x01FC, WORD_LEN, 0},         // LL_SFFB_END_GAIN
1270 { 0xBCCC, 0x00C8, WORD_LEN, 0},         // LL_SFFB_START_MAX_GM
1271 { 0xBCCE, 0x0640, WORD_LEN, 0},         // LL_SFFB_END_MAX_GM
1272 { 0xBC90, 0x00C8, WORD_LEN, 0},         // LL_START_GRB_GM
1273 { 0xBC92, 0x0640, WORD_LEN, 0},         // LL_END_GRB_GM
1274 { 0xBC0E, 0x0032, WORD_LEN, 0},         // LL_GAMMA_CURVE_ADJ_START_POS
1275 { 0xBC10, 0x0064, WORD_LEN, 0},         // LL_GAMMA_CURVE_ADJ_MID_POS
1276 { 0xBC12, 0x0FA0, WORD_LEN, 0},         // LL_GAMMA_CURVE_ADJ_END_POS
1277 { 0xBCAA, 0x03E8, WORD_LEN, 0},         // LL_CDC_THR_ADJ_START_POS
1278 { 0xBCAC, 0x012C, WORD_LEN, 0},         // LL_CDC_THR_ADJ_MID_POS
1279 { 0xBCAE, 0x0009, WORD_LEN, 0},         // LL_CDC_THR_ADJ_END_POS
1280 { 0xBCD8, 0x00C8, WORD_LEN, 0},         // LL_PCR_START_BM
1281 { 0xBCDA, 0x0A28, WORD_LEN, 0},         // LL_PCR_END_BM
1282
1283 //[Kernel]
1284 { 0x3380, 0x0504, WORD_LEN, 0},         // KERNEL_CONFIG
1285 { 0x3380, 0x0505, WORD_LEN, 0},         // KERNEL_CONFIG
1286 { 0x3380, 0x0584, WORD_LEN, 0},         // KERNEL_CONFIG
1287 { 0x3380, 0x0586, WORD_LEN, 0},         // KERNEL_CONFIG
1288 { 0x3380, 0x0587, WORD_LEN, 0},         // KERNEL_CONFIG
1289
1290 //GRB
1291 { 0xBC94, 0x06, BYTE_LEN, 0},   // LL_GB_START_THRESHOLD_0
1292 { 0xBC95, 0x05, BYTE_LEN, 0},   // LL_GB_START_THRESHOLD_1
1293 { 0xBC9C, 0x09, BYTE_LEN, 0},   // RESERVED_LL_9C
1294 { 0xBC9D, 0x05, BYTE_LEN, 0},   // RESERVED_LL_9D
1295
1296 //demosaic
1297 { 0x33B0, 0x2A16, WORD_LEN, 0},         // FFNR_ALPHA_BETA
1298 { 0xBC8A, 0x0E, BYTE_LEN, 0},   //0x00  // LL_START_FF_MIX_THRESH_Y
1299 { 0xBC8B, 0x4C, BYTE_LEN, 0},   // LL_END_FF_MIX_THRESH_Y
1300 { 0xBC8C, 0x00, BYTE_LEN, 0},   // LL_START_FF_MIX_THRESH_YGAIN
1301 { 0xBC8D, 0x24, BYTE_LEN, 0},   // LL_END_FF_MIX_THRESH_YGAIN
1302 { 0xBC8E, 0xFF, BYTE_LEN, 0},   // LL_START_FF_MIX_THRESH_GAIN
1303 { 0xBC8F, 0x00, BYTE_LEN, 0},   // LL_END_FF_MIX_THRESH_GAIN
1304 { 0xBCB2, 0x20, BYTE_LEN, 0},   // LL_CDC_DARK_CLUS_SLOPE
1305 { 0xBCB3, 0x3A, BYTE_LEN, 0},   // LL_CDC_DARK_CLUS_SATUR
1306 { 0xBCB4, 0x39, BYTE_LEN, 0},   // RESERVED_LL_B4
1307 { 0xBCB7, 0x39, BYTE_LEN, 0},   // RESERVED_LL_B7
1308 { 0xBCB5, 0x20, BYTE_LEN, 0},   // RESERVED_LL_B5
1309 { 0xBCB8, 0x3A, BYTE_LEN, 0},   // RESERVED_LL_B8
1310 { 0xBCB6, 0x80, BYTE_LEN, 0},   // RESERVED_LL_B6
1311 { 0xBCB9, 0x24, BYTE_LEN, 0},   // RESERVED_LL_B9
1312
1313 //SFFB_rev3_noisemodel
1314 { 0xBCC0, 0x1F, BYTE_LEN, 0},   // LL_SFFB_RAMP_START
1315 { 0xBCC1, 0x03, BYTE_LEN, 0},   // LL_SFFB_RAMP_STOP
1316 { 0xBCC2, 0x3C, BYTE_LEN, 0},   // LL_SFFB_SLOPE_START
1317 { 0xBCC3, 0x10, BYTE_LEN, 0},   // LL_SFFB_SLOPE_STOP
1318 { 0xBCC4, 0x07, BYTE_LEN, 0},   // LL_SFFB_THSTART
1319 { 0xBCC5, 0x0B, BYTE_LEN, 0},   // LL_SFFB_THSTOP
1320 { 0xBCBA, 0x0009, WORD_LEN, 0},         // LL_SFFB_CONFIG
1321
1322 //[Step7-CPIPE_Preference]
1323 //ftb_off
1324 { 0xBC14, 0xFFFE, WORD_LEN, 0},         // LL_GAMMA_FADE_TO_BLACK_START_POS
1325 { 0xBC16, 0xFFFF, WORD_LEN, 0},         // LL_GAMMA_FADE_TO_BLACK_END_POS
1326
1327 //aperture_preference
1328 { 0xBC6A, 0x06, BYTE_LEN, 0},   // LL_START_APERTURE_INTEGER_GAIN
1329 { 0xBC6B, 0x00, BYTE_LEN, 0},   // LL_END_APERTURE_INTEGER_GAIN
1330 { 0xBC6C, 0x00, BYTE_LEN, 0},   // LL_START_APERTURE_EXP_GAIN
1331 { 0xBC6D, 0x00, BYTE_LEN, 0},   // LL_END_APERTURE_EXP_GAIN
1332 { 0xBCE2, 0x0A, BYTE_LEN, 0},   // LL_START_POS_KNEE
1333 { 0xBCE3, 0x2B, BYTE_LEN, 0},   // LL_END_POS_KNEE
1334 { 0xBCE4, 0x0A, BYTE_LEN, 0},   // LL_START_NEG_KNEE
1335 { 0xBCE5, 0x2B, BYTE_LEN, 0},   // LL_END_NEG_KNEE
1336 { 0x33BA, 0x0084, WORD_LEN, 0},         // APEDGE_CONTROL
1337 { 0x33BE, 0x0000, WORD_LEN, 0},         // UA_KNEE_L
1338 { 0x33C2, 0x5600, WORD_LEN, 0},         // UA_WEIGHTS
1339 { 0xBC62, 0x10, BYTE_LEN, 0},   // LL_START_APERTURE_KPGAIN
1340 { 0xBC63, 0x1F, BYTE_LEN, 0},   // LL_END_APERTURE_KPGAIN
1341 { 0xBC64, 0x10, BYTE_LEN, 0},   // LL_START_APERTURE_KNGAIN
1342 { 0xBC65, 0x1F, BYTE_LEN, 0},   // LL_END_APERTURE_KNGAIN
1343 { 0xA81C, 0x0043, WORD_LEN, 0},         // AE_TRACK_MIN_AGAIN
1344 { 0xA81E, 0x0102, WORD_LEN, 0},         // AE_TRACK_TARGET_AGAIN
1345 { 0xA820, 0x0102, WORD_LEN, 0},         // AE_TRACK_MAX_AGAIN
1346 { 0xA822, 0x0080, WORD_LEN, 0},         // AE_TRACK_MIN_DGAIN
1347 { 0xA824, 0x0080, WORD_LEN, 0},         // AE_TRACK_MAX_DGAIN
1348
1349 //min_fps
1350 { 0xA818, 0x07D0, WORD_LEN, 0},         // AE_TRACK_TARGET_INT_TIME_ROWS
1351 { 0xA81A, 0x0A00, WORD_LEN, 0},  //0x0810(10.9Fps)   //0x0FF4(5Fps)     // AE_TRACK_MAX_INT_TIME_ROWS
1352
1353 //ccm_saturation
1354 { 0xBC56, 0x80, BYTE_LEN, 0},           //0xA8  // LL_START_CCM_SATURATION
1355 { 0xBC57, 0x10, BYTE_LEN, 0},   // LL_END_CCM_SATURATION
1356
1357 //DCCM
1358 { 0xBCDE, 0x03, BYTE_LEN, 0},   // LL_START_SYS_THRESHOLD
1359 { 0xBCDF, 0x50, BYTE_LEN, 0},   // LL_STOP_SYS_THRESHOLD
1360 { 0xBCE0, 0x08, BYTE_LEN, 0},   // LL_START_SYS_GAIN
1361 { 0xBCE1, 0x03, BYTE_LEN, 0},   // LL_STOP_SYS_GAIN
1362
1363 //sobel
1364 { 0xBCD0, 0x000A, WORD_LEN, 0},         // LL_SFFB_SOBEL_FLAT_START
1365 { 0xBCD2, 0x00FE, WORD_LEN, 0},         // LL_SFFB_SOBEL_FLAT_STOP
1366 { 0xBCD4, 0x001E, WORD_LEN, 0},         // LL_SFFB_SOBEL_SHARP_START
1367 { 0xBCD6, 0x00FF, WORD_LEN, 0},         // LL_SFFB_SOBEL_SHARP_STOP
1368 { 0xBCC6, 0x00, BYTE_LEN, 0},   // LL_SFFB_SHARPENING_START
1369 { 0xBCC7, 0x00, BYTE_LEN, 0},   // LL_SFFB_SHARPENING_STOP
1370 { 0xBCC8, 0x20, BYTE_LEN, 0},   // LL_SFFB_FLATNESS_START
1371 { 0xBCC9, 0x40, BYTE_LEN, 0},   // LL_SFFB_FLATNESS_STOP
1372 { 0xBCCA, 0x04, BYTE_LEN, 0},   // LL_SFFB_TRANSITION_START
1373 { 0xBCCB, 0x00, BYTE_LEN, 0},   // LL_SFFB_TRANSITION_STOP
1374 //SFFB_slope_zero_enable
1375 { 0xBCE6, 0x03 , BYTE_LEN, 0 }, // LL_SFFB_ZERO_ENABLE
1376 //manual_FD(auto)
1377 { 0x8417, 0x02, BYTE_LEN, 0 },  // SEQ_STATE_CFG_1_FD
1378 //tx_setting
1379 { 0xC8ED, 0x02, BYTE_LEN, 0 },  // CAM_TX_ENABLE_MODE Context A,B time
1380 //cdc_off
1381 { 0x8404, 0x06, BYTE_LEN, 0 },  // SEQ_CMD
1382 ///{ SEQUENCE_WAIT_MS,300, WORD_LEN, 0},
1383 { SEQUENCE_WAIT_MS,100, WORD_LEN, 0},
1384 { SEQUENCE_END, 0x00, 0, 0}
1385 };
1386
1387 /* 720p 15fps @ 1280x720 */
1388 static struct reginfo sensor_720p[]=
1389 {
1390         //{SEQUENCE_END, 0x00},
1391         {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [CAM_CORE_A_Y_ADDR_START]
1392         {0x843C, 0x01, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
1393         {0x8404, 0x01, BYTE_LEN, 0 }, // SEQ_CMD
1394         {0x0016, 0x0447, WORD_LEN, 0},  // CLOCKS_CONTROL
1395         {0xC83A, 0x0106, WORD_LEN, 0},  // CAM_CORE_A_Y_ADDR_START
1396         {0xC83C, 0x0018, WORD_LEN, 0},  // CAM_CORE_A_X_ADDR_START
1397         {0xC83E, 0x06B7, WORD_LEN, 0},  // CAM_CORE_A_Y_ADDR_END
1398         {0xC840, 0x0A45, WORD_LEN, 0},  // CAM_CORE_A_X_ADDR_END
1399         {0xC86C, 0x0518, WORD_LEN, 0},  // CAM_CORE_A_OUTPUT_SIZE_WIDTH
1400         {0xC86E, 0x02D8, WORD_LEN, 0},  // CAM_CORE_A_OUTPUT_SIZE_HEIGHT
1401         {0xC870, 0x0014, WORD_LEN, 0},  // CAM_CORE_A_RX_FIFO_TRIGGER_MARK
1402         {0xC858, 0x0003, WORD_LEN, 0}, // CAM_CORE_A_COARSE_ITMIN
1403         {0xC8B8, 0x0004, WORD_LEN, 0},  // CAM_OUTPUT_0_JPEG_CONTROL
1404 /****bug:part pixsels data not to be aquired *****/
1405 #if ADJUST_FOR_720P_FALG            
1406         {0xC8AA, 0x0500, WORD_LEN, 0},  // CAM_OUTPUT_0_IMAGE_WIDTH
1407         {0xC8AC, 0x02D1, WORD_LEN, 0},  // CAM_OUTPUT_0_IMAGE_HEIGHT
1408 #else
1409         {0xC8AA, 0x0500, WORD_LEN, 0},  // CAM_OUTPUT_0_IMAGE_WIDTH
1410         {0xC8AC, 0x02D0, WORD_LEN, 0},  // CAM_OUTPUT_0_IMAGE_HEIGHT
1411 #endif  
1412         {0xC8AE, 0x0001, WORD_LEN, 0},  // CAM_OUTPUT_0_OUTPUT_FORMAT
1413         {0x8404, 0x06, BYTE_LEN, 0 },  // SEQ_CMD
1414
1415         {SEQUENCE_WAIT_MS,100, WORD_LEN, 0},
1416    { SEQUENCE_END, 0x00, 0, 0}
1417 };
1418
1419 /*      1080p, 0x15fps, 0xyuv @1920x1080 */
1420 static struct reginfo sensor_1080p[]=
1421 {
1422 { SEQUENCE_END, 0x00, 0, 0}
1423 };
1424
1425 /* 2592X1944 QSXGA */
1426 #if  ADJUST_FOR_CAPTURE_FALG
1427 static struct reginfo sensor_qsxga[] =
1428 {
1429     {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
1430     {0xC8C0, 0x0A20,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
1431     {0xC8C2, 0x0798,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
1432     {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
1433     {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
1434     {SEQUENCE_END, 0x00, 0, 0}
1435 };
1436 #else
1437 static struct reginfo sensor_qsxga[] =
1438 {
1439         {SEQUENCE_PROPERTY,SEQUENCE_CAPTURE},
1440     { SEQUENCE_END, 0x00, 0, 0}
1441 };
1442 #endif
1443
1444 /* 2048*1536 QXGA */
1445 #if ADJUST_FOR_CAPTURE_FALG
1446 // send extra two lines to forbid to be captured error
1447 static struct reginfo sensor_qxga[] =
1448 {
1449     {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
1450     {0xC8C0, 0x0800,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
1451     {0xC8C2, 0x0602,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
1452     {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
1453     {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
1454     {SEQUENCE_END, 0x00, 0, 0}
1455 };
1456 #else
1457 static struct reginfo sensor_qxga[] =
1458 {
1459 { SEQUENCE_END, 0x00, 0, 0}
1460 };
1461 #endif
1462
1463 /* 1600X1200 UXGA */
1464 #if ADJUST_FOR_CAPTURE_FALG
1465 static struct reginfo sensor_uxga[] =
1466 {
1467     {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
1468     {0xC8C0, 0x0640,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
1469     {0xC8C2, 0x04b2,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
1470     {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
1471     {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
1472     {SEQUENCE_END, 0x00, 0, 0}
1473 };
1474 #else
1475 static struct reginfo sensor_uxga[] =
1476 {
1477     { SEQUENCE_END, 0x00, 0, 0}
1478 };
1479 #endif
1480
1481 /* 1280X1024 SXGA */
1482 static struct reginfo sensor_sxga[] =
1483 {
1484         {SEQUENCE_END, 0x00}
1485 };
1486
1487 /*  1024X768 XGA */
1488 #if ADJUST_FOR_CAPTURE_FALG
1489 static struct reginfo sensor_xga[] =
1490 {
1491     {0x098E, 0x48C0,WORD_LEN,0},    // LOGICAL_ADDRESS_ACCESS [CAM_OUTPUT_1_IMAGE_WIDTH]
1492     {0xC8C0, 0x0403,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_WIDTH
1493     {0xC8C2, 0x0302,WORD_LEN,0},    // CAM_OUTPUT_1_IMAGE_HEIGHT
1494     {0x8404, 0x06 ,BYTE_LEN,0},      // SEQ_CMD
1495     {SEQUENCE_WAIT_MS,100,WORD_LEN,0},
1496     {SEQUENCE_END, 0x00, 0, 0}
1497 };
1498 #else
1499 static struct reginfo sensor_xga[] =
1500 {
1501     {SEQUENCE_END, 0x00, 0, 0}
1502 };
1503 #endif
1504
1505
1506 /* 800X600 SVGA*/
1507 static struct reginfo sensor_svga[] =
1508 {
1509     { SEQUENCE_END, 0x00, 0, 0}
1510 };
1511
1512 /* 640X480 VGA */
1513 static struct reginfo sensor_vga[] =
1514 {
1515         //720p2vga
1516     {0xC83A, 0x000C, WORD_LEN, 0},    // CAM_CORE_A_Y_ADDR_START
1517     {0xC83C, 0x0018, WORD_LEN, 0},    // CAM_CORE_A_X_ADDR_START
1518     {0xC83E, 0x07B1, WORD_LEN, 0 },    // CAM_CORE_A_Y_ADDR_END
1519     {0xC840, 0x0A45, WORD_LEN, 0},    // CAM_CORE_A_X_ADDR_END
1520     {0xC868, 0x0423, WORD_LEN, 0},    // CAM_CORE_A_FRAME_LENGTH_LINES
1521     {0xC86A, 0x1194, WORD_LEN, 0},    // CAM_CORE_A_LINE_LENGTH_PCK
1522     {0xC86C, 0x0518, WORD_LEN, 0},    // CAM_CORE_A_OUTPUT_SIZE_WIDTH
1523     {0xC86E, 0x03D4, WORD_LEN, 0},    // CAM_CORE_A_OUTPUT_SIZE_HEIGHT
1524     {0xC870, 0x0014, WORD_LEN, 0},    // CAM_CORE_A_RX_FIFO_TRIGGER_MARK
1525     {0xC858, 0x0003, WORD_LEN, 0},  // CAM_CORE_A_COARSE_ITMIN
1526     {0xC8A4, 0x0A28, WORD_LEN, 0},    // CAM_CORE_B_OUTPUT_SIZE_WIDTH
1527     {0xC8A6, 0x07A0, WORD_LEN, 0 },    // CAM_CORE_B_OUTPUT_SIZE_HEIGHT
1528     {0xC8AA, 0x0280, WORD_LEN, 0 },    // CAM_OUTPUT_0_IMAGE_WIDTH
1529     {0xC8AC, 0x01E0, WORD_LEN, 0 },    // CAM_OUTPUT_0_IMAGE_HEIGHT
1530     {0xC8AE, 0x0001, WORD_LEN, 0 },    // CAM_OUTPUT_0_OUTPUT_FORMAT
1531     {0x8404, 0x06, BYTE_LEN, 0 }, // SEQ_CMD
1532     {SEQUENCE_WAIT_MS,100, WORD_LEN, 0},
1533     {SEQUENCE_END, 0x00, 0, 0}
1534
1535 };
1536
1537 /* 352X288 CIF */
1538 static struct reginfo sensor_cif[] =
1539 {
1540         {SEQUENCE_END, 0x00}
1541 };
1542
1543 /* 320*240 QVGA */
1544 static  struct reginfo sensor_qvga[] =
1545 {
1546         {SEQUENCE_END, 0x00}
1547 };
1548
1549 /* 176X144 QCIF*/
1550 static struct reginfo sensor_qcif[] =
1551 {
1552         {SEQUENCE_END, 0x00}
1553 };
1554 #endif
1555 static  struct reginfo sensor_Preview2Capture[]=
1556 {
1557         //capture2preview
1558         {0x098E, 0x843C, WORD_LEN, 0},  // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
1559         {0x843C, 0xFF, BYTE_LEN, 0 },   // SEQ_STATE_CFG_5_MAX_FRAME_CNT
1560         {0x8404, 0x02, BYTE_LEN, 0 },   // SEQ_CMD
1561         {SEQUENCE_END, 0x00, 0, 0}
1562
1563 };
1564
1565 static  struct reginfo sensor_Capture2Preview[]=
1566 {
1567         //snap2preview
1568         {0x098E, 0x843C, WORD_LEN, 0},  // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
1569         {0x843C, 0x01, BYTE_LEN, 0 },   // SEQ_STATE_CFG_5_MAX_FRAME_CNT
1570         {0x8404, 0x01, BYTE_LEN, 0 },   // SEQ_CMD
1571         {0x0016, 0x0447, WORD_LEN, 0},  // CLOCKS_CONTRO
1572         {SEQUENCE_END, 0x00, 0, 0}
1573
1574 };
1575 static  struct reginfo sensor_ClrFmt_YUYV[]=
1576 {
1577         {SEQUENCE_END, 0x00}
1578 };
1579
1580 static  struct reginfo sensor_ClrFmt_UYVY[]=
1581 {
1582         {SEQUENCE_END, 0x00}
1583 };
1584
1585
1586 #if CONFIG_SENSOR_WhiteBalance
1587 static  struct reginfo sensor_WhiteB_Auto[]=
1588 {
1589         //Auto
1590         {0x098E, 0xACB0, WORD_LEN, 0},  // LOGICAL_ADDRESS_ACCESS [AWB_MIN_ACCEPTED_PRE_AWB_R2G_RATIO]
1591         {0xACB0, 0x31, BYTE_LEN, 0 },   // AWB_RG_MIN
1592         {0xACB1, 0x5B, BYTE_LEN, 0 },   // AWB_RG_MAX
1593         {0xACB4, 0x2A, BYTE_LEN, 0 },   // AWB_BG_MIN
1594         {0xACB5, 0x5B, BYTE_LEN, 0 },   // AWB_BG_MAX
1595         {0xACB2, 0x40, BYTE_LEN, 0 },   // AWB_RG_MIN_BRIGHT
1596         {0xACB3, 0x48, BYTE_LEN, 0 },   // AWB_RG_MAX_BRIGHT
1597         {0xACB6, 0x3f, BYTE_LEN, 0 },   // AWB_BG_MIN_BRIGHT
1598         {0xACB7, 0x48, BYTE_LEN, 0 },   // AWB_BG_MAX_BRIGHT
1599         {0xAC44, 0x00, BYTE_LEN, 0 },   // AWB_LEFT_CCM_POS_RANGE_LIMIT
1600         {0xAC45, 0x7F, BYTE_LEN, 0 },   // AWB_RIGHT_CCM_POS_RANGE_LIMIT
1601         {SEQUENCE_END, 0x00, 0, 0}
1602
1603 };
1604 /* Cloudy Colour Temperature : 6500K - 8000K  */
1605 static  struct reginfo sensor_WhiteB_Cloudy[]=
1606 {
1607         //[V.       DL 7500]
1608         { 0x098E, 0xACB0, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS [AWB_MIN_ACCEPTED_PRE_AWB_R2G_RATIO]
1609         {0xACB0, 0x38, BYTE_LEN, 0 },   // AWB_RG_MIN
1610         {0xACB1, 0x42, BYTE_LEN, 0 },   // AWB_RG_MAX
1611         {0xACB4, 0x44, BYTE_LEN, 0 },   // AWB_BG_MIN
1612         {0xACB5, 0x4C, BYTE_LEN, 0 },   // AWB_BG_MAX
1613         {0xACB2, 0x38, BYTE_LEN, 0 },   // AWB_RG_MIN_BRIGHT
1614         {0xACB3, 0x42, BYTE_LEN, 0 },   // AWB_RG_MAX_BRIGHT
1615         {0xACB6, 0x44, BYTE_LEN, 0 },   // AWB_BG_MIN_BRIGHT
1616         {0xACB7, 0x4C, BYTE_LEN, 0 },   // AWB_BG_MAX_BRIGHT
1617         {0xAC44, 0x7C, BYTE_LEN, 0 },   // AWB_LEFT_CCM_POS_RANGE_LIMIT
1618         {0xAC45, 0x7F, BYTE_LEN, 0 },   // AWB_RIGHT_CCM_POS_RANGE_LIMIT
1619         {0xAC04, 0x3E, BYTE_LEN, 0 },   // AWB_PRE_AWB_R2G_RATIO
1620         {0xAC05, 0x48, BYTE_LEN, 0 },   // AWB_PRE_AWB_B2G_RATIO
1621         {0xAC08, 0x7F, BYTE_LEN, 0 },   // AWB_CUR_CCM_POS
1622         {SEQUENCE_END, 0x00, 0, 0}
1623
1624 };
1625 /* ClearDay Colour Temperature : 5000K - 6500K  */
1626 static  struct reginfo sensor_WhiteB_ClearDay[]=
1627 {
1628         //[IV       Day Light]
1629         { 0x098E, 0xACB0, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS [AWB_MIN_ACCEPTED_PRE_AWB_R2G_RATIO]
1630         {0xACB0, 0x3A, BYTE_LEN, 0 },   // AWB_RG_MIN
1631         {0xACB1, 0x44, BYTE_LEN, 0 },   // AWB_RG_MAX
1632         {0xACB4, 0x40, BYTE_LEN, 0 },   // AWB_BG_MIN
1633         {0xACB5, 0x4A, BYTE_LEN, 0 },   // AWB_BG_MAX
1634         {0xACB2, 0x3A, BYTE_LEN, 0 },   // AWB_RG_MIN_BRIGHT
1635         {0xACB3, 0x44, BYTE_LEN, 0 },   // AWB_RG_MAX_BRIGHT
1636         {0xACB6, 0x40, BYTE_LEN, 0 },   // AWB_BG_MIN_BRIGHT
1637         {0xACB7, 0x4A, BYTE_LEN, 0 },   // AWB_BG_MAX_BRIGHT
1638         {0xAC44, 0x7C, BYTE_LEN, 0 },   // AWB_LEFT_CCM_POS_RANGE_LIMIT
1639         {0xAC45, 0x7F, BYTE_LEN, 0 },   // AWB_RIGHT_CCM_POS_RANGE_LIMIT
1640         {0xAC04, 0x40, BYTE_LEN, 0 },   // AWB_PRE_AWB_R2G_RATIO
1641         {0xAC05, 0x48, BYTE_LEN, 0 },   // AWB_PRE_AWB_B2G_RATIO
1642         {0xAC08, 0x7F, BYTE_LEN, 0 },   // AWB_CUR_CCM_POS
1643         {SEQUENCE_END, 0x00, 0, 0}
1644
1645 };
1646 /* Office Colour Temperature : 3500K - 5000K  */
1647 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
1648 {
1649         //[III        Fluorescent]
1650         { 0x098E, 0xACB0, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS [AWB_MIN_ACCEPTED_PRE_AWB_R2G_RATIO]
1651         {0xACB0, 0x44, BYTE_LEN, 0 },   // AWB_RG_MIN
1652         {0xACB1, 0x4B, BYTE_LEN, 0 },   // AWB_RG_MAX
1653         {0xACB4, 0x2C, BYTE_LEN, 0 },   // AWB_BG_MIN
1654         {0xACB5, 0x34, BYTE_LEN, 0 },   // AWB_BG_MAX
1655         {0xACB2, 0x44, BYTE_LEN, 0 },   // AWB_RG_MIN_BRIGHT
1656         {0xACB3, 0x4B, BYTE_LEN, 0 },   // AWB_RG_MAX_BRIGHT
1657         {0xACB6, 0x2C, BYTE_LEN, 0 },   // AWB_BG_MIN_BRIGHT
1658         {0xACB7, 0x34, BYTE_LEN, 0 },   // AWB_BG_MAX_BRIGHT
1659         {0xAC44, 0x40, BYTE_LEN, 0 },   // AWB_LEFT_CCM_POS_RANGE_LIMIT
1660         {0xAC45, 0x4A, BYTE_LEN, 0 },   // AWB_RIGHT_CCM_POS_RANGE_LIMIT
1661         {0xAC04, 0x47, BYTE_LEN, 0 },   // AWB_PRE_AWB_R2G_RATIO
1662         {0xAC05, 0x30, BYTE_LEN, 0 },   // AWB_PRE_AWB_B2G_RATIO
1663         {0xAC08, 0x45, BYTE_LEN, 0 },   // AWB_CUR_CCM_POS
1664         {SEQUENCE_END, 0x00, 0, 0}
1665 };
1666 /* Home Colour Temperature : 2500K - 3500K  */
1667 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
1668 {
1669         //[II.        Incandescent]
1670         { 0x098E, 0xACB0, WORD_LEN, 0},         // LOGICAL_ADDRESS_ACCESS [AWB_MIN_ACCEPTED_PRE_AWB_R2G_RATIO]
1671         {0xACB0, 0x57, BYTE_LEN, 0 },   // AWB_RG_MIN
1672         {0xACB1, 0x5F, BYTE_LEN, 0 },   // AWB_RG_MAX
1673         {0xACB4, 0x26, BYTE_LEN, 0 },   // AWB_BG_MIN
1674         {0xACB5, 0x2E, BYTE_LEN, 0 },   // AWB_BG_MAX
1675         {0xACB2, 0x57, BYTE_LEN, 0 },   // AWB_RG_MIN_BRIGHT
1676         {0xACB3, 0x5F, BYTE_LEN, 0 },   // AWB_RG_MAX_BRIGHT
1677         {0xACB6, 0x26, BYTE_LEN, 0 },   // AWB_BG_MIN_BRIGHT
1678         {0xACB7, 0x2E, BYTE_LEN, 0 },   // AWB_BG_MAX_BRIGHT
1679         {0xAC44, 0x00, BYTE_LEN, 0 },   // AWB_LEFT_CCM_POS_RANGE_LIMIT
1680         {0xAC45, 0x08, BYTE_LEN, 0 },   // AWB_RIGHT_CCM_POS_RANGE_LIMIT
1681         {0xAC04, 0x5B, BYTE_LEN, 0 },   // AWB_PRE_AWB_R2G_RATIO
1682         {0xAC05, 0x2A, BYTE_LEN, 0 },   // AWB_PRE_AWB_B2G_RATIO
1683         {0xAC08, 0x00, BYTE_LEN, 0 },   // AWB_CUR_CCM_POS
1684         {SEQUENCE_END, 0x00, 0, 0}
1685 };
1686 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
1687     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
1688 };
1689 #endif
1690
1691 #if CONFIG_SENSOR_Brightness
1692 static  struct reginfo sensor_Brightness0[]=
1693 {
1694         {SEQUENCE_END, 0x00}
1695 };
1696
1697 static  struct reginfo sensor_Brightness1[]=
1698 {
1699         {SEQUENCE_END, 0x00}
1700 };
1701
1702 static  struct reginfo sensor_Brightness2[]=
1703 {
1704         {SEQUENCE_END, 0x00}
1705 };
1706
1707 static  struct reginfo sensor_Brightness3[]=
1708 {
1709         {SEQUENCE_END, 0x00}
1710 };
1711
1712 static  struct reginfo sensor_Brightness4[]=
1713 {
1714         {SEQUENCE_END, 0x00}
1715 };
1716
1717 static  struct reginfo sensor_Brightness5[]=
1718 {
1719         {SEQUENCE_END, 0x00}
1720 };
1721 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
1722     sensor_Brightness4, sensor_Brightness5,NULL,
1723 };
1724
1725 #endif
1726
1727 #if CONFIG_SENSOR_Effect
1728 static  struct reginfo sensor_Effect_Normal[] =
1729 {
1730         {0x098e,0xdc38, WORD_LEN, 0},
1731         {0xdc38,0x00, BYTE_LEN, 0 },
1732         {0x8404,0x06, BYTE_LEN, 0 },
1733         {SEQUENCE_END, 0x00, 0, 0}
1734 };
1735 #if 0
1736 static  struct reginfo sensor_Effect_WandB[] =
1737 {
1738     {SEQUENCE_END, 0x00, 0, 0}
1739 };
1740 #endif
1741 static  struct reginfo sensor_Effect_Sepia[] =
1742 {
1743         {0x098e,0xdc38, WORD_LEN, 0},
1744         {0xdc38,0x02, BYTE_LEN, 0 },
1745         {0xdc3a,0x10, BYTE_LEN, 0 },
1746         {0xdc3b,0xe0, BYTE_LEN, 0 },
1747         {0x8404,0x06, BYTE_LEN, 0 },
1748         {SEQUENCE_END, 0x00, 0, 0}
1749 };
1750
1751 static  struct reginfo sensor_Effect_Negative[] =
1752 {
1753         {0x098e,0xdc38, WORD_LEN, 0},
1754         {0xdc38,0x03, BYTE_LEN, 0 },
1755         {0x8404,0x06, BYTE_LEN, 0 },
1756         {SEQUENCE_END, 0x00, 0, 0}
1757 };
1758 #if 0
1759 static  struct reginfo sensor_Effect_Bluish[] =
1760 {
1761     {SEQUENCE_END, 0x00, 0, 0}
1762 };
1763
1764 static  struct reginfo sensor_Effect_Green[] =
1765 {
1766     {SEQUENCE_END, 0x00, 0, 0}
1767 };
1768 #endif
1769 static struct reginfo sensor_Effect_Solarize[] =
1770 {
1771         {0x098e,0xdc38, WORD_LEN, 0},
1772         {0xdc38,0x05, BYTE_LEN, 0 },
1773         {0xdc39,0x20, BYTE_LEN, 0 },
1774         {0x8404,0x06, BYTE_LEN, 0 },
1775         {SEQUENCE_END, 0x00, 0, 0}
1776 };
1777 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_Negative,sensor_Effect_Sepia,
1778     sensor_Effect_Solarize,NULL,
1779 };
1780 #endif
1781 #if CONFIG_SENSOR_Exposure
1782 static  struct reginfo sensor_Exposure0[]=
1783 {
1784         {SEQUENCE_END, 0x00}
1785 };
1786
1787 static  struct reginfo sensor_Exposure1[]=
1788 {
1789         {SEQUENCE_END, 0x00}
1790 };
1791
1792 static  struct reginfo sensor_Exposure2[]=
1793 {
1794         {SEQUENCE_END, 0x00}
1795 };
1796
1797 static  struct reginfo sensor_Exposure3[]=
1798 {
1799         {SEQUENCE_END, 0x00}
1800 };
1801
1802 static  struct reginfo sensor_Exposure4[]=
1803 {
1804         {SEQUENCE_END, 0x00}
1805 };
1806
1807 static  struct reginfo sensor_Exposure5[]=
1808 {
1809         {SEQUENCE_END, 0x00}
1810 };
1811
1812 static  struct reginfo sensor_Exposure6[]=
1813 {
1814         {SEQUENCE_END, 0x00}
1815 };
1816
1817 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1818     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1819 };
1820 #endif
1821 #if CONFIG_SENSOR_Saturation
1822 static  struct reginfo sensor_Saturation0[]=
1823 {
1824         {SEQUENCE_END, 0x00}
1825 };
1826
1827 static  struct reginfo sensor_Saturation1[]=
1828 {
1829         {SEQUENCE_END, 0x00}
1830 };
1831
1832 static  struct reginfo sensor_Saturation2[]=
1833 {
1834         {SEQUENCE_END, 0x00}
1835 };
1836 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1837
1838 #endif
1839 #if CONFIG_SENSOR_Contrast
1840 static  struct reginfo sensor_Contrast0[]=
1841 {
1842         {SEQUENCE_END, 0x00}
1843 };
1844
1845 static  struct reginfo sensor_Contrast1[]=
1846 {
1847         {SEQUENCE_END, 0x00}
1848 };
1849
1850 static  struct reginfo sensor_Contrast2[]=
1851 {
1852         {SEQUENCE_END, 0x00}
1853 };
1854
1855 static  struct reginfo sensor_Contrast3[]=
1856 {
1857         {SEQUENCE_END, 0x00}
1858 };
1859
1860 static  struct reginfo sensor_Contrast4[]=
1861 {
1862         {SEQUENCE_END, 0x00}
1863 };
1864
1865
1866 static  struct reginfo sensor_Contrast5[]=
1867 {
1868         {SEQUENCE_END, 0x00}
1869 };
1870
1871 static  struct reginfo sensor_Contrast6[]=
1872 {
1873         {SEQUENCE_END, 0x00}
1874 };
1875 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1876     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1877 };
1878
1879 #endif
1880 #if CONFIG_SENSOR_Mirror
1881 static  struct reginfo sensor_MirrorOn[]=
1882 {
1883     {SEQUENCE_END, 0x00, 0, 0}
1884 };
1885
1886 static  struct reginfo sensor_MirrorOff[]=
1887 {
1888     {SEQUENCE_END, 0x00, 0, 0}
1889 };
1890 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1891 #endif
1892 #if CONFIG_SENSOR_Flip
1893 static  struct reginfo sensor_FlipOn[]=
1894 {
1895     {SEQUENCE_END, 0x00, 0, 0}
1896 };
1897
1898 static  struct reginfo sensor_FlipOff[]=
1899 {
1900     {SEQUENCE_END, 0x00, 0, 0}
1901 };
1902 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1903
1904 #endif
1905
1906 #if CONFIG_SENSOR_Scene
1907 static  struct reginfo sensor_SceneAuto[] =
1908 {
1909     {SEQUENCE_END, 0x00, 0, 0}
1910 };
1911
1912 static  struct reginfo sensor_SceneNight[] =
1913 {
1914     {SEQUENCE_END, 0x00, 0, 0}
1915 };
1916 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1917
1918 #endif
1919
1920 #if CONFIG_SENSOR_DigitalZoom
1921 static struct reginfo sensor_Zoom0[] =
1922 {
1923     {SEQUENCE_END, 0x00, 0, 0}
1924 };
1925
1926 static struct reginfo sensor_Zoom1[] =
1927 {
1928     {SEQUENCE_END, 0x00, 0, 0}
1929 };
1930
1931 static struct reginfo sensor_Zoom2[] =
1932 {
1933     {SEQUENCE_END, 0x00, 0, 0}
1934 };
1935
1936
1937 static struct reginfo sensor_Zoom3[] =
1938 {
1939     {SEQUENCE_END, 0x00, 0, 0}
1940 };
1941 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
1942 #endif
1943 static const struct v4l2_querymenu sensor_menus[] =
1944 {
1945         #if CONFIG_SENSOR_WhiteBalance
1946     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
1947     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
1948     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
1949     #endif
1950
1951         #if CONFIG_SENSOR_Effect
1952     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "negative",  .reserved = 0,},
1953     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "sepia", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "solarize", .reserved = 0,},
1954     #endif
1955
1956         #if CONFIG_SENSOR_Scene
1957     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
1958     #endif
1959
1960         #if CONFIG_SENSOR_Flash
1961     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
1962     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
1963     #endif
1964 };
1965
1966 static  struct v4l2_queryctrl sensor_controls[] =
1967 {
1968         #if CONFIG_SENSOR_WhiteBalance
1969     {
1970         .id             = V4L2_CID_DO_WHITE_BALANCE,
1971         .type           = V4L2_CTRL_TYPE_MENU,
1972         .name           = "White Balance Control",
1973         .minimum        = 0,
1974         .maximum        = 4,
1975         .step           = 1,
1976         .default_value = 0,
1977     },
1978     #endif
1979
1980         #if CONFIG_SENSOR_Brightness
1981         {
1982         .id             = V4L2_CID_BRIGHTNESS,
1983         .type           = V4L2_CTRL_TYPE_INTEGER,
1984         .name           = "Brightness Control",
1985         .minimum        = -3,
1986         .maximum        = 2,
1987         .step           = 1,
1988         .default_value = 0,
1989     },
1990     #endif
1991
1992         #if CONFIG_SENSOR_Effect
1993         {
1994         .id             = V4L2_CID_EFFECT,
1995         .type           = V4L2_CTRL_TYPE_MENU,
1996         .name           = "Effect Control",
1997         .minimum        = 0,
1998         .maximum        = 3,
1999         .step           = 1,
2000         .default_value = 0,
2001     },
2002         #endif
2003
2004         #if CONFIG_SENSOR_Exposure
2005         {
2006         .id             = V4L2_CID_EXPOSURE,
2007         .type           = V4L2_CTRL_TYPE_INTEGER,
2008         .name           = "Exposure Control",
2009         .minimum        = 0,
2010         .maximum        = 6,
2011         .step           = 1,
2012         .default_value = 0,
2013     },
2014         #endif
2015
2016         #if CONFIG_SENSOR_Saturation
2017         {
2018         .id             = V4L2_CID_SATURATION,
2019         .type           = V4L2_CTRL_TYPE_INTEGER,
2020         .name           = "Saturation Control",
2021         .minimum        = 0,
2022         .maximum        = 2,
2023         .step           = 1,
2024         .default_value = 0,
2025     },
2026     #endif
2027
2028         #if CONFIG_SENSOR_Contrast
2029         {
2030         .id             = V4L2_CID_CONTRAST,
2031         .type           = V4L2_CTRL_TYPE_INTEGER,
2032         .name           = "Contrast Control",
2033         .minimum        = -3,
2034         .maximum        = 3,
2035         .step           = 1,
2036         .default_value = 0,
2037     },
2038         #endif
2039
2040         #if CONFIG_SENSOR_Mirror
2041         {
2042         .id             = V4L2_CID_HFLIP,
2043         .type           = V4L2_CTRL_TYPE_BOOLEAN,
2044         .name           = "Mirror Control",
2045         .minimum        = 0,
2046         .maximum        = 1,
2047         .step           = 1,
2048         .default_value = 1,
2049     },
2050     #endif
2051
2052         #if CONFIG_SENSOR_Flip
2053         {
2054         .id             = V4L2_CID_VFLIP,
2055         .type           = V4L2_CTRL_TYPE_BOOLEAN,
2056         .name           = "Flip Control",
2057         .minimum        = 0,
2058         .maximum        = 1,
2059         .step           = 1,
2060         .default_value = 1,
2061     },
2062     #endif
2063
2064         #if CONFIG_SENSOR_Scene
2065     {
2066         .id             = V4L2_CID_SCENE,
2067         .type           = V4L2_CTRL_TYPE_MENU,
2068         .name           = "Scene Control",
2069         .minimum        = 0,
2070         .maximum        = 1,
2071         .step           = 1,
2072         .default_value = 0,
2073     },
2074     #endif
2075
2076         #if CONFIG_SENSOR_DigitalZoom
2077     {
2078         .id             = V4L2_CID_ZOOM_RELATIVE,
2079         .type           = V4L2_CTRL_TYPE_INTEGER,
2080         .name           = "DigitalZoom Control",
2081         .minimum        = -1,
2082         .maximum        = 1,
2083         .step           = 1,
2084         .default_value = 0,
2085     }, {
2086         .id             = V4L2_CID_ZOOM_ABSOLUTE,
2087         .type           = V4L2_CTRL_TYPE_INTEGER,
2088         .name           = "DigitalZoom Control",
2089         .minimum        = 0,
2090         .maximum        = 3,
2091         .step           = 1,
2092         .default_value = 0,
2093     },
2094     #endif
2095
2096         #if CONFIG_SENSOR_Focus
2097         {
2098         .id             = V4L2_CID_FOCUS_RELATIVE,
2099         .type           = V4L2_CTRL_TYPE_INTEGER,
2100         .name           = "Focus Control",
2101         .minimum        = -1,
2102         .maximum        = 1,
2103         .step           = 1,
2104         .default_value = 0,
2105     }, {
2106         .id             = V4L2_CID_FOCUS_ABSOLUTE,
2107         .type           = V4L2_CTRL_TYPE_INTEGER,
2108         .name           = "Focus Control",
2109         .minimum        = 0,
2110         .maximum        = 255,
2111         .step           = 1,
2112         .default_value = 125,
2113     },
2114         {
2115         .id             = V4L2_CID_FOCUS_AUTO,
2116         .type           = V4L2_CTRL_TYPE_BOOLEAN,
2117         .name           = "Focus Control",
2118         .minimum        = 0,
2119         .maximum        = 1,
2120         .step           = 1,
2121         .default_value = 0,
2122     },{
2123         .id             = V4L2_CID_FOCUS_CONTINUOUS,
2124         .type           = V4L2_CTRL_TYPE_BOOLEAN,
2125         .name           = "Focus Control",
2126         .minimum        = 0,
2127         .maximum        = 1,
2128         .step           = 1,
2129         .default_value = 0,
2130     },
2131     #endif
2132
2133         #if CONFIG_SENSOR_Flash
2134         {
2135         .id             = V4L2_CID_FLASH,
2136         .type           = V4L2_CTRL_TYPE_MENU,
2137         .name           = "Flash Control",
2138         .minimum        = 0,
2139         .maximum        = 2,
2140         //.maximum      = 3
2141         .step           = 1,
2142         .default_value = 0,
2143     },
2144         #endif
2145 };
2146
2147 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
2148 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
2149 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
2150 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
2151 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
2152 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
2153 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
2154 static int sensor_resume(struct soc_camera_device *icd);
2155 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
2156 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
2157 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
2158 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
2159 static int sensor_deactivate(struct i2c_client *client);
2160
2161 static struct soc_camera_ops sensor_ops =
2162 {
2163     .suspend                     = sensor_suspend,
2164     .resume                       = sensor_resume,
2165     .set_bus_param              = sensor_set_bus_param,
2166     .query_bus_param    = sensor_query_bus_param,
2167     .controls           = sensor_controls,
2168     .menus                         = sensor_menus,
2169     .num_controls               = ARRAY_SIZE(sensor_controls),
2170     .num_menus          = ARRAY_SIZE(sensor_menus),
2171 };
2172
2173 /* only one fixed colorspace per pixelcode */
2174 struct sensor_datafmt {
2175         enum v4l2_mbus_pixelcode code;
2176         enum v4l2_colorspace colorspace;
2177 };
2178
2179 /* Find a data format by a pixel code in an array */
2180 static const struct sensor_datafmt *sensor_find_datafmt(
2181         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
2182         int n)
2183 {
2184         int i;
2185         for (i = 0; i < n; i++)
2186                 if (fmt[i].code == code)
2187                         return fmt + i;
2188
2189         return NULL;
2190 }
2191
2192 static const struct sensor_datafmt sensor_colour_fmts[] = {
2193     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
2194     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
2195 };
2196 enum sensor_work_state
2197 {
2198         sensor_work_ready = 0,
2199         sensor_working,
2200 };
2201 struct sensor_work
2202 {
2203         struct i2c_client *client;
2204         struct delayed_work dwork;
2205         enum sensor_work_state state;
2206 };
2207
2208 typedef struct sensor_info_priv_s
2209 {
2210     int whiteBalance;
2211     int brightness;
2212     int contrast;
2213     int saturation;
2214     int effect;
2215     int scene;
2216     int digitalzoom;
2217     int focus;
2218         int auto_focus;
2219         int affm_reinit;
2220     int flash;
2221     int exposure;
2222     unsigned char mirror;                                        /* HFLIP */
2223     unsigned char flip;                                          /* VFLIP */
2224         bool snap2preview;
2225         bool video2preview;
2226         int capture_w;
2227         int capture_h;
2228         int preview_w;
2229         int preview_h;
2230     struct reginfo *winseqe_cur_addr;
2231         struct sensor_datafmt fmt;
2232         unsigned int enable;
2233         unsigned int funmodule_state;
2234 } sensor_info_priv_t;
2235
2236
2237
2238 struct sensor_parameter
2239 {
2240         unsigned short int preview_maxlines;
2241         unsigned short int preview_exposure;
2242         unsigned short int preview_line_width;
2243         unsigned short int preview_gain;
2244
2245         unsigned short int capture_framerate;
2246         unsigned short int preview_framerate;
2247 };
2248
2249 struct sensor
2250 {
2251     struct v4l2_subdev subdev;
2252     struct i2c_client *client;
2253     sensor_info_priv_t info_priv;
2254         struct sensor_parameter parameter;
2255         struct workqueue_struct *sensor_wq;
2256         struct sensor_work sensor_wk;
2257         struct mutex wq_lock;
2258     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
2259 #if CONFIG_SENSOR_I2C_NOSCHED
2260         atomic_t tasklock_cnt;
2261 #endif
2262         struct rk29camera_platform_data *sensor_io_request;
2263     struct rk29camera_gpio_res *sensor_gpio_res;
2264 };
2265
2266 static struct sensor* to_sensor(const struct i2c_client *client)
2267 {
2268     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
2269 }
2270
2271 static int sensor_task_lock(struct i2c_client *client, int lock)
2272 {
2273 #if CONFIG_SENSOR_I2C_NOSCHED
2274         int cnt = 3;
2275     struct sensor *sensor = to_sensor(client);
2276
2277         if (lock) {
2278                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
2279                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
2280                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
2281                                 msleep(35);
2282                                 cnt--;
2283                         }
2284                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
2285                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
2286                                 goto sensor_task_lock_err;
2287                         }
2288                         preempt_disable();
2289                 }
2290
2291                 atomic_add(1, &sensor->tasklock_cnt);
2292         } else {
2293                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
2294                         atomic_sub(1, &sensor->tasklock_cnt);
2295
2296                         if (atomic_read(&sensor->tasklock_cnt) == 0)
2297                                 preempt_enable();
2298                 }
2299         }    
2300         return 0;
2301 sensor_task_lock_err:
2302         return -1;    
2303 #else
2304     return 0;
2305 #endif
2306 }
2307 /*sensor register write */
2308 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
2309 {
2310     int err=0,cnt;
2311     u8 buf[4];
2312     struct i2c_msg msg[1];
2313
2314         switch (reg_info->reg)
2315         {
2316                 case SEQUENCE_WAIT_MS:
2317                 {
2318                         if (in_atomic())
2319                                 mdelay(reg_info->val);
2320                         else
2321                                 msleep(reg_info->val);
2322                         break;
2323                 }
2324
2325                 case SEQUENCE_WAIT_US:
2326                 {
2327                         udelay(reg_info->val);
2328                         break;
2329                 }
2330                 case SEQUENCE_PROPERTY:
2331                 {
2332                         break;
2333                 }
2334                 default:
2335                 {
2336                     buf[0] = reg_info->reg >> 8;
2337                     buf[1] = reg_info->reg & 0xFF;
2338                         if (reg_info->reg_len == WORD_LEN) {
2339                                 buf[2] = reg_info->val >> 8;
2340                                 buf[3] = reg_info->val & 0xFF;
2341                                 msg->len = 4;
2342                         } else if (reg_info->reg_len == BYTE_LEN) {
2343                                 buf[2] = reg_info->val;
2344                                 msg->len = 3;
2345                         }
2346                     msg->addr = client->addr;
2347                     msg->flags = client->flags;
2348                     msg->buf = buf;
2349                     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
2350                     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2351                     cnt = 3;
2352                     err = -EAGAIN;
2353                     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2354                         err = i2c_transfer(client->adapter, msg, 1);
2355
2356                         if (err >= 0) {
2357                             return 0;
2358                         } else {
2359                             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg_info->reg, reg_info->val);
2360                             udelay(10);
2361                         }
2362                     }
2363                 }
2364         }
2365     return err;
2366 }
2367
2368 /**
2369  *sensor_write_Multiple_data - sensor register write with Multiple data
2370  * @i2c_client: 
2371  * @reg_info: the first register address
2372  * @count: data number
2373  *
2374  * Returns negative errno, else the number of messages executed.
2375  *
2376  * Note that it 
2377  */
2378 static int sensor_write_Multiple_data(struct i2c_client *client, struct reginfo *reg_info, int count)
2379 {
2380     int err=0,cnt;  
2381     int i=0;
2382     int sum =0;
2383     struct reginfo *tmpval = NULL;
2384     u8 *buf;
2385     struct i2c_msg msg[1];
2386     tmpval = reg_info;
2387     
2388     if(count < 1 || tmpval==NULL||tmpval->reg==0x0000)                         
2389      return -EINVAL;
2390
2391     memset((char*)&msg[0],0,sizeof(struct i2c_msg));   
2392     buf = kmalloc((count*2+10)*sizeof(u8),GFP_KERNEL);
2393     if (buf == NULL) {
2394         SENSOR_TR("%s %s fail,because kmalloc failed",SENSOR_NAME_STRING(),__FUNCTION__);
2395         err = -1;
2396         goto sensor_write_Multiple_data_end;
2397     }
2398     memset(buf,0,sizeof(buf));
2399     
2400         switch (reg_info->reg)
2401         {
2402                 case SEQUENCE_WAIT_MS:
2403                 {
2404                         if (in_atomic())
2405                                 mdelay(reg_info->val);
2406                         else
2407                                 msleep(reg_info->val);
2408                         break;
2409                 }
2410
2411                 case SEQUENCE_WAIT_US:
2412                 {
2413                         udelay(reg_info->val);
2414                         break;
2415                 }
2416
2417                 case SEQUENCE_PROPERTY:
2418                 {
2419                         break;
2420                 }
2421                 default:
2422                 {
2423             
2424                     buf[0] = tmpval->reg >> 8;
2425                     buf[1] = tmpval->reg & 0xFF;
2426             i= 2;    
2427                         if (tmpval->reg_len == WORD_LEN)
2428             {
2429                sum = (count+1)*2;
2430                while(i<sum) 
2431                {
2432                                  buf[i] = tmpval->val >> 8;
2433                                  buf[i+1] = tmpval->val & 0xFF;
2434                  i=i+2;
2435                  tmpval++;
2436                }             
2437                            msg->len = sum;               
2438                         } else if (tmpval->reg_len == BYTE_LEN) {
2439                           sum = count+2;
2440                while(i<sum) 
2441                {
2442                                  buf[i] = tmpval->val;
2443                  i++;
2444                  tmpval++;
2445                }             
2446                            msg->len = sum;               
2447                         }
2448                     msg->addr = client->addr;
2449                     msg->flags = client->flags;
2450                     msg->buf = buf;
2451                     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
2452                     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2453                     cnt = 3;
2454                     err = -EAGAIN;
2455                     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2456                         err = i2c_transfer(client->adapter, msg, 1);
2457                         if (err >= 0) {
2458                             return 0;
2459                         } else {
2460                             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg_info->reg, reg_info->val);
2461                             udelay(10);
2462                         }
2463                     }            
2464                 }                
2465         }
2466 sensor_write_Multiple_data_end:  
2467     if (buf) {
2468         kfree(buf);
2469         buf = NULL;
2470     }
2471     return err;
2472 }
2473
2474 /* sensor register read */
2475 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
2476 {
2477     int err,cnt;
2478     u8 buf[2];
2479     struct i2c_msg msg[2];
2480
2481     buf[0] = reg >> 8;
2482     buf[1] = reg & 0xFF; 
2483
2484     msg[0].addr = client->addr;
2485     msg[0].flags = client->flags;
2486     msg[0].buf = buf;
2487     msg[0].len = sizeof(buf);
2488     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
2489     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2490
2491     msg[1].addr = client->addr;
2492     msg[1].flags = client->flags|I2C_M_RD;
2493     msg[1].buf = buf;
2494     msg[1].len = 2;
2495     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
2496     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
2497
2498     cnt = 3;
2499     err = -EAGAIN;
2500     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
2501         err = i2c_transfer(client->adapter, msg, 2);
2502
2503         if (err >= 0) {
2504             *val = buf[0];
2505             return 0;
2506         } else {
2507                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
2508             udelay(10);
2509         }
2510     }
2511
2512     return err;
2513 }
2514
2515 /* write a array of registers  */
2516 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2517 {
2518     int err = 0, cnt;
2519     int i = 0,j=0;
2520     int num = 0;  
2521     u16 temp = 0;
2522     
2523 #if CONFIG_SENSOR_I2C_RDWRCHK
2524         char valchk;
2525 #endif
2526         cnt = 0;
2527
2528         if (sensor_task_lock(client, 1) < 0)
2529                 goto sensor_write_array_end;
2530     
2531    // SENSOR_TR("%s ..%s..\n",SENSOR_NAME_STRING(),__FUNCTION__);         
2532    
2533     while (regarray[i].reg != SEQUENCE_END) {           
2534        num =1;
2535        j= i+1;      
2536        while((regarray[j].reg_len ==regarray[i].reg_len)&&regarray[j].reg != SEQUENCE_END)
2537        {
2538           temp = regarray[j].reg - regarray[j-1].reg;            
2539           if((regarray[j].reg_len==WORD_LEN && temp!=0x0002)||(regarray[j].reg_len==BYTE_LEN && temp!=0x0001))
2540            break;
2541            num++;
2542            j++;
2543        }         
2544        err = sensor_write_Multiple_data(client, &regarray[i], num) ;            
2545        if (err < 0)
2546         {
2547             if (cnt-- > 0) {
2548                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2549                                 i = 0;
2550                                 continue;
2551             } else {
2552                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2553                 err = -EPERM;
2554                                 goto sensor_write_array_end;
2555             }
2556         } else {
2557         #if CONFIG_SENSOR_I2C_RDWRCHK
2558                         sensor_read(client, regarray[i].reg, &valchk);
2559                         if (valchk != regarray[i].val)
2560                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2561                 #endif
2562         }
2563
2564        i=i+num;
2565     }
2566 sensor_write_array_end:
2567         sensor_task_lock(client,0);
2568     return err;
2569 }
2570
2571 /* write sensor initial data */
2572 static int sensor_write_init_data(struct i2c_client *client, struct reginfo *regarray)
2573 {
2574     int err = 0, cnt;
2575     int i = 0;
2576     int num = 0;
2577 #if CONFIG_SENSOR_I2C_RDWRCHK
2578         char valchk;
2579 #endif
2580     int ti=0;      
2581     int table[167] = {                   /*written data numbers every time*/
2582         3,1,1,3,1,1,1,1,11,2,2,13,1,1,1,2,11,2,2,13,
2583         1,2,1,1,2,1,1,1,1,1,8,1,1,1,1,1,1,714,1,1,
2584         1,1,1,1,1,42,1,3,9,1,1,2,2,1,1,1,1,3,1,1,
2585         1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,8,2,2,2,
2586         2,2,1,1,1,1,10,10,9,6,4,2,9,2,2,2,1,1,1,1,
2587         1,1,1,1,1,1,1,1,58,1,1,1,1,1,1,1,1,1,1,1,
2588         2,2,2,2,2,2,2,2,2,3,3,2,1,1,1,1,1, 2,2,1,
2589         6,3,1,1,1,1,1,6,1,2,4,4,1,1,1,4,5,2,2,4,
2590         4,6,1,1,1,1,1
2591     };
2592     
2593     cnt = 0; 
2594         if (sensor_task_lock(client, 1) < 0)
2595                 goto sensor_write_array_end;
2596    
2597     while (regarray[i].reg != SEQUENCE_END) { 
2598
2599       if(ti < 167){
2600          num = table[ti];
2601          ti++;
2602        }         
2603        err = sensor_write_Multiple_data(client, &regarray[i], num) ;            
2604        if (err < 0)
2605         {
2606             if (cnt-- > 0) {
2607                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2608                                 i = 0;
2609                                 continue;
2610             } else {
2611                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2612                 err = -EPERM;
2613                                 goto sensor_write_array_end;
2614             }
2615         } else {
2616         #if CONFIG_SENSOR_I2C_RDWRCHK
2617                         sensor_read(client, regarray[i].reg, &valchk);
2618                         if (valchk != regarray[i].val)
2619                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2620                 #endif
2621         }
2622        i=i+num;
2623     }
2624 sensor_write_array_end:
2625         sensor_task_lock(client,0);
2626     return err;
2627 }
2628
2629 #if 0
2630 /* write a array of registers  */
2631 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
2632 {
2633     int err = 0, cnt;
2634     int i = 0;
2635 #if CONFIG_SENSOR_I2C_RDWRCHK
2636         char valchk;
2637 #endif
2638         cnt = 0;
2639         if (sensor_task_lock(client, 1) < 0)
2640                 goto sensor_write_array_end;
2641     
2642     while (regarray[i].reg != SEQUENCE_END) {
2643        
2644         err = sensor_write(client, &regarray[i]);
2645         
2646         if (err < 0)
2647         {
2648             if (cnt-- > 0) {
2649                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
2650                                 i = 0;
2651                                 continue;
2652             } else {
2653                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
2654                 err = -EPERM;
2655                                 goto sensor_write_array_end;
2656             }
2657         } else {
2658         #if CONFIG_SENSOR_I2C_RDWRCHK
2659                         sensor_read(client, regarray[i].reg, &valchk);
2660                         if (valchk != regarray[i].val)
2661                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2662                 #endif
2663         }
2664         i++;
2665     }
2666 sensor_write_array_end:
2667         sensor_task_lock(client,0);
2668     return err;
2669 }
2670 #endif
2671 #if CONFIG_SENSOR_I2C_RDWRCHK
2672 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
2673 {
2674     int cnt;
2675     int i = 0;
2676         char valchk;
2677
2678         cnt = 0;
2679         valchk = 0;
2680     while (regarray[i].reg != SEQUENCE_END)
2681     {
2682                 sensor_read(client, regarray[i].reg, &valchk);
2683                 if (valchk != regarray[i].val)
2684                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
2685
2686         i++;
2687     }
2688     return 0;
2689 }
2690 #endif
2691
2692 #if CONFIG_SENSOR_Focus
2693 static struct reginfo sensor_af_init0[] =
2694 {
2695         { 0xC400, 0x88, BYTE_LEN, 0 },  // AFM_ALGO
2696         { 0x8419, 0x05, BYTE_LEN, 0 },  // SEQ_STATE_CFG_1_AF
2697         { 0xC400, 0x08, BYTE_LEN, 0 },  // AFM_ALGO
2698         //AF_settings
2699         { 0xB002, 0x0305, WORD_LEN, 0},         // AF_MODE
2700         { 0xB004, 0x0002, WORD_LEN, 0},         // AF_ALGO
2701
2702         { 0xB008, 0x0003, WORD_LEN, 0},  // AF_ZONE_WEIGHTS_HI
2703         { 0xB00A, 0xFFFF, WORD_LEN, 0},  // AF_ZONE_WEIGHTS_HI
2704         { 0xB00C, 0xFFFF, WORD_LEN, 0},  // AF_ZONE_WEIGHTS_LO
2705         { 0xB00E, 0xFFFF, WORD_LEN, 0},  // AF_ZONE_WEIGHTS_LO
2706     {SEQUENCE_END, 0x00, 0, 0}
2707 };
2708 static struct reginfo sensor_af_init1[] =
2709 {
2710 //set_posMin/Max
2711 { 0xC40A, 0x0028, WORD_LEN, 0 },        // AFM_POS_MIN
2712 { 0xC40C, 0x00BE, WORD_LEN, 0 },        // AFM_POS_MAX
2713 //AF_postition_settings
2714 { 0xB018, 0x00, BYTE_LEN, 0},   // AF_FS_POS_0
2715 { 0xB019, 0x20, BYTE_LEN, 0},   // AF_FS_POS_1
2716 { 0xB01A, 0x40, BYTE_LEN, 0},   // AF_FS_POS_2
2717 { 0xB01B, 0x60, BYTE_LEN, 0},   // AF_FS_POS_3
2718 { 0xB01C, 0x80, BYTE_LEN, 0},   // AF_FS_POS_4
2719 { 0xB01D, 0xA0, BYTE_LEN, 0},   // AF_FS_POS_5
2720 { 0xB01E, 0xC0, BYTE_LEN, 0},   // AF_FS_POS_6
2721 { 0xB01A, 0x38, BYTE_LEN, 0},   // AF_FS_POS_2
2722 { 0xB01B, 0x50, BYTE_LEN, 0},   // AF_FS_POS_3
2723 { 0xB01C, 0x68, BYTE_LEN, 0},   // AF_FS_POS_4
2724 { 0xB01D, 0x80, BYTE_LEN, 0},   // AF_FS_POS_5
2725 { 0xB01E, 0x98, BYTE_LEN, 0},   // AF_FS_POS_6
2726 { 0xB01F, 0xB0, BYTE_LEN, 0},   // AF_FS_POS_7
2727 { 0xB020, 0xC0, BYTE_LEN, 0},   // AF_FS_POS_8
2728 { 0xB012, 0x09, BYTE_LEN, 0},   // AF_FS_NUM_STEPS
2729 //2nd_scan_option
2730 { 0xB013, 0x55, BYTE_LEN, 0},   // AF_FS_NUM_STEPS2
2731 { 0xB014, 0x06, BYTE_LEN, 0},   // AF_FS_STEP_SIZE
2732 { 0x8404, 0x05, BYTE_LEN, 0},   // SEQ_CMD
2733 //{ SEQUENCE_WAIT_MS,300, WORD_LEN, 0},
2734 { SEQUENCE_WAIT_MS,100, WORD_LEN, 0},
2735 //{ 0x3EDA, 0x6060      // DAC_LD_14_15
2736 { 0x0018, 0x2008, WORD_LEN, 0},         // STANDBY_CONTROL_AND_STATUS
2737 //{ SEQUENCE_WAIT_MS,100, WORD_LEN, 0},
2738 { SEQUENCE_WAIT_MS,30, WORD_LEN, 0},
2739 { 0x3EDA, 0x6060, WORD_LEN, 0 },        // DAC_LD_14_15
2740 {SEQUENCE_END, 0x00, 0, 0}
2741 };
2742
2743
2744 static struct reginfo sensor_af_trigger[] =
2745 {
2746         {0x098e,0xb006, WORD_LEN, 0 },
2747         {0xb006,0x01, BYTE_LEN, 0 },
2748     {SEQUENCE_END, 0x00, 0, 0}
2749 };
2750 static int sensor_af_single(struct i2c_client *client)
2751 {
2752         int ret = 0;
2753
2754         ret = sensor_write_array(client, sensor_af_trigger);
2755         if (ret<0)
2756                 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
2757         else
2758                 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
2759 sensor_af_single_end:
2760         return ret;
2761 }
2762
2763 static int sensor_af_const(struct i2c_client *client)
2764 {
2765         int ret = 0;
2766
2767 sensor_af_const_end:
2768         return ret;
2769 }
2770
2771 static int sensor_af_zoneupdate(struct i2c_client *client)
2772 {
2773         int ret = 0;
2774         struct i2c_msg msg[2];
2775     u8 buf[2][6] =
2776         {
2777                 {0xb0,0x08,0x00,0x03,0xff,0xff},
2778                 {0xb0,0x0c,0xff,0xff,0xff,0xff},
2779         };
2780
2781     msg[0].addr = client->addr;
2782     msg[0].flags = client->flags;
2783     msg[0].buf = buf[0];
2784     msg[0].len = sizeof(buf);
2785     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
2786     msg[0].read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2787
2788     msg[1].addr = client->addr;
2789     msg[1].flags = client->flags;
2790     msg[1].buf = buf[1];
2791     msg[1].len = sizeof(buf);
2792     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
2793     msg[1].read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
2794
2795     ret = i2c_transfer(client->adapter, &msg[0], 1);
2796         ret |= i2c_transfer(client->adapter, &msg[1], 1);
2797     if (ret >= 0) {
2798         return 0;
2799     } else {
2800         SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
2801     }
2802
2803 sensor_af_zoneupdate_end:
2804         return ret;
2805 }
2806
2807 static int sensor_af_init(struct i2c_client *client)
2808 {
2809         int ret = 0;
2810
2811         ret = sensor_write_array(client, sensor_af_init0);
2812         if (ret<0) {
2813                 SENSOR_DG("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
2814         } else {
2815             SENSOR_DG("%s sensor auto focus init_0 sucess!!",SENSOR_NAME_STRING());
2816                 if (sensor_af_zoneupdate(client) == 0) {
2817                         ret = sensor_write_array(client, sensor_af_init1);
2818                         if (ret<0) {
2819                                 SENSOR_DG("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
2820                         }else{
2821                                 SENSOR_DG("%s sensor auto focus init_1 success!!",SENSOR_NAME_STRING());
2822             }
2823                 }
2824         }
2825
2826         return ret;
2827 }
2828 #endif
2829
2830 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
2831 {
2832         struct soc_camera_link *icl = to_soc_camera_link(icd);
2833         int ret = 0;
2834
2835     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
2836         switch (cmd)
2837         {
2838                 case Sensor_PowerDown:
2839                 {
2840                         if (icl->powerdown) {
2841                                 ret = icl->powerdown(icd->pdev, on);
2842                                 if (ret == RK29_CAM_IO_SUCCESS) {
2843                                         if (on == 0) {
2844                                                 mdelay(2);
2845                                                 if (icl->reset)
2846                                                         icl->reset(icd->pdev);
2847                                         }
2848                                 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
2849                                         ret = -ENODEV;
2850                                         goto sensor_power_end;
2851                                 }
2852                         }
2853                         break;
2854                 }
2855                 case Sensor_Flash:
2856                 {
2857                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2858                 struct sensor *sensor = to_sensor(client);
2859
2860                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
2861                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
2862                 if(on){
2863                     //flash off after 2 secs
2864                         hrtimer_cancel(&(flash_off_timer.timer));
2865                         hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
2866                     }
2867                         }
2868                         break;
2869                 }
2870                 default:
2871                 {
2872                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2873                         break;
2874                 }
2875         }
2876
2877 sensor_power_end:
2878         return ret;
2879 }
2880
2881 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
2882         struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
2883     sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
2884         SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
2885     return 0;
2886     
2887 }
2888
2889 static int sensor_init(struct v4l2_subdev *sd, u32 val)
2890 {
2891     struct i2c_client *client = v4l2_get_subdevdata(sd);
2892     struct soc_camera_device *icd = client->dev.platform_data;
2893     struct sensor *sensor = to_sensor(client);
2894 #if (ADJUST_OPTIMIZE_TIME_FALG == 0)
2895         const struct v4l2_queryctrl *qctrl;
2896 #endif
2897     const struct sensor_datafmt *fmt;
2898     int ret,pid = 0;
2899     int index  =0 ;
2900 #if (SENSOR_RESET_REG != SEQUENCE_END)
2901     struct reginfo reg_info;
2902 #endif
2903
2904     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
2905
2906         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2907                 ret = -ENODEV;
2908                 goto sensor_INIT_ERR;
2909         }
2910     
2911     SENSOR_DG("\n soft reset..%s.\n",SENSOR_NAME_STRING());
2912
2913     /* soft reset */
2914         if (sensor_task_lock(client,1)<0)
2915                 goto sensor_INIT_ERR;
2916
2917 #if (SENSOR_RESET_REG != SEQUENCE_END)
2918         reg_info.reg = SENSOR_RESET_REG;
2919         reg_info.val = SENSOR_RESET_VAL;
2920         reg_info.reg_len = SENSOR_RESET_REG_LEN;
2921     ret = sensor_write(client, &reg_info);
2922     if (ret != 0) {
2923         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2924         ret = -ENODEV;
2925                 goto sensor_INIT_ERR;
2926     }
2927     mdelay(5);     //delay 5 microseconds
2928 #endif
2929
2930         /* check if it is an sensor sensor */
2931 #if (SENSOR_ID_REG != SEQUENCE_END)
2932     ret = sensor_read(client, SENSOR_ID_REG, &pid);
2933     if (ret != 0) {
2934         SENSOR_TR("read chip id failed\n");
2935         ret = -ENODEV;
2936         goto sensor_INIT_ERR;
2937     }
2938     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2939 #else
2940         pid = SENSOR_ID;
2941 #endif
2942
2943     if (pid == SENSOR_ID) {
2944         sensor->model = SENSOR_V4L2_IDENT;
2945     } else {
2946         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2947         ret = -ENODEV;
2948         goto sensor_INIT_ERR;
2949     }
2950     
2951     SENSOR_DG("\n sensor_init_data..%s.\n",SENSOR_NAME_STRING());
2952  
2953     ret =sensor_write_init_data(client, sensor_init_data);
2954     if (ret != 0) {
2955         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
2956         goto sensor_INIT_ERR;
2957     }
2958         sensor_task_lock(client,0);
2959     sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
2960     sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
2961     sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
2962     sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
2963     sensor->info_priv.winseqe_cur_addr  = SENSOR_INIT_WINSEQADR;
2964         fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
2965     if (!fmt) {
2966         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
2967         ret = -EINVAL;
2968         goto sensor_INIT_ERR;
2969     }
2970         sensor->info_priv.fmt = *fmt;
2971
2972     /* sensor sensor information for initialization  */
2973 #if ADJUST_OPTIMIZE_TIME_FALG   
2974     SENSOR_DG("\n optimize code..%s.\n",SENSOR_NAME_STRING());
2975         #if CONFIG_SENSOR_WhiteBalance
2976       sensor->info_priv.whiteBalance = 0;
2977     #endif    
2978         #if CONFIG_SENSOR_Brightness
2979       sensor->info_priv.brightness = 0;
2980     #endif
2981         #if CONFIG_SENSOR_Effect
2982         sensor->info_priv.effect = 0;
2983     #endif
2984         #if CONFIG_SENSOR_Exposure
2985         sensor->info_priv.exposure = 0;
2986     #endif
2987         #if CONFIG_SENSOR_Saturation
2988         sensor->info_priv.saturation = 0;
2989     #endif
2990         #if CONFIG_SENSOR_Contrast
2991         sensor->info_priv.contrast = 0;
2992     #endif        
2993         #if CONFIG_SENSOR_Mirror
2994         sensor->info_priv.mirror = 1;
2995     #endif
2996         #if CONFIG_SENSOR_Flip
2997         sensor->info_priv.flip = 1;
2998         index++;        
2999     #endif        
3000         #if CONFIG_SENSOR_Scene
3001         sensor->info_priv.scene = 0;
3002         index++;        
3003     #endif
3004         #if CONFIG_SENSOR_DigitalZoom
3005         sensor->info_priv.digitalzoom = 0;
3006     #endif        
3007         #if CONFIG_SENSOR_Focus
3008         sensor->info_priv.focus = 125  ;
3009         if (sensor_af_init(client) < 0) {
3010                 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
3011                 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
3012             } else {
3013                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
3014                 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
3015             }
3016     #endif    
3017         #if CONFIG_SENSOR_Flash
3018         sensor->info_priv.flash = 0 ;    
3019     #endif
3020     
3021 #else
3022     SENSOR_DG("\n origin code..%s.\n",SENSOR_NAME_STRING());
3023
3024         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
3025         if (qctrl)
3026         sensor->info_priv.whiteBalance = qctrl->default_value;
3027     
3028         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
3029         if (qctrl)
3030         sensor->info_priv.brightness = qctrl->default_value;
3031     
3032         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
3033         if (qctrl)
3034         sensor->info_priv.effect = qctrl->default_value;
3035     
3036         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
3037         if (qctrl)
3038         sensor->info_priv.exposure = qctrl->default_value;
3039
3040         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
3041         if (qctrl)
3042         sensor->info_priv.saturation = qctrl->default_value;
3043     
3044         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
3045         if (qctrl)
3046         sensor->info_priv.contrast = qctrl->default_value;
3047     
3048         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
3049         if (qctrl)
3050         sensor->info_priv.mirror = qctrl->default_value;
3051     
3052         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
3053         if (qctrl)
3054         sensor->info_priv.flip = qctrl->default_value;
3055     
3056         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
3057         if (qctrl)
3058         sensor->info_priv.scene = qctrl->default_value;
3059     
3060         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3061         if (qctrl)
3062         sensor->info_priv.digitalzoom = qctrl->default_value;
3063
3064     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
3065         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
3066         if (qctrl)
3067         sensor->info_priv.focus = qctrl->default_value;
3068    
3069         #if CONFIG_SENSOR_Focus
3070         if (sensor_af_init(client) < 0) {
3071                 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
3072                 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
3073         } else {
3074                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
3075                 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
3076         }
3077         #endif
3078         #if CONFIG_SENSOR_Flash
3079         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
3080         if (qctrl)
3081         sensor->info_priv.flash = qctrl->default_value;
3082
3083         hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3084     flash_off_timer.icd = icd;
3085         flash_off_timer.timer.function = flash_off_func;
3086     #endif
3087 #endif      
3088     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);
3089     sensor->info_priv.funmodule_state |= SENSOR_INIT_IS_OK;
3090     return 0;
3091 sensor_INIT_ERR:
3092     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
3093         sensor_task_lock(client,0);
3094         sensor_deactivate(client);
3095     return ret;
3096 }
3097 static int sensor_deactivate(struct i2c_client *client)
3098 {
3099         struct soc_camera_device *icd = client->dev.platform_data;
3100     struct sensor *sensor = to_sensor(client);
3101
3102         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
3103
3104         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
3105
3106
3107         sensor_ioctrl(icd, Sensor_PowerDown, 1);
3108     msleep(100);
3109
3110         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
3111         icd->user_width = SENSOR_INIT_WIDTH;
3112     icd->user_height = SENSOR_INIT_HEIGHT;
3113     sensor->info_priv.funmodule_state &= ~SENSOR_INIT_IS_OK;
3114
3115         return 0;
3116 }
3117 static  struct reginfo sensor_power_down_sequence[]=
3118 {
3119     {0x00,0x00}
3120 };
3121 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
3122 {
3123     int ret;
3124     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3125
3126     if (pm_msg.event == PM_EVENT_SUSPEND) {
3127         SENSOR_DG("\n %s Enter Suspend..pm_msg.event=%d \n", SENSOR_NAME_STRING(),pm_msg.event);
3128         ret = sensor_write_array(client, sensor_power_down_sequence) ;
3129         if (ret != 0) {
3130             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
3131             return ret;
3132         } else {
3133             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
3134             if (ret < 0) {
3135                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
3136                 return -EINVAL;
3137             }
3138         }
3139     } else {
3140         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
3141         return -EINVAL;
3142     }
3143
3144     return 0;
3145 }
3146
3147 static int sensor_resume(struct soc_camera_device *icd)
3148 {
3149         int ret;
3150
3151     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
3152     if (ret < 0) {
3153                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
3154         return -EINVAL;
3155     }
3156
3157         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
3158         return 0;
3159 }
3160
3161 static int sensor_set_bus_param(struct soc_camera_device *icd,
3162                                 unsigned long flags)
3163 {
3164
3165     return 0;
3166 }
3167
3168 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
3169 {
3170     struct soc_camera_link *icl = to_soc_camera_link(icd);
3171     unsigned long flags = SENSOR_BUS_PARAM;
3172
3173     return soc_camera_apply_sensor_flags(icl, flags);
3174 }
3175
3176 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3177 {
3178     struct i2c_client *client = v4l2_get_subdevdata(sd);
3179     struct soc_camera_device *icd = client->dev.platform_data;
3180     struct sensor *sensor = to_sensor(client);
3181
3182     mf->width   = icd->user_width;
3183         mf->height      = icd->user_height;
3184         mf->code        = sensor->info_priv.fmt.code;
3185         mf->colorspace  = sensor->info_priv.fmt.colorspace;
3186         mf->field       = V4L2_FIELD_NONE;
3187
3188     return 0;
3189 }
3190 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3191 {
3192     bool ret = false;
3193
3194         if ((mf->width == 1024) && (mf->height == 768)) {
3195                 ret = true;
3196         } else if ((mf->width == 1280) && (mf->height == 1024)) {
3197                 ret = true;
3198         } else if ((mf->width == 1600) && (mf->height == 1200)) {
3199                 ret = true;
3200         } else if ((mf->width == 2048) && (mf->height == 1536)) {
3201                 ret = true;
3202         } else if ((mf->width == 2592) && (mf->height == 1944)) {
3203                 ret = true;
3204         }
3205
3206         if (ret == true)
3207                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
3208         return ret;
3209 }
3210
3211 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3212 {
3213     bool ret = false;
3214
3215         if ((mf->width == 1280) && (mf->height == 720)) {
3216                 ret = true;
3217         } else if ((mf->width == 1920) && (mf->height == 1080)) {
3218                 ret = true;
3219         }
3220
3221         if (ret == true)
3222                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
3223         return ret;
3224 }
3225 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
3226 {
3227         struct reginfo *winseqe_set_addr = NULL;
3228     
3229     if (set_w*240 == set_h*320) {        
3230         if (((set_w >= 320) && (set_h >= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
3231             winseqe_set_addr = sensor_qvga;
3232             *ret_w = 320;
3233             *ret_h = 240;
3234         } 
3235
3236 #if  ADJUST_FOR_VGA_FALG    
3237         // to forbid preview err         
3238         if (((set_w >= 576) && (set_h >= 432)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
3239             winseqe_set_addr = sensor_vga;
3240             *ret_w = 576;
3241             *ret_h = 432;
3242         } 
3243 #else
3244         if (((set_w >= 640) && (set_h >= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
3245             winseqe_set_addr = sensor_vga;
3246             *ret_w = 640;
3247             *ret_h = 480;
3248         } 
3249
3250 #endif
3251               
3252         if (((set_w >= 800) && (set_h >= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
3253             winseqe_set_addr = sensor_svga;
3254             *ret_w = 800;
3255             *ret_h = 600;
3256         } 
3257
3258         if (((set_w >= 1024) && (set_h >= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
3259             winseqe_set_addr = sensor_xga;
3260             *ret_w = 1024;
3261             *ret_h = 768;
3262         } 
3263       
3264         if (((set_w >= 1280) && (set_h >= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
3265             winseqe_set_addr = sensor_sxga;
3266             *ret_w = 1280;
3267             *ret_h = 1024;
3268         }         
3269
3270         if (((set_w >= 1600) && (set_h >= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
3271             winseqe_set_addr = sensor_uxga;
3272             *ret_w = 1600;
3273             *ret_h = 1200;
3274         } 
3275
3276         if (((set_w >= 2048) && (set_h >= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
3277             winseqe_set_addr = sensor_qxga;
3278             *ret_w = 2048;
3279             *ret_h = 1536;
3280         } 
3281
3282         if (((set_w >= 2592) && (set_h >= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
3283             winseqe_set_addr = sensor_qsxga;
3284             *ret_w = 2592;
3285             *ret_h = 1944;
3286         }
3287
3288         if (winseqe_set_addr == NULL) {
3289             if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
3290                         winseqe_set_addr = sensor_qcif;
3291                 *ret_w = 176;
3292                 *ret_h = 144;
3293                 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
3294                 winseqe_set_addr = sensor_cif;
3295                 *ret_w = 352;
3296                 *ret_h = 288;
3297             }
3298
3299             if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
3300                 winseqe_set_addr = sensor_720p;
3301                 *ret_w = 1280;
3302                 *ret_h = 720;
3303             } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
3304                 winseqe_set_addr = sensor_1080p;
3305                 *ret_w = 1920;
3306                 *ret_h = 1080;
3307             } 
3308         }
3309
3310     } else if (set_w*288 == set_h*352) {
3311         if (((set_w >= 176) && (set_h >= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
3312                 winseqe_set_addr = sensor_qcif;
3313             *ret_w = 176;
3314             *ret_h = 144;
3315         } else if (((set_w >= 352) && (set_h >= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
3316             winseqe_set_addr = sensor_cif;
3317             *ret_w = 352;
3318             *ret_h = 288;
3319         }
3320
3321         if (winseqe_set_addr == NULL) {
3322             if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
3323                 winseqe_set_addr = sensor_qvga;
3324                 *ret_w = 320;
3325                 *ret_h = 240;
3326                 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
3327                 winseqe_set_addr = sensor_vga;
3328                 *ret_w = 640;
3329                 *ret_h = 480;
3330             } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
3331                 winseqe_set_addr = sensor_svga;
3332                 *ret_w = 800;
3333                 *ret_h = 600;
3334             } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
3335                 winseqe_set_addr = sensor_xga;
3336                 *ret_w = 1024;
3337                 *ret_h = 768;
3338                 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
3339                 winseqe_set_addr = sensor_sxga;
3340                 *ret_w = 1280;
3341                 *ret_h = 1024;
3342             } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
3343                 winseqe_set_addr = sensor_uxga;
3344                 *ret_w = 1600;
3345                 *ret_h = 1200;
3346                 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
3347                 winseqe_set_addr = sensor_qxga;
3348                 *ret_w = 2048;
3349                 *ret_h = 1536;
3350             } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
3351                 winseqe_set_addr = sensor_qsxga;
3352                 *ret_w = 2592;
3353                 *ret_h = 1944;
3354             }        
3355
3356
3357             if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
3358                 winseqe_set_addr = sensor_720p;
3359                 *ret_w = 1280;
3360                 *ret_h = 720;
3361             } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
3362                 winseqe_set_addr = sensor_1080p;
3363                 *ret_w = 1920;
3364                 *ret_h = 1080;
3365             }  
3366         }
3367     } else if (set_w*720 == set_h*1280) {
3368         if (((set_w >= 1280) && (set_h >= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
3369             winseqe_set_addr = sensor_720p;
3370             *ret_w = 1280;
3371             *ret_h = 720;
3372         } else if (((set_w >= 1920) && (set_h >= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
3373             winseqe_set_addr = sensor_1080p;
3374             *ret_w = 1920;
3375             *ret_h = 1080;
3376         }
3377
3378         if (winseqe_set_addr == NULL) {
3379     
3380             if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
3381                         winseqe_set_addr = sensor_qcif;
3382                 *ret_w = 176;
3383                 *ret_h = 144;
3384                 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
3385                 winseqe_set_addr = sensor_cif;
3386                 *ret_w = 352;
3387                 *ret_h = 288;
3388             }
3389         
3390             if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
3391                 winseqe_set_addr = sensor_qvga;
3392                 *ret_w = 320;
3393                 *ret_h = 240;
3394                 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
3395                 winseqe_set_addr = sensor_vga;
3396                 *ret_w = 640;
3397                 *ret_h = 480;
3398             } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
3399                 winseqe_set_addr = sensor_svga;
3400                 *ret_w = 800;
3401                 *ret_h = 600;
3402             } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
3403                 winseqe_set_addr = sensor_xga;
3404                 *ret_w = 1024;
3405                 *ret_h = 768;
3406                 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
3407                 winseqe_set_addr = sensor_sxga;
3408                 *ret_w = 1280;
3409                 *ret_h = 1024;
3410             } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
3411                 winseqe_set_addr = sensor_uxga;
3412                 *ret_w = 1600;
3413                 *ret_h = 1200;
3414                 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
3415                 winseqe_set_addr = sensor_qxga;
3416                 *ret_w = 2048;
3417                 *ret_h = 1536;
3418             } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
3419                 winseqe_set_addr = sensor_qsxga;
3420                 *ret_w = 2592;
3421                 *ret_h = 1944;
3422             } 
3423         }
3424     } else {
3425         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
3426                 winseqe_set_addr = sensor_qcif;
3427             *ret_w = 176;
3428             *ret_h = 144;
3429         } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
3430             winseqe_set_addr = sensor_qvga;
3431             *ret_w = 320;
3432             *ret_h = 240;
3433         } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
3434             winseqe_set_addr = sensor_cif;
3435             *ret_w = 352;
3436             *ret_h = 288;
3437         } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
3438             winseqe_set_addr = sensor_vga;
3439             *ret_w = 640;
3440             *ret_h = 480;
3441         } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
3442             winseqe_set_addr = sensor_svga;
3443             *ret_w = 800;
3444             *ret_h = 600;
3445         } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
3446             winseqe_set_addr = sensor_xga;
3447             *ret_w = 1024;
3448             *ret_h = 768;
3449         } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
3450             winseqe_set_addr = sensor_720p;
3451             *ret_w = 1280;
3452             *ret_h = 720;
3453         } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
3454             winseqe_set_addr = sensor_sxga;
3455             *ret_w = 1280;
3456             *ret_h = 1024;
3457         } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
3458             winseqe_set_addr = sensor_uxga;
3459             *ret_w = 1600;
3460             *ret_h = 1200;
3461         } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
3462             winseqe_set_addr = sensor_1080p;
3463             *ret_w = 1920;
3464             *ret_h = 1080;
3465         } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
3466             winseqe_set_addr = sensor_qxga;
3467             *ret_w = 2048;
3468             *ret_h = 1536;
3469         } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
3470             winseqe_set_addr = sensor_qsxga;
3471             *ret_w = 2592;
3472             *ret_h = 1944;
3473         }        
3474     }
3475     
3476         return winseqe_set_addr;
3477 }
3478
3479 /*modify image with resolution 2592*1944;solve bug that the first 32 pixel data*/
3480 /*in the first line have misplace with the last 32 pixel data in the last line*/
3481 static int sensor_cb(void *arg)
3482 {
3483    void __iomem *vbpmem;
3484    struct videobuf_buffer *buffer;
3485    char *imagey_addr =NULL;
3486    char *imageuv_addr = NULL;
3487    char *tempaddr = NULL;
3488    int  tempsize = 0;
3489    
3490    buffer = (struct videobuf_buffer*)arg; 
3491    if(buffer->width!=SENSOR_MAX_WIDTH||buffer->height!=SENSOR_MAX_HEIGHT||buffer==NULL)
3492     return -EINVAL;
3493  
3494    if (buffer->bsize< YUV420_BUFFER_MAX_SIZE)        //yuv420 format size
3495     return -EINVAL;
3496
3497    
3498    vbpmem = ioremap(buffer->boff,buffer->bsize);
3499    if(vbpmem == NULL) {
3500       SENSOR_DG("\n%s..%s..ioremap fail\n",__FUNCTION__,SENSOR_NAME_STRING());
3501       return -ENXIO;
3502    }
3503      
3504    imagey_addr = (char*)vbpmem;         // y data  to be dealed with
3505    imageuv_addr = imagey_addr+buffer->width*buffer->height;
3506    
3507    tempaddr =  imageuv_addr - 32;  
3508    memcpy(tempaddr,imagey_addr,32);
3509
3510    tempaddr = imagey_addr+32;
3511    memcpy(imagey_addr,tempaddr,32);
3512
3513                                       //uv data to be dealed with
3514    tempsize  = YUV420_BUFFER_MAX_SIZE-32;                              
3515    tempaddr = imagey_addr+tempsize;
3516    memcpy(tempaddr,imageuv_addr,32);
3517
3518    tempaddr = imageuv_addr+32;
3519    memcpy(imageuv_addr,tempaddr,32);
3520    return 0;
3521 }
3522
3523
3524 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3525 {
3526     struct i2c_client *client = v4l2_get_subdevdata(sd);
3527     struct soc_camera_device *icd = client->dev.platform_data;
3528     struct sensor *sensor = to_sensor(client);
3529     const struct sensor_datafmt *fmt;
3530     struct reginfo *winseqe_set_addr=NULL;
3531     int ret = 0, set_w,set_h,cnt;
3532     u16 seq_state=0;
3533     int time = 0;
3534     u16 targetbrightness,realbrightness;
3535     
3536     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3537
3538         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
3539                                    ARRAY_SIZE(sensor_colour_fmts));
3540         if (!fmt) {
3541         ret = -EINVAL;
3542         goto sensor_s_fmt_end;
3543     }
3544
3545         if (sensor->info_priv.fmt.code != mf->code) {
3546                 switch (mf->code)
3547                 {
3548                         case V4L2_MBUS_FMT_YUYV8_2X8:
3549                         {
3550                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
3551                                 break;
3552                         }
3553                         case V4L2_MBUS_FMT_UYVY8_2X8:
3554                         {
3555                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
3556                                 break;
3557                         }
3558                         default:
3559                                 break;
3560                 }
3561                 if (winseqe_set_addr != NULL) {
3562             sensor_write_array(client, winseqe_set_addr);
3563                         sensor->info_priv.fmt.code = mf->code;
3564             sensor->info_priv.fmt.colorspace= mf->colorspace;            
3565                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
3566                 } else {
3567                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
3568                 }
3569         }
3570
3571     set_w = mf->width;
3572     set_h = mf->height;
3573
3574         winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
3575
3576     if ((winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr)
3577     { 
3578        /*solve bug that video set is ineffective */
3579        /*set five times to make sure sensor_720p set go into effect*/
3580         if(winseqe_set_addr==sensor_720p)
3581         {
3582           time = 5;
3583         }else{
3584           time = 1;
3585         }
3586         
3587         while(time > 0)
3588         {
3589            time--;
3590            ret |= sensor_write_array(client, winseqe_set_addr);
3591            if (ret != 0) {
3592                 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
3593                 goto sensor_s_fmt_end;
3594            }
3595            udelay(10);
3596         }
3597         sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
3598                 if (winseqe_set_addr==sensor_qxga ||winseqe_set_addr==sensor_qsxga||winseqe_set_addr==sensor_uxga ||winseqe_set_addr==sensor_xga)
3599         {
3600                 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
3601                 } else {
3602                         SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
3603                         sensor->info_priv.preview_w = mf->width;
3604                         sensor->info_priv.preview_h = mf->height;
3605                 }
3606     }
3607
3608         if (winseqe_set_addr && (winseqe_set_addr==sensor_qxga ||winseqe_set_addr==sensor_qsxga||winseqe_set_addr==sensor_uxga ||winseqe_set_addr==sensor_xga)) 
3609      {
3610                 ret |= sensor_write_array(client, sensor_Preview2Capture);      
3611                 if (ret != 0) {
3612                 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
3613                 goto sensor_s_fmt_end;
3614         }
3615
3616       /*check state of register 0x8405 to make sure set is successful*/
3617       /*set sensor_Preview2Capture more times to make sure set go into effect */
3618         cnt = 0;
3619         time  =0;
3620         do{                      
3621             ret =  0;
3622             msleep(50);   
3623             ret =sensor_read(client,0x8405, &seq_state);
3624             if (ret < 0)
3625               goto sensor_s_fmt_end;
3626             cnt++;
3627             if(cnt > 9)
3628             {
3629                 time++;
3630                 cnt = 0;
3631                         ret |= sensor_write_array(client, sensor_Preview2Capture);      
3632                         if (ret != 0||time >2) {
3633                         SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
3634                         goto sensor_s_fmt_end;
3635                 }
3636                 SENSOR_DG("mt9p111 Preview 2 Capture again\n");
3637             }
3638             SENSOR_DG("mt9p111 Preview 2 Capture count = %d;seq_state = 0x%x\n",cnt,seq_state);
3639          } while((seq_state != 0x07) && (time < 4));
3640
3641        SENSOR_TR("%s Preview 2 Capture successs\n", SENSOR_NAME_STRING());
3642
3643       #if CONFIG_SENSOR_Flash
3644        /*The 0xA409 is AE target register address.*/
3645        /*The 0xB804 is currently total brightness Y value of sensor.*/
3646        targetbrightness = 0;
3647        realbrightness =0;
3648        if((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2))
3649        {
3650           if(sensor->info_priv.flash == 1)
3651           {
3652             ret =sensor_read(client,0xA409, &targetbrightness);
3653             if (ret < 0)
3654               SENSOR_DG("%s ..%s..get targetbrightness fail\n", SENSOR_NAME_STRING(),__FUNCTION__);
3655             
3656             ret =sensor_read(client, 0xB804, &realbrightness);
3657             if (ret < 0)
3658               SENSOR_DG("%s ..%s..get realbrightness fail\n", SENSOR_NAME_STRING(),__FUNCTION__);
3659           }
3660          
3661           if((realbrightness < targetbrightness)|| (sensor->info_priv.flash == 2))
3662           {
3663             sensor_ioctrl(icd, Sensor_Flash, Flash_On);
3664             SENSOR_DG("%s flash on,realbrightness=%d,targetbrightness=%d\n", SENSOR_NAME_STRING(),realbrightness,targetbrightness);
3665           }else{
3666             SENSOR_DG("%s not need to flash in capture!\n", SENSOR_NAME_STRING());
3667           }
3668         }
3669       #endif        
3670                 sensor->info_priv.capture_w = set_w;
3671                 sensor->info_priv.capture_h = set_h;
3672                 sensor->info_priv.snap2preview = true;
3673         } else if (sensor->info_priv.snap2preview == true) {
3674                 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
3675                         ret |= sensor_write_array(client, sensor_Capture2Preview);
3676                         if (ret != 0) {
3677                         SENSOR_TR("%s Capture 2 Preview success\n", SENSOR_NAME_STRING());
3678                         goto sensor_s_fmt_end;
3679                 }
3680             
3681             cnt = 0;
3682             do{                                    //check state of register 0x8405 to make sure set is successful
3683                 ret =  0;
3684                 msleep(50);   
3685                 ret =sensor_read(client,0x8405, &seq_state);
3686                 if (ret < 0)
3687                   goto sensor_s_fmt_end;
3688                 SENSOR_DG("mt9p111 Capture 2 Preview seq_state = 0x%x\n",seq_state);
3689               } while((seq_state != 0x03) && (cnt < 20));
3690             
3691             SENSOR_TR("%s Capture 2 Preview success\n", SENSOR_NAME_STRING());
3692
3693             #if CONFIG_SENSOR_Flash
3694             if ((sensor->info_priv.flash == 1) || (sensor->info_priv.flash == 2)) {
3695                 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
3696                 SENSOR_DG("%s flash off in preivew!\n", SENSOR_NAME_STRING());
3697             }
3698             #endif        
3699                 sensor->info_priv.preview_w = mf->width;
3700                 sensor->info_priv.preview_h = mf->height;
3701                 sensor->info_priv.snap2preview = false;
3702                 } else {
3703                         SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
3704                 }
3705         }
3706
3707         mf->width = set_w;
3708         mf->height = set_h;
3709 sensor_s_fmt_end:
3710     return ret;
3711 }
3712
3713 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
3714 {
3715     struct i2c_client *client = v4l2_get_subdevdata(sd);
3716     struct sensor *sensor = to_sensor(client);
3717     const struct sensor_datafmt *fmt;
3718     int ret = 0;
3719    
3720         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
3721                                    ARRAY_SIZE(sensor_colour_fmts));
3722         if (fmt == NULL) {
3723                 fmt = &sensor->info_priv.fmt;
3724         mf->code = fmt->code;
3725         } 
3726
3727     if (mf->height > SENSOR_MAX_HEIGHT)
3728         mf->height = SENSOR_MAX_HEIGHT;
3729     else if (mf->height < SENSOR_MIN_HEIGHT)
3730         mf->height = SENSOR_MIN_HEIGHT;
3731
3732     if (mf->width > SENSOR_MAX_WIDTH)
3733         mf->width = SENSOR_MAX_WIDTH;
3734     else if (mf->width < SENSOR_MIN_WIDTH)
3735         mf->width = SENSOR_MIN_WIDTH;
3736     if (sensor_fmt_catch(mf->width, mf->height, &mf->width, &mf->height) == NULL) {
3737                 mf->width = 0;
3738                 mf->height = 0;
3739         }
3740     mf->colorspace = fmt->colorspace;
3741     
3742     return ret;
3743 }
3744  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
3745 {
3746     struct i2c_client *client = v4l2_get_subdevdata(sd);
3747
3748     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
3749         return -EINVAL;
3750
3751     if (id->match.addr != client->addr)
3752         return -ENODEV;
3753
3754     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
3755     id->revision = 0;
3756
3757     return 0;
3758 }
3759 #if CONFIG_SENSOR_Brightness
3760 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3761 {
3762     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3763
3764     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3765     {
3766         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
3767         {
3768             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
3769             {
3770                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3771                 return -EINVAL;
3772             }
3773             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3774             return 0;
3775         }
3776     }
3777         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3778     return -EINVAL;
3779 }
3780 #endif
3781 #if CONFIG_SENSOR_Effect
3782 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3783 {
3784     int time =5;
3785     int ret =0 ;
3786     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3787
3788     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3789     {
3790         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
3791         {
3792            /*set five times to make sure the set go into effect*/
3793            /*solve bug for setting invalidate during changing from preview to video*/
3794             while(time >0)
3795             {
3796                 time--;
3797                 ret |=sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]);
3798                 if(ret != 0)
3799                 {  
3800                     SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3801                     return -EINVAL;
3802                 }
3803                 msleep(50);   
3804             }       
3805             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3806             return 0;
3807         }
3808     }
3809         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3810     return -EINVAL;
3811 }
3812 #endif
3813 #if CONFIG_SENSOR_Exposure
3814 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3815 {
3816     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3817
3818     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3819     {
3820         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
3821         {
3822             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
3823             {
3824                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3825                 return -EINVAL;
3826             }
3827             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3828             return 0;
3829         }
3830     }
3831         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3832     return -EINVAL;
3833 }
3834 #endif
3835 #if CONFIG_SENSOR_Saturation
3836 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3837 {
3838     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3839
3840     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3841     {
3842         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
3843         {
3844             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
3845             {
3846                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3847                 return -EINVAL;
3848             }
3849             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3850             return 0;
3851         }
3852     }
3853     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3854     return -EINVAL;
3855 }
3856 #endif
3857 #if CONFIG_SENSOR_Contrast
3858 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3859 {
3860     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3861
3862     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3863     {
3864         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
3865         {
3866             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
3867             {
3868                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3869                 return -EINVAL;
3870             }
3871             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3872             return 0;
3873         }
3874     }
3875     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3876     return -EINVAL;
3877 }
3878 #endif
3879 #if CONFIG_SENSOR_Mirror
3880 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3881 {
3882     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3883
3884     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3885     {
3886         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
3887         {
3888             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
3889             {
3890                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3891                 return -EINVAL;
3892             }
3893             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3894             return 0;
3895         }
3896     }
3897     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3898     return -EINVAL;
3899 }
3900 #endif
3901 #if CONFIG_SENSOR_Flip
3902 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3903 {
3904     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3905
3906     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3907     {
3908         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
3909         {
3910             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
3911             {
3912                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3913                 return -EINVAL;
3914             }
3915             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3916             return 0;
3917         }
3918     }
3919     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3920     return -EINVAL;
3921 }
3922 #endif
3923 #if CONFIG_SENSOR_Scene
3924 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3925 {
3926     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3927
3928     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3929     {
3930         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
3931         {
3932             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
3933             {
3934                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3935                 return -EINVAL;
3936             }
3937             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3938             return 0;
3939         }
3940     }
3941     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3942     return -EINVAL;
3943 }
3944 #endif
3945 #if CONFIG_SENSOR_WhiteBalance
3946 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3947 {
3948     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3949
3950     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
3951     {
3952         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
3953         {
3954             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
3955             {
3956                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
3957                 return -EINVAL;
3958             }
3959             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
3960             return 0;
3961         }
3962     }
3963         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
3964     return -EINVAL;
3965 }
3966 #endif
3967 #if CONFIG_SENSOR_DigitalZoom
3968 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
3969 {
3970     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
3971     struct sensor *sensor = to_sensor(client);
3972         const struct v4l2_queryctrl *qctrl_info;
3973     int digitalzoom_cur, digitalzoom_total;
3974
3975         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
3976         if (qctrl_info)
3977                 return -EINVAL;
3978
3979     digitalzoom_cur = sensor->info_priv.digitalzoom;
3980     digitalzoom_total = qctrl_info->maximum;
3981
3982     if ((value > 0) && (digitalzoom_cur >= digitalzoom_total))
3983     {
3984         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3985         return -EINVAL;
3986     }
3987
3988     if  ((value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
3989     {
3990         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
3991         return -EINVAL;
3992     }
3993
3994     if ((value > 0) && ((digitalzoom_cur + value) > digitalzoom_total))
3995     {
3996         value = digitalzoom_total - digitalzoom_cur;
3997     }
3998
3999     if ((value < 0) && ((digitalzoom_cur + value) < 0))
4000     {
4001         value = 0 - digitalzoom_cur;
4002     }
4003
4004     digitalzoom_cur += value;
4005
4006     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
4007     {
4008         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
4009         {
4010             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
4011             return -EINVAL;
4012         }
4013         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4014         return 0;
4015     }
4016
4017     return -EINVAL;
4018 }
4019 #endif
4020 #if CONFIG_SENSOR_Flash
4021 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4022 {    
4023     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
4024         if (value == 3) {       /* ddl@rock-chips.com: torch */
4025             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
4026         } else {
4027             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
4028         }
4029         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
4030         return 0;
4031     }
4032     
4033         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4034     return -EINVAL;
4035 }
4036 #endif
4037 #if CONFIG_SENSOR_Focus
4038 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4039 {
4040         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4041     struct sensor *sensor = to_sensor(client);
4042         const struct v4l2_queryctrl *qctrl_info;
4043         int ret = 0;
4044
4045         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
4046         if (!qctrl_info)
4047                 return -EINVAL;
4048
4049         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
4050                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
4051
4052                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
4053                 } else {
4054                         ret = -EINVAL;
4055                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4056                 }
4057         } else {
4058                 ret = -EACCES;
4059                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
4060                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
4061         }
4062
4063 sensor_set_focus_absolute_end:
4064         return ret;
4065 }
4066 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4067 {
4068         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4069         struct sensor *sensor = to_sensor(client);
4070         const struct v4l2_queryctrl *qctrl_info;
4071         int ret = 0;
4072
4073         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
4074         if (!qctrl_info)
4075                 return -EINVAL;
4076
4077         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
4078                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
4079
4080                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
4081                 } else {
4082                         ret = -EINVAL;
4083                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4084                 }
4085         } else {
4086                 ret = -EACCES;
4087                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
4088                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
4089         }
4090 sensor_set_focus_relative_end:
4091         return ret;
4092 }
4093
4094 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
4095 {
4096         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4097         struct sensor *sensor = to_sensor(client);
4098         int ret = 0;
4099
4100         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)  && (sensor->info_priv.affm_reinit == 0)) {
4101                 switch (value)
4102                 {
4103                         case SENSOR_AF_MODE_AUTO:
4104                         {
4105                                 ret = sensor_af_single(client);
4106                                 break;
4107                         }
4108
4109                         case SENSOR_AF_MODE_MACRO:
4110                         {
4111                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
4112                                 break;
4113                         }
4114
4115                         case SENSOR_AF_MODE_INFINITY:
4116                         {
4117                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
4118                                 break;
4119                         }
4120
4121                         case SENSOR_AF_MODE_CONTINUOUS:
4122                         {
4123                                 ret = sensor_af_const(client);
4124                                 break;
4125                         }
4126                         default:
4127                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
4128                                 break;
4129
4130                 }
4131
4132                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
4133         } else {
4134                 ret = -EACCES;
4135                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
4136                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
4137         }
4138
4139         return ret;
4140 }
4141 #endif
4142 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
4143 {
4144     struct i2c_client *client = v4l2_get_subdevdata(sd);
4145     struct sensor *sensor = to_sensor(client);
4146     const struct v4l2_queryctrl *qctrl;
4147     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4148
4149     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
4150
4151     if (!qctrl)
4152     {
4153         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
4154         return -EINVAL;
4155     }
4156
4157     switch (ctrl->id)
4158     {
4159         case V4L2_CID_BRIGHTNESS:
4160             {
4161                 ctrl->value = sensor->info_priv.brightness;
4162                 break;
4163             }
4164         case V4L2_CID_SATURATION:
4165             {
4166                 ctrl->value = sensor->info_priv.saturation;
4167                 break;
4168             }
4169         case V4L2_CID_CONTRAST:
4170             {
4171                 ctrl->value = sensor->info_priv.contrast;
4172                 break;
4173             }
4174         case V4L2_CID_DO_WHITE_BALANCE:
4175             {
4176                 ctrl->value = sensor->info_priv.whiteBalance;
4177                 break;
4178             }
4179         case V4L2_CID_EXPOSURE:
4180             {
4181                 ctrl->value = sensor->info_priv.exposure;
4182                 break;
4183             }
4184         case V4L2_CID_HFLIP:
4185             {
4186                 ctrl->value = sensor->info_priv.mirror;
4187                 break;
4188             }
4189         case V4L2_CID_VFLIP:
4190             {
4191                 ctrl->value = sensor->info_priv.flip;
4192                 break;
4193             }
4194         default :
4195                 break;
4196     }
4197     return 0;
4198 }
4199
4200
4201
4202 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
4203 {
4204     struct i2c_client *client = v4l2_get_subdevdata(sd);
4205     struct sensor *sensor = to_sensor(client);
4206     struct soc_camera_device *icd = client->dev.platform_data;
4207     const struct v4l2_queryctrl *qctrl;
4208     
4209     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4210
4211
4212     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
4213
4214     if (!qctrl)
4215     {
4216         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
4217         return -EINVAL;
4218     }
4219
4220     switch (ctrl->id)
4221     {
4222 #if CONFIG_SENSOR_Brightness
4223         case V4L2_CID_BRIGHTNESS:
4224             {
4225                 if (ctrl->value != sensor->info_priv.brightness)
4226                 {
4227                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
4228                     {
4229                         return -EINVAL;
4230                     }
4231                     sensor->info_priv.brightness = ctrl->value;
4232                 }
4233                 break;
4234             }
4235 #endif
4236 #if CONFIG_SENSOR_Exposure
4237         case V4L2_CID_EXPOSURE:
4238             {
4239                 if (ctrl->value != sensor->info_priv.exposure)
4240                 {
4241                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
4242                     {
4243                         return -EINVAL;
4244                     }
4245                     sensor->info_priv.exposure = ctrl->value;
4246                 }
4247                 break;
4248             }
4249 #endif
4250 #if CONFIG_SENSOR_Saturation
4251         case V4L2_CID_SATURATION:
4252             {
4253                 if (ctrl->value != sensor->info_priv.saturation)
4254                 {
4255                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
4256                     {
4257                         return -EINVAL;
4258                     }
4259                     sensor->info_priv.saturation = ctrl->value;
4260                 }
4261                 break;
4262             }
4263 #endif
4264 #if CONFIG_SENSOR_Contrast
4265         case V4L2_CID_CONTRAST:
4266             {
4267                 if (ctrl->value != sensor->info_priv.contrast)
4268                 {
4269                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
4270                     {
4271                         return -EINVAL;
4272                     }
4273                     sensor->info_priv.contrast = ctrl->value;
4274                 }
4275                 break;
4276             }
4277 #endif
4278 #if CONFIG_SENSOR_WhiteBalance
4279         case V4L2_CID_DO_WHITE_BALANCE:
4280             {
4281                 if (ctrl->value != sensor->info_priv.whiteBalance)
4282                 {
4283                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
4284                     {
4285                         return -EINVAL;
4286                     }
4287                     sensor->info_priv.whiteBalance = ctrl->value;
4288                 }
4289                 break;
4290             }
4291 #endif
4292 #if CONFIG_SENSOR_Mirror
4293         case V4L2_CID_HFLIP:
4294             {
4295                 if (ctrl->value != sensor->info_priv.mirror)
4296                 {
4297                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
4298                         return -EINVAL;
4299                     sensor->info_priv.mirror = ctrl->value;
4300                 }
4301                 break;
4302             }
4303 #endif
4304 #if CONFIG_SENSOR_Flip
4305         case V4L2_CID_VFLIP:
4306             {
4307                 if (ctrl->value != sensor->info_priv.flip)
4308                 {
4309                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
4310                         return -EINVAL;
4311                     sensor->info_priv.flip = ctrl->value;
4312                 }
4313                 break;
4314             }
4315 #endif
4316         default:
4317             break;
4318     }
4319
4320     return 0;
4321 }
4322 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
4323 {
4324     const struct v4l2_queryctrl *qctrl;
4325     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4326     struct sensor *sensor = to_sensor(client);
4327     
4328     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4329
4330     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
4331
4332     if (!qctrl)
4333     {
4334         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
4335         return -EINVAL;
4336     }
4337
4338     switch (ext_ctrl->id)
4339     {
4340         case V4L2_CID_SCENE:
4341             {
4342                 ext_ctrl->value = sensor->info_priv.scene;
4343                 break;
4344             }
4345         case V4L2_CID_EFFECT:
4346             {
4347                 ext_ctrl->value = sensor->info_priv.effect;
4348                 break;
4349             }
4350         case V4L2_CID_ZOOM_ABSOLUTE:
4351             {
4352                 ext_ctrl->value = sensor->info_priv.digitalzoom;
4353                 break;
4354             }
4355         case V4L2_CID_ZOOM_RELATIVE:
4356             {
4357                 return -EINVAL;
4358             }
4359         case V4L2_CID_FOCUS_ABSOLUTE:
4360             {
4361                 return -EINVAL;
4362             }
4363         case V4L2_CID_FOCUS_RELATIVE:
4364             {
4365                 return -EINVAL;
4366             }
4367         case V4L2_CID_FLASH:
4368             {
4369                 ext_ctrl->value = sensor->info_priv.flash;
4370                 break;
4371             }
4372         default :
4373             break;
4374     }
4375     return 0;
4376 }
4377 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
4378 {
4379     const struct v4l2_queryctrl *qctrl;
4380     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
4381     struct sensor *sensor = to_sensor(client);
4382     int val_offset;
4383
4384     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
4385
4386     if (!qctrl)
4387     {
4388         SENSOR_TR("\n %s ioctrl id = 0x%x  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
4389         return -EINVAL;
4390     }
4391
4392         val_offset = 0;
4393     switch (ext_ctrl->id)
4394     {
4395 #if CONFIG_SENSOR_Scene
4396         case V4L2_CID_SCENE:
4397             {
4398                 if (ext_ctrl->value != sensor->info_priv.scene)
4399                 {
4400                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
4401                         return -EINVAL;
4402                     sensor->info_priv.scene = ext_ctrl->value;
4403                 }
4404                 break;
4405             }
4406 #endif
4407 #if CONFIG_SENSOR_Effect
4408         case V4L2_CID_EFFECT:
4409             {
4410                 if (ext_ctrl->value != sensor->info_priv.effect)
4411                 {
4412                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
4413                         return -EINVAL;
4414                     sensor->info_priv.effect= ext_ctrl->value;
4415                 }
4416                 break;
4417             }
4418 #endif
4419 #if CONFIG_SENSOR_DigitalZoom
4420         case V4L2_CID_ZOOM_ABSOLUTE:
4421             {
4422                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
4423                     return -EINVAL;
4424
4425                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
4426                 {
4427                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
4428
4429                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
4430                         return -EINVAL;
4431                     sensor->info_priv.digitalzoom += val_offset;
4432
4433                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
4434                 }
4435
4436                 break;
4437             }
4438         case V4L2_CID_ZOOM_RELATIVE:
4439             {
4440                 if (ext_ctrl->value)
4441                 {
4442                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
4443                         return -EINVAL;
4444                     sensor->info_priv.digitalzoom += ext_ctrl->value;
4445
4446                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
4447                 }
4448                 break;
4449             }
4450 #endif
4451 #if CONFIG_SENSOR_Focus
4452         case V4L2_CID_FOCUS_ABSOLUTE:
4453             {
4454                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
4455                     return -EINVAL;
4456
4457                                 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
4458                                         if (ext_ctrl->value == qctrl->minimum) {
4459                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
4460                                         } else if (ext_ctrl->value == qctrl->maximum) {
4461                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
4462                                         } else {
4463                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
4464                                         }
4465                                 }
4466
4467                 break;
4468             }
4469         case V4L2_CID_FOCUS_RELATIVE:
4470             {
4471                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
4472                     return -EINVAL;
4473
4474                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
4475                 break;
4476             }
4477                 case V4L2_CID_FOCUS_AUTO:
4478                         {
4479                                 if (ext_ctrl->value == 1) {
4480                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
4481                                                 return -EINVAL;
4482                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
4483                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
4484                                         if (ext_ctrl->value == 0)
4485                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
4486                                 }
4487                                 break;
4488                         }
4489                 case V4L2_CID_FOCUS_CONTINUOUS:
4490                         {
4491                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
4492                                         if (ext_ctrl->value == 1) {
4493                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
4494                                                         return -EINVAL;
4495                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
4496                                         }
4497                                 } else {
4498                                         if (ext_ctrl->value == 0)
4499                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
4500                                 }
4501                                 break;
4502                         }
4503 #endif
4504 #if CONFIG_SENSOR_Flash
4505         case V4L2_CID_FLASH:
4506             {
4507                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
4508                     return -EINVAL;
4509                 sensor->info_priv.flash = ext_ctrl->value;
4510
4511                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
4512                 break;
4513             }
4514 #endif
4515         default:
4516             break;
4517     }
4518
4519     return 0;
4520 }
4521
4522 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
4523 {
4524     struct i2c_client *client = v4l2_get_subdevdata(sd);
4525     struct soc_camera_device *icd = client->dev.platform_data;
4526     int i, error_cnt=0, error_idx=-1;
4527     
4528     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4529
4530
4531     for (i=0; i<ext_ctrl->count; i++) {
4532         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
4533             error_cnt++;
4534             error_idx = i;
4535         }
4536     }
4537
4538     if (error_cnt > 1)
4539         error_idx = ext_ctrl->count;
4540
4541     if (error_idx != -1) {
4542         ext_ctrl->error_idx = error_idx;
4543         return -EINVAL;
4544     } else {
4545         return 0;
4546     }
4547 }
4548
4549 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
4550 {
4551     struct i2c_client *client = v4l2_get_subdevdata(sd);
4552     struct soc_camera_device *icd = client->dev.platform_data;
4553     int i, error_cnt=0, error_idx=-1;
4554     
4555     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4556
4557     for (i=0; i<ext_ctrl->count; i++) {
4558         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
4559             error_cnt++;
4560             error_idx = i;
4561         }
4562     }
4563
4564     if (error_cnt > 1)
4565         error_idx = ext_ctrl->count;
4566
4567     if (error_idx != -1) {
4568         ext_ctrl->error_idx = error_idx;
4569         return -EINVAL;
4570     } else {
4571         return 0;
4572     }
4573 }
4574
4575 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
4576 {
4577         struct i2c_client *client = v4l2_get_subdevdata(sd);
4578     struct sensor *sensor = to_sensor(client);
4579
4580         if (enable == 1) {
4581                 sensor->info_priv.enable = 1;
4582         } else if (enable == 0) {
4583                 sensor->info_priv.enable = 0;
4584         }
4585
4586         return 0;
4587 }
4588
4589 /* Interface active, can use i2c. If it fails, it can indeed mean, that
4590  * this wasn't our capture interface, so, we wait for the right one */
4591 static int sensor_video_probe(struct soc_camera_device *icd,
4592                                struct i2c_client *client)
4593 {
4594     int ret,pid = 0;
4595     struct sensor *sensor = to_sensor(client);
4596 #if (SENSOR_RESET_REG != SEQUENCE_END)
4597     struct reginfo reg_info;
4598 #endif
4599     /* We must have a parent by now. And it cannot be a wrong one.
4600      * So this entire test is completely redundant. */
4601     if (!icd->dev.parent ||
4602             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
4603                 return -ENODEV;
4604
4605         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
4606                 ret = -ENODEV;
4607                 goto sensor_video_probe_err;
4608         }
4609
4610     /* soft reset */
4611 #if (SENSOR_RESET_REG != SEQUENCE_END)   
4612         reg_info.reg = SENSOR_RESET_REG;
4613         reg_info.val = SENSOR_RESET_VAL;
4614         reg_info.reg_len = SENSOR_RESET_REG_LEN;
4615     ret = sensor_write(client, &reg_info);
4616     if (ret != 0) {
4617         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
4618         ret = -ENODEV;
4619                 goto sensor_video_probe_err;
4620     }
4621
4622     mdelay(5);  //delay 5 microseconds
4623 #endif
4624
4625         /* check if it is an sensor sensor */
4626 #if (SENSOR_ID_REG != SEQUENCE_END)
4627     ret = sensor_read(client, SENSOR_ID_REG, &pid);
4628     if (ret != 0) {
4629         SENSOR_TR("read chip id failed\n");
4630         ret = -ENODEV;
4631         goto sensor_video_probe_err;
4632     }
4633
4634     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
4635 #else
4636         pid = SENSOR_ID;
4637 #endif
4638
4639     if (pid == SENSOR_ID) {
4640         sensor->model = SENSOR_V4L2_IDENT;
4641     } else {
4642         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
4643         ret = -ENODEV;
4644         goto sensor_video_probe_err;
4645     }
4646
4647     return 0;
4648
4649 sensor_video_probe_err:
4650
4651     return ret;
4652 }
4653 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
4654 {
4655         struct i2c_client *client = v4l2_get_subdevdata(sd);
4656     struct soc_camera_device *icd = client->dev.platform_data;
4657     struct sensor *sensor = to_sensor(client);
4658 #if CONFIG_SENSOR_Flash 
4659     int i;
4660 #endif
4661     int ret = 0;
4662     
4663     rk29_camera_sensor_cb_s *icd_cb =NULL;
4664     
4665         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4666         switch (cmd)
4667         {
4668                 case RK29_CAM_SUBDEV_DEACTIVATE:
4669                 {
4670                         sensor_deactivate(client);
4671                         break;
4672                 }
4673                 case RK29_CAM_SUBDEV_IOREQUEST:
4674                 {
4675                         sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;           
4676             if (sensor->sensor_io_request != NULL) { 
4677                 sensor->sensor_gpio_res = NULL;
4678                 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
4679                     if (sensor->sensor_io_request->gpio_res[i].dev_name && 
4680                         (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
4681                         sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
4682                     }
4683                 }
4684                 if (sensor->sensor_gpio_res == NULL) {
4685                     SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
4686                     ret = -EINVAL;
4687                     goto sensor_ioctl_end;
4688                 }
4689             } else {
4690                 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
4691                 ret = -EINVAL;
4692                 goto sensor_ioctl_end;
4693             }
4694             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
4695                for this project */
4696             #if CONFIG_SENSOR_Flash     
4697                 if (sensor->sensor_gpio_res) {
4698                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
4699                     for (i = 0; i < icd->ops->num_controls; i++) {
4700                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
4701                                         //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));  
4702                               sensor_controls[i].id=0xffff;                             
4703                                 }
4704                     }
4705                     sensor->info_priv.flash = 0xff;
4706                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
4707                 }else{ //two cameras are the same,need to deal diffrently ,zyc
4708                     for (i = 0; i < icd->ops->num_controls; i++) {
4709                            if(0xffff == icd->ops->controls[i].id){
4710                               sensor_controls[i].id=V4L2_CID_FLASH;
4711                            }               
4712                     }
4713                 }
4714                 }
4715             #endif
4716                         break;
4717                 }
4718         case RK29_CAM_SUBDEV_CB_REGISTER:
4719         {
4720            icd_cb = (rk29_camera_sensor_cb_s*)(arg);
4721            icd_cb->sensor_cb = sensor_cb;
4722            break;    
4723         }
4724                 default:
4725                 {
4726                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
4727                         break;
4728                 }
4729         }
4730 sensor_ioctl_end:
4731         return ret;
4732
4733 }
4734 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
4735                             enum v4l2_mbus_pixelcode *code)
4736 {
4737         if (index >= ARRAY_SIZE(sensor_colour_fmts))
4738                 return -EINVAL;
4739
4740         *code = sensor_colour_fmts[index].code;
4741         return 0;
4742 }
4743 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
4744         .init           = sensor_init,
4745         .g_ctrl         = sensor_g_control,
4746         .s_ctrl         = sensor_s_control,
4747         .g_ext_ctrls          = sensor_g_ext_controls,
4748         .s_ext_ctrls          = sensor_s_ext_controls,
4749         .g_chip_ident   = sensor_g_chip_ident,
4750         .ioctl = sensor_ioctl,
4751 };
4752 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
4753         .s_mbus_fmt     = sensor_s_fmt,
4754         .g_mbus_fmt     = sensor_g_fmt,
4755         .try_mbus_fmt   = sensor_try_fmt,
4756         .enum_mbus_fmt  = sensor_enum_fmt,
4757         .s_stream   = sensor_s_stream,
4758 };
4759 static struct v4l2_subdev_ops sensor_subdev_ops = {
4760         .core   = &sensor_subdev_core_ops,
4761         .video = &sensor_subdev_video_ops,
4762 };
4763
4764 static int sensor_probe(struct i2c_client *client,
4765                          const struct i2c_device_id *did)
4766 {
4767     struct sensor *sensor;
4768     struct soc_camera_device *icd = client->dev.platform_data;
4769     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
4770     struct soc_camera_link *icl;
4771     int ret;
4772
4773     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
4774     if (!icd) {
4775         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
4776         return -EINVAL;
4777     }
4778
4779     icl = to_soc_camera_link(icd);
4780     if (!icl) {
4781         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
4782         return -EINVAL;
4783     }
4784
4785     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
4786         dev_warn(&adapter->dev,
4787                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
4788         return -EIO;
4789     }
4790
4791     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
4792     if (!sensor)
4793         return -ENOMEM;
4794
4795     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
4796
4797     /* Second stage probe - when a capture adapter is there */
4798     icd->ops            = &sensor_ops;
4799     sensor->info_priv.fmt = sensor_colour_fmts[0];
4800         #if CONFIG_SENSOR_I2C_NOSCHED
4801         atomic_set(&sensor->tasklock_cnt,0);
4802         #endif
4803
4804     ret = sensor_video_probe(icd, client);
4805     if (ret < 0) {
4806         icd->ops = NULL;
4807         i2c_set_clientdata(client, NULL);
4808         kfree(sensor);
4809                 sensor = NULL;
4810     }
4811     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
4812     return ret;
4813 }
4814
4815 static int sensor_remove(struct i2c_client *client)
4816 {
4817     struct sensor *sensor = to_sensor(client);
4818     struct soc_camera_device *icd = client->dev.platform_data;
4819
4820         #if CONFIG_SENSOR_Focus
4821         if (sensor->sensor_wq) {
4822                 destroy_workqueue(sensor->sensor_wq);
4823                 sensor->sensor_wq = NULL;
4824         }
4825         #endif
4826
4827     icd->ops = NULL;
4828     i2c_set_clientdata(client, NULL);
4829     client->driver = NULL;
4830     kfree(sensor);
4831         sensor = NULL;
4832     return 0;
4833 }
4834
4835 static const struct i2c_device_id sensor_id[] = {
4836         {SENSOR_NAME_STRING(), 0 },
4837         { }
4838 };
4839 MODULE_DEVICE_TABLE(i2c, sensor_id);
4840
4841 static struct i2c_driver sensor_i2c_driver = {
4842         .driver = {
4843                 .name = SENSOR_NAME_STRING(),
4844         },
4845         .probe          = sensor_probe,
4846         .remove         = sensor_remove,
4847         .id_table       = sensor_id,
4848 };
4849
4850 static int __init sensor_mod_init(void)
4851 {
4852     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4853     return i2c_add_driver(&sensor_i2c_driver);
4854 }
4855
4856 static void __exit sensor_mod_exit(void)
4857 {
4858     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
4859     i2c_del_driver(&sensor_i2c_driver);
4860 }
4861
4862 device_initcall_sync(sensor_mod_init);
4863 module_exit(sensor_mod_exit);
4864
4865 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
4866 MODULE_AUTHOR("ddl <kernel@rock-chips>");
4867 MODULE_LICENSE("GPL");
4868
4869