4 * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
5 * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com>
7 * This module is adapted from the ov51x-jpeg package, which itself
8 * was adapted from the ov511 driver.
10 * Original copyright for the ov511 driver is:
12 * Copyright (c) 1999-2006 Mark W. McClelland
13 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
14 * Many improvements by Bret Wallach <bwallac1@san.rr.com>
15 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
16 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
17 * Changes by Claudio Matsuoka <claudio@conectiva.com>
19 * ov51x-jpeg original copyright is:
21 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
22 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 #define MODULE_NAME "ov519"
41 #include <linux/input.h>
44 /* The jpeg_hdr is used by w996Xcf only */
45 /* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
49 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
50 MODULE_DESCRIPTION("OV519 USB Camera Driver");
51 MODULE_LICENSE("GPL");
53 /* global parameters */
54 static int frame_rate;
56 /* Number of times to retry a failed I2C transaction. Increase this if you
57 * are getting "Failed to read sensor ID..." */
58 static int i2c_detect_tries = 10;
69 NCTRL /* number of controls */
72 /* ov519 device descriptor */
74 struct gspca_dev gspca_dev; /* !! must be the first item */
76 struct gspca_ctrl ctrls[NCTRL];
81 #define BRIDGE_OV511 0
82 #define BRIDGE_OV511PLUS 1
83 #define BRIDGE_OV518 2
84 #define BRIDGE_OV518PLUS 3
85 #define BRIDGE_OV519 4
86 #define BRIDGE_OVFX2 5
87 #define BRIDGE_W9968CF 6
91 #define BRIDGE_INVERT_LED 8
93 char snapshot_pressed;
94 char snapshot_needs_reset;
96 /* Determined by sensor type */
100 #define QUALITY_MIN 50
101 #define QUALITY_MAX 70
102 #define QUALITY_DEF 50
104 u8 stopped; /* Streaming is temporarily paused */
107 u8 frame_rate; /* current Framerate */
108 u8 clockdiv; /* clockdiv override */
110 s8 sensor; /* Type of image sensor chip (SEN_*) */
115 s16 sensor_reg_cache[256];
117 u8 jpeg_hdr[JPEG_HDR_SZ];
135 /* Note this is a bit of a hack, but the w9968cf driver needs the code for all
136 the ov sensors which is already present here. When we have the time we
137 really should move the sensor drivers to v4l2 sub drivers. */
140 /* V4L2 controls supported by the driver */
141 static void setbrightness(struct gspca_dev *gspca_dev);
142 static void setcontrast(struct gspca_dev *gspca_dev);
143 static void setcolors(struct gspca_dev *gspca_dev);
144 static void sethvflip(struct gspca_dev *gspca_dev);
145 static void setautobright(struct gspca_dev *gspca_dev);
146 static void setfreq(struct gspca_dev *gspca_dev);
147 static void setfreq_i(struct sd *sd);
149 static const struct ctrl sd_ctrls[] = {
152 .id = V4L2_CID_BRIGHTNESS,
153 .type = V4L2_CTRL_TYPE_INTEGER,
154 .name = "Brightness",
158 .default_value = 127,
160 .set_control = setbrightness,
164 .id = V4L2_CID_CONTRAST,
165 .type = V4L2_CTRL_TYPE_INTEGER,
170 .default_value = 127,
172 .set_control = setcontrast,
176 .id = V4L2_CID_SATURATION,
177 .type = V4L2_CTRL_TYPE_INTEGER,
182 .default_value = 127,
184 .set_control = setcolors,
186 /* The flip controls work with ov7670 only */
189 .id = V4L2_CID_HFLIP,
190 .type = V4L2_CTRL_TYPE_BOOLEAN,
197 .set_control = sethvflip,
201 .id = V4L2_CID_VFLIP,
202 .type = V4L2_CTRL_TYPE_BOOLEAN,
209 .set_control = sethvflip,
213 .id = V4L2_CID_AUTOBRIGHTNESS,
214 .type = V4L2_CTRL_TYPE_BOOLEAN,
215 .name = "Auto Brightness",
221 .set_control = setautobright,
225 .id = V4L2_CID_POWER_LINE_FREQUENCY,
226 .type = V4L2_CTRL_TYPE_MENU,
227 .name = "Light frequency filter",
229 .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
233 .set_control = setfreq,
237 /* table of the disabled controls */
238 static const unsigned ctrl_dis[] = {
239 [SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
241 [SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
243 [SEN_OV6620] = (1 << HFLIP) |
246 [SEN_OV6630] = (1 << HFLIP) |
249 [SEN_OV66308AF] = (1 << HFLIP) |
252 [SEN_OV7610] = (1 << HFLIP) |
255 [SEN_OV7620] = (1 << HFLIP) |
258 [SEN_OV7620AE] = (1 << HFLIP) |
261 [SEN_OV7640] = (1 << HFLIP) |
266 [SEN_OV7648] = (1 << HFLIP) |
271 [SEN_OV7670] = (1 << COLORS) |
274 [SEN_OV76BE] = (1 << HFLIP) |
277 [SEN_OV8610] = (1 << HFLIP) |
282 static const struct v4l2_pix_format ov519_vga_mode[] = {
283 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
285 .sizeimage = 320 * 240 * 3 / 8 + 590,
286 .colorspace = V4L2_COLORSPACE_JPEG,
288 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
290 .sizeimage = 640 * 480 * 3 / 8 + 590,
291 .colorspace = V4L2_COLORSPACE_JPEG,
294 static const struct v4l2_pix_format ov519_sif_mode[] = {
295 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
297 .sizeimage = 160 * 120 * 3 / 8 + 590,
298 .colorspace = V4L2_COLORSPACE_JPEG,
300 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
302 .sizeimage = 176 * 144 * 3 / 8 + 590,
303 .colorspace = V4L2_COLORSPACE_JPEG,
305 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
307 .sizeimage = 320 * 240 * 3 / 8 + 590,
308 .colorspace = V4L2_COLORSPACE_JPEG,
310 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
312 .sizeimage = 352 * 288 * 3 / 8 + 590,
313 .colorspace = V4L2_COLORSPACE_JPEG,
317 /* Note some of the sizeimage values for the ov511 / ov518 may seem
318 larger then necessary, however they need to be this big as the ov511 /
319 ov518 always fills the entire isoc frame, using 0 padding bytes when
320 it doesn't have any data. So with low framerates the amount of data
321 transfered can become quite large (libv4l will remove all the 0 padding
323 static const struct v4l2_pix_format ov518_vga_mode[] = {
324 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
326 .sizeimage = 320 * 240 * 3,
327 .colorspace = V4L2_COLORSPACE_JPEG,
329 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
331 .sizeimage = 640 * 480 * 2,
332 .colorspace = V4L2_COLORSPACE_JPEG,
335 static const struct v4l2_pix_format ov518_sif_mode[] = {
336 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
339 .colorspace = V4L2_COLORSPACE_JPEG,
341 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
344 .colorspace = V4L2_COLORSPACE_JPEG,
346 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
348 .sizeimage = 320 * 240 * 3,
349 .colorspace = V4L2_COLORSPACE_JPEG,
351 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
353 .sizeimage = 352 * 288 * 3,
354 .colorspace = V4L2_COLORSPACE_JPEG,
358 static const struct v4l2_pix_format ov511_vga_mode[] = {
359 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
361 .sizeimage = 320 * 240 * 3,
362 .colorspace = V4L2_COLORSPACE_JPEG,
364 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
366 .sizeimage = 640 * 480 * 2,
367 .colorspace = V4L2_COLORSPACE_JPEG,
370 static const struct v4l2_pix_format ov511_sif_mode[] = {
371 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
374 .colorspace = V4L2_COLORSPACE_JPEG,
376 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
379 .colorspace = V4L2_COLORSPACE_JPEG,
381 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
383 .sizeimage = 320 * 240 * 3,
384 .colorspace = V4L2_COLORSPACE_JPEG,
386 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
388 .sizeimage = 352 * 288 * 3,
389 .colorspace = V4L2_COLORSPACE_JPEG,
393 static const struct v4l2_pix_format ovfx2_vga_mode[] = {
394 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
396 .sizeimage = 320 * 240,
397 .colorspace = V4L2_COLORSPACE_SRGB,
399 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
401 .sizeimage = 640 * 480,
402 .colorspace = V4L2_COLORSPACE_SRGB,
405 static const struct v4l2_pix_format ovfx2_cif_mode[] = {
406 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
408 .sizeimage = 160 * 120,
409 .colorspace = V4L2_COLORSPACE_SRGB,
411 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
413 .sizeimage = 176 * 144,
414 .colorspace = V4L2_COLORSPACE_SRGB,
416 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
418 .sizeimage = 320 * 240,
419 .colorspace = V4L2_COLORSPACE_SRGB,
421 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
423 .sizeimage = 352 * 288,
424 .colorspace = V4L2_COLORSPACE_SRGB,
427 static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
428 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
429 .bytesperline = 1600,
430 .sizeimage = 1600 * 1200,
431 .colorspace = V4L2_COLORSPACE_SRGB},
433 static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
434 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
436 .sizeimage = 640 * 480,
437 .colorspace = V4L2_COLORSPACE_SRGB,
439 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
441 .sizeimage = 800 * 600,
442 .colorspace = V4L2_COLORSPACE_SRGB,
444 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
445 .bytesperline = 1024,
446 .sizeimage = 1024 * 768,
447 .colorspace = V4L2_COLORSPACE_SRGB,
449 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
450 .bytesperline = 1600,
451 .sizeimage = 1600 * 1200,
452 .colorspace = V4L2_COLORSPACE_SRGB,
454 {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
455 .bytesperline = 2048,
456 .sizeimage = 2048 * 1536,
457 .colorspace = V4L2_COLORSPACE_SRGB,
461 /* Registers common to OV511 / OV518 */
462 #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
463 #define R51x_SYS_RESET 0x50
464 /* Reset type flags */
465 #define OV511_RESET_OMNICE 0x08
466 #define R51x_SYS_INIT 0x53
467 #define R51x_SYS_SNAP 0x52
468 #define R51x_SYS_CUST_ID 0x5f
469 #define R51x_COMP_LUT_BEGIN 0x80
471 /* OV511 Camera interface register numbers */
472 #define R511_CAM_DELAY 0x10
473 #define R511_CAM_EDGE 0x11
474 #define R511_CAM_PXCNT 0x12
475 #define R511_CAM_LNCNT 0x13
476 #define R511_CAM_PXDIV 0x14
477 #define R511_CAM_LNDIV 0x15
478 #define R511_CAM_UV_EN 0x16
479 #define R511_CAM_LINE_MODE 0x17
480 #define R511_CAM_OPTS 0x18
482 #define R511_SNAP_FRAME 0x19
483 #define R511_SNAP_PXCNT 0x1a
484 #define R511_SNAP_LNCNT 0x1b
485 #define R511_SNAP_PXDIV 0x1c
486 #define R511_SNAP_LNDIV 0x1d
487 #define R511_SNAP_UV_EN 0x1e
488 #define R511_SNAP_UV_EN 0x1e
489 #define R511_SNAP_OPTS 0x1f
491 #define R511_DRAM_FLOW_CTL 0x20
492 #define R511_FIFO_OPTS 0x31
493 #define R511_I2C_CTL 0x40
494 #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
495 #define R511_COMP_EN 0x78
496 #define R511_COMP_LUT_EN 0x79
498 /* OV518 Camera interface register numbers */
499 #define R518_GPIO_OUT 0x56 /* OV518(+) only */
500 #define R518_GPIO_CTL 0x57 /* OV518(+) only */
502 /* OV519 Camera interface register numbers */
503 #define OV519_R10_H_SIZE 0x10
504 #define OV519_R11_V_SIZE 0x11
505 #define OV519_R12_X_OFFSETL 0x12
506 #define OV519_R13_X_OFFSETH 0x13
507 #define OV519_R14_Y_OFFSETL 0x14
508 #define OV519_R15_Y_OFFSETH 0x15
509 #define OV519_R16_DIVIDER 0x16
510 #define OV519_R20_DFR 0x20
511 #define OV519_R25_FORMAT 0x25
513 /* OV519 System Controller register numbers */
514 #define OV519_R51_RESET1 0x51
515 #define OV519_R54_EN_CLK1 0x54
516 #define OV519_R57_SNAPSHOT 0x57
518 #define OV519_GPIO_DATA_OUT0 0x71
519 #define OV519_GPIO_IO_CTRL0 0x72
521 /*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
524 * The FX2 chip does not give us a zero length read at end of frame.
525 * It does, however, give a short read at the end of a frame, if
526 * necessary, rather than run two frames together.
528 * By choosing the right bulk transfer size, we are guaranteed to always
529 * get a short read for the last read of each frame. Frame sizes are
530 * always a composite number (width * height, or a multiple) so if we
531 * choose a prime number, we are guaranteed that the last read of a
532 * frame will be short.
534 * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
535 * otherwise EOVERFLOW "babbling" errors occur. I have not been able
536 * to figure out why. [PMiller]
538 * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
540 * It isn't enough to know the number of bytes per frame, in case we
541 * have data dropouts or buffer overruns (even though the FX2 double
542 * buffers, there are some pretty strict real time constraints for
543 * isochronous transfer for larger frame sizes).
545 #define OVFX2_BULK_SIZE (13 * 4096)
548 #define R51x_I2C_W_SID 0x41
549 #define R51x_I2C_SADDR_3 0x42
550 #define R51x_I2C_SADDR_2 0x43
551 #define R51x_I2C_R_SID 0x44
552 #define R51x_I2C_DATA 0x45
553 #define R518_I2C_CTL 0x47 /* OV518(+) only */
554 #define OVFX2_I2C_ADDR 0x00
557 #define OV7xx0_SID 0x42
558 #define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
559 #define OV8xx0_SID 0xa0
560 #define OV6xx0_SID 0xc0
562 /* OV7610 registers */
563 #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
564 #define OV7610_REG_BLUE 0x01 /* blue channel balance */
565 #define OV7610_REG_RED 0x02 /* red channel balance */
566 #define OV7610_REG_SAT 0x03 /* saturation */
567 #define OV8610_REG_HUE 0x04 /* 04 reserved */
568 #define OV7610_REG_CNT 0x05 /* Y contrast */
569 #define OV7610_REG_BRT 0x06 /* Y brightness */
570 #define OV7610_REG_COM_C 0x14 /* misc common regs */
571 #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
572 #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
573 #define OV7610_REG_COM_I 0x29 /* misc settings */
575 /* OV7670 registers */
576 #define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
577 #define OV7670_R01_BLUE 0x01 /* blue gain */
578 #define OV7670_R02_RED 0x02 /* red gain */
579 #define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
580 #define OV7670_R04_COM1 0x04 /* Control 1 */
581 /*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
582 #define OV7670_R0C_COM3 0x0c /* Control 3 */
583 #define OV7670_R0D_COM4 0x0d /* Control 4 */
584 #define OV7670_R0E_COM5 0x0e /* All "reserved" */
585 #define OV7670_R0F_COM6 0x0f /* Control 6 */
586 #define OV7670_R10_AECH 0x10 /* More bits of AEC value */
587 #define OV7670_R11_CLKRC 0x11 /* Clock control */
588 #define OV7670_R12_COM7 0x12 /* Control 7 */
589 #define OV7670_COM7_FMT_VGA 0x00
590 /*#define OV7670_COM7_YUV 0x00 * YUV */
591 #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
592 #define OV7670_COM7_FMT_MASK 0x38
593 #define OV7670_COM7_RESET 0x80 /* Register reset */
594 #define OV7670_R13_COM8 0x13 /* Control 8 */
595 #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
596 #define OV7670_COM8_AWB 0x02 /* White balance enable */
597 #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
598 #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
599 #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
600 #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
601 #define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
602 #define OV7670_R15_COM10 0x15 /* Control 10 */
603 #define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
604 #define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
605 #define OV7670_R19_VSTART 0x19 /* Vert start high bits */
606 #define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
607 #define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
608 #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
609 #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
610 #define OV7670_R24_AEW 0x24 /* AGC upper limit */
611 #define OV7670_R25_AEB 0x25 /* AGC lower limit */
612 #define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
613 #define OV7670_R32_HREF 0x32 /* HREF pieces */
614 #define OV7670_R3A_TSLB 0x3a /* lots of stuff */
615 #define OV7670_R3B_COM11 0x3b /* Control 11 */
616 #define OV7670_COM11_EXP 0x02
617 #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
618 #define OV7670_R3C_COM12 0x3c /* Control 12 */
619 #define OV7670_R3D_COM13 0x3d /* Control 13 */
620 #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
621 #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
622 #define OV7670_R3E_COM14 0x3e /* Control 14 */
623 #define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
624 #define OV7670_R40_COM15 0x40 /* Control 15 */
625 /*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
626 #define OV7670_R41_COM16 0x41 /* Control 16 */
627 #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
628 #define OV7670_R55_BRIGHT 0x55 /* Brightness */
629 #define OV7670_R56_CONTRAS 0x56 /* Contrast control */
630 #define OV7670_R69_GFIX 0x69 /* Fix gain control */
631 /*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
632 #define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
633 #define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
634 #define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
635 #define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
636 #define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
637 #define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
638 #define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
639 #define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
640 #define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
646 struct ov_i2c_regvals {
651 /* Settings for OV2610 camera chip */
652 static const struct ov_i2c_regvals norm_2610[] = {
653 { 0x12, 0x80 }, /* reset */
656 static const struct ov_i2c_regvals norm_3620b[] = {
658 * From the datasheet: "Note that after writing to register COMH
659 * (0x12) to change the sensor mode, registers related to the
660 * sensor’s cropping window will be reset back to their default
663 * "wait 4096 external clock ... to make sure the sensor is
664 * stable and ready to access registers" i.e. 160us at 24MHz
666 { 0x12, 0x80 }, /* COMH reset */
667 { 0x12, 0x00 }, /* QXGA, master */
670 * 11 CLKRC "Clock Rate Control"
671 * [7] internal frequency doublers: on
672 * [6] video port mode: master
673 * [5:0] clock divider: 1
678 * 13 COMI "Common Control I"
679 * = 192 (0xC0) 11000000
680 * COMI[7] "AEC speed selection"
681 * = 1 (0x01) 1....... "Faster AEC correction"
682 * COMI[6] "AEC speed step selection"
683 * = 1 (0x01) .1...... "Big steps, fast"
684 * COMI[5] "Banding filter on off"
685 * = 0 (0x00) ..0..... "Off"
686 * COMI[4] "Banding filter option"
687 * = 0 (0x00) ...0.... "Main clock is 48 MHz and
690 * = 0 (0x00) ....0...
691 * COMI[2] "AGC auto manual control selection"
692 * = 0 (0x00) .....0.. "Manual"
693 * COMI[1] "AWB auto manual control selection"
694 * = 0 (0x00) ......0. "Manual"
695 * COMI[0] "Exposure control"
696 * = 0 (0x00) .......0 "Manual"
701 * 09 COMC "Common Control C"
702 * = 8 (0x08) 00001000
703 * COMC[7:5] "Reserved"
704 * = 0 (0x00) 000.....
705 * COMC[4] "Sleep Mode Enable"
706 * = 0 (0x00) ...0.... "Normal mode"
707 * COMC[3:2] "Sensor sampling reset timing selection"
708 * = 2 (0x02) ....10.. "Longer reset time"
709 * COMC[1:0] "Output drive current select"
710 * = 0 (0x00) ......00 "Weakest"
715 * 0C COMD "Common Control D"
716 * = 8 (0x08) 00001000
718 * = 0 (0x00) 0.......
719 * COMD[6] "Swap MSB and LSB at the output port"
720 * = 0 (0x00) .0...... "False"
721 * COMD[5:3] "Reserved"
722 * = 1 (0x01) ..001...
723 * COMD[2] "Output Average On Off"
724 * = 0 (0x00) .....0.. "Output Normal"
725 * COMD[1] "Sensor precharge voltage selection"
726 * = 0 (0x00) ......0. "Selects internal
727 * reference precharge
729 * COMD[0] "Snapshot option"
730 * = 0 (0x00) .......0 "Enable live video output
731 * after snapshot sequence"
736 * 0D COME "Common Control E"
737 * = 161 (0xA1) 10100001
738 * COME[7] "Output average option"
739 * = 1 (0x01) 1....... "Output average of 4 pixels"
740 * COME[6] "Anti-blooming control"
741 * = 0 (0x00) .0...... "Off"
742 * COME[5:3] "Reserved"
743 * = 4 (0x04) ..100...
744 * COME[2] "Clock output power down pin status"
745 * = 0 (0x00) .....0.. "Tri-state data output pin
747 * COME[1] "Data output pin status selection at power down"
748 * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
749 * HREF, and CHSYNC pins on
751 * COME[0] "Auto zero circuit select"
752 * = 1 (0x01) .......1 "On"
757 * 0E COMF "Common Control F"
758 * = 112 (0x70) 01110000
759 * COMF[7] "System clock selection"
760 * = 0 (0x00) 0....... "Use 24 MHz system clock"
761 * COMF[6:4] "Reserved"
762 * = 7 (0x07) .111....
763 * COMF[3] "Manual auto negative offset canceling selection"
764 * = 0 (0x00) ....0... "Auto detect negative
765 * offset and cancel it"
766 * COMF[2:0] "Reserved"
767 * = 0 (0x00) .....000
772 * 0F COMG "Common Control G"
773 * = 66 (0x42) 01000010
774 * COMG[7] "Optical black output selection"
775 * = 0 (0x00) 0....... "Disable"
776 * COMG[6] "Black level calibrate selection"
777 * = 1 (0x01) .1...... "Use optical black pixels
779 * COMG[5:4] "Reserved"
780 * = 0 (0x00) ..00....
781 * COMG[3] "Channel offset adjustment"
782 * = 0 (0x00) ....0... "Disable offset adjustment"
783 * COMG[2] "ADC black level calibration option"
784 * = 0 (0x00) .....0.. "Use B/G line and G/R
785 * line to calibrate each
786 * channel's black level"
788 * = 1 (0x01) ......1.
789 * COMG[0] "ADC black level calibration enable"
790 * = 0 (0x00) .......0 "Disable"
795 * 14 COMJ "Common Control J"
796 * = 198 (0xC6) 11000110
797 * COMJ[7:6] "AGC gain ceiling"
798 * = 3 (0x03) 11...... "8x"
799 * COMJ[5:4] "Reserved"
800 * = 0 (0x00) ..00....
801 * COMJ[3] "Auto banding filter"
802 * = 0 (0x00) ....0... "Banding filter is always
803 * on off depending on
805 * COMJ[2] "VSYNC drop option"
806 * = 1 (0x01) .....1.. "SYNC is dropped if frame
808 * COMJ[1] "Frame data drop"
809 * = 1 (0x01) ......1. "Drop frame data if
810 * exposure is not within
811 * tolerance. In AEC mode,
812 * data is normally dropped
813 * when data is out of
816 * = 0 (0x00) .......0
821 * 15 COMK "Common Control K"
822 * = 2 (0x02) 00000010
823 * COMK[7] "CHSYNC pin output swap"
824 * = 0 (0x00) 0....... "CHSYNC"
825 * COMK[6] "HREF pin output swap"
826 * = 0 (0x00) .0...... "HREF"
827 * COMK[5] "PCLK output selection"
828 * = 0 (0x00) ..0..... "PCLK always output"
829 * COMK[4] "PCLK edge selection"
830 * = 0 (0x00) ...0.... "Data valid on falling edge"
831 * COMK[3] "HREF output polarity"
832 * = 0 (0x00) ....0... "positive"
834 * = 0 (0x00) .....0..
835 * COMK[1] "VSYNC polarity"
836 * = 1 (0x01) ......1. "negative"
837 * COMK[0] "HSYNC polarity"
838 * = 0 (0x00) .......0 "positive"
843 * 33 CHLF "Current Control"
844 * = 9 (0x09) 00001001
845 * CHLF[7:6] "Sensor current control"
846 * = 0 (0x00) 00......
847 * CHLF[5] "Sensor current range control"
848 * = 0 (0x00) ..0..... "normal range"
849 * CHLF[4] "Sensor current"
850 * = 0 (0x00) ...0.... "normal current"
851 * CHLF[3] "Sensor buffer current control"
852 * = 1 (0x01) ....1... "half current"
853 * CHLF[2] "Column buffer current control"
854 * = 0 (0x00) .....0.. "normal current"
855 * CHLF[1] "Analog DSP current control"
856 * = 0 (0x00) ......0. "normal current"
857 * CHLF[1] "ADC current control"
858 * = 0 (0x00) ......0. "normal current"
863 * 34 VBLM "Blooming Control"
864 * = 80 (0x50) 01010000
865 * VBLM[7] "Hard soft reset switch"
866 * = 0 (0x00) 0....... "Hard reset"
867 * VBLM[6:4] "Blooming voltage selection"
868 * = 5 (0x05) .101....
869 * VBLM[3:0] "Sensor current control"
870 * = 0 (0x00) ....0000
875 * 36 VCHG "Sensor Precharge Voltage Control"
876 * = 0 (0x00) 00000000
878 * = 0 (0x00) 0.......
879 * VCHG[6:4] "Sensor precharge voltage control"
880 * = 0 (0x00) .000....
881 * VCHG[3:0] "Sensor array common reference"
882 * = 0 (0x00) ....0000
887 * 37 ADC "ADC Reference Control"
888 * = 4 (0x04) 00000100
889 * ADC[7:4] "Reserved"
890 * = 0 (0x00) 0000....
891 * ADC[3] "ADC input signal range"
892 * = 0 (0x00) ....0... "Input signal 1.0x"
893 * ADC[2:0] "ADC range control"
894 * = 4 (0x04) .....100
899 * 38 ACOM "Analog Common Ground"
900 * = 82 (0x52) 01010010
901 * ACOM[7] "Analog gain control"
902 * = 0 (0x00) 0....... "Gain 1x"
903 * ACOM[6] "Analog black level calibration"
904 * = 1 (0x01) .1...... "On"
905 * ACOM[5:0] "Reserved"
906 * = 18 (0x12) ..010010
911 * 3A FREFA "Internal Reference Adjustment"
912 * = 0 (0x00) 00000000
914 * = 0 (0x00) 00000000
919 * 3C FVOPT "Internal Reference Adjustment"
920 * = 31 (0x1F) 00011111
922 * = 31 (0x1F) 00011111
927 * 44 Undocumented = 0 (0x00) 00000000
928 * 44[7:0] "It's a secret"
929 * = 0 (0x00) 00000000
934 * 40 Undocumented = 0 (0x00) 00000000
935 * 40[7:0] "It's a secret"
936 * = 0 (0x00) 00000000
941 * 41 Undocumented = 0 (0x00) 00000000
942 * 41[7:0] "It's a secret"
943 * = 0 (0x00) 00000000
948 * 42 Undocumented = 0 (0x00) 00000000
949 * 42[7:0] "It's a secret"
950 * = 0 (0x00) 00000000
955 * 43 Undocumented = 0 (0x00) 00000000
956 * 43[7:0] "It's a secret"
957 * = 0 (0x00) 00000000
962 * 45 Undocumented = 128 (0x80) 10000000
963 * 45[7:0] "It's a secret"
964 * = 128 (0x80) 10000000
969 * 48 Undocumented = 192 (0xC0) 11000000
970 * 48[7:0] "It's a secret"
971 * = 192 (0xC0) 11000000
976 * 49 Undocumented = 25 (0x19) 00011001
977 * 49[7:0] "It's a secret"
978 * = 25 (0x19) 00011001
983 * 4B Undocumented = 128 (0x80) 10000000
984 * 4B[7:0] "It's a secret"
985 * = 128 (0x80) 10000000
990 * 4D Undocumented = 196 (0xC4) 11000100
991 * 4D[7:0] "It's a secret"
992 * = 196 (0xC4) 11000100
997 * 35 VREF "Reference Voltage Control"
998 * = 76 (0x4c) 01001100
999 * VREF[7:5] "Column high reference control"
1000 * = 2 (0x02) 010..... "higher voltage"
1001 * VREF[4:2] "Column low reference control"
1002 * = 3 (0x03) ...011.. "Highest voltage"
1003 * VREF[1:0] "Reserved"
1004 * = 0 (0x00) ......00
1009 * 3D Undocumented = 0 (0x00) 00000000
1010 * 3D[7:0] "It's a secret"
1011 * = 0 (0x00) 00000000
1016 * 3E Undocumented = 0 (0x00) 00000000
1017 * 3E[7:0] "It's a secret"
1018 * = 0 (0x00) 00000000
1023 * 3B FREFB "Internal Reference Adjustment"
1024 * = 24 (0x18) 00011000
1025 * FREFB[7:0] "Range"
1026 * = 24 (0x18) 00011000
1031 * 33 CHLF "Current Control"
1032 * = 25 (0x19) 00011001
1033 * CHLF[7:6] "Sensor current control"
1034 * = 0 (0x00) 00......
1035 * CHLF[5] "Sensor current range control"
1036 * = 0 (0x00) ..0..... "normal range"
1037 * CHLF[4] "Sensor current"
1038 * = 1 (0x01) ...1.... "double current"
1039 * CHLF[3] "Sensor buffer current control"
1040 * = 1 (0x01) ....1... "half current"
1041 * CHLF[2] "Column buffer current control"
1042 * = 0 (0x00) .....0.. "normal current"
1043 * CHLF[1] "Analog DSP current control"
1044 * = 0 (0x00) ......0. "normal current"
1045 * CHLF[1] "ADC current control"
1046 * = 0 (0x00) ......0. "normal current"
1051 * 34 VBLM "Blooming Control"
1052 * = 90 (0x5A) 01011010
1053 * VBLM[7] "Hard soft reset switch"
1054 * = 0 (0x00) 0....... "Hard reset"
1055 * VBLM[6:4] "Blooming voltage selection"
1056 * = 5 (0x05) .101....
1057 * VBLM[3:0] "Sensor current control"
1058 * = 10 (0x0A) ....1010
1063 * 3B FREFB "Internal Reference Adjustment"
1064 * = 0 (0x00) 00000000
1065 * FREFB[7:0] "Range"
1066 * = 0 (0x00) 00000000
1071 * 33 CHLF "Current Control"
1072 * = 9 (0x09) 00001001
1073 * CHLF[7:6] "Sensor current control"
1074 * = 0 (0x00) 00......
1075 * CHLF[5] "Sensor current range control"
1076 * = 0 (0x00) ..0..... "normal range"
1077 * CHLF[4] "Sensor current"
1078 * = 0 (0x00) ...0.... "normal current"
1079 * CHLF[3] "Sensor buffer current control"
1080 * = 1 (0x01) ....1... "half current"
1081 * CHLF[2] "Column buffer current control"
1082 * = 0 (0x00) .....0.. "normal current"
1083 * CHLF[1] "Analog DSP current control"
1084 * = 0 (0x00) ......0. "normal current"
1085 * CHLF[1] "ADC current control"
1086 * = 0 (0x00) ......0. "normal current"
1091 * 34 VBLM "Blooming Control"
1092 * = 80 (0x50) 01010000
1093 * VBLM[7] "Hard soft reset switch"
1094 * = 0 (0x00) 0....... "Hard reset"
1095 * VBLM[6:4] "Blooming voltage selection"
1096 * = 5 (0x05) .101....
1097 * VBLM[3:0] "Sensor current control"
1098 * = 0 (0x00) ....0000
1103 * 12 COMH "Common Control H"
1104 * = 64 (0x40) 01000000
1106 * = 0 (0x00) 0....... "No-op"
1107 * COMH[6:4] "Resolution selection"
1108 * = 4 (0x04) .100.... "XGA"
1109 * COMH[3] "Master slave selection"
1110 * = 0 (0x00) ....0... "Master mode"
1111 * COMH[2] "Internal B/R channel option"
1112 * = 0 (0x00) .....0.. "B/R use same channel"
1113 * COMH[1] "Color bar test pattern"
1114 * = 0 (0x00) ......0. "Off"
1115 * COMH[0] "Reserved"
1116 * = 0 (0x00) .......0
1121 * 17 HREFST "Horizontal window start"
1122 * = 31 (0x1F) 00011111
1123 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1124 * = 31 (0x1F) 00011111
1129 * 18 HREFEND "Horizontal window end"
1130 * = 95 (0x5F) 01011111
1131 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1132 * = 95 (0x5F) 01011111
1137 * 19 VSTRT "Vertical window start"
1138 * = 0 (0x00) 00000000
1139 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1140 * = 0 (0x00) 00000000
1145 * 1A VEND "Vertical window end"
1146 * = 96 (0x60) 01100000
1147 * VEND[7:0] "Vertical Window End, 8 MSBs"
1148 * = 96 (0x60) 01100000
1153 * 32 COMM "Common Control M"
1154 * = 18 (0x12) 00010010
1155 * COMM[7:6] "Pixel clock divide option"
1156 * = 0 (0x00) 00...... "/1"
1157 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1158 * = 2 (0x02) ..010...
1159 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1160 * = 2 (0x02) .....010
1165 * 03 COMA "Common Control A"
1166 * = 74 (0x4A) 01001010
1167 * COMA[7:4] "AWB Update Threshold"
1168 * = 4 (0x04) 0100....
1169 * COMA[3:2] "Vertical window end line control 2 LSBs"
1170 * = 2 (0x02) ....10..
1171 * COMA[1:0] "Vertical window start line control 2 LSBs"
1172 * = 2 (0x02) ......10
1177 * 11 CLKRC "Clock Rate Control"
1178 * = 128 (0x80) 10000000
1179 * CLKRC[7] "Internal frequency doublers on off seclection"
1180 * = 1 (0x01) 1....... "On"
1181 * CLKRC[6] "Digital video master slave selection"
1182 * = 0 (0x00) .0...... "Master mode, sensor
1184 * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
1185 * = 0 (0x00) ..000000
1190 * 12 COMH "Common Control H"
1191 * = 0 (0x00) 00000000
1193 * = 0 (0x00) 0....... "No-op"
1194 * COMH[6:4] "Resolution selection"
1195 * = 0 (0x00) .000.... "QXGA"
1196 * COMH[3] "Master slave selection"
1197 * = 0 (0x00) ....0... "Master mode"
1198 * COMH[2] "Internal B/R channel option"
1199 * = 0 (0x00) .....0.. "B/R use same channel"
1200 * COMH[1] "Color bar test pattern"
1201 * = 0 (0x00) ......0. "Off"
1202 * COMH[0] "Reserved"
1203 * = 0 (0x00) .......0
1208 * 12 COMH "Common Control H"
1209 * = 64 (0x40) 01000000
1211 * = 0 (0x00) 0....... "No-op"
1212 * COMH[6:4] "Resolution selection"
1213 * = 4 (0x04) .100.... "XGA"
1214 * COMH[3] "Master slave selection"
1215 * = 0 (0x00) ....0... "Master mode"
1216 * COMH[2] "Internal B/R channel option"
1217 * = 0 (0x00) .....0.. "B/R use same channel"
1218 * COMH[1] "Color bar test pattern"
1219 * = 0 (0x00) ......0. "Off"
1220 * COMH[0] "Reserved"
1221 * = 0 (0x00) .......0
1226 * 17 HREFST "Horizontal window start"
1227 * = 31 (0x1F) 00011111
1228 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1229 * = 31 (0x1F) 00011111
1234 * 18 HREFEND "Horizontal window end"
1235 * = 95 (0x5F) 01011111
1236 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1237 * = 95 (0x5F) 01011111
1242 * 19 VSTRT "Vertical window start"
1243 * = 0 (0x00) 00000000
1244 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1245 * = 0 (0x00) 00000000
1250 * 1A VEND "Vertical window end"
1251 * = 96 (0x60) 01100000
1252 * VEND[7:0] "Vertical Window End, 8 MSBs"
1253 * = 96 (0x60) 01100000
1258 * 32 COMM "Common Control M"
1259 * = 18 (0x12) 00010010
1260 * COMM[7:6] "Pixel clock divide option"
1261 * = 0 (0x00) 00...... "/1"
1262 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1263 * = 2 (0x02) ..010...
1264 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1265 * = 2 (0x02) .....010
1270 * 03 COMA "Common Control A"
1271 * = 74 (0x4A) 01001010
1272 * COMA[7:4] "AWB Update Threshold"
1273 * = 4 (0x04) 0100....
1274 * COMA[3:2] "Vertical window end line control 2 LSBs"
1275 * = 2 (0x02) ....10..
1276 * COMA[1:0] "Vertical window start line control 2 LSBs"
1277 * = 2 (0x02) ......10
1282 * 02 RED "Red Gain Control"
1283 * = 175 (0xAF) 10101111
1285 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1287 * = 47 (0x2F) .0101111
1292 * 2D ADDVSL "VSYNC Pulse Width"
1293 * = 210 (0xD2) 11010010
1294 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1295 * = 210 (0xD2) 11010010
1300 * 00 GAIN = 24 (0x18) 00011000
1301 * GAIN[7:6] "Reserved"
1302 * = 0 (0x00) 00......
1304 * = 0 (0x00) ..0..... "False"
1306 * = 1 (0x01) ...1.... "True"
1308 * = 8 (0x08) ....1000
1313 * 01 BLUE "Blue Gain Control"
1314 * = 240 (0xF0) 11110000
1316 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1318 * = 112 (0x70) .1110000
1323 * 10 AEC "Automatic Exposure Control"
1324 * = 10 (0x0A) 00001010
1325 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1326 * = 10 (0x0A) 00001010
1338 static const struct ov_i2c_regvals norm_6x20[] = {
1339 { 0x12, 0x80 }, /* reset */
1342 { 0x05, 0x7f }, /* For when autoadjust is off */
1344 /* The ratio of 0x0c and 0x0d controls the white point */
1347 { 0x0f, 0x15 }, /* COMS */
1348 { 0x10, 0x75 }, /* AEC Exposure time */
1349 { 0x12, 0x24 }, /* Enable AGC */
1351 /* 0x16: 0x06 helps frame stability with moving objects */
1353 /* { 0x20, 0x30 }, * Aperture correction enable */
1354 { 0x26, 0xb2 }, /* BLC enable */
1355 /* 0x28: 0x05 Selects RGB format if RGB on */
1357 { 0x2a, 0x04 }, /* Disable framerate adjust */
1358 /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
1360 { 0x33, 0xa0 }, /* Color Processing Parameter */
1361 { 0x34, 0xd2 }, /* Max A/D range */
1365 { 0x3c, 0x39 }, /* Enable AEC mode changing */
1366 { 0x3c, 0x3c }, /* Change AEC mode */
1367 { 0x3c, 0x24 }, /* Disable AEC mode changing */
1370 /* These next two registers (0x4a, 0x4b) are undocumented.
1371 * They control the color balance */
1374 { 0x4d, 0xd2 }, /* This reduces noise a bit */
1377 /* Do 50-53 have any effect? */
1378 /* Toggle 0x12[2] off and on here? */
1381 static const struct ov_i2c_regvals norm_6x30[] = {
1382 { 0x12, 0x80 }, /* Reset */
1383 { 0x00, 0x1f }, /* Gain */
1384 { 0x01, 0x99 }, /* Blue gain */
1385 { 0x02, 0x7c }, /* Red gain */
1386 { 0x03, 0xc0 }, /* Saturation */
1387 { 0x05, 0x0a }, /* Contrast */
1388 { 0x06, 0x95 }, /* Brightness */
1389 { 0x07, 0x2d }, /* Sharpness */
1392 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
1395 { 0x11, 0x00 }, /* Pixel clock = fastest */
1396 { 0x12, 0x24 }, /* Enable AGC and AWB */
1411 { 0x23, 0xc0 }, /* Crystal circuit power level */
1412 { 0x25, 0x9a }, /* Increase AEC black ratio */
1413 { 0x26, 0xb2 }, /* BLC enable */
1417 { 0x2a, 0x84 }, /* 60 Hz power */
1418 { 0x2b, 0xa8 }, /* 60 Hz power */
1420 { 0x2d, 0x95 }, /* Enable auto-brightness */
1434 { 0x40, 0x00 }, /* White bal */
1435 { 0x41, 0x00 }, /* White bal */
1437 { 0x43, 0x3f }, /* White bal */
1447 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
1449 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
1451 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
1456 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
1458 { 0x5b, 0x0f }, /* AWB chrominance levels */
1462 { 0x12, 0x20 }, /* Toggle AWB */
1466 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
1468 * Register 0x0f in the 7610 has the following effects:
1470 * 0x85 (AEC method 1): Best overall, good contrast range
1471 * 0x45 (AEC method 2): Very overexposed
1472 * 0xa5 (spec sheet default): Ok, but the black level is
1473 * shifted resulting in loss of contrast
1474 * 0x05 (old driver setting): very overexposed, too much
1477 static const struct ov_i2c_regvals norm_7610[] = {
1484 { 0x28, 0x24 }, /* 0c */
1485 { 0x0f, 0x85 }, /* lg's setting */
1507 static const struct ov_i2c_regvals norm_7620[] = {
1508 { 0x12, 0x80 }, /* reset */
1509 { 0x00, 0x00 }, /* gain */
1510 { 0x01, 0x80 }, /* blue gain */
1511 { 0x02, 0x80 }, /* red gain */
1512 { 0x03, 0xc0 }, /* OV7670_R03_VREF */
1535 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
1574 /* 7640 and 7648. The defaults should be OK for most registers. */
1575 static const struct ov_i2c_regvals norm_7640[] = {
1580 /* 7670. Defaults taken from OmniVision provided data,
1581 * as provided by Jonathan Corbet of OLPC */
1582 static const struct ov_i2c_regvals norm_7670[] = {
1583 { OV7670_R12_COM7, OV7670_COM7_RESET },
1584 { OV7670_R3A_TSLB, 0x04 }, /* OV */
1585 { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1586 { OV7670_R11_CLKRC, 0x01 },
1588 * Set the hardware window. These values from OV don't entirely
1589 * make sense - hstop is less than hstart. But they work...
1591 { OV7670_R17_HSTART, 0x13 },
1592 { OV7670_R18_HSTOP, 0x01 },
1593 { OV7670_R32_HREF, 0xb6 },
1594 { OV7670_R19_VSTART, 0x02 },
1595 { OV7670_R1A_VSTOP, 0x7a },
1596 { OV7670_R03_VREF, 0x0a },
1598 { OV7670_R0C_COM3, 0x00 },
1599 { OV7670_R3E_COM14, 0x00 },
1600 /* Mystery scaling numbers */
1606 /* { OV7670_R15_COM10, 0x0 }, */
1608 /* Gamma curve values */
1626 /* AGC and AEC parameters. Note we start by disabling those features,
1627 then turn them only after tweaking the values. */
1628 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
1629 | OV7670_COM8_AECSTEP
1630 | OV7670_COM8_BFILT },
1631 { OV7670_R00_GAIN, 0x00 },
1632 { OV7670_R10_AECH, 0x00 },
1633 { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
1634 { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1635 { OV7670_RA5_BD50MAX, 0x05 },
1636 { OV7670_RAB_BD60MAX, 0x07 },
1637 { OV7670_R24_AEW, 0x95 },
1638 { OV7670_R25_AEB, 0x33 },
1639 { OV7670_R26_VPT, 0xe3 },
1640 { OV7670_R9F_HAECC1, 0x78 },
1641 { OV7670_RA0_HAECC2, 0x68 },
1642 { 0xa1, 0x03 }, /* magic */
1643 { OV7670_RA6_HAECC3, 0xd8 },
1644 { OV7670_RA7_HAECC4, 0xd8 },
1645 { OV7670_RA8_HAECC5, 0xf0 },
1646 { OV7670_RA9_HAECC6, 0x90 },
1647 { OV7670_RAA_HAECC7, 0x94 },
1648 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
1649 | OV7670_COM8_AECSTEP
1652 | OV7670_COM8_AEC },
1654 /* Almost all of these are magic "reserved" values. */
1655 { OV7670_R0E_COM5, 0x61 },
1656 { OV7670_R0F_COM6, 0x4b },
1658 { OV7670_R1E_MVFP, 0x07 },
1667 { OV7670_R3C_COM12, 0x78 },
1670 { OV7670_R69_GFIX, 0x00 },
1686 /* More reserved magic, some of which tweaks white balance */
1703 /* "9e for advance AWB" */
1705 { OV7670_R01_BLUE, 0x40 },
1706 { OV7670_R02_RED, 0x60 },
1707 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
1708 | OV7670_COM8_AECSTEP
1712 | OV7670_COM8_AWB },
1714 /* Matrix coefficients */
1723 { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
1724 { OV7670_R3F_EDGE, 0x00 },
1729 { OV7670_R3D_COM13, OV7670_COM13_GAMMA
1730 | OV7670_COM13_UVSAT
1734 { OV7670_R41_COM16, 0x38 },
1738 { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
1751 /* Extra-weird stuff. Some sort of multiplexor register */
1777 static const struct ov_i2c_regvals norm_8610[] = {
1784 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
1785 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
1794 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
1796 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
1797 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
1798 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
1801 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
1802 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
1803 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
1804 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
1810 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
1812 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
1814 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
1816 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
1817 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
1818 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
1819 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
1821 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
1822 * maybe thats wrong */
1826 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1830 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1831 * deleting bit7 colors the first images red */
1832 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1833 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1839 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1841 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1846 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1848 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1849 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1856 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1862 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1865 static unsigned char ov7670_abs_to_sm(unsigned char v)
1869 return (128 - v) | 0x80;
1872 /* Write a OV519 register */
1873 static void reg_w(struct sd *sd, u16 index, u16 value)
1877 if (sd->gspca_dev.usb_err < 0)
1880 switch (sd->bridge) {
1882 case BRIDGE_OV511PLUS:
1888 case BRIDGE_W9968CF:
1889 PDEBUG(D_USBO, "SET %02x %04x %04x",
1891 ret = usb_control_msg(sd->gspca_dev.dev,
1892 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1894 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1895 value, index, NULL, 0, 500);
1901 PDEBUG(D_USBO, "SET %02x 0000 %04x %02x",
1903 sd->gspca_dev.usb_buf[0] = value;
1904 ret = usb_control_msg(sd->gspca_dev.dev,
1905 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1907 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1909 sd->gspca_dev.usb_buf, 1, 500);
1912 err("reg_w %02x failed %d", index, ret);
1913 sd->gspca_dev.usb_err = ret;
1918 /* Read from a OV519 register, note not valid for the w9968cf!! */
1919 /* returns: negative is error, pos or zero is data */
1920 static int reg_r(struct sd *sd, u16 index)
1925 if (sd->gspca_dev.usb_err < 0)
1928 switch (sd->bridge) {
1930 case BRIDGE_OV511PLUS:
1940 ret = usb_control_msg(sd->gspca_dev.dev,
1941 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1943 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1944 0, index, sd->gspca_dev.usb_buf, 1, 500);
1947 ret = sd->gspca_dev.usb_buf[0];
1948 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
1951 err("reg_r %02x failed %d", index, ret);
1952 sd->gspca_dev.usb_err = ret;
1958 /* Read 8 values from a OV519 register */
1959 static int reg_r8(struct sd *sd,
1964 if (sd->gspca_dev.usb_err < 0)
1967 ret = usb_control_msg(sd->gspca_dev.dev,
1968 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1970 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1971 0, index, sd->gspca_dev.usb_buf, 8, 500);
1974 ret = sd->gspca_dev.usb_buf[0];
1976 err("reg_r8 %02x failed %d", index, ret);
1977 sd->gspca_dev.usb_err = ret;
1984 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1985 * the same position as 1's in "mask" are cleared and set to "value". Bits
1986 * that are in the same position as 0's in "mask" are preserved, regardless
1987 * of their respective state in "value".
1989 static void reg_w_mask(struct sd *sd,
1998 value &= mask; /* Enforce mask on value */
1999 ret = reg_r(sd, index);
2003 oldval = ret & ~mask; /* Clear the masked bits */
2004 value |= oldval; /* Set the desired bits */
2006 reg_w(sd, index, value);
2010 * Writes multiple (n) byte value to a single register. Only valid with certain
2011 * registers (0x30 and 0xc4 - 0xce).
2013 static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
2017 if (sd->gspca_dev.usb_err < 0)
2020 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
2022 ret = usb_control_msg(sd->gspca_dev.dev,
2023 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2025 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2027 sd->gspca_dev.usb_buf, n, 500);
2029 err("reg_w32 %02x failed %d", index, ret);
2030 sd->gspca_dev.usb_err = ret;
2034 static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
2038 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value);
2040 /* Three byte write cycle */
2041 for (retries = 6; ; ) {
2042 /* Select camera register */
2043 reg_w(sd, R51x_I2C_SADDR_3, reg);
2045 /* Write "value" to I2C data port of OV511 */
2046 reg_w(sd, R51x_I2C_DATA, value);
2048 /* Initiate 3-byte write cycle */
2049 reg_w(sd, R511_I2C_CTL, 0x01);
2052 rc = reg_r(sd, R511_I2C_CTL);
2053 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
2058 if ((rc & 2) == 0) /* Ack? */
2060 if (--retries < 0) {
2061 PDEBUG(D_USBO, "i2c write retries exhausted");
2067 static int ov511_i2c_r(struct sd *sd, u8 reg)
2069 int rc, value, retries;
2071 /* Two byte write cycle */
2072 for (retries = 6; ; ) {
2073 /* Select camera register */
2074 reg_w(sd, R51x_I2C_SADDR_2, reg);
2076 /* Initiate 2-byte write cycle */
2077 reg_w(sd, R511_I2C_CTL, 0x03);
2080 rc = reg_r(sd, R511_I2C_CTL);
2081 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
2086 if ((rc & 2) == 0) /* Ack? */
2090 reg_w(sd, R511_I2C_CTL, 0x10);
2092 if (--retries < 0) {
2093 PDEBUG(D_USBI, "i2c write retries exhausted");
2098 /* Two byte read cycle */
2099 for (retries = 6; ; ) {
2100 /* Initiate 2-byte read cycle */
2101 reg_w(sd, R511_I2C_CTL, 0x05);
2104 rc = reg_r(sd, R511_I2C_CTL);
2105 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
2110 if ((rc & 2) == 0) /* Ack? */
2114 reg_w(sd, R511_I2C_CTL, 0x10);
2116 if (--retries < 0) {
2117 PDEBUG(D_USBI, "i2c read retries exhausted");
2122 value = reg_r(sd, R51x_I2C_DATA);
2124 PDEBUG(D_USBI, "ov511_i2c_r %02x %02x", reg, value);
2126 /* This is needed to make i2c_w() work */
2127 reg_w(sd, R511_I2C_CTL, 0x05);
2133 * The OV518 I2C I/O procedure is different, hence, this function.
2134 * This is normally only called from i2c_w(). Note that this function
2135 * always succeeds regardless of whether the sensor is present and working.
2137 static void ov518_i2c_w(struct sd *sd,
2141 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value);
2143 /* Select camera register */
2144 reg_w(sd, R51x_I2C_SADDR_3, reg);
2146 /* Write "value" to I2C data port of OV511 */
2147 reg_w(sd, R51x_I2C_DATA, value);
2149 /* Initiate 3-byte write cycle */
2150 reg_w(sd, R518_I2C_CTL, 0x01);
2152 /* wait for write complete */
2154 reg_r8(sd, R518_I2C_CTL);
2158 * returns: negative is error, pos or zero is data
2160 * The OV518 I2C I/O procedure is different, hence, this function.
2161 * This is normally only called from i2c_r(). Note that this function
2162 * always succeeds regardless of whether the sensor is present and working.
2164 static int ov518_i2c_r(struct sd *sd, u8 reg)
2168 /* Select camera register */
2169 reg_w(sd, R51x_I2C_SADDR_2, reg);
2171 /* Initiate 2-byte write cycle */
2172 reg_w(sd, R518_I2C_CTL, 0x03);
2174 /* Initiate 2-byte read cycle */
2175 reg_w(sd, R518_I2C_CTL, 0x05);
2176 value = reg_r(sd, R51x_I2C_DATA);
2177 PDEBUG(D_USBI, "ov518_i2c_r %02x %02x", reg, value);
2181 static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
2185 if (sd->gspca_dev.usb_err < 0)
2188 ret = usb_control_msg(sd->gspca_dev.dev,
2189 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2191 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2192 (u16) value, (u16) reg, NULL, 0, 500);
2195 err("ovfx2_i2c_w %02x failed %d", reg, ret);
2196 sd->gspca_dev.usb_err = ret;
2199 PDEBUG(D_USBO, "ovfx2_i2c_w %02x %02x", reg, value);
2202 static int ovfx2_i2c_r(struct sd *sd, u8 reg)
2206 if (sd->gspca_dev.usb_err < 0)
2209 ret = usb_control_msg(sd->gspca_dev.dev,
2210 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2212 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2213 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
2216 ret = sd->gspca_dev.usb_buf[0];
2217 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
2219 err("ovfx2_i2c_r %02x failed %d", reg, ret);
2220 sd->gspca_dev.usb_err = ret;
2226 static void i2c_w(struct sd *sd, u8 reg, u8 value)
2228 if (sd->sensor_reg_cache[reg] == value)
2231 switch (sd->bridge) {
2233 case BRIDGE_OV511PLUS:
2234 ov511_i2c_w(sd, reg, value);
2237 case BRIDGE_OV518PLUS:
2239 ov518_i2c_w(sd, reg, value);
2242 ovfx2_i2c_w(sd, reg, value);
2244 case BRIDGE_W9968CF:
2245 w9968cf_i2c_w(sd, reg, value);
2249 if (sd->gspca_dev.usb_err >= 0) {
2250 /* Up on sensor reset empty the register cache */
2251 if (reg == 0x12 && (value & 0x80))
2252 memset(sd->sensor_reg_cache, -1,
2253 sizeof(sd->sensor_reg_cache));
2255 sd->sensor_reg_cache[reg] = value;
2259 static int i2c_r(struct sd *sd, u8 reg)
2263 if (sd->sensor_reg_cache[reg] != -1)
2264 return sd->sensor_reg_cache[reg];
2266 switch (sd->bridge) {
2268 case BRIDGE_OV511PLUS:
2269 ret = ov511_i2c_r(sd, reg);
2272 case BRIDGE_OV518PLUS:
2274 ret = ov518_i2c_r(sd, reg);
2277 ret = ovfx2_i2c_r(sd, reg);
2279 case BRIDGE_W9968CF:
2280 ret = w9968cf_i2c_r(sd, reg);
2285 sd->sensor_reg_cache[reg] = ret;
2290 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
2291 * the same position as 1's in "mask" are cleared and set to "value". Bits
2292 * that are in the same position as 0's in "mask" are preserved, regardless
2293 * of their respective state in "value".
2295 static void i2c_w_mask(struct sd *sd,
2303 value &= mask; /* Enforce mask on value */
2304 rc = i2c_r(sd, reg);
2307 oldval = rc & ~mask; /* Clear the masked bits */
2308 value |= oldval; /* Set the desired bits */
2309 i2c_w(sd, reg, value);
2312 /* Temporarily stops OV511 from functioning. Must do this before changing
2313 * registers while the camera is streaming */
2314 static inline void ov51x_stop(struct sd *sd)
2316 PDEBUG(D_STREAM, "stopping");
2318 switch (sd->bridge) {
2320 case BRIDGE_OV511PLUS:
2321 reg_w(sd, R51x_SYS_RESET, 0x3d);
2324 case BRIDGE_OV518PLUS:
2325 reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2328 reg_w(sd, OV519_R51_RESET1, 0x0f);
2329 reg_w(sd, OV519_R51_RESET1, 0x00);
2330 reg_w(sd, 0x22, 0x00); /* FRAR */
2333 reg_w_mask(sd, 0x0f, 0x00, 0x02);
2335 case BRIDGE_W9968CF:
2336 reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
2341 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2342 * actually stopped (for performance). */
2343 static inline void ov51x_restart(struct sd *sd)
2345 PDEBUG(D_STREAM, "restarting");
2350 /* Reinitialize the stream */
2351 switch (sd->bridge) {
2353 case BRIDGE_OV511PLUS:
2354 reg_w(sd, R51x_SYS_RESET, 0x00);
2357 case BRIDGE_OV518PLUS:
2358 reg_w(sd, 0x2f, 0x80);
2359 reg_w(sd, R51x_SYS_RESET, 0x00);
2362 reg_w(sd, OV519_R51_RESET1, 0x0f);
2363 reg_w(sd, OV519_R51_RESET1, 0x00);
2364 reg_w(sd, 0x22, 0x1d); /* FRAR */
2367 reg_w_mask(sd, 0x0f, 0x02, 0x02);
2369 case BRIDGE_W9968CF:
2370 reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
2375 static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
2377 /* This does an initial reset of an OmniVision sensor and ensures that I2C
2378 * is synchronized. Returns <0 on failure.
2380 static int init_ov_sensor(struct sd *sd, u8 slave)
2384 ov51x_set_slave_ids(sd, slave);
2386 /* Reset the sensor */
2387 i2c_w(sd, 0x12, 0x80);
2389 /* Wait for it to initialize */
2392 for (i = 0; i < i2c_detect_tries; i++) {
2393 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
2394 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
2395 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
2399 /* Reset the sensor */
2400 i2c_w(sd, 0x12, 0x80);
2402 /* Wait for it to initialize */
2405 /* Dummy read to sync I2C */
2406 if (i2c_r(sd, 0x00) < 0)
2412 /* Set the read and write slave IDs. The "slave" argument is the write slave,
2413 * and the read slave will be set to (slave + 1).
2414 * This should not be called from outside the i2c I/O functions.
2415 * Sets I2C read and write slave IDs. Returns <0 for error
2417 static void ov51x_set_slave_ids(struct sd *sd,
2420 switch (sd->bridge) {
2422 reg_w(sd, OVFX2_I2C_ADDR, slave);
2424 case BRIDGE_W9968CF:
2425 sd->sensor_addr = slave;
2429 reg_w(sd, R51x_I2C_W_SID, slave);
2430 reg_w(sd, R51x_I2C_R_SID, slave + 1);
2433 static void write_regvals(struct sd *sd,
2434 const struct ov_regvals *regvals,
2438 reg_w(sd, regvals->reg, regvals->val);
2443 static void write_i2c_regvals(struct sd *sd,
2444 const struct ov_i2c_regvals *regvals,
2448 i2c_w(sd, regvals->reg, regvals->val);
2453 /****************************************************************************
2455 * OV511 and sensor configuration
2457 ***************************************************************************/
2459 /* This initializes the OV2x10 / OV3610 / OV3620 */
2460 static void ov_hires_configure(struct sd *sd)
2464 if (sd->bridge != BRIDGE_OVFX2) {
2465 err("error hires sensors only supported with ovfx2");
2469 PDEBUG(D_PROBE, "starting ov hires configuration");
2471 /* Detect sensor (sub)type */
2472 high = i2c_r(sd, 0x0a);
2473 low = i2c_r(sd, 0x0b);
2474 /* info("%x, %x", high, low); */
2475 if (high == 0x96 && low == 0x40) {
2476 PDEBUG(D_PROBE, "Sensor is an OV2610");
2477 sd->sensor = SEN_OV2610;
2478 } else if (high == 0x36 && (low & 0x0f) == 0x00) {
2479 PDEBUG(D_PROBE, "Sensor is an OV3610");
2480 sd->sensor = SEN_OV3610;
2482 err("Error unknown sensor type: %02x%02x",
2487 /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2488 * the same register settings as the OV8610, since they are very similar.
2490 static void ov8xx0_configure(struct sd *sd)
2494 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
2496 /* Detect sensor (sub)type */
2497 rc = i2c_r(sd, OV7610_REG_COM_I);
2499 PDEBUG(D_ERR, "Error detecting sensor type");
2503 sd->sensor = SEN_OV8610;
2505 err("Unknown image sensor version: %d", rc & 3);
2508 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2509 * the same register settings as the OV7610, since they are very similar.
2511 static void ov7xx0_configure(struct sd *sd)
2515 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2517 /* Detect sensor (sub)type */
2518 rc = i2c_r(sd, OV7610_REG_COM_I);
2521 * it appears to be wrongly detected as a 7610 by default */
2523 PDEBUG(D_ERR, "Error detecting sensor type");
2526 if ((rc & 3) == 3) {
2527 /* quick hack to make OV7670s work */
2528 high = i2c_r(sd, 0x0a);
2529 low = i2c_r(sd, 0x0b);
2530 /* info("%x, %x", high, low); */
2531 if (high == 0x76 && low == 0x73) {
2532 PDEBUG(D_PROBE, "Sensor is an OV7670");
2533 sd->sensor = SEN_OV7670;
2535 PDEBUG(D_PROBE, "Sensor is an OV7610");
2536 sd->sensor = SEN_OV7610;
2538 } else if ((rc & 3) == 1) {
2539 /* I don't know what's different about the 76BE yet. */
2540 if (i2c_r(sd, 0x15) & 1) {
2541 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
2542 sd->sensor = SEN_OV7620AE;
2544 PDEBUG(D_PROBE, "Sensor is an OV76BE");
2545 sd->sensor = SEN_OV76BE;
2547 } else if ((rc & 3) == 0) {
2548 /* try to read product id registers */
2549 high = i2c_r(sd, 0x0a);
2551 PDEBUG(D_ERR, "Error detecting camera chip PID");
2554 low = i2c_r(sd, 0x0b);
2556 PDEBUG(D_ERR, "Error detecting camera chip VER");
2562 err("Sensor is an OV7630/OV7635");
2563 err("7630 is not supported by this driver");
2566 PDEBUG(D_PROBE, "Sensor is an OV7645");
2567 sd->sensor = SEN_OV7640; /* FIXME */
2570 PDEBUG(D_PROBE, "Sensor is an OV7645B");
2571 sd->sensor = SEN_OV7640; /* FIXME */
2574 PDEBUG(D_PROBE, "Sensor is an OV7648");
2575 sd->sensor = SEN_OV7648;
2578 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
2582 PDEBUG(D_PROBE, "Sensor is an OV7620");
2583 sd->sensor = SEN_OV7620;
2586 err("Unknown image sensor version: %d", rc & 3);
2590 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
2591 static void ov6xx0_configure(struct sd *sd)
2594 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
2596 /* Detect sensor (sub)type */
2597 rc = i2c_r(sd, OV7610_REG_COM_I);
2599 PDEBUG(D_ERR, "Error detecting sensor type");
2603 /* Ugh. The first two bits are the version bits, but
2604 * the entire register value must be used. I guess OVT
2605 * underestimated how many variants they would make. */
2608 sd->sensor = SEN_OV6630;
2609 warn("WARNING: Sensor is an OV66308. Your camera may have");
2610 warn("been misdetected in previous driver versions.");
2613 sd->sensor = SEN_OV6620;
2614 PDEBUG(D_PROBE, "Sensor is an OV6620");
2617 sd->sensor = SEN_OV6630;
2618 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
2621 sd->sensor = SEN_OV66308AF;
2622 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
2625 sd->sensor = SEN_OV6630;
2626 warn("WARNING: Sensor is an OV66307. Your camera may have");
2627 warn("been misdetected in previous driver versions.");
2630 err("FATAL: Unknown sensor version: 0x%02x", rc);
2634 /* Set sensor-specific vars */
2638 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
2639 static void ov51x_led_control(struct sd *sd, int on)
2644 switch (sd->bridge) {
2645 /* OV511 has no LED control */
2646 case BRIDGE_OV511PLUS:
2647 reg_w(sd, R511_SYS_LED_CTL, on);
2650 case BRIDGE_OV518PLUS:
2651 reg_w_mask(sd, R518_GPIO_OUT, 0x02 * on, 0x02);
2654 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, on, 1);
2659 static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2661 struct sd *sd = (struct sd *) gspca_dev;
2663 if (!sd->snapshot_needs_reset)
2666 /* Note it is important that we clear sd->snapshot_needs_reset,
2667 before actually clearing the snapshot state in the bridge
2668 otherwise we might race with the pkt_scan interrupt handler */
2669 sd->snapshot_needs_reset = 0;
2671 switch (sd->bridge) {
2673 case BRIDGE_OV511PLUS:
2674 reg_w(sd, R51x_SYS_SNAP, 0x02);
2675 reg_w(sd, R51x_SYS_SNAP, 0x00);
2678 case BRIDGE_OV518PLUS:
2679 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2680 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2683 reg_w(sd, R51x_SYS_RESET, 0x40);
2684 reg_w(sd, R51x_SYS_RESET, 0x00);
2689 static void ov51x_upload_quan_tables(struct sd *sd)
2691 const unsigned char yQuanTable511[] = {
2692 0, 1, 1, 2, 2, 3, 3, 4,
2693 1, 1, 1, 2, 2, 3, 4, 4,
2694 1, 1, 2, 2, 3, 4, 4, 4,
2695 2, 2, 2, 3, 4, 4, 4, 4,
2696 2, 2, 3, 4, 4, 5, 5, 5,
2697 3, 3, 4, 4, 5, 5, 5, 5,
2698 3, 4, 4, 4, 5, 5, 5, 5,
2699 4, 4, 4, 4, 5, 5, 5, 5
2702 const unsigned char uvQuanTable511[] = {
2703 0, 2, 2, 3, 4, 4, 4, 4,
2704 2, 2, 2, 4, 4, 4, 4, 4,
2705 2, 2, 3, 4, 4, 4, 4, 4,
2706 3, 4, 4, 4, 4, 4, 4, 4,
2707 4, 4, 4, 4, 4, 4, 4, 4,
2708 4, 4, 4, 4, 4, 4, 4, 4,
2709 4, 4, 4, 4, 4, 4, 4, 4,
2710 4, 4, 4, 4, 4, 4, 4, 4
2713 /* OV518 quantization tables are 8x4 (instead of 8x8) */
2714 const unsigned char yQuanTable518[] = {
2715 5, 4, 5, 6, 6, 7, 7, 7,
2716 5, 5, 5, 5, 6, 7, 7, 7,
2717 6, 6, 6, 6, 7, 7, 7, 8,
2718 7, 7, 6, 7, 7, 7, 8, 8
2720 const unsigned char uvQuanTable518[] = {
2721 6, 6, 6, 7, 7, 7, 7, 7,
2722 6, 6, 6, 7, 7, 7, 7, 7,
2723 6, 6, 6, 7, 7, 7, 7, 8,
2724 7, 7, 7, 7, 7, 7, 8, 8
2727 const unsigned char *pYTable, *pUVTable;
2728 unsigned char val0, val1;
2729 int i, size, reg = R51x_COMP_LUT_BEGIN;
2731 PDEBUG(D_PROBE, "Uploading quantization tables");
2733 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2734 pYTable = yQuanTable511;
2735 pUVTable = uvQuanTable511;
2738 pYTable = yQuanTable518;
2739 pUVTable = uvQuanTable518;
2743 for (i = 0; i < size; i++) {
2749 reg_w(sd, reg, val0);
2756 reg_w(sd, reg + size, val0);
2762 /* This initializes the OV511/OV511+ and the sensor */
2763 static void ov511_configure(struct gspca_dev *gspca_dev)
2765 struct sd *sd = (struct sd *) gspca_dev;
2767 /* For 511 and 511+ */
2768 const struct ov_regvals init_511[] = {
2769 { R51x_SYS_RESET, 0x7f },
2770 { R51x_SYS_INIT, 0x01 },
2771 { R51x_SYS_RESET, 0x7f },
2772 { R51x_SYS_INIT, 0x01 },
2773 { R51x_SYS_RESET, 0x3f },
2774 { R51x_SYS_INIT, 0x01 },
2775 { R51x_SYS_RESET, 0x3d },
2778 const struct ov_regvals norm_511[] = {
2779 { R511_DRAM_FLOW_CTL, 0x01 },
2780 { R51x_SYS_SNAP, 0x00 },
2781 { R51x_SYS_SNAP, 0x02 },
2782 { R51x_SYS_SNAP, 0x00 },
2783 { R511_FIFO_OPTS, 0x1f },
2784 { R511_COMP_EN, 0x00 },
2785 { R511_COMP_LUT_EN, 0x03 },
2788 const struct ov_regvals norm_511_p[] = {
2789 { R511_DRAM_FLOW_CTL, 0xff },
2790 { R51x_SYS_SNAP, 0x00 },
2791 { R51x_SYS_SNAP, 0x02 },
2792 { R51x_SYS_SNAP, 0x00 },
2793 { R511_FIFO_OPTS, 0xff },
2794 { R511_COMP_EN, 0x00 },
2795 { R511_COMP_LUT_EN, 0x03 },
2798 const struct ov_regvals compress_511[] = {
2809 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2811 write_regvals(sd, init_511, ARRAY_SIZE(init_511));
2813 switch (sd->bridge) {
2815 write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
2817 case BRIDGE_OV511PLUS:
2818 write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
2822 /* Init compression */
2823 write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
2825 ov51x_upload_quan_tables(sd);
2828 /* This initializes the OV518/OV518+ and the sensor */
2829 static void ov518_configure(struct gspca_dev *gspca_dev)
2831 struct sd *sd = (struct sd *) gspca_dev;
2833 /* For 518 and 518+ */
2834 const struct ov_regvals init_518[] = {
2835 { R51x_SYS_RESET, 0x40 },
2836 { R51x_SYS_INIT, 0xe1 },
2837 { R51x_SYS_RESET, 0x3e },
2838 { R51x_SYS_INIT, 0xe1 },
2839 { R51x_SYS_RESET, 0x00 },
2840 { R51x_SYS_INIT, 0xe1 },
2845 const struct ov_regvals norm_518[] = {
2846 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2847 { R51x_SYS_SNAP, 0x01 }, /* Enable */
2858 const struct ov_regvals norm_518_p[] = {
2859 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2860 { R51x_SYS_SNAP, 0x01 }, /* Enable */
2877 /* First 5 bits of custom ID reg are a revision ID on OV518 */
2878 PDEBUG(D_PROBE, "Device revision %d",
2879 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
2881 write_regvals(sd, init_518, ARRAY_SIZE(init_518));
2883 /* Set LED GPIO pin to output mode */
2884 reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
2886 switch (sd->bridge) {
2888 write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
2890 case BRIDGE_OV518PLUS:
2891 write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
2895 ov51x_upload_quan_tables(sd);
2897 reg_w(sd, 0x2f, 0x80);
2900 static void ov519_configure(struct sd *sd)
2902 static const struct ov_regvals init_519[] = {
2903 { 0x5a, 0x6d }, /* EnableSystem */
2905 { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
2909 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
2910 * detection will fail. This deserves further investigation. */
2911 { OV519_GPIO_IO_CTRL0, 0xee },
2912 { OV519_R51_RESET1, 0x0f },
2913 { OV519_R51_RESET1, 0x00 },
2915 /* windows reads 0x55 at this point*/
2918 write_regvals(sd, init_519, ARRAY_SIZE(init_519));
2921 static void ovfx2_configure(struct sd *sd)
2923 static const struct ov_regvals init_fx2[] = {
2935 write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
2938 /* this function is called at probe time */
2939 static int sd_config(struct gspca_dev *gspca_dev,
2940 const struct usb_device_id *id)
2942 struct sd *sd = (struct sd *) gspca_dev;
2943 struct cam *cam = &gspca_dev->cam;
2945 sd->bridge = id->driver_info & BRIDGE_MASK;
2946 sd->invert_led = (id->driver_info & BRIDGE_INVERT_LED) != 0;
2948 switch (sd->bridge) {
2950 case BRIDGE_OV511PLUS:
2951 cam->cam_mode = ov511_vga_mode;
2952 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
2955 case BRIDGE_OV518PLUS:
2956 cam->cam_mode = ov518_vga_mode;
2957 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
2960 cam->cam_mode = ov519_vga_mode;
2961 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2962 sd->invert_led = !sd->invert_led;
2965 cam->cam_mode = ov519_vga_mode;
2966 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2967 cam->bulk_size = OVFX2_BULK_SIZE;
2968 cam->bulk_nurbs = MAX_NURBS;
2971 case BRIDGE_W9968CF:
2972 cam->cam_mode = w9968cf_vga_mode;
2973 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
2974 cam->reverse_alts = 1;
2978 gspca_dev->cam.ctrls = sd->ctrls;
2979 sd->quality = QUALITY_DEF;
2984 /* this function is called at probe and resume time */
2985 static int sd_init(struct gspca_dev *gspca_dev)
2987 struct sd *sd = (struct sd *) gspca_dev;
2988 struct cam *cam = &gspca_dev->cam;
2990 switch (sd->bridge) {
2992 case BRIDGE_OV511PLUS:
2993 ov511_configure(gspca_dev);
2996 case BRIDGE_OV518PLUS:
2997 ov518_configure(gspca_dev);
3000 ov519_configure(sd);
3003 ovfx2_configure(sd);
3005 case BRIDGE_W9968CF:
3006 w9968cf_configure(sd);
3010 /* The OV519 must be more aggressive about sensor detection since
3011 * I2C write will never fail if the sensor is not present. We have
3012 * to try to initialize the sensor to detect its presence */
3016 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
3017 ov7xx0_configure(sd);
3020 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
3021 ov6xx0_configure(sd);
3024 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
3025 ov8xx0_configure(sd);
3027 /* Test for 3xxx / 2xxx */
3028 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
3029 ov_hires_configure(sd);
3031 err("Can't determine sensor slave IDs");
3038 ov51x_led_control(sd, 0); /* turn LED off */
3040 switch (sd->bridge) {
3042 case BRIDGE_OV511PLUS:
3044 cam->cam_mode = ov511_sif_mode;
3045 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3049 case BRIDGE_OV518PLUS:
3051 cam->cam_mode = ov518_sif_mode;
3052 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3057 cam->cam_mode = ov519_sif_mode;
3058 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3062 if (sd->sensor == SEN_OV2610) {
3063 cam->cam_mode = ovfx2_ov2610_mode;
3064 cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
3065 } else if (sd->sensor == SEN_OV3610) {
3066 cam->cam_mode = ovfx2_ov3610_mode;
3067 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
3068 } else if (sd->sif) {
3069 cam->cam_mode = ov519_sif_mode;
3070 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3073 case BRIDGE_W9968CF:
3075 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode) - 1;
3077 /* w9968cf needs initialisation once the sensor is known */
3082 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
3084 /* initialize the sensor */
3085 switch (sd->sensor) {
3087 write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610));
3089 /* Enable autogain, autoexpo, awb, bandfilter */
3090 i2c_w_mask(sd, 0x13, 0x27, 0x27);
3093 write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b));
3095 /* Enable autogain, autoexpo, awb, bandfilter */
3096 i2c_w_mask(sd, 0x13, 0x27, 0x27);
3099 write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20));
3103 sd->ctrls[CONTRAST].def = 200;
3104 /* The default is too low for the ov6630 */
3105 write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30));
3108 /* case SEN_OV7610: */
3109 /* case SEN_OV76BE: */
3110 write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610));
3111 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
3115 write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620));
3119 write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640));
3122 sd->ctrls[FREQ].max = 3; /* auto */
3123 sd->ctrls[FREQ].def = 3;
3124 write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670));
3127 write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610));
3130 return gspca_dev->usb_err;
3132 PDEBUG(D_ERR, "OV519 Config failed");
3136 /* Set up the OV511/OV511+ with the given image parameters.
3138 * Do not put any sensor-specific code in here (including I2C I/O functions)
3140 static void ov511_mode_init_regs(struct sd *sd)
3142 int hsegs, vsegs, packet_size, fps, needed;
3144 struct usb_host_interface *alt;
3145 struct usb_interface *intf;
3147 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3148 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3150 err("Couldn't get altsetting");
3151 sd->gspca_dev.usb_err = -EIO;
3155 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3156 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
3158 reg_w(sd, R511_CAM_UV_EN, 0x01);
3159 reg_w(sd, R511_SNAP_UV_EN, 0x01);
3160 reg_w(sd, R511_SNAP_OPTS, 0x03);
3162 /* Here I'm assuming that snapshot size == image size.
3163 * I hope that's always true. --claudio
3165 hsegs = (sd->gspca_dev.width >> 3) - 1;
3166 vsegs = (sd->gspca_dev.height >> 3) - 1;
3168 reg_w(sd, R511_CAM_PXCNT, hsegs);
3169 reg_w(sd, R511_CAM_LNCNT, vsegs);
3170 reg_w(sd, R511_CAM_PXDIV, 0x00);
3171 reg_w(sd, R511_CAM_LNDIV, 0x00);
3173 /* YUV420, low pass filter on */
3174 reg_w(sd, R511_CAM_OPTS, 0x03);
3176 /* Snapshot additions */
3177 reg_w(sd, R511_SNAP_PXCNT, hsegs);
3178 reg_w(sd, R511_SNAP_LNCNT, vsegs);
3179 reg_w(sd, R511_SNAP_PXDIV, 0x00);
3180 reg_w(sd, R511_SNAP_LNDIV, 0x00);
3182 /******** Set the framerate ********/
3184 sd->frame_rate = frame_rate;
3186 switch (sd->sensor) {
3188 /* No framerate control, doesn't like higher rates yet */
3192 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3193 for more sensors we need to do this for them too */
3199 if (sd->gspca_dev.width == 320)
3205 switch (sd->frame_rate) {
3208 /* Not enough bandwidth to do 640x480 @ 30 fps */
3209 if (sd->gspca_dev.width != 640) {
3213 /* Fall through for 640x480 case */
3227 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
3228 /* Higher then 10 does not work */
3229 if (sd->clockdiv > 10)
3235 /* No framerate control ?? */
3240 /* Check if we have enough bandwidth to disable compression */
3241 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3242 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
3243 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
3244 if (needed > 1400 * packet_size) {
3245 /* Enable Y and UV quantization and compression */
3246 reg_w(sd, R511_COMP_EN, 0x07);
3247 reg_w(sd, R511_COMP_LUT_EN, 0x03);
3249 reg_w(sd, R511_COMP_EN, 0x06);
3250 reg_w(sd, R511_COMP_LUT_EN, 0x00);
3253 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3254 reg_w(sd, R51x_SYS_RESET, 0);
3257 /* Sets up the OV518/OV518+ with the given image parameters
3259 * OV518 needs a completely different approach, until we can figure out what
3260 * the individual registers do. Also, only 15 FPS is supported now.
3262 * Do not put any sensor-specific code in here (including I2C I/O functions)
3264 static void ov518_mode_init_regs(struct sd *sd)
3266 int hsegs, vsegs, packet_size;
3267 struct usb_host_interface *alt;
3268 struct usb_interface *intf;
3270 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3271 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3273 err("Couldn't get altsetting");
3274 sd->gspca_dev.usb_err = -EIO;
3278 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3279 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
3281 /******** Set the mode ********/
3291 if (sd->bridge == BRIDGE_OV518) {
3292 /* Set 8-bit (YVYU) input format */
3293 reg_w_mask(sd, 0x20, 0x08, 0x08);
3295 /* Set 12-bit (4:2:0) output format */
3296 reg_w_mask(sd, 0x28, 0x80, 0xf0);
3297 reg_w_mask(sd, 0x38, 0x80, 0xf0);
3299 reg_w(sd, 0x28, 0x80);
3300 reg_w(sd, 0x38, 0x80);
3303 hsegs = sd->gspca_dev.width / 16;
3304 vsegs = sd->gspca_dev.height / 4;
3306 reg_w(sd, 0x29, hsegs);
3307 reg_w(sd, 0x2a, vsegs);
3309 reg_w(sd, 0x39, hsegs);
3310 reg_w(sd, 0x3a, vsegs);
3312 /* Windows driver does this here; who knows why */
3313 reg_w(sd, 0x2f, 0x80);
3315 /******** Set the framerate ********/
3318 /* Mode independent, but framerate dependent, regs */
3319 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
3320 reg_w(sd, 0x51, 0x04);
3321 reg_w(sd, 0x22, 0x18);
3322 reg_w(sd, 0x23, 0xff);
3324 if (sd->bridge == BRIDGE_OV518PLUS) {
3325 switch (sd->sensor) {
3327 if (sd->gspca_dev.width == 320) {
3328 reg_w(sd, 0x20, 0x00);
3329 reg_w(sd, 0x21, 0x19);
3331 reg_w(sd, 0x20, 0x60);
3332 reg_w(sd, 0x21, 0x1f);
3336 reg_w(sd, 0x20, 0x00);
3337 reg_w(sd, 0x21, 0x19);
3340 reg_w(sd, 0x21, 0x19);
3343 reg_w(sd, 0x71, 0x17); /* Compression-related? */
3345 /* FIXME: Sensor-specific */
3346 /* Bit 5 is what matters here. Of course, it is "reserved" */
3347 i2c_w(sd, 0x54, 0x23);
3349 reg_w(sd, 0x2f, 0x80);
3351 if (sd->bridge == BRIDGE_OV518PLUS) {
3352 reg_w(sd, 0x24, 0x94);
3353 reg_w(sd, 0x25, 0x90);
3354 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3355 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
3356 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
3357 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
3358 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
3359 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
3360 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
3361 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
3362 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
3364 reg_w(sd, 0x24, 0x9f);
3365 reg_w(sd, 0x25, 0x90);
3366 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3367 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
3368 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
3369 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
3370 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
3371 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
3372 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
3373 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
3374 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
3377 reg_w(sd, 0x2f, 0x80);
3380 /* Sets up the OV519 with the given image parameters
3382 * OV519 needs a completely different approach, until we can figure out what
3383 * the individual registers do.
3385 * Do not put any sensor-specific code in here (including I2C I/O functions)
3387 static void ov519_mode_init_regs(struct sd *sd)
3389 static const struct ov_regvals mode_init_519_ov7670[] = {
3390 { 0x5d, 0x03 }, /* Turn off suspend mode */
3391 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
3392 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
3393 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3397 { 0x37, 0x00 }, /* SetUsbInit */
3398 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3399 /* Enable both fields, YUV Input, disable defect comp (why?) */
3403 { 0x17, 0x50 }, /* undocumented */
3404 { 0x37, 0x00 }, /* undocumented */
3405 { 0x40, 0xff }, /* I2C timeout counter */
3406 { 0x46, 0x00 }, /* I2C clock prescaler */
3407 { 0x59, 0x04 }, /* new from windrv 090403 */
3408 { 0xff, 0x00 }, /* undocumented */
3409 /* windows reads 0x55 at this point, why? */
3412 static const struct ov_regvals mode_init_519[] = {
3413 { 0x5d, 0x03 }, /* Turn off suspend mode */
3414 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
3415 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
3416 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3420 { 0x37, 0x00 }, /* SetUsbInit */
3421 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3422 /* Enable both fields, YUV Input, disable defect comp (why?) */
3424 { 0x17, 0x50 }, /* undocumented */
3425 { 0x37, 0x00 }, /* undocumented */
3426 { 0x40, 0xff }, /* I2C timeout counter */
3427 { 0x46, 0x00 }, /* I2C clock prescaler */
3428 { 0x59, 0x04 }, /* new from windrv 090403 */
3429 { 0xff, 0x00 }, /* undocumented */
3430 /* windows reads 0x55 at this point, why? */
3433 /******** Set the mode ********/
3434 if (sd->sensor != SEN_OV7670) {
3435 write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519));
3436 if (sd->sensor == SEN_OV7640 ||
3437 sd->sensor == SEN_OV7648) {
3438 /* Select 8-bit input mode */
3439 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
3442 write_regvals(sd, mode_init_519_ov7670,
3443 ARRAY_SIZE(mode_init_519_ov7670));
3446 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
3447 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
3448 if (sd->sensor == SEN_OV7670 &&
3449 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3450 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
3451 else if (sd->sensor == SEN_OV7648 &&
3452 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3453 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
3455 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
3456 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
3457 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
3458 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
3459 reg_w(sd, OV519_R16_DIVIDER, 0x00);
3460 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
3461 reg_w(sd, 0x26, 0x00); /* Undocumented */
3463 /******** Set the framerate ********/
3465 sd->frame_rate = frame_rate;
3467 /* FIXME: These are only valid at the max resolution. */
3469 switch (sd->sensor) {
3472 switch (sd->frame_rate) {
3475 reg_w(sd, 0xa4, 0x0c);
3476 reg_w(sd, 0x23, 0xff);
3479 reg_w(sd, 0xa4, 0x0c);
3480 reg_w(sd, 0x23, 0x1f);
3483 reg_w(sd, 0xa4, 0x0c);
3484 reg_w(sd, 0x23, 0x1b);
3487 reg_w(sd, 0xa4, 0x04);
3488 reg_w(sd, 0x23, 0xff);
3492 reg_w(sd, 0xa4, 0x04);
3493 reg_w(sd, 0x23, 0x1f);
3497 reg_w(sd, 0xa4, 0x04);
3498 reg_w(sd, 0x23, 0x1b);
3504 switch (sd->frame_rate) {
3505 default: /* 15 fps */
3507 reg_w(sd, 0xa4, 0x06);
3508 reg_w(sd, 0x23, 0xff);
3511 reg_w(sd, 0xa4, 0x06);
3512 reg_w(sd, 0x23, 0x1f);
3515 reg_w(sd, 0xa4, 0x06);
3516 reg_w(sd, 0x23, 0x1b);
3520 case SEN_OV7670: /* guesses, based on 7640 */
3521 PDEBUG(D_STREAM, "Setting framerate to %d fps",
3522 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
3523 reg_w(sd, 0xa4, 0x10);
3524 switch (sd->frame_rate) {
3526 reg_w(sd, 0x23, 0xff);
3529 reg_w(sd, 0x23, 0x1b);
3533 reg_w(sd, 0x23, 0xff);
3541 static void mode_init_ov_sensor_regs(struct sd *sd)
3543 struct gspca_dev *gspca_dev;
3544 int qvga, xstart, xend, ystart, yend;
3547 gspca_dev = &sd->gspca_dev;
3548 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3550 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3551 switch (sd->sensor) {
3553 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3554 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3555 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3556 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3557 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3558 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3559 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
3563 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
3564 ystart = (776 - gspca_dev->height) / 2;
3566 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
3567 ystart = (1544 - gspca_dev->height) / 2;
3569 xend = xstart + gspca_dev->width;
3570 yend = ystart + gspca_dev->height;
3571 /* Writing to the COMH register resets the other windowing regs
3572 to their default values, so we must do this first. */
3573 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
3574 i2c_w_mask(sd, 0x32,
3575 (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
3577 i2c_w_mask(sd, 0x03,
3578 (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
3580 i2c_w(sd, 0x17, xstart >> 4);
3581 i2c_w(sd, 0x18, xend >> 4);
3582 i2c_w(sd, 0x19, ystart >> 3);
3583 i2c_w(sd, 0x1a, yend >> 3);
3586 /* For OV8610 qvga means qsvga */
3587 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
3588 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3589 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3590 i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
3591 i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
3594 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3595 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
3596 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3597 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3602 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3603 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3604 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3605 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3606 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3607 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
3608 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
3609 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3610 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3611 if (sd->sensor == SEN_OV76BE)
3612 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
3616 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3617 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3618 /* Setting this undocumented bit in qvga mode removes a very
3619 annoying vertical shaking of the image */
3620 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3622 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3623 /* Allow higher automatic gain (to allow higher framerates) */
3624 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
3625 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
3628 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3629 * do we need to set anything else?
3630 * HSTART etc are set in set_ov_sensor_window itself */
3631 i2c_w_mask(sd, OV7670_R12_COM7,
3632 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3633 OV7670_COM7_FMT_MASK);
3634 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3635 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
3637 if (qvga) { /* QVGA from ov7670.c by
3638 * Jonathan Corbet */
3649 /* OV7670 hardware window registers are split across
3650 * multiple locations */
3651 i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
3652 i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
3653 v = i2c_r(sd, OV7670_R32_HREF);
3654 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
3655 msleep(10); /* need to sleep between read and write to
3657 i2c_w(sd, OV7670_R32_HREF, v);
3659 i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
3660 i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
3661 v = i2c_r(sd, OV7670_R03_VREF);
3662 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
3663 msleep(10); /* need to sleep between read and write to
3665 i2c_w(sd, OV7670_R03_VREF, v);
3668 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3669 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3670 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3674 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3675 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3681 /******** Clock programming ********/
3682 i2c_w(sd, 0x11, sd->clockdiv);
3685 static void sethvflip(struct gspca_dev *gspca_dev)
3687 struct sd *sd = (struct sd *) gspca_dev;
3689 if (sd->gspca_dev.streaming)
3690 reg_w(sd, OV519_R51_RESET1, 0x0f); /* block stream */
3691 i2c_w_mask(sd, OV7670_R1E_MVFP,
3692 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
3693 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
3694 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
3695 if (sd->gspca_dev.streaming)
3696 reg_w(sd, OV519_R51_RESET1, 0x00); /* restart stream */
3699 static void set_ov_sensor_window(struct sd *sd)
3701 struct gspca_dev *gspca_dev;
3703 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
3705 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
3706 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 ||
3707 sd->sensor == SEN_OV7670) {
3708 mode_init_ov_sensor_regs(sd);
3711 gspca_dev = &sd->gspca_dev;
3712 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3713 crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
3715 /* The different sensor ICs handle setting up of window differently.
3716 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
3717 switch (sd->sensor) {
3728 vwsbase = vwebase = 0x05;
3737 if (sd->sensor == SEN_OV66308AF && qvga)
3738 /* HDG: this fixes U and V getting swapped */
3749 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
3751 vwsbase = vwebase = 0x05;
3757 vwsbase = vwebase = 0x03;
3763 switch (sd->sensor) {
3767 if (qvga) { /* QCIF */
3772 vwscale = 1; /* The datasheet says 0;
3777 if (qvga) { /* QSVGA */
3785 default: /* SEN_OV7xx0 */
3786 if (qvga) { /* QVGA */
3795 mode_init_ov_sensor_regs(sd);
3797 i2c_w(sd, 0x17, hwsbase);
3798 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
3799 i2c_w(sd, 0x19, vwsbase);
3800 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
3803 /* -- start the camera -- */
3804 static int sd_start(struct gspca_dev *gspca_dev)
3806 struct sd *sd = (struct sd *) gspca_dev;
3808 /* Default for most bridges, allow bridge_mode_init_regs to override */
3809 sd->sensor_width = sd->gspca_dev.width;
3810 sd->sensor_height = sd->gspca_dev.height;
3812 switch (sd->bridge) {
3814 case BRIDGE_OV511PLUS:
3815 ov511_mode_init_regs(sd);
3818 case BRIDGE_OV518PLUS:
3819 ov518_mode_init_regs(sd);
3822 ov519_mode_init_regs(sd);
3824 /* case BRIDGE_OVFX2: nothing to do */
3825 case BRIDGE_W9968CF:
3826 w9968cf_mode_init_regs(sd);
3830 set_ov_sensor_window(sd);
3832 if (!(sd->gspca_dev.ctrl_dis & (1 << CONTRAST)))
3833 setcontrast(gspca_dev);
3834 if (!(sd->gspca_dev.ctrl_dis & (1 << BRIGHTNESS)))
3835 setbrightness(gspca_dev);
3836 if (!(sd->gspca_dev.ctrl_dis & (1 << COLORS)))
3837 setcolors(gspca_dev);
3838 if (!(sd->gspca_dev.ctrl_dis & ((1 << HFLIP) | (1 << VFLIP))))
3839 sethvflip(gspca_dev);
3840 if (!(sd->gspca_dev.ctrl_dis & (1 << AUTOBRIGHT)))
3841 setautobright(gspca_dev);
3842 if (!(sd->gspca_dev.ctrl_dis & (1 << FREQ)))
3845 /* Force clear snapshot state in case the snapshot button was
3846 pressed while we weren't streaming */
3847 sd->snapshot_needs_reset = 1;
3848 sd_reset_snapshot(gspca_dev);
3850 sd->first_frame = 3;
3853 ov51x_led_control(sd, 1);
3854 return gspca_dev->usb_err;
3857 static void sd_stopN(struct gspca_dev *gspca_dev)
3859 struct sd *sd = (struct sd *) gspca_dev;
3862 ov51x_led_control(sd, 0);
3865 static void sd_stop0(struct gspca_dev *gspca_dev)
3867 struct sd *sd = (struct sd *) gspca_dev;
3869 if (!sd->gspca_dev.present)
3871 if (sd->bridge == BRIDGE_W9968CF)
3874 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3875 /* If the last button state is pressed, release it now! */
3876 if (sd->snapshot_pressed) {
3877 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
3878 input_sync(gspca_dev->input_dev);
3879 sd->snapshot_pressed = 0;
3882 if (sd->bridge == BRIDGE_OV519)
3883 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
3886 static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
3888 struct sd *sd = (struct sd *) gspca_dev;
3890 if (sd->snapshot_pressed != state) {
3891 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3892 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
3893 input_sync(gspca_dev->input_dev);
3896 sd->snapshot_needs_reset = 1;
3898 sd->snapshot_pressed = state;
3900 /* On the ov511 / ov519 we need to reset the button state
3901 multiple times, as resetting does not work as long as the
3902 button stays pressed */
3903 switch (sd->bridge) {
3905 case BRIDGE_OV511PLUS:
3908 sd->snapshot_needs_reset = 1;
3914 static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
3915 u8 *in, /* isoc packet */
3916 int len) /* iso packet length */
3918 struct sd *sd = (struct sd *) gspca_dev;
3920 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3921 * byte non-zero. The EOF packet has image width/height in the
3922 * 10th and 11th bytes. The 9th byte is given as follows:
3925 * 6: compression enabled
3926 * 5: 422/420/400 modes
3927 * 4: 422/420/400 modes
3929 * 2: snapshot button on
3933 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
3935 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
3938 if ((in[9] + 1) * 8 != gspca_dev->width ||
3939 (in[10] + 1) * 8 != gspca_dev->height) {
3940 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
3941 " requested: %dx%d\n",
3942 (in[9] + 1) * 8, (in[10] + 1) * 8,
3943 gspca_dev->width, gspca_dev->height);
3944 gspca_dev->last_packet_type = DISCARD_PACKET;
3947 /* Add 11 byte footer to frame, might be usefull */
3948 gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
3952 gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
3957 /* Ignore the packet number */
3960 /* intermediate packet */
3961 gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
3964 static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
3965 u8 *data, /* isoc packet */
3966 int len) /* iso packet length */
3968 struct sd *sd = (struct sd *) gspca_dev;
3970 /* A false positive here is likely, until OVT gives me
3971 * the definitive SOF/EOF format */
3972 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
3973 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
3974 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
3975 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
3979 if (gspca_dev->last_packet_type == DISCARD_PACKET)
3982 /* Does this device use packet numbers ? */
3985 if (sd->packet_nr == data[len])
3987 /* The last few packets of the frame (which are all 0's
3988 except that they may contain part of the footer), are
3990 else if (sd->packet_nr == 0 || data[len]) {
3991 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
3992 (int)data[len], (int)sd->packet_nr);
3993 gspca_dev->last_packet_type = DISCARD_PACKET;
3998 /* intermediate packet */
3999 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4002 static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
4003 u8 *data, /* isoc packet */
4004 int len) /* iso packet length */
4006 /* Header of ov519 is 16 bytes:
4007 * Byte Value Description
4011 * 3 0xXX 0x50 = SOF, 0x51 = EOF
4012 * 9 0xXX 0x01 initial frame without data,
4013 * 0x00 standard frame with image
4014 * 14 Lo in EOF: length of image data / 8
4018 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
4020 case 0x50: /* start of frame */
4021 /* Don't check the button state here, as the state
4022 usually (always ?) changes at EOF and checking it
4023 here leads to unnecessary snapshot state resets. */
4028 if (data[0] == 0xff || data[1] == 0xd8)
4029 gspca_frame_add(gspca_dev, FIRST_PACKET,
4032 gspca_dev->last_packet_type = DISCARD_PACKET;
4034 case 0x51: /* end of frame */
4035 ov51x_handle_button(gspca_dev, data[11] & 1);
4037 gspca_dev->last_packet_type = DISCARD_PACKET;
4038 gspca_frame_add(gspca_dev, LAST_PACKET,
4044 /* intermediate packet */
4045 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4048 static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
4049 u8 *data, /* isoc packet */
4050 int len) /* iso packet length */
4052 struct sd *sd = (struct sd *) gspca_dev;
4054 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4056 /* A short read signals EOF */
4057 if (len < OVFX2_BULK_SIZE) {
4058 /* If the frame is short, and it is one of the first ones
4059 the sensor and bridge are still syncing, so drop it. */
4060 if (sd->first_frame) {
4062 if (gspca_dev->image_len <
4063 sd->gspca_dev.width * sd->gspca_dev.height)
4064 gspca_dev->last_packet_type = DISCARD_PACKET;
4066 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
4067 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
4071 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
4072 u8 *data, /* isoc packet */
4073 int len) /* iso packet length */
4075 struct sd *sd = (struct sd *) gspca_dev;
4077 switch (sd->bridge) {
4079 case BRIDGE_OV511PLUS:
4080 ov511_pkt_scan(gspca_dev, data, len);
4083 case BRIDGE_OV518PLUS:
4084 ov518_pkt_scan(gspca_dev, data, len);
4087 ov519_pkt_scan(gspca_dev, data, len);
4090 ovfx2_pkt_scan(gspca_dev, data, len);
4092 case BRIDGE_W9968CF:
4093 w9968cf_pkt_scan(gspca_dev, data, len);
4098 /* -- management routines -- */
4100 static void setbrightness(struct gspca_dev *gspca_dev)
4102 struct sd *sd = (struct sd *) gspca_dev;
4105 val = sd->ctrls[BRIGHTNESS].val;
4106 switch (sd->sensor) {
4115 i2c_w(sd, OV7610_REG_BRT, val);
4119 /* 7620 doesn't like manual changes when in auto mode */
4120 if (!sd->ctrls[AUTOBRIGHT].val)
4121 i2c_w(sd, OV7610_REG_BRT, val);
4125 * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
4126 i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
4131 static void setcontrast(struct gspca_dev *gspca_dev)
4133 struct sd *sd = (struct sd *) gspca_dev;
4136 val = sd->ctrls[CONTRAST].val;
4137 switch (sd->sensor) {
4140 i2c_w(sd, OV7610_REG_CNT, val);
4144 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
4147 static const u8 ctab[] = {
4148 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4151 /* Use Y gamma control instead. Bit 0 enables it. */
4152 i2c_w(sd, 0x64, ctab[val >> 5]);
4156 case SEN_OV7620AE: {
4157 static const u8 ctab[] = {
4158 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4159 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4162 /* Use Y gamma control instead. Bit 0 enables it. */
4163 i2c_w(sd, 0x64, ctab[val >> 4]);
4167 /* check that this isn't just the same as ov7610 */
4168 i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
4173 static void setcolors(struct gspca_dev *gspca_dev)
4175 struct sd *sd = (struct sd *) gspca_dev;
4178 val = sd->ctrls[COLORS].val;
4179 switch (sd->sensor) {
4186 i2c_w(sd, OV7610_REG_SAT, val);
4190 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4191 /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4194 i2c_w(sd, OV7610_REG_SAT, val);
4198 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4201 /* supported later once I work out how to do it
4202 * transparently fail now! */
4203 /* set REG_COM13 values for UV sat auto mode */
4208 static void setautobright(struct gspca_dev *gspca_dev)
4210 struct sd *sd = (struct sd *) gspca_dev;
4212 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
4215 static void setfreq_i(struct sd *sd)
4217 if (sd->sensor == SEN_OV7670) {
4218 switch (sd->ctrls[FREQ].val) {
4219 case 0: /* Banding filter disabled */
4220 i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
4223 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
4225 i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
4228 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
4230 i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18);
4232 case 3: /* Auto hz - ov7670 only */
4233 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
4235 i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO,
4240 switch (sd->ctrls[FREQ].val) {
4241 case 0: /* Banding filter disabled */
4242 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4243 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4245 case 1: /* 50 hz (filter on and framerate adj) */
4246 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4247 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4248 /* 20 fps -> 16.667 fps */
4249 if (sd->sensor == SEN_OV6620 ||
4250 sd->sensor == SEN_OV6630 ||
4251 sd->sensor == SEN_OV66308AF)
4252 i2c_w(sd, 0x2b, 0x5e);
4254 i2c_w(sd, 0x2b, 0xac);
4256 case 2: /* 60 hz (filter on, ...) */
4257 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4258 if (sd->sensor == SEN_OV6620 ||
4259 sd->sensor == SEN_OV6630 ||
4260 sd->sensor == SEN_OV66308AF) {
4261 /* 20 fps -> 15 fps */
4262 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4263 i2c_w(sd, 0x2b, 0xa8);
4265 /* no framerate adj. */
4266 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4272 static void setfreq(struct gspca_dev *gspca_dev)
4274 struct sd *sd = (struct sd *) gspca_dev;
4278 /* Ugly but necessary */
4279 if (sd->bridge == BRIDGE_W9968CF)
4280 w9968cf_set_crop_window(sd);
4283 static int sd_querymenu(struct gspca_dev *gspca_dev,
4284 struct v4l2_querymenu *menu)
4286 struct sd *sd = (struct sd *) gspca_dev;
4289 case V4L2_CID_POWER_LINE_FREQUENCY:
4290 switch (menu->index) {
4291 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
4292 strcpy((char *) menu->name, "NoFliker");
4294 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
4295 strcpy((char *) menu->name, "50 Hz");
4297 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
4298 strcpy((char *) menu->name, "60 Hz");
4301 if (sd->sensor != SEN_OV7670)
4304 strcpy((char *) menu->name, "Automatic");
4312 static int sd_get_jcomp(struct gspca_dev *gspca_dev,
4313 struct v4l2_jpegcompression *jcomp)
4315 struct sd *sd = (struct sd *) gspca_dev;
4317 if (sd->bridge != BRIDGE_W9968CF)
4320 memset(jcomp, 0, sizeof *jcomp);
4321 jcomp->quality = sd->quality;
4322 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
4323 V4L2_JPEG_MARKER_DRI;
4327 static int sd_set_jcomp(struct gspca_dev *gspca_dev,
4328 struct v4l2_jpegcompression *jcomp)
4330 struct sd *sd = (struct sd *) gspca_dev;
4332 if (sd->bridge != BRIDGE_W9968CF)
4335 if (gspca_dev->streaming)
4338 if (jcomp->quality < QUALITY_MIN)
4339 sd->quality = QUALITY_MIN;
4340 else if (jcomp->quality > QUALITY_MAX)
4341 sd->quality = QUALITY_MAX;
4343 sd->quality = jcomp->quality;
4345 /* Return resulting jcomp params to app */
4346 sd_get_jcomp(gspca_dev, jcomp);
4351 /* sub-driver description */
4352 static const struct sd_desc sd_desc = {
4353 .name = MODULE_NAME,
4355 .nctrls = ARRAY_SIZE(sd_ctrls),
4356 .config = sd_config,
4361 .pkt_scan = sd_pkt_scan,
4362 .dq_callback = sd_reset_snapshot,
4363 .querymenu = sd_querymenu,
4364 .get_jcomp = sd_get_jcomp,
4365 .set_jcomp = sd_set_jcomp,
4366 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
4371 /* -- module initialisation -- */
4372 static const __devinitdata struct usb_device_id device_table[] = {
4373 {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
4374 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
4375 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
4376 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4377 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
4378 {USB_DEVICE(0x041e, 0x4064),
4379 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4380 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
4381 {USB_DEVICE(0x041e, 0x4068),
4382 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4383 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4384 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
4385 {USB_DEVICE(0x054c, 0x0155),
4386 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4387 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
4388 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4389 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
4390 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
4391 {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
4392 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
4393 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
4394 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
4395 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
4396 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
4397 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4398 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
4399 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
4400 {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
4404 MODULE_DEVICE_TABLE(usb, device_table);
4406 /* -- device connect -- */
4407 static int sd_probe(struct usb_interface *intf,
4408 const struct usb_device_id *id)
4410 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
4414 static struct usb_driver sd_driver = {
4415 .name = MODULE_NAME,
4416 .id_table = device_table,
4418 .disconnect = gspca_disconnect,
4420 .suspend = gspca_suspend,
4421 .resume = gspca_resume,
4425 /* -- module insert / remove -- */
4426 static int __init sd_mod_init(void)
4428 return usb_register(&sd_driver);
4430 static void __exit sd_mod_exit(void)
4432 usb_deregister(&sd_driver);
4435 module_init(sd_mod_init);
4436 module_exit(sd_mod_exit);
4438 module_param(frame_rate, int, 0644);
4439 MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");