4 * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
6 * This module is adapted from the ov51x-jpeg package, which itself
7 * was adapted from the ov511 driver.
9 * Original copyright for the ov511 driver is:
11 * Copyright (c) 1999-2004 Mark W. McClelland
12 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
14 * ov51x-jpeg original copyright is:
16 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
17 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define MODULE_NAME "ov519"
38 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
39 MODULE_DESCRIPTION("OV519 USB Camera Driver");
40 MODULE_LICENSE("GPL");
42 /* global parameters */
43 static int frame_rate;
45 /* Number of times to retry a failed I2C transaction. Increase this if you
46 * are getting "Failed to read sensor ID..." */
47 static int i2c_detect_tries = 10;
49 /* ov519 device descriptor */
51 struct gspca_dev gspca_dev; /* !! must be the first item */
56 #define BRIDGE_OV511 0
57 #define BRIDGE_OV511PLUS 1
58 #define BRIDGE_OV518 2
59 #define BRIDGE_OV518PLUS 3
60 #define BRIDGE_OV519 4
64 #define BRIDGE_INVERT_LED 8
66 /* Determined by sensor type */
77 __u8 stopped; /* Streaming is temporarily paused */
79 __u8 frame_rate; /* current Framerate */
80 __u8 clockdiv; /* clockdiv override */
82 char sensor; /* Type of image sensor chip (SEN_*) */
86 #define SEN_OV66308AF 3
95 /* V4L2 controls supported by the driver */
96 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
97 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
98 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
99 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
100 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
101 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
102 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
103 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
104 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
105 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
106 static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val);
107 static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val);
108 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
109 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
110 static void setbrightness(struct gspca_dev *gspca_dev);
111 static void setcontrast(struct gspca_dev *gspca_dev);
112 static void setcolors(struct gspca_dev *gspca_dev);
113 static void setautobrightness(struct sd *sd);
114 static void setfreq(struct sd *sd);
116 static const struct ctrl sd_ctrls[] = {
119 .id = V4L2_CID_BRIGHTNESS,
120 .type = V4L2_CTRL_TYPE_INTEGER,
121 .name = "Brightness",
125 #define BRIGHTNESS_DEF 127
126 .default_value = BRIGHTNESS_DEF,
128 .set = sd_setbrightness,
129 .get = sd_getbrightness,
133 .id = V4L2_CID_CONTRAST,
134 .type = V4L2_CTRL_TYPE_INTEGER,
139 #define CONTRAST_DEF 127
140 .default_value = CONTRAST_DEF,
142 .set = sd_setcontrast,
143 .get = sd_getcontrast,
147 .id = V4L2_CID_SATURATION,
148 .type = V4L2_CTRL_TYPE_INTEGER,
153 #define COLOR_DEF 127
154 .default_value = COLOR_DEF,
159 /* The flip controls work with ov7670 only */
163 .id = V4L2_CID_HFLIP,
164 .type = V4L2_CTRL_TYPE_BOOLEAN,
170 .default_value = HFLIP_DEF,
178 .id = V4L2_CID_VFLIP,
179 .type = V4L2_CTRL_TYPE_BOOLEAN,
185 .default_value = VFLIP_DEF,
190 #define AUTOBRIGHT_IDX 5
193 .id = V4L2_CID_AUTOBRIGHTNESS,
194 .type = V4L2_CTRL_TYPE_BOOLEAN,
195 .name = "Auto Brightness",
199 #define AUTOBRIGHT_DEF 1
200 .default_value = AUTOBRIGHT_DEF,
202 .set = sd_setautobrightness,
203 .get = sd_getautobrightness,
208 .id = V4L2_CID_POWER_LINE_FREQUENCY,
209 .type = V4L2_CTRL_TYPE_MENU,
210 .name = "Light frequency filter",
212 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
215 .default_value = FREQ_DEF,
220 #define OV7670_FREQ_IDX 7
223 .id = V4L2_CID_POWER_LINE_FREQUENCY,
224 .type = V4L2_CTRL_TYPE_MENU,
225 .name = "Light frequency filter",
227 .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
229 #define OV7670_FREQ_DEF 3
230 .default_value = OV7670_FREQ_DEF,
237 static const struct v4l2_pix_format ov519_vga_mode[] = {
238 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
240 .sizeimage = 320 * 240 * 3 / 8 + 590,
241 .colorspace = V4L2_COLORSPACE_JPEG,
243 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
245 .sizeimage = 640 * 480 * 3 / 8 + 590,
246 .colorspace = V4L2_COLORSPACE_JPEG,
249 static const struct v4l2_pix_format ov519_sif_mode[] = {
250 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
252 .sizeimage = 160 * 120 * 3 / 8 + 590,
253 .colorspace = V4L2_COLORSPACE_JPEG,
255 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
257 .sizeimage = 176 * 144 * 3 / 8 + 590,
258 .colorspace = V4L2_COLORSPACE_JPEG,
260 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
262 .sizeimage = 320 * 240 * 3 / 8 + 590,
263 .colorspace = V4L2_COLORSPACE_JPEG,
265 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
267 .sizeimage = 352 * 288 * 3 / 8 + 590,
268 .colorspace = V4L2_COLORSPACE_JPEG,
272 /* Note some of the sizeimage values for the ov511 / ov518 may seem
273 larger then necessary, however they need to be this big as the ov511 /
274 ov518 always fills the entire isoc frame, using 0 padding bytes when
275 it doesn't have any data. So with low framerates the amount of data
276 transfered can become quite large (libv4l will remove all the 0 padding
278 static const struct v4l2_pix_format ov518_vga_mode[] = {
279 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
281 .sizeimage = 320 * 240 * 3,
282 .colorspace = V4L2_COLORSPACE_JPEG,
284 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
286 .sizeimage = 640 * 480 * 2,
287 .colorspace = V4L2_COLORSPACE_JPEG,
290 static const struct v4l2_pix_format ov518_sif_mode[] = {
291 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
294 .colorspace = V4L2_COLORSPACE_JPEG,
296 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
299 .colorspace = V4L2_COLORSPACE_JPEG,
301 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
303 .sizeimage = 320 * 240 * 3,
304 .colorspace = V4L2_COLORSPACE_JPEG,
306 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
308 .sizeimage = 352 * 288 * 3,
309 .colorspace = V4L2_COLORSPACE_JPEG,
313 static const struct v4l2_pix_format ov511_vga_mode[] = {
314 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
316 .sizeimage = 320 * 240 * 3,
317 .colorspace = V4L2_COLORSPACE_JPEG,
319 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
321 .sizeimage = 640 * 480 * 2,
322 .colorspace = V4L2_COLORSPACE_JPEG,
325 static const struct v4l2_pix_format ov511_sif_mode[] = {
326 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
329 .colorspace = V4L2_COLORSPACE_JPEG,
331 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
334 .colorspace = V4L2_COLORSPACE_JPEG,
336 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
338 .sizeimage = 320 * 240 * 3,
339 .colorspace = V4L2_COLORSPACE_JPEG,
341 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
343 .sizeimage = 352 * 288 * 3,
344 .colorspace = V4L2_COLORSPACE_JPEG,
348 /* Registers common to OV511 / OV518 */
349 #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
350 #define R51x_SYS_RESET 0x50
351 /* Reset type flags */
352 #define OV511_RESET_OMNICE 0x08
353 #define R51x_SYS_INIT 0x53
354 #define R51x_SYS_SNAP 0x52
355 #define R51x_SYS_CUST_ID 0x5F
356 #define R51x_COMP_LUT_BEGIN 0x80
358 /* OV511 Camera interface register numbers */
359 #define R511_CAM_DELAY 0x10
360 #define R511_CAM_EDGE 0x11
361 #define R511_CAM_PXCNT 0x12
362 #define R511_CAM_LNCNT 0x13
363 #define R511_CAM_PXDIV 0x14
364 #define R511_CAM_LNDIV 0x15
365 #define R511_CAM_UV_EN 0x16
366 #define R511_CAM_LINE_MODE 0x17
367 #define R511_CAM_OPTS 0x18
369 #define R511_SNAP_FRAME 0x19
370 #define R511_SNAP_PXCNT 0x1A
371 #define R511_SNAP_LNCNT 0x1B
372 #define R511_SNAP_PXDIV 0x1C
373 #define R511_SNAP_LNDIV 0x1D
374 #define R511_SNAP_UV_EN 0x1E
375 #define R511_SNAP_UV_EN 0x1E
376 #define R511_SNAP_OPTS 0x1F
378 #define R511_DRAM_FLOW_CTL 0x20
379 #define R511_FIFO_OPTS 0x31
380 #define R511_I2C_CTL 0x40
381 #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
382 #define R511_COMP_EN 0x78
383 #define R511_COMP_LUT_EN 0x79
385 /* OV518 Camera interface register numbers */
386 #define R518_GPIO_OUT 0x56 /* OV518(+) only */
387 #define R518_GPIO_CTL 0x57 /* OV518(+) only */
389 /* OV519 Camera interface register numbers */
390 #define OV519_R10_H_SIZE 0x10
391 #define OV519_R11_V_SIZE 0x11
392 #define OV519_R12_X_OFFSETL 0x12
393 #define OV519_R13_X_OFFSETH 0x13
394 #define OV519_R14_Y_OFFSETL 0x14
395 #define OV519_R15_Y_OFFSETH 0x15
396 #define OV519_R16_DIVIDER 0x16
397 #define OV519_R20_DFR 0x20
398 #define OV519_R25_FORMAT 0x25
400 /* OV519 System Controller register numbers */
401 #define OV519_SYS_RESET1 0x51
402 #define OV519_SYS_EN_CLK1 0x54
404 #define OV519_GPIO_DATA_OUT0 0x71
405 #define OV519_GPIO_IO_CTRL0 0x72
407 #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
410 #define R51x_I2C_W_SID 0x41
411 #define R51x_I2C_SADDR_3 0x42
412 #define R51x_I2C_SADDR_2 0x43
413 #define R51x_I2C_R_SID 0x44
414 #define R51x_I2C_DATA 0x45
415 #define R518_I2C_CTL 0x47 /* OV518(+) only */
418 #define OV7xx0_SID 0x42
419 #define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
420 #define OV8xx0_SID 0xa0
421 #define OV6xx0_SID 0xc0
423 /* OV7610 registers */
424 #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
425 #define OV7610_REG_BLUE 0x01 /* blue channel balance */
426 #define OV7610_REG_RED 0x02 /* red channel balance */
427 #define OV7610_REG_SAT 0x03 /* saturation */
428 #define OV8610_REG_HUE 0x04 /* 04 reserved */
429 #define OV7610_REG_CNT 0x05 /* Y contrast */
430 #define OV7610_REG_BRT 0x06 /* Y brightness */
431 #define OV7610_REG_COM_C 0x14 /* misc common regs */
432 #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
433 #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
434 #define OV7610_REG_COM_I 0x29 /* misc settings */
436 /* OV7670 registers */
437 #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
438 #define OV7670_REG_BLUE 0x01 /* blue gain */
439 #define OV7670_REG_RED 0x02 /* red gain */
440 #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
441 #define OV7670_REG_COM1 0x04 /* Control 1 */
442 #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
443 #define OV7670_REG_COM3 0x0c /* Control 3 */
444 #define OV7670_REG_COM4 0x0d /* Control 4 */
445 #define OV7670_REG_COM5 0x0e /* All "reserved" */
446 #define OV7670_REG_COM6 0x0f /* Control 6 */
447 #define OV7670_REG_AECH 0x10 /* More bits of AEC value */
448 #define OV7670_REG_CLKRC 0x11 /* Clock control */
449 #define OV7670_REG_COM7 0x12 /* Control 7 */
450 #define OV7670_COM7_FMT_VGA 0x00
451 #define OV7670_COM7_YUV 0x00 /* YUV */
452 #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
453 #define OV7670_COM7_FMT_MASK 0x38
454 #define OV7670_COM7_RESET 0x80 /* Register reset */
455 #define OV7670_REG_COM8 0x13 /* Control 8 */
456 #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
457 #define OV7670_COM8_AWB 0x02 /* White balance enable */
458 #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
459 #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
460 #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
461 #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
462 #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
463 #define OV7670_REG_COM10 0x15 /* Control 10 */
464 #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
465 #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
466 #define OV7670_REG_VSTART 0x19 /* Vert start high bits */
467 #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
468 #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
469 #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
470 #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
471 #define OV7670_REG_AEW 0x24 /* AGC upper limit */
472 #define OV7670_REG_AEB 0x25 /* AGC lower limit */
473 #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
474 #define OV7670_REG_HREF 0x32 /* HREF pieces */
475 #define OV7670_REG_TSLB 0x3a /* lots of stuff */
476 #define OV7670_REG_COM11 0x3b /* Control 11 */
477 #define OV7670_COM11_EXP 0x02
478 #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
479 #define OV7670_REG_COM12 0x3c /* Control 12 */
480 #define OV7670_REG_COM13 0x3d /* Control 13 */
481 #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
482 #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
483 #define OV7670_REG_COM14 0x3e /* Control 14 */
484 #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
485 #define OV7670_REG_COM15 0x40 /* Control 15 */
486 #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
487 #define OV7670_REG_COM16 0x41 /* Control 16 */
488 #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
489 #define OV7670_REG_BRIGHT 0x55 /* Brightness */
490 #define OV7670_REG_CONTRAS 0x56 /* Contrast control */
491 #define OV7670_REG_GFIX 0x69 /* Fix gain control */
492 #define OV7670_REG_RGB444 0x8c /* RGB 444 control */
493 #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
494 #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
495 #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
496 #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
497 #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
498 #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
499 #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
500 #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
501 #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
507 struct ov_i2c_regvals {
512 static const struct ov_i2c_regvals norm_6x20[] = {
513 { 0x12, 0x80 }, /* reset */
516 { 0x05, 0x7f }, /* For when autoadjust is off */
518 /* The ratio of 0x0c and 0x0d controls the white point */
521 { 0x0f, 0x15 }, /* COMS */
522 { 0x10, 0x75 }, /* AEC Exposure time */
523 { 0x12, 0x24 }, /* Enable AGC */
525 /* 0x16: 0x06 helps frame stability with moving objects */
527 /* { 0x20, 0x30 }, * Aperture correction enable */
528 { 0x26, 0xb2 }, /* BLC enable */
529 /* 0x28: 0x05 Selects RGB format if RGB on */
531 { 0x2a, 0x04 }, /* Disable framerate adjust */
532 /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
534 { 0x33, 0xa0 }, /* Color Processing Parameter */
535 { 0x34, 0xd2 }, /* Max A/D range */
539 { 0x3c, 0x39 }, /* Enable AEC mode changing */
540 { 0x3c, 0x3c }, /* Change AEC mode */
541 { 0x3c, 0x24 }, /* Disable AEC mode changing */
544 /* These next two registers (0x4a, 0x4b) are undocumented.
545 * They control the color balance */
548 { 0x4d, 0xd2 }, /* This reduces noise a bit */
551 /* Do 50-53 have any effect? */
552 /* Toggle 0x12[2] off and on here? */
555 static const struct ov_i2c_regvals norm_6x30[] = {
556 { 0x12, 0x80 }, /* Reset */
557 { 0x00, 0x1f }, /* Gain */
558 { 0x01, 0x99 }, /* Blue gain */
559 { 0x02, 0x7c }, /* Red gain */
560 { 0x03, 0xc0 }, /* Saturation */
561 { 0x05, 0x0a }, /* Contrast */
562 { 0x06, 0x95 }, /* Brightness */
563 { 0x07, 0x2d }, /* Sharpness */
566 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
569 { 0x11, 0x00 }, /* Pixel clock = fastest */
570 { 0x12, 0x24 }, /* Enable AGC and AWB */
585 { 0x23, 0xc0 }, /* Crystal circuit power level */
586 { 0x25, 0x9a }, /* Increase AEC black ratio */
587 { 0x26, 0xb2 }, /* BLC enable */
591 { 0x2a, 0x84 }, /* 60 Hz power */
592 { 0x2b, 0xa8 }, /* 60 Hz power */
594 { 0x2d, 0x95 }, /* Enable auto-brightness */
608 { 0x40, 0x00 }, /* White bal */
609 { 0x41, 0x00 }, /* White bal */
611 { 0x43, 0x3f }, /* White bal */
621 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
623 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
625 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
630 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
632 { 0x5b, 0x0f }, /* AWB chrominance levels */
636 { 0x12, 0x20 }, /* Toggle AWB */
640 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
642 * Register 0x0f in the 7610 has the following effects:
644 * 0x85 (AEC method 1): Best overall, good contrast range
645 * 0x45 (AEC method 2): Very overexposed
646 * 0xa5 (spec sheet default): Ok, but the black level is
647 * shifted resulting in loss of contrast
648 * 0x05 (old driver setting): very overexposed, too much
651 static const struct ov_i2c_regvals norm_7610[] = {
658 { 0x28, 0x24 }, /* 0c */
659 { 0x0f, 0x85 }, /* lg's setting */
681 static const struct ov_i2c_regvals norm_7620[] = {
682 { 0x00, 0x00 }, /* gain */
683 { 0x01, 0x80 }, /* blue gain */
684 { 0x02, 0x80 }, /* red gain */
685 { 0x03, 0xc0 }, /* OV7670_REG_VREF */
708 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
747 /* 7640 and 7648. The defaults should be OK for most registers. */
748 static const struct ov_i2c_regvals norm_7640[] = {
753 /* 7670. Defaults taken from OmniVision provided data,
754 * as provided by Jonathan Corbet of OLPC */
755 static const struct ov_i2c_regvals norm_7670[] = {
756 { OV7670_REG_COM7, OV7670_COM7_RESET },
757 { OV7670_REG_TSLB, 0x04 }, /* OV */
758 { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
759 { OV7670_REG_CLKRC, 0x01 },
761 * Set the hardware window. These values from OV don't entirely
762 * make sense - hstop is less than hstart. But they work...
764 { OV7670_REG_HSTART, 0x13 },
765 { OV7670_REG_HSTOP, 0x01 },
766 { OV7670_REG_HREF, 0xb6 },
767 { OV7670_REG_VSTART, 0x02 },
768 { OV7670_REG_VSTOP, 0x7a },
769 { OV7670_REG_VREF, 0x0a },
771 { OV7670_REG_COM3, 0x00 },
772 { OV7670_REG_COM14, 0x00 },
773 /* Mystery scaling numbers */
779 /* { OV7670_REG_COM10, 0x0 }, */
781 /* Gamma curve values */
799 /* AGC and AEC parameters. Note we start by disabling those features,
800 then turn them only after tweaking the values. */
801 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
802 | OV7670_COM8_AECSTEP
803 | OV7670_COM8_BFILT },
804 { OV7670_REG_GAIN, 0x00 },
805 { OV7670_REG_AECH, 0x00 },
806 { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
807 { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
808 { OV7670_REG_BD50MAX, 0x05 },
809 { OV7670_REG_BD60MAX, 0x07 },
810 { OV7670_REG_AEW, 0x95 },
811 { OV7670_REG_AEB, 0x33 },
812 { OV7670_REG_VPT, 0xe3 },
813 { OV7670_REG_HAECC1, 0x78 },
814 { OV7670_REG_HAECC2, 0x68 },
815 { 0xa1, 0x03 }, /* magic */
816 { OV7670_REG_HAECC3, 0xd8 },
817 { OV7670_REG_HAECC4, 0xd8 },
818 { OV7670_REG_HAECC5, 0xf0 },
819 { OV7670_REG_HAECC6, 0x90 },
820 { OV7670_REG_HAECC7, 0x94 },
821 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
822 | OV7670_COM8_AECSTEP
827 /* Almost all of these are magic "reserved" values. */
828 { OV7670_REG_COM5, 0x61 },
829 { OV7670_REG_COM6, 0x4b },
831 { OV7670_REG_MVFP, 0x07 },
840 { OV7670_REG_COM12, 0x78 },
843 { OV7670_REG_GFIX, 0x00 },
859 /* More reserved magic, some of which tweaks white balance */
876 /* "9e for advance AWB" */
878 { OV7670_REG_BLUE, 0x40 },
879 { OV7670_REG_RED, 0x60 },
880 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
881 | OV7670_COM8_AECSTEP
887 /* Matrix coefficients */
896 { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
897 { OV7670_REG_EDGE, 0x00 },
902 { OV7670_REG_COM13, OV7670_COM13_GAMMA
907 { OV7670_REG_COM16, 0x38 },
911 { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
924 /* Extra-weird stuff. Some sort of multiplexor register */
950 static const struct ov_i2c_regvals norm_8610[] = {
957 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
958 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
967 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
969 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
970 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
971 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
974 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
975 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
976 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
977 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
983 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
985 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
987 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
989 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
990 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
991 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
992 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
994 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
995 * maybe thats wrong */
999 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1003 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1004 * deleting bit7 colors the first images red */
1005 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1006 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1012 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1014 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1019 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1021 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1022 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1029 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1035 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1038 static unsigned char ov7670_abs_to_sm(unsigned char v)
1042 return (128 - v) | 0x80;
1045 /* Write a OV519 register */
1046 static int reg_w(struct sd *sd, __u16 index, __u8 value)
1049 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 2 : 1;
1051 sd->gspca_dev.usb_buf[0] = value;
1052 ret = usb_control_msg(sd->gspca_dev.dev,
1053 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1055 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1057 sd->gspca_dev.usb_buf, 1, 500);
1059 PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
1063 /* Read from a OV519 register */
1064 /* returns: negative is error, pos or zero is data */
1065 static int reg_r(struct sd *sd, __u16 index)
1068 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 3 : 1;
1070 ret = usb_control_msg(sd->gspca_dev.dev,
1071 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1073 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1074 0, index, sd->gspca_dev.usb_buf, 1, 500);
1077 ret = sd->gspca_dev.usb_buf[0];
1079 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
1083 /* Read 8 values from a OV519 register */
1084 static int reg_r8(struct sd *sd,
1089 ret = usb_control_msg(sd->gspca_dev.dev,
1090 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1092 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1093 0, index, sd->gspca_dev.usb_buf, 8, 500);
1096 ret = sd->gspca_dev.usb_buf[0];
1098 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
1103 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1104 * the same position as 1's in "mask" are cleared and set to "value". Bits
1105 * that are in the same position as 0's in "mask" are preserved, regardless
1106 * of their respective state in "value".
1108 static int reg_w_mask(struct sd *sd,
1117 value &= mask; /* Enforce mask on value */
1118 ret = reg_r(sd, index);
1122 oldval = ret & ~mask; /* Clear the masked bits */
1123 value |= oldval; /* Set the desired bits */
1125 return reg_w(sd, index, value);
1129 * Writes multiple (n) byte value to a single register. Only valid with certain
1130 * registers (0x30 and 0xc4 - 0xce).
1132 static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
1136 *((u32 *)sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
1138 ret = usb_control_msg(sd->gspca_dev.dev,
1139 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1141 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1143 sd->gspca_dev.usb_buf, n, 500);
1145 PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value);
1149 static int ov511_i2c_w(struct sd *sd, __u8 reg, __u8 value)
1153 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
1155 /* Three byte write cycle */
1156 for (retries = 6; ; ) {
1157 /* Select camera register */
1158 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
1162 /* Write "value" to I2C data port of OV511 */
1163 rc = reg_w(sd, R51x_I2C_DATA, value);
1167 /* Initiate 3-byte write cycle */
1168 rc = reg_w(sd, R511_I2C_CTL, 0x01);
1173 rc = reg_r(sd, R511_I2C_CTL);
1174 while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1179 if ((rc & 2) == 0) /* Ack? */
1181 if (--retries < 0) {
1182 PDEBUG(D_USBO, "i2c write retries exhausted");
1190 static int ov511_i2c_r(struct sd *sd, __u8 reg)
1192 int rc, value, retries;
1194 /* Two byte write cycle */
1195 for (retries = 6; ; ) {
1196 /* Select camera register */
1197 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
1201 /* Initiate 2-byte write cycle */
1202 rc = reg_w(sd, R511_I2C_CTL, 0x03);
1207 rc = reg_r(sd, R511_I2C_CTL);
1208 while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1213 if ((rc & 2) == 0) /* Ack? */
1217 reg_w(sd, R511_I2C_CTL, 0x10);
1219 if (--retries < 0) {
1220 PDEBUG(D_USBI, "i2c write retries exhausted");
1225 /* Two byte read cycle */
1226 for (retries = 6; ; ) {
1227 /* Initiate 2-byte read cycle */
1228 rc = reg_w(sd, R511_I2C_CTL, 0x05);
1233 rc = reg_r(sd, R511_I2C_CTL);
1234 while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1239 if ((rc & 2) == 0) /* Ack? */
1243 rc = reg_w(sd, R511_I2C_CTL, 0x10);
1247 if (--retries < 0) {
1248 PDEBUG(D_USBI, "i2c read retries exhausted");
1253 value = reg_r(sd, R51x_I2C_DATA);
1255 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
1257 /* This is needed to make i2c_w() work */
1258 rc = reg_w(sd, R511_I2C_CTL, 0x05);
1266 * The OV518 I2C I/O procedure is different, hence, this function.
1267 * This is normally only called from i2c_w(). Note that this function
1268 * always succeeds regardless of whether the sensor is present and working.
1270 static int ov518_i2c_w(struct sd *sd,
1276 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
1278 /* Select camera register */
1279 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
1283 /* Write "value" to I2C data port of OV511 */
1284 rc = reg_w(sd, R51x_I2C_DATA, value);
1288 /* Initiate 3-byte write cycle */
1289 rc = reg_w(sd, R518_I2C_CTL, 0x01);
1293 /* wait for write complete */
1295 return reg_r8(sd, R518_I2C_CTL);
1299 * returns: negative is error, pos or zero is data
1301 * The OV518 I2C I/O procedure is different, hence, this function.
1302 * This is normally only called from i2c_r(). Note that this function
1303 * always succeeds regardless of whether the sensor is present and working.
1305 static int ov518_i2c_r(struct sd *sd, __u8 reg)
1309 /* Select camera register */
1310 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
1314 /* Initiate 2-byte write cycle */
1315 rc = reg_w(sd, R518_I2C_CTL, 0x03);
1319 /* Initiate 2-byte read cycle */
1320 rc = reg_w(sd, R518_I2C_CTL, 0x05);
1323 value = reg_r(sd, R51x_I2C_DATA);
1324 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
1328 static int i2c_w(struct sd *sd, __u8 reg, __u8 value)
1330 switch (sd->bridge) {
1332 case BRIDGE_OV511PLUS:
1333 return ov511_i2c_w(sd, reg, value);
1335 case BRIDGE_OV518PLUS:
1337 return ov518_i2c_w(sd, reg, value);
1339 return -1; /* Should never happen */
1342 static int i2c_r(struct sd *sd, __u8 reg)
1344 switch (sd->bridge) {
1346 case BRIDGE_OV511PLUS:
1347 return ov511_i2c_r(sd, reg);
1349 case BRIDGE_OV518PLUS:
1351 return ov518_i2c_r(sd, reg);
1353 return -1; /* Should never happen */
1356 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
1357 * the same position as 1's in "mask" are cleared and set to "value". Bits
1358 * that are in the same position as 0's in "mask" are preserved, regardless
1359 * of their respective state in "value".
1361 static int i2c_w_mask(struct sd *sd,
1369 value &= mask; /* Enforce mask on value */
1370 rc = i2c_r(sd, reg);
1373 oldval = rc & ~mask; /* Clear the masked bits */
1374 value |= oldval; /* Set the desired bits */
1375 return i2c_w(sd, reg, value);
1378 /* Temporarily stops OV511 from functioning. Must do this before changing
1379 * registers while the camera is streaming */
1380 static inline int ov51x_stop(struct sd *sd)
1382 PDEBUG(D_STREAM, "stopping");
1384 switch (sd->bridge) {
1386 case BRIDGE_OV511PLUS:
1387 return reg_w(sd, R51x_SYS_RESET, 0x3d);
1389 case BRIDGE_OV518PLUS:
1390 return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
1392 return reg_w(sd, OV519_SYS_RESET1, 0x0f);
1398 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1399 * actually stopped (for performance). */
1400 static inline int ov51x_restart(struct sd *sd)
1404 PDEBUG(D_STREAM, "restarting");
1409 /* Reinitialize the stream */
1410 switch (sd->bridge) {
1412 case BRIDGE_OV511PLUS:
1413 return reg_w(sd, R51x_SYS_RESET, 0x00);
1415 case BRIDGE_OV518PLUS:
1416 rc = reg_w(sd, 0x2f, 0x80);
1419 return reg_w(sd, R51x_SYS_RESET, 0x00);
1421 return reg_w(sd, OV519_SYS_RESET1, 0x00);
1427 static int ov51x_set_slave_ids(struct sd *sd, __u8 slave);
1429 /* This does an initial reset of an OmniVision sensor and ensures that I2C
1430 * is synchronized. Returns <0 on failure.
1432 static int init_ov_sensor(struct sd *sd, __u8 slave)
1436 if (ov51x_set_slave_ids(sd, slave) < 0)
1439 /* Reset the sensor */
1440 if (i2c_w(sd, 0x12, 0x80) < 0)
1443 /* Wait for it to initialize */
1446 for (i = 0; i < i2c_detect_tries; i++) {
1447 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
1448 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
1449 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
1453 /* Reset the sensor */
1454 if (i2c_w(sd, 0x12, 0x80) < 0)
1456 /* Wait for it to initialize */
1458 /* Dummy read to sync I2C */
1459 if (i2c_r(sd, 0x00) < 0)
1465 /* Set the read and write slave IDs. The "slave" argument is the write slave,
1466 * and the read slave will be set to (slave + 1).
1467 * This should not be called from outside the i2c I/O functions.
1468 * Sets I2C read and write slave IDs. Returns <0 for error
1470 static int ov51x_set_slave_ids(struct sd *sd,
1475 rc = reg_w(sd, R51x_I2C_W_SID, slave);
1478 return reg_w(sd, R51x_I2C_R_SID, slave + 1);
1481 static int write_regvals(struct sd *sd,
1482 const struct ov_regvals *regvals,
1488 rc = reg_w(sd, regvals->reg, regvals->val);
1496 static int write_i2c_regvals(struct sd *sd,
1497 const struct ov_i2c_regvals *regvals,
1503 rc = i2c_w(sd, regvals->reg, regvals->val);
1511 /****************************************************************************
1513 * OV511 and sensor configuration
1515 ***************************************************************************/
1517 /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
1518 * the same register settings as the OV8610, since they are very similar.
1520 static int ov8xx0_configure(struct sd *sd)
1524 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
1526 /* Detect sensor (sub)type */
1527 rc = i2c_r(sd, OV7610_REG_COM_I);
1529 PDEBUG(D_ERR, "Error detecting sensor type");
1532 if ((rc & 3) == 1) {
1533 sd->sensor = SEN_OV8610;
1535 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1539 /* Set sensor-specific vars */
1543 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
1544 * the same register settings as the OV7610, since they are very similar.
1546 static int ov7xx0_configure(struct sd *sd)
1551 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
1553 /* Detect sensor (sub)type */
1554 rc = i2c_r(sd, OV7610_REG_COM_I);
1557 * it appears to be wrongly detected as a 7610 by default */
1559 PDEBUG(D_ERR, "Error detecting sensor type");
1562 if ((rc & 3) == 3) {
1563 /* quick hack to make OV7670s work */
1564 high = i2c_r(sd, 0x0a);
1565 low = i2c_r(sd, 0x0b);
1566 /* info("%x, %x", high, low); */
1567 if (high == 0x76 && low == 0x73) {
1568 PDEBUG(D_PROBE, "Sensor is an OV7670");
1569 sd->sensor = SEN_OV7670;
1571 PDEBUG(D_PROBE, "Sensor is an OV7610");
1572 sd->sensor = SEN_OV7610;
1574 } else if ((rc & 3) == 1) {
1575 /* I don't know what's different about the 76BE yet. */
1576 if (i2c_r(sd, 0x15) & 1) {
1577 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
1578 sd->sensor = SEN_OV7620;
1580 PDEBUG(D_PROBE, "Sensor is an OV76BE");
1581 sd->sensor = SEN_OV76BE;
1583 } else if ((rc & 3) == 0) {
1584 /* try to read product id registers */
1585 high = i2c_r(sd, 0x0a);
1587 PDEBUG(D_ERR, "Error detecting camera chip PID");
1590 low = i2c_r(sd, 0x0b);
1592 PDEBUG(D_ERR, "Error detecting camera chip VER");
1598 PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
1600 "7630 is not supported by this driver");
1603 PDEBUG(D_PROBE, "Sensor is an OV7645");
1604 sd->sensor = SEN_OV7640; /* FIXME */
1607 PDEBUG(D_PROBE, "Sensor is an OV7645B");
1608 sd->sensor = SEN_OV7640; /* FIXME */
1611 PDEBUG(D_PROBE, "Sensor is an OV7648");
1612 sd->sensor = SEN_OV7640; /* FIXME */
1615 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
1619 PDEBUG(D_PROBE, "Sensor is an OV7620");
1620 sd->sensor = SEN_OV7620;
1623 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1627 /* Set sensor-specific vars */
1631 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
1632 static int ov6xx0_configure(struct sd *sd)
1635 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
1637 /* Detect sensor (sub)type */
1638 rc = i2c_r(sd, OV7610_REG_COM_I);
1640 PDEBUG(D_ERR, "Error detecting sensor type");
1644 /* Ugh. The first two bits are the version bits, but
1645 * the entire register value must be used. I guess OVT
1646 * underestimated how many variants they would make. */
1649 sd->sensor = SEN_OV6630;
1651 "WARNING: Sensor is an OV66308. Your camera may have");
1652 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
1655 sd->sensor = SEN_OV6620;
1656 PDEBUG(D_PROBE, "Sensor is an OV6620");
1659 sd->sensor = SEN_OV6630;
1660 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
1663 sd->sensor = SEN_OV66308AF;
1664 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
1667 sd->sensor = SEN_OV6630;
1669 "WARNING: Sensor is an OV66307. Your camera may have");
1670 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
1673 PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
1677 /* Set sensor-specific vars */
1683 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
1684 static void ov51x_led_control(struct sd *sd, int on)
1689 switch (sd->bridge) {
1690 /* OV511 has no LED control */
1691 case BRIDGE_OV511PLUS:
1692 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
1695 case BRIDGE_OV518PLUS:
1696 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
1699 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
1704 static int ov51x_upload_quan_tables(struct sd *sd)
1706 const unsigned char yQuanTable511[] = {
1707 0, 1, 1, 2, 2, 3, 3, 4,
1708 1, 1, 1, 2, 2, 3, 4, 4,
1709 1, 1, 2, 2, 3, 4, 4, 4,
1710 2, 2, 2, 3, 4, 4, 4, 4,
1711 2, 2, 3, 4, 4, 5, 5, 5,
1712 3, 3, 4, 4, 5, 5, 5, 5,
1713 3, 4, 4, 4, 5, 5, 5, 5,
1714 4, 4, 4, 4, 5, 5, 5, 5
1717 const unsigned char uvQuanTable511[] = {
1718 0, 2, 2, 3, 4, 4, 4, 4,
1719 2, 2, 2, 4, 4, 4, 4, 4,
1720 2, 2, 3, 4, 4, 4, 4, 4,
1721 3, 4, 4, 4, 4, 4, 4, 4,
1722 4, 4, 4, 4, 4, 4, 4, 4,
1723 4, 4, 4, 4, 4, 4, 4, 4,
1724 4, 4, 4, 4, 4, 4, 4, 4,
1725 4, 4, 4, 4, 4, 4, 4, 4
1728 /* OV518 quantization tables are 8x4 (instead of 8x8) */
1729 const unsigned char yQuanTable518[] = {
1730 5, 4, 5, 6, 6, 7, 7, 7,
1731 5, 5, 5, 5, 6, 7, 7, 7,
1732 6, 6, 6, 6, 7, 7, 7, 8,
1733 7, 7, 6, 7, 7, 7, 8, 8
1736 const unsigned char uvQuanTable518[] = {
1737 6, 6, 6, 7, 7, 7, 7, 7,
1738 6, 6, 6, 7, 7, 7, 7, 7,
1739 6, 6, 6, 7, 7, 7, 7, 8,
1740 7, 7, 7, 7, 7, 7, 8, 8
1743 const unsigned char *pYTable, *pUVTable;
1744 unsigned char val0, val1;
1745 int i, size, rc, reg = R51x_COMP_LUT_BEGIN;
1747 PDEBUG(D_PROBE, "Uploading quantization tables");
1749 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
1750 pYTable = yQuanTable511;
1751 pUVTable = uvQuanTable511;
1754 pYTable = yQuanTable518;
1755 pUVTable = uvQuanTable518;
1759 for (i = 0; i < size; i++) {
1765 rc = reg_w(sd, reg, val0);
1774 rc = reg_w(sd, reg + size, val0);
1784 /* This initializes the OV511/OV511+ and the sensor */
1785 static int ov511_configure(struct gspca_dev *gspca_dev)
1787 struct sd *sd = (struct sd *) gspca_dev;
1790 /* For 511 and 511+ */
1791 const struct ov_regvals init_511[] = {
1792 { R51x_SYS_RESET, 0x7f },
1793 { R51x_SYS_INIT, 0x01 },
1794 { R51x_SYS_RESET, 0x7f },
1795 { R51x_SYS_INIT, 0x01 },
1796 { R51x_SYS_RESET, 0x3f },
1797 { R51x_SYS_INIT, 0x01 },
1798 { R51x_SYS_RESET, 0x3d },
1801 const struct ov_regvals norm_511[] = {
1802 { R511_DRAM_FLOW_CTL, 0x01 },
1803 { R51x_SYS_SNAP, 0x00 },
1804 { R51x_SYS_SNAP, 0x02 },
1805 { R51x_SYS_SNAP, 0x00 },
1806 { R511_FIFO_OPTS, 0x1f },
1807 { R511_COMP_EN, 0x00 },
1808 { R511_COMP_LUT_EN, 0x03 },
1811 const struct ov_regvals norm_511_p[] = {
1812 { R511_DRAM_FLOW_CTL, 0xff },
1813 { R51x_SYS_SNAP, 0x00 },
1814 { R51x_SYS_SNAP, 0x02 },
1815 { R51x_SYS_SNAP, 0x00 },
1816 { R511_FIFO_OPTS, 0xff },
1817 { R511_COMP_EN, 0x00 },
1818 { R511_COMP_LUT_EN, 0x03 },
1821 const struct ov_regvals compress_511[] = {
1832 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
1834 rc = write_regvals(sd, init_511, ARRAY_SIZE(init_511));
1838 switch (sd->bridge) {
1840 rc = write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
1844 case BRIDGE_OV511PLUS:
1845 rc = write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
1851 /* Init compression */
1852 rc = write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
1856 rc = ov51x_upload_quan_tables(sd);
1858 PDEBUG(D_ERR, "Error uploading quantization tables");
1865 /* This initializes the OV518/OV518+ and the sensor */
1866 static int ov518_configure(struct gspca_dev *gspca_dev)
1868 struct sd *sd = (struct sd *) gspca_dev;
1871 /* For 518 and 518+ */
1872 const struct ov_regvals init_518[] = {
1873 { R51x_SYS_RESET, 0x40 },
1874 { R51x_SYS_INIT, 0xe1 },
1875 { R51x_SYS_RESET, 0x3e },
1876 { R51x_SYS_INIT, 0xe1 },
1877 { R51x_SYS_RESET, 0x00 },
1878 { R51x_SYS_INIT, 0xe1 },
1883 const struct ov_regvals norm_518[] = {
1884 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1885 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1896 const struct ov_regvals norm_518_p[] = {
1897 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1898 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1915 /* First 5 bits of custom ID reg are a revision ID on OV518 */
1916 PDEBUG(D_PROBE, "Device revision %d",
1917 0x1F & reg_r(sd, R51x_SYS_CUST_ID));
1919 rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
1923 /* Set LED GPIO pin to output mode */
1924 rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
1928 switch (sd->bridge) {
1930 rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
1934 case BRIDGE_OV518PLUS:
1935 rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
1941 rc = ov51x_upload_quan_tables(sd);
1943 PDEBUG(D_ERR, "Error uploading quantization tables");
1947 rc = reg_w(sd, 0x2f, 0x80);
1954 static int ov519_configure(struct sd *sd)
1956 static const struct ov_regvals init_519[] = {
1957 { 0x5a, 0x6d }, /* EnableSystem */
1959 { 0x54, 0xff }, /* set bit2 to enable jpeg */
1963 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
1964 * detection will fail. This deserves further investigation. */
1965 { OV519_GPIO_IO_CTRL0, 0xee },
1966 { 0x51, 0x0f }, /* SetUsbInit */
1969 /* windows reads 0x55 at this point*/
1972 return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
1975 /* this function is called at probe time */
1976 static int sd_config(struct gspca_dev *gspca_dev,
1977 const struct usb_device_id *id)
1979 struct sd *sd = (struct sd *) gspca_dev;
1983 sd->bridge = id->driver_info & BRIDGE_MASK;
1984 sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
1986 switch (sd->bridge) {
1988 case BRIDGE_OV511PLUS:
1989 ret = ov511_configure(gspca_dev);
1992 case BRIDGE_OV518PLUS:
1993 ret = ov518_configure(gspca_dev);
1996 ret = ov519_configure(sd);
2003 ov51x_led_control(sd, 0); /* turn LED off */
2005 /* The OV519 must be more aggressive about sensor detection since
2006 * I2C write will never fail if the sensor is not present. We have
2007 * to try to initialize the sensor to detect its presence */
2010 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
2011 if (ov7xx0_configure(sd) < 0) {
2012 PDEBUG(D_ERR, "Failed to configure OV7xx0");
2016 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
2017 if (ov6xx0_configure(sd) < 0) {
2018 PDEBUG(D_ERR, "Failed to configure OV6xx0");
2022 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
2023 if (ov8xx0_configure(sd) < 0) {
2024 PDEBUG(D_ERR, "Failed to configure OV8xx0");
2028 PDEBUG(D_ERR, "Can't determine sensor slave IDs");
2032 cam = &gspca_dev->cam;
2033 switch (sd->bridge) {
2035 case BRIDGE_OV511PLUS:
2037 cam->cam_mode = ov511_vga_mode;
2038 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
2040 cam->cam_mode = ov511_sif_mode;
2041 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
2045 case BRIDGE_OV518PLUS:
2047 cam->cam_mode = ov518_vga_mode;
2048 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
2050 cam->cam_mode = ov518_sif_mode;
2051 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
2056 cam->cam_mode = ov519_vga_mode;
2057 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2059 cam->cam_mode = ov519_sif_mode;
2060 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
2064 sd->brightness = BRIGHTNESS_DEF;
2065 if (sd->sensor == SEN_OV6630 || sd->sensor == SEN_OV66308AF)
2066 sd->contrast = 200; /* The default is too low for the ov6630 */
2068 sd->contrast = CONTRAST_DEF;
2069 sd->colors = COLOR_DEF;
2070 sd->hflip = HFLIP_DEF;
2071 sd->vflip = VFLIP_DEF;
2072 sd->autobrightness = AUTOBRIGHT_DEF;
2073 if (sd->sensor == SEN_OV7670) {
2074 sd->freq = OV7670_FREQ_DEF;
2075 gspca_dev->ctrl_dis = 1 << FREQ_IDX;
2077 sd->freq = FREQ_DEF;
2078 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
2079 (1 << OV7670_FREQ_IDX);
2081 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
2082 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
2083 /* OV8610 Frequency filter control should work but needs testing */
2084 if (sd->sensor == SEN_OV8610)
2085 gspca_dev->ctrl_dis |= 1 << FREQ_IDX;
2089 PDEBUG(D_ERR, "OV519 Config failed");
2093 /* this function is called at probe and resume time */
2094 static int sd_init(struct gspca_dev *gspca_dev)
2096 struct sd *sd = (struct sd *) gspca_dev;
2098 /* initialize the sensor */
2099 switch (sd->sensor) {
2101 if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
2106 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
2110 /* case SEN_OV7610: */
2111 /* case SEN_OV76BE: */
2112 if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
2114 if (i2c_w_mask(sd, 0x0e, 0x00, 0x40))
2118 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
2122 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
2126 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
2130 if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
2137 /* Set up the OV511/OV511+ with the given image parameters.
2139 * Do not put any sensor-specific code in here (including I2C I/O functions)
2141 static int ov511_mode_init_regs(struct sd *sd)
2143 int hsegs, vsegs, packet_size, fps, needed;
2145 struct usb_host_interface *alt;
2146 struct usb_interface *intf;
2148 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
2149 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
2151 PDEBUG(D_ERR, "Couldn't get altsetting");
2155 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2156 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
2158 reg_w(sd, R511_CAM_UV_EN, 0x01);
2159 reg_w(sd, R511_SNAP_UV_EN, 0x01);
2160 reg_w(sd, R511_SNAP_OPTS, 0x03);
2162 /* Here I'm assuming that snapshot size == image size.
2163 * I hope that's always true. --claudio
2165 hsegs = (sd->gspca_dev.width >> 3) - 1;
2166 vsegs = (sd->gspca_dev.height >> 3) - 1;
2168 reg_w(sd, R511_CAM_PXCNT, hsegs);
2169 reg_w(sd, R511_CAM_LNCNT, vsegs);
2170 reg_w(sd, R511_CAM_PXDIV, 0x00);
2171 reg_w(sd, R511_CAM_LNDIV, 0x00);
2173 /* YUV420, low pass filter on */
2174 reg_w(sd, R511_CAM_OPTS, 0x03);
2176 /* Snapshot additions */
2177 reg_w(sd, R511_SNAP_PXCNT, hsegs);
2178 reg_w(sd, R511_SNAP_LNCNT, vsegs);
2179 reg_w(sd, R511_SNAP_PXDIV, 0x00);
2180 reg_w(sd, R511_SNAP_LNDIV, 0x00);
2182 /******** Set the framerate ********/
2184 sd->frame_rate = frame_rate;
2186 switch (sd->sensor) {
2188 /* No framerate control, doesn't like higher rates yet */
2192 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
2193 for more sensors we need to do this for them too */
2197 if (sd->gspca_dev.width == 320)
2203 switch (sd->frame_rate) {
2206 /* Not enough bandwidth to do 640x480 @ 30 fps */
2207 if (sd->gspca_dev.width != 640) {
2211 /* Fall through for 640x480 case */
2225 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
2226 /* Higher then 10 does not work */
2227 if (sd->clockdiv > 10)
2233 /* No framerate control ?? */
2238 /* Check if we have enough bandwidth to disable compression */
2239 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
2240 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
2241 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
2242 if (needed > 1400 * packet_size) {
2243 /* Enable Y and UV quantization and compression */
2244 reg_w(sd, R511_COMP_EN, 0x07);
2245 reg_w(sd, R511_COMP_LUT_EN, 0x03);
2247 reg_w(sd, R511_COMP_EN, 0x06);
2248 reg_w(sd, R511_COMP_LUT_EN, 0x00);
2251 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
2252 reg_w(sd, R51x_SYS_RESET, 0);
2257 /* Sets up the OV518/OV518+ with the given image parameters
2259 * OV518 needs a completely different approach, until we can figure out what
2260 * the individual registers do. Also, only 15 FPS is supported now.
2262 * Do not put any sensor-specific code in here (including I2C I/O functions)
2264 static int ov518_mode_init_regs(struct sd *sd)
2266 int hsegs, vsegs, packet_size;
2267 struct usb_host_interface *alt;
2268 struct usb_interface *intf;
2270 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
2271 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
2273 PDEBUG(D_ERR, "Couldn't get altsetting");
2277 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2278 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
2280 /******** Set the mode ********/
2291 if (sd->bridge == BRIDGE_OV518) {
2292 /* Set 8-bit (YVYU) input format */
2293 reg_w_mask(sd, 0x20, 0x08, 0x08);
2295 /* Set 12-bit (4:2:0) output format */
2296 reg_w_mask(sd, 0x28, 0x80, 0xf0);
2297 reg_w_mask(sd, 0x38, 0x80, 0xf0);
2299 reg_w(sd, 0x28, 0x80);
2300 reg_w(sd, 0x38, 0x80);
2303 hsegs = sd->gspca_dev.width / 16;
2304 vsegs = sd->gspca_dev.height / 4;
2306 reg_w(sd, 0x29, hsegs);
2307 reg_w(sd, 0x2a, vsegs);
2309 reg_w(sd, 0x39, hsegs);
2310 reg_w(sd, 0x3a, vsegs);
2312 /* Windows driver does this here; who knows why */
2313 reg_w(sd, 0x2f, 0x80);
2315 /******** Set the framerate ********/
2318 /* Mode independent, but framerate dependent, regs */
2319 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
2320 reg_w(sd, 0x51, 0x04);
2321 reg_w(sd, 0x22, 0x18);
2322 reg_w(sd, 0x23, 0xff);
2324 if (sd->bridge == BRIDGE_OV518PLUS) {
2325 switch (sd->sensor) {
2327 if (sd->gspca_dev.width == 320) {
2328 reg_w(sd, 0x20, 0x00);
2329 reg_w(sd, 0x21, 0x19);
2331 reg_w(sd, 0x20, 0x60);
2332 reg_w(sd, 0x21, 0x1f);
2336 reg_w(sd, 0x21, 0x19);
2339 reg_w(sd, 0x71, 0x17); /* Compression-related? */
2341 /* FIXME: Sensor-specific */
2342 /* Bit 5 is what matters here. Of course, it is "reserved" */
2343 i2c_w(sd, 0x54, 0x23);
2345 reg_w(sd, 0x2f, 0x80);
2347 if (sd->bridge == BRIDGE_OV518PLUS) {
2348 reg_w(sd, 0x24, 0x94);
2349 reg_w(sd, 0x25, 0x90);
2350 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
2351 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
2352 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
2353 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
2354 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
2355 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
2356 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
2357 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
2358 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
2360 reg_w(sd, 0x24, 0x9f);
2361 reg_w(sd, 0x25, 0x90);
2362 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
2363 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
2364 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
2365 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
2366 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
2367 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
2368 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
2369 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
2370 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
2373 reg_w(sd, 0x2f, 0x80);
2379 /* Sets up the OV519 with the given image parameters
2381 * OV519 needs a completely different approach, until we can figure out what
2382 * the individual registers do.
2384 * Do not put any sensor-specific code in here (including I2C I/O functions)
2386 static int ov519_mode_init_regs(struct sd *sd)
2388 static const struct ov_regvals mode_init_519_ov7670[] = {
2389 { 0x5d, 0x03 }, /* Turn off suspend mode */
2390 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
2391 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
2392 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
2396 { 0x37, 0x00 }, /* SetUsbInit */
2397 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
2398 /* Enable both fields, YUV Input, disable defect comp (why?) */
2402 { 0x17, 0x50 }, /* undocumented */
2403 { 0x37, 0x00 }, /* undocumented */
2404 { 0x40, 0xff }, /* I2C timeout counter */
2405 { 0x46, 0x00 }, /* I2C clock prescaler */
2406 { 0x59, 0x04 }, /* new from windrv 090403 */
2407 { 0xff, 0x00 }, /* undocumented */
2408 /* windows reads 0x55 at this point, why? */
2411 static const struct ov_regvals mode_init_519[] = {
2412 { 0x5d, 0x03 }, /* Turn off suspend mode */
2413 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
2414 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
2415 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
2419 { 0x37, 0x00 }, /* SetUsbInit */
2420 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
2421 /* Enable both fields, YUV Input, disable defect comp (why?) */
2423 { 0x17, 0x50 }, /* undocumented */
2424 { 0x37, 0x00 }, /* undocumented */
2425 { 0x40, 0xff }, /* I2C timeout counter */
2426 { 0x46, 0x00 }, /* I2C clock prescaler */
2427 { 0x59, 0x04 }, /* new from windrv 090403 */
2428 { 0xff, 0x00 }, /* undocumented */
2429 /* windows reads 0x55 at this point, why? */
2432 /******** Set the mode ********/
2433 if (sd->sensor != SEN_OV7670) {
2434 if (write_regvals(sd, mode_init_519,
2435 ARRAY_SIZE(mode_init_519)))
2437 if (sd->sensor == SEN_OV7640) {
2438 /* Select 8-bit input mode */
2439 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
2442 if (write_regvals(sd, mode_init_519_ov7670,
2443 ARRAY_SIZE(mode_init_519_ov7670)))
2447 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
2448 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
2449 if (sd->sensor == SEN_OV7670 &&
2450 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
2451 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
2453 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
2454 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
2455 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
2456 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
2457 reg_w(sd, OV519_R16_DIVIDER, 0x00);
2458 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
2459 reg_w(sd, 0x26, 0x00); /* Undocumented */
2461 /******** Set the framerate ********/
2463 sd->frame_rate = frame_rate;
2465 /* FIXME: These are only valid at the max resolution. */
2467 switch (sd->sensor) {
2469 switch (sd->frame_rate) {
2472 reg_w(sd, 0xa4, 0x0c);
2473 reg_w(sd, 0x23, 0xff);
2476 reg_w(sd, 0xa4, 0x0c);
2477 reg_w(sd, 0x23, 0x1f);
2480 reg_w(sd, 0xa4, 0x0c);
2481 reg_w(sd, 0x23, 0x1b);
2484 reg_w(sd, 0xa4, 0x04);
2485 reg_w(sd, 0x23, 0xff);
2489 reg_w(sd, 0xa4, 0x04);
2490 reg_w(sd, 0x23, 0x1f);
2494 reg_w(sd, 0xa4, 0x04);
2495 reg_w(sd, 0x23, 0x1b);
2501 switch (sd->frame_rate) {
2502 default: /* 15 fps */
2504 reg_w(sd, 0xa4, 0x06);
2505 reg_w(sd, 0x23, 0xff);
2508 reg_w(sd, 0xa4, 0x06);
2509 reg_w(sd, 0x23, 0x1f);
2512 reg_w(sd, 0xa4, 0x06);
2513 reg_w(sd, 0x23, 0x1b);
2517 case SEN_OV7670: /* guesses, based on 7640 */
2518 PDEBUG(D_STREAM, "Setting framerate to %d fps",
2519 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
2520 reg_w(sd, 0xa4, 0x10);
2521 switch (sd->frame_rate) {
2523 reg_w(sd, 0x23, 0xff);
2526 reg_w(sd, 0x23, 0x1b);
2530 reg_w(sd, 0x23, 0xff);
2539 static int mode_init_ov_sensor_regs(struct sd *sd)
2541 struct gspca_dev *gspca_dev;
2544 gspca_dev = &sd->gspca_dev;
2545 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
2547 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2548 switch (sd->sensor) {
2550 /* For OV8610 qvga means qsvga */
2551 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
2554 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2558 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2559 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2560 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
2561 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
2562 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
2563 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
2564 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
2567 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2568 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2569 /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
2570 /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
2571 /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
2572 /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
2573 /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
2576 /* set COM7_FMT_VGA or COM7_FMT_QVGA
2577 * do we need to set anything else?
2578 * HSTART etc are set in set_ov_sensor_window itself */
2579 i2c_w_mask(sd, OV7670_REG_COM7,
2580 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
2581 OV7670_COM7_FMT_MASK);
2586 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2592 /******** Palette-specific regs ********/
2594 /* The OV518 needs special treatment. Although both the OV518
2595 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2596 * bus is actually used. The UV bus is tied to ground.
2597 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2600 /* OV7640 is 8-bit only */
2602 if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV66308AF &&
2603 sd->sensor != SEN_OV7640)
2604 i2c_w_mask(sd, 0x13, 0x00, 0x20);
2606 /******** Clock programming ********/
2607 i2c_w(sd, 0x11, sd->clockdiv);
2609 /******** Special Features ********/
2610 /* no evidence this is possible with OV7670, either */
2612 if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
2613 i2c_w_mask(sd, 0x12, 0x00, 0x02);
2615 /* Enable auto white balance */
2616 if (sd->sensor == SEN_OV7670)
2617 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
2620 i2c_w_mask(sd, 0x12, 0x04, 0x04);
2622 /* This will go away as soon as ov51x_mode_init_sensor_regs() */
2623 /* is fully tested. */
2624 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2625 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
2627 i2c_w(sd, 0x35, 0x9e);
2629 i2c_w(sd, 0x35, 0x1e);
2634 static void sethvflip(struct sd *sd)
2636 if (sd->sensor != SEN_OV7670)
2638 if (sd->gspca_dev.streaming)
2640 i2c_w_mask(sd, OV7670_REG_MVFP,
2641 OV7670_MVFP_MIRROR * sd->hflip
2642 | OV7670_MVFP_VFLIP * sd->vflip,
2643 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
2644 if (sd->gspca_dev.streaming)
2648 static int set_ov_sensor_window(struct sd *sd)
2650 struct gspca_dev *gspca_dev;
2652 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
2653 int ret, hstart, hstop, vstop, vstart;
2656 gspca_dev = &sd->gspca_dev;
2657 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
2658 crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2;
2660 /* The different sensor ICs handle setting up of window differently.
2661 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
2662 switch (sd->sensor) {
2673 vwsbase = vwebase = 0x05;
2682 if (sd->sensor == SEN_OV66308AF && qvga)
2683 /* HDG: this fixes U and V getting swapped */
2693 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2695 vwsbase = vwebase = 0x05;
2700 vwsbase = vwebase = 0x03;
2703 /*handling of OV7670 hardware sensor start and stop values
2704 * is very odd, compared to the other OV sensors */
2705 vwsbase = vwebase = hwebase = hwsbase = 0x00;
2711 switch (sd->sensor) {
2715 if (qvga) { /* QCIF */
2720 vwscale = 1; /* The datasheet says 0;
2725 if (qvga) { /* QSVGA */
2733 default: /* SEN_OV7xx0 */
2734 if (qvga) { /* QVGA */
2743 ret = mode_init_ov_sensor_regs(sd);
2747 if (sd->sensor == SEN_OV8610) {
2748 i2c_w_mask(sd, 0x2d, 0x05, 0x40);
2749 /* old 0x95, new 0x05 from windrv 090403 */
2750 /* bits 5-7: reserved */
2751 i2c_w_mask(sd, 0x28, 0x20, 0x20);
2752 /* bit 5: progressive mode on */
2755 /* The below is wrong for OV7670s because their window registers
2756 * only store the high bits in 0x17 to 0x1a */
2758 /* SRH Use sd->max values instead of requested win values */
2759 /* SCS Since we're sticking with only the max hardware widths
2760 * for a given mode */
2761 /* I can hard code this for OV7670s */
2762 /* Yes, these numbers do look odd, but they're tested and work! */
2763 if (sd->sensor == SEN_OV7670) {
2764 if (qvga) { /* QVGA from ov7670.c by
2765 * Jonathan Corbet */
2776 /* OV7670 hardware window registers are split across
2777 * multiple locations */
2778 i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
2779 i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
2780 v = i2c_r(sd, OV7670_REG_HREF);
2781 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
2782 msleep(10); /* need to sleep between read and write to
2784 i2c_w(sd, OV7670_REG_HREF, v);
2786 i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
2787 i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
2788 v = i2c_r(sd, OV7670_REG_VREF);
2789 v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
2790 msleep(10); /* need to sleep between read and write to
2792 i2c_w(sd, OV7670_REG_VREF, v);
2794 i2c_w(sd, 0x17, hwsbase);
2795 i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
2796 i2c_w(sd, 0x19, vwsbase);
2797 i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
2802 /* -- start the camera -- */
2803 static int sd_start(struct gspca_dev *gspca_dev)
2805 struct sd *sd = (struct sd *) gspca_dev;
2808 switch (sd->bridge) {
2810 case BRIDGE_OV511PLUS:
2811 ret = ov511_mode_init_regs(sd);
2814 case BRIDGE_OV518PLUS:
2815 ret = ov518_mode_init_regs(sd);
2818 ret = ov519_mode_init_regs(sd);
2824 ret = set_ov_sensor_window(sd);
2828 setcontrast(gspca_dev);
2829 setbrightness(gspca_dev);
2830 setcolors(gspca_dev);
2832 setautobrightness(sd);
2835 ret = ov51x_restart(sd);
2838 ov51x_led_control(sd, 1);
2841 PDEBUG(D_ERR, "camera start error:%d", ret);
2845 static void sd_stopN(struct gspca_dev *gspca_dev)
2847 struct sd *sd = (struct sd *) gspca_dev;
2850 ov51x_led_control(sd, 0);
2853 static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
2854 struct gspca_frame *frame, /* target */
2855 __u8 *in, /* isoc packet */
2856 int len) /* iso packet length */
2858 struct sd *sd = (struct sd *) gspca_dev;
2860 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
2861 * byte non-zero. The EOF packet has image width/height in the
2862 * 10th and 11th bytes. The 9th byte is given as follows:
2865 * 6: compression enabled
2866 * 5: 422/420/400 modes
2867 * 4: 422/420/400 modes
2869 * 2: snapshot button on
2873 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
2877 if ((in[9] + 1) * 8 != gspca_dev->width ||
2878 (in[10] + 1) * 8 != gspca_dev->height) {
2879 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
2880 " requested: %dx%d\n",
2881 (in[9] + 1) * 8, (in[10] + 1) * 8,
2882 gspca_dev->width, gspca_dev->height);
2883 gspca_dev->last_packet_type = DISCARD_PACKET;
2886 /* Add 11 byte footer to frame, might be usefull */
2887 gspca_frame_add(gspca_dev, LAST_PACKET, frame, in, 11);
2891 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, in, 0);
2896 /* Ignore the packet number */
2899 /* intermediate packet */
2900 gspca_frame_add(gspca_dev, INTER_PACKET, frame, in, len);
2903 static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
2904 struct gspca_frame *frame, /* target */
2905 __u8 *data, /* isoc packet */
2906 int len) /* iso packet length */
2908 struct sd *sd = (struct sd *) gspca_dev;
2910 /* A false positive here is likely, until OVT gives me
2911 * the definitive SOF/EOF format */
2912 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
2913 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0);
2914 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, 0);
2918 if (gspca_dev->last_packet_type == DISCARD_PACKET)
2921 /* Does this device use packet numbers ? */
2924 if (sd->packet_nr == data[len])
2926 /* The last few packets of the frame (which are all 0's
2927 except that they may contain part of the footer), are
2929 else if (sd->packet_nr == 0 || data[len]) {
2930 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
2931 (int)data[len], (int)sd->packet_nr);
2932 gspca_dev->last_packet_type = DISCARD_PACKET;
2937 /* intermediate packet */
2938 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
2941 static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
2942 struct gspca_frame *frame, /* target */
2943 __u8 *data, /* isoc packet */
2944 int len) /* iso packet length */
2946 /* Header of ov519 is 16 bytes:
2947 * Byte Value Description
2951 * 3 0xXX 0x50 = SOF, 0x51 = EOF
2952 * 9 0xXX 0x01 initial frame without data,
2953 * 0x00 standard frame with image
2954 * 14 Lo in EOF: length of image data / 8
2958 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
2960 case 0x50: /* start of frame */
2965 if (data[0] == 0xff || data[1] == 0xd8)
2966 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
2969 gspca_dev->last_packet_type = DISCARD_PACKET;
2971 case 0x51: /* end of frame */
2973 gspca_dev->last_packet_type = DISCARD_PACKET;
2974 gspca_frame_add(gspca_dev, LAST_PACKET, frame,
2980 /* intermediate packet */
2981 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
2985 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2986 struct gspca_frame *frame, /* target */
2987 __u8 *data, /* isoc packet */
2988 int len) /* iso packet length */
2990 struct sd *sd = (struct sd *) gspca_dev;
2992 switch (sd->bridge) {
2994 case BRIDGE_OV511PLUS:
2995 ov511_pkt_scan(gspca_dev, frame, data, len);
2998 case BRIDGE_OV518PLUS:
2999 ov518_pkt_scan(gspca_dev, frame, data, len);
3002 ov519_pkt_scan(gspca_dev, frame, data, len);
3007 /* -- management routines -- */
3009 static void setbrightness(struct gspca_dev *gspca_dev)
3011 struct sd *sd = (struct sd *) gspca_dev;
3014 val = sd->brightness;
3015 switch (sd->sensor) {
3023 i2c_w(sd, OV7610_REG_BRT, val);
3026 /* 7620 doesn't like manual changes when in auto mode */
3027 if (!sd->autobrightness)
3028 i2c_w(sd, OV7610_REG_BRT, val);
3032 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
3033 i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
3038 static void setcontrast(struct gspca_dev *gspca_dev)
3040 struct sd *sd = (struct sd *) gspca_dev;
3044 switch (sd->sensor) {
3047 i2c_w(sd, OV7610_REG_CNT, val);
3051 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
3054 static const __u8 ctab[] = {
3055 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
3058 /* Use Y gamma control instead. Bit 0 enables it. */
3059 i2c_w(sd, 0x64, ctab[val >> 5]);
3063 static const __u8 ctab[] = {
3064 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
3065 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
3068 /* Use Y gamma control instead. Bit 0 enables it. */
3069 i2c_w(sd, 0x64, ctab[val >> 4]);
3073 /* Use gain control instead. */
3074 i2c_w(sd, OV7610_REG_GAIN, val >> 2);
3077 /* check that this isn't just the same as ov7610 */
3078 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
3083 static void setcolors(struct gspca_dev *gspca_dev)
3085 struct sd *sd = (struct sd *) gspca_dev;
3089 switch (sd->sensor) {
3096 i2c_w(sd, OV7610_REG_SAT, val);
3099 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
3100 /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
3103 i2c_w(sd, OV7610_REG_SAT, val);
3106 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
3109 /* supported later once I work out how to do it
3110 * transparently fail now! */
3111 /* set REG_COM13 values for UV sat auto mode */
3116 static void setautobrightness(struct sd *sd)
3118 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
3121 i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10);
3124 static void setfreq(struct sd *sd)
3126 if (sd->sensor == SEN_OV7670) {
3128 case 0: /* Banding filter disabled */
3129 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
3132 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
3134 i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18);
3137 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
3139 i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18);
3141 case 3: /* Auto hz */
3142 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
3144 i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO,
3150 case 0: /* Banding filter disabled */
3151 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
3152 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
3154 case 1: /* 50 hz (filter on and framerate adj) */
3155 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
3156 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
3157 /* 20 fps -> 16.667 fps */
3158 if (sd->sensor == SEN_OV6620 ||
3159 sd->sensor == SEN_OV6630 ||
3160 sd->sensor == SEN_OV66308AF)
3161 i2c_w(sd, 0x2b, 0x5e);
3163 i2c_w(sd, 0x2b, 0xac);
3165 case 2: /* 60 hz (filter on, ...) */
3166 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
3167 if (sd->sensor == SEN_OV6620 ||
3168 sd->sensor == SEN_OV6630 ||
3169 sd->sensor == SEN_OV66308AF) {
3170 /* 20 fps -> 15 fps */
3171 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
3172 i2c_w(sd, 0x2b, 0xa8);
3174 /* no framerate adj. */
3175 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
3182 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
3184 struct sd *sd = (struct sd *) gspca_dev;
3186 sd->brightness = val;
3187 if (gspca_dev->streaming)
3188 setbrightness(gspca_dev);
3192 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
3194 struct sd *sd = (struct sd *) gspca_dev;
3196 *val = sd->brightness;
3200 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
3202 struct sd *sd = (struct sd *) gspca_dev;
3205 if (gspca_dev->streaming)
3206 setcontrast(gspca_dev);
3210 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
3212 struct sd *sd = (struct sd *) gspca_dev;
3214 *val = sd->contrast;
3218 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
3220 struct sd *sd = (struct sd *) gspca_dev;
3223 if (gspca_dev->streaming)
3224 setcolors(gspca_dev);
3228 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
3230 struct sd *sd = (struct sd *) gspca_dev;
3236 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3238 struct sd *sd = (struct sd *) gspca_dev;
3241 if (gspca_dev->streaming)
3246 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
3248 struct sd *sd = (struct sd *) gspca_dev;
3254 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
3256 struct sd *sd = (struct sd *) gspca_dev;
3259 if (gspca_dev->streaming)
3264 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
3266 struct sd *sd = (struct sd *) gspca_dev;
3272 static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
3274 struct sd *sd = (struct sd *) gspca_dev;
3276 sd->autobrightness = val;
3277 if (gspca_dev->streaming)
3278 setautobrightness(sd);
3282 static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
3284 struct sd *sd = (struct sd *) gspca_dev;
3286 *val = sd->autobrightness;
3290 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
3292 struct sd *sd = (struct sd *) gspca_dev;
3295 if (gspca_dev->streaming)
3300 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
3302 struct sd *sd = (struct sd *) gspca_dev;
3308 static int sd_querymenu(struct gspca_dev *gspca_dev,
3309 struct v4l2_querymenu *menu)
3311 struct sd *sd = (struct sd *) gspca_dev;
3314 case V4L2_CID_POWER_LINE_FREQUENCY:
3315 switch (menu->index) {
3316 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
3317 strcpy((char *) menu->name, "NoFliker");
3319 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
3320 strcpy((char *) menu->name, "50 Hz");
3322 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
3323 strcpy((char *) menu->name, "60 Hz");
3326 if (sd->sensor != SEN_OV7670)
3329 strcpy((char *) menu->name, "Automatic");
3337 /* sub-driver description */
3338 static const struct sd_desc sd_desc = {
3339 .name = MODULE_NAME,
3341 .nctrls = ARRAY_SIZE(sd_ctrls),
3342 .config = sd_config,
3346 .pkt_scan = sd_pkt_scan,
3347 .querymenu = sd_querymenu,
3350 /* -- module initialisation -- */
3351 static const __devinitdata struct usb_device_id device_table[] = {
3352 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
3353 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
3354 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
3355 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
3356 {USB_DEVICE(0x041e, 0x4064),
3357 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
3358 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
3359 {USB_DEVICE(0x041e, 0x4068),
3360 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
3361 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
3362 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
3363 {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 },
3364 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
3365 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
3366 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
3367 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
3368 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
3369 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
3370 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
3371 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
3372 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
3376 MODULE_DEVICE_TABLE(usb, device_table);
3378 /* -- device connect -- */
3379 static int sd_probe(struct usb_interface *intf,
3380 const struct usb_device_id *id)
3382 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
3386 static struct usb_driver sd_driver = {
3387 .name = MODULE_NAME,
3388 .id_table = device_table,
3390 .disconnect = gspca_disconnect,
3392 .suspend = gspca_suspend,
3393 .resume = gspca_resume,
3397 /* -- module insert / remove -- */
3398 static int __init sd_mod_init(void)
3401 ret = usb_register(&sd_driver);
3404 PDEBUG(D_PROBE, "registered");
3407 static void __exit sd_mod_exit(void)
3409 usb_deregister(&sd_driver);
3410 PDEBUG(D_PROBE, "deregistered");
3413 module_init(sd_mod_init);
3414 module_exit(sd_mod_exit);
3416 module_param(frame_rate, int, 0644);
3417 MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");