camera: camera driver and all sensor driver support
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / mt9d113.c
1 /*
2  * Driver for OV5642 CMOS Image Sensor from OmniVision
3  *
4  * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/hardirq.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <mach/rk29_camera.h>
24 #include "mt9d113.h"
25
26 static int debug;
27 module_param(debug, int, S_IRUGO|S_IWUSR);
28
29 #define dprintk(level, fmt, arg...) do {                        \
30         if (debug >= level)                                     \
31         printk(KERN_WARNING fmt , ## arg); } while (0)
32
33 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
34 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
38
39 #define __STR(x) #x
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
42
43 #define MIN(x,y)   ((x<y) ? x: y)
44 #define MAX(x,y)    ((x>y) ? x: y)
45
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK29_CAM_SENSOR_MT9D113
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9D113
49 #define SENSOR_ID 0x2580
50 #define SENSOR_ID_REG 0x00
51 #define SENSOR_RESET_REG SEQUENCE_END
52 #define SENSOR_RESET_VAL 0
53 #define SENSOR_DERESET_VAL 0
54 #define SENSOR_RESET_REG_LEN  WORD_LEN
55 #define SENSOR_MIN_WIDTH    800
56 #define SENSOR_MIN_HEIGHT   600
57 #define SENSOR_MAX_WIDTH    1600
58 #define SENSOR_MAX_HEIGHT   1200
59 #define SENSOR_INIT_WIDTH       800                     /* Sensor pixel size for sensor_init_data array */
60 #define SENSOR_INIT_HEIGHT  600
61 #define SENSOR_INIT_WINSEQADR sensor_init_data
62 #define SENSOR_INIT_PIXFMT V4L2_PIX_FMT_UYVY
63
64 #define CONFIG_SENSOR_WhiteBalance      0
65 #define CONFIG_SENSOR_Brightness        0
66 #define CONFIG_SENSOR_Contrast      0
67 #define CONFIG_SENSOR_Saturation    0
68 #define CONFIG_SENSOR_Effect        0
69 #define CONFIG_SENSOR_Scene         0
70 #define CONFIG_SENSOR_DigitalZoom   0
71 #define CONFIG_SENSOR_Exposure      0
72 #define CONFIG_SENSOR_Flash         0
73 #define CONFIG_SENSOR_Mirror        0
74 #define CONFIG_SENSOR_Flip          0
75 #define CONFIG_SENSOR_Focus         0
76
77 #define CONFIG_SENSOR_I2C_SPEED     100000       /* Hz */
78 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
79 #define CONFIG_SENSOR_I2C_NOSCHED   0
80 #define CONFIG_SENSOR_I2C_RDWRCHK   1
81
82 #define SENSOR_BUS_PARAM  (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_FALLING |\
83                           SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
84                           SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
85
86 #define COLOR_TEMPERATURE_CLOUDY_DN  6500
87 #define COLOR_TEMPERATURE_CLOUDY_UP    8000
88 #define COLOR_TEMPERATURE_CLEARDAY_DN  5000
89 #define COLOR_TEMPERATURE_CLEARDAY_UP    6500
90 #define COLOR_TEMPERATURE_OFFICE_DN     3500
91 #define COLOR_TEMPERATURE_OFFICE_UP     5000
92 #define COLOR_TEMPERATURE_HOME_DN       2500
93 #define COLOR_TEMPERATURE_HOME_UP       3500
94
95 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
96 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
97
98 #define SENSOR_AF_IS_ERR    (0x00<<0)
99 #define SENSOR_AF_IS_OK         (0x01<<0)
100
101 #if CONFIG_SENSOR_Focus
102 #define SENSOR_AF_MODE_INFINITY    0
103 #define SENSOR_AF_MODE_MACRO       1
104 #define SENSOR_AF_MODE_FIXED       2
105 #define SENSOR_AF_MODE_AUTO        3
106 #define SENSOR_AF_MODE_CONTINUOUS  4
107 #define SENSOR_AF_MODE_CLOSE       5
108 #endif
109
110 /* init 800x600 SVGA */
111 static struct reginfo sensor_init_data[] =
112 {
113     #if 0
114     //[Step2-PLL_Timing]
115     //for 24MHz input, VCO=MAX PCLK=76.8MHz
116     { 0x0014, 0x21F9, WORD_LEN, 0},     //PLL Control: BYPASS PLL = 8697
117     { 0x0010, 0x0110, WORD_LEN, 0},     //PLL Dividers = 272
118     { 0x0012, 0x1FF7, WORD_LEN, 0},      //PLL P Dividers = 8183
119     { 0x0014, 0x21FB, WORD_LEN, 0},     //PLL Control: PLL_ENABLE on = 8699
120     { 0x0014, 0x20FB, WORD_LEN, 0},     //PLL Control: SEL_LOCK_DET on = 8443
121
122     { SEQUENCE_WAIT_US, 1, WORD_LEN, 0},                // Allow PLL to lock
123
124     { 0x0014, 0x20FA, WORD_LEN, 0},     //PLL Control: PLL_BYPASS off = 8442
125     { 0x0018, 0x402D, WORD_LEN, 0},
126
127     //GO
128     { 0x0018, 0x402C, WORD_LEN, 0},
129
130     { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
131
132     { 0x321C, 0x0003, WORD_LEN, 0},     //By Pass TxFIFO = 3
133     { 0x098C, 0x2703, WORD_LEN, 0},     //Output Width (A)
134     { 0x0990, 0x0320, WORD_LEN, 0},     //      = 800
135     { 0x98C, 0x2705, WORD_LEN, 0},        //Output Height (A)
136     { 0x990, 0x0258    , WORD_LEN, 0},   //      = 600
137     { 0x98C, 0x2707, WORD_LEN, 0},        //Output Width (B)
138     { 0x990, 0x0640    , WORD_LEN, 0},   //      = 1600
139     { 0x98C, 0x2709     , WORD_LEN, 0},   //Output Height (B)
140     { 0x990, 0x04B0    , WORD_LEN, 0},   //      = 1200
141     { 0x98C, 0x270D  , WORD_LEN, 0},     //Row Start (A)
142     { 0x990, 0x000      , WORD_LEN, 0},   //      = 0
143     { 0x98C, 0x270F   , WORD_LEN, 0},     //Column Start (A)
144     { 0x990, 0x000      , WORD_LEN, 0},   //      = 0
145     { 0x98C, 0x2711    , WORD_LEN, 0},    //Row End (A)
146     { 0x990, 0x4BD     , WORD_LEN, 0},   //      = 1213
147     { 0x98C, 0x2713  , WORD_LEN, 0},      //Column End (A)
148     { 0x990, 0x64D      , WORD_LEN, 0},   //      = 1613
149     { 0x98C, 0x2715  , WORD_LEN, 0},      //Row Speed (A)
150     { 0x990, 0x0111    , WORD_LEN, 0},   //      = 273
151     { 0x98C, 0x2717  , WORD_LEN, 0},      //Read Mode (A)
152 //miaozh modify    
153     { 0x0990, 0x046C      , WORD_LEN, 0}, //  MCU_DATA_0
154 //    { 0x0990, 0x046E      , WORD_LEN, 0}, //  MCU_DATA_0
155 //    { 0x098C, 0xA103      , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
156 //    { 0x0990, 0x0006      , WORD_LEN, 0}, // MCU_DATA_0
157
158     { 0x98C, 0x2719  , WORD_LEN, 0},      //sensor_fine_correction (A)
159     { 0x990, 0x005A   , WORD_LEN, 0},   //      = 90
160     { 0x98C, 0x271B , WORD_LEN, 0},      //sensor_fine_IT_min (A)
161     { 0x990, 0x01BE    , WORD_LEN, 0},   //      = 446
162     { 0x98C, 0x271D , WORD_LEN, 0},      //sensor_fine_IT_max_margin (A)
163     { 0x990, 0x0131    , WORD_LEN, 0},   //      = 305
164     { 0x98C, 0x271F , WORD_LEN, 0},       //Frame Lines (A)
165     { 0x990, 0x02B3    , WORD_LEN, 0},   //      = 691
166     { 0x98C, 0x2721 , WORD_LEN, 0},       //Line Length (A)
167     { 0x990, 0x056D   , WORD_LEN, 0},   //      = 1389
168     { 0x98C, 0x2723 , WORD_LEN, 0},       //Row Start (B)
169     { 0x990, 0x004      , WORD_LEN, 0},   //      = 4
170     { 0x98C, 0x2725 , WORD_LEN, 0},       //Column Start (B)
171     { 0x990, 0x004      , WORD_LEN, 0},   //      = 4
172     { 0x98C, 0x2727 , WORD_LEN, 0},       //Row End (B)
173     { 0x990, 0x4BB      , WORD_LEN, 0},   //      = 1211
174     { 0x98C, 0x2729 , WORD_LEN, 0},       //Column End (B)
175     { 0x990, 0x64B      , WORD_LEN, 0},   //      = 1611
176     { 0x98C, 0x272B , WORD_LEN, 0},      //Row Speed (B)
177     { 0x990, 0x0111    , WORD_LEN, 0},   //      = 273
178     { 0x98C, 0x272D , WORD_LEN, 0},      //Read Mode (B)
179     { 0x990, 0x0024    , WORD_LEN, 0},   //      = 36
180     { 0x98C, 0x272F , WORD_LEN, 0},       //sensor_fine_correction (B)
181     { 0x990, 0x003A   , WORD_LEN, 0},   //      = 58
182     { 0x98C, 0x2731 , WORD_LEN, 0},       //sensor_fine_IT_min (B)
183     { 0x990, 0x00F6    , WORD_LEN, 0},   //      = 246
184     { 0x98C, 0x2733 , WORD_LEN, 0},       //sensor_fine_IT_max_margin (B)
185     { 0x990, 0x008B    , WORD_LEN, 0},   //      = 139
186     { 0x98C, 0x2735  , WORD_LEN, 0},      //Frame Lines (B)
187     { 0x990, 0x050D   , WORD_LEN, 0},   //      = 1293
188     { 0x98C, 0x2737  , WORD_LEN, 0},      //Line Length (B)
189     { 0x990, 0x0894    , WORD_LEN, 0},   //      = 2196
190     { 0x98C, 0x2739  , WORD_LEN, 0},      //Crop_X0 (A)
191     { 0x990, 0x0000    , WORD_LEN, 0},   //      = 0
192     { 0x98C, 0x273B  , WORD_LEN, 0},     //Crop_X1 (A)
193     { 0x990, 0x031F    , WORD_LEN, 0},   //      = 799
194     { 0x98C, 0x273D , WORD_LEN, 0},      //Crop_Y0 (A)
195     { 0x990, 0x0000    , WORD_LEN, 0},   //      = 0
196     { 0x98C, 0x273F , WORD_LEN, 0},       //Crop_Y1 (A)
197     { 0x990, 0x0257    , WORD_LEN, 0},   //      = 599
198     { 0x98C, 0x2747  , WORD_LEN, 0},      //Crop_X0 (B)
199     { 0x990, 0x0000    , WORD_LEN, 0},   //      = 0
200     { 0x98C, 0x2749   , WORD_LEN, 0},     //Crop_X1 (B)
201     { 0x990, 0x063F    , WORD_LEN, 0},   //      = 1599
202     { 0x98C, 0x274B   , WORD_LEN, 0},    //Crop_Y0 (B)
203     { 0x990, 0x0000    , WORD_LEN, 0},   //      = 0
204     { 0x98C, 0x274D   , WORD_LEN, 0},    //Crop_Y1 (B)
205     { 0x990, 0x04AF   , WORD_LEN, 0},   //      = 1199
206     { 0x98C, 0x222D   , WORD_LEN, 0},    //R9 Step
207     { 0x990, 0x0090    , WORD_LEN, 0},   //      = 144
208     { 0x98C, 0xA408   , WORD_LEN, 0},    //search_f1_50
209     { 0x990, 0x23     , WORD_LEN, 0},     //      = 35
210     { 0x98C, 0xA409   , WORD_LEN, 0},    //search_f2_50
211     { 0x990, 0x25         , WORD_LEN, 0},   //      = 37
212     { 0x98C, 0xA40A    , WORD_LEN, 0},  //search_f1_60
213     { 0x990, 0x2A        , WORD_LEN, 0},   //      = 42
214     { 0x98C, 0xA40B    , WORD_LEN, 0},   //search_f2_60
215     { 0x990, 0x2C        , WORD_LEN, 0},   //      = 44
216     { 0x98C, 0x2411     , WORD_LEN, 0},   //R9_Step_60 (A)
217     { 0x990, 0x0090    , WORD_LEN, 0},   //      = 144
218     { 0x98C, 0x2413    , WORD_LEN, 0},    //R9_Step_50 (A)
219     { 0x990, 0x00AD   , WORD_LEN, 0},   //      = 173
220     { 0x98C, 0x2415     , WORD_LEN, 0},   //R9_Step_60 (B)
221     { 0x990, 0x005B    , WORD_LEN, 0},   //      = 91
222     { 0x98C, 0x2417    , WORD_LEN, 0},    //R9_Step_50 (B)
223     { 0x990, 0x006D   , WORD_LEN, 0},   //      = 109
224     { 0x98C, 0xA404   , WORD_LEN, 0},    //FD Mode
225     { 0x990, 0x10         , WORD_LEN, 0},   //      = 16
226     { 0x98C, 0xA40D   , WORD_LEN, 0},   //Stat_min
227     { 0x990, 0x02         , WORD_LEN, 0},   //      = 2
228     { 0x98C, 0xA40E    , WORD_LEN, 0},   //Stat_max
229     { 0x990, 0x03         , WORD_LEN, 0},   //      = 3
230     { 0x98C, 0xA410   , WORD_LEN, 0},    //Min_amplitude
231     { 0x990, 0x0A        , WORD_LEN, 0},   //      = 10
232     { 0x98C, 0xA103   , WORD_LEN, 0},    //Refresh Sequencer Mode
233     { 0x990, 0x06         , WORD_LEN, 0},   //      = 6
234     //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100  // wait for command to be processed
235
236     { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
237
238     { 0x98C, 0xA103  , WORD_LEN, 0},     //Refresh Sequencer
239     { 0x990, 0x05   , WORD_LEN, 0},   //      = 5
240
241     { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
242
243     //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100  // wait for command to be processed
244     {SEQUENCE_END, 0x00}
245 #else
246     //[Step2-PLL_Timing]
247     //for 24MHz input, VCO=MAX PCLK=76.8MHz
248     { 0x001A, 0x0051, WORD_LEN, 0}, //  RESET_AND_MISC_CONTROL
249     { 0x001A, 0x0050, WORD_LEN, 0}, //  RESET_AND_MISC_CONTROL
250     { 0x0014, 0x2545, WORD_LEN, 0}, //  PLL_CONTROL
251     { 0x0010, 0x011C, WORD_LEN, 0}, //  PLL_DIVIDERS
252     { 0x0012, 0x1FF7, WORD_LEN, 0}, //  PLL_P_DIVIDERS
253     { 0x0014, 0x2547, WORD_LEN, 0}, //  PLL_CONTROL
254     { 0x0014, 0x2447, WORD_LEN, 0}, //  PLL_CONTROL
255     { 0x0014, 0x2047, WORD_LEN, 0}, //  PLL_CONTROL
256     { 0x0014, 0x2046, WORD_LEN, 0}, //  PLL_CONTROL
257     { 0x001A, 0x0050, WORD_LEN, 0}, //  RESET_AND_MISC_CONTROL
258     { 0x0018, 0x4028      , WORD_LEN, 0}, //  STANDBY_CONTROL
259     { 0x321C, 0x0003      , WORD_LEN, 0}, //  OFIFO_CONTROL_STATUS
260     { 0x098C, 0x2703      , WORD_LEN, 0}, //  MCU_ADDRESS
261     { 0x0990, 0x0320      , WORD_LEN, 0}, //  MCU_DATA_0
262     { 0x098C, 0x2705      , WORD_LEN, 0}, //  MCU_ADDRESS
263     { 0x0990, 0x0258      , WORD_LEN, 0}, //  MCU_DATA_0
264     { 0x098C, 0x2707      , WORD_LEN, 0}, //  MCU_ADDRESS
265     { 0x0990, 0x0640      , WORD_LEN, 0}, //  MCU_DATA_0
266     { 0x098C, 0x2709      , WORD_LEN, 0}, //  MCU_ADDRESS
267     { 0x0990, 0x04B0      , WORD_LEN, 0}, //  MCU_DATA_0
268     { 0x098C, 0x270D      , WORD_LEN, 0}, //  MCU_ADDRESS
269     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
270     { 0x098C, 0x270F      , WORD_LEN, 0}, //  MCU_ADDRESS
271     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
272     { 0x098C, 0x2711      , WORD_LEN, 0}, //  MCU_ADDRESS
273     { 0x0990, 0x04BD      , WORD_LEN, 0}, //  MCU_DATA_0
274     { 0x098C, 0x2713      , WORD_LEN, 0}, //  MCU_ADDRESS
275     { 0x0990, 0x064D      , WORD_LEN, 0}, //  MCU_DATA_0
276     { 0x098C, 0x2715      , WORD_LEN, 0}, //  MCU_ADDRESS
277     { 0x0990, 0x0111      , WORD_LEN, 0}, //  MCU_DATA_0
278     { 0x098C, 0x2717      , WORD_LEN, 0}, //  MCU_ADDRESS
279 //miaozh modify    
280     { 0x0990, 0x046C      , WORD_LEN, 0}, //  MCU_DATA_0
281 //    { 0x0990, 0x046E      , WORD_LEN, 0}, //  MCU_DATA_0
282 //    { 0x098C, 0xA103      , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
283 //    { 0x0990, 0x0006      , WORD_LEN, 0}, // MCU_DATA_0
284
285     { 0x098C, 0x2719      , WORD_LEN, 0}, //  MCU_ADDRESS
286     { 0x0990, 0x005A      , WORD_LEN, 0}, //  MCU_DATA_0
287     { 0x098C, 0x271B      , WORD_LEN, 0}, //  MCU_ADDRESS
288     { 0x0990, 0x01BE      , WORD_LEN, 0}, //  MCU_DATA_0
289     { 0x098C, 0x271D      , WORD_LEN, 0}, //  MCU_ADDRESS
290     { 0x0990, 0x0131      , WORD_LEN, 0}, //  MCU_DATA_0
291     { 0x098C, 0x271F      , WORD_LEN, 0}, //  MCU_ADDRESS
292     { 0x0990, 0x02B3      , WORD_LEN, 0}, //  MCU_DATA_0
293     { 0x098C, 0x2721      , WORD_LEN, 0}, //  MCU_ADDRESS
294     { 0x0990, 0x09B0      , WORD_LEN, 0}, //  MCU_DATA_0
295     { 0x098C, 0x2723      , WORD_LEN, 0}, //  MCU_ADDRESS
296     { 0x0990, 0x0004      , WORD_LEN, 0}, //  MCU_DATA_0
297     { 0x098C, 0x2725      , WORD_LEN, 0}, //  MCU_ADDRESS
298     { 0x0990, 0x0004      , WORD_LEN, 0}, //  MCU_DATA_0
299     { 0x098C, 0x2727      , WORD_LEN, 0}, //  MCU_ADDRESS
300     { 0x0990, 0x04BB      , WORD_LEN, 0}, //  MCU_DATA_0
301     { 0x098C, 0x2729      , WORD_LEN, 0}, //  MCU_ADDRESS
302     { 0x0990, 0x064B      , WORD_LEN, 0}, //  MCU_DATA_0
303     { 0x098C, 0x272B      , WORD_LEN, 0}, //  MCU_ADDRESS
304     { 0x0990, 0x0111      , WORD_LEN, 0}, //  MCU_DATA_0
305     { 0x098C, 0x272D      , WORD_LEN, 0}, //  MCU_ADDRESS
306     { 0x0990, 0x0024      , WORD_LEN, 0}, //  MCU_DATA_0
307     { 0x098C, 0x272F      , WORD_LEN, 0}, //  MCU_ADDRESS
308     { 0x0990, 0x003A      , WORD_LEN, 0}, //  MCU_DATA_0
309     { 0x098C, 0x2731      , WORD_LEN, 0}, //  MCU_ADDRESS
310     { 0x0990, 0x00F6      , WORD_LEN, 0}, //  MCU_DATA_0
311     { 0x098C, 0x2733      , WORD_LEN, 0}, //  MCU_ADDRESS
312     { 0x0990, 0x008B      , WORD_LEN, 0}, //  MCU_DATA_0
313     { 0x098C, 0x2735      , WORD_LEN, 0}, //  MCU_ADDRESS
314     { 0x0990, 0x050D      , WORD_LEN, 0}, //  MCU_DATA_0
315     { 0x098C, 0x2737      , WORD_LEN, 0}, //  MCU_ADDRESS
316     { 0x0990, 0x0807      , WORD_LEN, 0}, //  MCU_DATA_0
317     { 0x098C, 0x2739      , WORD_LEN, 0}, //  MCU_ADDRESS
318     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
319     { 0x098C, 0x273B      , WORD_LEN, 0}, //  MCU_ADDRESS
320     { 0x0990, 0x031F      , WORD_LEN, 0}, //  MCU_DATA_0
321     { 0x098C, 0x273D      , WORD_LEN, 0}, //  MCU_ADDRESS
322     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
323     { 0x098C, 0x273F      , WORD_LEN, 0}, //  MCU_ADDRESS
324     { 0x0990, 0x0257      , WORD_LEN, 0}, //  MCU_DATA_0
325     { 0x098C, 0x2747      , WORD_LEN, 0}, //  MCU_ADDRESS
326     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
327     { 0x098C, 0x2749      , WORD_LEN, 0}, //  MCU_ADDRESS
328     { 0x0990, 0x063F      , WORD_LEN, 0}, //  MCU_DATA_0
329     { 0x098C, 0x274B      , WORD_LEN, 0}, //  MCU_ADDRESS
330     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
331     { 0x098C, 0x274D      , WORD_LEN, 0}, //  MCU_ADDRESS
332     { 0x0990, 0x04AF      , WORD_LEN, 0}, //  MCU_DATA_0
333     { 0x098C, 0x222D      , WORD_LEN, 0}, //  MCU_ADDRESS
334     { 0x0990, 0x008D      , WORD_LEN, 0}, //  MCU_DATA_0
335     { 0x098C, 0xA408      , WORD_LEN, 0}, //  MCU_ADDRESS
336     { 0x0990, 0x0022      , WORD_LEN, 0}, //  MCU_DATA_0
337     { 0x098C, 0xA409      , WORD_LEN, 0}, //  MCU_ADDRESS
338     { 0x0990, 0x0024      , WORD_LEN, 0}, //  MCU_DATA_0
339     { 0x098C, 0xA40A      , WORD_LEN, 0}, //  MCU_ADDRESS
340     { 0x0990, 0x0029      , WORD_LEN, 0}, //  MCU_DATA_0
341     { 0x098C, 0xA40B      , WORD_LEN, 0}, //  MCU_ADDRESS
342     { 0x0990, 0x002B      , WORD_LEN, 0}, //  MCU_DATA_0
343     { 0x098C, 0x2411      , WORD_LEN, 0}, //  MCU_ADDRESS
344     { 0x0990, 0x008D      , WORD_LEN, 0}, //  MCU_DATA_0
345     { 0x098C, 0x2413      , WORD_LEN, 0}, //  MCU_ADDRESS
346     { 0x0990, 0x00A9      , WORD_LEN, 0}, //  MCU_DATA_0
347     { 0x098C, 0x2415      , WORD_LEN, 0}, //  MCU_ADDRESS
348     { 0x0990, 0x00AA      , WORD_LEN, 0}, //  MCU_DATA_0
349     { 0x098C, 0x2417      , WORD_LEN, 0}, //  MCU_ADDRESS
350     { 0x0990, 0x00CC      , WORD_LEN, 0}, //  MCU_DATA_0
351     { 0x098C, 0xA404      , WORD_LEN, 0}, //  MCU_ADDRESS
352     { 0x0990, 0x0010      , WORD_LEN, 0}, //  MCU_DATA_0
353     { 0x098C, 0xA40D      , WORD_LEN, 0}, //  MCU_ADDRESS
354     { 0x0990, 0x0002      , WORD_LEN, 0}, //  MCU_DATA_0
355     { 0x098C, 0xA40E      , WORD_LEN, 0}, //  MCU_ADDRESS
356     { 0x0990, 0x0003      , WORD_LEN, 0}, //  MCU_DATA_0
357     { 0x098C, 0xA410      , WORD_LEN, 0}, //  MCU_ADDRESS
358     { 0x0990, 0x000A      , WORD_LEN, 0}, //  MCU_DATA_0
359     { 0x098C, 0xA103      , WORD_LEN, 0}, //  MCU_ADDRESS
360     { 0x0990, 0x0006      , WORD_LEN, 0}, //  MCU_DATA_0
361     { 0x098C, 0xA103      , WORD_LEN, 0}, //  MCU_ADDRESS
362     { 0x0990, 0x0005      , WORD_LEN, 0}, //  MCU_DATA_0
363     {SEQUENCE_END, 0x00}
364 #endif
365 };
366
367 /* 720p 15fps @ 1280x720 */
368
369 static struct reginfo sensor_720p[]=
370 {
371         {SEQUENCE_END, 0x00}
372 };
373
374 /*      1080p, 0x15fps, 0xyuv @1920x1080 */
375
376 static struct reginfo sensor_1080p[]=
377 {
378         {SEQUENCE_END, 0x00}
379 };
380
381 /* 2592X1944 QSXGA */
382 static struct reginfo sensor_qsxga[] =
383 {
384         {SEQUENCE_END, 0x00}
385 };
386 /* 2048*1536 QXGA */
387 static struct reginfo sensor_qxga[] =
388 {
389         {SEQUENCE_END, 0x00}
390 };
391
392 /* 1600X1200 UXGA */
393 static struct reginfo sensor_uxga[] =
394 {
395         //capture2preview
396         { 0x098C, 0xA115, WORD_LEN, 0},         // MCU_ADDRESS [SEQ_CAP_MODE]
397     { 0x0990, 0x0002, WORD_LEN, 0},     // MCU_DATA_0
398     { 0x098C, 0xA103, WORD_LEN, 0},     // MCU_ADDRESS [SEQ_CMD]
399     { 0x0990, 0x0002, WORD_LEN, 0},     // MCU_DATA_0
400         {SEQUENCE_END, 0x00}
401 };
402 /* 1280X1024 SXGA */
403 static struct reginfo sensor_sxga[] =
404 {
405 #if     0
406         { 0x098C, 0xA115, WORD_LEN, 0},         // MCU_ADDRESS [SEQ_CAP_MODE]
407         { 0x0990, 0x0000, WORD_LEN, 0},         // MCU_DATA_0
408         { 0x098C, 0xA103, WORD_LEN, 0},         // MCU_ADDRESS [SEQ_CMD]
409         { 0x0990, 0x0001, WORD_LEN, 0},         // MCU_DATA_0
410
411 //miaozh add
412 //    { 0x098C, 0x2717      , WORD_LEN, 0}, //  MCU_ADDRESS    
413 //    { 0x0990, 0x046E      , WORD_LEN, 0}, //  MCU_DATA_0
414 //    { 0x098C, 0xA103      , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
415 //    { 0x0990, 0x0006      , WORD_LEN, 0}, // MCU_DATA_0
416
417         { 0x098C, 0x2747, WORD_LEN, 0},         // MCU_ADDRESS [MODE_CROP_X0_B]
418         { 0x0990, 0x0000, WORD_LEN, 0},         // MCU_DATA_0
419         { 0x098C, 0x2749, WORD_LEN, 0},         // MCU_ADDRESS [MODE_CROP_X1_B]
420         { 0x0990, 0x063F, WORD_LEN, 0},         // MCU_DATA_0
421         { 0x098C, 0x274B, WORD_LEN, 0},         // MCU_ADDRESS [MODE_CROP_Y0_B]
422         { 0x0990, 0x0000, WORD_LEN, 0},         // MCU_DATA_0
423         { 0x098C, 0x274D, WORD_LEN, 0},         // MCU_ADDRESS [MODE_CROP_Y1_B]
424         { 0x0990, 0x04AF, WORD_LEN, 0},         // MCU_DATA_0
425         { 0x098C, 0x2707, WORD_LEN, 0},         // MCU_ADDRESS [MODE_OUTPUT_WIDTH_B]
426         { 0x0990, 0x0500, WORD_LEN, 0},         // MCU_DATA_0
427         { 0x098C, 0x2709, WORD_LEN, 0},         // MCU_ADDRESS [MODE_OUTPUT_HEIGHT_B]
428         { 0x0990, 0x0400, WORD_LEN, 0},         // MCU_DATA_0
429
430         { 0x098C, 0xA103, WORD_LEN, 0},         // MCU_ADDRESS [SEQ_CMD]
431         { 0x0990, 0x0005, WORD_LEN, 0},         // MCU_DATA_0
432
433         { 0x098C, 0xA115, WORD_LEN, 0},         // MCU_ADDRESS [SEQ_CAP_MODE]
434         { 0x0990, 0x0002, WORD_LEN, 0},         // MCU_DATA_0
435         { 0x098C, 0xA103, WORD_LEN, 0},         // MCU_ADDRESS [SEQ_CMD]
436         { 0x0990, 0x0002, WORD_LEN, 0},         // MCU_DATA_0
437
438 #endif
439         {SEQUENCE_END, 0x00}    
440 };
441 /*  1024X768 XGA */
442 static struct reginfo sensor_xga[] =
443 {
444         {SEQUENCE_END, 0x00}
445 };
446
447 /* 800X600 SVGA*/
448 static struct reginfo sensor_svga[] =
449 {
450         //[Step2-PLL_Timing]
451     //for 24MHz input, VCO=MAX PCLK=76.8MHz
452     { 0x001A, 0x0051, WORD_LEN, 0}, //  RESET_AND_MISC_CONTROL
453     { 0x001A, 0x0050, WORD_LEN, 0}, //  RESET_AND_MISC_CONTROL
454     { 0x0014, 0x2545, WORD_LEN, 0}, //  PLL_CONTROL
455     { 0x0010, 0x011C, WORD_LEN, 0}, //  PLL_DIVIDERS
456     { 0x0012, 0x1FF7, WORD_LEN, 0}, //  PLL_P_DIVIDERS
457     { 0x0014, 0x2547, WORD_LEN, 0}, //  PLL_CONTROL
458     { 0x0014, 0x2447, WORD_LEN, 0}, //  PLL_CONTROL
459     { 0x0014, 0x2047, WORD_LEN, 0}, //  PLL_CONTROL
460     { 0x0014, 0x2046, WORD_LEN, 0}, //  PLL_CONTROL
461     { 0x001A, 0x0050, WORD_LEN, 0}, //  RESET_AND_MISC_CONTROL
462     { 0x0018, 0x4028      , WORD_LEN, 0}, //  STANDBY_CONTROL
463     { 0x321C, 0x0003      , WORD_LEN, 0}, //  OFIFO_CONTROL_STATUS
464     { 0x098C, 0x2703      , WORD_LEN, 0}, //  MCU_ADDRESS
465     { 0x0990, 0x0320      , WORD_LEN, 0}, //  MCU_DATA_0
466     { 0x098C, 0x2705      , WORD_LEN, 0}, //  MCU_ADDRESS
467     { 0x0990, 0x0258      , WORD_LEN, 0}, //  MCU_DATA_0
468     { 0x098C, 0x2707      , WORD_LEN, 0}, //  MCU_ADDRESS
469     { 0x0990, 0x0640      , WORD_LEN, 0}, //  MCU_DATA_0
470     { 0x098C, 0x2709      , WORD_LEN, 0}, //  MCU_ADDRESS
471     { 0x0990, 0x04B0      , WORD_LEN, 0}, //  MCU_DATA_0
472     { 0x098C, 0x270D      , WORD_LEN, 0}, //  MCU_ADDRESS
473     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
474     { 0x098C, 0x270F      , WORD_LEN, 0}, //  MCU_ADDRESS
475     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
476     { 0x098C, 0x2711      , WORD_LEN, 0}, //  MCU_ADDRESS
477     { 0x0990, 0x04BD      , WORD_LEN, 0}, //  MCU_DATA_0
478     { 0x098C, 0x2713      , WORD_LEN, 0}, //  MCU_ADDRESS
479     { 0x0990, 0x064D      , WORD_LEN, 0}, //  MCU_DATA_0
480     { 0x098C, 0x2715      , WORD_LEN, 0}, //  MCU_ADDRESS
481     { 0x0990, 0x0111      , WORD_LEN, 0}, //  MCU_DATA_0
482     { 0x098C, 0x2717      , WORD_LEN, 0}, //  MCU_ADDRESS
483 //miaozh modify    
484     { 0x0990, 0x046C      , WORD_LEN, 0}, //  MCU_DATA_0
485 //    { 0x0990, 0x046E      , WORD_LEN, 0}, //  MCU_DATA_0
486 //    { 0x098C, 0xA103      , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
487 //    { 0x0990, 0x0006      , WORD_LEN, 0}, // MCU_DATA_0
488
489     
490     { 0x098C, 0x2719      , WORD_LEN, 0}, //  MCU_ADDRESS
491     { 0x0990, 0x005A      , WORD_LEN, 0}, //  MCU_DATA_0
492     { 0x098C, 0x271B      , WORD_LEN, 0}, //  MCU_ADDRESS
493     { 0x0990, 0x01BE      , WORD_LEN, 0}, //  MCU_DATA_0
494     { 0x098C, 0x271D      , WORD_LEN, 0}, //  MCU_ADDRESS
495     { 0x0990, 0x0131      , WORD_LEN, 0}, //  MCU_DATA_0
496     { 0x098C, 0x271F      , WORD_LEN, 0}, //  MCU_ADDRESS
497     { 0x0990, 0x02B3      , WORD_LEN, 0}, //  MCU_DATA_0
498     { 0x098C, 0x2721      , WORD_LEN, 0}, //  MCU_ADDRESS
499     { 0x0990, 0x09B0      , WORD_LEN, 0}, //  MCU_DATA_0
500     { 0x098C, 0x2723      , WORD_LEN, 0}, //  MCU_ADDRESS
501     { 0x0990, 0x0004      , WORD_LEN, 0}, //  MCU_DATA_0
502     { 0x098C, 0x2725      , WORD_LEN, 0}, //  MCU_ADDRESS
503     { 0x0990, 0x0004      , WORD_LEN, 0}, //  MCU_DATA_0
504     { 0x098C, 0x2727      , WORD_LEN, 0}, //  MCU_ADDRESS
505     { 0x0990, 0x04BB      , WORD_LEN, 0}, //  MCU_DATA_0
506     { 0x098C, 0x2729      , WORD_LEN, 0}, //  MCU_ADDRESS
507     { 0x0990, 0x064B      , WORD_LEN, 0}, //  MCU_DATA_0
508     { 0x098C, 0x272B      , WORD_LEN, 0}, //  MCU_ADDRESS
509     { 0x0990, 0x0111      , WORD_LEN, 0}, //  MCU_DATA_0
510     { 0x098C, 0x272D      , WORD_LEN, 0}, //  MCU_ADDRESS
511     { 0x0990, 0x0024      , WORD_LEN, 0}, //  MCU_DATA_0
512     { 0x098C, 0x272F      , WORD_LEN, 0}, //  MCU_ADDRESS
513     { 0x0990, 0x003A      , WORD_LEN, 0}, //  MCU_DATA_0
514     { 0x098C, 0x2731      , WORD_LEN, 0}, //  MCU_ADDRESS
515     { 0x0990, 0x00F6      , WORD_LEN, 0}, //  MCU_DATA_0
516     { 0x098C, 0x2733      , WORD_LEN, 0}, //  MCU_ADDRESS
517     { 0x0990, 0x008B      , WORD_LEN, 0}, //  MCU_DATA_0
518     { 0x098C, 0x2735      , WORD_LEN, 0}, //  MCU_ADDRESS
519     { 0x0990, 0x050D      , WORD_LEN, 0}, //  MCU_DATA_0
520     { 0x098C, 0x2737      , WORD_LEN, 0}, //  MCU_ADDRESS
521     { 0x0990, 0x0807      , WORD_LEN, 0}, //  MCU_DATA_0
522     { 0x098C, 0x2739      , WORD_LEN, 0}, //  MCU_ADDRESS
523     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
524     { 0x098C, 0x273B      , WORD_LEN, 0}, //  MCU_ADDRESS
525     { 0x0990, 0x031F      , WORD_LEN, 0}, //  MCU_DATA_0
526     { 0x098C, 0x273D      , WORD_LEN, 0}, //  MCU_ADDRESS
527     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
528     { 0x098C, 0x273F      , WORD_LEN, 0}, //  MCU_ADDRESS
529     { 0x0990, 0x0257      , WORD_LEN, 0}, //  MCU_DATA_0
530     { 0x098C, 0x2747      , WORD_LEN, 0}, //  MCU_ADDRESS
531     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
532     { 0x098C, 0x2749      , WORD_LEN, 0}, //  MCU_ADDRESS
533     { 0x0990, 0x063F      , WORD_LEN, 0}, //  MCU_DATA_0
534     { 0x098C, 0x274B      , WORD_LEN, 0}, //  MCU_ADDRESS
535     { 0x0990, 0x0000      , WORD_LEN, 0}, //  MCU_DATA_0
536     { 0x098C, 0x274D      , WORD_LEN, 0}, //  MCU_ADDRESS
537     { 0x0990, 0x04AF      , WORD_LEN, 0}, //  MCU_DATA_0
538     { 0x098C, 0x222D      , WORD_LEN, 0}, //  MCU_ADDRESS
539     { 0x0990, 0x008D      , WORD_LEN, 0}, //  MCU_DATA_0
540     { 0x098C, 0xA408      , WORD_LEN, 0}, //  MCU_ADDRESS
541     { 0x0990, 0x0022      , WORD_LEN, 0}, //  MCU_DATA_0
542     { 0x098C, 0xA409      , WORD_LEN, 0}, //  MCU_ADDRESS
543     { 0x0990, 0x0024      , WORD_LEN, 0}, //  MCU_DATA_0
544     { 0x098C, 0xA40A      , WORD_LEN, 0}, //  MCU_ADDRESS
545     { 0x0990, 0x0029      , WORD_LEN, 0}, //  MCU_DATA_0
546     { 0x098C, 0xA40B      , WORD_LEN, 0}, //  MCU_ADDRESS
547     { 0x0990, 0x002B      , WORD_LEN, 0}, //  MCU_DATA_0
548     { 0x098C, 0x2411      , WORD_LEN, 0}, //  MCU_ADDRESS
549     { 0x0990, 0x008D      , WORD_LEN, 0}, //  MCU_DATA_0
550     { 0x098C, 0x2413      , WORD_LEN, 0}, //  MCU_ADDRESS
551     { 0x0990, 0x00A9      , WORD_LEN, 0}, //  MCU_DATA_0
552     { 0x098C, 0x2415      , WORD_LEN, 0}, //  MCU_ADDRESS
553     { 0x0990, 0x00AA      , WORD_LEN, 0}, //  MCU_DATA_0
554     { 0x098C, 0x2417      , WORD_LEN, 0}, //  MCU_ADDRESS
555     { 0x0990, 0x00CC      , WORD_LEN, 0}, //  MCU_DATA_0
556     { 0x098C, 0xA404      , WORD_LEN, 0}, //  MCU_ADDRESS
557     { 0x0990, 0x0010      , WORD_LEN, 0}, //  MCU_DATA_0
558     { 0x098C, 0xA40D      , WORD_LEN, 0}, //  MCU_ADDRESS
559     { 0x0990, 0x0002      , WORD_LEN, 0}, //  MCU_DATA_0
560     { 0x098C, 0xA40E      , WORD_LEN, 0}, //  MCU_ADDRESS
561     { 0x0990, 0x0003      , WORD_LEN, 0}, //  MCU_DATA_0
562     { 0x098C, 0xA410      , WORD_LEN, 0}, //  MCU_ADDRESS
563     { 0x0990, 0x000A      , WORD_LEN, 0}, //  MCU_DATA_0
564     { 0x098C, 0xA103      , WORD_LEN, 0}, //  MCU_ADDRESS
565     { 0x0990, 0x0006      , WORD_LEN, 0}, //  MCU_DATA_0
566     { 0x098C, 0xA103      , WORD_LEN, 0}, //  MCU_ADDRESS
567     { 0x0990, 0x0005      , WORD_LEN, 0}, //  MCU_DATA_0
568     {SEQUENCE_END, 0x00}
569 };
570
571 /* 640X480 VGA */
572 static struct reginfo sensor_vga[] =
573 {
574     {SEQUENCE_END, 0x00}
575 };
576
577 /* 352X288 CIF */
578 static struct reginfo sensor_cif[] =
579 {
580         {SEQUENCE_END, 0x00}
581 };
582
583 /* 320*240 QVGA */
584 static  struct reginfo sensor_qvga[] =
585 {
586         {SEQUENCE_END, 0x00}
587 };
588
589 /* 176X144 QCIF*/
590 static struct reginfo sensor_qcif[] =
591 {
592         {SEQUENCE_END, 0x00}
593 };
594
595 static  struct reginfo sensor_Preview2Capture[]=
596 {
597         //capture2preview
598         {0x098E, 0x843C, WORD_LEN, 0},  // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
599         {0x843C, 0xFF, BYTE_LEN, 0 },   // SEQ_STATE_CFG_5_MAX_FRAME_CNT
600         {0x8404, 0x02, BYTE_LEN, 0 },   // SEQ_CMD
601         {SEQUENCE_END, 0x00}
602 };
603
604 static  struct reginfo sensor_Capture2Preview[]=
605 {
606         //snap2preview
607         {0x098E, 0x843C, WORD_LEN, 0},  // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
608         {0x843C, 0x01, BYTE_LEN, 0 },   // SEQ_STATE_CFG_5_MAX_FRAME_CNT
609         {0x8404, 0x01, BYTE_LEN, 0 },   // SEQ_CMD
610         {0x0016, 0x0047, WORD_LEN, 0},  // CLOCKS_CONTRO
611         {SEQUENCE_END, 0x00}
612 };
613
614 static  struct reginfo sensor_ClrFmt_YUYV[]=
615 {
616         {SEQUENCE_END, 0x00}
617 };
618
619 static  struct reginfo sensor_ClrFmt_UYVY[]=
620 {
621         {SEQUENCE_END, 0x00}
622 };
623
624
625 #if CONFIG_SENSOR_WhiteBalance
626 static  struct reginfo sensor_WhiteB_Auto[]=
627 {
628         //Auto
629         {SEQUENCE_END, 0x00}
630 };
631 /* Cloudy Colour Temperature : 6500K - 8000K  */
632 static  struct reginfo sensor_WhiteB_Cloudy[]=
633 {
634         //[V.       DL 7500]
635         {SEQUENCE_END, 0x00}
636 };
637 /* ClearDay Colour Temperature : 5000K - 6500K  */
638 static  struct reginfo sensor_WhiteB_ClearDay[]=
639 {
640         //[IV       Day Light]
641         {SEQUENCE_END, 0x00}
642 };
643 /* Office Colour Temperature : 3500K - 5000K  */
644 static  struct reginfo sensor_WhiteB_TungstenLamp1[]=
645 {
646         //[III        Fluorescent]
647         {SEQUENCE_END, 0x00}
648 };
649 /* Home Colour Temperature : 2500K - 3500K  */
650 static  struct reginfo sensor_WhiteB_TungstenLamp2[]=
651 {
652         //[II.        Incandescent]
653         {SEQUENCE_END, 0x00}
654 };
655 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
656     sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
657 };
658 #endif
659
660 #if CONFIG_SENSOR_Brightness
661 static  struct reginfo sensor_Brightness0[]=
662 {
663         {SEQUENCE_END, 0x00}
664 };
665
666 static  struct reginfo sensor_Brightness1[]=
667 {
668         {SEQUENCE_END, 0x00}
669 };
670
671 static  struct reginfo sensor_Brightness2[]=
672 {
673         {SEQUENCE_END, 0x00}
674 };
675
676 static  struct reginfo sensor_Brightness3[]=
677 {
678         {SEQUENCE_END, 0x00}
679 };
680
681 static  struct reginfo sensor_Brightness4[]=
682 {
683         {SEQUENCE_END, 0x00}
684 };
685
686 static  struct reginfo sensor_Brightness5[]=
687 {
688         {SEQUENCE_END, 0x00}
689 };
690 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
691     sensor_Brightness4, sensor_Brightness5,NULL,
692 };
693
694 #endif
695
696 #if CONFIG_SENSOR_Effect
697 static  struct reginfo sensor_Effect_Normal[] =
698 {
699         {SEQUENCE_END, 0x00}
700 };
701
702 static  struct reginfo sensor_Effect_WandB[] =
703 {
704         {SEQUENCE_END, 0x00}
705 };
706
707 static  struct reginfo sensor_Effect_Sepia[] =
708 {
709         {SEQUENCE_END, 0x00}
710 };
711
712 static  struct reginfo sensor_Effect_Negative[] =
713 {
714         {SEQUENCE_END, 0x00}
715 };
716 static  struct reginfo sensor_Effect_Bluish[] =
717 {
718         {SEQUENCE_END, 0x00}
719 };
720
721 static  struct reginfo sensor_Effect_Green[] =
722 {
723         {SEQUENCE_END, 0x00}
724 };
725
726 static struct reginfo sensor_Effect_Solarize[] =
727 {
728         {SEQUENCE_END, 0x00}
729 };
730 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_Negative,sensor_Effect_Sepia,
731     sensor_Effect_Solarize,NULL,
732 };
733 #endif
734 #if CONFIG_SENSOR_Exposure
735 static  struct reginfo sensor_Exposure0[]=
736 {
737         {SEQUENCE_END, 0x00}
738 };
739
740 static  struct reginfo sensor_Exposure1[]=
741 {
742         {SEQUENCE_END, 0x00}
743 };
744
745 static  struct reginfo sensor_Exposure2[]=
746 {
747         {SEQUENCE_END, 0x00}
748 };
749
750 static  struct reginfo sensor_Exposure3[]=
751 {
752         {SEQUENCE_END, 0x00}
753 };
754
755 static  struct reginfo sensor_Exposure4[]=
756 {
757         {SEQUENCE_END, 0x00}
758 };
759
760 static  struct reginfo sensor_Exposure5[]=
761 {
762         {SEQUENCE_END, 0x00}
763 };
764
765 static  struct reginfo sensor_Exposure6[]=
766 {
767         {SEQUENCE_END, 0x00}
768 };
769
770 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
771     sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
772 };
773 #endif
774 #if CONFIG_SENSOR_Saturation
775 static  struct reginfo sensor_Saturation0[]=
776 {
777         {SEQUENCE_END, 0x00}
778 };
779
780 static  struct reginfo sensor_Saturation1[]=
781 {
782         {SEQUENCE_END, 0x00}
783 };
784
785 static  struct reginfo sensor_Saturation2[]=
786 {
787         {SEQUENCE_END, 0x00}
788 };
789 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
790 #endif
791 #if CONFIG_SENSOR_Contrast
792 static  struct reginfo sensor_Contrast0[]=
793 {
794         {SEQUENCE_END, 0x00}
795 };
796
797 static  struct reginfo sensor_Contrast1[]=
798 {
799         {SEQUENCE_END, 0x00}
800 };
801
802 static  struct reginfo sensor_Contrast2[]=
803 {
804         {SEQUENCE_END, 0x00}
805 };
806
807 static  struct reginfo sensor_Contrast3[]=
808 {
809         {SEQUENCE_END, 0x00}
810 };
811
812 static  struct reginfo sensor_Contrast4[]=
813 {
814         {SEQUENCE_END, 0x00}
815 };
816
817
818 static  struct reginfo sensor_Contrast5[]=
819 {
820         {SEQUENCE_END, 0x00}
821 };
822
823 static  struct reginfo sensor_Contrast6[]=
824 {
825         {SEQUENCE_END, 0x00}
826 };
827 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
828     sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
829 };
830
831 #endif
832 #if CONFIG_SENSOR_Mirror
833 static  struct reginfo sensor_MirrorOn[]=
834 {
835         {SEQUENCE_END, 0x00}
836 };
837
838 static  struct reginfo sensor_MirrorOff[]=
839 {
840         {SEQUENCE_END, 0x00}
841 };
842 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
843 #endif
844 #if CONFIG_SENSOR_Flip
845 static  struct reginfo sensor_FlipOn[]=
846 {
847         {SEQUENCE_END, 0x00}
848 };
849
850 static  struct reginfo sensor_FlipOff[]=
851 {
852         {SEQUENCE_END, 0x00}
853 };
854 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
855
856 #endif
857 #if CONFIG_SENSOR_Scene
858 static  struct reginfo sensor_SceneAuto[] =
859 {
860         {SEQUENCE_END, 0x00}
861 };
862
863 static  struct reginfo sensor_SceneNight[] =
864 {
865         {SEQUENCE_END, 0x00}
866 };
867 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
868
869 #endif
870 #if CONFIG_SENSOR_DigitalZoom
871 static struct reginfo sensor_Zoom0[] =
872 {
873         {SEQUENCE_END, 0x00}
874 };
875
876 static struct reginfo sensor_Zoom1[] =
877 {
878         {SEQUENCE_END, 0x00}
879 };
880
881 static struct reginfo sensor_Zoom2[] =
882 {
883         {SEQUENCE_END, 0x00}
884 };
885
886
887 static struct reginfo sensor_Zoom3[] =
888 {
889         {SEQUENCE_END, 0x00}
890 };
891 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
892 #endif
893 static const struct v4l2_querymenu sensor_menus[] =
894 {
895         #if CONFIG_SENSOR_WhiteBalance
896     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 0,  .name = "auto",  .reserved = 0, }, {  .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 1, .name = "incandescent",  .reserved = 0,},
897     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 2,  .name = "fluorescent", .reserved = 0,}, {  .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3,  .name = "daylight", .reserved = 0,},
898     { .id = V4L2_CID_DO_WHITE_BALANCE,  .index = 4,  .name = "cloudy-daylight", .reserved = 0,},
899     #endif
900
901         #if CONFIG_SENSOR_Effect
902     { .id = V4L2_CID_EFFECT,  .index = 0,  .name = "none",  .reserved = 0, }, {  .id = V4L2_CID_EFFECT,  .index = 1, .name = "negative",  .reserved = 0,},
903     { .id = V4L2_CID_EFFECT,  .index = 2,  .name = "sepia", .reserved = 0,}, {  .id = V4L2_CID_EFFECT, .index = 3,  .name = "solarize", .reserved = 0,},
904     #endif
905
906         #if CONFIG_SENSOR_Scene
907     { .id = V4L2_CID_SCENE,  .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE,  .index = 1,  .name = "night", .reserved = 0,},
908     #endif
909
910         #if CONFIG_SENSOR_Flash
911     { .id = V4L2_CID_FLASH,  .index = 0,  .name = "off",  .reserved = 0, }, {  .id = V4L2_CID_FLASH,  .index = 1, .name = "auto",  .reserved = 0,},
912     { .id = V4L2_CID_FLASH,  .index = 2,  .name = "on", .reserved = 0,}, {  .id = V4L2_CID_FLASH, .index = 3,  .name = "torch", .reserved = 0,},
913     #endif
914 };
915
916 static const struct v4l2_queryctrl sensor_controls[] =
917 {
918         #if CONFIG_SENSOR_WhiteBalance
919     {
920         .id             = V4L2_CID_DO_WHITE_BALANCE,
921         .type           = V4L2_CTRL_TYPE_MENU,
922         .name           = "White Balance Control",
923         .minimum        = 0,
924         .maximum        = 4,
925         .step           = 1,
926         .default_value = 0,
927     },
928     #endif
929
930         #if CONFIG_SENSOR_Brightness
931         {
932         .id             = V4L2_CID_BRIGHTNESS,
933         .type           = V4L2_CTRL_TYPE_INTEGER,
934         .name           = "Brightness Control",
935         .minimum        = -3,
936         .maximum        = 2,
937         .step           = 1,
938         .default_value = 0,
939     },
940     #endif
941
942         #if CONFIG_SENSOR_Effect
943         {
944         .id             = V4L2_CID_EFFECT,
945         .type           = V4L2_CTRL_TYPE_MENU,
946         .name           = "Effect Control",
947         .minimum        = 0,
948         .maximum        = 3,
949         .step           = 1,
950         .default_value = 0,
951     },
952         #endif
953
954         #if CONFIG_SENSOR_Exposure
955         {
956         .id             = V4L2_CID_EXPOSURE,
957         .type           = V4L2_CTRL_TYPE_INTEGER,
958         .name           = "Exposure Control",
959         .minimum        = 0,
960         .maximum        = 6,
961         .step           = 1,
962         .default_value = 0,
963     },
964         #endif
965
966         #if CONFIG_SENSOR_Saturation
967         {
968         .id             = V4L2_CID_SATURATION,
969         .type           = V4L2_CTRL_TYPE_INTEGER,
970         .name           = "Saturation Control",
971         .minimum        = 0,
972         .maximum        = 2,
973         .step           = 1,
974         .default_value = 0,
975     },
976     #endif
977
978         #if CONFIG_SENSOR_Contrast
979         {
980         .id             = V4L2_CID_CONTRAST,
981         .type           = V4L2_CTRL_TYPE_INTEGER,
982         .name           = "Contrast Control",
983         .minimum        = -3,
984         .maximum        = 3,
985         .step           = 1,
986         .default_value = 0,
987     },
988         #endif
989
990         #if CONFIG_SENSOR_Mirror
991         {
992         .id             = V4L2_CID_HFLIP,
993         .type           = V4L2_CTRL_TYPE_BOOLEAN,
994         .name           = "Mirror Control",
995         .minimum        = 0,
996         .maximum        = 1,
997         .step           = 1,
998         .default_value = 1,
999     },
1000     #endif
1001
1002         #if CONFIG_SENSOR_Flip
1003         {
1004         .id             = V4L2_CID_VFLIP,
1005         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1006         .name           = "Flip Control",
1007         .minimum        = 0,
1008         .maximum        = 1,
1009         .step           = 1,
1010         .default_value = 1,
1011     },
1012     #endif
1013
1014         #if CONFIG_SENSOR_Scene
1015     {
1016         .id             = V4L2_CID_SCENE,
1017         .type           = V4L2_CTRL_TYPE_MENU,
1018         .name           = "Scene Control",
1019         .minimum        = 0,
1020         .maximum        = 1,
1021         .step           = 1,
1022         .default_value = 0,
1023     },
1024     #endif
1025
1026         #if CONFIG_SENSOR_DigitalZoom
1027     {
1028         .id             = V4L2_CID_ZOOM_RELATIVE,
1029         .type           = V4L2_CTRL_TYPE_INTEGER,
1030         .name           = "DigitalZoom Control",
1031         .minimum        = -1,
1032         .maximum        = 1,
1033         .step           = 1,
1034         .default_value = 0,
1035     }, {
1036         .id             = V4L2_CID_ZOOM_ABSOLUTE,
1037         .type           = V4L2_CTRL_TYPE_INTEGER,
1038         .name           = "DigitalZoom Control",
1039         .minimum        = 0,
1040         .maximum        = 3,
1041         .step           = 1,
1042         .default_value = 0,
1043     },
1044     #endif
1045
1046         #if CONFIG_SENSOR_Focus
1047         {
1048         .id             = V4L2_CID_FOCUS_RELATIVE,
1049         .type           = V4L2_CTRL_TYPE_INTEGER,
1050         .name           = "Focus Control",
1051         .minimum        = -1,
1052         .maximum        = 1,
1053         .step           = 1,
1054         .default_value = 0,
1055     }, {
1056         .id             = V4L2_CID_FOCUS_ABSOLUTE,
1057         .type           = V4L2_CTRL_TYPE_INTEGER,
1058         .name           = "Focus Control",
1059         .minimum        = 0,
1060         .maximum        = 255,
1061         .step           = 1,
1062         .default_value = 125,
1063     },
1064         {
1065         .id             = V4L2_CID_FOCUS_AUTO,
1066         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1067         .name           = "Focus Control",
1068         .minimum        = 0,
1069         .maximum        = 1,
1070         .step           = 1,
1071         .default_value = 0,
1072     },{
1073         .id             = V4L2_CID_FOCUS_CONTINUOUS,
1074         .type           = V4L2_CTRL_TYPE_BOOLEAN,
1075         .name           = "Focus Control",
1076         .minimum        = 0,
1077         .maximum        = 1,
1078         .step           = 1,
1079         .default_value = 0,
1080     },
1081     #endif
1082
1083         #if CONFIG_SENSOR_Flash
1084         {
1085         .id             = V4L2_CID_FLASH,
1086         .type           = V4L2_CTRL_TYPE_MENU,
1087         .name           = "Flash Control",
1088         .minimum        = 0,
1089         .maximum        = 3,
1090         .step           = 1,
1091         .default_value = 0,
1092     },
1093         #endif
1094 };
1095
1096 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1097 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1098 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1099 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1100 static int sensor_g_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1101 static int sensor_s_ext_controls(struct v4l2_subdev *sd,  struct v4l2_ext_controls *ext_ctrl);
1102 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1103 static int sensor_resume(struct soc_camera_device *icd);
1104 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1105 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1106 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1107 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1108 static int sensor_deactivate(struct i2c_client *client);
1109
1110 static struct soc_camera_ops sensor_ops =
1111 {
1112     .suspend                     = sensor_suspend,
1113     .resume                       = sensor_resume,
1114     .set_bus_param              = sensor_set_bus_param,
1115     .query_bus_param    = sensor_query_bus_param,
1116     .controls           = sensor_controls,
1117     .menus                         = sensor_menus,
1118     .num_controls               = ARRAY_SIZE(sensor_controls),
1119     .num_menus          = ARRAY_SIZE(sensor_menus),
1120 };
1121
1122 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1123         { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1124         .colorspace = _colorspace }
1125
1126 #define JPG_FMT(_name, _depth, _fourcc) \
1127         COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1128
1129 static const struct soc_camera_data_format sensor_colour_formats[] = {
1130         JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1131         JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1132 };
1133 enum sensor_work_state
1134 {
1135         sensor_work_ready = 0,
1136         sensor_working,
1137 };
1138 struct sensor_work
1139 {
1140         struct i2c_client *client;
1141         struct delayed_work dwork;
1142         enum sensor_work_state state;
1143 };
1144
1145 typedef struct sensor_info_priv_s
1146 {
1147     int whiteBalance;
1148     int brightness;
1149     int contrast;
1150     int saturation;
1151     int effect;
1152     int scene;
1153     int digitalzoom;
1154     int focus;
1155         int auto_focus;
1156         int affm_reinit;
1157     int flash;
1158     int exposure;
1159     unsigned char mirror;                                        /* HFLIP */
1160     unsigned char flip;                                          /* VFLIP */
1161         bool snap2preview;
1162         bool video2preview;
1163         int capture_w;
1164         int capture_h;
1165         int preview_w;
1166         int preview_h;
1167     struct reginfo *winseqe_cur_addr;
1168         unsigned int pixfmt;
1169         unsigned int enable;
1170         unsigned int funmodule_state;
1171 } sensor_info_priv_t;
1172
1173
1174
1175 struct sensor_parameter
1176 {
1177         unsigned short int preview_maxlines;
1178         unsigned short int preview_exposure;
1179         unsigned short int preview_line_width;
1180         unsigned short int preview_gain;
1181
1182         unsigned short int capture_framerate;
1183         unsigned short int preview_framerate;
1184 };
1185
1186 struct sensor
1187 {
1188     struct v4l2_subdev subdev;
1189     struct i2c_client *client;
1190     sensor_info_priv_t info_priv;
1191         struct sensor_parameter parameter;
1192         struct workqueue_struct *sensor_wq;
1193         struct sensor_work sensor_wk;
1194         struct mutex wq_lock;
1195     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1196 #if CONFIG_SENSOR_I2C_NOSCHED
1197         atomic_t tasklock_cnt;
1198 #endif
1199         struct rk29camera_platform_data *sensor_io_request;
1200     struct rk29camera_gpio_res *sensor_gpio_res;
1201 };
1202
1203 static struct sensor* to_sensor(const struct i2c_client *client)
1204 {
1205     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1206 }
1207
1208 static int sensor_task_lock(struct i2c_client *client, int lock)
1209 {
1210 #if CONFIG_SENSOR_I2C_NOSCHED
1211         int cnt = 3;
1212     struct sensor *sensor = to_sensor(client);
1213
1214         if (lock) {
1215                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1216                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1217                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1218                                 msleep(35);
1219                                 cnt--;
1220                         }
1221                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1222                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1223                                 goto sensor_task_lock_err;
1224                         }
1225                         preempt_disable();
1226                 }
1227
1228                 atomic_add(1, &sensor->tasklock_cnt);
1229         } else {
1230                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1231                         atomic_sub(1, &sensor->tasklock_cnt);
1232
1233                         if (atomic_read(&sensor->tasklock_cnt) == 0)
1234                                 preempt_enable();
1235                 }
1236         }
1237     
1238         return 0;
1239 sensor_task_lock_err:
1240         return -1;    
1241 #else
1242     return 0;
1243 #endif
1244 }
1245
1246 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val);
1247
1248 /* sensor register write */
1249 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1250 {
1251     int err=0,cnt;
1252     u8 buf[4];
1253     struct i2c_msg msg[1];
1254
1255         switch (reg_info->reg)
1256         {
1257                 case SEQUENCE_WAIT_MS:
1258                 {
1259                         if (in_atomic())
1260                                 mdelay(reg_info->val);
1261                         else
1262                                 msleep(reg_info->val);
1263                         break;
1264                 }
1265
1266                 case SEQUENCE_WAIT_US:
1267                 {
1268                         udelay(reg_info->val);
1269                         break;
1270                 }
1271
1272                 case SEQUENCE_PROPERTY:
1273                 {
1274                         break;
1275                 }
1276                 default:
1277                 {
1278                     buf[0] = reg_info->reg >> 8;
1279                     buf[1] = reg_info->reg & 0xFF;
1280                         if (reg_info->reg_len == WORD_LEN) {
1281                                 buf[2] = reg_info->val >> 8;
1282                                 buf[3] = reg_info->val & 0xFF;
1283
1284                                 msg->len = 4;
1285                         } else if (reg_info->reg_len == BYTE_LEN) {
1286                                 buf[2] = reg_info->val;
1287                                 msg->len = 3;
1288                         }
1289
1290                     msg->addr = client->addr;
1291                     msg->flags = client->flags;
1292                     msg->buf = buf;
1293                     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1294                     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1295
1296                     cnt = 3;
1297                     err = -EAGAIN;
1298
1299                     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1300                         err = i2c_transfer(client->adapter, msg, 1);
1301
1302                         if (err >= 0) {
1303                             return 0;
1304                         } else {
1305                             SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg_info->reg, reg_info->val);
1306                             udelay(10);
1307                         }
1308                     }
1309                 }
1310         }
1311     return err;
1312 }
1313
1314 /* sensor register read */
1315 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1316 {
1317     int err,cnt;
1318     u8 buf[2];
1319     struct i2c_msg msg[2];
1320
1321     buf[0] = reg >> 8;
1322     buf[1] = reg & 0xFF;
1323
1324     msg[0].addr = client->addr;
1325     msg[0].flags = client->flags;
1326     msg[0].buf = buf;
1327     msg[0].len = sizeof(buf);
1328     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
1329     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1330
1331     msg[1].addr = client->addr;
1332     msg[1].flags = client->flags|I2C_M_RD;
1333     msg[1].buf = buf;
1334     msg[1].len = 2;
1335     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
1336     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1337
1338     cnt = 3;
1339     err = -EAGAIN;
1340     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1341         err = i2c_transfer(client->adapter, msg, 2);
1342
1343         if (err >= 0) {
1344             *val = buf[0]<<8 | buf[1];
1345             return 0;
1346         } else {
1347                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1348             udelay(10);
1349         }
1350     }
1351
1352     return err;
1353 }
1354
1355 /* write a array of registers  */
1356 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1357 {
1358     int err = 0, cnt;
1359     int i = 0;
1360 #if CONFIG_SENSOR_I2C_RDWRCHK
1361         u16 valchk;
1362 #endif
1363
1364         cnt = 0;
1365         if (sensor_task_lock(client, 1) < 0)
1366                 goto sensor_write_array_end;
1367     while (regarray[i].reg != SEQUENCE_END) {
1368         err = sensor_write(client, &regarray[i]);
1369         if (err < 0)
1370         {
1371             if (cnt-- > 0) {
1372                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1373                                 i = 0;
1374                                 continue;
1375             } else {
1376                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1377                 err = -EPERM;
1378                                 goto sensor_write_array_end;
1379             }
1380         } else {
1381         #if CONFIG_SENSOR_I2C_RDWRCHK
1382                         sensor_read(client, regarray[i].reg, &valchk);
1383                         if (valchk != regarray[i].val)
1384                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1385                 #endif
1386         }
1387
1388         i++;
1389     }
1390
1391 sensor_write_array_end:
1392         sensor_task_lock(client,0);
1393     return err;
1394 }
1395 #if CONFIG_SENSOR_I2C_RDWRCHK
1396 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1397 {
1398     int cnt;
1399     int i = 0;
1400         u16 valchk;
1401
1402         cnt = 0;
1403         valchk = 0;
1404     while (regarray[i].reg != SEQUENCE_END)
1405     {
1406                 sensor_read(client, regarray[i].reg, &valchk);
1407                 if (valchk != regarray[i].val)
1408                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1409
1410         i++;
1411     }
1412     return 0;
1413 }
1414 #endif
1415 #if CONFIG_SENSOR_Focus
1416 static struct reginfo sensor_af_init0[] =
1417 {
1418
1419         {SEQUENCE_END, 0x00}
1420 };
1421 static struct reginfo sensor_af_init1[] =
1422 {
1423     {SEQUENCE_END, 0x00}
1424 };
1425
1426
1427 static struct reginfo sensor_af_trigger[] =
1428 {
1429         {SEQUENCE_END, 0x00}
1430 };
1431 static int sensor_af_single(struct i2c_client *client)
1432 {
1433         int ret = 0;
1434
1435         ret = sensor_write_array(client, sensor_af_trigger);
1436         if (ret<0)
1437                 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1438         else
1439                 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1440 sensor_af_single_end:
1441         return ret;
1442 }
1443
1444 static int sensor_af_const(struct i2c_client *client)
1445 {
1446         int ret = 0;
1447
1448 sensor_af_const_end:
1449         return ret;
1450 }
1451
1452 static int sensor_af_zoneupdate(struct i2c_client *client)
1453 {
1454         int ret = 0;
1455         struct i2c_msg msg[2];
1456     u8 buf[2][6] =
1457         {
1458                 {0xb0,0x08,0x00,0x03,0xff,0xff},
1459                 {0xb0,0x0c,0xff,0xff,0xff,0xff},
1460         };
1461
1462     msg[0].addr = client->addr;
1463     msg[0].flags = client->flags;
1464     msg[0].buf = buf[0];
1465     msg[0].len = sizeof(buf);
1466     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1467     msg[0].read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1468
1469     msg[1].addr = client->addr;
1470     msg[1].flags = client->flags;
1471     msg[1].buf = buf[1];
1472     msg[1].len = sizeof(buf);
1473     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1474     msg[1].read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1475
1476     ret = i2c_transfer(client->adapter, &msg[0], 1);
1477         ret |= i2c_transfer(client->adapter, &msg[1], 1);
1478     if (ret >= 0) {
1479         return 0;
1480     } else {
1481         SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
1482     }
1483
1484 sensor_af_zoneupdate_end:
1485         return ret;
1486 }
1487
1488 static int sensor_af_init(struct i2c_client *client)
1489 {
1490         int ret = 0;
1491
1492         ret = sensor_write_array(client, sensor_af_init0);
1493         if (ret<0) {
1494                 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1495         } else {
1496                 if (sensor_af_zoneupdate(client) == 0) {
1497                         ret = sensor_write_array(client, sensor_af_init1);
1498                         if (ret<0) {
1499                                 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1500                         }
1501                 }
1502         }
1503
1504         return ret;
1505 }
1506 #endif
1507
1508 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1509 {
1510         struct soc_camera_link *icl = to_soc_camera_link(icd);
1511         int ret = 0;
1512
1513     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1514         switch (cmd)
1515         {
1516                 case Sensor_PowerDown:
1517                 {
1518                         if (icl->powerdown) {
1519                                 ret = icl->powerdown(icd->pdev, on);
1520                                 if (ret == RK29_CAM_IO_SUCCESS) {
1521                                         if (on == 0) {
1522                                                 mdelay(2);
1523                                                 if (icl->reset)
1524                                                         icl->reset(icd->pdev);
1525                                         }
1526                                 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1527                                         ret = -ENODEV;
1528                                         goto sensor_power_end;
1529                                 }
1530                         }
1531                         break;
1532                 }
1533                 case Sensor_Flash:
1534                 {
1535                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1536                 struct sensor *sensor = to_sensor(client);
1537
1538                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1539                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1540                         }
1541                         break;
1542                 }
1543                 default:
1544                 {
1545                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1546                         break;
1547                 }
1548         }
1549
1550 sensor_power_end:
1551         return ret;
1552 }
1553 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1554 {
1555     struct i2c_client *client = sd->priv;
1556     struct soc_camera_device *icd = client->dev.platform_data;
1557     struct sensor *sensor = to_sensor(client);
1558         const struct v4l2_queryctrl *qctrl;
1559     int ret;
1560     u16 pid = 0;
1561
1562     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1563
1564         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1565                 ret = -ENODEV;
1566                 goto sensor_INIT_ERR;
1567         }
1568     mdelay(100);
1569     /* soft reset */
1570         if (sensor_task_lock(client,1)<0)
1571                 goto sensor_INIT_ERR;
1572
1573 #if (SENSOR_RESET_REG != SEQUENCE_END)
1574     struct reginfo reg_info;
1575         reg_info.reg = SENSOR_RESET_REG;
1576         reg_info.val = SENSOR_RESET_VAL;
1577         reg_info.reg_len = SENSOR_RESET_REG_LEN;
1578     ret = sensor_write(client, &reg_info);
1579     if (ret != 0) {
1580         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1581         ret = -ENODEV;
1582                 goto sensor_INIT_ERR;
1583     }
1584     mdelay(5);  //delay 5 microseconds
1585     reg_info.val = SENSOR_DERESET_VAL;
1586     ret = sensor_write(client, &reg_info);
1587     if (ret != 0) {
1588         SENSOR_TR("%s soft dereset sensor failed\n",SENSOR_NAME_STRING());
1589         ret = -ENODEV;
1590                 goto sensor_INIT_ERR;
1591     }
1592 #endif
1593
1594         /* check if it is an sensor sensor */
1595 #if (SENSOR_ID_REG != SEQUENCE_END)
1596     ret = sensor_read(client, SENSOR_ID_REG, &pid);
1597     if (ret != 0) {
1598         SENSOR_TR("read chip id failed\n");
1599         ret = -ENODEV;
1600         goto sensor_INIT_ERR;
1601     }
1602
1603     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1604 #else
1605         pid = SENSOR_ID;
1606 #endif
1607     if (pid == SENSOR_ID) {
1608         sensor->model = SENSOR_V4L2_IDENT;
1609     } else {
1610         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1611         ret = -ENODEV;
1612         goto sensor_INIT_ERR;
1613     }
1614
1615     ret = sensor_write_array(client, sensor_init_data);
1616     if (ret != 0)
1617     {
1618         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1619         goto sensor_INIT_ERR;
1620     }
1621         sensor_task_lock(client,0);
1622     sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1623     sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1624     sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1625     sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1626     sensor->info_priv.winseqe_cur_addr  = SENSOR_INIT_WINSEQADR;
1627         sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1628
1629     /* sensor sensor information for initialization  */
1630         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1631         if (qctrl)
1632         sensor->info_priv.whiteBalance = qctrl->default_value;
1633         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1634         if (qctrl)
1635         sensor->info_priv.brightness = qctrl->default_value;
1636         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1637         if (qctrl)
1638         sensor->info_priv.effect = qctrl->default_value;
1639         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1640         if (qctrl)
1641         sensor->info_priv.exposure = qctrl->default_value;
1642
1643         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1644         if (qctrl)
1645         sensor->info_priv.saturation = qctrl->default_value;
1646         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1647         if (qctrl)
1648         sensor->info_priv.contrast = qctrl->default_value;
1649         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1650         if (qctrl)
1651         sensor->info_priv.mirror = qctrl->default_value;
1652         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1653         if (qctrl)
1654         sensor->info_priv.flip = qctrl->default_value;
1655         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1656         if (qctrl)
1657         sensor->info_priv.scene = qctrl->default_value;
1658         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1659         if (qctrl)
1660         sensor->info_priv.digitalzoom = qctrl->default_value;
1661
1662     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
1663         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1664         if (qctrl)
1665         sensor->info_priv.focus = qctrl->default_value;
1666         #if CONFIG_SENSOR_Focus
1667         if (sensor_af_init(client) < 0) {
1668                 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1669                 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1670         } else {
1671                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1672                 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1673         }
1674         #endif
1675         #if CONFIG_SENSOR_Flash
1676         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1677         if (qctrl)
1678         sensor->info_priv.flash = qctrl->default_value;
1679     #endif
1680     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);
1681
1682     return 0;
1683 sensor_INIT_ERR:
1684         sensor_task_lock(client,0);
1685         sensor_deactivate(client);
1686     return ret;
1687 }
1688 static int sensor_deactivate(struct i2c_client *client)
1689 {
1690         struct soc_camera_device *icd = client->dev.platform_data;
1691
1692         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1693
1694         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1695         sensor_ioctrl(icd, Sensor_PowerDown, 1);
1696
1697         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1698         icd->user_width = SENSOR_INIT_WIDTH;
1699     icd->user_height = SENSOR_INIT_HEIGHT;
1700         msleep(100);
1701         return 0;
1702 }
1703 static  struct reginfo sensor_power_down_sequence[]=
1704 {
1705     {0x00,0x00}
1706 };
1707 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1708 {
1709     int ret;
1710     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1711
1712     if (pm_msg.event == PM_EVENT_SUSPEND) {
1713         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1714         ret = sensor_write_array(client, sensor_power_down_sequence) ;
1715         if (ret != 0) {
1716             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1717             return ret;
1718         } else {
1719             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1720             if (ret < 0) {
1721                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1722                 return -EINVAL;
1723             }
1724         }
1725     } else {
1726         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1727         return -EINVAL;
1728     }
1729
1730     return 0;
1731 }
1732
1733 static int sensor_resume(struct soc_camera_device *icd)
1734 {
1735         int ret;
1736
1737     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1738     if (ret < 0) {
1739                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1740         return -EINVAL;
1741     }
1742
1743         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1744         return 0;
1745 }
1746
1747 static int sensor_set_bus_param(struct soc_camera_device *icd,
1748                                 unsigned long flags)
1749 {
1750
1751     return 0;
1752 }
1753
1754 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1755 {
1756     struct soc_camera_link *icl = to_soc_camera_link(icd);
1757     unsigned long flags = SENSOR_BUS_PARAM;
1758
1759     return soc_camera_apply_sensor_flags(icl, flags);
1760 }
1761
1762 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1763 {
1764     struct i2c_client *client = sd->priv;
1765     struct soc_camera_device *icd = client->dev.platform_data;
1766     struct sensor *sensor = to_sensor(client);
1767     struct v4l2_pix_format *pix = &f->fmt.pix;
1768
1769     pix->width          = icd->user_width;
1770     pix->height         = icd->user_height;
1771     pix->pixelformat    = sensor->info_priv.pixfmt;
1772     pix->field          = V4L2_FIELD_NONE;
1773     pix->colorspace             = V4L2_COLORSPACE_JPEG;
1774
1775     return 0;
1776 }
1777 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
1778 {
1779     bool ret = false;
1780
1781         if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
1782                 ret = true;
1783         } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
1784                 ret = true;
1785         } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
1786                 ret = true;
1787         } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
1788                 ret = true;
1789         } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
1790                 ret = true;
1791         }
1792
1793         if (ret == true)
1794                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1795         return ret;
1796 }
1797
1798 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
1799 {
1800     bool ret = false;
1801
1802         if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
1803                 ret = true;  //true zyw
1804         } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
1805                 ret = true;  //true zyw
1806         }
1807
1808         if (ret == true)
1809                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1810         return ret;
1811 }
1812
1813 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1814 {
1815         struct reginfo *winseqe_set_addr = NULL;
1816
1817         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1818                 winseqe_set_addr = sensor_qcif;
1819         *ret_w = 176;
1820         *ret_h = 144;
1821         } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1822         winseqe_set_addr = sensor_qvga;
1823         *ret_w = 320;
1824         *ret_h = 240;
1825         } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1826         winseqe_set_addr = sensor_cif;
1827         *ret_w = 352;
1828         *ret_h = 288;
1829     } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1830         winseqe_set_addr = sensor_vga;
1831         *ret_w = 640;
1832         *ret_h = 480;
1833     } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1834         printk("enter 800x600\n");
1835         winseqe_set_addr = sensor_svga;
1836         *ret_w = 800;
1837         *ret_h = 600;
1838     } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1839         winseqe_set_addr = sensor_xga;
1840         *ret_w = 1024;
1841         *ret_h = 768;
1842         } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1843         printk("enter 1280X720\n");
1844         winseqe_set_addr = sensor_720p;
1845         *ret_w = 1280;
1846         *ret_h = 720;
1847     } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1848         printk("enter 1280X1024\n");
1849         winseqe_set_addr = sensor_sxga;
1850         *ret_w = 1280;
1851         *ret_h = 1024;
1852     } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1853         winseqe_set_addr = sensor_uxga;
1854         *ret_w = 1600;
1855         *ret_h = 1200;
1856         } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1857       winseqe_set_addr = sensor_1080p;
1858         *ret_w = 1920;
1859         *ret_h = 1080;
1860     } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1861         winseqe_set_addr = sensor_qxga;
1862         *ret_w = 2048;
1863         *ret_h = 1536;
1864     } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1865         winseqe_set_addr = sensor_qsxga;
1866         *ret_w = 2592;
1867         *ret_h = 1944;
1868     }
1869
1870         return winseqe_set_addr;
1871 }
1872
1873 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1874 {
1875     struct i2c_client *client = sd->priv;
1876     struct sensor *sensor = to_sensor(client);
1877     struct v4l2_pix_format *pix = &f->fmt.pix;
1878     struct reginfo *winseqe_set_addr=NULL;
1879     int ret = 0, set_w,set_h;
1880
1881     SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,pix->width,pix->height);
1882
1883         if (sensor->info_priv.pixfmt != pix->pixelformat) {
1884                 switch (pix->pixelformat)
1885                 {
1886                         case V4L2_PIX_FMT_YUYV:
1887                         {
1888                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
1889                                 break;
1890                         }
1891                         case V4L2_PIX_FMT_UYVY:
1892                         {
1893                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
1894                                 break;
1895                         }
1896                         default:
1897                                 break;
1898                 }
1899                 if (winseqe_set_addr != NULL) {
1900             sensor_write_array(client, winseqe_set_addr);
1901                         sensor->info_priv.pixfmt = pix->pixelformat;
1902
1903                         SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1904                 } else {
1905                         SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1906                 }
1907         }
1908
1909     set_w = pix->width;
1910     set_h = pix->height;
1911
1912         winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1913
1914     if ((winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1915         ret |= sensor_write_array(client, winseqe_set_addr);
1916         if (ret != 0) {
1917             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1918             goto sensor_s_fmt_end;
1919         }
1920         sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
1921                 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1922                 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1923                 } else {
1924                         SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1925                         sensor->info_priv.preview_w = pix->width;
1926                         sensor->info_priv.preview_h = pix->height;
1927                 }
1928     }
1929
1930         if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1931                 ret |= sensor_write_array(client, sensor_Preview2Capture);
1932                 if (ret != 0) {
1933                 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
1934                 goto sensor_s_fmt_end;
1935         }
1936                 sensor->info_priv.capture_w = set_w;
1937                 sensor->info_priv.capture_h = set_h;
1938                 sensor->info_priv.snap2preview = true;
1939         } else if (sensor->info_priv.snap2preview == true) {
1940                 if (winseqe_set_addr || ((sensor->info_priv.preview_w == pix->width) && (sensor->info_priv.preview_h == pix->height))) {
1941                         ret |= sensor_write_array(client, sensor_Capture2Preview);
1942                         if (ret != 0) {
1943                         SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
1944                         goto sensor_s_fmt_end;
1945                 }
1946                         sensor->info_priv.preview_w = pix->width;
1947                         sensor->info_priv.preview_h = pix->height;
1948                         sensor->info_priv.snap2preview = false;
1949                 } else {
1950                         SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1951                 }
1952         }
1953
1954         pix->width = set_w;
1955         pix->height = set_h;
1956 sensor_s_fmt_end:
1957     return ret;
1958 }
1959
1960 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1961 {
1962         int ret = 0;
1963     struct v4l2_pix_format *pix = &f->fmt.pix;
1964     bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1965         pix->pixelformat == V4L2_PIX_FMT_YUYV;
1966
1967     SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,pix->width,pix->height);
1968
1969     /*
1970     * With Bayer format enforce even side lengths, but let the user play
1971     * with the starting pixel
1972     */
1973
1974     if (pix->height > SENSOR_MAX_HEIGHT)
1975         pix->height = SENSOR_MAX_HEIGHT;
1976     else if (pix->height < SENSOR_MIN_HEIGHT)
1977         pix->height = SENSOR_MIN_HEIGHT;
1978     else if (bayer)
1979         pix->height = ALIGN(pix->height, 2);
1980
1981     if (pix->width > SENSOR_MAX_WIDTH)
1982         pix->width = SENSOR_MAX_WIDTH;
1983     else if (pix->width < SENSOR_MIN_WIDTH)
1984         pix->width = SENSOR_MIN_WIDTH;
1985     else if (bayer)
1986         pix->width = ALIGN(pix->width, 2);
1987
1988         if (sensor_fmt_catch(pix->width, pix->height, &pix->width, &pix->height) == NULL) {
1989         printk("%s[%d] ERR!!!!!!",__FUNCTION__,__LINE__);
1990                 pix->width = 0;
1991                 pix->height = 0;
1992         }
1993
1994     return ret;
1995 }
1996
1997  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1998 {
1999     struct i2c_client *client = sd->priv;
2000
2001     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2002         return -EINVAL;
2003
2004     if (id->match.addr != client->addr)
2005         return -ENODEV;
2006
2007     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
2008     id->revision = 0;
2009
2010     return 0;
2011 }
2012 #if CONFIG_SENSOR_Brightness
2013 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2014 {
2015     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2016
2017     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2018     {
2019         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2020         {
2021             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2022             {
2023                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2024                 return -EINVAL;
2025             }
2026             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2027             return 0;
2028         }
2029     }
2030         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2031     return -EINVAL;
2032 }
2033 #endif
2034 #if CONFIG_SENSOR_Effect
2035 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2036 {
2037     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2038
2039     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2040     {
2041         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2042         {
2043             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2044             {
2045                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2046                 return -EINVAL;
2047             }
2048             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2049             return 0;
2050         }
2051     }
2052         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2053     return -EINVAL;
2054 }
2055 #endif
2056 #if CONFIG_SENSOR_Exposure
2057 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2058 {
2059     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2060
2061     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2062     {
2063         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2064         {
2065             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2066             {
2067                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2068                 return -EINVAL;
2069             }
2070             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2071             return 0;
2072         }
2073     }
2074         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2075     return -EINVAL;
2076 }
2077 #endif
2078 #if CONFIG_SENSOR_Saturation
2079 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2080 {
2081     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2082
2083     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2084     {
2085         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2086         {
2087             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2088             {
2089                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2090                 return -EINVAL;
2091             }
2092             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2093             return 0;
2094         }
2095     }
2096     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2097     return -EINVAL;
2098 }
2099 #endif
2100 #if CONFIG_SENSOR_Contrast
2101 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2102 {
2103     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2104
2105     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2106     {
2107         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2108         {
2109             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2110             {
2111                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2112                 return -EINVAL;
2113             }
2114             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2115             return 0;
2116         }
2117     }
2118     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2119     return -EINVAL;
2120 }
2121 #endif
2122 #if CONFIG_SENSOR_Mirror
2123 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2124 {
2125     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2126
2127     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2128     {
2129         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2130         {
2131             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2132             {
2133                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2134                 return -EINVAL;
2135             }
2136             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2137             return 0;
2138         }
2139     }
2140     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2141     return -EINVAL;
2142 }
2143 #endif
2144 #if CONFIG_SENSOR_Flip
2145 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2146 {
2147     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2148
2149     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2150     {
2151         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2152         {
2153             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2154             {
2155                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2156                 return -EINVAL;
2157             }
2158             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2159             return 0;
2160         }
2161     }
2162     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2163     return -EINVAL;
2164 }
2165 #endif
2166 #if CONFIG_SENSOR_Scene
2167 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2168 {
2169     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2170
2171     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2172     {
2173         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2174         {
2175             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2176             {
2177                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2178                 return -EINVAL;
2179             }
2180             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2181             return 0;
2182         }
2183     }
2184     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2185     return -EINVAL;
2186 }
2187 #endif
2188 #if CONFIG_SENSOR_WhiteBalance
2189 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2190 {
2191     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2192
2193     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2194     {
2195         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2196         {
2197             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2198             {
2199                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2200                 return -EINVAL;
2201             }
2202             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2203             return 0;
2204         }
2205     }
2206         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2207     return -EINVAL;
2208 }
2209 #endif
2210 #if CONFIG_SENSOR_DigitalZoom
2211 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2212 {
2213     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2214     struct sensor *sensor = to_sensor(client);
2215         const struct v4l2_queryctrl *qctrl_info;
2216     int digitalzoom_cur, digitalzoom_total;
2217
2218         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2219         if (qctrl_info)
2220                 return -EINVAL;
2221
2222     digitalzoom_cur = sensor->info_priv.digitalzoom;
2223     digitalzoom_total = qctrl_info->maximum;
2224
2225     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2226     {
2227         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2228         return -EINVAL;
2229     }
2230
2231     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2232     {
2233         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2234         return -EINVAL;
2235     }
2236
2237     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2238     {
2239         *value = digitalzoom_total - digitalzoom_cur;
2240     }
2241
2242     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2243     {
2244         *value = 0 - digitalzoom_cur;
2245     }
2246
2247     digitalzoom_cur += *value;
2248
2249     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2250     {
2251         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2252         {
2253             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2254             return -EINVAL;
2255         }
2256         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2257         return 0;
2258     }
2259
2260     return -EINVAL;
2261 }
2262 #endif
2263 #if CONFIG_SENSOR_Flash
2264 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2265 {
2266     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2267     struct sensor *sensor = to_sensor(client);
2268         const struct v4l2_queryctrl *qctrl_info;
2269     
2270     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2271         if (value == 3) {       /* ddl@rock-chips.com: torch */
2272             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
2273         } else {
2274             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2275         }
2276         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2277         return 0;
2278     }
2279     
2280         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2281     return -EINVAL;
2282 }
2283 #endif
2284 #if CONFIG_SENSOR_Focus
2285 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2286 {
2287         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2288     struct sensor *sensor = to_sensor(client);
2289         const struct v4l2_queryctrl *qctrl_info;
2290         int ret = 0;
2291
2292         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2293         if (!qctrl_info)
2294                 return -EINVAL;
2295
2296         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2297                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2298
2299                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2300                 } else {
2301                         ret = -EINVAL;
2302                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2303                 }
2304         } else {
2305                 ret = -EACCES;
2306                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2307                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2308         }
2309
2310 sensor_set_focus_absolute_end:
2311         return ret;
2312 }
2313 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2314 {
2315         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2316         struct sensor *sensor = to_sensor(client);
2317         const struct v4l2_queryctrl *qctrl_info;
2318         int ret = 0;
2319
2320         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2321         if (!qctrl_info)
2322                 return -EINVAL;
2323
2324         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2325                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2326
2327                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2328                 } else {
2329                         ret = -EINVAL;
2330                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2331                 }
2332         } else {
2333                 ret = -EACCES;
2334                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2335                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2336         }
2337 sensor_set_focus_relative_end:
2338         return ret;
2339 }
2340
2341 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2342 {
2343         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2344         struct sensor *sensor = to_sensor(client);
2345         int ret = 0;
2346
2347         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)  && (sensor->info_priv.affm_reinit == 0)) {
2348                 switch (value)
2349                 {
2350                         case SENSOR_AF_MODE_AUTO:
2351                         {
2352                                 ret = sensor_af_single(client);
2353                                 break;
2354                         }
2355
2356                         case SENSOR_AF_MODE_MACRO:
2357                         {
2358                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2359                                 break;
2360                         }
2361
2362                         case SENSOR_AF_MODE_INFINITY:
2363                         {
2364                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2365                                 break;
2366                         }
2367
2368                         case SENSOR_AF_MODE_CONTINUOUS:
2369                         {
2370                                 ret = sensor_af_const(client);
2371                                 break;
2372                         }
2373                         default:
2374                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2375                                 break;
2376
2377                 }
2378
2379                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2380         } else {
2381                 ret = -EACCES;
2382                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2383                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2384         }
2385
2386         return ret;
2387 }
2388 #endif
2389 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2390 {
2391     struct i2c_client *client = sd->priv;
2392     struct sensor *sensor = to_sensor(client);
2393     const struct v4l2_queryctrl *qctrl;
2394
2395     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2396
2397     if (!qctrl)
2398     {
2399         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2400         return -EINVAL;
2401     }
2402
2403     switch (ctrl->id)
2404     {
2405         case V4L2_CID_BRIGHTNESS:
2406             {
2407                 ctrl->value = sensor->info_priv.brightness;
2408                 break;
2409             }
2410         case V4L2_CID_SATURATION:
2411             {
2412                 ctrl->value = sensor->info_priv.saturation;
2413                 break;
2414             }
2415         case V4L2_CID_CONTRAST:
2416             {
2417                 ctrl->value = sensor->info_priv.contrast;
2418                 break;
2419             }
2420         case V4L2_CID_DO_WHITE_BALANCE:
2421             {
2422                 ctrl->value = sensor->info_priv.whiteBalance;
2423                 break;
2424             }
2425         case V4L2_CID_EXPOSURE:
2426             {
2427                 ctrl->value = sensor->info_priv.exposure;
2428                 break;
2429             }
2430         case V4L2_CID_HFLIP:
2431             {
2432                 ctrl->value = sensor->info_priv.mirror;
2433                 break;
2434             }
2435         case V4L2_CID_VFLIP:
2436             {
2437                 ctrl->value = sensor->info_priv.flip;
2438                 break;
2439             }
2440         default :
2441                 break;
2442     }
2443     return 0;
2444 }
2445
2446
2447
2448 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2449 {
2450     struct i2c_client *client = sd->priv;
2451     const struct v4l2_queryctrl *qctrl;   
2452     struct sensor *sensor = to_sensor(client);
2453     struct soc_camera_device *icd = client->dev.platform_data;
2454     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2455
2456     if (!qctrl)
2457     {
2458         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2459         return -EINVAL;
2460     }
2461
2462     switch (ctrl->id)
2463     {
2464 #if CONFIG_SENSOR_Brightness
2465         case V4L2_CID_BRIGHTNESS:
2466             {
2467                 if (ctrl->value != sensor->info_priv.brightness)
2468                 {
2469                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2470                     {
2471                         return -EINVAL;
2472                     }
2473                     sensor->info_priv.brightness = ctrl->value;
2474                 }
2475                 break;
2476             }
2477 #endif
2478 #if CONFIG_SENSOR_Exposure
2479         case V4L2_CID_EXPOSURE:
2480             {
2481                 if (ctrl->value != sensor->info_priv.exposure)
2482                 {
2483                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2484                     {
2485                         return -EINVAL;
2486                     }
2487                     sensor->info_priv.exposure = ctrl->value;
2488                 }
2489                 break;
2490             }
2491 #endif
2492 #if CONFIG_SENSOR_Saturation
2493         case V4L2_CID_SATURATION:
2494             {
2495                 if (ctrl->value != sensor->info_priv.saturation)
2496                 {
2497                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2498                     {
2499                         return -EINVAL;
2500                     }
2501                     sensor->info_priv.saturation = ctrl->value;
2502                 }
2503                 break;
2504             }
2505 #endif
2506 #if CONFIG_SENSOR_Contrast
2507         case V4L2_CID_CONTRAST:
2508             {
2509                 if (ctrl->value != sensor->info_priv.contrast)
2510                 {
2511                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2512                     {
2513                         return -EINVAL;
2514                     }
2515                     sensor->info_priv.contrast = ctrl->value;
2516                 }
2517                 break;
2518             }
2519 #endif
2520 #if CONFIG_SENSOR_WhiteBalance
2521         case V4L2_CID_DO_WHITE_BALANCE:
2522             {
2523                 if (ctrl->value != sensor->info_priv.whiteBalance)
2524                 {
2525                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2526                     {
2527                         return -EINVAL;
2528                     }
2529                     sensor->info_priv.whiteBalance = ctrl->value;
2530                 }
2531                 break;
2532             }
2533 #endif
2534 #if CONFIG_SENSOR_Mirror
2535         case V4L2_CID_HFLIP:
2536             {
2537                 if (ctrl->value != sensor->info_priv.mirror)
2538                 {
2539                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2540                         return -EINVAL;
2541                     sensor->info_priv.mirror = ctrl->value;
2542                 }
2543                 break;
2544             }
2545 #endif
2546 #if CONFIG_SENSOR_Flip
2547         case V4L2_CID_VFLIP:
2548             {
2549                 if (ctrl->value != sensor->info_priv.flip)
2550                 {
2551                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2552                         return -EINVAL;
2553                     sensor->info_priv.flip = ctrl->value;
2554                 }
2555                 break;
2556             }
2557 #endif
2558         default:
2559             break;
2560     }
2561
2562     return 0;
2563 }
2564 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2565 {
2566     const struct v4l2_queryctrl *qctrl;
2567     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2568     struct sensor *sensor = to_sensor(client);
2569
2570     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2571
2572     if (!qctrl)
2573     {
2574         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2575         return -EINVAL;
2576     }
2577
2578     switch (ext_ctrl->id)
2579     {
2580         case V4L2_CID_SCENE:
2581             {
2582                 ext_ctrl->value = sensor->info_priv.scene;
2583                 break;
2584             }
2585         case V4L2_CID_EFFECT:
2586             {
2587                 ext_ctrl->value = sensor->info_priv.effect;
2588                 break;
2589             }
2590         case V4L2_CID_ZOOM_ABSOLUTE:
2591             {
2592                 ext_ctrl->value = sensor->info_priv.digitalzoom;
2593                 break;
2594             }
2595         case V4L2_CID_ZOOM_RELATIVE:
2596             {
2597                 return -EINVAL;
2598             }
2599         case V4L2_CID_FOCUS_ABSOLUTE:
2600             {
2601                 return -EINVAL;
2602             }
2603         case V4L2_CID_FOCUS_RELATIVE:
2604             {
2605                 return -EINVAL;
2606             }
2607         case V4L2_CID_FLASH:
2608             {
2609                 ext_ctrl->value = sensor->info_priv.flash;
2610                 break;
2611             }
2612         default :
2613             break;
2614     }
2615     return 0;
2616 }
2617 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2618 {
2619     const struct v4l2_queryctrl *qctrl;
2620     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2621     struct sensor *sensor = to_sensor(client);
2622     int val_offset;      
2623
2624     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2625
2626     if (!qctrl)
2627     {
2628         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2629         return -EINVAL;
2630     }
2631
2632         val_offset = 0;
2633     switch (ext_ctrl->id)
2634     {
2635 #if CONFIG_SENSOR_Scene
2636         case V4L2_CID_SCENE:
2637             {
2638                 if (ext_ctrl->value != sensor->info_priv.scene)
2639                 {
2640                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2641                         return -EINVAL;
2642                     sensor->info_priv.scene = ext_ctrl->value;
2643                 }
2644                 break;
2645             }
2646 #endif
2647 #if CONFIG_SENSOR_Effect
2648         case V4L2_CID_EFFECT:
2649             {
2650                 if (ext_ctrl->value != sensor->info_priv.effect)
2651                 {
2652                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2653                         return -EINVAL;
2654                     sensor->info_priv.effect= ext_ctrl->value;
2655                 }
2656                 break;
2657             }
2658 #endif
2659 #if CONFIG_SENSOR_DigitalZoom
2660         case V4L2_CID_ZOOM_ABSOLUTE:
2661             {
2662                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2663                     return -EINVAL;
2664
2665                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2666                 {
2667                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2668
2669                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2670                         return -EINVAL;
2671                     sensor->info_priv.digitalzoom += val_offset;
2672
2673                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
2674                 }
2675
2676                 break;
2677             }
2678         case V4L2_CID_ZOOM_RELATIVE:
2679             {
2680                 if (ext_ctrl->value)
2681                 {
2682                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2683                         return -EINVAL;
2684                     sensor->info_priv.digitalzoom += ext_ctrl->value;
2685
2686                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2687                 }
2688                 break;
2689             }
2690 #endif
2691 #if CONFIG_SENSOR_Focus
2692         case V4L2_CID_FOCUS_ABSOLUTE:
2693             {
2694                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2695                     return -EINVAL;
2696
2697                                 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2698                                         if (ext_ctrl->value == qctrl->minimum) {
2699                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2700                                         } else if (ext_ctrl->value == qctrl->maximum) {
2701                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2702                                         } else {
2703                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2704                                         }
2705                                 }
2706
2707                 break;
2708             }
2709         case V4L2_CID_FOCUS_RELATIVE:
2710             {
2711                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2712                     return -EINVAL;
2713
2714                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2715                 break;
2716             }
2717                 case V4L2_CID_FOCUS_AUTO:
2718                         {
2719                                 if (ext_ctrl->value == 1) {
2720                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2721                                                 return -EINVAL;
2722                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2723                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2724                                         if (ext_ctrl->value == 0)
2725                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2726                                 }
2727                                 break;
2728                         }
2729                 case V4L2_CID_FOCUS_CONTINUOUS:
2730                         {
2731                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2732                                         if (ext_ctrl->value == 1) {
2733                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2734                                                         return -EINVAL;
2735                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2736                                         }
2737                                 } else {
2738                                         if (ext_ctrl->value == 0)
2739                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2740                                 }
2741                                 break;
2742                         }
2743 #endif
2744 #if CONFIG_SENSOR_Flash
2745         case V4L2_CID_FLASH:
2746             {
2747                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2748                     return -EINVAL;
2749                 sensor->info_priv.flash = ext_ctrl->value;
2750
2751                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2752                 break;
2753             }
2754 #endif
2755         default:
2756             break;
2757     }
2758
2759     return 0;
2760 }
2761
2762 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2763 {
2764     struct i2c_client *client = sd->priv;
2765     struct soc_camera_device *icd = client->dev.platform_data;
2766     int i, error_cnt=0, error_idx=-1;
2767
2768
2769     for (i=0; i<ext_ctrl->count; i++) {
2770         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2771             error_cnt++;
2772             error_idx = i;
2773         }
2774     }
2775
2776     if (error_cnt > 1)
2777         error_idx = ext_ctrl->count;
2778
2779     if (error_idx != -1) {
2780         ext_ctrl->error_idx = error_idx;
2781         return -EINVAL;
2782     } else {
2783         return 0;
2784     }
2785 }
2786
2787 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2788 {
2789     struct i2c_client *client = sd->priv;
2790     struct soc_camera_device *icd = client->dev.platform_data;
2791     int i, error_cnt=0, error_idx=-1;
2792
2793     for (i=0; i<ext_ctrl->count; i++) {
2794         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2795             error_cnt++;
2796             error_idx = i;
2797         }
2798     }
2799
2800     if (error_cnt > 1)
2801         error_idx = ext_ctrl->count;
2802
2803     if (error_idx != -1) {
2804         ext_ctrl->error_idx = error_idx;
2805         return -EINVAL;
2806     } else {
2807         return 0;
2808     }
2809 }
2810
2811 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2812 {
2813         struct i2c_client *client = sd->priv;
2814     struct sensor *sensor = to_sensor(client);
2815
2816         if (enable == 1) {
2817                 sensor->info_priv.enable = 1;
2818         } else if (enable == 0) {
2819                 sensor->info_priv.enable = 0;
2820         }
2821
2822         return 0;
2823 }
2824
2825 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2826  * this wasn't our capture interface, so, we wait for the right one */
2827 static int sensor_video_probe(struct soc_camera_device *icd,
2828                                struct i2c_client *client)
2829 {
2830     int ret=0;
2831     struct sensor *sensor = to_sensor(client);
2832 #if (SENSOR_ID_REG != SEQUENCE_END)
2833     u16 pid;
2834 #endif
2835
2836     /* We must have a parent by now. And it cannot be a wrong one.
2837      * So this entire test is completely redundant. */
2838     if (!icd->dev.parent ||
2839             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2840                 return -ENODEV;
2841
2842         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2843                 ret = -ENODEV;
2844                 goto sensor_video_probe_err;
2845         }
2846
2847     /* soft reset */
2848 #if (SENSOR_RESET_REG != SEQUENCE_END)
2849     struct reginfo reg_info;
2850         reg_info.reg = SENSOR_RESET_REG;
2851         reg_info.val = SENSOR_RESET_VAL;
2852         reg_info.reg_len = SENSOR_RESET_REG_LEN;
2853     ret = sensor_write(client, &reg_info);
2854     if (ret != 0) {
2855         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2856         ret = -ENODEV;
2857                 goto sensor_video_probe_err;
2858     }
2859
2860     mdelay(5);  //delay 5 microseconds
2861 #endif
2862
2863         /* check if it is an sensor sensor */
2864 #if (SENSOR_ID_REG != SEQUENCE_END)
2865     ret = sensor_read(client, SENSOR_ID_REG, &pid);
2866     if (ret != 0) {
2867         SENSOR_TR("read chip id failed\n");
2868         ret = -ENODEV;
2869         goto sensor_video_probe_err;
2870     }
2871
2872     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2873 #else
2874         pid = SENSOR_ID;
2875 #endif
2876
2877     if (pid == SENSOR_ID) {
2878         sensor->model = SENSOR_V4L2_IDENT;
2879     } else {
2880         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2881         ret = -ENODEV;
2882         goto sensor_video_probe_err;
2883     }
2884
2885     icd->formats = sensor_colour_formats;
2886     icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2887
2888     return 0;
2889
2890 sensor_video_probe_err:
2891
2892     return ret;
2893 }
2894 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2895 {
2896         struct i2c_client *client = sd->priv;
2897     struct soc_camera_device *icd = client->dev.platform_data;
2898     struct sensor *sensor = to_sensor(client);
2899     int ret = 0;
2900     
2901         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2902         switch (cmd)
2903         {
2904                 case RK29_CAM_SUBDEV_DEACTIVATE:
2905                 {
2906                         sensor_deactivate(client);
2907                         break;
2908                 }
2909                 case RK29_CAM_SUBDEV_IOREQUEST:
2910                 {
2911                         sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;           
2912             if (sensor->sensor_io_request != NULL) { 
2913                 if (sensor->sensor_io_request->gpio_res[0].dev_name && 
2914                     (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2915                     sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2916                 } else if (sensor->sensor_io_request->gpio_res[1].dev_name && 
2917                     (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2918                     sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2919                 }
2920             } else {
2921                 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2922                 ret = -EINVAL;
2923                 goto sensor_ioctl_end;
2924             }
2925             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
2926                for this project */
2927             #if CONFIG_SENSOR_Flash     
2928             int i;
2929                 if (sensor->sensor_gpio_res) {
2930                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2931                     for (i = 0; i < icd->ops->num_controls; i++) {
2932                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2933                                         memset(&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                      
2934                                 }
2935                     }
2936                     sensor->info_priv.flash = 0xff;
2937                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2938                 }
2939                 }
2940             #endif
2941                         break;
2942                 }
2943                 default:
2944                 {
2945                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2946                         break;
2947                 }
2948         }
2949 sensor_ioctl_end:
2950         return ret;
2951
2952 }
2953
2954 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2955         .init           = sensor_init,
2956         .g_ctrl         = sensor_g_control,
2957         .s_ctrl         = sensor_s_control,
2958         .g_ext_ctrls          = sensor_g_ext_controls,
2959         .s_ext_ctrls          = sensor_s_ext_controls,
2960         .g_chip_ident   = sensor_g_chip_ident,
2961         .ioctl = sensor_ioctl,
2962 };
2963
2964 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2965         .s_fmt          = sensor_s_fmt,
2966         .g_fmt          = sensor_g_fmt,
2967         .try_fmt        = sensor_try_fmt,
2968         .s_stream   = sensor_s_stream,
2969 };
2970
2971 static struct v4l2_subdev_ops sensor_subdev_ops = {
2972         .core   = &sensor_subdev_core_ops,
2973         .video = &sensor_subdev_video_ops,
2974 };
2975
2976 static int sensor_probe(struct i2c_client *client,
2977                          const struct i2c_device_id *did)
2978 {
2979     struct sensor *sensor;
2980     struct soc_camera_device *icd = client->dev.platform_data;
2981     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2982     struct soc_camera_link *icl;
2983     int ret;
2984
2985     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2986     if (!icd) {
2987         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2988         return -EINVAL;
2989     }
2990
2991     icl = to_soc_camera_link(icd);
2992     if (!icl) {
2993         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2994         return -EINVAL;
2995     }
2996
2997     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2998         dev_warn(&adapter->dev,
2999                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3000         return -EIO;
3001     }
3002
3003     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3004     if (!sensor)
3005         return -ENOMEM;
3006
3007     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3008
3009     /* Second stage probe - when a capture adapter is there */
3010     icd->ops            = &sensor_ops;
3011     icd->y_skip_top             = 0;
3012         #if CONFIG_SENSOR_I2C_NOSCHED
3013         atomic_set(&sensor->tasklock_cnt,0);
3014         #endif
3015
3016     ret = sensor_video_probe(icd, client);
3017     if (ret < 0) {
3018         icd->ops = NULL;
3019         i2c_set_clientdata(client, NULL);
3020         kfree(sensor);
3021                 sensor = NULL;
3022     }
3023     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3024     return ret;
3025 }
3026
3027 static int sensor_remove(struct i2c_client *client)
3028 {
3029     struct sensor *sensor = to_sensor(client);
3030     struct soc_camera_device *icd = client->dev.platform_data;
3031
3032         #if CONFIG_SENSOR_Focus
3033         if (sensor->sensor_wq) {
3034                 destroy_workqueue(sensor->sensor_wq);
3035                 sensor->sensor_wq = NULL;
3036         }
3037         #endif
3038
3039     icd->ops = NULL;
3040     i2c_set_clientdata(client, NULL);
3041     client->driver = NULL;
3042     kfree(sensor);
3043         sensor = NULL;
3044     return 0;
3045 }
3046
3047 static const struct i2c_device_id sensor_id[] = {
3048         {SENSOR_NAME_STRING(), 0 },
3049         { }
3050 };
3051 MODULE_DEVICE_TABLE(i2c, sensor_id);
3052
3053 static struct i2c_driver sensor_i2c_driver = {
3054         .driver = {
3055                 .name = SENSOR_NAME_STRING(),
3056         },
3057         .probe          = sensor_probe,
3058         .remove         = sensor_remove,
3059         .id_table       = sensor_id,
3060 };
3061
3062 static int __init sensor_mod_init(void)
3063 {
3064     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3065     return i2c_add_driver(&sensor_i2c_driver);
3066 }
3067
3068 static void __exit sensor_mod_exit(void)
3069 {
3070     i2c_del_driver(&sensor_i2c_driver);
3071 }
3072
3073 device_initcall_sync(sensor_mod_init);
3074 module_exit(sensor_mod_exit);
3075
3076 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3077 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3078 MODULE_LICENSE("GPL");
3079
3080