Merge remote-tracking branch 'origin/develop-3.0-rk30' into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / mt9d112.c
1 /*
2  * Driver for mt9d112 CMOS Image Sensor from Aptina(micron)
3  *
4  * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk29_camera.h>
23 #include "mt9d112.h"
24
25 static int debug;
26 module_param(debug, int, S_IRUGO|S_IWUSR);
27
28 #define dprintk(level, fmt, arg...) do {                        \
29         if (debug >= level)                                     \
30         printk(KERN_WARNING fmt , ## arg); } while (0)
31
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
34
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
37
38 #define __STR(x) #x
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
41
42 #define MIN(x,y)   ((x<y) ? x: y)
43 #define MAX(x,y)    ((x>y) ? x: y)
44
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_MT9D112
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9D112
48 #define SENSOR_ID 0x1580
49 #define SENSOR_ID_REG 0x3000
50 #define SENSOR_RESET_REG SEQUENCE_END
51 #define SENSOR_RESET_VAL 0x00
52 #define SENSOR_MIN_WIDTH    320
53 #define SENSOR_MIN_HEIGHT   240
54 #define SENSOR_MAX_WIDTH    1600
55 #define SENSOR_MAX_HEIGHT   1200
56 #define SENSOR_INIT_WIDTH       640                     /* Sensor pixel size for sensor_init_data array */
57 #define SENSOR_INIT_HEIGHT  480
58 #define SENSOR_INIT_WINSEQADR sensor_vga
59 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
60
61 #define CONFIG_SENSOR_WhiteBalance      1
62 #define CONFIG_SENSOR_Brightness        0
63 #define CONFIG_SENSOR_Contrast      0
64 #define CONFIG_SENSOR_Saturation    0
65 #define CONFIG_SENSOR_Effect        1
66 #define CONFIG_SENSOR_Scene         1
67 #define CONFIG_SENSOR_DigitalZoom   0
68 #define CONFIG_SENSOR_Exposure      0
69 #define CONFIG_SENSOR_Flash         0
70 #define CONFIG_SENSOR_Mirror        0
71 #define CONFIG_SENSOR_Flip          0
72 #define CONFIG_SENSOR_Focus         0
73
74
75 #define CONFIG_SENSOR_I2C_SPEED     250000       /* Hz */
76 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
77 #define CONFIG_SENSOR_I2C_NOSCHED   0
78 #define CONFIG_SENSOR_I2C_RDWRCHK   0
79
80
81 #define SENSOR_BUS_PARAM  (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
82                           SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
83                           SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8  |SOCAM_MCLK_24MHZ)
84
85 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
86 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
87 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
88 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
89 #define COLOR_TEMPERATURE_OFFICE_DN     3500
90 #define COLOR_TEMPERATURE_OFFICE_UP     5000
91 #define COLOR_TEMPERATURE_HOME_DN       2500
92 #define COLOR_TEMPERATURE_HOME_UP       3500
93
94 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
95 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
96
97 #define SENSOR_AF_IS_ERR    (0x00<<0)
98 #define SENSOR_AF_IS_OK         (0x01<<0)
99 #define SENSOR_INIT_IS_ERR   (0x00<<28)
100 #define SENSOR_INIT_IS_OK    (0x01<<28)
101
102 #if CONFIG_SENSOR_Focus
103 #define SENSOR_AF_MODE_INFINITY    0
104 #define SENSOR_AF_MODE_MACRO       1
105 #define SENSOR_AF_MODE_FIXED       2
106 #define SENSOR_AF_MODE_AUTO        3
107 #define SENSOR_AF_MODE_CONTINUOUS  4
108 #define SENSOR_AF_MODE_CLOSE       5
109 #endif
110 #define SENSOR_CCM_ONLY
111 /* init 640X480 VGA */
112 static struct reginfo sensor_init_data[] =
113 {
114         {0x301A, 0x0ACC},       // RESET_REGISTER
115         {0x3202, 0x0008},       // STANDBY_CONTROL
116         {SEQUENCE_WAIT_MS, 10},
117         {0x341E, 0x8F09},       // PLL_CLK_IN_CONTROL
118         {0x341C, 0x0218},       // PLL_DIVIDERS1
119         {SEQUENCE_WAIT_MS, 1},
120         {0x341E, 0x8F09},       // PLL_CLK_IN_CONTROL
121         {0x341E, 0x8F08},       // PLL_CLK_IN_CONTROL
122         {0x3044, 0x0540},       // DARK_CONTROL
123         {0x3216, 0x02CF},       // INTERNAL_CLOCK_CONTROL
124         {0x321C, 0x0402},       // OF_CONTROL_STATUS
125         {0x3212, 0x0001},       // FACTORY_BYPASS
126         {0x341E, 0x8F09},       // PLL_CLK_IN_CONTROL
127         {0x341C, 0x0120},       // PLL_DIVIDERS1
128         {0x341E, 0x8F09},       // PLL_CLK_IN_CONTROL
129         {0x341E, 0x8F08},       // PLL_CLK_IN_CONTROL
130         {0x3044, 0x0540},       // DARK_CONTROL
131         {0x3216, 0x02CF},       // INTERNAL_CLOCK_CONTROL
132         {0x321C, 0x0402},       // OF_CONTROL_STATUS
133         {0x3212, 0x0001},       // FACTORY_BYPASS//¹©Æ·¸ÉÈųÌÐòÀûÓÃ֮ǰµÄ07005
134 #ifdef SENSOR_CCM_ONLY
135         {0x338C, 0x2703},
136         {0x3390, 0x0320},
137         {0x338C, 0x2705},
138         {0x3390, 0x0258},
139         {0x338C, 0x2707},
140         {0x3390, 0x0640},
141         {0x338C, 0x2709},
142         {0x3390, 0x04B0},
143         {0x338C, 0x270D},
144         {0x3390, 0x0000},
145         {0x338C, 0x270F},
146         {0x3390, 0x0000},
147         {0x338C, 0x2711},
148         {0x3390, 0x4BD},
149         {0x338C, 0x2713},
150         {0x3390, 0x64D},
151         {0x3390, 0x411},
152 #else
153         {0x338C, 0x2703},       // MCU_ADDRESS
154         {0x3390, 0x0140},       // MCU_DATA_0
155         {0x338C, 0x2705},       // MCU_ADDRESS
156         {0x3390, 0x00F0},       // MCU_DATA_0
157         {0x338C, 0x2707},       // MCU_ADDRESS
158         {0x3390, 0x0640},       // MCU_DATA_0
159         {0x338C, 0x2709},       // MCU_ADDRESS
160         {0x3390, 0x04B0},       // MCU_DATA_0
161         {0x338C, 0x270D},       // MCU_ADDRESS
162         {0x3390, 0x0000},       // MCU_DATA_0
163         {0x338C, 0x270F},       // MCU_ADDRESS
164         {0x3390, 0x0000},       // MCU_DATA_0
165         {0x338C, 0x2711},       // MCU_ADDRESS
166         {0x3390, 0x04BD},       // MCU_DATA_0
167         {0x338C, 0x2713},       // MCU_ADDRESS
168         {0x3390, 0x064D},       // MCU_DATA_0
169         {0x338C, 0x2715},       // MCU_ADDRESS
170         {0x3390, 0x0022},       // MCU_DATA_0
171 #endif
172         {0x338C, 0x2717},       // MCU_ADDRESS
173         {0x3390, 0x2111},       // MCU_DATA_0
174         {0x338C, 0x2719},       // MCU_ADDRESS
175         {0x3390, 0x046C},       // MCU_DATA_0
176         {0x338C, 0x271B},       // MCU_ADDRESS
177         {0x3390, 0x024F},       // MCU_DATA_0
178         {0x338C, 0x271D},       // MCU_ADDRESS
179         {0x3390, 0x0102},       // MCU_DATA_0
180         {0x338C, 0x271F},       // MCU_ADDRESS
181         {0x3390, 0x0279},       // MCU_DATA_0
182         {0x338C, 0x2721},       // MCU_ADDRESS
183         {0x3390, 0x0155},       // MCU_DATA_0
184         {0x338C, 0x2723},       // MCU_ADDRESS
185         {0x3390, 0x0293},       // MCU_DATA_0
186         {0x338C, 0x2725},       // MCU_ADDRESS
187         {0x3390, 0x0824},       // MCU_DATA_0
188         {0x338C, 0x2727},       // MCU_ADDRESS
189         {0x3390, 0x2020},       // MCU_DATA_0
190         {0x338C, 0x2729},       // MCU_ADDRESS
191         {0x3390, 0x2020},       // MCU_DATA_0
192         {0x338C, 0x272B},       // MCU_ADDRESS
193         {0x3390, 0x1020},       // MCU_DATA_0
194         {0x338C, 0x272D},       // MCU_ADDRESS
195         {0x3390, 0x2007},       // MCU_DATA_0
196         {0x338C, 0x272F},       // MCU_ADDRESS
197         {0x3390, 0x0004},       // MCU_DATA_0
198         {0x338C, 0x2731},       // MCU_ADDRESS
199         {0x3390, 0x0004},       // MCU_DATA_0
200         {0x338C, 0x2733},       // MCU_ADDRESS
201         {0x3390, 0x04BB},       // MCU_DATA_0
202         {0x338C, 0x2735},       // MCU_ADDRESS
203         {0x3390, 0x064B},       // MCU_DATA_0
204         {0x338C, 0x2737},       // MCU_ADDRESS
205         {0x3390, 0x0000},       // MCU_DATA_0
206         {0x338C, 0x2739},       // MCU_ADDRESS
207         {0x3390, 0x2111},       // MCU_DATA_0
208         {0x338C, 0x273B},       // MCU_ADDRESS
209         {0x3390, 0x0024},       // MCU_DATA_0
210         {0x338C, 0x273D},       // MCU_ADDRESS
211         {0x3390, 0x0120},       // MCU_DATA_0
212         {0x338C, 0x273F},       // MCU_ADDRESS
213         {0x3390, 0x00A4},       // MCU_DATA_0
214         {0x338C, 0x2741},       // MCU_ADDRESS
215         {0x3390, 0x0169},       // MCU_DATA_0
216         {0x338C, 0x2743},       // MCU_ADDRESS
217         {0x3390, 0x00A4},       // MCU_DATA_0
218         {0x338C, 0x2745},       // MCU_ADDRESS
219         {0x3390, 0x04ED},       // MCU_DATA_0
220         {0x338C, 0x2747},       // MCU_ADDRESS
221         {0x3390, 0x0824},       // MCU_DATA_0
222         {0x338C, 0x2751},       // MCU_ADDRESS
223         {0x3390, 0x0000},       // MCU_DATA_0
224         {0x338C, 0x2753},       // MCU_ADDRESS
225         {0x3390, 0x0320},       // MCU_DATA_0
226         {0x338C, 0x2755},       // MCU_ADDRESS
227         {0x3390, 0x0000},       // MCU_DATA_0
228         {0x338C, 0x2757},       // MCU_ADDRESS
229         {0x3390, 0x0258},       // MCU_DATA_0
230         {0x338C, 0x275F},       // MCU_ADDRESS
231         {0x3390, 0x0000},       // MCU_DATA_0
232         {0x338C, 0x2761},       // MCU_ADDRESS
233         {0x3390, 0x0640},       // MCU_DATA_0
234         {0x338C, 0x2763},       // MCU_ADDRESS
235         {0x3390, 0x0000},       // MCU_DATA_0
236         {0x338C, 0x2765},       // MCU_ADDRESS
237         {0x3390, 0x04B0},       // MCU_DATA_0
238         {0x338C, 0x222E},       // MCU_ADDRESS
239         {0x3390, 0x0060},       // MCU_DATA_0
240         {0x338C, 0xA408},       // MCU_ADDRESS
241         {0x3390, 0x0017},       // MCU_DATA_0
242         {0x338C, 0xA409},       // MCU_ADDRESS
243         {0x3390, 0x001A},       // MCU_DATA_0
244         {0x338C, 0xA40A},       // MCU_ADDRESS
245         {0x3390, 0x001B},       // MCU_DATA_0
246         {0x338C, 0xA40B},       // MCU_ADDRESS
247         {0x3390, 0x001E},       // MCU_DATA_0
248         {0x338C, 0x2411},       // MCU_ADDRESS
249         {0x3390, 0x0060},       // MCU_DATA_0
250         {0x338C, 0x2413},       // MCU_ADDRESS
251         {0x3390, 0x0073},       // MCU_DATA_0
252         {0x338C, 0x2415},       // MCU_ADDRESS
253         {0x3390, 0x0060},       // MCU_DATA_0
254         {0x338C, 0x2417},       // MCU_ADDRESS
255         {0x3390, 0x0073},       // MCU_DATA_0
256         {0x338C, 0xA40D},       // MCU_ADDRESS
257         {0x3390, 0x0002},       // MCU_DATA_0
258         {0x338C, 0xA410},       // MCU_ADDRESS
259         {0x3390, 0x0001},       // MCU_DATA_0
260         {0x338C, 0xA103},       // MCU_ADDRESS
261         {0x3390, 0x0006},       // MCU_DATA_0
262         {0x338C, 0xA103},       // MCU_ADDRESS
263         {0x3390, 0x0005},       // MCU_DATA_0
264         {0x338C, 0x2703},       // MCU_ADDRESS
265         {0x3390, 0x0140},       // MCU_DATA_0
266         {0x338C, 0x2705},       // MCU_ADDRESS
267         {0x3390, 0x00F0},       // MCU_DATA_0
268         {0x338C, 0x2707},       // MCU_ADDRESS
269         {0x3390, 0x0640},       // MCU_DATA_0
270         {0x338C, 0x2709},       // MCU_ADDRESS
271         {0x3390, 0x04B0},       // MCU_DATA_0
272         {0x338C, 0x270D},       // MCU_ADDRESS
273         {0x3390, 0x0000},       // MCU_DATA_0
274         {0x338C, 0x270F},       // MCU_ADDRESS
275         {0x3390, 0x0000},       // MCU_DATA_0
276         {0x338C, 0x2711},       // MCU_ADDRESS
277         {0x3390, 0x04BD},       // MCU_DATA_0
278         {0x338C, 0x2713},       // MCU_ADDRESS
279         {0x3390, 0x064D},       // MCU_DATA_0
280         {0x338C, 0x2715},       // MCU_ADDRESS
281         {0x3390, 0x0022},       // MCU_DATA_0
282         {0x338C, 0x2717},       // MCU_ADDRESS
283         {0x3390, 0x2111},       // MCU_DATA_0
284         {0x338C, 0x2719},       // MCU_ADDRESS
285         {0x3390, 0x046C},       // MCU_DATA_0
286         {0x338C, 0x271B},       // MCU_ADDRESS
287         {0x3390, 0x024F},       // MCU_DATA_0
288         {0x338C, 0x271D},       // MCU_ADDRESS
289         {0x3390, 0x0102},       // MCU_DATA_0
290         {0x338C, 0x271F},       // MCU_ADDRESS
291         {0x3390, 0x0279},       // MCU_DATA_0
292         {0x338C, 0x2721},       // MCU_ADDRESS
293         {0x3390, 0x0155},       // MCU_DATA_0
294         {0x338C, 0x2723},       // MCU_ADDRESS
295         {0x3390, 0x0293},       // MCU_DATA_0
296         {0x338C, 0x2725},       // MCU_ADDRESS
297         {0x3390, 0x0824},       // MCU_DATA_0
298         {0x338C, 0x2727},       // MCU_ADDRESS
299         {0x3390, 0x2020},       // MCU_DATA_0
300         {0x338C, 0x2729},       // MCU_ADDRESS
301         {0x3390, 0x2020},       // MCU_DATA_0
302         {0x338C, 0x272B},       // MCU_ADDRESS
303         {0x3390, 0x1020},       // MCU_DATA_0
304         {0x338C, 0x272D},       // MCU_ADDRESS
305         {0x3390, 0x2007},       // MCU_DATA_0
306         {0x338C, 0x272F},       // MCU_ADDRESS
307         {0x3390, 0x0004},       // MCU_DATA_0
308         {0x338C, 0x2731},       // MCU_ADDRESS
309         {0x3390, 0x0004},       // MCU_DATA_0
310         {0x338C, 0x2733},       // MCU_ADDRESS
311         {0x3390, 0x04BB},       // MCU_DATA_0
312         {0x338C, 0x2735},       // MCU_ADDRESS
313         {0x3390, 0x064B},       // MCU_DATA_0
314         {0x338C, 0x2737},       // MCU_ADDRESS
315         {0x3390, 0x0000},       // MCU_DATA_0
316         {0x338C, 0x2739},       // MCU_ADDRESS
317         {0x3390, 0x2111},       // MCU_DATA_0
318         {0x338C, 0x273B},       // MCU_ADDRESS
319         {0x3390, 0x0024},       // MCU_DATA_0
320         {0x338C, 0x273D},       // MCU_ADDRESS
321         {0x3390, 0x0120},       // MCU_DATA_0
322         {0x338C, 0x273F},       // MCU_ADDRESS
323         {0x3390, 0x00A4},       // MCU_DATA_0
324         {0x338C, 0x2741},       // MCU_ADDRESS
325         {0x3390, 0x0169},       // MCU_DATA_0
326         {0x338C, 0x2743},       // MCU_ADDRESS
327         {0x3390, 0x00A4},       // MCU_DATA_0
328         {0x338C, 0x2745},       // MCU_ADDRESS
329         {0x3390, 0x04ED},       // MCU_DATA_0
330         {0x338C, 0x2747},       // MCU_ADDRESS
331         {0x3390, 0x0824},       // MCU_DATA_0
332         {0x338C, 0x2751},       // MCU_ADDRESS
333         {0x3390, 0x0000},       // MCU_DATA_0
334         {0x338C, 0x2753},       // MCU_ADDRESS
335         {0x3390, 0x0320},       // MCU_DATA_0
336         {0x338C, 0x2755},       // MCU_ADDRESS
337         {0x3390, 0x0000},       // MCU_DATA_0
338         {0x338C, 0x2757},       // MCU_ADDRESS
339         {0x3390, 0x0258},       // MCU_DATA_0
340         {0x338C, 0x275F},       // MCU_ADDRESS
341         {0x3390, 0x0000},       // MCU_DATA_0
342         {0x338C, 0x2761},       // MCU_ADDRESS
343         {0x3390, 0x0640},       // MCU_DATA_0
344         {0x338C, 0x2763},       // MCU_ADDRESS
345         {0x3390, 0x0000},       // MCU_DATA_0
346         {0x338C, 0x2765},       // MCU_ADDRESS
347         {0x3390, 0x04B0},       // MCU_DATA_0
348         {0x338C, 0x222E},       // MCU_ADDRESS
349         {0x3390, 0x0060},       // MCU_DATA_0
350         {0x338C, 0xA408},       // MCU_ADDRESS
351         {0x3390, 0x0017},       // MCU_DATA_0
352         {0x338C, 0xA409},       // MCU_ADDRESS
353         {0x3390, 0x001A},       // MCU_DATA_0
354         {0x338C, 0xA40A},       // MCU_ADDRESS
355         {0x3390, 0x001B},       // MCU_DATA_0
356         {0x338C, 0xA40B},       // MCU_ADDRESS
357         {0x3390, 0x001E},       // MCU_DATA_0
358         {0x338C, 0x2411},       // MCU_ADDRESS
359         {0x3390, 0x0060},       // MCU_DATA_0
360         {0x338C, 0x2413},       // MCU_ADDRESS
361         {0x3390, 0x0073},       // MCU_DATA_0
362         {0x338C, 0x2415},       // MCU_ADDRESS
363         {0x3390, 0x0060},       // MCU_DATA_0
364         {0x338C, 0x2417},       // MCU_ADDRESS
365         {0x3390, 0x0073},       // MCU_DATA_0
366         {0x338C, 0xA40D},       // MCU_ADDRESS
367         {0x3390, 0x0002},       // MCU_DATA_0
368         {0x338C, 0xA410},       // MCU_ADDRESS
369         {0x3390, 0x0001},       // MCU_DATA_0
370         {0x338C, 0xA103},       // MCU_ADDRESS
371         {0x3390, 0x0006},       // MCU_DATA_0
372         {SEQUENCE_WAIT_MS, 100},
373         {0x338C, 0xA103},       // MCU_ADDRESS
374         {0x3390, 0x0005},       // MCU_DATA_0
375         {SEQUENCE_WAIT_MS, 100},
376
377
378         //[Lens Correction 01/04/07 20:07:28]
379         {0x34CE, 0x01A0}, //LENS_CORRECTION_CONTROL
380         {0x34D0, 0x6532}, //ZONE_BOUNDS_X1_X2
381         {0x34D2, 0x3297}, //ZONE_BOUNDS_X0_X3
382         {0x34D4, 0x9664}, //ZONE_BOUNDS_X4_X5
383         {0x34D6, 0x4B25}, //ZONE_BOUNDS_Y1_Y2
384         {0x34D8, 0x2670}, //ZONE_BOUNDS_Y0_Y3
385         {0x34DA, 0x724C}, //ZONE_BOUNDS_Y4_Y5
386         {0x34DC, 0xFF01}, //CENTER_OFFSET
387         {0x34DE, 0x011F}, //FX_RED
388         {0x34E6, 0x00B3}, //FY_RED
389         {0x34EE, 0x0D8F}, //DF_DX_RED
390         {0x34F6, 0x0D6E}, //DF_DY_RED
391         {0x3500, 0xF51C}, //SECOND_DERIV_ZONE_0_RED
392         {0x3508, 0xFEF8}, //SECOND_DERIV_ZONE_1_RED
393         {0x3510, 0x212D}, //SECOND_DERIV_ZONE_2_RED
394         {0x3518, 0x212B}, //SECOND_DERIV_ZONE_3_RED
395         {0x3520, 0x1F2A}, //SECOND_DERIV_ZONE_4_RED
396         {0x3528, 0x2934}, //SECOND_DERIV_ZONE_5_RED
397         {0x3530, 0x17DB}, //SECOND_DERIV_ZONE_6_RED
398         {0x3538, 0xE7D6}, //SECOND_DERIV_ZONE_7_RED
399         {0x354C, 0x07C6}, //K_FACTOR_IN_K_FX_FY_R_TL
400         {0x3544, 0x07FF}, //K_FACTOR_IN_K_FX_FY_R_TR
401         {0x355C, 0x051C}, //K_FACTOR_IN_K_FX_FY_R_BL
402         {0x3554, 0x07FF}, //K_FACTOR_IN_K_FX_FY_R_BR
403         {0x34E0, 0x0137}, //FX_GREEN
404         {0x34E8, 0x00A8}, //FY_GREEN
405         {0x34F0, 0x0E3E}, //DF_DX_GREEN
406         {0x34F8, 0x0DCB}, //DF_DY_GREEN
407         {0x3502, 0xF20A}, //SECOND_DERIV_ZONE_0_GREEN
408         {0x350A, 0xFBE1}, //SECOND_DERIV_ZONE_1_GREEN
409         {0x3512, 0x1C26}, //SECOND_DERIV_ZONE_2_GREEN
410         {0x351A, 0x232B}, //SECOND_DERIV_ZONE_3_GREEN
411         {0x3522, 0x312E}, //SECOND_DERIV_ZONE_4_GREEN
412         {0x352A, 0x2121}, //SECOND_DERIV_ZONE_5_GREEN
413         {0x3532, 0xF106}, //SECOND_DERIV_ZONE_6_GREEN
414         {0x353A, 0x0C0D}, //SECOND_DERIV_ZONE_7_GREEN
415         {0x354E, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G1_TL
416         {0x3546, 0x0638}, //K_FACTOR_IN_K_FX_FY_G1_TR
417         {0x355E, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G1_BL
418         {0x3556, 0x0155}, //K_FACTOR_IN_K_FX_FY_G1_BR
419         {0x34E4, 0x0107}, //FX_BLUE
420         {0x34EC, 0x0079}, //FY_BLUE
421         {0x34F4, 0x0E19}, //DF_DX_BLUE
422         {0x34FC, 0x0D35}, //DF_DY_BLUE
423         {0x3506, 0x111C}, //SECOND_DERIV_ZONE_0_BLUE
424         {0x350E, 0x02E6}, //SECOND_DERIV_ZONE_1_BLUE
425         {0x3516, 0x2521}, //SECOND_DERIV_ZONE_2_BLUE
426         {0x351E, 0x2620}, //SECOND_DERIV_ZONE_3_BLUE
427         {0x3526, 0x1A25}, //SECOND_DERIV_ZONE_4_BLUE
428         {0x352E, 0x0B1D}, //SECOND_DERIV_ZONE_5_BLUE
429         {0x3536, 0xFD03}, //SECOND_DERIV_ZONE_6_BLUE
430         {0x353E, 0xB315}, //SECOND_DERIV_ZONE_7_BLUE
431         {0x3552, 0x06D0}, //K_FACTOR_IN_K_FX_FY_B_TL
432         {0x354A, 0x03FF}, //K_FACTOR_IN_K_FX_FY_B_TR
433         {0x3562, 0x07FF}, //K_FACTOR_IN_K_FX_FY_B_BL
434         {0x355A, 0x057B}, //K_FACTOR_IN_K_FX_FY_B_BR
435         {0x34E2, 0x011E}, //FX_GREEN2
436         {0x34EA, 0x008A}, //FY_GREEN2
437         {0x34F2, 0x0D6E}, //DF_DX_GREEN2
438         {0x34FA, 0x0D7F}, //DF_DY_GREEN2
439         {0x3504, 0xF822}, //SECOND_DERIV_ZONE_0_GREEN2
440         {0x350C, 0x0DFC}, //SECOND_DERIV_ZONE_1_GREEN2
441         {0x3514, 0x1F25}, //SECOND_DERIV_ZONE_2_GREEN2
442         {0x351C, 0x3032}, //SECOND_DERIV_ZONE_3_GREEN2
443         {0x3524, 0x2628}, //SECOND_DERIV_ZONE_4_GREEN2
444         {0x352C, 0x1523}, //SECOND_DERIV_ZONE_5_GREEN2
445         {0x3534, 0xFADF}, //SECOND_DERIV_ZONE_6_GREEN2
446         {0x353C, 0xDEF7}, //SECOND_DERIV_ZONE_7_GREEN2
447         {0x3550, 0x0109}, //K_FACTOR_IN_K_FX_FY_G2_TL
448         {0x3548, 0x0638}, //K_FACTOR_IN_K_FX_FY_G2_TR
449         {0x3560, 0x0638}, //K_FACTOR_IN_K_FX_FY_G2_BL
450         {0x3558, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G2_BR
451         {0x3540, 0x0000}, //X2_FACTORS
452         {0x3542, 0x0000}, //GLOBAL_OFFSET_FXY_FUNCTION
453         {0x3210, 0x01FC},       // COLOR_PIPELINE_CONTROL
454         //CCM
455         //CCM
456         {0x338C, 0xA364},       // MCU_ADDRESS [AWB_KR_L]
457         {0x3390, 0x0080},       // MCU_DATA_0
458         {0x338C, 0xA364},       // MCU_ADDRESS [AWB_KR_L]
459         {0x3390, 0x0080},       // MCU_DATA_0
460         {0x338C, 0xA365},       // MCU_ADDRESS [AWB_KG_L]
461         {0x3390, 0x008C},       // MCU_DATA_0
462         {0x338C, 0xA365},       // MCU_ADDRESS [AWB_KG_L]
463         {0x3390, 0x008C},       // MCU_DATA_0
464         {0x338C, 0xA366},       // MCU_ADDRESS [AWB_KB_L]
465         {0x3390, 0x0082},       // MCU_DATA_0
466         {0x338C, 0xA366},       // MCU_ADDRESS [AWB_KB_L]
467         {0x3390, 0x0082},       // MCU_DATA_0
468         {0x338C, 0x2306},       // MCU_ADDRESS [AWB_CCM_L_0]
469         {0x3390, 0x0619},       // MCU_DATA_0
470         {0x338C, 0x2308},       // MCU_ADDRESS [AWB_CCM_L_1]
471         {0x3390, 0xFC80},       // MCU_DATA_0
472         {0x338C, 0x230A},       // MCU_ADDRESS [AWB_CCM_L_2]
473         {0x3390, 0xFEFB},       // MCU_DATA_0
474         {0x338C, 0x230C},       // MCU_ADDRESS [AWB_CCM_L_3]
475         {0x3390, 0xFEEE},       // MCU_DATA_0
476         {0x338C, 0x230E},       // MCU_ADDRESS [AWB_CCM_L_4]
477         {0x3390, 0x0571},       // MCU_DATA_0
478         {0x338C, 0x2310},       // MCU_ADDRESS [AWB_CCM_L_5]
479         {0x3390, 0xFE26},       // MCU_DATA_0
480         {0x338C, 0x2312},       // MCU_ADDRESS [AWB_CCM_L_6]
481         {0x3390, 0xFF0C},       // MCU_DATA_0
482         {0x338C, 0x2314},       // MCU_ADDRESS [AWB_CCM_L_7]
483         {0x3390, 0xFE48},       // MCU_DATA_0
484         {0x338C, 0x2316},       // MCU_ADDRESS [AWB_CCM_L_8]
485         {0x3390, 0x04A2},       // MCU_DATA_0
486         {0x338C, 0x2318},       // MCU_ADDRESS [AWB_CCM_L_9]
487         {0x3390, 0x0024},       // MCU_DATA_0
488         {0x338C, 0x231A},       // MCU_ADDRESS [AWB_CCM_L_10]
489         {0x3390, 0x003F},       // MCU_DATA_0
490         {0x338C, 0x231C},       // MCU_ADDRESS [AWB_CCM_RL_0]
491         {0x3390, 0xFDA7},       // MCU_DATA_0
492         {0x338C, 0x231E},       // MCU_ADDRESS [AWB_CCM_RL_1]
493         {0x3390, 0x0158},       // MCU_DATA_0
494         {0x338C, 0x2320},       // MCU_ADDRESS [AWB_CCM_RL_2]
495         {0x3390, 0x00EE},       // MCU_DATA_0
496         {0x338C, 0x2322},       // MCU_ADDRESS [AWB_CCM_RL_3]
497         {0x3390, 0x00D3},       // MCU_DATA_0
498         {0x338C, 0x2324},       // MCU_ADDRESS [AWB_CCM_RL_4]
499         {0x3390, 0xFC74},       // MCU_DATA_0
500         {0x338C, 0x2326},       // MCU_ADDRESS [AWB_CCM_RL_5]
501         {0x3390, 0x01A9},       // MCU_DATA_0
502         {0x338C, 0x2328},       // MCU_ADDRESS [AWB_CCM_RL_6]
503         {0x3390, 0x014B},       // MCU_DATA_0
504         {0x338C, 0x232A},       // MCU_ADDRESS [AWB_CCM_RL_7]
505         {0x3390, 0xFE9D},       // MCU_DATA_0
506         {0x338C, 0x232C},       // MCU_ADDRESS [AWB_CCM_RL_8]
507         {0x3390, 0xFF69},       // MCU_DATA_0
508         {0x338C, 0x232E},       // MCU_ADDRESS [AWB_CCM_RL_9]
509         {0x3390, 0x0018},       // MCU_DATA_0
510         {0x338C, 0x2330},       // MCU_ADDRESS [AWB_CCM_RL_10]
511         {0x3390, 0xFFEC},       // MCU_DATA_0
512         {0x338C, 0xA348},       // MCU_ADDRESS [AWB_GAIN_BUFFER_SPEED]
513         {0x3390, 0x0008},       // MCU_DATA_0
514         {0x338C, 0xA349},       // MCU_ADDRESS [AWB_JUMP_DIVISOR]
515         {0x3390, 0x0002},       // MCU_DATA_0
516         {0x338C, 0xA34A},       // MCU_ADDRESS [AWB_GAIN_MIN]
517         {0x3390, 0x0059},       // MCU_DATA_0
518         {0x338C, 0xA34B},       // MCU_ADDRESS [AWB_GAIN_MAX]
519         {0x3390, 0x00A6},       // MCU_DATA_0
520         {0x338C, 0xA34F},       // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
521         {0x3390, 0x0000},       // MCU_DATA_0
522         {0x338C, 0xA350},       // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
523         {0x3390, 0x007F},       // MCU_DATA_0
524         {0x338C, 0xA353},       // MCU_ADDRESS [AWB_MODE]
525         {0x3390, 0x0002},       // MCU_DATA_0
526         {0x338C, 0xA35B},       // MCU_ADDRESS [AWB_STEADY_BGAIN_OUT_MIN]
527         {0x3390, 0x0078},       // MCU_DATA_0
528         {0x338C, 0xA35C},       // MCU_ADDRESS [AWB_STEADY_BGAIN_OUT_MAX]
529         {0x3390, 0x0086},       // MCU_DATA_0
530         {0x338C, 0xA35D},       // MCU_ADDRESS [AWB_STEADY_BGAIN_IN_MIN]
531         {0x3390, 0x007E},       // MCU_DATA_0
532         {0x338C, 0xA35E},       // MCU_ADDRESS [AWB_STEADY_BGAIN_IN_MAX]
533         {0x3390, 0x0082},       // MCU_DATA_0
534         {0x338C, 0x235F},       // MCU_ADDRESS [AWB_CNT_PXL_TH]
535         {0x3390, 0x0040},       // MCU_DATA_0
536         {0x338C, 0xA361},       // MCU_ADDRESS [AWB_TG_MIN0]
537         {0x3390, 0x00C8},       // MCU_DATA_0
538         {0x338C, 0xA362},       // MCU_ADDRESS [AWB_TG_MAX0]
539         {0x3390, 0x00E1},       // MCU_DATA_0
540         {0x338C, 0xA302},       // MCU_ADDRESS [AWB_WINDOW_POS]
541         {0x3390, 0x0000},       // MCU_DATA_0
542         {0x338C, 0xA303},       // MCU_ADDRESS [AWB_WINDOW_SIZE]
543         {0x3390, 0x00EF},       // MCU_DATA_0
544         {0x338C, 0xA352},       // MCU_ADDRESS [AWB_SATURATION]
545         {0x3390, 0x001E},       // MCU_DATA_0
546         {0x338C, 0xA118},       // MCU_ADDRESS [SEQ_LLSAT1]
547         {0x3390, 0x001E},       // MCU_DATA_0
548         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
549         {0x3390, 0x0005},       // MCU_DATA_0
550          //Contrast
551         {0x338C, 0xA76D},       // MCU_ADDRESS [MODE_GAM_CONT_A]
552         {0x3390, 0x0003},       // MCU_DATA_0
553         {0x338C, 0xA76F},       // MCU_ADDRESS [MODE_GAM_TABLE_A_0]
554         {0x3390, 0x0000},       // MCU_DATA_0
555         {0x338C, 0xA770},       // MCU_ADDRESS [MODE_GAM_TABLE_A_1]
556         {0x3390, 0x000B},       // MCU_DATA_0
557         {0x338C, 0xA771},       // MCU_ADDRESS [MODE_GAM_TABLE_A_2]
558         {0x3390, 0x0023},       // MCU_DATA_0
559         {0x338C, 0xA772},       // MCU_ADDRESS [MODE_GAM_TABLE_A_3]
560         {0x3390, 0x0043},       // MCU_DATA_0
561         {0x338C, 0xA773},       // MCU_ADDRESS [MODE_GAM_TABLE_A_4]
562         {0x3390, 0x006E},       // MCU_DATA_0
563         {0x338C, 0xA774},       // MCU_ADDRESS [MODE_GAM_TABLE_A_5]
564         {0x3390, 0x0090},       // MCU_DATA_0
565         {0x338C, 0xA775},       // MCU_ADDRESS [MODE_GAM_TABLE_A_6]
566         {0x3390, 0x00A8},       // MCU_DATA_0
567         {0x338C, 0xA776},       // MCU_ADDRESS [MODE_GAM_TABLE_A_7]
568         {0x3390, 0x00B9},       // MCU_DATA_0
569         {0x338C, 0xA777},       // MCU_ADDRESS [MODE_GAM_TABLE_A_8]
570         {0x3390, 0x00C6},       // MCU_DATA_0
571         {0x338C, 0xA778},       // MCU_ADDRESS [MODE_GAM_TABLE_A_9]
572         {0x3390, 0x00D0},       // MCU_DATA_0
573         {0x338C, 0xA779},       // MCU_ADDRESS [MODE_GAM_TABLE_A_10]
574         {0x3390, 0x00D9},       // MCU_DATA_0
575         {0x338C, 0xA77A},       // MCU_ADDRESS [MODE_GAM_TABLE_A_11]
576         {0x3390, 0x00E0},       // MCU_DATA_0
577         {0x338C, 0xA77B},       // MCU_ADDRESS [MODE_GAM_TABLE_A_12]
578         {0x3390, 0x00E6},       // MCU_DATA_0
579         {0x338C, 0xA77C},       // MCU_ADDRESS [MODE_GAM_TABLE_A_13]
580         {0x3390, 0x00EB},       // MCU_DATA_0
581         {0x338C, 0xA77D},       // MCU_ADDRESS [MODE_GAM_TABLE_A_14]
582         {0x3390, 0x00F0},       // MCU_DATA_0
583         {0x338C, 0xA77E},       // MCU_ADDRESS [MODE_GAM_TABLE_A_15]
584         {0x3390, 0x00F4},       // MCU_DATA_0
585         {0x338C, 0xA77F},       // MCU_ADDRESS [MODE_GAM_TABLE_A_16]
586         {0x3390, 0x00F8},       // MCU_DATA_0
587         {0x338C, 0xA780},       // MCU_ADDRESS [MODE_GAM_TABLE_A_17]
588         {0x3390, 0x00FC},       // MCU_DATA_0
589         {0x338C, 0xA781},       // MCU_ADDRESS [MODE_GAM_TABLE_A_18]
590         {0x3390, 0x00FF},       // MCU_DATA_0
591         //  into outdoor mode
592         {0x338C, 0xA102},       // MCU_ADDRESS
593         {0x3390, 0x002F},       // MCU_DATA_0
594         {0x338C, 0xA114},       // MCU_ADDRESS
595         {0x3390, 0x0005},       // MCU_DATA_0
596         {SEQUENCE_WAIT_MS, 20},
597         {0x338C, 0xA103},  // MCU_ADDRESS
598         {0x3390, 0x0005},  // MCU_DATA_0
599         //Exposure
600         {0x338C, 0xA206},       // MCU_ADDRESS [AE_TARGET]
601         {0x3390, 0x003C},       // MCU_DATA_0
602         {SEQUENCE_END, 0x00}
603 };
604
605 /* 720p 15fps @ 1280x720 */
606
607 static struct reginfo sensor_720p[]=
608 {
609         {SEQUENCE_END, 0x00}
610 };
611
612 /*      1080p, 0x15fps, 0xyuv @1920x1080 */
613
614 static struct reginfo sensor_1080p[]=
615 {
616         {SEQUENCE_END, 0x00}
617 };
618
619 /* 2592X1944 QSXGA */
620 static struct reginfo sensor_qsxga[] =
621 {
622         {SEQUENCE_END, 0x00}
623 };
624 /* 2048*1536 QXGA */
625 static struct reginfo sensor_qxga[] =
626 {
627         {SEQUENCE_END, 0x00}
628 };
629
630 /* 1600X1200 UXGA */
631 static struct reginfo sensor_uxga[] =
632 {
633         {SEQUENCE_PROPERTY, SEQUENCE_CAPTURE},
634         {0x338C, 0x275F},
635         {0x3390, 0x0000},
636         {0x338C, 0x2761},
637         {0x3390, 0x0640},
638         {0x338C, 0x2763},
639         {0x3390, 0x0000},
640         {0x338C, 0x2765},
641         {0x3390, 0x04B0},
642         {0x338C, 0x2707},
643         {0x3390, 0x0640},
644         {0x338C, 0x2709},
645         {0x3390, 0x04B0},
646         {0x338C, 0xA103},
647         {0x3390, 0x0005},
648         {SEQUENCE_END, 0x00}
649 };
650 /* 1280X1024 SXGA */
651 static struct reginfo sensor_sxga[] =
652 {
653         {SEQUENCE_PROPERTY, SEQUENCE_CAPTURE},
654         {0x338C, 0x275F},
655         {0x3390, 0x0000},
656         {0x338C, 0x2761},
657         {0x3390, 0x0640},
658         {0x338C, 0x2763},
659         {0x3390, 0x0000},
660         {0x338C, 0x2765},
661         {0x3390, 0x04B0},
662         {0x338C, 0x2707},
663         {0x3390, 0x0500},
664         {0x338C, 0x2709},
665         {0x3390, 0x0400},
666         {0x338C, 0xA103},
667         {0x3390, 0x0005},
668         {SEQUENCE_END, 0x00}
669 };
670 /*  1024X768 XGA */
671 static struct reginfo sensor_xga[] =
672 {
673         {SEQUENCE_END, 0x00}
674 };
675
676 /* 800X600 SVGA*/
677 static struct reginfo sensor_svga[] =
678 {
679         {SEQUENCE_END, 0x00}
680 };
681
682 /* 640X480 VGA */
683 static struct reginfo sensor_vga[] =
684 {
685     {SEQUENCE_END, 0x00}
686 };
687
688 /* 352X288 CIF */
689 static struct reginfo sensor_cif[] =
690 {
691         {SEQUENCE_END, 0x00}
692 };
693
694 /* 320*240 QVGA */
695 static  struct reginfo sensor_qvga[] =
696 {
697         {SEQUENCE_END, 0x00}
698 };
699
700 /* 176X144 QCIF*/
701 static struct reginfo sensor_qcif[] =
702 {
703         {SEQUENCE_END, 0x00}
704 };
705 #if 0
706 /* 160X120 QQVGA*/
707 static struct reginfo ov2655_qqvga[] =
708 {
709
710     {0x300E, 0x34},
711     {0x3011, 0x01},
712     {0x3012, 0x10},
713     {0x302a, 0x02},
714     {0x302b, 0xE6},
715     {0x306f, 0x14},
716     {0x3362, 0x90},
717
718     {0x3070, 0x5d},
719     {0x3072, 0x5d},
720     {0x301c, 0x07},
721     {0x301d, 0x07},
722
723     {0x3020, 0x01},
724     {0x3021, 0x18},
725     {0x3022, 0x00},
726     {0x3023, 0x06},
727     {0x3024, 0x06},
728     {0x3025, 0x58},
729     {0x3026, 0x02},
730     {0x3027, 0x61},
731     {0x3088, 0x00},
732     {0x3089, 0xa0},
733     {0x308a, 0x00},
734     {0x308b, 0x78},
735     {0x3316, 0x64},
736     {0x3317, 0x25},
737     {0x3318, 0x80},
738     {0x3319, 0x08},
739     {0x331a, 0x0a},
740     {0x331b, 0x07},
741     {0x331c, 0x80},
742     {0x331d, 0x38},
743     {0x3100, 0x00},
744     {0x3302, 0x11},
745
746     {0x0, 0x0},
747 };
748
749
750
751 static  struct reginfo ov2655_Sharpness_auto[] =
752 {
753     {0x3306, 0x00},
754 };
755
756 static  struct reginfo ov2655_Sharpness1[] =
757 {
758     {0x3306, 0x08},
759     {0x3371, 0x00},
760 };
761
762 static  struct reginfo ov2655_Sharpness2[][3] =
763 {
764     //Sharpness 2
765     {0x3306, 0x08},
766     {0x3371, 0x01},
767 };
768
769 static  struct reginfo ov2655_Sharpness3[] =
770 {
771     //default
772     {0x3306, 0x08},
773     {0x332d, 0x02},
774 };
775 static  struct reginfo ov2655_Sharpness4[]=
776 {
777     //Sharpness 4
778     {0x3306, 0x08},
779     {0x332d, 0x03},
780 };
781
782 static  struct reginfo ov2655_Sharpness5[] =
783 {
784     //Sharpness 5
785     {0x3306, 0x08},
786     {0x332d, 0x04},
787 };
788 #endif
789
790 static  struct reginfo sensor_Preview2Capture[]=
791 {
792         {0x338C, 0xA120},       // MCU_ADDRESS [SEQ_CAP_MODE]
793         {0x3390, 0x0002},       // MCU_DATA_0
794         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
795         {0x3390, 0x0002},       // MCU_DATA_0
796     {0x338C, 0xA102},   // MCU_ADDRESS [SEQ_CMD]  cgz oppo 2008-09-26
797         {0x3390, 0x000E},
798         {SEQUENCE_END, 0x00}
799 };
800
801 static  struct reginfo sensor_Capture2Preview[]=
802 {
803         {0x338C, 0xA120},       // MCU_ADDRESS [SEQ_CAP_MODE]
804         {0x3390, 0x0000},       // MCU_DATA_0
805         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
806         {0x3390, 0x0001},       // MCU_DATA_0
807         {SEQUENCE_END, 0x00}
808 };
809
810 static  struct reginfo sensor_ClrFmt_YUYV[]=
811 {
812         {SEQUENCE_END, 0x00}
813 };
814
815 static  struct reginfo sensor_ClrFmt_UYVY[]=
816 {
817         {SEQUENCE_END, 0x00}
818 };
819
820
821 #if CONFIG_SENSOR_WhiteBalance
822 static  struct reginfo sensor_WhiteB_Auto[]=
823 {
824         //Auto
825         {0x338C, 0xA34A},       // MCU_ADDRESS [AWB_GAIN_MIN]
826         {0x3390, 0x0059},       // MCU_DATA_0
827         {0x338C, 0xA34B},       // MCU_ADDRESS [AWB_GAIN_MAX]
828         {0x3390, 0x00A6},       // MCU_DATA_0
829         {0x338C, 0xA34F},       // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
830         {0x3390, 0x0000},       // MCU_DATA_0
831         {0x338C, 0xA350},       // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
832         {0x3390, 0x007F},       // MCU_DATA_0
833         {SEQUENCE_END, 0x00}
834 };
835 /* Cloudy Colour Temperature : 6500K - 8000K  */
836 static  struct reginfo sensor_WhiteB_Cloudy[]=
837 {
838         //[V.       DL 7500]
839         {0x338C, 0xA34B},       // MCU_ADDRESS [AWB_GAIN_MAX]
840         {0x3390, 0x0080},       // MCU_DATA_0
841         {0x338C, 0xA34F},       // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
842         {0x3390, 0x007F},       // MCU_DATA_0
843         {0x338C, 0xA350},       // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
844         {0x3390, 0x007F},       // MCU_DATA_
845         {SEQUENCE_END, 0x00}
846 };
847 /* ClearDay Colour Temperature : 5000K - 6500K  */
848 static  struct reginfo sensor_WhiteB_ClearDay[]=
849 {
850         //[IV       Day Light]
851         {0x338C, 0xA34A},       // MCU_ADDRESS [AWB_GAIN_MIN]
852         {0x3390, 0x0080},       // MCU_DATA_0
853         {0x338C, 0xA34B},       // MCU_ADDRESS [AWB_GAIN_MAX]
854         {0x3390, 0x0080},       // MCU_DATA_0
855         {0x338C, 0xA34F},       // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
856         {0x3390, 0x007E},        // MCU_DATA_0
857         {0x338C, 0xA350},       // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
858         {0x3390, 0x007E},        // MCU_DATA_0
859         {SEQUENCE_END, 0x00}
860 };
861 /* Office Colour Temperature : 3500K - 5000K  */
862 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
863 {
864         //[III        Fluorescent]
865         {0x338C, 0xA34A},  // MCU_ADDRESS [AWB_GAIN_MIN]
866         {0x3390, 0x0080},  // MCU_DATA_0
867         {0x338C, 0xA34B},  // MCU_ADDRESS [AWB_GAIN_MAX]
868         {0x3390, 0x0080},  // MCU_DATA_0
869         {0x338C, 0xA34F},  // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
870         {0x3390, 0x0030},   // MCU_DATA_0
871         {0x338C, 0xA350},  // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
872         {0x3390, 0x0030},   // MCU_DATA_0
873         {SEQUENCE_END, 0x00}
874 };
875 /* Home Colour Temperature : 2500K - 3500K  */
876 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
877 {
878         //[II.        Incandescent]
879         {0x338C, 0xA34A},       // MCU_ADDRESS [AWB_GAIN_MIN]
880         {0x3390, 0x0080},       // MCU_DATA_0
881         {0x338C, 0xA34B},       // MCU_ADDRESS [AWB_GAIN_MAX]
882         {0x3390, 0x0080},       // MCU_DATA_0
883         {0x338C, 0xA34F},       // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
884         {0x3390, 0x0032},        // MCU_DATA_0
885         {0x338C, 0xA350},       // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
886         {0x3390, 0x0032},        // MCU_DATA_0
887         {SEQUENCE_END, 0x00}
888 };
889 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
890     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
891 };
892 #endif
893
894 #if CONFIG_SENSOR_Brightness
895 static  struct reginfo sensor_Brightness0[]=
896 {
897         {SEQUENCE_END, 0x00}
898 };
899
900 static  struct reginfo sensor_Brightness1[]=
901 {
902         {SEQUENCE_END, 0x00}
903 };
904
905 static  struct reginfo sensor_Brightness2[]=
906 {
907         {SEQUENCE_END, 0x00}
908 };
909
910 static  struct reginfo sensor_Brightness3[]=
911 {
912         {SEQUENCE_END, 0x00}
913 };
914
915 static  struct reginfo sensor_Brightness4[]=
916 {
917         {SEQUENCE_END, 0x00}
918 };
919
920 static  struct reginfo sensor_Brightness5[]=
921 {
922         {SEQUENCE_END, 0x00}
923 };
924 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
925     sensor_Brightness4, sensor_Brightness5,NULL,
926 };
927
928 #endif
929
930 #if CONFIG_SENSOR_Effect
931 static  struct reginfo sensor_Effect_Normal[] =
932 {
933         {0x338C, 0x2799},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
934         {0x3390, 0x6408},       // MCU_DATA_0
935         {0x338C, 0x279B},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
936         {0x3390, 0x6408},       // MCU_DATA_0
937         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
938         {0x3390, 0x0005},       // MCU_DATA_0
939         {SEQUENCE_END, 0x00}
940 };
941
942 static  struct reginfo sensor_Effect_WandB[] =
943 {
944         {0x338C, 0x2799},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
945         {0x3390, 0x6409},       // MCU_DATA_0
946         {0x338C, 0x279B},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
947         {0x3390, 0x6409},       // MCU_DATA_0
948         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
949         {0x3390, 0x0005},       // MCU_DATA_0
950         {SEQUENCE_END, 0x00}
951 };
952
953 static  struct reginfo sensor_Effect_Sepia[] =
954 {
955         {0x338C, 0x2799},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
956         {0x3390, 0x640A},       // MCU_DATA_0
957         {0x338C, 0x279B},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
958         {0x3390, 0x640A},       // MCU_DATA_0
959         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
960         {0x3390, 0x0005},       // MCU_DATA_0
961         {SEQUENCE_END, 0x00}
962 };
963
964 static  struct reginfo sensor_Effect_Negative[] =
965 {
966         {0x338C, 0x2799},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
967         {0x3390, 0x640B},       // MCU_DATA_0
968         {0x338C, 0x279B},       // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
969         {0x3390, 0x640B},       // MCU_DATA_0
970         {0x338C, 0xA103},       // MCU_ADDRESS [SEQ_CMD]
971         {0x3390, 0x0005},       // MCU_DATA_0
972         {SEQUENCE_END, 0x00}
973 };
974 static  struct reginfo sensor_Effect_Bluish[] =
975 {
976         {SEQUENCE_END, 0x00}
977 };
978
979 static  struct reginfo sensor_Effect_Green[] =
980 {
981         {SEQUENCE_END, 0x00}
982 };
983
984 static struct reginfo sensor_Effect_Solarize[] =
985 {
986         {SEQUENCE_END, 0x00}
987 };
988 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Sepia,sensor_Effect_Negative,
989     NULL,
990 };
991 #endif
992 #if CONFIG_SENSOR_Exposure
993 static  struct reginfo sensor_Exposure0[]=
994 {
995         {SEQUENCE_END, 0x00}
996 };
997
998 static  struct reginfo sensor_Exposure1[]=
999 {
1000         {SEQUENCE_END, 0x00}
1001 };
1002
1003 static  struct reginfo sensor_Exposure2[]=
1004 {
1005         {SEQUENCE_END, 0x00}
1006 };
1007
1008 static  struct reginfo sensor_Exposure3[]=
1009 {
1010         {SEQUENCE_END, 0x00}
1011 };
1012
1013 static  struct reginfo sensor_Exposure4[]=
1014 {
1015         {SEQUENCE_END, 0x00}
1016 };
1017
1018 static  struct reginfo sensor_Exposure5[]=
1019 {
1020         {SEQUENCE_END, 0x00}
1021 };
1022
1023 static  struct reginfo sensor_Exposure6[]=
1024 {
1025         {SEQUENCE_END, 0x00}
1026 };
1027
1028 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1029     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1030 };
1031 #endif
1032 #if CONFIG_SENSOR_Saturation
1033 static  struct reginfo sensor_Saturation0[]=
1034 {
1035         {SEQUENCE_END, 0x00}
1036 };
1037
1038 static  struct reginfo sensor_Saturation1[]=
1039 {
1040         {SEQUENCE_END, 0x00}
1041 };
1042
1043 static  struct reginfo sensor_Saturation2[]=
1044 {
1045         {SEQUENCE_END, 0x00}
1046 };
1047 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1048
1049 #endif
1050 #if CONFIG_SENSOR_Contrast
1051 static  struct reginfo sensor_Contrast0[]=
1052 {
1053         {SEQUENCE_END, 0x00}
1054 };
1055
1056 static  struct reginfo sensor_Contrast1[]=
1057 {
1058         {SEQUENCE_END, 0x00}
1059 };
1060
1061 static  struct reginfo sensor_Contrast2[]=
1062 {
1063         {SEQUENCE_END, 0x00}
1064 };
1065
1066 static  struct reginfo sensor_Contrast3[]=
1067 {
1068         {SEQUENCE_END, 0x00}
1069 };
1070
1071 static  struct reginfo sensor_Contrast4[]=
1072 {
1073         {SEQUENCE_END, 0x00}
1074 };
1075
1076
1077 static  struct reginfo sensor_Contrast5[]=
1078 {
1079         {SEQUENCE_END, 0x00}
1080 };
1081
1082 static  struct reginfo sensor_Contrast6[]=
1083 {
1084         {SEQUENCE_END, 0x00}
1085 };
1086 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1087     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1088 };
1089
1090 #endif
1091 #if CONFIG_SENSOR_Mirror
1092 static  struct reginfo sensor_MirrorOn[]=
1093 {
1094         {SEQUENCE_END, 0x00}
1095 };
1096
1097 static  struct reginfo sensor_MirrorOff[]=
1098 {
1099         {SEQUENCE_END, 0x00}
1100 };
1101 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1102 #endif
1103 #if CONFIG_SENSOR_Flip
1104 static  struct reginfo sensor_FlipOn[]=
1105 {
1106         {SEQUENCE_END, 0x00}
1107 };
1108
1109 static  struct reginfo sensor_FlipOff[]=
1110 {
1111         {SEQUENCE_END, 0x00}
1112 };
1113 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1114
1115 #endif
1116 #if CONFIG_SENSOR_Scene
1117 static  struct reginfo sensor_SceneAuto[] =
1118 {
1119         {0x338C, 0xA102},         // MCU_ADDRESS
1120         {0x3390, 0x002F},         // MCU_DATA_0
1121         {0x338C, 0xA114},         // MCU_ADDRESS
1122         {0x3390, 0x0005},         // MCU_DATA_0
1123         {SEQUENCE_WAIT_MS, 20},
1124         {0x338C, 0xA103},  // MCU_ADDRESS
1125         {0x3390, 0x0005},  // MCU_DATA_0
1126         {SEQUENCE_END, 0x00}
1127 };
1128
1129 static  struct reginfo sensor_SceneNight[] =
1130 {
1131         {0x338C, 0xA102},     // MCU_ADDRESS
1132         {0x3390, 0x000F},     // MCU_DATA_0
1133         {SEQUENCE_WAIT_MS, 20},
1134         {0x338C, 0xA103},  // MCU_ADDRESS
1135         {0x3390, 0x0005},  // MCU_DATA_0
1136         {SEQUENCE_END, 0x00}
1137 };
1138 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1139
1140 #endif
1141 #if CONFIG_SENSOR_DigitalZoom
1142 static struct reginfo sensor_Zoom0[] =
1143 {
1144         {SEQUENCE_END, 0x00}
1145 };
1146
1147 static struct reginfo sensor_Zoom1[] =
1148 {
1149         {SEQUENCE_END, 0x00}
1150 };
1151
1152 static struct reginfo sensor_Zoom2[] =
1153 {
1154         {SEQUENCE_END, 0x00}
1155 };
1156
1157
1158 static struct reginfo sensor_Zoom3[] =
1159 {
1160         {SEQUENCE_END, 0x00}
1161 };
1162 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
1163 #endif
1164 static const struct v4l2_querymenu sensor_menus[] =
1165 {
1166         #if CONFIG_SENSOR_WhiteBalance
1167     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
1168     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
1169     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
1170     #endif
1171
1172         #if CONFIG_SENSOR_Effect
1173     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "mono",  .reserved = 0,},
1174     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "negative", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "sepia", .reserved = 0,},
1175     #endif
1176
1177         #if CONFIG_SENSOR_Scene
1178     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
1179     #endif
1180
1181         #if CONFIG_SENSOR_Flash
1182     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
1183     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
1184     #endif
1185 };
1186
1187 static const struct v4l2_queryctrl sensor_controls[] =
1188 {
1189         #if CONFIG_SENSOR_WhiteBalance
1190     {
1191         .id             = V4L2_CID_DO_WHITE_BALANCE,
1192         .type           = V4L2_CTRL_TYPE_MENU,
1193         .name           = "White Balance Control",
1194         .minimum        = 0,
1195         .maximum        = 4,
1196         .step           = 1,
1197         .default_value = 0,
1198     },
1199     #endif
1200
1201         #if CONFIG_SENSOR_Brightness
1202         {
1203         .id             = V4L2_CID_BRIGHTNESS,
1204         .type           = V4L2_CTRL_TYPE_INTEGER,
1205         .name           = "Brightness Control",
1206         .minimum        = -3,
1207         .maximum        = 2,
1208         .step           = 1,
1209         .default_value = 0,
1210     },
1211     #endif
1212
1213         #if CONFIG_SENSOR_Effect
1214         {
1215         .id             = V4L2_CID_EFFECT,
1216         .type           = V4L2_CTRL_TYPE_MENU,
1217         .name           = "Effect Control",
1218         .minimum        = 0,
1219         .maximum        = 3,
1220         .step           = 1,
1221         .default_value = 0,
1222     },
1223         #endif
1224
1225         #if CONFIG_SENSOR_Exposure
1226         {
1227         .id             = V4L2_CID_EXPOSURE,
1228         .type           = V4L2_CTRL_TYPE_INTEGER,
1229         .name           = "Exposure Control",
1230         .minimum        = 0,
1231         .maximum        = 6,
1232         .step           = 1,
1233         .default_value = 0,
1234     },
1235         #endif
1236
1237         #if CONFIG_SENSOR_Saturation
1238         {
1239         .id             = V4L2_CID_SATURATION,
1240         .type           = V4L2_CTRL_TYPE_INTEGER,
1241         .name           = "Saturation Control",
1242         .minimum        = 0,
1243         .maximum        = 2,
1244         .step           = 1,
1245         .default_value = 0,
1246     },
1247     #endif
1248
1249         #if CONFIG_SENSOR_Contrast
1250         {
1251         .id             = V4L2_CID_CONTRAST,
1252         .type           = V4L2_CTRL_TYPE_INTEGER,
1253         .name           = "Contrast Control",
1254         .minimum        = -3,
1255         .maximum        = 3,
1256         .step           = 1,
1257         .default_value = 0,
1258     },
1259         #endif
1260
1261         #if CONFIG_SENSOR_Mirror
1262         {
1263         .id             = V4L2_CID_HFLIP,
1264         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1265         .name           = "Mirror Control",
1266         .minimum        = 0,
1267         .maximum        = 1,
1268         .step           = 1,
1269         .default_value = 1,
1270     },
1271     #endif
1272
1273         #if CONFIG_SENSOR_Flip
1274         {
1275         .id             = V4L2_CID_VFLIP,
1276         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1277         .name           = "Flip Control",
1278         .minimum        = 0,
1279         .maximum        = 1,
1280         .step           = 1,
1281         .default_value = 1,
1282     },
1283     #endif
1284
1285         #if CONFIG_SENSOR_Scene
1286     {
1287         .id             = V4L2_CID_SCENE,
1288         .type           = V4L2_CTRL_TYPE_MENU,
1289         .name           = "Scene Control",
1290         .minimum        = 0,
1291         .maximum        = 1,
1292         .step           = 1,
1293         .default_value = 0,
1294     },
1295     #endif
1296
1297         #if CONFIG_SENSOR_DigitalZoom
1298     {
1299         .id             = V4L2_CID_ZOOM_RELATIVE,
1300         .type           = V4L2_CTRL_TYPE_INTEGER,
1301         .name           = "DigitalZoom Control",
1302         .minimum        = -1,
1303         .maximum        = 1,
1304         .step           = 1,
1305         .default_value = 0,
1306     }, {
1307         .id             = V4L2_CID_ZOOM_ABSOLUTE,
1308         .type           = V4L2_CTRL_TYPE_INTEGER,
1309         .name           = "DigitalZoom Control",
1310         .minimum        = 0,
1311         .maximum        = 3,
1312         .step           = 1,
1313         .default_value = 0,
1314     },
1315     #endif
1316
1317         #if CONFIG_SENSOR_Focus
1318         {
1319         .id             = V4L2_CID_FOCUS_RELATIVE,
1320         .type           = V4L2_CTRL_TYPE_INTEGER,
1321         .name           = "Focus Control",
1322         .minimum        = -1,
1323         .maximum        = 1,
1324         .step           = 1,
1325         .default_value = 0,
1326     }, {
1327         .id             = V4L2_CID_FOCUS_ABSOLUTE,
1328         .type           = V4L2_CTRL_TYPE_INTEGER,
1329         .name           = "Focus Control",
1330         .minimum        = 0,
1331         .maximum        = 255,
1332         .step           = 1,
1333         .default_value = 125,
1334     },
1335         {
1336         .id             = V4L2_CID_FOCUS_AUTO,
1337         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1338         .name           = "Focus Control",
1339         .minimum        = 0,
1340         .maximum        = 1,
1341         .step           = 1,
1342         .default_value = 0,
1343     },{
1344         .id             = V4L2_CID_FOCUS_CONTINUOUS,
1345         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1346         .name           = "Focus Control",
1347         .minimum        = 0,
1348         .maximum        = 1,
1349         .step           = 1,
1350         .default_value = 0,
1351     },
1352     #endif
1353
1354         #if CONFIG_SENSOR_Flash
1355         {
1356         .id             = V4L2_CID_FLASH,
1357         .type           = V4L2_CTRL_TYPE_MENU,
1358         .name           = "Flash Control",
1359         .minimum        = 0,
1360         .maximum        = 3,
1361         .step           = 1,
1362         .default_value = 0,
1363     },
1364         #endif
1365 };
1366
1367 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1368 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1369 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1370 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1371 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1372 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1373 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1374 static int sensor_resume(struct soc_camera_device *icd);
1375 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1376 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1377 #if CONFIG_SENSOR_Effect
1378 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1379 #endif
1380 #if CONFIG_SENSOR_WhiteBalance
1381 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1382 #endif
1383 static int sensor_deactivate(struct i2c_client *client);
1384 static struct soc_camera_ops sensor_ops =
1385 {
1386     .suspend                     = sensor_suspend,
1387     .resume                       = sensor_resume,
1388     .set_bus_param              = sensor_set_bus_param,
1389     .query_bus_param    = sensor_query_bus_param,
1390     .controls           = sensor_controls,
1391     .menus                         = sensor_menus,
1392     .num_controls               = ARRAY_SIZE(sensor_controls),
1393     .num_menus          = ARRAY_SIZE(sensor_menus),
1394 };
1395 /* only one fixed colorspace per pixelcode */
1396 struct sensor_datafmt {
1397         enum v4l2_mbus_pixelcode code;
1398         enum v4l2_colorspace colorspace;
1399 };
1400
1401 /* Find a data format by a pixel code in an array */
1402 static const struct sensor_datafmt *sensor_find_datafmt(
1403         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1404         int n)
1405 {
1406         int i;
1407         for (i = 0; i < n; i++)
1408                 if (fmt[i].code == code)
1409                         return fmt + i;
1410
1411         return NULL;
1412 }
1413
1414 static const struct sensor_datafmt sensor_colour_fmts[] = {
1415     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1416     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
1417 };
1418 enum sensor_work_state
1419 {
1420         sensor_work_ready = 0,
1421         sensor_working,
1422 };
1423 struct sensor_work
1424 {
1425         struct i2c_client *client;
1426         struct delayed_work dwork;
1427         enum sensor_work_state state;
1428 };
1429
1430 typedef struct sensor_info_priv_s
1431 {
1432     int whiteBalance;
1433     int brightness;
1434     int contrast;
1435     int saturation;
1436     int effect;
1437     int scene;
1438     int digitalzoom;
1439     int focus;
1440         int auto_focus;
1441         int affm_reinit;
1442     int flash;
1443     int exposure;
1444     unsigned char mirror;                                        /* HFLIP */
1445     unsigned char flip;                                          /* VFLIP */
1446         bool snap2preview;
1447         bool video2preview;
1448         int capture_w;
1449         int capture_h;
1450         int preview_w;
1451         int preview_h;
1452     struct reginfo *winseqe_cur_addr;
1453         struct sensor_datafmt fmt;
1454         unsigned int enable;
1455         unsigned int funmodule_state;
1456 } sensor_info_priv_t;
1457
1458
1459
1460 struct sensor_parameter
1461 {
1462         unsigned short int preview_maxlines;
1463         unsigned short int preview_exposure;
1464         unsigned short int preview_line_width;
1465         unsigned short int preview_gain;
1466
1467         unsigned short int capture_framerate;
1468         unsigned short int preview_framerate;
1469 };
1470
1471 struct sensor
1472 {
1473     struct v4l2_subdev subdev;
1474     struct i2c_client *client;
1475     sensor_info_priv_t info_priv;
1476         struct sensor_parameter parameter;
1477         struct workqueue_struct *sensor_wq;
1478         struct sensor_work sensor_wk;
1479         struct mutex wq_lock;
1480     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1481 #if CONFIG_SENSOR_I2C_NOSCHED
1482         atomic_t tasklock_cnt;
1483 #endif
1484         struct rk29camera_platform_data *sensor_io_request;
1485     struct rk29camera_gpio_res *sensor_gpio_res;
1486 };
1487
1488 static struct sensor* to_sensor(const struct i2c_client *client)
1489 {
1490     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1491 }
1492
1493 static int sensor_task_lock(struct i2c_client *client, int lock)
1494 {
1495 #if CONFIG_SENSOR_I2C_NOSCHED
1496         int cnt = 3;
1497     struct sensor *sensor = to_sensor(client);
1498
1499         if (lock) {
1500                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1501                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1502                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1503                                 msleep(35);
1504                                 cnt--;
1505                         }
1506                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1507                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1508                                 goto sensor_task_lock_err;
1509                         }
1510                         preempt_disable();
1511                 }
1512
1513                 atomic_add(1, &sensor->tasklock_cnt);
1514         } else {
1515                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1516                         atomic_sub(1, &sensor->tasklock_cnt);
1517
1518                         if (atomic_read(&sensor->tasklock_cnt) == 0)
1519                                 preempt_enable();
1520                 }
1521         }
1522         return 0;
1523 sensor_task_lock_err:
1524         return -1;  
1525 #else
1526     return 0;
1527 #endif
1528
1529 }
1530
1531 /* sensor register write */
1532 static int sensor_write(struct i2c_client *client, u16 reg, u16 val)
1533 {
1534     int err=0,cnt;
1535     u8 buf[4];
1536     struct i2c_msg msg[1];
1537
1538         switch (reg)
1539         {
1540                 case SEQUENCE_WAIT_MS:
1541                 {
1542                         msleep(val);
1543                         break;
1544                 }
1545
1546                 case SEQUENCE_WAIT_US:
1547                 {
1548                         udelay(val);
1549                         break;
1550                 }
1551
1552                 case SEQUENCE_PROPERTY:
1553                 {
1554                         break;
1555                 }
1556                 default:
1557                 {
1558                     buf[0] = reg >> 8;
1559                     buf[1] = reg & 0xFF;
1560                     buf[2] = val >> 8;
1561                         buf[3] = val & 0xFF;
1562
1563                     msg->addr = client->addr;
1564                     msg->flags = client->flags;
1565                     msg->buf = buf;
1566                     msg->len = sizeof(buf);
1567                     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1568                     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1569
1570                     cnt = 3;
1571                     err = -EAGAIN;
1572
1573                     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1574                         err = i2c_transfer(client->adapter, msg, 1);
1575
1576                         if (err >= 0) {
1577                             return 0;
1578                         } else {
1579                             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1580                             udelay(10);
1581                         }
1582                     }
1583                 }
1584         }
1585     return err;
1586 }
1587
1588 /* sensor register read */
1589 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1590 {
1591     int err,cnt;
1592     u8 buf[2];
1593     struct i2c_msg msg[2];
1594
1595     buf[0] = reg >> 8;
1596     buf[1] = reg & 0xFF;
1597
1598     msg[0].addr = client->addr;
1599     msg[0].flags = client->flags;
1600     msg[0].buf = buf;
1601     msg[0].len = sizeof(buf);
1602     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
1603     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1604
1605     msg[1].addr = client->addr;
1606     msg[1].flags = client->flags|I2C_M_RD;
1607     msg[1].buf = buf;
1608     msg[1].len = 2;
1609     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
1610     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1611
1612     cnt = 3;
1613     err = -EAGAIN;
1614     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1615         err = i2c_transfer(client->adapter, msg, 2);
1616
1617         if (err >= 0) {
1618             *val = buf[0];
1619             return 0;
1620         } else {
1621                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1622             udelay(10);
1623         }
1624     }
1625
1626     return err;
1627 }
1628
1629 /* write a array of registers  */
1630 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1631 {
1632     int err = 0, cnt;
1633     int i = 0;
1634 #if CONFIG_SENSOR_I2C_RDWRCHK
1635         char valchk;
1636 #endif
1637
1638         cnt = 0;
1639         if (sensor_task_lock(client, 1) < 0)
1640                 goto sensor_write_array_end;
1641     while (regarray[i].reg != SEQUENCE_END)
1642     {
1643
1644         err = sensor_write(client, regarray[i].reg, regarray[i].val);
1645         if (err < 0)
1646         {
1647             if (cnt-- > 0) {
1648                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1649                                 i = 0;
1650                                 continue;
1651             } else {
1652                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1653                 err = -EPERM;
1654                                 goto sensor_write_array_end;
1655             }
1656         } else {
1657         #if CONFIG_SENSOR_I2C_RDWRCHK
1658                         sensor_read(client, regarray[i].reg, &valchk);
1659                         if (valchk != regarray[i].val)
1660                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1661                 #endif
1662         }
1663
1664         i++;
1665     }
1666
1667 sensor_write_array_end:
1668         sensor_task_lock(client,0);
1669     return err;
1670 }
1671 #if CONFIG_SENSOR_I2C_RDWRCHK
1672 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1673 {
1674     int cnt;
1675     int i = 0;
1676         char valchk;
1677
1678         cnt = 0;
1679         valchk = 0;
1680     while (regarray[i].reg != SEQUENCE_END)
1681     {
1682                 sensor_read(client, regarray[i].reg, &valchk);
1683                 if (valchk != regarray[i].val)
1684                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1685
1686         i++;
1687     }
1688     return 0;
1689 }
1690 #endif
1691 #if CONFIG_SENSOR_Focus
1692
1693 static int sensor_af_single(struct i2c_client *client)
1694 {
1695         int ret = 0;
1696
1697
1698 sensor_af_single_end:
1699         return ret;
1700 }
1701
1702 static int sensor_af_const(struct i2c_client *client)
1703 {
1704         int ret = 0;
1705
1706 sensor_af_const_end:
1707         return ret;
1708 }
1709
1710 static int sensor_af_zoneupdate(struct i2c_client *client)
1711 {
1712         int ret = 0;
1713
1714 sensor_af_zoneupdate_end:
1715         return ret;
1716 }
1717
1718 static int sensor_af_init(struct i2c_client *client)
1719 {
1720         int ret = 0;
1721
1722         return ret;
1723 }
1724 #endif
1725
1726 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1727 {
1728         struct soc_camera_link *icl = to_soc_camera_link(icd);
1729         int ret = 0;
1730
1731     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1732         switch (cmd)
1733         {
1734                 case Sensor_PowerDown:
1735                 {
1736                         if (icl->powerdown) {
1737                                 ret = icl->powerdown(icd->pdev, on);
1738                                 if (ret == RK29_CAM_IO_SUCCESS) {
1739                                         if (on == 0) {
1740                                                 mdelay(2);
1741                                                 if (icl->reset)
1742                                                         icl->reset(icd->pdev);
1743                                         }
1744                                 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1745                                         ret = -ENODEV;
1746                                         goto sensor_power_end;
1747                                 }
1748                         }
1749                         break;
1750                 }
1751                 case Sensor_Flash:
1752                 {
1753                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1754                 struct sensor *sensor = to_sensor(client);
1755
1756                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1757                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1758                         }
1759                         break;
1760                 }
1761                 default:
1762                 {
1763                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1764                         break;
1765                 }
1766         }
1767
1768 sensor_power_end:
1769         return ret;
1770 }
1771 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1772 {
1773     struct i2c_client *client = v4l2_get_subdevdata(sd);
1774     struct soc_camera_device *icd = client->dev.platform_data;
1775     struct sensor *sensor = to_sensor(client);
1776         const struct v4l2_queryctrl *qctrl;
1777     const struct sensor_datafmt *fmt;
1778     int ret;
1779 #if (SENSOR_ID_REG != SEQUENCE_END)    
1780     u16 pid = 0;
1781 #endif
1782
1783     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1784
1785         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1786                 ret = -ENODEV;
1787                 goto sensor_INIT_ERR;
1788         }
1789
1790     /* soft reset */
1791         if (sensor_task_lock(client,1)<0)
1792                 goto sensor_INIT_ERR;
1793
1794 #if (SENSOR_RESET_REG != SEQUENCE_END)
1795     ret = sensor_write(client, SENSOR_RESET_REG, SENSOR_RESET_VAL);
1796     if (ret != 0) {
1797         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1798         ret = -ENODEV;
1799                 goto sensor_INIT_ERR;
1800     }
1801
1802     mdelay(5);  //delay 5 microseconds
1803 #endif
1804
1805         /* check if it is an sensor sensor */
1806 #if (SENSOR_ID_REG != SEQUENCE_END)
1807     ret = sensor_read(client, SENSOR_ID_REG, &pid);
1808     if (ret != 0) {
1809         SENSOR_TR("read chip id failed\n");
1810         ret = -ENODEV;
1811         goto sensor_INIT_ERR;
1812     }
1813
1814     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1815 #else
1816         pid = SENSOR_ID;
1817 #endif
1818     if (pid == SENSOR_ID) {
1819         sensor->model = SENSOR_V4L2_IDENT;
1820     } else {
1821         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1822         ret = -ENODEV;
1823         goto sensor_INIT_ERR;
1824     }
1825
1826     ret = sensor_write_array(client, sensor_init_data);
1827     if (ret != 0)
1828     {
1829         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1830         goto sensor_INIT_ERR;
1831     }
1832         sensor_task_lock(client,0);
1833     sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1834     sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1835     sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1836     sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1837     sensor->info_priv.winseqe_cur_addr  = SENSOR_INIT_WINSEQADR;
1838     fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1839     if (!fmt) {
1840         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1841         ret = -EINVAL;
1842         goto sensor_INIT_ERR;
1843     }
1844         sensor->info_priv.fmt = *fmt;
1845
1846     /* sensor sensor information for initialization  */
1847         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1848         if (qctrl)
1849         sensor->info_priv.whiteBalance = qctrl->default_value;
1850         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1851         if (qctrl)
1852         sensor->info_priv.brightness = qctrl->default_value;
1853         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1854         if (qctrl)
1855         sensor->info_priv.effect = qctrl->default_value;
1856         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1857         if (qctrl)
1858         sensor->info_priv.exposure = qctrl->default_value;
1859
1860         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1861         if (qctrl)
1862         sensor->info_priv.saturation = qctrl->default_value;
1863         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1864         if (qctrl)
1865         sensor->info_priv.contrast = qctrl->default_value;
1866         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1867         if (qctrl)
1868         sensor->info_priv.mirror = qctrl->default_value;
1869         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1870         if (qctrl)
1871         sensor->info_priv.flip = qctrl->default_value;
1872         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1873         if (qctrl)
1874         sensor->info_priv.scene = qctrl->default_value;
1875         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1876         if (qctrl)
1877         sensor->info_priv.digitalzoom = qctrl->default_value;
1878
1879     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
1880         #if CONFIG_SENSOR_Focus
1881     sensor_set_focus();
1882     qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1883         if (qctrl)
1884         sensor->info_priv.focus = qctrl->default_value;
1885         #endif
1886
1887         #if CONFIG_SENSOR_Flash
1888         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1889         if (qctrl)
1890         sensor->info_priv.flash = qctrl->default_value;
1891     #endif
1892     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);
1893
1894     return 0;
1895 sensor_INIT_ERR:
1896         sensor_task_lock(client,0);
1897         sensor_deactivate(client);
1898     return ret;
1899 }
1900 static int sensor_deactivate(struct i2c_client *client)
1901 {
1902         struct soc_camera_device *icd = client->dev.platform_data;
1903
1904         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1905
1906         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1907         sensor_task_lock(client, 1);
1908         sensor_ioctrl(icd, Sensor_PowerDown, 1);
1909
1910         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1911         icd->user_width = SENSOR_INIT_WIDTH;
1912     icd->user_height = SENSOR_INIT_HEIGHT;
1913         msleep(100);
1914         return 0;
1915 }
1916 static  struct reginfo sensor_power_down_sequence[]=
1917 {
1918     {0x00,0x00}
1919 };
1920 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1921 {
1922     int ret;
1923     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1924
1925     if (pm_msg.event == PM_EVENT_SUSPEND) {
1926         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1927         ret = sensor_write_array(client, sensor_power_down_sequence) ;
1928         if (ret != 0) {
1929             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1930             return ret;
1931         } else {
1932             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1933             if (ret < 0) {
1934                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1935                 return -EINVAL;
1936             }
1937         }
1938     } else {
1939         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1940         return -EINVAL;
1941     }
1942
1943     return 0;
1944 }
1945
1946 static int sensor_resume(struct soc_camera_device *icd)
1947 {
1948         int ret;
1949
1950     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1951     if (ret < 0) {
1952                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1953         return -EINVAL;
1954     }
1955
1956         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1957         return 0;
1958 }
1959
1960 static int sensor_set_bus_param(struct soc_camera_device *icd,
1961                                 unsigned long flags)
1962 {
1963
1964     return 0;
1965 }
1966
1967 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1968 {
1969     struct soc_camera_link *icl = to_soc_camera_link(icd);
1970     unsigned long flags = SENSOR_BUS_PARAM;
1971
1972     return soc_camera_apply_sensor_flags(icl, flags);
1973 }
1974 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1975 {
1976     struct i2c_client *client = v4l2_get_subdevdata(sd);
1977     struct soc_camera_device *icd = client->dev.platform_data;
1978     struct sensor *sensor = to_sensor(client);
1979
1980     mf->width   = icd->user_width;
1981         mf->height      = icd->user_height;
1982         mf->code        = sensor->info_priv.fmt.code;
1983         mf->colorspace  = sensor->info_priv.fmt.colorspace;
1984         mf->field       = V4L2_FIELD_NONE;
1985
1986     return 0;
1987 }
1988 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1989 {
1990     bool ret = false;
1991
1992         if ((mf->width == 1024) && (mf->height == 768)) {
1993                 ret = true;
1994         } else if ((mf->width == 1280) && (mf->height == 1024)) {
1995                 ret = true;
1996         } else if ((mf->width == 1600) && (mf->height == 1200)) {
1997                 ret = true;
1998         } else if ((mf->width == 2048) && (mf->height == 1536)) {
1999                 ret = true;
2000         } else if ((mf->width == 2592) && (mf->height == 1944)) {
2001                 ret = true;
2002         }
2003
2004         if (ret == true)
2005                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2006         return ret;
2007 }
2008
2009 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2010 {
2011     bool ret = false;
2012
2013         if ((mf->width == 1280) && (mf->height == 720)) {
2014                 ret = true;
2015         } else if ((mf->width == 1920) && (mf->height == 1080)) {
2016                 ret = true;
2017         }
2018
2019         if (ret == true)
2020                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2021         return ret;
2022 }
2023 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2024 {
2025     struct i2c_client *client = v4l2_get_subdevdata(sd);
2026     struct sensor *sensor = to_sensor(client);
2027     const struct sensor_datafmt *fmt;
2028     struct reginfo *winseqe_set_addr=NULL;
2029     int ret = 0, set_w,set_h;
2030
2031         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2032                                    ARRAY_SIZE(sensor_colour_fmts));
2033         if (!fmt) {
2034         ret = -EINVAL;
2035         goto sensor_s_fmt_end;
2036     }
2037
2038         if (sensor->info_priv.fmt.code != mf->code) {
2039                 switch (mf->code)
2040                 {
2041                         case V4L2_MBUS_FMT_YUYV8_2X8:
2042                         {
2043                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
2044                                 break;
2045                         }
2046                         case V4L2_MBUS_FMT_UYVY8_2X8:
2047                         {
2048                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
2049                                 break;
2050                         }
2051                         default:
2052                                 break;
2053                 }
2054                 if (winseqe_set_addr != NULL) {
2055             sensor_write_array(client, winseqe_set_addr);
2056                         sensor->info_priv.fmt.code = mf->code;
2057             sensor->info_priv.fmt.colorspace= mf->colorspace;            
2058                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2059                 } else {
2060                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2061                 }
2062         }
2063
2064     set_w = mf->width;
2065     set_h = mf->height;
2066         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
2067         {
2068                 winseqe_set_addr = sensor_qcif;
2069         set_w = 176;
2070         set_h = 144;
2071         }
2072         else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
2073     {
2074         winseqe_set_addr = sensor_qvga;
2075         set_w = 320;
2076         set_h = 240;
2077     }
2078     else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
2079     {
2080         winseqe_set_addr = sensor_cif;
2081         set_w = 352;
2082         set_h = 288;
2083     }
2084     else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
2085     {
2086         winseqe_set_addr = sensor_vga;
2087         set_w = 640;
2088         set_h = 480;
2089     }
2090     else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
2091     {
2092         winseqe_set_addr = sensor_svga;
2093         set_w = 800;
2094         set_h = 600;
2095     }
2096         else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
2097     {
2098         winseqe_set_addr = sensor_xga;
2099         set_w = 1024;
2100         set_h = 768;
2101     }
2102         else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
2103     {
2104         winseqe_set_addr = sensor_720p;
2105         set_w = 1280;
2106         set_h = 720;
2107     }
2108     else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
2109     {
2110         winseqe_set_addr = sensor_sxga;
2111         set_w = 1280;
2112         set_h = 1024;
2113     }
2114     else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
2115     {
2116         winseqe_set_addr = sensor_uxga;
2117         set_w = 1600;
2118         set_h = 1200;
2119     }
2120     else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
2121     {
2122         winseqe_set_addr = sensor_1080p;
2123         set_w = 1920;
2124         set_h = 1080;
2125     }
2126         else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
2127     {
2128         winseqe_set_addr = sensor_qxga;
2129         set_w = 2048;
2130         set_h = 1536;
2131     }
2132         else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
2133     {
2134         winseqe_set_addr = sensor_qsxga;
2135         set_w = 2592;
2136         set_h = 1944;
2137     }
2138
2139     if ((winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
2140         ret |= sensor_write_array(client, winseqe_set_addr);
2141         if (ret != 0) {
2142             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2143             goto sensor_s_fmt_end;
2144         }
2145         sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
2146                 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2147                 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2148                 } else {
2149                         SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2150                 }
2151     }
2152
2153         if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2154                 ret |= sensor_write_array(client, sensor_Preview2Capture);
2155                 if (ret != 0) {
2156                 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
2157                 goto sensor_s_fmt_end;
2158         }
2159                 sensor->info_priv.capture_w = set_w;
2160                 sensor->info_priv.capture_h = set_h;
2161                 sensor->info_priv.snap2preview = true;
2162         } else if (sensor->info_priv.snap2preview == true) {
2163                 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
2164                         ret |= sensor_write_array(client, sensor_Capture2Preview);
2165                         if (ret != 0) {
2166                         SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
2167                         goto sensor_s_fmt_end;
2168                 }
2169                         sensor->info_priv.preview_w = mf->width;
2170                         sensor->info_priv.preview_h = mf->height;
2171                         sensor->info_priv.snap2preview = false;
2172                 } else {
2173                         SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2174                 }
2175         }
2176
2177         mf->width = set_w;
2178         mf->height = set_h;
2179 sensor_s_fmt_end:
2180     return ret;
2181 }
2182
2183 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2184 {
2185     struct i2c_client *client = v4l2_get_subdevdata(sd);
2186     struct sensor *sensor = to_sensor(client);
2187     const struct sensor_datafmt *fmt;
2188     int ret = 0,set_w,set_h;
2189    
2190         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2191                                    ARRAY_SIZE(sensor_colour_fmts));
2192         if (fmt == NULL) {
2193                 fmt = &sensor->info_priv.fmt;
2194         mf->code = fmt->code;
2195         } 
2196
2197     if (mf->height > SENSOR_MAX_HEIGHT)
2198         mf->height = SENSOR_MAX_HEIGHT;
2199     else if (mf->height < SENSOR_MIN_HEIGHT)
2200         mf->height = SENSOR_MIN_HEIGHT;
2201
2202     if (mf->width > SENSOR_MAX_WIDTH)
2203         mf->width = SENSOR_MAX_WIDTH;
2204     else if (mf->width < SENSOR_MIN_WIDTH)
2205         mf->width = SENSOR_MIN_WIDTH;
2206
2207     set_w = mf->width;
2208     set_h = mf->height;
2209         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
2210         {
2211         set_w = 176;
2212         set_h = 144;
2213         }
2214         else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
2215     {
2216         set_w = 320;
2217         set_h = 240;
2218     }
2219     else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
2220     {
2221         set_w = 352;
2222         set_h = 288;
2223     }
2224     else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
2225     {
2226         set_w = 640;
2227         set_h = 480;
2228     }
2229     else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
2230     {
2231         set_w = 800;
2232         set_h = 600;
2233     }
2234         else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
2235     {
2236         set_w = 1024;
2237         set_h = 768;
2238     }
2239         else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
2240     {
2241         set_w = 1280;
2242         set_h = 720;
2243     }
2244     else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
2245     {
2246         set_w = 1280;
2247         set_h = 1024;
2248     }
2249     else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
2250     {
2251         set_w = 1600;
2252         set_h = 1200;
2253     }
2254     else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
2255     {
2256         set_w = 1920;
2257         set_h = 1080;
2258     }
2259         else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
2260     {
2261         set_w = 2048;
2262         set_h = 1536;
2263     }
2264         else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
2265     {
2266         set_w = 2592;
2267         set_h = 1944;
2268     }
2269
2270         mf->width = set_w;
2271         mf->height = set_h;
2272     
2273     mf->colorspace = fmt->colorspace;
2274     
2275     return ret;
2276 }
2277
2278  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2279 {
2280     struct i2c_client *client = v4l2_get_subdevdata(sd);
2281
2282     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2283         return -EINVAL;
2284
2285     if (id->match.addr != client->addr)
2286         return -ENODEV;
2287
2288     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
2289     id->revision = 0;
2290
2291     return 0;
2292 }
2293 #if CONFIG_SENSOR_Brightness
2294 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2295 {
2296     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2297
2298     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2299     {
2300         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2301         {
2302             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2303             {
2304                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2305                 return -EINVAL;
2306             }
2307             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2308             return 0;
2309         }
2310     }
2311         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2312     return -EINVAL;
2313 }
2314 #endif
2315 #if CONFIG_SENSOR_Effect
2316 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2317 {
2318     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2319
2320     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2321     {
2322         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2323         {
2324             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2325             {
2326                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2327                 return -EINVAL;
2328             }
2329             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2330             return 0;
2331         }
2332     }
2333         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2334     return -EINVAL;
2335 }
2336 #endif
2337 #if CONFIG_SENSOR_Exposure
2338 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2339 {
2340     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2341
2342     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2343     {
2344         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2345         {
2346             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2347             {
2348                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2349                 return -EINVAL;
2350             }
2351             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2352             return 0;
2353         }
2354     }
2355         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2356     return -EINVAL;
2357 }
2358 #endif
2359 #if CONFIG_SENSOR_Saturation
2360 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2361 {
2362     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2363
2364     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2365     {
2366         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2367         {
2368             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2369             {
2370                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2371                 return -EINVAL;
2372             }
2373             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2374             return 0;
2375         }
2376     }
2377     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2378     return -EINVAL;
2379 }
2380 #endif
2381 #if CONFIG_SENSOR_Contrast
2382 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2383 {
2384     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2385
2386     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2387     {
2388         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2389         {
2390             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2391             {
2392                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2393                 return -EINVAL;
2394             }
2395             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2396             return 0;
2397         }
2398     }
2399     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2400     return -EINVAL;
2401 }
2402 #endif
2403 #if CONFIG_SENSOR_Mirror
2404 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2405 {
2406     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2407
2408     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2409     {
2410         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2411         {
2412             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2413             {
2414                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2415                 return -EINVAL;
2416             }
2417             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2418             return 0;
2419         }
2420     }
2421     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2422     return -EINVAL;
2423 }
2424 #endif
2425 #if CONFIG_SENSOR_Flip
2426 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2427 {
2428     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2429
2430     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2431     {
2432         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2433         {
2434             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2435             {
2436                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2437                 return -EINVAL;
2438             }
2439             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2440             return 0;
2441         }
2442     }
2443     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2444     return -EINVAL;
2445 }
2446 #endif
2447 #if CONFIG_SENSOR_Scene
2448 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2449 {
2450     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2451
2452     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2453     {
2454         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2455         {
2456             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2457             {
2458                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2459                 return -EINVAL;
2460             }
2461             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2462             return 0;
2463         }
2464     }
2465     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2466     return -EINVAL;
2467 }
2468 #endif
2469 #if CONFIG_SENSOR_WhiteBalance
2470 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2471 {
2472     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2473
2474     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2475     {
2476         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2477         {
2478             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2479             {
2480                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2481                 return -EINVAL;
2482             }
2483             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2484             return 0;
2485         }
2486     }
2487         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2488     return -EINVAL;
2489 }
2490 #endif
2491 #if CONFIG_SENSOR_DigitalZoom
2492 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2493 {
2494     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2495     struct sensor *sensor = to_sensor(client);
2496         const struct v4l2_queryctrl *qctrl_info;
2497     int digitalzoom_cur, digitalzoom_total;
2498
2499         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2500         if (qctrl_info)
2501                 return -EINVAL;
2502
2503     digitalzoom_cur = sensor->info_priv.digitalzoom;
2504     digitalzoom_total = qctrl_info->maximum;
2505
2506     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2507     {
2508         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2509         return -EINVAL;
2510     }
2511
2512     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2513     {
2514         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2515         return -EINVAL;
2516     }
2517
2518     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2519     {
2520         *value = digitalzoom_total - digitalzoom_cur;
2521     }
2522
2523     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2524     {
2525         *value = 0 - digitalzoom_cur;
2526     }
2527
2528     digitalzoom_cur += *value;
2529
2530     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2531     {
2532         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2533         {
2534             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2535             return -EINVAL;
2536         }
2537         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2538         return 0;
2539     }
2540
2541     return -EINVAL;
2542 }
2543 #endif
2544 #if CONFIG_SENSOR_Flash
2545 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2546 {    
2547     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2548         if (value == 3) {       /* ddl@rock-chips.com: torch */
2549             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
2550         } else {
2551             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2552         }
2553         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2554         return 0;
2555     }
2556     
2557         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2558     return -EINVAL;
2559 }
2560 #endif
2561 #if CONFIG_SENSOR_Focus
2562 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2563 {
2564         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2565     struct sensor *sensor = to_sensor(client);
2566         const struct v4l2_queryctrl *qctrl_info;
2567         int ret = 0;
2568
2569         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2570         if (!qctrl_info)
2571                 return -EINVAL;
2572
2573         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2574                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2575
2576                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2577                 } else {
2578                         ret = -EINVAL;
2579                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2580                 }
2581         } else {
2582                 ret = -EACCES;
2583                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2584                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2585         }
2586
2587 sensor_set_focus_absolute_end:
2588         return ret;
2589 }
2590 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2591 {
2592         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2593         struct sensor *sensor = to_sensor(client);
2594         const struct v4l2_queryctrl *qctrl_info;
2595         int ret = 0;
2596
2597         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2598         if (!qctrl_info)
2599                 return -EINVAL;
2600
2601         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2602                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2603
2604                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2605                 } else {
2606                         ret = -EINVAL;
2607                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2608                 }
2609         } else {
2610                 ret = -EACCES;
2611                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2612                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2613         }
2614 sensor_set_focus_relative_end:
2615         return ret;
2616 }
2617
2618 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2619 {
2620         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2621         struct sensor *sensor = to_sensor(client);
2622         int ret = 0;
2623
2624         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)  && (sensor->info_priv.affm_reinit == 0)) {
2625                 switch (value)
2626                 {
2627                         case SENSOR_AF_MODE_AUTO:
2628                         {
2629                                 ret = sensor_af_single(client);
2630                                 break;
2631                         }
2632
2633                         case SENSOR_AF_MODE_MACRO:
2634                         {
2635                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2636                                 break;
2637                         }
2638
2639                         case SENSOR_AF_MODE_INFINITY:
2640                         {
2641                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2642                                 break;
2643                         }
2644
2645                         case SENSOR_AF_MODE_CONTINUOUS:
2646                         {
2647                                 ret = sensor_af_const(client);
2648                                 break;
2649                         }
2650                         default:
2651                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2652                                 break;
2653
2654                 }
2655
2656                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2657         } else {
2658                 ret = -EACCES;
2659                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2660                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2661         }
2662
2663         return ret;
2664 }
2665 #endif
2666 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2667 {
2668     struct i2c_client *client = v4l2_get_subdevdata(sd);
2669     struct sensor *sensor = to_sensor(client);
2670     const struct v4l2_queryctrl *qctrl;
2671
2672     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2673
2674     if (!qctrl)
2675     {
2676         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2677         return -EINVAL;
2678     }
2679
2680     switch (ctrl->id)
2681     {
2682         case V4L2_CID_BRIGHTNESS:
2683             {
2684                 ctrl->value = sensor->info_priv.brightness;
2685                 break;
2686             }
2687         case V4L2_CID_SATURATION:
2688             {
2689                 ctrl->value = sensor->info_priv.saturation;
2690                 break;
2691             }
2692         case V4L2_CID_CONTRAST:
2693             {
2694                 ctrl->value = sensor->info_priv.contrast;
2695                 break;
2696             }
2697         case V4L2_CID_DO_WHITE_BALANCE:
2698             {
2699                 ctrl->value = sensor->info_priv.whiteBalance;
2700                 break;
2701             }
2702         case V4L2_CID_EXPOSURE:
2703             {
2704                 ctrl->value = sensor->info_priv.exposure;
2705                 break;
2706             }
2707         case V4L2_CID_HFLIP:
2708             {
2709                 ctrl->value = sensor->info_priv.mirror;
2710                 break;
2711             }
2712         case V4L2_CID_VFLIP:
2713             {
2714                 ctrl->value = sensor->info_priv.flip;
2715                 break;
2716             }
2717         default :
2718                 break;
2719     }
2720     return 0;
2721 }
2722
2723
2724
2725 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2726 {
2727     struct i2c_client *client = v4l2_get_subdevdata(sd);
2728     struct sensor *sensor = to_sensor(client);
2729     struct soc_camera_device *icd = client->dev.platform_data;
2730     const struct v4l2_queryctrl *qctrl;
2731
2732
2733     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2734
2735     if (!qctrl)
2736     {
2737         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2738         return -EINVAL;
2739     }
2740
2741     switch (ctrl->id)
2742     {
2743 #if CONFIG_SENSOR_Brightness
2744         case V4L2_CID_BRIGHTNESS:
2745             {
2746                 if (ctrl->value != sensor->info_priv.brightness)
2747                 {
2748                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2749                     {
2750                         return -EINVAL;
2751                     }
2752                     sensor->info_priv.brightness = ctrl->value;
2753                 }
2754                 break;
2755             }
2756 #endif
2757 #if CONFIG_SENSOR_Exposure
2758         case V4L2_CID_EXPOSURE:
2759             {
2760                 if (ctrl->value != sensor->info_priv.exposure)
2761                 {
2762                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2763                     {
2764                         return -EINVAL;
2765                     }
2766                     sensor->info_priv.exposure = ctrl->value;
2767                 }
2768                 break;
2769             }
2770 #endif
2771 #if CONFIG_SENSOR_Saturation
2772         case V4L2_CID_SATURATION:
2773             {
2774                 if (ctrl->value != sensor->info_priv.saturation)
2775                 {
2776                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2777                     {
2778                         return -EINVAL;
2779                     }
2780                     sensor->info_priv.saturation = ctrl->value;
2781                 }
2782                 break;
2783             }
2784 #endif
2785 #if CONFIG_SENSOR_Contrast
2786         case V4L2_CID_CONTRAST:
2787             {
2788                 if (ctrl->value != sensor->info_priv.contrast)
2789                 {
2790                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2791                     {
2792                         return -EINVAL;
2793                     }
2794                     sensor->info_priv.contrast = ctrl->value;
2795                 }
2796                 break;
2797             }
2798 #endif
2799 #if CONFIG_SENSOR_WhiteBalance
2800         case V4L2_CID_DO_WHITE_BALANCE:
2801             {
2802                 if (ctrl->value != sensor->info_priv.whiteBalance)
2803                 {
2804                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2805                     {
2806                         return -EINVAL;
2807                     }
2808                     sensor->info_priv.whiteBalance = ctrl->value;
2809                 }
2810                 break;
2811             }
2812 #endif
2813 #if CONFIG_SENSOR_Mirror
2814         case V4L2_CID_HFLIP:
2815             {
2816                 if (ctrl->value != sensor->info_priv.mirror)
2817                 {
2818                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2819                         return -EINVAL;
2820                     sensor->info_priv.mirror = ctrl->value;
2821                 }
2822                 break;
2823             }
2824 #endif
2825 #if CONFIG_SENSOR_Flip
2826         case V4L2_CID_VFLIP:
2827             {
2828                 if (ctrl->value != sensor->info_priv.flip)
2829                 {
2830                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2831                         return -EINVAL;
2832                     sensor->info_priv.flip = ctrl->value;
2833                 }
2834                 break;
2835             }
2836 #endif
2837         default:
2838             break;
2839     }
2840
2841     return 0;
2842 }
2843 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2844 {
2845     const struct v4l2_queryctrl *qctrl;
2846     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2847     struct sensor *sensor = to_sensor(client);
2848
2849     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2850
2851     if (!qctrl)
2852     {
2853         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2854         return -EINVAL;
2855     }
2856
2857     switch (ext_ctrl->id)
2858     {
2859         case V4L2_CID_SCENE:
2860             {
2861                 ext_ctrl->value = sensor->info_priv.scene;
2862                 break;
2863             }
2864         case V4L2_CID_EFFECT:
2865             {
2866                 ext_ctrl->value = sensor->info_priv.effect;
2867                 break;
2868             }
2869         case V4L2_CID_ZOOM_ABSOLUTE:
2870             {
2871                 ext_ctrl->value = sensor->info_priv.digitalzoom;
2872                 break;
2873             }
2874         case V4L2_CID_ZOOM_RELATIVE:
2875             {
2876                 return -EINVAL;
2877             }
2878         case V4L2_CID_FOCUS_ABSOLUTE:
2879             {
2880                 ext_ctrl->value = sensor->info_priv.focus;
2881                 break;
2882             }
2883         case V4L2_CID_FOCUS_RELATIVE:
2884             {
2885                 return -EINVAL;
2886             }
2887         case V4L2_CID_FLASH:
2888             {
2889                 ext_ctrl->value = sensor->info_priv.flash;
2890                 break;
2891             }
2892         default :
2893             break;
2894     }
2895     return 0;
2896 }
2897 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2898 {
2899     const struct v4l2_queryctrl *qctrl;
2900     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2901     struct sensor *sensor = to_sensor(client);
2902     int val_offset;
2903
2904     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2905
2906     if (!qctrl)
2907     {
2908         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2909         return -EINVAL;
2910     }
2911
2912         val_offset = 0;
2913     switch (ext_ctrl->id)
2914     {
2915 #if CONFIG_SENSOR_Scene
2916         case V4L2_CID_SCENE:
2917             {
2918                 if (ext_ctrl->value != sensor->info_priv.scene)
2919                 {
2920                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2921                         return -EINVAL;
2922                     sensor->info_priv.scene = ext_ctrl->value;
2923                 }
2924                 break;
2925             }
2926 #endif
2927 #if CONFIG_SENSOR_Effect
2928         case V4L2_CID_EFFECT:
2929             {
2930                 if (ext_ctrl->value != sensor->info_priv.effect)
2931                 {
2932                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2933                         return -EINVAL;
2934                     sensor->info_priv.effect= ext_ctrl->value;
2935                 }
2936                 break;
2937             }
2938 #endif
2939 #if CONFIG_SENSOR_DigitalZoom
2940         case V4L2_CID_ZOOM_ABSOLUTE:
2941             {
2942                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2943                     return -EINVAL;
2944
2945                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2946                 {
2947                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2948
2949                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2950                         return -EINVAL;
2951                     sensor->info_priv.digitalzoom += val_offset;
2952
2953                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
2954                 }
2955
2956                 break;
2957             }
2958         case V4L2_CID_ZOOM_RELATIVE:
2959             {
2960                 if (ext_ctrl->value)
2961                 {
2962                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2963                         return -EINVAL;
2964                     sensor->info_priv.digitalzoom += ext_ctrl->value;
2965
2966                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2967                 }
2968                 break;
2969             }
2970 #endif
2971 #if CONFIG_SENSOR_Focus
2972         case V4L2_CID_FOCUS_ABSOLUTE:
2973             {
2974                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2975                     return -EINVAL;
2976
2977                                 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2978                                         if (ext_ctrl->value == qctrl->minimum) {
2979                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2980                                         } else if (ext_ctrl->value == qctrl->maximum) {
2981                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2982                                         } else {
2983                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2984                                         }
2985                                 }
2986
2987                 break;
2988             }
2989         case V4L2_CID_FOCUS_RELATIVE:
2990             {
2991                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2992                     return -EINVAL;
2993
2994                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2995                 break;
2996             }
2997                 case V4L2_CID_FOCUS_AUTO:
2998                         {
2999                                 if (ext_ctrl->value == 1) {
3000                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
3001                                                 return -EINVAL;
3002                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
3003                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
3004                                         if (ext_ctrl->value == 0)
3005                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3006                                 }
3007                                 break;
3008                         }
3009                 case V4L2_CID_FOCUS_CONTINUOUS:
3010                         {
3011                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3012                                         if (ext_ctrl->value == 1) {
3013                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3014                                                         return -EINVAL;
3015                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3016                                         }
3017                                 } else {
3018                                         if (ext_ctrl->value == 0)
3019                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3020                                 }
3021                                 break;
3022                         }
3023 #endif
3024 #if CONFIG_SENSOR_Flash
3025         case V4L2_CID_FLASH:
3026             {
3027                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3028                     return -EINVAL;
3029                 sensor->info_priv.flash = ext_ctrl->value;
3030
3031                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3032                 break;
3033             }
3034 #endif
3035         default:
3036             break;
3037     }
3038
3039     return 0;
3040 }
3041
3042 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3043 {
3044     struct i2c_client *client = v4l2_get_subdevdata(sd);
3045     struct soc_camera_device *icd = client->dev.platform_data;
3046     int i, error_cnt=0, error_idx=-1;
3047
3048
3049     for (i=0; i<ext_ctrl->count; i++) {
3050         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3051             error_cnt++;
3052             error_idx = i;
3053         }
3054     }
3055
3056     if (error_cnt > 1)
3057         error_idx = ext_ctrl->count;
3058
3059     if (error_idx != -1) {
3060         ext_ctrl->error_idx = error_idx;
3061         return -EINVAL;
3062     } else {
3063         return 0;
3064     }
3065 }
3066
3067 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3068 {
3069     struct i2c_client *client = v4l2_get_subdevdata(sd);
3070     struct soc_camera_device *icd = client->dev.platform_data;
3071     int i, error_cnt=0, error_idx=-1;
3072
3073     for (i=0; i<ext_ctrl->count; i++) {
3074         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3075             error_cnt++;
3076             error_idx = i;
3077         }
3078     }
3079
3080     if (error_cnt > 1)
3081         error_idx = ext_ctrl->count;
3082
3083     if (error_idx != -1) {
3084         ext_ctrl->error_idx = error_idx;
3085         return -EINVAL;
3086     } else {
3087         return 0;
3088     }
3089 }
3090
3091 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
3092 {
3093         struct i2c_client *client = v4l2_get_subdevdata(sd);
3094     struct sensor *sensor = to_sensor(client);
3095
3096         if (enable == 1) {
3097                 sensor->info_priv.enable = 1;
3098         } else if (enable == 0) {
3099                 sensor->info_priv.enable = 0;
3100         }
3101     
3102         return 0;
3103 }
3104
3105 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3106  * this wasn't our capture interface, so, we wait for the right one */
3107 static int sensor_video_probe(struct soc_camera_device *icd,
3108                                struct i2c_client *client)
3109 {
3110     int ret;
3111 #if (SENSOR_ID_REG != SEQUENCE_END)
3112     u16 pid = 0;
3113 #endif
3114
3115     struct sensor *sensor = to_sensor(client);
3116
3117     /* We must have a parent by now. And it cannot be a wrong one.
3118      * So this entire test is completely redundant. */
3119     if (!icd->dev.parent ||
3120             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3121                 return -ENODEV;
3122
3123         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3124                 ret = -ENODEV;
3125                 goto sensor_video_probe_err;
3126         }
3127
3128     /* soft reset */
3129 #if (SENSOR_RESET_REG != SEQUENCE_END)
3130     ret = sensor_write(client, SENSOR_RESET_REG, SENSOR_RESET_VAL);
3131     if (ret != 0) {
3132         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
3133         ret = -ENODEV;
3134                 goto sensor_INIT_ERR;
3135     }
3136
3137     mdelay(5);  //delay 5 microseconds
3138 #endif
3139
3140         /* check if it is an sensor sensor */
3141 #if (SENSOR_ID_REG != SEQUENCE_END)
3142     ret = sensor_read(client, SENSOR_ID_REG, &pid);
3143     if (ret != 0) {
3144         SENSOR_TR("read chip id failed\n");
3145         ret = -ENODEV;
3146         goto sensor_video_probe_err;
3147     }
3148
3149     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
3150 #else
3151         pid = SENSOR_ID;
3152 #endif
3153
3154     if (pid == SENSOR_ID) {
3155         sensor->model = SENSOR_V4L2_IDENT;
3156     } else {
3157         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3158         ret = -ENODEV;
3159         goto sensor_video_probe_err;
3160     }
3161
3162
3163     return 0;
3164
3165 sensor_video_probe_err:
3166     return ret;
3167 }
3168 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3169 {
3170         struct i2c_client *client = v4l2_get_subdevdata(sd);
3171     struct soc_camera_device *icd = client->dev.platform_data;
3172     struct sensor *sensor = to_sensor(client);
3173     int ret = 0;
3174 #if CONFIG_SENSOR_Flash 
3175     int i;
3176 #endif
3177     
3178         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3179         switch (cmd)
3180         {
3181                 case RK29_CAM_SUBDEV_DEACTIVATE:
3182                 {
3183                         sensor_deactivate(client);
3184                         break;
3185                 }
3186                 case RK29_CAM_SUBDEV_IOREQUEST:
3187                 {
3188                         sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;           
3189             if (sensor->sensor_io_request != NULL) { 
3190                 sensor->sensor_gpio_res = NULL;
3191                 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
3192                     if (sensor->sensor_io_request->gpio_res[i].dev_name && 
3193                         (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
3194                         sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
3195                     }
3196                 }
3197                 if (sensor->sensor_gpio_res == NULL) {
3198                     SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
3199                     ret = -EINVAL;
3200                     goto sensor_ioctl_end;
3201                 }
3202             } else {
3203                 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3204                 ret = -EINVAL;
3205                 goto sensor_ioctl_end;
3206             }
3207             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
3208                for this project */
3209             #if CONFIG_SENSOR_Flash     
3210                 if (sensor->sensor_gpio_res) { 
3211                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3212                     for (i = 0; i < icd->ops->num_controls; i++) {
3213                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3214                                         memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                       
3215                                 }
3216                     }
3217                     sensor->info_priv.flash = 0xff;
3218                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3219                 }
3220                 }
3221             #endif
3222                         break;
3223                 }
3224                 default:
3225                 {
3226                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3227                         break;
3228                 }
3229         }
3230 sensor_ioctl_end:
3231         return ret;
3232
3233 }
3234 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3235                             enum v4l2_mbus_pixelcode *code)
3236 {
3237         if (index >= ARRAY_SIZE(sensor_colour_fmts))
3238                 return -EINVAL;
3239
3240         *code = sensor_colour_fmts[index].code;
3241         return 0;
3242 }
3243 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3244         .init           = sensor_init,
3245         .g_ctrl         = sensor_g_control,
3246         .s_ctrl         = sensor_s_control,
3247         .g_ext_ctrls          = sensor_g_ext_controls,
3248         .s_ext_ctrls          = sensor_s_ext_controls,
3249         .g_chip_ident   = sensor_g_chip_ident,
3250         .ioctl = sensor_ioctl,
3251 };
3252
3253 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3254         .s_mbus_fmt     = sensor_s_fmt,
3255         .g_mbus_fmt     = sensor_g_fmt,
3256         .try_mbus_fmt   = sensor_try_fmt,
3257         .enum_mbus_fmt  = sensor_enum_fmt,
3258 };
3259
3260 static struct v4l2_subdev_ops sensor_subdev_ops = {
3261         .core   = &sensor_subdev_core_ops,
3262         .video = &sensor_subdev_video_ops,
3263 };
3264
3265 static int sensor_probe(struct i2c_client *client,
3266                          const struct i2c_device_id *did)
3267 {
3268     struct sensor *sensor;
3269     struct soc_camera_device *icd = client->dev.platform_data;
3270     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3271     struct soc_camera_link *icl;
3272     int ret;
3273
3274     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3275     if (!icd) {
3276         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3277         return -EINVAL;
3278     }
3279
3280     icl = to_soc_camera_link(icd);
3281     if (!icl) {
3282         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3283         return -EINVAL;
3284     }
3285
3286     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3287         dev_warn(&adapter->dev,
3288                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3289         return -EIO;
3290     }
3291
3292     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3293     if (!sensor)
3294         return -ENOMEM;
3295
3296     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3297
3298     /* Second stage probe - when a capture adapter is there */
3299     icd->ops            = &sensor_ops;
3300     sensor->info_priv.fmt = sensor_colour_fmts[0];
3301         #if CONFIG_SENSOR_I2C_NOSCHED
3302         atomic_set(&sensor->tasklock_cnt,0);
3303         #endif
3304
3305     ret = sensor_video_probe(icd, client);
3306     if (ret < 0) {
3307         icd->ops = NULL;
3308         i2c_set_clientdata(client, NULL);
3309         kfree(sensor);
3310                 sensor = NULL;
3311     }
3312     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3313     return ret;
3314 }
3315
3316 static int sensor_remove(struct i2c_client *client)
3317 {
3318     struct sensor *sensor = to_sensor(client);
3319     struct soc_camera_device *icd = client->dev.platform_data;
3320
3321     icd->ops = NULL;
3322     i2c_set_clientdata(client, NULL);
3323     client->driver = NULL;
3324     kfree(sensor);
3325         sensor = NULL;
3326     return 0;
3327 }
3328
3329 static const struct i2c_device_id sensor_id[] = {
3330         {SENSOR_NAME_STRING(), 0 },
3331         { }
3332 };
3333 MODULE_DEVICE_TABLE(i2c, sensor_id);
3334
3335 static struct i2c_driver sensor_i2c_driver = {
3336         .driver = {
3337                 .name = SENSOR_NAME_STRING(),
3338         },
3339         .probe          = sensor_probe,
3340         .remove         = sensor_remove,
3341         .id_table       = sensor_id,
3342 };
3343
3344 static int __init sensor_mod_init(void)
3345 {
3346     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3347     return i2c_add_driver(&sensor_i2c_driver);
3348 }
3349
3350 static void __exit sensor_mod_exit(void)
3351 {
3352     i2c_del_driver(&sensor_i2c_driver);
3353 }
3354
3355 device_initcall_sync(sensor_mod_init);
3356 module_exit(sensor_mod_exit);
3357
3358 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3359 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3360 MODULE_LICENSE("GPL");
3361
3362
3363