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_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 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 /* only one fixed colorspace per pixelcode */
1123 struct sensor_datafmt {
1124 enum v4l2_mbus_pixelcode code;
1125 enum v4l2_colorspace colorspace;
1128 /* Find a data format by a pixel code in an array */
1129 static const struct sensor_datafmt *sensor_find_datafmt(
1130 enum v4l2_mbus_pixelcode code, const struct sensor_datafmt *fmt,
1134 for (i = 0; i < n; i++)
1135 if (fmt[i].code == code)
1141 static const struct sensor_datafmt sensor_colour_fmts[] = {
1142 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
1143 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG}
1145 enum sensor_work_state
1147 sensor_work_ready = 0,
1152 struct i2c_client *client;
1153 struct delayed_work dwork;
1154 enum sensor_work_state state;
1157 typedef struct sensor_info_priv_s
1171 unsigned char mirror; /* HFLIP */
1172 unsigned char flip; /* VFLIP */
1179 struct reginfo *winseqe_cur_addr;
1180 struct sensor_datafmt fmt;
1181 unsigned int enable;
1182 unsigned int funmodule_state;
1183 } sensor_info_priv_t;
1187 struct sensor_parameter
1189 unsigned short int preview_maxlines;
1190 unsigned short int preview_exposure;
1191 unsigned short int preview_line_width;
1192 unsigned short int preview_gain;
1194 unsigned short int capture_framerate;
1195 unsigned short int preview_framerate;
1200 struct v4l2_subdev subdev;
1201 struct i2c_client *client;
1202 sensor_info_priv_t info_priv;
1203 struct sensor_parameter parameter;
1204 struct workqueue_struct *sensor_wq;
1205 struct sensor_work sensor_wk;
1206 struct mutex wq_lock;
1207 int model; /* V4L2_IDENT_OV* codes from v4l2-chip-ident.h */
1208 #if CONFIG_SENSOR_I2C_NOSCHED
1209 atomic_t tasklock_cnt;
1211 struct rk29camera_platform_data *sensor_io_request;
1212 struct rk29camera_gpio_res *sensor_gpio_res;
1215 static struct sensor* to_sensor(const struct i2c_client *client)
1217 return container_of(i2c_get_clientdata(client), struct sensor, subdev);
1220 static int sensor_task_lock(struct i2c_client *client, int lock)
1222 #if CONFIG_SENSOR_I2C_NOSCHED
1224 struct sensor *sensor = to_sensor(client);
1227 if (atomic_read(&sensor->tasklock_cnt) == 0) {
1228 while ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt>0)) {
1229 SENSOR_TR("\n %s will obtain i2c in atomic, but i2c bus is locked! Wait...\n",SENSOR_NAME_STRING());
1233 if ((atomic_read(&client->adapter->bus_lock.count) < 1) && (cnt<=0)) {
1234 SENSOR_TR("\n %s obtain i2c fail in atomic!!\n",SENSOR_NAME_STRING());
1235 goto sensor_task_lock_err;
1240 atomic_add(1, &sensor->tasklock_cnt);
1242 if (atomic_read(&sensor->tasklock_cnt) > 0) {
1243 atomic_sub(1, &sensor->tasklock_cnt);
1245 if (atomic_read(&sensor->tasklock_cnt) == 0)
1251 sensor_task_lock_err:
1258 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val);
1260 /* sensor register write */
1261 static int sensor_write(struct i2c_client *client, struct reginfo *reg_info)
1265 struct i2c_msg msg[1];
1267 switch (reg_info->reg)
1269 case SEQUENCE_WAIT_MS:
1272 mdelay(reg_info->val);
1274 msleep(reg_info->val);
1278 case SEQUENCE_WAIT_US:
1280 udelay(reg_info->val);
1284 case SEQUENCE_PROPERTY:
1290 buf[0] = reg_info->reg >> 8;
1291 buf[1] = reg_info->reg & 0xFF;
1292 if (reg_info->reg_len == WORD_LEN) {
1293 buf[2] = reg_info->val >> 8;
1294 buf[3] = reg_info->val & 0xFF;
1297 } else if (reg_info->reg_len == BYTE_LEN) {
1298 buf[2] = reg_info->val;
1302 msg->addr = client->addr;
1303 msg->flags = client->flags;
1305 msg->scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1306 msg->read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1311 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1312 err = i2c_transfer(client->adapter, msg, 1);
1317 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);
1326 /* sensor register read */
1327 static int sensor_read(struct i2c_client *client, u16 reg, u16 *val)
1331 struct i2c_msg msg[2];
1334 buf[1] = reg & 0xFF;
1336 msg[0].addr = client->addr;
1337 msg[0].flags = client->flags;
1339 msg[0].len = sizeof(buf);
1340 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1341 msg[0].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1343 msg[1].addr = client->addr;
1344 msg[1].flags = client->flags|I2C_M_RD;
1347 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1348 msg[1].read_type = 2; /* fpga i2c:0==I2C_NO_STOP : direct use number not enum for don't want include spi_fpga.h */
1352 while ((cnt-- > 0) && (err < 0)) { /* ddl@rock-chips.com : Transfer again if transent is failed */
1353 err = i2c_transfer(client->adapter, msg, 2);
1356 *val = buf[0]<<8 | buf[1];
1359 SENSOR_TR("\n %s read reg(0x%x val:0x%x) failed, try to read again! \n",SENSOR_NAME_STRING(),reg, *val);
1367 /* write a array of registers */
1368 static int sensor_write_array(struct i2c_client *client, struct reginfo *regarray)
1372 #if CONFIG_SENSOR_I2C_RDWRCHK
1377 if (sensor_task_lock(client, 1) < 0)
1378 goto sensor_write_array_end;
1379 while (regarray[i].reg != SEQUENCE_END) {
1380 err = sensor_write(client, ®array[i]);
1384 SENSOR_TR("%s..write failed current reg:0x%x, Write array again !\n", SENSOR_NAME_STRING(),regarray[i].reg);
1388 SENSOR_TR("%s..write array failed!!!\n", SENSOR_NAME_STRING());
1390 goto sensor_write_array_end;
1393 #if CONFIG_SENSOR_I2C_RDWRCHK
1394 sensor_read(client, regarray[i].reg, &valchk);
1395 if (valchk != regarray[i].val)
1396 SENSOR_TR("%s Reg:0x%x write(0x%x, 0x%x) fail\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1403 sensor_write_array_end:
1404 sensor_task_lock(client,0);
1407 #if CONFIG_SENSOR_I2C_RDWRCHK
1408 static int sensor_readchk_array(struct i2c_client *client, struct reginfo *regarray)
1416 while (regarray[i].reg != SEQUENCE_END)
1418 sensor_read(client, regarray[i].reg, &valchk);
1419 if (valchk != regarray[i].val)
1420 SENSOR_TR("%s Reg:0x%x read(0x%x, 0x%x) error\n",SENSOR_NAME_STRING(), regarray[i].reg, regarray[i].val, valchk);
1427 #if CONFIG_SENSOR_Focus
1428 static struct reginfo sensor_af_init0[] =
1431 {SEQUENCE_END, 0x00}
1433 static struct reginfo sensor_af_init1[] =
1435 {SEQUENCE_END, 0x00}
1439 static struct reginfo sensor_af_trigger[] =
1441 {SEQUENCE_END, 0x00}
1443 static int sensor_af_single(struct i2c_client *client)
1447 ret = sensor_write_array(client, sensor_af_trigger);
1449 SENSOR_TR("%s sensor auto focus trigger fail!!\n",SENSOR_NAME_STRING());
1451 SENSOR_DG("%s sensor auto focus trigger success!\n",SENSOR_NAME_STRING());
1452 sensor_af_single_end:
1456 static int sensor_af_const(struct i2c_client *client)
1460 sensor_af_const_end:
1464 static int sensor_af_zoneupdate(struct i2c_client *client)
1467 struct i2c_msg msg[2];
1470 {0xb0,0x08,0x00,0x03,0xff,0xff},
1471 {0xb0,0x0c,0xff,0xff,0xff,0xff},
1474 msg[0].addr = client->addr;
1475 msg[0].flags = client->flags;
1476 msg[0].buf = buf[0];
1477 msg[0].len = sizeof(buf);
1478 msg[0].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1479 msg[0].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1481 msg[1].addr = client->addr;
1482 msg[1].flags = client->flags;
1483 msg[1].buf = buf[1];
1484 msg[1].len = sizeof(buf);
1485 msg[1].scl_rate = CONFIG_SENSOR_I2C_SPEED; /* ddl@rock-chips.com : 100kHz */
1486 msg[1].read_type = 0; /* fpga i2c:0==I2C_NORMAL : direct use number not enum for don't want include spi_fpga.h */
1488 ret = i2c_transfer(client->adapter, &msg[0], 1);
1489 ret |= i2c_transfer(client->adapter, &msg[1], 1);
1493 SENSOR_TR("\n %s sensor auto focus zone set fail!!\n",SENSOR_NAME_STRING());
1496 sensor_af_zoneupdate_end:
1500 static int sensor_af_init(struct i2c_client *client)
1504 ret = sensor_write_array(client, sensor_af_init0);
1506 SENSOR_TR("%s sensor auto focus init_0 fail!!",SENSOR_NAME_STRING());
1508 if (sensor_af_zoneupdate(client) == 0) {
1509 ret = sensor_write_array(client, sensor_af_init1);
1511 SENSOR_TR("%s sensor auto focus init_1 fail!!",SENSOR_NAME_STRING());
1520 static int sensor_ioctrl(struct soc_camera_device *icd,enum rk29sensor_power_cmd cmd, int on)
1522 struct soc_camera_link *icl = to_soc_camera_link(icd);
1525 SENSOR_DG("%s %s cmd(%d) on(%d)\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd,on);
1528 case Sensor_PowerDown:
1530 if (icl->powerdown) {
1531 ret = icl->powerdown(icd->pdev, on);
1532 if (ret == RK29_CAM_IO_SUCCESS) {
1536 icl->reset(icd->pdev);
1538 } else if (ret == RK29_CAM_EIO_REQUESTFAIL) {
1540 goto sensor_power_end;
1547 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1548 struct sensor *sensor = to_sensor(client);
1550 if (sensor->sensor_io_request && sensor->sensor_io_request->sensor_ioctrl) {
1551 sensor->sensor_io_request->sensor_ioctrl(icd->pdev,Cam_Flash, on);
1557 SENSOR_TR("%s %s cmd(0x%x) is unknown!",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
1565 static int sensor_init(struct v4l2_subdev *sd, u32 val)
1567 struct i2c_client *client = v4l2_get_subdevdata(sd);
1568 struct soc_camera_device *icd = client->dev.platform_data;
1569 struct sensor *sensor = to_sensor(client);
1570 const struct v4l2_queryctrl *qctrl;
1571 const struct sensor_datafmt *fmt;
1575 SENSOR_DG("\n%s..%s.. \n",SENSOR_NAME_STRING(),__FUNCTION__);
1577 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
1579 goto sensor_INIT_ERR;
1583 if (sensor_task_lock(client,1)<0)
1584 goto sensor_INIT_ERR;
1586 #if (SENSOR_RESET_REG != SEQUENCE_END)
1587 struct reginfo reg_info;
1588 reg_info.reg = SENSOR_RESET_REG;
1589 reg_info.val = SENSOR_RESET_VAL;
1590 reg_info.reg_len = SENSOR_RESET_REG_LEN;
1591 ret = sensor_write(client, ®_info);
1593 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
1595 goto sensor_INIT_ERR;
1597 mdelay(5); //delay 5 microseconds
1598 reg_info.val = SENSOR_DERESET_VAL;
1599 ret = sensor_write(client, ®_info);
1601 SENSOR_TR("%s soft dereset sensor failed\n",SENSOR_NAME_STRING());
1603 goto sensor_INIT_ERR;
1607 /* check if it is an sensor sensor */
1608 #if (SENSOR_ID_REG != SEQUENCE_END)
1609 ret = sensor_read(client, SENSOR_ID_REG, &pid);
1611 SENSOR_TR("read chip id failed\n");
1613 goto sensor_INIT_ERR;
1616 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
1620 if (pid == SENSOR_ID) {
1621 sensor->model = SENSOR_V4L2_IDENT;
1623 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
1625 goto sensor_INIT_ERR;
1628 ret = sensor_write_array(client, sensor_init_data);
1631 SENSOR_TR("error: %s initial failed\n",SENSOR_NAME_STRING());
1632 goto sensor_INIT_ERR;
1634 sensor_task_lock(client,0);
1635 sensor->info_priv.preview_w = SENSOR_INIT_WIDTH;
1636 sensor->info_priv.preview_h = SENSOR_INIT_HEIGHT;
1637 sensor->info_priv.capture_w = SENSOR_MAX_WIDTH;
1638 sensor->info_priv.capture_h = SENSOR_MAX_HEIGHT;
1639 sensor->info_priv.winseqe_cur_addr = SENSOR_INIT_WINSEQADR;
1640 fmt = sensor_find_datafmt(SENSOR_INIT_PIXFMT,sensor_colour_fmts, ARRAY_SIZE(sensor_colour_fmts));
1642 SENSOR_TR("error: %s initial array colour fmts is not support!!",SENSOR_NAME_STRING());
1644 goto sensor_INIT_ERR;
1646 sensor->info_priv.fmt = *fmt;
1648 /* sensor sensor information for initialization */
1649 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_DO_WHITE_BALANCE);
1651 sensor->info_priv.whiteBalance = qctrl->default_value;
1652 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_BRIGHTNESS);
1654 sensor->info_priv.brightness = qctrl->default_value;
1655 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EFFECT);
1657 sensor->info_priv.effect = qctrl->default_value;
1658 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_EXPOSURE);
1660 sensor->info_priv.exposure = qctrl->default_value;
1662 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SATURATION);
1664 sensor->info_priv.saturation = qctrl->default_value;
1665 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_CONTRAST);
1667 sensor->info_priv.contrast = qctrl->default_value;
1668 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_HFLIP);
1670 sensor->info_priv.mirror = qctrl->default_value;
1671 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_VFLIP);
1673 sensor->info_priv.flip = qctrl->default_value;
1674 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_SCENE);
1676 sensor->info_priv.scene = qctrl->default_value;
1677 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
1679 sensor->info_priv.digitalzoom = qctrl->default_value;
1681 /* ddl@rock-chips.com : if sensor support auto focus and flash, programer must run focus and flash code */
1682 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
1684 sensor->info_priv.focus = qctrl->default_value;
1685 #if CONFIG_SENSOR_Focus
1686 if (sensor_af_init(client) < 0) {
1687 sensor->info_priv.funmodule_state &= ~SENSOR_AF_IS_OK;
1688 SENSOR_TR("%s auto focus module init is fail!\n",SENSOR_NAME_STRING());
1690 sensor->info_priv.funmodule_state |= SENSOR_AF_IS_OK;
1691 SENSOR_DG("%s auto focus module init is success!\n",SENSOR_NAME_STRING());
1694 #if CONFIG_SENSOR_Flash
1695 qctrl = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FLASH);
1697 sensor->info_priv.flash = qctrl->default_value;
1699 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);
1703 sensor_task_lock(client,0);
1704 sensor_deactivate(client);
1707 static int sensor_deactivate(struct i2c_client *client)
1709 struct soc_camera_device *icd = client->dev.platform_data;
1711 SENSOR_DG("\n%s..%s.. Enter\n",SENSOR_NAME_STRING(),__FUNCTION__);
1713 /* ddl@rock-chips.com : all sensor output pin must change to input for other sensor */
1714 sensor_ioctrl(icd, Sensor_PowerDown, 1);
1716 /* ddl@rock-chips.com : sensor config init width , because next open sensor quickly(soc_camera_open -> Try to configure with default parameters) */
1717 icd->user_width = SENSOR_INIT_WIDTH;
1718 icd->user_height = SENSOR_INIT_HEIGHT;
1722 static struct reginfo sensor_power_down_sequence[]=
1726 static int sensor_suspend(struct soc_camera_device *icd, pm_message_t pm_msg)
1729 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
1731 if (pm_msg.event == PM_EVENT_SUSPEND) {
1732 SENSOR_DG("\n %s Enter Suspend.. \n", SENSOR_NAME_STRING());
1733 ret = sensor_write_array(client, sensor_power_down_sequence) ;
1735 SENSOR_TR("\n %s..%s WriteReg Fail.. \n", SENSOR_NAME_STRING(),__FUNCTION__);
1738 ret = sensor_ioctrl(icd, Sensor_PowerDown, 1);
1740 SENSOR_TR("\n %s suspend fail for turn on power!\n", SENSOR_NAME_STRING());
1745 SENSOR_TR("\n %s cann't suppout Suspend..\n",SENSOR_NAME_STRING());
1752 static int sensor_resume(struct soc_camera_device *icd)
1756 ret = sensor_ioctrl(icd, Sensor_PowerDown, 0);
1758 SENSOR_TR("\n %s resume fail for turn on power!\n", SENSOR_NAME_STRING());
1762 SENSOR_DG("\n %s Enter Resume.. \n", SENSOR_NAME_STRING());
1766 static int sensor_set_bus_param(struct soc_camera_device *icd,
1767 unsigned long flags)
1773 static unsigned long sensor_query_bus_param(struct soc_camera_device *icd)
1775 struct soc_camera_link *icl = to_soc_camera_link(icd);
1776 unsigned long flags = SENSOR_BUS_PARAM;
1778 return soc_camera_apply_sensor_flags(icl, flags);
1780 static int sensor_g_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1782 struct i2c_client *client = v4l2_get_subdevdata(sd);
1783 struct soc_camera_device *icd = client->dev.platform_data;
1784 struct sensor *sensor = to_sensor(client);
1786 mf->width = icd->user_width;
1787 mf->height = icd->user_height;
1788 mf->code = sensor->info_priv.fmt.code;
1789 mf->colorspace = sensor->info_priv.fmt.colorspace;
1790 mf->field = V4L2_FIELD_NONE;
1794 static bool sensor_fmt_capturechk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1798 if ((mf->width == 1024) && (mf->height == 768)) {
1800 } else if ((mf->width == 1280) && (mf->height == 1024)) {
1802 } else if ((mf->width == 1600) && (mf->height == 1200)) {
1804 } else if ((mf->width == 2048) && (mf->height == 1536)) {
1806 } else if ((mf->width == 2592) && (mf->height == 1944)) {
1811 SENSOR_DG("%s %dx%d is capture format\n", __FUNCTION__, mf->width, mf->height);
1815 static bool sensor_fmt_videochk(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1819 if ((mf->width == 1280) && (mf->height == 720)) {
1821 } else if ((mf->width == 1920) && (mf->height == 1080)) {
1826 SENSOR_DG("%s %dx%d is video format\n", __FUNCTION__, mf->width, mf->height);
1829 static struct reginfo* sensor_fmt_catch(int set_w, int set_h, int *ret_w, int *ret_h)
1831 struct reginfo *winseqe_set_addr = NULL;
1833 if (((set_w <= 176) && (set_h <= 144)) && (sensor_qcif[0].reg!=SEQUENCE_END)) {
1834 winseqe_set_addr = sensor_qcif;
1837 } else if (((set_w <= 320) && (set_h <= 240)) && (sensor_qvga[0].reg!=SEQUENCE_END)) {
1838 winseqe_set_addr = sensor_qvga;
1841 } else if (((set_w <= 352) && (set_h<= 288)) && (sensor_cif[0].reg!=SEQUENCE_END)) {
1842 winseqe_set_addr = sensor_cif;
1845 } else if (((set_w <= 640) && (set_h <= 480)) && (sensor_vga[0].reg!=SEQUENCE_END)) {
1846 winseqe_set_addr = sensor_vga;
1849 } else if (((set_w <= 800) && (set_h <= 600)) && (sensor_svga[0].reg!=SEQUENCE_END)) {
1850 printk("enter 800x600\n");
1851 winseqe_set_addr = sensor_svga;
1854 } else if (((set_w <= 1024) && (set_h <= 768)) && (sensor_xga[0].reg!=SEQUENCE_END)) {
1855 winseqe_set_addr = sensor_xga;
1858 } else if (((set_w <= 1280) && (set_h <= 720)) && (sensor_720p[0].reg!=SEQUENCE_END)) {
1859 printk("enter 1280X720\n");
1860 winseqe_set_addr = sensor_720p;
1863 } else if (((set_w <= 1280) && (set_h <= 1024)) && (sensor_sxga[0].reg!=SEQUENCE_END)) {
1864 printk("enter 1280X1024\n");
1865 winseqe_set_addr = sensor_sxga;
1868 } else if (((set_w <= 1600) && (set_h <= 1200)) && (sensor_uxga[0].reg!=SEQUENCE_END)) {
1869 winseqe_set_addr = sensor_uxga;
1872 } else if (((set_w <= 1920) && (set_h <= 1080)) && (sensor_1080p[0].reg!=SEQUENCE_END)) {
1873 winseqe_set_addr = sensor_1080p;
1876 } else if (((set_w <= 2048) && (set_h <= 1536)) && (sensor_qxga[0].reg!=SEQUENCE_END)) {
1877 winseqe_set_addr = sensor_qxga;
1880 } else if (((set_w <= 2592) && (set_h <= 1944)) && (sensor_qsxga[0].reg!=SEQUENCE_END)) {
1881 winseqe_set_addr = sensor_qsxga;
1886 return winseqe_set_addr;
1889 static int sensor_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1891 struct i2c_client *client = v4l2_get_subdevdata(sd);
1892 struct sensor *sensor = to_sensor(client);
1893 const struct sensor_datafmt *fmt;
1894 struct reginfo *winseqe_set_addr=NULL;
1895 int ret = 0, set_w,set_h;
1897 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
1899 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1900 ARRAY_SIZE(sensor_colour_fmts));
1903 goto sensor_s_fmt_end;
1906 if (sensor->info_priv.fmt.code != mf->code) {
1909 case V4L2_MBUS_FMT_YUYV8_2X8:
1911 winseqe_set_addr = sensor_ClrFmt_YUYV;
1914 case V4L2_MBUS_FMT_UYVY8_2X8:
1916 winseqe_set_addr = sensor_ClrFmt_UYVY;
1922 if (winseqe_set_addr != NULL) {
1923 sensor_write_array(client, winseqe_set_addr);
1924 sensor->info_priv.fmt.code = mf->code;
1925 sensor->info_priv.fmt.colorspace= mf->colorspace;
1926 SENSOR_DG("%s v4l2_mbus_code:%d set success!\n", SENSOR_NAME_STRING(),mf->code);
1928 SENSOR_TR("%s v4l2_mbus_code:%d is invalidate!\n", SENSOR_NAME_STRING(),mf->code);
1935 winseqe_set_addr = sensor_fmt_catch(set_w, set_h, &set_w, &set_h);
1937 if ((winseqe_set_addr != sensor->info_priv.winseqe_cur_addr) && winseqe_set_addr) {
1938 ret |= sensor_write_array(client, winseqe_set_addr);
1940 SENSOR_TR("%s set format capability failed\n", SENSOR_NAME_STRING());
1941 goto sensor_s_fmt_end;
1943 sensor->info_priv.winseqe_cur_addr = winseqe_set_addr;
1944 if ((winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1945 SENSOR_DG("\n%s..%s..Capture icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1947 SENSOR_DG("\n%s..%s..Video icd->width = %d.. icd->height %d\n",SENSOR_NAME_STRING(),__FUNCTION__,set_w,set_h);
1948 sensor->info_priv.preview_w = mf->width;
1949 sensor->info_priv.preview_h = mf->height;
1953 if (winseqe_set_addr && (winseqe_set_addr[0].reg==SEQUENCE_PROPERTY) && (winseqe_set_addr[0].val==SEQUENCE_CAPTURE)) {
1954 ret |= sensor_write_array(client, sensor_Preview2Capture);
1956 SENSOR_TR("%s Preview 2 Capture failed\n", SENSOR_NAME_STRING());
1957 goto sensor_s_fmt_end;
1959 sensor->info_priv.capture_w = set_w;
1960 sensor->info_priv.capture_h = set_h;
1961 sensor->info_priv.snap2preview = true;
1962 } else if (sensor->info_priv.snap2preview == true) {
1963 if (winseqe_set_addr || ((sensor->info_priv.preview_w == mf->width) && (sensor->info_priv.preview_h == mf->height))) {
1964 ret |= sensor_write_array(client, sensor_Capture2Preview);
1966 SENSOR_TR("%s Capture 2 Preview failed\n", SENSOR_NAME_STRING());
1967 goto sensor_s_fmt_end;
1969 sensor->info_priv.preview_w = mf->width;
1970 sensor->info_priv.preview_h = mf->height;
1971 sensor->info_priv.snap2preview = false;
1973 SENSOR_TR("\n %s..%s Format is Invalidate. mf->width = %d.. mf->height = %d\n",SENSOR_NAME_STRING(),__FUNCTION__,mf->width,mf->height);
1983 static int sensor_try_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
1986 struct i2c_client *client = v4l2_get_subdevdata(sd);
1987 struct sensor *sensor = to_sensor(client);
1988 const struct sensor_datafmt *fmt;
1990 fmt = sensor_find_datafmt(mf->code, sensor_colour_fmts,
1991 ARRAY_SIZE(sensor_colour_fmts));
1993 fmt = &sensor->info_priv.fmt;
1994 mf->code = fmt->code;
1997 SENSOR_TR("%s pix->width=%d,pix->height=%d\n",__FUNCTION__,mf->width,mf->height);
2000 * With Bayer format enforce even side lengths, but let the user play
2001 * with the starting pixel
2004 if (mf->height > SENSOR_MAX_HEIGHT)
2005 mf->height = SENSOR_MAX_HEIGHT;
2006 else if (mf->height < SENSOR_MIN_HEIGHT)
2007 mf->height = SENSOR_MIN_HEIGHT;
2009 if (mf->width > SENSOR_MAX_WIDTH)
2010 mf->width = SENSOR_MAX_WIDTH;
2011 else if (mf->width < SENSOR_MIN_WIDTH)
2012 mf->width = SENSOR_MIN_WIDTH;
2014 if (sensor_fmt_catch(mf->width, mf->height, &mf->width, &mf->height) == NULL) {
2015 printk("%s[%d] ERR!!!!!!",__FUNCTION__,__LINE__);
2023 static int sensor_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *id)
2025 struct i2c_client *client = v4l2_get_subdevdata(sd);
2027 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
2030 if (id->match.addr != client->addr)
2033 id->ident = SENSOR_V4L2_IDENT; /* ddl@rock-chips.com : Return OV2655 identifier */
2038 #if CONFIG_SENSOR_Brightness
2039 static int sensor_set_brightness(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2041 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2043 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2045 if (sensor_BrightnessSeqe[value - qctrl->minimum] != NULL)
2047 if (sensor_write_array(client, sensor_BrightnessSeqe[value - qctrl->minimum]) != 0)
2049 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2052 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2056 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2060 #if CONFIG_SENSOR_Effect
2061 static int sensor_set_effect(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2063 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2065 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2067 if (sensor_EffectSeqe[value - qctrl->minimum] != NULL)
2069 if (sensor_write_array(client, sensor_EffectSeqe[value - qctrl->minimum]) != 0)
2071 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2074 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2078 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2082 #if CONFIG_SENSOR_Exposure
2083 static int sensor_set_exposure(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2085 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2087 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2089 if (sensor_ExposureSeqe[value - qctrl->minimum] != NULL)
2091 if (sensor_write_array(client, sensor_ExposureSeqe[value - qctrl->minimum]) != 0)
2093 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2096 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2100 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2104 #if CONFIG_SENSOR_Saturation
2105 static int sensor_set_saturation(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2107 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2109 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2111 if (sensor_SaturationSeqe[value - qctrl->minimum] != NULL)
2113 if (sensor_write_array(client, sensor_SaturationSeqe[value - qctrl->minimum]) != 0)
2115 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2118 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2122 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2126 #if CONFIG_SENSOR_Contrast
2127 static int sensor_set_contrast(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2129 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2131 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2133 if (sensor_ContrastSeqe[value - qctrl->minimum] != NULL)
2135 if (sensor_write_array(client, sensor_ContrastSeqe[value - qctrl->minimum]) != 0)
2137 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2140 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2144 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2148 #if CONFIG_SENSOR_Mirror
2149 static int sensor_set_mirror(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2151 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2153 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2155 if (sensor_MirrorSeqe[value - qctrl->minimum] != NULL)
2157 if (sensor_write_array(client, sensor_MirrorSeqe[value - qctrl->minimum]) != 0)
2159 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2162 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2166 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2170 #if CONFIG_SENSOR_Flip
2171 static int sensor_set_flip(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2173 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2175 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2177 if (sensor_FlipSeqe[value - qctrl->minimum] != NULL)
2179 if (sensor_write_array(client, sensor_FlipSeqe[value - qctrl->minimum]) != 0)
2181 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2184 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2188 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2192 #if CONFIG_SENSOR_Scene
2193 static int sensor_set_scene(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2195 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2197 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2199 if (sensor_SceneSeqe[value - qctrl->minimum] != NULL)
2201 if (sensor_write_array(client, sensor_SceneSeqe[value - qctrl->minimum]) != 0)
2203 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2206 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2210 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2214 #if CONFIG_SENSOR_WhiteBalance
2215 static int sensor_set_whiteBalance(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2217 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2219 if ((value >= qctrl->minimum) && (value <= qctrl->maximum))
2221 if (sensor_WhiteBalanceSeqe[value - qctrl->minimum] != NULL)
2223 if (sensor_write_array(client, sensor_WhiteBalanceSeqe[value - qctrl->minimum]) != 0)
2225 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2228 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2232 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2236 #if CONFIG_SENSOR_DigitalZoom
2237 static int sensor_set_digitalzoom(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2239 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2240 struct sensor *sensor = to_sensor(client);
2241 const struct v4l2_queryctrl *qctrl_info;
2242 int digitalzoom_cur, digitalzoom_total;
2244 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_ZOOM_ABSOLUTE);
2248 digitalzoom_cur = sensor->info_priv.digitalzoom;
2249 digitalzoom_total = qctrl_info->maximum;
2251 if ((*value > 0) && (digitalzoom_cur >= digitalzoom_total))
2253 SENSOR_TR("%s digitalzoom is maximum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2257 if ((*value < 0) && (digitalzoom_cur <= qctrl_info->minimum))
2259 SENSOR_TR("%s digitalzoom is minimum - %x\n", SENSOR_NAME_STRING(), digitalzoom_cur);
2263 if ((*value > 0) && ((digitalzoom_cur + *value) > digitalzoom_total))
2265 *value = digitalzoom_total - digitalzoom_cur;
2268 if ((*value < 0) && ((digitalzoom_cur + *value) < 0))
2270 *value = 0 - digitalzoom_cur;
2273 digitalzoom_cur += *value;
2275 if (sensor_ZoomSeqe[digitalzoom_cur] != NULL)
2277 if (sensor_write_array(client, sensor_ZoomSeqe[digitalzoom_cur]) != 0)
2279 SENSOR_TR("%s..%s WriteReg Fail.. \n",SENSOR_NAME_STRING(), __FUNCTION__);
2282 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, *value);
2289 #if CONFIG_SENSOR_Flash
2290 static int sensor_set_flash(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int *value)
2292 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2293 struct sensor *sensor = to_sensor(client);
2294 const struct v4l2_queryctrl *qctrl_info;
2296 if ((value >= qctrl->minimum) && (value <= qctrl->maximum)) {
2297 if (value == 3) { /* ddl@rock-chips.com: torch */
2298 sensor_ioctrl(icd, Sensor_Flash, Flash_Torch); /* Flash On */
2300 sensor_ioctrl(icd, Sensor_Flash, Flash_Off);
2302 SENSOR_DG("%s..%s : %x\n",SENSOR_NAME_STRING(),__FUNCTION__, value);
2306 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2310 #if CONFIG_SENSOR_Focus
2311 static int sensor_set_focus_absolute(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2313 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2314 struct sensor *sensor = to_sensor(client);
2315 const struct v4l2_queryctrl *qctrl_info;
2318 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_ABSOLUTE);
2322 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2323 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2325 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2328 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2332 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2333 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2336 sensor_set_focus_absolute_end:
2339 static int sensor_set_focus_relative(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2341 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2342 struct sensor *sensor = to_sensor(client);
2343 const struct v4l2_queryctrl *qctrl_info;
2346 qctrl_info = soc_camera_find_qctrl(&sensor_ops, V4L2_CID_FOCUS_RELATIVE);
2350 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2351 if ((value >= qctrl_info->minimum) && (value <= qctrl_info->maximum)) {
2353 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2356 SENSOR_TR("\n %s..%s valure = %d is invalidate.. \n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2360 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2361 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2363 sensor_set_focus_relative_end:
2367 static int sensor_set_focus_mode(struct soc_camera_device *icd, const struct v4l2_queryctrl *qctrl, int value)
2369 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2370 struct sensor *sensor = to_sensor(client);
2373 if ((sensor->info_priv.funmodule_state & SENSOR_AF_IS_OK) && (sensor->info_priv.affm_reinit == 0)) {
2376 case SENSOR_AF_MODE_AUTO:
2378 ret = sensor_af_single(client);
2382 case SENSOR_AF_MODE_MACRO:
2384 ret = sensor_set_focus_absolute(icd, qctrl, 0xff);
2388 case SENSOR_AF_MODE_INFINITY:
2390 ret = sensor_set_focus_absolute(icd, qctrl, 0x00);
2394 case SENSOR_AF_MODE_CONTINUOUS:
2396 ret = sensor_af_const(client);
2400 SENSOR_TR("\n %s..%s AF value(0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,value);
2405 SENSOR_DG("%s..%s : %d ret:0x%x\n",SENSOR_NAME_STRING(),__FUNCTION__, value,ret);
2408 SENSOR_TR("\n %s..%s AF module state(0x%x, 0x%x) is error!\n",SENSOR_NAME_STRING(),__FUNCTION__,
2409 sensor->info_priv.funmodule_state,sensor->info_priv.affm_reinit);
2415 static int sensor_g_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2417 struct i2c_client *client = v4l2_get_subdevdata(sd);
2418 struct sensor *sensor = to_sensor(client);
2419 const struct v4l2_queryctrl *qctrl;
2421 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2425 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2431 case V4L2_CID_BRIGHTNESS:
2433 ctrl->value = sensor->info_priv.brightness;
2436 case V4L2_CID_SATURATION:
2438 ctrl->value = sensor->info_priv.saturation;
2441 case V4L2_CID_CONTRAST:
2443 ctrl->value = sensor->info_priv.contrast;
2446 case V4L2_CID_DO_WHITE_BALANCE:
2448 ctrl->value = sensor->info_priv.whiteBalance;
2451 case V4L2_CID_EXPOSURE:
2453 ctrl->value = sensor->info_priv.exposure;
2456 case V4L2_CID_HFLIP:
2458 ctrl->value = sensor->info_priv.mirror;
2461 case V4L2_CID_VFLIP:
2463 ctrl->value = sensor->info_priv.flip;
2474 static int sensor_s_control(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
2476 struct i2c_client *client = v4l2_get_subdevdata(sd);
2477 const struct v4l2_queryctrl *qctrl;
2478 struct sensor *sensor = to_sensor(client);
2479 struct soc_camera_device *icd = client->dev.platform_data;
2480 qctrl = soc_camera_find_qctrl(&sensor_ops, ctrl->id);
2484 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ctrl->id);
2490 #if CONFIG_SENSOR_Brightness
2491 case V4L2_CID_BRIGHTNESS:
2493 if (ctrl->value != sensor->info_priv.brightness)
2495 if (sensor_set_brightness(icd, qctrl,ctrl->value) != 0)
2499 sensor->info_priv.brightness = ctrl->value;
2504 #if CONFIG_SENSOR_Exposure
2505 case V4L2_CID_EXPOSURE:
2507 if (ctrl->value != sensor->info_priv.exposure)
2509 if (sensor_set_exposure(icd, qctrl,ctrl->value) != 0)
2513 sensor->info_priv.exposure = ctrl->value;
2518 #if CONFIG_SENSOR_Saturation
2519 case V4L2_CID_SATURATION:
2521 if (ctrl->value != sensor->info_priv.saturation)
2523 if (sensor_set_saturation(icd, qctrl,ctrl->value) != 0)
2527 sensor->info_priv.saturation = ctrl->value;
2532 #if CONFIG_SENSOR_Contrast
2533 case V4L2_CID_CONTRAST:
2535 if (ctrl->value != sensor->info_priv.contrast)
2537 if (sensor_set_contrast(icd, qctrl,ctrl->value) != 0)
2541 sensor->info_priv.contrast = ctrl->value;
2546 #if CONFIG_SENSOR_WhiteBalance
2547 case V4L2_CID_DO_WHITE_BALANCE:
2549 if (ctrl->value != sensor->info_priv.whiteBalance)
2551 if (sensor_set_whiteBalance(icd, qctrl,ctrl->value) != 0)
2555 sensor->info_priv.whiteBalance = ctrl->value;
2560 #if CONFIG_SENSOR_Mirror
2561 case V4L2_CID_HFLIP:
2563 if (ctrl->value != sensor->info_priv.mirror)
2565 if (sensor_set_mirror(icd, qctrl,ctrl->value) != 0)
2567 sensor->info_priv.mirror = ctrl->value;
2572 #if CONFIG_SENSOR_Flip
2573 case V4L2_CID_VFLIP:
2575 if (ctrl->value != sensor->info_priv.flip)
2577 if (sensor_set_flip(icd, qctrl,ctrl->value) != 0)
2579 sensor->info_priv.flip = ctrl->value;
2590 static int sensor_g_ext_control(struct soc_camera_device *icd , struct v4l2_ext_control *ext_ctrl)
2592 const struct v4l2_queryctrl *qctrl;
2593 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2594 struct sensor *sensor = to_sensor(client);
2596 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2600 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2604 switch (ext_ctrl->id)
2606 case V4L2_CID_SCENE:
2608 ext_ctrl->value = sensor->info_priv.scene;
2611 case V4L2_CID_EFFECT:
2613 ext_ctrl->value = sensor->info_priv.effect;
2616 case V4L2_CID_ZOOM_ABSOLUTE:
2618 ext_ctrl->value = sensor->info_priv.digitalzoom;
2621 case V4L2_CID_ZOOM_RELATIVE:
2625 case V4L2_CID_FOCUS_ABSOLUTE:
2629 case V4L2_CID_FOCUS_RELATIVE:
2633 case V4L2_CID_FLASH:
2635 ext_ctrl->value = sensor->info_priv.flash;
2643 static int sensor_s_ext_control(struct soc_camera_device *icd, struct v4l2_ext_control *ext_ctrl)
2645 const struct v4l2_queryctrl *qctrl;
2646 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
2647 struct sensor *sensor = to_sensor(client);
2650 qctrl = soc_camera_find_qctrl(&sensor_ops, ext_ctrl->id);
2654 SENSOR_TR("\n %s ioctrl id = %d is invalidate \n", SENSOR_NAME_STRING(), ext_ctrl->id);
2659 switch (ext_ctrl->id)
2661 #if CONFIG_SENSOR_Scene
2662 case V4L2_CID_SCENE:
2664 if (ext_ctrl->value != sensor->info_priv.scene)
2666 if (sensor_set_scene(icd, qctrl,ext_ctrl->value) != 0)
2668 sensor->info_priv.scene = ext_ctrl->value;
2673 #if CONFIG_SENSOR_Effect
2674 case V4L2_CID_EFFECT:
2676 if (ext_ctrl->value != sensor->info_priv.effect)
2678 if (sensor_set_effect(icd, qctrl,ext_ctrl->value) != 0)
2680 sensor->info_priv.effect= ext_ctrl->value;
2685 #if CONFIG_SENSOR_DigitalZoom
2686 case V4L2_CID_ZOOM_ABSOLUTE:
2688 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2691 if (ext_ctrl->value != sensor->info_priv.digitalzoom)
2693 val_offset = ext_ctrl->value -sensor->info_priv.digitalzoom;
2695 if (sensor_set_digitalzoom(icd, qctrl,&val_offset) != 0)
2697 sensor->info_priv.digitalzoom += val_offset;
2699 SENSOR_DG("%s digitalzoom is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2704 case V4L2_CID_ZOOM_RELATIVE:
2706 if (ext_ctrl->value)
2708 if (sensor_set_digitalzoom(icd, qctrl,&ext_ctrl->value) != 0)
2710 sensor->info_priv.digitalzoom += ext_ctrl->value;
2712 SENSOR_DG("%s digitalzoom is %x\n", SENSOR_NAME_STRING(), sensor->info_priv.digitalzoom);
2717 #if CONFIG_SENSOR_Focus
2718 case V4L2_CID_FOCUS_ABSOLUTE:
2720 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2723 if (sensor_set_focus_absolute(icd, qctrl,ext_ctrl->value) == 0) {
2724 if (ext_ctrl->value == qctrl->minimum) {
2725 sensor->info_priv.auto_focus = SENSOR_AF_MODE_INFINITY;
2726 } else if (ext_ctrl->value == qctrl->maximum) {
2727 sensor->info_priv.auto_focus = SENSOR_AF_MODE_MACRO;
2729 sensor->info_priv.auto_focus = SENSOR_AF_MODE_FIXED;
2735 case V4L2_CID_FOCUS_RELATIVE:
2737 if ((ext_ctrl->value < qctrl->minimum) || (ext_ctrl->value > qctrl->maximum))
2740 sensor_set_focus_relative(icd, qctrl,ext_ctrl->value);
2743 case V4L2_CID_FOCUS_AUTO:
2745 if (ext_ctrl->value == 1) {
2746 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_AUTO) != 0)
2748 sensor->info_priv.auto_focus = SENSOR_AF_MODE_AUTO;
2749 } else if (SENSOR_AF_MODE_AUTO == sensor->info_priv.auto_focus){
2750 if (ext_ctrl->value == 0)
2751 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2755 case V4L2_CID_FOCUS_CONTINUOUS:
2757 if (SENSOR_AF_MODE_CONTINUOUS != sensor->info_priv.auto_focus) {
2758 if (ext_ctrl->value == 1) {
2759 if (sensor_set_focus_mode(icd, qctrl,SENSOR_AF_MODE_CONTINUOUS) != 0)
2761 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CONTINUOUS;
2764 if (ext_ctrl->value == 0)
2765 sensor->info_priv.auto_focus = SENSOR_AF_MODE_CLOSE;
2770 #if CONFIG_SENSOR_Flash
2771 case V4L2_CID_FLASH:
2773 if (sensor_set_flash(icd, qctrl,ext_ctrl->value) != 0)
2775 sensor->info_priv.flash = ext_ctrl->value;
2777 SENSOR_DG("%s flash is %x\n",SENSOR_NAME_STRING(), sensor->info_priv.flash);
2788 static int sensor_g_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2790 struct i2c_client *client = v4l2_get_subdevdata(sd);
2791 struct soc_camera_device *icd = client->dev.platform_data;
2792 int i, error_cnt=0, error_idx=-1;
2795 for (i=0; i<ext_ctrl->count; i++) {
2796 if (sensor_g_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2803 error_idx = ext_ctrl->count;
2805 if (error_idx != -1) {
2806 ext_ctrl->error_idx = error_idx;
2813 static int sensor_s_ext_controls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ext_ctrl)
2815 struct i2c_client *client = v4l2_get_subdevdata(sd);
2816 struct soc_camera_device *icd = client->dev.platform_data;
2817 int i, error_cnt=0, error_idx=-1;
2819 for (i=0; i<ext_ctrl->count; i++) {
2820 if (sensor_s_ext_control(icd, &ext_ctrl->controls[i]) != 0) {
2827 error_idx = ext_ctrl->count;
2829 if (error_idx != -1) {
2830 ext_ctrl->error_idx = error_idx;
2837 static int sensor_s_stream(struct v4l2_subdev *sd, int enable)
2839 struct i2c_client *client = v4l2_get_subdevdata(sd);
2840 struct sensor *sensor = to_sensor(client);
2843 sensor->info_priv.enable = 1;
2844 } else if (enable == 0) {
2845 sensor->info_priv.enable = 0;
2851 /* Interface active, can use i2c. If it fails, it can indeed mean, that
2852 * this wasn't our capture interface, so, we wait for the right one */
2853 static int sensor_video_probe(struct soc_camera_device *icd,
2854 struct i2c_client *client)
2857 struct sensor *sensor = to_sensor(client);
2858 #if (SENSOR_ID_REG != SEQUENCE_END)
2862 /* We must have a parent by now. And it cannot be a wrong one.
2863 * So this entire test is completely redundant. */
2864 if (!icd->dev.parent ||
2865 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
2868 if (sensor_ioctrl(icd, Sensor_PowerDown, 0) < 0) {
2870 goto sensor_video_probe_err;
2874 #if (SENSOR_RESET_REG != SEQUENCE_END)
2875 struct reginfo reg_info;
2876 reg_info.reg = SENSOR_RESET_REG;
2877 reg_info.val = SENSOR_RESET_VAL;
2878 reg_info.reg_len = SENSOR_RESET_REG_LEN;
2879 ret = sensor_write(client, ®_info);
2881 SENSOR_TR("%s soft reset sensor failed\n",SENSOR_NAME_STRING());
2883 goto sensor_video_probe_err;
2886 mdelay(5); //delay 5 microseconds
2889 /* check if it is an sensor sensor */
2890 #if (SENSOR_ID_REG != SEQUENCE_END)
2891 ret = sensor_read(client, SENSOR_ID_REG, &pid);
2893 SENSOR_TR("read chip id failed\n");
2895 goto sensor_video_probe_err;
2898 SENSOR_DG("\n %s pid = 0x%x \n", SENSOR_NAME_STRING(), pid);
2903 if (pid == SENSOR_ID) {
2904 sensor->model = SENSOR_V4L2_IDENT;
2906 SENSOR_TR("error: %s mismatched pid = 0x%x\n", SENSOR_NAME_STRING(), pid);
2908 goto sensor_video_probe_err;
2915 sensor_video_probe_err:
2919 static long sensor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
2921 struct i2c_client *client = v4l2_get_subdevdata(sd);
2922 struct soc_camera_device *icd = client->dev.platform_data;
2923 struct sensor *sensor = to_sensor(client);
2926 SENSOR_DG("\n%s..%s..cmd:%x \n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2929 case RK29_CAM_SUBDEV_DEACTIVATE:
2931 sensor_deactivate(client);
2934 case RK29_CAM_SUBDEV_IOREQUEST:
2936 sensor->sensor_io_request = (struct rk29camera_platform_data*)arg;
2937 if (sensor->sensor_io_request != NULL) {
2938 if (sensor->sensor_io_request->gpio_res[0].dev_name &&
2939 (strcmp(sensor->sensor_io_request->gpio_res[0].dev_name, dev_name(icd->pdev)) == 0)) {
2940 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[0];
2941 } else if (sensor->sensor_io_request->gpio_res[1].dev_name &&
2942 (strcmp(sensor->sensor_io_request->gpio_res[1].dev_name, dev_name(icd->pdev)) == 0)) {
2943 sensor->sensor_gpio_res = (struct rk29camera_gpio_res*)&sensor->sensor_io_request->gpio_res[1];
2946 SENSOR_TR("%s %s RK29_CAM_SUBDEV_IOREQUEST fail\n",SENSOR_NAME_STRING(),__FUNCTION__);
2948 goto sensor_ioctl_end;
2950 /* ddl@rock-chips.com : if gpio_flash havn't been set in board-xxx.c, sensor driver must notify is not support flash control
2952 #if CONFIG_SENSOR_Flash
2954 if (sensor->sensor_gpio_res) {
2955 if (sensor->sensor_gpio_res->gpio_flash == INVALID_GPIO) {
2956 for (i = 0; i < icd->ops->num_controls; i++) {
2957 if (V4L2_CID_FLASH == icd->ops->controls[i].id) {
2958 memset(&icd->ops->controls[i],0x00,sizeof(struct v4l2_queryctrl));
2961 sensor->info_priv.flash = 0xff;
2962 SENSOR_DG("%s flash gpio is invalidate!\n",SENSOR_NAME_STRING());
2970 SENSOR_TR("%s %s cmd(0x%x) is unknown !\n",SENSOR_NAME_STRING(),__FUNCTION__,cmd);
2978 static int sensor_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
2979 enum v4l2_mbus_pixelcode *code)
2981 if (index >= ARRAY_SIZE(sensor_colour_fmts))
2984 *code = sensor_colour_fmts[index].code;
2987 static struct v4l2_subdev_core_ops sensor_subdev_core_ops = {
2988 .init = sensor_init,
2989 .g_ctrl = sensor_g_control,
2990 .s_ctrl = sensor_s_control,
2991 .g_ext_ctrls = sensor_g_ext_controls,
2992 .s_ext_ctrls = sensor_s_ext_controls,
2993 .g_chip_ident = sensor_g_chip_ident,
2994 .ioctl = sensor_ioctl,
2997 static struct v4l2_subdev_video_ops sensor_subdev_video_ops = {
2998 .s_mbus_fmt = sensor_s_fmt,
2999 .g_mbus_fmt = sensor_g_fmt,
3000 .try_mbus_fmt = sensor_try_fmt,
3001 .enum_mbus_fmt = sensor_enum_fmt,
3003 static struct v4l2_subdev_ops sensor_subdev_ops = {
3004 .core = &sensor_subdev_core_ops,
3005 .video = &sensor_subdev_video_ops,
3008 static int sensor_probe(struct i2c_client *client,
3009 const struct i2c_device_id *did)
3011 struct sensor *sensor;
3012 struct soc_camera_device *icd = client->dev.platform_data;
3013 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
3014 struct soc_camera_link *icl;
3017 SENSOR_DG("\n%s..%s..%d..\n",__FUNCTION__,__FILE__,__LINE__);
3019 dev_err(&client->dev, "%s: missing soc-camera data!\n",SENSOR_NAME_STRING());
3023 icl = to_soc_camera_link(icd);
3025 dev_err(&client->dev, "%s driver needs platform data\n", SENSOR_NAME_STRING());
3029 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
3030 dev_warn(&adapter->dev,
3031 "I2C-Adapter doesn't support I2C_FUNC_I2C\n");
3035 sensor = kzalloc(sizeof(struct sensor), GFP_KERNEL);
3039 v4l2_i2c_subdev_init(&sensor->subdev, client, &sensor_subdev_ops);
3041 /* Second stage probe - when a capture adapter is there */
3042 icd->ops = &sensor_ops;
3043 sensor->info_priv.fmt = sensor_colour_fmts[0];
3044 #if CONFIG_SENSOR_I2C_NOSCHED
3045 atomic_set(&sensor->tasklock_cnt,0);
3048 ret = sensor_video_probe(icd, client);
3051 i2c_set_clientdata(client, NULL);
3055 SENSOR_DG("\n%s..%s..%d ret = %x \n",__FUNCTION__,__FILE__,__LINE__,ret);
3059 static int sensor_remove(struct i2c_client *client)
3061 struct sensor *sensor = to_sensor(client);
3062 struct soc_camera_device *icd = client->dev.platform_data;
3064 #if CONFIG_SENSOR_Focus
3065 if (sensor->sensor_wq) {
3066 destroy_workqueue(sensor->sensor_wq);
3067 sensor->sensor_wq = NULL;
3072 i2c_set_clientdata(client, NULL);
3073 client->driver = NULL;
3079 static const struct i2c_device_id sensor_id[] = {
3080 {SENSOR_NAME_STRING(), 0 },
3083 MODULE_DEVICE_TABLE(i2c, sensor_id);
3085 static struct i2c_driver sensor_i2c_driver = {
3087 .name = SENSOR_NAME_STRING(),
3089 .probe = sensor_probe,
3090 .remove = sensor_remove,
3091 .id_table = sensor_id,
3094 static int __init sensor_mod_init(void)
3096 SENSOR_DG("\n%s..%s.. \n",__FUNCTION__,SENSOR_NAME_STRING());
3097 return i2c_add_driver(&sensor_i2c_driver);
3100 static void __exit sensor_mod_exit(void)
3102 i2c_del_driver(&sensor_i2c_driver);
3105 device_initcall_sync(sensor_mod_init);
3106 module_exit(sensor_mod_exit);
3108 MODULE_DESCRIPTION(SENSOR_NAME_STRING(Camera sensor driver));
3109 MODULE_AUTHOR("ddl <kernel@rock-chips>");
3110 MODULE_LICENSE("GPL");