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 /* Bitmask marking allocated devices from 0 to OV511_MAX_UNIT_VIDEO */
116 static unsigned long ov511_devused;
117 static int unit_video[OV511_MAX_UNIT_VIDEO];
118 static int remove_zeros;
120 static int ov518_color;
122 module_param(autobright, int, 0);
123 MODULE_PARM_DESC(autobright, "Sensor automatically changes brightness");
124 module_param(autogain, int, 0);
125 MODULE_PARM_DESC(autogain, "Sensor automatically changes gain");
126 module_param(autoexp, int, 0);
127 MODULE_PARM_DESC(autoexp, "Sensor automatically changes exposure");
128 module_param(debug, int, 0);
129 MODULE_PARM_DESC(debug,
130 "Debug level: 0=none, 1=inits, 2=warning, 3=config, 4=functions, 5=max");
131 module_param(snapshot, int, 0);
132 MODULE_PARM_DESC(snapshot, "Enable snapshot mode");
133 module_param(cams, int, 0);
134 MODULE_PARM_DESC(cams, "Number of simultaneous cameras");
135 module_param(compress, int, 0);
136 MODULE_PARM_DESC(compress, "Turn on compression");
137 module_param(testpat, int, 0);
138 MODULE_PARM_DESC(testpat,
139 "Replace image with vertical bar testpattern (only partially working)");
140 module_param(dumppix, int, 0);
141 MODULE_PARM_DESC(dumppix, "Dump raw pixel data");
142 module_param(led, int, 0);
143 MODULE_PARM_DESC(led,
144 "LED policy (OV511+ or later). 0=off, 1=on (default), 2=auto (on when open)");
145 module_param(dump_bridge, int, 0);
146 MODULE_PARM_DESC(dump_bridge, "Dump the bridge registers");
147 module_param(dump_sensor, int, 0);
148 MODULE_PARM_DESC(dump_sensor, "Dump the sensor registers");
149 module_param(printph, int, 0);
150 MODULE_PARM_DESC(printph, "Print frame start/end headers");
151 module_param(phy, int, 0);
152 MODULE_PARM_DESC(phy, "Prediction range (horiz. Y)");
153 module_param(phuv, int, 0);
154 MODULE_PARM_DESC(phuv, "Prediction range (horiz. UV)");
155 module_param(pvy, int, 0);
156 MODULE_PARM_DESC(pvy, "Prediction range (vert. Y)");
157 module_param(pvuv, int, 0);
158 MODULE_PARM_DESC(pvuv, "Prediction range (vert. UV)");
159 module_param(qhy, int, 0);
160 MODULE_PARM_DESC(qhy, "Quantization threshold (horiz. Y)");
161 module_param(qhuv, int, 0);
162 MODULE_PARM_DESC(qhuv, "Quantization threshold (horiz. UV)");
163 module_param(qvy, int, 0);
164 MODULE_PARM_DESC(qvy, "Quantization threshold (vert. Y)");
165 module_param(qvuv, int, 0);
166 MODULE_PARM_DESC(qvuv, "Quantization threshold (vert. UV)");
167 module_param(lightfreq, int, 0);
168 MODULE_PARM_DESC(lightfreq,
169 "Light frequency. Set to 50 or 60 Hz, or zero for default settings");
170 module_param(bandingfilter, int, 0);
171 MODULE_PARM_DESC(bandingfilter,
172 "Enable banding filter (to reduce effects of fluorescent lighting)");
173 module_param(clockdiv, int, 0);
174 MODULE_PARM_DESC(clockdiv, "Force pixel clock divisor to a specific value");
175 module_param(packetsize, int, 0);
176 MODULE_PARM_DESC(packetsize, "Force a specific isoc packet size");
177 module_param(framedrop, int, 0);
178 MODULE_PARM_DESC(framedrop, "Force a specific frame drop register setting");
179 module_param(fastset, int, 0);
180 MODULE_PARM_DESC(fastset, "Allows picture settings to take effect immediately");
181 module_param(force_palette, int, 0);
182 MODULE_PARM_DESC(force_palette, "Force the palette to a specific value");
183 module_param(backlight, int, 0);
184 MODULE_PARM_DESC(backlight, "For objects that are lit from behind");
185 static unsigned int num_uv;
186 module_param_array(unit_video, int, &num_uv, 0);
187 MODULE_PARM_DESC(unit_video,
188 "Force use of specific minor number(s). 0 is not allowed.");
189 module_param(remove_zeros, int, 0);
190 MODULE_PARM_DESC(remove_zeros,
191 "Remove zero-padding from uncompressed incoming data");
192 module_param(mirror, int, 0);
193 MODULE_PARM_DESC(mirror, "Reverse image horizontally");
194 module_param(ov518_color, int, 0);
195 MODULE_PARM_DESC(ov518_color, "Enable OV518 color (experimental)");
197 MODULE_AUTHOR(DRIVER_AUTHOR);
198 MODULE_DESCRIPTION(DRIVER_DESC);
199 MODULE_LICENSE("GPL");
201 /**********************************************************************
202 * Miscellaneous Globals
203 **********************************************************************/
205 static struct usb_driver ov511_driver;
207 /* Number of times to retry a failed I2C transaction. Increase this if you
208 * are getting "Failed to read sensor ID..." */
209 static const int i2c_detect_tries = 5;
211 static struct usb_device_id device_table [] = {
212 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511) },
213 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511PLUS) },
214 { USB_DEVICE(VEND_OMNIVISION, PROD_OV518) },
215 { USB_DEVICE(VEND_OMNIVISION, PROD_OV518PLUS) },
216 { USB_DEVICE(VEND_MATTEL, PROD_ME2CAM) },
217 { } /* Terminating entry */
220 MODULE_DEVICE_TABLE (usb, device_table);
222 static unsigned char yQuanTable511[] = OV511_YQUANTABLE;
223 static unsigned char uvQuanTable511[] = OV511_UVQUANTABLE;
224 static unsigned char yQuanTable518[] = OV518_YQUANTABLE;
225 static unsigned char uvQuanTable518[] = OV518_UVQUANTABLE;
227 /**********************************************************************
229 **********************************************************************/
231 /* Known OV511-based cameras */
232 static struct symbolic_list camlist[] = {
233 { 0, "Generic Camera (no ID)" },
234 { 1, "Mustek WCam 3X" },
235 { 3, "D-Link DSB-C300" },
236 { 4, "Generic OV511/OV7610" },
237 { 5, "Puretek PT-6007" },
238 { 6, "Lifeview USB Life TV (NTSC)" },
239 { 21, "Creative Labs WebCam 3" },
240 { 22, "Lifeview USB Life TV (PAL D/K+B/G)" },
242 { 38, "Lifeview USB Life TV (PAL)" },
243 { 41, "Samsung Anycam MPC-M10" },
244 { 43, "Mtekvision Zeca MV402" },
246 { 70, "Lifeview USB Life TV (PAL/SECAM)" },
247 { 100, "Lifeview RoboCam" },
248 { 102, "AverMedia InterCam Elite" },
249 { 112, "MediaForte MV300" }, /* or OV7110 evaluation kit */
250 { 134, "Ezonics EZCam II" },
251 { 192, "Webeye 2000B" },
252 { 253, "Alpha Vision Tech. AlphaCam SE" },
256 /* Video4Linux1 Palettes */
257 static struct symbolic_list v4l1_plist[] = {
258 { VIDEO_PALETTE_GREY, "GREY" },
259 { VIDEO_PALETTE_HI240, "HI240" },
260 { VIDEO_PALETTE_RGB565, "RGB565" },
261 { VIDEO_PALETTE_RGB24, "RGB24" },
262 { VIDEO_PALETTE_RGB32, "RGB32" },
263 { VIDEO_PALETTE_RGB555, "RGB555" },
264 { VIDEO_PALETTE_YUV422, "YUV422" },
265 { VIDEO_PALETTE_YUYV, "YUYV" },
266 { VIDEO_PALETTE_UYVY, "UYVY" },
267 { VIDEO_PALETTE_YUV420, "YUV420" },
268 { VIDEO_PALETTE_YUV411, "YUV411" },
269 { VIDEO_PALETTE_RAW, "RAW" },
270 { VIDEO_PALETTE_YUV422P,"YUV422P" },
271 { VIDEO_PALETTE_YUV411P,"YUV411P" },
272 { VIDEO_PALETTE_YUV420P,"YUV420P" },
273 { VIDEO_PALETTE_YUV410P,"YUV410P" },
277 static struct symbolic_list brglist[] = {
278 { BRG_OV511, "OV511" },
279 { BRG_OV511PLUS, "OV511+" },
280 { BRG_OV518, "OV518" },
281 { BRG_OV518PLUS, "OV518+" },
285 static struct symbolic_list senlist[] = {
286 { SEN_OV76BE, "OV76BE" },
287 { SEN_OV7610, "OV7610" },
288 { SEN_OV7620, "OV7620" },
289 { SEN_OV7620AE, "OV7620AE" },
290 { SEN_OV6620, "OV6620" },
291 { SEN_OV6630, "OV6630" },
292 { SEN_OV6630AE, "OV6630AE" },
293 { SEN_OV6630AF, "OV6630AF" },
294 { SEN_OV8600, "OV8600" },
295 { SEN_KS0127, "KS0127" },
296 { SEN_KS0127B, "KS0127B" },
297 { SEN_SAA7111A, "SAA7111A" },
301 /* URB error codes: */
302 static struct symbolic_list urb_errlist[] = {
303 { -ENOSR, "Buffer error (overrun)" },
304 { -EPIPE, "Stalled (device not responding)" },
305 { -EOVERFLOW, "Babble (device sends too much data)" },
306 { -EPROTO, "Bit-stuff error (bad cable?)" },
307 { -EILSEQ, "CRC/Timeout (bad cable?)" },
308 { -ETIME, "Device does not respond to token" },
309 { -ETIMEDOUT, "Device does not respond to command" },
313 /**********************************************************************
315 **********************************************************************/
317 rvmalloc(unsigned long size)
322 size = PAGE_ALIGN(size);
323 mem = vmalloc_32(size);
327 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
328 adr = (unsigned long) mem;
330 SetPageReserved(vmalloc_to_page((void *)adr));
339 rvfree(void *mem, unsigned long size)
346 adr = (unsigned long) mem;
347 while ((long) size > 0) {
348 ClearPageReserved(vmalloc_to_page((void *)adr));
355 /**********************************************************************
359 **********************************************************************/
361 /* Write an OV51x register */
363 reg_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
367 PDEBUG(5, "0x%02X:0x%02X", reg, value);
369 mutex_lock(&ov->cbuf_lock);
371 rc = usb_control_msg(ov->dev,
372 usb_sndctrlpipe(ov->dev, 0),
373 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */,
374 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
375 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
376 mutex_unlock(&ov->cbuf_lock);
379 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc));
384 /* Read from an OV51x register */
385 /* returns: negative is error, pos or zero is data */
387 reg_r(struct usb_ov511 *ov, unsigned char reg)
391 mutex_lock(&ov->cbuf_lock);
392 rc = usb_control_msg(ov->dev,
393 usb_rcvctrlpipe(ov->dev, 0),
394 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */,
395 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
396 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
399 err("reg read: error %d: %s", rc, symbolic(urb_errlist, rc));
402 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]);
405 mutex_unlock(&ov->cbuf_lock);
411 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
412 * the same position as 1's in "mask" are cleared and set to "value". Bits
413 * that are in the same position as 0's in "mask" are preserved, regardless
414 * of their respective state in "value".
417 reg_w_mask(struct usb_ov511 *ov,
423 unsigned char oldval, newval;
425 ret = reg_r(ov, reg);
429 oldval = (unsigned char) ret;
430 oldval &= (~mask); /* Clear the masked bits */
431 value &= mask; /* Enforce mask on value */
432 newval = oldval | value; /* Set the desired bits */
434 return (reg_w(ov, reg, newval));
438 * Writes multiple (n) byte value to a single register. Only valid with certain
439 * registers (0x30 and 0xc4 - 0xce).
442 ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
446 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n);
448 mutex_lock(&ov->cbuf_lock);
450 *((__le32 *)ov->cbuf) = __cpu_to_le32(val);
452 rc = usb_control_msg(ov->dev,
453 usb_sndctrlpipe(ov->dev, 0),
455 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
456 0, (__u16)reg, ov->cbuf, n, 1000);
457 mutex_unlock(&ov->cbuf_lock);
460 err("reg write multiple: error %d: %s", rc,
461 symbolic(urb_errlist, rc));
467 ov511_upload_quan_tables(struct usb_ov511 *ov)
469 unsigned char *pYTable = yQuanTable511;
470 unsigned char *pUVTable = uvQuanTable511;
471 unsigned char val0, val1;
472 int i, rc, reg = R511_COMP_LUT_BEGIN;
474 PDEBUG(4, "Uploading quantization tables");
476 for (i = 0; i < OV511_QUANTABLESIZE / 2; i++) {
477 if (ENABLE_Y_QUANTABLE) {
483 rc = reg_w(ov, reg, val0);
488 if (ENABLE_UV_QUANTABLE) {
494 rc = reg_w(ov, reg + OV511_QUANTABLESIZE/2, val0);
505 /* OV518 quantization tables are 8x4 (instead of 8x8) */
507 ov518_upload_quan_tables(struct usb_ov511 *ov)
509 unsigned char *pYTable = yQuanTable518;
510 unsigned char *pUVTable = uvQuanTable518;
511 unsigned char val0, val1;
512 int i, rc, reg = R511_COMP_LUT_BEGIN;
514 PDEBUG(4, "Uploading quantization tables");
516 for (i = 0; i < OV518_QUANTABLESIZE / 2; i++) {
517 if (ENABLE_Y_QUANTABLE) {
523 rc = reg_w(ov, reg, val0);
528 if (ENABLE_UV_QUANTABLE) {
534 rc = reg_w(ov, reg + OV518_QUANTABLESIZE/2, val0);
546 ov51x_reset(struct usb_ov511 *ov, unsigned char reset_type)
550 /* Setting bit 0 not allowed on 518/518Plus */
551 if (ov->bclass == BCL_OV518)
554 PDEBUG(4, "Reset: type=0x%02X", reset_type);
556 rc = reg_w(ov, R51x_SYS_RESET, reset_type);
557 rc = reg_w(ov, R51x_SYS_RESET, 0);
560 err("reset: command failed");
565 /**********************************************************************
567 * Low-level I2C I/O functions
569 **********************************************************************/
571 /* NOTE: Do not call this function directly!
572 * The OV518 I2C I/O procedure is different, hence, this function.
573 * This is normally only called from i2c_w(). Note that this function
574 * always succeeds regardless of whether the sensor is present and working.
577 ov518_i2c_write_internal(struct usb_ov511 *ov,
583 PDEBUG(5, "0x%02X:0x%02X", reg, value);
585 /* Select camera register */
586 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
590 /* Write "value" to I2C data port of OV511 */
591 rc = reg_w(ov, R51x_I2C_DATA, value);
595 /* Initiate 3-byte write cycle */
596 rc = reg_w(ov, R518_I2C_CTL, 0x01);
603 /* NOTE: Do not call this function directly! */
605 ov511_i2c_write_internal(struct usb_ov511 *ov,
611 PDEBUG(5, "0x%02X:0x%02X", reg, value);
613 /* Three byte write cycle */
614 for (retries = OV511_I2C_RETRIES; ; ) {
615 /* Select camera register */
616 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
620 /* Write "value" to I2C data port of OV511 */
621 rc = reg_w(ov, R51x_I2C_DATA, value);
625 /* Initiate 3-byte write cycle */
626 rc = reg_w(ov, R511_I2C_CTL, 0x01);
630 /* Retry until idle */
632 rc = reg_r(ov, R511_I2C_CTL);
633 } while (rc > 0 && ((rc&1) == 0));
644 reg_w(ov, R511_I2C_CTL, 0x10);
647 err("i2c write retries exhausted");
656 /* NOTE: Do not call this function directly!
657 * The OV518 I2C I/O procedure is different, hence, this function.
658 * This is normally only called from i2c_r(). Note that this function
659 * always succeeds regardless of whether the sensor is present and working.
662 ov518_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
666 /* Select camera register */
667 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
671 /* Initiate 2-byte write cycle */
672 rc = reg_w(ov, R518_I2C_CTL, 0x03);
676 /* Initiate 2-byte read cycle */
677 rc = reg_w(ov, R518_I2C_CTL, 0x05);
681 value = reg_r(ov, R51x_I2C_DATA);
683 PDEBUG(5, "0x%02X:0x%02X", reg, value);
688 /* NOTE: Do not call this function directly!
689 * returns: negative is error, pos or zero is data */
691 ov511_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
693 int rc, value, retries;
695 /* Two byte write cycle */
696 for (retries = OV511_I2C_RETRIES; ; ) {
697 /* Select camera register */
698 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
702 /* Initiate 2-byte write cycle */
703 rc = reg_w(ov, R511_I2C_CTL, 0x03);
707 /* Retry until idle */
709 rc = reg_r(ov, R511_I2C_CTL);
710 } while (rc > 0 && ((rc & 1) == 0));
714 if ((rc&2) == 0) /* Ack? */
718 reg_w(ov, R511_I2C_CTL, 0x10);
721 err("i2c write retries exhausted");
726 /* Two byte read cycle */
727 for (retries = OV511_I2C_RETRIES; ; ) {
728 /* Initiate 2-byte read cycle */
729 rc = reg_w(ov, R511_I2C_CTL, 0x05);
733 /* Retry until idle */
735 rc = reg_r(ov, R511_I2C_CTL);
736 } while (rc > 0 && ((rc&1) == 0));
740 if ((rc&2) == 0) /* Ack? */
744 rc = reg_w(ov, R511_I2C_CTL, 0x10);
749 err("i2c read retries exhausted");
754 value = reg_r(ov, R51x_I2C_DATA);
756 PDEBUG(5, "0x%02X:0x%02X", reg, value);
758 /* This is needed to make i2c_w() work */
759 rc = reg_w(ov, R511_I2C_CTL, 0x05);
766 /* returns: negative is error, pos or zero is data */
768 i2c_r(struct usb_ov511 *ov, unsigned char reg)
772 mutex_lock(&ov->i2c_lock);
774 if (ov->bclass == BCL_OV518)
775 rc = ov518_i2c_read_internal(ov, reg);
777 rc = ov511_i2c_read_internal(ov, reg);
779 mutex_unlock(&ov->i2c_lock);
785 i2c_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
789 mutex_lock(&ov->i2c_lock);
791 if (ov->bclass == BCL_OV518)
792 rc = ov518_i2c_write_internal(ov, reg, value);
794 rc = ov511_i2c_write_internal(ov, reg, value);
796 mutex_unlock(&ov->i2c_lock);
801 /* Do not call this function directly! */
803 ov51x_i2c_write_mask_internal(struct usb_ov511 *ov,
809 unsigned char oldval, newval;
814 if (ov->bclass == BCL_OV518)
815 rc = ov518_i2c_read_internal(ov, reg);
817 rc = ov511_i2c_read_internal(ov, reg);
821 oldval = (unsigned char) rc;
822 oldval &= (~mask); /* Clear the masked bits */
823 value &= mask; /* Enforce mask on value */
824 newval = oldval | value; /* Set the desired bits */
827 if (ov->bclass == BCL_OV518)
828 return (ov518_i2c_write_internal(ov, reg, newval));
830 return (ov511_i2c_write_internal(ov, reg, newval));
833 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
834 * the same position as 1's in "mask" are cleared and set to "value". Bits
835 * that are in the same position as 0's in "mask" are preserved, regardless
836 * of their respective state in "value".
839 i2c_w_mask(struct usb_ov511 *ov,
846 mutex_lock(&ov->i2c_lock);
847 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
848 mutex_unlock(&ov->i2c_lock);
853 /* Set the read and write slave IDs. The "slave" argument is the write slave,
854 * and the read slave will be set to (slave + 1). ov->i2c_lock should be held
855 * when calling this. This should not be called from outside the i2c I/O
859 i2c_set_slave_internal(struct usb_ov511 *ov, unsigned char slave)
863 rc = reg_w(ov, R51x_I2C_W_SID, slave);
867 rc = reg_w(ov, R51x_I2C_R_SID, slave + 1);
874 /* Write to a specific I2C slave ID and register, using the specified mask */
876 i2c_w_slave(struct usb_ov511 *ov,
884 mutex_lock(&ov->i2c_lock);
886 /* Set new slave IDs */
887 rc = i2c_set_slave_internal(ov, slave);
891 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
894 /* Restore primary IDs */
895 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
896 err("Couldn't restore primary I2C slave");
898 mutex_unlock(&ov->i2c_lock);
902 /* Read from a specific I2C slave ID and register */
904 i2c_r_slave(struct usb_ov511 *ov,
910 mutex_lock(&ov->i2c_lock);
912 /* Set new slave IDs */
913 rc = i2c_set_slave_internal(ov, slave);
917 if (ov->bclass == BCL_OV518)
918 rc = ov518_i2c_read_internal(ov, reg);
920 rc = ov511_i2c_read_internal(ov, reg);
923 /* Restore primary IDs */
924 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
925 err("Couldn't restore primary I2C slave");
927 mutex_unlock(&ov->i2c_lock);
931 /* Sets I2C read and write slave IDs. Returns <0 for error */
933 ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
937 mutex_lock(&ov->i2c_lock);
939 rc = i2c_set_slave_internal(ov, sid);
943 // FIXME: Is this actually necessary?
944 rc = ov51x_reset(ov, OV511_RESET_NOREGS);
946 mutex_unlock(&ov->i2c_lock);
951 write_regvals(struct usb_ov511 *ov, struct ov511_regvals * pRegvals)
955 while (pRegvals->bus != OV511_DONE_BUS) {
956 if (pRegvals->bus == OV511_REG_BUS) {
957 if ((rc = reg_w(ov, pRegvals->reg, pRegvals->val)) < 0)
959 } else if (pRegvals->bus == OV511_I2C_BUS) {
960 if ((rc = i2c_w(ov, pRegvals->reg, pRegvals->val)) < 0)
963 err("Bad regval array");
973 dump_i2c_range(struct usb_ov511 *ov, int reg1, int regn)
977 for (i = reg1; i <= regn; i++) {
979 dev_info(&ov->dev->dev, "Sensor[0x%02X] = 0x%02X\n", i, rc);
984 dump_i2c_regs(struct usb_ov511 *ov)
986 dev_info(&ov->dev->dev, "I2C REGS\n");
987 dump_i2c_range(ov, 0x00, 0x7C);
991 dump_reg_range(struct usb_ov511 *ov, int reg1, int regn)
995 for (i = reg1; i <= regn; i++) {
997 dev_info(&ov->dev->dev, "OV511[0x%02X] = 0x%02X\n", i, rc);
1002 ov511_dump_regs(struct usb_ov511 *ov)
1004 dev_info(&ov->dev->dev, "CAMERA INTERFACE REGS\n");
1005 dump_reg_range(ov, 0x10, 0x1f);
1006 dev_info(&ov->dev->dev, "DRAM INTERFACE REGS\n");
1007 dump_reg_range(ov, 0x20, 0x23);
1008 dev_info(&ov->dev->dev, "ISO FIFO REGS\n");
1009 dump_reg_range(ov, 0x30, 0x31);
1010 dev_info(&ov->dev->dev, "PIO REGS\n");
1011 dump_reg_range(ov, 0x38, 0x39);
1012 dump_reg_range(ov, 0x3e, 0x3e);
1013 dev_info(&ov->dev->dev, "I2C REGS\n");
1014 dump_reg_range(ov, 0x40, 0x49);
1015 dev_info(&ov->dev->dev, "SYSTEM CONTROL REGS\n");
1016 dump_reg_range(ov, 0x50, 0x55);
1017 dump_reg_range(ov, 0x5e, 0x5f);
1018 dev_info(&ov->dev->dev, "OmniCE REGS\n");
1019 dump_reg_range(ov, 0x70, 0x79);
1020 /* NOTE: Quantization tables are not readable. You will get the value
1021 * in reg. 0x79 for every table register */
1022 dump_reg_range(ov, 0x80, 0x9f);
1023 dump_reg_range(ov, 0xa0, 0xbf);
1028 ov518_dump_regs(struct usb_ov511 *ov)
1030 dev_info(&ov->dev->dev, "VIDEO MODE REGS\n");
1031 dump_reg_range(ov, 0x20, 0x2f);
1032 dev_info(&ov->dev->dev, "DATA PUMP AND SNAPSHOT REGS\n");
1033 dump_reg_range(ov, 0x30, 0x3f);
1034 dev_info(&ov->dev->dev, "I2C REGS\n");
1035 dump_reg_range(ov, 0x40, 0x4f);
1036 dev_info(&ov->dev->dev, "SYSTEM CONTROL AND VENDOR REGS\n");
1037 dump_reg_range(ov, 0x50, 0x5f);
1038 dev_info(&ov->dev->dev, "60 - 6F\n");
1039 dump_reg_range(ov, 0x60, 0x6f);
1040 dev_info(&ov->dev->dev, "70 - 7F\n");
1041 dump_reg_range(ov, 0x70, 0x7f);
1042 dev_info(&ov->dev->dev, "Y QUANTIZATION TABLE\n");
1043 dump_reg_range(ov, 0x80, 0x8f);
1044 dev_info(&ov->dev->dev, "UV QUANTIZATION TABLE\n");
1045 dump_reg_range(ov, 0x90, 0x9f);
1046 dev_info(&ov->dev->dev, "A0 - BF\n");
1047 dump_reg_range(ov, 0xa0, 0xbf);
1048 dev_info(&ov->dev->dev, "CBR\n");
1049 dump_reg_range(ov, 0xc0, 0xcf);
1053 /*****************************************************************************/
1055 /* Temporarily stops OV511 from functioning. Must do this before changing
1056 * registers while the camera is streaming */
1058 ov51x_stop(struct usb_ov511 *ov)
1060 PDEBUG(4, "stopping");
1062 if (ov->bclass == BCL_OV518)
1063 return (reg_w_mask(ov, R51x_SYS_RESET, 0x3a, 0x3a));
1065 return (reg_w(ov, R51x_SYS_RESET, 0x3d));
1068 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1069 * actually stopped (for performance). */
1071 ov51x_restart(struct usb_ov511 *ov)
1074 PDEBUG(4, "restarting");
1077 /* Reinitialize the stream */
1078 if (ov->bclass == BCL_OV518)
1079 reg_w(ov, 0x2f, 0x80);
1081 return (reg_w(ov, R51x_SYS_RESET, 0x00));
1087 /* Sleeps until no frames are active. Returns !0 if got signal */
1089 ov51x_wait_frames_inactive(struct usb_ov511 *ov)
1091 return wait_event_interruptible(ov->wq, ov->curframe < 0);
1094 /* Resets the hardware snapshot button */
1096 ov51x_clear_snapshot(struct usb_ov511 *ov)
1098 if (ov->bclass == BCL_OV511) {
1099 reg_w(ov, R51x_SYS_SNAP, 0x00);
1100 reg_w(ov, R51x_SYS_SNAP, 0x02);
1101 reg_w(ov, R51x_SYS_SNAP, 0x00);
1102 } else if (ov->bclass == BCL_OV518) {
1103 dev_warn(&ov->dev->dev,
1104 "snapshot reset not supported yet on OV518(+)\n");
1106 dev_err(&ov->dev->dev, "clear snap: invalid bridge type\n");
1111 /* Checks the status of the snapshot button. Returns 1 if it was pressed since
1112 * it was last cleared, and zero in all other cases (including errors) */
1114 ov51x_check_snapshot(struct usb_ov511 *ov)
1116 int ret, status = 0;
1118 if (ov->bclass == BCL_OV511) {
1119 ret = reg_r(ov, R51x_SYS_SNAP);
1121 dev_err(&ov->dev->dev,
1122 "Error checking snspshot status (%d)\n", ret);
1123 } else if (ret & 0x08) {
1126 } else if (ov->bclass == BCL_OV518) {
1127 dev_warn(&ov->dev->dev,
1128 "snapshot check not supported yet on OV518(+)\n");
1130 dev_err(&ov->dev->dev, "clear snap: invalid bridge type\n");
1137 /* This does an initial reset of an OmniVision sensor and ensures that I2C
1138 * is synchronized. Returns <0 for failure.
1141 init_ov_sensor(struct usb_ov511 *ov)
1145 /* Reset the sensor */
1146 if (i2c_w(ov, 0x12, 0x80) < 0)
1149 /* Wait for it to initialize */
1152 for (i = 0, success = 0; i < i2c_detect_tries && !success; i++) {
1153 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
1154 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
1159 /* Reset the sensor */
1160 if (i2c_w(ov, 0x12, 0x80) < 0)
1162 /* Wait for it to initialize */
1164 /* Dummy read to sync I2C */
1165 if (i2c_r(ov, 0x00) < 0)
1172 PDEBUG(1, "I2C synced in %d attempt(s)", i);
1178 ov511_set_packet_size(struct usb_ov511 *ov, int size)
1182 if (ov51x_stop(ov) < 0)
1187 if (ov->bridge == BRG_OV511) {
1189 alt = OV511_ALT_SIZE_0;
1190 else if (size == 257)
1191 alt = OV511_ALT_SIZE_257;
1192 else if (size == 513)
1193 alt = OV511_ALT_SIZE_513;
1194 else if (size == 769)
1195 alt = OV511_ALT_SIZE_769;
1196 else if (size == 993)
1197 alt = OV511_ALT_SIZE_993;
1199 err("Set packet size: invalid size (%d)", size);
1202 } else if (ov->bridge == BRG_OV511PLUS) {
1204 alt = OV511PLUS_ALT_SIZE_0;
1205 else if (size == 33)
1206 alt = OV511PLUS_ALT_SIZE_33;
1207 else if (size == 129)
1208 alt = OV511PLUS_ALT_SIZE_129;
1209 else if (size == 257)
1210 alt = OV511PLUS_ALT_SIZE_257;
1211 else if (size == 385)
1212 alt = OV511PLUS_ALT_SIZE_385;
1213 else if (size == 513)
1214 alt = OV511PLUS_ALT_SIZE_513;
1215 else if (size == 769)
1216 alt = OV511PLUS_ALT_SIZE_769;
1217 else if (size == 961)
1218 alt = OV511PLUS_ALT_SIZE_961;
1220 err("Set packet size: invalid size (%d)", size);
1224 err("Set packet size: Invalid bridge type");
1228 PDEBUG(3, "%d, mult=%d, alt=%d", size, mult, alt);
1230 if (reg_w(ov, R51x_FIFO_PSIZE, mult) < 0)
1233 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1234 err("Set packet size: set interface error");
1238 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1241 ov->packet_size = size;
1243 if (ov51x_restart(ov) < 0)
1249 /* Note: Unlike the OV511/OV511+, the size argument does NOT include the
1250 * optional packet number byte. The actual size *is* stored in ov->packet_size,
1253 ov518_set_packet_size(struct usb_ov511 *ov, int size)
1257 if (ov51x_stop(ov) < 0)
1260 if (ov->bclass == BCL_OV518) {
1262 alt = OV518_ALT_SIZE_0;
1263 else if (size == 128)
1264 alt = OV518_ALT_SIZE_128;
1265 else if (size == 256)
1266 alt = OV518_ALT_SIZE_256;
1267 else if (size == 384)
1268 alt = OV518_ALT_SIZE_384;
1269 else if (size == 512)
1270 alt = OV518_ALT_SIZE_512;
1271 else if (size == 640)
1272 alt = OV518_ALT_SIZE_640;
1273 else if (size == 768)
1274 alt = OV518_ALT_SIZE_768;
1275 else if (size == 896)
1276 alt = OV518_ALT_SIZE_896;
1278 err("Set packet size: invalid size (%d)", size);
1282 err("Set packet size: Invalid bridge type");
1286 PDEBUG(3, "%d, alt=%d", size, alt);
1288 ov->packet_size = size;
1290 /* Program ISO FIFO size reg (packet number isn't included) */
1291 ov518_reg_w32(ov, 0x30, size, 2);
1293 if (ov->packet_numbering)
1297 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1298 err("Set packet size: set interface error");
1302 /* Initialize the stream */
1303 if (reg_w(ov, 0x2f, 0x80) < 0)
1306 if (ov51x_restart(ov) < 0)
1309 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1315 /* Upload compression params and quantization tables. Returns 0 for success. */
1317 ov511_init_compression(struct usb_ov511 *ov)
1321 if (!ov->compress_inited) {
1322 reg_w(ov, 0x70, phy);
1323 reg_w(ov, 0x71, phuv);
1324 reg_w(ov, 0x72, pvy);
1325 reg_w(ov, 0x73, pvuv);
1326 reg_w(ov, 0x74, qhy);
1327 reg_w(ov, 0x75, qhuv);
1328 reg_w(ov, 0x76, qvy);
1329 reg_w(ov, 0x77, qvuv);
1331 if (ov511_upload_quan_tables(ov) < 0) {
1332 err("Error uploading quantization tables");
1338 ov->compress_inited = 1;
1343 /* Upload compression params and quantization tables. Returns 0 for success. */
1345 ov518_init_compression(struct usb_ov511 *ov)
1349 if (!ov->compress_inited) {
1350 if (ov518_upload_quan_tables(ov) < 0) {
1351 err("Error uploading quantization tables");
1357 ov->compress_inited = 1;
1362 /* -------------------------------------------------------------------------- */
1364 /* Sets sensor's contrast setting to "val" */
1366 sensor_set_contrast(struct usb_ov511 *ov, unsigned short val)
1370 PDEBUG(3, "%d", val);
1372 if (ov->stop_during_set)
1373 if (ov51x_stop(ov) < 0)
1376 switch (ov->sensor) {
1380 rc = i2c_w(ov, OV7610_REG_CNT, val >> 8);
1387 rc = i2c_w_mask(ov, OV7610_REG_CNT, val >> 12, 0x0f);
1394 unsigned char ctab[] = {
1395 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
1396 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
1399 /* Use Y gamma control instead. Bit 0 enables it. */
1400 rc = i2c_w(ov, 0x64, ctab[val>>12]);
1407 rc = i2c_w(ov, 0x0b, val >> 9);
1414 PDEBUG(3, "Unsupported with this sensor");
1420 rc = 0; /* Success */
1423 if (ov51x_restart(ov) < 0)
1429 /* Gets sensor's contrast setting */
1431 sensor_get_contrast(struct usb_ov511 *ov, unsigned short *val)
1435 switch (ov->sensor) {
1438 rc = i2c_r(ov, OV7610_REG_CNT);
1445 rc = i2c_r(ov, OV7610_REG_CNT);
1452 /* Use Y gamma reg instead. Bit 0 is the enable bit. */
1453 rc = i2c_r(ov, 0x64);
1457 *val = (rc & 0xfe) << 8;
1460 *val = ov->contrast;
1463 PDEBUG(3, "Unsupported with this sensor");
1467 PDEBUG(3, "%d", *val);
1468 ov->contrast = *val;
1473 /* -------------------------------------------------------------------------- */
1475 /* Sets sensor's brightness setting to "val" */
1477 sensor_set_brightness(struct usb_ov511 *ov, unsigned short val)
1481 PDEBUG(4, "%d", val);
1483 if (ov->stop_during_set)
1484 if (ov51x_stop(ov) < 0)
1487 switch (ov->sensor) {
1492 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1497 /* 7620 doesn't like manual changes when in auto mode */
1498 if (!ov->auto_brt) {
1499 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1505 rc = i2c_w(ov, 0x0a, val >> 8);
1510 PDEBUG(3, "Unsupported with this sensor");
1515 rc = 0; /* Success */
1516 ov->brightness = val;
1518 if (ov51x_restart(ov) < 0)
1524 /* Gets sensor's brightness setting */
1526 sensor_get_brightness(struct usb_ov511 *ov, unsigned short *val)
1530 switch (ov->sensor) {
1536 rc = i2c_r(ov, OV7610_REG_BRT);
1543 *val = ov->brightness;
1546 PDEBUG(3, "Unsupported with this sensor");
1550 PDEBUG(3, "%d", *val);
1551 ov->brightness = *val;
1556 /* -------------------------------------------------------------------------- */
1558 /* Sets sensor's saturation (color intensity) setting to "val" */
1560 sensor_set_saturation(struct usb_ov511 *ov, unsigned short val)
1564 PDEBUG(3, "%d", val);
1566 if (ov->stop_during_set)
1567 if (ov51x_stop(ov) < 0)
1570 switch (ov->sensor) {
1575 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1580 // /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
1581 // rc = ov_i2c_write(ov->dev, 0x62, (val >> 9) & 0x7e);
1584 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1589 rc = i2c_w(ov, 0x0c, val >> 9);
1594 PDEBUG(3, "Unsupported with this sensor");
1599 rc = 0; /* Success */
1602 if (ov51x_restart(ov) < 0)
1608 /* Gets sensor's saturation (color intensity) setting */
1610 sensor_get_saturation(struct usb_ov511 *ov, unsigned short *val)
1614 switch (ov->sensor) {
1619 rc = i2c_r(ov, OV7610_REG_SAT);
1626 // /* Use UV gamma reg instead. Bits 0 & 7 are reserved. */
1627 // rc = i2c_r(ov, 0x62);
1631 // *val = (rc & 0x7e) << 9;
1632 rc = i2c_r(ov, OV7610_REG_SAT);
1642 PDEBUG(3, "Unsupported with this sensor");
1646 PDEBUG(3, "%d", *val);
1652 /* -------------------------------------------------------------------------- */
1654 /* Sets sensor's hue (red/blue balance) setting to "val" */
1656 sensor_set_hue(struct usb_ov511 *ov, unsigned short val)
1660 PDEBUG(3, "%d", val);
1662 if (ov->stop_during_set)
1663 if (ov51x_stop(ov) < 0)
1666 switch (ov->sensor) {
1670 rc = i2c_w(ov, OV7610_REG_RED, 0xFF - (val >> 8));
1674 rc = i2c_w(ov, OV7610_REG_BLUE, val >> 8);
1679 // Hue control is causing problems. I will enable it once it's fixed.
1681 rc = i2c_w(ov, 0x7a, (unsigned char)(val >> 8) + 0xb);
1685 rc = i2c_w(ov, 0x79, (unsigned char)(val >> 8) + 0xb);
1691 rc = i2c_w(ov, 0x0d, (val + 32768) >> 8);
1696 PDEBUG(3, "Unsupported with this sensor");
1701 rc = 0; /* Success */
1704 if (ov51x_restart(ov) < 0)
1710 /* Gets sensor's hue (red/blue balance) setting */
1712 sensor_get_hue(struct usb_ov511 *ov, unsigned short *val)
1716 switch (ov->sensor) {
1720 rc = i2c_r(ov, OV7610_REG_BLUE);
1727 rc = i2c_r(ov, 0x7a);
1737 PDEBUG(3, "Unsupported with this sensor");
1741 PDEBUG(3, "%d", *val);
1747 /* -------------------------------------------------------------------------- */
1750 sensor_set_picture(struct usb_ov511 *ov, struct video_picture *p)
1754 PDEBUG(4, "sensor_set_picture");
1756 ov->whiteness = p->whiteness;
1758 /* Don't return error if a setting is unsupported, or rest of settings
1759 * will not be performed */
1761 rc = sensor_set_contrast(ov, p->contrast);
1762 if (FATAL_ERROR(rc))
1765 rc = sensor_set_brightness(ov, p->brightness);
1766 if (FATAL_ERROR(rc))
1769 rc = sensor_set_saturation(ov, p->colour);
1770 if (FATAL_ERROR(rc))
1773 rc = sensor_set_hue(ov, p->hue);
1774 if (FATAL_ERROR(rc))
1781 sensor_get_picture(struct usb_ov511 *ov, struct video_picture *p)
1785 PDEBUG(4, "sensor_get_picture");
1787 /* Don't return error if a setting is unsupported, or rest of settings
1788 * will not be performed */
1790 rc = sensor_get_contrast(ov, &(p->contrast));
1791 if (FATAL_ERROR(rc))
1794 rc = sensor_get_brightness(ov, &(p->brightness));
1795 if (FATAL_ERROR(rc))
1798 rc = sensor_get_saturation(ov, &(p->colour));
1799 if (FATAL_ERROR(rc))
1802 rc = sensor_get_hue(ov, &(p->hue));
1803 if (FATAL_ERROR(rc))
1806 p->whiteness = 105 << 8;
1812 // FIXME: Exposure range is only 0x00-0x7f in interlace mode
1813 /* Sets current exposure for sensor. This only has an effect if auto-exposure
1816 sensor_set_exposure(struct usb_ov511 *ov, unsigned char val)
1820 PDEBUG(3, "%d", val);
1822 if (ov->stop_during_set)
1823 if (ov51x_stop(ov) < 0)
1826 switch (ov->sensor) {
1833 rc = i2c_w(ov, 0x10, val);
1841 PDEBUG(3, "Unsupported with this sensor");
1844 err("Sensor not supported for set_exposure");
1848 rc = 0; /* Success */
1851 if (ov51x_restart(ov) < 0)
1858 /* Gets current exposure level from sensor, regardless of whether it is under
1859 * manual control. */
1861 sensor_get_exposure(struct usb_ov511 *ov, unsigned char *val)
1865 switch (ov->sensor) {
1872 rc = i2c_r(ov, 0x10);
1882 PDEBUG(3, "Unsupported with this sensor");
1885 err("Sensor not supported for get_exposure");
1889 PDEBUG(3, "%d", *val);
1890 ov->exposure = *val;
1895 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+) */
1897 ov51x_led_control(struct usb_ov511 *ov, int enable)
1899 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1901 if (ov->bridge == BRG_OV511PLUS)
1902 reg_w(ov, R511_SYS_LED_CTL, enable ? 1 : 0);
1903 else if (ov->bclass == BCL_OV518)
1904 reg_w_mask(ov, R518_GPIO_OUT, enable ? 0x02 : 0x00, 0x02);
1909 /* Matches the sensor's internal frame rate to the lighting frequency.
1910 * Valid frequencies are:
1911 * 50 - 50Hz, for European and Asian lighting
1912 * 60 - 60Hz, for American lighting
1914 * Tested with: OV7610, OV7620, OV76BE, OV6620
1915 * Unsupported: KS0127, KS0127B, SAA7111A
1916 * Returns: 0 for success
1919 sensor_set_light_freq(struct usb_ov511 *ov, int freq)
1923 PDEBUG(4, "%d Hz", freq);
1927 else if (freq == 50)
1930 err("Invalid light freq (%d Hz)", freq);
1934 switch (ov->sensor) {
1936 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1937 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1938 i2c_w_mask(ov, 0x13, 0x10, 0x10);
1939 i2c_w_mask(ov, 0x13, 0x00, 0x10);
1944 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1945 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1946 i2c_w_mask(ov, 0x76, 0x01, 0x01);
1950 i2c_w(ov, 0x2b, sixty?0xa8:0x28);
1951 i2c_w(ov, 0x2a, sixty?0x84:0xa4);
1956 PDEBUG(5, "Unsupported with this sensor");
1959 err("Sensor not supported for set_light_freq");
1963 ov->lightfreq = freq;
1968 /* If enable is true, turn on the sensor's banding filter, otherwise turn it
1969 * off. This filter tries to reduce the pattern of horizontal light/dark bands
1970 * caused by some (usually fluorescent) lighting. The light frequency must be
1971 * set either before or after enabling it with ov51x_set_light_freq().
1973 * Tested with: OV7610, OV7620, OV76BE, OV6620.
1974 * Unsupported: KS0127, KS0127B, SAA7111A
1975 * Returns: 0 for success
1978 sensor_set_banding_filter(struct usb_ov511 *ov, int enable)
1982 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1984 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
1985 || ov->sensor == SEN_SAA7111A) {
1986 PDEBUG(5, "Unsupported with this sensor");
1990 rc = i2c_w_mask(ov, 0x2d, enable?0x04:0x00, 0x04);
1994 ov->bandfilt = enable;
1999 /* If enable is true, turn on the sensor's auto brightness control, otherwise
2002 * Unsupported: KS0127, KS0127B, SAA7111A
2003 * Returns: 0 for success
2006 sensor_set_auto_brightness(struct usb_ov511 *ov, int enable)
2010 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2012 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
2013 || ov->sensor == SEN_SAA7111A) {
2014 PDEBUG(5, "Unsupported with this sensor");
2018 rc = i2c_w_mask(ov, 0x2d, enable?0x10:0x00, 0x10);
2022 ov->auto_brt = enable;
2027 /* If enable is true, turn on the sensor's auto exposure control, otherwise
2030 * Unsupported: KS0127, KS0127B, SAA7111A
2031 * Returns: 0 for success
2034 sensor_set_auto_exposure(struct usb_ov511 *ov, int enable)
2036 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2038 switch (ov->sensor) {
2040 i2c_w_mask(ov, 0x29, enable?0x00:0x80, 0x80);
2046 i2c_w_mask(ov, 0x13, enable?0x01:0x00, 0x01);
2049 i2c_w_mask(ov, 0x28, enable?0x00:0x10, 0x10);
2054 PDEBUG(5, "Unsupported with this sensor");
2057 err("Sensor not supported for set_auto_exposure");
2061 ov->auto_exp = enable;
2066 /* Modifies the sensor's exposure algorithm to allow proper exposure of objects
2067 * that are illuminated from behind.
2069 * Tested with: OV6620, OV7620
2070 * Unsupported: OV7610, OV76BE, KS0127, KS0127B, SAA7111A
2071 * Returns: 0 for success
2074 sensor_set_backlight(struct usb_ov511 *ov, int enable)
2076 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2078 switch (ov->sensor) {
2081 i2c_w_mask(ov, 0x68, enable?0xe0:0xc0, 0xe0);
2082 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2083 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2086 i2c_w_mask(ov, 0x4e, enable?0xe0:0xc0, 0xe0);
2087 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2088 i2c_w_mask(ov, 0x0e, enable?0x80:0x00, 0x80);
2091 i2c_w_mask(ov, 0x4e, enable?0x80:0x60, 0xe0);
2092 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2093 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2100 PDEBUG(5, "Unsupported with this sensor");
2103 err("Sensor not supported for set_backlight");
2107 ov->backlight = enable;
2113 sensor_set_mirror(struct usb_ov511 *ov, int enable)
2115 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2117 switch (ov->sensor) {
2124 i2c_w_mask(ov, 0x12, enable?0x40:0x00, 0x40);
2129 PDEBUG(5, "Unsupported with this sensor");
2132 err("Sensor not supported for set_mirror");
2136 ov->mirror = enable;
2141 /* Returns number of bits per pixel (regardless of where they are located;
2142 * planar or not), or zero for unsupported format.
2145 get_depth(int palette)
2148 case VIDEO_PALETTE_GREY: return 8;
2149 case VIDEO_PALETTE_YUV420: return 12;
2150 case VIDEO_PALETTE_YUV420P: return 12; /* Planar */
2151 default: return 0; /* Invalid format */
2155 /* Bytes per frame. Used by read(). Return of 0 indicates error */
2156 static inline long int
2157 get_frame_length(struct ov511_frame *frame)
2162 return ((frame->width * frame->height
2163 * get_depth(frame->format)) >> 3);
2167 mode_init_ov_sensor_regs(struct usb_ov511 *ov, int width, int height,
2168 int mode, int sub_flag, int qvga)
2172 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2174 switch (ov->sensor) {
2176 i2c_w(ov, 0x14, qvga?0x24:0x04);
2177 // FIXME: Does this improve the image quality or frame rate?
2179 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2180 i2c_w(ov, 0x24, 0x10);
2181 i2c_w(ov, 0x25, qvga?0x40:0x8a);
2182 i2c_w(ov, 0x2f, qvga?0x30:0xb0);
2183 i2c_w(ov, 0x35, qvga?0x1c:0x9c);
2187 // i2c_w(ov, 0x2b, 0x00);
2188 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2189 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2190 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2191 i2c_w(ov, 0x25, qvga?0x30:0x60);
2192 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2193 i2c_w_mask(ov, 0x67, qvga?0xf0:0x90, 0xf0);
2194 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2197 // i2c_w(ov, 0x2b, 0x00);
2198 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2199 // FIXME: Enable this once 7620AE uses 7620 initial settings
2201 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2202 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2203 i2c_w(ov, 0x25, qvga?0x30:0x60);
2204 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2205 i2c_w_mask(ov, 0x67, qvga?0xb0:0x90, 0xf0);
2206 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2210 i2c_w(ov, 0x14, qvga?0x24:0x04);
2213 i2c_w(ov, 0x14, qvga?0xa0:0x80);
2216 err("Invalid sensor");
2220 /******** Palette-specific regs ********/
2222 if (mode == VIDEO_PALETTE_GREY) {
2223 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2224 /* these aren't valid on the OV6620/OV7620/6630? */
2225 i2c_w_mask(ov, 0x0e, 0x40, 0x40);
2228 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2230 i2c_w_mask(ov, 0x12, 0x00, 0x10);
2231 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2233 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2236 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2237 /* not valid on the OV6620/OV7620/6630? */
2238 i2c_w_mask(ov, 0x0e, 0x00, 0x40);
2241 /* The OV518 needs special treatment. Although both the OV518
2242 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2243 * bus is actually used. The UV bus is tied to ground.
2244 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2247 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2249 i2c_w_mask(ov, 0x12, 0x10, 0x10);
2250 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2252 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2256 /******** Clock programming ********/
2258 /* The OV6620 needs special handling. This prevents the
2259 * severe banding that normally occurs */
2260 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630)
2264 i2c_w(ov, 0x2a, 0x04);
2267 // clock = 0; /* This ensures the highest frame rate */
2269 } else if (clockdiv == -1) { /* If user didn't override it */
2270 clock = 3; /* Gives better exposure time */
2275 PDEBUG(4, "Setting clock divisor to %d", clock);
2277 i2c_w(ov, 0x11, clock);
2279 i2c_w(ov, 0x2a, 0x84);
2280 /* This next setting is critical. It seems to improve
2281 * the gain or the contrast. The "reserved" bits seem
2282 * to have some effect in this case. */
2283 i2c_w(ov, 0x2d, 0x85);
2288 clock = 1; /* This ensures the highest frame rate */
2289 } else if (clockdiv == -1) { /* If user didn't override it */
2290 /* Calculate and set the clock divisor */
2291 clock = ((sub_flag ? ov->subw * ov->subh
2293 * (mode == VIDEO_PALETTE_GREY ? 2 : 3) / 2)
2299 PDEBUG(4, "Setting clock divisor to %d", clock);
2301 i2c_w(ov, 0x11, clock);
2304 /******** Special Features ********/
2307 i2c_w(ov, 0x16, framedrop);
2310 i2c_w_mask(ov, 0x12, (testpat?0x02:0x00), 0x02);
2312 /* Enable auto white balance */
2313 i2c_w_mask(ov, 0x12, 0x04, 0x04);
2315 // This will go away as soon as ov51x_mode_init_sensor_regs()
2317 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2318 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2319 if (width == 640 && height == 480)
2320 i2c_w(ov, 0x35, 0x9e);
2322 i2c_w(ov, 0x35, 0x1e);
2329 set_ov_sensor_window(struct usb_ov511 *ov, int width, int height, int mode,
2333 int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
2334 int hoffset, voffset, hwscale = 0, vwscale = 0;
2336 /* The different sensor ICs handle setting up of window differently.
2337 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!!! */
2338 switch (ov->sensor) {
2343 vwsbase = vwebase = 0x05;
2353 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2355 vwsbase = vwebase = 0x05;
2358 err("Invalid sensor");
2362 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630) {
2363 /* Note: OV518(+) does downsample on its own) */
2364 if ((width > 176 && height > 144)
2365 || ov->bclass == BCL_OV518) { /* CIF */
2366 ret = mode_init_ov_sensor_regs(ov, width, height,
2371 vwscale = 1; /* The datasheet says 0; it's wrong */
2374 } else if (width > 176 || height > 144) {
2375 err("Illegal dimensions");
2378 ret = mode_init_ov_sensor_regs(ov, width, height,
2386 if (width > 320 && height > 240) { /* VGA */
2387 ret = mode_init_ov_sensor_regs(ov, width, height,
2395 } else if (width > 320 || height > 240) {
2396 err("Illegal dimensions");
2399 ret = mode_init_ov_sensor_regs(ov, width, height,
2409 /* Center the window */
2410 hoffset = ((hwsize - width) / 2) >> hwscale;
2411 voffset = ((vwsize - height) / 2) >> vwscale;
2413 /* FIXME! - This needs to be changed to support 160x120 and 6620!!! */
2415 i2c_w(ov, 0x17, hwsbase+(ov->subx>>hwscale));
2416 i2c_w(ov, 0x18, hwebase+((ov->subx+ov->subw)>>hwscale));
2417 i2c_w(ov, 0x19, vwsbase+(ov->suby>>vwscale));
2418 i2c_w(ov, 0x1a, vwebase+((ov->suby+ov->subh)>>vwscale));
2420 i2c_w(ov, 0x17, hwsbase + hoffset);
2421 i2c_w(ov, 0x18, hwebase + hoffset + (hwsize>>hwscale));
2422 i2c_w(ov, 0x19, vwsbase + voffset);
2423 i2c_w(ov, 0x1a, vwebase + voffset + (vwsize>>vwscale));
2434 /* Set up the OV511/OV511+ with the given image parameters.
2436 * Do not put any sensor-specific code in here (including I2C I/O functions)
2439 ov511_mode_init_regs(struct usb_ov511 *ov,
2440 int width, int height, int mode, int sub_flag)
2449 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2450 width, height, mode, sub_flag);
2452 // FIXME: This should be moved to a 7111a-specific function once
2453 // subcapture is dealt with properly
2454 if (ov->sensor == SEN_SAA7111A) {
2455 if (width == 320 && height == 240) {
2456 /* No need to do anything special */
2457 } else if (width == 640 && height == 480) {
2458 /* Set the OV511 up as 320x480, but keep the
2459 * V4L resolution as 640x480 */
2462 err("SAA7111A only allows 320x240 or 640x480");
2467 /* Make sure width and height are a multiple of 8 */
2468 if (width % 8 || height % 8) {
2469 err("Invalid size (%d, %d) (mode = %d)", width, height, mode);
2473 if (width < ov->minwidth || height < ov->minheight) {
2474 err("Requested dimensions are too small");
2478 if (ov51x_stop(ov) < 0)
2481 if (mode == VIDEO_PALETTE_GREY) {
2482 reg_w(ov, R511_CAM_UV_EN, 0x00);
2483 reg_w(ov, R511_SNAP_UV_EN, 0x00);
2484 reg_w(ov, R511_SNAP_OPTS, 0x01);
2486 reg_w(ov, R511_CAM_UV_EN, 0x01);
2487 reg_w(ov, R511_SNAP_UV_EN, 0x01);
2488 reg_w(ov, R511_SNAP_OPTS, 0x03);
2491 /* Here I'm assuming that snapshot size == image size.
2492 * I hope that's always true. --claudio
2494 hsegs = (width >> 3) - 1;
2495 vsegs = (height >> 3) - 1;
2497 reg_w(ov, R511_CAM_PXCNT, hsegs);
2498 reg_w(ov, R511_CAM_LNCNT, vsegs);
2499 reg_w(ov, R511_CAM_PXDIV, 0x00);
2500 reg_w(ov, R511_CAM_LNDIV, 0x00);
2502 /* YUV420, low pass filter on */
2503 reg_w(ov, R511_CAM_OPTS, 0x03);
2505 /* Snapshot additions */
2506 reg_w(ov, R511_SNAP_PXCNT, hsegs);
2507 reg_w(ov, R511_SNAP_LNCNT, vsegs);
2508 reg_w(ov, R511_SNAP_PXDIV, 0x00);
2509 reg_w(ov, R511_SNAP_LNDIV, 0x00);
2512 /* Enable Y and UV quantization and compression */
2513 reg_w(ov, R511_COMP_EN, 0x07);
2514 reg_w(ov, R511_COMP_LUT_EN, 0x03);
2515 ov51x_reset(ov, OV511_RESET_OMNICE);
2518 if (ov51x_restart(ov) < 0)
2524 /* Sets up the OV518/OV518+ with the given image parameters
2526 * OV518 needs a completely different approach, until we can figure out what
2527 * the individual registers do. Also, only 15 FPS is supported now.
2529 * Do not put any sensor-specific code in here (including I2C I/O functions)
2532 ov518_mode_init_regs(struct usb_ov511 *ov,
2533 int width, int height, int mode, int sub_flag)
2535 int hsegs, vsegs, hi_res;
2542 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2543 width, height, mode, sub_flag);
2545 if (width % 16 || height % 8) {
2546 err("Invalid size (%d, %d)", width, height);
2550 if (width < ov->minwidth || height < ov->minheight) {
2551 err("Requested dimensions are too small");
2555 if (width >= 320 && height >= 240) {
2557 } else if (width >= 320 || height >= 240) {
2558 err("Invalid width/height combination (%d, %d)", width, height);
2564 if (ov51x_stop(ov) < 0)
2567 /******** Set the mode ********/
2578 if (ov->bridge == BRG_OV518 && ov518_color) {
2579 /* OV518 needs U and V swapped */
2580 i2c_w_mask(ov, 0x15, 0x00, 0x01);
2582 if (mode == VIDEO_PALETTE_GREY) {
2583 /* Set 16-bit input format (UV data are ignored) */
2584 reg_w_mask(ov, 0x20, 0x00, 0x08);
2586 /* Set 8-bit (4:0:0) output format */
2587 reg_w_mask(ov, 0x28, 0x00, 0xf0);
2588 reg_w_mask(ov, 0x38, 0x00, 0xf0);
2590 /* Set 8-bit (YVYU) input format */
2591 reg_w_mask(ov, 0x20, 0x08, 0x08);
2593 /* Set 12-bit (4:2:0) output format */
2594 reg_w_mask(ov, 0x28, 0x80, 0xf0);
2595 reg_w_mask(ov, 0x38, 0x80, 0xf0);
2598 reg_w(ov, 0x28, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2599 reg_w(ov, 0x38, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2605 reg_w(ov, 0x29, hsegs);
2606 reg_w(ov, 0x2a, vsegs);
2608 reg_w(ov, 0x39, hsegs);
2609 reg_w(ov, 0x3a, vsegs);
2611 /* Windows driver does this here; who knows why */
2612 reg_w(ov, 0x2f, 0x80);
2614 /******** Set the framerate (to 15 FPS) ********/
2616 /* Mode independent, but framerate dependent, regs */
2617 reg_w(ov, 0x51, 0x02); /* Clock divider; lower==faster */
2618 reg_w(ov, 0x22, 0x18);
2619 reg_w(ov, 0x23, 0xff);
2621 if (ov->bridge == BRG_OV518PLUS)
2622 reg_w(ov, 0x21, 0x19);
2624 reg_w(ov, 0x71, 0x19); /* Compression-related? */
2626 // FIXME: Sensor-specific
2627 /* Bit 5 is what matters here. Of course, it is "reserved" */
2628 i2c_w(ov, 0x54, 0x23);
2630 reg_w(ov, 0x2f, 0x80);
2632 if (ov->bridge == BRG_OV518PLUS) {
2633 reg_w(ov, 0x24, 0x94);
2634 reg_w(ov, 0x25, 0x90);
2635 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2636 ov518_reg_w32(ov, 0xc6, 540, 2); /* 21ch */
2637 ov518_reg_w32(ov, 0xc7, 540, 2); /* 21ch */
2638 ov518_reg_w32(ov, 0xc8, 108, 2); /* 6ch */
2639 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2640 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2641 ov518_reg_w32(ov, 0xcc, 2400, 2); /* 960h */
2642 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2643 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2645 reg_w(ov, 0x24, 0x9f);
2646 reg_w(ov, 0x25, 0x90);
2647 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2648 ov518_reg_w32(ov, 0xc6, 500, 2); /* 1f4h */
2649 ov518_reg_w32(ov, 0xc7, 500, 2); /* 1f4h */
2650 ov518_reg_w32(ov, 0xc8, 142, 2); /* 8eh */
2651 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2652 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2653 ov518_reg_w32(ov, 0xcc, 2000, 2); /* 7d0h */
2654 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2655 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2658 reg_w(ov, 0x2f, 0x80);
2660 if (ov51x_restart(ov) < 0)
2663 /* Reset it just for good measure */
2664 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
2670 /* This is a wrapper around the OV511, OV518, and sensor specific functions */
2672 mode_init_regs(struct usb_ov511 *ov,
2673 int width, int height, int mode, int sub_flag)
2677 if (!ov || !ov->dev)
2680 if (ov->bclass == BCL_OV518) {
2681 rc = ov518_mode_init_regs(ov, width, height, mode, sub_flag);
2683 rc = ov511_mode_init_regs(ov, width, height, mode, sub_flag);
2686 if (FATAL_ERROR(rc))
2689 switch (ov->sensor) {
2696 rc = set_ov_sensor_window(ov, width, height, mode, sub_flag);
2700 err("KS0127-series decoders not supported yet");
2704 // rc = mode_init_saa_sensor_regs(ov, width, height, mode,
2707 PDEBUG(1, "SAA status = 0x%02X", i2c_r(ov, 0x1f));
2710 err("Unknown sensor");
2714 if (FATAL_ERROR(rc))
2717 /* Sensor-independent settings */
2718 rc = sensor_set_auto_brightness(ov, ov->auto_brt);
2719 if (FATAL_ERROR(rc))
2722 rc = sensor_set_auto_exposure(ov, ov->auto_exp);
2723 if (FATAL_ERROR(rc))
2726 rc = sensor_set_banding_filter(ov, bandingfilter);
2727 if (FATAL_ERROR(rc))
2730 if (ov->lightfreq) {
2731 rc = sensor_set_light_freq(ov, lightfreq);
2732 if (FATAL_ERROR(rc))
2736 rc = sensor_set_backlight(ov, ov->backlight);
2737 if (FATAL_ERROR(rc))
2740 rc = sensor_set_mirror(ov, ov->mirror);
2741 if (FATAL_ERROR(rc))
2747 /* This sets the default image parameters. This is useful for apps that use
2748 * read() and do not set these.
2751 ov51x_set_default_params(struct usb_ov511 *ov)
2755 /* Set default sizes in case IOCTL (VIDIOCMCAPTURE) is not used
2756 * (using read() instead). */
2757 for (i = 0; i < OV511_NUMFRAMES; i++) {
2758 ov->frame[i].width = ov->maxwidth;
2759 ov->frame[i].height = ov->maxheight;
2760 ov->frame[i].bytes_read = 0;
2762 ov->frame[i].format = force_palette;
2764 ov->frame[i].format = VIDEO_PALETTE_YUV420;
2766 ov->frame[i].depth = get_depth(ov->frame[i].format);
2769 PDEBUG(3, "%dx%d, %s", ov->maxwidth, ov->maxheight,
2770 symbolic(v4l1_plist, ov->frame[0].format));
2772 /* Initialize to max width/height, YUV420 or RGB24 (if supported) */
2773 if (mode_init_regs(ov, ov->maxwidth, ov->maxheight,
2774 ov->frame[0].format, 0) < 0)
2780 /**********************************************************************
2782 * Video decoder stuff
2784 **********************************************************************/
2786 /* Set analog input port of decoder */
2788 decoder_set_input(struct usb_ov511 *ov, int input)
2790 PDEBUG(4, "port %d", input);
2792 switch (ov->sensor) {
2796 i2c_w_mask(ov, 0x02, input, 0x07);
2797 /* Bypass chrominance trap for modes 4..7 */
2798 i2c_w_mask(ov, 0x09, (input > 3) ? 0x80:0x00, 0x80);
2808 /* Get ASCII name of video input */
2810 decoder_get_input_name(struct usb_ov511 *ov, int input, char *name)
2812 switch (ov->sensor) {
2815 if (input < 0 || input > 7)
2818 sprintf(name, "CVBS-%d", input);
2819 else // if (input < 8)
2820 sprintf(name, "S-Video-%d", input - 4);
2824 sprintf(name, "%s", "Camera");
2830 /* Set norm (NTSC, PAL, SECAM, AUTO) */
2832 decoder_set_norm(struct usb_ov511 *ov, int norm)
2834 PDEBUG(4, "%d", norm);
2836 switch (ov->sensor) {
2841 if (norm == VIDEO_MODE_NTSC) {
2842 reg_8 = 0x40; /* 60 Hz */
2843 reg_e = 0x00; /* NTSC M / PAL BGHI */
2844 } else if (norm == VIDEO_MODE_PAL) {
2845 reg_8 = 0x00; /* 50 Hz */
2846 reg_e = 0x00; /* NTSC M / PAL BGHI */
2847 } else if (norm == VIDEO_MODE_AUTO) {
2848 reg_8 = 0x80; /* Auto field detect */
2849 reg_e = 0x00; /* NTSC M / PAL BGHI */
2850 } else if (norm == VIDEO_MODE_SECAM) {
2851 reg_8 = 0x00; /* 50 Hz */
2852 reg_e = 0x50; /* SECAM / PAL 4.43 */
2857 i2c_w_mask(ov, 0x08, reg_8, 0xc0);
2858 i2c_w_mask(ov, 0x0e, reg_e, 0x70);
2868 /**********************************************************************
2872 **********************************************************************/
2874 /* Copies a 64-byte segment at pIn to an 8x8 block at pOut. The width of the
2875 * image at pOut is specified by w.
2878 make_8x8(unsigned char *pIn, unsigned char *pOut, int w)
2880 unsigned char *pOut1 = pOut;
2883 for (y = 0; y < 8; y++) {
2885 for (x = 0; x < 8; x++) {
2893 * For RAW BW (YUV 4:0:0) images, data show up in 256 byte segments.
2894 * The segments represent 4 squares of 8x8 pixels as follows:
2896 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2897 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2899 * 56 57 ... 63 120 121 ... 127 248 249 ... 255
2903 yuv400raw_to_yuv400p(struct ov511_frame *frame,
2904 unsigned char *pIn0, unsigned char *pOut0)
2907 unsigned char *pIn, *pOut, *pOutLine;
2912 for (y = 0; y < frame->rawheight - 1; y += 8) {
2914 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2915 make_8x8(pIn, pOut, frame->rawwidth);
2919 pOutLine += 8 * frame->rawwidth;
2924 * For YUV 4:2:0 images, the data show up in 384 byte segments.
2925 * The first 64 bytes of each segment are U, the next 64 are V. The U and
2926 * V are arranged as follows:
2933 * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block).
2935 * The next 256 bytes are full resolution Y data and represent 4 squares
2936 * of 8x8 pixels as follows:
2938 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2939 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2941 * 56 57 ... 63 120 121 ... 127 ... 248 249 ... 255
2943 * Note that the U and V data in one segment represent a 16 x 16 pixel
2944 * area, but the Y data represent a 32 x 8 pixel area. If the width is not an
2945 * even multiple of 32, the extra 8x8 blocks within a 32x8 block belong to the
2946 * next horizontal stripe.
2948 * If dumppix module param is set, _parse_data just dumps the incoming segments,
2949 * verbatim, in order, into the frame. When used with vidcat -f ppm -s 640x480
2950 * this puts the data on the standard output and can be analyzed with the
2951 * parseppm.c utility I wrote. That's a much faster way for figuring out how
2952 * these data are scrambled.
2955 /* Converts from raw, uncompressed segments at pIn0 to a YUV420P frame at pOut0.
2957 * FIXME: Currently only handles width and height that are multiples of 16
2960 yuv420raw_to_yuv420p(struct ov511_frame *frame,
2961 unsigned char *pIn0, unsigned char *pOut0)
2964 unsigned char *pIn, *pOut, *pOutLine;
2965 const unsigned int a = frame->rawwidth * frame->rawheight;
2966 const unsigned int w = frame->rawwidth / 2;
2970 pOutLine = pOut0 + a;
2971 for (y = 0; y < frame->rawheight - 1; y += 16) {
2973 for (x = 0; x < frame->rawwidth - 1; x += 16) {
2974 make_8x8(pIn, pOut, w);
2975 make_8x8(pIn + 64, pOut + a/4, w);
2986 for (y = 0; y < frame->rawheight - 1; y += 8) {
2988 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2989 make_8x8(pIn, pOut, frame->rawwidth);
2997 pOutLine += 8 * frame->rawwidth;
3001 /**********************************************************************
3005 **********************************************************************/
3008 request_decompressor(struct usb_ov511 *ov)
3010 if (ov->bclass == BCL_OV511 || ov->bclass == BCL_OV518) {
3011 err("No decompressor available");
3013 err("Unknown bridge");
3020 decompress(struct usb_ov511 *ov, struct ov511_frame *frame,
3021 unsigned char *pIn0, unsigned char *pOut0)
3023 if (!ov->decomp_ops)
3024 if (request_decompressor(ov))
3029 /**********************************************************************
3033 **********************************************************************/
3035 /* Fuses even and odd fields together, and doubles width.
3036 * INPUT: an odd field followed by an even field at pIn0, in YUV planar format
3037 * OUTPUT: a normal YUV planar image, with correct aspect ratio
3040 deinterlace(struct ov511_frame *frame, int rawformat,
3041 unsigned char *pIn0, unsigned char *pOut0)
3043 const int fieldheight = frame->rawheight / 2;
3044 const int fieldpix = fieldheight * frame->rawwidth;
3045 const int w = frame->width;
3047 unsigned char *pInEven, *pInOdd, *pOut;
3049 PDEBUG(5, "fieldheight=%d", fieldheight);
3051 if (frame->rawheight != frame->height) {
3052 err("invalid height");
3056 if ((frame->rawwidth * 2) != frame->width) {
3057 err("invalid width");
3063 pInEven = pInOdd + fieldpix;
3065 for (y = 0; y < fieldheight; y++) {
3066 for (x = 0; x < frame->rawwidth; x++) {
3068 *(pOut+1) = *pInEven++;
3069 *(pOut+w) = *pInOdd;
3070 *(pOut+w+1) = *pInOdd++;
3076 if (rawformat == RAWFMT_YUV420) {
3078 pInOdd = pIn0 + fieldpix * 2;
3079 pInEven = pInOdd + fieldpix / 4;
3080 for (y = 0; y < fieldheight / 2; y++) {
3081 for (x = 0; x < frame->rawwidth / 2; x++) {
3083 *(pOut+1) = *pInEven++;
3084 *(pOut+w/2) = *pInOdd;
3085 *(pOut+w/2+1) = *pInOdd++;
3091 pInOdd = pIn0 + fieldpix * 2 + fieldpix / 2;
3092 pInEven = pInOdd + fieldpix / 4;
3093 for (y = 0; y < fieldheight / 2; y++) {
3094 for (x = 0; x < frame->rawwidth / 2; x++) {
3096 *(pOut+1) = *pInEven++;
3097 *(pOut+w/2) = *pInOdd;
3098 *(pOut+w/2+1) = *pInOdd++;
3107 ov51x_postprocess_grey(struct usb_ov511 *ov, struct ov511_frame *frame)
3109 /* Deinterlace frame, if necessary */
3110 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3111 if (frame->compressed)
3112 decompress(ov, frame, frame->rawdata,
3115 yuv400raw_to_yuv400p(frame, frame->rawdata,
3118 deinterlace(frame, RAWFMT_YUV400, frame->tempdata,
3121 if (frame->compressed)
3122 decompress(ov, frame, frame->rawdata,
3125 yuv400raw_to_yuv400p(frame, frame->rawdata,
3130 /* Process raw YUV420 data into standard YUV420P */
3132 ov51x_postprocess_yuv420(struct usb_ov511 *ov, struct ov511_frame *frame)
3134 /* Deinterlace frame, if necessary */
3135 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3136 if (frame->compressed)
3137 decompress(ov, frame, frame->rawdata, frame->tempdata);
3139 yuv420raw_to_yuv420p(frame, frame->rawdata,
3142 deinterlace(frame, RAWFMT_YUV420, frame->tempdata,
3145 if (frame->compressed)
3146 decompress(ov, frame, frame->rawdata, frame->data);
3148 yuv420raw_to_yuv420p(frame, frame->rawdata,
3153 /* Post-processes the specified frame. This consists of:
3154 * 1. Decompress frame, if necessary
3155 * 2. Deinterlace frame and scale to proper size, if necessary
3156 * 3. Convert from YUV planar to destination format, if necessary
3157 * 4. Fix the RGB offset, if necessary
3160 ov51x_postprocess(struct usb_ov511 *ov, struct ov511_frame *frame)
3163 memset(frame->data, 0,
3164 MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3165 PDEBUG(4, "Dumping %d bytes", frame->bytes_recvd);
3166 memcpy(frame->data, frame->rawdata, frame->bytes_recvd);
3168 switch (frame->format) {
3169 case VIDEO_PALETTE_GREY:
3170 ov51x_postprocess_grey(ov, frame);
3172 case VIDEO_PALETTE_YUV420:
3173 case VIDEO_PALETTE_YUV420P:
3174 ov51x_postprocess_yuv420(ov, frame);
3177 err("Cannot convert data to %s",
3178 symbolic(v4l1_plist, frame->format));
3183 /**********************************************************************
3185 * OV51x data transfer, IRQ handler
3187 **********************************************************************/
3190 ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3193 int pnum = in[ov->packet_size - 1]; /* Get packet number */
3194 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3195 struct ov511_frame *frame = &ov->frame[ov->curframe];
3198 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3199 * byte non-zero. The EOF packet has image width/height in the
3200 * 10th and 11th bytes. The 9th byte is given as follows:
3203 * 6: compression enabled
3204 * 5: 422/420/400 modes
3205 * 4: 422/420/400 modes
3207 * 2: snapshot button on
3213 dev_info(&ov->dev->dev,
3214 "ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
3215 pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
3216 in[7], in[8], in[9], in[10], in[11]);
3219 /* Check for SOF/EOF packet */
3220 if ((in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) ||
3226 ts = (struct timeval *)(frame->data
3227 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3228 do_gettimeofday(ts);
3230 /* Get the actual frame size from the EOF header */
3231 frame->rawwidth = ((int)(in[9]) + 1) * 8;
3232 frame->rawheight = ((int)(in[10]) + 1) * 8;
3234 PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
3235 ov->curframe, pnum, frame->rawwidth, frame->rawheight,
3236 frame->bytes_recvd);
3238 /* Validate the header data */
3239 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3240 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight,
3243 /* Don't allow byte count to exceed buffer size */
3244 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3246 if (frame->scanstate == STATE_LINES) {
3249 frame->grabstate = FRAME_DONE;
3250 wake_up_interruptible(&frame->wq);
3252 /* If next frame is ready or grabbing,
3254 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3255 if (ov->frame[nextf].grabstate == FRAME_READY
3256 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3257 ov->curframe = nextf;
3258 ov->frame[nextf].scanstate = STATE_SCANNING;
3260 if (frame->grabstate == FRAME_DONE) {
3261 PDEBUG(4, "** Frame done **");
3263 PDEBUG(4, "Frame not ready? state = %d",
3264 ov->frame[nextf].grabstate);
3270 PDEBUG(5, "Frame done, but not scanning");
3272 /* Image corruption caused by misplaced frame->segment = 0
3273 * fixed by carlosf@conectiva.com.br
3277 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3279 /* Check to see if it's a snapshot frame */
3280 /* FIXME?? Should the snapshot reset go here? Performance? */
3282 frame->snapshot = 1;
3283 PDEBUG(3, "snapshot detected");
3286 frame->scanstate = STATE_LINES;
3287 frame->bytes_recvd = 0;
3288 frame->compressed = in[8] & 0x40;
3292 /* Are we in a frame? */
3293 if (frame->scanstate != STATE_LINES) {
3294 PDEBUG(5, "Not in a frame; packet skipped");
3298 /* If frame start, skip header */
3299 if (frame->bytes_recvd == 0)
3304 num = n - offset - 1;
3306 /* Dump all data exactly as received */
3308 frame->bytes_recvd += n - 1;
3309 if (frame->bytes_recvd <= max_raw)
3310 memcpy(frame->rawdata + frame->bytes_recvd - (n - 1),
3313 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3314 frame->bytes_recvd - max_raw);
3315 } else if (!frame->compressed && !remove_zeros) {
3316 frame->bytes_recvd += num;
3317 if (frame->bytes_recvd <= max_raw)
3318 memcpy(frame->rawdata + frame->bytes_recvd - num,
3321 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3322 frame->bytes_recvd - max_raw);
3323 } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
3324 int b, read = 0, allzero, copied = 0;
3326 frame->bytes_recvd += 32 - offset; // Bytes out
3327 memcpy(frame->rawdata, in + offset, 32 - offset);
3331 while (read < n - 1) {
3333 for (b = 0; b < 32; b++) {
3343 if (frame->bytes_recvd + copied + 32 <= max_raw)
3345 memcpy(frame->rawdata
3346 + frame->bytes_recvd + copied,
3350 PDEBUG(3, "Raw data buffer overrun!!");
3356 frame->bytes_recvd += copied;
3361 ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3363 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3364 struct ov511_frame *frame = &ov->frame[ov->curframe];
3367 /* Don't copy the packet number byte */
3368 if (ov->packet_numbering)
3371 /* A false positive here is likely, until OVT gives me
3372 * the definitive SOF/EOF format */
3373 if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
3375 dev_info(&ov->dev->dev,
3376 "ph: %2x %2x %2x %2x %2x %2x %2x %2x\n",
3377 in[0], in[1], in[2], in[3], in[4], in[5],
3381 if (frame->scanstate == STATE_LINES) {
3382 PDEBUG(4, "Detected frame end/start");
3384 } else { //scanstate == STATE_SCANNING
3386 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3394 ts = (struct timeval *)(frame->data
3395 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3396 do_gettimeofday(ts);
3398 PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
3400 (int)(in[9]), (int)(in[10]), frame->bytes_recvd);
3402 // FIXME: Since we don't know the header formats yet,
3403 // there is no way to know what the actual image size is
3404 frame->rawwidth = frame->width;
3405 frame->rawheight = frame->height;
3407 /* Validate the header data */
3408 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3409 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
3411 /* Don't allow byte count to exceed buffer size */
3412 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3414 if (frame->scanstate == STATE_LINES) {
3417 frame->grabstate = FRAME_DONE;
3418 wake_up_interruptible(&frame->wq);
3420 /* If next frame is ready or grabbing,
3422 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3423 if (ov->frame[nextf].grabstate == FRAME_READY
3424 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3425 ov->curframe = nextf;
3426 ov->frame[nextf].scanstate = STATE_SCANNING;
3427 frame = &ov->frame[nextf];
3429 if (frame->grabstate == FRAME_DONE) {
3430 PDEBUG(4, "** Frame done **");
3432 PDEBUG(4, "Frame not ready? state = %d",
3433 ov->frame[nextf].grabstate);
3437 PDEBUG(4, "SOF dropped (no active frame)");
3438 return; /* Nowhere to store this frame */
3442 PDEBUG(4, "Starting capture on frame %d", frame->framenum);
3444 // Snapshot not reverse-engineered yet.
3446 /* Check to see if it's a snapshot frame */
3447 /* FIXME?? Should the snapshot reset go here? Performance? */
3449 frame->snapshot = 1;
3450 PDEBUG(3, "snapshot detected");
3453 frame->scanstate = STATE_LINES;
3454 frame->bytes_recvd = 0;
3455 frame->compressed = 1;
3458 /* Are we in a frame? */
3459 if (frame->scanstate != STATE_LINES) {
3460 PDEBUG(4, "scanstate: no SOF yet");
3464 /* Dump all data exactly as received */
3466 frame->bytes_recvd += n;
3467 if (frame->bytes_recvd <= max_raw)
3468 memcpy(frame->rawdata + frame->bytes_recvd - n, in, n);
3470 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3471 frame->bytes_recvd - max_raw);
3473 /* All incoming data are divided into 8-byte segments. If the
3474 * segment contains all zero bytes, it must be skipped. These
3475 * zero-segments allow the OV518 to mainain a constant data rate
3476 * regardless of the effectiveness of the compression. Segments
3477 * are aligned relative to the beginning of each isochronous
3478 * packet. The first segment in each image is a header (the
3479 * decompressor skips it later).
3482 int b, read = 0, allzero, copied = 0;
3486 for (b = 0; b < 8; b++) {
3496 if (frame->bytes_recvd + copied + 8 <= max_raw)
3498 memcpy(frame->rawdata
3499 + frame->bytes_recvd + copied,
3503 PDEBUG(3, "Raw data buffer overrun!!");
3508 frame->bytes_recvd += copied;
3513 ov51x_isoc_irq(struct urb *urb)
3516 struct usb_ov511 *ov;
3517 struct ov511_sbuf *sbuf;
3519 if (!urb->context) {
3520 PDEBUG(4, "no context");
3524 sbuf = urb->context;
3527 if (!ov || !ov->dev || !ov->user) {
3528 PDEBUG(4, "no device, or not open");
3532 if (!ov->streaming) {
3533 PDEBUG(4, "hmmm... not streaming, but got interrupt");
3537 if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
3538 PDEBUG(4, "URB unlinked");
3542 if (urb->status != -EINPROGRESS && urb->status != 0) {
3543 err("ERROR: urb->status=%d: %s", urb->status,
3544 symbolic(urb_errlist, urb->status));
3547 /* Copy the data received into our frame buffer */
3548 PDEBUG(5, "sbuf[%d]: Moving %d packets", sbuf->n,
3549 urb->number_of_packets);
3550 for (i = 0; i < urb->number_of_packets; i++) {
3551 /* Warning: Don't call *_move_data() if no frame active! */
3552 if (ov->curframe >= 0) {
3553 int n = urb->iso_frame_desc[i].actual_length;
3554 int st = urb->iso_frame_desc[i].status;
3555 unsigned char *cdata;
3557 urb->iso_frame_desc[i].actual_length = 0;
3558 urb->iso_frame_desc[i].status = 0;
3560 cdata = urb->transfer_buffer
3561 + urb->iso_frame_desc[i].offset;
3564 PDEBUG(4, "Zero-length packet");
3569 PDEBUG(2, "data error: [%d] len=%d, status=%d",
3572 if (ov->bclass == BCL_OV511)
3573 ov511_move_data(ov, cdata, n);
3574 else if (ov->bclass == BCL_OV518)
3575 ov518_move_data(ov, cdata, n);
3577 err("Unknown bridge device (%d)", ov->bridge);
3579 } else if (waitqueue_active(&ov->wq)) {
3580 wake_up_interruptible(&ov->wq);
3584 /* Resubmit this URB */
3586 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
3587 err("usb_submit_urb() ret %d", i);
3592 /****************************************************************************
3594 * Stream initialization and termination
3596 ***************************************************************************/
3599 ov51x_init_isoc(struct usb_ov511 *ov)
3602 int fx, err, n, i, size;
3604 PDEBUG(3, "*** Initializing capture ***");
3608 if (ov->bridge == BRG_OV511) {
3613 else if (cams == 3 || cams == 4)
3616 err("\"cams\" parameter too high!");
3619 } else if (ov->bridge == BRG_OV511PLUS) {
3624 else if (cams == 3 || cams == 4)
3626 else if (cams >= 5 && cams <= 8)
3628 else if (cams >= 9 && cams <= 31)
3631 err("\"cams\" parameter too high!");
3634 } else if (ov->bclass == BCL_OV518) {
3639 else if (cams == 3 || cams == 4)
3641 else if (cams >= 5 && cams <= 8)
3644 err("\"cams\" parameter too high!");
3648 err("invalid bridge type");
3652 // FIXME: OV518 is hardcoded to 15 FPS (alternate 5) for now
3653 if (ov->bclass == BCL_OV518) {
3654 if (packetsize == -1) {
3655 ov518_set_packet_size(ov, 640);
3657 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3659 ov518_set_packet_size(ov, packetsize);
3662 if (packetsize == -1) {
3663 ov511_set_packet_size(ov, size);
3665 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3667 ov511_set_packet_size(ov, packetsize);
3671 for (n = 0; n < OV511_NUMSBUF; n++) {
3672 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
3674 err("init isoc: usb_alloc_urb ret. NULL");
3675 for (i = 0; i < n; i++)
3676 usb_free_urb(ov->sbuf[i].urb);
3679 ov->sbuf[n].urb = urb;
3681 urb->context = &ov->sbuf[n];
3682 urb->pipe = usb_rcvisocpipe(ov->dev, OV511_ENDPOINT_ADDRESS);
3683 urb->transfer_flags = URB_ISO_ASAP;
3684 urb->transfer_buffer = ov->sbuf[n].data;
3685 urb->complete = ov51x_isoc_irq;
3686 urb->number_of_packets = FRAMES_PER_DESC;
3687 urb->transfer_buffer_length = ov->packet_size * FRAMES_PER_DESC;
3689 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
3690 urb->iso_frame_desc[fx].offset = ov->packet_size * fx;
3691 urb->iso_frame_desc[fx].length = ov->packet_size;
3697 for (n = 0; n < OV511_NUMSBUF; n++) {
3698 ov->sbuf[n].urb->dev = ov->dev;
3699 err = usb_submit_urb(ov->sbuf[n].urb, GFP_KERNEL);
3701 err("init isoc: usb_submit_urb(%d) ret %d", n, err);
3710 ov51x_unlink_isoc(struct usb_ov511 *ov)
3714 /* Unschedule all of the iso td's */
3715 for (n = OV511_NUMSBUF - 1; n >= 0; n--) {
3716 if (ov->sbuf[n].urb) {
3717 usb_kill_urb(ov->sbuf[n].urb);
3718 usb_free_urb(ov->sbuf[n].urb);
3719 ov->sbuf[n].urb = NULL;
3725 ov51x_stop_isoc(struct usb_ov511 *ov)
3727 if (!ov->streaming || !ov->dev)
3730 PDEBUG(3, "*** Stopping capture ***");
3732 if (ov->bclass == BCL_OV518)
3733 ov518_set_packet_size(ov, 0);
3735 ov511_set_packet_size(ov, 0);
3739 ov51x_unlink_isoc(ov);
3743 ov51x_new_frame(struct usb_ov511 *ov, int framenum)
3745 struct ov511_frame *frame;
3748 PDEBUG(4, "ov->curframe = %d, framenum = %d", ov->curframe, framenum);
3753 /* If we're not grabbing a frame right now and the other frame is */
3754 /* ready to be grabbed into, then use it instead */
3755 if (ov->curframe == -1) {
3756 newnum = (framenum - 1 + OV511_NUMFRAMES) % OV511_NUMFRAMES;
3757 if (ov->frame[newnum].grabstate == FRAME_READY)
3762 frame = &ov->frame[framenum];
3764 PDEBUG(4, "framenum = %d, width = %d, height = %d", framenum,
3765 frame->width, frame->height);
3767 frame->grabstate = FRAME_GRABBING;
3768 frame->scanstate = STATE_SCANNING;
3769 frame->snapshot = 0;
3771 ov->curframe = framenum;
3773 /* Make sure it's not too big */
3774 if (frame->width > ov->maxwidth)
3775 frame->width = ov->maxwidth;
3777 frame->width &= ~7L; /* Multiple of 8 */
3779 if (frame->height > ov->maxheight)
3780 frame->height = ov->maxheight;
3782 frame->height &= ~3L; /* Multiple of 4 */
3787 /****************************************************************************
3791 ***************************************************************************/
3794 * - You must acquire buf_lock before entering this function.
3795 * - Because this code will free any non-null pointer, you must be sure to null
3796 * them if you explicitly free them somewhere else!
3799 ov51x_do_dealloc(struct usb_ov511 *ov)
3802 PDEBUG(4, "entered");
3805 rvfree(ov->fbuf, OV511_NUMFRAMES
3806 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3813 vfree(ov->tempfbuf);
3814 ov->tempfbuf = NULL;
3816 for (i = 0; i < OV511_NUMSBUF; i++) {
3817 kfree(ov->sbuf[i].data);
3818 ov->sbuf[i].data = NULL;
3821 for (i = 0; i < OV511_NUMFRAMES; i++) {
3822 ov->frame[i].data = NULL;
3823 ov->frame[i].rawdata = NULL;
3824 ov->frame[i].tempdata = NULL;
3825 if (ov->frame[i].compbuf) {
3826 free_page((unsigned long) ov->frame[i].compbuf);
3827 ov->frame[i].compbuf = NULL;
3831 PDEBUG(4, "buffer memory deallocated");
3832 ov->buf_state = BUF_NOT_ALLOCATED;
3833 PDEBUG(4, "leaving");
3837 ov51x_alloc(struct usb_ov511 *ov)
3840 const int w = ov->maxwidth;
3841 const int h = ov->maxheight;
3842 const int data_bufsize = OV511_NUMFRAMES * MAX_DATA_SIZE(w, h);
3843 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h);
3845 PDEBUG(4, "entered");
3846 mutex_lock(&ov->buf_lock);
3848 if (ov->buf_state == BUF_ALLOCATED)
3851 ov->fbuf = rvmalloc(data_bufsize);
3855 ov->rawfbuf = vmalloc(raw_bufsize);
3859 memset(ov->rawfbuf, 0, raw_bufsize);
3861 ov->tempfbuf = vmalloc(raw_bufsize);
3865 memset(ov->tempfbuf, 0, raw_bufsize);
3867 for (i = 0; i < OV511_NUMSBUF; i++) {
3868 ov->sbuf[i].data = kmalloc(FRAMES_PER_DESC *
3869 MAX_FRAME_SIZE_PER_DESC, GFP_KERNEL);
3870 if (!ov->sbuf[i].data)
3873 PDEBUG(4, "sbuf[%d] @ %p", i, ov->sbuf[i].data);
3876 for (i = 0; i < OV511_NUMFRAMES; i++) {
3877 ov->frame[i].data = ov->fbuf + i * MAX_DATA_SIZE(w, h);
3878 ov->frame[i].rawdata = ov->rawfbuf
3879 + i * MAX_RAW_DATA_SIZE(w, h);
3880 ov->frame[i].tempdata = ov->tempfbuf
3881 + i * MAX_RAW_DATA_SIZE(w, h);
3883 ov->frame[i].compbuf =
3884 (unsigned char *) __get_free_page(GFP_KERNEL);
3885 if (!ov->frame[i].compbuf)
3888 PDEBUG(4, "frame[%d] @ %p", i, ov->frame[i].data);
3891 ov->buf_state = BUF_ALLOCATED;
3893 mutex_unlock(&ov->buf_lock);
3894 PDEBUG(4, "leaving");
3897 ov51x_do_dealloc(ov);
3898 mutex_unlock(&ov->buf_lock);
3899 PDEBUG(4, "errored");
3904 ov51x_dealloc(struct usb_ov511 *ov)
3906 PDEBUG(4, "entered");
3907 mutex_lock(&ov->buf_lock);
3908 ov51x_do_dealloc(ov);
3909 mutex_unlock(&ov->buf_lock);
3910 PDEBUG(4, "leaving");
3913 /****************************************************************************
3917 ***************************************************************************/
3920 ov51x_v4l1_open(struct file *file)
3922 struct video_device *vdev = video_devdata(file);
3923 struct usb_ov511 *ov = video_get_drvdata(vdev);
3926 PDEBUG(4, "opening");
3928 mutex_lock(&ov->lock);
3936 /* In case app doesn't set them... */
3937 err = ov51x_set_default_params(ov);
3941 /* Make sure frames are reset */
3942 for (i = 0; i < OV511_NUMFRAMES; i++) {
3943 ov->frame[i].grabstate = FRAME_UNUSED;
3944 ov->frame[i].bytes_read = 0;
3947 /* If compression is on, make sure now that a
3948 * decompressor can be loaded */
3949 if (ov->compress && !ov->decomp_ops) {
3950 err = request_decompressor(ov);
3951 if (err && !dumppix)
3955 err = ov51x_alloc(ov);
3959 err = ov51x_init_isoc(ov);
3966 file->private_data = vdev;
3968 if (ov->led_policy == LED_AUTO)
3969 ov51x_led_control(ov, 1);
3972 mutex_unlock(&ov->lock);
3977 ov51x_v4l1_close(struct file *file)
3979 struct video_device *vdev = file->private_data;
3980 struct usb_ov511 *ov = video_get_drvdata(vdev);
3982 PDEBUG(4, "ov511_close");
3984 mutex_lock(&ov->lock);
3987 ov51x_stop_isoc(ov);
3989 if (ov->led_policy == LED_AUTO)
3990 ov51x_led_control(ov, 0);
3995 mutex_unlock(&ov->lock);
3997 /* Device unplugged while open. Only a minimum of unregistration is done
3998 * here; the disconnect callback already did the rest. */
4000 mutex_lock(&ov->cbuf_lock);
4003 mutex_unlock(&ov->cbuf_lock);
4010 file->private_data = NULL;
4014 /* Do not call this function directly! */
4016 ov51x_v4l1_ioctl_internal(struct file *file, unsigned int cmd, void *arg)
4018 struct video_device *vdev = file->private_data;
4019 struct usb_ov511 *ov = video_get_drvdata(vdev);
4020 PDEBUG(5, "IOCtl: 0x%X", cmd);
4028 struct video_capability *b = arg;
4030 PDEBUG(4, "VIDIOCGCAP");
4032 memset(b, 0, sizeof(struct video_capability));
4033 sprintf(b->name, "%s USB Camera",
4034 symbolic(brglist, ov->bridge));
4035 b->type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE;
4036 b->channels = ov->num_inputs;
4038 b->maxwidth = ov->maxwidth;
4039 b->maxheight = ov->maxheight;
4040 b->minwidth = ov->minwidth;
4041 b->minheight = ov->minheight;
4047 struct video_channel *v = arg;
4049 PDEBUG(4, "VIDIOCGCHAN");
4051 if ((unsigned)(v->channel) >= ov->num_inputs) {
4052 err("Invalid channel (%d)", v->channel);
4057 v->type = VIDEO_TYPE_CAMERA;
4059 // v->flags |= (ov->has_decoder) ? VIDEO_VC_NORM : 0;
4061 decoder_get_input_name(ov, v->channel, v->name);
4067 struct video_channel *v = arg;
4070 PDEBUG(4, "VIDIOCSCHAN");
4072 /* Make sure it's not a camera */
4073 if (!ov->has_decoder) {
4074 if (v->channel == 0)
4080 if (v->norm != VIDEO_MODE_PAL &&
4081 v->norm != VIDEO_MODE_NTSC &&
4082 v->norm != VIDEO_MODE_SECAM &&
4083 v->norm != VIDEO_MODE_AUTO) {
4084 err("Invalid norm (%d)", v->norm);
4088 if ((unsigned)(v->channel) >= ov->num_inputs) {
4089 err("Invalid channel (%d)", v->channel);
4093 err = decoder_set_input(ov, v->channel);
4097 err = decoder_set_norm(ov, v->norm);
4105 struct video_picture *p = arg;
4107 PDEBUG(4, "VIDIOCGPICT");
4109 memset(p, 0, sizeof(struct video_picture));
4110 if (sensor_get_picture(ov, p))
4113 /* Can we get these from frame[0]? -claudio? */
4114 p->depth = ov->frame[0].depth;
4115 p->palette = ov->frame[0].format;
4121 struct video_picture *p = arg;
4124 PDEBUG(4, "VIDIOCSPICT");
4126 if (!get_depth(p->palette))
4129 if (sensor_set_picture(ov, p))
4132 if (force_palette && p->palette != force_palette) {
4133 dev_info(&ov->dev->dev, "Palette rejected (%s)\n",
4134 symbolic(v4l1_plist, p->palette));
4138 // FIXME: Format should be independent of frames
4139 if (p->palette != ov->frame[0].format) {
4140 PDEBUG(4, "Detected format change");
4142 rc = ov51x_wait_frames_inactive(ov);
4146 mode_init_regs(ov, ov->frame[0].width,
4147 ov->frame[0].height, p->palette, ov->sub_flag);
4150 PDEBUG(4, "Setting depth=%d, palette=%s",
4151 p->depth, symbolic(v4l1_plist, p->palette));
4153 for (i = 0; i < OV511_NUMFRAMES; i++) {
4154 ov->frame[i].depth = p->depth;
4155 ov->frame[i].format = p->palette;
4160 case VIDIOCGCAPTURE:
4164 PDEBUG(4, "VIDIOCGCAPTURE");
4169 case VIDIOCSCAPTURE:
4171 struct video_capture *vc = arg;
4173 PDEBUG(4, "VIDIOCSCAPTURE");
4189 if (vc->height == 0)
4194 ov->subw = vc->width;
4195 ov->subh = vc->height;
4201 struct video_window *vw = arg;
4204 PDEBUG(4, "VIDIOCSWIN: %dx%d", vw->width, vw->height);
4211 if (vw->height != ov->maxheight)
4213 if (vw->width != ov->maxwidth)
4217 rc = ov51x_wait_frames_inactive(ov);
4221 rc = mode_init_regs(ov, vw->width, vw->height,
4222 ov->frame[0].format, ov->sub_flag);
4226 for (i = 0; i < OV511_NUMFRAMES; i++) {
4227 ov->frame[i].width = vw->width;
4228 ov->frame[i].height = vw->height;
4235 struct video_window *vw = arg;
4237 memset(vw, 0, sizeof(struct video_window));
4238 vw->x = 0; /* FIXME */
4240 vw->width = ov->frame[0].width;
4241 vw->height = ov->frame[0].height;
4244 PDEBUG(4, "VIDIOCGWIN: %dx%d", vw->width, vw->height);
4250 struct video_mbuf *vm = arg;
4253 PDEBUG(4, "VIDIOCGMBUF");
4255 memset(vm, 0, sizeof(struct video_mbuf));
4256 vm->size = OV511_NUMFRAMES
4257 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4258 vm->frames = OV511_NUMFRAMES;
4261 for (i = 1; i < OV511_NUMFRAMES; i++) {
4262 vm->offsets[i] = vm->offsets[i-1]
4263 + MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4268 case VIDIOCMCAPTURE:
4270 struct video_mmap *vm = arg;
4272 unsigned int f = vm->frame;
4274 PDEBUG(4, "VIDIOCMCAPTURE: frame: %d, %dx%d, %s", f, vm->width,
4275 vm->height, symbolic(v4l1_plist, vm->format));
4277 depth = get_depth(vm->format);
4279 PDEBUG(2, "VIDIOCMCAPTURE: invalid format (%s)",
4280 symbolic(v4l1_plist, vm->format));
4284 if (f >= OV511_NUMFRAMES) {
4285 err("VIDIOCMCAPTURE: invalid frame (%d)", f);
4289 if (vm->width > ov->maxwidth
4290 || vm->height > ov->maxheight) {
4291 err("VIDIOCMCAPTURE: requested dimensions too big");
4295 if (ov->frame[f].grabstate == FRAME_GRABBING) {
4296 PDEBUG(4, "VIDIOCMCAPTURE: already grabbing");
4300 if (force_palette && (vm->format != force_palette)) {
4301 PDEBUG(2, "palette rejected (%s)",
4302 symbolic(v4l1_plist, vm->format));
4306 if ((ov->frame[f].width != vm->width) ||
4307 (ov->frame[f].height != vm->height) ||
4308 (ov->frame[f].format != vm->format) ||
4309 (ov->frame[f].sub_flag != ov->sub_flag) ||
4310 (ov->frame[f].depth != depth)) {
4311 PDEBUG(4, "VIDIOCMCAPTURE: change in image parameters");
4313 rc = ov51x_wait_frames_inactive(ov);
4317 rc = mode_init_regs(ov, vm->width, vm->height,
4318 vm->format, ov->sub_flag);
4321 PDEBUG(1, "Got error while initializing regs ");
4325 ov->frame[f].width = vm->width;
4326 ov->frame[f].height = vm->height;
4327 ov->frame[f].format = vm->format;
4328 ov->frame[f].sub_flag = ov->sub_flag;
4329 ov->frame[f].depth = depth;
4332 /* Mark it as ready */
4333 ov->frame[f].grabstate = FRAME_READY;
4335 PDEBUG(4, "VIDIOCMCAPTURE: renewing frame %d", f);
4337 return ov51x_new_frame(ov, f);
4341 unsigned int fnum = *((unsigned int *) arg);
4342 struct ov511_frame *frame;
4345 if (fnum >= OV511_NUMFRAMES) {
4346 err("VIDIOCSYNC: invalid frame (%d)", fnum);
4350 frame = &ov->frame[fnum];
4352 PDEBUG(4, "syncing to frame %d, grabstate = %d", fnum,
4355 switch (frame->grabstate) {
4359 case FRAME_GRABBING:
4365 rc = wait_event_interruptible(frame->wq,
4366 (frame->grabstate == FRAME_DONE)
4367 || (frame->grabstate == FRAME_ERROR));
4372 if (frame->grabstate == FRAME_ERROR) {
4373 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4379 if (ov->snap_enabled && !frame->snapshot) {
4380 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4385 frame->grabstate = FRAME_UNUSED;
4387 /* Reset the hardware snapshot button */
4388 /* FIXME - Is this the best place for this? */
4389 if ((ov->snap_enabled) && (frame->snapshot)) {
4390 frame->snapshot = 0;
4391 ov51x_clear_snapshot(ov);
4394 /* Decompression, format conversion, etc... */
4395 ov51x_postprocess(ov, frame);
4404 struct video_buffer *vb = arg;
4406 PDEBUG(4, "VIDIOCGFBUF");
4408 memset(vb, 0, sizeof(struct video_buffer));
4414 struct video_unit *vu = arg;
4416 PDEBUG(4, "VIDIOCGUNIT");
4418 memset(vu, 0, sizeof(struct video_unit));
4420 vu->video = ov->vdev->minor;
4421 vu->vbi = VIDEO_NO_UNIT;
4422 vu->radio = VIDEO_NO_UNIT;
4423 vu->audio = VIDEO_NO_UNIT;
4424 vu->teletext = VIDEO_NO_UNIT;
4430 struct ov511_i2c_struct *w = arg;
4432 return i2c_w_slave(ov, w->slave, w->reg, w->value, w->mask);
4436 struct ov511_i2c_struct *r = arg;
4439 rc = i2c_r_slave(ov, r->slave, r->reg);
4447 PDEBUG(3, "Unsupported IOCtl: 0x%X", cmd);
4448 return -ENOIOCTLCMD;
4455 ov51x_v4l1_ioctl(struct file *file,
4456 unsigned int cmd, unsigned long arg)
4458 struct video_device *vdev = file->private_data;
4459 struct usb_ov511 *ov = video_get_drvdata(vdev);
4462 if (mutex_lock_interruptible(&ov->lock))
4465 rc = video_usercopy(file, cmd, arg, ov51x_v4l1_ioctl_internal);
4467 mutex_unlock(&ov->lock);
4472 ov51x_v4l1_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos)
4474 struct video_device *vdev = file->private_data;
4475 int noblock = file->f_flags&O_NONBLOCK;
4476 unsigned long count = cnt;
4477 struct usb_ov511 *ov = video_get_drvdata(vdev);
4478 int i, rc = 0, frmx = -1;
4479 struct ov511_frame *frame;
4481 if (mutex_lock_interruptible(&ov->lock))
4484 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock);
4486 if (!vdev || !buf) {
4496 // FIXME: Only supports two frames
4497 /* See if a frame is completed, then use it. */
4498 if (ov->frame[0].grabstate >= FRAME_DONE) /* _DONE or _ERROR */
4500 else if (ov->frame[1].grabstate >= FRAME_DONE)/* _DONE or _ERROR */
4503 /* If nonblocking we return immediately */
4504 if (noblock && (frmx == -1)) {
4509 /* If no FRAME_DONE, look for a FRAME_GRABBING state. */
4510 /* See if a frame is in process (grabbing), then use it. */
4512 if (ov->frame[0].grabstate == FRAME_GRABBING)
4514 else if (ov->frame[1].grabstate == FRAME_GRABBING)
4518 /* If no frame is active, start one. */
4520 if ((rc = ov51x_new_frame(ov, frmx = 0))) {
4521 err("read: ov51x_new_frame error");
4526 frame = &ov->frame[frmx];
4534 /* Wait while we're grabbing the image */
4535 PDEBUG(4, "Waiting image grabbing");
4536 rc = wait_event_interruptible(frame->wq,
4537 (frame->grabstate == FRAME_DONE)
4538 || (frame->grabstate == FRAME_ERROR));
4543 PDEBUG(4, "Got image, frame->grabstate = %d", frame->grabstate);
4544 PDEBUG(4, "bytes_recvd = %d", frame->bytes_recvd);
4546 if (frame->grabstate == FRAME_ERROR) {
4547 frame->bytes_read = 0;
4548 err("** ick! ** Errored frame %d", ov->curframe);
4549 if (ov51x_new_frame(ov, frmx)) {
4550 err("read: ov51x_new_frame error");
4557 /* Repeat until we get a snapshot frame */
4558 if (ov->snap_enabled)
4559 PDEBUG(4, "Waiting snapshot frame");
4560 if (ov->snap_enabled && !frame->snapshot) {
4561 frame->bytes_read = 0;
4562 if ((rc = ov51x_new_frame(ov, frmx))) {
4563 err("read: ov51x_new_frame error");
4569 /* Clear the snapshot */
4570 if (ov->snap_enabled && frame->snapshot) {
4571 frame->snapshot = 0;
4572 ov51x_clear_snapshot(ov);
4575 /* Decompression, format conversion, etc... */
4576 ov51x_postprocess(ov, frame);
4578 PDEBUG(4, "frmx=%d, bytes_read=%ld, length=%ld", frmx,
4580 get_frame_length(frame));
4582 /* copy bytes to user space; we allow for partials reads */
4583 // if ((count + frame->bytes_read)
4584 // > get_frame_length((struct ov511_frame *)frame))
4585 // count = frame->scanlength - frame->bytes_read;
4587 /* FIXME - count hardwired to be one frame... */
4588 count = get_frame_length(frame);
4590 PDEBUG(4, "Copy to user space: %ld bytes", count);
4591 if ((i = copy_to_user(buf, frame->data + frame->bytes_read, count))) {
4592 PDEBUG(4, "Copy failed! %d bytes not copied", i);
4597 frame->bytes_read += count;
4598 PDEBUG(4, "{copy} count used=%ld, new bytes_read=%ld",
4599 count, frame->bytes_read);
4601 /* If all data have been read... */
4602 if (frame->bytes_read
4603 >= get_frame_length(frame)) {
4604 frame->bytes_read = 0;
4606 // FIXME: Only supports two frames
4607 /* Mark it as available to be used again. */
4608 ov->frame[frmx].grabstate = FRAME_UNUSED;
4609 if ((rc = ov51x_new_frame(ov, !frmx))) {
4610 err("ov51x_new_frame returned error");
4615 PDEBUG(4, "read finished, returning %ld (sweet)", count);
4617 mutex_unlock(&ov->lock);
4621 mutex_unlock(&ov->lock);
4626 ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4628 struct video_device *vdev = file->private_data;
4629 unsigned long start = vma->vm_start;
4630 unsigned long size = vma->vm_end - vma->vm_start;
4631 struct usb_ov511 *ov = video_get_drvdata(vdev);
4632 unsigned long page, pos;
4634 if (ov->dev == NULL)
4637 PDEBUG(4, "mmap: %ld (%lX) bytes", size, size);
4639 if (size > (((OV511_NUMFRAMES
4640 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
4641 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4644 if (mutex_lock_interruptible(&ov->lock))
4647 pos = (unsigned long)ov->fbuf;
4649 page = vmalloc_to_pfn((void *)pos);
4650 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
4651 mutex_unlock(&ov->lock);
4656 if (size > PAGE_SIZE)
4662 mutex_unlock(&ov->lock);
4666 static const struct v4l2_file_operations ov511_fops = {
4667 .owner = THIS_MODULE,
4668 .open = ov51x_v4l1_open,
4669 .release = ov51x_v4l1_close,
4670 .read = ov51x_v4l1_read,
4671 .mmap = ov51x_v4l1_mmap,
4672 .ioctl = ov51x_v4l1_ioctl,
4675 static struct video_device vdev_template = {
4676 .name = "OV511 USB Camera",
4677 .fops = &ov511_fops,
4678 .release = video_device_release,
4682 /****************************************************************************
4684 * OV511 and sensor configuration
4686 ***************************************************************************/
4688 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
4689 * the same register settings as the OV7610, since they are very similar.
4692 ov7xx0_configure(struct usb_ov511 *ov)
4697 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
4699 * Register 0x0f in the 7610 has the following effects:
4701 * 0x85 (AEC method 1): Best overall, good contrast range
4702 * 0x45 (AEC method 2): Very overexposed
4703 * 0xa5 (spec sheet default): Ok, but the black level is
4704 * shifted resulting in loss of contrast
4705 * 0x05 (old driver setting): very overexposed, too much
4708 static struct ov511_regvals aRegvalsNorm7610[] = {
4709 { OV511_I2C_BUS, 0x10, 0xff },
4710 { OV511_I2C_BUS, 0x16, 0x06 },
4711 { OV511_I2C_BUS, 0x28, 0x24 },
4712 { OV511_I2C_BUS, 0x2b, 0xac },
4713 { OV511_I2C_BUS, 0x12, 0x00 },
4714 { OV511_I2C_BUS, 0x38, 0x81 },
4715 { OV511_I2C_BUS, 0x28, 0x24 }, /* 0c */
4716 { OV511_I2C_BUS, 0x0f, 0x85 }, /* lg's setting */
4717 { OV511_I2C_BUS, 0x15, 0x01 },
4718 { OV511_I2C_BUS, 0x20, 0x1c },
4719 { OV511_I2C_BUS, 0x23, 0x2a },
4720 { OV511_I2C_BUS, 0x24, 0x10 },
4721 { OV511_I2C_BUS, 0x25, 0x8a },
4722 { OV511_I2C_BUS, 0x26, 0xa2 },
4723 { OV511_I2C_BUS, 0x27, 0xc2 },
4724 { OV511_I2C_BUS, 0x2a, 0x04 },
4725 { OV511_I2C_BUS, 0x2c, 0xfe },
4726 { OV511_I2C_BUS, 0x2d, 0x93 },
4727 { OV511_I2C_BUS, 0x30, 0x71 },
4728 { OV511_I2C_BUS, 0x31, 0x60 },
4729 { OV511_I2C_BUS, 0x32, 0x26 },
4730 { OV511_I2C_BUS, 0x33, 0x20 },
4731 { OV511_I2C_BUS, 0x34, 0x48 },
4732 { OV511_I2C_BUS, 0x12, 0x24 },
4733 { OV511_I2C_BUS, 0x11, 0x01 },
4734 { OV511_I2C_BUS, 0x0c, 0x24 },
4735 { OV511_I2C_BUS, 0x0d, 0x24 },
4736 { OV511_DONE_BUS, 0x0, 0x00 },
4739 static struct ov511_regvals aRegvalsNorm7620[] = {
4740 { OV511_I2C_BUS, 0x00, 0x00 },
4741 { OV511_I2C_BUS, 0x01, 0x80 },
4742 { OV511_I2C_BUS, 0x02, 0x80 },
4743 { OV511_I2C_BUS, 0x03, 0xc0 },
4744 { OV511_I2C_BUS, 0x06, 0x60 },
4745 { OV511_I2C_BUS, 0x07, 0x00 },
4746 { OV511_I2C_BUS, 0x0c, 0x24 },
4747 { OV511_I2C_BUS, 0x0c, 0x24 },
4748 { OV511_I2C_BUS, 0x0d, 0x24 },
4749 { OV511_I2C_BUS, 0x11, 0x01 },
4750 { OV511_I2C_BUS, 0x12, 0x24 },
4751 { OV511_I2C_BUS, 0x13, 0x01 },
4752 { OV511_I2C_BUS, 0x14, 0x84 },
4753 { OV511_I2C_BUS, 0x15, 0x01 },
4754 { OV511_I2C_BUS, 0x16, 0x03 },
4755 { OV511_I2C_BUS, 0x17, 0x2f },
4756 { OV511_I2C_BUS, 0x18, 0xcf },
4757 { OV511_I2C_BUS, 0x19, 0x06 },
4758 { OV511_I2C_BUS, 0x1a, 0xf5 },
4759 { OV511_I2C_BUS, 0x1b, 0x00 },
4760 { OV511_I2C_BUS, 0x20, 0x18 },
4761 { OV511_I2C_BUS, 0x21, 0x80 },
4762 { OV511_I2C_BUS, 0x22, 0x80 },
4763 { OV511_I2C_BUS, 0x23, 0x00 },
4764 { OV511_I2C_BUS, 0x26, 0xa2 },
4765 { OV511_I2C_BUS, 0x27, 0xea },
4766 { OV511_I2C_BUS, 0x28, 0x20 },
4767 { OV511_I2C_BUS, 0x29, 0x00 },
4768 { OV511_I2C_BUS, 0x2a, 0x10 },
4769 { OV511_I2C_BUS, 0x2b, 0x00 },
4770 { OV511_I2C_BUS, 0x2c, 0x88 },
4771 { OV511_I2C_BUS, 0x2d, 0x91 },
4772 { OV511_I2C_BUS, 0x2e, 0x80 },
4773 { OV511_I2C_BUS, 0x2f, 0x44 },
4774 { OV511_I2C_BUS, 0x60, 0x27 },
4775 { OV511_I2C_BUS, 0x61, 0x02 },
4776 { OV511_I2C_BUS, 0x62, 0x5f },
4777 { OV511_I2C_BUS, 0x63, 0xd5 },
4778 { OV511_I2C_BUS, 0x64, 0x57 },
4779 { OV511_I2C_BUS, 0x65, 0x83 },
4780 { OV511_I2C_BUS, 0x66, 0x55 },
4781 { OV511_I2C_BUS, 0x67, 0x92 },
4782 { OV511_I2C_BUS, 0x68, 0xcf },
4783 { OV511_I2C_BUS, 0x69, 0x76 },
4784 { OV511_I2C_BUS, 0x6a, 0x22 },
4785 { OV511_I2C_BUS, 0x6b, 0x00 },
4786 { OV511_I2C_BUS, 0x6c, 0x02 },
4787 { OV511_I2C_BUS, 0x6d, 0x44 },
4788 { OV511_I2C_BUS, 0x6e, 0x80 },
4789 { OV511_I2C_BUS, 0x6f, 0x1d },
4790 { OV511_I2C_BUS, 0x70, 0x8b },
4791 { OV511_I2C_BUS, 0x71, 0x00 },
4792 { OV511_I2C_BUS, 0x72, 0x14 },
4793 { OV511_I2C_BUS, 0x73, 0x54 },
4794 { OV511_I2C_BUS, 0x74, 0x00 },
4795 { OV511_I2C_BUS, 0x75, 0x8e },
4796 { OV511_I2C_BUS, 0x76, 0x00 },
4797 { OV511_I2C_BUS, 0x77, 0xff },
4798 { OV511_I2C_BUS, 0x78, 0x80 },
4799 { OV511_I2C_BUS, 0x79, 0x80 },
4800 { OV511_I2C_BUS, 0x7a, 0x80 },
4801 { OV511_I2C_BUS, 0x7b, 0xe2 },
4802 { OV511_I2C_BUS, 0x7c, 0x00 },
4803 { OV511_DONE_BUS, 0x0, 0x00 },
4806 PDEBUG(4, "starting configuration");
4808 /* This looks redundant, but is necessary for WebCam 3 */
4809 ov->primary_i2c_slave = OV7xx0_SID;
4810 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
4813 if (init_ov_sensor(ov) >= 0) {
4814 PDEBUG(1, "OV7xx0 sensor initalized (method 1)");
4816 /* Reset the 76xx */
4817 if (i2c_w(ov, 0x12, 0x80) < 0)
4820 /* Wait for it to initialize */
4825 while (i <= i2c_detect_tries) {
4826 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
4827 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
4835 // Was (i == i2c_detect_tries) previously. This obviously used to always report
4836 // success. Whether anyone actually depended on that bug is unknown
4837 if ((i >= i2c_detect_tries) && (success == 0)) {
4838 err("Failed to read sensor ID. You might not have an");
4839 err("OV7610/20, or it may be not responding. Report");
4840 err("this to " EMAIL);
4841 err("This is only a warning. You can attempt to use");
4842 err("your camera anyway");
4843 // Only issue a warning for now
4846 PDEBUG(1, "OV7xx0 initialized (method 2, %dx)", i+1);
4850 /* Detect sensor (sub)type */
4851 rc = i2c_r(ov, OV7610_REG_COM_I);
4854 err("Error detecting sensor type");
4856 } else if ((rc & 3) == 3) {
4857 dev_info(&ov->dev->dev, "Sensor is an OV7610\n");
4858 ov->sensor = SEN_OV7610;
4859 } else if ((rc & 3) == 1) {
4860 /* I don't know what's different about the 76BE yet. */
4861 if (i2c_r(ov, 0x15) & 1)
4862 dev_info(&ov->dev->dev, "Sensor is an OV7620AE\n");
4864 dev_info(&ov->dev->dev, "Sensor is an OV76BE\n");
4866 /* OV511+ will return all zero isoc data unless we
4867 * configure the sensor as a 7620. Someone needs to
4868 * find the exact reg. setting that causes this. */
4869 if (ov->bridge == BRG_OV511PLUS) {
4870 dev_info(&ov->dev->dev,
4871 "Enabling 511+/7620AE workaround\n");
4872 ov->sensor = SEN_OV7620;
4874 ov->sensor = SEN_OV76BE;
4876 } else if ((rc & 3) == 0) {
4877 dev_info(&ov->dev->dev, "Sensor is an OV7620\n");
4878 ov->sensor = SEN_OV7620;
4880 err("Unknown image sensor version: %d", rc & 3);
4884 if (ov->sensor == SEN_OV7620) {
4885 PDEBUG(4, "Writing 7620 registers");
4886 if (write_regvals(ov, aRegvalsNorm7620))
4889 PDEBUG(4, "Writing 7610 registers");
4890 if (write_regvals(ov, aRegvalsNorm7610))
4894 /* Set sensor-specific vars */
4896 ov->maxheight = 480;
4900 // FIXME: These do not match the actual settings yet
4901 ov->brightness = 0x80 << 8;
4902 ov->contrast = 0x80 << 8;
4903 ov->colour = 0x80 << 8;
4904 ov->hue = 0x80 << 8;
4909 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
4911 ov6xx0_configure(struct usb_ov511 *ov)
4915 static struct ov511_regvals aRegvalsNorm6x20[] = {
4916 { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
4917 { OV511_I2C_BUS, 0x11, 0x01 },
4918 { OV511_I2C_BUS, 0x03, 0x60 },
4919 { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
4920 { OV511_I2C_BUS, 0x07, 0xa8 },
4921 /* The ratio of 0x0c and 0x0d controls the white point */
4922 { OV511_I2C_BUS, 0x0c, 0x24 },
4923 { OV511_I2C_BUS, 0x0d, 0x24 },
4924 { OV511_I2C_BUS, 0x0f, 0x15 }, /* COMS */
4925 { OV511_I2C_BUS, 0x10, 0x75 }, /* AEC Exposure time */
4926 { OV511_I2C_BUS, 0x12, 0x24 }, /* Enable AGC */
4927 { OV511_I2C_BUS, 0x14, 0x04 },
4928 /* 0x16: 0x06 helps frame stability with moving objects */
4929 { OV511_I2C_BUS, 0x16, 0x06 },
4930 // { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
4931 { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
4932 /* 0x28: 0x05 Selects RGB format if RGB on */
4933 { OV511_I2C_BUS, 0x28, 0x05 },
4934 { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
4935 // { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
4936 { OV511_I2C_BUS, 0x2d, 0x99 },
4937 { OV511_I2C_BUS, 0x33, 0xa0 }, /* Color Processing Parameter */
4938 { OV511_I2C_BUS, 0x34, 0xd2 }, /* Max A/D range */
4939 { OV511_I2C_BUS, 0x38, 0x8b },
4940 { OV511_I2C_BUS, 0x39, 0x40 },
4942 { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
4943 { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
4944 { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
4946 { OV511_I2C_BUS, 0x3d, 0x80 },
4947 /* These next two registers (0x4a, 0x4b) are undocumented. They
4948 * control the color balance */
4949 { OV511_I2C_BUS, 0x4a, 0x80 },
4950 { OV511_I2C_BUS, 0x4b, 0x80 },
4951 { OV511_I2C_BUS, 0x4d, 0xd2 }, /* This reduces noise a bit */
4952 { OV511_I2C_BUS, 0x4e, 0xc1 },
4953 { OV511_I2C_BUS, 0x4f, 0x04 },
4954 // Do 50-53 have any effect?
4955 // Toggle 0x12[2] off and on here?
4956 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
4959 static struct ov511_regvals aRegvalsNorm6x30[] = {
4960 /*OK*/ { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
4961 { OV511_I2C_BUS, 0x11, 0x00 },
4962 /*OK*/ { OV511_I2C_BUS, 0x03, 0x60 },
4963 /*0A?*/ { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
4964 { OV511_I2C_BUS, 0x07, 0xa8 },
4965 /* The ratio of 0x0c and 0x0d controls the white point */
4966 /*OK*/ { OV511_I2C_BUS, 0x0c, 0x24 },
4967 /*OK*/ { OV511_I2C_BUS, 0x0d, 0x24 },
4968 /*A*/ { OV511_I2C_BUS, 0x0e, 0x20 },
4969 // /*04?*/ { OV511_I2C_BUS, 0x14, 0x80 },
4970 { OV511_I2C_BUS, 0x16, 0x03 },
4971 // /*OK*/ { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
4972 // 21 & 22? The suggested values look wrong. Go with default
4973 /*A*/ { OV511_I2C_BUS, 0x23, 0xc0 },
4974 /*A*/ { OV511_I2C_BUS, 0x25, 0x9a }, // Check this against default
4975 // /*OK*/ { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
4977 /* 0x28: 0x05 Selects RGB format if RGB on */
4978 // /*04?*/ { OV511_I2C_BUS, 0x28, 0x05 },
4979 // /*04?*/ { OV511_I2C_BUS, 0x28, 0x45 }, // DEBUG: Tristate UV bus
4981 /*OK*/ { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
4982 // /*OK*/ { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
4983 { OV511_I2C_BUS, 0x2d, 0x99 },
4984 // /*A*/ { OV511_I2C_BUS, 0x33, 0x26 }, // Reserved bits on 6620
4985 // /*d2?*/ { OV511_I2C_BUS, 0x34, 0x03 }, /* Max A/D range */
4986 // /*8b?*/ { OV511_I2C_BUS, 0x38, 0x83 },
4987 // /*40?*/ { OV511_I2C_BUS, 0x39, 0xc0 }, // 6630 adds bit 7
4988 // { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
4989 // { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
4990 // { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
4991 { OV511_I2C_BUS, 0x3d, 0x80 },
4992 // /*A*/ { OV511_I2C_BUS, 0x3f, 0x0e },
4994 /* These next two registers (0x4a, 0x4b) are undocumented. They
4995 * control the color balance */
4996 // /*OK?*/ { OV511_I2C_BUS, 0x4a, 0x80 }, // Check these
4997 // /*OK?*/ { OV511_I2C_BUS, 0x4b, 0x80 },
4998 { OV511_I2C_BUS, 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
4999 /*c1?*/ { OV511_I2C_BUS, 0x4e, 0x40 },
5001 /* UV average mode, color killer: strongest */
5002 { OV511_I2C_BUS, 0x4f, 0x07 },
5004 { OV511_I2C_BUS, 0x54, 0x23 }, /* Max AGC gain: 18dB */
5005 { OV511_I2C_BUS, 0x57, 0x81 }, /* (default) */
5006 { OV511_I2C_BUS, 0x59, 0x01 }, /* AGC dark current comp: +1 */
5007 { OV511_I2C_BUS, 0x5a, 0x2c }, /* (undocumented) */
5008 { OV511_I2C_BUS, 0x5b, 0x0f }, /* AWB chrominance levels */
5009 // { OV511_I2C_BUS, 0x5c, 0x10 },
5010 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
5013 PDEBUG(4, "starting sensor configuration");
5015 if (init_ov_sensor(ov) < 0) {
5016 err("Failed to read sensor ID. You might not have an OV6xx0,");
5017 err("or it may be not responding. Report this to " EMAIL);
5020 PDEBUG(1, "OV6xx0 sensor detected");
5023 /* Detect sensor (sub)type */
5024 rc = i2c_r(ov, OV7610_REG_COM_I);
5027 err("Error detecting sensor type");
5031 if ((rc & 3) == 0) {
5032 ov->sensor = SEN_OV6630;
5033 dev_info(&ov->dev->dev, "Sensor is an OV6630\n");
5034 } else if ((rc & 3) == 1) {
5035 ov->sensor = SEN_OV6620;
5036 dev_info(&ov->dev->dev, "Sensor is an OV6620\n");
5037 } else if ((rc & 3) == 2) {
5038 ov->sensor = SEN_OV6630;
5039 dev_info(&ov->dev->dev, "Sensor is an OV6630AE\n");
5040 } else if ((rc & 3) == 3) {
5041 ov->sensor = SEN_OV6630;
5042 dev_info(&ov->dev->dev, "Sensor is an OV6630AF\n");
5045 /* Set sensor-specific vars */
5047 ov->maxheight = 288;
5051 // FIXME: These do not match the actual settings yet
5052 ov->brightness = 0x80 << 8;
5053 ov->contrast = 0x80 << 8;
5054 ov->colour = 0x80 << 8;
5055 ov->hue = 0x80 << 8;
5057 if (ov->sensor == SEN_OV6620) {
5058 PDEBUG(4, "Writing 6x20 registers");
5059 if (write_regvals(ov, aRegvalsNorm6x20))
5062 PDEBUG(4, "Writing 6x30 registers");
5063 if (write_regvals(ov, aRegvalsNorm6x30))
5070 /* This initializes the KS0127 and KS0127B video decoders. */
5072 ks0127_configure(struct usb_ov511 *ov)
5076 // FIXME: I don't know how to sync or reset it yet
5078 if (ov51x_init_ks_sensor(ov) < 0) {
5079 err("Failed to initialize the KS0127");
5082 PDEBUG(1, "KS012x(B) sensor detected");
5086 /* Detect decoder subtype */
5087 rc = i2c_r(ov, 0x00);
5089 err("Error detecting sensor type");
5091 } else if (rc & 0x08) {
5092 rc = i2c_r(ov, 0x3d);
5094 err("Error detecting sensor type");
5096 } else if ((rc & 0x0f) == 0) {
5097 dev_info(&ov->dev->dev, "Sensor is a KS0127\n");
5098 ov->sensor = SEN_KS0127;
5099 } else if ((rc & 0x0f) == 9) {
5100 dev_info(&ov->dev->dev, "Sensor is a KS0127B Rev. A\n");
5101 ov->sensor = SEN_KS0127B;
5104 err("Error: Sensor is an unsupported KS0122");
5108 /* Set sensor-specific vars */
5110 ov->maxheight = 480;
5114 // FIXME: These do not match the actual settings yet
5115 ov->brightness = 0x80 << 8;
5116 ov->contrast = 0x80 << 8;
5117 ov->colour = 0x80 << 8;
5118 ov->hue = 0x80 << 8;
5120 /* This device is not supported yet. Bail out now... */
5121 err("This sensor is not supported yet.");
5127 /* This initializes the SAA7111A video decoder. */
5129 saa7111a_configure(struct usb_ov511 *ov)
5133 /* Since there is no register reset command, all registers must be
5134 * written, otherwise gives erratic results */
5135 static struct ov511_regvals aRegvalsNormSAA7111A[] = {
5136 { OV511_I2C_BUS, 0x06, 0xce },
5137 { OV511_I2C_BUS, 0x07, 0x00 },
5138 { OV511_I2C_BUS, 0x10, 0x44 }, /* YUV422, 240/286 lines */
5139 { OV511_I2C_BUS, 0x0e, 0x01 }, /* NTSC M or PAL BGHI */
5140 { OV511_I2C_BUS, 0x00, 0x00 },
5141 { OV511_I2C_BUS, 0x01, 0x00 },
5142 { OV511_I2C_BUS, 0x03, 0x23 },
5143 { OV511_I2C_BUS, 0x04, 0x00 },
5144 { OV511_I2C_BUS, 0x05, 0x00 },
5145 { OV511_I2C_BUS, 0x08, 0xc8 }, /* Auto field freq */
5146 { OV511_I2C_BUS, 0x09, 0x01 }, /* Chrom. trap off, APER=0.25 */
5147 { OV511_I2C_BUS, 0x0a, 0x80 }, /* BRIG=128 */
5148 { OV511_I2C_BUS, 0x0b, 0x40 }, /* CONT=1.0 */
5149 { OV511_I2C_BUS, 0x0c, 0x40 }, /* SATN=1.0 */
5150 { OV511_I2C_BUS, 0x0d, 0x00 }, /* HUE=0 */
5151 { OV511_I2C_BUS, 0x0f, 0x00 },
5152 { OV511_I2C_BUS, 0x11, 0x0c },
5153 { OV511_I2C_BUS, 0x12, 0x00 },
5154 { OV511_I2C_BUS, 0x13, 0x00 },
5155 { OV511_I2C_BUS, 0x14, 0x00 },
5156 { OV511_I2C_BUS, 0x15, 0x00 },
5157 { OV511_I2C_BUS, 0x16, 0x00 },
5158 { OV511_I2C_BUS, 0x17, 0x00 },
5159 { OV511_I2C_BUS, 0x02, 0xc0 }, /* Composite input 0 */
5160 { OV511_DONE_BUS, 0x0, 0x00 },
5163 // FIXME: I don't know how to sync or reset it yet
5165 if (ov51x_init_saa_sensor(ov) < 0) {
5166 err("Failed to initialize the SAA7111A");
5169 PDEBUG(1, "SAA7111A sensor detected");
5173 /* 640x480 not supported with PAL */
5176 ov->maxheight = 240; /* Even field only */
5179 ov->maxheight = 480; /* Even/Odd fields */
5183 ov->minheight = 240; /* Even field only */
5185 ov->has_decoder = 1;
5187 ov->norm = VIDEO_MODE_AUTO;
5188 ov->stop_during_set = 0; /* Decoder guarantees stable image */
5190 /* Decoder doesn't change these values, so we use these instead of
5191 * acutally reading the registers (which doesn't work) */
5192 ov->brightness = 0x80 << 8;
5193 ov->contrast = 0x40 << 9;
5194 ov->colour = 0x40 << 9;
5197 PDEBUG(4, "Writing SAA7111A registers");
5198 if (write_regvals(ov, aRegvalsNormSAA7111A))
5201 /* Detect version of decoder. This must be done after writing the
5202 * initial regs or the decoder will lock up. */
5203 rc = i2c_r(ov, 0x00);
5206 err("Error detecting sensor version");
5209 dev_info(&ov->dev->dev,
5210 "Sensor is an SAA7111A (version 0x%x)\n", rc);
5211 ov->sensor = SEN_SAA7111A;
5214 // FIXME: Fix this for OV518(+)
5215 /* Latch to negative edge of clock. Otherwise, we get incorrect
5216 * colors and jitter in the digital signal. */
5217 if (ov->bclass == BCL_OV511)
5218 reg_w(ov, 0x11, 0x00);
5220 dev_warn(&ov->dev->dev,
5221 "SAA7111A not yet supported with OV518/OV518+\n");
5226 /* This initializes the OV511/OV511+ and the sensor */
5228 ov511_configure(struct usb_ov511 *ov)
5230 static struct ov511_regvals aRegvalsInit511[] = {
5231 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5232 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5233 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5234 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5235 { OV511_REG_BUS, R51x_SYS_RESET, 0x3f },
5236 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5237 { OV511_REG_BUS, R51x_SYS_RESET, 0x3d },
5238 { OV511_DONE_BUS, 0x0, 0x00},
5241 static struct ov511_regvals aRegvalsNorm511[] = {
5242 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0x01 },
5243 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5244 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5245 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5246 { OV511_REG_BUS, R511_FIFO_OPTS, 0x1f },
5247 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5248 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5249 { OV511_DONE_BUS, 0x0, 0x00 },
5252 static struct ov511_regvals aRegvalsNorm511Plus[] = {
5253 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0xff },
5254 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5255 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5256 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5257 { OV511_REG_BUS, R511_FIFO_OPTS, 0xff },
5258 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5259 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5260 { OV511_DONE_BUS, 0x0, 0x00 },
5265 ov->customid = reg_r(ov, R511_SYS_CUST_ID);
5266 if (ov->customid < 0) {
5267 err("Unable to read camera bridge registers");
5271 PDEBUG (1, "CustomID = %d", ov->customid);
5272 ov->desc = symbolic(camlist, ov->customid);
5273 dev_info(&ov->dev->dev, "model: %s\n", ov->desc);
5275 if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) {
5276 err("Camera type (%d) not recognized", ov->customid);
5277 err("Please notify " EMAIL " of the name,");
5278 err("manufacturer, model, and this number of your camera.");
5279 err("Also include the output of the detection process.");
5282 if (ov->customid == 70) /* USB Life TV (PAL/SECAM) */
5285 if (write_regvals(ov, aRegvalsInit511))
5288 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5289 ov51x_led_control(ov, 0);
5291 /* The OV511+ has undocumented bits in the flow control register.
5292 * Setting it to 0xff fixes the corruption with moving objects. */
5293 if (ov->bridge == BRG_OV511) {
5294 if (write_regvals(ov, aRegvalsNorm511))
5296 } else if (ov->bridge == BRG_OV511PLUS) {
5297 if (write_regvals(ov, aRegvalsNorm511Plus))
5300 err("Invalid bridge");
5303 if (ov511_init_compression(ov))
5306 ov->packet_numbering = 1;
5307 ov511_set_packet_size(ov, 0);
5309 ov->snap_enabled = snapshot;
5312 PDEBUG(3, "Testing for 0V7xx0");
5313 ov->primary_i2c_slave = OV7xx0_SID;
5314 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5317 if (i2c_w(ov, 0x12, 0x80) < 0) {
5319 PDEBUG(3, "Testing for 0V6xx0");
5320 ov->primary_i2c_slave = OV6xx0_SID;
5321 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5324 if (i2c_w(ov, 0x12, 0x80) < 0) {
5326 PDEBUG(3, "Testing for 0V8xx0");
5327 ov->primary_i2c_slave = OV8xx0_SID;
5328 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5331 if (i2c_w(ov, 0x12, 0x80) < 0) {
5332 /* Test for SAA7111A */
5333 PDEBUG(3, "Testing for SAA7111A");
5334 ov->primary_i2c_slave = SAA7111A_SID;
5335 if (ov51x_set_slave_ids(ov, SAA7111A_SID) < 0)
5338 if (i2c_w(ov, 0x0d, 0x00) < 0) {
5339 /* Test for KS0127 */
5340 PDEBUG(3, "Testing for KS0127");
5341 ov->primary_i2c_slave = KS0127_SID;
5342 if (ov51x_set_slave_ids(ov, KS0127_SID) < 0)
5345 if (i2c_w(ov, 0x10, 0x00) < 0) {
5346 err("Can't determine sensor slave IDs");
5349 if (ks0127_configure(ov) < 0) {
5350 err("Failed to configure KS0127");
5355 if (saa7111a_configure(ov) < 0) {
5356 err("Failed to configure SAA7111A");
5361 err("Detected unsupported OV8xx0 sensor");
5365 if (ov6xx0_configure(ov) < 0) {
5366 err("Failed to configure OV6xx0");
5371 if (ov7xx0_configure(ov) < 0) {
5372 err("Failed to configure OV7xx0");
5380 err("OV511 Config failed");
5385 /* This initializes the OV518/OV518+ and the sensor */
5387 ov518_configure(struct usb_ov511 *ov)
5389 /* For 518 and 518+ */
5390 static struct ov511_regvals aRegvalsInit518[] = {
5391 { OV511_REG_BUS, R51x_SYS_RESET, 0x40 },
5392 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5393 { OV511_REG_BUS, R51x_SYS_RESET, 0x3e },
5394 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5395 { OV511_REG_BUS, R51x_SYS_RESET, 0x00 },
5396 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5397 { OV511_REG_BUS, 0x46, 0x00 },
5398 { OV511_REG_BUS, 0x5d, 0x03 },
5399 { OV511_DONE_BUS, 0x0, 0x00},
5402 static struct ov511_regvals aRegvalsNorm518[] = {
5403 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5404 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5405 { OV511_REG_BUS, 0x31, 0x0f },
5406 { OV511_REG_BUS, 0x5d, 0x03 },
5407 { OV511_REG_BUS, 0x24, 0x9f },
5408 { OV511_REG_BUS, 0x25, 0x90 },
5409 { OV511_REG_BUS, 0x20, 0x00 },
5410 { OV511_REG_BUS, 0x51, 0x04 },
5411 { OV511_REG_BUS, 0x71, 0x19 },
5412 { OV511_DONE_BUS, 0x0, 0x00 },
5415 static struct ov511_regvals aRegvalsNorm518Plus[] = {
5416 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5417 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5418 { OV511_REG_BUS, 0x31, 0x0f },
5419 { OV511_REG_BUS, 0x5d, 0x03 },
5420 { OV511_REG_BUS, 0x24, 0x9f },
5421 { OV511_REG_BUS, 0x25, 0x90 },
5422 { OV511_REG_BUS, 0x20, 0x60 },
5423 { OV511_REG_BUS, 0x51, 0x02 },
5424 { OV511_REG_BUS, 0x71, 0x19 },
5425 { OV511_REG_BUS, 0x40, 0xff },
5426 { OV511_REG_BUS, 0x41, 0x42 },
5427 { OV511_REG_BUS, 0x46, 0x00 },
5428 { OV511_REG_BUS, 0x33, 0x04 },
5429 { OV511_REG_BUS, 0x21, 0x19 },
5430 { OV511_REG_BUS, 0x3f, 0x10 },
5431 { OV511_DONE_BUS, 0x0, 0x00 },
5436 /* First 5 bits of custom ID reg are a revision ID on OV518 */
5437 dev_info(&ov->dev->dev, "Device revision %d\n",
5438 0x1F & reg_r(ov, R511_SYS_CUST_ID));
5440 /* Give it the default description */
5441 ov->desc = symbolic(camlist, 0);
5443 if (write_regvals(ov, aRegvalsInit518))
5446 /* Set LED GPIO pin to output mode */
5447 if (reg_w_mask(ov, 0x57, 0x00, 0x02) < 0)
5450 /* LED is off by default with OV518; have to explicitly turn it on */
5451 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5452 ov51x_led_control(ov, 0);
5454 ov51x_led_control(ov, 1);
5456 /* Don't require compression if dumppix is enabled; otherwise it's
5457 * required. OV518 has no uncompressed mode, to save RAM. */
5458 if (!dumppix && !ov->compress) {
5460 dev_warn(&ov->dev->dev,
5461 "Compression required with OV518...enabling\n");
5464 if (ov->bridge == BRG_OV518) {
5465 if (write_regvals(ov, aRegvalsNorm518))
5467 } else if (ov->bridge == BRG_OV518PLUS) {
5468 if (write_regvals(ov, aRegvalsNorm518Plus))
5471 err("Invalid bridge");
5474 if (reg_w(ov, 0x2f, 0x80) < 0)
5477 if (ov518_init_compression(ov))
5480 if (ov->bridge == BRG_OV518)
5482 struct usb_interface *ifp;
5483 struct usb_host_interface *alt;
5486 ifp = usb_ifnum_to_if(ov->dev, 0);
5488 alt = usb_altnum_to_altsetting(ifp, 7);
5490 mxps = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
5493 /* Some OV518s have packet numbering by default, some don't */
5495 ov->packet_numbering = 1;
5497 ov->packet_numbering = 0;
5499 /* OV518+ has packet numbering turned on by default */
5500 ov->packet_numbering = 1;
5503 ov518_set_packet_size(ov, 0);
5505 ov->snap_enabled = snapshot;
5508 ov->primary_i2c_slave = OV7xx0_SID;
5509 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5512 /* The OV518 must be more aggressive about sensor detection since
5513 * I2C write will never fail if the sensor is not present. We have
5514 * to try to initialize the sensor to detect its presence */
5516 if (init_ov_sensor(ov) < 0) {
5518 ov->primary_i2c_slave = OV6xx0_SID;
5519 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5522 if (init_ov_sensor(ov) < 0) {
5524 ov->primary_i2c_slave = OV8xx0_SID;
5525 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5528 if (init_ov_sensor(ov) < 0) {
5529 err("Can't determine sensor slave IDs");
5532 err("Detected unsupported OV8xx0 sensor");
5536 if (ov6xx0_configure(ov) < 0) {
5537 err("Failed to configure OV6xx0");
5542 if (ov7xx0_configure(ov) < 0) {
5543 err("Failed to configure OV7xx0");
5549 ov->maxheight = 288;
5551 // The OV518 cannot go as low as the sensor can
5553 ov->minheight = 120;
5558 err("OV518 Config failed");
5563 /****************************************************************************
5565 ***************************************************************************/
5567 static inline struct usb_ov511 *cd_to_ov(struct device *cd)
5569 struct video_device *vdev = to_video_device(cd);
5570 return video_get_drvdata(vdev);
5573 static ssize_t show_custom_id(struct device *cd,
5574 struct device_attribute *attr, char *buf)
5576 struct usb_ov511 *ov = cd_to_ov(cd);
5577 return sprintf(buf, "%d\n", ov->customid);
5579 static DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
5581 static ssize_t show_model(struct device *cd,
5582 struct device_attribute *attr, char *buf)
5584 struct usb_ov511 *ov = cd_to_ov(cd);
5585 return sprintf(buf, "%s\n", ov->desc);
5587 static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
5589 static ssize_t show_bridge(struct device *cd,
5590 struct device_attribute *attr, char *buf)
5592 struct usb_ov511 *ov = cd_to_ov(cd);
5593 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
5595 static DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
5597 static ssize_t show_sensor(struct device *cd,
5598 struct device_attribute *attr, char *buf)
5600 struct usb_ov511 *ov = cd_to_ov(cd);
5601 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
5603 static DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
5605 static ssize_t show_brightness(struct device *cd,
5606 struct device_attribute *attr, char *buf)
5608 struct usb_ov511 *ov = cd_to_ov(cd);
5613 sensor_get_brightness(ov, &x);
5614 return sprintf(buf, "%d\n", x >> 8);
5616 static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
5618 static ssize_t show_saturation(struct device *cd,
5619 struct device_attribute *attr, char *buf)
5621 struct usb_ov511 *ov = cd_to_ov(cd);
5626 sensor_get_saturation(ov, &x);
5627 return sprintf(buf, "%d\n", x >> 8);
5629 static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
5631 static ssize_t show_contrast(struct device *cd,
5632 struct device_attribute *attr, char *buf)
5634 struct usb_ov511 *ov = cd_to_ov(cd);
5639 sensor_get_contrast(ov, &x);
5640 return sprintf(buf, "%d\n", x >> 8);
5642 static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
5644 static ssize_t show_hue(struct device *cd,
5645 struct device_attribute *attr, char *buf)
5647 struct usb_ov511 *ov = cd_to_ov(cd);
5652 sensor_get_hue(ov, &x);
5653 return sprintf(buf, "%d\n", x >> 8);
5655 static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5657 static ssize_t show_exposure(struct device *cd,
5658 struct device_attribute *attr, char *buf)
5660 struct usb_ov511 *ov = cd_to_ov(cd);
5661 unsigned char exp = 0;
5665 sensor_get_exposure(ov, &exp);
5666 return sprintf(buf, "%d\n", exp);
5668 static DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
5670 static int ov_create_sysfs(struct video_device *vdev)
5674 rc = device_create_file(&vdev->dev, &dev_attr_custom_id);
5676 rc = device_create_file(&vdev->dev, &dev_attr_model);
5677 if (rc) goto err_id;
5678 rc = device_create_file(&vdev->dev, &dev_attr_bridge);
5679 if (rc) goto err_model;
5680 rc = device_create_file(&vdev->dev, &dev_attr_sensor);
5681 if (rc) goto err_bridge;
5682 rc = device_create_file(&vdev->dev, &dev_attr_brightness);
5683 if (rc) goto err_sensor;
5684 rc = device_create_file(&vdev->dev, &dev_attr_saturation);
5685 if (rc) goto err_bright;
5686 rc = device_create_file(&vdev->dev, &dev_attr_contrast);
5687 if (rc) goto err_sat;
5688 rc = device_create_file(&vdev->dev, &dev_attr_hue);
5689 if (rc) goto err_contrast;
5690 rc = device_create_file(&vdev->dev, &dev_attr_exposure);
5691 if (rc) goto err_hue;
5696 device_remove_file(&vdev->dev, &dev_attr_hue);
5698 device_remove_file(&vdev->dev, &dev_attr_contrast);
5700 device_remove_file(&vdev->dev, &dev_attr_saturation);
5702 device_remove_file(&vdev->dev, &dev_attr_brightness);
5704 device_remove_file(&vdev->dev, &dev_attr_sensor);
5706 device_remove_file(&vdev->dev, &dev_attr_bridge);
5708 device_remove_file(&vdev->dev, &dev_attr_model);
5710 device_remove_file(&vdev->dev, &dev_attr_custom_id);
5715 /****************************************************************************
5717 ***************************************************************************/
5720 ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5722 struct usb_device *dev = interface_to_usbdev(intf);
5723 struct usb_interface_descriptor *idesc;
5724 struct usb_ov511 *ov;
5727 PDEBUG(1, "probing for device...");
5729 /* We don't handle multi-config cameras */
5730 if (dev->descriptor.bNumConfigurations != 1)
5733 idesc = &intf->cur_altsetting->desc;
5735 if (idesc->bInterfaceClass != 0xFF)
5737 if (idesc->bInterfaceSubClass != 0x00)
5740 if ((ov = kzalloc(sizeof(*ov), GFP_KERNEL)) == NULL) {
5741 err("couldn't kmalloc ov struct");
5746 ov->iface = idesc->bInterfaceNumber;
5747 ov->led_policy = led;
5748 ov->compress = compress;
5749 ov->lightfreq = lightfreq;
5750 ov->num_inputs = 1; /* Video decoder init functs. change this */
5751 ov->stop_during_set = !fastset;
5752 ov->backlight = backlight;
5753 ov->mirror = mirror;
5754 ov->auto_brt = autobright;
5755 ov->auto_gain = autogain;
5756 ov->auto_exp = autoexp;
5758 switch (le16_to_cpu(dev->descriptor.idProduct)) {
5760 ov->bridge = BRG_OV511;
5761 ov->bclass = BCL_OV511;
5763 case PROD_OV511PLUS:
5764 ov->bridge = BRG_OV511PLUS;
5765 ov->bclass = BCL_OV511;
5768 ov->bridge = BRG_OV518;
5769 ov->bclass = BCL_OV518;
5771 case PROD_OV518PLUS:
5772 ov->bridge = BRG_OV518PLUS;
5773 ov->bclass = BCL_OV518;
5776 if (le16_to_cpu(dev->descriptor.idVendor) != VEND_MATTEL)
5778 ov->bridge = BRG_OV511PLUS;
5779 ov->bclass = BCL_OV511;
5782 err("Unknown product ID 0x%04x", le16_to_cpu(dev->descriptor.idProduct));
5786 dev_info(&intf->dev, "USB %s video device found\n",
5787 symbolic(brglist, ov->bridge));
5789 init_waitqueue_head(&ov->wq);
5791 mutex_init(&ov->lock); /* to 1 == available */
5792 mutex_init(&ov->buf_lock);
5793 mutex_init(&ov->i2c_lock);
5794 mutex_init(&ov->cbuf_lock);
5796 ov->buf_state = BUF_NOT_ALLOCATED;
5798 if (usb_make_path(dev, ov->usb_path, OV511_USB_PATH_LEN) < 0) {
5799 err("usb_make_path error");
5803 /* Allocate control transfer buffer. */
5804 /* Must be kmalloc()'ed, for DMA compatibility */
5805 ov->cbuf = kmalloc(OV511_CBUF_SIZE, GFP_KERNEL);
5809 if (ov->bclass == BCL_OV518) {
5810 if (ov518_configure(ov) < 0)
5813 if (ov511_configure(ov) < 0)
5817 for (i = 0; i < OV511_NUMFRAMES; i++) {
5818 ov->frame[i].framenum = i;
5819 init_waitqueue_head(&ov->frame[i].wq);
5822 for (i = 0; i < OV511_NUMSBUF; i++) {
5823 ov->sbuf[i].ov = ov;
5824 spin_lock_init(&ov->sbuf[i].lock);
5828 /* Unnecessary? (This is done on open(). Need to make sure variables
5829 * are properly initialized without this before removing it, though). */
5830 if (ov51x_set_default_params(ov) < 0)
5835 if (ov->bclass == BCL_OV511)
5836 ov511_dump_regs(ov);
5838 ov518_dump_regs(ov);
5842 ov->vdev = video_device_alloc();
5846 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
5847 ov->vdev->parent = &intf->dev;
5848 video_set_drvdata(ov->vdev, ov);
5850 mutex_lock(&ov->lock);
5852 /* Check to see next free device and mark as used */
5853 nr = find_first_zero_bit(&ov511_devused, OV511_MAX_UNIT_VIDEO);
5855 /* Registers device */
5856 if (unit_video[nr] != 0)
5857 rc = video_register_device(ov->vdev, VFL_TYPE_GRABBER,
5860 rc = video_register_device(ov->vdev, VFL_TYPE_GRABBER, -1);
5863 err("video_register_device failed");
5864 mutex_unlock(&ov->lock);
5868 /* Mark device as used */
5869 ov511_devused |= 1 << nr;
5872 dev_info(&intf->dev, "Device at %s registered to minor %d\n",
5873 ov->usb_path, ov->vdev->minor);
5875 usb_set_intfdata(intf, ov);
5876 if (ov_create_sysfs(ov->vdev)) {
5877 err("ov_create_sysfs failed");
5878 ov511_devused &= ~(1 << nr);
5879 mutex_unlock(&ov->lock);
5883 mutex_lock(&ov->lock);
5889 if (-1 == ov->vdev->minor)
5890 video_device_release(ov->vdev);
5892 video_unregister_device(ov->vdev);
5897 mutex_lock(&ov->cbuf_lock);
5900 mutex_unlock(&ov->cbuf_lock);
5907 err("Camera initialization failed");
5912 ov51x_disconnect(struct usb_interface *intf)
5914 struct usb_ov511 *ov = usb_get_intfdata(intf);
5919 mutex_lock(&ov->lock);
5920 usb_set_intfdata (intf, NULL);
5923 mutex_unlock(&ov->lock);
5927 /* Free device number */
5928 ov511_devused &= ~(1 << ov->nr);
5931 video_unregister_device(ov->vdev);
5933 for (n = 0; n < OV511_NUMFRAMES; n++)
5934 ov->frame[n].grabstate = FRAME_ERROR;
5938 /* This will cause the process to request another frame */
5939 for (n = 0; n < OV511_NUMFRAMES; n++)
5940 wake_up_interruptible(&ov->frame[n].wq);
5942 wake_up_interruptible(&ov->wq);
5945 ov51x_unlink_isoc(ov);
5946 mutex_unlock(&ov->lock);
5950 /* Free the memory */
5951 if (ov && !ov->user) {
5952 mutex_lock(&ov->cbuf_lock);
5955 mutex_unlock(&ov->cbuf_lock);
5962 PDEBUG(3, "Disconnect complete");
5965 static struct usb_driver ov511_driver = {
5967 .id_table = device_table,
5968 .probe = ov51x_probe,
5969 .disconnect = ov51x_disconnect
5972 /****************************************************************************
5976 ***************************************************************************/
5979 usb_ov511_init(void)
5983 retval = usb_register(&ov511_driver);
5987 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
5995 usb_ov511_exit(void)
5997 usb_deregister(&ov511_driver);
5998 printk(KERN_INFO KBUILD_MODNAME ": driver deregistered\n");
6001 module_init(usb_ov511_init);
6002 module_exit(usb_ov511_exit);