2 * Driver for mt9d112 CMOS Image Sensor from Aptina(micron)
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/miscdevice.h>
19 #include <media/v4l2-common.h>
20 #include <media/v4l2-chip-ident.h>
21 #include <media/soc_camera.h>
22 #include <mach/rk29_camera.h>
26 module_param(debug, int, S_IRUGO|S_IWUSR);
28 #define dprintk(level, fmt, arg...) do { \
30 printk(KERN_WARNING fmt , ## arg); } while (0)
32 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
33 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
35 #define _CONS(a,b) a##b
36 #define CONS(a,b) _CONS(a,b)
39 #define _STR(x) __STR(x)
40 #define STR(x) _STR(x)
42 #define MIN(x,y) ((x<y) ? x: y)
43 #define MAX(x,y) ((x>y) ? x: y)
45 /* Sensor Driver Configuration */
46 #define SENSOR_NAME RK29_CAM_SENSOR_MT9D112
47 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9D112
48 #define SENSOR_ID 0x1580
49 #define SENSOR_ID_REG 0x3000
50 #define SENSOR_RESET_REG SEQUENCE_END
51 #define SENSOR_RESET_VAL 0x00
52 #define SENSOR_MIN_WIDTH 320
53 #define SENSOR_MIN_HEIGHT 240
54 #define SENSOR_MAX_WIDTH 1600
55 #define SENSOR_MAX_HEIGHT 1200
56 #define SENSOR_INIT_WIDTH 640 /* Sensor pixel size for sensor_init_data array */
57 #define SENSOR_INIT_HEIGHT 480
58 #define SENSOR_INIT_WINSEQADR sensor_vga
59 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
61 #define CONFIG_SENSOR_WhiteBalance 1
62 #define CONFIG_SENSOR_Brightness 0
63 #define CONFIG_SENSOR_Contrast 0
64 #define CONFIG_SENSOR_Saturation 0
65 #define CONFIG_SENSOR_Effect 1
66 #define CONFIG_SENSOR_Scene 1
67 #define CONFIG_SENSOR_DigitalZoom 0
68 #define CONFIG_SENSOR_Exposure 0
69 #define CONFIG_SENSOR_Flash 0
70 #define CONFIG_SENSOR_Mirror 0
71 #define CONFIG_SENSOR_Flip 0
72 #define CONFIG_SENSOR_Focus 0
75 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
76 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
77 #define CONFIG_SENSOR_I2C_NOSCHED 0
78 #define CONFIG_SENSOR_I2C_RDWRCHK 0
81 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |\
82 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
83 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
85 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
86 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
87 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
88 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
89 #define COLOR_TEMPERATURE_OFFICE_DN 3500
90 #define COLOR_TEMPERATURE_OFFICE_UP 5000
91 #define COLOR_TEMPERATURE_HOME_DN 2500
92 #define COLOR_TEMPERATURE_HOME_UP 3500
94 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
95 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
97 #define SENSOR_AF_IS_ERR (0x00<<0)
98 #define SENSOR_AF_IS_OK (0x01<<0)
99 #define SENSOR_INIT_IS_ERR (0x00<<28)
100 #define SENSOR_INIT_IS_OK (0x01<<28)
102 #if CONFIG_SENSOR_Focus
103 #define SENSOR_AF_MODE_INFINITY 0
104 #define SENSOR_AF_MODE_MACRO 1
105 #define SENSOR_AF_MODE_FIXED 2
106 #define SENSOR_AF_MODE_AUTO 3
107 #define SENSOR_AF_MODE_CONTINUOUS 4
108 #define SENSOR_AF_MODE_CLOSE 5
110 #define SENSOR_CCM_ONLY
111 /* init 640X480 VGA */
112 static struct reginfo sensor_init_data[] =
114 {0x301A, 0x0ACC}, // RESET_REGISTER
115 {0x3202, 0x0008}, // STANDBY_CONTROL
116 {SEQUENCE_WAIT_MS, 10},
117 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
118 {0x341C, 0x0218}, // PLL_DIVIDERS1
119 {SEQUENCE_WAIT_MS, 1},
120 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
121 {0x341E, 0x8F08}, // PLL_CLK_IN_CONTROL
122 {0x3044, 0x0540}, // DARK_CONTROL
123 {0x3216, 0x02CF}, // INTERNAL_CLOCK_CONTROL
124 {0x321C, 0x0402}, // OF_CONTROL_STATUS
125 {0x3212, 0x0001}, // FACTORY_BYPASS
126 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
127 {0x341C, 0x0120}, // PLL_DIVIDERS1
128 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
129 {0x341E, 0x8F08}, // PLL_CLK_IN_CONTROL
130 {0x3044, 0x0540}, // DARK_CONTROL
131 {0x3216, 0x02CF}, // INTERNAL_CLOCK_CONTROL
132 {0x321C, 0x0402}, // OF_CONTROL_STATUS
133 {0x3212, 0x0001}, // FACTORY_BYPASS//¹©Æ·¸ÉÈųÌÐòÀûÓÃ֮ǰµÄ07005
134 #ifdef SENSOR_CCM_ONLY
153 {0x338C, 0x2703}, // MCU_ADDRESS
154 {0x3390, 0x0140}, // MCU_DATA_0
155 {0x338C, 0x2705}, // MCU_ADDRESS
156 {0x3390, 0x00F0}, // MCU_DATA_0
157 {0x338C, 0x2707}, // MCU_ADDRESS
158 {0x3390, 0x0640}, // MCU_DATA_0
159 {0x338C, 0x2709}, // MCU_ADDRESS
160 {0x3390, 0x04B0}, // MCU_DATA_0
161 {0x338C, 0x270D}, // MCU_ADDRESS
162 {0x3390, 0x0000}, // MCU_DATA_0
163 {0x338C, 0x270F}, // MCU_ADDRESS
164 {0x3390, 0x0000}, // MCU_DATA_0
165 {0x338C, 0x2711}, // MCU_ADDRESS
166 {0x3390, 0x04BD}, // MCU_DATA_0
167 {0x338C, 0x2713}, // MCU_ADDRESS
168 {0x3390, 0x064D}, // MCU_DATA_0
169 {0x338C, 0x2715}, // MCU_ADDRESS
170 {0x3390, 0x0022}, // MCU_DATA_0
172 {0x338C, 0x2717}, // MCU_ADDRESS
173 {0x3390, 0x2111}, // MCU_DATA_0
174 {0x338C, 0x2719}, // MCU_ADDRESS
175 {0x3390, 0x046C}, // MCU_DATA_0
176 {0x338C, 0x271B}, // MCU_ADDRESS
177 {0x3390, 0x024F}, // MCU_DATA_0
178 {0x338C, 0x271D}, // MCU_ADDRESS
179 {0x3390, 0x0102}, // MCU_DATA_0
180 {0x338C, 0x271F}, // MCU_ADDRESS
181 {0x3390, 0x0279}, // MCU_DATA_0
182 {0x338C, 0x2721}, // MCU_ADDRESS
183 {0x3390, 0x0155}, // MCU_DATA_0
184 {0x338C, 0x2723}, // MCU_ADDRESS
185 {0x3390, 0x0293}, // MCU_DATA_0
186 {0x338C, 0x2725}, // MCU_ADDRESS
187 {0x3390, 0x0824}, // MCU_DATA_0
188 {0x338C, 0x2727}, // MCU_ADDRESS
189 {0x3390, 0x2020}, // MCU_DATA_0
190 {0x338C, 0x2729}, // MCU_ADDRESS
191 {0x3390, 0x2020}, // MCU_DATA_0
192 {0x338C, 0x272B}, // MCU_ADDRESS
193 {0x3390, 0x1020}, // MCU_DATA_0
194 {0x338C, 0x272D}, // MCU_ADDRESS
195 {0x3390, 0x2007}, // MCU_DATA_0
196 {0x338C, 0x272F}, // MCU_ADDRESS
197 {0x3390, 0x0004}, // MCU_DATA_0
198 {0x338C, 0x2731}, // MCU_ADDRESS
199 {0x3390, 0x0004}, // MCU_DATA_0
200 {0x338C, 0x2733}, // MCU_ADDRESS
201 {0x3390, 0x04BB}, // MCU_DATA_0
202 {0x338C, 0x2735}, // MCU_ADDRESS
203 {0x3390, 0x064B}, // MCU_DATA_0
204 {0x338C, 0x2737}, // MCU_ADDRESS
205 {0x3390, 0x0000}, // MCU_DATA_0
206 {0x338C, 0x2739}, // MCU_ADDRESS
207 {0x3390, 0x2111}, // MCU_DATA_0
208 {0x338C, 0x273B}, // MCU_ADDRESS
209 {0x3390, 0x0024}, // MCU_DATA_0
210 {0x338C, 0x273D}, // MCU_ADDRESS
211 {0x3390, 0x0120}, // MCU_DATA_0
212 {0x338C, 0x273F}, // MCU_ADDRESS
213 {0x3390, 0x00A4}, // MCU_DATA_0
214 {0x338C, 0x2741}, // MCU_ADDRESS
215 {0x3390, 0x0169}, // MCU_DATA_0
216 {0x338C, 0x2743}, // MCU_ADDRESS
217 {0x3390, 0x00A4}, // MCU_DATA_0
218 {0x338C, 0x2745}, // MCU_ADDRESS
219 {0x3390, 0x04ED}, // MCU_DATA_0
220 {0x338C, 0x2747}, // MCU_ADDRESS
221 {0x3390, 0x0824}, // MCU_DATA_0
222 {0x338C, 0x2751}, // MCU_ADDRESS
223 {0x3390, 0x0000}, // MCU_DATA_0
224 {0x338C, 0x2753}, // MCU_ADDRESS
225 {0x3390, 0x0320}, // MCU_DATA_0
226 {0x338C, 0x2755}, // MCU_ADDRESS
227 {0x3390, 0x0000}, // MCU_DATA_0
228 {0x338C, 0x2757}, // MCU_ADDRESS
229 {0x3390, 0x0258}, // MCU_DATA_0
230 {0x338C, 0x275F}, // MCU_ADDRESS
231 {0x3390, 0x0000}, // MCU_DATA_0
232 {0x338C, 0x2761}, // MCU_ADDRESS
233 {0x3390, 0x0640}, // MCU_DATA_0
234 {0x338C, 0x2763}, // MCU_ADDRESS
235 {0x3390, 0x0000}, // MCU_DATA_0
236 {0x338C, 0x2765}, // MCU_ADDRESS
237 {0x3390, 0x04B0}, // MCU_DATA_0
238 {0x338C, 0x222E}, // MCU_ADDRESS
239 {0x3390, 0x0060}, // MCU_DATA_0
240 {0x338C, 0xA408}, // MCU_ADDRESS
241 {0x3390, 0x0017}, // MCU_DATA_0
242 {0x338C, 0xA409}, // MCU_ADDRESS
243 {0x3390, 0x001A}, // MCU_DATA_0
244 {0x338C, 0xA40A}, // MCU_ADDRESS
245 {0x3390, 0x001B}, // MCU_DATA_0
246 {0x338C, 0xA40B}, // MCU_ADDRESS
247 {0x3390, 0x001E}, // MCU_DATA_0
248 {0x338C, 0x2411}, // MCU_ADDRESS
249 {0x3390, 0x0060}, // MCU_DATA_0
250 {0x338C, 0x2413}, // MCU_ADDRESS
251 {0x3390, 0x0073}, // MCU_DATA_0
252 {0x338C, 0x2415}, // MCU_ADDRESS
253 {0x3390, 0x0060}, // MCU_DATA_0
254 {0x338C, 0x2417}, // MCU_ADDRESS
255 {0x3390, 0x0073}, // MCU_DATA_0
256 {0x338C, 0xA40D}, // MCU_ADDRESS
257 {0x3390, 0x0002}, // MCU_DATA_0
258 {0x338C, 0xA410}, // MCU_ADDRESS
259 {0x3390, 0x0001}, // MCU_DATA_0
260 {0x338C, 0xA103}, // MCU_ADDRESS
261 {0x3390, 0x0006}, // MCU_DATA_0
262 {0x338C, 0xA103}, // MCU_ADDRESS
263 {0x3390, 0x0005}, // MCU_DATA_0
264 {0x338C, 0x2703}, // MCU_ADDRESS
265 {0x3390, 0x0140}, // MCU_DATA_0
266 {0x338C, 0x2705}, // MCU_ADDRESS
267 {0x3390, 0x00F0}, // MCU_DATA_0
268 {0x338C, 0x2707}, // MCU_ADDRESS
269 {0x3390, 0x0640}, // MCU_DATA_0
270 {0x338C, 0x2709}, // MCU_ADDRESS
271 {0x3390, 0x04B0}, // MCU_DATA_0
272 {0x338C, 0x270D}, // MCU_ADDRESS
273 {0x3390, 0x0000}, // MCU_DATA_0
274 {0x338C, 0x270F}, // MCU_ADDRESS
275 {0x3390, 0x0000}, // MCU_DATA_0
276 {0x338C, 0x2711}, // MCU_ADDRESS
277 {0x3390, 0x04BD}, // MCU_DATA_0
278 {0x338C, 0x2713}, // MCU_ADDRESS
279 {0x3390, 0x064D}, // MCU_DATA_0
280 {0x338C, 0x2715}, // MCU_ADDRESS
281 {0x3390, 0x0022}, // MCU_DATA_0
282 {0x338C, 0x2717}, // MCU_ADDRESS
283 {0x3390, 0x2111}, // MCU_DATA_0
284 {0x338C, 0x2719}, // MCU_ADDRESS
285 {0x3390, 0x046C}, // MCU_DATA_0
286 {0x338C, 0x271B}, // MCU_ADDRESS
287 {0x3390, 0x024F}, // MCU_DATA_0
288 {0x338C, 0x271D}, // MCU_ADDRESS
289 {0x3390, 0x0102}, // MCU_DATA_0
290 {0x338C, 0x271F}, // MCU_ADDRESS
291 {0x3390, 0x0279}, // MCU_DATA_0
292 {0x338C, 0x2721}, // MCU_ADDRESS
293 {0x3390, 0x0155}, // MCU_DATA_0
294 {0x338C, 0x2723}, // MCU_ADDRESS
295 {0x3390, 0x0293}, // MCU_DATA_0
296 {0x338C, 0x2725}, // MCU_ADDRESS
297 {0x3390, 0x0824}, // MCU_DATA_0
298 {0x338C, 0x2727}, // MCU_ADDRESS
299 {0x3390, 0x2020}, // MCU_DATA_0
300 {0x338C, 0x2729}, // MCU_ADDRESS
301 {0x3390, 0x2020}, // MCU_DATA_0
302 {0x338C, 0x272B}, // MCU_ADDRESS
303 {0x3390, 0x1020}, // MCU_DATA_0
304 {0x338C, 0x272D}, // MCU_ADDRESS
305 {0x3390, 0x2007}, // MCU_DATA_0
306 {0x338C, 0x272F}, // MCU_ADDRESS
307 {0x3390, 0x0004}, // MCU_DATA_0
308 {0x338C, 0x2731}, // MCU_ADDRESS
309 {0x3390, 0x0004}, // MCU_DATA_0
310 {0x338C, 0x2733}, // MCU_ADDRESS
311 {0x3390, 0x04BB}, // MCU_DATA_0
312 {0x338C, 0x2735}, // MCU_ADDRESS
313 {0x3390, 0x064B}, // MCU_DATA_0
314 {0x338C, 0x2737}, // MCU_ADDRESS
315 {0x3390, 0x0000}, // MCU_DATA_0
316 {0x338C, 0x2739}, // MCU_ADDRESS
317 {0x3390, 0x2111}, // MCU_DATA_0
318 {0x338C, 0x273B}, // MCU_ADDRESS
319 {0x3390, 0x0024}, // MCU_DATA_0
320 {0x338C, 0x273D}, // MCU_ADDRESS
321 {0x3390, 0x0120}, // MCU_DATA_0
322 {0x338C, 0x273F}, // MCU_ADDRESS
323 {0x3390, 0x00A4}, // MCU_DATA_0
324 {0x338C, 0x2741}, // MCU_ADDRESS
325 {0x3390, 0x0169}, // MCU_DATA_0
326 {0x338C, 0x2743}, // MCU_ADDRESS
327 {0x3390, 0x00A4}, // MCU_DATA_0
328 {0x338C, 0x2745}, // MCU_ADDRESS
329 {0x3390, 0x04ED}, // MCU_DATA_0
330 {0x338C, 0x2747}, // MCU_ADDRESS
331 {0x3390, 0x0824}, // MCU_DATA_0
332 {0x338C, 0x2751}, // MCU_ADDRESS
333 {0x3390, 0x0000}, // MCU_DATA_0
334 {0x338C, 0x2753}, // MCU_ADDRESS
335 {0x3390, 0x0320}, // MCU_DATA_0
336 {0x338C, 0x2755}, // MCU_ADDRESS
337 {0x3390, 0x0000}, // MCU_DATA_0
338 {0x338C, 0x2757}, // MCU_ADDRESS
339 {0x3390, 0x0258}, // MCU_DATA_0
340 {0x338C, 0x275F}, // MCU_ADDRESS
341 {0x3390, 0x0000}, // MCU_DATA_0
342 {0x338C, 0x2761}, // MCU_ADDRESS
343 {0x3390, 0x0640}, // MCU_DATA_0
344 {0x338C, 0x2763}, // MCU_ADDRESS
345 {0x3390, 0x0000}, // MCU_DATA_0
346 {0x338C, 0x2765}, // MCU_ADDRESS
347 {0x3390, 0x04B0}, // MCU_DATA_0
348 {0x338C, 0x222E}, // MCU_ADDRESS
349 {0x3390, 0x0060}, // MCU_DATA_0
350 {0x338C, 0xA408}, // MCU_ADDRESS
351 {0x3390, 0x0017}, // MCU_DATA_0
352 {0x338C, 0xA409}, // MCU_ADDRESS
353 {0x3390, 0x001A}, // MCU_DATA_0
354 {0x338C, 0xA40A}, // MCU_ADDRESS
355 {0x3390, 0x001B}, // MCU_DATA_0
356 {0x338C, 0xA40B}, // MCU_ADDRESS
357 {0x3390, 0x001E}, // MCU_DATA_0
358 {0x338C, 0x2411}, // MCU_ADDRESS
359 {0x3390, 0x0060}, // MCU_DATA_0
360 {0x338C, 0x2413}, // MCU_ADDRESS
361 {0x3390, 0x0073}, // MCU_DATA_0
362 {0x338C, 0x2415}, // MCU_ADDRESS
363 {0x3390, 0x0060}, // MCU_DATA_0
364 {0x338C, 0x2417}, // MCU_ADDRESS
365 {0x3390, 0x0073}, // MCU_DATA_0
366 {0x338C, 0xA40D}, // MCU_ADDRESS
367 {0x3390, 0x0002}, // MCU_DATA_0
368 {0x338C, 0xA410}, // MCU_ADDRESS
369 {0x3390, 0x0001}, // MCU_DATA_0
370 {0x338C, 0xA103}, // MCU_ADDRESS
371 {0x3390, 0x0006}, // MCU_DATA_0
372 {SEQUENCE_WAIT_MS, 100},
373 {0x338C, 0xA103}, // MCU_ADDRESS
374 {0x3390, 0x0005}, // MCU_DATA_0
375 {SEQUENCE_WAIT_MS, 100},
378 //[Lens Correction 01/04/07 20:07:28]
379 {0x34CE, 0x01A0}, //LENS_CORRECTION_CONTROL
380 {0x34D0, 0x6532}, //ZONE_BOUNDS_X1_X2
381 {0x34D2, 0x3297}, //ZONE_BOUNDS_X0_X3
382 {0x34D4, 0x9664}, //ZONE_BOUNDS_X4_X5
383 {0x34D6, 0x4B25}, //ZONE_BOUNDS_Y1_Y2
384 {0x34D8, 0x2670}, //ZONE_BOUNDS_Y0_Y3
385 {0x34DA, 0x724C}, //ZONE_BOUNDS_Y4_Y5
386 {0x34DC, 0xFF01}, //CENTER_OFFSET
387 {0x34DE, 0x011F}, //FX_RED
388 {0x34E6, 0x00B3}, //FY_RED
389 {0x34EE, 0x0D8F}, //DF_DX_RED
390 {0x34F6, 0x0D6E}, //DF_DY_RED
391 {0x3500, 0xF51C}, //SECOND_DERIV_ZONE_0_RED
392 {0x3508, 0xFEF8}, //SECOND_DERIV_ZONE_1_RED
393 {0x3510, 0x212D}, //SECOND_DERIV_ZONE_2_RED
394 {0x3518, 0x212B}, //SECOND_DERIV_ZONE_3_RED
395 {0x3520, 0x1F2A}, //SECOND_DERIV_ZONE_4_RED
396 {0x3528, 0x2934}, //SECOND_DERIV_ZONE_5_RED
397 {0x3530, 0x17DB}, //SECOND_DERIV_ZONE_6_RED
398 {0x3538, 0xE7D6}, //SECOND_DERIV_ZONE_7_RED
399 {0x354C, 0x07C6}, //K_FACTOR_IN_K_FX_FY_R_TL
400 {0x3544, 0x07FF}, //K_FACTOR_IN_K_FX_FY_R_TR
401 {0x355C, 0x051C}, //K_FACTOR_IN_K_FX_FY_R_BL
402 {0x3554, 0x07FF}, //K_FACTOR_IN_K_FX_FY_R_BR
403 {0x34E0, 0x0137}, //FX_GREEN
404 {0x34E8, 0x00A8}, //FY_GREEN
405 {0x34F0, 0x0E3E}, //DF_DX_GREEN
406 {0x34F8, 0x0DCB}, //DF_DY_GREEN
407 {0x3502, 0xF20A}, //SECOND_DERIV_ZONE_0_GREEN
408 {0x350A, 0xFBE1}, //SECOND_DERIV_ZONE_1_GREEN
409 {0x3512, 0x1C26}, //SECOND_DERIV_ZONE_2_GREEN
410 {0x351A, 0x232B}, //SECOND_DERIV_ZONE_3_GREEN
411 {0x3522, 0x312E}, //SECOND_DERIV_ZONE_4_GREEN
412 {0x352A, 0x2121}, //SECOND_DERIV_ZONE_5_GREEN
413 {0x3532, 0xF106}, //SECOND_DERIV_ZONE_6_GREEN
414 {0x353A, 0x0C0D}, //SECOND_DERIV_ZONE_7_GREEN
415 {0x354E, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G1_TL
416 {0x3546, 0x0638}, //K_FACTOR_IN_K_FX_FY_G1_TR
417 {0x355E, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G1_BL
418 {0x3556, 0x0155}, //K_FACTOR_IN_K_FX_FY_G1_BR
419 {0x34E4, 0x0107}, //FX_BLUE
420 {0x34EC, 0x0079}, //FY_BLUE
421 {0x34F4, 0x0E19}, //DF_DX_BLUE
422 {0x34FC, 0x0D35}, //DF_DY_BLUE
423 {0x3506, 0x111C}, //SECOND_DERIV_ZONE_0_BLUE
424 {0x350E, 0x02E6}, //SECOND_DERIV_ZONE_1_BLUE
425 {0x3516, 0x2521}, //SECOND_DERIV_ZONE_2_BLUE
426 {0x351E, 0x2620}, //SECOND_DERIV_ZONE_3_BLUE
427 {0x3526, 0x1A25}, //SECOND_DERIV_ZONE_4_BLUE
428 {0x352E, 0x0B1D}, //SECOND_DERIV_ZONE_5_BLUE
429 {0x3536, 0xFD03}, //SECOND_DERIV_ZONE_6_BLUE
430 {0x353E, 0xB315}, //SECOND_DERIV_ZONE_7_BLUE
431 {0x3552, 0x06D0}, //K_FACTOR_IN_K_FX_FY_B_TL
432 {0x354A, 0x03FF}, //K_FACTOR_IN_K_FX_FY_B_TR
433 {0x3562, 0x07FF}, //K_FACTOR_IN_K_FX_FY_B_BL
434 {0x355A, 0x057B}, //K_FACTOR_IN_K_FX_FY_B_BR
435 {0x34E2, 0x011E}, //FX_GREEN2
436 {0x34EA, 0x008A}, //FY_GREEN2
437 {0x34F2, 0x0D6E}, //DF_DX_GREEN2
438 {0x34FA, 0x0D7F}, //DF_DY_GREEN2
439 {0x3504, 0xF822}, //SECOND_DERIV_ZONE_0_GREEN2
440 {0x350C, 0x0DFC}, //SECOND_DERIV_ZONE_1_GREEN2
441 {0x3514, 0x1F25}, //SECOND_DERIV_ZONE_2_GREEN2
442 {0x351C, 0x3032}, //SECOND_DERIV_ZONE_3_GREEN2
443 {0x3524, 0x2628}, //SECOND_DERIV_ZONE_4_GREEN2
444 {0x352C, 0x1523}, //SECOND_DERIV_ZONE_5_GREEN2
445 {0x3534, 0xFADF}, //SECOND_DERIV_ZONE_6_GREEN2
446 {0x353C, 0xDEF7}, //SECOND_DERIV_ZONE_7_GREEN2
447 {0x3550, 0x0109}, //K_FACTOR_IN_K_FX_FY_G2_TL
448 {0x3548, 0x0638}, //K_FACTOR_IN_K_FX_FY_G2_TR
449 {0x3560, 0x0638}, //K_FACTOR_IN_K_FX_FY_G2_BL
450 {0x3558, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G2_BR
451 {0x3540, 0x0000}, //X2_FACTORS
452 {0x3542, 0x0000}, //GLOBAL_OFFSET_FXY_FUNCTION
453 {0x3210, 0x01FC}, // COLOR_PIPELINE_CONTROL
456 {0x338C, 0xA364}, // MCU_ADDRESS [AWB_KR_L]
457 {0x3390, 0x0080}, // MCU_DATA_0
458 {0x338C, 0xA364}, // MCU_ADDRESS [AWB_KR_L]
459 {0x3390, 0x0080}, // MCU_DATA_0
460 {0x338C, 0xA365}, // MCU_ADDRESS [AWB_KG_L]
461 {0x3390, 0x008C}, // MCU_DATA_0
462 {0x338C, 0xA365}, // MCU_ADDRESS [AWB_KG_L]
463 {0x3390, 0x008C}, // MCU_DATA_0
464 {0x338C, 0xA366}, // MCU_ADDRESS [AWB_KB_L]
465 {0x3390, 0x0082}, // MCU_DATA_0
466 {0x338C, 0xA366}, // MCU_ADDRESS [AWB_KB_L]
467 {0x3390, 0x0082}, // MCU_DATA_0
468 {0x338C, 0x2306}, // MCU_ADDRESS [AWB_CCM_L_0]
469 {0x3390, 0x0619}, // MCU_DATA_0
470 {0x338C, 0x2308}, // MCU_ADDRESS [AWB_CCM_L_1]
471 {0x3390, 0xFC80}, // MCU_DATA_0
472 {0x338C, 0x230A}, // MCU_ADDRESS [AWB_CCM_L_2]
473 {0x3390, 0xFEFB}, // MCU_DATA_0
474 {0x338C, 0x230C}, // MCU_ADDRESS [AWB_CCM_L_3]
475 {0x3390, 0xFEEE}, // MCU_DATA_0
476 {0x338C, 0x230E}, // MCU_ADDRESS [AWB_CCM_L_4]
477 {0x3390, 0x0571}, // MCU_DATA_0
478 {0x338C, 0x2310}, // MCU_ADDRESS [AWB_CCM_L_5]
479 {0x3390, 0xFE26}, // MCU_DATA_0
480 {0x338C, 0x2312}, // MCU_ADDRESS [AWB_CCM_L_6]
481 {0x3390, 0xFF0C}, // MCU_DATA_0
482 {0x338C, 0x2314}, // MCU_ADDRESS [AWB_CCM_L_7]
483 {0x3390, 0xFE48}, // MCU_DATA_0
484 {0x338C, 0x2316}, // MCU_ADDRESS [AWB_CCM_L_8]
485 {0x3390, 0x04A2}, // MCU_DATA_0
486 {0x338C, 0x2318}, // MCU_ADDRESS [AWB_CCM_L_9]
487 {0x3390, 0x0024}, // MCU_DATA_0
488 {0x338C, 0x231A}, // MCU_ADDRESS [AWB_CCM_L_10]
489 {0x3390, 0x003F}, // MCU_DATA_0
490 {0x338C, 0x231C}, // MCU_ADDRESS [AWB_CCM_RL_0]
491 {0x3390, 0xFDA7}, // MCU_DATA_0
492 {0x338C, 0x231E}, // MCU_ADDRESS [AWB_CCM_RL_1]
493 {0x3390, 0x0158}, // MCU_DATA_0
494 {0x338C, 0x2320}, // MCU_ADDRESS [AWB_CCM_RL_2]
495 {0x3390, 0x00EE}, // MCU_DATA_0
496 {0x338C, 0x2322}, // MCU_ADDRESS [AWB_CCM_RL_3]
497 {0x3390, 0x00D3}, // MCU_DATA_0
498 {0x338C, 0x2324}, // MCU_ADDRESS [AWB_CCM_RL_4]
499 {0x3390, 0xFC74}, // MCU_DATA_0
500 {0x338C, 0x2326}, // MCU_ADDRESS [AWB_CCM_RL_5]
501 {0x3390, 0x01A9}, // MCU_DATA_0
502 {0x338C, 0x2328}, // MCU_ADDRESS [AWB_CCM_RL_6]
503 {0x3390, 0x014B}, // MCU_DATA_0
504 {0x338C, 0x232A}, // MCU_ADDRESS [AWB_CCM_RL_7]
505 {0x3390, 0xFE9D}, // MCU_DATA_0
506 {0x338C, 0x232C}, // MCU_ADDRESS [AWB_CCM_RL_8]
507 {0x3390, 0xFF69}, // MCU_DATA_0
508 {0x338C, 0x232E}, // MCU_ADDRESS [AWB_CCM_RL_9]
509 {0x3390, 0x0018}, // MCU_DATA_0
510 {0x338C, 0x2330}, // MCU_ADDRESS [AWB_CCM_RL_10]
511 {0x3390, 0xFFEC}, // MCU_DATA_0
512 {0x338C, 0xA348}, // MCU_ADDRESS [AWB_GAIN_BUFFER_SPEED]
513 {0x3390, 0x0008}, // MCU_DATA_0
514 {0x338C, 0xA349}, // MCU_ADDRESS [AWB_JUMP_DIVISOR]
515 {0x3390, 0x0002}, // MCU_DATA_0
516 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
517 {0x3390, 0x0059}, // MCU_DATA_0
518 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
519 {0x3390, 0x00A6}, // MCU_DATA_0
520 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
521 {0x3390, 0x0000}, // MCU_DATA_0
522 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
523 {0x3390, 0x007F}, // MCU_DATA_0
524 {0x338C, 0xA353}, // MCU_ADDRESS [AWB_MODE]
525 {0x3390, 0x0002}, // MCU_DATA_0
526 {0x338C, 0xA35B}, // MCU_ADDRESS [AWB_STEADY_BGAIN_OUT_MIN]
527 {0x3390, 0x0078}, // MCU_DATA_0
528 {0x338C, 0xA35C}, // MCU_ADDRESS [AWB_STEADY_BGAIN_OUT_MAX]
529 {0x3390, 0x0086}, // MCU_DATA_0
530 {0x338C, 0xA35D}, // MCU_ADDRESS [AWB_STEADY_BGAIN_IN_MIN]
531 {0x3390, 0x007E}, // MCU_DATA_0
532 {0x338C, 0xA35E}, // MCU_ADDRESS [AWB_STEADY_BGAIN_IN_MAX]
533 {0x3390, 0x0082}, // MCU_DATA_0
534 {0x338C, 0x235F}, // MCU_ADDRESS [AWB_CNT_PXL_TH]
535 {0x3390, 0x0040}, // MCU_DATA_0
536 {0x338C, 0xA361}, // MCU_ADDRESS [AWB_TG_MIN0]
537 {0x3390, 0x00C8}, // MCU_DATA_0
538 {0x338C, 0xA362}, // MCU_ADDRESS [AWB_TG_MAX0]
539 {0x3390, 0x00E1}, // MCU_DATA_0
540 {0x338C, 0xA302}, // MCU_ADDRESS [AWB_WINDOW_POS]
541 {0x3390, 0x0000}, // MCU_DATA_0
542 {0x338C, 0xA303}, // MCU_ADDRESS [AWB_WINDOW_SIZE]
543 {0x3390, 0x00EF}, // MCU_DATA_0
544 {0x338C, 0xA352}, // MCU_ADDRESS [AWB_SATURATION]
545 {0x3390, 0x001E}, // MCU_DATA_0
546 {0x338C, 0xA118}, // MCU_ADDRESS [SEQ_LLSAT1]
547 {0x3390, 0x001E}, // MCU_DATA_0
548 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
549 {0x3390, 0x0005}, // MCU_DATA_0
551 {0x338C, 0xA76D}, // MCU_ADDRESS [MODE_GAM_CONT_A]
552 {0x3390, 0x0003}, // MCU_DATA_0
553 {0x338C, 0xA76F}, // MCU_ADDRESS [MODE_GAM_TABLE_A_0]
554 {0x3390, 0x0000}, // MCU_DATA_0
555 {0x338C, 0xA770}, // MCU_ADDRESS [MODE_GAM_TABLE_A_1]
556 {0x3390, 0x000B}, // MCU_DATA_0
557 {0x338C, 0xA771}, // MCU_ADDRESS [MODE_GAM_TABLE_A_2]
558 {0x3390, 0x0023}, // MCU_DATA_0
559 {0x338C, 0xA772}, // MCU_ADDRESS [MODE_GAM_TABLE_A_3]
560 {0x3390, 0x0043}, // MCU_DATA_0
561 {0x338C, 0xA773}, // MCU_ADDRESS [MODE_GAM_TABLE_A_4]
562 {0x3390, 0x006E}, // MCU_DATA_0
563 {0x338C, 0xA774}, // MCU_ADDRESS [MODE_GAM_TABLE_A_5]
564 {0x3390, 0x0090}, // MCU_DATA_0
565 {0x338C, 0xA775}, // MCU_ADDRESS [MODE_GAM_TABLE_A_6]
566 {0x3390, 0x00A8}, // MCU_DATA_0
567 {0x338C, 0xA776}, // MCU_ADDRESS [MODE_GAM_TABLE_A_7]
568 {0x3390, 0x00B9}, // MCU_DATA_0
569 {0x338C, 0xA777}, // MCU_ADDRESS [MODE_GAM_TABLE_A_8]
570 {0x3390, 0x00C6}, // MCU_DATA_0
571 {0x338C, 0xA778}, // MCU_ADDRESS [MODE_GAM_TABLE_A_9]
572 {0x3390, 0x00D0}, // MCU_DATA_0
573 {0x338C, 0xA779}, // MCU_ADDRESS [MODE_GAM_TABLE_A_10]
574 {0x3390, 0x00D9}, // MCU_DATA_0
575 {0x338C, 0xA77A}, // MCU_ADDRESS [MODE_GAM_TABLE_A_11]
576 {0x3390, 0x00E0}, // MCU_DATA_0
577 {0x338C, 0xA77B}, // MCU_ADDRESS [MODE_GAM_TABLE_A_12]
578 {0x3390, 0x00E6}, // MCU_DATA_0
579 {0x338C, 0xA77C}, // MCU_ADDRESS [MODE_GAM_TABLE_A_13]
580 {0x3390, 0x00EB}, // MCU_DATA_0
581 {0x338C, 0xA77D}, // MCU_ADDRESS [MODE_GAM_TABLE_A_14]
582 {0x3390, 0x00F0}, // MCU_DATA_0
583 {0x338C, 0xA77E}, // MCU_ADDRESS [MODE_GAM_TABLE_A_15]
584 {0x3390, 0x00F4}, // MCU_DATA_0
585 {0x338C, 0xA77F}, // MCU_ADDRESS [MODE_GAM_TABLE_A_16]
586 {0x3390, 0x00F8}, // MCU_DATA_0
587 {0x338C, 0xA780}, // MCU_ADDRESS [MODE_GAM_TABLE_A_17]
588 {0x3390, 0x00FC}, // MCU_DATA_0
589 {0x338C, 0xA781}, // MCU_ADDRESS [MODE_GAM_TABLE_A_18]
590 {0x3390, 0x00FF}, // MCU_DATA_0
592 {0x338C, 0xA102}, // MCU_ADDRESS
593 {0x3390, 0x002F}, // MCU_DATA_0
594 {0x338C, 0xA114}, // MCU_ADDRESS
595 {0x3390, 0x0005}, // MCU_DATA_0
596 {SEQUENCE_WAIT_MS, 20},
597 {0x338C, 0xA103}, // MCU_ADDRESS
598 {0x3390, 0x0005}, // MCU_DATA_0
600 {0x338C, 0xA206}, // MCU_ADDRESS [AE_TARGET]
601 {0x3390, 0x003C}, // MCU_DATA_0
605 /* 720p 15fps @ 1280x720 */
607 static struct reginfo sensor_720p[]=
612 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
614 static struct reginfo sensor_1080p[]=
619 /* 2592X1944 QSXGA */
620 static struct reginfo sensor_qsxga[] =
625 static struct reginfo sensor_qxga[] =
631 static struct reginfo sensor_uxga[] =
633 {SEQUENCE_PROPERTY, SEQUENCE_CAPTURE},
651 static struct reginfo sensor_sxga[] =
653 {SEQUENCE_PROPERTY, SEQUENCE_CAPTURE},
671 static struct reginfo sensor_xga[] =
677 static struct reginfo sensor_svga[] =
683 static struct reginfo sensor_vga[] =
689 static struct reginfo sensor_cif[] =
695 static struct reginfo sensor_qvga[] =
701 static struct reginfo sensor_qcif[] =
707 static struct reginfo ov2655_qqvga[] =
751 static struct reginfo ov2655_Sharpness_auto[] =
756 static struct reginfo ov2655_Sharpness1[] =
762 static struct reginfo ov2655_Sharpness2[][3] =
769 static struct reginfo ov2655_Sharpness3[] =
775 static struct reginfo ov2655_Sharpness4[]=
782 static struct reginfo ov2655_Sharpness5[] =
790 static struct reginfo sensor_Preview2Capture[]=
792 {0x338C, 0xA120}, // MCU_ADDRESS [SEQ_CAP_MODE]
793 {0x3390, 0x0002}, // MCU_DATA_0
794 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
795 {0x3390, 0x0002}, // MCU_DATA_0
796 {0x338C, 0xA102}, // MCU_ADDRESS [SEQ_CMD] cgz oppo 2008-09-26
801 static struct reginfo sensor_Capture2Preview[]=
803 {0x338C, 0xA120}, // MCU_ADDRESS [SEQ_CAP_MODE]
804 {0x3390, 0x0000}, // MCU_DATA_0
805 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
806 {0x3390, 0x0001}, // MCU_DATA_0
810 static struct reginfo sensor_ClrFmt_YUYV[]=
815 static struct reginfo sensor_ClrFmt_UYVY[]=
821 #if CONFIG_SENSOR_WhiteBalance
822 static struct reginfo sensor_WhiteB_Auto[]=
825 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
826 {0x3390, 0x0059}, // MCU_DATA_0
827 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
828 {0x3390, 0x00A6}, // MCU_DATA_0
829 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
830 {0x3390, 0x0000}, // MCU_DATA_0
831 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
832 {0x3390, 0x007F}, // MCU_DATA_0
835 /* Cloudy Colour Temperature : 6500K - 8000K */
836 static struct reginfo sensor_WhiteB_Cloudy[]=
839 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
840 {0x3390, 0x0080}, // MCU_DATA_0
841 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
842 {0x3390, 0x007F}, // MCU_DATA_0
843 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
844 {0x3390, 0x007F}, // MCU_DATA_
847 /* ClearDay Colour Temperature : 5000K - 6500K */
848 static struct reginfo sensor_WhiteB_ClearDay[]=
851 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
852 {0x3390, 0x0080}, // MCU_DATA_0
853 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
854 {0x3390, 0x0080}, // MCU_DATA_0
855 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
856 {0x3390, 0x007E}, // MCU_DATA_0
857 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
858 {0x3390, 0x007E}, // MCU_DATA_0
861 /* Office Colour Temperature : 3500K - 5000K */
862 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
865 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
866 {0x3390, 0x0080}, // MCU_DATA_0
867 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
868 {0x3390, 0x0080}, // MCU_DATA_0
869 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
870 {0x3390, 0x0030}, // MCU_DATA_0
871 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
872 {0x3390, 0x0030}, // MCU_DATA_0
875 /* Home Colour Temperature : 2500K - 3500K */
876 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
879 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
880 {0x3390, 0x0080}, // MCU_DATA_0
881 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
882 {0x3390, 0x0080}, // MCU_DATA_0
883 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
884 {0x3390, 0x0032}, // MCU_DATA_0
885 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
886 {0x3390, 0x0032}, // MCU_DATA_0
889 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
890 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
894 #if CONFIG_SENSOR_Brightness
895 static struct reginfo sensor_Brightness0[]=
900 static struct reginfo sensor_Brightness1[]=
905 static struct reginfo sensor_Brightness2[]=
910 static struct reginfo sensor_Brightness3[]=
915 static struct reginfo sensor_Brightness4[]=
920 static struct reginfo sensor_Brightness5[]=
924 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
925 sensor_Brightness4, sensor_Brightness5,NULL,
930 #if CONFIG_SENSOR_Effect
931 static struct reginfo sensor_Effect_Normal[] =
933 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
934 {0x3390, 0x6408}, // MCU_DATA_0
935 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
936 {0x3390, 0x6408}, // MCU_DATA_0
937 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
938 {0x3390, 0x0005}, // MCU_DATA_0
942 static struct reginfo sensor_Effect_WandB[] =
944 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
945 {0x3390, 0x6409}, // MCU_DATA_0
946 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
947 {0x3390, 0x6409}, // MCU_DATA_0
948 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
949 {0x3390, 0x0005}, // MCU_DATA_0
953 static struct reginfo sensor_Effect_Sepia[] =
955 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
956 {0x3390, 0x640A}, // MCU_DATA_0
957 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
958 {0x3390, 0x640A}, // MCU_DATA_0
959 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
960 {0x3390, 0x0005}, // MCU_DATA_0
964 static struct reginfo sensor_Effect_Negative[] =
966 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
967 {0x3390, 0x640B}, // MCU_DATA_0
968 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
969 {0x3390, 0x640B}, // MCU_DATA_0
970 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
971 {0x3390, 0x0005}, // MCU_DATA_0
974 static struct reginfo sensor_Effect_Bluish[] =
979 static struct reginfo sensor_Effect_Green[] =
984 static struct reginfo sensor_Effect_Solarize[] =
988 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Sepia,sensor_Effect_Negative,
992 #if CONFIG_SENSOR_Exposure
993 static struct reginfo sensor_Exposure0[]=
998 static struct reginfo sensor_Exposure1[]=
1000 {SEQUENCE_END, 0x00}
1003 static struct reginfo sensor_Exposure2[]=
1005 {SEQUENCE_END, 0x00}
1008 static struct reginfo sensor_Exposure3[]=
1010 {SEQUENCE_END, 0x00}
1013 static struct reginfo sensor_Exposure4[]=
1015 {SEQUENCE_END, 0x00}
1018 static struct reginfo sensor_Exposure5[]=
1020 {SEQUENCE_END, 0x00}
1023 static struct reginfo sensor_Exposure6[]=
1025 {SEQUENCE_END, 0x00}
1028 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1029 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1032 #if CONFIG_SENSOR_Saturation
1033 static struct reginfo sensor_Saturation0[]=
1035 {SEQUENCE_END, 0x00}
1038 static struct reginfo sensor_Saturation1[]=
1040 {SEQUENCE_END, 0x00}
1043 static struct reginfo sensor_Saturation2[]=
1045 {SEQUENCE_END, 0x00}
1047 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1050 #if CONFIG_SENSOR_Contrast
1051 static struct reginfo sensor_Contrast0[]=
1053 {SEQUENCE_END, 0x00}
1056 static struct reginfo sensor_Contrast1[]=
1058 {SEQUENCE_END, 0x00}
1061 static struct reginfo sensor_Contrast2[]=
1063 {SEQUENCE_END, 0x00}
1066 static struct reginfo sensor_Contrast3[]=
1068 {SEQUENCE_END, 0x00}
1071 static struct reginfo sensor_Contrast4[]=
1073 {SEQUENCE_END, 0x00}
1077 static struct reginfo sensor_Contrast5[]=
1079 {SEQUENCE_END, 0x00}
1082 static struct reginfo sensor_Contrast6[]=
1084 {SEQUENCE_END, 0x00}
1086 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1087 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1091 #if CONFIG_SENSOR_Mirror
1092 static struct reginfo sensor_MirrorOn[]=
1094 {SEQUENCE_END, 0x00}
1097 static struct reginfo sensor_MirrorOff[]=
1099 {SEQUENCE_END, 0x00}
1101 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1103 #if CONFIG_SENSOR_Flip
1104 static struct reginfo sensor_FlipOn[]=
1106 {SEQUENCE_END, 0x00}
1109 static struct reginfo sensor_FlipOff[]=
1111 {SEQUENCE_END, 0x00}
1113 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1116 #if CONFIG_SENSOR_Scene
1117 static struct reginfo sensor_SceneAuto[] =
1119 {0x338C, 0xA102}, // MCU_ADDRESS
1120 {0x3390, 0x002F}, // MCU_DATA_0
1121 {0x338C, 0xA114}, // MCU_ADDRESS
1122 {0x3390, 0x0005}, // MCU_DATA_0
1123 {SEQUENCE_WAIT_MS, 20},
1124 {0x338C, 0xA103}, // MCU_ADDRESS
1125 {0x3390, 0x0005}, // MCU_DATA_0
1126 {SEQUENCE_END, 0x00}
1129 static struct reginfo sensor_SceneNight[] =
1131 {0x338C, 0xA102}, // MCU_ADDRESS
1132 {0x3390, 0x000F}, // MCU_DATA_0
1133 {SEQUENCE_WAIT_MS, 20},
1134 {0x338C, 0xA103}, // MCU_ADDRESS
1135 {0x3390, 0x0005}, // MCU_DATA_0
1136 {SEQUENCE_END, 0x00}
1138 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1141 #if CONFIG_SENSOR_DigitalZoom
1142 static struct reginfo sensor_Zoom0[] =
1144 {SEQUENCE_END, 0x00}
1147 static struct reginfo sensor_Zoom1[] =
1149 {SEQUENCE_END, 0x00}
1152 static struct reginfo sensor_Zoom2[] =
1154 {SEQUENCE_END, 0x00}
1158 static struct reginfo sensor_Zoom3[] =
1160 {SEQUENCE_END, 0x00}
1162 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
1164 static const struct v4l2_querymenu sensor_menus[] =
1166 #if CONFIG_SENSOR_WhiteBalance
1167 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1168 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1169 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1172 #if CONFIG_SENSOR_Effect
1173 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1174 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1177 #if CONFIG_SENSOR_Scene
1178 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1181 #if CONFIG_SENSOR_Flash
1182 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1183 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1187 static const struct v4l2_queryctrl sensor_controls[] =
1189 #if CONFIG_SENSOR_WhiteBalance
1191 .id = V4L2_CID_DO_WHITE_BALANCE,
1192 .type = V4L2_CTRL_TYPE_MENU,
1193 .name = "White Balance Control",
1201 #if CONFIG_SENSOR_Brightness
1203 .id = V4L2_CID_BRIGHTNESS,
1204 .type = V4L2_CTRL_TYPE_INTEGER,
1205 .name = "Brightness Control",
1213 #if CONFIG_SENSOR_Effect
1215 .id = V4L2_CID_EFFECT,
1216 .type = V4L2_CTRL_TYPE_MENU,
1217 .name = "Effect Control",
1225 #if CONFIG_SENSOR_Exposure
1227 .id = V4L2_CID_EXPOSURE,
1228 .type = V4L2_CTRL_TYPE_INTEGER,
1229 .name = "Exposure Control",
1237 #if CONFIG_SENSOR_Saturation
1239 .id = V4L2_CID_SATURATION,
1240 .type = V4L2_CTRL_TYPE_INTEGER,
1241 .name = "Saturation Control",
1249 #if CONFIG_SENSOR_Contrast
1251 .id = V4L2_CID_CONTRAST,
1252 .type = V4L2_CTRL_TYPE_INTEGER,
1253 .name = "Contrast Control",
1261 #if CONFIG_SENSOR_Mirror
1263 .id = V4L2_CID_HFLIP,
1264 .type = V4L2_CTRL_TYPE_BOOLEAN,
1265 .name = "Mirror Control",
1273 #if CONFIG_SENSOR_Flip
1275 .id = V4L2_CID_VFLIP,
1276 .type = V4L2_CTRL_TYPE_BOOLEAN,
1277 .name = "Flip Control",
1285 #if CONFIG_SENSOR_Scene
1287 .id = V4L2_CID_SCENE,
1288 .type = V4L2_CTRL_TYPE_MENU,
1289 .name = "Scene Control",
1297 #if CONFIG_SENSOR_DigitalZoom
1299 .id = V4L2_CID_ZOOM_RELATIVE,
1300 .type = V4L2_CTRL_TYPE_INTEGER,
1301 .name = "DigitalZoom Control",
1307 .id = V4L2_CID_ZOOM_ABSOLUTE,
1308 .type = V4L2_CTRL_TYPE_INTEGER,
1309 .name = "DigitalZoom Control",
1317 #if CONFIG_SENSOR_Focus
1319 .id = V4L2_CID_FOCUS_RELATIVE,
1320 .type = V4L2_CTRL_TYPE_INTEGER,
1321 .name = "Focus Control",
1327 .id = V4L2_CID_FOCUS_ABSOLUTE,
1328 .type = V4L2_CTRL_TYPE_INTEGER,
1329 .name = "Focus Control",
1333 .default_value = 125,
1336 .id = V4L2_CID_FOCUS_AUTO,
1337 .type = V4L2_CTRL_TYPE_BOOLEAN,
1338 .name = "Focus Control",
1344 .id = V4L2_CID_FOCUS_CONTINUOUS,
1345 .type = V4L2_CTRL_TYPE_BOOLEAN,
1346 .name = "Focus Control",
1354 #if CONFIG_SENSOR_Flash
1356 .id = V4L2_CID_FLASH,
1357 .type = V4L2_CTRL_TYPE_MENU,
1358 .name = "Flash Control",
1367 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1368 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1369 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1370 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1371 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1372 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1373 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1374 static int sensor_resume(struct soc_camera_device *icd);
1375 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1376 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1377 #if CONFIG_SENSOR_Effect
1378 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1380 #if CONFIG_SENSOR_WhiteBalance
1381 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1383 static int sensor_deactivate(struct i2c_client *client);
1384 static struct soc_camera_ops sensor_ops =
1386 .suspend = sensor_suspend,
1387 .resume = sensor_resume,
1388 .set_bus_param = sensor_set_bus_param,
1389 .query_bus_param = sensor_query_bus_param,
1390 .controls = sensor_controls,
1391 .menus = sensor_menus,
1392 .num_controls = ARRAY_SIZE(sensor_controls),
1393 .num_menus = ARRAY_SIZE(sensor_menus),
1395 /* only one fixed colorspace per pixelcode */
1396 struct sensor_datafmt {
1397 enum v4l2_mbus_pixelcode code;
1398 enum v4l2_colorspace colorspace;
1401 /* Find a data format by a pixel code in an array */
1402 static const struct sensor_datafmt *sensor_find_datafmt(
1403 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1407 for (i = 0; i < n; i++)
1408 if (fmt[i].code == code)
1414 static const struct sensor_datafmt sensor_colour_fmts[] = {
1415 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1416 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1418 enum sensor_work_state
1420 sensor_work_ready = 0,
1425 struct i2c_client *client;
1426 struct delayed_work dwork;
1427 enum sensor_work_state state;
1430 typedef struct sensor_info_priv_s
1444 unsigned char mirror; /* HFLIP */
1445 unsigned char flip; /* VFLIP */
1452 struct reginfo *winseqe_cur_addr;
1453 struct sensor_datafmt fmt;
1454 unsigned int enable;
1455 unsigned int funmodule_state;
1456 } sensor_info_priv_t;
1460 struct sensor_parameter
1462 unsigned short int preview_maxlines;
1463 unsigned short int preview_exposure;
1464 unsigned short int preview_line_width;
1465 unsigned short int preview_gain;
1467 unsigned short int capture_framerate;
1468 unsigned short int preview_framerate;
1473 struct v4l2_subdev subdev;
1474 struct i2c_client *client;
1475 sensor_info_priv_t info_priv;
1476 struct sensor_parameter parameter;
1477 struct workqueue_struct *sensor_wq;
1478 struct sensor_work sensor_wk;
1479 struct mutex wq_lock;
1480 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1481 #if CONFIG_SENSOR_I2C_NOSCHED
1482 atomic_t tasklock_cnt;
1484 struct rk29camera_platform_data *sensor_io_request;
1485 struct rk29camera_gpio_res *sensor_gpio_res;
1488 static struct sensor* to_sensor(const struct i2c_client *client)
1490 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1493 static int sensor_task_lock(struct i2c_client *client, int lock)
1495 #if CONFIG_SENSOR_I2C_NOSCHED
1497 struct sensor *sensor = to_sensor(client);
1500 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1501 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1502 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1506 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1507 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1508 goto sensor_task_lock_err;
1513 atomic_add(1, &sensor->tasklock_cnt);
1515 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1516 atomic_sub(1, &sensor->tasklock_cnt);
1518 if (atomic_read(&sensor->tasklock_cnt) == 0)
1523 sensor_task_lock_err:
1531 /* sensor register write */
1532 static int sensor_write(struct i2c_client *client, u16 reg, u16 val)
1536 struct i2c_msg msg[1];
1540 case SEQUENCE_WAIT_MS:
1546 case SEQUENCE_WAIT_US:
1552 case SEQUENCE_PROPERTY:
1559 buf[1] = reg & 0xFF;
1561 buf[3] = val & 0xFF;
1563 msg->addr = client->addr;
1564 msg->flags = client->flags;
1566 msg->len = sizeof(buf);
1567 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1568 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1573 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1574 err = i2c_transfer(client->adapter, msg, 1);
1579 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1588 /* sensor register read */
1589 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1593 struct i2c_msg msg[2];
1596 buf[1] = reg & 0xFF;
1598 msg[0].addr = client->addr;
1599 msg[0].flags = client->flags;
1601 msg[0].len = sizeof(buf);
1602 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1603 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1605 msg[1].addr = client->addr;
1606 msg[1].flags = client->flags|I2C_M_RD;
1609 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1610 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1614 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1615 err = i2c_transfer(client->adapter, msg, 2);
1621 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1629 /* write a array of registers */
1630 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1634 #if CONFIG_SENSOR_I2C_RDWRCHK
1639 if (sensor_task_lock(client, 1) < 0)
1640 goto sensor_write_array_end;
1641 while (regarray[i].reg != SEQUENCE_END)
1644 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1648 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1652 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1654 goto sensor_write_array_end;
1657 #if CONFIG_SENSOR_I2C_RDWRCHK
1658 sensor_read(client, regarray[i].reg, &valchk);
1659 if (valchk != regarray[i].val)
1660 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1667 sensor_write_array_end:
1668 sensor_task_lock(client,0);
1671 #if CONFIG_SENSOR_I2C_RDWRCHK
1672 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1680 while (regarray[i].reg != SEQUENCE_END)
1682 sensor_read(client, regarray[i].reg, &valchk);
1683 if (valchk != regarray[i].val)
1684 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1691 #if CONFIG_SENSOR_Focus
1693 static int sensor_af_single(struct i2c_client *client)
1698 sensor_af_single_end:
1702 static int sensor_af_const(struct i2c_client *client)
1706 sensor_af_const_end:
1710 static int sensor_af_zoneupdate(struct i2c_client *client)
1714 sensor_af_zoneupdate_end:
1718 static int sensor_af_init(struct i2c_client *client)
1726 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1728 struct soc_camera_link *icl = to_soc_camera_link(icd);
1731 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1734 case Sensor_PowerDown:
1736 if (icl->powerdown) {
1737 ret = icl->powerdown(icd->pdev, on);
1738 if (ret == RK29_CAM_IO_SUCCESS) {
1742 icl->reset(icd->pdev);
1744 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1746 goto sensor_power_end;
1753 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1754 struct sensor *sensor = to_sensor(client);
1756 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1757 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1763 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1771 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1773 struct i2c_client *client = v4l2_get_subdevdata(sd);
1774 struct soc_camera_device *icd = client->dev.platform_data;
1775 struct sensor *sensor = to_sensor(client);
1776 const struct v4l2_queryctrl *qctrl;
1777 const struct sensor_datafmt *fmt;
1779 #if (SENSOR_ID_REG != SEQUENCE_END)
1783 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1785 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1787 goto sensor_INIT_ERR;
1791 if (sensor_task_lock(client,1)<0)
1792 goto sensor_INIT_ERR;
1794 #if (SENSOR_RESET_REG != SEQUENCE_END)
1795 ret = sensor_write(client, SENSOR_RESET_REG, SENSOR_RESET_VAL);
1797 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1799 goto sensor_INIT_ERR;
1802 mdelay(5); //delay 5 microseconds
1805 /* check if it is an sensor sensor */
1806 #if (SENSOR_ID_REG != SEQUENCE_END)
1807 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1809 SENSOR_TR("read chip id failed\n");
1811 goto sensor_INIT_ERR;
1814 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1818 if (pid == SENSOR_ID) {
1819 sensor->model = SENSOR_V4L2_IDENT;
1821 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1823 goto sensor_INIT_ERR;
1826 ret = sensor_write_array(client, sensor_init_data);
1829 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1830 goto sensor_INIT_ERR;
1832 sensor_task_lock(client,0);
1833 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1834 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1835 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1836 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1837 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1838 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1840 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1842 goto sensor_INIT_ERR;
1844 sensor->info_priv.fmt = *fmt;
1846 /* sensor sensor information for initialization */
1847 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1849 sensor->info_priv.whiteBalance = qctrl->default_value;
1850 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1852 sensor->info_priv.brightness = qctrl->default_value;
1853 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1855 sensor->info_priv.effect = qctrl->default_value;
1856 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1858 sensor->info_priv.exposure = qctrl->default_value;
1860 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1862 sensor->info_priv.saturation = qctrl->default_value;
1863 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1865 sensor->info_priv.contrast = qctrl->default_value;
1866 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1868 sensor->info_priv.mirror = qctrl->default_value;
1869 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1871 sensor->info_priv.flip = qctrl->default_value;
1872 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1874 sensor->info_priv.scene = qctrl->default_value;
1875 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1877 sensor->info_priv.digitalzoom = qctrl->default_value;
1879 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1880 #if CONFIG_SENSOR_Focus
1882 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1884 sensor->info_priv.focus = qctrl->default_value;
1887 #if CONFIG_SENSOR_Flash
1888 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1890 sensor->info_priv.flash = qctrl->default_value;
1892 SENSOR_DG("\n%s..%s.. icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),((val == 0)?__FUNCTION__:"sensor_reinit"),icd->user_width,icd->user_height);
1896 sensor_task_lock(client,0);
1897 sensor_deactivate(client);
1900 static int sensor_deactivate(struct i2c_client *client)
1902 struct soc_camera_device *icd = client->dev.platform_data;
1904 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1906 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1907 sensor_task_lock(client, 1);
1908 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1910 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1911 icd->user_width = SENSOR_INIT_WIDTH;
1912 icd->user_height = SENSOR_INIT_HEIGHT;
1916 static struct reginfo sensor_power_down_sequence[]=
1920 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1923 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1925 if (pm_msg.event == PM_EVENT_SUSPEND) {
1926 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1927 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1929 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1932 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1934 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1939 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1946 static int sensor_resume(struct soc_camera_device *icd)
1950 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1952 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1956 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1960 static int sensor_set_bus_param(struct soc_camera_device *icd,
1961 unsigned long flags)
1967 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1969 struct soc_camera_link *icl = to_soc_camera_link(icd);
1970 unsigned long flags = SENSOR_BUS_PARAM;
1972 return soc_camera_apply_sensor_flags(icl, flags);
1974 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1976 struct i2c_client *client = v4l2_get_subdevdata(sd);
1977 struct soc_camera_device *icd = client->dev.platform_data;
1978 struct sensor *sensor = to_sensor(client);
1980 mf->width = icd->user_width;
1981 mf->height = icd->user_height;
1982 mf->code = sensor->info_priv.fmt.code;
1983 mf->colorspace = sensor->info_priv.fmt.colorspace;
1984 mf->field = V4L2_FIELD_NONE;
1988 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1992 if ((mf->width == 1024) && (mf->height == 768)) {
1994 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1996 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1998 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2000 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2005 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2009 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2013 if ((mf->width == 1280) && (mf->height == 720)) {
2015 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2020 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2023 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2025 struct i2c_client *client = v4l2_get_subdevdata(sd);
2026 struct sensor *sensor = to_sensor(client);
2027 const struct sensor_datafmt *fmt;
2028 struct reginfo *winseqe_set_addr=NULL;
2029 int ret = 0, set_w,set_h;
2031 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2032 ARRAY_SIZE(sensor_colour_fmts));
2035 goto sensor_s_fmt_end;
2038 if (sensor->info_priv.fmt.code != mf->code) {
2041 case V4L2_MBUS_FMT_YUYV8_2X8:
2043 winseqe_set_addr = sensor_ClrFmt_YUYV;
2046 case V4L2_MBUS_FMT_UYVY8_2X8:
2048 winseqe_set_addr = sensor_ClrFmt_UYVY;
2054 if (winseqe_set_addr != NULL) {
2055 sensor_write_array(client, winseqe_set_addr);
2056 sensor->info_priv.fmt.code = mf->code;
2057 sensor->info_priv.fmt.colorspace= mf->colorspace;
2058 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2060 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2066 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
2068 winseqe_set_addr = sensor_qcif;
2072 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
2074 winseqe_set_addr = sensor_qvga;
2078 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
2080 winseqe_set_addr = sensor_cif;
2084 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
2086 winseqe_set_addr = sensor_vga;
2090 else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
2092 winseqe_set_addr = sensor_svga;
2096 else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
2098 winseqe_set_addr = sensor_xga;
2102 else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
2104 winseqe_set_addr = sensor_720p;
2108 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
2110 winseqe_set_addr = sensor_sxga;
2114 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
2116 winseqe_set_addr = sensor_uxga;
2120 else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
2122 winseqe_set_addr = sensor_1080p;
2126 else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
2128 winseqe_set_addr = sensor_qxga;
2132 else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
2134 winseqe_set_addr = sensor_qsxga;
2139 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
2140 ret |= sensor_write_array(client, winseqe_set_addr);
2142 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2143 goto sensor_s_fmt_end;
2145 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
2146 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2147 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2149 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2153 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2154 ret |= sensor_write_array(client, sensor_Preview2Capture);
2156 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
2157 goto sensor_s_fmt_end;
2159 sensor->info_priv.capture_w = set_w;
2160 sensor->info_priv.capture_h = set_h;
2161 sensor->info_priv.snap2preview = true;
2162 } else if (sensor->info_priv.snap2preview == true) {
2163 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
2164 ret |= sensor_write_array(client, sensor_Capture2Preview);
2166 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
2167 goto sensor_s_fmt_end;
2169 sensor->info_priv.preview_w = mf->width;
2170 sensor->info_priv.preview_h = mf->height;
2171 sensor->info_priv.snap2preview = false;
2173 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2183 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2185 struct i2c_client *client = v4l2_get_subdevdata(sd);
2186 struct sensor *sensor = to_sensor(client);
2187 const struct sensor_datafmt *fmt;
2190 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2191 ARRAY_SIZE(sensor_colour_fmts));
2193 fmt = &sensor->info_priv.fmt;
2194 mf->code = fmt->code;
2197 if (mf->height > SENSOR_MAX_HEIGHT)
2198 mf->height = SENSOR_MAX_HEIGHT;
2199 else if (mf->height < SENSOR_MIN_HEIGHT)
2200 mf->height = SENSOR_MIN_HEIGHT;
2202 if (mf->width > SENSOR_MAX_WIDTH)
2203 mf->width = SENSOR_MAX_WIDTH;
2204 else if (mf->width < SENSOR_MIN_WIDTH)
2205 mf->width = SENSOR_MIN_WIDTH;
2207 mf->colorspace = fmt->colorspace;
2212 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2214 struct i2c_client *client = v4l2_get_subdevdata(sd);
2216 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2219 if (id->match.addr != client->addr)
2222 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2227 #if CONFIG_SENSOR_Brightness
2228 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2230 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2232 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2234 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2236 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2238 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2241 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2245 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2249 #if CONFIG_SENSOR_Effect
2250 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2252 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2254 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2256 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2258 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2260 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2263 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2267 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2271 #if CONFIG_SENSOR_Exposure
2272 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2274 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2276 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2278 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2280 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2282 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2285 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2289 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2293 #if CONFIG_SENSOR_Saturation
2294 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2296 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2298 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2300 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2302 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2304 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2307 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2311 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2315 #if CONFIG_SENSOR_Contrast
2316 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2318 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2320 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2322 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2324 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2326 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2329 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2333 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2337 #if CONFIG_SENSOR_Mirror
2338 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2340 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2342 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2344 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2346 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2348 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2351 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2355 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2359 #if CONFIG_SENSOR_Flip
2360 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2362 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2364 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2366 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2368 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2370 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2373 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2377 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2381 #if CONFIG_SENSOR_Scene
2382 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2384 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2386 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2388 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2390 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2392 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2395 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2399 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2403 #if CONFIG_SENSOR_WhiteBalance
2404 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2406 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2408 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2410 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2412 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2414 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2417 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2421 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2425 #if CONFIG_SENSOR_DigitalZoom
2426 static int sensor_set_digitalzoom(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);
2430 const struct v4l2_queryctrl *qctrl_info;
2431 int digitalzoom_cur, digitalzoom_total;
2433 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2437 digitalzoom_cur = sensor->info_priv.digitalzoom;
2438 digitalzoom_total = qctrl_info->maximum;
2440 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2442 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2446 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2448 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2452 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2454 *value = digitalzoom_total - digitalzoom_cur;
2457 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2459 *value = 0 - digitalzoom_cur;
2462 digitalzoom_cur += *value;
2464 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2466 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2468 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2471 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2478 #if CONFIG_SENSOR_Flash
2479 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2481 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2482 if (value == 3) { /* ddl@rock-chips.com: torch */
2483 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2485 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2487 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2491 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2495 #if CONFIG_SENSOR_Focus
2496 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2498 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2499 struct sensor *sensor = to_sensor(client);
2500 const struct v4l2_queryctrl *qctrl_info;
2503 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2507 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2508 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2510 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2513 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2517 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2518 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2521 sensor_set_focus_absolute_end:
2524 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2526 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2527 struct sensor *sensor = to_sensor(client);
2528 const struct v4l2_queryctrl *qctrl_info;
2531 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2535 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2536 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2538 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2541 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2545 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2546 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2548 sensor_set_focus_relative_end:
2552 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2554 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2555 struct sensor *sensor = to_sensor(client);
2558 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2561 case SENSOR_AF_MODE_AUTO:
2563 ret = sensor_af_single(client);
2567 case SENSOR_AF_MODE_MACRO:
2569 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2573 case SENSOR_AF_MODE_INFINITY:
2575 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2579 case SENSOR_AF_MODE_CONTINUOUS:
2581 ret = sensor_af_const(client);
2585 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2590 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2593 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2594 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2600 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2602 struct i2c_client *client = v4l2_get_subdevdata(sd);
2603 struct sensor *sensor = to_sensor(client);
2604 const struct v4l2_queryctrl *qctrl;
2606 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2610 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2616 case V4L2_CID_BRIGHTNESS:
2618 ctrl->value = sensor->info_priv.brightness;
2621 case V4L2_CID_SATURATION:
2623 ctrl->value = sensor->info_priv.saturation;
2626 case V4L2_CID_CONTRAST:
2628 ctrl->value = sensor->info_priv.contrast;
2631 case V4L2_CID_DO_WHITE_BALANCE:
2633 ctrl->value = sensor->info_priv.whiteBalance;
2636 case V4L2_CID_EXPOSURE:
2638 ctrl->value = sensor->info_priv.exposure;
2641 case V4L2_CID_HFLIP:
2643 ctrl->value = sensor->info_priv.mirror;
2646 case V4L2_CID_VFLIP:
2648 ctrl->value = sensor->info_priv.flip;
2659 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2661 struct i2c_client *client = v4l2_get_subdevdata(sd);
2662 struct sensor *sensor = to_sensor(client);
2663 struct soc_camera_device *icd = client->dev.platform_data;
2664 const struct v4l2_queryctrl *qctrl;
2667 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2671 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2677 #if CONFIG_SENSOR_Brightness
2678 case V4L2_CID_BRIGHTNESS:
2680 if (ctrl->value != sensor->info_priv.brightness)
2682 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2686 sensor->info_priv.brightness = ctrl->value;
2691 #if CONFIG_SENSOR_Exposure
2692 case V4L2_CID_EXPOSURE:
2694 if (ctrl->value != sensor->info_priv.exposure)
2696 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2700 sensor->info_priv.exposure = ctrl->value;
2705 #if CONFIG_SENSOR_Saturation
2706 case V4L2_CID_SATURATION:
2708 if (ctrl->value != sensor->info_priv.saturation)
2710 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2714 sensor->info_priv.saturation = ctrl->value;
2719 #if CONFIG_SENSOR_Contrast
2720 case V4L2_CID_CONTRAST:
2722 if (ctrl->value != sensor->info_priv.contrast)
2724 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2728 sensor->info_priv.contrast = ctrl->value;
2733 #if CONFIG_SENSOR_WhiteBalance
2734 case V4L2_CID_DO_WHITE_BALANCE:
2736 if (ctrl->value != sensor->info_priv.whiteBalance)
2738 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2742 sensor->info_priv.whiteBalance = ctrl->value;
2747 #if CONFIG_SENSOR_Mirror
2748 case V4L2_CID_HFLIP:
2750 if (ctrl->value != sensor->info_priv.mirror)
2752 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2754 sensor->info_priv.mirror = ctrl->value;
2759 #if CONFIG_SENSOR_Flip
2760 case V4L2_CID_VFLIP:
2762 if (ctrl->value != sensor->info_priv.flip)
2764 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2766 sensor->info_priv.flip = ctrl->value;
2777 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2779 const struct v4l2_queryctrl *qctrl;
2780 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2781 struct sensor *sensor = to_sensor(client);
2783 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2787 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2791 switch (ext_ctrl->id)
2793 case V4L2_CID_SCENE:
2795 ext_ctrl->value = sensor->info_priv.scene;
2798 case V4L2_CID_EFFECT:
2800 ext_ctrl->value = sensor->info_priv.effect;
2803 case V4L2_CID_ZOOM_ABSOLUTE:
2805 ext_ctrl->value = sensor->info_priv.digitalzoom;
2808 case V4L2_CID_ZOOM_RELATIVE:
2812 case V4L2_CID_FOCUS_ABSOLUTE:
2814 ext_ctrl->value = sensor->info_priv.focus;
2817 case V4L2_CID_FOCUS_RELATIVE:
2821 case V4L2_CID_FLASH:
2823 ext_ctrl->value = sensor->info_priv.flash;
2831 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2833 const struct v4l2_queryctrl *qctrl;
2834 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2835 struct sensor *sensor = to_sensor(client);
2838 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2842 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2847 switch (ext_ctrl->id)
2849 #if CONFIG_SENSOR_Scene
2850 case V4L2_CID_SCENE:
2852 if (ext_ctrl->value != sensor->info_priv.scene)
2854 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2856 sensor->info_priv.scene = ext_ctrl->value;
2861 #if CONFIG_SENSOR_Effect
2862 case V4L2_CID_EFFECT:
2864 if (ext_ctrl->value != sensor->info_priv.effect)
2866 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2868 sensor->info_priv.effect= ext_ctrl->value;
2873 #if CONFIG_SENSOR_DigitalZoom
2874 case V4L2_CID_ZOOM_ABSOLUTE:
2876 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2879 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2881 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2883 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2885 sensor->info_priv.digitalzoom += val_offset;
2887 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2892 case V4L2_CID_ZOOM_RELATIVE:
2894 if (ext_ctrl->value)
2896 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2898 sensor->info_priv.digitalzoom += ext_ctrl->value;
2900 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2905 #if CONFIG_SENSOR_Focus
2906 case V4L2_CID_FOCUS_ABSOLUTE:
2908 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2911 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2912 if (ext_ctrl->value == qctrl->minimum) {
2913 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2914 } else if (ext_ctrl->value == qctrl->maximum) {
2915 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2917 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2923 case V4L2_CID_FOCUS_RELATIVE:
2925 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2928 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2931 case V4L2_CID_FOCUS_AUTO:
2933 if (ext_ctrl->value == 1) {
2934 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2936 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2937 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2938 if (ext_ctrl->value == 0)
2939 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2943 case V4L2_CID_FOCUS_CONTINUOUS:
2945 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2946 if (ext_ctrl->value == 1) {
2947 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2949 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2952 if (ext_ctrl->value == 0)
2953 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2958 #if CONFIG_SENSOR_Flash
2959 case V4L2_CID_FLASH:
2961 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2963 sensor->info_priv.flash = ext_ctrl->value;
2965 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2976 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2978 struct i2c_client *client = v4l2_get_subdevdata(sd);
2979 struct soc_camera_device *icd = client->dev.platform_data;
2980 int i, error_cnt=0, error_idx=-1;
2983 for (i=0; i<ext_ctrl->count; i++) {
2984 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2991 error_idx = ext_ctrl->count;
2993 if (error_idx != -1) {
2994 ext_ctrl->error_idx = error_idx;
3001 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3003 struct i2c_client *client = v4l2_get_subdevdata(sd);
3004 struct soc_camera_device *icd = client->dev.platform_data;
3005 int i, error_cnt=0, error_idx=-1;
3007 for (i=0; i<ext_ctrl->count; i++) {
3008 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3015 error_idx = ext_ctrl->count;
3017 if (error_idx != -1) {
3018 ext_ctrl->error_idx = error_idx;
3025 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
3027 struct i2c_client *client = v4l2_get_subdevdata(sd);
3028 struct sensor *sensor = to_sensor(client);
3031 sensor->info_priv.enable = 1;
3032 } else if (enable == 0) {
3033 sensor->info_priv.enable = 0;
3039 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3040 * this wasn't our capture interface, so, we wait for the right one */
3041 static int sensor_video_probe(struct soc_camera_device *icd,
3042 struct i2c_client *client)
3045 #if (SENSOR_ID_REG != SEQUENCE_END)
3049 struct sensor *sensor = to_sensor(client);
3051 /* We must have a parent by now. And it cannot be a wrong one.
3052 * So this entire test is completely redundant. */
3053 if (!icd->dev.parent ||
3054 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3057 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3059 goto sensor_video_probe_err;
3063 #if (SENSOR_RESET_REG != SEQUENCE_END)
3064 ret = sensor_write(client, SENSOR_RESET_REG, SENSOR_RESET_VAL);
3066 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
3068 goto sensor_INIT_ERR;
3071 mdelay(5); //delay 5 microseconds
3074 /* check if it is an sensor sensor */
3075 #if (SENSOR_ID_REG != SEQUENCE_END)
3076 ret = sensor_read(client, SENSOR_ID_REG, &pid);
3078 SENSOR_TR("read chip id failed\n");
3080 goto sensor_video_probe_err;
3083 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
3088 if (pid == SENSOR_ID) {
3089 sensor->model = SENSOR_V4L2_IDENT;
3091 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3093 goto sensor_video_probe_err;
3099 sensor_video_probe_err:
3102 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3104 struct i2c_client *client = v4l2_get_subdevdata(sd);
3105 struct soc_camera_device *icd = client->dev.platform_data;
3106 struct sensor *sensor = to_sensor(client);
3108 #if CONFIG_SENSOR_Flash
3112 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3115 case RK29_CAM_SUBDEV_DEACTIVATE:
3117 sensor_deactivate(client);
3120 case RK29_CAM_SUBDEV_IOREQUEST:
3122 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
3123 if (sensor->sensor_io_request != NULL) {
3124 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
3125 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
3126 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
3127 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
3128 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
3129 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
3132 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3134 goto sensor_ioctl_end;
3136 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3138 #if CONFIG_SENSOR_Flash
3139 if (sensor->sensor_gpio_res) {
3140 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3141 for (i = 0; i < icd->ops->num_controls; i++) {
3142 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3143 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3146 sensor->info_priv.flash = 0xff;
3147 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3155 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3163 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3164 enum v4l2_mbus_pixelcode *code)
3166 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3169 *code = sensor_colour_fmts[index].code;
3172 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3173 .init = sensor_init,
3174 .g_ctrl = sensor_g_control,
3175 .s_ctrl = sensor_s_control,
3176 .g_ext_ctrls = sensor_g_ext_controls,
3177 .s_ext_ctrls = sensor_s_ext_controls,
3178 .g_chip_ident = sensor_g_chip_ident,
3179 .ioctl = sensor_ioctl,
3182 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3183 .s_mbus_fmt = sensor_s_fmt,
3184 .g_mbus_fmt = sensor_g_fmt,
3185 .try_mbus_fmt = sensor_try_fmt,
3186 .enum_mbus_fmt = sensor_enum_fmt,
3189 static struct v4l2_subdev_ops sensor_subdev_ops = {
3190 .core = &sensor_subdev_core_ops,
3191 .video = &sensor_subdev_video_ops,
3194 static int sensor_probe(struct i2c_client *client,
3195 const struct i2c_device_id *did)
3197 struct sensor *sensor;
3198 struct soc_camera_device *icd = client->dev.platform_data;
3199 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3200 struct soc_camera_link *icl;
3203 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3205 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3209 icl = to_soc_camera_link(icd);
3211 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3215 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3216 dev_warn(&adapter->dev,
3217 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3221 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3225 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3227 /* Second stage probe - when a capture adapter is there */
3228 icd->ops = &sensor_ops;
3229 sensor->info_priv.fmt = sensor_colour_fmts[0];
3230 #if CONFIG_SENSOR_I2C_NOSCHED
3231 atomic_set(&sensor->tasklock_cnt,0);
3234 ret = sensor_video_probe(icd, client);
3237 i2c_set_clientdata(client, NULL);
3241 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3245 static int sensor_remove(struct i2c_client *client)
3247 struct sensor *sensor = to_sensor(client);
3248 struct soc_camera_device *icd = client->dev.platform_data;
3251 i2c_set_clientdata(client, NULL);
3252 client->driver = NULL;
3258 static const struct i2c_device_id sensor_id[] = {
3259 {SENSOR_NAME_STRING(), 0 },
3262 MODULE_DEVICE_TABLE(i2c, sensor_id);
3264 static struct i2c_driver sensor_i2c_driver = {
3266 .name = SENSOR_NAME_STRING(),
3268 .probe = sensor_probe,
3269 .remove = sensor_remove,
3270 .id_table = sensor_id,
3273 static int __init sensor_mod_init(void)
3275 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3276 return i2c_add_driver(&sensor_i2c_driver);
3279 static void __exit sensor_mod_exit(void)
3281 i2c_del_driver(&sensor_i2c_driver);
3284 device_initcall_sync(sensor_mod_init);
3285 module_exit(sensor_mod_exit);
3287 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3288 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3289 MODULE_LICENSE("GPL");