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 <mach/rk29_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_PIX_FMT_UYVY
64 #define CONFIG_SENSOR_WhiteBalance 0
65 #define CONFIG_SENSOR_Brightness 0
66 #define CONFIG_SENSOR_Contrast 0
67 #define CONFIG_SENSOR_Saturation 0
68 #define CONFIG_SENSOR_Effect 0
69 #define CONFIG_SENSOR_Scene 0
70 #define CONFIG_SENSOR_DigitalZoom 0
71 #define CONFIG_SENSOR_Exposure 0
72 #define CONFIG_SENSOR_Flash 0
73 #define CONFIG_SENSOR_Mirror 0
74 #define CONFIG_SENSOR_Flip 0
75 #define CONFIG_SENSOR_Focus 0
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
110 /* init 800x600 SVGA */
111 static struct reginfo sensor_init_data[] =
115 //for 24MHz input, VCO=MAX PCLK=76.8MHz
116 { 0x0014, 0x21F9, WORD_LEN, 0}, //PLL Control: BYPASS PLL = 8697
117 { 0x0010, 0x0110, WORD_LEN, 0}, //PLL Dividers = 272
118 { 0x0012, 0x1FF7, WORD_LEN, 0}, //PLL P Dividers = 8183
119 { 0x0014, 0x21FB, WORD_LEN, 0}, //PLL Control: PLL_ENABLE on = 8699
120 { 0x0014, 0x20FB, WORD_LEN, 0}, //PLL Control: SEL_LOCK_DET on = 8443
122 { SEQUENCE_WAIT_US, 1, WORD_LEN, 0}, // Allow PLL to lock
124 { 0x0014, 0x20FA, WORD_LEN, 0}, //PLL Control: PLL_BYPASS off = 8442
125 { 0x0018, 0x402D, WORD_LEN, 0},
128 { 0x0018, 0x402C, WORD_LEN, 0},
130 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
132 { 0x321C, 0x0003, WORD_LEN, 0}, //By Pass TxFIFO = 3
133 { 0x098C, 0x2703, WORD_LEN, 0}, //Output Width (A)
134 { 0x0990, 0x0320, WORD_LEN, 0}, // = 800
135 { 0x98C, 0x2705, WORD_LEN, 0}, //Output Height (A)
136 { 0x990, 0x0258 , WORD_LEN, 0}, // = 600
137 { 0x98C, 0x2707, WORD_LEN, 0}, //Output Width (B)
138 { 0x990, 0x0640 , WORD_LEN, 0}, // = 1600
139 { 0x98C, 0x2709 , WORD_LEN, 0}, //Output Height (B)
140 { 0x990, 0x04B0 , WORD_LEN, 0}, // = 1200
141 { 0x98C, 0x270D , WORD_LEN, 0}, //Row Start (A)
142 { 0x990, 0x000 , WORD_LEN, 0}, // = 0
143 { 0x98C, 0x270F , WORD_LEN, 0}, //Column Start (A)
144 { 0x990, 0x000 , WORD_LEN, 0}, // = 0
145 { 0x98C, 0x2711 , WORD_LEN, 0}, //Row End (A)
146 { 0x990, 0x4BD , WORD_LEN, 0}, // = 1213
147 { 0x98C, 0x2713 , WORD_LEN, 0}, //Column End (A)
148 { 0x990, 0x64D , WORD_LEN, 0}, // = 1613
149 { 0x98C, 0x2715 , WORD_LEN, 0}, //Row Speed (A)
150 { 0x990, 0x0111 , WORD_LEN, 0}, // = 273
151 { 0x98C, 0x2717 , WORD_LEN, 0}, //Read Mode (A)
153 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
154 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
155 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
156 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
158 { 0x98C, 0x2719 , WORD_LEN, 0}, //sensor_fine_correction (A)
159 { 0x990, 0x005A , WORD_LEN, 0}, // = 90
160 { 0x98C, 0x271B , WORD_LEN, 0}, //sensor_fine_IT_min (A)
161 { 0x990, 0x01BE , WORD_LEN, 0}, // = 446
162 { 0x98C, 0x271D , WORD_LEN, 0}, //sensor_fine_IT_max_margin (A)
163 { 0x990, 0x0131 , WORD_LEN, 0}, // = 305
164 { 0x98C, 0x271F , WORD_LEN, 0}, //Frame Lines (A)
165 { 0x990, 0x02B3 , WORD_LEN, 0}, // = 691
166 { 0x98C, 0x2721 , WORD_LEN, 0}, //Line Length (A)
167 { 0x990, 0x056D , WORD_LEN, 0}, // = 1389
168 { 0x98C, 0x2723 , WORD_LEN, 0}, //Row Start (B)
169 { 0x990, 0x004 , WORD_LEN, 0}, // = 4
170 { 0x98C, 0x2725 , WORD_LEN, 0}, //Column Start (B)
171 { 0x990, 0x004 , WORD_LEN, 0}, // = 4
172 { 0x98C, 0x2727 , WORD_LEN, 0}, //Row End (B)
173 { 0x990, 0x4BB , WORD_LEN, 0}, // = 1211
174 { 0x98C, 0x2729 , WORD_LEN, 0}, //Column End (B)
175 { 0x990, 0x64B , WORD_LEN, 0}, // = 1611
176 { 0x98C, 0x272B , WORD_LEN, 0}, //Row Speed (B)
177 { 0x990, 0x0111 , WORD_LEN, 0}, // = 273
178 { 0x98C, 0x272D , WORD_LEN, 0}, //Read Mode (B)
179 { 0x990, 0x0024 , WORD_LEN, 0}, // = 36
180 { 0x98C, 0x272F , WORD_LEN, 0}, //sensor_fine_correction (B)
181 { 0x990, 0x003A , WORD_LEN, 0}, // = 58
182 { 0x98C, 0x2731 , WORD_LEN, 0}, //sensor_fine_IT_min (B)
183 { 0x990, 0x00F6 , WORD_LEN, 0}, // = 246
184 { 0x98C, 0x2733 , WORD_LEN, 0}, //sensor_fine_IT_max_margin (B)
185 { 0x990, 0x008B , WORD_LEN, 0}, // = 139
186 { 0x98C, 0x2735 , WORD_LEN, 0}, //Frame Lines (B)
187 { 0x990, 0x050D , WORD_LEN, 0}, // = 1293
188 { 0x98C, 0x2737 , WORD_LEN, 0}, //Line Length (B)
189 { 0x990, 0x0894 , WORD_LEN, 0}, // = 2196
190 { 0x98C, 0x2739 , WORD_LEN, 0}, //Crop_X0 (A)
191 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
192 { 0x98C, 0x273B , WORD_LEN, 0}, //Crop_X1 (A)
193 { 0x990, 0x031F , WORD_LEN, 0}, // = 799
194 { 0x98C, 0x273D , WORD_LEN, 0}, //Crop_Y0 (A)
195 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
196 { 0x98C, 0x273F , WORD_LEN, 0}, //Crop_Y1 (A)
197 { 0x990, 0x0257 , WORD_LEN, 0}, // = 599
198 { 0x98C, 0x2747 , WORD_LEN, 0}, //Crop_X0 (B)
199 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
200 { 0x98C, 0x2749 , WORD_LEN, 0}, //Crop_X1 (B)
201 { 0x990, 0x063F , WORD_LEN, 0}, // = 1599
202 { 0x98C, 0x274B , WORD_LEN, 0}, //Crop_Y0 (B)
203 { 0x990, 0x0000 , WORD_LEN, 0}, // = 0
204 { 0x98C, 0x274D , WORD_LEN, 0}, //Crop_Y1 (B)
205 { 0x990, 0x04AF , WORD_LEN, 0}, // = 1199
206 { 0x98C, 0x222D , WORD_LEN, 0}, //R9 Step
207 { 0x990, 0x0090 , WORD_LEN, 0}, // = 144
208 { 0x98C, 0xA408 , WORD_LEN, 0}, //search_f1_50
209 { 0x990, 0x23 , WORD_LEN, 0}, // = 35
210 { 0x98C, 0xA409 , WORD_LEN, 0}, //search_f2_50
211 { 0x990, 0x25 , WORD_LEN, 0}, // = 37
212 { 0x98C, 0xA40A , WORD_LEN, 0}, //search_f1_60
213 { 0x990, 0x2A , WORD_LEN, 0}, // = 42
214 { 0x98C, 0xA40B , WORD_LEN, 0}, //search_f2_60
215 { 0x990, 0x2C , WORD_LEN, 0}, // = 44
216 { 0x98C, 0x2411 , WORD_LEN, 0}, //R9_Step_60 (A)
217 { 0x990, 0x0090 , WORD_LEN, 0}, // = 144
218 { 0x98C, 0x2413 , WORD_LEN, 0}, //R9_Step_50 (A)
219 { 0x990, 0x00AD , WORD_LEN, 0}, // = 173
220 { 0x98C, 0x2415 , WORD_LEN, 0}, //R9_Step_60 (B)
221 { 0x990, 0x005B , WORD_LEN, 0}, // = 91
222 { 0x98C, 0x2417 , WORD_LEN, 0}, //R9_Step_50 (B)
223 { 0x990, 0x006D , WORD_LEN, 0}, // = 109
224 { 0x98C, 0xA404 , WORD_LEN, 0}, //FD Mode
225 { 0x990, 0x10 , WORD_LEN, 0}, // = 16
226 { 0x98C, 0xA40D , WORD_LEN, 0}, //Stat_min
227 { 0x990, 0x02 , WORD_LEN, 0}, // = 2
228 { 0x98C, 0xA40E , WORD_LEN, 0}, //Stat_max
229 { 0x990, 0x03 , WORD_LEN, 0}, // = 3
230 { 0x98C, 0xA410 , WORD_LEN, 0}, //Min_amplitude
231 { 0x990, 0x0A , WORD_LEN, 0}, // = 10
232 { 0x98C, 0xA103 , WORD_LEN, 0}, //Refresh Sequencer Mode
233 { 0x990, 0x06 , WORD_LEN, 0}, // = 6
234 //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100 // wait for command to be processed
236 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
238 { 0x98C, 0xA103 , WORD_LEN, 0}, //Refresh Sequencer
239 { 0x990, 0x05 , WORD_LEN, 0}, // = 5
241 { SEQUENCE_WAIT_US, 100, WORD_LEN, 0},
243 //POLL_FIELD=SEQ_CMD, !=0, DELAY=10, TIMEOUT=100 // wait for command to be processed
247 //for 24MHz input, VCO=MAX PCLK=76.8MHz
248 { 0x001A, 0x0051, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
249 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
250 { 0x0014, 0x2545, WORD_LEN, 0}, // PLL_CONTROL
251 { 0x0010, 0x011C, WORD_LEN, 0}, // PLL_DIVIDERS
252 { 0x0012, 0x1FF7, WORD_LEN, 0}, // PLL_P_DIVIDERS
253 { 0x0014, 0x2547, WORD_LEN, 0}, // PLL_CONTROL
254 { 0x0014, 0x2447, WORD_LEN, 0}, // PLL_CONTROL
255 { 0x0014, 0x2047, WORD_LEN, 0}, // PLL_CONTROL
256 { 0x0014, 0x2046, WORD_LEN, 0}, // PLL_CONTROL
257 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
258 { 0x0018, 0x4028 , WORD_LEN, 0}, // STANDBY_CONTROL
259 { 0x321C, 0x0003 , WORD_LEN, 0}, // OFIFO_CONTROL_STATUS
260 { 0x098C, 0x2703 , WORD_LEN, 0}, // MCU_ADDRESS
261 { 0x0990, 0x0320 , WORD_LEN, 0}, // MCU_DATA_0
262 { 0x098C, 0x2705 , WORD_LEN, 0}, // MCU_ADDRESS
263 { 0x0990, 0x0258 , WORD_LEN, 0}, // MCU_DATA_0
264 { 0x098C, 0x2707 , WORD_LEN, 0}, // MCU_ADDRESS
265 { 0x0990, 0x0640 , WORD_LEN, 0}, // MCU_DATA_0
266 { 0x098C, 0x2709 , WORD_LEN, 0}, // MCU_ADDRESS
267 { 0x0990, 0x04B0 , WORD_LEN, 0}, // MCU_DATA_0
268 { 0x098C, 0x270D , WORD_LEN, 0}, // MCU_ADDRESS
269 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
270 { 0x098C, 0x270F , WORD_LEN, 0}, // MCU_ADDRESS
271 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
272 { 0x098C, 0x2711 , WORD_LEN, 0}, // MCU_ADDRESS
273 { 0x0990, 0x04BD , WORD_LEN, 0}, // MCU_DATA_0
274 { 0x098C, 0x2713 , WORD_LEN, 0}, // MCU_ADDRESS
275 { 0x0990, 0x064D , WORD_LEN, 0}, // MCU_DATA_0
276 { 0x098C, 0x2715 , WORD_LEN, 0}, // MCU_ADDRESS
277 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
278 { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
280 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
281 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
282 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
283 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
285 { 0x098C, 0x2719 , WORD_LEN, 0}, // MCU_ADDRESS
286 { 0x0990, 0x005A , WORD_LEN, 0}, // MCU_DATA_0
287 { 0x098C, 0x271B , WORD_LEN, 0}, // MCU_ADDRESS
288 { 0x0990, 0x01BE , WORD_LEN, 0}, // MCU_DATA_0
289 { 0x098C, 0x271D , WORD_LEN, 0}, // MCU_ADDRESS
290 { 0x0990, 0x0131 , WORD_LEN, 0}, // MCU_DATA_0
291 { 0x098C, 0x271F , WORD_LEN, 0}, // MCU_ADDRESS
292 { 0x0990, 0x02B3 , WORD_LEN, 0}, // MCU_DATA_0
293 { 0x098C, 0x2721 , WORD_LEN, 0}, // MCU_ADDRESS
294 { 0x0990, 0x09B0 , WORD_LEN, 0}, // MCU_DATA_0
295 { 0x098C, 0x2723 , WORD_LEN, 0}, // MCU_ADDRESS
296 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
297 { 0x098C, 0x2725 , WORD_LEN, 0}, // MCU_ADDRESS
298 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
299 { 0x098C, 0x2727 , WORD_LEN, 0}, // MCU_ADDRESS
300 { 0x0990, 0x04BB , WORD_LEN, 0}, // MCU_DATA_0
301 { 0x098C, 0x2729 , WORD_LEN, 0}, // MCU_ADDRESS
302 { 0x0990, 0x064B , WORD_LEN, 0}, // MCU_DATA_0
303 { 0x098C, 0x272B , WORD_LEN, 0}, // MCU_ADDRESS
304 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
305 { 0x098C, 0x272D , WORD_LEN, 0}, // MCU_ADDRESS
306 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
307 { 0x098C, 0x272F , WORD_LEN, 0}, // MCU_ADDRESS
308 { 0x0990, 0x003A , WORD_LEN, 0}, // MCU_DATA_0
309 { 0x098C, 0x2731 , WORD_LEN, 0}, // MCU_ADDRESS
310 { 0x0990, 0x00F6 , WORD_LEN, 0}, // MCU_DATA_0
311 { 0x098C, 0x2733 , WORD_LEN, 0}, // MCU_ADDRESS
312 { 0x0990, 0x008B , WORD_LEN, 0}, // MCU_DATA_0
313 { 0x098C, 0x2735 , WORD_LEN, 0}, // MCU_ADDRESS
314 { 0x0990, 0x050D , WORD_LEN, 0}, // MCU_DATA_0
315 { 0x098C, 0x2737 , WORD_LEN, 0}, // MCU_ADDRESS
316 { 0x0990, 0x0807 , WORD_LEN, 0}, // MCU_DATA_0
317 { 0x098C, 0x2739 , WORD_LEN, 0}, // MCU_ADDRESS
318 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
319 { 0x098C, 0x273B , WORD_LEN, 0}, // MCU_ADDRESS
320 { 0x0990, 0x031F , WORD_LEN, 0}, // MCU_DATA_0
321 { 0x098C, 0x273D , WORD_LEN, 0}, // MCU_ADDRESS
322 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
323 { 0x098C, 0x273F , WORD_LEN, 0}, // MCU_ADDRESS
324 { 0x0990, 0x0257 , WORD_LEN, 0}, // MCU_DATA_0
325 { 0x098C, 0x2747 , WORD_LEN, 0}, // MCU_ADDRESS
326 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
327 { 0x098C, 0x2749 , WORD_LEN, 0}, // MCU_ADDRESS
328 { 0x0990, 0x063F , WORD_LEN, 0}, // MCU_DATA_0
329 { 0x098C, 0x274B , WORD_LEN, 0}, // MCU_ADDRESS
330 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
331 { 0x098C, 0x274D , WORD_LEN, 0}, // MCU_ADDRESS
332 { 0x0990, 0x04AF , WORD_LEN, 0}, // MCU_DATA_0
333 { 0x098C, 0x222D , WORD_LEN, 0}, // MCU_ADDRESS
334 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
335 { 0x098C, 0xA408 , WORD_LEN, 0}, // MCU_ADDRESS
336 { 0x0990, 0x0022 , WORD_LEN, 0}, // MCU_DATA_0
337 { 0x098C, 0xA409 , WORD_LEN, 0}, // MCU_ADDRESS
338 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
339 { 0x098C, 0xA40A , WORD_LEN, 0}, // MCU_ADDRESS
340 { 0x0990, 0x0029 , WORD_LEN, 0}, // MCU_DATA_0
341 { 0x098C, 0xA40B , WORD_LEN, 0}, // MCU_ADDRESS
342 { 0x0990, 0x002B , WORD_LEN, 0}, // MCU_DATA_0
343 { 0x098C, 0x2411 , WORD_LEN, 0}, // MCU_ADDRESS
344 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
345 { 0x098C, 0x2413 , WORD_LEN, 0}, // MCU_ADDRESS
346 { 0x0990, 0x00A9 , WORD_LEN, 0}, // MCU_DATA_0
347 { 0x098C, 0x2415 , WORD_LEN, 0}, // MCU_ADDRESS
348 { 0x0990, 0x00AA , WORD_LEN, 0}, // MCU_DATA_0
349 { 0x098C, 0x2417 , WORD_LEN, 0}, // MCU_ADDRESS
350 { 0x0990, 0x00CC , WORD_LEN, 0}, // MCU_DATA_0
351 { 0x098C, 0xA404 , WORD_LEN, 0}, // MCU_ADDRESS
352 { 0x0990, 0x0010 , WORD_LEN, 0}, // MCU_DATA_0
353 { 0x098C, 0xA40D , WORD_LEN, 0}, // MCU_ADDRESS
354 { 0x0990, 0x0002 , WORD_LEN, 0}, // MCU_DATA_0
355 { 0x098C, 0xA40E , WORD_LEN, 0}, // MCU_ADDRESS
356 { 0x0990, 0x0003 , WORD_LEN, 0}, // MCU_DATA_0
357 { 0x098C, 0xA410 , WORD_LEN, 0}, // MCU_ADDRESS
358 { 0x0990, 0x000A , WORD_LEN, 0}, // MCU_DATA_0
359 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
360 { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
361 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
362 { 0x0990, 0x0005 , WORD_LEN, 0}, // MCU_DATA_0
367 /* 720p 15fps @ 1280x720 */
369 static struct reginfo sensor_720p[]=
374 /* 1080p, 0x15fps, 0xyuv @1920x1080 */
376 static struct reginfo sensor_1080p[]=
381 /* 2592X1944 QSXGA */
382 static struct reginfo sensor_qsxga[] =
387 static struct reginfo sensor_qxga[] =
393 static struct reginfo sensor_uxga[] =
396 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
397 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
398 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
399 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
403 static struct reginfo sensor_sxga[] =
406 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
407 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
408 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
409 { 0x0990, 0x0001, WORD_LEN, 0}, // MCU_DATA_0
412 // { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
413 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
414 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
415 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
417 { 0x098C, 0x2747, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_X0_B]
418 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
419 { 0x098C, 0x2749, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_X1_B]
420 { 0x0990, 0x063F, WORD_LEN, 0}, // MCU_DATA_0
421 { 0x098C, 0x274B, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_Y0_B]
422 { 0x0990, 0x0000, WORD_LEN, 0}, // MCU_DATA_0
423 { 0x098C, 0x274D, WORD_LEN, 0}, // MCU_ADDRESS [MODE_CROP_Y1_B]
424 { 0x0990, 0x04AF, WORD_LEN, 0}, // MCU_DATA_0
425 { 0x098C, 0x2707, WORD_LEN, 0}, // MCU_ADDRESS [MODE_OUTPUT_WIDTH_B]
426 { 0x0990, 0x0500, WORD_LEN, 0}, // MCU_DATA_0
427 { 0x098C, 0x2709, WORD_LEN, 0}, // MCU_ADDRESS [MODE_OUTPUT_HEIGHT_B]
428 { 0x0990, 0x0400, WORD_LEN, 0}, // MCU_DATA_0
430 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
431 { 0x0990, 0x0005, WORD_LEN, 0}, // MCU_DATA_0
433 { 0x098C, 0xA115, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CAP_MODE]
434 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
435 { 0x098C, 0xA103, WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
436 { 0x0990, 0x0002, WORD_LEN, 0}, // MCU_DATA_0
442 static struct reginfo sensor_xga[] =
448 static struct reginfo sensor_svga[] =
451 //for 24MHz input, VCO=MAX PCLK=76.8MHz
452 { 0x001A, 0x0051, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
453 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
454 { 0x0014, 0x2545, WORD_LEN, 0}, // PLL_CONTROL
455 { 0x0010, 0x011C, WORD_LEN, 0}, // PLL_DIVIDERS
456 { 0x0012, 0x1FF7, WORD_LEN, 0}, // PLL_P_DIVIDERS
457 { 0x0014, 0x2547, WORD_LEN, 0}, // PLL_CONTROL
458 { 0x0014, 0x2447, WORD_LEN, 0}, // PLL_CONTROL
459 { 0x0014, 0x2047, WORD_LEN, 0}, // PLL_CONTROL
460 { 0x0014, 0x2046, WORD_LEN, 0}, // PLL_CONTROL
461 { 0x001A, 0x0050, WORD_LEN, 0}, // RESET_AND_MISC_CONTROL
462 { 0x0018, 0x4028 , WORD_LEN, 0}, // STANDBY_CONTROL
463 { 0x321C, 0x0003 , WORD_LEN, 0}, // OFIFO_CONTROL_STATUS
464 { 0x098C, 0x2703 , WORD_LEN, 0}, // MCU_ADDRESS
465 { 0x0990, 0x0320 , WORD_LEN, 0}, // MCU_DATA_0
466 { 0x098C, 0x2705 , WORD_LEN, 0}, // MCU_ADDRESS
467 { 0x0990, 0x0258 , WORD_LEN, 0}, // MCU_DATA_0
468 { 0x098C, 0x2707 , WORD_LEN, 0}, // MCU_ADDRESS
469 { 0x0990, 0x0640 , WORD_LEN, 0}, // MCU_DATA_0
470 { 0x098C, 0x2709 , WORD_LEN, 0}, // MCU_ADDRESS
471 { 0x0990, 0x04B0 , WORD_LEN, 0}, // MCU_DATA_0
472 { 0x098C, 0x270D , WORD_LEN, 0}, // MCU_ADDRESS
473 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
474 { 0x098C, 0x270F , WORD_LEN, 0}, // MCU_ADDRESS
475 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
476 { 0x098C, 0x2711 , WORD_LEN, 0}, // MCU_ADDRESS
477 { 0x0990, 0x04BD , WORD_LEN, 0}, // MCU_DATA_0
478 { 0x098C, 0x2713 , WORD_LEN, 0}, // MCU_ADDRESS
479 { 0x0990, 0x064D , WORD_LEN, 0}, // MCU_DATA_0
480 { 0x098C, 0x2715 , WORD_LEN, 0}, // MCU_ADDRESS
481 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
482 { 0x098C, 0x2717 , WORD_LEN, 0}, // MCU_ADDRESS
484 { 0x0990, 0x046C , WORD_LEN, 0}, // MCU_DATA_0
485 // { 0x0990, 0x046E , WORD_LEN, 0}, // MCU_DATA_0
486 // { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS [SEQ_CMD]
487 // { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
490 { 0x098C, 0x2719 , WORD_LEN, 0}, // MCU_ADDRESS
491 { 0x0990, 0x005A , WORD_LEN, 0}, // MCU_DATA_0
492 { 0x098C, 0x271B , WORD_LEN, 0}, // MCU_ADDRESS
493 { 0x0990, 0x01BE , WORD_LEN, 0}, // MCU_DATA_0
494 { 0x098C, 0x271D , WORD_LEN, 0}, // MCU_ADDRESS
495 { 0x0990, 0x0131 , WORD_LEN, 0}, // MCU_DATA_0
496 { 0x098C, 0x271F , WORD_LEN, 0}, // MCU_ADDRESS
497 { 0x0990, 0x02B3 , WORD_LEN, 0}, // MCU_DATA_0
498 { 0x098C, 0x2721 , WORD_LEN, 0}, // MCU_ADDRESS
499 { 0x0990, 0x09B0 , WORD_LEN, 0}, // MCU_DATA_0
500 { 0x098C, 0x2723 , WORD_LEN, 0}, // MCU_ADDRESS
501 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
502 { 0x098C, 0x2725 , WORD_LEN, 0}, // MCU_ADDRESS
503 { 0x0990, 0x0004 , WORD_LEN, 0}, // MCU_DATA_0
504 { 0x098C, 0x2727 , WORD_LEN, 0}, // MCU_ADDRESS
505 { 0x0990, 0x04BB , WORD_LEN, 0}, // MCU_DATA_0
506 { 0x098C, 0x2729 , WORD_LEN, 0}, // MCU_ADDRESS
507 { 0x0990, 0x064B , WORD_LEN, 0}, // MCU_DATA_0
508 { 0x098C, 0x272B , WORD_LEN, 0}, // MCU_ADDRESS
509 { 0x0990, 0x0111 , WORD_LEN, 0}, // MCU_DATA_0
510 { 0x098C, 0x272D , WORD_LEN, 0}, // MCU_ADDRESS
511 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
512 { 0x098C, 0x272F , WORD_LEN, 0}, // MCU_ADDRESS
513 { 0x0990, 0x003A , WORD_LEN, 0}, // MCU_DATA_0
514 { 0x098C, 0x2731 , WORD_LEN, 0}, // MCU_ADDRESS
515 { 0x0990, 0x00F6 , WORD_LEN, 0}, // MCU_DATA_0
516 { 0x098C, 0x2733 , WORD_LEN, 0}, // MCU_ADDRESS
517 { 0x0990, 0x008B , WORD_LEN, 0}, // MCU_DATA_0
518 { 0x098C, 0x2735 , WORD_LEN, 0}, // MCU_ADDRESS
519 { 0x0990, 0x050D , WORD_LEN, 0}, // MCU_DATA_0
520 { 0x098C, 0x2737 , WORD_LEN, 0}, // MCU_ADDRESS
521 { 0x0990, 0x0807 , WORD_LEN, 0}, // MCU_DATA_0
522 { 0x098C, 0x2739 , WORD_LEN, 0}, // MCU_ADDRESS
523 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
524 { 0x098C, 0x273B , WORD_LEN, 0}, // MCU_ADDRESS
525 { 0x0990, 0x031F , WORD_LEN, 0}, // MCU_DATA_0
526 { 0x098C, 0x273D , WORD_LEN, 0}, // MCU_ADDRESS
527 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
528 { 0x098C, 0x273F , WORD_LEN, 0}, // MCU_ADDRESS
529 { 0x0990, 0x0257 , WORD_LEN, 0}, // MCU_DATA_0
530 { 0x098C, 0x2747 , WORD_LEN, 0}, // MCU_ADDRESS
531 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
532 { 0x098C, 0x2749 , WORD_LEN, 0}, // MCU_ADDRESS
533 { 0x0990, 0x063F , WORD_LEN, 0}, // MCU_DATA_0
534 { 0x098C, 0x274B , WORD_LEN, 0}, // MCU_ADDRESS
535 { 0x0990, 0x0000 , WORD_LEN, 0}, // MCU_DATA_0
536 { 0x098C, 0x274D , WORD_LEN, 0}, // MCU_ADDRESS
537 { 0x0990, 0x04AF , WORD_LEN, 0}, // MCU_DATA_0
538 { 0x098C, 0x222D , WORD_LEN, 0}, // MCU_ADDRESS
539 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
540 { 0x098C, 0xA408 , WORD_LEN, 0}, // MCU_ADDRESS
541 { 0x0990, 0x0022 , WORD_LEN, 0}, // MCU_DATA_0
542 { 0x098C, 0xA409 , WORD_LEN, 0}, // MCU_ADDRESS
543 { 0x0990, 0x0024 , WORD_LEN, 0}, // MCU_DATA_0
544 { 0x098C, 0xA40A , WORD_LEN, 0}, // MCU_ADDRESS
545 { 0x0990, 0x0029 , WORD_LEN, 0}, // MCU_DATA_0
546 { 0x098C, 0xA40B , WORD_LEN, 0}, // MCU_ADDRESS
547 { 0x0990, 0x002B , WORD_LEN, 0}, // MCU_DATA_0
548 { 0x098C, 0x2411 , WORD_LEN, 0}, // MCU_ADDRESS
549 { 0x0990, 0x008D , WORD_LEN, 0}, // MCU_DATA_0
550 { 0x098C, 0x2413 , WORD_LEN, 0}, // MCU_ADDRESS
551 { 0x0990, 0x00A9 , WORD_LEN, 0}, // MCU_DATA_0
552 { 0x098C, 0x2415 , WORD_LEN, 0}, // MCU_ADDRESS
553 { 0x0990, 0x00AA , WORD_LEN, 0}, // MCU_DATA_0
554 { 0x098C, 0x2417 , WORD_LEN, 0}, // MCU_ADDRESS
555 { 0x0990, 0x00CC , WORD_LEN, 0}, // MCU_DATA_0
556 { 0x098C, 0xA404 , WORD_LEN, 0}, // MCU_ADDRESS
557 { 0x0990, 0x0010 , WORD_LEN, 0}, // MCU_DATA_0
558 { 0x098C, 0xA40D , WORD_LEN, 0}, // MCU_ADDRESS
559 { 0x0990, 0x0002 , WORD_LEN, 0}, // MCU_DATA_0
560 { 0x098C, 0xA40E , WORD_LEN, 0}, // MCU_ADDRESS
561 { 0x0990, 0x0003 , WORD_LEN, 0}, // MCU_DATA_0
562 { 0x098C, 0xA410 , WORD_LEN, 0}, // MCU_ADDRESS
563 { 0x0990, 0x000A , WORD_LEN, 0}, // MCU_DATA_0
564 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
565 { 0x0990, 0x0006 , WORD_LEN, 0}, // MCU_DATA_0
566 { 0x098C, 0xA103 , WORD_LEN, 0}, // MCU_ADDRESS
567 { 0x0990, 0x0005 , WORD_LEN, 0}, // MCU_DATA_0
572 static struct reginfo sensor_vga[] =
578 static struct reginfo sensor_cif[] =
584 static struct reginfo sensor_qvga[] =
590 static struct reginfo sensor_qcif[] =
595 static struct reginfo sensor_Preview2Capture[]=
598 {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
599 {0x843C, 0xFF, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
600 {0x8404, 0x02, BYTE_LEN, 0 }, // SEQ_CMD
604 static struct reginfo sensor_Capture2Preview[]=
607 {0x098E, 0x843C, WORD_LEN, 0}, // LOGICAL_ADDRESS_ACCESS [SEQ_STATE_CFG_5_MAX_FRAME_CNT]
608 {0x843C, 0x01, BYTE_LEN, 0 }, // SEQ_STATE_CFG_5_MAX_FRAME_CNT
609 {0x8404, 0x01, BYTE_LEN, 0 }, // SEQ_CMD
610 {0x0016, 0x0047, WORD_LEN, 0}, // CLOCKS_CONTRO
614 static struct reginfo sensor_ClrFmt_YUYV[]=
619 static struct reginfo sensor_ClrFmt_UYVY[]=
625 #if CONFIG_SENSOR_WhiteBalance
626 static struct reginfo sensor_WhiteB_Auto[]=
631 /* Cloudy Colour Temperature : 6500K - 8000K */
632 static struct reginfo sensor_WhiteB_Cloudy[]=
637 /* ClearDay Colour Temperature : 5000K - 6500K */
638 static struct reginfo sensor_WhiteB_ClearDay[]=
643 /* Office Colour Temperature : 3500K - 5000K */
644 static struct reginfo sensor_WhiteB_TungstenLamp1[]=
649 /* Home Colour Temperature : 2500K - 3500K */
650 static struct reginfo sensor_WhiteB_TungstenLamp2[]=
655 static struct reginfo *sensor_WhiteBalanceSeqe[] = {sensor_WhiteB_Auto, sensor_WhiteB_TungstenLamp1,sensor_WhiteB_TungstenLamp2,
656 sensor_WhiteB_ClearDay, sensor_WhiteB_Cloudy,NULL,
660 #if CONFIG_SENSOR_Brightness
661 static struct reginfo sensor_Brightness0[]=
666 static struct reginfo sensor_Brightness1[]=
671 static struct reginfo sensor_Brightness2[]=
676 static struct reginfo sensor_Brightness3[]=
681 static struct reginfo sensor_Brightness4[]=
686 static struct reginfo sensor_Brightness5[]=
690 static struct reginfo *sensor_BrightnessSeqe[] = {sensor_Brightness0, sensor_Brightness1, sensor_Brightness2, sensor_Brightness3,
691 sensor_Brightness4, sensor_Brightness5,NULL,
696 #if CONFIG_SENSOR_Effect
697 static struct reginfo sensor_Effect_Normal[] =
702 static struct reginfo sensor_Effect_WandB[] =
707 static struct reginfo sensor_Effect_Sepia[] =
712 static struct reginfo sensor_Effect_Negative[] =
716 static struct reginfo sensor_Effect_Bluish[] =
721 static struct reginfo sensor_Effect_Green[] =
726 static struct reginfo sensor_Effect_Solarize[] =
730 static struct reginfo *sensor_EffectSeqe[] = {sensor_Effect_Normal, sensor_Effect_Negative,sensor_Effect_Sepia,
731 sensor_Effect_Solarize,NULL,
734 #if CONFIG_SENSOR_Exposure
735 static struct reginfo sensor_Exposure0[]=
740 static struct reginfo sensor_Exposure1[]=
745 static struct reginfo sensor_Exposure2[]=
750 static struct reginfo sensor_Exposure3[]=
755 static struct reginfo sensor_Exposure4[]=
760 static struct reginfo sensor_Exposure5[]=
765 static struct reginfo sensor_Exposure6[]=
770 static struct reginfo *sensor_ExposureSeqe[] = {sensor_Exposure0, sensor_Exposure1, sensor_Exposure2, sensor_Exposure3,
771 sensor_Exposure4, sensor_Exposure5,sensor_Exposure6,NULL,
774 #if CONFIG_SENSOR_Saturation
775 static struct reginfo sensor_Saturation0[]=
780 static struct reginfo sensor_Saturation1[]=
785 static struct reginfo sensor_Saturation2[]=
789 static struct reginfo *sensor_SaturationSeqe[] = {sensor_Saturation0, sensor_Saturation1, sensor_Saturation2, NULL,};
791 #if CONFIG_SENSOR_Contrast
792 static struct reginfo sensor_Contrast0[]=
797 static struct reginfo sensor_Contrast1[]=
802 static struct reginfo sensor_Contrast2[]=
807 static struct reginfo sensor_Contrast3[]=
812 static struct reginfo sensor_Contrast4[]=
818 static struct reginfo sensor_Contrast5[]=
823 static struct reginfo sensor_Contrast6[]=
827 static struct reginfo *sensor_ContrastSeqe[] = {sensor_Contrast0, sensor_Contrast1, sensor_Contrast2, sensor_Contrast3,
828 sensor_Contrast4, sensor_Contrast5, sensor_Contrast6, NULL,
832 #if CONFIG_SENSOR_Mirror
833 static struct reginfo sensor_MirrorOn[]=
838 static struct reginfo sensor_MirrorOff[]=
842 static struct reginfo *sensor_MirrorSeqe[] = {sensor_MirrorOff, sensor_MirrorOn,NULL,};
844 #if CONFIG_SENSOR_Flip
845 static struct reginfo sensor_FlipOn[]=
850 static struct reginfo sensor_FlipOff[]=
854 static struct reginfo *sensor_FlipSeqe[] = {sensor_FlipOff, sensor_FlipOn,NULL,};
857 #if CONFIG_SENSOR_Scene
858 static struct reginfo sensor_SceneAuto[] =
863 static struct reginfo sensor_SceneNight[] =
867 static struct reginfo *sensor_SceneSeqe[] = {sensor_SceneAuto, sensor_SceneNight,NULL,};
870 #if CONFIG_SENSOR_DigitalZoom
871 static struct reginfo sensor_Zoom0[] =
876 static struct reginfo sensor_Zoom1[] =
881 static struct reginfo sensor_Zoom2[] =
887 static struct reginfo sensor_Zoom3[] =
891 static struct reginfo *sensor_ZoomSeqe[] = {sensor_Zoom0, sensor_Zoom1, sensor_Zoom2, sensor_Zoom3, NULL};
893 static const struct v4l2_querymenu sensor_menus[] =
895 #if CONFIG_SENSOR_WhiteBalance
896 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 0, .name = "auto", .reserved = 0, }, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 1, .name = "incandescent", .reserved = 0,},
897 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 2, .name = "fluorescent", .reserved = 0,}, { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 3, .name = "daylight", .reserved = 0,},
898 { .id = V4L2_CID_DO_WHITE_BALANCE, .index = 4, .name = "cloudy-daylight", .reserved = 0,},
901 #if CONFIG_SENSOR_Effect
902 { .id = V4L2_CID_EFFECT, .index = 0, .name = "none", .reserved = 0, }, { .id = V4L2_CID_EFFECT, .index = 1, .name = "negative", .reserved = 0,},
903 { .id = V4L2_CID_EFFECT, .index = 2, .name = "sepia", .reserved = 0,}, { .id = V4L2_CID_EFFECT, .index = 3, .name = "solarize", .reserved = 0,},
906 #if CONFIG_SENSOR_Scene
907 { .id = V4L2_CID_SCENE, .index = 0, .name = "auto", .reserved = 0,} ,{ .id = V4L2_CID_SCENE, .index = 1, .name = "night", .reserved = 0,},
910 #if CONFIG_SENSOR_Flash
911 { .id = V4L2_CID_FLASH, .index = 0, .name = "off", .reserved = 0, }, { .id = V4L2_CID_FLASH, .index = 1, .name = "auto", .reserved = 0,},
912 { .id = V4L2_CID_FLASH, .index = 2, .name = "on", .reserved = 0,}, { .id = V4L2_CID_FLASH, .index = 3, .name = "torch", .reserved = 0,},
916 static const struct v4l2_queryctrl sensor_controls[] =
918 #if CONFIG_SENSOR_WhiteBalance
920 .id = V4L2_CID_DO_WHITE_BALANCE,
921 .type = V4L2_CTRL_TYPE_MENU,
922 .name = "White Balance Control",
930 #if CONFIG_SENSOR_Brightness
932 .id = V4L2_CID_BRIGHTNESS,
933 .type = V4L2_CTRL_TYPE_INTEGER,
934 .name = "Brightness Control",
942 #if CONFIG_SENSOR_Effect
944 .id = V4L2_CID_EFFECT,
945 .type = V4L2_CTRL_TYPE_MENU,
946 .name = "Effect Control",
954 #if CONFIG_SENSOR_Exposure
956 .id = V4L2_CID_EXPOSURE,
957 .type = V4L2_CTRL_TYPE_INTEGER,
958 .name = "Exposure Control",
966 #if CONFIG_SENSOR_Saturation
968 .id = V4L2_CID_SATURATION,
969 .type = V4L2_CTRL_TYPE_INTEGER,
970 .name = "Saturation Control",
978 #if CONFIG_SENSOR_Contrast
980 .id = V4L2_CID_CONTRAST,
981 .type = V4L2_CTRL_TYPE_INTEGER,
982 .name = "Contrast Control",
990 #if CONFIG_SENSOR_Mirror
992 .id = V4L2_CID_HFLIP,
993 .type = V4L2_CTRL_TYPE_BOOLEAN,
994 .name = "Mirror Control",
1002 #if CONFIG_SENSOR_Flip
1004 .id = V4L2_CID_VFLIP,
1005 .type = V4L2_CTRL_TYPE_BOOLEAN,
1006 .name = "Flip Control",
1014 #if CONFIG_SENSOR_Scene
1016 .id = V4L2_CID_SCENE,
1017 .type = V4L2_CTRL_TYPE_MENU,
1018 .name = "Scene Control",
1026 #if CONFIG_SENSOR_DigitalZoom
1028 .id = V4L2_CID_ZOOM_RELATIVE,
1029 .type = V4L2_CTRL_TYPE_INTEGER,
1030 .name = "DigitalZoom Control",
1036 .id = V4L2_CID_ZOOM_ABSOLUTE,
1037 .type = V4L2_CTRL_TYPE_INTEGER,
1038 .name = "DigitalZoom Control",
1046 #if CONFIG_SENSOR_Focus
1048 .id = V4L2_CID_FOCUS_RELATIVE,
1049 .type = V4L2_CTRL_TYPE_INTEGER,
1050 .name = "Focus Control",
1056 .id = V4L2_CID_FOCUS_ABSOLUTE,
1057 .type = V4L2_CTRL_TYPE_INTEGER,
1058 .name = "Focus Control",
1062 .default_value = 125,
1065 .id = V4L2_CID_FOCUS_AUTO,
1066 .type = V4L2_CTRL_TYPE_BOOLEAN,
1067 .name = "Focus Control",
1073 .id = V4L2_CID_FOCUS_CONTINUOUS,
1074 .type = V4L2_CTRL_TYPE_BOOLEAN,
1075 .name = "Focus Control",
1083 #if CONFIG_SENSOR_Flash
1085 .id = V4L2_CID_FLASH,
1086 .type = V4L2_CTRL_TYPE_MENU,
1087 .name = "Flash Control",
1096 static int sensor_probe(struct i2c_client *client, const struct i2c_device_id *did);
1097 static int sensor_video_probe(struct soc_camera_device *icd, struct i2c_client *client);
1098 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1099 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
1100 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1101 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl);
1102 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg);
1103 static int sensor_resume(struct soc_camera_device *icd);
1104 static int sensor_set_bus_param(struct soc_camera_device *icd,unsigned long flags);
1105 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd);
1106 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1107 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value);
1108 static int sensor_deactivate(struct i2c_client *client);
1110 static struct soc_camera_ops sensor_ops =
1112 .suspend = sensor_suspend,
1113 .resume = sensor_resume,
1114 .set_bus_param = sensor_set_bus_param,
1115 .query_bus_param = sensor_query_bus_param,
1116 .controls = sensor_controls,
1117 .menus = sensor_menus,
1118 .num_controls = ARRAY_SIZE(sensor_controls),
1119 .num_menus = ARRAY_SIZE(sensor_menus),
1122 #define COL_FMT(_name, _depth, _fourcc, _colorspace) \
1123 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
1124 .colorspace = _colorspace }
1126 #define JPG_FMT(_name, _depth, _fourcc) \
1127 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_JPEG)
1129 static const struct soc_camera_data_format sensor_colour_formats[] = {
1130 JPG_FMT(SENSOR_NAME_STRING(UYVY), 16, V4L2_PIX_FMT_UYVY),
1131 JPG_FMT(SENSOR_NAME_STRING(YUYV), 16, V4L2_PIX_FMT_YUYV),
1133 enum sensor_work_state
1135 sensor_work_ready = 0,
1140 struct i2c_client *client;
1141 struct delayed_work dwork;
1142 enum sensor_work_state state;
1145 typedef struct sensor_info_priv_s
1159 unsigned char mirror; /* HFLIP */
1160 unsigned char flip; /* VFLIP */
1167 struct reginfo *winseqe_cur_addr;
1168 unsigned int pixfmt;
1169 unsigned int enable;
1170 unsigned int funmodule_state;
1171 } sensor_info_priv_t;
1175 struct sensor_parameter
1177 unsigned short int preview_maxlines;
1178 unsigned short int preview_exposure;
1179 unsigned short int preview_line_width;
1180 unsigned short int preview_gain;
1182 unsigned short int capture_framerate;
1183 unsigned short int preview_framerate;
1188 struct v4l2_subdev subdev;
1189 struct i2c_client *client;
1190 sensor_info_priv_t info_priv;
1191 struct sensor_parameter parameter;
1192 struct workqueue_struct *sensor_wq;
1193 struct sensor_work sensor_wk;
1194 struct mutex wq_lock;
1195 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1196 #if CONFIG_SENSOR_I2C_NOSCHED
1197 atomic_t tasklock_cnt;
1199 struct rk29camera_platform_data *sensor_io_request;
1200 struct rk29camera_gpio_res *sensor_gpio_res;
1203 static struct sensor* to_sensor(const struct i2c_client *client)
1205 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1208 static int sensor_task_lock(struct i2c_client *client, int lock)
1210 #if CONFIG_SENSOR_I2C_NOSCHED
1212 struct sensor *sensor = to_sensor(client);
1215 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1216 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1217 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1221 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1222 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1223 goto sensor_task_lock_err;
1228 atomic_add(1, &sensor->tasklock_cnt);
1230 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1231 atomic_sub(1, &sensor->tasklock_cnt);
1233 if (atomic_read(&sensor->tasklock_cnt) == 0)
1239 sensor_task_lock_err:
1246 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val);
1248 /* sensor register write */
1249 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1253 struct i2c_msg msg[1];
1255 switch (reg_info->reg)
1257 case SEQUENCE_WAIT_MS:
1260 mdelay(reg_info->val);
1262 msleep(reg_info->val);
1266 case SEQUENCE_WAIT_US:
1268 udelay(reg_info->val);
1272 case SEQUENCE_PROPERTY:
1278 buf[0] = reg_info->reg >> 8;
1279 buf[1] = reg_info->reg & 0xFF;
1280 if (reg_info->reg_len == WORD_LEN) {
1281 buf[2] = reg_info->val >> 8;
1282 buf[3] = reg_info->val & 0xFF;
1285 } else if (reg_info->reg_len == BYTE_LEN) {
1286 buf[2] = reg_info->val;
1290 msg->addr = client->addr;
1291 msg->flags = client->flags;
1293 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1294 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1299 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1300 err = i2c_transfer(client->adapter, msg, 1);
1305 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);
1314 /* sensor register read */
1315 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1319 struct i2c_msg msg[2];
1322 buf[1] = reg & 0xFF;
1324 msg[0].addr = client->addr;
1325 msg[0].flags = client->flags;
1327 msg[0].len = sizeof(buf);
1328 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1329 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1331 msg[1].addr = client->addr;
1332 msg[1].flags = client->flags|I2C_M_RD;
1335 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1336 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1340 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1341 err = i2c_transfer(client->adapter, msg, 2);
1344 *val = buf[0]<<8 | buf[1];
1347 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1355 /* write a array of registers */
1356 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1360 #if CONFIG_SENSOR_I2C_RDWRCHK
1365 if (sensor_task_lock(client, 1) < 0)
1366 goto sensor_write_array_end;
1367 while (regarray[i].reg != SEQUENCE_END) {
1368 err = sensor_write(client, ®array[i]);
1372 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1376 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1378 goto sensor_write_array_end;
1381 #if CONFIG_SENSOR_I2C_RDWRCHK
1382 sensor_read(client, regarray[i].reg, &valchk);
1383 if (valchk != regarray[i].val)
1384 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1391 sensor_write_array_end:
1392 sensor_task_lock(client,0);
1395 #if CONFIG_SENSOR_I2C_RDWRCHK
1396 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1404 while (regarray[i].reg != SEQUENCE_END)
1406 sensor_read(client, regarray[i].reg, &valchk);
1407 if (valchk != regarray[i].val)
1408 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1415 #if CONFIG_SENSOR_Focus
1416 static struct reginfo sensor_af_init0[] =
1419 {SEQUENCE_END, 0x00}
1421 static struct reginfo sensor_af_init1[] =
1423 {SEQUENCE_END, 0x00}
1427 static struct reginfo sensor_af_trigger[] =
1429 {SEQUENCE_END, 0x00}
1431 static int sensor_af_single(struct i2c_client *client)
1435 ret = sensor_write_array(client, sensor_af_trigger);
1437 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1439 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1440 sensor_af_single_end:
1444 static int sensor_af_const(struct i2c_client *client)
1448 sensor_af_const_end:
1452 static int sensor_af_zoneupdate(struct i2c_client *client)
1455 struct i2c_msg msg[2];
1458 {0xb0,0x08,0x00,0x03,0xff,0xff},
1459 {0xb0,0x0c,0xff,0xff,0xff,0xff},
1462 msg[0].addr = client->addr;
1463 msg[0].flags = client->flags;
1464 msg[0].buf = buf[0];
1465 msg[0].len = sizeof(buf);
1466 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1467 msg[0].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1469 msg[1].addr = client->addr;
1470 msg[1].flags = client->flags;
1471 msg[1].buf = buf[1];
1472 msg[1].len = sizeof(buf);
1473 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1474 msg[1].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1476 ret = i2c_transfer(client->adapter, &msg[0], 1);
1477 ret |= i2c_transfer(client->adapter, &msg[1], 1);
1481 SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
1484 sensor_af_zoneupdate_end:
1488 static int sensor_af_init(struct i2c_client *client)
1492 ret = sensor_write_array(client, sensor_af_init0);
1494 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1496 if (sensor_af_zoneupdate(client) == 0) {
1497 ret = sensor_write_array(client, sensor_af_init1);
1499 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1508 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1510 struct soc_camera_link *icl = to_soc_camera_link(icd);
1513 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1516 case Sensor_PowerDown:
1518 if (icl->powerdown) {
1519 ret = icl->powerdown(icd->pdev, on);
1520 if (ret == RK29_CAM_IO_SUCCESS) {
1524 icl->reset(icd->pdev);
1526 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1528 goto sensor_power_end;
1535 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1536 struct sensor *sensor = to_sensor(client);
1538 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1539 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1545 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1553 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1555 struct i2c_client *client = sd->priv;
1556 struct soc_camera_device *icd = client->dev.platform_data;
1557 struct sensor *sensor = to_sensor(client);
1558 const struct v4l2_queryctrl *qctrl;
1562 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1564 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1566 goto sensor_INIT_ERR;
1570 if (sensor_task_lock(client,1)<0)
1571 goto sensor_INIT_ERR;
1573 #if (SENSOR_RESET_REG != SEQUENCE_END)
1574 struct reginfo reg_info;
1575 reg_info.reg = SENSOR_RESET_REG;
1576 reg_info.val = SENSOR_RESET_VAL;
1577 reg_info.reg_len = SENSOR_RESET_REG_LEN;
1578 ret = sensor_write(client, ®_info);
1580 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1582 goto sensor_INIT_ERR;
1584 mdelay(5); //delay 5 microseconds
1585 reg_info.val = SENSOR_DERESET_VAL;
1586 ret = sensor_write(client, ®_info);
1588 SENSOR_TR("%s soft dereset sensor failed\n",SENSOR_NAME_STRING());
1590 goto sensor_INIT_ERR;
1594 /* check if it is an sensor sensor */
1595 #if (SENSOR_ID_REG != SEQUENCE_END)
1596 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1598 SENSOR_TR("read chip id failed\n");
1600 goto sensor_INIT_ERR;
1603 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1607 if (pid == SENSOR_ID) {
1608 sensor->model = SENSOR_V4L2_IDENT;
1610 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1612 goto sensor_INIT_ERR;
1615 ret = sensor_write_array(client, sensor_init_data);
1618 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1619 goto sensor_INIT_ERR;
1621 sensor_task_lock(client,0);
1622 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1623 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1624 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1625 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1626 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1627 sensor->info_priv.pixfmt = SENSOR_INIT_PIXFMT;
1629 /* sensor sensor information for initialization */
1630 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1632 sensor->info_priv.whiteBalance = qctrl->default_value;
1633 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1635 sensor->info_priv.brightness = qctrl->default_value;
1636 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1638 sensor->info_priv.effect = qctrl->default_value;
1639 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1641 sensor->info_priv.exposure = qctrl->default_value;
1643 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1645 sensor->info_priv.saturation = qctrl->default_value;
1646 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1648 sensor->info_priv.contrast = qctrl->default_value;
1649 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1651 sensor->info_priv.mirror = qctrl->default_value;
1652 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1654 sensor->info_priv.flip = qctrl->default_value;
1655 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1657 sensor->info_priv.scene = qctrl->default_value;
1658 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1660 sensor->info_priv.digitalzoom = qctrl->default_value;
1662 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1663 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1665 sensor->info_priv.focus = qctrl->default_value;
1666 #if CONFIG_SENSOR_Focus
1667 if (sensor_af_init(client) < 0) {
1668 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1669 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1671 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1672 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1675 #if CONFIG_SENSOR_Flash
1676 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1678 sensor->info_priv.flash = qctrl->default_value;
1680 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);
1684 sensor_task_lock(client,0);
1685 sensor_deactivate(client);
1688 static int sensor_deactivate(struct i2c_client *client)
1690 struct soc_camera_device *icd = client->dev.platform_data;
1692 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1694 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1695 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1697 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1698 icd->user_width = SENSOR_INIT_WIDTH;
1699 icd->user_height = SENSOR_INIT_HEIGHT;
1703 static struct reginfo sensor_power_down_sequence[]=
1707 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1710 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1712 if (pm_msg.event == PM_EVENT_SUSPEND) {
1713 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1714 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1716 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1719 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1721 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1726 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1733 static int sensor_resume(struct soc_camera_device *icd)
1737 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1739 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1743 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1747 static int sensor_set_bus_param(struct soc_camera_device *icd,
1748 unsigned long flags)
1754 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1756 struct soc_camera_link *icl = to_soc_camera_link(icd);
1757 unsigned long flags = SENSOR_BUS_PARAM;
1759 return soc_camera_apply_sensor_flags(icl, flags);
1762 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1764 struct i2c_client *client = sd->priv;
1765 struct soc_camera_device *icd = client->dev.platform_data;
1766 struct sensor *sensor = to_sensor(client);
1767 struct v4l2_pix_format *pix = &f->fmt.pix;
1769 pix->width = icd->user_width;
1770 pix->height = icd->user_height;
1771 pix->pixelformat = sensor->info_priv.pixfmt;
1772 pix->field = V4L2_FIELD_NONE;
1773 pix->colorspace = V4L2_COLORSPACE_JPEG;
1777 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_format *f)
1781 if ((f->fmt.pix.width == 1024) && (f->fmt.pix.height == 768)) {
1783 } else if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 1024)) {
1785 } else if ((f->fmt.pix.width == 1600) && (f->fmt.pix.height == 1200)) {
1787 } else if ((f->fmt.pix.width == 2048) && (f->fmt.pix.height == 1536)) {
1789 } else if ((f->fmt.pix.width == 2592) && (f->fmt.pix.height == 1944)) {
1794 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1798 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_format *f)
1802 if ((f->fmt.pix.width == 1280) && (f->fmt.pix.height == 720)) {
1803 ret = true; //true zyw
1804 } else if ((f->fmt.pix.width == 1920) && (f->fmt.pix.height == 1080)) {
1805 ret = true; //true zyw
1809 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, f->fmt.pix.width, f->fmt.pix.height);
1813 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1815 struct reginfo *winseqe_set_addr = NULL;
1817 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1818 winseqe_set_addr = sensor_qcif;
1821 } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1822 winseqe_set_addr = sensor_qvga;
1825 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1826 winseqe_set_addr = sensor_cif;
1829 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1830 winseqe_set_addr = sensor_vga;
1833 } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1834 printk("enter 800x600\n");
1835 winseqe_set_addr = sensor_svga;
1838 } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1839 winseqe_set_addr = sensor_xga;
1842 } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1843 printk("enter 1280X720\n");
1844 winseqe_set_addr = sensor_720p;
1847 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1848 printk("enter 1280X1024\n");
1849 winseqe_set_addr = sensor_sxga;
1852 } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1853 winseqe_set_addr = sensor_uxga;
1856 } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1857 winseqe_set_addr = sensor_1080p;
1860 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1861 winseqe_set_addr = sensor_qxga;
1864 } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1865 winseqe_set_addr = sensor_qsxga;
1870 return winseqe_set_addr;
1873 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1875 struct i2c_client *client = sd->priv;
1876 struct sensor *sensor = to_sensor(client);
1877 struct v4l2_pix_format *pix = &f->fmt.pix;
1878 struct reginfo *winseqe_set_addr=NULL;
1879 int ret = 0, set_w,set_h;
1881 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,pix->width,pix->height);
1883 if (sensor->info_priv.pixfmt != pix->pixelformat) {
1884 switch (pix->pixelformat)
1886 case V4L2_PIX_FMT_YUYV:
1888 winseqe_set_addr = sensor_ClrFmt_YUYV;
1891 case V4L2_PIX_FMT_UYVY:
1893 winseqe_set_addr = sensor_ClrFmt_UYVY;
1899 if (winseqe_set_addr != NULL) {
1900 sensor_write_array(client, winseqe_set_addr);
1901 sensor->info_priv.pixfmt = pix->pixelformat;
1903 SENSOR_DG("%s Pixelformat(0x%x) set success!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1905 SENSOR_TR("%s Pixelformat(0x%x) is invalidate!\n", SENSOR_NAME_STRING(),pix->pixelformat);
1910 set_h = pix->height;
1912 winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1914 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1915 ret |= sensor_write_array(client, winseqe_set_addr);
1917 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1918 goto sensor_s_fmt_end;
1920 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
1921 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1922 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1924 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1925 sensor->info_priv.preview_w = pix->width;
1926 sensor->info_priv.preview_h = pix->height;
1930 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1931 ret |= sensor_write_array(client, sensor_Preview2Capture);
1933 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
1934 goto sensor_s_fmt_end;
1936 sensor->info_priv.capture_w = set_w;
1937 sensor->info_priv.capture_h = set_h;
1938 sensor->info_priv.snap2preview = true;
1939 } else if (sensor->info_priv.snap2preview == true) {
1940 if (winseqe_set_addr || ((sensor->info_priv.preview_w == pix->width) && (sensor->info_priv.preview_h == pix->height))) {
1941 ret |= sensor_write_array(client, sensor_Capture2Preview);
1943 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
1944 goto sensor_s_fmt_end;
1946 sensor->info_priv.preview_w = pix->width;
1947 sensor->info_priv.preview_h = pix->height;
1948 sensor->info_priv.snap2preview = false;
1950 SENSOR_TR("\n %s..%s Format is Invalidate. pix->width = %d.. pix->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,pix->width,pix->height);
1955 pix->height = set_h;
1960 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
1963 struct v4l2_pix_format *pix = &f->fmt.pix;
1964 bool bayer = pix->pixelformat == V4L2_PIX_FMT_UYVY ||
1965 pix->pixelformat == V4L2_PIX_FMT_YUYV;
1967 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,pix->width,pix->height);
1970 * With Bayer format enforce even side lengths, but let the user play
1971 * with the starting pixel
1974 if (pix->height > SENSOR_MAX_HEIGHT)
1975 pix->height = SENSOR_MAX_HEIGHT;
1976 else if (pix->height < SENSOR_MIN_HEIGHT)
1977 pix->height = SENSOR_MIN_HEIGHT;
1979 pix->height = ALIGN(pix->height, 2);
1981 if (pix->width > SENSOR_MAX_WIDTH)
1982 pix->width = SENSOR_MAX_WIDTH;
1983 else if (pix->width < SENSOR_MIN_WIDTH)
1984 pix->width = SENSOR_MIN_WIDTH;
1986 pix->width = ALIGN(pix->width, 2);
1988 if (sensor_fmt_catch(pix->width, pix->height, &pix->width, &pix->height) == NULL) {
1989 printk("%s[%d] ERR!!!!!!",__FUNCTION__,__LINE__);
1997 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
1999 struct i2c_client *client = sd->priv;
2001 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2004 if (id->match.addr != client->addr)
2007 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2012 #if CONFIG_SENSOR_Brightness
2013 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2015 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2017 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2019 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2021 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2023 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2026 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2030 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2034 #if CONFIG_SENSOR_Effect
2035 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2037 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2039 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2041 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2043 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2045 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2048 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2052 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2056 #if CONFIG_SENSOR_Exposure
2057 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2059 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2061 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2063 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2065 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2067 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2070 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2074 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2078 #if CONFIG_SENSOR_Saturation
2079 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2081 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2083 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2085 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2087 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2089 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2092 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2096 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2100 #if CONFIG_SENSOR_Contrast
2101 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2103 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2105 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2107 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2109 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2111 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2114 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2118 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2122 #if CONFIG_SENSOR_Mirror
2123 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2125 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2127 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2129 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2131 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2133 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2136 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2140 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2144 #if CONFIG_SENSOR_Flip
2145 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2147 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2149 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2151 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2153 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2155 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2158 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2162 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2166 #if CONFIG_SENSOR_Scene
2167 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2169 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2171 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2173 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2175 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2177 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2180 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2184 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2188 #if CONFIG_SENSOR_WhiteBalance
2189 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2191 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2193 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2195 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2197 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2199 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2202 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2206 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2210 #if CONFIG_SENSOR_DigitalZoom
2211 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2213 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2214 struct sensor *sensor = to_sensor(client);
2215 const struct v4l2_queryctrl *qctrl_info;
2216 int digitalzoom_cur, digitalzoom_total;
2218 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2222 digitalzoom_cur = sensor->info_priv.digitalzoom;
2223 digitalzoom_total = qctrl_info->maximum;
2225 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2227 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2231 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2233 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2237 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2239 *value = digitalzoom_total - digitalzoom_cur;
2242 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2244 *value = 0 - digitalzoom_cur;
2247 digitalzoom_cur += *value;
2249 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2251 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2253 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2256 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2263 #if CONFIG_SENSOR_Flash
2264 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2266 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2267 struct sensor *sensor = to_sensor(client);
2268 const struct v4l2_queryctrl *qctrl_info;
2270 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2271 if (value == 3) { /* ddl@rock-chips.com: torch */
2272 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2274 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2276 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2280 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2284 #if CONFIG_SENSOR_Focus
2285 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2287 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2288 struct sensor *sensor = to_sensor(client);
2289 const struct v4l2_queryctrl *qctrl_info;
2292 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2296 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2297 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2299 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2302 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2306 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2307 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2310 sensor_set_focus_absolute_end:
2313 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2315 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2316 struct sensor *sensor = to_sensor(client);
2317 const struct v4l2_queryctrl *qctrl_info;
2320 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2324 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2325 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2327 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2330 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2334 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2335 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2337 sensor_set_focus_relative_end:
2341 static int sensor_set_focus_mode(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);
2347 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2350 case SENSOR_AF_MODE_AUTO:
2352 ret = sensor_af_single(client);
2356 case SENSOR_AF_MODE_MACRO:
2358 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2362 case SENSOR_AF_MODE_INFINITY:
2364 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2368 case SENSOR_AF_MODE_CONTINUOUS:
2370 ret = sensor_af_const(client);
2374 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2379 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2382 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2383 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2389 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2391 struct i2c_client *client = sd->priv;
2392 struct sensor *sensor = to_sensor(client);
2393 const struct v4l2_queryctrl *qctrl;
2395 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2399 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2405 case V4L2_CID_BRIGHTNESS:
2407 ctrl->value = sensor->info_priv.brightness;
2410 case V4L2_CID_SATURATION:
2412 ctrl->value = sensor->info_priv.saturation;
2415 case V4L2_CID_CONTRAST:
2417 ctrl->value = sensor->info_priv.contrast;
2420 case V4L2_CID_DO_WHITE_BALANCE:
2422 ctrl->value = sensor->info_priv.whiteBalance;
2425 case V4L2_CID_EXPOSURE:
2427 ctrl->value = sensor->info_priv.exposure;
2430 case V4L2_CID_HFLIP:
2432 ctrl->value = sensor->info_priv.mirror;
2435 case V4L2_CID_VFLIP:
2437 ctrl->value = sensor->info_priv.flip;
2448 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2450 struct i2c_client *client = sd->priv;
2451 const struct v4l2_queryctrl *qctrl;
2452 struct sensor *sensor = to_sensor(client);
2453 struct soc_camera_device *icd = client->dev.platform_data;
2454 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2458 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2464 #if CONFIG_SENSOR_Brightness
2465 case V4L2_CID_BRIGHTNESS:
2467 if (ctrl->value != sensor->info_priv.brightness)
2469 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2473 sensor->info_priv.brightness = ctrl->value;
2478 #if CONFIG_SENSOR_Exposure
2479 case V4L2_CID_EXPOSURE:
2481 if (ctrl->value != sensor->info_priv.exposure)
2483 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2487 sensor->info_priv.exposure = ctrl->value;
2492 #if CONFIG_SENSOR_Saturation
2493 case V4L2_CID_SATURATION:
2495 if (ctrl->value != sensor->info_priv.saturation)
2497 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2501 sensor->info_priv.saturation = ctrl->value;
2506 #if CONFIG_SENSOR_Contrast
2507 case V4L2_CID_CONTRAST:
2509 if (ctrl->value != sensor->info_priv.contrast)
2511 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2515 sensor->info_priv.contrast = ctrl->value;
2520 #if CONFIG_SENSOR_WhiteBalance
2521 case V4L2_CID_DO_WHITE_BALANCE:
2523 if (ctrl->value != sensor->info_priv.whiteBalance)
2525 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2529 sensor->info_priv.whiteBalance = ctrl->value;
2534 #if CONFIG_SENSOR_Mirror
2535 case V4L2_CID_HFLIP:
2537 if (ctrl->value != sensor->info_priv.mirror)
2539 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2541 sensor->info_priv.mirror = ctrl->value;
2546 #if CONFIG_SENSOR_Flip
2547 case V4L2_CID_VFLIP:
2549 if (ctrl->value != sensor->info_priv.flip)
2551 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2553 sensor->info_priv.flip = ctrl->value;
2564 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2566 const struct v4l2_queryctrl *qctrl;
2567 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2568 struct sensor *sensor = to_sensor(client);
2570 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2574 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2578 switch (ext_ctrl->id)
2580 case V4L2_CID_SCENE:
2582 ext_ctrl->value = sensor->info_priv.scene;
2585 case V4L2_CID_EFFECT:
2587 ext_ctrl->value = sensor->info_priv.effect;
2590 case V4L2_CID_ZOOM_ABSOLUTE:
2592 ext_ctrl->value = sensor->info_priv.digitalzoom;
2595 case V4L2_CID_ZOOM_RELATIVE:
2599 case V4L2_CID_FOCUS_ABSOLUTE:
2603 case V4L2_CID_FOCUS_RELATIVE:
2607 case V4L2_CID_FLASH:
2609 ext_ctrl->value = sensor->info_priv.flash;
2617 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2619 const struct v4l2_queryctrl *qctrl;
2620 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2621 struct sensor *sensor = to_sensor(client);
2624 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2628 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2633 switch (ext_ctrl->id)
2635 #if CONFIG_SENSOR_Scene
2636 case V4L2_CID_SCENE:
2638 if (ext_ctrl->value != sensor->info_priv.scene)
2640 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2642 sensor->info_priv.scene = ext_ctrl->value;
2647 #if CONFIG_SENSOR_Effect
2648 case V4L2_CID_EFFECT:
2650 if (ext_ctrl->value != sensor->info_priv.effect)
2652 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2654 sensor->info_priv.effect= ext_ctrl->value;
2659 #if CONFIG_SENSOR_DigitalZoom
2660 case V4L2_CID_ZOOM_ABSOLUTE:
2662 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2665 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2667 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2669 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2671 sensor->info_priv.digitalzoom += val_offset;
2673 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2678 case V4L2_CID_ZOOM_RELATIVE:
2680 if (ext_ctrl->value)
2682 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2684 sensor->info_priv.digitalzoom += ext_ctrl->value;
2686 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2691 #if CONFIG_SENSOR_Focus
2692 case V4L2_CID_FOCUS_ABSOLUTE:
2694 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2697 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2698 if (ext_ctrl->value == qctrl->minimum) {
2699 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2700 } else if (ext_ctrl->value == qctrl->maximum) {
2701 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2703 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2709 case V4L2_CID_FOCUS_RELATIVE:
2711 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2714 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2717 case V4L2_CID_FOCUS_AUTO:
2719 if (ext_ctrl->value == 1) {
2720 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2722 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2723 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2724 if (ext_ctrl->value == 0)
2725 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2729 case V4L2_CID_FOCUS_CONTINUOUS:
2731 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2732 if (ext_ctrl->value == 1) {
2733 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2735 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2738 if (ext_ctrl->value == 0)
2739 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2744 #if CONFIG_SENSOR_Flash
2745 case V4L2_CID_FLASH:
2747 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2749 sensor->info_priv.flash = ext_ctrl->value;
2751 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2762 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2764 struct i2c_client *client = sd->priv;
2765 struct soc_camera_device *icd = client->dev.platform_data;
2766 int i, error_cnt=0, error_idx=-1;
2769 for (i=0; i<ext_ctrl->count; i++) {
2770 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2777 error_idx = ext_ctrl->count;
2779 if (error_idx != -1) {
2780 ext_ctrl->error_idx = error_idx;
2787 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2789 struct i2c_client *client = sd->priv;
2790 struct soc_camera_device *icd = client->dev.platform_data;
2791 int i, error_cnt=0, error_idx=-1;
2793 for (i=0; i<ext_ctrl->count; i++) {
2794 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2801 error_idx = ext_ctrl->count;
2803 if (error_idx != -1) {
2804 ext_ctrl->error_idx = error_idx;
2811 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2813 struct i2c_client *client = sd->priv;
2814 struct sensor *sensor = to_sensor(client);
2817 sensor->info_priv.enable = 1;
2818 } else if (enable == 0) {
2819 sensor->info_priv.enable = 0;
2825 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2826 * this wasn't our capture interface, so, we wait for the right one */
2827 static int sensor_video_probe(struct soc_camera_device *icd,
2828 struct i2c_client *client)
2831 struct sensor *sensor = to_sensor(client);
2832 #if (SENSOR_ID_REG != SEQUENCE_END)
2836 /* We must have a parent by now. And it cannot be a wrong one.
2837 * So this entire test is completely redundant. */
2838 if (!icd->dev.parent ||
2839 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2842 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2844 goto sensor_video_probe_err;
2848 #if (SENSOR_RESET_REG != SEQUENCE_END)
2849 struct reginfo reg_info;
2850 reg_info.reg = SENSOR_RESET_REG;
2851 reg_info.val = SENSOR_RESET_VAL;
2852 reg_info.reg_len = SENSOR_RESET_REG_LEN;
2853 ret = sensor_write(client, ®_info);
2855 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2857 goto sensor_video_probe_err;
2860 mdelay(5); //delay 5 microseconds
2863 /* check if it is an sensor sensor */
2864 #if (SENSOR_ID_REG != SEQUENCE_END)
2865 ret = sensor_read(client, SENSOR_ID_REG, &pid);
2867 SENSOR_TR("read chip id failed\n");
2869 goto sensor_video_probe_err;
2872 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2877 if (pid == SENSOR_ID) {
2878 sensor->model = SENSOR_V4L2_IDENT;
2880 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2882 goto sensor_video_probe_err;
2885 icd->formats = sensor_colour_formats;
2886 icd->num_formats = ARRAY_SIZE(sensor_colour_formats);
2890 sensor_video_probe_err:
2894 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2896 struct i2c_client *client = sd->priv;
2897 struct soc_camera_device *icd = client->dev.platform_data;
2898 struct sensor *sensor = to_sensor(client);
2901 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2904 case RK29_CAM_SUBDEV_DEACTIVATE:
2906 sensor_deactivate(client);
2909 case RK29_CAM_SUBDEV_IOREQUEST:
2911 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2912 if (sensor->sensor_io_request != NULL) {
2913 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2914 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2915 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2916 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2917 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2918 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2921 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2923 goto sensor_ioctl_end;
2925 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2927 #if CONFIG_SENSOR_Flash
2929 if (sensor->sensor_gpio_res) {
2930 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2931 for (i = 0; i < icd->ops->num_controls; i++) {
2932 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2933 memset(&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2936 sensor->info_priv.flash = 0xff;
2937 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2945 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2954 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2955 .init = sensor_init,
2956 .g_ctrl = sensor_g_control,
2957 .s_ctrl = sensor_s_control,
2958 .g_ext_ctrls = sensor_g_ext_controls,
2959 .s_ext_ctrls = sensor_s_ext_controls,
2960 .g_chip_ident = sensor_g_chip_ident,
2961 .ioctl = sensor_ioctl,
2964 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2965 .s_fmt = sensor_s_fmt,
2966 .g_fmt = sensor_g_fmt,
2967 .try_fmt = sensor_try_fmt,
2968 .s_stream = sensor_s_stream,
2971 static struct v4l2_subdev_ops sensor_subdev_ops = {
2972 .core = &sensor_subdev_core_ops,
2973 .video = &sensor_subdev_video_ops,
2976 static int sensor_probe(struct i2c_client *client,
2977 const struct i2c_device_id *did)
2979 struct sensor *sensor;
2980 struct soc_camera_device *icd = client->dev.platform_data;
2981 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
2982 struct soc_camera_link *icl;
2985 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
2987 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
2991 icl = to_soc_camera_link(icd);
2993 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
2997 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
2998 dev_warn(&adapter->dev,
2999 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3003 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3007 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3009 /* Second stage probe - when a capture adapter is there */
3010 icd->ops = &sensor_ops;
3011 icd->y_skip_top = 0;
3012 #if CONFIG_SENSOR_I2C_NOSCHED
3013 atomic_set(&sensor->tasklock_cnt,0);
3016 ret = sensor_video_probe(icd, client);
3019 i2c_set_clientdata(client, NULL);
3023 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3027 static int sensor_remove(struct i2c_client *client)
3029 struct sensor *sensor = to_sensor(client);
3030 struct soc_camera_device *icd = client->dev.platform_data;
3032 #if CONFIG_SENSOR_Focus
3033 if (sensor->sensor_wq) {
3034 destroy_workqueue(sensor->sensor_wq);
3035 sensor->sensor_wq = NULL;
3040 i2c_set_clientdata(client, NULL);
3041 client->driver = NULL;
3047 static const struct i2c_device_id sensor_id[] = {
3048 {SENSOR_NAME_STRING(), 0 },
3051 MODULE_DEVICE_TABLE(i2c, sensor_id);
3053 static struct i2c_driver sensor_i2c_driver = {
3055 .name = SENSOR_NAME_STRING(),
3057 .probe = sensor_probe,
3058 .remove = sensor_remove,
3059 .id_table = sensor_id,
3062 static int __init sensor_mod_init(void)
3064 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3065 return i2c_add_driver(&sensor_i2c_driver);
3068 static void __exit sensor_mod_exit(void)
3070 i2c_del_driver(&sensor_i2c_driver);
3073 device_initcall_sync(sensor_mod_init);
3074 module_exit(sensor_mod_exit);
3076 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3077 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3078 MODULE_LICENSE("GPL");