2 * Driver for OV5642 CMOS Image Sensor from OmniVision
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
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.
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 <plat/rk_camera.h>
24 #include <linux/vmalloc.h>
28 module_param(debug, int, S_IRUGO|S_IWUSR);
30 #define dprintk(level, fmt, arg...) do { \
32 printk(KERN_WARNING fmt , ## arg); } while (0)
34 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
35 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
37 #define _CONS(a,b) a##b
38 #define CONS(a,b) _CONS(a,b)
41 #define _STR(x) __STR(x)
42 #define STR(x) _STR(x)
44 #define MIN(x,y) ((x<y) ? x: y)
45 #define MAX(x,y) ((x>y) ? x: y)
47 /* Sensor Driver Configuration */
48 #define SENSOR_NAME RK29_CAM_SENSOR_MT9D113
49 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9D113
50 #define SENSOR_ID 0x2580
51 #define SENSOR_ID_REG 0x00
52 #define SENSOR_RESET_REG SEQUENCE_END
53 #define SENSOR_RESET_VAL 0
54 #define SENSOR_DERESET_VAL 0
55 #define SENSOR_RESET_REG_LEN WORD_LEN
56 #define SENSOR_MIN_WIDTH 800
57 #define SENSOR_MIN_HEIGHT 600
58 #define SENSOR_MAX_WIDTH 1600
59 #define SENSOR_MAX_HEIGHT 1200
60 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
61 #define SENSOR_INIT_HEIGHT sensor_init_height
62 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
63 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
64 #define SENSOR_BUS_PARAM sensor_init_busparam
66 #define CONFIG_SENSOR_WhiteBalance 0
67 #define CONFIG_SENSOR_Brightness 0
68 #define CONFIG_SENSOR_Contrast 0
69 #define CONFIG_SENSOR_Saturation 0
70 #define CONFIG_SENSOR_Effect 0
71 #define CONFIG_SENSOR_Scene 0
72 #define CONFIG_SENSOR_DigitalZoom 0
73 #define CONFIG_SENSOR_Exposure 0
74 #define CONFIG_SENSOR_Flash 0
75 #define CONFIG_SENSOR_Mirror 0
76 #define CONFIG_SENSOR_Flip 0
77 #define CONFIG_SENSOR_Focus 0
79 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
80 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
81 #define CONFIG_SENSOR_I2C_NOSCHED 0
82 #define CONFIG_SENSOR_I2C_RDWRCHK 1
84 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
85 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
86 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
87 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
88 #define COLOR_TEMPERATURE_OFFICE_DN 3500
89 #define COLOR_TEMPERATURE_OFFICE_UP 5000
90 #define COLOR_TEMPERATURE_HOME_DN 2500
91 #define COLOR_TEMPERATURE_HOME_UP 3500
93 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
94 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
96 #define SENSOR_AF_IS_ERR (0x00<<0)
97 #define SENSOR_AF_IS_OK (0x01<<0)
99 #if CONFIG_SENSOR_Focus
100 #define SENSOR_AF_MODE_INFINITY 0
101 #define SENSOR_AF_MODE_MACRO 1
102 #define SENSOR_AF_MODE_FIXED 2
103 #define SENSOR_AF_MODE_AUTO 3
104 #define SENSOR_AF_MODE_CONTINUOUS 4
105 #define SENSOR_AF_MODE_CLOSE 5
108 /* init 800x600 SVGA */
109 static struct reginfo sensor_init_data[] =
113 //for 24MHz input, VCO=MAX PCLK=76.8MHz
114 { 0x0014, 0x21F9, WORD_LEN, 0}, //PLL Control: BYPASS PLL = 8697
115 { 0x0010, 0x0110, WORD_LEN, 0}, //PLL Dividers = 272
116 { 0x0012, 0x1FF7, WORD_LEN, 0}, //PLL P Dividers = 8183
117 { 0x0014, 0x21FB, WORD_LEN, 0}, //PLL Control: PLL_ENABLE on = 8699
118 { 0x0014, 0x20FB, WORD_LEN, 0}, //PLL Control: SEL_LOCK_DET on = 8443
120 { SEQUENCE_WAIT_US, 1, WORD_LEN, 0}, // Allow PLL to lock
122 { 0x0014, 0x20FA, WORD_LEN, 0}, //PLL Control: PLL_BYPASS off = 8442
123 { 0x0018, 0x402D, WORD_LEN, 0},
126 { 0x0018, 0x402C, WORD_LEN, 0},
128 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
130 { 0x321C, 0x0003, WORD_LEN, 0}, //By Pass TxFIFO = 3
131 { 0x098C, 0x2703, WORD_LEN, 0}, //Output Width (A)
132 { 0x0990, 0x0320, WORD_LEN, 0}, // = 800
133 { 0x98C, 0x2705, WORD_LEN, 0}, //Output Height (A)
134 { 0x990, 0x0258 , WORD_LEN, 0}, // = 600
135 { 0x98C, 0x2707, WORD_LEN, 0}, //Output Width (B)
136 { 0x990, 0x0640 , WORD_LEN, 0}, // = 1600
137 { 0x98C, 0x2709 , WORD_LEN, 0}, //Output Height (B)
138 { 0x990, 0x04B0 , WORD_LEN, 0}, // = 1200
139 { 0x98C, 0x270D , WORD_LEN, 0}, //Row Start (A)
140 { 0x990, 0x000 , WORD_LEN, 0}, // = 0
141 { 0x98C, 0x270F , WORD_LEN, 0}, //Column Start (A)
142 { 0x990, 0x000 , WORD_LEN, 0}, // = 0
143 { 0x98C, 0x2711 , WORD_LEN, 0}, //Row End (A)
144 { 0x990, 0x4BD , WORD_LEN, 0}, // = 1213
145 { 0x98C, 0x2713 , WORD_LEN, 0}, //Column End (A)
146 { 0x990, 0x64D , WORD_LEN, 0}, // = 1613
147 { 0x98C, 0x2715 , WORD_LEN, 0}, //Row Speed (A)
148 { 0x990, 0x0111 , WORD_LEN, 0}, // = 273
149 { 0x98C, 0x2717 , WORD_LEN, 0}, //Read Mode (A)
151 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
152 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
153 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
154 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
156 { 0x98C, 0x2719 , WORD_LEN, 0}, //sensor_fine_correction (A)
157 { 0x990, 0x005A , WORD_LEN, 0}, // = 90
158 { 0x98C, 0x271B , WORD_LEN, 0}, //sensor_fine_IT_min (A)
159 { 0x990, 0x01BE , WORD_LEN, 0}, // = 446
160 { 0x98C, 0x271D , WORD_LEN, 0}, //sensor_fine_IT_max_margin (A)
161 { 0x990, 0x0131 , WORD_LEN, 0}, // = 305
162 { 0x98C, 0x271F , WORD_LEN, 0}, //Frame Lines (A)
163 { 0x990, 0x02B3 , WORD_LEN, 0}, // = 691
164 { 0x98C, 0x2721 , WORD_LEN, 0}, //Line Length (A)
165 { 0x990, 0x056D , WORD_LEN, 0}, // = 1389
166 { 0x98C, 0x2723 , WORD_LEN, 0}, //Row Start (B)
167 { 0x990, 0x004 , WORD_LEN, 0}, // = 4
168 { 0x98C, 0x2725 , WORD_LEN, 0}, //Column Start (B)
169 { 0x990, 0x004 , WORD_LEN, 0}, // = 4
170 { 0x98C, 0x2727 , WORD_LEN, 0}, //Row End (B)
171 { 0x990, 0x4BB , WORD_LEN, 0}, // = 1211
172 { 0x98C, 0x2729 , WORD_LEN, 0}, //Column End (B)
173 { 0x990, 0x64B , WORD_LEN, 0}, // = 1611
174 { 0x98C, 0x272B , WORD_LEN, 0}, //Row Speed (B)
175 { 0x990, 0x0111 , WORD_LEN, 0}, // = 273
176 { 0x98C, 0x272D , WORD_LEN, 0}, //Read Mode (B)
177 { 0x990, 0x0024 , WORD_LEN, 0}, // = 36
178 { 0x98C, 0x272F , WORD_LEN, 0}, //sensor_fine_correction (B)
179 { 0x990, 0x003A , WORD_LEN, 0}, // = 58
180 { 0x98C, 0x2731 , WORD_LEN, 0}, //sensor_fine_IT_min (B)
181 { 0x990, 0x00F6 , WORD_LEN, 0}, // = 246
182 { 0x98C, 0x2733 , WORD_LEN, 0}, //sensor_fine_IT_max_margin (B)
183 { 0x990, 0x008B , WORD_LEN, 0}, // = 139
184 { 0x98C, 0x2735 , WORD_LEN, 0}, //Frame Lines (B)
185 { 0x990, 0x050D , WORD_LEN, 0}, // = 1293
186 { 0x98C, 0x2737 , WORD_LEN, 0}, //Line Length (B)
187 { 0x990, 0x0894 , WORD_LEN, 0}, // = 2196
188 { 0x98C, 0x2739 , WORD_LEN, 0}, //Crop_X0 (A)
189 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
190 { 0x98C, 0x273B , WORD_LEN, 0}, //Crop_X1 (A)
191 { 0x990, 0x031F , WORD_LEN, 0}, // = 799
192 { 0x98C, 0x273D , WORD_LEN, 0}, //Crop_Y0 (A)
193 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
194 { 0x98C, 0x273F , WORD_LEN, 0}, //Crop_Y1 (A)
195 { 0x990, 0x0257 , WORD_LEN, 0}, // = 599
196 { 0x98C, 0x2747 , WORD_LEN, 0}, //Crop_X0 (B)
197 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
198 { 0x98C, 0x2749 , WORD_LEN, 0}, //Crop_X1 (B)
199 { 0x990, 0x063F , WORD_LEN, 0}, // = 1599
200 { 0x98C, 0x274B , WORD_LEN, 0}, //Crop_Y0 (B)
201 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
202 { 0x98C, 0x274D , WORD_LEN, 0}, //Crop_Y1 (B)
203 { 0x990, 0x04AF , WORD_LEN, 0}, // = 1199
204 { 0x98C, 0x222D , WORD_LEN, 0}, //R9 Step
205 { 0x990, 0x0090 , WORD_LEN, 0}, // = 144
206 { 0x98C, 0xA408 , WORD_LEN, 0}, //search_f1_50
207 { 0x990, 0x23 , WORD_LEN, 0}, // = 35
208 { 0x98C, 0xA409 , WORD_LEN, 0}, //search_f2_50
209 { 0x990, 0x25 , WORD_LEN, 0}, // = 37
210 { 0x98C, 0xA40A , WORD_LEN, 0}, //search_f1_60
211 { 0x990, 0x2A , WORD_LEN, 0}, // = 42
212 { 0x98C, 0xA40B , WORD_LEN, 0}, //search_f2_60
213 { 0x990, 0x2C , WORD_LEN, 0}, // = 44
214 { 0x98C, 0x2411 , WORD_LEN, 0}, //R9_Step_60 (A)
215 { 0x990, 0x0090 , WORD_LEN, 0}, // = 144
216 { 0x98C, 0x2413 , WORD_LEN, 0}, //R9_Step_50 (A)
217 { 0x990, 0x00AD , WORD_LEN, 0}, // = 173
218 { 0x98C, 0x2415 , WORD_LEN, 0}, //R9_Step_60 (B)
219 { 0x990, 0x005B , WORD_LEN, 0}, // = 91
220 { 0x98C, 0x2417 , WORD_LEN, 0}, //R9_Step_50 (B)
221 { 0x990, 0x006D , WORD_LEN, 0}, // = 109
222 { 0x98C, 0xA404 , WORD_LEN, 0}, //FD Mode
223 { 0x990, 0x10 , WORD_LEN, 0}, // = 16
224 { 0x98C, 0xA40D , WORD_LEN, 0}, //Stat_min
225 { 0x990, 0x02 , WORD_LEN, 0}, // = 2
226 { 0x98C, 0xA40E , WORD_LEN, 0}, //Stat_max
227 { 0x990, 0x03 , WORD_LEN, 0}, // = 3
228 { 0x98C, 0xA410 , WORD_LEN, 0}, //Min_amplitude
229 { 0x990, 0x0A , WORD_LEN, 0}, // = 10
230 { 0x98C, 0xA103 , WORD_LEN, 0}, //Refresh Sequencer Mode
231 { 0x990, 0x06 , WORD_LEN, 0}, // = 6
232 //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100 // wait for command to be processed
234 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
236 { 0x98C, 0xA103 , WORD_LEN, 0}, //Refresh Sequencer
237 { 0x990, 0x05 , WORD_LEN, 0}, // = 5
239 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
241 //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100 // wait for command to be processed
245 //for 24MHz input, VCO=MAX PCLK=76.8MHz
246 { 0x001A, 0x0051, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
247 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
248 { 0x0014, 0x2545, WORD_LEN, 0}, // PLL_CONTROL
249 { 0x0010, 0x011C, WORD_LEN, 0}, // PLL_DIVIDERS
250 { 0x0012, 0x1FF7, WORD_LEN, 0}, // PLL_P_DIVIDERS
251 { 0x0014, 0x2547, WORD_LEN, 0}, // PLL_CONTROL
252 { 0x0014, 0x2447, WORD_LEN, 0}, // PLL_CONTROL
253 { 0x0014, 0x2047, WORD_LEN, 0}, // PLL_CONTROL
254 { 0x0014, 0x2046, WORD_LEN, 0}, // PLL_CONTROL
255 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
256 { 0x0018, 0x4028 , WORD_LEN, 0}, // STANDBY_CONTROL
257 { 0x321C, 0x0003 , WORD_LEN, 0}, // OFIFO_CONTROL_STATUS
258 { 0x098C, 0x2703 , WORD_LEN, 0}, // MCU_ADDRESS
259 { 0x0990, 0x0320 , WORD_LEN, 0}, // MCU_DATA_0
260 { 0x098C, 0x2705 , WORD_LEN, 0}, // MCU_ADDRESS
261 { 0x0990, 0x0258 , WORD_LEN, 0}, // MCU_DATA_0
262 { 0x098C, 0x2707 , WORD_LEN, 0}, // MCU_ADDRESS
263 { 0x0990, 0x0640 , WORD_LEN, 0}, // MCU_DATA_0
264 { 0x098C, 0x2709 , WORD_LEN, 0}, // MCU_ADDRESS
265 { 0x0990, 0x04B0 , WORD_LEN, 0}, // MCU_DATA_0
266 { 0x098C, 0x270D , WORD_LEN, 0}, // MCU_ADDRESS
267 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
268 { 0x098C, 0x270F , WORD_LEN, 0}, // MCU_ADDRESS
269 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
270 { 0x098C, 0x2711 , WORD_LEN, 0}, // MCU_ADDRESS
271 { 0x0990, 0x04BD , WORD_LEN, 0}, // MCU_DATA_0
272 { 0x098C, 0x2713 , WORD_LEN, 0}, // MCU_ADDRESS
273 { 0x0990, 0x064D , WORD_LEN, 0}, // MCU_DATA_0
274 { 0x098C, 0x2715 , WORD_LEN, 0}, // MCU_ADDRESS
275 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
276 { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
278 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
279 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
280 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
281 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
283 { 0x098C, 0x2719 , WORD_LEN, 0}, // MCU_ADDRESS
284 { 0x0990, 0x005A , WORD_LEN, 0}, // MCU_DATA_0
285 { 0x098C, 0x271B , WORD_LEN, 0}, // MCU_ADDRESS
286 { 0x0990, 0x01BE , WORD_LEN, 0}, // MCU_DATA_0
287 { 0x098C, 0x271D , WORD_LEN, 0}, // MCU_ADDRESS
288 { 0x0990, 0x0131 , WORD_LEN, 0}, // MCU_DATA_0
289 { 0x098C, 0x271F , WORD_LEN, 0}, // MCU_ADDRESS
290 { 0x0990, 0x02B3 , WORD_LEN, 0}, // MCU_DATA_0
291 { 0x098C, 0x2721 , WORD_LEN, 0}, // MCU_ADDRESS
292 { 0x0990, 0x09B0 , WORD_LEN, 0}, // MCU_DATA_0
293 { 0x098C, 0x2723 , WORD_LEN, 0}, // MCU_ADDRESS
294 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
295 { 0x098C, 0x2725 , WORD_LEN, 0}, // MCU_ADDRESS
296 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
297 { 0x098C, 0x2727 , WORD_LEN, 0}, // MCU_ADDRESS
298 { 0x0990, 0x04BB , WORD_LEN, 0}, // MCU_DATA_0
299 { 0x098C, 0x2729 , WORD_LEN, 0}, // MCU_ADDRESS
300 { 0x0990, 0x064B , WORD_LEN, 0}, // MCU_DATA_0
301 { 0x098C, 0x272B , WORD_LEN, 0}, // MCU_ADDRESS
302 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
303 { 0x098C, 0x272D , WORD_LEN, 0}, // MCU_ADDRESS
304 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
305 { 0x098C, 0x272F , WORD_LEN, 0}, // MCU_ADDRESS
306 { 0x0990, 0x003A , WORD_LEN, 0}, // MCU_DATA_0
307 { 0x098C, 0x2731 , WORD_LEN, 0}, // MCU_ADDRESS
308 { 0x0990, 0x00F6 , WORD_LEN, 0}, // MCU_DATA_0
309 { 0x098C, 0x2733 , WORD_LEN, 0}, // MCU_ADDRESS
310 { 0x0990, 0x008B , WORD_LEN, 0}, // MCU_DATA_0
311 { 0x098C, 0x2735 , WORD_LEN, 0}, // MCU_ADDRESS
312 { 0x0990, 0x050D , WORD_LEN, 0}, // MCU_DATA_0
313 { 0x098C, 0x2737 , WORD_LEN, 0}, // MCU_ADDRESS
314 { 0x0990, 0x0807 , WORD_LEN, 0}, // MCU_DATA_0
315 { 0x098C, 0x2739 , WORD_LEN, 0}, // MCU_ADDRESS
316 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
317 { 0x098C, 0x273B , WORD_LEN, 0}, // MCU_ADDRESS
318 { 0x0990, 0x031F , WORD_LEN, 0}, // MCU_DATA_0
319 { 0x098C, 0x273D , WORD_LEN, 0}, // MCU_ADDRESS
320 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
321 { 0x098C, 0x273F , WORD_LEN, 0}, // MCU_ADDRESS
322 { 0x0990, 0x0257 , WORD_LEN, 0}, // MCU_DATA_0
323 { 0x098C, 0x2747 , WORD_LEN, 0}, // MCU_ADDRESS
324 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
325 { 0x098C, 0x2749 , WORD_LEN, 0}, // MCU_ADDRESS
326 { 0x0990, 0x063F , WORD_LEN, 0}, // MCU_DATA_0
327 { 0x098C, 0x274B , WORD_LEN, 0}, // MCU_ADDRESS
328 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
329 { 0x098C, 0x274D , WORD_LEN, 0}, // MCU_ADDRESS
330 { 0x0990, 0x04AF , WORD_LEN, 0}, // MCU_DATA_0
331 { 0x098C, 0x222D , WORD_LEN, 0}, // MCU_ADDRESS
332 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
333 { 0x098C, 0xA408 , WORD_LEN, 0}, // MCU_ADDRESS
334 { 0x0990, 0x0022 , WORD_LEN, 0}, // MCU_DATA_0
335 { 0x098C, 0xA409 , WORD_LEN, 0}, // MCU_ADDRESS
336 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
337 { 0x098C, 0xA40A , WORD_LEN, 0}, // MCU_ADDRESS
338 { 0x0990, 0x0029 , WORD_LEN, 0}, // MCU_DATA_0
339 { 0x098C, 0xA40B , WORD_LEN, 0}, // MCU_ADDRESS
340 { 0x0990, 0x002B , WORD_LEN, 0}, // MCU_DATA_0
341 { 0x098C, 0x2411 , WORD_LEN, 0}, // MCU_ADDRESS
342 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
343 { 0x098C, 0x2413 , WORD_LEN, 0}, // MCU_ADDRESS
344 { 0x0990, 0x00A9 , WORD_LEN, 0}, // MCU_DATA_0
345 { 0x098C, 0x2415 , WORD_LEN, 0}, // MCU_ADDRESS
346 { 0x0990, 0x00AA , WORD_LEN, 0}, // MCU_DATA_0
347 { 0x098C, 0x2417 , WORD_LEN, 0}, // MCU_ADDRESS
348 { 0x0990, 0x00CC , WORD_LEN, 0}, // MCU_DATA_0
349 { 0x098C, 0xA404 , WORD_LEN, 0}, // MCU_ADDRESS
350 { 0x0990, 0x0010 , WORD_LEN, 0}, // MCU_DATA_0
351 { 0x098C, 0xA40D , WORD_LEN, 0}, // MCU_ADDRESS
352 { 0x0990, 0x0002 , WORD_LEN, 0}, // MCU_DATA_0
353 { 0x098C, 0xA40E , WORD_LEN, 0}, // MCU_ADDRESS
354 { 0x0990, 0x0003 , WORD_LEN, 0}, // MCU_DATA_0
355 { 0x098C, 0xA410 , WORD_LEN, 0}, // MCU_ADDRESS
356 { 0x0990, 0x000A , WORD_LEN, 0}, // MCU_DATA_0
357 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
358 { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
359 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
360 { 0x0990, 0x0005 , WORD_LEN, 0}, // MCU_DATA_0
365 /* 720p 15fps @ 1280x720 */
367 static struct reginfo sensor_720p[]=
372 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
374 static struct reginfo sensor_1080p[]=
379 /* 2592X1944 QSXGA */
380 static struct reginfo sensor_qsxga[] =
385 static struct reginfo sensor_qxga[] =
391 static struct reginfo sensor_uxga[] =
394 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
395 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
396 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
397 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
401 static struct reginfo sensor_sxga[] =
404 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
405 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
406 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
407 { 0x0990, 0x0001, WORD_LEN, 0}, // MCU_DATA_0
410 // { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
411 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
412 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
413 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
415 { 0x098C, 0x2747, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_X0_B]
416 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
417 { 0x098C, 0x2749, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_X1_B]
418 { 0x0990, 0x063F, WORD_LEN, 0}, // MCU_DATA_0
419 { 0x098C, 0x274B, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_Y0_B]
420 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
421 { 0x098C, 0x274D, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_Y1_B]
422 { 0x0990, 0x04AF, WORD_LEN, 0}, // MCU_DATA_0
423 { 0x098C, 0x2707, WORD_LEN, 0}, // MCU_ADDRESS [MODE_OUTPUT_WIDTH_B]
424 { 0x0990, 0x0500, WORD_LEN, 0}, // MCU_DATA_0
425 { 0x098C, 0x2709, WORD_LEN, 0}, // MCU_ADDRESS [MODE_OUTPUT_HEIGHT_B]
426 { 0x0990, 0x0400, WORD_LEN, 0}, // MCU_DATA_0
428 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
429 { 0x0990, 0x0005, WORD_LEN, 0}, // MCU_DATA_0
431 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
432 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
433 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
434 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
440 static struct reginfo sensor_xga[] =
446 static struct reginfo sensor_svga[] =
449 //for 24MHz input, VCO=MAX PCLK=76.8MHz
450 { 0x001A, 0x0051, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
451 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
452 { 0x0014, 0x2545, WORD_LEN, 0}, // PLL_CONTROL
453 { 0x0010, 0x011C, WORD_LEN, 0}, // PLL_DIVIDERS
454 { 0x0012, 0x1FF7, WORD_LEN, 0}, // PLL_P_DIVIDERS
455 { 0x0014, 0x2547, WORD_LEN, 0}, // PLL_CONTROL
456 { 0x0014, 0x2447, WORD_LEN, 0}, // PLL_CONTROL
457 { 0x0014, 0x2047, WORD_LEN, 0}, // PLL_CONTROL
458 { 0x0014, 0x2046, WORD_LEN, 0}, // PLL_CONTROL
459 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
460 { 0x0018, 0x4028 , WORD_LEN, 0}, // STANDBY_CONTROL
461 { 0x321C, 0x0003 , WORD_LEN, 0}, // OFIFO_CONTROL_STATUS
462 { 0x098C, 0x2703 , WORD_LEN, 0}, // MCU_ADDRESS
463 { 0x0990, 0x0320 , WORD_LEN, 0}, // MCU_DATA_0
464 { 0x098C, 0x2705 , WORD_LEN, 0}, // MCU_ADDRESS
465 { 0x0990, 0x0258 , WORD_LEN, 0}, // MCU_DATA_0
466 { 0x098C, 0x2707 , WORD_LEN, 0}, // MCU_ADDRESS
467 { 0x0990, 0x0640 , WORD_LEN, 0}, // MCU_DATA_0
468 { 0x098C, 0x2709 , WORD_LEN, 0}, // MCU_ADDRESS
469 { 0x0990, 0x04B0 , WORD_LEN, 0}, // MCU_DATA_0
470 { 0x098C, 0x270D , WORD_LEN, 0}, // MCU_ADDRESS
471 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
472 { 0x098C, 0x270F , WORD_LEN, 0}, // MCU_ADDRESS
473 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
474 { 0x098C, 0x2711 , WORD_LEN, 0}, // MCU_ADDRESS
475 { 0x0990, 0x04BD , WORD_LEN, 0}, // MCU_DATA_0
476 { 0x098C, 0x2713 , WORD_LEN, 0}, // MCU_ADDRESS
477 { 0x0990, 0x064D , WORD_LEN, 0}, // MCU_DATA_0
478 { 0x098C, 0x2715 , WORD_LEN, 0}, // MCU_ADDRESS
479 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
480 { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
482 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
483 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
484 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
485 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
488 { 0x098C, 0x2719 , WORD_LEN, 0}, // MCU_ADDRESS
489 { 0x0990, 0x005A , WORD_LEN, 0}, // MCU_DATA_0
490 { 0x098C, 0x271B , WORD_LEN, 0}, // MCU_ADDRESS
491 { 0x0990, 0x01BE , WORD_LEN, 0}, // MCU_DATA_0
492 { 0x098C, 0x271D , WORD_LEN, 0}, // MCU_ADDRESS
493 { 0x0990, 0x0131 , WORD_LEN, 0}, // MCU_DATA_0
494 { 0x098C, 0x271F , WORD_LEN, 0}, // MCU_ADDRESS
495 { 0x0990, 0x02B3 , WORD_LEN, 0}, // MCU_DATA_0
496 { 0x098C, 0x2721 , WORD_LEN, 0}, // MCU_ADDRESS
497 { 0x0990, 0x09B0 , WORD_LEN, 0}, // MCU_DATA_0
498 { 0x098C, 0x2723 , WORD_LEN, 0}, // MCU_ADDRESS
499 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
500 { 0x098C, 0x2725 , WORD_LEN, 0}, // MCU_ADDRESS
501 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
502 { 0x098C, 0x2727 , WORD_LEN, 0}, // MCU_ADDRESS
503 { 0x0990, 0x04BB , WORD_LEN, 0}, // MCU_DATA_0
504 { 0x098C, 0x2729 , WORD_LEN, 0}, // MCU_ADDRESS
505 { 0x0990, 0x064B , WORD_LEN, 0}, // MCU_DATA_0
506 { 0x098C, 0x272B , WORD_LEN, 0}, // MCU_ADDRESS
507 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
508 { 0x098C, 0x272D , WORD_LEN, 0}, // MCU_ADDRESS
509 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
510 { 0x098C, 0x272F , WORD_LEN, 0}, // MCU_ADDRESS
511 { 0x0990, 0x003A , WORD_LEN, 0}, // MCU_DATA_0
512 { 0x098C, 0x2731 , WORD_LEN, 0}, // MCU_ADDRESS
513 { 0x0990, 0x00F6 , WORD_LEN, 0}, // MCU_DATA_0
514 { 0x098C, 0x2733 , WORD_LEN, 0}, // MCU_ADDRESS
515 { 0x0990, 0x008B , WORD_LEN, 0}, // MCU_DATA_0
516 { 0x098C, 0x2735 , WORD_LEN, 0}, // MCU_ADDRESS
517 { 0x0990, 0x050D , WORD_LEN, 0}, // MCU_DATA_0
518 { 0x098C, 0x2737 , WORD_LEN, 0}, // MCU_ADDRESS
519 { 0x0990, 0x0807 , WORD_LEN, 0}, // MCU_DATA_0
520 { 0x098C, 0x2739 , WORD_LEN, 0}, // MCU_ADDRESS
521 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
522 { 0x098C, 0x273B , WORD_LEN, 0}, // MCU_ADDRESS
523 { 0x0990, 0x031F , WORD_LEN, 0}, // MCU_DATA_0
524 { 0x098C, 0x273D , WORD_LEN, 0}, // MCU_ADDRESS
525 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
526 { 0x098C, 0x273F , WORD_LEN, 0}, // MCU_ADDRESS
527 { 0x0990, 0x0257 , WORD_LEN, 0}, // MCU_DATA_0
528 { 0x098C, 0x2747 , WORD_LEN, 0}, // MCU_ADDRESS
529 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
530 { 0x098C, 0x2749 , WORD_LEN, 0}, // MCU_ADDRESS
531 { 0x0990, 0x063F , WORD_LEN, 0}, // MCU_DATA_0
532 { 0x098C, 0x274B , WORD_LEN, 0}, // MCU_ADDRESS
533 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
534 { 0x098C, 0x274D , WORD_LEN, 0}, // MCU_ADDRESS
535 { 0x0990, 0x04AF , WORD_LEN, 0}, // MCU_DATA_0
536 { 0x098C, 0x222D , WORD_LEN, 0}, // MCU_ADDRESS
537 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
538 { 0x098C, 0xA408 , WORD_LEN, 0}, // MCU_ADDRESS
539 { 0x0990, 0x0022 , WORD_LEN, 0}, // MCU_DATA_0
540 { 0x098C, 0xA409 , WORD_LEN, 0}, // MCU_ADDRESS
541 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
542 { 0x098C, 0xA40A , WORD_LEN, 0}, // MCU_ADDRESS
543 { 0x0990, 0x0029 , WORD_LEN, 0}, // MCU_DATA_0
544 { 0x098C, 0xA40B , WORD_LEN, 0}, // MCU_ADDRESS
545 { 0x0990, 0x002B , WORD_LEN, 0}, // MCU_DATA_0
546 { 0x098C, 0x2411 , WORD_LEN, 0}, // MCU_ADDRESS
547 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
548 { 0x098C, 0x2413 , WORD_LEN, 0}, // MCU_ADDRESS
549 { 0x0990, 0x00A9 , WORD_LEN, 0}, // MCU_DATA_0
550 { 0x098C, 0x2415 , WORD_LEN, 0}, // MCU_ADDRESS
551 { 0x0990, 0x00AA , WORD_LEN, 0}, // MCU_DATA_0
552 { 0x098C, 0x2417 , WORD_LEN, 0}, // MCU_ADDRESS
553 { 0x0990, 0x00CC , WORD_LEN, 0}, // MCU_DATA_0
554 { 0x098C, 0xA404 , WORD_LEN, 0}, // MCU_ADDRESS
555 { 0x0990, 0x0010 , WORD_LEN, 0}, // MCU_DATA_0
556 { 0x098C, 0xA40D , WORD_LEN, 0}, // MCU_ADDRESS
557 { 0x0990, 0x0002 , WORD_LEN, 0}, // MCU_DATA_0
558 { 0x098C, 0xA40E , WORD_LEN, 0}, // MCU_ADDRESS
559 { 0x0990, 0x0003 , WORD_LEN, 0}, // MCU_DATA_0
560 { 0x098C, 0xA410 , WORD_LEN, 0}, // MCU_ADDRESS
561 { 0x0990, 0x000A , WORD_LEN, 0}, // MCU_DATA_0
562 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
563 { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
564 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
565 { 0x0990, 0x0005 , WORD_LEN, 0}, // MCU_DATA_0
570 static struct reginfo sensor_vga[] =
576 static struct reginfo sensor_cif[] =
582 static struct reginfo sensor_qvga[] =
588 static struct reginfo sensor_qcif[] =
593 static struct reginfo sensor_Preview2Capture[]=
596 {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
597 {0x843C, 0xFF, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
598 {0x8404, 0x02, BYTE_LEN, 0 }, // SEQ_CMD
602 static struct reginfo sensor_Capture2Preview[]=
605 {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
606 {0x843C, 0x01, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
607 {0x8404, 0x01, BYTE_LEN, 0 }, // SEQ_CMD
608 {0x0016, 0x0047, WORD_LEN, 0}, // CLOCKS_CONTRO
612 static struct reginfo sensor_ClrFmt_YUYV[]=
617 static struct reginfo sensor_ClrFmt_UYVY[]=
623 #if CONFIG_SENSOR_WhiteBalance
624 static struct reginfo sensor_WhiteB_Auto[]=
629 /* Cloudy Colour Temperature : 6500K - 8000K */
630 static struct reginfo sensor_WhiteB_Cloudy[]=
635 /* ClearDay Colour Temperature : 5000K - 6500K */
636 static struct reginfo sensor_WhiteB_ClearDay[]=
641 /* Office Colour Temperature : 3500K - 5000K */
642 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
647 /* Home Colour Temperature : 2500K - 3500K */
648 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
653 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
654 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
658 #if CONFIG_SENSOR_Brightness
659 static struct reginfo sensor_Brightness0[]=
664 static struct reginfo sensor_Brightness1[]=
669 static struct reginfo sensor_Brightness2[]=
674 static struct reginfo sensor_Brightness3[]=
679 static struct reginfo sensor_Brightness4[]=
684 static struct reginfo sensor_Brightness5[]=
688 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
689 sensor_Brightness4, sensor_Brightness5,NULL,
694 #if CONFIG_SENSOR_Effect
695 static struct reginfo sensor_Effect_Normal[] =
700 static struct reginfo sensor_Effect_WandB[] =
705 static struct reginfo sensor_Effect_Sepia[] =
710 static struct reginfo sensor_Effect_Negative[] =
714 static struct reginfo sensor_Effect_Bluish[] =
719 static struct reginfo sensor_Effect_Green[] =
724 static struct reginfo sensor_Effect_Solarize[] =
728 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_Negative,sensor_Effect_Sepia,
729 sensor_Effect_Solarize,NULL,
732 #if CONFIG_SENSOR_Exposure
733 static struct reginfo sensor_Exposure0[]=
738 static struct reginfo sensor_Exposure1[]=
743 static struct reginfo sensor_Exposure2[]=
748 static struct reginfo sensor_Exposure3[]=
753 static struct reginfo sensor_Exposure4[]=
758 static struct reginfo sensor_Exposure5[]=
763 static struct reginfo sensor_Exposure6[]=
768 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
769 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
772 #if CONFIG_SENSOR_Saturation
773 static struct reginfo sensor_Saturation0[]=
778 static struct reginfo sensor_Saturation1[]=
783 static struct reginfo sensor_Saturation2[]=
787 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
789 #if CONFIG_SENSOR_Contrast
790 static struct reginfo sensor_Contrast0[]=
795 static struct reginfo sensor_Contrast1[]=
800 static struct reginfo sensor_Contrast2[]=
805 static struct reginfo sensor_Contrast3[]=
810 static struct reginfo sensor_Contrast4[]=
816 static struct reginfo sensor_Contrast5[]=
821 static struct reginfo sensor_Contrast6[]=
825 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
826 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
830 #if CONFIG_SENSOR_Mirror
831 static struct reginfo sensor_MirrorOn[]=
836 static struct reginfo sensor_MirrorOff[]=
840 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
842 #if CONFIG_SENSOR_Flip
843 static struct reginfo sensor_FlipOn[]=
848 static struct reginfo sensor_FlipOff[]=
852 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
855 #if CONFIG_SENSOR_Scene
856 static struct reginfo sensor_SceneAuto[] =
861 static struct reginfo sensor_SceneNight[] =
865 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
868 #if CONFIG_SENSOR_DigitalZoom
869 static struct reginfo sensor_Zoom0[] =
874 static struct reginfo sensor_Zoom1[] =
879 static struct reginfo sensor_Zoom2[] =
885 static struct reginfo sensor_Zoom3[] =
889 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
891 static const struct v4l2_querymenu sensor_menus[] =
893 #if CONFIG_SENSOR_WhiteBalance
894 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
895 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
896 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
899 #if CONFIG_SENSOR_Effect
900 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "negative", .reserved = 0,},
901 { .id = V4L2_CID_EFFECT, .index = 2, .name = "sepia", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "solarize", .reserved = 0,},
904 #if CONFIG_SENSOR_Scene
905 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
908 #if CONFIG_SENSOR_Flash
909 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
910 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
914 static const struct v4l2_queryctrl sensor_controls[] =
916 #if CONFIG_SENSOR_WhiteBalance
918 .id = V4L2_CID_DO_WHITE_BALANCE,
919 .type = V4L2_CTRL_TYPE_MENU,
920 .name = "White Balance Control",
928 #if CONFIG_SENSOR_Brightness
930 .id = V4L2_CID_BRIGHTNESS,
931 .type = V4L2_CTRL_TYPE_INTEGER,
932 .name = "Brightness Control",
940 #if CONFIG_SENSOR_Effect
942 .id = V4L2_CID_EFFECT,
943 .type = V4L2_CTRL_TYPE_MENU,
944 .name = "Effect Control",
952 #if CONFIG_SENSOR_Exposure
954 .id = V4L2_CID_EXPOSURE,
955 .type = V4L2_CTRL_TYPE_INTEGER,
956 .name = "Exposure Control",
964 #if CONFIG_SENSOR_Saturation
966 .id = V4L2_CID_SATURATION,
967 .type = V4L2_CTRL_TYPE_INTEGER,
968 .name = "Saturation Control",
976 #if CONFIG_SENSOR_Contrast
978 .id = V4L2_CID_CONTRAST,
979 .type = V4L2_CTRL_TYPE_INTEGER,
980 .name = "Contrast Control",
988 #if CONFIG_SENSOR_Mirror
990 .id = V4L2_CID_HFLIP,
991 .type = V4L2_CTRL_TYPE_BOOLEAN,
992 .name = "Mirror Control",
1000 #if CONFIG_SENSOR_Flip
1002 .id = V4L2_CID_VFLIP,
1003 .type = V4L2_CTRL_TYPE_BOOLEAN,
1004 .name = "Flip Control",
1012 #if CONFIG_SENSOR_Scene
1014 .id = V4L2_CID_SCENE,
1015 .type = V4L2_CTRL_TYPE_MENU,
1016 .name = "Scene Control",
1024 #if CONFIG_SENSOR_DigitalZoom
1026 .id = V4L2_CID_ZOOM_RELATIVE,
1027 .type = V4L2_CTRL_TYPE_INTEGER,
1028 .name = "DigitalZoom Control",
1034 .id = V4L2_CID_ZOOM_ABSOLUTE,
1035 .type = V4L2_CTRL_TYPE_INTEGER,
1036 .name = "DigitalZoom Control",
1044 #if CONFIG_SENSOR_Focus
1046 .id = V4L2_CID_FOCUS_RELATIVE,
1047 .type = V4L2_CTRL_TYPE_INTEGER,
1048 .name = "Focus Control",
1054 .id = V4L2_CID_FOCUS_ABSOLUTE,
1055 .type = V4L2_CTRL_TYPE_INTEGER,
1056 .name = "Focus Control",
1060 .default_value = 125,
1063 .id = V4L2_CID_FOCUS_AUTO,
1064 .type = V4L2_CTRL_TYPE_BOOLEAN,
1065 .name = "Focus Control",
1071 .id = V4L2_CID_FOCUS_CONTINUOUS,
1072 .type = V4L2_CTRL_TYPE_BOOLEAN,
1073 .name = "Focus Control",
1081 #if CONFIG_SENSOR_Flash
1083 .id = V4L2_CID_FLASH,
1084 .type = V4L2_CTRL_TYPE_MENU,
1085 .name = "Flash Control",
1094 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1095 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1096 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1097 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1098 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1099 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1100 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1101 static int sensor_resume(struct soc_camera_device *icd);
1102 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1103 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1104 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1105 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1106 static int sensor_deactivate(struct i2c_client *client);
1108 static struct soc_camera_ops sensor_ops =
1110 .suspend = sensor_suspend,
1111 .resume = sensor_resume,
1112 .set_bus_param = sensor_set_bus_param,
1113 .query_bus_param = sensor_query_bus_param,
1114 .controls = sensor_controls,
1115 .menus = sensor_menus,
1116 .num_controls = ARRAY_SIZE(sensor_controls),
1117 .num_menus = ARRAY_SIZE(sensor_menus),
1120 /* only one fixed colorspace per pixelcode */
1121 struct sensor_datafmt {
1122 enum v4l2_mbus_pixelcode code;
1123 enum v4l2_colorspace colorspace;
1126 /* Find a data format by a pixel code in an array */
1127 static const struct sensor_datafmt *sensor_find_datafmt(
1128 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1132 for (i = 0; i < n; i++)
1133 if (fmt[i].code == code)
1139 static const struct sensor_datafmt sensor_colour_fmts[] = {
1140 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1141 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1143 enum sensor_work_state
1145 sensor_work_ready = 0,
1150 struct i2c_client *client;
1151 struct delayed_work dwork;
1152 enum sensor_work_state state;
1155 typedef struct sensor_info_priv_s
1169 unsigned char mirror; /* HFLIP */
1170 unsigned char flip; /* VFLIP */
1177 struct reginfo *winseqe_cur_addr;
1178 struct sensor_datafmt fmt;
1179 unsigned int enable;
1180 unsigned int funmodule_state;
1181 } sensor_info_priv_t;
1185 struct sensor_parameter
1187 unsigned short int preview_maxlines;
1188 unsigned short int preview_exposure;
1189 unsigned short int preview_line_width;
1190 unsigned short int preview_gain;
1192 unsigned short int capture_framerate;
1193 unsigned short int preview_framerate;
1198 struct v4l2_subdev subdev;
1199 struct i2c_client *client;
1200 sensor_info_priv_t info_priv;
1201 struct sensor_parameter parameter;
1202 struct workqueue_struct *sensor_wq;
1203 struct sensor_work sensor_wk;
1204 struct mutex wq_lock;
1205 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1206 #if CONFIG_SENSOR_I2C_NOSCHED
1207 atomic_t tasklock_cnt;
1209 struct rk29camera_platform_data *sensor_io_request;
1210 struct rk29camera_gpio_res *sensor_gpio_res;
1213 static struct sensor* to_sensor(const struct i2c_client *client)
1215 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1218 static int sensor_task_lock(struct i2c_client *client, int lock)
1220 #if CONFIG_SENSOR_I2C_NOSCHED
1222 struct sensor *sensor = to_sensor(client);
1225 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1226 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1227 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1231 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1232 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1233 goto sensor_task_lock_err;
1238 atomic_add(1, &sensor->tasklock_cnt);
1240 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1241 atomic_sub(1, &sensor->tasklock_cnt);
1243 if (atomic_read(&sensor->tasklock_cnt) == 0)
1249 sensor_task_lock_err:
1256 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val);
1258 /* sensor register write */
1259 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1263 struct i2c_msg msg[1];
1265 switch (reg_info->reg)
1267 case SEQUENCE_WAIT_MS:
1270 mdelay(reg_info->val);
1272 msleep(reg_info->val);
1276 case SEQUENCE_WAIT_US:
1278 udelay(reg_info->val);
1282 case SEQUENCE_PROPERTY:
1288 buf[0] = reg_info->reg >> 8;
1289 buf[1] = reg_info->reg & 0xFF;
1290 if (reg_info->reg_len == WORD_LEN) {
1291 buf[2] = reg_info->val >> 8;
1292 buf[3] = reg_info->val & 0xFF;
1295 } else if (reg_info->reg_len == BYTE_LEN) {
1296 buf[2] = reg_info->val;
1300 msg->addr = client->addr;
1301 msg->flags = client->flags;
1303 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1304 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1309 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1310 err = i2c_transfer(client->adapter, msg, 1);
1315 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);
1324 /* sensor register read */
1325 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1329 struct i2c_msg msg[2];
1332 buf[1] = reg & 0xFF;
1334 msg[0].addr = client->addr;
1335 msg[0].flags = client->flags;
1337 msg[0].len = sizeof(buf);
1338 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1339 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1341 msg[1].addr = client->addr;
1342 msg[1].flags = client->flags|I2C_M_RD;
1345 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1346 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1350 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1351 err = i2c_transfer(client->adapter, msg, 2);
1354 *val = buf[0]<<8 | buf[1];
1357 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1365 /* write a array of registers */
1366 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1370 #if CONFIG_SENSOR_I2C_RDWRCHK
1375 if (sensor_task_lock(client, 1) < 0)
1376 goto sensor_write_array_end;
1377 while (regarray[i].reg != SEQUENCE_END) {
1378 err = sensor_write(client, ®array[i]);
1382 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1386 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1388 goto sensor_write_array_end;
1391 #if CONFIG_SENSOR_I2C_RDWRCHK
1392 sensor_read(client, regarray[i].reg, &valchk);
1393 if (valchk != regarray[i].val)
1394 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1401 sensor_write_array_end:
1402 sensor_task_lock(client,0);
1405 #if CONFIG_SENSOR_I2C_RDWRCHK
1406 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1414 while (regarray[i].reg != SEQUENCE_END)
1416 sensor_read(client, regarray[i].reg, &valchk);
1417 if (valchk != regarray[i].val)
1418 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1425 #if CONFIG_SENSOR_Focus
1426 static struct reginfo sensor_af_init0[] =
1429 {SEQUENCE_END, 0x00}
1431 static struct reginfo sensor_af_init1[] =
1433 {SEQUENCE_END, 0x00}
1437 static struct reginfo sensor_af_trigger[] =
1439 {SEQUENCE_END, 0x00}
1441 static int sensor_af_single(struct i2c_client *client)
1445 ret = sensor_write_array(client, sensor_af_trigger);
1447 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1449 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1450 sensor_af_single_end:
1454 static int sensor_af_const(struct i2c_client *client)
1458 sensor_af_const_end:
1462 static int sensor_af_zoneupdate(struct i2c_client *client)
1465 struct i2c_msg msg[2];
1468 {0xb0,0x08,0x00,0x03,0xff,0xff},
1469 {0xb0,0x0c,0xff,0xff,0xff,0xff},
1472 msg[0].addr = client->addr;
1473 msg[0].flags = client->flags;
1474 msg[0].buf = buf[0];
1475 msg[0].len = sizeof(buf);
1476 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1477 msg[0].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1479 msg[1].addr = client->addr;
1480 msg[1].flags = client->flags;
1481 msg[1].buf = buf[1];
1482 msg[1].len = sizeof(buf);
1483 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1484 msg[1].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1486 ret = i2c_transfer(client->adapter, &msg[0], 1);
1487 ret |= i2c_transfer(client->adapter, &msg[1], 1);
1491 SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
1494 sensor_af_zoneupdate_end:
1498 static int sensor_af_init(struct i2c_client *client)
1502 ret = sensor_write_array(client, sensor_af_init0);
1504 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1506 if (sensor_af_zoneupdate(client) == 0) {
1507 ret = sensor_write_array(client, sensor_af_init1);
1509 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1518 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1520 struct soc_camera_link *icl = to_soc_camera_link(icd);
1523 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1526 case Sensor_PowerDown:
1528 if (icl->powerdown) {
1529 ret = icl->powerdown(icd->pdev, on);
1530 if (ret == RK29_CAM_IO_SUCCESS) {
1534 icl->reset(icd->pdev);
1536 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1538 goto sensor_power_end;
1545 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1546 struct sensor *sensor = to_sensor(client);
1548 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1549 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1555 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1563 static s32 sensor_init_width = 800;
1564 static s32 sensor_init_height = 600;
1565 static unsigned long sensor_init_busparam = (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING|SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ);
1566 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
1567 static struct reginfo* sensor_init_data_p = NULL;
1568 static struct reginfo* sensor_init_winseq_p = NULL;
1569 static struct reginfo* sensor_init_winseq_board = NULL;
1570 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1572 struct i2c_client *client = v4l2_get_subdevdata(sd);
1573 struct soc_camera_device *icd = client->dev.platform_data;
1574 struct sensor *sensor = to_sensor(client);
1575 const struct v4l2_queryctrl *qctrl;
1576 const struct sensor_datafmt *fmt;
1578 int ret,pid = 0,i = 0,j=0;
1579 struct rk29camera_platform_data* tmp_plat_data =(struct rk29camera_platform_data*)val;
1580 sensor_init_data_p = sensor_init_data;
1581 sensor_init_winseq_p = sensor_svga;
1582 sensor_init_width = 800;
1583 sensor_init_height = 600;
1584 if (tmp_plat_data != NULL && (u32)tmp_plat_data != 1) {
1585 for(i = 0;i < RK_CAM_NUM;i++){
1586 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1587 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1591 if(tmp_plat_data && ((u32)tmp_plat_data != 1) &&(i < RK_CAM_NUM) && tmp_plat_data->sensor_init_data[i]){
1592 //user has defined the init data
1594 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1595 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1596 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1597 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1599 sensor_init_data_p = sensor_init_data;
1601 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1602 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1605 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1606 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1607 if(sensor_init_winseq_board)
1609 vfree(sensor_init_winseq_board);
1610 sensor_init_winseq_board = NULL;
1612 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1613 if(!sensor_init_winseq_board)
1614 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1615 for(j = 0;j< tmp_winseq_size;j++){
1616 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1617 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1619 sensor_init_winseq_p = sensor_init_winseq_board;
1621 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1622 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1624 //init width,height,bus,pixelcode
1625 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1626 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1627 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1628 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1629 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1630 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1631 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1632 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1634 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1636 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1638 goto sensor_INIT_ERR;
1642 if (sensor_task_lock(client,1)<0)
1643 goto sensor_INIT_ERR;
1645 #if (SENSOR_RESET_REG != SEQUENCE_END)
1646 struct reginfo reg_info;
1647 reg_info.reg = SENSOR_RESET_REG;
1648 reg_info.val = SENSOR_RESET_VAL;
1649 reg_info.reg_len = SENSOR_RESET_REG_LEN;
1650 ret = sensor_write(client, ®_info);
1652 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1654 goto sensor_INIT_ERR;
1656 mdelay(5); //delay 5 microseconds
1657 reg_info.val = SENSOR_DERESET_VAL;
1658 ret = sensor_write(client, ®_info);
1660 SENSOR_TR("%s soft dereset sensor failed\n",SENSOR_NAME_STRING());
1662 goto sensor_INIT_ERR;
1666 /* check if it is an sensor sensor */
1667 #if (SENSOR_ID_REG != SEQUENCE_END)
1668 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1670 SENSOR_TR("read chip id failed\n");
1672 goto sensor_INIT_ERR;
1675 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1679 if (pid == SENSOR_ID) {
1680 sensor->model = SENSOR_V4L2_IDENT;
1682 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1684 goto sensor_INIT_ERR;
1687 ret = sensor_write_array(client, sensor_init_data_p);
1690 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1691 goto sensor_INIT_ERR;
1693 sensor_task_lock(client,0);
1694 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1695 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1696 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1697 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1698 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1699 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1701 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1703 goto sensor_INIT_ERR;
1705 sensor->info_priv.fmt = *fmt;
1707 /* sensor sensor information for initialization */
1708 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1710 sensor->info_priv.whiteBalance = qctrl->default_value;
1711 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1713 sensor->info_priv.brightness = qctrl->default_value;
1714 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1716 sensor->info_priv.effect = qctrl->default_value;
1717 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1719 sensor->info_priv.exposure = qctrl->default_value;
1721 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1723 sensor->info_priv.saturation = qctrl->default_value;
1724 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1726 sensor->info_priv.contrast = qctrl->default_value;
1727 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1729 sensor->info_priv.mirror = qctrl->default_value;
1730 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1732 sensor->info_priv.flip = qctrl->default_value;
1733 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1735 sensor->info_priv.scene = qctrl->default_value;
1736 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1738 sensor->info_priv.digitalzoom = qctrl->default_value;
1740 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1741 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1743 sensor->info_priv.focus = qctrl->default_value;
1744 #if CONFIG_SENSOR_Focus
1745 if (sensor_af_init(client) < 0) {
1746 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1747 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1749 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1750 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1753 #if CONFIG_SENSOR_Flash
1754 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1756 sensor->info_priv.flash = qctrl->default_value;
1758 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);
1762 sensor_task_lock(client,0);
1763 sensor_deactivate(client);
1766 static int sensor_deactivate(struct i2c_client *client)
1768 struct soc_camera_device *icd = client->dev.platform_data;
1770 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1772 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1773 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1775 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1776 icd->user_width = SENSOR_INIT_WIDTH;
1777 icd->user_height = SENSOR_INIT_HEIGHT;
1781 static struct reginfo sensor_power_down_sequence[]=
1785 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1788 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1790 if (pm_msg.event == PM_EVENT_SUSPEND) {
1791 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1792 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1794 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1797 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1799 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1804 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1811 static int sensor_resume(struct soc_camera_device *icd)
1815 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1817 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1821 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1825 static int sensor_set_bus_param(struct soc_camera_device *icd,
1826 unsigned long flags)
1832 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1834 struct soc_camera_link *icl = to_soc_camera_link(icd);
1835 unsigned long flags = SENSOR_BUS_PARAM;
1837 return soc_camera_apply_sensor_flags(icl, flags);
1839 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1841 struct i2c_client *client = v4l2_get_subdevdata(sd);
1842 struct soc_camera_device *icd = client->dev.platform_data;
1843 struct sensor *sensor = to_sensor(client);
1845 mf->width = icd->user_width;
1846 mf->height = icd->user_height;
1847 mf->code = sensor->info_priv.fmt.code;
1848 mf->colorspace = sensor->info_priv.fmt.colorspace;
1849 mf->field = V4L2_FIELD_NONE;
1853 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1857 if ((mf->width == 1024) && (mf->height == 768)) {
1859 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1861 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1863 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1865 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1870 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1874 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1878 if ((mf->width == 1280) && (mf->height == 720)) {
1880 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1885 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1888 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1890 struct reginfo *winseqe_set_addr = NULL;
1892 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1893 winseqe_set_addr = sensor_qcif;
1896 } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1897 winseqe_set_addr = sensor_qvga;
1900 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1901 winseqe_set_addr = sensor_cif;
1904 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1905 winseqe_set_addr = sensor_vga;
1908 } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1909 printk("enter 800x600\n");
1910 winseqe_set_addr = sensor_svga;
1913 } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1914 winseqe_set_addr = sensor_xga;
1917 } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1918 printk("enter 1280X720\n");
1919 winseqe_set_addr = sensor_720p;
1922 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1923 printk("enter 1280X1024\n");
1924 winseqe_set_addr = sensor_sxga;
1927 } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1928 winseqe_set_addr = sensor_uxga;
1931 } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1932 winseqe_set_addr = sensor_1080p;
1935 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1936 winseqe_set_addr = sensor_qxga;
1939 } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1940 winseqe_set_addr = sensor_qsxga;
1945 return winseqe_set_addr;
1948 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1950 struct i2c_client *client = v4l2_get_subdevdata(sd);
1951 struct sensor *sensor = to_sensor(client);
1952 const struct sensor_datafmt *fmt;
1953 struct reginfo *winseqe_set_addr=NULL;
1954 int ret = 0, set_w,set_h;
1956 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
1958 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1959 ARRAY_SIZE(sensor_colour_fmts));
1962 goto sensor_s_fmt_end;
1965 if (sensor->info_priv.fmt.code != mf->code) {
1968 case V4L2_MBUS_FMT_YUYV8_2X8:
1970 winseqe_set_addr = sensor_ClrFmt_YUYV;
1973 case V4L2_MBUS_FMT_UYVY8_2X8:
1975 winseqe_set_addr = sensor_ClrFmt_UYVY;
1981 if (winseqe_set_addr != NULL) {
1982 sensor_write_array(client, winseqe_set_addr);
1983 sensor->info_priv.fmt.code = mf->code;
1984 sensor->info_priv.fmt.colorspace= mf->colorspace;
1985 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1987 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1994 winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1996 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1997 ret |= sensor_write_array(client, winseqe_set_addr);
1999 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2000 goto sensor_s_fmt_end;
2002 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
2003 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2004 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2006 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2007 sensor->info_priv.preview_w = mf->width;
2008 sensor->info_priv.preview_h = mf->height;
2012 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2013 ret |= sensor_write_array(client, sensor_Preview2Capture);
2015 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
2016 goto sensor_s_fmt_end;
2018 sensor->info_priv.capture_w = set_w;
2019 sensor->info_priv.capture_h = set_h;
2020 sensor->info_priv.snap2preview = true;
2021 } else if (sensor->info_priv.snap2preview == true) {
2022 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
2023 ret |= sensor_write_array(client, sensor_Capture2Preview);
2025 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
2026 goto sensor_s_fmt_end;
2028 sensor->info_priv.preview_w = mf->width;
2029 sensor->info_priv.preview_h = mf->height;
2030 sensor->info_priv.snap2preview = false;
2032 SENSOR_TR("\n %s..%s Format is Invalidate. mf->width = %d.. mf->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2042 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2045 struct i2c_client *client = v4l2_get_subdevdata(sd);
2046 struct sensor *sensor = to_sensor(client);
2047 const struct sensor_datafmt *fmt;
2049 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2050 ARRAY_SIZE(sensor_colour_fmts));
2052 fmt = &sensor->info_priv.fmt;
2053 mf->code = fmt->code;
2056 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
2059 * With Bayer format enforce even side lengths, but let the user play
2060 * with the starting pixel
2063 if (mf->height > SENSOR_MAX_HEIGHT)
2064 mf->height = SENSOR_MAX_HEIGHT;
2065 else if (mf->height < SENSOR_MIN_HEIGHT)
2066 mf->height = SENSOR_MIN_HEIGHT;
2068 if (mf->width > SENSOR_MAX_WIDTH)
2069 mf->width = SENSOR_MAX_WIDTH;
2070 else if (mf->width < SENSOR_MIN_WIDTH)
2071 mf->width = SENSOR_MIN_WIDTH;
2073 if (sensor_fmt_catch(mf->width, mf->height, &mf->width, &mf->height) == NULL) {
2074 printk("%s[%d] ERR!!!!!!",__FUNCTION__,__LINE__);
2082 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2084 struct i2c_client *client = v4l2_get_subdevdata(sd);
2086 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2089 if (id->match.addr != client->addr)
2092 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2097 #if CONFIG_SENSOR_Brightness
2098 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2100 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2102 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2104 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2106 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2108 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2111 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2115 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2119 #if CONFIG_SENSOR_Effect
2120 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2122 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2124 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2126 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2128 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2130 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2133 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2137 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2141 #if CONFIG_SENSOR_Exposure
2142 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2144 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2146 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2148 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2150 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2152 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2155 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2159 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2163 #if CONFIG_SENSOR_Saturation
2164 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2166 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2168 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2170 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2172 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2174 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2177 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2181 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2185 #if CONFIG_SENSOR_Contrast
2186 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2188 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2190 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2192 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2194 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2196 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2199 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2203 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2207 #if CONFIG_SENSOR_Mirror
2208 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2210 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2212 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2214 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2216 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2218 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2221 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2225 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2229 #if CONFIG_SENSOR_Flip
2230 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2232 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2234 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2236 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2238 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2240 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2243 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2247 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2251 #if CONFIG_SENSOR_Scene
2252 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2254 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2256 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2258 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2260 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2262 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2265 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2269 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2273 #if CONFIG_SENSOR_WhiteBalance
2274 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2276 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2278 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2280 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2282 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2284 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2287 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2291 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2295 #if CONFIG_SENSOR_DigitalZoom
2296 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2298 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2299 struct sensor *sensor = to_sensor(client);
2300 const struct v4l2_queryctrl *qctrl_info;
2301 int digitalzoom_cur, digitalzoom_total;
2303 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2307 digitalzoom_cur = sensor->info_priv.digitalzoom;
2308 digitalzoom_total = qctrl_info->maximum;
2310 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2312 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2316 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2318 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2322 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2324 *value = digitalzoom_total - digitalzoom_cur;
2327 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2329 *value = 0 - digitalzoom_cur;
2332 digitalzoom_cur += *value;
2334 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2336 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2338 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2341 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2348 #if CONFIG_SENSOR_Flash
2349 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2351 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2352 struct sensor *sensor = to_sensor(client);
2353 const struct v4l2_queryctrl *qctrl_info;
2355 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2356 if (value == 3) { /* ddl@rock-chips.com: torch */
2357 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2359 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2361 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2365 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2369 #if CONFIG_SENSOR_Focus
2370 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2372 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2373 struct sensor *sensor = to_sensor(client);
2374 const struct v4l2_queryctrl *qctrl_info;
2377 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2381 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2382 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2384 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2387 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2391 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2392 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2395 sensor_set_focus_absolute_end:
2398 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2400 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2401 struct sensor *sensor = to_sensor(client);
2402 const struct v4l2_queryctrl *qctrl_info;
2405 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2409 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2410 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2412 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2415 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2419 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2420 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2422 sensor_set_focus_relative_end:
2426 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2428 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2429 struct sensor *sensor = to_sensor(client);
2432 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2435 case SENSOR_AF_MODE_AUTO:
2437 ret = sensor_af_single(client);
2441 case SENSOR_AF_MODE_MACRO:
2443 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2447 case SENSOR_AF_MODE_INFINITY:
2449 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2453 case SENSOR_AF_MODE_CONTINUOUS:
2455 ret = sensor_af_const(client);
2459 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2464 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2467 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2468 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2474 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2476 struct i2c_client *client = v4l2_get_subdevdata(sd);
2477 struct sensor *sensor = to_sensor(client);
2478 const struct v4l2_queryctrl *qctrl;
2480 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2484 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2490 case V4L2_CID_BRIGHTNESS:
2492 ctrl->value = sensor->info_priv.brightness;
2495 case V4L2_CID_SATURATION:
2497 ctrl->value = sensor->info_priv.saturation;
2500 case V4L2_CID_CONTRAST:
2502 ctrl->value = sensor->info_priv.contrast;
2505 case V4L2_CID_DO_WHITE_BALANCE:
2507 ctrl->value = sensor->info_priv.whiteBalance;
2510 case V4L2_CID_EXPOSURE:
2512 ctrl->value = sensor->info_priv.exposure;
2515 case V4L2_CID_HFLIP:
2517 ctrl->value = sensor->info_priv.mirror;
2520 case V4L2_CID_VFLIP:
2522 ctrl->value = sensor->info_priv.flip;
2533 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2535 struct i2c_client *client = v4l2_get_subdevdata(sd);
2536 const struct v4l2_queryctrl *qctrl;
2537 struct sensor *sensor = to_sensor(client);
2538 struct soc_camera_device *icd = client->dev.platform_data;
2539 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2543 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2549 #if CONFIG_SENSOR_Brightness
2550 case V4L2_CID_BRIGHTNESS:
2552 if (ctrl->value != sensor->info_priv.brightness)
2554 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2558 sensor->info_priv.brightness = ctrl->value;
2563 #if CONFIG_SENSOR_Exposure
2564 case V4L2_CID_EXPOSURE:
2566 if (ctrl->value != sensor->info_priv.exposure)
2568 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2572 sensor->info_priv.exposure = ctrl->value;
2577 #if CONFIG_SENSOR_Saturation
2578 case V4L2_CID_SATURATION:
2580 if (ctrl->value != sensor->info_priv.saturation)
2582 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2586 sensor->info_priv.saturation = ctrl->value;
2591 #if CONFIG_SENSOR_Contrast
2592 case V4L2_CID_CONTRAST:
2594 if (ctrl->value != sensor->info_priv.contrast)
2596 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2600 sensor->info_priv.contrast = ctrl->value;
2605 #if CONFIG_SENSOR_WhiteBalance
2606 case V4L2_CID_DO_WHITE_BALANCE:
2608 if (ctrl->value != sensor->info_priv.whiteBalance)
2610 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2614 sensor->info_priv.whiteBalance = ctrl->value;
2619 #if CONFIG_SENSOR_Mirror
2620 case V4L2_CID_HFLIP:
2622 if (ctrl->value != sensor->info_priv.mirror)
2624 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2626 sensor->info_priv.mirror = ctrl->value;
2631 #if CONFIG_SENSOR_Flip
2632 case V4L2_CID_VFLIP:
2634 if (ctrl->value != sensor->info_priv.flip)
2636 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2638 sensor->info_priv.flip = ctrl->value;
2649 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2651 const struct v4l2_queryctrl *qctrl;
2652 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2653 struct sensor *sensor = to_sensor(client);
2655 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2659 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2663 switch (ext_ctrl->id)
2665 case V4L2_CID_SCENE:
2667 ext_ctrl->value = sensor->info_priv.scene;
2670 case V4L2_CID_EFFECT:
2672 ext_ctrl->value = sensor->info_priv.effect;
2675 case V4L2_CID_ZOOM_ABSOLUTE:
2677 ext_ctrl->value = sensor->info_priv.digitalzoom;
2680 case V4L2_CID_ZOOM_RELATIVE:
2684 case V4L2_CID_FOCUS_ABSOLUTE:
2688 case V4L2_CID_FOCUS_RELATIVE:
2692 case V4L2_CID_FLASH:
2694 ext_ctrl->value = sensor->info_priv.flash;
2702 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2704 const struct v4l2_queryctrl *qctrl;
2705 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2706 struct sensor *sensor = to_sensor(client);
2709 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2713 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2718 switch (ext_ctrl->id)
2720 #if CONFIG_SENSOR_Scene
2721 case V4L2_CID_SCENE:
2723 if (ext_ctrl->value != sensor->info_priv.scene)
2725 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2727 sensor->info_priv.scene = ext_ctrl->value;
2732 #if CONFIG_SENSOR_Effect
2733 case V4L2_CID_EFFECT:
2735 if (ext_ctrl->value != sensor->info_priv.effect)
2737 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2739 sensor->info_priv.effect= ext_ctrl->value;
2744 #if CONFIG_SENSOR_DigitalZoom
2745 case V4L2_CID_ZOOM_ABSOLUTE:
2747 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2750 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2752 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2754 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2756 sensor->info_priv.digitalzoom += val_offset;
2758 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2763 case V4L2_CID_ZOOM_RELATIVE:
2765 if (ext_ctrl->value)
2767 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2769 sensor->info_priv.digitalzoom += ext_ctrl->value;
2771 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2776 #if CONFIG_SENSOR_Focus
2777 case V4L2_CID_FOCUS_ABSOLUTE:
2779 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2782 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2783 if (ext_ctrl->value == qctrl->minimum) {
2784 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2785 } else if (ext_ctrl->value == qctrl->maximum) {
2786 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2788 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2794 case V4L2_CID_FOCUS_RELATIVE:
2796 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2799 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2802 case V4L2_CID_FOCUS_AUTO:
2804 if (ext_ctrl->value == 1) {
2805 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2807 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2808 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2809 if (ext_ctrl->value == 0)
2810 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2814 case V4L2_CID_FOCUS_CONTINUOUS:
2816 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2817 if (ext_ctrl->value == 1) {
2818 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2820 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2823 if (ext_ctrl->value == 0)
2824 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2829 #if CONFIG_SENSOR_Flash
2830 case V4L2_CID_FLASH:
2832 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2834 sensor->info_priv.flash = ext_ctrl->value;
2836 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2847 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2849 struct i2c_client *client = v4l2_get_subdevdata(sd);
2850 struct soc_camera_device *icd = client->dev.platform_data;
2851 int i, error_cnt=0, error_idx=-1;
2854 for (i=0; i<ext_ctrl->count; i++) {
2855 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2862 error_idx = ext_ctrl->count;
2864 if (error_idx != -1) {
2865 ext_ctrl->error_idx = error_idx;
2872 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2874 struct i2c_client *client = v4l2_get_subdevdata(sd);
2875 struct soc_camera_device *icd = client->dev.platform_data;
2876 int i, error_cnt=0, error_idx=-1;
2878 for (i=0; i<ext_ctrl->count; i++) {
2879 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2886 error_idx = ext_ctrl->count;
2888 if (error_idx != -1) {
2889 ext_ctrl->error_idx = error_idx;
2896 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2898 struct i2c_client *client = v4l2_get_subdevdata(sd);
2899 struct sensor *sensor = to_sensor(client);
2902 sensor->info_priv.enable = 1;
2903 } else if (enable == 0) {
2904 sensor->info_priv.enable = 0;
2910 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2911 * this wasn't our capture interface, so, we wait for the right one */
2912 static int sensor_video_probe(struct soc_camera_device *icd,
2913 struct i2c_client *client)
2916 struct sensor *sensor = to_sensor(client);
2917 #if (SENSOR_ID_REG != SEQUENCE_END)
2921 /* We must have a parent by now. And it cannot be a wrong one.
2922 * So this entire test is completely redundant. */
2923 if (!icd->dev.parent ||
2924 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2927 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2929 goto sensor_video_probe_err;
2933 #if (SENSOR_RESET_REG != SEQUENCE_END)
2934 struct reginfo reg_info;
2935 reg_info.reg = SENSOR_RESET_REG;
2936 reg_info.val = SENSOR_RESET_VAL;
2937 reg_info.reg_len = SENSOR_RESET_REG_LEN;
2938 ret = sensor_write(client, ®_info);
2940 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2942 goto sensor_video_probe_err;
2945 mdelay(5); //delay 5 microseconds
2948 /* check if it is an sensor sensor */
2949 #if (SENSOR_ID_REG != SEQUENCE_END)
2950 ret = sensor_read(client, SENSOR_ID_REG, &pid);
2952 SENSOR_TR("read chip id failed\n");
2954 goto sensor_video_probe_err;
2957 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2962 if (pid == SENSOR_ID) {
2963 sensor->model = SENSOR_V4L2_IDENT;
2965 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2967 goto sensor_video_probe_err;
2974 sensor_video_probe_err:
2978 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2980 struct i2c_client *client = v4l2_get_subdevdata(sd);
2981 struct soc_camera_device *icd = client->dev.platform_data;
2982 struct sensor *sensor = to_sensor(client);
2985 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2988 case RK29_CAM_SUBDEV_DEACTIVATE:
2990 sensor_deactivate(client);
2993 case RK29_CAM_SUBDEV_IOREQUEST:
2995 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2996 if (sensor->sensor_io_request != NULL) {
2998 for(j = 0;j < RK_CAM_NUM;j++){
2999 if (sensor->sensor_io_request->gpio_res[j].dev_name &&
3000 (strcmp(sensor->sensor_io_request->gpio_res[j].dev_name, dev_name(icd->pdev)) == 0)) {
3001 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[j];
3005 if(j == RK_CAM_NUM){
3006 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3008 goto sensor_ioctl_end;
3011 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3013 #if CONFIG_SENSOR_Flash
3015 if (sensor->sensor_gpio_res) {
3016 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3017 for (i = 0; i < icd->ops->num_controls; i++) {
3018 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3019 memset(&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3022 sensor->info_priv.flash = 0xff;
3023 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3031 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3039 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3040 enum v4l2_mbus_pixelcode *code)
3042 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3045 *code = sensor_colour_fmts[index].code;
3048 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3049 .init = sensor_init,
3050 .g_ctrl = sensor_g_control,
3051 .s_ctrl = sensor_s_control,
3052 .g_ext_ctrls = sensor_g_ext_controls,
3053 .s_ext_ctrls = sensor_s_ext_controls,
3054 .g_chip_ident = sensor_g_chip_ident,
3055 .ioctl = sensor_ioctl,
3058 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3059 .s_mbus_fmt = sensor_s_fmt,
3060 .g_mbus_fmt = sensor_g_fmt,
3061 .try_mbus_fmt = sensor_try_fmt,
3062 .enum_mbus_fmt = sensor_enum_fmt,
3064 static struct v4l2_subdev_ops sensor_subdev_ops = {
3065 .core = &sensor_subdev_core_ops,
3066 .video = &sensor_subdev_video_ops,
3069 static int sensor_probe(struct i2c_client *client,
3070 const struct i2c_device_id *did)
3072 struct sensor *sensor;
3073 struct soc_camera_device *icd = client->dev.platform_data;
3074 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3075 struct soc_camera_link *icl;
3078 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3080 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3084 icl = to_soc_camera_link(icd);
3086 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3090 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3091 dev_warn(&adapter->dev,
3092 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3096 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3100 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3102 /* Second stage probe - when a capture adapter is there */
3103 icd->ops = &sensor_ops;
3104 sensor->info_priv.fmt = sensor_colour_fmts[0];
3105 #if CONFIG_SENSOR_I2C_NOSCHED
3106 atomic_set(&sensor->tasklock_cnt,0);
3109 ret = sensor_video_probe(icd, client);
3112 i2c_set_clientdata(client, NULL);
3116 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3120 static int sensor_remove(struct i2c_client *client)
3122 struct sensor *sensor = to_sensor(client);
3123 struct soc_camera_device *icd = client->dev.platform_data;
3125 #if CONFIG_SENSOR_Focus
3126 if (sensor->sensor_wq) {
3127 destroy_workqueue(sensor->sensor_wq);
3128 sensor->sensor_wq = NULL;
3133 i2c_set_clientdata(client, NULL);
3134 client->driver = NULL;
3140 static const struct i2c_device_id sensor_id[] = {
3141 {SENSOR_NAME_STRING(), 0 },
3144 MODULE_DEVICE_TABLE(i2c, sensor_id);
3146 static struct i2c_driver sensor_i2c_driver = {
3148 .name = SENSOR_NAME_STRING(),
3150 .probe = sensor_probe,
3151 .remove = sensor_remove,
3152 .id_table = sensor_id,
3155 static int __init sensor_mod_init(void)
3157 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3158 return i2c_add_driver(&sensor_i2c_driver);
3161 static void __exit sensor_mod_exit(void)
3163 i2c_del_driver(&sensor_i2c_driver);
3166 device_initcall_sync(sensor_mod_init);
3167 module_exit(sensor_mod_exit);
3169 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3170 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3171 MODULE_LICENSE("GPL");