2 * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
4 * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
5 * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define MODULE_NAME "sonixj"
27 #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
29 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30 MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
31 MODULE_LICENSE("GPL");
33 /* specific webcam descriptor */
35 struct gspca_dev gspca_dev; /* !! must be the first item */
47 u8 vflip; /* ov7630/ov7648 only */
48 u8 infrared; /* mt9v111 only */
49 u8 freq; /* ov76xx only */
50 u8 quality; /* image quality */
51 #define QUALITY_MIN 60
52 #define QUALITY_MAX 95
53 #define QUALITY_DEF 80
54 u8 jpegqual; /* webcam quality */
59 #define AG_CNT_START 13
62 #define BRIDGE_SN9C102P 0
63 #define BRIDGE_SN9C105 1
64 #define BRIDGE_SN9C110 2
65 #define BRIDGE_SN9C120 3
66 u8 sensor; /* Type of image sensor chip */
67 #define SENSOR_HV7131R 0
68 #define SENSOR_MI0360 1
69 #define SENSOR_MO4000 2
70 #define SENSOR_MT9V111 3
71 #define SENSOR_OM6802 4
72 #define SENSOR_OV7630 5
73 #define SENSOR_OV7648 6
74 #define SENSOR_OV7660 7
75 #define SENSOR_PO1030 8
76 #define SENSOR_SP80708 9
82 /* V4L2 controls supported by the driver */
83 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
84 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
85 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
86 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
87 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
88 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
89 static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
90 static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
91 static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
92 static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
93 static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
94 static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
95 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
96 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
97 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
98 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
99 static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
100 static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
101 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
102 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
104 static struct ctrl sd_ctrls[] = {
105 #define BRIGHTNESS_IDX 0
108 .id = V4L2_CID_BRIGHTNESS,
109 .type = V4L2_CTRL_TYPE_INTEGER,
110 .name = "Brightness",
112 #define BRIGHTNESS_MAX 0xffff
113 .maximum = BRIGHTNESS_MAX,
115 #define BRIGHTNESS_DEF 0x8000
116 .default_value = BRIGHTNESS_DEF,
118 .set = sd_setbrightness,
119 .get = sd_getbrightness,
121 #define CONTRAST_IDX 1
124 .id = V4L2_CID_CONTRAST,
125 .type = V4L2_CTRL_TYPE_INTEGER,
128 #define CONTRAST_MAX 127
129 .maximum = CONTRAST_MAX,
131 #define CONTRAST_DEF 63
132 .default_value = CONTRAST_DEF,
134 .set = sd_setcontrast,
135 .get = sd_getcontrast,
140 .id = V4L2_CID_SATURATION,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Saturation",
147 .default_value = COLOR_DEF,
152 #define BLUE_BALANCE_IDX 3
155 .id = V4L2_CID_BLUE_BALANCE,
156 .type = V4L2_CTRL_TYPE_INTEGER,
157 .name = "Blue Balance",
161 #define BLUE_BALANCE_DEF 32
162 .default_value = BLUE_BALANCE_DEF,
164 .set = sd_setblue_balance,
165 .get = sd_getblue_balance,
167 #define RED_BALANCE_IDX 4
170 .id = V4L2_CID_RED_BALANCE,
171 .type = V4L2_CTRL_TYPE_INTEGER,
172 .name = "Red Balance",
176 #define RED_BALANCE_DEF 32
177 .default_value = RED_BALANCE_DEF,
179 .set = sd_setred_balance,
180 .get = sd_getred_balance,
185 .id = V4L2_CID_GAMMA,
186 .type = V4L2_CTRL_TYPE_INTEGER,
192 .default_value = GAMMA_DEF,
197 #define AUTOGAIN_IDX 6
200 .id = V4L2_CID_AUTOGAIN,
201 .type = V4L2_CTRL_TYPE_BOOLEAN,
206 #define AUTOGAIN_DEF 1
207 .default_value = AUTOGAIN_DEF,
209 .set = sd_setautogain,
210 .get = sd_getautogain,
212 /* ov7630/ov7648 only */
216 .id = V4L2_CID_VFLIP,
217 .type = V4L2_CTRL_TYPE_BOOLEAN,
223 .default_value = VFLIP_DEF,
229 #define INFRARED_IDX 8
232 .id = V4L2_CID_INFRARED,
233 .type = V4L2_CTRL_TYPE_BOOLEAN,
238 #define INFRARED_DEF 0
239 .default_value = INFRARED_DEF,
241 .set = sd_setinfrared,
242 .get = sd_getinfrared,
244 /* ov7630/ov7648/ov7660 only */
248 .id = V4L2_CID_POWER_LINE_FREQUENCY,
249 .type = V4L2_CTRL_TYPE_MENU,
250 .name = "Light frequency filter",
252 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
255 .default_value = FREQ_DEF,
262 /* table of the disabled controls */
263 static __u32 ctrl_dis[] = {
264 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
265 /* SENSOR_HV7131R 0 */
266 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
267 /* SENSOR_MI0360 1 */
268 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
269 /* SENSOR_MO4000 2 */
270 (1 << VFLIP_IDX) | (1 << FREQ_IDX),
271 /* SENSOR_MT9V111 3 */
272 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
273 /* SENSOR_OM6802 4 */
275 /* SENSOR_OV7630 5 */
277 /* SENSOR_OV7648 6 */
278 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
279 /* SENSOR_OV7660 7 */
280 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
281 (1 << FREQ_IDX), /* SENSOR_PO1030 8 */
282 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
283 (1 << FREQ_IDX), /* SENSOR_SP80708 9 */
286 static const struct v4l2_pix_format vga_mode[] = {
287 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
289 .sizeimage = 160 * 120 * 4 / 8 + 590,
290 .colorspace = V4L2_COLORSPACE_JPEG,
292 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
294 .sizeimage = 320 * 240 * 3 / 8 + 590,
295 .colorspace = V4L2_COLORSPACE_JPEG,
297 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
299 /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
300 .sizeimage = 640 * 480 * 3 / 4 + 590,
301 .colorspace = V4L2_COLORSPACE_JPEG,
305 /*Data from sn9c102p+hv7131r */
306 static const u8 sn_hv7131[0x1c] = {
307 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
308 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
309 /* reg8 reg9 rega regb regc regd rege regf */
310 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
311 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
312 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
313 /* reg18 reg19 reg1a reg1b */
314 0x0a, 0x00, 0x00, 0x00
317 static const u8 sn_mi0360[0x1c] = {
318 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
319 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
320 /* reg8 reg9 rega regb regc regd rege regf */
321 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
323 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
324 /* reg18 reg19 reg1a reg1b */
325 0x06, 0x00, 0x00, 0x00
328 static const u8 sn_mo4000[0x1c] = {
329 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
330 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
331 /* reg8 reg9 rega regb regc regd rege regf */
332 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
334 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
335 /* reg18 reg19 reg1a reg1b */
336 0x08, 0x00, 0x00, 0x00
339 static const u8 sn_mt9v111[0x1c] = {
340 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
341 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
342 /* reg8 reg9 rega regb regc regd rege regf */
343 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
344 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
345 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
346 /* reg18 reg19 reg1a reg1b */
347 0x06, 0x00, 0x00, 0x00
350 static const u8 sn_om6802[0x1c] = {
351 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
352 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
353 /* reg8 reg9 rega regb regc regd rege regf */
354 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
356 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
357 /* reg18 reg19 reg1a reg1b */
358 0x05, 0x00, 0x00, 0x00
361 static const u8 sn_ov7630[0x1c] = {
362 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
363 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
364 /* reg8 reg9 rega regb regc regd rege regf */
365 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
366 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
367 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
368 /* reg18 reg19 reg1a reg1b */
369 0x0b, 0x00, 0x00, 0x00
372 static const u8 sn_ov7648[0x1c] = {
373 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
374 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
375 /* reg8 reg9 rega regb regc regd rege regf */
376 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
378 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
379 /* reg18 reg19 reg1a reg1b */
380 0x0b, 0x00, 0x00, 0x00
383 static const u8 sn_ov7660[0x1c] = {
384 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
385 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
386 /* reg8 reg9 rega regb regc regd rege regf */
387 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
388 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
389 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
390 /* reg18 reg19 reg1a reg1b */
391 0x07, 0x00, 0x00, 0x00
394 static const u8 sn_po1030[0x1c] = {
395 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
396 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
397 /* reg8 reg9 rega regb regc regd rege regf */
398 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
400 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
401 /* reg18 reg19 reg1a reg1b */
402 0x07, 0x00, 0x00, 0x00
405 static const u8 sn_sp80708[0x1c] = {
406 /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
407 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
408 /* reg8 reg9 rega regb regc regd rege regf */
409 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
410 /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
411 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
412 /* reg18 reg19 reg1a reg1b */
413 0x07, 0x00, 0x00, 0x00
416 /* sequence specific to the sensors - !! index = SENSOR_xxx */
417 static const u8 *sn_tb[] = {
430 /* default gamma table */
431 static const u8 gamma_def[17] = {
432 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
433 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
435 /* gamma for sensors HV7131R and MT9V111 */
436 static const u8 gamma_spec_1[17] = {
437 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
438 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
440 /* gamma for sensor SP80708 */
441 static const u8 gamma_spec_2[17] = {
442 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
443 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
446 /* color matrix and offsets */
447 static const u8 reg84[] = {
448 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
449 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
450 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
451 0x00, 0x00, 0x00 /* YUV offsets */
453 static const u8 hv7131r_sensor_init[][8] = {
454 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
455 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
456 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
457 /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
458 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
459 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
460 /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
462 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
463 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
464 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
465 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
466 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
467 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
468 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
469 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
471 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
472 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
473 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
474 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
475 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
477 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
478 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
479 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
480 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
481 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
482 {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
483 /* set sensor clock */
486 static const u8 mi0360_sensor_init[][8] = {
487 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
488 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
489 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
490 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
491 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
492 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
493 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
494 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
495 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
496 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
497 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
498 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
499 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
500 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
501 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
502 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
503 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
504 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
505 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
506 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
507 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
508 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
509 {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
510 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
511 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
512 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
513 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
514 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
515 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
516 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
517 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
518 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
519 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
521 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
522 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
523 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
524 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
525 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
527 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
528 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
529 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
530 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
532 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
533 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
534 /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
535 /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
536 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
537 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
540 static const u8 mo4000_sensor_init[][8] = {
541 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
542 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
543 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
544 {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
545 {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
546 {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
547 {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
548 {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
549 {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
550 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
551 {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
552 {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
553 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
554 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
555 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
556 {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
557 {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
558 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
559 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
560 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
563 static const u8 mt9v111_sensor_init[][8] = {
564 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
565 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
566 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
567 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
568 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
569 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
570 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
571 {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
572 {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
573 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
574 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
575 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
576 {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
577 {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
578 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
579 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
580 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
581 {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
582 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
583 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
584 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
585 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
586 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
587 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
588 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
589 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
590 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
591 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
594 static const u8 mt9v111_sensor_param1[][8] = {
595 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
596 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
597 {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
598 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
599 {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
601 {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
602 {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
603 {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
604 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
607 static const u8 om6802_init0[2][8] = {
609 {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
610 {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
612 static const u8 om6802_sensor_init[][8] = {
613 {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
615 {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
617 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
618 /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
619 {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
620 /* auto-exposure speed (0) / white balance mode (auto RGB) */
621 /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
623 /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
624 * max AGC value in AE */
625 /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
627 /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
628 * preset brightness */
629 /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
631 /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
633 {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
634 /* luminance mode (0x4f -> AutoExpo on) */
635 {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
637 /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
639 /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
640 {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
643 static const u8 om6802_sensor_param1[][8] = {
644 {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
645 {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
646 {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
647 {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
650 static const u8 ov7630_sensor_init[][8] = {
651 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
652 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
653 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
654 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
655 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
656 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
657 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
658 /* win: i2c_r from 00 to 80 */
659 {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
660 {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
661 /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
662 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
663 {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
664 {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
665 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
666 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
667 {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
668 {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
669 {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
670 {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
671 {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
672 {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
673 {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
674 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
675 {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
676 {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
677 {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
678 {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
679 {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
680 {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
681 {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
682 {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
683 {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
684 {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
685 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
686 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
688 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
689 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
690 /*fixme: + 0x12, 0x04*/
691 /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
693 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
694 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
695 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
697 /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
698 /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
700 {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
701 /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
705 static const u8 ov7648_sensor_init[][8] = {
706 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
707 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
708 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
709 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
710 {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
711 {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
712 {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
713 {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
714 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
715 {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
716 {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
717 {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
718 {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
719 {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
720 {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
721 {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
722 {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
723 {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
724 {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
725 {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
726 {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
727 {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
729 {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
730 /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
731 /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
732 /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
735 static const u8 ov7648_sensor_param1[][8] = {
736 /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
737 /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
739 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
740 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
741 /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
742 /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
743 /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
745 {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
746 /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
747 /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
748 /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
749 /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
750 /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
755 static const u8 ov7660_sensor_init[][8] = {
756 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
757 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
758 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
759 /* Outformat = rawRGB */
760 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
761 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
762 /* GAIN BLUE RED VREF */
763 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
764 /* COM 1 BAVE GEAVE AECHH */
765 {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
766 {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
767 {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
768 /* AECH CLKRC COM7 COM8 */
769 {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
770 {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
771 /* HSTART HSTOP VSTRT VSTOP */
772 {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
773 {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
774 {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
775 /* BOS GBOS GROS ROS (BGGR offset) */
776 /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
777 {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
778 /* AEW AEB VPT BBIAS */
779 {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
780 /* GbBIAS RSVD EXHCH EXHCL */
781 {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
782 /* RBIAS ADVFL ASDVFH YAVE */
783 {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
784 /* HSYST HSYEN HREF */
785 {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
786 {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
787 /* ADC ACOM OFON TSLB */
788 {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
789 /* COM11 COM12 COM13 COM14 */
790 {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
791 /* EDGE COM15 COM16 COM17 */
792 {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
793 {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
794 {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
795 {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
796 {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
797 {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
798 {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
799 {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
800 {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
801 {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
802 /* LCC1 LCC2 LCC3 LCC4 */
803 {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
804 {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
805 {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
806 /* band gap reference [0:3] DBLV */
807 {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
808 {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
809 {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
810 {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
811 {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
812 {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
813 {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
814 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
815 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
816 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
817 /* not in all ms-win traces*/
818 {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
821 static const u8 ov7660_sensor_param1[][8] = {
822 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
823 /* bits[3..0]reserved */
824 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
825 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
826 /* VREF vertical frame ctrl */
827 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
828 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
829 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
830 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
831 {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
832 /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
833 /****** (some exchanges in the win trace) ******/
835 {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
836 {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
837 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
838 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
839 /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
840 /****** (some exchanges in the win trace) ******/
841 /******!! startsensor KO if changed !!****/
843 {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
844 {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
845 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
846 {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
850 static const u8 po1030_sensor_init[][8] = {
851 /* the sensor registers are described in m5602/m5602_po1030.h */
852 {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
853 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
854 {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
855 {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
856 {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
857 {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
858 {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
859 {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
860 {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
861 {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
862 {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
863 {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
864 {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
865 {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
866 {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
867 {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
868 {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
869 {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
870 {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
871 {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
872 {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
873 {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
874 {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
875 {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
876 {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
877 {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
878 {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
879 {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
881 {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
882 {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
883 {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
884 {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
885 {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
888 static const u8 po1030_sensor_param1[][8] = {
889 /* from ms-win traces - these values change with auto gain/expo/wb.. */
890 {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
891 {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
893 {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
894 {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
895 {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
897 {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
898 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
899 {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
900 /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
904 static const u8 sp80708_sensor_init[][8] = {
905 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
906 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
907 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
908 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
909 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
910 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
911 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
912 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
913 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
914 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
915 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
916 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
917 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
918 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
919 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
920 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
921 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
922 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
923 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
924 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
925 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
926 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
927 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
928 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
929 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
930 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
931 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
932 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
933 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
934 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
935 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
936 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
937 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
938 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
939 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
940 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
941 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
942 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
943 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
944 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
945 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
946 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
947 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
948 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
949 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
950 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
951 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
952 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
953 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
954 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
955 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
956 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
957 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
958 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
959 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
960 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
961 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
962 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
963 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
964 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
965 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
966 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
967 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
968 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
969 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
970 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
971 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
972 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
973 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
974 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
975 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
978 static const u8 sp80708_sensor_param1[][8] = {
979 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
980 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
981 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
982 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
983 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
984 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
985 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
989 static const u8 (*sensor_init[10])[8] = {
990 hv7131r_sensor_init, /* HV7131R 0 */
991 mi0360_sensor_init, /* MI0360 1 */
992 mo4000_sensor_init, /* MO4000 2 */
993 mt9v111_sensor_init, /* MT9V111 3 */
994 om6802_sensor_init, /* OM6802 4 */
995 ov7630_sensor_init, /* OV7630 5 */
996 ov7648_sensor_init, /* OV7648 6 */
997 ov7660_sensor_init, /* OV7660 7 */
998 po1030_sensor_init, /* PO1030 8 */
999 sp80708_sensor_init, /* SP80708 9 */
1002 /* read <len> bytes to gspca_dev->usb_buf */
1003 static void reg_r(struct gspca_dev *gspca_dev,
1007 if (len > USB_BUF_SZ) {
1008 err("reg_r: buffer overflow");
1012 usb_control_msg(gspca_dev->dev,
1013 usb_rcvctrlpipe(gspca_dev->dev, 0),
1015 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1017 gspca_dev->usb_buf, len,
1019 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
1022 static void reg_w1(struct gspca_dev *gspca_dev,
1026 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
1027 gspca_dev->usb_buf[0] = data;
1028 usb_control_msg(gspca_dev->dev,
1029 usb_sndctrlpipe(gspca_dev->dev, 0),
1031 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1034 gspca_dev->usb_buf, 1,
1037 static void reg_w(struct gspca_dev *gspca_dev,
1042 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
1043 value, buffer[0], buffer[1]);
1045 if (len > USB_BUF_SZ) {
1046 err("reg_w: buffer overflow");
1050 memcpy(gspca_dev->usb_buf, buffer, len);
1051 usb_control_msg(gspca_dev->dev,
1052 usb_sndctrlpipe(gspca_dev->dev, 0),
1054 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1056 gspca_dev->usb_buf, len,
1060 /* I2C write 1 byte */
1061 static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1063 struct sd *sd = (struct sd *) gspca_dev;
1065 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
1066 switch (sd->sensor) {
1067 case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */
1068 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
1070 default: /* i2c command = a1 (400 kHz) */
1071 gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
1074 gspca_dev->usb_buf[1] = sd->i2c_addr;
1075 gspca_dev->usb_buf[2] = reg;
1076 gspca_dev->usb_buf[3] = val;
1077 gspca_dev->usb_buf[4] = 0;
1078 gspca_dev->usb_buf[5] = 0;
1079 gspca_dev->usb_buf[6] = 0;
1080 gspca_dev->usb_buf[7] = 0x10;
1081 usb_control_msg(gspca_dev->dev,
1082 usb_sndctrlpipe(gspca_dev->dev, 0),
1084 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1085 0x08, /* value = i2c */
1087 gspca_dev->usb_buf, 8,
1091 /* I2C write 8 bytes */
1092 static void i2c_w8(struct gspca_dev *gspca_dev,
1095 memcpy(gspca_dev->usb_buf, buffer, 8);
1096 usb_control_msg(gspca_dev->dev,
1097 usb_sndctrlpipe(gspca_dev->dev, 0),
1099 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1100 0x08, 0, /* value, index */
1101 gspca_dev->usb_buf, 8,
1106 /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
1107 static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
1109 struct sd *sd = (struct sd *) gspca_dev;
1112 switch (sd->sensor) {
1113 case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */
1114 mode[0] = 0x80 | 0x10;
1116 default: /* i2c command = 91 (400 kHz) */
1117 mode[0] = 0x81 | 0x10;
1120 mode[1] = sd->i2c_addr;
1127 i2c_w8(gspca_dev, mode);
1129 mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
1131 i2c_w8(gspca_dev, mode);
1133 reg_r(gspca_dev, 0x0a, 5);
1136 static void i2c_w_seq(struct gspca_dev *gspca_dev,
1137 const u8 (*data)[8])
1139 while ((*data)[0] != 0) {
1140 if ((*data)[0] != 0xdd)
1141 i2c_w8(gspca_dev, *data);
1148 static void hv7131r_probe(struct gspca_dev *gspca_dev)
1150 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
1152 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
1154 i2c_r(gspca_dev, 0, 5); /* read sensor id */
1155 if (gspca_dev->usb_buf[0] == 0x02
1156 && gspca_dev->usb_buf[1] == 0x09
1157 && gspca_dev->usb_buf[2] == 0x01
1158 && gspca_dev->usb_buf[3] == 0x00
1159 && gspca_dev->usb_buf[4] == 0x00) {
1160 PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
1163 PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
1164 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1165 gspca_dev->usb_buf[2]);
1168 static void mi0360_probe(struct gspca_dev *gspca_dev)
1170 struct sd *sd = (struct sd *) gspca_dev;
1173 static const u8 probe_tb[][4][8] = {
1175 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1176 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1177 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1178 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1181 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1182 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1183 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1188 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1189 reg_w1(gspca_dev, 0x17, 0x62);
1190 reg_w1(gspca_dev, 0x01, 0x08);
1191 for (j = 0; j < 3; j++)
1192 i2c_w8(gspca_dev, probe_tb[i][j]);
1194 reg_r(gspca_dev, 0x0a, 5);
1195 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1196 if (probe_tb[i][3][0] != 0)
1197 i2c_w8(gspca_dev, probe_tb[i][3]);
1198 reg_w1(gspca_dev, 0x01, 0x29);
1199 reg_w1(gspca_dev, 0x17, 0x42);
1205 PDEBUG(D_PROBE, "Sensor mt9v111");
1206 sd->sensor = SENSOR_MT9V111;
1209 PDEBUG(D_PROBE, "Sensor mi0360");
1212 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1217 static void ov7648_probe(struct gspca_dev *gspca_dev)
1219 struct sd *sd = (struct sd *) gspca_dev;
1222 reg_w1(gspca_dev, 0x17, 0x62);
1223 reg_w1(gspca_dev, 0x01, 0x08);
1224 sd->i2c_addr = 0x21;
1225 i2c_r(gspca_dev, 0x0a, 2);
1226 if (gspca_dev->usb_buf[3] == 0x76) { /* ov76xx */
1227 PDEBUG(D_PROBE, "Sensor ov%02x%02x",
1228 gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
1233 reg_w1(gspca_dev, 0x01, 0x29);
1234 reg_w1(gspca_dev, 0x17, 0x42);
1237 reg_w1(gspca_dev, 0x17, 0x62);
1238 reg_w1(gspca_dev, 0x01, 0x08);
1239 sd->i2c_addr = 0x6e;
1240 i2c_r(gspca_dev, 0x00, 2);
1241 if (gspca_dev->usb_buf[3] == 0x10 /* po1030 */
1242 && gspca_dev->usb_buf[4] == 0x30) {
1243 PDEBUG(D_PROBE, "Sensor po1030");
1244 sd->sensor = SENSOR_PO1030;
1248 PDEBUG(D_PROBE, "Unknown sensor %02x%02x",
1249 gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
1252 static void bridge_init(struct gspca_dev *gspca_dev,
1255 struct sd *sd = (struct sd *) gspca_dev;
1257 static const u8 reg9a_def[] =
1258 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
1259 static const u8 reg9a_spec[] =
1260 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
1261 static const u8 regd4[] = {0x60, 0x00, 0x00};
1263 reg_w1(gspca_dev, 0xf1, 0x00);
1264 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1266 /* configure gpio */
1267 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
1268 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
1269 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
1270 switch (sd->sensor) {
1273 case SENSOR_SP80708:
1280 reg_w(gspca_dev, 0x9a, reg9a, 6);
1282 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
1284 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
1286 switch (sd->sensor) {
1287 case SENSOR_MT9V111:
1288 reg_w1(gspca_dev, 0x01, 0x61);
1289 reg_w1(gspca_dev, 0x17, 0x61);
1290 reg_w1(gspca_dev, 0x01, 0x60);
1291 reg_w1(gspca_dev, 0x01, 0x40);
1295 reg_w1(gspca_dev, 0x02, 0x73);
1296 reg_w1(gspca_dev, 0x17, 0x60);
1297 reg_w1(gspca_dev, 0x01, 0x22);
1299 reg_w1(gspca_dev, 0x01, 0x62);
1300 reg_w1(gspca_dev, 0x17, 0x64);
1301 reg_w1(gspca_dev, 0x17, 0x64);
1302 reg_w1(gspca_dev, 0x01, 0x42);
1304 reg_w1(gspca_dev, 0x01, 0x42);
1305 i2c_w8(gspca_dev, om6802_init0[0]);
1306 i2c_w8(gspca_dev, om6802_init0[1]);
1308 reg_w1(gspca_dev, 0x02, 0x71);
1312 reg_w1(gspca_dev, 0x01, 0x61);
1313 reg_w1(gspca_dev, 0x17, 0xe2);
1314 reg_w1(gspca_dev, 0x01, 0x60);
1315 reg_w1(gspca_dev, 0x01, 0x40);
1318 reg_w1(gspca_dev, 0x01, 0x63);
1319 reg_w1(gspca_dev, 0x17, 0x20);
1320 reg_w1(gspca_dev, 0x01, 0x62);
1321 reg_w1(gspca_dev, 0x01, 0x42);
1324 reg_w1(gspca_dev, 0x01, 0x61);
1325 reg_w1(gspca_dev, 0x17, 0x20);
1326 reg_w1(gspca_dev, 0x01, 0x60);
1327 reg_w1(gspca_dev, 0x01, 0x40);
1331 case SENSOR_SP80708:
1332 reg_w1(gspca_dev, 0x01, 0x63);
1333 reg_w1(gspca_dev, 0x17, 0x20);
1334 reg_w1(gspca_dev, 0x01, 0x62);
1335 reg_w1(gspca_dev, 0x01, 0x42);
1337 reg_w1(gspca_dev, 0x02, 0x62);
1340 /* case SENSOR_HV7131R: */
1341 /* case SENSOR_MI0360: */
1342 /* case SENSOR_MO4000: */
1343 reg_w1(gspca_dev, 0x01, 0x43);
1344 reg_w1(gspca_dev, 0x17, 0x61);
1345 reg_w1(gspca_dev, 0x01, 0x42);
1346 if (sd->sensor == SENSOR_HV7131R
1347 && sd->bridge == BRIDGE_SN9C102P)
1348 hv7131r_probe(gspca_dev);
1353 /* this function is called at probe time */
1354 static int sd_config(struct gspca_dev *gspca_dev,
1355 const struct usb_device_id *id)
1357 struct sd *sd = (struct sd *) gspca_dev;
1360 cam = &gspca_dev->cam;
1361 cam->cam_mode = vga_mode;
1362 cam->nmodes = ARRAY_SIZE(vga_mode);
1363 cam->npkt = 24; /* 24 packets per ISOC message */
1365 sd->bridge = id->driver_info >> 16;
1366 sd->sensor = id->driver_info;
1368 sd->brightness = BRIGHTNESS_DEF;
1369 sd->contrast = CONTRAST_DEF;
1370 sd->colors = COLOR_DEF;
1371 sd->blue = BLUE_BALANCE_DEF;
1372 sd->red = RED_BALANCE_DEF;
1373 sd->gamma = GAMMA_DEF;
1374 sd->autogain = AUTOGAIN_DEF;
1376 sd->vflip = VFLIP_DEF;
1377 sd->infrared = INFRARED_DEF;
1378 sd->freq = FREQ_DEF;
1379 sd->quality = QUALITY_DEF;
1385 /* this function is called at probe and resume time */
1386 static int sd_init(struct gspca_dev *gspca_dev)
1388 struct sd *sd = (struct sd *) gspca_dev;
1390 u8 regGpio[] = { 0x29, 0x74 };
1393 /* setup a selector by bridge */
1394 reg_w1(gspca_dev, 0xf1, 0x01);
1395 reg_r(gspca_dev, 0x00, 1);
1396 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
1397 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
1398 regF1 = gspca_dev->usb_buf[0];
1399 PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
1400 switch (sd->bridge) {
1401 case BRIDGE_SN9C102P:
1404 reg_w1(gspca_dev, 0x02, regGpio[1]);
1406 case BRIDGE_SN9C105:
1409 if (sd->sensor == SENSOR_MI0360)
1410 mi0360_probe(gspca_dev);
1411 reg_w(gspca_dev, 0x01, regGpio, 2);
1413 case BRIDGE_SN9C120:
1416 switch (sd->sensor) {
1418 mi0360_probe(gspca_dev);
1421 ov7648_probe(gspca_dev);
1425 reg_w(gspca_dev, 0x01, regGpio, 2);
1428 /* case BRIDGE_SN9C110: */
1429 /* case BRIDGE_SN9C325: */
1432 reg_w1(gspca_dev, 0x02, 0x62);
1436 reg_w1(gspca_dev, 0xf1, 0x01);
1438 /* set the i2c address */
1439 sn9c1xx = sn_tb[sd->sensor];
1440 sd->i2c_addr = sn9c1xx[9];
1442 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
1447 static u32 setexposure(struct gspca_dev *gspca_dev,
1450 struct sd *sd = (struct sd *) gspca_dev;
1452 switch (sd->sensor) {
1453 case SENSOR_HV7131R: {
1455 { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
1457 Expodoit[3] = expo >> 16;
1458 Expodoit[4] = expo >> 8;
1460 i2c_w8(gspca_dev, Expodoit);
1463 case SENSOR_MI0360: {
1464 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
1465 { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
1466 static const u8 doit[] = /* update sensor */
1467 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1468 static const u8 sensorgo[] = /* sensor on */
1469 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
1473 else if (expo < 0x0001)
1475 expoMi[3] = expo >> 8;
1477 i2c_w8(gspca_dev, expoMi);
1478 i2c_w8(gspca_dev, doit);
1479 i2c_w8(gspca_dev, sensorgo);
1482 case SENSOR_MO4000: {
1484 { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
1486 { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
1487 static const u8 gainMo[] =
1488 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
1492 else if (expo < 0x0001)
1494 expoMof[3] = (expo & 0x03fc) >> 2;
1495 i2c_w8(gspca_dev, expoMof);
1496 expoMo10[3] = ((expo & 0x1c00) >> 10)
1497 | ((expo & 0x0003) << 4);
1498 i2c_w8(gspca_dev, expoMo10);
1499 i2c_w8(gspca_dev, gainMo);
1500 PDEBUG(D_FRAM, "set exposure %d",
1501 ((expoMo10[3] & 0x07) << 10)
1503 | ((expoMo10[3] & 0x30) >> 4));
1506 case SENSOR_MT9V111: {
1508 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1512 else if (expo < 0x0040)
1514 expo_c1[3] = expo >> 8;
1516 i2c_w8(gspca_dev, expo_c1);
1519 case SENSOR_OM6802: {
1521 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
1522 /* preset AGC - works when AutoExpo = off */
1528 gainOm[3] = expo >> 2;
1529 i2c_w8(gspca_dev, gainOm);
1530 reg_w1(gspca_dev, 0x96, expo >> 5);
1531 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
1538 static void setbrightness(struct gspca_dev *gspca_dev)
1540 struct sd *sd = (struct sd *) gspca_dev;
1544 k2 = ((int) sd->brightness - 0x8000) >> 10;
1545 switch (sd->sensor) {
1546 case SENSOR_HV7131R:
1547 expo = sd->brightness << 4;
1548 if (expo > 0x002dc6c0)
1550 else if (expo < 0x02a0)
1552 sd->exposure = setexposure(gspca_dev, expo);
1556 expo = sd->brightness >> 4;
1557 sd->exposure = setexposure(gspca_dev, expo);
1559 case SENSOR_MT9V111:
1560 expo = sd->brightness >> 8;
1561 sd->exposure = setexposure(gspca_dev, expo);
1562 return; /* don't set the Y offset */
1564 expo = sd->brightness >> 6;
1565 sd->exposure = setexposure(gspca_dev, expo);
1566 k2 = sd->brightness >> 11;
1570 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
1573 static void setcontrast(struct gspca_dev *gspca_dev)
1575 struct sd *sd = (struct sd *) gspca_dev;
1579 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
1580 contrast[0] = (k2 + 1) / 2; /* red */
1582 contrast[2] = k2; /* green */
1584 contrast[4] = (k2 + 1) / 5; /* blue */
1586 reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
1589 static void setcolors(struct gspca_dev *gspca_dev)
1591 struct sd *sd = (struct sd *) gspca_dev;
1593 u8 reg8a[12]; /* U & V gains */
1594 static s16 uv[6] = { /* same as reg84 in signed decimal */
1595 -24, -38, 64, /* UR UG UB */
1596 62, -51, -9 /* VR VG VB */
1599 for (i = 0; i < 6; i++) {
1600 v = uv[i] * sd->colors / COLOR_DEF;
1602 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
1604 reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
1607 static void setredblue(struct gspca_dev *gspca_dev)
1609 struct sd *sd = (struct sd *) gspca_dev;
1611 reg_w1(gspca_dev, 0x05, sd->red);
1612 /* reg_w1(gspca_dev, 0x07, 32); */
1613 reg_w1(gspca_dev, 0x06, sd->blue);
1616 static void setgamma(struct gspca_dev *gspca_dev)
1618 struct sd *sd = (struct sd *) gspca_dev;
1621 const u8 *gamma_base;
1622 static const u8 delta[17] = {
1623 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
1624 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
1627 switch (sd->sensor) {
1628 case SENSOR_HV7131R:
1629 case SENSOR_MT9V111:
1630 gamma_base = gamma_spec_1;
1632 case SENSOR_SP80708:
1633 gamma_base = gamma_spec_2;
1636 gamma_base = gamma_def;
1640 for (i = 0; i < sizeof gamma; i++)
1641 gamma[i] = gamma_base[i]
1642 + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
1643 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
1646 static void setautogain(struct gspca_dev *gspca_dev)
1648 struct sd *sd = (struct sd *) gspca_dev;
1650 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1652 switch (sd->sensor) {
1654 case SENSOR_OV7648: {
1657 if (sd->sensor == SENSOR_OV7630)
1663 i2c_w1(&sd->gspca_dev, 0x13, comb);
1668 sd->ag_cnt = AG_CNT_START;
1673 /* ov7630/ov7648 only */
1674 static void setvflip(struct sd *sd)
1678 if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX))
1680 if (sd->sensor == SENSOR_OV7630) {
1689 i2c_w1(&sd->gspca_dev, 0x75, comn);
1692 static void setinfrared(struct sd *sd)
1694 if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX))
1696 /*fixme: different sequence for StarCam Clip and StarCam 370i */
1698 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
1699 sd->infrared ? 0x66 : 0x64);
1702 static void setfreq(struct gspca_dev *gspca_dev)
1704 struct sd *sd = (struct sd *) gspca_dev;
1706 if (gspca_dev->ctrl_dis & (1 << FREQ_IDX))
1708 if (sd->sensor == SENSOR_OV7660) {
1711 com8 = 0xdf; /* auto gain/wb/expo */
1713 case 0: /* Banding filter disabled */
1714 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
1717 i2c_w1(gspca_dev, 0x13, com8);
1718 i2c_w1(gspca_dev, 0x3b, 0x0a);
1721 i2c_w1(gspca_dev, 0x13, com8);
1722 i2c_w1(gspca_dev, 0x3b, 0x02);
1726 u8 reg2a = 0, reg2b = 0, reg2d = 0;
1728 /* Get reg2a / reg2d base values */
1729 switch (sd->sensor) {
1741 case 0: /* Banding filter disabled */
1743 case 1: /* 50 hz (filter on and framerate adj) */
1748 case 2: /* 60 hz (filter on, no framerate adj) */
1753 i2c_w1(gspca_dev, 0x2a, reg2a);
1754 i2c_w1(gspca_dev, 0x2b, reg2b);
1755 i2c_w1(gspca_dev, 0x2d, reg2d);
1759 static void setjpegqual(struct gspca_dev *gspca_dev)
1761 struct sd *sd = (struct sd *) gspca_dev;
1764 if (sd->jpegqual < 50)
1765 sc = 5000 / sd->jpegqual;
1767 sc = 200 - sd->jpegqual * 2;
1769 #error "No room enough in usb_buf for quantization table"
1771 for (i = 0; i < 64; i++)
1772 gspca_dev->usb_buf[i] =
1773 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
1774 usb_control_msg(gspca_dev->dev,
1775 usb_sndctrlpipe(gspca_dev->dev, 0),
1777 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1779 gspca_dev->usb_buf, 64,
1781 for (i = 0; i < 64; i++)
1782 gspca_dev->usb_buf[i] =
1783 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
1784 usb_control_msg(gspca_dev->dev,
1785 usb_sndctrlpipe(gspca_dev->dev, 0),
1787 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1789 gspca_dev->usb_buf, 64,
1793 reg_w1(gspca_dev, 0x18, sd->reg18);
1796 /* -- start the camera -- */
1797 static int sd_start(struct gspca_dev *gspca_dev)
1799 struct sd *sd = (struct sd *) gspca_dev;
1801 u8 reg1, reg2, reg17;
1803 const u8 (*init)[8];
1805 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1806 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1807 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
1808 static const u8 CE_ov76xx[] =
1809 { 0x32, 0xdd, 0x32, 0xdd };
1811 /* create the JPEG header */
1812 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
1815 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1816 0x21); /* JPEG 422 */
1817 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1819 /* initialize the bridge */
1820 sn9c1xx = sn_tb[sd->sensor];
1821 bridge_init(gspca_dev, sn9c1xx);
1823 /* initialize the sensor */
1824 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
1826 switch (sd->sensor) {
1830 case SENSOR_SP80708:
1837 reg_w1(gspca_dev, 0x02, reg2);
1838 reg_w1(gspca_dev, 0x02, reg2);
1840 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
1841 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
1842 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1843 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1844 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1845 reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
1846 reg_w1(gspca_dev, 0xd3, 0x50);
1847 reg_w1(gspca_dev, 0xc6, 0x00);
1848 reg_w1(gspca_dev, 0xc7, 0x00);
1849 reg_w1(gspca_dev, 0xc8, 0x50);
1850 reg_w1(gspca_dev, 0xc9, 0x3c);
1851 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1852 switch (sd->sensor) {
1853 case SENSOR_MT9V111:
1872 reg_w1(gspca_dev, 0x17, reg17);
1873 /* set reg1 was here */
1874 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1875 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1876 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
1877 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
1879 setgamma(gspca_dev);
1881 for (i = 0; i < 8; i++)
1882 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1883 switch (sd->sensor) {
1884 case SENSOR_MT9V111:
1885 reg_w1(gspca_dev, 0x9a, 0x07);
1886 reg_w1(gspca_dev, 0x99, 0x59);
1889 reg_w1(gspca_dev, 0x9a, 0x08);
1890 reg_w1(gspca_dev, 0x99, 0x10);
1893 reg_w1(gspca_dev, 0x9a, 0x0a);
1894 reg_w1(gspca_dev, 0x99, 0x60);
1897 case SENSOR_SP80708:
1898 reg_w1(gspca_dev, 0x9a, 0x05);
1899 reg_w1(gspca_dev, 0x99, 0x59);
1902 reg_w1(gspca_dev, 0x9a, 0x08);
1903 reg_w1(gspca_dev, 0x99, 0x59);
1907 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1908 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1909 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1910 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
1913 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1915 reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
1917 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
1918 reg17 = 0x61; /* 0x:20: enable sensor clock */
1919 switch (sd->sensor) {
1922 /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
1923 reg1 = 0x06; /* clk 24Mz */
1925 reg17 = 0x22; /* 640 MCKSIZE */
1926 /* reg1 = 0x06; * 640 clk 24Mz (done) */
1929 case SENSOR_MT9V111:
1930 init = mt9v111_sensor_param1;
1932 reg1 = 0x04; /* 320 clk 48Mhz */
1934 /* reg1 = 0x06; * 640 clk 24Mz (done) */
1939 init = om6802_sensor_param1;
1940 reg17 = 0x64; /* 640 MCKSIZE */
1948 init = ov7648_sensor_param1;
1950 /* reg1 = 0x42; * 42 - 46? */
1953 init = ov7660_sensor_param1;
1954 if (sd->bridge == BRIDGE_SN9C120) {
1955 if (mode) { /* 320x240 - 160x120 */
1957 reg1 = 0x44; /* 48 Mhz, video trf eneble */
1961 reg1 = 0x06; /* 24 Mhz, video trf eneble
1962 * inverse power down */
1966 init = po1030_sensor_param1;
1971 /* case SENSOR_SP80708: */
1972 init = sp80708_sensor_param1;
1974 /*?? reg1 = 0x04; * 320 clk 48Mhz */
1976 reg1 = 0x46; /* 640 clk 48Mz */
1982 /* more sensor initialization - param1 */
1984 i2c_w_seq(gspca_dev, init);
1988 reg_w(gspca_dev, 0xc0, C0, 6);
1989 reg_w(gspca_dev, 0xca, CA, 4);
1990 switch (sd->sensor) {
1994 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
1997 reg_w(gspca_dev, 0xce, CE, 4);
1998 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
2003 /* here change size mode 0 -> VGA; 1 -> CIF */
2004 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
2005 reg_w1(gspca_dev, 0x18, sd->reg18);
2006 setjpegqual(gspca_dev);
2008 reg_w1(gspca_dev, 0x17, reg17);
2009 reg_w1(gspca_dev, 0x01, reg1);
2011 switch (sd->sensor) {
2016 setbrightness(gspca_dev);
2017 setcontrast(gspca_dev);
2018 setautogain(gspca_dev);
2023 static void sd_stopN(struct gspca_dev *gspca_dev)
2025 struct sd *sd = (struct sd *) gspca_dev;
2026 static const u8 stophv7131[] =
2027 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
2028 static const u8 stopmi0360[] =
2029 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
2030 static const u8 stopov7648[] =
2031 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
2036 switch (sd->sensor) {
2037 case SENSOR_HV7131R:
2038 i2c_w8(gspca_dev, stophv7131);
2042 i2c_w8(gspca_dev, stopmi0360);
2046 i2c_w8(gspca_dev, stopov7648);
2048 case SENSOR_MT9V111:
2054 sn9c1xx = sn_tb[sd->sensor];
2055 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2056 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
2057 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2058 reg_w1(gspca_dev, 0x01, data);
2059 reg_w1(gspca_dev, 0xf1, 0x00);
2062 static void sd_stop0(struct gspca_dev *gspca_dev)
2064 struct sd *sd = (struct sd *) gspca_dev;
2066 kfree(sd->jpeg_hdr);
2069 static void do_autogain(struct gspca_dev *gspca_dev)
2071 struct sd *sd = (struct sd *) gspca_dev;
2077 /* Thanks S., without your advice, autobright should not work :) */
2080 if (--sd->ag_cnt >= 0)
2082 sd->ag_cnt = AG_CNT_START;
2084 delta = atomic_read(&sd->avg_lum);
2085 PDEBUG(D_FRAM, "mean lum %d", delta);
2086 if (delta < luma_mean - luma_delta ||
2087 delta > luma_mean + luma_delta) {
2088 switch (sd->sensor) {
2089 case SENSOR_HV7131R:
2090 expotimes = sd->exposure >> 8;
2091 expotimes += (luma_mean - delta) >> 4;
2094 sd->exposure = setexposure(gspca_dev,
2095 (unsigned int) (expotimes << 8));
2098 expotimes = sd->exposure;
2099 expotimes += (luma_mean - delta) >> 2;
2102 sd->exposure = setexposure(gspca_dev,
2103 (unsigned int) expotimes);
2104 setredblue(gspca_dev);
2107 /* case SENSOR_MO4000: */
2108 /* case SENSOR_MI0360: */
2109 /* case SENSOR_MT9V111: */
2110 expotimes = sd->exposure;
2111 expotimes += (luma_mean - delta) >> 6;
2114 sd->exposure = setexposure(gspca_dev,
2115 (unsigned int) expotimes);
2116 setredblue(gspca_dev);
2122 /* scan the URB packets */
2123 /* This function is run at interrupt level. */
2124 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2125 u8 *data, /* isoc packet */
2126 int len) /* iso packet length */
2128 struct sd *sd = (struct sd *) gspca_dev;
2132 if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
2135 gspca_frame_add(gspca_dev, LAST_PACKET,
2143 avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
2145 avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
2147 avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
2149 avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
2151 avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
2153 atomic_set(&sd->avg_lum, avg_lum);
2156 if (gspca_dev->last_packet_type == LAST_PACKET) {
2158 /* put the JPEG 422 header */
2159 gspca_frame_add(gspca_dev, FIRST_PACKET,
2160 sd->jpeg_hdr, JPEG_HDR_SZ);
2162 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
2165 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2167 struct sd *sd = (struct sd *) gspca_dev;
2169 sd->brightness = val;
2170 if (gspca_dev->streaming)
2171 setbrightness(gspca_dev);
2175 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2177 struct sd *sd = (struct sd *) gspca_dev;
2179 *val = sd->brightness;
2183 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2185 struct sd *sd = (struct sd *) gspca_dev;
2188 if (gspca_dev->streaming)
2189 setcontrast(gspca_dev);
2193 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2195 struct sd *sd = (struct sd *) gspca_dev;
2197 *val = sd->contrast;
2201 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2203 struct sd *sd = (struct sd *) gspca_dev;
2206 if (gspca_dev->streaming)
2207 setcolors(gspca_dev);
2211 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2213 struct sd *sd = (struct sd *) gspca_dev;
2219 static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
2221 struct sd *sd = (struct sd *) gspca_dev;
2224 if (gspca_dev->streaming)
2225 setredblue(gspca_dev);
2229 static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
2231 struct sd *sd = (struct sd *) gspca_dev;
2237 static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
2239 struct sd *sd = (struct sd *) gspca_dev;
2242 if (gspca_dev->streaming)
2243 setredblue(gspca_dev);
2247 static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
2249 struct sd *sd = (struct sd *) gspca_dev;
2255 static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2257 struct sd *sd = (struct sd *) gspca_dev;
2260 if (gspca_dev->streaming)
2261 setgamma(gspca_dev);
2265 static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2267 struct sd *sd = (struct sd *) gspca_dev;
2273 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2275 struct sd *sd = (struct sd *) gspca_dev;
2278 if (gspca_dev->streaming)
2279 setautogain(gspca_dev);
2283 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2285 struct sd *sd = (struct sd *) gspca_dev;
2287 *val = sd->autogain;
2291 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2293 struct sd *sd = (struct sd *) gspca_dev;
2296 if (gspca_dev->streaming)
2301 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2303 struct sd *sd = (struct sd *) gspca_dev;
2309 static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
2311 struct sd *sd = (struct sd *) gspca_dev;
2314 if (gspca_dev->streaming)
2319 static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
2321 struct sd *sd = (struct sd *) gspca_dev;
2323 *val = sd->infrared;
2327 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2329 struct sd *sd = (struct sd *) gspca_dev;
2332 if (gspca_dev->streaming)
2337 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2339 struct sd *sd = (struct sd *) gspca_dev;
2345 static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2346 struct v4l2_jpegcompression *jcomp)
2348 struct sd *sd = (struct sd *) gspca_dev;
2350 if (jcomp->quality < QUALITY_MIN)
2351 sd->quality = QUALITY_MIN;
2352 else if (jcomp->quality > QUALITY_MAX)
2353 sd->quality = QUALITY_MAX;
2355 sd->quality = jcomp->quality;
2356 if (gspca_dev->streaming)
2357 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2361 static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2362 struct v4l2_jpegcompression *jcomp)
2364 struct sd *sd = (struct sd *) gspca_dev;
2366 memset(jcomp, 0, sizeof *jcomp);
2367 jcomp->quality = sd->quality;
2368 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2369 | V4L2_JPEG_MARKER_DQT;
2373 static int sd_querymenu(struct gspca_dev *gspca_dev,
2374 struct v4l2_querymenu *menu)
2377 case V4L2_CID_POWER_LINE_FREQUENCY:
2378 switch (menu->index) {
2379 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2380 strcpy((char *) menu->name, "NoFliker");
2382 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2383 strcpy((char *) menu->name, "50 Hz");
2385 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2386 strcpy((char *) menu->name, "60 Hz");
2394 /* sub-driver description */
2395 static const struct sd_desc sd_desc = {
2396 .name = MODULE_NAME,
2398 .nctrls = ARRAY_SIZE(sd_ctrls),
2399 .config = sd_config,
2404 .pkt_scan = sd_pkt_scan,
2405 .dq_callback = do_autogain,
2406 .get_jcomp = sd_get_jcomp,
2407 .set_jcomp = sd_set_jcomp,
2408 .querymenu = sd_querymenu,
2411 /* -- module initialisation -- */
2412 #define BS(bridge, sensor) \
2413 .driver_info = (BRIDGE_ ## bridge << 16) \
2415 static const __devinitdata struct usb_device_id device_table[] = {
2416 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2417 {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
2418 {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
2420 {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)},
2421 {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)},
2422 {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
2423 {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
2424 {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
2425 {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
2426 {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
2427 /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
2428 {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
2429 /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
2430 /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
2431 {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
2432 /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
2433 {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
2434 /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
2435 /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
2436 /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
2437 {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
2438 /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
2439 /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
2440 {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
2441 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2442 {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
2443 {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
2445 {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
2446 /* {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, P1030xC)}, */
2447 /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
2448 {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
2449 {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
2450 {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
2451 {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
2452 /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
2453 /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
2454 /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
2455 {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
2457 {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
2458 {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
2459 {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
2460 /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
2461 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2462 {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
2464 /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
2465 {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
2466 {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
2467 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2468 {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
2470 {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
2471 {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
2472 /* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/
2473 {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
2474 {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
2477 MODULE_DEVICE_TABLE(usb, device_table);
2479 /* -- device connect -- */
2480 static int sd_probe(struct usb_interface *intf,
2481 const struct usb_device_id *id)
2483 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2487 static struct usb_driver sd_driver = {
2488 .name = MODULE_NAME,
2489 .id_table = device_table,
2491 .disconnect = gspca_disconnect,
2493 .suspend = gspca_suspend,
2494 .resume = gspca_resume,
2498 /* -- module insert / remove -- */
2499 static int __init sd_mod_init(void)
2502 ret = usb_register(&sd_driver);
2508 static void __exit sd_mod_exit(void)
2510 usb_deregister(&sd_driver);
2511 info("deregistered");
2514 module_init(sd_mod_init);
2515 module_exit(sd_mod_exit);