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/rk_camera.h>
23 #include <linux/vmalloc.h>
27 module_param(debug, int, S_IRUGO|S_IWUSR);
29 #define dprintk(level, fmt, arg...) do { \
31 printk(KERN_WARNING fmt , ## arg); } while (0)
33 #define SENSOR_TR(format, ...) printk(KERN_ERR format, ## __VA_ARGS__)
34 #define SENSOR_DG(format, ...) dprintk(1, format, ## __VA_ARGS__)
36 #define _CONS(a,b) a##b
37 #define CONS(a,b) _CONS(a,b)
40 #define _STR(x) __STR(x)
41 #define STR(x) _STR(x)
43 #define MIN(x,y) ((x<y) ? x: y)
44 #define MAX(x,y) ((x>y) ? x: y)
46 /* Sensor Driver Configuration */
47 #define SENSOR_NAME RK_CAM_SENSOR_MT9D112
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9D112
49 #define SENSOR_ID 0x1580
50 #define SENSOR_ID_REG 0x3000
51 #define SENSOR_RESET_REG SEQUENCE_END
52 #define SENSOR_RESET_VAL 0x00
53 #define SENSOR_MIN_WIDTH 320
54 #define SENSOR_MIN_HEIGHT 240
55 #define SENSOR_MAX_WIDTH 1600
56 #define SENSOR_MAX_HEIGHT 1200
57 #define SENSOR_INIT_WIDTH sensor_init_width /* Sensor pixel size for sensor_init_data array */
58 #define SENSOR_INIT_HEIGHT sensor_init_height
59 #define SENSOR_INIT_WINSEQADR sensor_init_winseq_p
60 #define SENSOR_INIT_PIXFMT sensor_init_pixelcode
61 #define SENSOR_BUS_PARAM sensor_init_busparam
63 #define CONFIG_SENSOR_WhiteBalance 1
64 #define CONFIG_SENSOR_Brightness 0
65 #define CONFIG_SENSOR_Contrast 0
66 #define CONFIG_SENSOR_Saturation 0
67 #define CONFIG_SENSOR_Effect 1
68 #define CONFIG_SENSOR_Scene 1
69 #define CONFIG_SENSOR_DigitalZoom 0
70 #define CONFIG_SENSOR_Exposure 0
71 #define CONFIG_SENSOR_Flash 0
72 #define CONFIG_SENSOR_Mirror 0
73 #define CONFIG_SENSOR_Flip 0
74 #define CONFIG_SENSOR_Focus 0
77 #define CONFIG_SENSOR_I2C_SPEED 250000 /* Hz */
78 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
79 #define CONFIG_SENSOR_I2C_NOSCHED 0
80 #define CONFIG_SENSOR_I2C_RDWRCHK 0
82 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
83 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
84 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
85 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
86 #define COLOR_TEMPERATURE_OFFICE_DN 3500
87 #define COLOR_TEMPERATURE_OFFICE_UP 5000
88 #define COLOR_TEMPERATURE_HOME_DN 2500
89 #define COLOR_TEMPERATURE_HOME_UP 3500
91 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
92 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
94 #define SENSOR_AF_IS_ERR (0x00<<0)
95 #define SENSOR_AF_IS_OK (0x01<<0)
96 #define SENSOR_INIT_IS_ERR (0x00<<28)
97 #define SENSOR_INIT_IS_OK (0x01<<28)
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
107 #define SENSOR_CCM_ONLY
108 static s32 sensor_init_width = 0;
109 static s32 sensor_init_height = 0;
110 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);
111 static enum v4l2_mbus_pixelcode sensor_init_pixelcode = V4L2_MBUS_FMT_YUYV8_2X8;
112 static struct reginfo* sensor_init_data_p = NULL;
113 static struct reginfo* sensor_init_winseq_p = NULL;
114 static struct reginfo* sensor_init_winseq_board = NULL;
115 /* init 640X480 VGA */
116 static struct reginfo sensor_init_data[] =
118 {0x301A, 0x0ACC}, // RESET_REGISTER
119 {0x3202, 0x0008}, // STANDBY_CONTROL
120 {SEQUENCE_WAIT_MS, 10},
121 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
122 {0x341C, 0x0218}, // PLL_DIVIDERS1
123 {SEQUENCE_WAIT_MS, 1},
124 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
125 {0x341E, 0x8F08}, // PLL_CLK_IN_CONTROL
126 {0x3044, 0x0540}, // DARK_CONTROL
127 {0x3216, 0x02CF}, // INTERNAL_CLOCK_CONTROL
128 {0x321C, 0x0402}, // OF_CONTROL_STATUS
129 {0x3212, 0x0001}, // FACTORY_BYPASS
130 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
131 {0x341C, 0x0120}, // PLL_DIVIDERS1
132 {0x341E, 0x8F09}, // PLL_CLK_IN_CONTROL
133 {0x341E, 0x8F08}, // PLL_CLK_IN_CONTROL
134 {0x3044, 0x0540}, // DARK_CONTROL
135 {0x3216, 0x02CF}, // INTERNAL_CLOCK_CONTROL
136 {0x321C, 0x0402}, // OF_CONTROL_STATUS
137 {0x3212, 0x0001}, // FACTORY_BYPASS//¹©Æ·¸ÉÈųÌÐòÀûÓÃ֮ǰµÄ07005
138 #ifdef SENSOR_CCM_ONLY
157 {0x338C, 0x2703}, // MCU_ADDRESS
158 {0x3390, 0x0140}, // MCU_DATA_0
159 {0x338C, 0x2705}, // MCU_ADDRESS
160 {0x3390, 0x00F0}, // MCU_DATA_0
161 {0x338C, 0x2707}, // MCU_ADDRESS
162 {0x3390, 0x0640}, // MCU_DATA_0
163 {0x338C, 0x2709}, // MCU_ADDRESS
164 {0x3390, 0x04B0}, // MCU_DATA_0
165 {0x338C, 0x270D}, // MCU_ADDRESS
166 {0x3390, 0x0000}, // MCU_DATA_0
167 {0x338C, 0x270F}, // MCU_ADDRESS
168 {0x3390, 0x0000}, // MCU_DATA_0
169 {0x338C, 0x2711}, // MCU_ADDRESS
170 {0x3390, 0x04BD}, // MCU_DATA_0
171 {0x338C, 0x2713}, // MCU_ADDRESS
172 {0x3390, 0x064D}, // MCU_DATA_0
173 {0x338C, 0x2715}, // MCU_ADDRESS
174 {0x3390, 0x0022}, // MCU_DATA_0
176 {0x338C, 0x2717}, // MCU_ADDRESS
177 {0x3390, 0x2111}, // MCU_DATA_0
178 {0x338C, 0x2719}, // MCU_ADDRESS
179 {0x3390, 0x046C}, // MCU_DATA_0
180 {0x338C, 0x271B}, // MCU_ADDRESS
181 {0x3390, 0x024F}, // MCU_DATA_0
182 {0x338C, 0x271D}, // MCU_ADDRESS
183 {0x3390, 0x0102}, // MCU_DATA_0
184 {0x338C, 0x271F}, // MCU_ADDRESS
185 {0x3390, 0x0279}, // MCU_DATA_0
186 {0x338C, 0x2721}, // MCU_ADDRESS
187 {0x3390, 0x0155}, // MCU_DATA_0
188 {0x338C, 0x2723}, // MCU_ADDRESS
189 {0x3390, 0x0293}, // MCU_DATA_0
190 {0x338C, 0x2725}, // MCU_ADDRESS
191 {0x3390, 0x0824}, // MCU_DATA_0
192 {0x338C, 0x2727}, // MCU_ADDRESS
193 {0x3390, 0x2020}, // MCU_DATA_0
194 {0x338C, 0x2729}, // MCU_ADDRESS
195 {0x3390, 0x2020}, // MCU_DATA_0
196 {0x338C, 0x272B}, // MCU_ADDRESS
197 {0x3390, 0x1020}, // MCU_DATA_0
198 {0x338C, 0x272D}, // MCU_ADDRESS
199 {0x3390, 0x2007}, // MCU_DATA_0
200 {0x338C, 0x272F}, // MCU_ADDRESS
201 {0x3390, 0x0004}, // MCU_DATA_0
202 {0x338C, 0x2731}, // MCU_ADDRESS
203 {0x3390, 0x0004}, // MCU_DATA_0
204 {0x338C, 0x2733}, // MCU_ADDRESS
205 {0x3390, 0x04BB}, // MCU_DATA_0
206 {0x338C, 0x2735}, // MCU_ADDRESS
207 {0x3390, 0x064B}, // MCU_DATA_0
208 {0x338C, 0x2737}, // MCU_ADDRESS
209 {0x3390, 0x0000}, // MCU_DATA_0
210 {0x338C, 0x2739}, // MCU_ADDRESS
211 {0x3390, 0x2111}, // MCU_DATA_0
212 {0x338C, 0x273B}, // MCU_ADDRESS
213 {0x3390, 0x0024}, // MCU_DATA_0
214 {0x338C, 0x273D}, // MCU_ADDRESS
215 {0x3390, 0x0120}, // MCU_DATA_0
216 {0x338C, 0x273F}, // MCU_ADDRESS
217 {0x3390, 0x00A4}, // MCU_DATA_0
218 {0x338C, 0x2741}, // MCU_ADDRESS
219 {0x3390, 0x0169}, // MCU_DATA_0
220 {0x338C, 0x2743}, // MCU_ADDRESS
221 {0x3390, 0x00A4}, // MCU_DATA_0
222 {0x338C, 0x2745}, // MCU_ADDRESS
223 {0x3390, 0x04ED}, // MCU_DATA_0
224 {0x338C, 0x2747}, // MCU_ADDRESS
225 {0x3390, 0x0824}, // MCU_DATA_0
226 {0x338C, 0x2751}, // MCU_ADDRESS
227 {0x3390, 0x0000}, // MCU_DATA_0
228 {0x338C, 0x2753}, // MCU_ADDRESS
229 {0x3390, 0x0320}, // MCU_DATA_0
230 {0x338C, 0x2755}, // MCU_ADDRESS
231 {0x3390, 0x0000}, // MCU_DATA_0
232 {0x338C, 0x2757}, // MCU_ADDRESS
233 {0x3390, 0x0258}, // MCU_DATA_0
234 {0x338C, 0x275F}, // MCU_ADDRESS
235 {0x3390, 0x0000}, // MCU_DATA_0
236 {0x338C, 0x2761}, // MCU_ADDRESS
237 {0x3390, 0x0640}, // MCU_DATA_0
238 {0x338C, 0x2763}, // MCU_ADDRESS
239 {0x3390, 0x0000}, // MCU_DATA_0
240 {0x338C, 0x2765}, // MCU_ADDRESS
241 {0x3390, 0x04B0}, // MCU_DATA_0
242 {0x338C, 0x222E}, // MCU_ADDRESS
243 {0x3390, 0x0060}, // MCU_DATA_0
244 {0x338C, 0xA408}, // MCU_ADDRESS
245 {0x3390, 0x0017}, // MCU_DATA_0
246 {0x338C, 0xA409}, // MCU_ADDRESS
247 {0x3390, 0x001A}, // MCU_DATA_0
248 {0x338C, 0xA40A}, // MCU_ADDRESS
249 {0x3390, 0x001B}, // MCU_DATA_0
250 {0x338C, 0xA40B}, // MCU_ADDRESS
251 {0x3390, 0x001E}, // MCU_DATA_0
252 {0x338C, 0x2411}, // MCU_ADDRESS
253 {0x3390, 0x0060}, // MCU_DATA_0
254 {0x338C, 0x2413}, // MCU_ADDRESS
255 {0x3390, 0x0073}, // MCU_DATA_0
256 {0x338C, 0x2415}, // MCU_ADDRESS
257 {0x3390, 0x0060}, // MCU_DATA_0
258 {0x338C, 0x2417}, // MCU_ADDRESS
259 {0x3390, 0x0073}, // MCU_DATA_0
260 {0x338C, 0xA40D}, // MCU_ADDRESS
261 {0x3390, 0x0002}, // MCU_DATA_0
262 {0x338C, 0xA410}, // MCU_ADDRESS
263 {0x3390, 0x0001}, // MCU_DATA_0
264 {0x338C, 0xA103}, // MCU_ADDRESS
265 {0x3390, 0x0006}, // MCU_DATA_0
266 {0x338C, 0xA103}, // MCU_ADDRESS
267 {0x3390, 0x0005}, // MCU_DATA_0
268 {0x338C, 0x2703}, // MCU_ADDRESS
269 {0x3390, 0x0140}, // MCU_DATA_0
270 {0x338C, 0x2705}, // MCU_ADDRESS
271 {0x3390, 0x00F0}, // MCU_DATA_0
272 {0x338C, 0x2707}, // MCU_ADDRESS
273 {0x3390, 0x0640}, // MCU_DATA_0
274 {0x338C, 0x2709}, // MCU_ADDRESS
275 {0x3390, 0x04B0}, // MCU_DATA_0
276 {0x338C, 0x270D}, // MCU_ADDRESS
277 {0x3390, 0x0000}, // MCU_DATA_0
278 {0x338C, 0x270F}, // MCU_ADDRESS
279 {0x3390, 0x0000}, // MCU_DATA_0
280 {0x338C, 0x2711}, // MCU_ADDRESS
281 {0x3390, 0x04BD}, // MCU_DATA_0
282 {0x338C, 0x2713}, // MCU_ADDRESS
283 {0x3390, 0x064D}, // MCU_DATA_0
284 {0x338C, 0x2715}, // MCU_ADDRESS
285 {0x3390, 0x0022}, // MCU_DATA_0
286 {0x338C, 0x2717}, // MCU_ADDRESS
287 {0x3390, 0x2111}, // MCU_DATA_0
288 {0x338C, 0x2719}, // MCU_ADDRESS
289 {0x3390, 0x046C}, // MCU_DATA_0
290 {0x338C, 0x271B}, // MCU_ADDRESS
291 {0x3390, 0x024F}, // MCU_DATA_0
292 {0x338C, 0x271D}, // MCU_ADDRESS
293 {0x3390, 0x0102}, // MCU_DATA_0
294 {0x338C, 0x271F}, // MCU_ADDRESS
295 {0x3390, 0x0279}, // MCU_DATA_0
296 {0x338C, 0x2721}, // MCU_ADDRESS
297 {0x3390, 0x0155}, // MCU_DATA_0
298 {0x338C, 0x2723}, // MCU_ADDRESS
299 {0x3390, 0x0293}, // MCU_DATA_0
300 {0x338C, 0x2725}, // MCU_ADDRESS
301 {0x3390, 0x0824}, // MCU_DATA_0
302 {0x338C, 0x2727}, // MCU_ADDRESS
303 {0x3390, 0x2020}, // MCU_DATA_0
304 {0x338C, 0x2729}, // MCU_ADDRESS
305 {0x3390, 0x2020}, // MCU_DATA_0
306 {0x338C, 0x272B}, // MCU_ADDRESS
307 {0x3390, 0x1020}, // MCU_DATA_0
308 {0x338C, 0x272D}, // MCU_ADDRESS
309 {0x3390, 0x2007}, // MCU_DATA_0
310 {0x338C, 0x272F}, // MCU_ADDRESS
311 {0x3390, 0x0004}, // MCU_DATA_0
312 {0x338C, 0x2731}, // MCU_ADDRESS
313 {0x3390, 0x0004}, // MCU_DATA_0
314 {0x338C, 0x2733}, // MCU_ADDRESS
315 {0x3390, 0x04BB}, // MCU_DATA_0
316 {0x338C, 0x2735}, // MCU_ADDRESS
317 {0x3390, 0x064B}, // MCU_DATA_0
318 {0x338C, 0x2737}, // MCU_ADDRESS
319 {0x3390, 0x0000}, // MCU_DATA_0
320 {0x338C, 0x2739}, // MCU_ADDRESS
321 {0x3390, 0x2111}, // MCU_DATA_0
322 {0x338C, 0x273B}, // MCU_ADDRESS
323 {0x3390, 0x0024}, // MCU_DATA_0
324 {0x338C, 0x273D}, // MCU_ADDRESS
325 {0x3390, 0x0120}, // MCU_DATA_0
326 {0x338C, 0x273F}, // MCU_ADDRESS
327 {0x3390, 0x00A4}, // MCU_DATA_0
328 {0x338C, 0x2741}, // MCU_ADDRESS
329 {0x3390, 0x0169}, // MCU_DATA_0
330 {0x338C, 0x2743}, // MCU_ADDRESS
331 {0x3390, 0x00A4}, // MCU_DATA_0
332 {0x338C, 0x2745}, // MCU_ADDRESS
333 {0x3390, 0x04ED}, // MCU_DATA_0
334 {0x338C, 0x2747}, // MCU_ADDRESS
335 {0x3390, 0x0824}, // MCU_DATA_0
336 {0x338C, 0x2751}, // MCU_ADDRESS
337 {0x3390, 0x0000}, // MCU_DATA_0
338 {0x338C, 0x2753}, // MCU_ADDRESS
339 {0x3390, 0x0320}, // MCU_DATA_0
340 {0x338C, 0x2755}, // MCU_ADDRESS
341 {0x3390, 0x0000}, // MCU_DATA_0
342 {0x338C, 0x2757}, // MCU_ADDRESS
343 {0x3390, 0x0258}, // MCU_DATA_0
344 {0x338C, 0x275F}, // MCU_ADDRESS
345 {0x3390, 0x0000}, // MCU_DATA_0
346 {0x338C, 0x2761}, // MCU_ADDRESS
347 {0x3390, 0x0640}, // MCU_DATA_0
348 {0x338C, 0x2763}, // MCU_ADDRESS
349 {0x3390, 0x0000}, // MCU_DATA_0
350 {0x338C, 0x2765}, // MCU_ADDRESS
351 {0x3390, 0x04B0}, // MCU_DATA_0
352 {0x338C, 0x222E}, // MCU_ADDRESS
353 {0x3390, 0x0060}, // MCU_DATA_0
354 {0x338C, 0xA408}, // MCU_ADDRESS
355 {0x3390, 0x0017}, // MCU_DATA_0
356 {0x338C, 0xA409}, // MCU_ADDRESS
357 {0x3390, 0x001A}, // MCU_DATA_0
358 {0x338C, 0xA40A}, // MCU_ADDRESS
359 {0x3390, 0x001B}, // MCU_DATA_0
360 {0x338C, 0xA40B}, // MCU_ADDRESS
361 {0x3390, 0x001E}, // MCU_DATA_0
362 {0x338C, 0x2411}, // MCU_ADDRESS
363 {0x3390, 0x0060}, // MCU_DATA_0
364 {0x338C, 0x2413}, // MCU_ADDRESS
365 {0x3390, 0x0073}, // MCU_DATA_0
366 {0x338C, 0x2415}, // MCU_ADDRESS
367 {0x3390, 0x0060}, // MCU_DATA_0
368 {0x338C, 0x2417}, // MCU_ADDRESS
369 {0x3390, 0x0073}, // MCU_DATA_0
370 {0x338C, 0xA40D}, // MCU_ADDRESS
371 {0x3390, 0x0002}, // MCU_DATA_0
372 {0x338C, 0xA410}, // MCU_ADDRESS
373 {0x3390, 0x0001}, // MCU_DATA_0
374 {0x338C, 0xA103}, // MCU_ADDRESS
375 {0x3390, 0x0006}, // MCU_DATA_0
376 {SEQUENCE_WAIT_MS, 100},
377 {0x338C, 0xA103}, // MCU_ADDRESS
378 {0x3390, 0x0005}, // MCU_DATA_0
379 {SEQUENCE_WAIT_MS, 100},
382 //[Lens Correction 01/04/07 20:07:28]
383 {0x34CE, 0x01A0}, //LENS_CORRECTION_CONTROL
384 {0x34D0, 0x6532}, //ZONE_BOUNDS_X1_X2
385 {0x34D2, 0x3297}, //ZONE_BOUNDS_X0_X3
386 {0x34D4, 0x9664}, //ZONE_BOUNDS_X4_X5
387 {0x34D6, 0x4B25}, //ZONE_BOUNDS_Y1_Y2
388 {0x34D8, 0x2670}, //ZONE_BOUNDS_Y0_Y3
389 {0x34DA, 0x724C}, //ZONE_BOUNDS_Y4_Y5
390 {0x34DC, 0xFF01}, //CENTER_OFFSET
391 {0x34DE, 0x011F}, //FX_RED
392 {0x34E6, 0x00B3}, //FY_RED
393 {0x34EE, 0x0D8F}, //DF_DX_RED
394 {0x34F6, 0x0D6E}, //DF_DY_RED
395 {0x3500, 0xF51C}, //SECOND_DERIV_ZONE_0_RED
396 {0x3508, 0xFEF8}, //SECOND_DERIV_ZONE_1_RED
397 {0x3510, 0x212D}, //SECOND_DERIV_ZONE_2_RED
398 {0x3518, 0x212B}, //SECOND_DERIV_ZONE_3_RED
399 {0x3520, 0x1F2A}, //SECOND_DERIV_ZONE_4_RED
400 {0x3528, 0x2934}, //SECOND_DERIV_ZONE_5_RED
401 {0x3530, 0x17DB}, //SECOND_DERIV_ZONE_6_RED
402 {0x3538, 0xE7D6}, //SECOND_DERIV_ZONE_7_RED
403 {0x354C, 0x07C6}, //K_FACTOR_IN_K_FX_FY_R_TL
404 {0x3544, 0x07FF}, //K_FACTOR_IN_K_FX_FY_R_TR
405 {0x355C, 0x051C}, //K_FACTOR_IN_K_FX_FY_R_BL
406 {0x3554, 0x07FF}, //K_FACTOR_IN_K_FX_FY_R_BR
407 {0x34E0, 0x0137}, //FX_GREEN
408 {0x34E8, 0x00A8}, //FY_GREEN
409 {0x34F0, 0x0E3E}, //DF_DX_GREEN
410 {0x34F8, 0x0DCB}, //DF_DY_GREEN
411 {0x3502, 0xF20A}, //SECOND_DERIV_ZONE_0_GREEN
412 {0x350A, 0xFBE1}, //SECOND_DERIV_ZONE_1_GREEN
413 {0x3512, 0x1C26}, //SECOND_DERIV_ZONE_2_GREEN
414 {0x351A, 0x232B}, //SECOND_DERIV_ZONE_3_GREEN
415 {0x3522, 0x312E}, //SECOND_DERIV_ZONE_4_GREEN
416 {0x352A, 0x2121}, //SECOND_DERIV_ZONE_5_GREEN
417 {0x3532, 0xF106}, //SECOND_DERIV_ZONE_6_GREEN
418 {0x353A, 0x0C0D}, //SECOND_DERIV_ZONE_7_GREEN
419 {0x354E, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G1_TL
420 {0x3546, 0x0638}, //K_FACTOR_IN_K_FX_FY_G1_TR
421 {0x355E, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G1_BL
422 {0x3556, 0x0155}, //K_FACTOR_IN_K_FX_FY_G1_BR
423 {0x34E4, 0x0107}, //FX_BLUE
424 {0x34EC, 0x0079}, //FY_BLUE
425 {0x34F4, 0x0E19}, //DF_DX_BLUE
426 {0x34FC, 0x0D35}, //DF_DY_BLUE
427 {0x3506, 0x111C}, //SECOND_DERIV_ZONE_0_BLUE
428 {0x350E, 0x02E6}, //SECOND_DERIV_ZONE_1_BLUE
429 {0x3516, 0x2521}, //SECOND_DERIV_ZONE_2_BLUE
430 {0x351E, 0x2620}, //SECOND_DERIV_ZONE_3_BLUE
431 {0x3526, 0x1A25}, //SECOND_DERIV_ZONE_4_BLUE
432 {0x352E, 0x0B1D}, //SECOND_DERIV_ZONE_5_BLUE
433 {0x3536, 0xFD03}, //SECOND_DERIV_ZONE_6_BLUE
434 {0x353E, 0xB315}, //SECOND_DERIV_ZONE_7_BLUE
435 {0x3552, 0x06D0}, //K_FACTOR_IN_K_FX_FY_B_TL
436 {0x354A, 0x03FF}, //K_FACTOR_IN_K_FX_FY_B_TR
437 {0x3562, 0x07FF}, //K_FACTOR_IN_K_FX_FY_B_BL
438 {0x355A, 0x057B}, //K_FACTOR_IN_K_FX_FY_B_BR
439 {0x34E2, 0x011E}, //FX_GREEN2
440 {0x34EA, 0x008A}, //FY_GREEN2
441 {0x34F2, 0x0D6E}, //DF_DX_GREEN2
442 {0x34FA, 0x0D7F}, //DF_DY_GREEN2
443 {0x3504, 0xF822}, //SECOND_DERIV_ZONE_0_GREEN2
444 {0x350C, 0x0DFC}, //SECOND_DERIV_ZONE_1_GREEN2
445 {0x3514, 0x1F25}, //SECOND_DERIV_ZONE_2_GREEN2
446 {0x351C, 0x3032}, //SECOND_DERIV_ZONE_3_GREEN2
447 {0x3524, 0x2628}, //SECOND_DERIV_ZONE_4_GREEN2
448 {0x352C, 0x1523}, //SECOND_DERIV_ZONE_5_GREEN2
449 {0x3534, 0xFADF}, //SECOND_DERIV_ZONE_6_GREEN2
450 {0x353C, 0xDEF7}, //SECOND_DERIV_ZONE_7_GREEN2
451 {0x3550, 0x0109}, //K_FACTOR_IN_K_FX_FY_G2_TL
452 {0x3548, 0x0638}, //K_FACTOR_IN_K_FX_FY_G2_TR
453 {0x3560, 0x0638}, //K_FACTOR_IN_K_FX_FY_G2_BL
454 {0x3558, 0x07FF}, //K_FACTOR_IN_K_FX_FY_G2_BR
455 {0x3540, 0x0000}, //X2_FACTORS
456 {0x3542, 0x0000}, //GLOBAL_OFFSET_FXY_FUNCTION
457 {0x3210, 0x01FC}, // COLOR_PIPELINE_CONTROL
460 {0x338C, 0xA364}, // MCU_ADDRESS [AWB_KR_L]
461 {0x3390, 0x0080}, // MCU_DATA_0
462 {0x338C, 0xA364}, // MCU_ADDRESS [AWB_KR_L]
463 {0x3390, 0x0080}, // MCU_DATA_0
464 {0x338C, 0xA365}, // MCU_ADDRESS [AWB_KG_L]
465 {0x3390, 0x008C}, // MCU_DATA_0
466 {0x338C, 0xA365}, // MCU_ADDRESS [AWB_KG_L]
467 {0x3390, 0x008C}, // MCU_DATA_0
468 {0x338C, 0xA366}, // MCU_ADDRESS [AWB_KB_L]
469 {0x3390, 0x0082}, // MCU_DATA_0
470 {0x338C, 0xA366}, // MCU_ADDRESS [AWB_KB_L]
471 {0x3390, 0x0082}, // MCU_DATA_0
472 {0x338C, 0x2306}, // MCU_ADDRESS [AWB_CCM_L_0]
473 {0x3390, 0x0619}, // MCU_DATA_0
474 {0x338C, 0x2308}, // MCU_ADDRESS [AWB_CCM_L_1]
475 {0x3390, 0xFC80}, // MCU_DATA_0
476 {0x338C, 0x230A}, // MCU_ADDRESS [AWB_CCM_L_2]
477 {0x3390, 0xFEFB}, // MCU_DATA_0
478 {0x338C, 0x230C}, // MCU_ADDRESS [AWB_CCM_L_3]
479 {0x3390, 0xFEEE}, // MCU_DATA_0
480 {0x338C, 0x230E}, // MCU_ADDRESS [AWB_CCM_L_4]
481 {0x3390, 0x0571}, // MCU_DATA_0
482 {0x338C, 0x2310}, // MCU_ADDRESS [AWB_CCM_L_5]
483 {0x3390, 0xFE26}, // MCU_DATA_0
484 {0x338C, 0x2312}, // MCU_ADDRESS [AWB_CCM_L_6]
485 {0x3390, 0xFF0C}, // MCU_DATA_0
486 {0x338C, 0x2314}, // MCU_ADDRESS [AWB_CCM_L_7]
487 {0x3390, 0xFE48}, // MCU_DATA_0
488 {0x338C, 0x2316}, // MCU_ADDRESS [AWB_CCM_L_8]
489 {0x3390, 0x04A2}, // MCU_DATA_0
490 {0x338C, 0x2318}, // MCU_ADDRESS [AWB_CCM_L_9]
491 {0x3390, 0x0024}, // MCU_DATA_0
492 {0x338C, 0x231A}, // MCU_ADDRESS [AWB_CCM_L_10]
493 {0x3390, 0x003F}, // MCU_DATA_0
494 {0x338C, 0x231C}, // MCU_ADDRESS [AWB_CCM_RL_0]
495 {0x3390, 0xFDA7}, // MCU_DATA_0
496 {0x338C, 0x231E}, // MCU_ADDRESS [AWB_CCM_RL_1]
497 {0x3390, 0x0158}, // MCU_DATA_0
498 {0x338C, 0x2320}, // MCU_ADDRESS [AWB_CCM_RL_2]
499 {0x3390, 0x00EE}, // MCU_DATA_0
500 {0x338C, 0x2322}, // MCU_ADDRESS [AWB_CCM_RL_3]
501 {0x3390, 0x00D3}, // MCU_DATA_0
502 {0x338C, 0x2324}, // MCU_ADDRESS [AWB_CCM_RL_4]
503 {0x3390, 0xFC74}, // MCU_DATA_0
504 {0x338C, 0x2326}, // MCU_ADDRESS [AWB_CCM_RL_5]
505 {0x3390, 0x01A9}, // MCU_DATA_0
506 {0x338C, 0x2328}, // MCU_ADDRESS [AWB_CCM_RL_6]
507 {0x3390, 0x014B}, // MCU_DATA_0
508 {0x338C, 0x232A}, // MCU_ADDRESS [AWB_CCM_RL_7]
509 {0x3390, 0xFE9D}, // MCU_DATA_0
510 {0x338C, 0x232C}, // MCU_ADDRESS [AWB_CCM_RL_8]
511 {0x3390, 0xFF69}, // MCU_DATA_0
512 {0x338C, 0x232E}, // MCU_ADDRESS [AWB_CCM_RL_9]
513 {0x3390, 0x0018}, // MCU_DATA_0
514 {0x338C, 0x2330}, // MCU_ADDRESS [AWB_CCM_RL_10]
515 {0x3390, 0xFFEC}, // MCU_DATA_0
516 {0x338C, 0xA348}, // MCU_ADDRESS [AWB_GAIN_BUFFER_SPEED]
517 {0x3390, 0x0008}, // MCU_DATA_0
518 {0x338C, 0xA349}, // MCU_ADDRESS [AWB_JUMP_DIVISOR]
519 {0x3390, 0x0002}, // MCU_DATA_0
520 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
521 {0x3390, 0x0059}, // MCU_DATA_0
522 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
523 {0x3390, 0x00A6}, // MCU_DATA_0
524 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
525 {0x3390, 0x0000}, // MCU_DATA_0
526 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
527 {0x3390, 0x007F}, // MCU_DATA_0
528 {0x338C, 0xA353}, // MCU_ADDRESS [AWB_MODE]
529 {0x3390, 0x0002}, // MCU_DATA_0
530 {0x338C, 0xA35B}, // MCU_ADDRESS [AWB_STEADY_BGAIN_OUT_MIN]
531 {0x3390, 0x0078}, // MCU_DATA_0
532 {0x338C, 0xA35C}, // MCU_ADDRESS [AWB_STEADY_BGAIN_OUT_MAX]
533 {0x3390, 0x0086}, // MCU_DATA_0
534 {0x338C, 0xA35D}, // MCU_ADDRESS [AWB_STEADY_BGAIN_IN_MIN]
535 {0x3390, 0x007E}, // MCU_DATA_0
536 {0x338C, 0xA35E}, // MCU_ADDRESS [AWB_STEADY_BGAIN_IN_MAX]
537 {0x3390, 0x0082}, // MCU_DATA_0
538 {0x338C, 0x235F}, // MCU_ADDRESS [AWB_CNT_PXL_TH]
539 {0x3390, 0x0040}, // MCU_DATA_0
540 {0x338C, 0xA361}, // MCU_ADDRESS [AWB_TG_MIN0]
541 {0x3390, 0x00C8}, // MCU_DATA_0
542 {0x338C, 0xA362}, // MCU_ADDRESS [AWB_TG_MAX0]
543 {0x3390, 0x00E1}, // MCU_DATA_0
544 {0x338C, 0xA302}, // MCU_ADDRESS [AWB_WINDOW_POS]
545 {0x3390, 0x0000}, // MCU_DATA_0
546 {0x338C, 0xA303}, // MCU_ADDRESS [AWB_WINDOW_SIZE]
547 {0x3390, 0x00EF}, // MCU_DATA_0
548 {0x338C, 0xA352}, // MCU_ADDRESS [AWB_SATURATION]
549 {0x3390, 0x001E}, // MCU_DATA_0
550 {0x338C, 0xA118}, // MCU_ADDRESS [SEQ_LLSAT1]
551 {0x3390, 0x001E}, // MCU_DATA_0
552 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
553 {0x3390, 0x0005}, // MCU_DATA_0
555 {0x338C, 0xA76D}, // MCU_ADDRESS [MODE_GAM_CONT_A]
556 {0x3390, 0x0003}, // MCU_DATA_0
557 {0x338C, 0xA76F}, // MCU_ADDRESS [MODE_GAM_TABLE_A_0]
558 {0x3390, 0x0000}, // MCU_DATA_0
559 {0x338C, 0xA770}, // MCU_ADDRESS [MODE_GAM_TABLE_A_1]
560 {0x3390, 0x000B}, // MCU_DATA_0
561 {0x338C, 0xA771}, // MCU_ADDRESS [MODE_GAM_TABLE_A_2]
562 {0x3390, 0x0023}, // MCU_DATA_0
563 {0x338C, 0xA772}, // MCU_ADDRESS [MODE_GAM_TABLE_A_3]
564 {0x3390, 0x0043}, // MCU_DATA_0
565 {0x338C, 0xA773}, // MCU_ADDRESS [MODE_GAM_TABLE_A_4]
566 {0x3390, 0x006E}, // MCU_DATA_0
567 {0x338C, 0xA774}, // MCU_ADDRESS [MODE_GAM_TABLE_A_5]
568 {0x3390, 0x0090}, // MCU_DATA_0
569 {0x338C, 0xA775}, // MCU_ADDRESS [MODE_GAM_TABLE_A_6]
570 {0x3390, 0x00A8}, // MCU_DATA_0
571 {0x338C, 0xA776}, // MCU_ADDRESS [MODE_GAM_TABLE_A_7]
572 {0x3390, 0x00B9}, // MCU_DATA_0
573 {0x338C, 0xA777}, // MCU_ADDRESS [MODE_GAM_TABLE_A_8]
574 {0x3390, 0x00C6}, // MCU_DATA_0
575 {0x338C, 0xA778}, // MCU_ADDRESS [MODE_GAM_TABLE_A_9]
576 {0x3390, 0x00D0}, // MCU_DATA_0
577 {0x338C, 0xA779}, // MCU_ADDRESS [MODE_GAM_TABLE_A_10]
578 {0x3390, 0x00D9}, // MCU_DATA_0
579 {0x338C, 0xA77A}, // MCU_ADDRESS [MODE_GAM_TABLE_A_11]
580 {0x3390, 0x00E0}, // MCU_DATA_0
581 {0x338C, 0xA77B}, // MCU_ADDRESS [MODE_GAM_TABLE_A_12]
582 {0x3390, 0x00E6}, // MCU_DATA_0
583 {0x338C, 0xA77C}, // MCU_ADDRESS [MODE_GAM_TABLE_A_13]
584 {0x3390, 0x00EB}, // MCU_DATA_0
585 {0x338C, 0xA77D}, // MCU_ADDRESS [MODE_GAM_TABLE_A_14]
586 {0x3390, 0x00F0}, // MCU_DATA_0
587 {0x338C, 0xA77E}, // MCU_ADDRESS [MODE_GAM_TABLE_A_15]
588 {0x3390, 0x00F4}, // MCU_DATA_0
589 {0x338C, 0xA77F}, // MCU_ADDRESS [MODE_GAM_TABLE_A_16]
590 {0x3390, 0x00F8}, // MCU_DATA_0
591 {0x338C, 0xA780}, // MCU_ADDRESS [MODE_GAM_TABLE_A_17]
592 {0x3390, 0x00FC}, // MCU_DATA_0
593 {0x338C, 0xA781}, // MCU_ADDRESS [MODE_GAM_TABLE_A_18]
594 {0x3390, 0x00FF}, // MCU_DATA_0
596 {0x338C, 0xA102}, // MCU_ADDRESS
597 {0x3390, 0x002F}, // MCU_DATA_0
598 {0x338C, 0xA114}, // MCU_ADDRESS
599 {0x3390, 0x0005}, // MCU_DATA_0
600 {SEQUENCE_WAIT_MS, 20},
601 {0x338C, 0xA103}, // MCU_ADDRESS
602 {0x3390, 0x0005}, // MCU_DATA_0
604 {0x338C, 0xA206}, // MCU_ADDRESS [AE_TARGET]
605 {0x3390, 0x003C}, // MCU_DATA_0
609 /* 720p 15fps @ 1280x720 */
611 static struct reginfo sensor_720p[]=
616 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
618 static struct reginfo sensor_1080p[]=
623 /* 2592X1944 QSXGA */
624 static struct reginfo sensor_qsxga[] =
629 static struct reginfo sensor_qxga[] =
635 static struct reginfo sensor_uxga[] =
637 {SEQUENCE_PROPERTY, SEQUENCE_CAPTURE},
655 static struct reginfo sensor_sxga[] =
657 {SEQUENCE_PROPERTY, SEQUENCE_CAPTURE},
675 static struct reginfo sensor_xga[] =
681 static struct reginfo sensor_svga[] =
687 static struct reginfo sensor_vga[] =
693 static struct reginfo sensor_cif[] =
699 static struct reginfo sensor_qvga[] =
705 static struct reginfo sensor_qcif[] =
711 static struct reginfo ov2655_qqvga[] =
755 static struct reginfo ov2655_Sharpness_auto[] =
760 static struct reginfo ov2655_Sharpness1[] =
766 static struct reginfo ov2655_Sharpness2[][3] =
773 static struct reginfo ov2655_Sharpness3[] =
779 static struct reginfo ov2655_Sharpness4[]=
786 static struct reginfo ov2655_Sharpness5[] =
794 static struct reginfo sensor_Preview2Capture[]=
796 {0x338C, 0xA120}, // MCU_ADDRESS [SEQ_CAP_MODE]
797 {0x3390, 0x0002}, // MCU_DATA_0
798 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
799 {0x3390, 0x0002}, // MCU_DATA_0
800 {0x338C, 0xA102}, // MCU_ADDRESS [SEQ_CMD] cgz oppo 2008-09-26
805 static struct reginfo sensor_Capture2Preview[]=
807 {0x338C, 0xA120}, // MCU_ADDRESS [SEQ_CAP_MODE]
808 {0x3390, 0x0000}, // MCU_DATA_0
809 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
810 {0x3390, 0x0001}, // MCU_DATA_0
814 static struct reginfo sensor_ClrFmt_YUYV[]=
819 static struct reginfo sensor_ClrFmt_UYVY[]=
825 #if CONFIG_SENSOR_WhiteBalance
826 static struct reginfo sensor_WhiteB_Auto[]=
829 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
830 {0x3390, 0x0059}, // MCU_DATA_0
831 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
832 {0x3390, 0x00A6}, // MCU_DATA_0
833 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
834 {0x3390, 0x0000}, // MCU_DATA_0
835 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
836 {0x3390, 0x007F}, // MCU_DATA_0
839 /* Cloudy Colour Temperature : 6500K - 8000K */
840 static struct reginfo sensor_WhiteB_Cloudy[]=
843 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
844 {0x3390, 0x0080}, // MCU_DATA_0
845 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
846 {0x3390, 0x007F}, // MCU_DATA_0
847 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
848 {0x3390, 0x007F}, // MCU_DATA_
851 /* ClearDay Colour Temperature : 5000K - 6500K */
852 static struct reginfo sensor_WhiteB_ClearDay[]=
855 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
856 {0x3390, 0x0080}, // MCU_DATA_0
857 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
858 {0x3390, 0x0080}, // MCU_DATA_0
859 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
860 {0x3390, 0x007E}, // MCU_DATA_0
861 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
862 {0x3390, 0x007E}, // MCU_DATA_0
865 /* Office Colour Temperature : 3500K - 5000K */
866 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
869 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
870 {0x3390, 0x0080}, // MCU_DATA_0
871 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
872 {0x3390, 0x0080}, // MCU_DATA_0
873 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
874 {0x3390, 0x0030}, // MCU_DATA_0
875 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
876 {0x3390, 0x0030}, // MCU_DATA_0
879 /* Home Colour Temperature : 2500K - 3500K */
880 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
883 {0x338C, 0xA34A}, // MCU_ADDRESS [AWB_GAIN_MIN]
884 {0x3390, 0x0080}, // MCU_DATA_0
885 {0x338C, 0xA34B}, // MCU_ADDRESS [AWB_GAIN_MAX]
886 {0x3390, 0x0080}, // MCU_DATA_0
887 {0x338C, 0xA34F}, // MCU_ADDRESS [AWB_CCM_POSITION_MIN]
888 {0x3390, 0x0032}, // MCU_DATA_0
889 {0x338C, 0xA350}, // MCU_ADDRESS [AWB_CCM_POSITION_MAX]
890 {0x3390, 0x0032}, // MCU_DATA_0
893 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
894 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
898 #if CONFIG_SENSOR_Brightness
899 static struct reginfo sensor_Brightness0[]=
904 static struct reginfo sensor_Brightness1[]=
909 static struct reginfo sensor_Brightness2[]=
914 static struct reginfo sensor_Brightness3[]=
919 static struct reginfo sensor_Brightness4[]=
924 static struct reginfo sensor_Brightness5[]=
928 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
929 sensor_Brightness4, sensor_Brightness5,NULL,
934 #if CONFIG_SENSOR_Effect
935 static struct reginfo sensor_Effect_Normal[] =
937 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
938 {0x3390, 0x6408}, // MCU_DATA_0
939 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
940 {0x3390, 0x6408}, // MCU_DATA_0
941 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
942 {0x3390, 0x0005}, // MCU_DATA_0
946 static struct reginfo sensor_Effect_WandB[] =
948 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
949 {0x3390, 0x6409}, // MCU_DATA_0
950 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
951 {0x3390, 0x6409}, // MCU_DATA_0
952 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
953 {0x3390, 0x0005}, // MCU_DATA_0
957 static struct reginfo sensor_Effect_Sepia[] =
959 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
960 {0x3390, 0x640A}, // MCU_DATA_0
961 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
962 {0x3390, 0x640A}, // MCU_DATA_0
963 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
964 {0x3390, 0x0005}, // MCU_DATA_0
968 static struct reginfo sensor_Effect_Negative[] =
970 {0x338C, 0x2799}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_A]
971 {0x3390, 0x640B}, // MCU_DATA_0
972 {0x338C, 0x279B}, // MCU_ADDRESS [MODE_SPEC_EFFECTS_B]
973 {0x3390, 0x640B}, // MCU_DATA_0
974 {0x338C, 0xA103}, // MCU_ADDRESS [SEQ_CMD]
975 {0x3390, 0x0005}, // MCU_DATA_0
978 static struct reginfo sensor_Effect_Bluish[] =
983 static struct reginfo sensor_Effect_Green[] =
988 static struct reginfo sensor_Effect_Solarize[] =
992 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_WandB, sensor_Effect_Sepia,sensor_Effect_Negative,
996 #if CONFIG_SENSOR_Exposure
997 static struct reginfo sensor_Exposure0[]=
1002 static struct reginfo sensor_Exposure1[]=
1004 {SEQUENCE_END, 0x00}
1007 static struct reginfo sensor_Exposure2[]=
1009 {SEQUENCE_END, 0x00}
1012 static struct reginfo sensor_Exposure3[]=
1014 {SEQUENCE_END, 0x00}
1017 static struct reginfo sensor_Exposure4[]=
1019 {SEQUENCE_END, 0x00}
1022 static struct reginfo sensor_Exposure5[]=
1024 {SEQUENCE_END, 0x00}
1027 static struct reginfo sensor_Exposure6[]=
1029 {SEQUENCE_END, 0x00}
1032 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
1033 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
1036 #if CONFIG_SENSOR_Saturation
1037 static struct reginfo sensor_Saturation0[]=
1039 {SEQUENCE_END, 0x00}
1042 static struct reginfo sensor_Saturation1[]=
1044 {SEQUENCE_END, 0x00}
1047 static struct reginfo sensor_Saturation2[]=
1049 {SEQUENCE_END, 0x00}
1051 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
1054 #if CONFIG_SENSOR_Contrast
1055 static struct reginfo sensor_Contrast0[]=
1057 {SEQUENCE_END, 0x00}
1060 static struct reginfo sensor_Contrast1[]=
1062 {SEQUENCE_END, 0x00}
1065 static struct reginfo sensor_Contrast2[]=
1067 {SEQUENCE_END, 0x00}
1070 static struct reginfo sensor_Contrast3[]=
1072 {SEQUENCE_END, 0x00}
1075 static struct reginfo sensor_Contrast4[]=
1077 {SEQUENCE_END, 0x00}
1081 static struct reginfo sensor_Contrast5[]=
1083 {SEQUENCE_END, 0x00}
1086 static struct reginfo sensor_Contrast6[]=
1088 {SEQUENCE_END, 0x00}
1090 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
1091 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
1095 #if CONFIG_SENSOR_Mirror
1096 static struct reginfo sensor_MirrorOn[]=
1098 {SEQUENCE_END, 0x00}
1101 static struct reginfo sensor_MirrorOff[]=
1103 {SEQUENCE_END, 0x00}
1105 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
1107 #if CONFIG_SENSOR_Flip
1108 static struct reginfo sensor_FlipOn[]=
1110 {SEQUENCE_END, 0x00}
1113 static struct reginfo sensor_FlipOff[]=
1115 {SEQUENCE_END, 0x00}
1117 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
1120 #if CONFIG_SENSOR_Scene
1121 static struct reginfo sensor_SceneAuto[] =
1123 {0x338C, 0xA102}, // MCU_ADDRESS
1124 {0x3390, 0x002F}, // MCU_DATA_0
1125 {0x338C, 0xA114}, // MCU_ADDRESS
1126 {0x3390, 0x0005}, // MCU_DATA_0
1127 {SEQUENCE_WAIT_MS, 20},
1128 {0x338C, 0xA103}, // MCU_ADDRESS
1129 {0x3390, 0x0005}, // MCU_DATA_0
1130 {SEQUENCE_END, 0x00}
1133 static struct reginfo sensor_SceneNight[] =
1135 {0x338C, 0xA102}, // MCU_ADDRESS
1136 {0x3390, 0x000F}, // MCU_DATA_0
1137 {SEQUENCE_WAIT_MS, 20},
1138 {0x338C, 0xA103}, // MCU_ADDRESS
1139 {0x3390, 0x0005}, // MCU_DATA_0
1140 {SEQUENCE_END, 0x00}
1142 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
1145 #if CONFIG_SENSOR_DigitalZoom
1146 static struct reginfo sensor_Zoom0[] =
1148 {SEQUENCE_END, 0x00}
1151 static struct reginfo sensor_Zoom1[] =
1153 {SEQUENCE_END, 0x00}
1156 static struct reginfo sensor_Zoom2[] =
1158 {SEQUENCE_END, 0x00}
1162 static struct reginfo sensor_Zoom3[] =
1164 {SEQUENCE_END, 0x00}
1166 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
1168 static const struct v4l2_querymenu sensor_menus[] =
1170 #if CONFIG_SENSOR_WhiteBalance
1171 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
1172 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
1173 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
1176 #if CONFIG_SENSOR_Effect
1177 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "mono", .reserved = 0,},
1178 { .id = V4L2_CID_EFFECT, .index = 2, .name = "negative", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "sepia", .reserved = 0,},
1181 #if CONFIG_SENSOR_Scene
1182 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
1185 #if CONFIG_SENSOR_Flash
1186 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
1187 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
1191 static const struct v4l2_queryctrl sensor_controls[] =
1193 #if CONFIG_SENSOR_WhiteBalance
1195 .id = V4L2_CID_DO_WHITE_BALANCE,
1196 .type = V4L2_CTRL_TYPE_MENU,
1197 .name = "White Balance Control",
1205 #if CONFIG_SENSOR_Brightness
1207 .id = V4L2_CID_BRIGHTNESS,
1208 .type = V4L2_CTRL_TYPE_INTEGER,
1209 .name = "Brightness Control",
1217 #if CONFIG_SENSOR_Effect
1219 .id = V4L2_CID_EFFECT,
1220 .type = V4L2_CTRL_TYPE_MENU,
1221 .name = "Effect Control",
1229 #if CONFIG_SENSOR_Exposure
1231 .id = V4L2_CID_EXPOSURE,
1232 .type = V4L2_CTRL_TYPE_INTEGER,
1233 .name = "Exposure Control",
1241 #if CONFIG_SENSOR_Saturation
1243 .id = V4L2_CID_SATURATION,
1244 .type = V4L2_CTRL_TYPE_INTEGER,
1245 .name = "Saturation Control",
1253 #if CONFIG_SENSOR_Contrast
1255 .id = V4L2_CID_CONTRAST,
1256 .type = V4L2_CTRL_TYPE_INTEGER,
1257 .name = "Contrast Control",
1265 #if CONFIG_SENSOR_Mirror
1267 .id = V4L2_CID_HFLIP,
1268 .type = V4L2_CTRL_TYPE_BOOLEAN,
1269 .name = "Mirror Control",
1277 #if CONFIG_SENSOR_Flip
1279 .id = V4L2_CID_VFLIP,
1280 .type = V4L2_CTRL_TYPE_BOOLEAN,
1281 .name = "Flip Control",
1289 #if CONFIG_SENSOR_Scene
1291 .id = V4L2_CID_SCENE,
1292 .type = V4L2_CTRL_TYPE_MENU,
1293 .name = "Scene Control",
1301 #if CONFIG_SENSOR_DigitalZoom
1303 .id = V4L2_CID_ZOOM_RELATIVE,
1304 .type = V4L2_CTRL_TYPE_INTEGER,
1305 .name = "DigitalZoom Control",
1311 .id = V4L2_CID_ZOOM_ABSOLUTE,
1312 .type = V4L2_CTRL_TYPE_INTEGER,
1313 .name = "DigitalZoom Control",
1321 #if CONFIG_SENSOR_Focus
1323 .id = V4L2_CID_FOCUS_RELATIVE,
1324 .type = V4L2_CTRL_TYPE_INTEGER,
1325 .name = "Focus Control",
1331 .id = V4L2_CID_FOCUS_ABSOLUTE,
1332 .type = V4L2_CTRL_TYPE_INTEGER,
1333 .name = "Focus Control",
1337 .default_value = 125,
1340 .id = V4L2_CID_FOCUS_AUTO,
1341 .type = V4L2_CTRL_TYPE_BOOLEAN,
1342 .name = "Focus Control",
1348 .id = V4L2_CID_FOCUS_CONTINUOUS,
1349 .type = V4L2_CTRL_TYPE_BOOLEAN,
1350 .name = "Focus Control",
1358 #if CONFIG_SENSOR_Flash
1360 .id = V4L2_CID_FLASH,
1361 .type = V4L2_CTRL_TYPE_MENU,
1362 .name = "Flash Control",
1371 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1372 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1373 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1374 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1375 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1376 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1377 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1378 static int sensor_resume(struct soc_camera_device *icd);
1379 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1380 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1381 #if CONFIG_SENSOR_Effect
1382 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1384 #if CONFIG_SENSOR_WhiteBalance
1385 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1387 static int sensor_deactivate(struct i2c_client *client);
1388 static struct soc_camera_ops sensor_ops =
1390 .suspend = sensor_suspend,
1391 .resume = sensor_resume,
1392 .set_bus_param = sensor_set_bus_param,
1393 .query_bus_param = sensor_query_bus_param,
1394 .controls = sensor_controls,
1395 .menus = sensor_menus,
1396 .num_controls = ARRAY_SIZE(sensor_controls),
1397 .num_menus = ARRAY_SIZE(sensor_menus),
1399 /* only one fixed colorspace per pixelcode */
1400 struct sensor_datafmt {
1401 enum v4l2_mbus_pixelcode code;
1402 enum v4l2_colorspace colorspace;
1405 /* Find a data format by a pixel code in an array */
1406 static const struct sensor_datafmt *sensor_find_datafmt(
1407 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1411 for (i = 0; i < n; i++)
1412 if (fmt[i].code == code)
1418 static const struct sensor_datafmt sensor_colour_fmts[] = {
1419 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1420 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1422 enum sensor_work_state
1424 sensor_work_ready = 0,
1429 struct i2c_client *client;
1430 struct delayed_work dwork;
1431 enum sensor_work_state state;
1434 typedef struct sensor_info_priv_s
1448 unsigned char mirror; /* HFLIP */
1449 unsigned char flip; /* VFLIP */
1456 struct reginfo *winseqe_cur_addr;
1457 struct sensor_datafmt fmt;
1458 unsigned int enable;
1459 unsigned int funmodule_state;
1460 } sensor_info_priv_t;
1464 struct sensor_parameter
1466 unsigned short int preview_maxlines;
1467 unsigned short int preview_exposure;
1468 unsigned short int preview_line_width;
1469 unsigned short int preview_gain;
1471 unsigned short int capture_framerate;
1472 unsigned short int preview_framerate;
1477 struct v4l2_subdev subdev;
1478 struct i2c_client *client;
1479 sensor_info_priv_t info_priv;
1480 struct sensor_parameter parameter;
1481 struct workqueue_struct *sensor_wq;
1482 struct sensor_work sensor_wk;
1483 struct mutex wq_lock;
1484 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1485 #if CONFIG_SENSOR_I2C_NOSCHED
1486 atomic_t tasklock_cnt;
1488 struct rkcamera_platform_data *sensor_io_request;
1489 struct rkcamera_gpio_res *sensor_gpio_res;
1492 static struct sensor* to_sensor(const struct i2c_client *client)
1494 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1497 static int sensor_task_lock(struct i2c_client *client, int lock)
1499 #if CONFIG_SENSOR_I2C_NOSCHED
1501 struct sensor *sensor = to_sensor(client);
1504 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1505 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1506 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1510 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1511 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1512 goto sensor_task_lock_err;
1517 atomic_add(1, &sensor->tasklock_cnt);
1519 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1520 atomic_sub(1, &sensor->tasklock_cnt);
1522 if (atomic_read(&sensor->tasklock_cnt) == 0)
1527 sensor_task_lock_err:
1535 /* sensor register write */
1536 static int sensor_write(struct i2c_client *client, u16 reg, u16 val)
1540 struct i2c_msg msg[1];
1544 case SEQUENCE_WAIT_MS:
1550 case SEQUENCE_WAIT_US:
1556 case SEQUENCE_PROPERTY:
1563 buf[1] = reg & 0xFF;
1565 buf[3] = val & 0xFF;
1567 msg->addr = client->addr;
1568 msg->flags = client->flags;
1570 msg->len = sizeof(buf);
1571 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1572 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1577 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1578 err = i2c_transfer(client->adapter, msg, 1);
1583 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg, val);
1592 /* sensor register read */
1593 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1597 struct i2c_msg msg[2];
1600 buf[1] = reg & 0xFF;
1602 msg[0].addr = client->addr;
1603 msg[0].flags = client->flags;
1605 msg[0].len = sizeof(buf);
1606 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1607 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1609 msg[1].addr = client->addr;
1610 msg[1].flags = client->flags|I2C_M_RD;
1613 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1614 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1618 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1619 err = i2c_transfer(client->adapter, msg, 2);
1625 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1633 /* write a array of registers */
1634 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1638 #if CONFIG_SENSOR_I2C_RDWRCHK
1643 if (sensor_task_lock(client, 1) < 0)
1644 goto sensor_write_array_end;
1645 while (regarray[i].reg != SEQUENCE_END)
1648 err = sensor_write(client, regarray[i].reg, regarray[i].val);
1652 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1656 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1658 goto sensor_write_array_end;
1661 #if CONFIG_SENSOR_I2C_RDWRCHK
1662 sensor_read(client, regarray[i].reg, &valchk);
1663 if (valchk != regarray[i].val)
1664 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1671 sensor_write_array_end:
1672 sensor_task_lock(client,0);
1675 #if CONFIG_SENSOR_I2C_RDWRCHK
1676 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1684 while (regarray[i].reg != SEQUENCE_END)
1686 sensor_read(client, regarray[i].reg, &valchk);
1687 if (valchk != regarray[i].val)
1688 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1695 #if CONFIG_SENSOR_Focus
1697 static int sensor_af_single(struct i2c_client *client)
1702 sensor_af_single_end:
1706 static int sensor_af_const(struct i2c_client *client)
1710 sensor_af_const_end:
1714 static int sensor_af_zoneupdate(struct i2c_client *client)
1718 sensor_af_zoneupdate_end:
1722 static int sensor_af_init(struct i2c_client *client)
1730 static int sensor_ioctrl(struct soc_camera_device *icd,enum rksensor_power_cmd cmd, int on)
1732 struct soc_camera_link *icl = to_soc_camera_link(icd);
1735 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1738 case Sensor_PowerDown:
1740 if (icl->powerdown) {
1741 ret = icl->powerdown(icd->pdev, on);
1742 if (ret == RK_CAM_IO_SUCCESS) {
1746 icl->reset(icd->pdev);
1748 } else if (ret == RK_CAM_EIO_REQUESTFAIL) {
1750 goto sensor_power_end;
1757 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1758 struct sensor *sensor = to_sensor(client);
1760 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1761 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1767 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1775 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1777 struct i2c_client *client = v4l2_get_subdevdata(sd);
1778 struct soc_camera_device *icd = client->dev.platform_data;
1779 struct sensor *sensor = to_sensor(client);
1780 const struct v4l2_queryctrl *qctrl;
1781 const struct sensor_datafmt *fmt;
1783 #if (SENSOR_ID_REG != SEQUENCE_END)
1786 struct rkcamera_platform_data* tmp_plat_data =(struct rkcamera_platform_data*)val;
1787 sensor_init_data_p = sensor_init_data;
1788 sensor_init_winseq_p = sensor_svga;
1789 sensor_init_width = 800;
1790 sensor_init_height = 600;
1791 if (tmp_plat_data != NULL) {
1792 for(i = 0;i < RK_CAM_NUM_PER_HOST;i++){
1793 if ((tmp_plat_data->sensor_init_data[i])&& tmp_plat_data->info[i].dev_name &&
1794 (strcmp(tmp_plat_data->info[i].dev_name, dev_name(icd->pdev)) == 0))
1798 if(tmp_plat_data && (i < RK_CAM_NUM_PER_HOST) && tmp_plat_data->sensor_init_data[i]){
1799 //user has defined the init data
1801 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1802 for(j = 0;j< sizeof(sensor_init_data)/sizeof(struct reginfo);j++){
1803 sensor_init_data[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].reg;
1804 sensor_init_data[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data[j].val;
1806 sensor_init_data_p = sensor_init_data;
1808 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data){
1809 sensor_init_data_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_data);
1812 if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq && (sizeof(struct reginfo) != sizeof(struct reginfo_t))){
1813 int tmp_winseq_size = tmp_plat_data->sensor_init_data[i]->rk_sensor_winseq_size;
1814 if(sensor_init_winseq_board)
1816 vfree(sensor_init_winseq_board);
1817 sensor_init_winseq_board = NULL;
1819 sensor_init_winseq_board = (struct reginfo*)vmalloc(tmp_winseq_size);
1820 if(!sensor_init_winseq_board)
1821 SENSOR_TR("%s :vmalloc erro !",__FUNCTION__);
1822 for(j = 0;j< tmp_winseq_size;j++){
1823 sensor_init_winseq_board[j].reg = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].reg;
1824 sensor_init_winseq_board[j].val = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq[j].val;
1826 sensor_init_winseq_p = sensor_init_winseq_board;
1828 else if(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq){
1829 sensor_init_winseq_p = (struct reginfo*)(tmp_plat_data->sensor_init_data[i]->rk_sensor_init_winseq);
1831 //init width,height,bus,pixelcode
1832 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width != INVALID_VALUE)
1833 sensor_init_width = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_width;
1834 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height != INVALID_VALUE)
1835 sensor_init_height = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_height;
1836 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param != INVALID_VALUE)
1837 sensor_init_busparam = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_bus_param;
1838 if(tmp_plat_data->sensor_init_data[i] && tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode != INVALID_VALUE)
1839 sensor_init_pixelcode = tmp_plat_data->sensor_init_data[i]->rk_sensor_init_pixelcode;
1843 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1845 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1847 goto sensor_INIT_ERR;
1851 if (sensor_task_lock(client,1)<0)
1852 goto sensor_INIT_ERR;
1854 #if (SENSOR_RESET_REG != SEQUENCE_END)
1855 ret = sensor_write(client, SENSOR_RESET_REG, SENSOR_RESET_VAL);
1857 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1859 goto sensor_INIT_ERR;
1862 mdelay(5); //delay 5 microseconds
1865 /* check if it is an sensor sensor */
1866 #if (SENSOR_ID_REG != SEQUENCE_END)
1867 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1869 SENSOR_TR("read chip id failed\n");
1871 goto sensor_INIT_ERR;
1874 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1878 if (pid == SENSOR_ID) {
1879 sensor->model = SENSOR_V4L2_IDENT;
1881 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1883 goto sensor_INIT_ERR;
1886 ret = sensor_write_array(client, sensor_init_data_p);
1889 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1890 goto sensor_INIT_ERR;
1892 sensor_task_lock(client,0);
1893 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1894 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1895 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1896 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1897 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1898 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1900 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1902 goto sensor_INIT_ERR;
1904 sensor->info_priv.fmt = *fmt;
1906 /* sensor sensor information for initialization */
1907 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1909 sensor->info_priv.whiteBalance = qctrl->default_value;
1910 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1912 sensor->info_priv.brightness = qctrl->default_value;
1913 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1915 sensor->info_priv.effect = qctrl->default_value;
1916 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1918 sensor->info_priv.exposure = qctrl->default_value;
1920 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1922 sensor->info_priv.saturation = qctrl->default_value;
1923 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1925 sensor->info_priv.contrast = qctrl->default_value;
1926 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1928 sensor->info_priv.mirror = qctrl->default_value;
1929 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1931 sensor->info_priv.flip = qctrl->default_value;
1932 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1934 sensor->info_priv.scene = qctrl->default_value;
1935 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1937 sensor->info_priv.digitalzoom = qctrl->default_value;
1939 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1940 #if CONFIG_SENSOR_Focus
1942 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1944 sensor->info_priv.focus = qctrl->default_value;
1947 #if CONFIG_SENSOR_Flash
1948 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1950 sensor->info_priv.flash = qctrl->default_value;
1952 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);
1956 sensor_task_lock(client,0);
1957 sensor_deactivate(client);
1960 static int sensor_deactivate(struct i2c_client *client)
1962 struct soc_camera_device *icd = client->dev.platform_data;
1964 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1966 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1967 sensor_task_lock(client, 1);
1968 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1970 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1971 icd->user_width = SENSOR_INIT_WIDTH;
1972 icd->user_height = SENSOR_INIT_HEIGHT;
1976 static struct reginfo sensor_power_down_sequence[]=
1980 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1983 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1985 if (pm_msg.event == PM_EVENT_SUSPEND) {
1986 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1987 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1989 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1992 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1994 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1999 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
2006 static int sensor_resume(struct soc_camera_device *icd)
2010 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
2012 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
2016 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
2020 static int sensor_set_bus_param(struct soc_camera_device *icd,
2021 unsigned long flags)
2027 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
2029 struct soc_camera_link *icl = to_soc_camera_link(icd);
2030 unsigned long flags = SENSOR_BUS_PARAM;
2032 return soc_camera_apply_sensor_flags(icl, flags);
2034 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2036 struct i2c_client *client = v4l2_get_subdevdata(sd);
2037 struct soc_camera_device *icd = client->dev.platform_data;
2038 struct sensor *sensor = to_sensor(client);
2040 mf->width = icd->user_width;
2041 mf->height = icd->user_height;
2042 mf->code = sensor->info_priv.fmt.code;
2043 mf->colorspace = sensor->info_priv.fmt.colorspace;
2044 mf->field = V4L2_FIELD_NONE;
2048 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2052 if ((mf->width == 1024) && (mf->height == 768)) {
2054 } else if ((mf->width == 1280) && (mf->height == 1024)) {
2056 } else if ((mf->width == 1600) && (mf->height == 1200)) {
2058 } else if ((mf->width == 2048) && (mf->height == 1536)) {
2060 } else if ((mf->width == 2592) && (mf->height == 1944)) {
2065 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
2069 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2073 if ((mf->width == 1280) && (mf->height == 720)) {
2075 } else if ((mf->width == 1920) && (mf->height == 1080)) {
2080 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
2083 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2085 struct i2c_client *client = v4l2_get_subdevdata(sd);
2086 struct sensor *sensor = to_sensor(client);
2087 const struct sensor_datafmt *fmt;
2088 struct reginfo *winseqe_set_addr=NULL;
2089 int ret = 0, set_w,set_h;
2091 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2092 ARRAY_SIZE(sensor_colour_fmts));
2095 goto sensor_s_fmt_end;
2098 if (sensor->info_priv.fmt.code != mf->code) {
2101 case V4L2_MBUS_FMT_YUYV8_2X8:
2103 winseqe_set_addr = sensor_ClrFmt_YUYV;
2106 case V4L2_MBUS_FMT_UYVY8_2X8:
2108 winseqe_set_addr = sensor_ClrFmt_UYVY;
2114 if (winseqe_set_addr != NULL) {
2115 sensor_write_array(client, winseqe_set_addr);
2116 sensor->info_priv.fmt.code = mf->code;
2117 sensor->info_priv.fmt.colorspace= mf->colorspace;
2118 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
2120 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
2126 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END))
2128 winseqe_set_addr = sensor_qcif;
2132 else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END))
2134 winseqe_set_addr = sensor_qvga;
2138 else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END))
2140 winseqe_set_addr = sensor_cif;
2144 else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END))
2146 winseqe_set_addr = sensor_vga;
2150 else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END))
2152 winseqe_set_addr = sensor_svga;
2156 else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END))
2158 winseqe_set_addr = sensor_xga;
2162 else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END))
2164 winseqe_set_addr = sensor_720p;
2168 else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END))
2170 winseqe_set_addr = sensor_sxga;
2174 else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END))
2176 winseqe_set_addr = sensor_uxga;
2180 else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END))
2182 winseqe_set_addr = sensor_1080p;
2186 else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END))
2188 winseqe_set_addr = sensor_qxga;
2192 else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END))
2194 winseqe_set_addr = sensor_qsxga;
2199 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
2200 ret |= sensor_write_array(client, winseqe_set_addr);
2202 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
2203 goto sensor_s_fmt_end;
2205 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
2206 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2207 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2209 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
2213 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
2214 ret |= sensor_write_array(client, sensor_Preview2Capture);
2216 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
2217 goto sensor_s_fmt_end;
2219 sensor->info_priv.capture_w = set_w;
2220 sensor->info_priv.capture_h = set_h;
2221 sensor->info_priv.snap2preview = true;
2222 } else if (sensor->info_priv.snap2preview == true) {
2223 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
2224 ret |= sensor_write_array(client, sensor_Capture2Preview);
2226 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
2227 goto sensor_s_fmt_end;
2229 sensor->info_priv.preview_w = mf->width;
2230 sensor->info_priv.preview_h = mf->height;
2231 sensor->info_priv.snap2preview = false;
2233 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2243 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2245 struct i2c_client *client = v4l2_get_subdevdata(sd);
2246 struct sensor *sensor = to_sensor(client);
2247 const struct sensor_datafmt *fmt;
2250 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2251 ARRAY_SIZE(sensor_colour_fmts));
2253 fmt = &sensor->info_priv.fmt;
2254 mf->code = fmt->code;
2257 if (mf->height > SENSOR_MAX_HEIGHT)
2258 mf->height = SENSOR_MAX_HEIGHT;
2259 else if (mf->height < SENSOR_MIN_HEIGHT)
2260 mf->height = SENSOR_MIN_HEIGHT;
2262 if (mf->width > SENSOR_MAX_WIDTH)
2263 mf->width = SENSOR_MAX_WIDTH;
2264 else if (mf->width < SENSOR_MIN_WIDTH)
2265 mf->width = SENSOR_MIN_WIDTH;
2267 mf->colorspace = fmt->colorspace;
2272 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2274 struct i2c_client *client = v4l2_get_subdevdata(sd);
2276 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2279 if (id->match.addr != client->addr)
2282 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2287 #if CONFIG_SENSOR_Brightness
2288 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2290 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2292 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2294 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2296 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2298 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2301 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2305 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2309 #if CONFIG_SENSOR_Effect
2310 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2312 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2314 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2316 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2318 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2320 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2323 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2327 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2331 #if CONFIG_SENSOR_Exposure
2332 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2334 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2336 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2338 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2340 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2342 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2345 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2349 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2353 #if CONFIG_SENSOR_Saturation
2354 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2356 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2358 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2360 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2362 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2364 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2367 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2371 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2375 #if CONFIG_SENSOR_Contrast
2376 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2378 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2380 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2382 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2384 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2386 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2389 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2393 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2397 #if CONFIG_SENSOR_Mirror
2398 static int sensor_set_mirror(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));
2402 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2404 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2406 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2408 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2411 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2415 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2419 #if CONFIG_SENSOR_Flip
2420 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2422 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2424 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2426 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2428 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2430 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2433 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2437 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2441 #if CONFIG_SENSOR_Scene
2442 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2444 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2446 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2448 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2450 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2452 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2455 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2459 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2463 #if CONFIG_SENSOR_WhiteBalance
2464 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2466 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2468 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2470 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2472 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2474 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2477 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2481 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2485 #if CONFIG_SENSOR_DigitalZoom
2486 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2488 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2489 struct sensor *sensor = to_sensor(client);
2490 const struct v4l2_queryctrl *qctrl_info;
2491 int digitalzoom_cur, digitalzoom_total;
2493 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2497 digitalzoom_cur = sensor->info_priv.digitalzoom;
2498 digitalzoom_total = qctrl_info->maximum;
2500 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2502 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2506 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2508 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2512 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2514 *value = digitalzoom_total - digitalzoom_cur;
2517 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2519 *value = 0 - digitalzoom_cur;
2522 digitalzoom_cur += *value;
2524 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2526 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2528 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2531 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2538 #if CONFIG_SENSOR_Flash
2539 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2541 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2542 if (value == 3) { /* ddl@rock-chips.com: torch */
2543 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2545 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2547 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2551 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2555 #if CONFIG_SENSOR_Focus
2556 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2558 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2559 struct sensor *sensor = to_sensor(client);
2560 const struct v4l2_queryctrl *qctrl_info;
2563 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2567 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2568 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2570 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2573 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2577 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2578 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2581 sensor_set_focus_absolute_end:
2584 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2586 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2587 struct sensor *sensor = to_sensor(client);
2588 const struct v4l2_queryctrl *qctrl_info;
2591 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2595 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2596 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2598 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2601 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2605 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2606 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2608 sensor_set_focus_relative_end:
2612 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2614 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2615 struct sensor *sensor = to_sensor(client);
2618 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2621 case SENSOR_AF_MODE_AUTO:
2623 ret = sensor_af_single(client);
2627 case SENSOR_AF_MODE_MACRO:
2629 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2633 case SENSOR_AF_MODE_INFINITY:
2635 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2639 case SENSOR_AF_MODE_CONTINUOUS:
2641 ret = sensor_af_const(client);
2645 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2650 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2653 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2654 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2660 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2662 struct i2c_client *client = v4l2_get_subdevdata(sd);
2663 struct sensor *sensor = to_sensor(client);
2664 const struct v4l2_queryctrl *qctrl;
2666 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2670 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2676 case V4L2_CID_BRIGHTNESS:
2678 ctrl->value = sensor->info_priv.brightness;
2681 case V4L2_CID_SATURATION:
2683 ctrl->value = sensor->info_priv.saturation;
2686 case V4L2_CID_CONTRAST:
2688 ctrl->value = sensor->info_priv.contrast;
2691 case V4L2_CID_DO_WHITE_BALANCE:
2693 ctrl->value = sensor->info_priv.whiteBalance;
2696 case V4L2_CID_EXPOSURE:
2698 ctrl->value = sensor->info_priv.exposure;
2701 case V4L2_CID_HFLIP:
2703 ctrl->value = sensor->info_priv.mirror;
2706 case V4L2_CID_VFLIP:
2708 ctrl->value = sensor->info_priv.flip;
2719 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2721 struct i2c_client *client = v4l2_get_subdevdata(sd);
2722 struct sensor *sensor = to_sensor(client);
2723 struct soc_camera_device *icd = client->dev.platform_data;
2724 const struct v4l2_queryctrl *qctrl;
2727 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2731 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2737 #if CONFIG_SENSOR_Brightness
2738 case V4L2_CID_BRIGHTNESS:
2740 if (ctrl->value != sensor->info_priv.brightness)
2742 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2746 sensor->info_priv.brightness = ctrl->value;
2751 #if CONFIG_SENSOR_Exposure
2752 case V4L2_CID_EXPOSURE:
2754 if (ctrl->value != sensor->info_priv.exposure)
2756 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2760 sensor->info_priv.exposure = ctrl->value;
2765 #if CONFIG_SENSOR_Saturation
2766 case V4L2_CID_SATURATION:
2768 if (ctrl->value != sensor->info_priv.saturation)
2770 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2774 sensor->info_priv.saturation = ctrl->value;
2779 #if CONFIG_SENSOR_Contrast
2780 case V4L2_CID_CONTRAST:
2782 if (ctrl->value != sensor->info_priv.contrast)
2784 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2788 sensor->info_priv.contrast = ctrl->value;
2793 #if CONFIG_SENSOR_WhiteBalance
2794 case V4L2_CID_DO_WHITE_BALANCE:
2796 if (ctrl->value != sensor->info_priv.whiteBalance)
2798 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2802 sensor->info_priv.whiteBalance = ctrl->value;
2807 #if CONFIG_SENSOR_Mirror
2808 case V4L2_CID_HFLIP:
2810 if (ctrl->value != sensor->info_priv.mirror)
2812 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2814 sensor->info_priv.mirror = ctrl->value;
2819 #if CONFIG_SENSOR_Flip
2820 case V4L2_CID_VFLIP:
2822 if (ctrl->value != sensor->info_priv.flip)
2824 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2826 sensor->info_priv.flip = ctrl->value;
2837 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2839 const struct v4l2_queryctrl *qctrl;
2840 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2841 struct sensor *sensor = to_sensor(client);
2843 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2847 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2851 switch (ext_ctrl->id)
2853 case V4L2_CID_SCENE:
2855 ext_ctrl->value = sensor->info_priv.scene;
2858 case V4L2_CID_EFFECT:
2860 ext_ctrl->value = sensor->info_priv.effect;
2863 case V4L2_CID_ZOOM_ABSOLUTE:
2865 ext_ctrl->value = sensor->info_priv.digitalzoom;
2868 case V4L2_CID_ZOOM_RELATIVE:
2872 case V4L2_CID_FOCUS_ABSOLUTE:
2874 ext_ctrl->value = sensor->info_priv.focus;
2877 case V4L2_CID_FOCUS_RELATIVE:
2881 case V4L2_CID_FLASH:
2883 ext_ctrl->value = sensor->info_priv.flash;
2891 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2893 const struct v4l2_queryctrl *qctrl;
2894 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2895 struct sensor *sensor = to_sensor(client);
2898 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2902 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2907 switch (ext_ctrl->id)
2909 #if CONFIG_SENSOR_Scene
2910 case V4L2_CID_SCENE:
2912 if (ext_ctrl->value != sensor->info_priv.scene)
2914 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2916 sensor->info_priv.scene = ext_ctrl->value;
2921 #if CONFIG_SENSOR_Effect
2922 case V4L2_CID_EFFECT:
2924 if (ext_ctrl->value != sensor->info_priv.effect)
2926 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2928 sensor->info_priv.effect= ext_ctrl->value;
2933 #if CONFIG_SENSOR_DigitalZoom
2934 case V4L2_CID_ZOOM_ABSOLUTE:
2936 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2939 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2941 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2943 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2945 sensor->info_priv.digitalzoom += val_offset;
2947 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2952 case V4L2_CID_ZOOM_RELATIVE:
2954 if (ext_ctrl->value)
2956 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2958 sensor->info_priv.digitalzoom += ext_ctrl->value;
2960 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2965 #if CONFIG_SENSOR_Focus
2966 case V4L2_CID_FOCUS_ABSOLUTE:
2968 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2971 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2972 if (ext_ctrl->value == qctrl->minimum) {
2973 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2974 } else if (ext_ctrl->value == qctrl->maximum) {
2975 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2977 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2983 case V4L2_CID_FOCUS_RELATIVE:
2985 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2988 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2991 case V4L2_CID_FOCUS_AUTO:
2993 if (ext_ctrl->value == 1) {
2994 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2996 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2997 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2998 if (ext_ctrl->value == 0)
2999 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3003 case V4L2_CID_FOCUS_CONTINUOUS:
3005 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
3006 if (ext_ctrl->value == 1) {
3007 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
3009 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
3012 if (ext_ctrl->value == 0)
3013 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
3018 #if CONFIG_SENSOR_Flash
3019 case V4L2_CID_FLASH:
3021 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
3023 sensor->info_priv.flash = ext_ctrl->value;
3025 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
3036 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3038 struct i2c_client *client = v4l2_get_subdevdata(sd);
3039 struct soc_camera_device *icd = client->dev.platform_data;
3040 int i, error_cnt=0, error_idx=-1;
3043 for (i=0; i<ext_ctrl->count; i++) {
3044 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3051 error_idx = ext_ctrl->count;
3053 if (error_idx != -1) {
3054 ext_ctrl->error_idx = error_idx;
3061 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
3063 struct i2c_client *client = v4l2_get_subdevdata(sd);
3064 struct soc_camera_device *icd = client->dev.platform_data;
3065 int i, error_cnt=0, error_idx=-1;
3067 for (i=0; i<ext_ctrl->count; i++) {
3068 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
3075 error_idx = ext_ctrl->count;
3077 if (error_idx != -1) {
3078 ext_ctrl->error_idx = error_idx;
3085 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
3087 struct i2c_client *client = v4l2_get_subdevdata(sd);
3088 struct sensor *sensor = to_sensor(client);
3091 sensor->info_priv.enable = 1;
3092 } else if (enable == 0) {
3093 sensor->info_priv.enable = 0;
3099 /* Interface active, can use i2c. If it fails, it can indeed mean, that
3100 * this wasn't our capture interface, so, we wait for the right one */
3101 static int sensor_video_probe(struct soc_camera_device *icd,
3102 struct i2c_client *client)
3105 #if (SENSOR_ID_REG != SEQUENCE_END)
3109 struct sensor *sensor = to_sensor(client);
3111 /* We must have a parent by now. And it cannot be a wrong one.
3112 * So this entire test is completely redundant. */
3113 if (!icd->dev.parent ||
3114 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
3117 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
3119 goto sensor_video_probe_err;
3123 #if (SENSOR_RESET_REG != SEQUENCE_END)
3124 ret = sensor_write(client, SENSOR_RESET_REG, SENSOR_RESET_VAL);
3126 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
3128 goto sensor_INIT_ERR;
3131 mdelay(5); //delay 5 microseconds
3134 /* check if it is an sensor sensor */
3135 #if (SENSOR_ID_REG != SEQUENCE_END)
3136 ret = sensor_read(client, SENSOR_ID_REG, &pid);
3138 SENSOR_TR("read chip id failed\n");
3140 goto sensor_video_probe_err;
3143 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
3148 if (pid == SENSOR_ID) {
3149 sensor->model = SENSOR_V4L2_IDENT;
3151 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
3153 goto sensor_video_probe_err;
3159 sensor_video_probe_err:
3162 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
3164 struct i2c_client *client = v4l2_get_subdevdata(sd);
3165 struct soc_camera_device *icd = client->dev.platform_data;
3166 struct sensor *sensor = to_sensor(client);
3168 #if CONFIG_SENSOR_Flash
3172 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3175 case RK_CAM_SUBDEV_DEACTIVATE:
3177 sensor_deactivate(client);
3180 case RK_CAM_SUBDEV_IOREQUEST:
3182 sensor->sensor_io_request = (struct rkcamera_platform_data*)arg;
3183 if (sensor->sensor_io_request != NULL) {
3184 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
3185 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
3186 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
3187 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
3188 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
3189 sensor->sensor_gpio_res = (struct rkcamera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
3192 SENSOR_TR("%s %s RK_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
3194 goto sensor_ioctl_end;
3196 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
3198 #if CONFIG_SENSOR_Flash
3199 if (sensor->sensor_gpio_res) {
3200 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
3201 for (i = 0; i < icd->ops->num_controls; i++) {
3202 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
3203 memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
3206 sensor->info_priv.flash = 0xff;
3207 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
3215 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3223 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3224 enum v4l2_mbus_pixelcode *code)
3226 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3229 *code = sensor_colour_fmts[index].code;
3232 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3233 .init = sensor_init,
3234 .g_ctrl = sensor_g_control,
3235 .s_ctrl = sensor_s_control,
3236 .g_ext_ctrls = sensor_g_ext_controls,
3237 .s_ext_ctrls = sensor_s_ext_controls,
3238 .g_chip_ident = sensor_g_chip_ident,
3239 .ioctl = sensor_ioctl,
3242 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3243 .s_mbus_fmt = sensor_s_fmt,
3244 .g_mbus_fmt = sensor_g_fmt,
3245 .try_mbus_fmt = sensor_try_fmt,
3246 .enum_mbus_fmt = sensor_enum_fmt,
3249 static struct v4l2_subdev_ops sensor_subdev_ops = {
3250 .core = &sensor_subdev_core_ops,
3251 .video = &sensor_subdev_video_ops,
3254 static int sensor_probe(struct i2c_client *client,
3255 const struct i2c_device_id *did)
3257 struct sensor *sensor;
3258 struct soc_camera_device *icd = client->dev.platform_data;
3259 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3260 struct soc_camera_link *icl;
3263 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3265 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3269 icl = to_soc_camera_link(icd);
3271 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3275 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3276 dev_warn(&adapter->dev,
3277 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3281 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3285 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3287 /* Second stage probe - when a capture adapter is there */
3288 icd->ops = &sensor_ops;
3289 sensor->info_priv.fmt = sensor_colour_fmts[0];
3290 #if CONFIG_SENSOR_I2C_NOSCHED
3291 atomic_set(&sensor->tasklock_cnt,0);
3294 ret = sensor_video_probe(icd, client);
3297 i2c_set_clientdata(client, NULL);
3301 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3305 static int sensor_remove(struct i2c_client *client)
3307 struct sensor *sensor = to_sensor(client);
3308 struct soc_camera_device *icd = client->dev.platform_data;
3311 i2c_set_clientdata(client, NULL);
3312 client->driver = NULL;
3318 static const struct i2c_device_id sensor_id[] = {
3319 {SENSOR_NAME_STRING(), 0 },
3322 MODULE_DEVICE_TABLE(i2c, sensor_id);
3324 static struct i2c_driver sensor_i2c_driver = {
3326 .name = SENSOR_NAME_STRING(),
3328 .probe = sensor_probe,
3329 .remove = sensor_remove,
3330 .id_table = sensor_id,
3333 static int __init sensor_mod_init(void)
3335 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3336 return i2c_add_driver(&sensor_i2c_driver);
3339 static void __exit sensor_mod_exit(void)
3341 i2c_del_driver(&sensor_i2c_driver);
3344 device_initcall_sync(sensor_mod_init);
3345 module_exit(sensor_mod_exit);
3347 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3348 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3349 MODULE_LICENSE("GPL");