2 * Driver for OV5642 CMOS Image Sensor from OmniVision
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/videodev2.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
14 #include <linux/log2.h>
15 #include <linux/platform_device.h>
16 #include <linux/delay.h>
17 #include <linux/circ_buf.h>
18 #include <linux/hardirq.h>
19 #include <linux/miscdevice.h>
20 #include <media/v4l2-common.h>
21 #include <media/v4l2-chip-ident.h>
22 #include <media/soc_camera.h>
23 #include <plat/rk_camera.h>
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 RK29_CAM_SENSOR_MT9D113
48 #define SENSOR_V4L2_IDENT V4L2_IDENT_MT9D113
49 #define SENSOR_ID 0x2580
50 #define SENSOR_ID_REG 0x00
51 #define SENSOR_RESET_REG SEQUENCE_END
52 #define SENSOR_RESET_VAL 0
53 #define SENSOR_DERESET_VAL 0
54 #define SENSOR_RESET_REG_LEN WORD_LEN
55 #define SENSOR_MIN_WIDTH 800
56 #define SENSOR_MIN_HEIGHT 600
57 #define SENSOR_MAX_WIDTH 1600
58 #define SENSOR_MAX_HEIGHT 1200
59 #define SENSOR_INIT_WIDTH 800 /* Sensor pixel size for sensor_init_data array */
60 #define SENSOR_INIT_HEIGHT 600
61 #define SENSOR_INIT_WINSEQADR sensor_init_data
62 #define SENSOR_INIT_PIXFMT V4L2_MBUS_FMT_UYVY8_2X8
64 #define CONFIG_SENSOR_WhiteBalance 0
65 #define CONFIG_SENSOR_Brightness 0
66 #define CONFIG_SENSOR_Contrast 0
67 #define CONFIG_SENSOR_Saturation 0
68 #define CONFIG_SENSOR_Effect 0
69 #define CONFIG_SENSOR_Scene 0
70 #define CONFIG_SENSOR_DigitalZoom 0
71 #define CONFIG_SENSOR_Exposure 0
72 #define CONFIG_SENSOR_Flash 1
73 #define CONFIG_SENSOR_Mirror 0
74 #define CONFIG_SENSOR_Flip 0
75 #define CONFIG_SENSOR_Focus 0
77 #define CONFIG_SENSOR_I2C_SPEED 100000 /* Hz */
78 /* Sensor write register continues by preempt_disable/preempt_enable for current process not be scheduled */
79 #define CONFIG_SENSOR_I2C_NOSCHED 0
80 #define CONFIG_SENSOR_I2C_RDWRCHK 1
82 #define SENSOR_BUS_PARAM (SOCAM_MASTER | SOCAM_PCLK_SAMPLE_FALLING |\
83 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |\
84 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8 |SOCAM_MCLK_24MHZ)
86 #define COLOR_TEMPERATURE_CLOUDY_DN 6500
87 #define COLOR_TEMPERATURE_CLOUDY_UP 8000
88 #define COLOR_TEMPERATURE_CLEARDAY_DN 5000
89 #define COLOR_TEMPERATURE_CLEARDAY_UP 6500
90 #define COLOR_TEMPERATURE_OFFICE_DN 3500
91 #define COLOR_TEMPERATURE_OFFICE_UP 5000
92 #define COLOR_TEMPERATURE_HOME_DN 2500
93 #define COLOR_TEMPERATURE_HOME_UP 3500
95 #define SENSOR_NAME_STRING(a) STR(CONS(SENSOR_NAME, a))
96 #define SENSOR_NAME_VARFUN(a) CONS(SENSOR_NAME, a)
98 #define SENSOR_AF_IS_ERR (0x00<<0)
99 #define SENSOR_AF_IS_OK (0x01<<0)
101 #if CONFIG_SENSOR_Focus
102 #define SENSOR_AF_MODE_INFINITY 0
103 #define SENSOR_AF_MODE_MACRO 1
104 #define SENSOR_AF_MODE_FIXED 2
105 #define SENSOR_AF_MODE_AUTO 3
106 #define SENSOR_AF_MODE_CONTINUOUS 4
107 #define SENSOR_AF_MODE_CLOSE 5
111 //flash off in fixed time to prevent from too hot , zyc
113 struct soc_camera_device *icd;
114 struct hrtimer timer;
116 static enum hrtimer_restart flash_off_func(struct hrtimer *timer);
118 static struct flash_timer flash_off_timer;
119 //for user defined if user want to customize the series , zyc
120 #ifdef CONFIG_MT9D113_USER_DEFINED_SERIES
121 #include "mt9d113_user_series.c"
123 /* init 800x600 SVGA */
124 static struct reginfo sensor_init_data[] =
128 //for 24MHz input, VCO=MAX PCLK=76.8MHz
129 { 0x0014, 0x21F9, WORD_LEN, 0}, //PLL Control: BYPASS PLL = 8697
130 { 0x0010, 0x0110, WORD_LEN, 0}, //PLL Dividers = 272
131 { 0x0012, 0x1FF7, WORD_LEN, 0}, //PLL P Dividers = 8183
132 { 0x0014, 0x21FB, WORD_LEN, 0}, //PLL Control: PLL_ENABLE on = 8699
133 { 0x0014, 0x20FB, WORD_LEN, 0}, //PLL Control: SEL_LOCK_DET on = 8443
135 { SEQUENCE_WAIT_US, 1, WORD_LEN, 0}, // Allow PLL to lock
137 { 0x0014, 0x20FA, WORD_LEN, 0}, //PLL Control: PLL_BYPASS off = 8442
138 { 0x0018, 0x402D, WORD_LEN, 0},
141 { 0x0018, 0x402C, WORD_LEN, 0},
143 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
145 { 0x321C, 0x0003, WORD_LEN, 0}, //By Pass TxFIFO = 3
146 { 0x098C, 0x2703, WORD_LEN, 0}, //Output Width (A)
147 { 0x0990, 0x0320, WORD_LEN, 0}, // = 800
148 { 0x98C, 0x2705, WORD_LEN, 0}, //Output Height (A)
149 { 0x990, 0x0258 , WORD_LEN, 0}, // = 600
150 { 0x98C, 0x2707, WORD_LEN, 0}, //Output Width (B)
151 { 0x990, 0x0640 , WORD_LEN, 0}, // = 1600
152 { 0x98C, 0x2709 , WORD_LEN, 0}, //Output Height (B)
153 { 0x990, 0x04B0 , WORD_LEN, 0}, // = 1200
154 { 0x98C, 0x270D , WORD_LEN, 0}, //Row Start (A)
155 { 0x990, 0x000 , WORD_LEN, 0}, // = 0
156 { 0x98C, 0x270F , WORD_LEN, 0}, //Column Start (A)
157 { 0x990, 0x000 , WORD_LEN, 0}, // = 0
158 { 0x98C, 0x2711 , WORD_LEN, 0}, //Row End (A)
159 { 0x990, 0x4BD , WORD_LEN, 0}, // = 1213
160 { 0x98C, 0x2713 , WORD_LEN, 0}, //Column End (A)
161 { 0x990, 0x64D , WORD_LEN, 0}, // = 1613
162 { 0x98C, 0x2715 , WORD_LEN, 0}, //Row Speed (A)
163 { 0x990, 0x0111 , WORD_LEN, 0}, // = 273
164 { 0x98C, 0x2717 , WORD_LEN, 0}, //Read Mode (A)
166 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
167 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
168 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
169 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
171 { 0x98C, 0x2719 , WORD_LEN, 0}, //sensor_fine_correction (A)
172 { 0x990, 0x005A , WORD_LEN, 0}, // = 90
173 { 0x98C, 0x271B , WORD_LEN, 0}, //sensor_fine_IT_min (A)
174 { 0x990, 0x01BE , WORD_LEN, 0}, // = 446
175 { 0x98C, 0x271D , WORD_LEN, 0}, //sensor_fine_IT_max_margin (A)
176 { 0x990, 0x0131 , WORD_LEN, 0}, // = 305
177 { 0x98C, 0x271F , WORD_LEN, 0}, //Frame Lines (A)
178 { 0x990, 0x02B3 , WORD_LEN, 0}, // = 691
179 { 0x98C, 0x2721 , WORD_LEN, 0}, //Line Length (A)
180 { 0x990, 0x056D , WORD_LEN, 0}, // = 1389
181 { 0x98C, 0x2723 , WORD_LEN, 0}, //Row Start (B)
182 { 0x990, 0x004 , WORD_LEN, 0}, // = 4
183 { 0x98C, 0x2725 , WORD_LEN, 0}, //Column Start (B)
184 { 0x990, 0x004 , WORD_LEN, 0}, // = 4
185 { 0x98C, 0x2727 , WORD_LEN, 0}, //Row End (B)
186 { 0x990, 0x4BB , WORD_LEN, 0}, // = 1211
187 { 0x98C, 0x2729 , WORD_LEN, 0}, //Column End (B)
188 { 0x990, 0x64B , WORD_LEN, 0}, // = 1611
189 { 0x98C, 0x272B , WORD_LEN, 0}, //Row Speed (B)
190 { 0x990, 0x0111 , WORD_LEN, 0}, // = 273
191 { 0x98C, 0x272D , WORD_LEN, 0}, //Read Mode (B)
192 { 0x990, 0x0024 , WORD_LEN, 0}, // = 36
193 { 0x98C, 0x272F , WORD_LEN, 0}, //sensor_fine_correction (B)
194 { 0x990, 0x003A , WORD_LEN, 0}, // = 58
195 { 0x98C, 0x2731 , WORD_LEN, 0}, //sensor_fine_IT_min (B)
196 { 0x990, 0x00F6 , WORD_LEN, 0}, // = 246
197 { 0x98C, 0x2733 , WORD_LEN, 0}, //sensor_fine_IT_max_margin (B)
198 { 0x990, 0x008B , WORD_LEN, 0}, // = 139
199 { 0x98C, 0x2735 , WORD_LEN, 0}, //Frame Lines (B)
200 { 0x990, 0x050D , WORD_LEN, 0}, // = 1293
201 { 0x98C, 0x2737 , WORD_LEN, 0}, //Line Length (B)
202 { 0x990, 0x0894 , WORD_LEN, 0}, // = 2196
203 { 0x98C, 0x2739 , WORD_LEN, 0}, //Crop_X0 (A)
204 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
205 { 0x98C, 0x273B , WORD_LEN, 0}, //Crop_X1 (A)
206 { 0x990, 0x031F , WORD_LEN, 0}, // = 799
207 { 0x98C, 0x273D , WORD_LEN, 0}, //Crop_Y0 (A)
208 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
209 { 0x98C, 0x273F , WORD_LEN, 0}, //Crop_Y1 (A)
210 { 0x990, 0x0257 , WORD_LEN, 0}, // = 599
211 { 0x98C, 0x2747 , WORD_LEN, 0}, //Crop_X0 (B)
212 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
213 { 0x98C, 0x2749 , WORD_LEN, 0}, //Crop_X1 (B)
214 { 0x990, 0x063F , WORD_LEN, 0}, // = 1599
215 { 0x98C, 0x274B , WORD_LEN, 0}, //Crop_Y0 (B)
216 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
217 { 0x98C, 0x274D , WORD_LEN, 0}, //Crop_Y1 (B)
218 { 0x990, 0x04AF , WORD_LEN, 0}, // = 1199
219 { 0x98C, 0x222D , WORD_LEN, 0}, //R9 Step
220 { 0x990, 0x0090 , WORD_LEN, 0}, // = 144
221 { 0x98C, 0xA408 , WORD_LEN, 0}, //search_f1_50
222 { 0x990, 0x23 , WORD_LEN, 0}, // = 35
223 { 0x98C, 0xA409 , WORD_LEN, 0}, //search_f2_50
224 { 0x990, 0x25 , WORD_LEN, 0}, // = 37
225 { 0x98C, 0xA40A , WORD_LEN, 0}, //search_f1_60
226 { 0x990, 0x2A , WORD_LEN, 0}, // = 42
227 { 0x98C, 0xA40B , WORD_LEN, 0}, //search_f2_60
228 { 0x990, 0x2C , WORD_LEN, 0}, // = 44
229 { 0x98C, 0x2411 , WORD_LEN, 0}, //R9_Step_60 (A)
230 { 0x990, 0x0090 , WORD_LEN, 0}, // = 144
231 { 0x98C, 0x2413 , WORD_LEN, 0}, //R9_Step_50 (A)
232 { 0x990, 0x00AD , WORD_LEN, 0}, // = 173
233 { 0x98C, 0x2415 , WORD_LEN, 0}, //R9_Step_60 (B)
234 { 0x990, 0x005B , WORD_LEN, 0}, // = 91
235 { 0x98C, 0x2417 , WORD_LEN, 0}, //R9_Step_50 (B)
236 { 0x990, 0x006D , WORD_LEN, 0}, // = 109
237 { 0x98C, 0xA404 , WORD_LEN, 0}, //FD Mode
238 { 0x990, 0x10 , WORD_LEN, 0}, // = 16
239 { 0x98C, 0xA40D , WORD_LEN, 0}, //Stat_min
240 { 0x990, 0x02 , WORD_LEN, 0}, // = 2
241 { 0x98C, 0xA40E , WORD_LEN, 0}, //Stat_max
242 { 0x990, 0x03 , WORD_LEN, 0}, // = 3
243 { 0x98C, 0xA410 , WORD_LEN, 0}, //Min_amplitude
244 { 0x990, 0x0A , WORD_LEN, 0}, // = 10
245 { 0x98C, 0xA103 , WORD_LEN, 0}, //Refresh Sequencer Mode
246 { 0x990, 0x06 , WORD_LEN, 0}, // = 6
247 //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100 // wait for command to be processed
249 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
251 { 0x98C, 0xA103 , WORD_LEN, 0}, //Refresh Sequencer
252 { 0x990, 0x05 , WORD_LEN, 0}, // = 5
254 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
256 //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100 // wait for command to be processed
260 //for 24MHz input, VCO=MAX PCLK=76.8MHz
261 { 0x001A, 0x0051, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
262 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
263 { 0x0014, 0x2545, WORD_LEN, 0}, // PLL_CONTROL
264 { 0x0010, 0x011C, WORD_LEN, 0}, // PLL_DIVIDERS
265 { 0x0012, 0x1FF7, WORD_LEN, 0}, // PLL_P_DIVIDERS
266 { 0x0014, 0x2547, WORD_LEN, 0}, // PLL_CONTROL
267 { 0x0014, 0x2447, WORD_LEN, 0}, // PLL_CONTROL
268 { 0x0014, 0x2047, WORD_LEN, 0}, // PLL_CONTROL
269 { 0x0014, 0x2046, WORD_LEN, 0}, // PLL_CONTROL
270 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
271 { 0x0018, 0x4028 , WORD_LEN, 0}, // STANDBY_CONTROL
272 { 0x321C, 0x0003 , WORD_LEN, 0}, // OFIFO_CONTROL_STATUS
273 { 0x098C, 0x2703 , WORD_LEN, 0}, // MCU_ADDRESS
274 { 0x0990, 0x0320 , WORD_LEN, 0}, // MCU_DATA_0
275 { 0x098C, 0x2705 , WORD_LEN, 0}, // MCU_ADDRESS
276 { 0x0990, 0x0258 , WORD_LEN, 0}, // MCU_DATA_0
277 { 0x098C, 0x2707 , WORD_LEN, 0}, // MCU_ADDRESS
278 { 0x0990, 0x0640 , WORD_LEN, 0}, // MCU_DATA_0
279 { 0x098C, 0x2709 , WORD_LEN, 0}, // MCU_ADDRESS
280 { 0x0990, 0x04B0 , WORD_LEN, 0}, // MCU_DATA_0
281 { 0x098C, 0x270D , WORD_LEN, 0}, // MCU_ADDRESS
282 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
283 { 0x098C, 0x270F , WORD_LEN, 0}, // MCU_ADDRESS
284 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
285 { 0x098C, 0x2711 , WORD_LEN, 0}, // MCU_ADDRESS
286 { 0x0990, 0x04BD , WORD_LEN, 0}, // MCU_DATA_0
287 { 0x098C, 0x2713 , WORD_LEN, 0}, // MCU_ADDRESS
288 { 0x0990, 0x064D , WORD_LEN, 0}, // MCU_DATA_0
289 { 0x098C, 0x2715 , WORD_LEN, 0}, // MCU_ADDRESS
290 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
291 { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
293 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
294 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
295 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
296 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
298 { 0x098C, 0x2719 , WORD_LEN, 0}, // MCU_ADDRESS
299 { 0x0990, 0x005A , WORD_LEN, 0}, // MCU_DATA_0
300 { 0x098C, 0x271B , WORD_LEN, 0}, // MCU_ADDRESS
301 { 0x0990, 0x01BE , WORD_LEN, 0}, // MCU_DATA_0
302 { 0x098C, 0x271D , WORD_LEN, 0}, // MCU_ADDRESS
303 { 0x0990, 0x0131 , WORD_LEN, 0}, // MCU_DATA_0
304 { 0x098C, 0x271F , WORD_LEN, 0}, // MCU_ADDRESS
305 { 0x0990, 0x02B3 , WORD_LEN, 0}, // MCU_DATA_0
306 { 0x098C, 0x2721 , WORD_LEN, 0}, // MCU_ADDRESS
307 { 0x0990, 0x09B0 , WORD_LEN, 0}, // MCU_DATA_0
308 { 0x098C, 0x2723 , WORD_LEN, 0}, // MCU_ADDRESS
309 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
310 { 0x098C, 0x2725 , WORD_LEN, 0}, // MCU_ADDRESS
311 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
312 { 0x098C, 0x2727 , WORD_LEN, 0}, // MCU_ADDRESS
313 { 0x0990, 0x04BB , WORD_LEN, 0}, // MCU_DATA_0
314 { 0x098C, 0x2729 , WORD_LEN, 0}, // MCU_ADDRESS
315 { 0x0990, 0x064B , WORD_LEN, 0}, // MCU_DATA_0
316 { 0x098C, 0x272B , WORD_LEN, 0}, // MCU_ADDRESS
317 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
318 { 0x098C, 0x272D , WORD_LEN, 0}, // MCU_ADDRESS
319 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
320 { 0x098C, 0x272F , WORD_LEN, 0}, // MCU_ADDRESS
321 { 0x0990, 0x003A , WORD_LEN, 0}, // MCU_DATA_0
322 { 0x098C, 0x2731 , WORD_LEN, 0}, // MCU_ADDRESS
323 { 0x0990, 0x00F6 , WORD_LEN, 0}, // MCU_DATA_0
324 { 0x098C, 0x2733 , WORD_LEN, 0}, // MCU_ADDRESS
325 { 0x0990, 0x008B , WORD_LEN, 0}, // MCU_DATA_0
326 { 0x098C, 0x2735 , WORD_LEN, 0}, // MCU_ADDRESS
327 { 0x0990, 0x050D , WORD_LEN, 0}, // MCU_DATA_0
328 { 0x098C, 0x2737 , WORD_LEN, 0}, // MCU_ADDRESS
329 { 0x0990, 0x0807 , WORD_LEN, 0}, // MCU_DATA_0
330 { 0x098C, 0x2739 , WORD_LEN, 0}, // MCU_ADDRESS
331 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
332 { 0x098C, 0x273B , WORD_LEN, 0}, // MCU_ADDRESS
333 { 0x0990, 0x031F , WORD_LEN, 0}, // MCU_DATA_0
334 { 0x098C, 0x273D , WORD_LEN, 0}, // MCU_ADDRESS
335 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
336 { 0x098C, 0x273F , WORD_LEN, 0}, // MCU_ADDRESS
337 { 0x0990, 0x0257 , WORD_LEN, 0}, // MCU_DATA_0
338 { 0x098C, 0x2747 , WORD_LEN, 0}, // MCU_ADDRESS
339 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
340 { 0x098C, 0x2749 , WORD_LEN, 0}, // MCU_ADDRESS
341 { 0x0990, 0x063F , WORD_LEN, 0}, // MCU_DATA_0
342 { 0x098C, 0x274B , WORD_LEN, 0}, // MCU_ADDRESS
343 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
344 { 0x098C, 0x274D , WORD_LEN, 0}, // MCU_ADDRESS
345 { 0x0990, 0x04AF , WORD_LEN, 0}, // MCU_DATA_0
346 { 0x098C, 0x222D , WORD_LEN, 0}, // MCU_ADDRESS
347 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
348 { 0x098C, 0xA408 , WORD_LEN, 0}, // MCU_ADDRESS
349 { 0x0990, 0x0022 , WORD_LEN, 0}, // MCU_DATA_0
350 { 0x098C, 0xA409 , WORD_LEN, 0}, // MCU_ADDRESS
351 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
352 { 0x098C, 0xA40A , WORD_LEN, 0}, // MCU_ADDRESS
353 { 0x0990, 0x0029 , WORD_LEN, 0}, // MCU_DATA_0
354 { 0x098C, 0xA40B , WORD_LEN, 0}, // MCU_ADDRESS
355 { 0x0990, 0x002B , WORD_LEN, 0}, // MCU_DATA_0
356 { 0x098C, 0x2411 , WORD_LEN, 0}, // MCU_ADDRESS
357 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
358 { 0x098C, 0x2413 , WORD_LEN, 0}, // MCU_ADDRESS
359 { 0x0990, 0x00A9 , WORD_LEN, 0}, // MCU_DATA_0
360 { 0x098C, 0x2415 , WORD_LEN, 0}, // MCU_ADDRESS
361 { 0x0990, 0x00AA , WORD_LEN, 0}, // MCU_DATA_0
362 { 0x098C, 0x2417 , WORD_LEN, 0}, // MCU_ADDRESS
363 { 0x0990, 0x00CC , WORD_LEN, 0}, // MCU_DATA_0
364 { 0x098C, 0xA404 , WORD_LEN, 0}, // MCU_ADDRESS
365 { 0x0990, 0x0010 , WORD_LEN, 0}, // MCU_DATA_0
366 { 0x098C, 0xA40D , WORD_LEN, 0}, // MCU_ADDRESS
367 { 0x0990, 0x0002 , WORD_LEN, 0}, // MCU_DATA_0
368 { 0x098C, 0xA40E , WORD_LEN, 0}, // MCU_ADDRESS
369 { 0x0990, 0x0003 , WORD_LEN, 0}, // MCU_DATA_0
370 { 0x098C, 0xA410 , WORD_LEN, 0}, // MCU_ADDRESS
371 { 0x0990, 0x000A , WORD_LEN, 0}, // MCU_DATA_0
372 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
373 { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
374 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
375 { 0x0990, 0x0005 , WORD_LEN, 0}, // MCU_DATA_0
380 /* 720p 15fps @ 1280x720 */
382 static struct reginfo sensor_720p[]=
387 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
389 static struct reginfo sensor_1080p[]=
394 /* 2592X1944 QSXGA */
395 static struct reginfo sensor_qsxga[] =
400 static struct reginfo sensor_qxga[] =
406 static struct reginfo sensor_uxga[] =
409 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
410 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
411 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
412 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
416 static struct reginfo sensor_sxga[] =
419 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
420 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
421 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
422 { 0x0990, 0x0001, WORD_LEN, 0}, // MCU_DATA_0
425 // { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
426 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
427 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
428 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
430 { 0x098C, 0x2747, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_X0_B]
431 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
432 { 0x098C, 0x2749, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_X1_B]
433 { 0x0990, 0x063F, WORD_LEN, 0}, // MCU_DATA_0
434 { 0x098C, 0x274B, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_Y0_B]
435 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
436 { 0x098C, 0x274D, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_Y1_B]
437 { 0x0990, 0x04AF, WORD_LEN, 0}, // MCU_DATA_0
438 { 0x098C, 0x2707, WORD_LEN, 0}, // MCU_ADDRESS [MODE_OUTPUT_WIDTH_B]
439 { 0x0990, 0x0500, WORD_LEN, 0}, // MCU_DATA_0
440 { 0x098C, 0x2709, WORD_LEN, 0}, // MCU_ADDRESS [MODE_OUTPUT_HEIGHT_B]
441 { 0x0990, 0x0400, WORD_LEN, 0}, // MCU_DATA_0
443 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
444 { 0x0990, 0x0005, WORD_LEN, 0}, // MCU_DATA_0
446 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
447 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
448 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
449 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
455 static struct reginfo sensor_xga[] =
461 static struct reginfo sensor_svga[] =
464 //for 24MHz input, VCO=MAX PCLK=76.8MHz
465 { 0x001A, 0x0051, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
466 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
467 { 0x0014, 0x2545, WORD_LEN, 0}, // PLL_CONTROL
468 { 0x0010, 0x011C, WORD_LEN, 0}, // PLL_DIVIDERS
469 { 0x0012, 0x1FF7, WORD_LEN, 0}, // PLL_P_DIVIDERS
470 { 0x0014, 0x2547, WORD_LEN, 0}, // PLL_CONTROL
471 { 0x0014, 0x2447, WORD_LEN, 0}, // PLL_CONTROL
472 { 0x0014, 0x2047, WORD_LEN, 0}, // PLL_CONTROL
473 { 0x0014, 0x2046, WORD_LEN, 0}, // PLL_CONTROL
474 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
475 { 0x0018, 0x4028 , WORD_LEN, 0}, // STANDBY_CONTROL
476 { 0x321C, 0x0003 , WORD_LEN, 0}, // OFIFO_CONTROL_STATUS
477 { 0x098C, 0x2703 , WORD_LEN, 0}, // MCU_ADDRESS
478 { 0x0990, 0x0320 , WORD_LEN, 0}, // MCU_DATA_0
479 { 0x098C, 0x2705 , WORD_LEN, 0}, // MCU_ADDRESS
480 { 0x0990, 0x0258 , WORD_LEN, 0}, // MCU_DATA_0
481 { 0x098C, 0x2707 , WORD_LEN, 0}, // MCU_ADDRESS
482 { 0x0990, 0x0640 , WORD_LEN, 0}, // MCU_DATA_0
483 { 0x098C, 0x2709 , WORD_LEN, 0}, // MCU_ADDRESS
484 { 0x0990, 0x04B0 , WORD_LEN, 0}, // MCU_DATA_0
485 { 0x098C, 0x270D , WORD_LEN, 0}, // MCU_ADDRESS
486 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
487 { 0x098C, 0x270F , WORD_LEN, 0}, // MCU_ADDRESS
488 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
489 { 0x098C, 0x2711 , WORD_LEN, 0}, // MCU_ADDRESS
490 { 0x0990, 0x04BD , WORD_LEN, 0}, // MCU_DATA_0
491 { 0x098C, 0x2713 , WORD_LEN, 0}, // MCU_ADDRESS
492 { 0x0990, 0x064D , WORD_LEN, 0}, // MCU_DATA_0
493 { 0x098C, 0x2715 , WORD_LEN, 0}, // MCU_ADDRESS
494 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
495 { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
497 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
498 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
499 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
500 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
503 { 0x098C, 0x2719 , WORD_LEN, 0}, // MCU_ADDRESS
504 { 0x0990, 0x005A , WORD_LEN, 0}, // MCU_DATA_0
505 { 0x098C, 0x271B , WORD_LEN, 0}, // MCU_ADDRESS
506 { 0x0990, 0x01BE , WORD_LEN, 0}, // MCU_DATA_0
507 { 0x098C, 0x271D , WORD_LEN, 0}, // MCU_ADDRESS
508 { 0x0990, 0x0131 , WORD_LEN, 0}, // MCU_DATA_0
509 { 0x098C, 0x271F , WORD_LEN, 0}, // MCU_ADDRESS
510 { 0x0990, 0x02B3 , WORD_LEN, 0}, // MCU_DATA_0
511 { 0x098C, 0x2721 , WORD_LEN, 0}, // MCU_ADDRESS
512 { 0x0990, 0x09B0 , WORD_LEN, 0}, // MCU_DATA_0
513 { 0x098C, 0x2723 , WORD_LEN, 0}, // MCU_ADDRESS
514 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
515 { 0x098C, 0x2725 , WORD_LEN, 0}, // MCU_ADDRESS
516 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
517 { 0x098C, 0x2727 , WORD_LEN, 0}, // MCU_ADDRESS
518 { 0x0990, 0x04BB , WORD_LEN, 0}, // MCU_DATA_0
519 { 0x098C, 0x2729 , WORD_LEN, 0}, // MCU_ADDRESS
520 { 0x0990, 0x064B , WORD_LEN, 0}, // MCU_DATA_0
521 { 0x098C, 0x272B , WORD_LEN, 0}, // MCU_ADDRESS
522 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
523 { 0x098C, 0x272D , WORD_LEN, 0}, // MCU_ADDRESS
524 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
525 { 0x098C, 0x272F , WORD_LEN, 0}, // MCU_ADDRESS
526 { 0x0990, 0x003A , WORD_LEN, 0}, // MCU_DATA_0
527 { 0x098C, 0x2731 , WORD_LEN, 0}, // MCU_ADDRESS
528 { 0x0990, 0x00F6 , WORD_LEN, 0}, // MCU_DATA_0
529 { 0x098C, 0x2733 , WORD_LEN, 0}, // MCU_ADDRESS
530 { 0x0990, 0x008B , WORD_LEN, 0}, // MCU_DATA_0
531 { 0x098C, 0x2735 , WORD_LEN, 0}, // MCU_ADDRESS
532 { 0x0990, 0x050D , WORD_LEN, 0}, // MCU_DATA_0
533 { 0x098C, 0x2737 , WORD_LEN, 0}, // MCU_ADDRESS
534 { 0x0990, 0x0807 , WORD_LEN, 0}, // MCU_DATA_0
535 { 0x098C, 0x2739 , WORD_LEN, 0}, // MCU_ADDRESS
536 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
537 { 0x098C, 0x273B , WORD_LEN, 0}, // MCU_ADDRESS
538 { 0x0990, 0x031F , WORD_LEN, 0}, // MCU_DATA_0
539 { 0x098C, 0x273D , WORD_LEN, 0}, // MCU_ADDRESS
540 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
541 { 0x098C, 0x273F , WORD_LEN, 0}, // MCU_ADDRESS
542 { 0x0990, 0x0257 , WORD_LEN, 0}, // MCU_DATA_0
543 { 0x098C, 0x2747 , WORD_LEN, 0}, // MCU_ADDRESS
544 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
545 { 0x098C, 0x2749 , WORD_LEN, 0}, // MCU_ADDRESS
546 { 0x0990, 0x063F , WORD_LEN, 0}, // MCU_DATA_0
547 { 0x098C, 0x274B , WORD_LEN, 0}, // MCU_ADDRESS
548 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
549 { 0x098C, 0x274D , WORD_LEN, 0}, // MCU_ADDRESS
550 { 0x0990, 0x04AF , WORD_LEN, 0}, // MCU_DATA_0
551 { 0x098C, 0x222D , WORD_LEN, 0}, // MCU_ADDRESS
552 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
553 { 0x098C, 0xA408 , WORD_LEN, 0}, // MCU_ADDRESS
554 { 0x0990, 0x0022 , WORD_LEN, 0}, // MCU_DATA_0
555 { 0x098C, 0xA409 , WORD_LEN, 0}, // MCU_ADDRESS
556 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
557 { 0x098C, 0xA40A , WORD_LEN, 0}, // MCU_ADDRESS
558 { 0x0990, 0x0029 , WORD_LEN, 0}, // MCU_DATA_0
559 { 0x098C, 0xA40B , WORD_LEN, 0}, // MCU_ADDRESS
560 { 0x0990, 0x002B , WORD_LEN, 0}, // MCU_DATA_0
561 { 0x098C, 0x2411 , WORD_LEN, 0}, // MCU_ADDRESS
562 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
563 { 0x098C, 0x2413 , WORD_LEN, 0}, // MCU_ADDRESS
564 { 0x0990, 0x00A9 , WORD_LEN, 0}, // MCU_DATA_0
565 { 0x098C, 0x2415 , WORD_LEN, 0}, // MCU_ADDRESS
566 { 0x0990, 0x00AA , WORD_LEN, 0}, // MCU_DATA_0
567 { 0x098C, 0x2417 , WORD_LEN, 0}, // MCU_ADDRESS
568 { 0x0990, 0x00CC , WORD_LEN, 0}, // MCU_DATA_0
569 { 0x098C, 0xA404 , WORD_LEN, 0}, // MCU_ADDRESS
570 { 0x0990, 0x0010 , WORD_LEN, 0}, // MCU_DATA_0
571 { 0x098C, 0xA40D , WORD_LEN, 0}, // MCU_ADDRESS
572 { 0x0990, 0x0002 , WORD_LEN, 0}, // MCU_DATA_0
573 { 0x098C, 0xA40E , WORD_LEN, 0}, // MCU_ADDRESS
574 { 0x0990, 0x0003 , WORD_LEN, 0}, // MCU_DATA_0
575 { 0x098C, 0xA410 , WORD_LEN, 0}, // MCU_ADDRESS
576 { 0x0990, 0x000A , WORD_LEN, 0}, // MCU_DATA_0
577 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
578 { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
579 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
580 { 0x0990, 0x0005 , WORD_LEN, 0}, // MCU_DATA_0
585 static struct reginfo sensor_vga[] =
591 static struct reginfo sensor_cif[] =
597 static struct reginfo sensor_qvga[] =
603 static struct reginfo sensor_qcif[] =
609 static struct reginfo sensor_Preview2Capture[]=
612 {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
613 {0x843C, 0xFF, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
614 {0x8404, 0x02, BYTE_LEN, 0 }, // SEQ_CMD
618 static struct reginfo sensor_Capture2Preview[]=
621 {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
622 {0x843C, 0x01, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
623 {0x8404, 0x01, BYTE_LEN, 0 }, // SEQ_CMD
624 {0x0016, 0x0047, WORD_LEN, 0}, // CLOCKS_CONTRO
628 static struct reginfo sensor_ClrFmt_YUYV[]=
633 static struct reginfo sensor_ClrFmt_UYVY[]=
639 #if CONFIG_SENSOR_WhiteBalance
640 static struct reginfo sensor_WhiteB_Auto[]=
645 /* Cloudy Colour Temperature : 6500K - 8000K */
646 static struct reginfo sensor_WhiteB_Cloudy[]=
651 /* ClearDay Colour Temperature : 5000K - 6500K */
652 static struct reginfo sensor_WhiteB_ClearDay[]=
657 /* Office Colour Temperature : 3500K - 5000K */
658 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
663 /* Home Colour Temperature : 2500K - 3500K */
664 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
669 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
670 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
674 #if CONFIG_SENSOR_Brightness
675 static struct reginfo sensor_Brightness0[]=
680 static struct reginfo sensor_Brightness1[]=
685 static struct reginfo sensor_Brightness2[]=
690 static struct reginfo sensor_Brightness3[]=
695 static struct reginfo sensor_Brightness4[]=
700 static struct reginfo sensor_Brightness5[]=
704 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
705 sensor_Brightness4, sensor_Brightness5,NULL,
710 #if CONFIG_SENSOR_Effect
711 static struct reginfo sensor_Effect_Normal[] =
716 static struct reginfo sensor_Effect_WandB[] =
721 static struct reginfo sensor_Effect_Sepia[] =
726 static struct reginfo sensor_Effect_Negative[] =
730 static struct reginfo sensor_Effect_Bluish[] =
735 static struct reginfo sensor_Effect_Green[] =
740 static struct reginfo sensor_Effect_Solarize[] =
744 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_Negative,sensor_Effect_Sepia,
745 sensor_Effect_Solarize,NULL,
748 #if CONFIG_SENSOR_Exposure
749 static struct reginfo sensor_Exposure0[]=
754 static struct reginfo sensor_Exposure1[]=
759 static struct reginfo sensor_Exposure2[]=
764 static struct reginfo sensor_Exposure3[]=
769 static struct reginfo sensor_Exposure4[]=
774 static struct reginfo sensor_Exposure5[]=
779 static struct reginfo sensor_Exposure6[]=
784 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
785 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
788 #if CONFIG_SENSOR_Saturation
789 static struct reginfo sensor_Saturation0[]=
794 static struct reginfo sensor_Saturation1[]=
799 static struct reginfo sensor_Saturation2[]=
803 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
805 #if CONFIG_SENSOR_Contrast
806 static struct reginfo sensor_Contrast0[]=
811 static struct reginfo sensor_Contrast1[]=
816 static struct reginfo sensor_Contrast2[]=
821 static struct reginfo sensor_Contrast3[]=
826 static struct reginfo sensor_Contrast4[]=
832 static struct reginfo sensor_Contrast5[]=
837 static struct reginfo sensor_Contrast6[]=
841 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
842 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
846 #if CONFIG_SENSOR_Mirror
847 static struct reginfo sensor_MirrorOn[]=
852 static struct reginfo sensor_MirrorOff[]=
856 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
858 #if CONFIG_SENSOR_Flip
859 static struct reginfo sensor_FlipOn[]=
864 static struct reginfo sensor_FlipOff[]=
868 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
871 #if CONFIG_SENSOR_Scene
872 static struct reginfo sensor_SceneAuto[] =
877 static struct reginfo sensor_SceneNight[] =
881 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
884 #if CONFIG_SENSOR_DigitalZoom
885 static struct reginfo sensor_Zoom0[] =
890 static struct reginfo sensor_Zoom1[] =
895 static struct reginfo sensor_Zoom2[] =
901 static struct reginfo sensor_Zoom3[] =
905 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
907 static const struct v4l2_querymenu sensor_menus[] =
909 #if CONFIG_SENSOR_WhiteBalance
910 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
911 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
912 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
915 #if CONFIG_SENSOR_Effect
916 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "negative", .reserved = 0,},
917 { .id = V4L2_CID_EFFECT, .index = 2, .name = "sepia", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "solarize", .reserved = 0,},
920 #if CONFIG_SENSOR_Scene
921 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
924 #if CONFIG_SENSOR_Flash
925 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
926 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
930 static struct v4l2_queryctrl sensor_controls[] =
932 #if CONFIG_SENSOR_WhiteBalance
934 .id = V4L2_CID_DO_WHITE_BALANCE,
935 .type = V4L2_CTRL_TYPE_MENU,
936 .name = "White Balance Control",
944 #if CONFIG_SENSOR_Brightness
946 .id = V4L2_CID_BRIGHTNESS,
947 .type = V4L2_CTRL_TYPE_INTEGER,
948 .name = "Brightness Control",
956 #if CONFIG_SENSOR_Effect
958 .id = V4L2_CID_EFFECT,
959 .type = V4L2_CTRL_TYPE_MENU,
960 .name = "Effect Control",
968 #if CONFIG_SENSOR_Exposure
970 .id = V4L2_CID_EXPOSURE,
971 .type = V4L2_CTRL_TYPE_INTEGER,
972 .name = "Exposure Control",
980 #if CONFIG_SENSOR_Saturation
982 .id = V4L2_CID_SATURATION,
983 .type = V4L2_CTRL_TYPE_INTEGER,
984 .name = "Saturation Control",
992 #if CONFIG_SENSOR_Contrast
994 .id = V4L2_CID_CONTRAST,
995 .type = V4L2_CTRL_TYPE_INTEGER,
996 .name = "Contrast Control",
1004 #if CONFIG_SENSOR_Mirror
1006 .id = V4L2_CID_HFLIP,
1007 .type = V4L2_CTRL_TYPE_BOOLEAN,
1008 .name = "Mirror Control",
1016 #if CONFIG_SENSOR_Flip
1018 .id = V4L2_CID_VFLIP,
1019 .type = V4L2_CTRL_TYPE_BOOLEAN,
1020 .name = "Flip Control",
1028 #if CONFIG_SENSOR_Scene
1030 .id = V4L2_CID_SCENE,
1031 .type = V4L2_CTRL_TYPE_MENU,
1032 .name = "Scene Control",
1040 #if CONFIG_SENSOR_DigitalZoom
1042 .id = V4L2_CID_ZOOM_RELATIVE,
1043 .type = V4L2_CTRL_TYPE_INTEGER,
1044 .name = "DigitalZoom Control",
1050 .id = V4L2_CID_ZOOM_ABSOLUTE,
1051 .type = V4L2_CTRL_TYPE_INTEGER,
1052 .name = "DigitalZoom Control",
1060 #if CONFIG_SENSOR_Focus
1062 .id = V4L2_CID_FOCUS_RELATIVE,
1063 .type = V4L2_CTRL_TYPE_INTEGER,
1064 .name = "Focus Control",
1070 .id = V4L2_CID_FOCUS_ABSOLUTE,
1071 .type = V4L2_CTRL_TYPE_INTEGER,
1072 .name = "Focus Control",
1076 .default_value = 125,
1079 .id = V4L2_CID_FOCUS_AUTO,
1080 .type = V4L2_CTRL_TYPE_BOOLEAN,
1081 .name = "Focus Control",
1087 .id = V4L2_CID_FOCUS_CONTINUOUS,
1088 .type = V4L2_CTRL_TYPE_BOOLEAN,
1089 .name = "Focus Control",
1097 #if CONFIG_SENSOR_Flash
1099 .id = V4L2_CID_FLASH,
1100 .type = V4L2_CTRL_TYPE_MENU,
1101 .name = "Flash Control",
1110 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1111 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1112 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1113 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1114 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1115 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1116 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1117 static int sensor_resume(struct soc_camera_device *icd);
1118 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1119 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1120 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1121 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1122 static int sensor_deactivate(struct i2c_client *client);
1124 static struct soc_camera_ops sensor_ops =
1126 .suspend = sensor_suspend,
1127 .resume = sensor_resume,
1128 .set_bus_param = sensor_set_bus_param,
1129 .query_bus_param = sensor_query_bus_param,
1130 .controls = sensor_controls,
1131 .menus = sensor_menus,
1132 .num_controls = ARRAY_SIZE(sensor_controls),
1133 .num_menus = ARRAY_SIZE(sensor_menus),
1136 /* only one fixed colorspace per pixelcode */
1137 struct sensor_datafmt {
1138 enum v4l2_mbus_pixelcode code;
1139 enum v4l2_colorspace colorspace;
1142 /* Find a data format by a pixel code in an array */
1143 static const struct sensor_datafmt *sensor_find_datafmt(
1144 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1148 for (i = 0; i < n; i++)
1149 if (fmt[i].code == code)
1155 static const struct sensor_datafmt sensor_colour_fmts[] = {
1156 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1157 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1159 enum sensor_work_state
1161 sensor_work_ready = 0,
1166 struct i2c_client *client;
1167 struct delayed_work dwork;
1168 enum sensor_work_state state;
1171 typedef struct sensor_info_priv_s
1185 unsigned char mirror; /* HFLIP */
1186 unsigned char flip; /* VFLIP */
1193 struct reginfo *winseqe_cur_addr;
1194 struct sensor_datafmt fmt;
1195 unsigned int enable;
1196 unsigned int funmodule_state;
1197 } sensor_info_priv_t;
1201 struct sensor_parameter
1203 unsigned short int preview_maxlines;
1204 unsigned short int preview_exposure;
1205 unsigned short int preview_line_width;
1206 unsigned short int preview_gain;
1208 unsigned short int capture_framerate;
1209 unsigned short int preview_framerate;
1214 struct v4l2_subdev subdev;
1215 struct i2c_client *client;
1216 sensor_info_priv_t info_priv;
1217 struct sensor_parameter parameter;
1218 struct workqueue_struct *sensor_wq;
1219 struct sensor_work sensor_wk;
1220 struct mutex wq_lock;
1221 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1222 #if CONFIG_SENSOR_I2C_NOSCHED
1223 atomic_t tasklock_cnt;
1225 struct rk29camera_platform_data *sensor_io_request;
1226 struct rk29camera_gpio_res *sensor_gpio_res;
1229 static struct sensor* to_sensor(const struct i2c_client *client)
1231 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1234 static int sensor_task_lock(struct i2c_client *client, int lock)
1236 #if CONFIG_SENSOR_I2C_NOSCHED
1238 struct sensor *sensor = to_sensor(client);
1241 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1242 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1243 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1247 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1248 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1249 goto sensor_task_lock_err;
1254 atomic_add(1, &sensor->tasklock_cnt);
1256 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1257 atomic_sub(1, &sensor->tasklock_cnt);
1259 if (atomic_read(&sensor->tasklock_cnt) == 0)
1265 sensor_task_lock_err:
1272 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val);
1274 /* sensor register write */
1275 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1279 struct i2c_msg msg[1];
1281 switch (reg_info->reg)
1283 case SEQUENCE_WAIT_MS:
1286 mdelay(reg_info->val);
1288 msleep(reg_info->val);
1292 case SEQUENCE_WAIT_US:
1294 udelay(reg_info->val);
1298 case SEQUENCE_PROPERTY:
1304 buf[0] = reg_info->reg >> 8;
1305 buf[1] = reg_info->reg & 0xFF;
1306 if (reg_info->reg_len == WORD_LEN) {
1307 buf[2] = reg_info->val >> 8;
1308 buf[3] = reg_info->val & 0xFF;
1311 } else if (reg_info->reg_len == BYTE_LEN) {
1312 buf[2] = reg_info->val;
1316 msg->addr = client->addr;
1317 msg->flags = client->flags;
1319 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1320 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1325 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1326 err = i2c_transfer(client->adapter, msg, 1);
1331 SENSOR_TR("\n %s write reg(0x%x, val:0x%x) failed, try to write again!\n",SENSOR_NAME_STRING(),reg_info->reg, reg_info->val);
1340 /* sensor register read */
1341 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1345 struct i2c_msg msg[2];
1348 buf[1] = reg & 0xFF;
1350 msg[0].addr = client->addr;
1351 msg[0].flags = client->flags;
1353 msg[0].len = sizeof(buf);
1354 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1355 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1357 msg[1].addr = client->addr;
1358 msg[1].flags = client->flags|I2C_M_RD;
1361 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1362 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1366 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1367 err = i2c_transfer(client->adapter, msg, 2);
1370 *val = buf[0]<<8 | buf[1];
1373 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1381 /* write a array of registers */
1382 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1386 #if CONFIG_SENSOR_I2C_RDWRCHK
1391 if (sensor_task_lock(client, 1) < 0)
1392 goto sensor_write_array_end;
1393 while (regarray[i].reg != SEQUENCE_END) {
1394 err = sensor_write(client, ®array[i]);
1398 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1402 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1404 goto sensor_write_array_end;
1407 #if CONFIG_SENSOR_I2C_RDWRCHK
1408 sensor_read(client, regarray[i].reg, &valchk);
1409 if (valchk != regarray[i].val)
1410 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1417 sensor_write_array_end:
1418 sensor_task_lock(client,0);
1421 #if CONFIG_SENSOR_I2C_RDWRCHK
1422 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1430 while (regarray[i].reg != SEQUENCE_END)
1432 sensor_read(client, regarray[i].reg, &valchk);
1433 if (valchk != regarray[i].val)
1434 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1441 #if CONFIG_SENSOR_Focus
1442 static struct reginfo sensor_af_init0[] =
1445 {SEQUENCE_END, 0x00}
1447 static struct reginfo sensor_af_init1[] =
1449 {SEQUENCE_END, 0x00}
1453 static struct reginfo sensor_af_trigger[] =
1455 {SEQUENCE_END, 0x00}
1457 static int sensor_af_single(struct i2c_client *client)
1461 ret = sensor_write_array(client, sensor_af_trigger);
1463 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1465 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1466 sensor_af_single_end:
1470 static int sensor_af_const(struct i2c_client *client)
1474 sensor_af_const_end:
1478 static int sensor_af_zoneupdate(struct i2c_client *client)
1481 struct i2c_msg msg[2];
1484 {0xb0,0x08,0x00,0x03,0xff,0xff},
1485 {0xb0,0x0c,0xff,0xff,0xff,0xff},
1488 msg[0].addr = client->addr;
1489 msg[0].flags = client->flags;
1490 msg[0].buf = buf[0];
1491 msg[0].len = sizeof(buf);
1492 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1493 msg[0].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1495 msg[1].addr = client->addr;
1496 msg[1].flags = client->flags;
1497 msg[1].buf = buf[1];
1498 msg[1].len = sizeof(buf);
1499 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1500 msg[1].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1502 ret = i2c_transfer(client->adapter, &msg[0], 1);
1503 ret |= i2c_transfer(client->adapter, &msg[1], 1);
1507 SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
1510 sensor_af_zoneupdate_end:
1514 static int sensor_af_init(struct i2c_client *client)
1518 ret = sensor_write_array(client, sensor_af_init0);
1520 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1522 if (sensor_af_zoneupdate(client) == 0) {
1523 ret = sensor_write_array(client, sensor_af_init1);
1525 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1534 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1536 struct soc_camera_link *icl = to_soc_camera_link(icd);
1539 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1542 case Sensor_PowerDown:
1544 if (icl->powerdown) {
1545 ret = icl->powerdown(icd->pdev, on);
1546 if (ret == RK29_CAM_IO_SUCCESS) {
1550 icl->reset(icd->pdev);
1552 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1554 goto sensor_power_end;
1561 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1562 struct sensor *sensor = to_sensor(client);
1564 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1565 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1567 //flash off after 2 secs
1568 hrtimer_cancel(&(flash_off_timer.timer));
1569 hrtimer_start(&(flash_off_timer.timer),ktime_set(0, 800*1000*1000),HRTIMER_MODE_REL);
1576 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1585 static enum hrtimer_restart flash_off_func(struct hrtimer *timer){
1586 struct flash_timer *fps_timer = container_of(timer, struct flash_timer, timer);
1587 sensor_ioctrl(fps_timer->icd,Sensor_Flash,0);
1588 SENSOR_DG("%s %s !!!!!!",SENSOR_NAME_STRING(),__FUNCTION__);
1593 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1595 struct i2c_client *client = v4l2_get_subdevdata(sd);
1596 struct soc_camera_device *icd = client->dev.platform_data;
1597 struct sensor *sensor = to_sensor(client);
1598 const struct v4l2_queryctrl *qctrl;
1599 const struct sensor_datafmt *fmt;
1603 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1605 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1607 goto sensor_INIT_ERR;
1611 if (sensor_task_lock(client,1)<0)
1612 goto sensor_INIT_ERR;
1614 #if (SENSOR_RESET_REG != SEQUENCE_END)
1615 struct reginfo reg_info;
1616 reg_info.reg = SENSOR_RESET_REG;
1617 reg_info.val = SENSOR_RESET_VAL;
1618 reg_info.reg_len = SENSOR_RESET_REG_LEN;
1619 ret = sensor_write(client, ®_info);
1621 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1623 goto sensor_INIT_ERR;
1625 mdelay(5); //delay 5 microseconds
1626 reg_info.val = SENSOR_DERESET_VAL;
1627 ret = sensor_write(client, ®_info);
1629 SENSOR_TR("%s soft dereset sensor failed\n",SENSOR_NAME_STRING());
1631 goto sensor_INIT_ERR;
1635 /* check if it is an sensor sensor */
1636 #if (SENSOR_ID_REG != SEQUENCE_END)
1637 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1639 SENSOR_TR("read chip id failed\n");
1641 goto sensor_INIT_ERR;
1644 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1648 if (pid == SENSOR_ID) {
1649 sensor->model = SENSOR_V4L2_IDENT;
1651 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1653 goto sensor_INIT_ERR;
1656 ret = sensor_write_array(client, sensor_init_data);
1659 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1660 goto sensor_INIT_ERR;
1662 sensor_task_lock(client,0);
1663 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1664 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1665 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1666 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1667 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1668 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1670 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1672 goto sensor_INIT_ERR;
1674 sensor->info_priv.fmt = *fmt;
1676 /* sensor sensor information for initialization */
1677 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1679 sensor->info_priv.whiteBalance = qctrl->default_value;
1680 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1682 sensor->info_priv.brightness = qctrl->default_value;
1683 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1685 sensor->info_priv.effect = qctrl->default_value;
1686 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1688 sensor->info_priv.exposure = qctrl->default_value;
1690 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1692 sensor->info_priv.saturation = qctrl->default_value;
1693 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1695 sensor->info_priv.contrast = qctrl->default_value;
1696 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1698 sensor->info_priv.mirror = qctrl->default_value;
1699 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1701 sensor->info_priv.flip = qctrl->default_value;
1702 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1704 sensor->info_priv.scene = qctrl->default_value;
1705 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1707 sensor->info_priv.digitalzoom = qctrl->default_value;
1709 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1710 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1712 sensor->info_priv.focus = qctrl->default_value;
1713 #if CONFIG_SENSOR_Focus
1714 if (sensor_af_init(client) < 0) {
1715 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1716 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1718 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1719 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1722 #if CONFIG_SENSOR_Flash
1723 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1725 sensor->info_priv.flash = qctrl->default_value;
1726 flash_off_timer.icd = icd;
1727 flash_off_timer.timer.function = flash_off_func;
1729 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);
1733 sensor_task_lock(client,0);
1734 sensor_deactivate(client);
1737 static int sensor_deactivate(struct i2c_client *client)
1739 struct soc_camera_device *icd = client->dev.platform_data;
1741 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1743 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1744 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1746 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1747 icd->user_width = SENSOR_INIT_WIDTH;
1748 icd->user_height = SENSOR_INIT_HEIGHT;
1752 static struct reginfo sensor_power_down_sequence[]=
1756 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1759 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1761 if (pm_msg.event == PM_EVENT_SUSPEND) {
1762 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1763 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1765 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1768 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1770 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1775 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1782 static int sensor_resume(struct soc_camera_device *icd)
1786 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1788 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1792 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1796 static int sensor_set_bus_param(struct soc_camera_device *icd,
1797 unsigned long flags)
1803 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1805 struct soc_camera_link *icl = to_soc_camera_link(icd);
1806 unsigned long flags = SENSOR_BUS_PARAM;
1808 return soc_camera_apply_sensor_flags(icl, flags);
1810 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1812 struct i2c_client *client = v4l2_get_subdevdata(sd);
1813 struct soc_camera_device *icd = client->dev.platform_data;
1814 struct sensor *sensor = to_sensor(client);
1816 mf->width = icd->user_width;
1817 mf->height = icd->user_height;
1818 mf->code = sensor->info_priv.fmt.code;
1819 mf->colorspace = sensor->info_priv.fmt.colorspace;
1820 mf->field = V4L2_FIELD_NONE;
1824 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1828 if ((mf->width == 1024) && (mf->height == 768)) {
1830 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1832 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1834 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1836 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1841 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1845 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1849 if ((mf->width == 1280) && (mf->height == 720)) {
1851 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1856 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1859 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1861 struct reginfo *winseqe_set_addr = NULL;
1863 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1864 winseqe_set_addr = sensor_qcif;
1867 } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1868 winseqe_set_addr = sensor_qvga;
1871 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1872 winseqe_set_addr = sensor_cif;
1875 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1876 winseqe_set_addr = sensor_vga;
1879 } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1880 printk("enter 800x600\n");
1881 winseqe_set_addr = sensor_svga;
1884 } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1885 winseqe_set_addr = sensor_xga;
1888 } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1889 printk("enter 1280X720\n");
1890 winseqe_set_addr = sensor_720p;
1893 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1894 printk("enter 1280X1024\n");
1895 winseqe_set_addr = sensor_sxga;
1898 } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1899 winseqe_set_addr = sensor_uxga;
1902 } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1903 winseqe_set_addr = sensor_1080p;
1906 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1907 winseqe_set_addr = sensor_qxga;
1910 } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1911 winseqe_set_addr = sensor_qsxga;
1916 return winseqe_set_addr;
1919 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1921 struct i2c_client *client = v4l2_get_subdevdata(sd);
1922 struct sensor *sensor = to_sensor(client);
1923 const struct sensor_datafmt *fmt;
1924 struct reginfo *winseqe_set_addr=NULL;
1925 int ret = 0, set_w,set_h;
1927 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
1929 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1930 ARRAY_SIZE(sensor_colour_fmts));
1933 goto sensor_s_fmt_end;
1936 if (sensor->info_priv.fmt.code != mf->code) {
1939 case V4L2_MBUS_FMT_YUYV8_2X8:
1941 winseqe_set_addr = sensor_ClrFmt_YUYV;
1944 case V4L2_MBUS_FMT_UYVY8_2X8:
1946 winseqe_set_addr = sensor_ClrFmt_UYVY;
1952 if (winseqe_set_addr != NULL) {
1953 sensor_write_array(client, winseqe_set_addr);
1954 sensor->info_priv.fmt.code = mf->code;
1955 sensor->info_priv.fmt.colorspace= mf->colorspace;
1956 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1958 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1965 winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1967 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1968 ret |= sensor_write_array(client, winseqe_set_addr);
1970 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1971 goto sensor_s_fmt_end;
1973 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
1974 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1975 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1977 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1978 sensor->info_priv.preview_w = mf->width;
1979 sensor->info_priv.preview_h = mf->height;
1983 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1984 ret |= sensor_write_array(client, sensor_Preview2Capture);
1986 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
1987 goto sensor_s_fmt_end;
1989 sensor->info_priv.capture_w = set_w;
1990 sensor->info_priv.capture_h = set_h;
1991 sensor->info_priv.snap2preview = true;
1992 } else if (sensor->info_priv.snap2preview == true) {
1993 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
1994 ret |= sensor_write_array(client, sensor_Capture2Preview);
1996 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
1997 goto sensor_s_fmt_end;
1999 sensor->info_priv.preview_w = mf->width;
2000 sensor->info_priv.preview_h = mf->height;
2001 sensor->info_priv.snap2preview = false;
2003 SENSOR_TR("\n %s..%s Format is Invalidate. mf->width = %d.. mf->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
2013 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
2016 struct i2c_client *client = v4l2_get_subdevdata(sd);
2017 struct sensor *sensor = to_sensor(client);
2018 const struct sensor_datafmt *fmt;
2020 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
2021 ARRAY_SIZE(sensor_colour_fmts));
2023 fmt = &sensor->info_priv.fmt;
2024 mf->code = fmt->code;
2027 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
2030 * With Bayer format enforce even side lengths, but let the user play
2031 * with the starting pixel
2034 if (mf->height > SENSOR_MAX_HEIGHT)
2035 mf->height = SENSOR_MAX_HEIGHT;
2036 else if (mf->height < SENSOR_MIN_HEIGHT)
2037 mf->height = SENSOR_MIN_HEIGHT;
2039 if (mf->width > SENSOR_MAX_WIDTH)
2040 mf->width = SENSOR_MAX_WIDTH;
2041 else if (mf->width < SENSOR_MIN_WIDTH)
2042 mf->width = SENSOR_MIN_WIDTH;
2044 if (sensor_fmt_catch(mf->width, mf->height, &mf->width, &mf->height) == NULL) {
2045 printk("%s[%d] ERR!!!!!!",__FUNCTION__,__LINE__);
2053 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2055 struct i2c_client *client = v4l2_get_subdevdata(sd);
2057 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2060 if (id->match.addr != client->addr)
2063 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2068 #if CONFIG_SENSOR_Brightness
2069 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2071 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2073 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2075 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2077 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2079 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2082 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2086 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2090 #if CONFIG_SENSOR_Effect
2091 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2093 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2095 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2097 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2099 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2101 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2104 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2108 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2112 #if CONFIG_SENSOR_Exposure
2113 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2115 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2117 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2119 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2121 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2123 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2126 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2130 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2134 #if CONFIG_SENSOR_Saturation
2135 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2137 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2139 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2141 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2143 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2145 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2148 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2152 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2156 #if CONFIG_SENSOR_Contrast
2157 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2159 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2161 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2163 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2165 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2167 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2170 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2174 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2178 #if CONFIG_SENSOR_Mirror
2179 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2181 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2183 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2185 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2187 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2189 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2192 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2196 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2200 #if CONFIG_SENSOR_Flip
2201 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2203 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2205 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2207 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2209 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2211 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2214 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2218 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2222 #if CONFIG_SENSOR_Scene
2223 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2225 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2227 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2229 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2231 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2233 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2236 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2240 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2244 #if CONFIG_SENSOR_WhiteBalance
2245 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2247 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2249 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2251 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2253 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2255 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2258 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2262 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2266 #if CONFIG_SENSOR_DigitalZoom
2267 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2269 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2270 struct sensor *sensor = to_sensor(client);
2271 const struct v4l2_queryctrl *qctrl_info;
2272 int digitalzoom_cur, digitalzoom_total;
2274 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2278 digitalzoom_cur = sensor->info_priv.digitalzoom;
2279 digitalzoom_total = qctrl_info->maximum;
2281 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2283 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2287 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2289 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2293 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2295 *value = digitalzoom_total - digitalzoom_cur;
2298 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2300 *value = 0 - digitalzoom_cur;
2303 digitalzoom_cur += *value;
2305 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2307 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2309 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2312 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2319 #if CONFIG_SENSOR_Flash
2320 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2322 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2323 struct sensor *sensor = to_sensor(client);
2324 const struct v4l2_queryctrl *qctrl_info;
2326 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2327 if (value == 3) { /* ddl@rock-chips.com: torch */
2328 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2330 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2332 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2336 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2340 #if CONFIG_SENSOR_Focus
2341 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2343 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2344 struct sensor *sensor = to_sensor(client);
2345 const struct v4l2_queryctrl *qctrl_info;
2348 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2352 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2353 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2355 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2358 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2362 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2363 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2366 sensor_set_focus_absolute_end:
2369 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2371 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2372 struct sensor *sensor = to_sensor(client);
2373 const struct v4l2_queryctrl *qctrl_info;
2376 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2380 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2381 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2383 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2386 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2390 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2391 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2393 sensor_set_focus_relative_end:
2397 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2399 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2400 struct sensor *sensor = to_sensor(client);
2403 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2406 case SENSOR_AF_MODE_AUTO:
2408 ret = sensor_af_single(client);
2412 case SENSOR_AF_MODE_MACRO:
2414 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2418 case SENSOR_AF_MODE_INFINITY:
2420 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2424 case SENSOR_AF_MODE_CONTINUOUS:
2426 ret = sensor_af_const(client);
2430 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2435 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2438 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2439 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2445 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2447 struct i2c_client *client = v4l2_get_subdevdata(sd);
2448 struct sensor *sensor = to_sensor(client);
2449 const struct v4l2_queryctrl *qctrl;
2451 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2455 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2461 case V4L2_CID_BRIGHTNESS:
2463 ctrl->value = sensor->info_priv.brightness;
2466 case V4L2_CID_SATURATION:
2468 ctrl->value = sensor->info_priv.saturation;
2471 case V4L2_CID_CONTRAST:
2473 ctrl->value = sensor->info_priv.contrast;
2476 case V4L2_CID_DO_WHITE_BALANCE:
2478 ctrl->value = sensor->info_priv.whiteBalance;
2481 case V4L2_CID_EXPOSURE:
2483 ctrl->value = sensor->info_priv.exposure;
2486 case V4L2_CID_HFLIP:
2488 ctrl->value = sensor->info_priv.mirror;
2491 case V4L2_CID_VFLIP:
2493 ctrl->value = sensor->info_priv.flip;
2504 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2506 struct i2c_client *client = v4l2_get_subdevdata(sd);
2507 const struct v4l2_queryctrl *qctrl;
2508 struct sensor *sensor = to_sensor(client);
2509 struct soc_camera_device *icd = client->dev.platform_data;
2510 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2514 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2520 #if CONFIG_SENSOR_Brightness
2521 case V4L2_CID_BRIGHTNESS:
2523 if (ctrl->value != sensor->info_priv.brightness)
2525 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2529 sensor->info_priv.brightness = ctrl->value;
2534 #if CONFIG_SENSOR_Exposure
2535 case V4L2_CID_EXPOSURE:
2537 if (ctrl->value != sensor->info_priv.exposure)
2539 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2543 sensor->info_priv.exposure = ctrl->value;
2548 #if CONFIG_SENSOR_Saturation
2549 case V4L2_CID_SATURATION:
2551 if (ctrl->value != sensor->info_priv.saturation)
2553 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2557 sensor->info_priv.saturation = ctrl->value;
2562 #if CONFIG_SENSOR_Contrast
2563 case V4L2_CID_CONTRAST:
2565 if (ctrl->value != sensor->info_priv.contrast)
2567 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2571 sensor->info_priv.contrast = ctrl->value;
2576 #if CONFIG_SENSOR_WhiteBalance
2577 case V4L2_CID_DO_WHITE_BALANCE:
2579 if (ctrl->value != sensor->info_priv.whiteBalance)
2581 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2585 sensor->info_priv.whiteBalance = ctrl->value;
2590 #if CONFIG_SENSOR_Mirror
2591 case V4L2_CID_HFLIP:
2593 if (ctrl->value != sensor->info_priv.mirror)
2595 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2597 sensor->info_priv.mirror = ctrl->value;
2602 #if CONFIG_SENSOR_Flip
2603 case V4L2_CID_VFLIP:
2605 if (ctrl->value != sensor->info_priv.flip)
2607 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2609 sensor->info_priv.flip = ctrl->value;
2620 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2622 const struct v4l2_queryctrl *qctrl;
2623 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2624 struct sensor *sensor = to_sensor(client);
2626 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2630 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2634 switch (ext_ctrl->id)
2636 case V4L2_CID_SCENE:
2638 ext_ctrl->value = sensor->info_priv.scene;
2641 case V4L2_CID_EFFECT:
2643 ext_ctrl->value = sensor->info_priv.effect;
2646 case V4L2_CID_ZOOM_ABSOLUTE:
2648 ext_ctrl->value = sensor->info_priv.digitalzoom;
2651 case V4L2_CID_ZOOM_RELATIVE:
2655 case V4L2_CID_FOCUS_ABSOLUTE:
2659 case V4L2_CID_FOCUS_RELATIVE:
2663 case V4L2_CID_FLASH:
2665 ext_ctrl->value = sensor->info_priv.flash;
2673 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2675 const struct v4l2_queryctrl *qctrl;
2676 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2677 struct sensor *sensor = to_sensor(client);
2680 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2684 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2689 switch (ext_ctrl->id)
2691 #if CONFIG_SENSOR_Scene
2692 case V4L2_CID_SCENE:
2694 if (ext_ctrl->value != sensor->info_priv.scene)
2696 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2698 sensor->info_priv.scene = ext_ctrl->value;
2703 #if CONFIG_SENSOR_Effect
2704 case V4L2_CID_EFFECT:
2706 if (ext_ctrl->value != sensor->info_priv.effect)
2708 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2710 sensor->info_priv.effect= ext_ctrl->value;
2715 #if CONFIG_SENSOR_DigitalZoom
2716 case V4L2_CID_ZOOM_ABSOLUTE:
2718 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2721 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2723 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2725 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2727 sensor->info_priv.digitalzoom += val_offset;
2729 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2734 case V4L2_CID_ZOOM_RELATIVE:
2736 if (ext_ctrl->value)
2738 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2740 sensor->info_priv.digitalzoom += ext_ctrl->value;
2742 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2747 #if CONFIG_SENSOR_Focus
2748 case V4L2_CID_FOCUS_ABSOLUTE:
2750 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2753 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2754 if (ext_ctrl->value == qctrl->minimum) {
2755 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2756 } else if (ext_ctrl->value == qctrl->maximum) {
2757 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2759 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2765 case V4L2_CID_FOCUS_RELATIVE:
2767 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2770 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2773 case V4L2_CID_FOCUS_AUTO:
2775 if (ext_ctrl->value == 1) {
2776 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2778 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2779 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2780 if (ext_ctrl->value == 0)
2781 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2785 case V4L2_CID_FOCUS_CONTINUOUS:
2787 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2788 if (ext_ctrl->value == 1) {
2789 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2791 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2794 if (ext_ctrl->value == 0)
2795 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2800 #if CONFIG_SENSOR_Flash
2801 case V4L2_CID_FLASH:
2803 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2805 sensor->info_priv.flash = ext_ctrl->value;
2807 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2818 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2820 struct i2c_client *client = v4l2_get_subdevdata(sd);
2821 struct soc_camera_device *icd = client->dev.platform_data;
2822 int i, error_cnt=0, error_idx=-1;
2825 for (i=0; i<ext_ctrl->count; i++) {
2826 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2833 error_idx = ext_ctrl->count;
2835 if (error_idx != -1) {
2836 ext_ctrl->error_idx = error_idx;
2843 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2845 struct i2c_client *client = v4l2_get_subdevdata(sd);
2846 struct soc_camera_device *icd = client->dev.platform_data;
2847 int i, error_cnt=0, error_idx=-1;
2849 for (i=0; i<ext_ctrl->count; i++) {
2850 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2857 error_idx = ext_ctrl->count;
2859 if (error_idx != -1) {
2860 ext_ctrl->error_idx = error_idx;
2867 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2869 struct i2c_client *client = v4l2_get_subdevdata(sd);
2870 struct sensor *sensor = to_sensor(client);
2873 sensor->info_priv.enable = 1;
2874 } else if (enable == 0) {
2875 sensor->info_priv.enable = 0;
2881 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2882 * this wasn't our capture interface, so, we wait for the right one */
2883 static int sensor_video_probe(struct soc_camera_device *icd,
2884 struct i2c_client *client)
2887 struct sensor *sensor = to_sensor(client);
2888 #if (SENSOR_ID_REG != SEQUENCE_END)
2892 /* We must have a parent by now. And it cannot be a wrong one.
2893 * So this entire test is completely redundant. */
2894 if (!icd->dev.parent ||
2895 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2898 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2900 goto sensor_video_probe_err;
2904 #if (SENSOR_RESET_REG != SEQUENCE_END)
2905 struct reginfo reg_info;
2906 reg_info.reg = SENSOR_RESET_REG;
2907 reg_info.val = SENSOR_RESET_VAL;
2908 reg_info.reg_len = SENSOR_RESET_REG_LEN;
2909 ret = sensor_write(client, ®_info);
2911 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2913 goto sensor_video_probe_err;
2916 mdelay(5); //delay 5 microseconds
2919 /* check if it is an sensor sensor */
2920 #if (SENSOR_ID_REG != SEQUENCE_END)
2921 ret = sensor_read(client, SENSOR_ID_REG, &pid);
2923 SENSOR_TR("read chip id failed\n");
2925 goto sensor_video_probe_err;
2928 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2933 if (pid == SENSOR_ID) {
2934 sensor->model = SENSOR_V4L2_IDENT;
2936 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2938 goto sensor_video_probe_err;
2945 sensor_video_probe_err:
2949 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2951 struct i2c_client *client = v4l2_get_subdevdata(sd);
2952 struct soc_camera_device *icd = client->dev.platform_data;
2953 struct sensor *sensor = to_sensor(client);
2956 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2959 case RK29_CAM_SUBDEV_DEACTIVATE:
2961 sensor_deactivate(client);
2964 case RK29_CAM_SUBDEV_IOREQUEST:
2966 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2967 if (sensor->sensor_io_request != NULL) {
2968 sensor->sensor_gpio_res = NULL;
2969 for (i=0; i<RK29_CAM_SUPPORT_NUMS;i++) {
2970 if (sensor->sensor_io_request->gpio_res[i].dev_name &&
2971 (strcmp(sensor->sensor_io_request->gpio_res[i].dev_name, dev_name(icd->pdev)) == 0)) {
2972 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[i];
2975 if (sensor->sensor_gpio_res == NULL) {
2976 SENSOR_TR("%s %s obtain gpio resource failed when RK29_CAM_SUBDEV_IOREQUEST \n",SENSOR_NAME_STRING(),__FUNCTION__);
2978 goto sensor_ioctl_end;
2981 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2983 goto sensor_ioctl_end;
2985 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2987 #if CONFIG_SENSOR_Flash
2989 if (sensor->sensor_gpio_res) {
2990 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2991 for (i = 0; i < icd->ops->num_controls; i++) {
2992 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2993 //memset((char*)&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2994 sensor_controls[i].id=0xffff;
2997 sensor->info_priv.flash = 0xff;
2998 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2999 }else{ //two cameras are the same,need to deal diffrently ,zyc
3000 for (i = 0; i < icd->ops->num_controls; i++) {
3001 if(0xffff == icd->ops->controls[i].id){
3002 sensor_controls[i].id=V4L2_CID_FLASH;
3012 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
3020 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
3021 enum v4l2_mbus_pixelcode *code)
3023 if (index >= ARRAY_SIZE(sensor_colour_fmts))
3026 *code = sensor_colour_fmts[index].code;
3029 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
3030 .init = sensor_init,
3031 .g_ctrl = sensor_g_control,
3032 .s_ctrl = sensor_s_control,
3033 .g_ext_ctrls = sensor_g_ext_controls,
3034 .s_ext_ctrls = sensor_s_ext_controls,
3035 .g_chip_ident = sensor_g_chip_ident,
3036 .ioctl = sensor_ioctl,
3039 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
3040 .s_mbus_fmt = sensor_s_fmt,
3041 .g_mbus_fmt = sensor_g_fmt,
3042 .try_mbus_fmt = sensor_try_fmt,
3043 .enum_mbus_fmt = sensor_enum_fmt,
3045 static struct v4l2_subdev_ops sensor_subdev_ops = {
3046 .core = &sensor_subdev_core_ops,
3047 .video = &sensor_subdev_video_ops,
3050 static int sensor_probe(struct i2c_client *client,
3051 const struct i2c_device_id *did)
3053 struct sensor *sensor;
3054 struct soc_camera_device *icd = client->dev.platform_data;
3055 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3056 struct soc_camera_link *icl;
3059 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3061 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3065 icl = to_soc_camera_link(icd);
3067 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3071 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3072 dev_warn(&adapter->dev,
3073 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3077 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3081 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3083 /* Second stage probe - when a capture adapter is there */
3084 icd->ops = &sensor_ops;
3085 sensor->info_priv.fmt = sensor_colour_fmts[0];
3086 #if CONFIG_SENSOR_I2C_NOSCHED
3087 atomic_set(&sensor->tasklock_cnt,0);
3090 ret = sensor_video_probe(icd, client);
3093 i2c_set_clientdata(client, NULL);
3097 hrtimer_init(&(flash_off_timer.timer), CLOCK_MONOTONIC, HRTIMER_MODE_REL);
3098 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3102 static int sensor_remove(struct i2c_client *client)
3104 struct sensor *sensor = to_sensor(client);
3105 struct soc_camera_device *icd = client->dev.platform_data;
3107 #if CONFIG_SENSOR_Focus
3108 if (sensor->sensor_wq) {
3109 destroy_workqueue(sensor->sensor_wq);
3110 sensor->sensor_wq = NULL;
3115 i2c_set_clientdata(client, NULL);
3116 client->driver = NULL;
3122 static const struct i2c_device_id sensor_id[] = {
3123 {SENSOR_NAME_STRING(), 0 },
3126 MODULE_DEVICE_TABLE(i2c, sensor_id);
3128 static struct i2c_driver sensor_i2c_driver = {
3130 .name = SENSOR_NAME_STRING(),
3132 .probe = sensor_probe,
3133 .remove = sensor_remove,
3134 .id_table = sensor_id,
3137 static int __init sensor_mod_init(void)
3139 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3140 return i2c_add_driver(&sensor_i2c_driver);
3143 static void __exit sensor_mod_exit(void)
3145 i2c_del_driver(&sensor_i2c_driver);
3148 device_initcall_sync(sensor_mod_init);
3149 module_exit(sensor_mod_exit);
3151 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3152 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3153 MODULE_LICENSE("GPL");