Revert "camera driver v0.2.1 for RK30"
[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_MBUS_FMT_UYVY8_2X8
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 /* only one fixed colorspace per pixelcode */
1123 struct sensor_datafmt {
1124         enum v4l2_mbus_pixelcode code;
1125         enum v4l2_colorspace colorspace;
1126 };
1127
1128 /* Find a data format by a pixel code in an array */
1129 static const struct sensor_datafmt *sensor_find_datafmt(
1130         enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1131         int n)
1132 {
1133         int i;
1134         for (i = 0; i < n; i++)
1135                 if (fmt[i].code == code)
1136                         return fmt + i;
1137
1138         return NULL;
1139 }
1140
1141 static const struct sensor_datafmt sensor_colour_fmts[] = {
1142     {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1143     {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}     
1144 };
1145 enum sensor_work_state
1146 {
1147         sensor_work_ready = 0,
1148         sensor_working,
1149 };
1150 struct sensor_work
1151 {
1152         struct i2c_client *client;
1153         struct delayed_work dwork;
1154         enum sensor_work_state state;
1155 };
1156
1157 typedef struct sensor_info_priv_s
1158 {
1159     int whiteBalance;
1160     int brightness;
1161     int contrast;
1162     int saturation;
1163     int effect;
1164     int scene;
1165     int digitalzoom;
1166     int focus;
1167         int auto_focus;
1168         int affm_reinit;
1169     int flash;
1170     int exposure;
1171     unsigned char mirror;                                        /* HFLIP */
1172     unsigned char flip;                                          /* VFLIP */
1173         bool snap2preview;
1174         bool video2preview;
1175         int capture_w;
1176         int capture_h;
1177         int preview_w;
1178         int preview_h;
1179     struct reginfo *winseqe_cur_addr;
1180         struct sensor_datafmt fmt;
1181         unsigned int enable;
1182         unsigned int funmodule_state;
1183 } sensor_info_priv_t;
1184
1185
1186
1187 struct sensor_parameter
1188 {
1189         unsigned short int preview_maxlines;
1190         unsigned short int preview_exposure;
1191         unsigned short int preview_line_width;
1192         unsigned short int preview_gain;
1193
1194         unsigned short int capture_framerate;
1195         unsigned short int preview_framerate;
1196 };
1197
1198 struct sensor
1199 {
1200     struct v4l2_subdev subdev;
1201     struct i2c_client *client;
1202     sensor_info_priv_t info_priv;
1203         struct sensor_parameter parameter;
1204         struct workqueue_struct *sensor_wq;
1205         struct sensor_work sensor_wk;
1206         struct mutex wq_lock;
1207     int model;  /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1208 #if CONFIG_SENSOR_I2C_NOSCHED
1209         atomic_t tasklock_cnt;
1210 #endif
1211         struct rk29camera_platform_data *sensor_io_request;
1212     struct rk29camera_gpio_res *sensor_gpio_res;
1213 };
1214
1215 static struct sensor* to_sensor(const struct i2c_client *client)
1216 {
1217     return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1218 }
1219
1220 static int sensor_task_lock(struct i2c_client *client, int lock)
1221 {
1222 #if CONFIG_SENSOR_I2C_NOSCHED
1223         int cnt = 3;
1224     struct sensor *sensor = to_sensor(client);
1225
1226         if (lock) {
1227                 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1228                         while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1229                                 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1230                                 msleep(35);
1231                                 cnt--;
1232                         }
1233                         if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1234                                 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1235                                 goto sensor_task_lock_err;
1236                         }
1237                         preempt_disable();
1238                 }
1239
1240                 atomic_add(1, &sensor->tasklock_cnt);
1241         } else {
1242                 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1243                         atomic_sub(1, &sensor->tasklock_cnt);
1244
1245                         if (atomic_read(&sensor->tasklock_cnt) == 0)
1246                                 preempt_enable();
1247                 }
1248         }
1249     
1250         return 0;
1251 sensor_task_lock_err:
1252         return -1;    
1253 #else
1254     return 0;
1255 #endif
1256 }
1257
1258 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val);
1259
1260 /* sensor register write */
1261 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1262 {
1263     int err=0,cnt;
1264     u8 buf[4];
1265     struct i2c_msg msg[1];
1266
1267         switch (reg_info->reg)
1268         {
1269                 case SEQUENCE_WAIT_MS:
1270                 {
1271                         if (in_atomic())
1272                                 mdelay(reg_info->val);
1273                         else
1274                                 msleep(reg_info->val);
1275                         break;
1276                 }
1277
1278                 case SEQUENCE_WAIT_US:
1279                 {
1280                         udelay(reg_info->val);
1281                         break;
1282                 }
1283
1284                 case SEQUENCE_PROPERTY:
1285                 {
1286                         break;
1287                 }
1288                 default:
1289                 {
1290                     buf[0] = reg_info->reg >> 8;
1291                     buf[1] = reg_info->reg & 0xFF;
1292                         if (reg_info->reg_len == WORD_LEN) {
1293                                 buf[2] = reg_info->val >> 8;
1294                                 buf[3] = reg_info->val & 0xFF;
1295
1296                                 msg->len = 4;
1297                         } else if (reg_info->reg_len == BYTE_LEN) {
1298                                 buf[2] = reg_info->val;
1299                                 msg->len = 3;
1300                         }
1301
1302                     msg->addr = client->addr;
1303                     msg->flags = client->flags;
1304                     msg->buf = buf;
1305                     msg->scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1306                     msg->read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1307
1308                     cnt = 3;
1309                     err = -EAGAIN;
1310
1311                     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1312                         err = i2c_transfer(client->adapter, msg, 1);
1313
1314                         if (err >= 0) {
1315                             return 0;
1316                         } else {
1317                             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);
1318                             udelay(10);
1319                         }
1320                     }
1321                 }
1322         }
1323     return err;
1324 }
1325
1326 /* sensor register read */
1327 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1328 {
1329     int err,cnt;
1330     u8 buf[2];
1331     struct i2c_msg msg[2];
1332
1333     buf[0] = reg >> 8;
1334     buf[1] = reg & 0xFF;
1335
1336     msg[0].addr = client->addr;
1337     msg[0].flags = client->flags;
1338     msg[0].buf = buf;
1339     msg[0].len = sizeof(buf);
1340     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;       /* ddl@rock-chips.com : 100kHz */
1341     msg[0].read_type = 2;   /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1342
1343     msg[1].addr = client->addr;
1344     msg[1].flags = client->flags|I2C_M_RD;
1345     msg[1].buf = buf;
1346     msg[1].len = 2;
1347     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;                       /* ddl@rock-chips.com : 100kHz */
1348     msg[1].read_type = 2;                             /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1349
1350     cnt = 3;
1351     err = -EAGAIN;
1352     while ((cnt-- > 0) && (err < 0)) {                       /* ddl@rock-chips.com :  Transfer again if transent is failed   */
1353         err = i2c_transfer(client->adapter, msg, 2);
1354
1355         if (err >= 0) {
1356             *val = buf[0]<<8 | buf[1];
1357             return 0;
1358         } else {
1359                 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1360             udelay(10);
1361         }
1362     }
1363
1364     return err;
1365 }
1366
1367 /* write a array of registers  */
1368 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1369 {
1370     int err = 0, cnt;
1371     int i = 0;
1372 #if CONFIG_SENSOR_I2C_RDWRCHK
1373         u16 valchk;
1374 #endif
1375
1376         cnt = 0;
1377         if (sensor_task_lock(client, 1) < 0)
1378                 goto sensor_write_array_end;
1379     while (regarray[i].reg != SEQUENCE_END) {
1380         err = sensor_write(client, &regarray[i]);
1381         if (err < 0)
1382         {
1383             if (cnt-- > 0) {
1384                             SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1385                                 i = 0;
1386                                 continue;
1387             } else {
1388                 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1389                 err = -EPERM;
1390                                 goto sensor_write_array_end;
1391             }
1392         } else {
1393         #if CONFIG_SENSOR_I2C_RDWRCHK
1394                         sensor_read(client, regarray[i].reg, &valchk);
1395                         if (valchk != regarray[i].val)
1396                                 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1397                 #endif
1398         }
1399
1400         i++;
1401     }
1402
1403 sensor_write_array_end:
1404         sensor_task_lock(client,0);
1405     return err;
1406 }
1407 #if CONFIG_SENSOR_I2C_RDWRCHK
1408 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1409 {
1410     int cnt;
1411     int i = 0;
1412         u16 valchk;
1413
1414         cnt = 0;
1415         valchk = 0;
1416     while (regarray[i].reg != SEQUENCE_END)
1417     {
1418                 sensor_read(client, regarray[i].reg, &valchk);
1419                 if (valchk != regarray[i].val)
1420                         SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1421
1422         i++;
1423     }
1424     return 0;
1425 }
1426 #endif
1427 #if CONFIG_SENSOR_Focus
1428 static struct reginfo sensor_af_init0[] =
1429 {
1430
1431         {SEQUENCE_END, 0x00}
1432 };
1433 static struct reginfo sensor_af_init1[] =
1434 {
1435     {SEQUENCE_END, 0x00}
1436 };
1437
1438
1439 static struct reginfo sensor_af_trigger[] =
1440 {
1441         {SEQUENCE_END, 0x00}
1442 };
1443 static int sensor_af_single(struct i2c_client *client)
1444 {
1445         int ret = 0;
1446
1447         ret = sensor_write_array(client, sensor_af_trigger);
1448         if (ret<0)
1449                 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1450         else
1451                 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1452 sensor_af_single_end:
1453         return ret;
1454 }
1455
1456 static int sensor_af_const(struct i2c_client *client)
1457 {
1458         int ret = 0;
1459
1460 sensor_af_const_end:
1461         return ret;
1462 }
1463
1464 static int sensor_af_zoneupdate(struct i2c_client *client)
1465 {
1466         int ret = 0;
1467         struct i2c_msg msg[2];
1468     u8 buf[2][6] =
1469         {
1470                 {0xb0,0x08,0x00,0x03,0xff,0xff},
1471                 {0xb0,0x0c,0xff,0xff,0xff,0xff},
1472         };
1473
1474     msg[0].addr = client->addr;
1475     msg[0].flags = client->flags;
1476     msg[0].buf = buf[0];
1477     msg[0].len = sizeof(buf);
1478     msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1479     msg[0].read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1480
1481     msg[1].addr = client->addr;
1482     msg[1].flags = client->flags;
1483     msg[1].buf = buf[1];
1484     msg[1].len = sizeof(buf);
1485     msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED;         /* ddl@rock-chips.com : 100kHz */
1486     msg[1].read_type = 0;               /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1487
1488     ret = i2c_transfer(client->adapter, &msg[0], 1);
1489         ret |= i2c_transfer(client->adapter, &msg[1], 1);
1490     if (ret >= 0) {
1491         return 0;
1492     } else {
1493         SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
1494     }
1495
1496 sensor_af_zoneupdate_end:
1497         return ret;
1498 }
1499
1500 static int sensor_af_init(struct i2c_client *client)
1501 {
1502         int ret = 0;
1503
1504         ret = sensor_write_array(client, sensor_af_init0);
1505         if (ret<0) {
1506                 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1507         } else {
1508                 if (sensor_af_zoneupdate(client) == 0) {
1509                         ret = sensor_write_array(client, sensor_af_init1);
1510                         if (ret<0) {
1511                                 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1512                         }
1513                 }
1514         }
1515
1516         return ret;
1517 }
1518 #endif
1519
1520 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1521 {
1522         struct soc_camera_link *icl = to_soc_camera_link(icd);
1523         int ret = 0;
1524
1525     SENSOR_DG("%s %s  cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1526         switch (cmd)
1527         {
1528                 case Sensor_PowerDown:
1529                 {
1530                         if (icl->powerdown) {
1531                                 ret = icl->powerdown(icd->pdev, on);
1532                                 if (ret == RK29_CAM_IO_SUCCESS) {
1533                                         if (on == 0) {
1534                                                 mdelay(2);
1535                                                 if (icl->reset)
1536                                                         icl->reset(icd->pdev);
1537                                         }
1538                                 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1539                                         ret = -ENODEV;
1540                                         goto sensor_power_end;
1541                                 }
1542                         }
1543                         break;
1544                 }
1545                 case Sensor_Flash:
1546                 {
1547                         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1548                 struct sensor *sensor = to_sensor(client);
1549
1550                         if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1551                                 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1552                         }
1553                         break;
1554                 }
1555                 default:
1556                 {
1557                         SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1558                         break;
1559                 }
1560         }
1561
1562 sensor_power_end:
1563         return ret;
1564 }
1565 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1566 {
1567     struct i2c_client *client = v4l2_get_subdevdata(sd);
1568     struct soc_camera_device *icd = client->dev.platform_data;
1569     struct sensor *sensor = to_sensor(client);
1570         const struct v4l2_queryctrl *qctrl;
1571     const struct sensor_datafmt *fmt;
1572     int ret;
1573     u16 pid = 0;
1574
1575     SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1576
1577         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1578                 ret = -ENODEV;
1579                 goto sensor_INIT_ERR;
1580         }
1581     mdelay(100);
1582     /* soft reset */
1583         if (sensor_task_lock(client,1)<0)
1584                 goto sensor_INIT_ERR;
1585
1586 #if (SENSOR_RESET_REG != SEQUENCE_END)
1587     struct reginfo reg_info;
1588         reg_info.reg = SENSOR_RESET_REG;
1589         reg_info.val = SENSOR_RESET_VAL;
1590         reg_info.reg_len = SENSOR_RESET_REG_LEN;
1591     ret = sensor_write(client, &reg_info);
1592     if (ret != 0) {
1593         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1594         ret = -ENODEV;
1595                 goto sensor_INIT_ERR;
1596     }
1597     mdelay(5);  //delay 5 microseconds
1598     reg_info.val = SENSOR_DERESET_VAL;
1599     ret = sensor_write(client, &reg_info);
1600     if (ret != 0) {
1601         SENSOR_TR("%s soft dereset sensor failed\n",SENSOR_NAME_STRING());
1602         ret = -ENODEV;
1603                 goto sensor_INIT_ERR;
1604     }
1605 #endif
1606
1607         /* check if it is an sensor sensor */
1608 #if (SENSOR_ID_REG != SEQUENCE_END)
1609     ret = sensor_read(client, SENSOR_ID_REG, &pid);
1610     if (ret != 0) {
1611         SENSOR_TR("read chip id failed\n");
1612         ret = -ENODEV;
1613         goto sensor_INIT_ERR;
1614     }
1615
1616     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1617 #else
1618         pid = SENSOR_ID;
1619 #endif
1620     if (pid == SENSOR_ID) {
1621         sensor->model = SENSOR_V4L2_IDENT;
1622     } else {
1623         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1624         ret = -ENODEV;
1625         goto sensor_INIT_ERR;
1626     }
1627
1628     ret = sensor_write_array(client, sensor_init_data);
1629     if (ret != 0)
1630     {
1631         SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1632         goto sensor_INIT_ERR;
1633     }
1634         sensor_task_lock(client,0);
1635     sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1636     sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1637     sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1638     sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1639     sensor->info_priv.winseqe_cur_addr  = SENSOR_INIT_WINSEQADR;
1640     fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1641     if (!fmt) {
1642         SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1643         ret = -EINVAL;
1644         goto sensor_INIT_ERR;
1645     }
1646         sensor->info_priv.fmt = *fmt;
1647
1648     /* sensor sensor information for initialization  */
1649         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1650         if (qctrl)
1651         sensor->info_priv.whiteBalance = qctrl->default_value;
1652         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1653         if (qctrl)
1654         sensor->info_priv.brightness = qctrl->default_value;
1655         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1656         if (qctrl)
1657         sensor->info_priv.effect = qctrl->default_value;
1658         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1659         if (qctrl)
1660         sensor->info_priv.exposure = qctrl->default_value;
1661
1662         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1663         if (qctrl)
1664         sensor->info_priv.saturation = qctrl->default_value;
1665         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1666         if (qctrl)
1667         sensor->info_priv.contrast = qctrl->default_value;
1668         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1669         if (qctrl)
1670         sensor->info_priv.mirror = qctrl->default_value;
1671         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1672         if (qctrl)
1673         sensor->info_priv.flip = qctrl->default_value;
1674         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1675         if (qctrl)
1676         sensor->info_priv.scene = qctrl->default_value;
1677         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1678         if (qctrl)
1679         sensor->info_priv.digitalzoom = qctrl->default_value;
1680
1681     /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code  */
1682         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1683         if (qctrl)
1684         sensor->info_priv.focus = qctrl->default_value;
1685         #if CONFIG_SENSOR_Focus
1686         if (sensor_af_init(client) < 0) {
1687                 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1688                 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1689         } else {
1690                 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1691                 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1692         }
1693         #endif
1694         #if CONFIG_SENSOR_Flash
1695         qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1696         if (qctrl)
1697         sensor->info_priv.flash = qctrl->default_value;
1698     #endif
1699     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);
1700
1701     return 0;
1702 sensor_INIT_ERR:
1703         sensor_task_lock(client,0);
1704         sensor_deactivate(client);
1705     return ret;
1706 }
1707 static int sensor_deactivate(struct i2c_client *client)
1708 {
1709         struct soc_camera_device *icd = client->dev.platform_data;
1710
1711         SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1712
1713         /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1714         sensor_ioctrl(icd, Sensor_PowerDown, 1);
1715
1716         /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1717         icd->user_width = SENSOR_INIT_WIDTH;
1718     icd->user_height = SENSOR_INIT_HEIGHT;
1719         msleep(100);
1720         return 0;
1721 }
1722 static  struct reginfo sensor_power_down_sequence[]=
1723 {
1724     {0x00,0x00}
1725 };
1726 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1727 {
1728     int ret;
1729     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1730
1731     if (pm_msg.event == PM_EVENT_SUSPEND) {
1732         SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1733         ret = sensor_write_array(client, sensor_power_down_sequence) ;
1734         if (ret != 0) {
1735             SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1736             return ret;
1737         } else {
1738             ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1739             if (ret < 0) {
1740                             SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1741                 return -EINVAL;
1742             }
1743         }
1744     } else {
1745         SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1746         return -EINVAL;
1747     }
1748
1749     return 0;
1750 }
1751
1752 static int sensor_resume(struct soc_camera_device *icd)
1753 {
1754         int ret;
1755
1756     ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1757     if (ret < 0) {
1758                 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1759         return -EINVAL;
1760     }
1761
1762         SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1763         return 0;
1764 }
1765
1766 static int sensor_set_bus_param(struct soc_camera_device *icd,
1767                                 unsigned long flags)
1768 {
1769
1770     return 0;
1771 }
1772
1773 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1774 {
1775     struct soc_camera_link *icl = to_soc_camera_link(icd);
1776     unsigned long flags = SENSOR_BUS_PARAM;
1777
1778     return soc_camera_apply_sensor_flags(icl, flags);
1779 }
1780 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1781 {
1782     struct i2c_client *client = v4l2_get_subdevdata(sd);
1783     struct soc_camera_device *icd = client->dev.platform_data;
1784     struct sensor *sensor = to_sensor(client);
1785
1786     mf->width   = icd->user_width;
1787         mf->height      = icd->user_height;
1788         mf->code        = sensor->info_priv.fmt.code;
1789         mf->colorspace  = sensor->info_priv.fmt.colorspace;
1790         mf->field       = V4L2_FIELD_NONE;
1791
1792     return 0;
1793 }
1794 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1795 {
1796     bool ret = false;
1797
1798         if ((mf->width == 1024) && (mf->height == 768)) {
1799                 ret = true;
1800         } else if ((mf->width == 1280) && (mf->height == 1024)) {
1801                 ret = true;
1802         } else if ((mf->width == 1600) && (mf->height == 1200)) {
1803                 ret = true;
1804         } else if ((mf->width == 2048) && (mf->height == 1536)) {
1805                 ret = true;
1806         } else if ((mf->width == 2592) && (mf->height == 1944)) {
1807                 ret = true;
1808         }
1809
1810         if (ret == true)
1811                 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1812         return ret;
1813 }
1814
1815 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1816 {
1817     bool ret = false;
1818
1819         if ((mf->width == 1280) && (mf->height == 720)) {
1820                 ret = true;
1821         } else if ((mf->width == 1920) && (mf->height == 1080)) {
1822                 ret = true;
1823         }
1824
1825         if (ret == true)
1826                 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1827         return ret;
1828 }
1829 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1830 {
1831         struct reginfo *winseqe_set_addr = NULL;
1832
1833         if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1834                 winseqe_set_addr = sensor_qcif;
1835         *ret_w = 176;
1836         *ret_h = 144;
1837         } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1838         winseqe_set_addr = sensor_qvga;
1839         *ret_w = 320;
1840         *ret_h = 240;
1841         } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1842         winseqe_set_addr = sensor_cif;
1843         *ret_w = 352;
1844         *ret_h = 288;
1845     } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1846         winseqe_set_addr = sensor_vga;
1847         *ret_w = 640;
1848         *ret_h = 480;
1849     } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1850         printk("enter 800x600\n");
1851         winseqe_set_addr = sensor_svga;
1852         *ret_w = 800;
1853         *ret_h = 600;
1854     } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1855         winseqe_set_addr = sensor_xga;
1856         *ret_w = 1024;
1857         *ret_h = 768;
1858         } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1859         printk("enter 1280X720\n");
1860         winseqe_set_addr = sensor_720p;
1861         *ret_w = 1280;
1862         *ret_h = 720;
1863     } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1864         printk("enter 1280X1024\n");
1865         winseqe_set_addr = sensor_sxga;
1866         *ret_w = 1280;
1867         *ret_h = 1024;
1868     } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1869         winseqe_set_addr = sensor_uxga;
1870         *ret_w = 1600;
1871         *ret_h = 1200;
1872         } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1873       winseqe_set_addr = sensor_1080p;
1874         *ret_w = 1920;
1875         *ret_h = 1080;
1876     } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1877         winseqe_set_addr = sensor_qxga;
1878         *ret_w = 2048;
1879         *ret_h = 1536;
1880     } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1881         winseqe_set_addr = sensor_qsxga;
1882         *ret_w = 2592;
1883         *ret_h = 1944;
1884     }
1885
1886         return winseqe_set_addr;
1887 }
1888
1889 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1890 {
1891     struct i2c_client *client = v4l2_get_subdevdata(sd);
1892     struct sensor *sensor = to_sensor(client);
1893     const struct sensor_datafmt *fmt;
1894     struct reginfo *winseqe_set_addr=NULL;
1895     int ret = 0, set_w,set_h;
1896
1897     SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
1898
1899         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1900                                    ARRAY_SIZE(sensor_colour_fmts));
1901         if (!fmt) {
1902         ret = -EINVAL;
1903         goto sensor_s_fmt_end;
1904     }
1905
1906         if (sensor->info_priv.fmt.code != mf->code) {
1907                 switch (mf->code)
1908                 {
1909                         case V4L2_MBUS_FMT_YUYV8_2X8:
1910                         {
1911                                 winseqe_set_addr = sensor_ClrFmt_YUYV;
1912                                 break;
1913                         }
1914                         case V4L2_MBUS_FMT_UYVY8_2X8:
1915                         {
1916                                 winseqe_set_addr = sensor_ClrFmt_UYVY;
1917                                 break;
1918                         }
1919                         default:
1920                                 break;
1921                 }
1922                 if (winseqe_set_addr != NULL) {
1923             sensor_write_array(client, winseqe_set_addr);
1924                         sensor->info_priv.fmt.code = mf->code;
1925             sensor->info_priv.fmt.colorspace= mf->colorspace;            
1926                         SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1927                 } else {
1928                         SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1929                 }
1930         }
1931
1932     set_w = mf->width;
1933     set_h = mf->height;
1934
1935         winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1936
1937     if ((winseqe_set_addr  != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1938         ret |= sensor_write_array(client, winseqe_set_addr);
1939         if (ret != 0) {
1940             SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1941             goto sensor_s_fmt_end;
1942         }
1943         sensor->info_priv.winseqe_cur_addr  = winseqe_set_addr;
1944                 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1945                 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1946                 } else {
1947                         SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1948                         sensor->info_priv.preview_w = mf->width;
1949                         sensor->info_priv.preview_h = mf->height;
1950                 }
1951     }
1952
1953         if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1954                 ret |= sensor_write_array(client, sensor_Preview2Capture);
1955                 if (ret != 0) {
1956                 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
1957                 goto sensor_s_fmt_end;
1958         }
1959                 sensor->info_priv.capture_w = set_w;
1960                 sensor->info_priv.capture_h = set_h;
1961                 sensor->info_priv.snap2preview = true;
1962         } else if (sensor->info_priv.snap2preview == true) {
1963                 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
1964                         ret |= sensor_write_array(client, sensor_Capture2Preview);
1965                         if (ret != 0) {
1966                         SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
1967                         goto sensor_s_fmt_end;
1968                 }
1969                         sensor->info_priv.preview_w = mf->width;
1970                         sensor->info_priv.preview_h = mf->height;
1971                         sensor->info_priv.snap2preview = false;
1972                 } else {
1973                         SENSOR_TR("\n %s..%s Format is Invalidate. mf->width = %d.. mf->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1974                 }
1975         }
1976
1977         mf->width = set_w;
1978         mf->height = set_h;
1979 sensor_s_fmt_end:
1980     return ret;
1981 }
1982
1983 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1984 {
1985         int ret = 0;
1986     struct i2c_client *client = v4l2_get_subdevdata(sd);
1987     struct sensor *sensor = to_sensor(client);
1988     const struct sensor_datafmt *fmt;
1989    
1990         fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1991                                    ARRAY_SIZE(sensor_colour_fmts));
1992         if (fmt == NULL) {
1993                 fmt = &sensor->info_priv.fmt;
1994         mf->code = fmt->code;
1995         } 
1996
1997     SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
1998
1999     /*
2000     * With Bayer format enforce even side lengths, but let the user play
2001     * with the starting pixel
2002     */
2003
2004     if (mf->height > SENSOR_MAX_HEIGHT)
2005         mf->height = SENSOR_MAX_HEIGHT;
2006     else if (mf->height < SENSOR_MIN_HEIGHT)
2007         mf->height = SENSOR_MIN_HEIGHT;
2008
2009     if (mf->width > SENSOR_MAX_WIDTH)
2010         mf->width = SENSOR_MAX_WIDTH;
2011     else if (mf->width < SENSOR_MIN_WIDTH)
2012         mf->width = SENSOR_MIN_WIDTH;
2013
2014         if (sensor_fmt_catch(mf->width, mf->height, &mf->width, &mf->height) == NULL) {
2015         printk("%s[%d] ERR!!!!!!",__FUNCTION__,__LINE__);
2016                 mf->width = 0;
2017                 mf->height = 0;
2018         }
2019
2020     return ret;
2021 }
2022
2023  static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2024 {
2025     struct i2c_client *client = v4l2_get_subdevdata(sd);
2026
2027     if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2028         return -EINVAL;
2029
2030     if (id->match.addr != client->addr)
2031         return -ENODEV;
2032
2033     id->ident = SENSOR_V4L2_IDENT;      /* ddl@rock-chips.com :  Return OV2655  identifier */
2034     id->revision = 0;
2035
2036     return 0;
2037 }
2038 #if CONFIG_SENSOR_Brightness
2039 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2040 {
2041     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2042
2043     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2044     {
2045         if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2046         {
2047             if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2048             {
2049                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2050                 return -EINVAL;
2051             }
2052             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2053             return 0;
2054         }
2055     }
2056         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2057     return -EINVAL;
2058 }
2059 #endif
2060 #if CONFIG_SENSOR_Effect
2061 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2062 {
2063     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2064
2065     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2066     {
2067         if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2068         {
2069             if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2070             {
2071                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2072                 return -EINVAL;
2073             }
2074             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2075             return 0;
2076         }
2077     }
2078         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2079     return -EINVAL;
2080 }
2081 #endif
2082 #if CONFIG_SENSOR_Exposure
2083 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2084 {
2085     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2086
2087     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2088     {
2089         if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2090         {
2091             if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2092             {
2093                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2094                 return -EINVAL;
2095             }
2096             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2097             return 0;
2098         }
2099     }
2100         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2101     return -EINVAL;
2102 }
2103 #endif
2104 #if CONFIG_SENSOR_Saturation
2105 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2106 {
2107     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2108
2109     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2110     {
2111         if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2112         {
2113             if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2114             {
2115                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2116                 return -EINVAL;
2117             }
2118             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2119             return 0;
2120         }
2121     }
2122     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2123     return -EINVAL;
2124 }
2125 #endif
2126 #if CONFIG_SENSOR_Contrast
2127 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2128 {
2129     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2130
2131     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2132     {
2133         if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2134         {
2135             if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2136             {
2137                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2138                 return -EINVAL;
2139             }
2140             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2141             return 0;
2142         }
2143     }
2144     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2145     return -EINVAL;
2146 }
2147 #endif
2148 #if CONFIG_SENSOR_Mirror
2149 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2150 {
2151     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2152
2153     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2154     {
2155         if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2156         {
2157             if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2158             {
2159                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2160                 return -EINVAL;
2161             }
2162             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2163             return 0;
2164         }
2165     }
2166     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2167     return -EINVAL;
2168 }
2169 #endif
2170 #if CONFIG_SENSOR_Flip
2171 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2172 {
2173     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2174
2175     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2176     {
2177         if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2178         {
2179             if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2180             {
2181                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2182                 return -EINVAL;
2183             }
2184             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2185             return 0;
2186         }
2187     }
2188     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2189     return -EINVAL;
2190 }
2191 #endif
2192 #if CONFIG_SENSOR_Scene
2193 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2194 {
2195     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2196
2197     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2198     {
2199         if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2200         {
2201             if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2202             {
2203                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2204                 return -EINVAL;
2205             }
2206             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2207             return 0;
2208         }
2209     }
2210     SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2211     return -EINVAL;
2212 }
2213 #endif
2214 #if CONFIG_SENSOR_WhiteBalance
2215 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2216 {
2217     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2218
2219     if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2220     {
2221         if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2222         {
2223             if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2224             {
2225                 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2226                 return -EINVAL;
2227             }
2228             SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2229             return 0;
2230         }
2231     }
2232         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2233     return -EINVAL;
2234 }
2235 #endif
2236 #if CONFIG_SENSOR_DigitalZoom
2237 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2238 {
2239     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2240     struct sensor *sensor = to_sensor(client);
2241         const struct v4l2_queryctrl *qctrl_info;
2242     int digitalzoom_cur, digitalzoom_total;
2243
2244         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2245         if (qctrl_info)
2246                 return -EINVAL;
2247
2248     digitalzoom_cur = sensor->info_priv.digitalzoom;
2249     digitalzoom_total = qctrl_info->maximum;
2250
2251     if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2252     {
2253         SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2254         return -EINVAL;
2255     }
2256
2257     if  ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2258     {
2259         SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2260         return -EINVAL;
2261     }
2262
2263     if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2264     {
2265         *value = digitalzoom_total - digitalzoom_cur;
2266     }
2267
2268     if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2269     {
2270         *value = 0 - digitalzoom_cur;
2271     }
2272
2273     digitalzoom_cur += *value;
2274
2275     if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2276     {
2277         if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2278         {
2279             SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2280             return -EINVAL;
2281         }
2282         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2283         return 0;
2284     }
2285
2286     return -EINVAL;
2287 }
2288 #endif
2289 #if CONFIG_SENSOR_Flash
2290 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2291 {
2292     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2293     struct sensor *sensor = to_sensor(client);
2294         const struct v4l2_queryctrl *qctrl_info;
2295     
2296     if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2297         if (value == 3) {       /* ddl@rock-chips.com: torch */
2298             sensor_ioctrl(icd, Sensor_Flash, Flash_Torch);   /* Flash On */
2299         } else {
2300             sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2301         }
2302         SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2303         return 0;
2304     }
2305     
2306         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2307     return -EINVAL;
2308 }
2309 #endif
2310 #if CONFIG_SENSOR_Focus
2311 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2312 {
2313         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2314     struct sensor *sensor = to_sensor(client);
2315         const struct v4l2_queryctrl *qctrl_info;
2316         int ret = 0;
2317
2318         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2319         if (!qctrl_info)
2320                 return -EINVAL;
2321
2322         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2323                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2324
2325                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2326                 } else {
2327                         ret = -EINVAL;
2328                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2329                 }
2330         } else {
2331                 ret = -EACCES;
2332                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2333                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2334         }
2335
2336 sensor_set_focus_absolute_end:
2337         return ret;
2338 }
2339 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2340 {
2341         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2342         struct sensor *sensor = to_sensor(client);
2343         const struct v4l2_queryctrl *qctrl_info;
2344         int ret = 0;
2345
2346         qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2347         if (!qctrl_info)
2348                 return -EINVAL;
2349
2350         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2351                 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2352
2353                         SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2354                 } else {
2355                         ret = -EINVAL;
2356                         SENSOR_TR("\n %s..%s valure = %d is invalidate..    \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2357                 }
2358         } else {
2359                 ret = -EACCES;
2360                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2361                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2362         }
2363 sensor_set_focus_relative_end:
2364         return ret;
2365 }
2366
2367 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2368 {
2369         struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2370         struct sensor *sensor = to_sensor(client);
2371         int ret = 0;
2372
2373         if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK)  && (sensor->info_priv.affm_reinit == 0)) {
2374                 switch (value)
2375                 {
2376                         case SENSOR_AF_MODE_AUTO:
2377                         {
2378                                 ret = sensor_af_single(client);
2379                                 break;
2380                         }
2381
2382                         case SENSOR_AF_MODE_MACRO:
2383                         {
2384                                 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2385                                 break;
2386                         }
2387
2388                         case SENSOR_AF_MODE_INFINITY:
2389                         {
2390                                 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2391                                 break;
2392                         }
2393
2394                         case SENSOR_AF_MODE_CONTINUOUS:
2395                         {
2396                                 ret = sensor_af_const(client);
2397                                 break;
2398                         }
2399                         default:
2400                                 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2401                                 break;
2402
2403                 }
2404
2405                 SENSOR_DG("%s..%s : %d  ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2406         } else {
2407                 ret = -EACCES;
2408                 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2409                         sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2410         }
2411
2412         return ret;
2413 }
2414 #endif
2415 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2416 {
2417     struct i2c_client *client = v4l2_get_subdevdata(sd);
2418     struct sensor *sensor = to_sensor(client);
2419     const struct v4l2_queryctrl *qctrl;
2420
2421     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2422
2423     if (!qctrl)
2424     {
2425         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2426         return -EINVAL;
2427     }
2428
2429     switch (ctrl->id)
2430     {
2431         case V4L2_CID_BRIGHTNESS:
2432             {
2433                 ctrl->value = sensor->info_priv.brightness;
2434                 break;
2435             }
2436         case V4L2_CID_SATURATION:
2437             {
2438                 ctrl->value = sensor->info_priv.saturation;
2439                 break;
2440             }
2441         case V4L2_CID_CONTRAST:
2442             {
2443                 ctrl->value = sensor->info_priv.contrast;
2444                 break;
2445             }
2446         case V4L2_CID_DO_WHITE_BALANCE:
2447             {
2448                 ctrl->value = sensor->info_priv.whiteBalance;
2449                 break;
2450             }
2451         case V4L2_CID_EXPOSURE:
2452             {
2453                 ctrl->value = sensor->info_priv.exposure;
2454                 break;
2455             }
2456         case V4L2_CID_HFLIP:
2457             {
2458                 ctrl->value = sensor->info_priv.mirror;
2459                 break;
2460             }
2461         case V4L2_CID_VFLIP:
2462             {
2463                 ctrl->value = sensor->info_priv.flip;
2464                 break;
2465             }
2466         default :
2467                 break;
2468     }
2469     return 0;
2470 }
2471
2472
2473
2474 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2475 {
2476     struct i2c_client *client = v4l2_get_subdevdata(sd);
2477     const struct v4l2_queryctrl *qctrl;   
2478     struct sensor *sensor = to_sensor(client);
2479     struct soc_camera_device *icd = client->dev.platform_data;
2480     qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2481
2482     if (!qctrl)
2483     {
2484         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2485         return -EINVAL;
2486     }
2487
2488     switch (ctrl->id)
2489     {
2490 #if CONFIG_SENSOR_Brightness
2491         case V4L2_CID_BRIGHTNESS:
2492             {
2493                 if (ctrl->value != sensor->info_priv.brightness)
2494                 {
2495                     if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2496                     {
2497                         return -EINVAL;
2498                     }
2499                     sensor->info_priv.brightness = ctrl->value;
2500                 }
2501                 break;
2502             }
2503 #endif
2504 #if CONFIG_SENSOR_Exposure
2505         case V4L2_CID_EXPOSURE:
2506             {
2507                 if (ctrl->value != sensor->info_priv.exposure)
2508                 {
2509                     if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2510                     {
2511                         return -EINVAL;
2512                     }
2513                     sensor->info_priv.exposure = ctrl->value;
2514                 }
2515                 break;
2516             }
2517 #endif
2518 #if CONFIG_SENSOR_Saturation
2519         case V4L2_CID_SATURATION:
2520             {
2521                 if (ctrl->value != sensor->info_priv.saturation)
2522                 {
2523                     if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2524                     {
2525                         return -EINVAL;
2526                     }
2527                     sensor->info_priv.saturation = ctrl->value;
2528                 }
2529                 break;
2530             }
2531 #endif
2532 #if CONFIG_SENSOR_Contrast
2533         case V4L2_CID_CONTRAST:
2534             {
2535                 if (ctrl->value != sensor->info_priv.contrast)
2536                 {
2537                     if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2538                     {
2539                         return -EINVAL;
2540                     }
2541                     sensor->info_priv.contrast = ctrl->value;
2542                 }
2543                 break;
2544             }
2545 #endif
2546 #if CONFIG_SENSOR_WhiteBalance
2547         case V4L2_CID_DO_WHITE_BALANCE:
2548             {
2549                 if (ctrl->value != sensor->info_priv.whiteBalance)
2550                 {
2551                     if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2552                     {
2553                         return -EINVAL;
2554                     }
2555                     sensor->info_priv.whiteBalance = ctrl->value;
2556                 }
2557                 break;
2558             }
2559 #endif
2560 #if CONFIG_SENSOR_Mirror
2561         case V4L2_CID_HFLIP:
2562             {
2563                 if (ctrl->value != sensor->info_priv.mirror)
2564                 {
2565                     if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2566                         return -EINVAL;
2567                     sensor->info_priv.mirror = ctrl->value;
2568                 }
2569                 break;
2570             }
2571 #endif
2572 #if CONFIG_SENSOR_Flip
2573         case V4L2_CID_VFLIP:
2574             {
2575                 if (ctrl->value != sensor->info_priv.flip)
2576                 {
2577                     if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2578                         return -EINVAL;
2579                     sensor->info_priv.flip = ctrl->value;
2580                 }
2581                 break;
2582             }
2583 #endif
2584         default:
2585             break;
2586     }
2587
2588     return 0;
2589 }
2590 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2591 {
2592     const struct v4l2_queryctrl *qctrl;
2593     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2594     struct sensor *sensor = to_sensor(client);
2595
2596     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2597
2598     if (!qctrl)
2599     {
2600         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2601         return -EINVAL;
2602     }
2603
2604     switch (ext_ctrl->id)
2605     {
2606         case V4L2_CID_SCENE:
2607             {
2608                 ext_ctrl->value = sensor->info_priv.scene;
2609                 break;
2610             }
2611         case V4L2_CID_EFFECT:
2612             {
2613                 ext_ctrl->value = sensor->info_priv.effect;
2614                 break;
2615             }
2616         case V4L2_CID_ZOOM_ABSOLUTE:
2617             {
2618                 ext_ctrl->value = sensor->info_priv.digitalzoom;
2619                 break;
2620             }
2621         case V4L2_CID_ZOOM_RELATIVE:
2622             {
2623                 return -EINVAL;
2624             }
2625         case V4L2_CID_FOCUS_ABSOLUTE:
2626             {
2627                 return -EINVAL;
2628             }
2629         case V4L2_CID_FOCUS_RELATIVE:
2630             {
2631                 return -EINVAL;
2632             }
2633         case V4L2_CID_FLASH:
2634             {
2635                 ext_ctrl->value = sensor->info_priv.flash;
2636                 break;
2637             }
2638         default :
2639             break;
2640     }
2641     return 0;
2642 }
2643 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2644 {
2645     const struct v4l2_queryctrl *qctrl;
2646     struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2647     struct sensor *sensor = to_sensor(client);
2648     int val_offset;      
2649
2650     qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2651
2652     if (!qctrl)
2653     {
2654         SENSOR_TR("\n %s ioctrl id = %d  is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2655         return -EINVAL;
2656     }
2657
2658         val_offset = 0;
2659     switch (ext_ctrl->id)
2660     {
2661 #if CONFIG_SENSOR_Scene
2662         case V4L2_CID_SCENE:
2663             {
2664                 if (ext_ctrl->value != sensor->info_priv.scene)
2665                 {
2666                     if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2667                         return -EINVAL;
2668                     sensor->info_priv.scene = ext_ctrl->value;
2669                 }
2670                 break;
2671             }
2672 #endif
2673 #if CONFIG_SENSOR_Effect
2674         case V4L2_CID_EFFECT:
2675             {
2676                 if (ext_ctrl->value != sensor->info_priv.effect)
2677                 {
2678                     if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2679                         return -EINVAL;
2680                     sensor->info_priv.effect= ext_ctrl->value;
2681                 }
2682                 break;
2683             }
2684 #endif
2685 #if CONFIG_SENSOR_DigitalZoom
2686         case V4L2_CID_ZOOM_ABSOLUTE:
2687             {
2688                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2689                     return -EINVAL;
2690
2691                 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2692                 {
2693                     val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2694
2695                     if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2696                         return -EINVAL;
2697                     sensor->info_priv.digitalzoom += val_offset;
2698
2699                     SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(),  sensor->info_priv.digitalzoom);
2700                 }
2701
2702                 break;
2703             }
2704         case V4L2_CID_ZOOM_RELATIVE:
2705             {
2706                 if (ext_ctrl->value)
2707                 {
2708                     if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2709                         return -EINVAL;
2710                     sensor->info_priv.digitalzoom += ext_ctrl->value;
2711
2712                     SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2713                 }
2714                 break;
2715             }
2716 #endif
2717 #if CONFIG_SENSOR_Focus
2718         case V4L2_CID_FOCUS_ABSOLUTE:
2719             {
2720                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2721                     return -EINVAL;
2722
2723                                 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2724                                         if (ext_ctrl->value == qctrl->minimum) {
2725                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2726                                         } else if (ext_ctrl->value == qctrl->maximum) {
2727                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2728                                         } else {
2729                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2730                                         }
2731                                 }
2732
2733                 break;
2734             }
2735         case V4L2_CID_FOCUS_RELATIVE:
2736             {
2737                 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2738                     return -EINVAL;
2739
2740                 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2741                 break;
2742             }
2743                 case V4L2_CID_FOCUS_AUTO:
2744                         {
2745                                 if (ext_ctrl->value == 1) {
2746                                         if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2747                                                 return -EINVAL;
2748                                         sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2749                                 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2750                                         if (ext_ctrl->value == 0)
2751                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2752                                 }
2753                                 break;
2754                         }
2755                 case V4L2_CID_FOCUS_CONTINUOUS:
2756                         {
2757                                 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2758                                         if (ext_ctrl->value == 1) {
2759                                                 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2760                                                         return -EINVAL;
2761                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2762                                         }
2763                                 } else {
2764                                         if (ext_ctrl->value == 0)
2765                                                 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2766                                 }
2767                                 break;
2768                         }
2769 #endif
2770 #if CONFIG_SENSOR_Flash
2771         case V4L2_CID_FLASH:
2772             {
2773                 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2774                     return -EINVAL;
2775                 sensor->info_priv.flash = ext_ctrl->value;
2776
2777                 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2778                 break;
2779             }
2780 #endif
2781         default:
2782             break;
2783     }
2784
2785     return 0;
2786 }
2787
2788 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2789 {
2790     struct i2c_client *client = v4l2_get_subdevdata(sd);
2791     struct soc_camera_device *icd = client->dev.platform_data;
2792     int i, error_cnt=0, error_idx=-1;
2793
2794
2795     for (i=0; i<ext_ctrl->count; i++) {
2796         if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2797             error_cnt++;
2798             error_idx = i;
2799         }
2800     }
2801
2802     if (error_cnt > 1)
2803         error_idx = ext_ctrl->count;
2804
2805     if (error_idx != -1) {
2806         ext_ctrl->error_idx = error_idx;
2807         return -EINVAL;
2808     } else {
2809         return 0;
2810     }
2811 }
2812
2813 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2814 {
2815     struct i2c_client *client = v4l2_get_subdevdata(sd);
2816     struct soc_camera_device *icd = client->dev.platform_data;
2817     int i, error_cnt=0, error_idx=-1;
2818
2819     for (i=0; i<ext_ctrl->count; i++) {
2820         if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2821             error_cnt++;
2822             error_idx = i;
2823         }
2824     }
2825
2826     if (error_cnt > 1)
2827         error_idx = ext_ctrl->count;
2828
2829     if (error_idx != -1) {
2830         ext_ctrl->error_idx = error_idx;
2831         return -EINVAL;
2832     } else {
2833         return 0;
2834     }
2835 }
2836
2837 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2838 {
2839         struct i2c_client *client = v4l2_get_subdevdata(sd);
2840     struct sensor *sensor = to_sensor(client);
2841
2842         if (enable == 1) {
2843                 sensor->info_priv.enable = 1;
2844         } else if (enable == 0) {
2845                 sensor->info_priv.enable = 0;
2846         }
2847
2848         return 0;
2849 }
2850
2851 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2852  * this wasn't our capture interface, so, we wait for the right one */
2853 static int sensor_video_probe(struct soc_camera_device *icd,
2854                                struct i2c_client *client)
2855 {
2856     int ret=0;
2857     struct sensor *sensor = to_sensor(client);
2858 #if (SENSOR_ID_REG != SEQUENCE_END)
2859     u16 pid;
2860 #endif
2861
2862     /* We must have a parent by now. And it cannot be a wrong one.
2863      * So this entire test is completely redundant. */
2864     if (!icd->dev.parent ||
2865             to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2866                 return -ENODEV;
2867
2868         if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2869                 ret = -ENODEV;
2870                 goto sensor_video_probe_err;
2871         }
2872
2873     /* soft reset */
2874 #if (SENSOR_RESET_REG != SEQUENCE_END)
2875     struct reginfo reg_info;
2876         reg_info.reg = SENSOR_RESET_REG;
2877         reg_info.val = SENSOR_RESET_VAL;
2878         reg_info.reg_len = SENSOR_RESET_REG_LEN;
2879     ret = sensor_write(client, &reg_info);
2880     if (ret != 0) {
2881         SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2882         ret = -ENODEV;
2883                 goto sensor_video_probe_err;
2884     }
2885
2886     mdelay(5);  //delay 5 microseconds
2887 #endif
2888
2889         /* check if it is an sensor sensor */
2890 #if (SENSOR_ID_REG != SEQUENCE_END)
2891     ret = sensor_read(client, SENSOR_ID_REG, &pid);
2892     if (ret != 0) {
2893         SENSOR_TR("read chip id failed\n");
2894         ret = -ENODEV;
2895         goto sensor_video_probe_err;
2896     }
2897
2898     SENSOR_DG("\n %s  pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2899 #else
2900         pid = SENSOR_ID;
2901 #endif
2902
2903     if (pid == SENSOR_ID) {
2904         sensor->model = SENSOR_V4L2_IDENT;
2905     } else {
2906         SENSOR_TR("error: %s mismatched   pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2907         ret = -ENODEV;
2908         goto sensor_video_probe_err;
2909     }
2910
2911
2912
2913     return 0;
2914
2915 sensor_video_probe_err:
2916
2917     return ret;
2918 }
2919 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2920 {
2921         struct i2c_client *client = v4l2_get_subdevdata(sd);
2922     struct soc_camera_device *icd = client->dev.platform_data;
2923     struct sensor *sensor = to_sensor(client);
2924     int ret = 0;
2925     
2926         SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2927         switch (cmd)
2928         {
2929                 case RK29_CAM_SUBDEV_DEACTIVATE:
2930                 {
2931                         sensor_deactivate(client);
2932                         break;
2933                 }
2934                 case RK29_CAM_SUBDEV_IOREQUEST:
2935                 {
2936                         sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;           
2937             if (sensor->sensor_io_request != NULL) { 
2938                 if (sensor->sensor_io_request->gpio_res[0].dev_name && 
2939                     (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2940                     sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2941                 } else if (sensor->sensor_io_request->gpio_res[1].dev_name && 
2942                     (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2943                     sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2944                 }
2945             } else {
2946                 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2947                 ret = -EINVAL;
2948                 goto sensor_ioctl_end;
2949             }
2950             /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control 
2951                for this project */
2952             #if CONFIG_SENSOR_Flash     
2953             int i;
2954                 if (sensor->sensor_gpio_res) {
2955                 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2956                     for (i = 0; i < icd->ops->num_controls; i++) {
2957                                 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2958                                         memset(&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));                                      
2959                                 }
2960                     }
2961                     sensor->info_priv.flash = 0xff;
2962                     SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2963                 }
2964                 }
2965             #endif
2966                         break;
2967                 }
2968                 default:
2969                 {
2970                         SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2971                         break;
2972                 }
2973         }
2974 sensor_ioctl_end:
2975         return ret;
2976
2977 }
2978 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2979                             enum v4l2_mbus_pixelcode *code)
2980 {
2981         if (index >= ARRAY_SIZE(sensor_colour_fmts))
2982                 return -EINVAL;
2983
2984         *code = sensor_colour_fmts[index].code;
2985         return 0;
2986 }
2987 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2988         .init           = sensor_init,
2989         .g_ctrl         = sensor_g_control,
2990         .s_ctrl         = sensor_s_control,
2991         .g_ext_ctrls          = sensor_g_ext_controls,
2992         .s_ext_ctrls          = sensor_s_ext_controls,
2993         .g_chip_ident   = sensor_g_chip_ident,
2994         .ioctl = sensor_ioctl,
2995 };
2996
2997 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2998         .s_mbus_fmt     = sensor_s_fmt,
2999         .g_mbus_fmt     = sensor_g_fmt,
3000         .try_mbus_fmt   = sensor_try_fmt,
3001         .enum_mbus_fmt  = sensor_enum_fmt,
3002 };
3003 static struct v4l2_subdev_ops sensor_subdev_ops = {
3004         .core   = &sensor_subdev_core_ops,
3005         .video = &sensor_subdev_video_ops,
3006 };
3007
3008 static int sensor_probe(struct i2c_client *client,
3009                          const struct i2c_device_id *did)
3010 {
3011     struct sensor *sensor;
3012     struct soc_camera_device *icd = client->dev.platform_data;
3013     struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3014     struct soc_camera_link *icl;
3015     int ret;
3016
3017     SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3018     if (!icd) {
3019         dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3020         return -EINVAL;
3021     }
3022
3023     icl = to_soc_camera_link(icd);
3024     if (!icl) {
3025         dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3026         return -EINVAL;
3027     }
3028
3029     if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3030         dev_warn(&adapter->dev,
3031                  "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3032         return -EIO;
3033     }
3034
3035     sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3036     if (!sensor)
3037         return -ENOMEM;
3038
3039     v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3040
3041     /* Second stage probe - when a capture adapter is there */
3042     icd->ops            = &sensor_ops;
3043     sensor->info_priv.fmt = sensor_colour_fmts[0];
3044         #if CONFIG_SENSOR_I2C_NOSCHED
3045         atomic_set(&sensor->tasklock_cnt,0);
3046         #endif
3047
3048     ret = sensor_video_probe(icd, client);
3049     if (ret < 0) {
3050         icd->ops = NULL;
3051         i2c_set_clientdata(client, NULL);
3052         kfree(sensor);
3053                 sensor = NULL;
3054     }
3055     SENSOR_DG("\n%s..%s..%d  ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3056     return ret;
3057 }
3058
3059 static int sensor_remove(struct i2c_client *client)
3060 {
3061     struct sensor *sensor = to_sensor(client);
3062     struct soc_camera_device *icd = client->dev.platform_data;
3063
3064         #if CONFIG_SENSOR_Focus
3065         if (sensor->sensor_wq) {
3066                 destroy_workqueue(sensor->sensor_wq);
3067                 sensor->sensor_wq = NULL;
3068         }
3069         #endif
3070
3071     icd->ops = NULL;
3072     i2c_set_clientdata(client, NULL);
3073     client->driver = NULL;
3074     kfree(sensor);
3075         sensor = NULL;
3076     return 0;
3077 }
3078
3079 static const struct i2c_device_id sensor_id[] = {
3080         {SENSOR_NAME_STRING(), 0 },
3081         { }
3082 };
3083 MODULE_DEVICE_TABLE(i2c, sensor_id);
3084
3085 static struct i2c_driver sensor_i2c_driver = {
3086         .driver = {
3087                 .name = SENSOR_NAME_STRING(),
3088         },
3089         .probe          = sensor_probe,
3090         .remove         = sensor_remove,
3091         .id_table       = sensor_id,
3092 };
3093
3094 static int __init sensor_mod_init(void)
3095 {
3096     SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3097     return i2c_add_driver(&sensor_i2c_driver);
3098 }
3099
3100 static void __exit sensor_mod_exit(void)
3101 {
3102     i2c_del_driver(&sensor_i2c_driver);
3103 }
3104
3105 device_initcall_sync(sensor_mod_init);
3106 module_exit(sensor_mod_exit);
3107
3108 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3109 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3110 MODULE_LICENSE("GPL");
3111
3112