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 */
54 #define BRIDGE_OV511 0
55 #define BRIDGE_OV511PLUS 1
56 #define BRIDGE_OV518 2
57 #define BRIDGE_OV518PLUS 3
58 #define BRIDGE_OV519 4
60 /* Determined by sensor type */
71 __u8 stopped; /* Streaming is temporarily paused */
73 __u8 frame_rate; /* current Framerate (OV519 only) */
74 __u8 clockdiv; /* clockdiv override for OV519 only */
76 char sensor; /* Type of image sensor chip (SEN_*) */
80 #define SEN_OV66308AF 3
89 /* V4L2 controls supported by the driver */
90 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
91 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
92 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
93 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
94 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
95 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
96 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
97 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
98 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
99 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
100 static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val);
101 static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val);
102 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
103 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
104 static void setbrightness(struct gspca_dev *gspca_dev);
105 static void setcontrast(struct gspca_dev *gspca_dev);
106 static void setcolors(struct gspca_dev *gspca_dev);
107 static void setautobrightness(struct sd *sd);
108 static void setfreq(struct sd *sd);
110 static const struct ctrl sd_ctrls[] = {
113 .id = V4L2_CID_BRIGHTNESS,
114 .type = V4L2_CTRL_TYPE_INTEGER,
115 .name = "Brightness",
119 #define BRIGHTNESS_DEF 127
120 .default_value = BRIGHTNESS_DEF,
122 .set = sd_setbrightness,
123 .get = sd_getbrightness,
127 .id = V4L2_CID_CONTRAST,
128 .type = V4L2_CTRL_TYPE_INTEGER,
133 #define CONTRAST_DEF 127
134 .default_value = CONTRAST_DEF,
136 .set = sd_setcontrast,
137 .get = sd_getcontrast,
141 .id = V4L2_CID_SATURATION,
142 .type = V4L2_CTRL_TYPE_INTEGER,
147 #define COLOR_DEF 127
148 .default_value = COLOR_DEF,
153 /* The flip controls work with ov7670 only */
157 .id = V4L2_CID_HFLIP,
158 .type = V4L2_CTRL_TYPE_BOOLEAN,
164 .default_value = HFLIP_DEF,
172 .id = V4L2_CID_VFLIP,
173 .type = V4L2_CTRL_TYPE_BOOLEAN,
179 .default_value = VFLIP_DEF,
184 #define AUTOBRIGHT_IDX 5
187 .id = V4L2_CID_AUTOBRIGHTNESS,
188 .type = V4L2_CTRL_TYPE_BOOLEAN,
189 .name = "Auto Brightness",
193 #define AUTOBRIGHT_DEF 1
194 .default_value = AUTOBRIGHT_DEF,
196 .set = sd_setautobrightness,
197 .get = sd_getautobrightness,
202 .id = V4L2_CID_POWER_LINE_FREQUENCY,
203 .type = V4L2_CTRL_TYPE_MENU,
204 .name = "Light frequency filter",
206 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
209 .default_value = FREQ_DEF,
214 #define OV7670_FREQ_IDX 7
217 .id = V4L2_CID_POWER_LINE_FREQUENCY,
218 .type = V4L2_CTRL_TYPE_MENU,
219 .name = "Light frequency filter",
221 .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
223 #define OV7670_FREQ_DEF 3
224 .default_value = OV7670_FREQ_DEF,
231 static const struct v4l2_pix_format ov519_vga_mode[] = {
232 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
234 .sizeimage = 320 * 240 * 3 / 8 + 590,
235 .colorspace = V4L2_COLORSPACE_JPEG,
237 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
239 .sizeimage = 640 * 480 * 3 / 8 + 590,
240 .colorspace = V4L2_COLORSPACE_JPEG,
243 static const struct v4l2_pix_format ov519_sif_mode[] = {
244 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
246 .sizeimage = 160 * 120 * 3 / 8 + 590,
247 .colorspace = V4L2_COLORSPACE_JPEG,
249 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
251 .sizeimage = 176 * 144 * 3 / 8 + 590,
252 .colorspace = V4L2_COLORSPACE_JPEG,
254 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
256 .sizeimage = 320 * 240 * 3 / 8 + 590,
257 .colorspace = V4L2_COLORSPACE_JPEG,
259 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
261 .sizeimage = 352 * 288 * 3 / 8 + 590,
262 .colorspace = V4L2_COLORSPACE_JPEG,
266 static const struct v4l2_pix_format ov518_vga_mode[] = {
267 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
269 .sizeimage = 320 * 240 * 3 / 8 + 590,
270 .colorspace = V4L2_COLORSPACE_JPEG,
272 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
274 .sizeimage = 640 * 480 * 3 / 8 + 590,
275 .colorspace = V4L2_COLORSPACE_JPEG,
278 static const struct v4l2_pix_format ov518_sif_mode[] = {
279 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
282 .colorspace = V4L2_COLORSPACE_JPEG,
284 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
287 .colorspace = V4L2_COLORSPACE_JPEG,
289 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
291 .sizeimage = 320 * 240 * 3 / 8 + 590,
292 .colorspace = V4L2_COLORSPACE_JPEG,
294 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
296 .sizeimage = 352 * 288 * 3 / 8 + 590,
297 .colorspace = V4L2_COLORSPACE_JPEG,
302 /* Registers common to OV511 / OV518 */
303 #define R51x_SYS_RESET 0x50
304 #define R51x_SYS_INIT 0x53
305 #define R51x_SYS_SNAP 0x52
306 #define R51x_SYS_CUST_ID 0x5F
307 #define R51x_COMP_LUT_BEGIN 0x80
309 /* OV511 Camera interface register numbers */
310 #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
311 #define OV511_RESET_NOREGS 0x3F /* All but OV511 & regs */
313 /* OV518 Camera interface register numbers */
314 #define R518_GPIO_OUT 0x56 /* OV518(+) only */
315 #define R518_GPIO_CTL 0x57 /* OV518(+) only */
317 /* OV519 Camera interface register numbers */
318 #define OV519_R10_H_SIZE 0x10
319 #define OV519_R11_V_SIZE 0x11
320 #define OV519_R12_X_OFFSETL 0x12
321 #define OV519_R13_X_OFFSETH 0x13
322 #define OV519_R14_Y_OFFSETL 0x14
323 #define OV519_R15_Y_OFFSETH 0x15
324 #define OV519_R16_DIVIDER 0x16
325 #define OV519_R20_DFR 0x20
326 #define OV519_R25_FORMAT 0x25
328 /* OV519 System Controller register numbers */
329 #define OV519_SYS_RESET1 0x51
330 #define OV519_SYS_EN_CLK1 0x54
332 #define OV519_GPIO_DATA_OUT0 0x71
333 #define OV519_GPIO_IO_CTRL0 0x72
335 #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
338 #define R51x_I2C_W_SID 0x41
339 #define R51x_I2C_SADDR_3 0x42
340 #define R51x_I2C_SADDR_2 0x43
341 #define R51x_I2C_R_SID 0x44
342 #define R51x_I2C_DATA 0x45
343 #define R518_I2C_CTL 0x47 /* OV518(+) only */
346 #define OV7xx0_SID 0x42
347 #define OV8xx0_SID 0xa0
348 #define OV6xx0_SID 0xc0
350 /* OV7610 registers */
351 #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
352 #define OV7610_REG_BLUE 0x01 /* blue channel balance */
353 #define OV7610_REG_RED 0x02 /* red channel balance */
354 #define OV7610_REG_SAT 0x03 /* saturation */
355 #define OV8610_REG_HUE 0x04 /* 04 reserved */
356 #define OV7610_REG_CNT 0x05 /* Y contrast */
357 #define OV7610_REG_BRT 0x06 /* Y brightness */
358 #define OV7610_REG_COM_C 0x14 /* misc common regs */
359 #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
360 #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
361 #define OV7610_REG_COM_I 0x29 /* misc settings */
363 /* OV7670 registers */
364 #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
365 #define OV7670_REG_BLUE 0x01 /* blue gain */
366 #define OV7670_REG_RED 0x02 /* red gain */
367 #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
368 #define OV7670_REG_COM1 0x04 /* Control 1 */
369 #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
370 #define OV7670_REG_COM3 0x0c /* Control 3 */
371 #define OV7670_REG_COM4 0x0d /* Control 4 */
372 #define OV7670_REG_COM5 0x0e /* All "reserved" */
373 #define OV7670_REG_COM6 0x0f /* Control 6 */
374 #define OV7670_REG_AECH 0x10 /* More bits of AEC value */
375 #define OV7670_REG_CLKRC 0x11 /* Clock control */
376 #define OV7670_REG_COM7 0x12 /* Control 7 */
377 #define OV7670_COM7_FMT_VGA 0x00
378 #define OV7670_COM7_YUV 0x00 /* YUV */
379 #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
380 #define OV7670_COM7_FMT_MASK 0x38
381 #define OV7670_COM7_RESET 0x80 /* Register reset */
382 #define OV7670_REG_COM8 0x13 /* Control 8 */
383 #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
384 #define OV7670_COM8_AWB 0x02 /* White balance enable */
385 #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
386 #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
387 #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
388 #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
389 #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
390 #define OV7670_REG_COM10 0x15 /* Control 10 */
391 #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
392 #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
393 #define OV7670_REG_VSTART 0x19 /* Vert start high bits */
394 #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
395 #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
396 #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
397 #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
398 #define OV7670_REG_AEW 0x24 /* AGC upper limit */
399 #define OV7670_REG_AEB 0x25 /* AGC lower limit */
400 #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
401 #define OV7670_REG_HREF 0x32 /* HREF pieces */
402 #define OV7670_REG_TSLB 0x3a /* lots of stuff */
403 #define OV7670_REG_COM11 0x3b /* Control 11 */
404 #define OV7670_COM11_EXP 0x02
405 #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
406 #define OV7670_REG_COM12 0x3c /* Control 12 */
407 #define OV7670_REG_COM13 0x3d /* Control 13 */
408 #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
409 #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
410 #define OV7670_REG_COM14 0x3e /* Control 14 */
411 #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
412 #define OV7670_REG_COM15 0x40 /* Control 15 */
413 #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
414 #define OV7670_REG_COM16 0x41 /* Control 16 */
415 #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
416 #define OV7670_REG_BRIGHT 0x55 /* Brightness */
417 #define OV7670_REG_CONTRAS 0x56 /* Contrast control */
418 #define OV7670_REG_GFIX 0x69 /* Fix gain control */
419 #define OV7670_REG_RGB444 0x8c /* RGB 444 control */
420 #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
421 #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
422 #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
423 #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
424 #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
425 #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
426 #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
427 #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
428 #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
434 struct ov_i2c_regvals {
439 static const struct ov_i2c_regvals norm_6x20[] = {
440 { 0x12, 0x80 }, /* reset */
443 { 0x05, 0x7f }, /* For when autoadjust is off */
445 /* The ratio of 0x0c and 0x0d controls the white point */
448 { 0x0f, 0x15 }, /* COMS */
449 { 0x10, 0x75 }, /* AEC Exposure time */
450 { 0x12, 0x24 }, /* Enable AGC */
452 /* 0x16: 0x06 helps frame stability with moving objects */
454 /* { 0x20, 0x30 }, * Aperture correction enable */
455 { 0x26, 0xb2 }, /* BLC enable */
456 /* 0x28: 0x05 Selects RGB format if RGB on */
458 { 0x2a, 0x04 }, /* Disable framerate adjust */
459 /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
461 { 0x33, 0xa0 }, /* Color Processing Parameter */
462 { 0x34, 0xd2 }, /* Max A/D range */
466 { 0x3c, 0x39 }, /* Enable AEC mode changing */
467 { 0x3c, 0x3c }, /* Change AEC mode */
468 { 0x3c, 0x24 }, /* Disable AEC mode changing */
471 /* These next two registers (0x4a, 0x4b) are undocumented.
472 * They control the color balance */
475 { 0x4d, 0xd2 }, /* This reduces noise a bit */
478 /* Do 50-53 have any effect? */
479 /* Toggle 0x12[2] off and on here? */
482 static const struct ov_i2c_regvals norm_6x30[] = {
483 { 0x12, 0x80 }, /* Reset */
484 { 0x00, 0x1f }, /* Gain */
485 { 0x01, 0x99 }, /* Blue gain */
486 { 0x02, 0x7c }, /* Red gain */
487 { 0x03, 0xc0 }, /* Saturation */
488 { 0x05, 0x0a }, /* Contrast */
489 { 0x06, 0x95 }, /* Brightness */
490 { 0x07, 0x2d }, /* Sharpness */
493 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
496 { 0x11, 0x00 }, /* Pixel clock = fastest */
497 { 0x12, 0x24 }, /* Enable AGC and AWB */
512 { 0x23, 0xc0 }, /* Crystal circuit power level */
513 { 0x25, 0x9a }, /* Increase AEC black ratio */
514 { 0x26, 0xb2 }, /* BLC enable */
518 { 0x2a, 0x84 }, /* 60 Hz power */
519 { 0x2b, 0xa8 }, /* 60 Hz power */
521 { 0x2d, 0x95 }, /* Enable auto-brightness */
535 { 0x40, 0x00 }, /* White bal */
536 { 0x41, 0x00 }, /* White bal */
538 { 0x43, 0x3f }, /* White bal */
548 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
550 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
552 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
557 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
559 { 0x5b, 0x0f }, /* AWB chrominance levels */
563 { 0x12, 0x20 }, /* Toggle AWB */
567 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
569 * Register 0x0f in the 7610 has the following effects:
571 * 0x85 (AEC method 1): Best overall, good contrast range
572 * 0x45 (AEC method 2): Very overexposed
573 * 0xa5 (spec sheet default): Ok, but the black level is
574 * shifted resulting in loss of contrast
575 * 0x05 (old driver setting): very overexposed, too much
578 static const struct ov_i2c_regvals norm_7610[] = {
585 { 0x28, 0x24 }, /* 0c */
586 { 0x0f, 0x85 }, /* lg's setting */
608 static const struct ov_i2c_regvals norm_7620[] = {
609 { 0x00, 0x00 }, /* gain */
610 { 0x01, 0x80 }, /* blue gain */
611 { 0x02, 0x80 }, /* red gain */
612 { 0x03, 0xc0 }, /* OV7670_REG_VREF */
674 /* 7640 and 7648. The defaults should be OK for most registers. */
675 static const struct ov_i2c_regvals norm_7640[] = {
680 /* 7670. Defaults taken from OmniVision provided data,
681 * as provided by Jonathan Corbet of OLPC */
682 static const struct ov_i2c_regvals norm_7670[] = {
683 { OV7670_REG_COM7, OV7670_COM7_RESET },
684 { OV7670_REG_TSLB, 0x04 }, /* OV */
685 { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
686 { OV7670_REG_CLKRC, 0x01 },
688 * Set the hardware window. These values from OV don't entirely
689 * make sense - hstop is less than hstart. But they work...
691 { OV7670_REG_HSTART, 0x13 },
692 { OV7670_REG_HSTOP, 0x01 },
693 { OV7670_REG_HREF, 0xb6 },
694 { OV7670_REG_VSTART, 0x02 },
695 { OV7670_REG_VSTOP, 0x7a },
696 { OV7670_REG_VREF, 0x0a },
698 { OV7670_REG_COM3, 0x00 },
699 { OV7670_REG_COM14, 0x00 },
700 /* Mystery scaling numbers */
706 /* { OV7670_REG_COM10, 0x0 }, */
708 /* Gamma curve values */
726 /* AGC and AEC parameters. Note we start by disabling those features,
727 then turn them only after tweaking the values. */
728 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
729 | OV7670_COM8_AECSTEP
730 | OV7670_COM8_BFILT },
731 { OV7670_REG_GAIN, 0x00 },
732 { OV7670_REG_AECH, 0x00 },
733 { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
734 { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
735 { OV7670_REG_BD50MAX, 0x05 },
736 { OV7670_REG_BD60MAX, 0x07 },
737 { OV7670_REG_AEW, 0x95 },
738 { OV7670_REG_AEB, 0x33 },
739 { OV7670_REG_VPT, 0xe3 },
740 { OV7670_REG_HAECC1, 0x78 },
741 { OV7670_REG_HAECC2, 0x68 },
742 { 0xa1, 0x03 }, /* magic */
743 { OV7670_REG_HAECC3, 0xd8 },
744 { OV7670_REG_HAECC4, 0xd8 },
745 { OV7670_REG_HAECC5, 0xf0 },
746 { OV7670_REG_HAECC6, 0x90 },
747 { OV7670_REG_HAECC7, 0x94 },
748 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
749 | OV7670_COM8_AECSTEP
754 /* Almost all of these are magic "reserved" values. */
755 { OV7670_REG_COM5, 0x61 },
756 { OV7670_REG_COM6, 0x4b },
758 { OV7670_REG_MVFP, 0x07 },
767 { OV7670_REG_COM12, 0x78 },
770 { OV7670_REG_GFIX, 0x00 },
786 /* More reserved magic, some of which tweaks white balance */
803 /* "9e for advance AWB" */
805 { OV7670_REG_BLUE, 0x40 },
806 { OV7670_REG_RED, 0x60 },
807 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
808 | OV7670_COM8_AECSTEP
814 /* Matrix coefficients */
823 { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
824 { OV7670_REG_EDGE, 0x00 },
829 { OV7670_REG_COM13, OV7670_COM13_GAMMA
834 { OV7670_REG_COM16, 0x38 },
838 { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
851 /* Extra-weird stuff. Some sort of multiplexor register */
877 static const struct ov_i2c_regvals norm_8610[] = {
884 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
885 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
894 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
896 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
897 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
898 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
901 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
902 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
903 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
904 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
910 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
912 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
914 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
916 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
917 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
918 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
919 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
921 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
922 * maybe thats wrong */
926 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
930 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
931 * deleting bit7 colors the first images red */
932 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
933 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
939 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
941 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
946 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
948 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
949 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
956 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
962 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
965 static unsigned char ov7670_abs_to_sm(unsigned char v)
969 return (128 - v) | 0x80;
972 /* Write a OV519 register */
973 static int reg_w(struct sd *sd, __u16 index, __u8 value)
976 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 2 : 1;
978 sd->gspca_dev.usb_buf[0] = value;
979 ret = usb_control_msg(sd->gspca_dev.dev,
980 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
982 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
984 sd->gspca_dev.usb_buf, 1, 500);
986 PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
990 /* Read from a OV519 register */
991 /* returns: negative is error, pos or zero is data */
992 static int reg_r(struct sd *sd, __u16 index)
995 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 3 : 1;
997 ret = usb_control_msg(sd->gspca_dev.dev,
998 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1000 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1001 0, index, sd->gspca_dev.usb_buf, 1, 500);
1004 ret = sd->gspca_dev.usb_buf[0];
1006 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
1010 /* Read 8 values from a OV519 register */
1011 static int reg_r8(struct sd *sd,
1016 ret = usb_control_msg(sd->gspca_dev.dev,
1017 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1019 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1020 0, index, sd->gspca_dev.usb_buf, 8, 500);
1023 ret = sd->gspca_dev.usb_buf[0];
1025 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
1030 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1031 * the same position as 1's in "mask" are cleared and set to "value". Bits
1032 * that are in the same position as 0's in "mask" are preserved, regardless
1033 * of their respective state in "value".
1035 static int reg_w_mask(struct sd *sd,
1044 value &= mask; /* Enforce mask on value */
1045 ret = reg_r(sd, index);
1049 oldval = ret & ~mask; /* Clear the masked bits */
1050 value |= oldval; /* Set the desired bits */
1052 return reg_w(sd, index, value);
1056 * Writes multiple (n) byte value to a single register. Only valid with certain
1057 * registers (0x30 and 0xc4 - 0xce).
1059 static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
1063 *((u32 *)sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
1065 ret = usb_control_msg(sd->gspca_dev.dev,
1066 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1068 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1070 sd->gspca_dev.usb_buf, n, 500);
1072 PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value);
1078 * The OV518 I2C I/O procedure is different, hence, this function.
1079 * This is normally only called from i2c_w(). Note that this function
1080 * always succeeds regardless of whether the sensor is present and working.
1082 static int i2c_w(struct sd *sd,
1088 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
1090 /* Select camera register */
1091 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
1095 /* Write "value" to I2C data port of OV511 */
1096 rc = reg_w(sd, R51x_I2C_DATA, value);
1100 /* Initiate 3-byte write cycle */
1101 rc = reg_w(sd, R518_I2C_CTL, 0x01);
1105 /* wait for write complete */
1107 return reg_r8(sd, R518_I2C_CTL);
1111 * returns: negative is error, pos or zero is data
1113 * The OV518 I2C I/O procedure is different, hence, this function.
1114 * This is normally only called from i2c_r(). Note that this function
1115 * always succeeds regardless of whether the sensor is present and working.
1117 static int i2c_r(struct sd *sd, __u8 reg)
1121 /* Select camera register */
1122 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
1126 /* Initiate 2-byte write cycle */
1127 rc = reg_w(sd, R518_I2C_CTL, 0x03);
1131 /* Initiate 2-byte read cycle */
1132 rc = reg_w(sd, R518_I2C_CTL, 0x05);
1135 value = reg_r(sd, R51x_I2C_DATA);
1136 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
1140 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
1141 * the same position as 1's in "mask" are cleared and set to "value". Bits
1142 * that are in the same position as 0's in "mask" are preserved, regardless
1143 * of their respective state in "value".
1145 static int i2c_w_mask(struct sd *sd,
1153 value &= mask; /* Enforce mask on value */
1154 rc = i2c_r(sd, reg);
1157 oldval = rc & ~mask; /* Clear the masked bits */
1158 value |= oldval; /* Set the desired bits */
1159 return i2c_w(sd, reg, value);
1162 /* Temporarily stops OV511 from functioning. Must do this before changing
1163 * registers while the camera is streaming */
1164 static inline int ov51x_stop(struct sd *sd)
1166 PDEBUG(D_STREAM, "stopping");
1168 switch (sd->bridge) {
1170 case BRIDGE_OV511PLUS:
1171 return reg_w(sd, R51x_SYS_RESET, 0x3d);
1173 case BRIDGE_OV518PLUS:
1174 return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
1176 return reg_w(sd, OV519_SYS_RESET1, 0x0f);
1182 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1183 * actually stopped (for performance). */
1184 static inline int ov51x_restart(struct sd *sd)
1188 PDEBUG(D_STREAM, "restarting");
1193 /* Reinitialize the stream */
1194 switch (sd->bridge) {
1196 case BRIDGE_OV511PLUS:
1197 return reg_w(sd, R51x_SYS_RESET, 0x00);
1199 case BRIDGE_OV518PLUS:
1200 rc = reg_w(sd, 0x2f, 0x80);
1203 return reg_w(sd, R51x_SYS_RESET, 0x00);
1205 return reg_w(sd, OV519_SYS_RESET1, 0x00);
1211 /* This does an initial reset of an OmniVision sensor and ensures that I2C
1212 * is synchronized. Returns <0 on failure.
1214 static int init_ov_sensor(struct sd *sd)
1218 /* Reset the sensor */
1219 if (i2c_w(sd, 0x12, 0x80) < 0)
1222 /* Wait for it to initialize */
1225 for (i = 0; i < i2c_detect_tries; i++) {
1226 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
1227 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
1228 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
1232 /* Reset the sensor */
1233 if (i2c_w(sd, 0x12, 0x80) < 0)
1235 /* Wait for it to initialize */
1237 /* Dummy read to sync I2C */
1238 if (i2c_r(sd, 0x00) < 0)
1244 /* Set the read and write slave IDs. The "slave" argument is the write slave,
1245 * and the read slave will be set to (slave + 1).
1246 * This should not be called from outside the i2c I/O functions.
1247 * Sets I2C read and write slave IDs. Returns <0 for error
1249 static int ov51x_set_slave_ids(struct sd *sd,
1254 rc = reg_w(sd, R51x_I2C_W_SID, slave);
1257 return reg_w(sd, R51x_I2C_R_SID, slave + 1);
1260 static int write_regvals(struct sd *sd,
1261 const struct ov_regvals *regvals,
1267 rc = reg_w(sd, regvals->reg, regvals->val);
1275 static int write_i2c_regvals(struct sd *sd,
1276 const struct ov_i2c_regvals *regvals,
1282 rc = i2c_w(sd, regvals->reg, regvals->val);
1290 /****************************************************************************
1292 * OV511 and sensor configuration
1294 ***************************************************************************/
1296 /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
1297 * the same register settings as the OV8610, since they are very similar.
1299 static int ov8xx0_configure(struct sd *sd)
1303 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
1305 /* Detect sensor (sub)type */
1306 rc = i2c_r(sd, OV7610_REG_COM_I);
1308 PDEBUG(D_ERR, "Error detecting sensor type");
1311 if ((rc & 3) == 1) {
1312 sd->sensor = SEN_OV8610;
1314 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1318 /* Set sensor-specific vars */
1319 /* sd->sif = 0; already done */
1323 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
1324 * the same register settings as the OV7610, since they are very similar.
1326 static int ov7xx0_configure(struct sd *sd)
1331 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
1333 /* Detect sensor (sub)type */
1334 rc = i2c_r(sd, OV7610_REG_COM_I);
1337 * it appears to be wrongly detected as a 7610 by default */
1339 PDEBUG(D_ERR, "Error detecting sensor type");
1342 if ((rc & 3) == 3) {
1343 /* quick hack to make OV7670s work */
1344 high = i2c_r(sd, 0x0a);
1345 low = i2c_r(sd, 0x0b);
1346 /* info("%x, %x", high, low); */
1347 if (high == 0x76 && low == 0x73) {
1348 PDEBUG(D_PROBE, "Sensor is an OV7670");
1349 sd->sensor = SEN_OV7670;
1351 PDEBUG(D_PROBE, "Sensor is an OV7610");
1352 sd->sensor = SEN_OV7610;
1354 } else if ((rc & 3) == 1) {
1355 /* I don't know what's different about the 76BE yet. */
1356 if (i2c_r(sd, 0x15) & 1)
1357 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
1359 PDEBUG(D_PROBE, "Sensor is an OV76BE");
1361 /* OV511+ will return all zero isoc data unless we
1362 * configure the sensor as a 7620. Someone needs to
1363 * find the exact reg. setting that causes this. */
1364 sd->sensor = SEN_OV76BE;
1365 } else if ((rc & 3) == 0) {
1366 /* try to read product id registers */
1367 high = i2c_r(sd, 0x0a);
1369 PDEBUG(D_ERR, "Error detecting camera chip PID");
1372 low = i2c_r(sd, 0x0b);
1374 PDEBUG(D_ERR, "Error detecting camera chip VER");
1380 PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
1382 "7630 is not supported by this driver");
1385 PDEBUG(D_PROBE, "Sensor is an OV7645");
1386 sd->sensor = SEN_OV7640; /* FIXME */
1389 PDEBUG(D_PROBE, "Sensor is an OV7645B");
1390 sd->sensor = SEN_OV7640; /* FIXME */
1393 PDEBUG(D_PROBE, "Sensor is an OV7648");
1394 sd->sensor = SEN_OV7640; /* FIXME */
1397 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
1401 PDEBUG(D_PROBE, "Sensor is an OV7620");
1402 sd->sensor = SEN_OV7620;
1405 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1409 /* Set sensor-specific vars */
1410 /* sd->sif = 0; already done */
1414 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
1415 static int ov6xx0_configure(struct sd *sd)
1418 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
1420 /* Detect sensor (sub)type */
1421 rc = i2c_r(sd, OV7610_REG_COM_I);
1423 PDEBUG(D_ERR, "Error detecting sensor type");
1427 /* Ugh. The first two bits are the version bits, but
1428 * the entire register value must be used. I guess OVT
1429 * underestimated how many variants they would make. */
1432 sd->sensor = SEN_OV6630;
1434 "WARNING: Sensor is an OV66308. Your camera may have");
1435 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
1438 sd->sensor = SEN_OV6620;
1439 PDEBUG(D_PROBE, "Sensor is an OV6620");
1442 sd->sensor = SEN_OV6630;
1443 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
1446 sd->sensor = SEN_OV66308AF;
1447 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
1450 sd->sensor = SEN_OV6630;
1452 "WARNING: Sensor is an OV66307. Your camera may have");
1453 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
1456 PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
1460 /* Set sensor-specific vars */
1466 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
1467 static void ov51x_led_control(struct sd *sd, int on)
1469 switch (sd->bridge) {
1470 /* OV511 has no LED control */
1471 case BRIDGE_OV511PLUS:
1472 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
1475 case BRIDGE_OV518PLUS:
1476 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
1479 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
1484 /* OV518 quantization tables are 8x4 (instead of 8x8) */
1485 static int ov518_upload_quan_tables(struct sd *sd)
1487 const unsigned char yQuanTable518[] = {
1488 5, 4, 5, 6, 6, 7, 7, 7,
1489 5, 5, 5, 5, 6, 7, 7, 7,
1490 6, 6, 6, 6, 7, 7, 7, 8,
1491 7, 7, 6, 7, 7, 7, 8, 8
1494 const unsigned char uvQuanTable518[] = {
1495 6, 6, 6, 7, 7, 7, 7, 7,
1496 6, 6, 6, 7, 7, 7, 7, 7,
1497 6, 6, 6, 7, 7, 7, 7, 8,
1498 7, 7, 7, 7, 7, 7, 8, 8
1501 const unsigned char *pYTable = yQuanTable518;
1502 const unsigned char *pUVTable = uvQuanTable518;
1503 unsigned char val0, val1;
1504 int i, rc, reg = R51x_COMP_LUT_BEGIN;
1506 PDEBUG(D_PROBE, "Uploading quantization tables");
1508 for (i = 0; i < 16; i++) {
1514 rc = reg_w(sd, reg, val0);
1523 rc = reg_w(sd, reg + 16, val0);
1533 /* This initializes the OV518/OV518+ and the sensor */
1534 static int ov518_configure(struct gspca_dev *gspca_dev)
1536 struct sd *sd = (struct sd *) gspca_dev;
1539 /* For 518 and 518+ */
1540 static struct ov_regvals init_518[] = {
1541 { R51x_SYS_RESET, 0x40 },
1542 { R51x_SYS_INIT, 0xe1 },
1543 { R51x_SYS_RESET, 0x3e },
1544 { R51x_SYS_INIT, 0xe1 },
1545 { R51x_SYS_RESET, 0x00 },
1546 { R51x_SYS_INIT, 0xe1 },
1551 static struct ov_regvals norm_518[] = {
1552 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1553 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1564 static struct ov_regvals norm_518_p[] = {
1565 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1566 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1583 /* First 5 bits of custom ID reg are a revision ID on OV518 */
1584 PDEBUG(D_PROBE, "Device revision %d",
1585 0x1F & reg_r(sd, R51x_SYS_CUST_ID));
1587 rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
1591 /* Set LED GPIO pin to output mode */
1592 rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
1596 switch (sd->bridge) {
1598 rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
1602 case BRIDGE_OV518PLUS:
1603 rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
1609 rc = ov518_upload_quan_tables(sd);
1611 PDEBUG(D_ERR, "Error uploading quantization tables");
1615 rc = reg_w(sd, 0x2f, 0x80);
1622 static int ov519_configure(struct sd *sd)
1624 static const struct ov_regvals init_519[] = {
1625 { 0x5a, 0x6d }, /* EnableSystem */
1627 { 0x54, 0xff }, /* set bit2 to enable jpeg */
1631 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
1632 * detection will fail. This deserves further investigation. */
1633 { OV519_GPIO_IO_CTRL0, 0xee },
1634 { 0x51, 0x0f }, /* SetUsbInit */
1637 /* windows reads 0x55 at this point*/
1640 return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
1643 /* this function is called at probe time */
1644 static int sd_config(struct gspca_dev *gspca_dev,
1645 const struct usb_device_id *id)
1647 struct sd *sd = (struct sd *) gspca_dev;
1651 sd->bridge = id->driver_info;
1653 switch (sd->bridge) {
1655 case BRIDGE_OV518PLUS:
1656 ret = ov518_configure(gspca_dev);
1659 ret = ov519_configure(sd);
1666 ov51x_led_control(sd, 0); /* turn LED off */
1669 if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0)
1672 /* The OV519 must be more aggressive about sensor detection since
1673 * I2C write will never fail if the sensor is not present. We have
1674 * to try to initialize the sensor to detect its presence */
1675 if (init_ov_sensor(sd) >= 0) {
1676 if (ov7xx0_configure(sd) < 0) {
1677 PDEBUG(D_ERR, "Failed to configure OV7xx0");
1683 if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0)
1686 if (init_ov_sensor(sd) >= 0) {
1687 if (ov6xx0_configure(sd) < 0) {
1688 PDEBUG(D_ERR, "Failed to configure OV6xx0");
1694 if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0)
1697 if (init_ov_sensor(sd) < 0) {
1699 "Can't determine sensor slave IDs");
1702 if (ov8xx0_configure(sd) < 0) {
1704 "Failed to configure OV8xx0 sensor");
1710 cam = &gspca_dev->cam;
1711 switch (sd->bridge) {
1713 case BRIDGE_OV518PLUS:
1715 cam->cam_mode = ov518_vga_mode;
1716 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
1718 cam->cam_mode = ov518_sif_mode;
1719 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
1724 cam->cam_mode = ov519_vga_mode;
1725 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
1727 cam->cam_mode = ov519_sif_mode;
1728 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
1732 sd->brightness = BRIGHTNESS_DEF;
1733 sd->contrast = CONTRAST_DEF;
1734 sd->colors = COLOR_DEF;
1735 sd->hflip = HFLIP_DEF;
1736 sd->vflip = VFLIP_DEF;
1737 sd->autobrightness = AUTOBRIGHT_DEF;
1738 if (sd->sensor == SEN_OV7670) {
1739 sd->freq = OV7670_FREQ_DEF;
1740 gspca_dev->ctrl_dis = 1 << FREQ_IDX;
1742 sd->freq = FREQ_DEF;
1743 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
1744 (1 << OV7670_FREQ_IDX);
1746 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
1747 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
1748 /* OV8610 Frequency filter control should work but needs testing */
1749 if (sd->sensor == SEN_OV8610)
1750 gspca_dev->ctrl_dis |= 1 << FREQ_IDX;
1754 PDEBUG(D_ERR, "OV519 Config failed");
1758 /* this function is called at probe and resume time */
1759 static int sd_init(struct gspca_dev *gspca_dev)
1761 struct sd *sd = (struct sd *) gspca_dev;
1763 /* initialize the sensor */
1764 switch (sd->sensor) {
1766 if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
1771 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
1775 /* case SEN_OV7610: */
1776 /* case SEN_OV76BE: */
1777 if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
1781 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
1785 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
1789 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
1793 if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
1800 /* Sets up the OV518/OV518+ with the given image parameters
1802 * OV518 needs a completely different approach, until we can figure out what
1803 * the individual registers do. Also, only 15 FPS is supported now.
1805 * Do not put any sensor-specific code in here (including I2C I/O functions)
1807 static int ov518_mode_init_regs(struct sd *sd)
1811 /******** Set the mode ********/
1822 if (sd->bridge == BRIDGE_OV518) {
1823 /* Set 8-bit (YVYU) input format */
1824 reg_w_mask(sd, 0x20, 0x08, 0x08);
1826 /* Set 12-bit (4:2:0) output format */
1827 reg_w_mask(sd, 0x28, 0x80, 0xf0);
1828 reg_w_mask(sd, 0x38, 0x80, 0xf0);
1830 reg_w(sd, 0x28, 0x80);
1831 reg_w(sd, 0x38, 0x80);
1834 hsegs = sd->gspca_dev.width / 16;
1835 vsegs = sd->gspca_dev.height / 4;
1837 reg_w(sd, 0x29, hsegs);
1838 reg_w(sd, 0x2a, vsegs);
1840 reg_w(sd, 0x39, hsegs);
1841 reg_w(sd, 0x3a, vsegs);
1843 /* Windows driver does this here; who knows why */
1844 reg_w(sd, 0x2f, 0x80);
1846 /******** Set the framerate (to 30 FPS) ********/
1847 if (sd->bridge == BRIDGE_OV518PLUS)
1852 /* Mode independent, but framerate dependent, regs */
1853 reg_w(sd, 0x51, 0x04); /* Clock divider; lower==faster */
1854 reg_w(sd, 0x22, 0x18);
1855 reg_w(sd, 0x23, 0xff);
1857 if (sd->bridge == BRIDGE_OV518PLUS)
1858 reg_w(sd, 0x21, 0x19);
1860 reg_w(sd, 0x71, 0x17); /* Compression-related? */
1862 /* FIXME: Sensor-specific */
1863 /* Bit 5 is what matters here. Of course, it is "reserved" */
1864 i2c_w(sd, 0x54, 0x23);
1866 reg_w(sd, 0x2f, 0x80);
1868 if (sd->bridge == BRIDGE_OV518PLUS) {
1869 reg_w(sd, 0x24, 0x94);
1870 reg_w(sd, 0x25, 0x90);
1871 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
1872 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
1873 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
1874 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
1875 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
1876 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
1877 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
1878 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
1879 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
1881 reg_w(sd, 0x24, 0x9f);
1882 reg_w(sd, 0x25, 0x90);
1883 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
1884 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
1885 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
1886 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
1887 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
1888 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
1889 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
1890 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
1891 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
1894 reg_w(sd, 0x2f, 0x80);
1900 /* Sets up the OV519 with the given image parameters
1902 * OV519 needs a completely different approach, until we can figure out what
1903 * the individual registers do.
1905 * Do not put any sensor-specific code in here (including I2C I/O functions)
1907 static int ov519_mode_init_regs(struct sd *sd)
1909 static const struct ov_regvals mode_init_519_ov7670[] = {
1910 { 0x5d, 0x03 }, /* Turn off suspend mode */
1911 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
1912 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
1913 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
1917 { 0x37, 0x00 }, /* SetUsbInit */
1918 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
1919 /* Enable both fields, YUV Input, disable defect comp (why?) */
1923 { 0x17, 0x50 }, /* undocumented */
1924 { 0x37, 0x00 }, /* undocumented */
1925 { 0x40, 0xff }, /* I2C timeout counter */
1926 { 0x46, 0x00 }, /* I2C clock prescaler */
1927 { 0x59, 0x04 }, /* new from windrv 090403 */
1928 { 0xff, 0x00 }, /* undocumented */
1929 /* windows reads 0x55 at this point, why? */
1932 static const struct ov_regvals mode_init_519[] = {
1933 { 0x5d, 0x03 }, /* Turn off suspend mode */
1934 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
1935 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
1936 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
1940 { 0x37, 0x00 }, /* SetUsbInit */
1941 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
1942 /* Enable both fields, YUV Input, disable defect comp (why?) */
1944 { 0x17, 0x50 }, /* undocumented */
1945 { 0x37, 0x00 }, /* undocumented */
1946 { 0x40, 0xff }, /* I2C timeout counter */
1947 { 0x46, 0x00 }, /* I2C clock prescaler */
1948 { 0x59, 0x04 }, /* new from windrv 090403 */
1949 { 0xff, 0x00 }, /* undocumented */
1950 /* windows reads 0x55 at this point, why? */
1953 /******** Set the mode ********/
1954 if (sd->sensor != SEN_OV7670) {
1955 if (write_regvals(sd, mode_init_519,
1956 ARRAY_SIZE(mode_init_519)))
1958 if (sd->sensor == SEN_OV7640) {
1959 /* Select 8-bit input mode */
1960 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
1963 if (write_regvals(sd, mode_init_519_ov7670,
1964 ARRAY_SIZE(mode_init_519_ov7670)))
1968 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
1969 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
1970 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
1971 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
1972 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
1973 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
1974 reg_w(sd, OV519_R16_DIVIDER, 0x00);
1975 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
1976 reg_w(sd, 0x26, 0x00); /* Undocumented */
1978 /******** Set the framerate ********/
1980 sd->frame_rate = frame_rate;
1982 /* FIXME: These are only valid at the max resolution. */
1984 switch (sd->sensor) {
1986 switch (sd->frame_rate) {
1989 reg_w(sd, 0xa4, 0x0c);
1990 reg_w(sd, 0x23, 0xff);
1993 reg_w(sd, 0xa4, 0x0c);
1994 reg_w(sd, 0x23, 0x1f);
1997 reg_w(sd, 0xa4, 0x0c);
1998 reg_w(sd, 0x23, 0x1b);
2001 reg_w(sd, 0xa4, 0x04);
2002 reg_w(sd, 0x23, 0xff);
2006 reg_w(sd, 0xa4, 0x04);
2007 reg_w(sd, 0x23, 0x1f);
2011 reg_w(sd, 0xa4, 0x04);
2012 reg_w(sd, 0x23, 0x1b);
2018 switch (sd->frame_rate) {
2019 default: /* 15 fps */
2021 reg_w(sd, 0xa4, 0x06);
2022 reg_w(sd, 0x23, 0xff);
2025 reg_w(sd, 0xa4, 0x06);
2026 reg_w(sd, 0x23, 0x1f);
2029 reg_w(sd, 0xa4, 0x06);
2030 reg_w(sd, 0x23, 0x1b);
2034 case SEN_OV7670: /* guesses, based on 7640 */
2035 PDEBUG(D_STREAM, "Setting framerate to %d fps",
2036 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
2037 reg_w(sd, 0xa4, 0x10);
2038 switch (sd->frame_rate) {
2040 reg_w(sd, 0x23, 0xff);
2043 reg_w(sd, 0x23, 0x1b);
2047 reg_w(sd, 0x23, 0xff);
2056 static int mode_init_ov_sensor_regs(struct sd *sd)
2058 struct gspca_dev *gspca_dev;
2061 gspca_dev = &sd->gspca_dev;
2062 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
2064 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2065 switch (sd->sensor) {
2067 /* For OV8610 qvga means qsvga */
2068 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
2071 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2074 /* i2c_w(sd, 0x2b, 0x00); */
2075 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2076 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2077 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
2078 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
2079 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
2080 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
2081 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
2084 /* i2c_w(sd, 0x2b, 0x00); */
2085 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2088 /* i2c_w(sd, 0x2b, 0x00); */
2089 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2090 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2091 /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
2092 /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
2093 /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
2094 /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
2095 /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
2098 /* set COM7_FMT_VGA or COM7_FMT_QVGA
2099 * do we need to set anything else?
2100 * HSTART etc are set in set_ov_sensor_window itself */
2101 i2c_w_mask(sd, OV7670_REG_COM7,
2102 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
2103 OV7670_COM7_FMT_MASK);
2108 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2114 /******** Palette-specific regs ********/
2115 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
2116 /* not valid on the OV6620/OV7620/6630? */
2117 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
2120 /* The OV518 needs special treatment. Although both the OV518
2121 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2122 * bus is actually used. The UV bus is tied to ground.
2123 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2126 /* OV7640 is 8-bit only */
2128 if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV66308AF &&
2129 sd->sensor != SEN_OV7640)
2130 i2c_w_mask(sd, 0x13, 0x00, 0x20);
2132 /******** Clock programming ********/
2133 /* The OV6620 needs special handling. This prevents the
2134 * severe banding that normally occurs */
2135 if (sd->sensor == SEN_OV6620) {
2138 i2c_w(sd, 0x2a, 0x04);
2139 i2c_w(sd, 0x11, sd->clockdiv);
2140 i2c_w(sd, 0x2a, 0x84);
2141 /* This next setting is critical. It seems to improve
2142 * the gain or the contrast. The "reserved" bits seem
2143 * to have some effect in this case. */
2144 i2c_w(sd, 0x2d, 0x85);
2146 i2c_w(sd, 0x11, sd->clockdiv);
2149 /******** Special Features ********/
2150 /* no evidence this is possible with OV7670, either */
2152 if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
2153 i2c_w_mask(sd, 0x12, 0x00, 0x02);
2155 /* Enable auto white balance */
2156 if (sd->sensor == SEN_OV7670)
2157 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
2160 i2c_w_mask(sd, 0x12, 0x04, 0x04);
2162 /* This will go away as soon as ov51x_mode_init_sensor_regs() */
2163 /* is fully tested. */
2164 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2165 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
2167 i2c_w(sd, 0x35, 0x9e);
2169 i2c_w(sd, 0x35, 0x1e);
2174 static void sethvflip(struct sd *sd)
2176 if (sd->sensor != SEN_OV7670)
2178 if (sd->gspca_dev.streaming)
2180 i2c_w_mask(sd, OV7670_REG_MVFP,
2181 OV7670_MVFP_MIRROR * sd->hflip
2182 | OV7670_MVFP_VFLIP * sd->vflip,
2183 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
2184 if (sd->gspca_dev.streaming)
2188 static int set_ov_sensor_window(struct sd *sd)
2190 struct gspca_dev *gspca_dev;
2192 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
2193 int ret, hstart, hstop, vstop, vstart;
2196 gspca_dev = &sd->gspca_dev;
2197 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
2198 crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2;
2200 /* The different sensor ICs handle setting up of window differently.
2201 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
2202 switch (sd->sensor) {
2213 vwsbase = vwebase = 0x05;
2222 if (sd->sensor == SEN_OV66308AF && qvga)
2223 /* HDG: this fixes U and V getting swapped */
2233 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2235 vwsbase = vwebase = 0x05;
2240 vwsbase = vwebase = 0x03;
2243 /*handling of OV7670 hardware sensor start and stop values
2244 * is very odd, compared to the other OV sensors */
2245 vwsbase = vwebase = hwebase = hwsbase = 0x00;
2251 switch (sd->sensor) {
2255 if (qvga) { /* QCIF */
2260 vwscale = 1; /* The datasheet says 0;
2265 if (qvga) { /* QSVGA */
2273 default: /* SEN_OV7xx0 */
2274 if (qvga) { /* QVGA */
2283 ret = mode_init_ov_sensor_regs(sd);
2287 if (sd->sensor == SEN_OV8610) {
2288 i2c_w_mask(sd, 0x2d, 0x05, 0x40);
2289 /* old 0x95, new 0x05 from windrv 090403 */
2290 /* bits 5-7: reserved */
2291 i2c_w_mask(sd, 0x28, 0x20, 0x20);
2292 /* bit 5: progressive mode on */
2295 /* The below is wrong for OV7670s because their window registers
2296 * only store the high bits in 0x17 to 0x1a */
2298 /* SRH Use sd->max values instead of requested win values */
2299 /* SCS Since we're sticking with only the max hardware widths
2300 * for a given mode */
2301 /* I can hard code this for OV7670s */
2302 /* Yes, these numbers do look odd, but they're tested and work! */
2303 if (sd->sensor == SEN_OV7670) {
2304 if (qvga) { /* QVGA from ov7670.c by
2305 * Jonathan Corbet */
2316 /* OV7670 hardware window registers are split across
2317 * multiple locations */
2318 i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
2319 i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
2320 v = i2c_r(sd, OV7670_REG_HREF);
2321 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
2322 msleep(10); /* need to sleep between read and write to
2324 i2c_w(sd, OV7670_REG_HREF, v);
2326 i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
2327 i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
2328 v = i2c_r(sd, OV7670_REG_VREF);
2329 v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
2330 msleep(10); /* need to sleep between read and write to
2332 i2c_w(sd, OV7670_REG_VREF, v);
2334 i2c_w(sd, 0x17, hwsbase);
2335 i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
2336 i2c_w(sd, 0x19, vwsbase);
2337 i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
2342 /* -- start the camera -- */
2343 static int sd_start(struct gspca_dev *gspca_dev)
2345 struct sd *sd = (struct sd *) gspca_dev;
2348 switch (sd->bridge) {
2350 case BRIDGE_OV518PLUS:
2351 ret = ov518_mode_init_regs(sd);
2354 ret = ov519_mode_init_regs(sd);
2360 ret = set_ov_sensor_window(sd);
2364 setcontrast(gspca_dev);
2365 setbrightness(gspca_dev);
2366 setcolors(gspca_dev);
2368 setautobrightness(sd);
2371 ret = ov51x_restart(sd);
2374 ov51x_led_control(sd, 1);
2377 PDEBUG(D_ERR, "camera start error:%d", ret);
2381 static void sd_stopN(struct gspca_dev *gspca_dev)
2383 struct sd *sd = (struct sd *) gspca_dev;
2386 ov51x_led_control(sd, 0);
2389 static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
2390 struct gspca_frame *frame, /* target */
2391 __u8 *data, /* isoc packet */
2392 int len) /* iso packet length */
2394 PDEBUG(D_STREAM, "ov518_pkt_scan: %d bytes", len);
2398 PDEBUG(D_STREAM, "packet number: %d\n", (int)data[len]);
2401 /* A false positive here is likely, until OVT gives me
2402 * the definitive SOF/EOF format */
2403 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
2404 gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0);
2405 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, 0);
2408 /* intermediate packet */
2409 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
2412 static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
2413 struct gspca_frame *frame, /* target */
2414 __u8 *data, /* isoc packet */
2415 int len) /* iso packet length */
2417 /* Header of ov519 is 16 bytes:
2418 * Byte Value Description
2422 * 3 0xXX 0x50 = SOF, 0x51 = EOF
2423 * 9 0xXX 0x01 initial frame without data,
2424 * 0x00 standard frame with image
2425 * 14 Lo in EOF: length of image data / 8
2429 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
2431 case 0x50: /* start of frame */
2436 if (data[0] == 0xff || data[1] == 0xd8)
2437 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
2440 gspca_dev->last_packet_type = DISCARD_PACKET;
2442 case 0x51: /* end of frame */
2444 gspca_dev->last_packet_type = DISCARD_PACKET;
2445 gspca_frame_add(gspca_dev, LAST_PACKET, frame,
2451 /* intermediate packet */
2452 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
2456 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2457 struct gspca_frame *frame, /* target */
2458 __u8 *data, /* isoc packet */
2459 int len) /* iso packet length */
2461 struct sd *sd = (struct sd *) gspca_dev;
2463 switch (sd->bridge) {
2465 case BRIDGE_OV511PLUS:
2468 case BRIDGE_OV518PLUS:
2469 ov518_pkt_scan(gspca_dev, frame, data, len);
2472 ov519_pkt_scan(gspca_dev, frame, data, len);
2477 /* -- management routines -- */
2479 static void setbrightness(struct gspca_dev *gspca_dev)
2481 struct sd *sd = (struct sd *) gspca_dev;
2484 val = sd->brightness;
2485 switch (sd->sensor) {
2493 i2c_w(sd, OV7610_REG_BRT, val);
2496 /* 7620 doesn't like manual changes when in auto mode */
2497 if (!sd->autobrightness)
2498 i2c_w(sd, OV7610_REG_BRT, val);
2502 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
2503 i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
2508 static void setcontrast(struct gspca_dev *gspca_dev)
2510 struct sd *sd = (struct sd *) gspca_dev;
2514 switch (sd->sensor) {
2517 i2c_w(sd, OV7610_REG_CNT, val);
2521 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
2524 static const __u8 ctab[] = {
2525 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
2528 /* Use Y gamma control instead. Bit 0 enables it. */
2529 i2c_w(sd, 0x64, ctab[val >> 5]);
2533 static const __u8 ctab[] = {
2534 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
2535 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
2538 /* Use Y gamma control instead. Bit 0 enables it. */
2539 i2c_w(sd, 0x64, ctab[val >> 4]);
2543 /* Use gain control instead. */
2544 i2c_w(sd, OV7610_REG_GAIN, val >> 2);
2547 /* check that this isn't just the same as ov7610 */
2548 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
2553 static void setcolors(struct gspca_dev *gspca_dev)
2555 struct sd *sd = (struct sd *) gspca_dev;
2559 switch (sd->sensor) {
2566 i2c_w(sd, OV7610_REG_SAT, val);
2569 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
2570 /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
2573 i2c_w(sd, OV7610_REG_SAT, val);
2576 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
2579 /* supported later once I work out how to do it
2580 * transparently fail now! */
2581 /* set REG_COM13 values for UV sat auto mode */
2586 static void setautobrightness(struct sd *sd)
2588 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
2591 i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10);
2594 static void setfreq(struct sd *sd)
2596 if (sd->sensor == SEN_OV7670) {
2598 case 0: /* Banding filter disabled */
2599 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
2602 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
2604 i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18);
2607 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
2609 i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18);
2611 case 3: /* Auto hz */
2612 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
2614 i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO,
2620 case 0: /* Banding filter disabled */
2621 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
2622 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
2624 case 1: /* 50 hz (filter on and framerate adj) */
2625 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
2626 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
2627 /* 20 fps -> 16.667 fps */
2628 if (sd->sensor == SEN_OV6620 ||
2629 sd->sensor == SEN_OV6630 ||
2630 sd->sensor == SEN_OV66308AF)
2631 i2c_w(sd, 0x2b, 0x5e);
2633 i2c_w(sd, 0x2b, 0xac);
2635 case 2: /* 60 hz (filter on, ...) */
2636 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
2637 if (sd->sensor == SEN_OV6620 ||
2638 sd->sensor == SEN_OV6630 ||
2639 sd->sensor == SEN_OV66308AF) {
2640 /* 20 fps -> 15 fps */
2641 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
2642 i2c_w(sd, 0x2b, 0xa8);
2644 /* no framerate adj. */
2645 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
2652 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2654 struct sd *sd = (struct sd *) gspca_dev;
2656 sd->brightness = val;
2657 if (gspca_dev->streaming)
2658 setbrightness(gspca_dev);
2662 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2664 struct sd *sd = (struct sd *) gspca_dev;
2666 *val = sd->brightness;
2670 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2672 struct sd *sd = (struct sd *) gspca_dev;
2675 if (gspca_dev->streaming)
2676 setcontrast(gspca_dev);
2680 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2682 struct sd *sd = (struct sd *) gspca_dev;
2684 *val = sd->contrast;
2688 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2690 struct sd *sd = (struct sd *) gspca_dev;
2693 if (gspca_dev->streaming)
2694 setcolors(gspca_dev);
2698 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2700 struct sd *sd = (struct sd *) gspca_dev;
2706 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
2708 struct sd *sd = (struct sd *) gspca_dev;
2711 if (gspca_dev->streaming)
2716 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
2718 struct sd *sd = (struct sd *) gspca_dev;
2724 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2726 struct sd *sd = (struct sd *) gspca_dev;
2729 if (gspca_dev->streaming)
2734 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2736 struct sd *sd = (struct sd *) gspca_dev;
2742 static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
2744 struct sd *sd = (struct sd *) gspca_dev;
2746 sd->autobrightness = val;
2747 if (gspca_dev->streaming)
2748 setautobrightness(sd);
2752 static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
2754 struct sd *sd = (struct sd *) gspca_dev;
2756 *val = sd->autobrightness;
2760 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2762 struct sd *sd = (struct sd *) gspca_dev;
2765 if (gspca_dev->streaming)
2770 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2772 struct sd *sd = (struct sd *) gspca_dev;
2778 static int sd_querymenu(struct gspca_dev *gspca_dev,
2779 struct v4l2_querymenu *menu)
2781 struct sd *sd = (struct sd *) gspca_dev;
2784 case V4L2_CID_POWER_LINE_FREQUENCY:
2785 switch (menu->index) {
2786 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2787 strcpy((char *) menu->name, "NoFliker");
2789 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2790 strcpy((char *) menu->name, "50 Hz");
2792 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2793 strcpy((char *) menu->name, "60 Hz");
2796 if (sd->sensor != SEN_OV7670)
2799 strcpy((char *) menu->name, "Automatic");
2807 /* sub-driver description */
2808 static const struct sd_desc sd_desc = {
2809 .name = MODULE_NAME,
2811 .nctrls = ARRAY_SIZE(sd_ctrls),
2812 .config = sd_config,
2816 .pkt_scan = sd_pkt_scan,
2817 .querymenu = sd_querymenu,
2820 /* -- module initialisation -- */
2821 static const __devinitdata struct usb_device_id device_table[] = {
2822 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
2823 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
2824 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
2825 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
2826 {USB_DEVICE(0x041e, 0x4064), .driver_info = BRIDGE_OV519 },
2827 {USB_DEVICE(0x041e, 0x4068), .driver_info = BRIDGE_OV519 },
2828 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
2829 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
2830 {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 },
2831 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
2832 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
2833 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
2834 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
2835 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
2836 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
2840 MODULE_DEVICE_TABLE(usb, device_table);
2842 /* -- device connect -- */
2843 static int sd_probe(struct usb_interface *intf,
2844 const struct usb_device_id *id)
2846 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2850 static struct usb_driver sd_driver = {
2851 .name = MODULE_NAME,
2852 .id_table = device_table,
2854 .disconnect = gspca_disconnect,
2856 .suspend = gspca_suspend,
2857 .resume = gspca_resume,
2861 /* -- module insert / remove -- */
2862 static int __init sd_mod_init(void)
2865 ret = usb_register(&sd_driver);
2868 PDEBUG(D_PROBE, "registered");
2871 static void __exit sd_mod_exit(void)
2873 usb_deregister(&sd_driver);
2874 PDEBUG(D_PROBE, "deregistered");
2877 module_init(sd_mod_init);
2878 module_exit(sd_mod_exit);
2880 module_param(frame_rate, int, 0644);
2881 MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");