2 * OmniVision OV511 Camera-to-USB Bridge Driver
4 * Copyright (c) 1999-2003 Mark W. McClelland
5 * Original decompression code Copyright 1998-2000 OmniVision Technologies
6 * Many improvements by Bret Wallach <bwallac1@san.rr.com>
7 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
8 * Snapshot code by Kevin Moore
9 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
10 * Changes by Claudio Matsuoka <claudio@conectiva.com>
11 * Original SAA7111A code by Dave Perks <dperks@ibm.net>
12 * URB error messages from pwc driver by Nemosoft
13 * generic_ioctl() code from videodev.c by Gerd Knorr and Alan Cox
14 * Memory management (rvmalloc) code from bttv driver, by Gerd Knorr and others
16 * Based on the Linux CPiA driver written by Peter Pregler,
17 * Scott J. Bertin and Johannes Erdfelt.
19 * Please see the file: Documentation/usb/ov511.txt
20 * and the website at: http://alpha.dyndns.org/ov511
23 * This program is free software; you can redistribute it and/or modify it
24 * under the terms of the GNU General Public License as published by the
25 * Free Software Foundation; either version 2 of the License, or (at your
26 * option) any later version.
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software Foundation,
35 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/vmalloc.h>
41 #include <linux/slab.h>
42 #include <linux/ctype.h>
43 #include <linux/pagemap.h>
44 #include <asm/processor.h>
46 #include <linux/device.h>
48 #if defined (__i386__)
49 #include <asm/cpufeature.h>
57 #define DRIVER_VERSION "v1.64 for Linux 2.5"
58 #define EMAIL "mark@alpha.dyndns.org"
59 #define DRIVER_AUTHOR "Mark McClelland <mark@alpha.dyndns.org> & Bret Wallach \
60 & Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha \
61 <cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>"
62 #define DRIVER_DESC "ov511 USB Camera Driver"
64 #define OV511_I2C_RETRIES 3
65 #define ENABLE_Y_QUANTABLE 1
66 #define ENABLE_UV_QUANTABLE 1
68 #define OV511_MAX_UNIT_VIDEO 16
70 /* Pixel count * bytes per YUV420 pixel (1.5) */
71 #define MAX_FRAME_SIZE(w, h) ((w) * (h) * 3 / 2)
73 #define MAX_DATA_SIZE(w, h) (MAX_FRAME_SIZE(w, h) + sizeof(struct timeval))
75 /* Max size * bytes per YUV420 pixel (1.5) + one extra isoc frame for safety */
76 #define MAX_RAW_DATA_SIZE(w, h) ((w) * (h) * 3 / 2 + 1024)
78 #define FATAL_ERROR(rc) ((rc) < 0 && (rc) != -EPERM)
80 /**********************************************************************
82 * (See ov511.txt for detailed descriptions of these)
83 **********************************************************************/
85 /* These variables (and all static globals) default to zero */
86 static int autobright = 1;
87 static int autogain = 1;
88 static int autoexp = 1;
96 static int dump_bridge;
97 static int dump_sensor;
99 static int phy = 0x1f;
100 static int phuv = 0x05;
101 static int pvy = 0x06;
102 static int pvuv = 0x06;
103 static int qhy = 0x14;
104 static int qhuv = 0x03;
105 static int qvy = 0x04;
106 static int qvuv = 0x04;
107 static int lightfreq;
108 static int bandingfilter;
109 static int clockdiv = -1;
110 static int packetsize = -1;
111 static int framedrop = -1;
113 static int force_palette;
114 static int backlight;
115 static int unit_video[OV511_MAX_UNIT_VIDEO];
116 static int remove_zeros;
118 static int ov518_color;
120 module_param(autobright, int, 0);
121 MODULE_PARM_DESC(autobright, "Sensor automatically changes brightness");
122 module_param(autogain, int, 0);
123 MODULE_PARM_DESC(autogain, "Sensor automatically changes gain");
124 module_param(autoexp, int, 0);
125 MODULE_PARM_DESC(autoexp, "Sensor automatically changes exposure");
126 module_param(debug, int, 0);
127 MODULE_PARM_DESC(debug,
128 "Debug level: 0=none, 1=inits, 2=warning, 3=config, 4=functions, 5=max");
129 module_param(snapshot, int, 0);
130 MODULE_PARM_DESC(snapshot, "Enable snapshot mode");
131 module_param(cams, int, 0);
132 MODULE_PARM_DESC(cams, "Number of simultaneous cameras");
133 module_param(compress, int, 0);
134 MODULE_PARM_DESC(compress, "Turn on compression");
135 module_param(testpat, int, 0);
136 MODULE_PARM_DESC(testpat,
137 "Replace image with vertical bar testpattern (only partially working)");
138 module_param(dumppix, int, 0);
139 MODULE_PARM_DESC(dumppix, "Dump raw pixel data");
140 module_param(led, int, 0);
141 MODULE_PARM_DESC(led,
142 "LED policy (OV511+ or later). 0=off, 1=on (default), 2=auto (on when open)");
143 module_param(dump_bridge, int, 0);
144 MODULE_PARM_DESC(dump_bridge, "Dump the bridge registers");
145 module_param(dump_sensor, int, 0);
146 MODULE_PARM_DESC(dump_sensor, "Dump the sensor registers");
147 module_param(printph, int, 0);
148 MODULE_PARM_DESC(printph, "Print frame start/end headers");
149 module_param(phy, int, 0);
150 MODULE_PARM_DESC(phy, "Prediction range (horiz. Y)");
151 module_param(phuv, int, 0);
152 MODULE_PARM_DESC(phuv, "Prediction range (horiz. UV)");
153 module_param(pvy, int, 0);
154 MODULE_PARM_DESC(pvy, "Prediction range (vert. Y)");
155 module_param(pvuv, int, 0);
156 MODULE_PARM_DESC(pvuv, "Prediction range (vert. UV)");
157 module_param(qhy, int, 0);
158 MODULE_PARM_DESC(qhy, "Quantization threshold (horiz. Y)");
159 module_param(qhuv, int, 0);
160 MODULE_PARM_DESC(qhuv, "Quantization threshold (horiz. UV)");
161 module_param(qvy, int, 0);
162 MODULE_PARM_DESC(qvy, "Quantization threshold (vert. Y)");
163 module_param(qvuv, int, 0);
164 MODULE_PARM_DESC(qvuv, "Quantization threshold (vert. UV)");
165 module_param(lightfreq, int, 0);
166 MODULE_PARM_DESC(lightfreq,
167 "Light frequency. Set to 50 or 60 Hz, or zero for default settings");
168 module_param(bandingfilter, int, 0);
169 MODULE_PARM_DESC(bandingfilter,
170 "Enable banding filter (to reduce effects of fluorescent lighting)");
171 module_param(clockdiv, int, 0);
172 MODULE_PARM_DESC(clockdiv, "Force pixel clock divisor to a specific value");
173 module_param(packetsize, int, 0);
174 MODULE_PARM_DESC(packetsize, "Force a specific isoc packet size");
175 module_param(framedrop, int, 0);
176 MODULE_PARM_DESC(framedrop, "Force a specific frame drop register setting");
177 module_param(fastset, int, 0);
178 MODULE_PARM_DESC(fastset, "Allows picture settings to take effect immediately");
179 module_param(force_palette, int, 0);
180 MODULE_PARM_DESC(force_palette, "Force the palette to a specific value");
181 module_param(backlight, int, 0);
182 MODULE_PARM_DESC(backlight, "For objects that are lit from behind");
183 static unsigned int num_uv;
184 module_param_array(unit_video, int, &num_uv, 0);
185 MODULE_PARM_DESC(unit_video,
186 "Force use of specific minor number(s). 0 is not allowed.");
187 module_param(remove_zeros, int, 0);
188 MODULE_PARM_DESC(remove_zeros,
189 "Remove zero-padding from uncompressed incoming data");
190 module_param(mirror, int, 0);
191 MODULE_PARM_DESC(mirror, "Reverse image horizontally");
192 module_param(ov518_color, int, 0);
193 MODULE_PARM_DESC(ov518_color, "Enable OV518 color (experimental)");
195 MODULE_AUTHOR(DRIVER_AUTHOR);
196 MODULE_DESCRIPTION(DRIVER_DESC);
197 MODULE_LICENSE("GPL");
199 /**********************************************************************
200 * Miscellaneous Globals
201 **********************************************************************/
203 static struct usb_driver ov511_driver;
205 /* Number of times to retry a failed I2C transaction. Increase this if you
206 * are getting "Failed to read sensor ID..." */
207 static const int i2c_detect_tries = 5;
209 static struct usb_device_id device_table [] = {
210 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511) },
211 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511PLUS) },
212 { USB_DEVICE(VEND_OMNIVISION, PROD_OV518) },
213 { USB_DEVICE(VEND_OMNIVISION, PROD_OV518PLUS) },
214 { USB_DEVICE(VEND_MATTEL, PROD_ME2CAM) },
215 { } /* Terminating entry */
218 MODULE_DEVICE_TABLE (usb, device_table);
220 static unsigned char yQuanTable511[] = OV511_YQUANTABLE;
221 static unsigned char uvQuanTable511[] = OV511_UVQUANTABLE;
222 static unsigned char yQuanTable518[] = OV518_YQUANTABLE;
223 static unsigned char uvQuanTable518[] = OV518_UVQUANTABLE;
225 /**********************************************************************
227 **********************************************************************/
229 /* Known OV511-based cameras */
230 static struct symbolic_list camlist[] = {
231 { 0, "Generic Camera (no ID)" },
232 { 1, "Mustek WCam 3X" },
233 { 3, "D-Link DSB-C300" },
234 { 4, "Generic OV511/OV7610" },
235 { 5, "Puretek PT-6007" },
236 { 6, "Lifeview USB Life TV (NTSC)" },
237 { 21, "Creative Labs WebCam 3" },
238 { 22, "Lifeview USB Life TV (PAL D/K+B/G)" },
240 { 38, "Lifeview USB Life TV (PAL)" },
241 { 41, "Samsung Anycam MPC-M10" },
242 { 43, "Mtekvision Zeca MV402" },
244 { 70, "Lifeview USB Life TV (PAL/SECAM)" },
245 { 100, "Lifeview RoboCam" },
246 { 102, "AverMedia InterCam Elite" },
247 { 112, "MediaForte MV300" }, /* or OV7110 evaluation kit */
248 { 134, "Ezonics EZCam II" },
249 { 192, "Webeye 2000B" },
250 { 253, "Alpha Vision Tech. AlphaCam SE" },
254 /* Video4Linux1 Palettes */
255 static struct symbolic_list v4l1_plist[] = {
256 { VIDEO_PALETTE_GREY, "GREY" },
257 { VIDEO_PALETTE_HI240, "HI240" },
258 { VIDEO_PALETTE_RGB565, "RGB565" },
259 { VIDEO_PALETTE_RGB24, "RGB24" },
260 { VIDEO_PALETTE_RGB32, "RGB32" },
261 { VIDEO_PALETTE_RGB555, "RGB555" },
262 { VIDEO_PALETTE_YUV422, "YUV422" },
263 { VIDEO_PALETTE_YUYV, "YUYV" },
264 { VIDEO_PALETTE_UYVY, "UYVY" },
265 { VIDEO_PALETTE_YUV420, "YUV420" },
266 { VIDEO_PALETTE_YUV411, "YUV411" },
267 { VIDEO_PALETTE_RAW, "RAW" },
268 { VIDEO_PALETTE_YUV422P,"YUV422P" },
269 { VIDEO_PALETTE_YUV411P,"YUV411P" },
270 { VIDEO_PALETTE_YUV420P,"YUV420P" },
271 { VIDEO_PALETTE_YUV410P,"YUV410P" },
275 static struct symbolic_list brglist[] = {
276 { BRG_OV511, "OV511" },
277 { BRG_OV511PLUS, "OV511+" },
278 { BRG_OV518, "OV518" },
279 { BRG_OV518PLUS, "OV518+" },
283 static struct symbolic_list senlist[] = {
284 { SEN_OV76BE, "OV76BE" },
285 { SEN_OV7610, "OV7610" },
286 { SEN_OV7620, "OV7620" },
287 { SEN_OV7620AE, "OV7620AE" },
288 { SEN_OV6620, "OV6620" },
289 { SEN_OV6630, "OV6630" },
290 { SEN_OV6630AE, "OV6630AE" },
291 { SEN_OV6630AF, "OV6630AF" },
292 { SEN_OV8600, "OV8600" },
293 { SEN_KS0127, "KS0127" },
294 { SEN_KS0127B, "KS0127B" },
295 { SEN_SAA7111A, "SAA7111A" },
299 /* URB error codes: */
300 static struct symbolic_list urb_errlist[] = {
301 { -ENOSR, "Buffer error (overrun)" },
302 { -EPIPE, "Stalled (device not responding)" },
303 { -EOVERFLOW, "Babble (device sends too much data)" },
304 { -EPROTO, "Bit-stuff error (bad cable?)" },
305 { -EILSEQ, "CRC/Timeout (bad cable?)" },
306 { -ETIME, "Device does not respond to token" },
307 { -ETIMEDOUT, "Device does not respond to command" },
311 /**********************************************************************
313 **********************************************************************/
315 rvmalloc(unsigned long size)
320 size = PAGE_ALIGN(size);
321 mem = vmalloc_32(size);
325 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
326 adr = (unsigned long) mem;
328 SetPageReserved(vmalloc_to_page((void *)adr));
337 rvfree(void *mem, unsigned long size)
344 adr = (unsigned long) mem;
345 while ((long) size > 0) {
346 ClearPageReserved(vmalloc_to_page((void *)adr));
353 /**********************************************************************
357 **********************************************************************/
359 /* Write an OV51x register */
361 reg_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
365 PDEBUG(5, "0x%02X:0x%02X", reg, value);
367 mutex_lock(&ov->cbuf_lock);
369 rc = usb_control_msg(ov->dev,
370 usb_sndctrlpipe(ov->dev, 0),
371 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */,
372 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
373 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
374 mutex_unlock(&ov->cbuf_lock);
377 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc));
382 /* Read from an OV51x register */
383 /* returns: negative is error, pos or zero is data */
385 reg_r(struct usb_ov511 *ov, unsigned char reg)
389 mutex_lock(&ov->cbuf_lock);
390 rc = usb_control_msg(ov->dev,
391 usb_rcvctrlpipe(ov->dev, 0),
392 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */,
393 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
394 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
397 err("reg read: error %d: %s", rc, symbolic(urb_errlist, rc));
400 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]);
403 mutex_unlock(&ov->cbuf_lock);
409 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
410 * the same position as 1's in "mask" are cleared and set to "value". Bits
411 * that are in the same position as 0's in "mask" are preserved, regardless
412 * of their respective state in "value".
415 reg_w_mask(struct usb_ov511 *ov,
421 unsigned char oldval, newval;
423 ret = reg_r(ov, reg);
427 oldval = (unsigned char) ret;
428 oldval &= (~mask); /* Clear the masked bits */
429 value &= mask; /* Enforce mask on value */
430 newval = oldval | value; /* Set the desired bits */
432 return (reg_w(ov, reg, newval));
436 * Writes multiple (n) byte value to a single register. Only valid with certain
437 * registers (0x30 and 0xc4 - 0xce).
440 ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
444 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n);
446 mutex_lock(&ov->cbuf_lock);
448 *((__le32 *)ov->cbuf) = __cpu_to_le32(val);
450 rc = usb_control_msg(ov->dev,
451 usb_sndctrlpipe(ov->dev, 0),
453 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
454 0, (__u16)reg, ov->cbuf, n, 1000);
455 mutex_unlock(&ov->cbuf_lock);
458 err("reg write multiple: error %d: %s", rc,
459 symbolic(urb_errlist, rc));
465 ov511_upload_quan_tables(struct usb_ov511 *ov)
467 unsigned char *pYTable = yQuanTable511;
468 unsigned char *pUVTable = uvQuanTable511;
469 unsigned char val0, val1;
470 int i, rc, reg = R511_COMP_LUT_BEGIN;
472 PDEBUG(4, "Uploading quantization tables");
474 for (i = 0; i < OV511_QUANTABLESIZE / 2; i++) {
475 if (ENABLE_Y_QUANTABLE) {
481 rc = reg_w(ov, reg, val0);
486 if (ENABLE_UV_QUANTABLE) {
492 rc = reg_w(ov, reg + OV511_QUANTABLESIZE/2, val0);
503 /* OV518 quantization tables are 8x4 (instead of 8x8) */
505 ov518_upload_quan_tables(struct usb_ov511 *ov)
507 unsigned char *pYTable = yQuanTable518;
508 unsigned char *pUVTable = uvQuanTable518;
509 unsigned char val0, val1;
510 int i, rc, reg = R511_COMP_LUT_BEGIN;
512 PDEBUG(4, "Uploading quantization tables");
514 for (i = 0; i < OV518_QUANTABLESIZE / 2; i++) {
515 if (ENABLE_Y_QUANTABLE) {
521 rc = reg_w(ov, reg, val0);
526 if (ENABLE_UV_QUANTABLE) {
532 rc = reg_w(ov, reg + OV518_QUANTABLESIZE/2, val0);
544 ov51x_reset(struct usb_ov511 *ov, unsigned char reset_type)
548 /* Setting bit 0 not allowed on 518/518Plus */
549 if (ov->bclass == BCL_OV518)
552 PDEBUG(4, "Reset: type=0x%02X", reset_type);
554 rc = reg_w(ov, R51x_SYS_RESET, reset_type);
555 rc = reg_w(ov, R51x_SYS_RESET, 0);
558 err("reset: command failed");
563 /**********************************************************************
565 * Low-level I2C I/O functions
567 **********************************************************************/
569 /* NOTE: Do not call this function directly!
570 * The OV518 I2C I/O procedure is different, hence, this function.
571 * This is normally only called from i2c_w(). Note that this function
572 * always succeeds regardless of whether the sensor is present and working.
575 ov518_i2c_write_internal(struct usb_ov511 *ov,
581 PDEBUG(5, "0x%02X:0x%02X", reg, value);
583 /* Select camera register */
584 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
588 /* Write "value" to I2C data port of OV511 */
589 rc = reg_w(ov, R51x_I2C_DATA, value);
593 /* Initiate 3-byte write cycle */
594 rc = reg_w(ov, R518_I2C_CTL, 0x01);
601 /* NOTE: Do not call this function directly! */
603 ov511_i2c_write_internal(struct usb_ov511 *ov,
609 PDEBUG(5, "0x%02X:0x%02X", reg, value);
611 /* Three byte write cycle */
612 for (retries = OV511_I2C_RETRIES; ; ) {
613 /* Select camera register */
614 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
618 /* Write "value" to I2C data port of OV511 */
619 rc = reg_w(ov, R51x_I2C_DATA, value);
623 /* Initiate 3-byte write cycle */
624 rc = reg_w(ov, R511_I2C_CTL, 0x01);
628 /* Retry until idle */
630 rc = reg_r(ov, R511_I2C_CTL);
631 } while (rc > 0 && ((rc&1) == 0));
642 reg_w(ov, R511_I2C_CTL, 0x10);
645 err("i2c write retries exhausted");
654 /* NOTE: Do not call this function directly!
655 * The OV518 I2C I/O procedure is different, hence, this function.
656 * This is normally only called from i2c_r(). Note that this function
657 * always succeeds regardless of whether the sensor is present and working.
660 ov518_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
664 /* Select camera register */
665 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
669 /* Initiate 2-byte write cycle */
670 rc = reg_w(ov, R518_I2C_CTL, 0x03);
674 /* Initiate 2-byte read cycle */
675 rc = reg_w(ov, R518_I2C_CTL, 0x05);
679 value = reg_r(ov, R51x_I2C_DATA);
681 PDEBUG(5, "0x%02X:0x%02X", reg, value);
686 /* NOTE: Do not call this function directly!
687 * returns: negative is error, pos or zero is data */
689 ov511_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
691 int rc, value, retries;
693 /* Two byte write cycle */
694 for (retries = OV511_I2C_RETRIES; ; ) {
695 /* Select camera register */
696 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
700 /* Initiate 2-byte write cycle */
701 rc = reg_w(ov, R511_I2C_CTL, 0x03);
705 /* Retry until idle */
707 rc = reg_r(ov, R511_I2C_CTL);
708 } while (rc > 0 && ((rc & 1) == 0));
712 if ((rc&2) == 0) /* Ack? */
716 reg_w(ov, R511_I2C_CTL, 0x10);
719 err("i2c write retries exhausted");
724 /* Two byte read cycle */
725 for (retries = OV511_I2C_RETRIES; ; ) {
726 /* Initiate 2-byte read cycle */
727 rc = reg_w(ov, R511_I2C_CTL, 0x05);
731 /* Retry until idle */
733 rc = reg_r(ov, R511_I2C_CTL);
734 } while (rc > 0 && ((rc&1) == 0));
738 if ((rc&2) == 0) /* Ack? */
742 rc = reg_w(ov, R511_I2C_CTL, 0x10);
747 err("i2c read retries exhausted");
752 value = reg_r(ov, R51x_I2C_DATA);
754 PDEBUG(5, "0x%02X:0x%02X", reg, value);
756 /* This is needed to make i2c_w() work */
757 rc = reg_w(ov, R511_I2C_CTL, 0x05);
764 /* returns: negative is error, pos or zero is data */
766 i2c_r(struct usb_ov511 *ov, unsigned char reg)
770 mutex_lock(&ov->i2c_lock);
772 if (ov->bclass == BCL_OV518)
773 rc = ov518_i2c_read_internal(ov, reg);
775 rc = ov511_i2c_read_internal(ov, reg);
777 mutex_unlock(&ov->i2c_lock);
783 i2c_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
787 mutex_lock(&ov->i2c_lock);
789 if (ov->bclass == BCL_OV518)
790 rc = ov518_i2c_write_internal(ov, reg, value);
792 rc = ov511_i2c_write_internal(ov, reg, value);
794 mutex_unlock(&ov->i2c_lock);
799 /* Do not call this function directly! */
801 ov51x_i2c_write_mask_internal(struct usb_ov511 *ov,
807 unsigned char oldval, newval;
812 if (ov->bclass == BCL_OV518)
813 rc = ov518_i2c_read_internal(ov, reg);
815 rc = ov511_i2c_read_internal(ov, reg);
819 oldval = (unsigned char) rc;
820 oldval &= (~mask); /* Clear the masked bits */
821 value &= mask; /* Enforce mask on value */
822 newval = oldval | value; /* Set the desired bits */
825 if (ov->bclass == BCL_OV518)
826 return (ov518_i2c_write_internal(ov, reg, newval));
828 return (ov511_i2c_write_internal(ov, reg, newval));
831 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
832 * the same position as 1's in "mask" are cleared and set to "value". Bits
833 * that are in the same position as 0's in "mask" are preserved, regardless
834 * of their respective state in "value".
837 i2c_w_mask(struct usb_ov511 *ov,
844 mutex_lock(&ov->i2c_lock);
845 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
846 mutex_unlock(&ov->i2c_lock);
851 /* Set the read and write slave IDs. The "slave" argument is the write slave,
852 * and the read slave will be set to (slave + 1). ov->i2c_lock should be held
853 * when calling this. This should not be called from outside the i2c I/O
857 i2c_set_slave_internal(struct usb_ov511 *ov, unsigned char slave)
861 rc = reg_w(ov, R51x_I2C_W_SID, slave);
865 rc = reg_w(ov, R51x_I2C_R_SID, slave + 1);
872 /* Write to a specific I2C slave ID and register, using the specified mask */
874 i2c_w_slave(struct usb_ov511 *ov,
882 mutex_lock(&ov->i2c_lock);
884 /* Set new slave IDs */
885 rc = i2c_set_slave_internal(ov, slave);
889 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
892 /* Restore primary IDs */
893 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
894 err("Couldn't restore primary I2C slave");
896 mutex_unlock(&ov->i2c_lock);
900 /* Read from a specific I2C slave ID and register */
902 i2c_r_slave(struct usb_ov511 *ov,
908 mutex_lock(&ov->i2c_lock);
910 /* Set new slave IDs */
911 rc = i2c_set_slave_internal(ov, slave);
915 if (ov->bclass == BCL_OV518)
916 rc = ov518_i2c_read_internal(ov, reg);
918 rc = ov511_i2c_read_internal(ov, reg);
921 /* Restore primary IDs */
922 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
923 err("Couldn't restore primary I2C slave");
925 mutex_unlock(&ov->i2c_lock);
929 /* Sets I2C read and write slave IDs. Returns <0 for error */
931 ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
935 mutex_lock(&ov->i2c_lock);
937 rc = i2c_set_slave_internal(ov, sid);
941 // FIXME: Is this actually necessary?
942 rc = ov51x_reset(ov, OV511_RESET_NOREGS);
944 mutex_unlock(&ov->i2c_lock);
949 write_regvals(struct usb_ov511 *ov, struct ov511_regvals * pRegvals)
953 while (pRegvals->bus != OV511_DONE_BUS) {
954 if (pRegvals->bus == OV511_REG_BUS) {
955 if ((rc = reg_w(ov, pRegvals->reg, pRegvals->val)) < 0)
957 } else if (pRegvals->bus == OV511_I2C_BUS) {
958 if ((rc = i2c_w(ov, pRegvals->reg, pRegvals->val)) < 0)
961 err("Bad regval array");
971 dump_i2c_range(struct usb_ov511 *ov, int reg1, int regn)
975 for (i = reg1; i <= regn; i++) {
977 dev_info(&ov->dev->dev, "Sensor[0x%02X] = 0x%02X\n", i, rc);
982 dump_i2c_regs(struct usb_ov511 *ov)
984 dev_info(&ov->dev->dev, "I2C REGS\n");
985 dump_i2c_range(ov, 0x00, 0x7C);
989 dump_reg_range(struct usb_ov511 *ov, int reg1, int regn)
993 for (i = reg1; i <= regn; i++) {
995 dev_info(&ov->dev->dev, "OV511[0x%02X] = 0x%02X\n", i, rc);
1000 ov511_dump_regs(struct usb_ov511 *ov)
1002 dev_info(&ov->dev->dev, "CAMERA INTERFACE REGS\n");
1003 dump_reg_range(ov, 0x10, 0x1f);
1004 dev_info(&ov->dev->dev, "DRAM INTERFACE REGS\n");
1005 dump_reg_range(ov, 0x20, 0x23);
1006 dev_info(&ov->dev->dev, "ISO FIFO REGS\n");
1007 dump_reg_range(ov, 0x30, 0x31);
1008 dev_info(&ov->dev->dev, "PIO REGS\n");
1009 dump_reg_range(ov, 0x38, 0x39);
1010 dump_reg_range(ov, 0x3e, 0x3e);
1011 dev_info(&ov->dev->dev, "I2C REGS\n");
1012 dump_reg_range(ov, 0x40, 0x49);
1013 dev_info(&ov->dev->dev, "SYSTEM CONTROL REGS\n");
1014 dump_reg_range(ov, 0x50, 0x55);
1015 dump_reg_range(ov, 0x5e, 0x5f);
1016 dev_info(&ov->dev->dev, "OmniCE REGS\n");
1017 dump_reg_range(ov, 0x70, 0x79);
1018 /* NOTE: Quantization tables are not readable. You will get the value
1019 * in reg. 0x79 for every table register */
1020 dump_reg_range(ov, 0x80, 0x9f);
1021 dump_reg_range(ov, 0xa0, 0xbf);
1026 ov518_dump_regs(struct usb_ov511 *ov)
1028 dev_info(&ov->dev->dev, "VIDEO MODE REGS\n");
1029 dump_reg_range(ov, 0x20, 0x2f);
1030 dev_info(&ov->dev->dev, "DATA PUMP AND SNAPSHOT REGS\n");
1031 dump_reg_range(ov, 0x30, 0x3f);
1032 dev_info(&ov->dev->dev, "I2C REGS\n");
1033 dump_reg_range(ov, 0x40, 0x4f);
1034 dev_info(&ov->dev->dev, "SYSTEM CONTROL AND VENDOR REGS\n");
1035 dump_reg_range(ov, 0x50, 0x5f);
1036 dev_info(&ov->dev->dev, "60 - 6F\n");
1037 dump_reg_range(ov, 0x60, 0x6f);
1038 dev_info(&ov->dev->dev, "70 - 7F\n");
1039 dump_reg_range(ov, 0x70, 0x7f);
1040 dev_info(&ov->dev->dev, "Y QUANTIZATION TABLE\n");
1041 dump_reg_range(ov, 0x80, 0x8f);
1042 dev_info(&ov->dev->dev, "UV QUANTIZATION TABLE\n");
1043 dump_reg_range(ov, 0x90, 0x9f);
1044 dev_info(&ov->dev->dev, "A0 - BF\n");
1045 dump_reg_range(ov, 0xa0, 0xbf);
1046 dev_info(&ov->dev->dev, "CBR\n");
1047 dump_reg_range(ov, 0xc0, 0xcf);
1051 /*****************************************************************************/
1053 /* Temporarily stops OV511 from functioning. Must do this before changing
1054 * registers while the camera is streaming */
1056 ov51x_stop(struct usb_ov511 *ov)
1058 PDEBUG(4, "stopping");
1060 if (ov->bclass == BCL_OV518)
1061 return (reg_w_mask(ov, R51x_SYS_RESET, 0x3a, 0x3a));
1063 return (reg_w(ov, R51x_SYS_RESET, 0x3d));
1066 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1067 * actually stopped (for performance). */
1069 ov51x_restart(struct usb_ov511 *ov)
1072 PDEBUG(4, "restarting");
1075 /* Reinitialize the stream */
1076 if (ov->bclass == BCL_OV518)
1077 reg_w(ov, 0x2f, 0x80);
1079 return (reg_w(ov, R51x_SYS_RESET, 0x00));
1085 /* Sleeps until no frames are active. Returns !0 if got signal */
1087 ov51x_wait_frames_inactive(struct usb_ov511 *ov)
1089 return wait_event_interruptible(ov->wq, ov->curframe < 0);
1092 /* Resets the hardware snapshot button */
1094 ov51x_clear_snapshot(struct usb_ov511 *ov)
1096 if (ov->bclass == BCL_OV511) {
1097 reg_w(ov, R51x_SYS_SNAP, 0x00);
1098 reg_w(ov, R51x_SYS_SNAP, 0x02);
1099 reg_w(ov, R51x_SYS_SNAP, 0x00);
1100 } else if (ov->bclass == BCL_OV518) {
1101 dev_warn(&ov->dev->dev,
1102 "snapshot reset not supported yet on OV518(+)\n");
1104 dev_err(&ov->dev->dev, "clear snap: invalid bridge type\n");
1109 /* Checks the status of the snapshot button. Returns 1 if it was pressed since
1110 * it was last cleared, and zero in all other cases (including errors) */
1112 ov51x_check_snapshot(struct usb_ov511 *ov)
1114 int ret, status = 0;
1116 if (ov->bclass == BCL_OV511) {
1117 ret = reg_r(ov, R51x_SYS_SNAP);
1119 dev_err(&ov->dev->dev,
1120 "Error checking snspshot status (%d)\n", ret);
1121 } else if (ret & 0x08) {
1124 } else if (ov->bclass == BCL_OV518) {
1125 dev_warn(&ov->dev->dev,
1126 "snapshot check not supported yet on OV518(+)\n");
1128 dev_err(&ov->dev->dev, "clear snap: invalid bridge type\n");
1135 /* This does an initial reset of an OmniVision sensor and ensures that I2C
1136 * is synchronized. Returns <0 for failure.
1139 init_ov_sensor(struct usb_ov511 *ov)
1143 /* Reset the sensor */
1144 if (i2c_w(ov, 0x12, 0x80) < 0)
1147 /* Wait for it to initialize */
1150 for (i = 0, success = 0; i < i2c_detect_tries && !success; i++) {
1151 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
1152 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
1157 /* Reset the sensor */
1158 if (i2c_w(ov, 0x12, 0x80) < 0)
1160 /* Wait for it to initialize */
1162 /* Dummy read to sync I2C */
1163 if (i2c_r(ov, 0x00) < 0)
1170 PDEBUG(1, "I2C synced in %d attempt(s)", i);
1176 ov511_set_packet_size(struct usb_ov511 *ov, int size)
1180 if (ov51x_stop(ov) < 0)
1185 if (ov->bridge == BRG_OV511) {
1187 alt = OV511_ALT_SIZE_0;
1188 else if (size == 257)
1189 alt = OV511_ALT_SIZE_257;
1190 else if (size == 513)
1191 alt = OV511_ALT_SIZE_513;
1192 else if (size == 769)
1193 alt = OV511_ALT_SIZE_769;
1194 else if (size == 993)
1195 alt = OV511_ALT_SIZE_993;
1197 err("Set packet size: invalid size (%d)", size);
1200 } else if (ov->bridge == BRG_OV511PLUS) {
1202 alt = OV511PLUS_ALT_SIZE_0;
1203 else if (size == 33)
1204 alt = OV511PLUS_ALT_SIZE_33;
1205 else if (size == 129)
1206 alt = OV511PLUS_ALT_SIZE_129;
1207 else if (size == 257)
1208 alt = OV511PLUS_ALT_SIZE_257;
1209 else if (size == 385)
1210 alt = OV511PLUS_ALT_SIZE_385;
1211 else if (size == 513)
1212 alt = OV511PLUS_ALT_SIZE_513;
1213 else if (size == 769)
1214 alt = OV511PLUS_ALT_SIZE_769;
1215 else if (size == 961)
1216 alt = OV511PLUS_ALT_SIZE_961;
1218 err("Set packet size: invalid size (%d)", size);
1222 err("Set packet size: Invalid bridge type");
1226 PDEBUG(3, "%d, mult=%d, alt=%d", size, mult, alt);
1228 if (reg_w(ov, R51x_FIFO_PSIZE, mult) < 0)
1231 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1232 err("Set packet size: set interface error");
1236 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1239 ov->packet_size = size;
1241 if (ov51x_restart(ov) < 0)
1247 /* Note: Unlike the OV511/OV511+, the size argument does NOT include the
1248 * optional packet number byte. The actual size *is* stored in ov->packet_size,
1251 ov518_set_packet_size(struct usb_ov511 *ov, int size)
1255 if (ov51x_stop(ov) < 0)
1258 if (ov->bclass == BCL_OV518) {
1260 alt = OV518_ALT_SIZE_0;
1261 else if (size == 128)
1262 alt = OV518_ALT_SIZE_128;
1263 else if (size == 256)
1264 alt = OV518_ALT_SIZE_256;
1265 else if (size == 384)
1266 alt = OV518_ALT_SIZE_384;
1267 else if (size == 512)
1268 alt = OV518_ALT_SIZE_512;
1269 else if (size == 640)
1270 alt = OV518_ALT_SIZE_640;
1271 else if (size == 768)
1272 alt = OV518_ALT_SIZE_768;
1273 else if (size == 896)
1274 alt = OV518_ALT_SIZE_896;
1276 err("Set packet size: invalid size (%d)", size);
1280 err("Set packet size: Invalid bridge type");
1284 PDEBUG(3, "%d, alt=%d", size, alt);
1286 ov->packet_size = size;
1288 /* Program ISO FIFO size reg (packet number isn't included) */
1289 ov518_reg_w32(ov, 0x30, size, 2);
1291 if (ov->packet_numbering)
1295 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1296 err("Set packet size: set interface error");
1300 /* Initialize the stream */
1301 if (reg_w(ov, 0x2f, 0x80) < 0)
1304 if (ov51x_restart(ov) < 0)
1307 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1313 /* Upload compression params and quantization tables. Returns 0 for success. */
1315 ov511_init_compression(struct usb_ov511 *ov)
1319 if (!ov->compress_inited) {
1320 reg_w(ov, 0x70, phy);
1321 reg_w(ov, 0x71, phuv);
1322 reg_w(ov, 0x72, pvy);
1323 reg_w(ov, 0x73, pvuv);
1324 reg_w(ov, 0x74, qhy);
1325 reg_w(ov, 0x75, qhuv);
1326 reg_w(ov, 0x76, qvy);
1327 reg_w(ov, 0x77, qvuv);
1329 if (ov511_upload_quan_tables(ov) < 0) {
1330 err("Error uploading quantization tables");
1336 ov->compress_inited = 1;
1341 /* Upload compression params and quantization tables. Returns 0 for success. */
1343 ov518_init_compression(struct usb_ov511 *ov)
1347 if (!ov->compress_inited) {
1348 if (ov518_upload_quan_tables(ov) < 0) {
1349 err("Error uploading quantization tables");
1355 ov->compress_inited = 1;
1360 /* -------------------------------------------------------------------------- */
1362 /* Sets sensor's contrast setting to "val" */
1364 sensor_set_contrast(struct usb_ov511 *ov, unsigned short val)
1368 PDEBUG(3, "%d", val);
1370 if (ov->stop_during_set)
1371 if (ov51x_stop(ov) < 0)
1374 switch (ov->sensor) {
1378 rc = i2c_w(ov, OV7610_REG_CNT, val >> 8);
1385 rc = i2c_w_mask(ov, OV7610_REG_CNT, val >> 12, 0x0f);
1392 unsigned char ctab[] = {
1393 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
1394 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
1397 /* Use Y gamma control instead. Bit 0 enables it. */
1398 rc = i2c_w(ov, 0x64, ctab[val>>12]);
1405 rc = i2c_w(ov, 0x0b, val >> 9);
1412 PDEBUG(3, "Unsupported with this sensor");
1418 rc = 0; /* Success */
1421 if (ov51x_restart(ov) < 0)
1427 /* Gets sensor's contrast setting */
1429 sensor_get_contrast(struct usb_ov511 *ov, unsigned short *val)
1433 switch (ov->sensor) {
1436 rc = i2c_r(ov, OV7610_REG_CNT);
1443 rc = i2c_r(ov, OV7610_REG_CNT);
1450 /* Use Y gamma reg instead. Bit 0 is the enable bit. */
1451 rc = i2c_r(ov, 0x64);
1455 *val = (rc & 0xfe) << 8;
1458 *val = ov->contrast;
1461 PDEBUG(3, "Unsupported with this sensor");
1465 PDEBUG(3, "%d", *val);
1466 ov->contrast = *val;
1471 /* -------------------------------------------------------------------------- */
1473 /* Sets sensor's brightness setting to "val" */
1475 sensor_set_brightness(struct usb_ov511 *ov, unsigned short val)
1479 PDEBUG(4, "%d", val);
1481 if (ov->stop_during_set)
1482 if (ov51x_stop(ov) < 0)
1485 switch (ov->sensor) {
1490 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1495 /* 7620 doesn't like manual changes when in auto mode */
1496 if (!ov->auto_brt) {
1497 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1503 rc = i2c_w(ov, 0x0a, val >> 8);
1508 PDEBUG(3, "Unsupported with this sensor");
1513 rc = 0; /* Success */
1514 ov->brightness = val;
1516 if (ov51x_restart(ov) < 0)
1522 /* Gets sensor's brightness setting */
1524 sensor_get_brightness(struct usb_ov511 *ov, unsigned short *val)
1528 switch (ov->sensor) {
1534 rc = i2c_r(ov, OV7610_REG_BRT);
1541 *val = ov->brightness;
1544 PDEBUG(3, "Unsupported with this sensor");
1548 PDEBUG(3, "%d", *val);
1549 ov->brightness = *val;
1554 /* -------------------------------------------------------------------------- */
1556 /* Sets sensor's saturation (color intensity) setting to "val" */
1558 sensor_set_saturation(struct usb_ov511 *ov, unsigned short val)
1562 PDEBUG(3, "%d", val);
1564 if (ov->stop_during_set)
1565 if (ov51x_stop(ov) < 0)
1568 switch (ov->sensor) {
1573 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1578 // /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
1579 // rc = ov_i2c_write(ov->dev, 0x62, (val >> 9) & 0x7e);
1582 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1587 rc = i2c_w(ov, 0x0c, val >> 9);
1592 PDEBUG(3, "Unsupported with this sensor");
1597 rc = 0; /* Success */
1600 if (ov51x_restart(ov) < 0)
1606 /* Gets sensor's saturation (color intensity) setting */
1608 sensor_get_saturation(struct usb_ov511 *ov, unsigned short *val)
1612 switch (ov->sensor) {
1617 rc = i2c_r(ov, OV7610_REG_SAT);
1624 // /* Use UV gamma reg instead. Bits 0 & 7 are reserved. */
1625 // rc = i2c_r(ov, 0x62);
1629 // *val = (rc & 0x7e) << 9;
1630 rc = i2c_r(ov, OV7610_REG_SAT);
1640 PDEBUG(3, "Unsupported with this sensor");
1644 PDEBUG(3, "%d", *val);
1650 /* -------------------------------------------------------------------------- */
1652 /* Sets sensor's hue (red/blue balance) setting to "val" */
1654 sensor_set_hue(struct usb_ov511 *ov, unsigned short val)
1658 PDEBUG(3, "%d", val);
1660 if (ov->stop_during_set)
1661 if (ov51x_stop(ov) < 0)
1664 switch (ov->sensor) {
1668 rc = i2c_w(ov, OV7610_REG_RED, 0xFF - (val >> 8));
1672 rc = i2c_w(ov, OV7610_REG_BLUE, val >> 8);
1677 // Hue control is causing problems. I will enable it once it's fixed.
1679 rc = i2c_w(ov, 0x7a, (unsigned char)(val >> 8) + 0xb);
1683 rc = i2c_w(ov, 0x79, (unsigned char)(val >> 8) + 0xb);
1689 rc = i2c_w(ov, 0x0d, (val + 32768) >> 8);
1694 PDEBUG(3, "Unsupported with this sensor");
1699 rc = 0; /* Success */
1702 if (ov51x_restart(ov) < 0)
1708 /* Gets sensor's hue (red/blue balance) setting */
1710 sensor_get_hue(struct usb_ov511 *ov, unsigned short *val)
1714 switch (ov->sensor) {
1718 rc = i2c_r(ov, OV7610_REG_BLUE);
1725 rc = i2c_r(ov, 0x7a);
1735 PDEBUG(3, "Unsupported with this sensor");
1739 PDEBUG(3, "%d", *val);
1745 /* -------------------------------------------------------------------------- */
1748 sensor_set_picture(struct usb_ov511 *ov, struct video_picture *p)
1752 PDEBUG(4, "sensor_set_picture");
1754 ov->whiteness = p->whiteness;
1756 /* Don't return error if a setting is unsupported, or rest of settings
1757 * will not be performed */
1759 rc = sensor_set_contrast(ov, p->contrast);
1760 if (FATAL_ERROR(rc))
1763 rc = sensor_set_brightness(ov, p->brightness);
1764 if (FATAL_ERROR(rc))
1767 rc = sensor_set_saturation(ov, p->colour);
1768 if (FATAL_ERROR(rc))
1771 rc = sensor_set_hue(ov, p->hue);
1772 if (FATAL_ERROR(rc))
1779 sensor_get_picture(struct usb_ov511 *ov, struct video_picture *p)
1783 PDEBUG(4, "sensor_get_picture");
1785 /* Don't return error if a setting is unsupported, or rest of settings
1786 * will not be performed */
1788 rc = sensor_get_contrast(ov, &(p->contrast));
1789 if (FATAL_ERROR(rc))
1792 rc = sensor_get_brightness(ov, &(p->brightness));
1793 if (FATAL_ERROR(rc))
1796 rc = sensor_get_saturation(ov, &(p->colour));
1797 if (FATAL_ERROR(rc))
1800 rc = sensor_get_hue(ov, &(p->hue));
1801 if (FATAL_ERROR(rc))
1804 p->whiteness = 105 << 8;
1810 // FIXME: Exposure range is only 0x00-0x7f in interlace mode
1811 /* Sets current exposure for sensor. This only has an effect if auto-exposure
1814 sensor_set_exposure(struct usb_ov511 *ov, unsigned char val)
1818 PDEBUG(3, "%d", val);
1820 if (ov->stop_during_set)
1821 if (ov51x_stop(ov) < 0)
1824 switch (ov->sensor) {
1831 rc = i2c_w(ov, 0x10, val);
1839 PDEBUG(3, "Unsupported with this sensor");
1842 err("Sensor not supported for set_exposure");
1846 rc = 0; /* Success */
1849 if (ov51x_restart(ov) < 0)
1856 /* Gets current exposure level from sensor, regardless of whether it is under
1857 * manual control. */
1859 sensor_get_exposure(struct usb_ov511 *ov, unsigned char *val)
1863 switch (ov->sensor) {
1870 rc = i2c_r(ov, 0x10);
1880 PDEBUG(3, "Unsupported with this sensor");
1883 err("Sensor not supported for get_exposure");
1887 PDEBUG(3, "%d", *val);
1888 ov->exposure = *val;
1893 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+) */
1895 ov51x_led_control(struct usb_ov511 *ov, int enable)
1897 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1899 if (ov->bridge == BRG_OV511PLUS)
1900 reg_w(ov, R511_SYS_LED_CTL, enable ? 1 : 0);
1901 else if (ov->bclass == BCL_OV518)
1902 reg_w_mask(ov, R518_GPIO_OUT, enable ? 0x02 : 0x00, 0x02);
1907 /* Matches the sensor's internal frame rate to the lighting frequency.
1908 * Valid frequencies are:
1909 * 50 - 50Hz, for European and Asian lighting
1910 * 60 - 60Hz, for American lighting
1912 * Tested with: OV7610, OV7620, OV76BE, OV6620
1913 * Unsupported: KS0127, KS0127B, SAA7111A
1914 * Returns: 0 for success
1917 sensor_set_light_freq(struct usb_ov511 *ov, int freq)
1921 PDEBUG(4, "%d Hz", freq);
1925 else if (freq == 50)
1928 err("Invalid light freq (%d Hz)", freq);
1932 switch (ov->sensor) {
1934 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1935 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1936 i2c_w_mask(ov, 0x13, 0x10, 0x10);
1937 i2c_w_mask(ov, 0x13, 0x00, 0x10);
1942 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1943 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1944 i2c_w_mask(ov, 0x76, 0x01, 0x01);
1948 i2c_w(ov, 0x2b, sixty?0xa8:0x28);
1949 i2c_w(ov, 0x2a, sixty?0x84:0xa4);
1954 PDEBUG(5, "Unsupported with this sensor");
1957 err("Sensor not supported for set_light_freq");
1961 ov->lightfreq = freq;
1966 /* If enable is true, turn on the sensor's banding filter, otherwise turn it
1967 * off. This filter tries to reduce the pattern of horizontal light/dark bands
1968 * caused by some (usually fluorescent) lighting. The light frequency must be
1969 * set either before or after enabling it with ov51x_set_light_freq().
1971 * Tested with: OV7610, OV7620, OV76BE, OV6620.
1972 * Unsupported: KS0127, KS0127B, SAA7111A
1973 * Returns: 0 for success
1976 sensor_set_banding_filter(struct usb_ov511 *ov, int enable)
1980 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1982 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
1983 || ov->sensor == SEN_SAA7111A) {
1984 PDEBUG(5, "Unsupported with this sensor");
1988 rc = i2c_w_mask(ov, 0x2d, enable?0x04:0x00, 0x04);
1992 ov->bandfilt = enable;
1997 /* If enable is true, turn on the sensor's auto brightness control, otherwise
2000 * Unsupported: KS0127, KS0127B, SAA7111A
2001 * Returns: 0 for success
2004 sensor_set_auto_brightness(struct usb_ov511 *ov, int enable)
2008 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2010 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
2011 || ov->sensor == SEN_SAA7111A) {
2012 PDEBUG(5, "Unsupported with this sensor");
2016 rc = i2c_w_mask(ov, 0x2d, enable?0x10:0x00, 0x10);
2020 ov->auto_brt = enable;
2025 /* If enable is true, turn on the sensor's auto exposure control, otherwise
2028 * Unsupported: KS0127, KS0127B, SAA7111A
2029 * Returns: 0 for success
2032 sensor_set_auto_exposure(struct usb_ov511 *ov, int enable)
2034 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2036 switch (ov->sensor) {
2038 i2c_w_mask(ov, 0x29, enable?0x00:0x80, 0x80);
2044 i2c_w_mask(ov, 0x13, enable?0x01:0x00, 0x01);
2047 i2c_w_mask(ov, 0x28, enable?0x00:0x10, 0x10);
2052 PDEBUG(5, "Unsupported with this sensor");
2055 err("Sensor not supported for set_auto_exposure");
2059 ov->auto_exp = enable;
2064 /* Modifies the sensor's exposure algorithm to allow proper exposure of objects
2065 * that are illuminated from behind.
2067 * Tested with: OV6620, OV7620
2068 * Unsupported: OV7610, OV76BE, KS0127, KS0127B, SAA7111A
2069 * Returns: 0 for success
2072 sensor_set_backlight(struct usb_ov511 *ov, int enable)
2074 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2076 switch (ov->sensor) {
2079 i2c_w_mask(ov, 0x68, enable?0xe0:0xc0, 0xe0);
2080 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2081 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2084 i2c_w_mask(ov, 0x4e, enable?0xe0:0xc0, 0xe0);
2085 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2086 i2c_w_mask(ov, 0x0e, enable?0x80:0x00, 0x80);
2089 i2c_w_mask(ov, 0x4e, enable?0x80:0x60, 0xe0);
2090 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2091 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2098 PDEBUG(5, "Unsupported with this sensor");
2101 err("Sensor not supported for set_backlight");
2105 ov->backlight = enable;
2111 sensor_set_mirror(struct usb_ov511 *ov, int enable)
2113 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2115 switch (ov->sensor) {
2122 i2c_w_mask(ov, 0x12, enable?0x40:0x00, 0x40);
2127 PDEBUG(5, "Unsupported with this sensor");
2130 err("Sensor not supported for set_mirror");
2134 ov->mirror = enable;
2139 /* Returns number of bits per pixel (regardless of where they are located;
2140 * planar or not), or zero for unsupported format.
2143 get_depth(int palette)
2146 case VIDEO_PALETTE_GREY: return 8;
2147 case VIDEO_PALETTE_YUV420: return 12;
2148 case VIDEO_PALETTE_YUV420P: return 12; /* Planar */
2149 default: return 0; /* Invalid format */
2153 /* Bytes per frame. Used by read(). Return of 0 indicates error */
2154 static inline long int
2155 get_frame_length(struct ov511_frame *frame)
2160 return ((frame->width * frame->height
2161 * get_depth(frame->format)) >> 3);
2165 mode_init_ov_sensor_regs(struct usb_ov511 *ov, int width, int height,
2166 int mode, int sub_flag, int qvga)
2170 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2172 switch (ov->sensor) {
2174 i2c_w(ov, 0x14, qvga?0x24:0x04);
2175 // FIXME: Does this improve the image quality or frame rate?
2177 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2178 i2c_w(ov, 0x24, 0x10);
2179 i2c_w(ov, 0x25, qvga?0x40:0x8a);
2180 i2c_w(ov, 0x2f, qvga?0x30:0xb0);
2181 i2c_w(ov, 0x35, qvga?0x1c:0x9c);
2185 // i2c_w(ov, 0x2b, 0x00);
2186 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2187 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2188 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2189 i2c_w(ov, 0x25, qvga?0x30:0x60);
2190 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2191 i2c_w_mask(ov, 0x67, qvga?0xf0:0x90, 0xf0);
2192 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2195 // i2c_w(ov, 0x2b, 0x00);
2196 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2197 // FIXME: Enable this once 7620AE uses 7620 initial settings
2199 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2200 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2201 i2c_w(ov, 0x25, qvga?0x30:0x60);
2202 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2203 i2c_w_mask(ov, 0x67, qvga?0xb0:0x90, 0xf0);
2204 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2208 i2c_w(ov, 0x14, qvga?0x24:0x04);
2211 i2c_w(ov, 0x14, qvga?0xa0:0x80);
2214 err("Invalid sensor");
2218 /******** Palette-specific regs ********/
2220 if (mode == VIDEO_PALETTE_GREY) {
2221 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2222 /* these aren't valid on the OV6620/OV7620/6630? */
2223 i2c_w_mask(ov, 0x0e, 0x40, 0x40);
2226 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2228 i2c_w_mask(ov, 0x12, 0x00, 0x10);
2229 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2231 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2234 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2235 /* not valid on the OV6620/OV7620/6630? */
2236 i2c_w_mask(ov, 0x0e, 0x00, 0x40);
2239 /* The OV518 needs special treatment. Although both the OV518
2240 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2241 * bus is actually used. The UV bus is tied to ground.
2242 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2245 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2247 i2c_w_mask(ov, 0x12, 0x10, 0x10);
2248 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2250 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2254 /******** Clock programming ********/
2256 /* The OV6620 needs special handling. This prevents the
2257 * severe banding that normally occurs */
2258 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630)
2262 i2c_w(ov, 0x2a, 0x04);
2265 // clock = 0; /* This ensures the highest frame rate */
2267 } else if (clockdiv == -1) { /* If user didn't override it */
2268 clock = 3; /* Gives better exposure time */
2273 PDEBUG(4, "Setting clock divisor to %d", clock);
2275 i2c_w(ov, 0x11, clock);
2277 i2c_w(ov, 0x2a, 0x84);
2278 /* This next setting is critical. It seems to improve
2279 * the gain or the contrast. The "reserved" bits seem
2280 * to have some effect in this case. */
2281 i2c_w(ov, 0x2d, 0x85);
2286 clock = 1; /* This ensures the highest frame rate */
2287 } else if (clockdiv == -1) { /* If user didn't override it */
2288 /* Calculate and set the clock divisor */
2289 clock = ((sub_flag ? ov->subw * ov->subh
2291 * (mode == VIDEO_PALETTE_GREY ? 2 : 3) / 2)
2297 PDEBUG(4, "Setting clock divisor to %d", clock);
2299 i2c_w(ov, 0x11, clock);
2302 /******** Special Features ********/
2305 i2c_w(ov, 0x16, framedrop);
2308 i2c_w_mask(ov, 0x12, (testpat?0x02:0x00), 0x02);
2310 /* Enable auto white balance */
2311 i2c_w_mask(ov, 0x12, 0x04, 0x04);
2313 // This will go away as soon as ov51x_mode_init_sensor_regs()
2315 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2316 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2317 if (width == 640 && height == 480)
2318 i2c_w(ov, 0x35, 0x9e);
2320 i2c_w(ov, 0x35, 0x1e);
2327 set_ov_sensor_window(struct usb_ov511 *ov, int width, int height, int mode,
2331 int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
2332 int hoffset, voffset, hwscale = 0, vwscale = 0;
2334 /* The different sensor ICs handle setting up of window differently.
2335 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!!! */
2336 switch (ov->sensor) {
2341 vwsbase = vwebase = 0x05;
2351 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2353 vwsbase = vwebase = 0x05;
2356 err("Invalid sensor");
2360 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630) {
2361 /* Note: OV518(+) does downsample on its own) */
2362 if ((width > 176 && height > 144)
2363 || ov->bclass == BCL_OV518) { /* CIF */
2364 ret = mode_init_ov_sensor_regs(ov, width, height,
2369 vwscale = 1; /* The datasheet says 0; it's wrong */
2372 } else if (width > 176 || height > 144) {
2373 err("Illegal dimensions");
2376 ret = mode_init_ov_sensor_regs(ov, width, height,
2384 if (width > 320 && height > 240) { /* VGA */
2385 ret = mode_init_ov_sensor_regs(ov, width, height,
2393 } else if (width > 320 || height > 240) {
2394 err("Illegal dimensions");
2397 ret = mode_init_ov_sensor_regs(ov, width, height,
2407 /* Center the window */
2408 hoffset = ((hwsize - width) / 2) >> hwscale;
2409 voffset = ((vwsize - height) / 2) >> vwscale;
2411 /* FIXME! - This needs to be changed to support 160x120 and 6620!!! */
2413 i2c_w(ov, 0x17, hwsbase+(ov->subx>>hwscale));
2414 i2c_w(ov, 0x18, hwebase+((ov->subx+ov->subw)>>hwscale));
2415 i2c_w(ov, 0x19, vwsbase+(ov->suby>>vwscale));
2416 i2c_w(ov, 0x1a, vwebase+((ov->suby+ov->subh)>>vwscale));
2418 i2c_w(ov, 0x17, hwsbase + hoffset);
2419 i2c_w(ov, 0x18, hwebase + hoffset + (hwsize>>hwscale));
2420 i2c_w(ov, 0x19, vwsbase + voffset);
2421 i2c_w(ov, 0x1a, vwebase + voffset + (vwsize>>vwscale));
2432 /* Set up the OV511/OV511+ with the given image parameters.
2434 * Do not put any sensor-specific code in here (including I2C I/O functions)
2437 ov511_mode_init_regs(struct usb_ov511 *ov,
2438 int width, int height, int mode, int sub_flag)
2447 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2448 width, height, mode, sub_flag);
2450 // FIXME: This should be moved to a 7111a-specific function once
2451 // subcapture is dealt with properly
2452 if (ov->sensor == SEN_SAA7111A) {
2453 if (width == 320 && height == 240) {
2454 /* No need to do anything special */
2455 } else if (width == 640 && height == 480) {
2456 /* Set the OV511 up as 320x480, but keep the
2457 * V4L resolution as 640x480 */
2460 err("SAA7111A only allows 320x240 or 640x480");
2465 /* Make sure width and height are a multiple of 8 */
2466 if (width % 8 || height % 8) {
2467 err("Invalid size (%d, %d) (mode = %d)", width, height, mode);
2471 if (width < ov->minwidth || height < ov->minheight) {
2472 err("Requested dimensions are too small");
2476 if (ov51x_stop(ov) < 0)
2479 if (mode == VIDEO_PALETTE_GREY) {
2480 reg_w(ov, R511_CAM_UV_EN, 0x00);
2481 reg_w(ov, R511_SNAP_UV_EN, 0x00);
2482 reg_w(ov, R511_SNAP_OPTS, 0x01);
2484 reg_w(ov, R511_CAM_UV_EN, 0x01);
2485 reg_w(ov, R511_SNAP_UV_EN, 0x01);
2486 reg_w(ov, R511_SNAP_OPTS, 0x03);
2489 /* Here I'm assuming that snapshot size == image size.
2490 * I hope that's always true. --claudio
2492 hsegs = (width >> 3) - 1;
2493 vsegs = (height >> 3) - 1;
2495 reg_w(ov, R511_CAM_PXCNT, hsegs);
2496 reg_w(ov, R511_CAM_LNCNT, vsegs);
2497 reg_w(ov, R511_CAM_PXDIV, 0x00);
2498 reg_w(ov, R511_CAM_LNDIV, 0x00);
2500 /* YUV420, low pass filter on */
2501 reg_w(ov, R511_CAM_OPTS, 0x03);
2503 /* Snapshot additions */
2504 reg_w(ov, R511_SNAP_PXCNT, hsegs);
2505 reg_w(ov, R511_SNAP_LNCNT, vsegs);
2506 reg_w(ov, R511_SNAP_PXDIV, 0x00);
2507 reg_w(ov, R511_SNAP_LNDIV, 0x00);
2510 /* Enable Y and UV quantization and compression */
2511 reg_w(ov, R511_COMP_EN, 0x07);
2512 reg_w(ov, R511_COMP_LUT_EN, 0x03);
2513 ov51x_reset(ov, OV511_RESET_OMNICE);
2516 if (ov51x_restart(ov) < 0)
2522 /* Sets up the OV518/OV518+ with the given image parameters
2524 * OV518 needs a completely different approach, until we can figure out what
2525 * the individual registers do. Also, only 15 FPS is supported now.
2527 * Do not put any sensor-specific code in here (including I2C I/O functions)
2530 ov518_mode_init_regs(struct usb_ov511 *ov,
2531 int width, int height, int mode, int sub_flag)
2533 int hsegs, vsegs, hi_res;
2540 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2541 width, height, mode, sub_flag);
2543 if (width % 16 || height % 8) {
2544 err("Invalid size (%d, %d)", width, height);
2548 if (width < ov->minwidth || height < ov->minheight) {
2549 err("Requested dimensions are too small");
2553 if (width >= 320 && height >= 240) {
2555 } else if (width >= 320 || height >= 240) {
2556 err("Invalid width/height combination (%d, %d)", width, height);
2562 if (ov51x_stop(ov) < 0)
2565 /******** Set the mode ********/
2576 if (ov->bridge == BRG_OV518 && ov518_color) {
2577 /* OV518 needs U and V swapped */
2578 i2c_w_mask(ov, 0x15, 0x00, 0x01);
2580 if (mode == VIDEO_PALETTE_GREY) {
2581 /* Set 16-bit input format (UV data are ignored) */
2582 reg_w_mask(ov, 0x20, 0x00, 0x08);
2584 /* Set 8-bit (4:0:0) output format */
2585 reg_w_mask(ov, 0x28, 0x00, 0xf0);
2586 reg_w_mask(ov, 0x38, 0x00, 0xf0);
2588 /* Set 8-bit (YVYU) input format */
2589 reg_w_mask(ov, 0x20, 0x08, 0x08);
2591 /* Set 12-bit (4:2:0) output format */
2592 reg_w_mask(ov, 0x28, 0x80, 0xf0);
2593 reg_w_mask(ov, 0x38, 0x80, 0xf0);
2596 reg_w(ov, 0x28, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2597 reg_w(ov, 0x38, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2603 reg_w(ov, 0x29, hsegs);
2604 reg_w(ov, 0x2a, vsegs);
2606 reg_w(ov, 0x39, hsegs);
2607 reg_w(ov, 0x3a, vsegs);
2609 /* Windows driver does this here; who knows why */
2610 reg_w(ov, 0x2f, 0x80);
2612 /******** Set the framerate (to 15 FPS) ********/
2614 /* Mode independent, but framerate dependent, regs */
2615 reg_w(ov, 0x51, 0x02); /* Clock divider; lower==faster */
2616 reg_w(ov, 0x22, 0x18);
2617 reg_w(ov, 0x23, 0xff);
2619 if (ov->bridge == BRG_OV518PLUS)
2620 reg_w(ov, 0x21, 0x19);
2622 reg_w(ov, 0x71, 0x19); /* Compression-related? */
2624 // FIXME: Sensor-specific
2625 /* Bit 5 is what matters here. Of course, it is "reserved" */
2626 i2c_w(ov, 0x54, 0x23);
2628 reg_w(ov, 0x2f, 0x80);
2630 if (ov->bridge == BRG_OV518PLUS) {
2631 reg_w(ov, 0x24, 0x94);
2632 reg_w(ov, 0x25, 0x90);
2633 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2634 ov518_reg_w32(ov, 0xc6, 540, 2); /* 21ch */
2635 ov518_reg_w32(ov, 0xc7, 540, 2); /* 21ch */
2636 ov518_reg_w32(ov, 0xc8, 108, 2); /* 6ch */
2637 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2638 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2639 ov518_reg_w32(ov, 0xcc, 2400, 2); /* 960h */
2640 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2641 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2643 reg_w(ov, 0x24, 0x9f);
2644 reg_w(ov, 0x25, 0x90);
2645 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2646 ov518_reg_w32(ov, 0xc6, 500, 2); /* 1f4h */
2647 ov518_reg_w32(ov, 0xc7, 500, 2); /* 1f4h */
2648 ov518_reg_w32(ov, 0xc8, 142, 2); /* 8eh */
2649 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2650 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2651 ov518_reg_w32(ov, 0xcc, 2000, 2); /* 7d0h */
2652 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2653 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2656 reg_w(ov, 0x2f, 0x80);
2658 if (ov51x_restart(ov) < 0)
2661 /* Reset it just for good measure */
2662 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
2668 /* This is a wrapper around the OV511, OV518, and sensor specific functions */
2670 mode_init_regs(struct usb_ov511 *ov,
2671 int width, int height, int mode, int sub_flag)
2675 if (!ov || !ov->dev)
2678 if (ov->bclass == BCL_OV518) {
2679 rc = ov518_mode_init_regs(ov, width, height, mode, sub_flag);
2681 rc = ov511_mode_init_regs(ov, width, height, mode, sub_flag);
2684 if (FATAL_ERROR(rc))
2687 switch (ov->sensor) {
2694 rc = set_ov_sensor_window(ov, width, height, mode, sub_flag);
2698 err("KS0127-series decoders not supported yet");
2702 // rc = mode_init_saa_sensor_regs(ov, width, height, mode,
2705 PDEBUG(1, "SAA status = 0x%02X", i2c_r(ov, 0x1f));
2708 err("Unknown sensor");
2712 if (FATAL_ERROR(rc))
2715 /* Sensor-independent settings */
2716 rc = sensor_set_auto_brightness(ov, ov->auto_brt);
2717 if (FATAL_ERROR(rc))
2720 rc = sensor_set_auto_exposure(ov, ov->auto_exp);
2721 if (FATAL_ERROR(rc))
2724 rc = sensor_set_banding_filter(ov, bandingfilter);
2725 if (FATAL_ERROR(rc))
2728 if (ov->lightfreq) {
2729 rc = sensor_set_light_freq(ov, lightfreq);
2730 if (FATAL_ERROR(rc))
2734 rc = sensor_set_backlight(ov, ov->backlight);
2735 if (FATAL_ERROR(rc))
2738 rc = sensor_set_mirror(ov, ov->mirror);
2739 if (FATAL_ERROR(rc))
2745 /* This sets the default image parameters. This is useful for apps that use
2746 * read() and do not set these.
2749 ov51x_set_default_params(struct usb_ov511 *ov)
2753 /* Set default sizes in case IOCTL (VIDIOCMCAPTURE) is not used
2754 * (using read() instead). */
2755 for (i = 0; i < OV511_NUMFRAMES; i++) {
2756 ov->frame[i].width = ov->maxwidth;
2757 ov->frame[i].height = ov->maxheight;
2758 ov->frame[i].bytes_read = 0;
2760 ov->frame[i].format = force_palette;
2762 ov->frame[i].format = VIDEO_PALETTE_YUV420;
2764 ov->frame[i].depth = get_depth(ov->frame[i].format);
2767 PDEBUG(3, "%dx%d, %s", ov->maxwidth, ov->maxheight,
2768 symbolic(v4l1_plist, ov->frame[0].format));
2770 /* Initialize to max width/height, YUV420 or RGB24 (if supported) */
2771 if (mode_init_regs(ov, ov->maxwidth, ov->maxheight,
2772 ov->frame[0].format, 0) < 0)
2778 /**********************************************************************
2780 * Video decoder stuff
2782 **********************************************************************/
2784 /* Set analog input port of decoder */
2786 decoder_set_input(struct usb_ov511 *ov, int input)
2788 PDEBUG(4, "port %d", input);
2790 switch (ov->sensor) {
2794 i2c_w_mask(ov, 0x02, input, 0x07);
2795 /* Bypass chrominance trap for modes 4..7 */
2796 i2c_w_mask(ov, 0x09, (input > 3) ? 0x80:0x00, 0x80);
2806 /* Get ASCII name of video input */
2808 decoder_get_input_name(struct usb_ov511 *ov, int input, char *name)
2810 switch (ov->sensor) {
2813 if (input < 0 || input > 7)
2816 sprintf(name, "CVBS-%d", input);
2817 else // if (input < 8)
2818 sprintf(name, "S-Video-%d", input - 4);
2822 sprintf(name, "%s", "Camera");
2828 /* Set norm (NTSC, PAL, SECAM, AUTO) */
2830 decoder_set_norm(struct usb_ov511 *ov, int norm)
2832 PDEBUG(4, "%d", norm);
2834 switch (ov->sensor) {
2839 if (norm == VIDEO_MODE_NTSC) {
2840 reg_8 = 0x40; /* 60 Hz */
2841 reg_e = 0x00; /* NTSC M / PAL BGHI */
2842 } else if (norm == VIDEO_MODE_PAL) {
2843 reg_8 = 0x00; /* 50 Hz */
2844 reg_e = 0x00; /* NTSC M / PAL BGHI */
2845 } else if (norm == VIDEO_MODE_AUTO) {
2846 reg_8 = 0x80; /* Auto field detect */
2847 reg_e = 0x00; /* NTSC M / PAL BGHI */
2848 } else if (norm == VIDEO_MODE_SECAM) {
2849 reg_8 = 0x00; /* 50 Hz */
2850 reg_e = 0x50; /* SECAM / PAL 4.43 */
2855 i2c_w_mask(ov, 0x08, reg_8, 0xc0);
2856 i2c_w_mask(ov, 0x0e, reg_e, 0x70);
2866 /**********************************************************************
2870 **********************************************************************/
2872 /* Copies a 64-byte segment at pIn to an 8x8 block at pOut. The width of the
2873 * image at pOut is specified by w.
2876 make_8x8(unsigned char *pIn, unsigned char *pOut, int w)
2878 unsigned char *pOut1 = pOut;
2881 for (y = 0; y < 8; y++) {
2883 for (x = 0; x < 8; x++) {
2891 * For RAW BW (YUV 4:0:0) images, data show up in 256 byte segments.
2892 * The segments represent 4 squares of 8x8 pixels as follows:
2894 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2895 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2897 * 56 57 ... 63 120 121 ... 127 248 249 ... 255
2901 yuv400raw_to_yuv400p(struct ov511_frame *frame,
2902 unsigned char *pIn0, unsigned char *pOut0)
2905 unsigned char *pIn, *pOut, *pOutLine;
2910 for (y = 0; y < frame->rawheight - 1; y += 8) {
2912 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2913 make_8x8(pIn, pOut, frame->rawwidth);
2917 pOutLine += 8 * frame->rawwidth;
2922 * For YUV 4:2:0 images, the data show up in 384 byte segments.
2923 * The first 64 bytes of each segment are U, the next 64 are V. The U and
2924 * V are arranged as follows:
2931 * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block).
2933 * The next 256 bytes are full resolution Y data and represent 4 squares
2934 * of 8x8 pixels as follows:
2936 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2937 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2939 * 56 57 ... 63 120 121 ... 127 ... 248 249 ... 255
2941 * Note that the U and V data in one segment represent a 16 x 16 pixel
2942 * area, but the Y data represent a 32 x 8 pixel area. If the width is not an
2943 * even multiple of 32, the extra 8x8 blocks within a 32x8 block belong to the
2944 * next horizontal stripe.
2946 * If dumppix module param is set, _parse_data just dumps the incoming segments,
2947 * verbatim, in order, into the frame. When used with vidcat -f ppm -s 640x480
2948 * this puts the data on the standard output and can be analyzed with the
2949 * parseppm.c utility I wrote. That's a much faster way for figuring out how
2950 * these data are scrambled.
2953 /* Converts from raw, uncompressed segments at pIn0 to a YUV420P frame at pOut0.
2955 * FIXME: Currently only handles width and height that are multiples of 16
2958 yuv420raw_to_yuv420p(struct ov511_frame *frame,
2959 unsigned char *pIn0, unsigned char *pOut0)
2962 unsigned char *pIn, *pOut, *pOutLine;
2963 const unsigned int a = frame->rawwidth * frame->rawheight;
2964 const unsigned int w = frame->rawwidth / 2;
2968 pOutLine = pOut0 + a;
2969 for (y = 0; y < frame->rawheight - 1; y += 16) {
2971 for (x = 0; x < frame->rawwidth - 1; x += 16) {
2972 make_8x8(pIn, pOut, w);
2973 make_8x8(pIn + 64, pOut + a/4, w);
2984 for (y = 0; y < frame->rawheight - 1; y += 8) {
2986 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2987 make_8x8(pIn, pOut, frame->rawwidth);
2995 pOutLine += 8 * frame->rawwidth;
2999 /**********************************************************************
3003 **********************************************************************/
3006 request_decompressor(struct usb_ov511 *ov)
3008 if (ov->bclass == BCL_OV511 || ov->bclass == BCL_OV518) {
3009 err("No decompressor available");
3011 err("Unknown bridge");
3018 decompress(struct usb_ov511 *ov, struct ov511_frame *frame,
3019 unsigned char *pIn0, unsigned char *pOut0)
3021 if (!ov->decomp_ops)
3022 if (request_decompressor(ov))
3027 /**********************************************************************
3031 **********************************************************************/
3033 /* Fuses even and odd fields together, and doubles width.
3034 * INPUT: an odd field followed by an even field at pIn0, in YUV planar format
3035 * OUTPUT: a normal YUV planar image, with correct aspect ratio
3038 deinterlace(struct ov511_frame *frame, int rawformat,
3039 unsigned char *pIn0, unsigned char *pOut0)
3041 const int fieldheight = frame->rawheight / 2;
3042 const int fieldpix = fieldheight * frame->rawwidth;
3043 const int w = frame->width;
3045 unsigned char *pInEven, *pInOdd, *pOut;
3047 PDEBUG(5, "fieldheight=%d", fieldheight);
3049 if (frame->rawheight != frame->height) {
3050 err("invalid height");
3054 if ((frame->rawwidth * 2) != frame->width) {
3055 err("invalid width");
3061 pInEven = pInOdd + fieldpix;
3063 for (y = 0; y < fieldheight; y++) {
3064 for (x = 0; x < frame->rawwidth; x++) {
3066 *(pOut+1) = *pInEven++;
3067 *(pOut+w) = *pInOdd;
3068 *(pOut+w+1) = *pInOdd++;
3074 if (rawformat == RAWFMT_YUV420) {
3076 pInOdd = pIn0 + fieldpix * 2;
3077 pInEven = pInOdd + fieldpix / 4;
3078 for (y = 0; y < fieldheight / 2; y++) {
3079 for (x = 0; x < frame->rawwidth / 2; x++) {
3081 *(pOut+1) = *pInEven++;
3082 *(pOut+w/2) = *pInOdd;
3083 *(pOut+w/2+1) = *pInOdd++;
3089 pInOdd = pIn0 + fieldpix * 2 + fieldpix / 2;
3090 pInEven = pInOdd + fieldpix / 4;
3091 for (y = 0; y < fieldheight / 2; y++) {
3092 for (x = 0; x < frame->rawwidth / 2; x++) {
3094 *(pOut+1) = *pInEven++;
3095 *(pOut+w/2) = *pInOdd;
3096 *(pOut+w/2+1) = *pInOdd++;
3105 ov51x_postprocess_grey(struct usb_ov511 *ov, struct ov511_frame *frame)
3107 /* Deinterlace frame, if necessary */
3108 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3109 if (frame->compressed)
3110 decompress(ov, frame, frame->rawdata,
3113 yuv400raw_to_yuv400p(frame, frame->rawdata,
3116 deinterlace(frame, RAWFMT_YUV400, frame->tempdata,
3119 if (frame->compressed)
3120 decompress(ov, frame, frame->rawdata,
3123 yuv400raw_to_yuv400p(frame, frame->rawdata,
3128 /* Process raw YUV420 data into standard YUV420P */
3130 ov51x_postprocess_yuv420(struct usb_ov511 *ov, struct ov511_frame *frame)
3132 /* Deinterlace frame, if necessary */
3133 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3134 if (frame->compressed)
3135 decompress(ov, frame, frame->rawdata, frame->tempdata);
3137 yuv420raw_to_yuv420p(frame, frame->rawdata,
3140 deinterlace(frame, RAWFMT_YUV420, frame->tempdata,
3143 if (frame->compressed)
3144 decompress(ov, frame, frame->rawdata, frame->data);
3146 yuv420raw_to_yuv420p(frame, frame->rawdata,
3151 /* Post-processes the specified frame. This consists of:
3152 * 1. Decompress frame, if necessary
3153 * 2. Deinterlace frame and scale to proper size, if necessary
3154 * 3. Convert from YUV planar to destination format, if necessary
3155 * 4. Fix the RGB offset, if necessary
3158 ov51x_postprocess(struct usb_ov511 *ov, struct ov511_frame *frame)
3161 memset(frame->data, 0,
3162 MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3163 PDEBUG(4, "Dumping %d bytes", frame->bytes_recvd);
3164 memcpy(frame->data, frame->rawdata, frame->bytes_recvd);
3166 switch (frame->format) {
3167 case VIDEO_PALETTE_GREY:
3168 ov51x_postprocess_grey(ov, frame);
3170 case VIDEO_PALETTE_YUV420:
3171 case VIDEO_PALETTE_YUV420P:
3172 ov51x_postprocess_yuv420(ov, frame);
3175 err("Cannot convert data to %s",
3176 symbolic(v4l1_plist, frame->format));
3181 /**********************************************************************
3183 * OV51x data transfer, IRQ handler
3185 **********************************************************************/
3188 ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3191 int pnum = in[ov->packet_size - 1]; /* Get packet number */
3192 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3193 struct ov511_frame *frame = &ov->frame[ov->curframe];
3196 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3197 * byte non-zero. The EOF packet has image width/height in the
3198 * 10th and 11th bytes. The 9th byte is given as follows:
3201 * 6: compression enabled
3202 * 5: 422/420/400 modes
3203 * 4: 422/420/400 modes
3205 * 2: snapshot button on
3211 dev_info(&ov->dev->dev,
3212 "ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
3213 pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
3214 in[7], in[8], in[9], in[10], in[11]);
3217 /* Check for SOF/EOF packet */
3218 if ((in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) ||
3224 ts = (struct timeval *)(frame->data
3225 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3226 do_gettimeofday(ts);
3228 /* Get the actual frame size from the EOF header */
3229 frame->rawwidth = ((int)(in[9]) + 1) * 8;
3230 frame->rawheight = ((int)(in[10]) + 1) * 8;
3232 PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
3233 ov->curframe, pnum, frame->rawwidth, frame->rawheight,
3234 frame->bytes_recvd);
3236 /* Validate the header data */
3237 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3238 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight,
3241 /* Don't allow byte count to exceed buffer size */
3242 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3244 if (frame->scanstate == STATE_LINES) {
3247 frame->grabstate = FRAME_DONE;
3248 wake_up_interruptible(&frame->wq);
3250 /* If next frame is ready or grabbing,
3252 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3253 if (ov->frame[nextf].grabstate == FRAME_READY
3254 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3255 ov->curframe = nextf;
3256 ov->frame[nextf].scanstate = STATE_SCANNING;
3258 if (frame->grabstate == FRAME_DONE) {
3259 PDEBUG(4, "** Frame done **");
3261 PDEBUG(4, "Frame not ready? state = %d",
3262 ov->frame[nextf].grabstate);
3268 PDEBUG(5, "Frame done, but not scanning");
3270 /* Image corruption caused by misplaced frame->segment = 0
3271 * fixed by carlosf@conectiva.com.br
3275 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3277 /* Check to see if it's a snapshot frame */
3278 /* FIXME?? Should the snapshot reset go here? Performance? */
3280 frame->snapshot = 1;
3281 PDEBUG(3, "snapshot detected");
3284 frame->scanstate = STATE_LINES;
3285 frame->bytes_recvd = 0;
3286 frame->compressed = in[8] & 0x40;
3290 /* Are we in a frame? */
3291 if (frame->scanstate != STATE_LINES) {
3292 PDEBUG(5, "Not in a frame; packet skipped");
3296 /* If frame start, skip header */
3297 if (frame->bytes_recvd == 0)
3302 num = n - offset - 1;
3304 /* Dump all data exactly as received */
3306 frame->bytes_recvd += n - 1;
3307 if (frame->bytes_recvd <= max_raw)
3308 memcpy(frame->rawdata + frame->bytes_recvd - (n - 1),
3311 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3312 frame->bytes_recvd - max_raw);
3313 } else if (!frame->compressed && !remove_zeros) {
3314 frame->bytes_recvd += num;
3315 if (frame->bytes_recvd <= max_raw)
3316 memcpy(frame->rawdata + frame->bytes_recvd - num,
3319 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3320 frame->bytes_recvd - max_raw);
3321 } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
3322 int b, read = 0, allzero, copied = 0;
3324 frame->bytes_recvd += 32 - offset; // Bytes out
3325 memcpy(frame->rawdata, in + offset, 32 - offset);
3329 while (read < n - 1) {
3331 for (b = 0; b < 32; b++) {
3341 if (frame->bytes_recvd + copied + 32 <= max_raw)
3343 memcpy(frame->rawdata
3344 + frame->bytes_recvd + copied,
3348 PDEBUG(3, "Raw data buffer overrun!!");
3354 frame->bytes_recvd += copied;
3359 ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3361 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3362 struct ov511_frame *frame = &ov->frame[ov->curframe];
3365 /* Don't copy the packet number byte */
3366 if (ov->packet_numbering)
3369 /* A false positive here is likely, until OVT gives me
3370 * the definitive SOF/EOF format */
3371 if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
3373 dev_info(&ov->dev->dev,
3374 "ph: %2x %2x %2x %2x %2x %2x %2x %2x\n",
3375 in[0], in[1], in[2], in[3], in[4], in[5],
3379 if (frame->scanstate == STATE_LINES) {
3380 PDEBUG(4, "Detected frame end/start");
3382 } else { //scanstate == STATE_SCANNING
3384 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3392 ts = (struct timeval *)(frame->data
3393 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3394 do_gettimeofday(ts);
3396 PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
3398 (int)(in[9]), (int)(in[10]), frame->bytes_recvd);
3400 // FIXME: Since we don't know the header formats yet,
3401 // there is no way to know what the actual image size is
3402 frame->rawwidth = frame->width;
3403 frame->rawheight = frame->height;
3405 /* Validate the header data */
3406 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3407 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
3409 /* Don't allow byte count to exceed buffer size */
3410 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3412 if (frame->scanstate == STATE_LINES) {
3415 frame->grabstate = FRAME_DONE;
3416 wake_up_interruptible(&frame->wq);
3418 /* If next frame is ready or grabbing,
3420 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3421 if (ov->frame[nextf].grabstate == FRAME_READY
3422 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3423 ov->curframe = nextf;
3424 ov->frame[nextf].scanstate = STATE_SCANNING;
3425 frame = &ov->frame[nextf];
3427 if (frame->grabstate == FRAME_DONE) {
3428 PDEBUG(4, "** Frame done **");
3430 PDEBUG(4, "Frame not ready? state = %d",
3431 ov->frame[nextf].grabstate);
3435 PDEBUG(4, "SOF dropped (no active frame)");
3436 return; /* Nowhere to store this frame */
3440 PDEBUG(4, "Starting capture on frame %d", frame->framenum);
3442 // Snapshot not reverse-engineered yet.
3444 /* Check to see if it's a snapshot frame */
3445 /* FIXME?? Should the snapshot reset go here? Performance? */
3447 frame->snapshot = 1;
3448 PDEBUG(3, "snapshot detected");
3451 frame->scanstate = STATE_LINES;
3452 frame->bytes_recvd = 0;
3453 frame->compressed = 1;
3456 /* Are we in a frame? */
3457 if (frame->scanstate != STATE_LINES) {
3458 PDEBUG(4, "scanstate: no SOF yet");
3462 /* Dump all data exactly as received */
3464 frame->bytes_recvd += n;
3465 if (frame->bytes_recvd <= max_raw)
3466 memcpy(frame->rawdata + frame->bytes_recvd - n, in, n);
3468 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3469 frame->bytes_recvd - max_raw);
3471 /* All incoming data are divided into 8-byte segments. If the
3472 * segment contains all zero bytes, it must be skipped. These
3473 * zero-segments allow the OV518 to mainain a constant data rate
3474 * regardless of the effectiveness of the compression. Segments
3475 * are aligned relative to the beginning of each isochronous
3476 * packet. The first segment in each image is a header (the
3477 * decompressor skips it later).
3480 int b, read = 0, allzero, copied = 0;
3484 for (b = 0; b < 8; b++) {
3494 if (frame->bytes_recvd + copied + 8 <= max_raw)
3496 memcpy(frame->rawdata
3497 + frame->bytes_recvd + copied,
3501 PDEBUG(3, "Raw data buffer overrun!!");
3506 frame->bytes_recvd += copied;
3511 ov51x_isoc_irq(struct urb *urb)
3514 struct usb_ov511 *ov;
3515 struct ov511_sbuf *sbuf;
3517 if (!urb->context) {
3518 PDEBUG(4, "no context");
3522 sbuf = urb->context;
3525 if (!ov || !ov->dev || !ov->user) {
3526 PDEBUG(4, "no device, or not open");
3530 if (!ov->streaming) {
3531 PDEBUG(4, "hmmm... not streaming, but got interrupt");
3535 if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
3536 PDEBUG(4, "URB unlinked");
3540 if (urb->status != -EINPROGRESS && urb->status != 0) {
3541 err("ERROR: urb->status=%d: %s", urb->status,
3542 symbolic(urb_errlist, urb->status));
3545 /* Copy the data received into our frame buffer */
3546 PDEBUG(5, "sbuf[%d]: Moving %d packets", sbuf->n,
3547 urb->number_of_packets);
3548 for (i = 0; i < urb->number_of_packets; i++) {
3549 /* Warning: Don't call *_move_data() if no frame active! */
3550 if (ov->curframe >= 0) {
3551 int n = urb->iso_frame_desc[i].actual_length;
3552 int st = urb->iso_frame_desc[i].status;
3553 unsigned char *cdata;
3555 urb->iso_frame_desc[i].actual_length = 0;
3556 urb->iso_frame_desc[i].status = 0;
3558 cdata = urb->transfer_buffer
3559 + urb->iso_frame_desc[i].offset;
3562 PDEBUG(4, "Zero-length packet");
3567 PDEBUG(2, "data error: [%d] len=%d, status=%d",
3570 if (ov->bclass == BCL_OV511)
3571 ov511_move_data(ov, cdata, n);
3572 else if (ov->bclass == BCL_OV518)
3573 ov518_move_data(ov, cdata, n);
3575 err("Unknown bridge device (%d)", ov->bridge);
3577 } else if (waitqueue_active(&ov->wq)) {
3578 wake_up_interruptible(&ov->wq);
3582 /* Resubmit this URB */
3584 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
3585 err("usb_submit_urb() ret %d", i);
3590 /****************************************************************************
3592 * Stream initialization and termination
3594 ***************************************************************************/
3597 ov51x_init_isoc(struct usb_ov511 *ov)
3600 int fx, err, n, i, size;
3602 PDEBUG(3, "*** Initializing capture ***");
3606 if (ov->bridge == BRG_OV511) {
3611 else if (cams == 3 || cams == 4)
3614 err("\"cams\" parameter too high!");
3617 } else if (ov->bridge == BRG_OV511PLUS) {
3622 else if (cams == 3 || cams == 4)
3624 else if (cams >= 5 && cams <= 8)
3626 else if (cams >= 9 && cams <= 31)
3629 err("\"cams\" parameter too high!");
3632 } else if (ov->bclass == BCL_OV518) {
3637 else if (cams == 3 || cams == 4)
3639 else if (cams >= 5 && cams <= 8)
3642 err("\"cams\" parameter too high!");
3646 err("invalid bridge type");
3650 // FIXME: OV518 is hardcoded to 15 FPS (alternate 5) for now
3651 if (ov->bclass == BCL_OV518) {
3652 if (packetsize == -1) {
3653 ov518_set_packet_size(ov, 640);
3655 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3657 ov518_set_packet_size(ov, packetsize);
3660 if (packetsize == -1) {
3661 ov511_set_packet_size(ov, size);
3663 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3665 ov511_set_packet_size(ov, packetsize);
3669 for (n = 0; n < OV511_NUMSBUF; n++) {
3670 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
3672 err("init isoc: usb_alloc_urb ret. NULL");
3673 for (i = 0; i < n; i++)
3674 usb_free_urb(ov->sbuf[i].urb);
3677 ov->sbuf[n].urb = urb;
3679 urb->context = &ov->sbuf[n];
3680 urb->pipe = usb_rcvisocpipe(ov->dev, OV511_ENDPOINT_ADDRESS);
3681 urb->transfer_flags = URB_ISO_ASAP;
3682 urb->transfer_buffer = ov->sbuf[n].data;
3683 urb->complete = ov51x_isoc_irq;
3684 urb->number_of_packets = FRAMES_PER_DESC;
3685 urb->transfer_buffer_length = ov->packet_size * FRAMES_PER_DESC;
3687 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
3688 urb->iso_frame_desc[fx].offset = ov->packet_size * fx;
3689 urb->iso_frame_desc[fx].length = ov->packet_size;
3695 for (n = 0; n < OV511_NUMSBUF; n++) {
3696 ov->sbuf[n].urb->dev = ov->dev;
3697 err = usb_submit_urb(ov->sbuf[n].urb, GFP_KERNEL);
3699 err("init isoc: usb_submit_urb(%d) ret %d", n, err);
3708 ov51x_unlink_isoc(struct usb_ov511 *ov)
3712 /* Unschedule all of the iso td's */
3713 for (n = OV511_NUMSBUF - 1; n >= 0; n--) {
3714 if (ov->sbuf[n].urb) {
3715 usb_kill_urb(ov->sbuf[n].urb);
3716 usb_free_urb(ov->sbuf[n].urb);
3717 ov->sbuf[n].urb = NULL;
3723 ov51x_stop_isoc(struct usb_ov511 *ov)
3725 if (!ov->streaming || !ov->dev)
3728 PDEBUG(3, "*** Stopping capture ***");
3730 if (ov->bclass == BCL_OV518)
3731 ov518_set_packet_size(ov, 0);
3733 ov511_set_packet_size(ov, 0);
3737 ov51x_unlink_isoc(ov);
3741 ov51x_new_frame(struct usb_ov511 *ov, int framenum)
3743 struct ov511_frame *frame;
3746 PDEBUG(4, "ov->curframe = %d, framenum = %d", ov->curframe, framenum);
3751 /* If we're not grabbing a frame right now and the other frame is */
3752 /* ready to be grabbed into, then use it instead */
3753 if (ov->curframe == -1) {
3754 newnum = (framenum - 1 + OV511_NUMFRAMES) % OV511_NUMFRAMES;
3755 if (ov->frame[newnum].grabstate == FRAME_READY)
3760 frame = &ov->frame[framenum];
3762 PDEBUG(4, "framenum = %d, width = %d, height = %d", framenum,
3763 frame->width, frame->height);
3765 frame->grabstate = FRAME_GRABBING;
3766 frame->scanstate = STATE_SCANNING;
3767 frame->snapshot = 0;
3769 ov->curframe = framenum;
3771 /* Make sure it's not too big */
3772 if (frame->width > ov->maxwidth)
3773 frame->width = ov->maxwidth;
3775 frame->width &= ~7L; /* Multiple of 8 */
3777 if (frame->height > ov->maxheight)
3778 frame->height = ov->maxheight;
3780 frame->height &= ~3L; /* Multiple of 4 */
3785 /****************************************************************************
3789 ***************************************************************************/
3792 * - You must acquire buf_lock before entering this function.
3793 * - Because this code will free any non-null pointer, you must be sure to null
3794 * them if you explicitly free them somewhere else!
3797 ov51x_do_dealloc(struct usb_ov511 *ov)
3800 PDEBUG(4, "entered");
3803 rvfree(ov->fbuf, OV511_NUMFRAMES
3804 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3811 vfree(ov->tempfbuf);
3812 ov->tempfbuf = NULL;
3814 for (i = 0; i < OV511_NUMSBUF; i++) {
3815 kfree(ov->sbuf[i].data);
3816 ov->sbuf[i].data = NULL;
3819 for (i = 0; i < OV511_NUMFRAMES; i++) {
3820 ov->frame[i].data = NULL;
3821 ov->frame[i].rawdata = NULL;
3822 ov->frame[i].tempdata = NULL;
3823 if (ov->frame[i].compbuf) {
3824 free_page((unsigned long) ov->frame[i].compbuf);
3825 ov->frame[i].compbuf = NULL;
3829 PDEBUG(4, "buffer memory deallocated");
3830 ov->buf_state = BUF_NOT_ALLOCATED;
3831 PDEBUG(4, "leaving");
3835 ov51x_alloc(struct usb_ov511 *ov)
3838 const int w = ov->maxwidth;
3839 const int h = ov->maxheight;
3840 const int data_bufsize = OV511_NUMFRAMES * MAX_DATA_SIZE(w, h);
3841 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h);
3843 PDEBUG(4, "entered");
3844 mutex_lock(&ov->buf_lock);
3846 if (ov->buf_state == BUF_ALLOCATED)
3849 ov->fbuf = rvmalloc(data_bufsize);
3853 ov->rawfbuf = vmalloc(raw_bufsize);
3857 memset(ov->rawfbuf, 0, raw_bufsize);
3859 ov->tempfbuf = vmalloc(raw_bufsize);
3863 memset(ov->tempfbuf, 0, raw_bufsize);
3865 for (i = 0; i < OV511_NUMSBUF; i++) {
3866 ov->sbuf[i].data = kmalloc(FRAMES_PER_DESC *
3867 MAX_FRAME_SIZE_PER_DESC, GFP_KERNEL);
3868 if (!ov->sbuf[i].data)
3871 PDEBUG(4, "sbuf[%d] @ %p", i, ov->sbuf[i].data);
3874 for (i = 0; i < OV511_NUMFRAMES; i++) {
3875 ov->frame[i].data = ov->fbuf + i * MAX_DATA_SIZE(w, h);
3876 ov->frame[i].rawdata = ov->rawfbuf
3877 + i * MAX_RAW_DATA_SIZE(w, h);
3878 ov->frame[i].tempdata = ov->tempfbuf
3879 + i * MAX_RAW_DATA_SIZE(w, h);
3881 ov->frame[i].compbuf =
3882 (unsigned char *) __get_free_page(GFP_KERNEL);
3883 if (!ov->frame[i].compbuf)
3886 PDEBUG(4, "frame[%d] @ %p", i, ov->frame[i].data);
3889 ov->buf_state = BUF_ALLOCATED;
3891 mutex_unlock(&ov->buf_lock);
3892 PDEBUG(4, "leaving");
3895 ov51x_do_dealloc(ov);
3896 mutex_unlock(&ov->buf_lock);
3897 PDEBUG(4, "errored");
3902 ov51x_dealloc(struct usb_ov511 *ov)
3904 PDEBUG(4, "entered");
3905 mutex_lock(&ov->buf_lock);
3906 ov51x_do_dealloc(ov);
3907 mutex_unlock(&ov->buf_lock);
3908 PDEBUG(4, "leaving");
3911 /****************************************************************************
3915 ***************************************************************************/
3918 ov51x_v4l1_open(struct inode *inode, struct file *file)
3920 struct video_device *vdev = video_devdata(file);
3921 struct usb_ov511 *ov = video_get_drvdata(vdev);
3924 PDEBUG(4, "opening");
3926 mutex_lock(&ov->lock);
3934 /* In case app doesn't set them... */
3935 err = ov51x_set_default_params(ov);
3939 /* Make sure frames are reset */
3940 for (i = 0; i < OV511_NUMFRAMES; i++) {
3941 ov->frame[i].grabstate = FRAME_UNUSED;
3942 ov->frame[i].bytes_read = 0;
3945 /* If compression is on, make sure now that a
3946 * decompressor can be loaded */
3947 if (ov->compress && !ov->decomp_ops) {
3948 err = request_decompressor(ov);
3949 if (err && !dumppix)
3953 err = ov51x_alloc(ov);
3957 err = ov51x_init_isoc(ov);
3964 file->private_data = vdev;
3966 if (ov->led_policy == LED_AUTO)
3967 ov51x_led_control(ov, 1);
3970 mutex_unlock(&ov->lock);
3975 ov51x_v4l1_close(struct inode *inode, struct file *file)
3977 struct video_device *vdev = file->private_data;
3978 struct usb_ov511 *ov = video_get_drvdata(vdev);
3980 PDEBUG(4, "ov511_close");
3982 mutex_lock(&ov->lock);
3985 ov51x_stop_isoc(ov);
3987 if (ov->led_policy == LED_AUTO)
3988 ov51x_led_control(ov, 0);
3993 mutex_unlock(&ov->lock);
3995 /* Device unplugged while open. Only a minimum of unregistration is done
3996 * here; the disconnect callback already did the rest. */
3998 mutex_lock(&ov->cbuf_lock);
4001 mutex_unlock(&ov->cbuf_lock);
4008 file->private_data = NULL;
4012 /* Do not call this function directly! */
4014 ov51x_v4l1_ioctl_internal(struct inode *inode, struct file *file,
4015 unsigned int cmd, void *arg)
4017 struct video_device *vdev = file->private_data;
4018 struct usb_ov511 *ov = video_get_drvdata(vdev);
4019 PDEBUG(5, "IOCtl: 0x%X", cmd);
4027 struct video_capability *b = arg;
4029 PDEBUG(4, "VIDIOCGCAP");
4031 memset(b, 0, sizeof(struct video_capability));
4032 sprintf(b->name, "%s USB Camera",
4033 symbolic(brglist, ov->bridge));
4034 b->type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE;
4035 b->channels = ov->num_inputs;
4037 b->maxwidth = ov->maxwidth;
4038 b->maxheight = ov->maxheight;
4039 b->minwidth = ov->minwidth;
4040 b->minheight = ov->minheight;
4046 struct video_channel *v = arg;
4048 PDEBUG(4, "VIDIOCGCHAN");
4050 if ((unsigned)(v->channel) >= ov->num_inputs) {
4051 err("Invalid channel (%d)", v->channel);
4056 v->type = VIDEO_TYPE_CAMERA;
4058 // v->flags |= (ov->has_decoder) ? VIDEO_VC_NORM : 0;
4060 decoder_get_input_name(ov, v->channel, v->name);
4066 struct video_channel *v = arg;
4069 PDEBUG(4, "VIDIOCSCHAN");
4071 /* Make sure it's not a camera */
4072 if (!ov->has_decoder) {
4073 if (v->channel == 0)
4079 if (v->norm != VIDEO_MODE_PAL &&
4080 v->norm != VIDEO_MODE_NTSC &&
4081 v->norm != VIDEO_MODE_SECAM &&
4082 v->norm != VIDEO_MODE_AUTO) {
4083 err("Invalid norm (%d)", v->norm);
4087 if ((unsigned)(v->channel) >= ov->num_inputs) {
4088 err("Invalid channel (%d)", v->channel);
4092 err = decoder_set_input(ov, v->channel);
4096 err = decoder_set_norm(ov, v->norm);
4104 struct video_picture *p = arg;
4106 PDEBUG(4, "VIDIOCGPICT");
4108 memset(p, 0, sizeof(struct video_picture));
4109 if (sensor_get_picture(ov, p))
4112 /* Can we get these from frame[0]? -claudio? */
4113 p->depth = ov->frame[0].depth;
4114 p->palette = ov->frame[0].format;
4120 struct video_picture *p = arg;
4123 PDEBUG(4, "VIDIOCSPICT");
4125 if (!get_depth(p->palette))
4128 if (sensor_set_picture(ov, p))
4131 if (force_palette && p->palette != force_palette) {
4132 dev_info(&ov->dev->dev, "Palette rejected (%s)\n",
4133 symbolic(v4l1_plist, p->palette));
4137 // FIXME: Format should be independent of frames
4138 if (p->palette != ov->frame[0].format) {
4139 PDEBUG(4, "Detected format change");
4141 rc = ov51x_wait_frames_inactive(ov);
4145 mode_init_regs(ov, ov->frame[0].width,
4146 ov->frame[0].height, p->palette, ov->sub_flag);
4149 PDEBUG(4, "Setting depth=%d, palette=%s",
4150 p->depth, symbolic(v4l1_plist, p->palette));
4152 for (i = 0; i < OV511_NUMFRAMES; i++) {
4153 ov->frame[i].depth = p->depth;
4154 ov->frame[i].format = p->palette;
4159 case VIDIOCGCAPTURE:
4163 PDEBUG(4, "VIDIOCGCAPTURE");
4168 case VIDIOCSCAPTURE:
4170 struct video_capture *vc = arg;
4172 PDEBUG(4, "VIDIOCSCAPTURE");
4188 if (vc->height == 0)
4193 ov->subw = vc->width;
4194 ov->subh = vc->height;
4200 struct video_window *vw = arg;
4203 PDEBUG(4, "VIDIOCSWIN: %dx%d", vw->width, vw->height);
4210 if (vw->height != ov->maxheight)
4212 if (vw->width != ov->maxwidth)
4216 rc = ov51x_wait_frames_inactive(ov);
4220 rc = mode_init_regs(ov, vw->width, vw->height,
4221 ov->frame[0].format, ov->sub_flag);
4225 for (i = 0; i < OV511_NUMFRAMES; i++) {
4226 ov->frame[i].width = vw->width;
4227 ov->frame[i].height = vw->height;
4234 struct video_window *vw = arg;
4236 memset(vw, 0, sizeof(struct video_window));
4237 vw->x = 0; /* FIXME */
4239 vw->width = ov->frame[0].width;
4240 vw->height = ov->frame[0].height;
4243 PDEBUG(4, "VIDIOCGWIN: %dx%d", vw->width, vw->height);
4249 struct video_mbuf *vm = arg;
4252 PDEBUG(4, "VIDIOCGMBUF");
4254 memset(vm, 0, sizeof(struct video_mbuf));
4255 vm->size = OV511_NUMFRAMES
4256 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4257 vm->frames = OV511_NUMFRAMES;
4260 for (i = 1; i < OV511_NUMFRAMES; i++) {
4261 vm->offsets[i] = vm->offsets[i-1]
4262 + MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4267 case VIDIOCMCAPTURE:
4269 struct video_mmap *vm = arg;
4271 unsigned int f = vm->frame;
4273 PDEBUG(4, "VIDIOCMCAPTURE: frame: %d, %dx%d, %s", f, vm->width,
4274 vm->height, symbolic(v4l1_plist, vm->format));
4276 depth = get_depth(vm->format);
4278 PDEBUG(2, "VIDIOCMCAPTURE: invalid format (%s)",
4279 symbolic(v4l1_plist, vm->format));
4283 if (f >= OV511_NUMFRAMES) {
4284 err("VIDIOCMCAPTURE: invalid frame (%d)", f);
4288 if (vm->width > ov->maxwidth
4289 || vm->height > ov->maxheight) {
4290 err("VIDIOCMCAPTURE: requested dimensions too big");
4294 if (ov->frame[f].grabstate == FRAME_GRABBING) {
4295 PDEBUG(4, "VIDIOCMCAPTURE: already grabbing");
4299 if (force_palette && (vm->format != force_palette)) {
4300 PDEBUG(2, "palette rejected (%s)",
4301 symbolic(v4l1_plist, vm->format));
4305 if ((ov->frame[f].width != vm->width) ||
4306 (ov->frame[f].height != vm->height) ||
4307 (ov->frame[f].format != vm->format) ||
4308 (ov->frame[f].sub_flag != ov->sub_flag) ||
4309 (ov->frame[f].depth != depth)) {
4310 PDEBUG(4, "VIDIOCMCAPTURE: change in image parameters");
4312 rc = ov51x_wait_frames_inactive(ov);
4316 rc = mode_init_regs(ov, vm->width, vm->height,
4317 vm->format, ov->sub_flag);
4320 PDEBUG(1, "Got error while initializing regs ");
4324 ov->frame[f].width = vm->width;
4325 ov->frame[f].height = vm->height;
4326 ov->frame[f].format = vm->format;
4327 ov->frame[f].sub_flag = ov->sub_flag;
4328 ov->frame[f].depth = depth;
4331 /* Mark it as ready */
4332 ov->frame[f].grabstate = FRAME_READY;
4334 PDEBUG(4, "VIDIOCMCAPTURE: renewing frame %d", f);
4336 return ov51x_new_frame(ov, f);
4340 unsigned int fnum = *((unsigned int *) arg);
4341 struct ov511_frame *frame;
4344 if (fnum >= OV511_NUMFRAMES) {
4345 err("VIDIOCSYNC: invalid frame (%d)", fnum);
4349 frame = &ov->frame[fnum];
4351 PDEBUG(4, "syncing to frame %d, grabstate = %d", fnum,
4354 switch (frame->grabstate) {
4358 case FRAME_GRABBING:
4364 rc = wait_event_interruptible(frame->wq,
4365 (frame->grabstate == FRAME_DONE)
4366 || (frame->grabstate == FRAME_ERROR));
4371 if (frame->grabstate == FRAME_ERROR) {
4372 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4378 if (ov->snap_enabled && !frame->snapshot) {
4379 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4384 frame->grabstate = FRAME_UNUSED;
4386 /* Reset the hardware snapshot button */
4387 /* FIXME - Is this the best place for this? */
4388 if ((ov->snap_enabled) && (frame->snapshot)) {
4389 frame->snapshot = 0;
4390 ov51x_clear_snapshot(ov);
4393 /* Decompression, format conversion, etc... */
4394 ov51x_postprocess(ov, frame);
4403 struct video_buffer *vb = arg;
4405 PDEBUG(4, "VIDIOCGFBUF");
4407 memset(vb, 0, sizeof(struct video_buffer));
4413 struct video_unit *vu = arg;
4415 PDEBUG(4, "VIDIOCGUNIT");
4417 memset(vu, 0, sizeof(struct video_unit));
4419 vu->video = ov->vdev->minor;
4420 vu->vbi = VIDEO_NO_UNIT;
4421 vu->radio = VIDEO_NO_UNIT;
4422 vu->audio = VIDEO_NO_UNIT;
4423 vu->teletext = VIDEO_NO_UNIT;
4429 struct ov511_i2c_struct *w = arg;
4431 return i2c_w_slave(ov, w->slave, w->reg, w->value, w->mask);
4435 struct ov511_i2c_struct *r = arg;
4438 rc = i2c_r_slave(ov, r->slave, r->reg);
4446 PDEBUG(3, "Unsupported IOCtl: 0x%X", cmd);
4447 return -ENOIOCTLCMD;
4454 ov51x_v4l1_ioctl(struct inode *inode, struct file *file,
4455 unsigned int cmd, unsigned long arg)
4457 struct video_device *vdev = file->private_data;
4458 struct usb_ov511 *ov = video_get_drvdata(vdev);
4461 if (mutex_lock_interruptible(&ov->lock))
4464 rc = video_usercopy(inode, file, cmd, arg, ov51x_v4l1_ioctl_internal);
4466 mutex_unlock(&ov->lock);
4471 ov51x_v4l1_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos)
4473 struct video_device *vdev = file->private_data;
4474 int noblock = file->f_flags&O_NONBLOCK;
4475 unsigned long count = cnt;
4476 struct usb_ov511 *ov = video_get_drvdata(vdev);
4477 int i, rc = 0, frmx = -1;
4478 struct ov511_frame *frame;
4480 if (mutex_lock_interruptible(&ov->lock))
4483 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock);
4485 if (!vdev || !buf) {
4495 // FIXME: Only supports two frames
4496 /* See if a frame is completed, then use it. */
4497 if (ov->frame[0].grabstate >= FRAME_DONE) /* _DONE or _ERROR */
4499 else if (ov->frame[1].grabstate >= FRAME_DONE)/* _DONE or _ERROR */
4502 /* If nonblocking we return immediately */
4503 if (noblock && (frmx == -1)) {
4508 /* If no FRAME_DONE, look for a FRAME_GRABBING state. */
4509 /* See if a frame is in process (grabbing), then use it. */
4511 if (ov->frame[0].grabstate == FRAME_GRABBING)
4513 else if (ov->frame[1].grabstate == FRAME_GRABBING)
4517 /* If no frame is active, start one. */
4519 if ((rc = ov51x_new_frame(ov, frmx = 0))) {
4520 err("read: ov51x_new_frame error");
4525 frame = &ov->frame[frmx];
4533 /* Wait while we're grabbing the image */
4534 PDEBUG(4, "Waiting image grabbing");
4535 rc = wait_event_interruptible(frame->wq,
4536 (frame->grabstate == FRAME_DONE)
4537 || (frame->grabstate == FRAME_ERROR));
4542 PDEBUG(4, "Got image, frame->grabstate = %d", frame->grabstate);
4543 PDEBUG(4, "bytes_recvd = %d", frame->bytes_recvd);
4545 if (frame->grabstate == FRAME_ERROR) {
4546 frame->bytes_read = 0;
4547 err("** ick! ** Errored frame %d", ov->curframe);
4548 if (ov51x_new_frame(ov, frmx)) {
4549 err("read: ov51x_new_frame error");
4556 /* Repeat until we get a snapshot frame */
4557 if (ov->snap_enabled)
4558 PDEBUG(4, "Waiting snapshot frame");
4559 if (ov->snap_enabled && !frame->snapshot) {
4560 frame->bytes_read = 0;
4561 if ((rc = ov51x_new_frame(ov, frmx))) {
4562 err("read: ov51x_new_frame error");
4568 /* Clear the snapshot */
4569 if (ov->snap_enabled && frame->snapshot) {
4570 frame->snapshot = 0;
4571 ov51x_clear_snapshot(ov);
4574 /* Decompression, format conversion, etc... */
4575 ov51x_postprocess(ov, frame);
4577 PDEBUG(4, "frmx=%d, bytes_read=%ld, length=%ld", frmx,
4579 get_frame_length(frame));
4581 /* copy bytes to user space; we allow for partials reads */
4582 // if ((count + frame->bytes_read)
4583 // > get_frame_length((struct ov511_frame *)frame))
4584 // count = frame->scanlength - frame->bytes_read;
4586 /* FIXME - count hardwired to be one frame... */
4587 count = get_frame_length(frame);
4589 PDEBUG(4, "Copy to user space: %ld bytes", count);
4590 if ((i = copy_to_user(buf, frame->data + frame->bytes_read, count))) {
4591 PDEBUG(4, "Copy failed! %d bytes not copied", i);
4596 frame->bytes_read += count;
4597 PDEBUG(4, "{copy} count used=%ld, new bytes_read=%ld",
4598 count, frame->bytes_read);
4600 /* If all data have been read... */
4601 if (frame->bytes_read
4602 >= get_frame_length(frame)) {
4603 frame->bytes_read = 0;
4605 // FIXME: Only supports two frames
4606 /* Mark it as available to be used again. */
4607 ov->frame[frmx].grabstate = FRAME_UNUSED;
4608 if ((rc = ov51x_new_frame(ov, !frmx))) {
4609 err("ov51x_new_frame returned error");
4614 PDEBUG(4, "read finished, returning %ld (sweet)", count);
4616 mutex_unlock(&ov->lock);
4620 mutex_unlock(&ov->lock);
4625 ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4627 struct video_device *vdev = file->private_data;
4628 unsigned long start = vma->vm_start;
4629 unsigned long size = vma->vm_end - vma->vm_start;
4630 struct usb_ov511 *ov = video_get_drvdata(vdev);
4631 unsigned long page, pos;
4633 if (ov->dev == NULL)
4636 PDEBUG(4, "mmap: %ld (%lX) bytes", size, size);
4638 if (size > (((OV511_NUMFRAMES
4639 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
4640 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4643 if (mutex_lock_interruptible(&ov->lock))
4646 pos = (unsigned long)ov->fbuf;
4648 page = vmalloc_to_pfn((void *)pos);
4649 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
4650 mutex_unlock(&ov->lock);
4655 if (size > PAGE_SIZE)
4661 mutex_unlock(&ov->lock);
4665 static const struct file_operations ov511_fops = {
4666 .owner = THIS_MODULE,
4667 .open = ov51x_v4l1_open,
4668 .release = ov51x_v4l1_close,
4669 .read = ov51x_v4l1_read,
4670 .mmap = ov51x_v4l1_mmap,
4671 .ioctl = ov51x_v4l1_ioctl,
4672 #ifdef CONFIG_COMPAT
4673 .compat_ioctl = v4l_compat_ioctl32,
4675 .llseek = no_llseek,
4678 static struct video_device vdev_template = {
4679 .name = "OV511 USB Camera",
4680 .fops = &ov511_fops,
4681 .release = video_device_release,
4685 /****************************************************************************
4687 * OV511 and sensor configuration
4689 ***************************************************************************/
4691 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
4692 * the same register settings as the OV7610, since they are very similar.
4695 ov7xx0_configure(struct usb_ov511 *ov)
4700 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
4702 * Register 0x0f in the 7610 has the following effects:
4704 * 0x85 (AEC method 1): Best overall, good contrast range
4705 * 0x45 (AEC method 2): Very overexposed
4706 * 0xa5 (spec sheet default): Ok, but the black level is
4707 * shifted resulting in loss of contrast
4708 * 0x05 (old driver setting): very overexposed, too much
4711 static struct ov511_regvals aRegvalsNorm7610[] = {
4712 { OV511_I2C_BUS, 0x10, 0xff },
4713 { OV511_I2C_BUS, 0x16, 0x06 },
4714 { OV511_I2C_BUS, 0x28, 0x24 },
4715 { OV511_I2C_BUS, 0x2b, 0xac },
4716 { OV511_I2C_BUS, 0x12, 0x00 },
4717 { OV511_I2C_BUS, 0x38, 0x81 },
4718 { OV511_I2C_BUS, 0x28, 0x24 }, /* 0c */
4719 { OV511_I2C_BUS, 0x0f, 0x85 }, /* lg's setting */
4720 { OV511_I2C_BUS, 0x15, 0x01 },
4721 { OV511_I2C_BUS, 0x20, 0x1c },
4722 { OV511_I2C_BUS, 0x23, 0x2a },
4723 { OV511_I2C_BUS, 0x24, 0x10 },
4724 { OV511_I2C_BUS, 0x25, 0x8a },
4725 { OV511_I2C_BUS, 0x26, 0xa2 },
4726 { OV511_I2C_BUS, 0x27, 0xc2 },
4727 { OV511_I2C_BUS, 0x2a, 0x04 },
4728 { OV511_I2C_BUS, 0x2c, 0xfe },
4729 { OV511_I2C_BUS, 0x2d, 0x93 },
4730 { OV511_I2C_BUS, 0x30, 0x71 },
4731 { OV511_I2C_BUS, 0x31, 0x60 },
4732 { OV511_I2C_BUS, 0x32, 0x26 },
4733 { OV511_I2C_BUS, 0x33, 0x20 },
4734 { OV511_I2C_BUS, 0x34, 0x48 },
4735 { OV511_I2C_BUS, 0x12, 0x24 },
4736 { OV511_I2C_BUS, 0x11, 0x01 },
4737 { OV511_I2C_BUS, 0x0c, 0x24 },
4738 { OV511_I2C_BUS, 0x0d, 0x24 },
4739 { OV511_DONE_BUS, 0x0, 0x00 },
4742 static struct ov511_regvals aRegvalsNorm7620[] = {
4743 { OV511_I2C_BUS, 0x00, 0x00 },
4744 { OV511_I2C_BUS, 0x01, 0x80 },
4745 { OV511_I2C_BUS, 0x02, 0x80 },
4746 { OV511_I2C_BUS, 0x03, 0xc0 },
4747 { OV511_I2C_BUS, 0x06, 0x60 },
4748 { OV511_I2C_BUS, 0x07, 0x00 },
4749 { OV511_I2C_BUS, 0x0c, 0x24 },
4750 { OV511_I2C_BUS, 0x0c, 0x24 },
4751 { OV511_I2C_BUS, 0x0d, 0x24 },
4752 { OV511_I2C_BUS, 0x11, 0x01 },
4753 { OV511_I2C_BUS, 0x12, 0x24 },
4754 { OV511_I2C_BUS, 0x13, 0x01 },
4755 { OV511_I2C_BUS, 0x14, 0x84 },
4756 { OV511_I2C_BUS, 0x15, 0x01 },
4757 { OV511_I2C_BUS, 0x16, 0x03 },
4758 { OV511_I2C_BUS, 0x17, 0x2f },
4759 { OV511_I2C_BUS, 0x18, 0xcf },
4760 { OV511_I2C_BUS, 0x19, 0x06 },
4761 { OV511_I2C_BUS, 0x1a, 0xf5 },
4762 { OV511_I2C_BUS, 0x1b, 0x00 },
4763 { OV511_I2C_BUS, 0x20, 0x18 },
4764 { OV511_I2C_BUS, 0x21, 0x80 },
4765 { OV511_I2C_BUS, 0x22, 0x80 },
4766 { OV511_I2C_BUS, 0x23, 0x00 },
4767 { OV511_I2C_BUS, 0x26, 0xa2 },
4768 { OV511_I2C_BUS, 0x27, 0xea },
4769 { OV511_I2C_BUS, 0x28, 0x20 },
4770 { OV511_I2C_BUS, 0x29, 0x00 },
4771 { OV511_I2C_BUS, 0x2a, 0x10 },
4772 { OV511_I2C_BUS, 0x2b, 0x00 },
4773 { OV511_I2C_BUS, 0x2c, 0x88 },
4774 { OV511_I2C_BUS, 0x2d, 0x91 },
4775 { OV511_I2C_BUS, 0x2e, 0x80 },
4776 { OV511_I2C_BUS, 0x2f, 0x44 },
4777 { OV511_I2C_BUS, 0x60, 0x27 },
4778 { OV511_I2C_BUS, 0x61, 0x02 },
4779 { OV511_I2C_BUS, 0x62, 0x5f },
4780 { OV511_I2C_BUS, 0x63, 0xd5 },
4781 { OV511_I2C_BUS, 0x64, 0x57 },
4782 { OV511_I2C_BUS, 0x65, 0x83 },
4783 { OV511_I2C_BUS, 0x66, 0x55 },
4784 { OV511_I2C_BUS, 0x67, 0x92 },
4785 { OV511_I2C_BUS, 0x68, 0xcf },
4786 { OV511_I2C_BUS, 0x69, 0x76 },
4787 { OV511_I2C_BUS, 0x6a, 0x22 },
4788 { OV511_I2C_BUS, 0x6b, 0x00 },
4789 { OV511_I2C_BUS, 0x6c, 0x02 },
4790 { OV511_I2C_BUS, 0x6d, 0x44 },
4791 { OV511_I2C_BUS, 0x6e, 0x80 },
4792 { OV511_I2C_BUS, 0x6f, 0x1d },
4793 { OV511_I2C_BUS, 0x70, 0x8b },
4794 { OV511_I2C_BUS, 0x71, 0x00 },
4795 { OV511_I2C_BUS, 0x72, 0x14 },
4796 { OV511_I2C_BUS, 0x73, 0x54 },
4797 { OV511_I2C_BUS, 0x74, 0x00 },
4798 { OV511_I2C_BUS, 0x75, 0x8e },
4799 { OV511_I2C_BUS, 0x76, 0x00 },
4800 { OV511_I2C_BUS, 0x77, 0xff },
4801 { OV511_I2C_BUS, 0x78, 0x80 },
4802 { OV511_I2C_BUS, 0x79, 0x80 },
4803 { OV511_I2C_BUS, 0x7a, 0x80 },
4804 { OV511_I2C_BUS, 0x7b, 0xe2 },
4805 { OV511_I2C_BUS, 0x7c, 0x00 },
4806 { OV511_DONE_BUS, 0x0, 0x00 },
4809 PDEBUG(4, "starting configuration");
4811 /* This looks redundant, but is necessary for WebCam 3 */
4812 ov->primary_i2c_slave = OV7xx0_SID;
4813 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
4816 if (init_ov_sensor(ov) >= 0) {
4817 PDEBUG(1, "OV7xx0 sensor initalized (method 1)");
4819 /* Reset the 76xx */
4820 if (i2c_w(ov, 0x12, 0x80) < 0)
4823 /* Wait for it to initialize */
4828 while (i <= i2c_detect_tries) {
4829 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
4830 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
4838 // Was (i == i2c_detect_tries) previously. This obviously used to always report
4839 // success. Whether anyone actually depended on that bug is unknown
4840 if ((i >= i2c_detect_tries) && (success == 0)) {
4841 err("Failed to read sensor ID. You might not have an");
4842 err("OV7610/20, or it may be not responding. Report");
4843 err("this to " EMAIL);
4844 err("This is only a warning. You can attempt to use");
4845 err("your camera anyway");
4846 // Only issue a warning for now
4849 PDEBUG(1, "OV7xx0 initialized (method 2, %dx)", i+1);
4853 /* Detect sensor (sub)type */
4854 rc = i2c_r(ov, OV7610_REG_COM_I);
4857 err("Error detecting sensor type");
4859 } else if ((rc & 3) == 3) {
4860 dev_info(&ov->dev->dev, "Sensor is an OV7610\n");
4861 ov->sensor = SEN_OV7610;
4862 } else if ((rc & 3) == 1) {
4863 /* I don't know what's different about the 76BE yet. */
4864 if (i2c_r(ov, 0x15) & 1)
4865 dev_info(&ov->dev->dev, "Sensor is an OV7620AE\n");
4867 dev_info(&ov->dev->dev, "Sensor is an OV76BE\n");
4869 /* OV511+ will return all zero isoc data unless we
4870 * configure the sensor as a 7620. Someone needs to
4871 * find the exact reg. setting that causes this. */
4872 if (ov->bridge == BRG_OV511PLUS) {
4873 dev_info(&ov->dev->dev,
4874 "Enabling 511+/7620AE workaround\n");
4875 ov->sensor = SEN_OV7620;
4877 ov->sensor = SEN_OV76BE;
4879 } else if ((rc & 3) == 0) {
4880 dev_info(&ov->dev->dev, "Sensor is an OV7620\n");
4881 ov->sensor = SEN_OV7620;
4883 err("Unknown image sensor version: %d", rc & 3);
4887 if (ov->sensor == SEN_OV7620) {
4888 PDEBUG(4, "Writing 7620 registers");
4889 if (write_regvals(ov, aRegvalsNorm7620))
4892 PDEBUG(4, "Writing 7610 registers");
4893 if (write_regvals(ov, aRegvalsNorm7610))
4897 /* Set sensor-specific vars */
4899 ov->maxheight = 480;
4903 // FIXME: These do not match the actual settings yet
4904 ov->brightness = 0x80 << 8;
4905 ov->contrast = 0x80 << 8;
4906 ov->colour = 0x80 << 8;
4907 ov->hue = 0x80 << 8;
4912 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
4914 ov6xx0_configure(struct usb_ov511 *ov)
4918 static struct ov511_regvals aRegvalsNorm6x20[] = {
4919 { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
4920 { OV511_I2C_BUS, 0x11, 0x01 },
4921 { OV511_I2C_BUS, 0x03, 0x60 },
4922 { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
4923 { OV511_I2C_BUS, 0x07, 0xa8 },
4924 /* The ratio of 0x0c and 0x0d controls the white point */
4925 { OV511_I2C_BUS, 0x0c, 0x24 },
4926 { OV511_I2C_BUS, 0x0d, 0x24 },
4927 { OV511_I2C_BUS, 0x0f, 0x15 }, /* COMS */
4928 { OV511_I2C_BUS, 0x10, 0x75 }, /* AEC Exposure time */
4929 { OV511_I2C_BUS, 0x12, 0x24 }, /* Enable AGC */
4930 { OV511_I2C_BUS, 0x14, 0x04 },
4931 /* 0x16: 0x06 helps frame stability with moving objects */
4932 { OV511_I2C_BUS, 0x16, 0x06 },
4933 // { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
4934 { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
4935 /* 0x28: 0x05 Selects RGB format if RGB on */
4936 { OV511_I2C_BUS, 0x28, 0x05 },
4937 { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
4938 // { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
4939 { OV511_I2C_BUS, 0x2d, 0x99 },
4940 { OV511_I2C_BUS, 0x33, 0xa0 }, /* Color Processing Parameter */
4941 { OV511_I2C_BUS, 0x34, 0xd2 }, /* Max A/D range */
4942 { OV511_I2C_BUS, 0x38, 0x8b },
4943 { OV511_I2C_BUS, 0x39, 0x40 },
4945 { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
4946 { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
4947 { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
4949 { OV511_I2C_BUS, 0x3d, 0x80 },
4950 /* These next two registers (0x4a, 0x4b) are undocumented. They
4951 * control the color balance */
4952 { OV511_I2C_BUS, 0x4a, 0x80 },
4953 { OV511_I2C_BUS, 0x4b, 0x80 },
4954 { OV511_I2C_BUS, 0x4d, 0xd2 }, /* This reduces noise a bit */
4955 { OV511_I2C_BUS, 0x4e, 0xc1 },
4956 { OV511_I2C_BUS, 0x4f, 0x04 },
4957 // Do 50-53 have any effect?
4958 // Toggle 0x12[2] off and on here?
4959 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
4962 static struct ov511_regvals aRegvalsNorm6x30[] = {
4963 /*OK*/ { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
4964 { OV511_I2C_BUS, 0x11, 0x00 },
4965 /*OK*/ { OV511_I2C_BUS, 0x03, 0x60 },
4966 /*0A?*/ { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
4967 { OV511_I2C_BUS, 0x07, 0xa8 },
4968 /* The ratio of 0x0c and 0x0d controls the white point */
4969 /*OK*/ { OV511_I2C_BUS, 0x0c, 0x24 },
4970 /*OK*/ { OV511_I2C_BUS, 0x0d, 0x24 },
4971 /*A*/ { OV511_I2C_BUS, 0x0e, 0x20 },
4972 // /*04?*/ { OV511_I2C_BUS, 0x14, 0x80 },
4973 { OV511_I2C_BUS, 0x16, 0x03 },
4974 // /*OK*/ { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
4975 // 21 & 22? The suggested values look wrong. Go with default
4976 /*A*/ { OV511_I2C_BUS, 0x23, 0xc0 },
4977 /*A*/ { OV511_I2C_BUS, 0x25, 0x9a }, // Check this against default
4978 // /*OK*/ { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
4980 /* 0x28: 0x05 Selects RGB format if RGB on */
4981 // /*04?*/ { OV511_I2C_BUS, 0x28, 0x05 },
4982 // /*04?*/ { OV511_I2C_BUS, 0x28, 0x45 }, // DEBUG: Tristate UV bus
4984 /*OK*/ { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
4985 // /*OK*/ { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
4986 { OV511_I2C_BUS, 0x2d, 0x99 },
4987 // /*A*/ { OV511_I2C_BUS, 0x33, 0x26 }, // Reserved bits on 6620
4988 // /*d2?*/ { OV511_I2C_BUS, 0x34, 0x03 }, /* Max A/D range */
4989 // /*8b?*/ { OV511_I2C_BUS, 0x38, 0x83 },
4990 // /*40?*/ { OV511_I2C_BUS, 0x39, 0xc0 }, // 6630 adds bit 7
4991 // { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
4992 // { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
4993 // { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
4994 { OV511_I2C_BUS, 0x3d, 0x80 },
4995 // /*A*/ { OV511_I2C_BUS, 0x3f, 0x0e },
4997 /* These next two registers (0x4a, 0x4b) are undocumented. They
4998 * control the color balance */
4999 // /*OK?*/ { OV511_I2C_BUS, 0x4a, 0x80 }, // Check these
5000 // /*OK?*/ { OV511_I2C_BUS, 0x4b, 0x80 },
5001 { OV511_I2C_BUS, 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
5002 /*c1?*/ { OV511_I2C_BUS, 0x4e, 0x40 },
5004 /* UV average mode, color killer: strongest */
5005 { OV511_I2C_BUS, 0x4f, 0x07 },
5007 { OV511_I2C_BUS, 0x54, 0x23 }, /* Max AGC gain: 18dB */
5008 { OV511_I2C_BUS, 0x57, 0x81 }, /* (default) */
5009 { OV511_I2C_BUS, 0x59, 0x01 }, /* AGC dark current comp: +1 */
5010 { OV511_I2C_BUS, 0x5a, 0x2c }, /* (undocumented) */
5011 { OV511_I2C_BUS, 0x5b, 0x0f }, /* AWB chrominance levels */
5012 // { OV511_I2C_BUS, 0x5c, 0x10 },
5013 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
5016 PDEBUG(4, "starting sensor configuration");
5018 if (init_ov_sensor(ov) < 0) {
5019 err("Failed to read sensor ID. You might not have an OV6xx0,");
5020 err("or it may be not responding. Report this to " EMAIL);
5023 PDEBUG(1, "OV6xx0 sensor detected");
5026 /* Detect sensor (sub)type */
5027 rc = i2c_r(ov, OV7610_REG_COM_I);
5030 err("Error detecting sensor type");
5034 if ((rc & 3) == 0) {
5035 ov->sensor = SEN_OV6630;
5036 dev_info(&ov->dev->dev, "Sensor is an OV6630\n");
5037 } else if ((rc & 3) == 1) {
5038 ov->sensor = SEN_OV6620;
5039 dev_info(&ov->dev->dev, "Sensor is an OV6620\n");
5040 } else if ((rc & 3) == 2) {
5041 ov->sensor = SEN_OV6630;
5042 dev_info(&ov->dev->dev, "Sensor is an OV6630AE\n");
5043 } else if ((rc & 3) == 3) {
5044 ov->sensor = SEN_OV6630;
5045 dev_info(&ov->dev->dev, "Sensor is an OV6630AF\n");
5048 /* Set sensor-specific vars */
5050 ov->maxheight = 288;
5054 // FIXME: These do not match the actual settings yet
5055 ov->brightness = 0x80 << 8;
5056 ov->contrast = 0x80 << 8;
5057 ov->colour = 0x80 << 8;
5058 ov->hue = 0x80 << 8;
5060 if (ov->sensor == SEN_OV6620) {
5061 PDEBUG(4, "Writing 6x20 registers");
5062 if (write_regvals(ov, aRegvalsNorm6x20))
5065 PDEBUG(4, "Writing 6x30 registers");
5066 if (write_regvals(ov, aRegvalsNorm6x30))
5073 /* This initializes the KS0127 and KS0127B video decoders. */
5075 ks0127_configure(struct usb_ov511 *ov)
5079 // FIXME: I don't know how to sync or reset it yet
5081 if (ov51x_init_ks_sensor(ov) < 0) {
5082 err("Failed to initialize the KS0127");
5085 PDEBUG(1, "KS012x(B) sensor detected");
5089 /* Detect decoder subtype */
5090 rc = i2c_r(ov, 0x00);
5092 err("Error detecting sensor type");
5094 } else if (rc & 0x08) {
5095 rc = i2c_r(ov, 0x3d);
5097 err("Error detecting sensor type");
5099 } else if ((rc & 0x0f) == 0) {
5100 dev_info(&ov->dev->dev, "Sensor is a KS0127\n");
5101 ov->sensor = SEN_KS0127;
5102 } else if ((rc & 0x0f) == 9) {
5103 dev_info(&ov->dev->dev, "Sensor is a KS0127B Rev. A\n");
5104 ov->sensor = SEN_KS0127B;
5107 err("Error: Sensor is an unsupported KS0122");
5111 /* Set sensor-specific vars */
5113 ov->maxheight = 480;
5117 // FIXME: These do not match the actual settings yet
5118 ov->brightness = 0x80 << 8;
5119 ov->contrast = 0x80 << 8;
5120 ov->colour = 0x80 << 8;
5121 ov->hue = 0x80 << 8;
5123 /* This device is not supported yet. Bail out now... */
5124 err("This sensor is not supported yet.");
5130 /* This initializes the SAA7111A video decoder. */
5132 saa7111a_configure(struct usb_ov511 *ov)
5136 /* Since there is no register reset command, all registers must be
5137 * written, otherwise gives erratic results */
5138 static struct ov511_regvals aRegvalsNormSAA7111A[] = {
5139 { OV511_I2C_BUS, 0x06, 0xce },
5140 { OV511_I2C_BUS, 0x07, 0x00 },
5141 { OV511_I2C_BUS, 0x10, 0x44 }, /* YUV422, 240/286 lines */
5142 { OV511_I2C_BUS, 0x0e, 0x01 }, /* NTSC M or PAL BGHI */
5143 { OV511_I2C_BUS, 0x00, 0x00 },
5144 { OV511_I2C_BUS, 0x01, 0x00 },
5145 { OV511_I2C_BUS, 0x03, 0x23 },
5146 { OV511_I2C_BUS, 0x04, 0x00 },
5147 { OV511_I2C_BUS, 0x05, 0x00 },
5148 { OV511_I2C_BUS, 0x08, 0xc8 }, /* Auto field freq */
5149 { OV511_I2C_BUS, 0x09, 0x01 }, /* Chrom. trap off, APER=0.25 */
5150 { OV511_I2C_BUS, 0x0a, 0x80 }, /* BRIG=128 */
5151 { OV511_I2C_BUS, 0x0b, 0x40 }, /* CONT=1.0 */
5152 { OV511_I2C_BUS, 0x0c, 0x40 }, /* SATN=1.0 */
5153 { OV511_I2C_BUS, 0x0d, 0x00 }, /* HUE=0 */
5154 { OV511_I2C_BUS, 0x0f, 0x00 },
5155 { OV511_I2C_BUS, 0x11, 0x0c },
5156 { OV511_I2C_BUS, 0x12, 0x00 },
5157 { OV511_I2C_BUS, 0x13, 0x00 },
5158 { OV511_I2C_BUS, 0x14, 0x00 },
5159 { OV511_I2C_BUS, 0x15, 0x00 },
5160 { OV511_I2C_BUS, 0x16, 0x00 },
5161 { OV511_I2C_BUS, 0x17, 0x00 },
5162 { OV511_I2C_BUS, 0x02, 0xc0 }, /* Composite input 0 */
5163 { OV511_DONE_BUS, 0x0, 0x00 },
5166 // FIXME: I don't know how to sync or reset it yet
5168 if (ov51x_init_saa_sensor(ov) < 0) {
5169 err("Failed to initialize the SAA7111A");
5172 PDEBUG(1, "SAA7111A sensor detected");
5176 /* 640x480 not supported with PAL */
5179 ov->maxheight = 240; /* Even field only */
5182 ov->maxheight = 480; /* Even/Odd fields */
5186 ov->minheight = 240; /* Even field only */
5188 ov->has_decoder = 1;
5190 ov->norm = VIDEO_MODE_AUTO;
5191 ov->stop_during_set = 0; /* Decoder guarantees stable image */
5193 /* Decoder doesn't change these values, so we use these instead of
5194 * acutally reading the registers (which doesn't work) */
5195 ov->brightness = 0x80 << 8;
5196 ov->contrast = 0x40 << 9;
5197 ov->colour = 0x40 << 9;
5200 PDEBUG(4, "Writing SAA7111A registers");
5201 if (write_regvals(ov, aRegvalsNormSAA7111A))
5204 /* Detect version of decoder. This must be done after writing the
5205 * initial regs or the decoder will lock up. */
5206 rc = i2c_r(ov, 0x00);
5209 err("Error detecting sensor version");
5212 dev_info(&ov->dev->dev,
5213 "Sensor is an SAA7111A (version 0x%x)\n", rc);
5214 ov->sensor = SEN_SAA7111A;
5217 // FIXME: Fix this for OV518(+)
5218 /* Latch to negative edge of clock. Otherwise, we get incorrect
5219 * colors and jitter in the digital signal. */
5220 if (ov->bclass == BCL_OV511)
5221 reg_w(ov, 0x11, 0x00);
5223 dev_warn(&ov->dev->dev,
5224 "SAA7111A not yet supported with OV518/OV518+\n");
5229 /* This initializes the OV511/OV511+ and the sensor */
5231 ov511_configure(struct usb_ov511 *ov)
5233 static struct ov511_regvals aRegvalsInit511[] = {
5234 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5235 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5236 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5237 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5238 { OV511_REG_BUS, R51x_SYS_RESET, 0x3f },
5239 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5240 { OV511_REG_BUS, R51x_SYS_RESET, 0x3d },
5241 { OV511_DONE_BUS, 0x0, 0x00},
5244 static struct ov511_regvals aRegvalsNorm511[] = {
5245 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0x01 },
5246 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5247 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5248 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5249 { OV511_REG_BUS, R511_FIFO_OPTS, 0x1f },
5250 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5251 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5252 { OV511_DONE_BUS, 0x0, 0x00 },
5255 static struct ov511_regvals aRegvalsNorm511Plus[] = {
5256 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0xff },
5257 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5258 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5259 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5260 { OV511_REG_BUS, R511_FIFO_OPTS, 0xff },
5261 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5262 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5263 { OV511_DONE_BUS, 0x0, 0x00 },
5268 ov->customid = reg_r(ov, R511_SYS_CUST_ID);
5269 if (ov->customid < 0) {
5270 err("Unable to read camera bridge registers");
5274 PDEBUG (1, "CustomID = %d", ov->customid);
5275 ov->desc = symbolic(camlist, ov->customid);
5276 dev_info(&ov->dev->dev, "model: %s\n", ov->desc);
5278 if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) {
5279 err("Camera type (%d) not recognized", ov->customid);
5280 err("Please notify " EMAIL " of the name,");
5281 err("manufacturer, model, and this number of your camera.");
5282 err("Also include the output of the detection process.");
5285 if (ov->customid == 70) /* USB Life TV (PAL/SECAM) */
5288 if (write_regvals(ov, aRegvalsInit511))
5291 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5292 ov51x_led_control(ov, 0);
5294 /* The OV511+ has undocumented bits in the flow control register.
5295 * Setting it to 0xff fixes the corruption with moving objects. */
5296 if (ov->bridge == BRG_OV511) {
5297 if (write_regvals(ov, aRegvalsNorm511))
5299 } else if (ov->bridge == BRG_OV511PLUS) {
5300 if (write_regvals(ov, aRegvalsNorm511Plus))
5303 err("Invalid bridge");
5306 if (ov511_init_compression(ov))
5309 ov->packet_numbering = 1;
5310 ov511_set_packet_size(ov, 0);
5312 ov->snap_enabled = snapshot;
5315 PDEBUG(3, "Testing for 0V7xx0");
5316 ov->primary_i2c_slave = OV7xx0_SID;
5317 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5320 if (i2c_w(ov, 0x12, 0x80) < 0) {
5322 PDEBUG(3, "Testing for 0V6xx0");
5323 ov->primary_i2c_slave = OV6xx0_SID;
5324 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5327 if (i2c_w(ov, 0x12, 0x80) < 0) {
5329 PDEBUG(3, "Testing for 0V8xx0");
5330 ov->primary_i2c_slave = OV8xx0_SID;
5331 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5334 if (i2c_w(ov, 0x12, 0x80) < 0) {
5335 /* Test for SAA7111A */
5336 PDEBUG(3, "Testing for SAA7111A");
5337 ov->primary_i2c_slave = SAA7111A_SID;
5338 if (ov51x_set_slave_ids(ov, SAA7111A_SID) < 0)
5341 if (i2c_w(ov, 0x0d, 0x00) < 0) {
5342 /* Test for KS0127 */
5343 PDEBUG(3, "Testing for KS0127");
5344 ov->primary_i2c_slave = KS0127_SID;
5345 if (ov51x_set_slave_ids(ov, KS0127_SID) < 0)
5348 if (i2c_w(ov, 0x10, 0x00) < 0) {
5349 err("Can't determine sensor slave IDs");
5352 if (ks0127_configure(ov) < 0) {
5353 err("Failed to configure KS0127");
5358 if (saa7111a_configure(ov) < 0) {
5359 err("Failed to configure SAA7111A");
5364 err("Detected unsupported OV8xx0 sensor");
5368 if (ov6xx0_configure(ov) < 0) {
5369 err("Failed to configure OV6xx0");
5374 if (ov7xx0_configure(ov) < 0) {
5375 err("Failed to configure OV7xx0");
5383 err("OV511 Config failed");
5388 /* This initializes the OV518/OV518+ and the sensor */
5390 ov518_configure(struct usb_ov511 *ov)
5392 /* For 518 and 518+ */
5393 static struct ov511_regvals aRegvalsInit518[] = {
5394 { OV511_REG_BUS, R51x_SYS_RESET, 0x40 },
5395 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5396 { OV511_REG_BUS, R51x_SYS_RESET, 0x3e },
5397 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5398 { OV511_REG_BUS, R51x_SYS_RESET, 0x00 },
5399 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5400 { OV511_REG_BUS, 0x46, 0x00 },
5401 { OV511_REG_BUS, 0x5d, 0x03 },
5402 { OV511_DONE_BUS, 0x0, 0x00},
5405 static struct ov511_regvals aRegvalsNorm518[] = {
5406 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5407 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5408 { OV511_REG_BUS, 0x31, 0x0f },
5409 { OV511_REG_BUS, 0x5d, 0x03 },
5410 { OV511_REG_BUS, 0x24, 0x9f },
5411 { OV511_REG_BUS, 0x25, 0x90 },
5412 { OV511_REG_BUS, 0x20, 0x00 },
5413 { OV511_REG_BUS, 0x51, 0x04 },
5414 { OV511_REG_BUS, 0x71, 0x19 },
5415 { OV511_DONE_BUS, 0x0, 0x00 },
5418 static struct ov511_regvals aRegvalsNorm518Plus[] = {
5419 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5420 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5421 { OV511_REG_BUS, 0x31, 0x0f },
5422 { OV511_REG_BUS, 0x5d, 0x03 },
5423 { OV511_REG_BUS, 0x24, 0x9f },
5424 { OV511_REG_BUS, 0x25, 0x90 },
5425 { OV511_REG_BUS, 0x20, 0x60 },
5426 { OV511_REG_BUS, 0x51, 0x02 },
5427 { OV511_REG_BUS, 0x71, 0x19 },
5428 { OV511_REG_BUS, 0x40, 0xff },
5429 { OV511_REG_BUS, 0x41, 0x42 },
5430 { OV511_REG_BUS, 0x46, 0x00 },
5431 { OV511_REG_BUS, 0x33, 0x04 },
5432 { OV511_REG_BUS, 0x21, 0x19 },
5433 { OV511_REG_BUS, 0x3f, 0x10 },
5434 { OV511_DONE_BUS, 0x0, 0x00 },
5439 /* First 5 bits of custom ID reg are a revision ID on OV518 */
5440 dev_info(&ov->dev->dev, "Device revision %d\n",
5441 0x1F & reg_r(ov, R511_SYS_CUST_ID));
5443 /* Give it the default description */
5444 ov->desc = symbolic(camlist, 0);
5446 if (write_regvals(ov, aRegvalsInit518))
5449 /* Set LED GPIO pin to output mode */
5450 if (reg_w_mask(ov, 0x57, 0x00, 0x02) < 0)
5453 /* LED is off by default with OV518; have to explicitly turn it on */
5454 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5455 ov51x_led_control(ov, 0);
5457 ov51x_led_control(ov, 1);
5459 /* Don't require compression if dumppix is enabled; otherwise it's
5460 * required. OV518 has no uncompressed mode, to save RAM. */
5461 if (!dumppix && !ov->compress) {
5463 dev_warn(&ov->dev->dev,
5464 "Compression required with OV518...enabling\n");
5467 if (ov->bridge == BRG_OV518) {
5468 if (write_regvals(ov, aRegvalsNorm518))
5470 } else if (ov->bridge == BRG_OV518PLUS) {
5471 if (write_regvals(ov, aRegvalsNorm518Plus))
5474 err("Invalid bridge");
5477 if (reg_w(ov, 0x2f, 0x80) < 0)
5480 if (ov518_init_compression(ov))
5483 if (ov->bridge == BRG_OV518)
5485 struct usb_interface *ifp;
5486 struct usb_host_interface *alt;
5489 ifp = usb_ifnum_to_if(ov->dev, 0);
5491 alt = usb_altnum_to_altsetting(ifp, 7);
5493 mxps = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
5496 /* Some OV518s have packet numbering by default, some don't */
5498 ov->packet_numbering = 1;
5500 ov->packet_numbering = 0;
5502 /* OV518+ has packet numbering turned on by default */
5503 ov->packet_numbering = 1;
5506 ov518_set_packet_size(ov, 0);
5508 ov->snap_enabled = snapshot;
5511 ov->primary_i2c_slave = OV7xx0_SID;
5512 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5515 /* The OV518 must be more aggressive about sensor detection since
5516 * I2C write will never fail if the sensor is not present. We have
5517 * to try to initialize the sensor to detect its presence */
5519 if (init_ov_sensor(ov) < 0) {
5521 ov->primary_i2c_slave = OV6xx0_SID;
5522 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5525 if (init_ov_sensor(ov) < 0) {
5527 ov->primary_i2c_slave = OV8xx0_SID;
5528 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5531 if (init_ov_sensor(ov) < 0) {
5532 err("Can't determine sensor slave IDs");
5535 err("Detected unsupported OV8xx0 sensor");
5539 if (ov6xx0_configure(ov) < 0) {
5540 err("Failed to configure OV6xx0");
5545 if (ov7xx0_configure(ov) < 0) {
5546 err("Failed to configure OV7xx0");
5552 ov->maxheight = 288;
5554 // The OV518 cannot go as low as the sensor can
5556 ov->minheight = 120;
5561 err("OV518 Config failed");
5566 /****************************************************************************
5568 ***************************************************************************/
5570 static inline struct usb_ov511 *cd_to_ov(struct device *cd)
5572 struct video_device *vdev = to_video_device(cd);
5573 return video_get_drvdata(vdev);
5576 static ssize_t show_custom_id(struct device *cd,
5577 struct device_attribute *attr, char *buf)
5579 struct usb_ov511 *ov = cd_to_ov(cd);
5580 return sprintf(buf, "%d\n", ov->customid);
5582 static DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
5584 static ssize_t show_model(struct device *cd,
5585 struct device_attribute *attr, char *buf)
5587 struct usb_ov511 *ov = cd_to_ov(cd);
5588 return sprintf(buf, "%s\n", ov->desc);
5590 static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
5592 static ssize_t show_bridge(struct device *cd,
5593 struct device_attribute *attr, char *buf)
5595 struct usb_ov511 *ov = cd_to_ov(cd);
5596 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
5598 static DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
5600 static ssize_t show_sensor(struct device *cd,
5601 struct device_attribute *attr, char *buf)
5603 struct usb_ov511 *ov = cd_to_ov(cd);
5604 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
5606 static DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
5608 static ssize_t show_brightness(struct device *cd,
5609 struct device_attribute *attr, char *buf)
5611 struct usb_ov511 *ov = cd_to_ov(cd);
5616 sensor_get_brightness(ov, &x);
5617 return sprintf(buf, "%d\n", x >> 8);
5619 static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
5621 static ssize_t show_saturation(struct device *cd,
5622 struct device_attribute *attr, char *buf)
5624 struct usb_ov511 *ov = cd_to_ov(cd);
5629 sensor_get_saturation(ov, &x);
5630 return sprintf(buf, "%d\n", x >> 8);
5632 static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
5634 static ssize_t show_contrast(struct device *cd,
5635 struct device_attribute *attr, char *buf)
5637 struct usb_ov511 *ov = cd_to_ov(cd);
5642 sensor_get_contrast(ov, &x);
5643 return sprintf(buf, "%d\n", x >> 8);
5645 static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
5647 static ssize_t show_hue(struct device *cd,
5648 struct device_attribute *attr, char *buf)
5650 struct usb_ov511 *ov = cd_to_ov(cd);
5655 sensor_get_hue(ov, &x);
5656 return sprintf(buf, "%d\n", x >> 8);
5658 static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5660 static ssize_t show_exposure(struct device *cd,
5661 struct device_attribute *attr, char *buf)
5663 struct usb_ov511 *ov = cd_to_ov(cd);
5664 unsigned char exp = 0;
5668 sensor_get_exposure(ov, &exp);
5669 return sprintf(buf, "%d\n", exp);
5671 static DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
5673 static int ov_create_sysfs(struct video_device *vdev)
5677 rc = device_create_file(&vdev->dev, &dev_attr_custom_id);
5679 rc = device_create_file(&vdev->dev, &dev_attr_model);
5680 if (rc) goto err_id;
5681 rc = device_create_file(&vdev->dev, &dev_attr_bridge);
5682 if (rc) goto err_model;
5683 rc = device_create_file(&vdev->dev, &dev_attr_sensor);
5684 if (rc) goto err_bridge;
5685 rc = device_create_file(&vdev->dev, &dev_attr_brightness);
5686 if (rc) goto err_sensor;
5687 rc = device_create_file(&vdev->dev, &dev_attr_saturation);
5688 if (rc) goto err_bright;
5689 rc = device_create_file(&vdev->dev, &dev_attr_contrast);
5690 if (rc) goto err_sat;
5691 rc = device_create_file(&vdev->dev, &dev_attr_hue);
5692 if (rc) goto err_contrast;
5693 rc = device_create_file(&vdev->dev, &dev_attr_exposure);
5694 if (rc) goto err_hue;
5699 device_remove_file(&vdev->dev, &dev_attr_hue);
5701 device_remove_file(&vdev->dev, &dev_attr_contrast);
5703 device_remove_file(&vdev->dev, &dev_attr_saturation);
5705 device_remove_file(&vdev->dev, &dev_attr_brightness);
5707 device_remove_file(&vdev->dev, &dev_attr_sensor);
5709 device_remove_file(&vdev->dev, &dev_attr_bridge);
5711 device_remove_file(&vdev->dev, &dev_attr_model);
5713 device_remove_file(&vdev->dev, &dev_attr_custom_id);
5718 /****************************************************************************
5720 ***************************************************************************/
5723 ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5725 struct usb_device *dev = interface_to_usbdev(intf);
5726 struct usb_interface_descriptor *idesc;
5727 struct usb_ov511 *ov;
5730 PDEBUG(1, "probing for device...");
5732 /* We don't handle multi-config cameras */
5733 if (dev->descriptor.bNumConfigurations != 1)
5736 idesc = &intf->cur_altsetting->desc;
5738 if (idesc->bInterfaceClass != 0xFF)
5740 if (idesc->bInterfaceSubClass != 0x00)
5743 if ((ov = kzalloc(sizeof(*ov), GFP_KERNEL)) == NULL) {
5744 err("couldn't kmalloc ov struct");
5749 ov->iface = idesc->bInterfaceNumber;
5750 ov->led_policy = led;
5751 ov->compress = compress;
5752 ov->lightfreq = lightfreq;
5753 ov->num_inputs = 1; /* Video decoder init functs. change this */
5754 ov->stop_during_set = !fastset;
5755 ov->backlight = backlight;
5756 ov->mirror = mirror;
5757 ov->auto_brt = autobright;
5758 ov->auto_gain = autogain;
5759 ov->auto_exp = autoexp;
5761 switch (le16_to_cpu(dev->descriptor.idProduct)) {
5763 ov->bridge = BRG_OV511;
5764 ov->bclass = BCL_OV511;
5766 case PROD_OV511PLUS:
5767 ov->bridge = BRG_OV511PLUS;
5768 ov->bclass = BCL_OV511;
5771 ov->bridge = BRG_OV518;
5772 ov->bclass = BCL_OV518;
5774 case PROD_OV518PLUS:
5775 ov->bridge = BRG_OV518PLUS;
5776 ov->bclass = BCL_OV518;
5779 if (le16_to_cpu(dev->descriptor.idVendor) != VEND_MATTEL)
5781 ov->bridge = BRG_OV511PLUS;
5782 ov->bclass = BCL_OV511;
5785 err("Unknown product ID 0x%04x", le16_to_cpu(dev->descriptor.idProduct));
5789 dev_info(&intf->dev, "USB %s video device found\n",
5790 symbolic(brglist, ov->bridge));
5792 init_waitqueue_head(&ov->wq);
5794 mutex_init(&ov->lock); /* to 1 == available */
5795 mutex_init(&ov->buf_lock);
5796 mutex_init(&ov->i2c_lock);
5797 mutex_init(&ov->cbuf_lock);
5799 ov->buf_state = BUF_NOT_ALLOCATED;
5801 if (usb_make_path(dev, ov->usb_path, OV511_USB_PATH_LEN) < 0) {
5802 err("usb_make_path error");
5806 /* Allocate control transfer buffer. */
5807 /* Must be kmalloc()'ed, for DMA compatibility */
5808 ov->cbuf = kmalloc(OV511_CBUF_SIZE, GFP_KERNEL);
5812 if (ov->bclass == BCL_OV518) {
5813 if (ov518_configure(ov) < 0)
5816 if (ov511_configure(ov) < 0)
5820 for (i = 0; i < OV511_NUMFRAMES; i++) {
5821 ov->frame[i].framenum = i;
5822 init_waitqueue_head(&ov->frame[i].wq);
5825 for (i = 0; i < OV511_NUMSBUF; i++) {
5826 ov->sbuf[i].ov = ov;
5827 spin_lock_init(&ov->sbuf[i].lock);
5831 /* Unnecessary? (This is done on open(). Need to make sure variables
5832 * are properly initialized without this before removing it, though). */
5833 if (ov51x_set_default_params(ov) < 0)
5838 if (ov->bclass == BCL_OV511)
5839 ov511_dump_regs(ov);
5841 ov518_dump_regs(ov);
5845 ov->vdev = video_device_alloc();
5849 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
5850 ov->vdev->parent = &intf->dev;
5851 video_set_drvdata(ov->vdev, ov);
5853 for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) {
5854 /* Minor 0 cannot be specified; assume user wants autodetect */
5855 if (unit_video[i] == 0)
5858 if (video_register_device(ov->vdev, VFL_TYPE_GRABBER,
5859 unit_video[i]) >= 0) {
5864 /* Use the next available one */
5865 if ((ov->vdev->minor == -1) &&
5866 video_register_device(ov->vdev, VFL_TYPE_GRABBER, -1) < 0) {
5867 err("video_register_device failed");
5871 dev_info(&intf->dev, "Device at %s registered to minor %d\n",
5872 ov->usb_path, ov->vdev->minor);
5874 usb_set_intfdata(intf, ov);
5875 if (ov_create_sysfs(ov->vdev)) {
5876 err("ov_create_sysfs failed");
5884 if (-1 == ov->vdev->minor)
5885 video_device_release(ov->vdev);
5887 video_unregister_device(ov->vdev);
5892 mutex_lock(&ov->cbuf_lock);
5895 mutex_unlock(&ov->cbuf_lock);
5902 err("Camera initialization failed");
5907 ov51x_disconnect(struct usb_interface *intf)
5909 struct usb_ov511 *ov = usb_get_intfdata(intf);
5914 usb_set_intfdata (intf, NULL);
5920 video_unregister_device(ov->vdev);
5922 for (n = 0; n < OV511_NUMFRAMES; n++)
5923 ov->frame[n].grabstate = FRAME_ERROR;
5927 /* This will cause the process to request another frame */
5928 for (n = 0; n < OV511_NUMFRAMES; n++)
5929 wake_up_interruptible(&ov->frame[n].wq);
5931 wake_up_interruptible(&ov->wq);
5934 ov51x_unlink_isoc(ov);
5938 /* Free the memory */
5939 if (ov && !ov->user) {
5940 mutex_lock(&ov->cbuf_lock);
5943 mutex_unlock(&ov->cbuf_lock);
5950 PDEBUG(3, "Disconnect complete");
5953 static struct usb_driver ov511_driver = {
5955 .id_table = device_table,
5956 .probe = ov51x_probe,
5957 .disconnect = ov51x_disconnect
5960 /****************************************************************************
5964 ***************************************************************************/
5967 usb_ov511_init(void)
5971 retval = usb_register(&ov511_driver);
5975 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
5983 usb_ov511_exit(void)
5985 usb_deregister(&ov511_driver);
5986 printk(KERN_INFO KBUILD_MODNAME ": driver deregistered\n");
5989 module_init(usb_ov511_init);
5990 module_exit(usb_ov511_exit);