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: linux/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/config.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/vmalloc.h>
42 #include <linux/slab.h>
43 #include <linux/ctype.h>
44 #include <linux/pagemap.h>
45 #include <asm/semaphore.h>
46 #include <asm/processor.h>
48 #include <linux/device.h>
50 #if defined (__i386__)
51 #include <asm/cpufeature.h>
59 #define DRIVER_VERSION "v1.64 for Linux 2.5"
60 #define EMAIL "mark@alpha.dyndns.org"
61 #define DRIVER_AUTHOR "Mark McClelland <mark@alpha.dyndns.org> & Bret Wallach \
62 & Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha \
63 <cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>"
64 #define DRIVER_DESC "ov511 USB Camera Driver"
66 #define OV511_I2C_RETRIES 3
67 #define ENABLE_Y_QUANTABLE 1
68 #define ENABLE_UV_QUANTABLE 1
70 #define OV511_MAX_UNIT_VIDEO 16
72 /* Pixel count * bytes per YUV420 pixel (1.5) */
73 #define MAX_FRAME_SIZE(w, h) ((w) * (h) * 3 / 2)
75 #define MAX_DATA_SIZE(w, h) (MAX_FRAME_SIZE(w, h) + sizeof(struct timeval))
77 /* Max size * bytes per YUV420 pixel (1.5) + one extra isoc frame for safety */
78 #define MAX_RAW_DATA_SIZE(w, h) ((w) * (h) * 3 / 2 + 1024)
80 #define FATAL_ERROR(rc) ((rc) < 0 && (rc) != -EPERM)
82 /**********************************************************************
84 * (See ov511.txt for detailed descriptions of these)
85 **********************************************************************/
87 /* These variables (and all static globals) default to zero */
88 static int autobright = 1;
89 static int autogain = 1;
90 static int autoexp = 1;
98 static int dump_bridge;
99 static int dump_sensor;
101 static int phy = 0x1f;
102 static int phuv = 0x05;
103 static int pvy = 0x06;
104 static int pvuv = 0x06;
105 static int qhy = 0x14;
106 static int qhuv = 0x03;
107 static int qvy = 0x04;
108 static int qvuv = 0x04;
109 static int lightfreq;
110 static int bandingfilter;
111 static int clockdiv = -1;
112 static int packetsize = -1;
113 static int framedrop = -1;
115 static int force_palette;
116 static int backlight;
117 static int unit_video[OV511_MAX_UNIT_VIDEO];
118 static int remove_zeros;
120 static int ov518_color;
122 MODULE_PARM(autobright, "i");
123 MODULE_PARM_DESC(autobright, "Sensor automatically changes brightness");
124 MODULE_PARM(autogain, "i");
125 MODULE_PARM_DESC(autogain, "Sensor automatically changes gain");
126 MODULE_PARM(autoexp, "i");
127 MODULE_PARM_DESC(autoexp, "Sensor automatically changes exposure");
128 MODULE_PARM(debug, "i");
129 MODULE_PARM_DESC(debug,
130 "Debug level: 0=none, 1=inits, 2=warning, 3=config, 4=functions, 5=max");
131 MODULE_PARM(snapshot, "i");
132 MODULE_PARM_DESC(snapshot, "Enable snapshot mode");
133 MODULE_PARM(cams, "i");
134 MODULE_PARM_DESC(cams, "Number of simultaneous cameras");
135 MODULE_PARM(compress, "i");
136 MODULE_PARM_DESC(compress, "Turn on compression");
137 MODULE_PARM(testpat, "i");
138 MODULE_PARM_DESC(testpat,
139 "Replace image with vertical bar testpattern (only partially working)");
140 MODULE_PARM(dumppix, "i");
141 MODULE_PARM_DESC(dumppix, "Dump raw pixel data");
142 MODULE_PARM(led, "i");
143 MODULE_PARM_DESC(led,
144 "LED policy (OV511+ or later). 0=off, 1=on (default), 2=auto (on when open)");
145 MODULE_PARM(dump_bridge, "i");
146 MODULE_PARM_DESC(dump_bridge, "Dump the bridge registers");
147 MODULE_PARM(dump_sensor, "i");
148 MODULE_PARM_DESC(dump_sensor, "Dump the sensor registers");
149 MODULE_PARM(printph, "i");
150 MODULE_PARM_DESC(printph, "Print frame start/end headers");
151 MODULE_PARM(phy, "i");
152 MODULE_PARM_DESC(phy, "Prediction range (horiz. Y)");
153 MODULE_PARM(phuv, "i");
154 MODULE_PARM_DESC(phuv, "Prediction range (horiz. UV)");
155 MODULE_PARM(pvy, "i");
156 MODULE_PARM_DESC(pvy, "Prediction range (vert. Y)");
157 MODULE_PARM(pvuv, "i");
158 MODULE_PARM_DESC(pvuv, "Prediction range (vert. UV)");
159 MODULE_PARM(qhy, "i");
160 MODULE_PARM_DESC(qhy, "Quantization threshold (horiz. Y)");
161 MODULE_PARM(qhuv, "i");
162 MODULE_PARM_DESC(qhuv, "Quantization threshold (horiz. UV)");
163 MODULE_PARM(qvy, "i");
164 MODULE_PARM_DESC(qvy, "Quantization threshold (vert. Y)");
165 MODULE_PARM(qvuv, "i");
166 MODULE_PARM_DESC(qvuv, "Quantization threshold (vert. UV)");
167 MODULE_PARM(lightfreq, "i");
168 MODULE_PARM_DESC(lightfreq,
169 "Light frequency. Set to 50 or 60 Hz, or zero for default settings");
170 MODULE_PARM(bandingfilter, "i");
171 MODULE_PARM_DESC(bandingfilter,
172 "Enable banding filter (to reduce effects of fluorescent lighting)");
173 MODULE_PARM(clockdiv, "i");
174 MODULE_PARM_DESC(clockdiv, "Force pixel clock divisor to a specific value");
175 MODULE_PARM(packetsize, "i");
176 MODULE_PARM_DESC(packetsize, "Force a specific isoc packet size");
177 MODULE_PARM(framedrop, "i");
178 MODULE_PARM_DESC(framedrop, "Force a specific frame drop register setting");
179 MODULE_PARM(fastset, "i");
180 MODULE_PARM_DESC(fastset, "Allows picture settings to take effect immediately");
181 MODULE_PARM(force_palette, "i");
182 MODULE_PARM_DESC(force_palette, "Force the palette to a specific value");
183 MODULE_PARM(backlight, "i");
184 MODULE_PARM_DESC(backlight, "For objects that are lit from behind");
185 MODULE_PARM(unit_video, "1-" __MODULE_STRING(OV511_MAX_UNIT_VIDEO) "i");
186 MODULE_PARM_DESC(unit_video,
187 "Force use of specific minor number(s). 0 is not allowed.");
188 MODULE_PARM(remove_zeros, "i");
189 MODULE_PARM_DESC(remove_zeros,
190 "Remove zero-padding from uncompressed incoming data");
191 MODULE_PARM(mirror, "i");
192 MODULE_PARM_DESC(mirror, "Reverse image horizontally");
193 MODULE_PARM(ov518_color, "i");
194 MODULE_PARM_DESC(ov518_color, "Enable OV518 color (experimental)");
196 MODULE_AUTHOR(DRIVER_AUTHOR);
197 MODULE_DESCRIPTION(DRIVER_DESC);
198 MODULE_LICENSE("GPL");
200 /**********************************************************************
201 * Miscellaneous Globals
202 **********************************************************************/
204 static struct usb_driver ov511_driver;
206 static struct ov51x_decomp_ops *ov511_decomp_ops;
207 static struct ov51x_decomp_ops *ov511_mmx_decomp_ops;
208 static struct ov51x_decomp_ops *ov518_decomp_ops;
209 static struct ov51x_decomp_ops *ov518_mmx_decomp_ops;
211 /* Number of times to retry a failed I2C transaction. Increase this if you
212 * are getting "Failed to read sensor ID..." */
213 static int i2c_detect_tries = 5;
215 /* MMX support is present in kernel and CPU. Checked upon decomp module load. */
216 #if defined(__i386__) || defined(__x86_64__)
217 #define ov51x_mmx_available (cpu_has_mmx)
219 #define ov51x_mmx_available (0)
222 static struct usb_device_id device_table [] = {
223 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511) },
224 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511PLUS) },
225 { USB_DEVICE(VEND_OMNIVISION, PROD_OV518) },
226 { USB_DEVICE(VEND_OMNIVISION, PROD_OV518PLUS) },
227 { USB_DEVICE(VEND_MATTEL, PROD_ME2CAM) },
228 { } /* Terminating entry */
231 MODULE_DEVICE_TABLE (usb, device_table);
233 static unsigned char yQuanTable511[] = OV511_YQUANTABLE;
234 static unsigned char uvQuanTable511[] = OV511_UVQUANTABLE;
235 static unsigned char yQuanTable518[] = OV518_YQUANTABLE;
236 static unsigned char uvQuanTable518[] = OV518_UVQUANTABLE;
238 /**********************************************************************
240 **********************************************************************/
242 /* Known OV511-based cameras */
243 static struct symbolic_list camlist[] = {
244 { 0, "Generic Camera (no ID)" },
245 { 1, "Mustek WCam 3X" },
246 { 3, "D-Link DSB-C300" },
247 { 4, "Generic OV511/OV7610" },
248 { 5, "Puretek PT-6007" },
249 { 6, "Lifeview USB Life TV (NTSC)" },
250 { 21, "Creative Labs WebCam 3" },
251 { 22, "Lifeview USB Life TV (PAL D/K+B/G)" },
253 { 38, "Lifeview USB Life TV (PAL)" },
254 { 41, "Samsung Anycam MPC-M10" },
255 { 43, "Mtekvision Zeca MV402" },
257 { 70, "Lifeview USB Life TV (PAL/SECAM)" },
258 { 100, "Lifeview RoboCam" },
259 { 102, "AverMedia InterCam Elite" },
260 { 112, "MediaForte MV300" }, /* or OV7110 evaluation kit */
261 { 134, "Ezonics EZCam II" },
262 { 192, "Webeye 2000B" },
263 { 253, "Alpha Vision Tech. AlphaCam SE" },
267 /* Video4Linux1 Palettes */
268 static struct symbolic_list v4l1_plist[] = {
269 { VIDEO_PALETTE_GREY, "GREY" },
270 { VIDEO_PALETTE_HI240, "HI240" },
271 { VIDEO_PALETTE_RGB565, "RGB565" },
272 { VIDEO_PALETTE_RGB24, "RGB24" },
273 { VIDEO_PALETTE_RGB32, "RGB32" },
274 { VIDEO_PALETTE_RGB555, "RGB555" },
275 { VIDEO_PALETTE_YUV422, "YUV422" },
276 { VIDEO_PALETTE_YUYV, "YUYV" },
277 { VIDEO_PALETTE_UYVY, "UYVY" },
278 { VIDEO_PALETTE_YUV420, "YUV420" },
279 { VIDEO_PALETTE_YUV411, "YUV411" },
280 { VIDEO_PALETTE_RAW, "RAW" },
281 { VIDEO_PALETTE_YUV422P,"YUV422P" },
282 { VIDEO_PALETTE_YUV411P,"YUV411P" },
283 { VIDEO_PALETTE_YUV420P,"YUV420P" },
284 { VIDEO_PALETTE_YUV410P,"YUV410P" },
288 static struct symbolic_list brglist[] = {
289 { BRG_OV511, "OV511" },
290 { BRG_OV511PLUS, "OV511+" },
291 { BRG_OV518, "OV518" },
292 { BRG_OV518PLUS, "OV518+" },
296 static struct symbolic_list senlist[] = {
297 { SEN_OV76BE, "OV76BE" },
298 { SEN_OV7610, "OV7610" },
299 { SEN_OV7620, "OV7620" },
300 { SEN_OV7620AE, "OV7620AE" },
301 { SEN_OV6620, "OV6620" },
302 { SEN_OV6630, "OV6630" },
303 { SEN_OV6630AE, "OV6630AE" },
304 { SEN_OV6630AF, "OV6630AF" },
305 { SEN_OV8600, "OV8600" },
306 { SEN_KS0127, "KS0127" },
307 { SEN_KS0127B, "KS0127B" },
308 { SEN_SAA7111A, "SAA7111A" },
312 /* URB error codes: */
313 static struct symbolic_list urb_errlist[] = {
314 { -ENOSR, "Buffer error (overrun)" },
315 { -EPIPE, "Stalled (device not responding)" },
316 { -EOVERFLOW, "Babble (bad cable?)" },
317 { -EPROTO, "Bit-stuff error (bad cable?)" },
318 { -EILSEQ, "CRC/Timeout" },
319 { -ETIMEDOUT, "NAK (device does not respond)" },
323 /**********************************************************************
325 **********************************************************************/
327 /* Here we want the physical address of the memory.
328 * This is used when initializing the contents of the area.
330 static inline unsigned long
331 kvirt_to_pa(unsigned long adr)
333 unsigned long kva, ret;
335 kva = (unsigned long) page_address(vmalloc_to_page((void *)adr));
336 kva |= adr & (PAGE_SIZE-1); /* restore the offset */
342 rvmalloc(unsigned long size)
347 size = PAGE_ALIGN(size);
348 mem = vmalloc_32(size);
352 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
353 adr = (unsigned long) mem;
355 SetPageReserved(vmalloc_to_page((void *)adr));
364 rvfree(void *mem, unsigned long size)
371 adr = (unsigned long) mem;
372 while ((long) size > 0) {
373 ClearPageReserved(vmalloc_to_page((void *)adr));
380 /**********************************************************************
384 **********************************************************************/
386 /* Write an OV51x register */
388 reg_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
392 PDEBUG(5, "0x%02X:0x%02X", reg, value);
394 down(&ov->cbuf_lock);
396 rc = usb_control_msg(ov->dev,
397 usb_sndctrlpipe(ov->dev, 0),
398 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */,
399 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
400 0, (__u16)reg, &ov->cbuf[0], 1, HZ);
404 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc));
409 /* Read from an OV51x register */
410 /* returns: negative is error, pos or zero is data */
412 reg_r(struct usb_ov511 *ov, unsigned char reg)
416 down(&ov->cbuf_lock);
417 rc = usb_control_msg(ov->dev,
418 usb_rcvctrlpipe(ov->dev, 0),
419 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */,
420 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
421 0, (__u16)reg, &ov->cbuf[0], 1, HZ);
424 err("reg read: error %d: %s", rc, symbolic(urb_errlist, rc));
427 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]);
436 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
437 * the same position as 1's in "mask" are cleared and set to "value". Bits
438 * that are in the same position as 0's in "mask" are preserved, regardless
439 * of their respective state in "value".
442 reg_w_mask(struct usb_ov511 *ov,
448 unsigned char oldval, newval;
450 ret = reg_r(ov, reg);
454 oldval = (unsigned char) ret;
455 oldval &= (~mask); /* Clear the masked bits */
456 value &= mask; /* Enforce mask on value */
457 newval = oldval | value; /* Set the desired bits */
459 return (reg_w(ov, reg, newval));
463 * Writes multiple (n) byte value to a single register. Only valid with certain
464 * registers (0x30 and 0xc4 - 0xce).
467 ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
471 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n);
473 down(&ov->cbuf_lock);
475 *((u32 *)ov->cbuf) = __cpu_to_le32(val);
477 rc = usb_control_msg(ov->dev,
478 usb_sndctrlpipe(ov->dev, 0),
480 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
481 0, (__u16)reg, ov->cbuf, n, HZ);
485 err("reg write multiple: error %d: %s", rc,
486 symbolic(urb_errlist, rc));
492 ov511_upload_quan_tables(struct usb_ov511 *ov)
494 unsigned char *pYTable = yQuanTable511;
495 unsigned char *pUVTable = uvQuanTable511;
496 unsigned char val0, val1;
497 int i, rc, reg = R511_COMP_LUT_BEGIN;
499 PDEBUG(4, "Uploading quantization tables");
501 for (i = 0; i < OV511_QUANTABLESIZE / 2; i++) {
502 if (ENABLE_Y_QUANTABLE) {
508 rc = reg_w(ov, reg, val0);
513 if (ENABLE_UV_QUANTABLE) {
519 rc = reg_w(ov, reg + OV511_QUANTABLESIZE/2, val0);
530 /* OV518 quantization tables are 8x4 (instead of 8x8) */
532 ov518_upload_quan_tables(struct usb_ov511 *ov)
534 unsigned char *pYTable = yQuanTable518;
535 unsigned char *pUVTable = uvQuanTable518;
536 unsigned char val0, val1;
537 int i, rc, reg = R511_COMP_LUT_BEGIN;
539 PDEBUG(4, "Uploading quantization tables");
541 for (i = 0; i < OV518_QUANTABLESIZE / 2; i++) {
542 if (ENABLE_Y_QUANTABLE) {
548 rc = reg_w(ov, reg, val0);
553 if (ENABLE_UV_QUANTABLE) {
559 rc = reg_w(ov, reg + OV518_QUANTABLESIZE/2, val0);
571 ov51x_reset(struct usb_ov511 *ov, unsigned char reset_type)
575 /* Setting bit 0 not allowed on 518/518Plus */
576 if (ov->bclass == BCL_OV518)
579 PDEBUG(4, "Reset: type=0x%02X", reset_type);
581 rc = reg_w(ov, R51x_SYS_RESET, reset_type);
582 rc = reg_w(ov, R51x_SYS_RESET, 0);
585 err("reset: command failed");
590 /**********************************************************************
592 * Low-level I2C I/O functions
594 **********************************************************************/
596 /* NOTE: Do not call this function directly!
597 * The OV518 I2C I/O procedure is different, hence, this function.
598 * This is normally only called from i2c_w(). Note that this function
599 * always succeeds regardless of whether the sensor is present and working.
602 ov518_i2c_write_internal(struct usb_ov511 *ov,
608 PDEBUG(5, "0x%02X:0x%02X", reg, value);
610 /* Select camera register */
611 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
615 /* Write "value" to I2C data port of OV511 */
616 rc = reg_w(ov, R51x_I2C_DATA, value);
620 /* Initiate 3-byte write cycle */
621 rc = reg_w(ov, R518_I2C_CTL, 0x01);
628 /* NOTE: Do not call this function directly! */
630 ov511_i2c_write_internal(struct usb_ov511 *ov,
636 PDEBUG(5, "0x%02X:0x%02X", reg, value);
638 /* Three byte write cycle */
639 for (retries = OV511_I2C_RETRIES; ; ) {
640 /* Select camera register */
641 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
645 /* Write "value" to I2C data port of OV511 */
646 rc = reg_w(ov, R51x_I2C_DATA, value);
650 /* Initiate 3-byte write cycle */
651 rc = reg_w(ov, R511_I2C_CTL, 0x01);
655 /* Retry until idle */
657 rc = reg_r(ov, R511_I2C_CTL);
658 while (rc > 0 && ((rc&1) == 0));
669 reg_w(ov, R511_I2C_CTL, 0x10);
672 err("i2c write retries exhausted");
681 /* NOTE: Do not call this function directly!
682 * The OV518 I2C I/O procedure is different, hence, this function.
683 * This is normally only called from i2c_r(). Note that this function
684 * always succeeds regardless of whether the sensor is present and working.
687 ov518_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
691 /* Select camera register */
692 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
696 /* Initiate 2-byte write cycle */
697 rc = reg_w(ov, R518_I2C_CTL, 0x03);
701 /* Initiate 2-byte read cycle */
702 rc = reg_w(ov, R518_I2C_CTL, 0x05);
706 value = reg_r(ov, R51x_I2C_DATA);
708 PDEBUG(5, "0x%02X:0x%02X", reg, value);
713 /* NOTE: Do not call this function directly!
714 * returns: negative is error, pos or zero is data */
716 ov511_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
718 int rc, value, retries;
720 /* Two byte write cycle */
721 for (retries = OV511_I2C_RETRIES; ; ) {
722 /* Select camera register */
723 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
727 /* Initiate 2-byte write cycle */
728 rc = reg_w(ov, R511_I2C_CTL, 0x03);
732 /* Retry until idle */
734 rc = reg_r(ov, R511_I2C_CTL);
735 while (rc > 0 && ((rc&1) == 0));
739 if ((rc&2) == 0) /* Ack? */
743 reg_w(ov, R511_I2C_CTL, 0x10);
746 err("i2c write retries exhausted");
751 /* Two byte read cycle */
752 for (retries = OV511_I2C_RETRIES; ; ) {
753 /* Initiate 2-byte read cycle */
754 rc = reg_w(ov, R511_I2C_CTL, 0x05);
758 /* Retry until idle */
760 rc = reg_r(ov, R511_I2C_CTL);
761 while (rc > 0 && ((rc&1) == 0));
765 if ((rc&2) == 0) /* Ack? */
769 rc = reg_w(ov, R511_I2C_CTL, 0x10);
774 err("i2c read retries exhausted");
779 value = reg_r(ov, R51x_I2C_DATA);
781 PDEBUG(5, "0x%02X:0x%02X", reg, value);
783 /* This is needed to make i2c_w() work */
784 rc = reg_w(ov, R511_I2C_CTL, 0x05);
791 /* returns: negative is error, pos or zero is data */
793 i2c_r(struct usb_ov511 *ov, unsigned char reg)
799 if (ov->bclass == BCL_OV518)
800 rc = ov518_i2c_read_internal(ov, reg);
802 rc = ov511_i2c_read_internal(ov, reg);
810 i2c_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
816 if (ov->bclass == BCL_OV518)
817 rc = ov518_i2c_write_internal(ov, reg, value);
819 rc = ov511_i2c_write_internal(ov, reg, value);
826 /* Do not call this function directly! */
828 ov51x_i2c_write_mask_internal(struct usb_ov511 *ov,
834 unsigned char oldval, newval;
839 if (ov->bclass == BCL_OV518)
840 rc = ov518_i2c_read_internal(ov, reg);
842 rc = ov511_i2c_read_internal(ov, reg);
846 oldval = (unsigned char) rc;
847 oldval &= (~mask); /* Clear the masked bits */
848 value &= mask; /* Enforce mask on value */
849 newval = oldval | value; /* Set the desired bits */
852 if (ov->bclass == BCL_OV518)
853 return (ov518_i2c_write_internal(ov, reg, newval));
855 return (ov511_i2c_write_internal(ov, reg, newval));
858 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
859 * the same position as 1's in "mask" are cleared and set to "value". Bits
860 * that are in the same position as 0's in "mask" are preserved, regardless
861 * of their respective state in "value".
864 i2c_w_mask(struct usb_ov511 *ov,
872 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
878 /* Set the read and write slave IDs. The "slave" argument is the write slave,
879 * and the read slave will be set to (slave + 1). ov->i2c_lock should be held
880 * when calling this. This should not be called from outside the i2c I/O
884 i2c_set_slave_internal(struct usb_ov511 *ov, unsigned char slave)
888 rc = reg_w(ov, R51x_I2C_W_SID, slave);
892 rc = reg_w(ov, R51x_I2C_R_SID, slave + 1);
899 /* Write to a specific I2C slave ID and register, using the specified mask */
901 i2c_w_slave(struct usb_ov511 *ov,
911 /* Set new slave IDs */
912 rc = i2c_set_slave_internal(ov, slave);
916 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
919 /* Restore primary IDs */
920 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
921 err("Couldn't restore primary I2C slave");
927 /* Read from a specific I2C slave ID and register */
929 i2c_r_slave(struct usb_ov511 *ov,
937 /* Set new slave IDs */
938 rc = i2c_set_slave_internal(ov, slave);
942 if (ov->bclass == BCL_OV518)
943 rc = ov518_i2c_read_internal(ov, reg);
945 rc = ov511_i2c_read_internal(ov, reg);
948 /* Restore primary IDs */
949 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
950 err("Couldn't restore primary I2C slave");
956 /* Sets I2C read and write slave IDs. Returns <0 for error */
958 ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
964 rc = i2c_set_slave_internal(ov, sid);
968 // FIXME: Is this actually necessary?
969 rc = ov51x_reset(ov, OV511_RESET_NOREGS);
976 write_regvals(struct usb_ov511 *ov, struct ov511_regvals * pRegvals)
980 while (pRegvals->bus != OV511_DONE_BUS) {
981 if (pRegvals->bus == OV511_REG_BUS) {
982 if ((rc = reg_w(ov, pRegvals->reg, pRegvals->val)) < 0)
984 } else if (pRegvals->bus == OV511_I2C_BUS) {
985 if ((rc = i2c_w(ov, pRegvals->reg, pRegvals->val)) < 0)
988 err("Bad regval array");
998 dump_i2c_range(struct usb_ov511 *ov, int reg1, int regn)
1002 for (i = reg1; i <= regn; i++) {
1004 info("Sensor[0x%02X] = 0x%02X", i, rc);
1009 dump_i2c_regs(struct usb_ov511 *ov)
1012 dump_i2c_range(ov, 0x00, 0x7C);
1016 dump_reg_range(struct usb_ov511 *ov, int reg1, int regn)
1020 for (i = reg1; i <= regn; i++) {
1022 info("OV511[0x%02X] = 0x%02X", i, rc);
1027 ov511_dump_regs(struct usb_ov511 *ov)
1029 info("CAMERA INTERFACE REGS");
1030 dump_reg_range(ov, 0x10, 0x1f);
1031 info("DRAM INTERFACE REGS");
1032 dump_reg_range(ov, 0x20, 0x23);
1033 info("ISO FIFO REGS");
1034 dump_reg_range(ov, 0x30, 0x31);
1036 dump_reg_range(ov, 0x38, 0x39);
1037 dump_reg_range(ov, 0x3e, 0x3e);
1039 dump_reg_range(ov, 0x40, 0x49);
1040 info("SYSTEM CONTROL REGS");
1041 dump_reg_range(ov, 0x50, 0x55);
1042 dump_reg_range(ov, 0x5e, 0x5f);
1043 info("OmniCE REGS");
1044 dump_reg_range(ov, 0x70, 0x79);
1045 /* NOTE: Quantization tables are not readable. You will get the value
1046 * in reg. 0x79 for every table register */
1047 dump_reg_range(ov, 0x80, 0x9f);
1048 dump_reg_range(ov, 0xa0, 0xbf);
1053 ov518_dump_regs(struct usb_ov511 *ov)
1055 info("VIDEO MODE REGS");
1056 dump_reg_range(ov, 0x20, 0x2f);
1057 info("DATA PUMP AND SNAPSHOT REGS");
1058 dump_reg_range(ov, 0x30, 0x3f);
1060 dump_reg_range(ov, 0x40, 0x4f);
1061 info("SYSTEM CONTROL AND VENDOR REGS");
1062 dump_reg_range(ov, 0x50, 0x5f);
1064 dump_reg_range(ov, 0x60, 0x6f);
1066 dump_reg_range(ov, 0x70, 0x7f);
1067 info("Y QUANTIZATION TABLE");
1068 dump_reg_range(ov, 0x80, 0x8f);
1069 info("UV QUANTIZATION TABLE");
1070 dump_reg_range(ov, 0x90, 0x9f);
1072 dump_reg_range(ov, 0xa0, 0xbf);
1074 dump_reg_range(ov, 0xc0, 0xcf);
1078 /*****************************************************************************/
1080 /* Temporarily stops OV511 from functioning. Must do this before changing
1081 * registers while the camera is streaming */
1083 ov51x_stop(struct usb_ov511 *ov)
1085 PDEBUG(4, "stopping");
1087 if (ov->bclass == BCL_OV518)
1088 return (reg_w_mask(ov, R51x_SYS_RESET, 0x3a, 0x3a));
1090 return (reg_w(ov, R51x_SYS_RESET, 0x3d));
1093 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1094 * actually stopped (for performance). */
1096 ov51x_restart(struct usb_ov511 *ov)
1099 PDEBUG(4, "restarting");
1102 /* Reinitialize the stream */
1103 if (ov->bclass == BCL_OV518)
1104 reg_w(ov, 0x2f, 0x80);
1106 return (reg_w(ov, R51x_SYS_RESET, 0x00));
1112 /* Sleeps until no frames are active. Returns !0 if got signal */
1114 ov51x_wait_frames_inactive(struct usb_ov511 *ov)
1116 return wait_event_interruptible(ov->wq, ov->curframe < 0);
1119 /* Resets the hardware snapshot button */
1121 ov51x_clear_snapshot(struct usb_ov511 *ov)
1123 if (ov->bclass == BCL_OV511) {
1124 reg_w(ov, R51x_SYS_SNAP, 0x00);
1125 reg_w(ov, R51x_SYS_SNAP, 0x02);
1126 reg_w(ov, R51x_SYS_SNAP, 0x00);
1127 } else if (ov->bclass == BCL_OV518) {
1128 warn("snapshot reset not supported yet on OV518(+)");
1130 err("clear snap: invalid bridge type");
1135 /* Checks the status of the snapshot button. Returns 1 if it was pressed since
1136 * it was last cleared, and zero in all other cases (including errors) */
1138 ov51x_check_snapshot(struct usb_ov511 *ov)
1140 int ret, status = 0;
1142 if (ov->bclass == BCL_OV511) {
1143 ret = reg_r(ov, R51x_SYS_SNAP);
1145 err("Error checking snspshot status (%d)", ret);
1146 } else if (ret & 0x08) {
1149 } else if (ov->bclass == BCL_OV518) {
1150 warn("snapshot check not supported yet on OV518(+)");
1152 err("check snap: invalid bridge type");
1159 /* This does an initial reset of an OmniVision sensor and ensures that I2C
1160 * is synchronized. Returns <0 for failure.
1163 init_ov_sensor(struct usb_ov511 *ov)
1167 /* Reset the sensor */
1168 if (i2c_w(ov, 0x12, 0x80) < 0)
1171 /* Wait for it to initialize */
1172 schedule_timeout(1 + 150 * HZ / 1000);
1174 for (i = 0, success = 0; i < i2c_detect_tries && !success; i++) {
1175 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
1176 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
1181 /* Reset the sensor */
1182 if (i2c_w(ov, 0x12, 0x80) < 0)
1184 /* Wait for it to initialize */
1185 schedule_timeout(1 + 150 * HZ / 1000);
1186 /* Dummy read to sync I2C */
1187 if (i2c_r(ov, 0x00) < 0)
1194 PDEBUG(1, "I2C synced in %d attempt(s)", i);
1200 ov511_set_packet_size(struct usb_ov511 *ov, int size)
1204 if (ov51x_stop(ov) < 0)
1209 if (ov->bridge == BRG_OV511) {
1211 alt = OV511_ALT_SIZE_0;
1212 else if (size == 257)
1213 alt = OV511_ALT_SIZE_257;
1214 else if (size == 513)
1215 alt = OV511_ALT_SIZE_513;
1216 else if (size == 769)
1217 alt = OV511_ALT_SIZE_769;
1218 else if (size == 993)
1219 alt = OV511_ALT_SIZE_993;
1221 err("Set packet size: invalid size (%d)", size);
1224 } else if (ov->bridge == BRG_OV511PLUS) {
1226 alt = OV511PLUS_ALT_SIZE_0;
1227 else if (size == 33)
1228 alt = OV511PLUS_ALT_SIZE_33;
1229 else if (size == 129)
1230 alt = OV511PLUS_ALT_SIZE_129;
1231 else if (size == 257)
1232 alt = OV511PLUS_ALT_SIZE_257;
1233 else if (size == 385)
1234 alt = OV511PLUS_ALT_SIZE_385;
1235 else if (size == 513)
1236 alt = OV511PLUS_ALT_SIZE_513;
1237 else if (size == 769)
1238 alt = OV511PLUS_ALT_SIZE_769;
1239 else if (size == 961)
1240 alt = OV511PLUS_ALT_SIZE_961;
1242 err("Set packet size: invalid size (%d)", size);
1246 err("Set packet size: Invalid bridge type");
1250 PDEBUG(3, "%d, mult=%d, alt=%d", size, mult, alt);
1252 if (reg_w(ov, R51x_FIFO_PSIZE, mult) < 0)
1255 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1256 err("Set packet size: set interface error");
1260 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1263 ov->packet_size = size;
1265 if (ov51x_restart(ov) < 0)
1271 /* Note: Unlike the OV511/OV511+, the size argument does NOT include the
1272 * optional packet number byte. The actual size *is* stored in ov->packet_size,
1275 ov518_set_packet_size(struct usb_ov511 *ov, int size)
1279 if (ov51x_stop(ov) < 0)
1282 if (ov->bclass == BCL_OV518) {
1284 alt = OV518_ALT_SIZE_0;
1285 else if (size == 128)
1286 alt = OV518_ALT_SIZE_128;
1287 else if (size == 256)
1288 alt = OV518_ALT_SIZE_256;
1289 else if (size == 384)
1290 alt = OV518_ALT_SIZE_384;
1291 else if (size == 512)
1292 alt = OV518_ALT_SIZE_512;
1293 else if (size == 640)
1294 alt = OV518_ALT_SIZE_640;
1295 else if (size == 768)
1296 alt = OV518_ALT_SIZE_768;
1297 else if (size == 896)
1298 alt = OV518_ALT_SIZE_896;
1300 err("Set packet size: invalid size (%d)", size);
1304 err("Set packet size: Invalid bridge type");
1308 PDEBUG(3, "%d, alt=%d", size, alt);
1310 ov->packet_size = size;
1312 /* Program ISO FIFO size reg (packet number isn't included) */
1313 ov518_reg_w32(ov, 0x30, size, 2);
1315 if (ov->packet_numbering)
1319 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1320 err("Set packet size: set interface error");
1324 /* Initialize the stream */
1325 if (reg_w(ov, 0x2f, 0x80) < 0)
1328 if (ov51x_restart(ov) < 0)
1331 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1337 /* Upload compression params and quantization tables. Returns 0 for success. */
1339 ov511_init_compression(struct usb_ov511 *ov)
1343 if (!ov->compress_inited) {
1344 reg_w(ov, 0x70, phy);
1345 reg_w(ov, 0x71, phuv);
1346 reg_w(ov, 0x72, pvy);
1347 reg_w(ov, 0x73, pvuv);
1348 reg_w(ov, 0x74, qhy);
1349 reg_w(ov, 0x75, qhuv);
1350 reg_w(ov, 0x76, qvy);
1351 reg_w(ov, 0x77, qvuv);
1353 if (ov511_upload_quan_tables(ov) < 0) {
1354 err("Error uploading quantization tables");
1360 ov->compress_inited = 1;
1365 /* Upload compression params and quantization tables. Returns 0 for success. */
1367 ov518_init_compression(struct usb_ov511 *ov)
1371 if (!ov->compress_inited) {
1372 if (ov518_upload_quan_tables(ov) < 0) {
1373 err("Error uploading quantization tables");
1379 ov->compress_inited = 1;
1384 /* -------------------------------------------------------------------------- */
1386 /* Sets sensor's contrast setting to "val" */
1388 sensor_set_contrast(struct usb_ov511 *ov, unsigned short val)
1392 PDEBUG(3, "%d", val);
1394 if (ov->stop_during_set)
1395 if (ov51x_stop(ov) < 0)
1398 switch (ov->sensor) {
1402 rc = i2c_w(ov, OV7610_REG_CNT, val >> 8);
1409 rc = i2c_w_mask(ov, OV7610_REG_CNT, val >> 12, 0x0f);
1416 unsigned char ctab[] = {
1417 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
1418 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
1421 /* Use Y gamma control instead. Bit 0 enables it. */
1422 rc = i2c_w(ov, 0x64, ctab[val>>12]);
1429 rc = i2c_w(ov, 0x0b, val >> 9);
1436 PDEBUG(3, "Unsupported with this sensor");
1442 rc = 0; /* Success */
1445 if (ov51x_restart(ov) < 0)
1451 /* Gets sensor's contrast setting */
1453 sensor_get_contrast(struct usb_ov511 *ov, unsigned short *val)
1457 switch (ov->sensor) {
1460 rc = i2c_r(ov, OV7610_REG_CNT);
1467 rc = i2c_r(ov, OV7610_REG_CNT);
1474 /* Use Y gamma reg instead. Bit 0 is the enable bit. */
1475 rc = i2c_r(ov, 0x64);
1479 *val = (rc & 0xfe) << 8;
1482 *val = ov->contrast;
1485 PDEBUG(3, "Unsupported with this sensor");
1489 PDEBUG(3, "%d", *val);
1490 ov->contrast = *val;
1495 /* -------------------------------------------------------------------------- */
1497 /* Sets sensor's brightness setting to "val" */
1499 sensor_set_brightness(struct usb_ov511 *ov, unsigned short val)
1503 PDEBUG(4, "%d", val);
1505 if (ov->stop_during_set)
1506 if (ov51x_stop(ov) < 0)
1509 switch (ov->sensor) {
1514 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1519 /* 7620 doesn't like manual changes when in auto mode */
1520 if (!ov->auto_brt) {
1521 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1527 rc = i2c_w(ov, 0x0a, val >> 8);
1532 PDEBUG(3, "Unsupported with this sensor");
1537 rc = 0; /* Success */
1538 ov->brightness = val;
1540 if (ov51x_restart(ov) < 0)
1546 /* Gets sensor's brightness setting */
1548 sensor_get_brightness(struct usb_ov511 *ov, unsigned short *val)
1552 switch (ov->sensor) {
1558 rc = i2c_r(ov, OV7610_REG_BRT);
1565 *val = ov->brightness;
1568 PDEBUG(3, "Unsupported with this sensor");
1572 PDEBUG(3, "%d", *val);
1573 ov->brightness = *val;
1578 /* -------------------------------------------------------------------------- */
1580 /* Sets sensor's saturation (color intensity) setting to "val" */
1582 sensor_set_saturation(struct usb_ov511 *ov, unsigned short val)
1586 PDEBUG(3, "%d", val);
1588 if (ov->stop_during_set)
1589 if (ov51x_stop(ov) < 0)
1592 switch (ov->sensor) {
1597 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1602 // /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
1603 // rc = ov_i2c_write(ov->dev, 0x62, (val >> 9) & 0x7e);
1606 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1611 rc = i2c_w(ov, 0x0c, val >> 9);
1616 PDEBUG(3, "Unsupported with this sensor");
1621 rc = 0; /* Success */
1624 if (ov51x_restart(ov) < 0)
1630 /* Gets sensor's saturation (color intensity) setting */
1632 sensor_get_saturation(struct usb_ov511 *ov, unsigned short *val)
1636 switch (ov->sensor) {
1641 rc = i2c_r(ov, OV7610_REG_SAT);
1648 // /* Use UV gamma reg instead. Bits 0 & 7 are reserved. */
1649 // rc = i2c_r(ov, 0x62);
1653 // *val = (rc & 0x7e) << 9;
1654 rc = i2c_r(ov, OV7610_REG_SAT);
1664 PDEBUG(3, "Unsupported with this sensor");
1668 PDEBUG(3, "%d", *val);
1674 /* -------------------------------------------------------------------------- */
1676 /* Sets sensor's hue (red/blue balance) setting to "val" */
1678 sensor_set_hue(struct usb_ov511 *ov, unsigned short val)
1682 PDEBUG(3, "%d", val);
1684 if (ov->stop_during_set)
1685 if (ov51x_stop(ov) < 0)
1688 switch (ov->sensor) {
1692 rc = i2c_w(ov, OV7610_REG_RED, 0xFF - (val >> 8));
1696 rc = i2c_w(ov, OV7610_REG_BLUE, val >> 8);
1701 // Hue control is causing problems. I will enable it once it's fixed.
1703 rc = i2c_w(ov, 0x7a, (unsigned char)(val >> 8) + 0xb);
1707 rc = i2c_w(ov, 0x79, (unsigned char)(val >> 8) + 0xb);
1713 rc = i2c_w(ov, 0x0d, (val + 32768) >> 8);
1718 PDEBUG(3, "Unsupported with this sensor");
1723 rc = 0; /* Success */
1726 if (ov51x_restart(ov) < 0)
1732 /* Gets sensor's hue (red/blue balance) setting */
1734 sensor_get_hue(struct usb_ov511 *ov, unsigned short *val)
1738 switch (ov->sensor) {
1742 rc = i2c_r(ov, OV7610_REG_BLUE);
1749 rc = i2c_r(ov, 0x7a);
1759 PDEBUG(3, "Unsupported with this sensor");
1763 PDEBUG(3, "%d", *val);
1769 /* -------------------------------------------------------------------------- */
1772 sensor_set_picture(struct usb_ov511 *ov, struct video_picture *p)
1776 PDEBUG(4, "sensor_set_picture");
1778 ov->whiteness = p->whiteness;
1780 /* Don't return error if a setting is unsupported, or rest of settings
1781 * will not be performed */
1783 rc = sensor_set_contrast(ov, p->contrast);
1784 if (FATAL_ERROR(rc))
1787 rc = sensor_set_brightness(ov, p->brightness);
1788 if (FATAL_ERROR(rc))
1791 rc = sensor_set_saturation(ov, p->colour);
1792 if (FATAL_ERROR(rc))
1795 rc = sensor_set_hue(ov, p->hue);
1796 if (FATAL_ERROR(rc))
1803 sensor_get_picture(struct usb_ov511 *ov, struct video_picture *p)
1807 PDEBUG(4, "sensor_get_picture");
1809 /* Don't return error if a setting is unsupported, or rest of settings
1810 * will not be performed */
1812 rc = sensor_get_contrast(ov, &(p->contrast));
1813 if (FATAL_ERROR(rc))
1816 rc = sensor_get_brightness(ov, &(p->brightness));
1817 if (FATAL_ERROR(rc))
1820 rc = sensor_get_saturation(ov, &(p->colour));
1821 if (FATAL_ERROR(rc))
1824 rc = sensor_get_hue(ov, &(p->hue));
1825 if (FATAL_ERROR(rc))
1828 p->whiteness = 105 << 8;
1834 // FIXME: Exposure range is only 0x00-0x7f in interlace mode
1835 /* Sets current exposure for sensor. This only has an effect if auto-exposure
1838 sensor_set_exposure(struct usb_ov511 *ov, unsigned char val)
1842 PDEBUG(3, "%d", val);
1844 if (ov->stop_during_set)
1845 if (ov51x_stop(ov) < 0)
1848 switch (ov->sensor) {
1855 rc = i2c_w(ov, 0x10, val);
1863 PDEBUG(3, "Unsupported with this sensor");
1866 err("Sensor not supported for set_exposure");
1870 rc = 0; /* Success */
1873 if (ov51x_restart(ov) < 0)
1880 /* Gets current exposure level from sensor, regardless of whether it is under
1881 * manual control. */
1883 sensor_get_exposure(struct usb_ov511 *ov, unsigned char *val)
1887 switch (ov->sensor) {
1894 rc = i2c_r(ov, 0x10);
1904 PDEBUG(3, "Unsupported with this sensor");
1907 err("Sensor not supported for get_exposure");
1911 PDEBUG(3, "%d", *val);
1912 ov->exposure = *val;
1917 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+) */
1919 ov51x_led_control(struct usb_ov511 *ov, int enable)
1921 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1923 if (ov->bridge == BRG_OV511PLUS)
1924 reg_w(ov, R511_SYS_LED_CTL, enable ? 1 : 0);
1925 else if (ov->bclass == BCL_OV518)
1926 reg_w_mask(ov, R518_GPIO_OUT, enable ? 0x02 : 0x00, 0x02);
1931 /* Matches the sensor's internal frame rate to the lighting frequency.
1932 * Valid frequencies are:
1933 * 50 - 50Hz, for European and Asian lighting
1934 * 60 - 60Hz, for American lighting
1936 * Tested with: OV7610, OV7620, OV76BE, OV6620
1937 * Unsupported: KS0127, KS0127B, SAA7111A
1938 * Returns: 0 for success
1941 sensor_set_light_freq(struct usb_ov511 *ov, int freq)
1945 PDEBUG(4, "%d Hz", freq);
1949 else if (freq == 50)
1952 err("Invalid light freq (%d Hz)", freq);
1956 switch (ov->sensor) {
1958 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1959 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1960 i2c_w_mask(ov, 0x13, 0x10, 0x10);
1961 i2c_w_mask(ov, 0x13, 0x00, 0x10);
1966 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1967 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1968 i2c_w_mask(ov, 0x76, 0x01, 0x01);
1972 i2c_w(ov, 0x2b, sixty?0xa8:0x28);
1973 i2c_w(ov, 0x2a, sixty?0x84:0xa4);
1978 PDEBUG(5, "Unsupported with this sensor");
1981 err("Sensor not supported for set_light_freq");
1985 ov->lightfreq = freq;
1990 /* If enable is true, turn on the sensor's banding filter, otherwise turn it
1991 * off. This filter tries to reduce the pattern of horizontal light/dark bands
1992 * caused by some (usually fluorescent) lighting. The light frequency must be
1993 * set either before or after enabling it with ov51x_set_light_freq().
1995 * Tested with: OV7610, OV7620, OV76BE, OV6620.
1996 * Unsupported: KS0127, KS0127B, SAA7111A
1997 * Returns: 0 for success
2000 sensor_set_banding_filter(struct usb_ov511 *ov, int enable)
2004 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2006 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
2007 || ov->sensor == SEN_SAA7111A) {
2008 PDEBUG(5, "Unsupported with this sensor");
2012 rc = i2c_w_mask(ov, 0x2d, enable?0x04:0x00, 0x04);
2016 ov->bandfilt = enable;
2021 /* If enable is true, turn on the sensor's auto brightness control, otherwise
2024 * Unsupported: KS0127, KS0127B, SAA7111A
2025 * Returns: 0 for success
2028 sensor_set_auto_brightness(struct usb_ov511 *ov, int enable)
2032 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2034 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
2035 || ov->sensor == SEN_SAA7111A) {
2036 PDEBUG(5, "Unsupported with this sensor");
2040 rc = i2c_w_mask(ov, 0x2d, enable?0x10:0x00, 0x10);
2044 ov->auto_brt = enable;
2049 /* If enable is true, turn on the sensor's auto exposure control, otherwise
2052 * Unsupported: KS0127, KS0127B, SAA7111A
2053 * Returns: 0 for success
2056 sensor_set_auto_exposure(struct usb_ov511 *ov, int enable)
2058 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2060 switch (ov->sensor) {
2062 i2c_w_mask(ov, 0x29, enable?0x00:0x80, 0x80);
2068 i2c_w_mask(ov, 0x13, enable?0x01:0x00, 0x01);
2071 i2c_w_mask(ov, 0x28, enable?0x00:0x10, 0x10);
2076 PDEBUG(5, "Unsupported with this sensor");
2079 err("Sensor not supported for set_auto_exposure");
2083 ov->auto_exp = enable;
2088 /* Modifies the sensor's exposure algorithm to allow proper exposure of objects
2089 * that are illuminated from behind.
2091 * Tested with: OV6620, OV7620
2092 * Unsupported: OV7610, OV76BE, KS0127, KS0127B, SAA7111A
2093 * Returns: 0 for success
2096 sensor_set_backlight(struct usb_ov511 *ov, int enable)
2098 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2100 switch (ov->sensor) {
2103 i2c_w_mask(ov, 0x68, enable?0xe0:0xc0, 0xe0);
2104 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2105 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2108 i2c_w_mask(ov, 0x4e, enable?0xe0:0xc0, 0xe0);
2109 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2110 i2c_w_mask(ov, 0x0e, enable?0x80:0x00, 0x80);
2113 i2c_w_mask(ov, 0x4e, enable?0x80:0x60, 0xe0);
2114 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2115 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2122 PDEBUG(5, "Unsupported with this sensor");
2125 err("Sensor not supported for set_backlight");
2129 ov->backlight = enable;
2135 sensor_set_mirror(struct usb_ov511 *ov, int enable)
2137 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2139 switch (ov->sensor) {
2146 i2c_w_mask(ov, 0x12, enable?0x40:0x00, 0x40);
2151 PDEBUG(5, "Unsupported with this sensor");
2154 err("Sensor not supported for set_mirror");
2158 ov->mirror = enable;
2163 /* Returns number of bits per pixel (regardless of where they are located;
2164 * planar or not), or zero for unsupported format.
2167 get_depth(int palette)
2170 case VIDEO_PALETTE_GREY: return 8;
2171 case VIDEO_PALETTE_YUV420: return 12;
2172 case VIDEO_PALETTE_YUV420P: return 12; /* Planar */
2173 default: return 0; /* Invalid format */
2177 /* Bytes per frame. Used by read(). Return of 0 indicates error */
2178 static inline long int
2179 get_frame_length(struct ov511_frame *frame)
2184 return ((frame->width * frame->height
2185 * get_depth(frame->format)) >> 3);
2189 mode_init_ov_sensor_regs(struct usb_ov511 *ov, int width, int height,
2190 int mode, int sub_flag, int qvga)
2194 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2196 switch (ov->sensor) {
2198 i2c_w(ov, 0x14, qvga?0x24:0x04);
2199 // FIXME: Does this improve the image quality or frame rate?
2201 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2202 i2c_w(ov, 0x24, 0x10);
2203 i2c_w(ov, 0x25, qvga?0x40:0x8a);
2204 i2c_w(ov, 0x2f, qvga?0x30:0xb0);
2205 i2c_w(ov, 0x35, qvga?0x1c:0x9c);
2209 // i2c_w(ov, 0x2b, 0x00);
2210 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2211 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2212 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2213 i2c_w(ov, 0x25, qvga?0x30:0x60);
2214 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2215 i2c_w_mask(ov, 0x67, qvga?0xf0:0x90, 0xf0);
2216 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2219 // i2c_w(ov, 0x2b, 0x00);
2220 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2221 // FIXME: Enable this once 7620AE uses 7620 initial settings
2223 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2224 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2225 i2c_w(ov, 0x25, qvga?0x30:0x60);
2226 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2227 i2c_w_mask(ov, 0x67, qvga?0xb0:0x90, 0xf0);
2228 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2232 i2c_w(ov, 0x14, qvga?0x24:0x04);
2235 i2c_w(ov, 0x14, qvga?0xa0:0x80);
2238 err("Invalid sensor");
2242 /******** Palette-specific regs ********/
2244 if (mode == VIDEO_PALETTE_GREY) {
2245 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2246 /* these aren't valid on the OV6620/OV7620/6630? */
2247 i2c_w_mask(ov, 0x0e, 0x40, 0x40);
2250 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2252 i2c_w_mask(ov, 0x12, 0x00, 0x10);
2253 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2255 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2258 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2259 /* not valid on the OV6620/OV7620/6630? */
2260 i2c_w_mask(ov, 0x0e, 0x00, 0x40);
2263 /* The OV518 needs special treatment. Although both the OV518
2264 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2265 * bus is actually used. The UV bus is tied to ground.
2266 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2269 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2271 i2c_w_mask(ov, 0x12, 0x10, 0x10);
2272 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2274 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2278 /******** Clock programming ********/
2280 /* The OV6620 needs special handling. This prevents the
2281 * severe banding that normally occurs */
2282 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630)
2286 i2c_w(ov, 0x2a, 0x04);
2289 // clock = 0; /* This ensures the highest frame rate */
2291 } else if (clockdiv == -1) { /* If user didn't override it */
2292 clock = 3; /* Gives better exposure time */
2297 PDEBUG(4, "Setting clock divisor to %d", clock);
2299 i2c_w(ov, 0x11, clock);
2301 i2c_w(ov, 0x2a, 0x84);
2302 /* This next setting is critical. It seems to improve
2303 * the gain or the contrast. The "reserved" bits seem
2304 * to have some effect in this case. */
2305 i2c_w(ov, 0x2d, 0x85);
2310 clock = 1; /* This ensures the highest frame rate */
2311 } else if (clockdiv == -1) { /* If user didn't override it */
2312 /* Calculate and set the clock divisor */
2313 clock = ((sub_flag ? ov->subw * ov->subh
2315 * (mode == VIDEO_PALETTE_GREY ? 2 : 3) / 2)
2321 PDEBUG(4, "Setting clock divisor to %d", clock);
2323 i2c_w(ov, 0x11, clock);
2326 /******** Special Features ********/
2329 i2c_w(ov, 0x16, framedrop);
2332 i2c_w_mask(ov, 0x12, (testpat?0x02:0x00), 0x02);
2334 /* Enable auto white balance */
2335 i2c_w_mask(ov, 0x12, 0x04, 0x04);
2337 // This will go away as soon as ov51x_mode_init_sensor_regs()
2339 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2340 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2341 if (width == 640 && height == 480)
2342 i2c_w(ov, 0x35, 0x9e);
2344 i2c_w(ov, 0x35, 0x1e);
2351 set_ov_sensor_window(struct usb_ov511 *ov, int width, int height, int mode,
2355 int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
2356 int hoffset, voffset, hwscale = 0, vwscale = 0;
2358 /* The different sensor ICs handle setting up of window differently.
2359 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!!! */
2360 switch (ov->sensor) {
2365 vwsbase = vwebase = 0x05;
2375 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2377 vwsbase = vwebase = 0x05;
2380 err("Invalid sensor");
2384 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630) {
2385 /* Note: OV518(+) does downsample on its own) */
2386 if ((width > 176 && height > 144)
2387 || ov->bclass == BCL_OV518) { /* CIF */
2388 ret = mode_init_ov_sensor_regs(ov, width, height,
2393 vwscale = 1; /* The datasheet says 0; it's wrong */
2396 } else if (width > 176 || height > 144) {
2397 err("Illegal dimensions");
2400 ret = mode_init_ov_sensor_regs(ov, width, height,
2408 if (width > 320 && height > 240) { /* VGA */
2409 ret = mode_init_ov_sensor_regs(ov, width, height,
2417 } else if (width > 320 || height > 240) {
2418 err("Illegal dimensions");
2421 ret = mode_init_ov_sensor_regs(ov, width, height,
2431 /* Center the window */
2432 hoffset = ((hwsize - width) / 2) >> hwscale;
2433 voffset = ((vwsize - height) / 2) >> vwscale;
2435 /* FIXME! - This needs to be changed to support 160x120 and 6620!!! */
2437 i2c_w(ov, 0x17, hwsbase+(ov->subx>>hwscale));
2438 i2c_w(ov, 0x18, hwebase+((ov->subx+ov->subw)>>hwscale));
2439 i2c_w(ov, 0x19, vwsbase+(ov->suby>>vwscale));
2440 i2c_w(ov, 0x1a, vwebase+((ov->suby+ov->subh)>>vwscale));
2442 i2c_w(ov, 0x17, hwsbase + hoffset);
2443 i2c_w(ov, 0x18, hwebase + hoffset + (hwsize>>hwscale));
2444 i2c_w(ov, 0x19, vwsbase + voffset);
2445 i2c_w(ov, 0x1a, vwebase + voffset + (vwsize>>vwscale));
2456 /* Set up the OV511/OV511+ with the given image parameters.
2458 * Do not put any sensor-specific code in here (including I2C I/O functions)
2461 ov511_mode_init_regs(struct usb_ov511 *ov,
2462 int width, int height, int mode, int sub_flag)
2471 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2472 width, height, mode, sub_flag);
2474 // FIXME: This should be moved to a 7111a-specific function once
2475 // subcapture is dealt with properly
2476 if (ov->sensor == SEN_SAA7111A) {
2477 if (width == 320 && height == 240) {
2478 /* No need to do anything special */
2479 } else if (width == 640 && height == 480) {
2480 /* Set the OV511 up as 320x480, but keep the
2481 * V4L resolution as 640x480 */
2484 err("SAA7111A only allows 320x240 or 640x480");
2489 /* Make sure width and height are a multiple of 8 */
2490 if (width % 8 || height % 8) {
2491 err("Invalid size (%d, %d) (mode = %d)", width, height, mode);
2495 if (width < ov->minwidth || height < ov->minheight) {
2496 err("Requested dimensions are too small");
2500 if (ov51x_stop(ov) < 0)
2503 if (mode == VIDEO_PALETTE_GREY) {
2504 reg_w(ov, R511_CAM_UV_EN, 0x00);
2505 reg_w(ov, R511_SNAP_UV_EN, 0x00);
2506 reg_w(ov, R511_SNAP_OPTS, 0x01);
2508 reg_w(ov, R511_CAM_UV_EN, 0x01);
2509 reg_w(ov, R511_SNAP_UV_EN, 0x01);
2510 reg_w(ov, R511_SNAP_OPTS, 0x03);
2513 /* Here I'm assuming that snapshot size == image size.
2514 * I hope that's always true. --claudio
2516 hsegs = (width >> 3) - 1;
2517 vsegs = (height >> 3) - 1;
2519 reg_w(ov, R511_CAM_PXCNT, hsegs);
2520 reg_w(ov, R511_CAM_LNCNT, vsegs);
2521 reg_w(ov, R511_CAM_PXDIV, 0x00);
2522 reg_w(ov, R511_CAM_LNDIV, 0x00);
2524 /* YUV420, low pass filter on */
2525 reg_w(ov, R511_CAM_OPTS, 0x03);
2527 /* Snapshot additions */
2528 reg_w(ov, R511_SNAP_PXCNT, hsegs);
2529 reg_w(ov, R511_SNAP_LNCNT, vsegs);
2530 reg_w(ov, R511_SNAP_PXDIV, 0x00);
2531 reg_w(ov, R511_SNAP_LNDIV, 0x00);
2534 /* Enable Y and UV quantization and compression */
2535 reg_w(ov, R511_COMP_EN, 0x07);
2536 reg_w(ov, R511_COMP_LUT_EN, 0x03);
2537 ov51x_reset(ov, OV511_RESET_OMNICE);
2540 if (ov51x_restart(ov) < 0)
2546 /* Sets up the OV518/OV518+ with the given image parameters
2548 * OV518 needs a completely different approach, until we can figure out what
2549 * the individual registers do. Also, only 15 FPS is supported now.
2551 * Do not put any sensor-specific code in here (including I2C I/O functions)
2554 ov518_mode_init_regs(struct usb_ov511 *ov,
2555 int width, int height, int mode, int sub_flag)
2557 int hsegs, vsegs, hi_res;
2564 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2565 width, height, mode, sub_flag);
2567 if (width % 16 || height % 8) {
2568 err("Invalid size (%d, %d)", width, height);
2572 if (width < ov->minwidth || height < ov->minheight) {
2573 err("Requested dimensions are too small");
2577 if (width >= 320 && height >= 240) {
2579 } else if (width >= 320 || height >= 240) {
2580 err("Invalid width/height combination (%d, %d)", width, height);
2586 if (ov51x_stop(ov) < 0)
2589 /******** Set the mode ********/
2600 if (ov->bridge == BRG_OV518 && ov518_color) {
2601 /* OV518 needs U and V swapped */
2602 i2c_w_mask(ov, 0x15, 0x00, 0x01);
2604 if (mode == VIDEO_PALETTE_GREY) {
2605 /* Set 16-bit input format (UV data are ignored) */
2606 reg_w_mask(ov, 0x20, 0x00, 0x08);
2608 /* Set 8-bit (4:0:0) output format */
2609 reg_w_mask(ov, 0x28, 0x00, 0xf0);
2610 reg_w_mask(ov, 0x38, 0x00, 0xf0);
2612 /* Set 8-bit (YVYU) input format */
2613 reg_w_mask(ov, 0x20, 0x08, 0x08);
2615 /* Set 12-bit (4:2:0) output format */
2616 reg_w_mask(ov, 0x28, 0x80, 0xf0);
2617 reg_w_mask(ov, 0x38, 0x80, 0xf0);
2620 reg_w(ov, 0x28, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2621 reg_w(ov, 0x38, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2627 reg_w(ov, 0x29, hsegs);
2628 reg_w(ov, 0x2a, vsegs);
2630 reg_w(ov, 0x39, hsegs);
2631 reg_w(ov, 0x3a, vsegs);
2633 /* Windows driver does this here; who knows why */
2634 reg_w(ov, 0x2f, 0x80);
2636 /******** Set the framerate (to 15 FPS) ********/
2638 /* Mode independent, but framerate dependent, regs */
2639 reg_w(ov, 0x51, 0x02); /* Clock divider; lower==faster */
2640 reg_w(ov, 0x22, 0x18);
2641 reg_w(ov, 0x23, 0xff);
2643 if (ov->bridge == BRG_OV518PLUS)
2644 reg_w(ov, 0x21, 0x19);
2646 reg_w(ov, 0x71, 0x19); /* Compression-related? */
2648 // FIXME: Sensor-specific
2649 /* Bit 5 is what matters here. Of course, it is "reserved" */
2650 i2c_w(ov, 0x54, 0x23);
2652 reg_w(ov, 0x2f, 0x80);
2654 if (ov->bridge == BRG_OV518PLUS) {
2655 reg_w(ov, 0x24, 0x94);
2656 reg_w(ov, 0x25, 0x90);
2657 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2658 ov518_reg_w32(ov, 0xc6, 540, 2); /* 21ch */
2659 ov518_reg_w32(ov, 0xc7, 540, 2); /* 21ch */
2660 ov518_reg_w32(ov, 0xc8, 108, 2); /* 6ch */
2661 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2662 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2663 ov518_reg_w32(ov, 0xcc, 2400, 2); /* 960h */
2664 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2665 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2667 reg_w(ov, 0x24, 0x9f);
2668 reg_w(ov, 0x25, 0x90);
2669 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2670 ov518_reg_w32(ov, 0xc6, 500, 2); /* 1f4h */
2671 ov518_reg_w32(ov, 0xc7, 500, 2); /* 1f4h */
2672 ov518_reg_w32(ov, 0xc8, 142, 2); /* 8eh */
2673 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2674 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2675 ov518_reg_w32(ov, 0xcc, 2000, 2); /* 7d0h */
2676 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2677 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2680 reg_w(ov, 0x2f, 0x80);
2682 if (ov51x_restart(ov) < 0)
2685 /* Reset it just for good measure */
2686 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
2692 /* This is a wrapper around the OV511, OV518, and sensor specific functions */
2694 mode_init_regs(struct usb_ov511 *ov,
2695 int width, int height, int mode, int sub_flag)
2699 if (!ov || !ov->dev)
2702 if (ov->bclass == BCL_OV518) {
2703 rc = ov518_mode_init_regs(ov, width, height, mode, sub_flag);
2705 rc = ov511_mode_init_regs(ov, width, height, mode, sub_flag);
2708 if (FATAL_ERROR(rc))
2711 switch (ov->sensor) {
2718 rc = set_ov_sensor_window(ov, width, height, mode, sub_flag);
2722 err("KS0127-series decoders not supported yet");
2726 // rc = mode_init_saa_sensor_regs(ov, width, height, mode,
2729 PDEBUG(1, "SAA status = 0x%02X", i2c_r(ov, 0x1f));
2732 err("Unknown sensor");
2736 if (FATAL_ERROR(rc))
2739 /* Sensor-independent settings */
2740 rc = sensor_set_auto_brightness(ov, ov->auto_brt);
2741 if (FATAL_ERROR(rc))
2744 rc = sensor_set_auto_exposure(ov, ov->auto_exp);
2745 if (FATAL_ERROR(rc))
2748 rc = sensor_set_banding_filter(ov, bandingfilter);
2749 if (FATAL_ERROR(rc))
2752 if (ov->lightfreq) {
2753 rc = sensor_set_light_freq(ov, lightfreq);
2754 if (FATAL_ERROR(rc))
2758 rc = sensor_set_backlight(ov, ov->backlight);
2759 if (FATAL_ERROR(rc))
2762 rc = sensor_set_mirror(ov, ov->mirror);
2763 if (FATAL_ERROR(rc))
2769 /* This sets the default image parameters. This is useful for apps that use
2770 * read() and do not set these.
2773 ov51x_set_default_params(struct usb_ov511 *ov)
2777 /* Set default sizes in case IOCTL (VIDIOCMCAPTURE) is not used
2778 * (using read() instead). */
2779 for (i = 0; i < OV511_NUMFRAMES; i++) {
2780 ov->frame[i].width = ov->maxwidth;
2781 ov->frame[i].height = ov->maxheight;
2782 ov->frame[i].bytes_read = 0;
2784 ov->frame[i].format = force_palette;
2786 ov->frame[i].format = VIDEO_PALETTE_YUV420;
2788 ov->frame[i].depth = get_depth(ov->frame[i].format);
2791 PDEBUG(3, "%dx%d, %s", ov->maxwidth, ov->maxheight,
2792 symbolic(v4l1_plist, ov->frame[0].format));
2794 /* Initialize to max width/height, YUV420 or RGB24 (if supported) */
2795 if (mode_init_regs(ov, ov->maxwidth, ov->maxheight,
2796 ov->frame[0].format, 0) < 0)
2802 /**********************************************************************
2804 * Video decoder stuff
2806 **********************************************************************/
2808 /* Set analog input port of decoder */
2810 decoder_set_input(struct usb_ov511 *ov, int input)
2812 PDEBUG(4, "port %d", input);
2814 switch (ov->sensor) {
2818 i2c_w_mask(ov, 0x02, input, 0x07);
2819 /* Bypass chrominance trap for modes 4..7 */
2820 i2c_w_mask(ov, 0x09, (input > 3) ? 0x80:0x00, 0x80);
2830 /* Get ASCII name of video input */
2832 decoder_get_input_name(struct usb_ov511 *ov, int input, char *name)
2834 switch (ov->sensor) {
2837 if (input < 0 || input > 7)
2840 sprintf(name, "CVBS-%d", input);
2841 else // if (input < 8)
2842 sprintf(name, "S-Video-%d", input - 4);
2846 sprintf(name, "%s", "Camera");
2852 /* Set norm (NTSC, PAL, SECAM, AUTO) */
2854 decoder_set_norm(struct usb_ov511 *ov, int norm)
2856 PDEBUG(4, "%d", norm);
2858 switch (ov->sensor) {
2863 if (norm == VIDEO_MODE_NTSC) {
2864 reg_8 = 0x40; /* 60 Hz */
2865 reg_e = 0x00; /* NTSC M / PAL BGHI */
2866 } else if (norm == VIDEO_MODE_PAL) {
2867 reg_8 = 0x00; /* 50 Hz */
2868 reg_e = 0x00; /* NTSC M / PAL BGHI */
2869 } else if (norm == VIDEO_MODE_AUTO) {
2870 reg_8 = 0x80; /* Auto field detect */
2871 reg_e = 0x00; /* NTSC M / PAL BGHI */
2872 } else if (norm == VIDEO_MODE_SECAM) {
2873 reg_8 = 0x00; /* 50 Hz */
2874 reg_e = 0x50; /* SECAM / PAL 4.43 */
2879 i2c_w_mask(ov, 0x08, reg_8, 0xc0);
2880 i2c_w_mask(ov, 0x0e, reg_e, 0x70);
2890 /**********************************************************************
2894 **********************************************************************/
2896 /* Copies a 64-byte segment at pIn to an 8x8 block at pOut. The width of the
2897 * image at pOut is specified by w.
2900 make_8x8(unsigned char *pIn, unsigned char *pOut, int w)
2902 unsigned char *pOut1 = pOut;
2905 for (y = 0; y < 8; y++) {
2907 for (x = 0; x < 8; x++) {
2915 * For RAW BW (YUV 4:0:0) images, data show up in 256 byte segments.
2916 * The segments represent 4 squares of 8x8 pixels as follows:
2918 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2919 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2921 * 56 57 ... 63 120 121 ... 127 248 249 ... 255
2925 yuv400raw_to_yuv400p(struct ov511_frame *frame,
2926 unsigned char *pIn0, unsigned char *pOut0)
2929 unsigned char *pIn, *pOut, *pOutLine;
2934 for (y = 0; y < frame->rawheight - 1; y += 8) {
2936 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2937 make_8x8(pIn, pOut, frame->rawwidth);
2941 pOutLine += 8 * frame->rawwidth;
2946 * For YUV 4:2:0 images, the data show up in 384 byte segments.
2947 * The first 64 bytes of each segment are U, the next 64 are V. The U and
2948 * V are arranged as follows:
2955 * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block).
2957 * The next 256 bytes are full resolution Y data and represent 4 squares
2958 * of 8x8 pixels as follows:
2960 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2961 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2963 * 56 57 ... 63 120 121 ... 127 ... 248 249 ... 255
2965 * Note that the U and V data in one segment represent a 16 x 16 pixel
2966 * area, but the Y data represent a 32 x 8 pixel area. If the width is not an
2967 * even multiple of 32, the extra 8x8 blocks within a 32x8 block belong to the
2968 * next horizontal stripe.
2970 * If dumppix module param is set, _parse_data just dumps the incoming segments,
2971 * verbatim, in order, into the frame. When used with vidcat -f ppm -s 640x480
2972 * this puts the data on the standard output and can be analyzed with the
2973 * parseppm.c utility I wrote. That's a much faster way for figuring out how
2974 * these data are scrambled.
2977 /* Converts from raw, uncompressed segments at pIn0 to a YUV420P frame at pOut0.
2979 * FIXME: Currently only handles width and height that are multiples of 16
2982 yuv420raw_to_yuv420p(struct ov511_frame *frame,
2983 unsigned char *pIn0, unsigned char *pOut0)
2986 unsigned char *pIn, *pOut, *pOutLine;
2987 const unsigned int a = frame->rawwidth * frame->rawheight;
2988 const unsigned int w = frame->rawwidth / 2;
2992 pOutLine = pOut0 + a;
2993 for (y = 0; y < frame->rawheight - 1; y += 16) {
2995 for (x = 0; x < frame->rawwidth - 1; x += 16) {
2996 make_8x8(pIn, pOut, w);
2997 make_8x8(pIn + 64, pOut + a/4, w);
3008 for (y = 0; y < frame->rawheight - 1; y += 8) {
3010 for (x = 0; x < frame->rawwidth - 1; x += 8) {
3011 make_8x8(pIn, pOut, frame->rawwidth);
3019 pOutLine += 8 * frame->rawwidth;
3023 /**********************************************************************
3027 **********************************************************************/
3029 /* Chooses a decompression module, locks it, and sets ov->decomp_ops
3030 * accordingly. Returns -ENXIO if decompressor is not available, otherwise
3031 * returns 0 if no other error.
3034 request_decompressor(struct usb_ov511 *ov)
3039 if (ov->decomp_ops) {
3040 err("ERROR: Decompressor already requested!");
3046 /* Try to get MMX, and fall back on no-MMX if necessary */
3047 if (ov->bclass == BCL_OV511) {
3048 if (ov511_mmx_decomp_ops) {
3049 PDEBUG(3, "Using OV511 MMX decompressor");
3050 ov->decomp_ops = ov511_mmx_decomp_ops;
3051 } else if (ov511_decomp_ops) {
3052 PDEBUG(3, "Using OV511 decompressor");
3053 ov->decomp_ops = ov511_decomp_ops;
3055 err("No decompressor available");
3057 } else if (ov->bclass == BCL_OV518) {
3058 if (ov518_mmx_decomp_ops) {
3059 PDEBUG(3, "Using OV518 MMX decompressor");
3060 ov->decomp_ops = ov518_mmx_decomp_ops;
3061 } else if (ov518_decomp_ops) {
3062 PDEBUG(3, "Using OV518 decompressor");
3063 ov->decomp_ops = ov518_decomp_ops;
3065 err("No decompressor available");
3068 err("Unknown bridge");
3071 if (!ov->decomp_ops)
3074 if (!ov->decomp_ops->owner) {
3075 ov->decomp_ops = NULL;
3079 if (!try_module_get(ov->decomp_ops->owner))
3090 /* Unlocks decompression module and nulls ov->decomp_ops. Safe to call even
3091 * if ov->decomp_ops is NULL.
3094 release_decompressor(struct usb_ov511 *ov)
3096 int released = 0; /* Did we actually do anything? */
3103 if (ov->decomp_ops) {
3104 module_put(ov->decomp_ops->owner);
3108 ov->decomp_ops = NULL;
3113 PDEBUG(3, "Decompressor released");
3117 decompress(struct usb_ov511 *ov, struct ov511_frame *frame,
3118 unsigned char *pIn0, unsigned char *pOut0)
3120 if (!ov->decomp_ops)
3121 if (request_decompressor(ov))
3124 PDEBUG(4, "Decompressing %d bytes", frame->bytes_recvd);
3126 if (frame->format == VIDEO_PALETTE_GREY
3127 && ov->decomp_ops->decomp_400) {
3128 int ret = ov->decomp_ops->decomp_400(
3134 frame->bytes_recvd);
3135 PDEBUG(4, "DEBUG: decomp_400 returned %d", ret);
3136 } else if (frame->format != VIDEO_PALETTE_GREY
3137 && ov->decomp_ops->decomp_420) {
3138 int ret = ov->decomp_ops->decomp_420(
3144 frame->bytes_recvd);
3145 PDEBUG(4, "DEBUG: decomp_420 returned %d", ret);
3147 err("Decompressor does not support this format");
3151 /**********************************************************************
3155 **********************************************************************/
3157 /* Fuses even and odd fields together, and doubles width.
3158 * INPUT: an odd field followed by an even field at pIn0, in YUV planar format
3159 * OUTPUT: a normal YUV planar image, with correct aspect ratio
3162 deinterlace(struct ov511_frame *frame, int rawformat,
3163 unsigned char *pIn0, unsigned char *pOut0)
3165 const int fieldheight = frame->rawheight / 2;
3166 const int fieldpix = fieldheight * frame->rawwidth;
3167 const int w = frame->width;
3169 unsigned char *pInEven, *pInOdd, *pOut;
3171 PDEBUG(5, "fieldheight=%d", fieldheight);
3173 if (frame->rawheight != frame->height) {
3174 err("invalid height");
3178 if ((frame->rawwidth * 2) != frame->width) {
3179 err("invalid width");
3185 pInEven = pInOdd + fieldpix;
3187 for (y = 0; y < fieldheight; y++) {
3188 for (x = 0; x < frame->rawwidth; x++) {
3190 *(pOut+1) = *pInEven++;
3191 *(pOut+w) = *pInOdd;
3192 *(pOut+w+1) = *pInOdd++;
3198 if (rawformat == RAWFMT_YUV420) {
3200 pInOdd = pIn0 + fieldpix * 2;
3201 pInEven = pInOdd + fieldpix / 4;
3202 for (y = 0; y < fieldheight / 2; y++) {
3203 for (x = 0; x < frame->rawwidth / 2; x++) {
3205 *(pOut+1) = *pInEven++;
3206 *(pOut+w/2) = *pInOdd;
3207 *(pOut+w/2+1) = *pInOdd++;
3213 pInOdd = pIn0 + fieldpix * 2 + fieldpix / 2;
3214 pInEven = pInOdd + fieldpix / 4;
3215 for (y = 0; y < fieldheight / 2; y++) {
3216 for (x = 0; x < frame->rawwidth / 2; x++) {
3218 *(pOut+1) = *pInEven++;
3219 *(pOut+w/2) = *pInOdd;
3220 *(pOut+w/2+1) = *pInOdd++;
3229 ov51x_postprocess_grey(struct usb_ov511 *ov, struct ov511_frame *frame)
3231 /* Deinterlace frame, if necessary */
3232 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3233 if (frame->compressed)
3234 decompress(ov, frame, frame->rawdata,
3237 yuv400raw_to_yuv400p(frame, frame->rawdata,
3240 deinterlace(frame, RAWFMT_YUV400, frame->tempdata,
3243 if (frame->compressed)
3244 decompress(ov, frame, frame->rawdata,
3247 yuv400raw_to_yuv400p(frame, frame->rawdata,
3252 /* Process raw YUV420 data into standard YUV420P */
3254 ov51x_postprocess_yuv420(struct usb_ov511 *ov, struct ov511_frame *frame)
3256 /* Deinterlace frame, if necessary */
3257 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3258 if (frame->compressed)
3259 decompress(ov, frame, frame->rawdata, frame->tempdata);
3261 yuv420raw_to_yuv420p(frame, frame->rawdata,
3264 deinterlace(frame, RAWFMT_YUV420, frame->tempdata,
3267 if (frame->compressed)
3268 decompress(ov, frame, frame->rawdata, frame->data);
3270 yuv420raw_to_yuv420p(frame, frame->rawdata,
3275 /* Post-processes the specified frame. This consists of:
3276 * 1. Decompress frame, if necessary
3277 * 2. Deinterlace frame and scale to proper size, if necessary
3278 * 3. Convert from YUV planar to destination format, if necessary
3279 * 4. Fix the RGB offset, if necessary
3282 ov51x_postprocess(struct usb_ov511 *ov, struct ov511_frame *frame)
3285 memset(frame->data, 0,
3286 MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3287 PDEBUG(4, "Dumping %d bytes", frame->bytes_recvd);
3288 memcpy(frame->data, frame->rawdata, frame->bytes_recvd);
3290 switch (frame->format) {
3291 case VIDEO_PALETTE_GREY:
3292 ov51x_postprocess_grey(ov, frame);
3294 case VIDEO_PALETTE_YUV420:
3295 case VIDEO_PALETTE_YUV420P:
3296 ov51x_postprocess_yuv420(ov, frame);
3299 err("Cannot convert data to %s",
3300 symbolic(v4l1_plist, frame->format));
3305 /**********************************************************************
3307 * OV51x data transfer, IRQ handler
3309 **********************************************************************/
3312 ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3315 int pnum = in[ov->packet_size - 1]; /* Get packet number */
3316 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3317 struct ov511_frame *frame = &ov->frame[ov->curframe];
3320 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3321 * byte non-zero. The EOF packet has image width/height in the
3322 * 10th and 11th bytes. The 9th byte is given as follows:
3325 * 6: compression enabled
3326 * 5: 422/420/400 modes
3327 * 4: 422/420/400 modes
3329 * 2: snapshot button on
3335 info("ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x",
3336 pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
3337 in[7], in[8], in[9], in[10], in[11]);
3340 /* Check for SOF/EOF packet */
3341 if ((in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) ||
3347 ts = (struct timeval *)(frame->data
3348 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3349 do_gettimeofday(ts);
3351 /* Get the actual frame size from the EOF header */
3352 frame->rawwidth = ((int)(in[9]) + 1) * 8;
3353 frame->rawheight = ((int)(in[10]) + 1) * 8;
3355 PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
3356 ov->curframe, pnum, frame->rawwidth, frame->rawheight,
3357 frame->bytes_recvd);
3359 /* Validate the header data */
3360 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3361 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight,
3364 /* Don't allow byte count to exceed buffer size */
3365 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3367 if (frame->scanstate == STATE_LINES) {
3370 frame->grabstate = FRAME_DONE;
3371 wake_up_interruptible(&frame->wq);
3373 /* If next frame is ready or grabbing,
3375 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3376 if (ov->frame[nextf].grabstate == FRAME_READY
3377 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3378 ov->curframe = nextf;
3379 ov->frame[nextf].scanstate = STATE_SCANNING;
3381 if (frame->grabstate == FRAME_DONE) {
3382 PDEBUG(4, "** Frame done **");
3384 PDEBUG(4, "Frame not ready? state = %d",
3385 ov->frame[nextf].grabstate);
3391 PDEBUG(5, "Frame done, but not scanning");
3393 /* Image corruption caused by misplaced frame->segment = 0
3394 * fixed by carlosf@conectiva.com.br
3398 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3400 /* Check to see if it's a snapshot frame */
3401 /* FIXME?? Should the snapshot reset go here? Performance? */
3403 frame->snapshot = 1;
3404 PDEBUG(3, "snapshot detected");
3407 frame->scanstate = STATE_LINES;
3408 frame->bytes_recvd = 0;
3409 frame->compressed = in[8] & 0x40;
3413 /* Are we in a frame? */
3414 if (frame->scanstate != STATE_LINES) {
3415 PDEBUG(5, "Not in a frame; packet skipped");
3419 /* If frame start, skip header */
3420 if (frame->bytes_recvd == 0)
3425 num = n - offset - 1;
3427 /* Dump all data exactly as received */
3429 frame->bytes_recvd += n - 1;
3430 if (frame->bytes_recvd <= max_raw)
3431 memcpy(frame->rawdata + frame->bytes_recvd - (n - 1),
3434 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3435 frame->bytes_recvd - max_raw);
3436 } else if (!frame->compressed && !remove_zeros) {
3437 frame->bytes_recvd += num;
3438 if (frame->bytes_recvd <= max_raw)
3439 memcpy(frame->rawdata + frame->bytes_recvd - num,
3442 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3443 frame->bytes_recvd - max_raw);
3444 } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
3445 int b, read = 0, allzero, copied = 0;
3447 frame->bytes_recvd += 32 - offset; // Bytes out
3448 memcpy(frame->rawdata, in + offset, 32 - offset);
3452 while (read < n - 1) {
3454 for (b = 0; b < 32; b++) {
3464 if (frame->bytes_recvd + copied + 32 <= max_raw)
3466 memcpy(frame->rawdata
3467 + frame->bytes_recvd + copied,
3471 PDEBUG(3, "Raw data buffer overrun!!");
3477 frame->bytes_recvd += copied;
3482 ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3484 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3485 struct ov511_frame *frame = &ov->frame[ov->curframe];
3488 /* Don't copy the packet number byte */
3489 if (ov->packet_numbering)
3492 /* A false positive here is likely, until OVT gives me
3493 * the definitive SOF/EOF format */
3494 if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
3496 info("ph: %2x %2x %2x %2x %2x %2x %2x %2x", in[0],
3497 in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
3500 if (frame->scanstate == STATE_LINES) {
3501 PDEBUG(4, "Detected frame end/start");
3503 } else { //scanstate == STATE_SCANNING
3505 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3513 ts = (struct timeval *)(frame->data
3514 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3515 do_gettimeofday(ts);
3517 PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
3519 (int)(in[9]), (int)(in[10]), frame->bytes_recvd);
3521 // FIXME: Since we don't know the header formats yet,
3522 // there is no way to know what the actual image size is
3523 frame->rawwidth = frame->width;
3524 frame->rawheight = frame->height;
3526 /* Validate the header data */
3527 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3528 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
3530 /* Don't allow byte count to exceed buffer size */
3531 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3533 if (frame->scanstate == STATE_LINES) {
3536 frame->grabstate = FRAME_DONE;
3537 wake_up_interruptible(&frame->wq);
3539 /* If next frame is ready or grabbing,
3541 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3542 if (ov->frame[nextf].grabstate == FRAME_READY
3543 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3544 ov->curframe = nextf;
3545 ov->frame[nextf].scanstate = STATE_SCANNING;
3546 frame = &ov->frame[nextf];
3548 if (frame->grabstate == FRAME_DONE) {
3549 PDEBUG(4, "** Frame done **");
3551 PDEBUG(4, "Frame not ready? state = %d",
3552 ov->frame[nextf].grabstate);
3556 PDEBUG(4, "SOF dropped (no active frame)");
3557 return; /* Nowhere to store this frame */
3561 PDEBUG(4, "Starting capture on frame %d", frame->framenum);
3563 // Snapshot not reverse-engineered yet.
3565 /* Check to see if it's a snapshot frame */
3566 /* FIXME?? Should the snapshot reset go here? Performance? */
3568 frame->snapshot = 1;
3569 PDEBUG(3, "snapshot detected");
3572 frame->scanstate = STATE_LINES;
3573 frame->bytes_recvd = 0;
3574 frame->compressed = 1;
3577 /* Are we in a frame? */
3578 if (frame->scanstate != STATE_LINES) {
3579 PDEBUG(4, "scanstate: no SOF yet");
3583 /* Dump all data exactly as received */
3585 frame->bytes_recvd += n;
3586 if (frame->bytes_recvd <= max_raw)
3587 memcpy(frame->rawdata + frame->bytes_recvd - n, in, n);
3589 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3590 frame->bytes_recvd - max_raw);
3592 /* All incoming data are divided into 8-byte segments. If the
3593 * segment contains all zero bytes, it must be skipped. These
3594 * zero-segments allow the OV518 to mainain a constant data rate
3595 * regardless of the effectiveness of the compression. Segments
3596 * are aligned relative to the beginning of each isochronous
3597 * packet. The first segment in each image is a header (the
3598 * decompressor skips it later).
3601 int b, read = 0, allzero, copied = 0;
3605 for (b = 0; b < 8; b++) {
3615 if (frame->bytes_recvd + copied + 8 <= max_raw)
3617 memcpy(frame->rawdata
3618 + frame->bytes_recvd + copied,
3622 PDEBUG(3, "Raw data buffer overrun!!");
3627 frame->bytes_recvd += copied;
3632 ov51x_isoc_irq(struct urb *urb, struct pt_regs *regs)
3635 struct usb_ov511 *ov;
3636 struct ov511_sbuf *sbuf;
3638 if (!urb->context) {
3639 PDEBUG(4, "no context");
3643 sbuf = urb->context;
3646 if (!ov || !ov->dev || !ov->user) {
3647 PDEBUG(4, "no device, or not open");
3651 if (!ov->streaming) {
3652 PDEBUG(4, "hmmm... not streaming, but got interrupt");
3656 if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
3657 PDEBUG(4, "URB unlinked");
3661 if (urb->status != -EINPROGRESS && urb->status != 0) {
3662 err("ERROR: urb->status=%d: %s", urb->status,
3663 symbolic(urb_errlist, urb->status));
3666 /* Copy the data received into our frame buffer */
3667 PDEBUG(5, "sbuf[%d]: Moving %d packets", sbuf->n,
3668 urb->number_of_packets);
3669 for (i = 0; i < urb->number_of_packets; i++) {
3670 /* Warning: Don't call *_move_data() if no frame active! */
3671 if (ov->curframe >= 0) {
3672 int n = urb->iso_frame_desc[i].actual_length;
3673 int st = urb->iso_frame_desc[i].status;
3674 unsigned char *cdata;
3676 urb->iso_frame_desc[i].actual_length = 0;
3677 urb->iso_frame_desc[i].status = 0;
3679 cdata = urb->transfer_buffer
3680 + urb->iso_frame_desc[i].offset;
3683 PDEBUG(4, "Zero-length packet");
3688 PDEBUG(2, "data error: [%d] len=%d, status=%d",
3691 if (ov->bclass == BCL_OV511)
3692 ov511_move_data(ov, cdata, n);
3693 else if (ov->bclass == BCL_OV518)
3694 ov518_move_data(ov, cdata, n);
3696 err("Unknown bridge device (%d)", ov->bridge);
3698 } else if (waitqueue_active(&ov->wq)) {
3699 wake_up_interruptible(&ov->wq);
3703 /* Resubmit this URB */
3705 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
3706 err("usb_submit_urb() ret %d", i);
3711 /****************************************************************************
3713 * Stream initialization and termination
3715 ***************************************************************************/
3718 ov51x_init_isoc(struct usb_ov511 *ov)
3721 int fx, err, n, size;
3723 PDEBUG(3, "*** Initializing capture ***");
3727 if (ov->bridge == BRG_OV511) {
3732 else if (cams == 3 || cams == 4)
3735 err("\"cams\" parameter too high!");
3738 } else if (ov->bridge == BRG_OV511PLUS) {
3743 else if (cams == 3 || cams == 4)
3745 else if (cams >= 5 && cams <= 8)
3747 else if (cams >= 9 && cams <= 31)
3750 err("\"cams\" parameter too high!");
3753 } else if (ov->bclass == BCL_OV518) {
3758 else if (cams == 3 || cams == 4)
3760 else if (cams >= 5 && cams <= 8)
3763 err("\"cams\" parameter too high!");
3767 err("invalid bridge type");
3771 // FIXME: OV518 is hardcoded to 15 FPS (alternate 5) for now
3772 if (ov->bclass == BCL_OV518) {
3773 if (packetsize == -1) {
3774 ov518_set_packet_size(ov, 640);
3776 info("Forcing packet size to %d", packetsize);
3777 ov518_set_packet_size(ov, packetsize);
3780 if (packetsize == -1) {
3781 ov511_set_packet_size(ov, size);
3783 info("Forcing packet size to %d", packetsize);
3784 ov511_set_packet_size(ov, packetsize);
3788 for (n = 0; n < OV511_NUMSBUF; n++) {
3789 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
3791 err("init isoc: usb_alloc_urb ret. NULL");
3794 ov->sbuf[n].urb = urb;
3796 urb->context = &ov->sbuf[n];
3797 urb->pipe = usb_rcvisocpipe(ov->dev, OV511_ENDPOINT_ADDRESS);
3798 urb->transfer_flags = URB_ISO_ASAP;
3799 urb->transfer_buffer = ov->sbuf[n].data;
3800 urb->complete = ov51x_isoc_irq;
3801 urb->number_of_packets = FRAMES_PER_DESC;
3802 urb->transfer_buffer_length = ov->packet_size * FRAMES_PER_DESC;
3804 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
3805 urb->iso_frame_desc[fx].offset = ov->packet_size * fx;
3806 urb->iso_frame_desc[fx].length = ov->packet_size;
3812 for (n = 0; n < OV511_NUMSBUF; n++) {
3813 ov->sbuf[n].urb->dev = ov->dev;
3814 err = usb_submit_urb(ov->sbuf[n].urb, GFP_KERNEL);
3816 err("init isoc: usb_submit_urb(%d) ret %d", n, err);
3825 ov51x_unlink_isoc(struct usb_ov511 *ov)
3829 /* Unschedule all of the iso td's */
3830 for (n = OV511_NUMSBUF - 1; n >= 0; n--) {
3831 if (ov->sbuf[n].urb) {
3832 usb_unlink_urb(ov->sbuf[n].urb);
3833 usb_free_urb(ov->sbuf[n].urb);
3834 ov->sbuf[n].urb = NULL;
3840 ov51x_stop_isoc(struct usb_ov511 *ov)
3842 if (!ov->streaming || !ov->dev)
3845 PDEBUG(3, "*** Stopping capture ***");
3847 if (ov->bclass == BCL_OV518)
3848 ov518_set_packet_size(ov, 0);
3850 ov511_set_packet_size(ov, 0);
3854 ov51x_unlink_isoc(ov);
3858 ov51x_new_frame(struct usb_ov511 *ov, int framenum)
3860 struct ov511_frame *frame;
3863 PDEBUG(4, "ov->curframe = %d, framenum = %d", ov->curframe, framenum);
3868 /* If we're not grabbing a frame right now and the other frame is */
3869 /* ready to be grabbed into, then use it instead */
3870 if (ov->curframe == -1) {
3871 newnum = (framenum - 1 + OV511_NUMFRAMES) % OV511_NUMFRAMES;
3872 if (ov->frame[newnum].grabstate == FRAME_READY)
3877 frame = &ov->frame[framenum];
3879 PDEBUG(4, "framenum = %d, width = %d, height = %d", framenum,
3880 frame->width, frame->height);
3882 frame->grabstate = FRAME_GRABBING;
3883 frame->scanstate = STATE_SCANNING;
3884 frame->snapshot = 0;
3886 ov->curframe = framenum;
3888 /* Make sure it's not too big */
3889 if (frame->width > ov->maxwidth)
3890 frame->width = ov->maxwidth;
3892 frame->width &= ~7L; /* Multiple of 8 */
3894 if (frame->height > ov->maxheight)
3895 frame->height = ov->maxheight;
3897 frame->height &= ~3L; /* Multiple of 4 */
3902 /****************************************************************************
3906 ***************************************************************************/
3909 * - You must acquire buf_lock before entering this function.
3910 * - Because this code will free any non-null pointer, you must be sure to null
3911 * them if you explicitly free them somewhere else!
3914 ov51x_do_dealloc(struct usb_ov511 *ov)
3917 PDEBUG(4, "entered");
3920 rvfree(ov->fbuf, OV511_NUMFRAMES
3921 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3931 vfree(ov->tempfbuf);
3932 ov->tempfbuf = NULL;
3935 for (i = 0; i < OV511_NUMSBUF; i++) {
3936 if (ov->sbuf[i].data) {
3937 kfree(ov->sbuf[i].data);
3938 ov->sbuf[i].data = NULL;
3942 for (i = 0; i < OV511_NUMFRAMES; i++) {
3943 ov->frame[i].data = NULL;
3944 ov->frame[i].rawdata = NULL;
3945 ov->frame[i].tempdata = NULL;
3946 if (ov->frame[i].compbuf) {
3947 free_page((unsigned long) ov->frame[i].compbuf);
3948 ov->frame[i].compbuf = NULL;
3952 PDEBUG(4, "buffer memory deallocated");
3953 ov->buf_state = BUF_NOT_ALLOCATED;
3954 PDEBUG(4, "leaving");
3958 ov51x_alloc(struct usb_ov511 *ov)
3961 const int w = ov->maxwidth;
3962 const int h = ov->maxheight;
3963 const int data_bufsize = OV511_NUMFRAMES * MAX_DATA_SIZE(w, h);
3964 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h);
3966 PDEBUG(4, "entered");
3967 down(&ov->buf_lock);
3969 if (ov->buf_state == BUF_ALLOCATED)
3972 ov->fbuf = rvmalloc(data_bufsize);
3976 ov->rawfbuf = vmalloc(raw_bufsize);
3980 memset(ov->rawfbuf, 0, raw_bufsize);
3982 ov->tempfbuf = vmalloc(raw_bufsize);
3986 memset(ov->tempfbuf, 0, raw_bufsize);
3988 for (i = 0; i < OV511_NUMSBUF; i++) {
3989 ov->sbuf[i].data = kmalloc(FRAMES_PER_DESC *
3990 MAX_FRAME_SIZE_PER_DESC, GFP_KERNEL);
3991 if (!ov->sbuf[i].data)
3994 PDEBUG(4, "sbuf[%d] @ %p", i, ov->sbuf[i].data);
3997 for (i = 0; i < OV511_NUMFRAMES; i++) {
3998 ov->frame[i].data = ov->fbuf + i * MAX_DATA_SIZE(w, h);
3999 ov->frame[i].rawdata = ov->rawfbuf
4000 + i * MAX_RAW_DATA_SIZE(w, h);
4001 ov->frame[i].tempdata = ov->tempfbuf
4002 + i * MAX_RAW_DATA_SIZE(w, h);
4004 ov->frame[i].compbuf =
4005 (unsigned char *) __get_free_page(GFP_KERNEL);
4006 if (!ov->frame[i].compbuf)
4009 PDEBUG(4, "frame[%d] @ %p", i, ov->frame[i].data);
4012 ov->buf_state = BUF_ALLOCATED;
4015 PDEBUG(4, "leaving");
4018 ov51x_do_dealloc(ov);
4020 PDEBUG(4, "errored");
4025 ov51x_dealloc(struct usb_ov511 *ov)
4027 PDEBUG(4, "entered");
4028 down(&ov->buf_lock);
4029 ov51x_do_dealloc(ov);
4031 PDEBUG(4, "leaving");
4034 /****************************************************************************
4038 ***************************************************************************/
4041 ov51x_v4l1_open(struct inode *inode, struct file *file)
4043 struct video_device *vdev = video_devdata(file);
4044 struct usb_ov511 *ov = video_get_drvdata(vdev);
4047 PDEBUG(4, "opening");
4057 /* In case app doesn't set them... */
4058 err = ov51x_set_default_params(ov);
4062 /* Make sure frames are reset */
4063 for (i = 0; i < OV511_NUMFRAMES; i++) {
4064 ov->frame[i].grabstate = FRAME_UNUSED;
4065 ov->frame[i].bytes_read = 0;
4068 /* If compression is on, make sure now that a
4069 * decompressor can be loaded */
4070 if (ov->compress && !ov->decomp_ops) {
4071 err = request_decompressor(ov);
4072 if (err && !dumppix)
4076 err = ov51x_alloc(ov);
4080 err = ov51x_init_isoc(ov);
4087 file->private_data = vdev;
4089 if (ov->led_policy == LED_AUTO)
4090 ov51x_led_control(ov, 1);
4098 ov51x_v4l1_close(struct inode *inode, struct file *file)
4100 struct video_device *vdev = file->private_data;
4101 struct usb_ov511 *ov = video_get_drvdata(vdev);
4103 PDEBUG(4, "ov511_close");
4108 ov51x_stop_isoc(ov);
4110 release_decompressor(ov);
4112 if (ov->led_policy == LED_AUTO)
4113 ov51x_led_control(ov, 0);
4120 /* Device unplugged while open. Only a minimum of unregistration is done
4121 * here; the disconnect callback already did the rest. */
4123 down(&ov->cbuf_lock);
4133 file->private_data = NULL;
4137 /* Do not call this function directly! */
4139 ov51x_v4l1_ioctl_internal(struct inode *inode, struct file *file,
4140 unsigned int cmd, void *arg)
4142 struct video_device *vdev = file->private_data;
4143 struct usb_ov511 *ov = video_get_drvdata(vdev);
4144 PDEBUG(5, "IOCtl: 0x%X", cmd);
4152 struct video_capability *b = arg;
4154 PDEBUG(4, "VIDIOCGCAP");
4156 memset(b, 0, sizeof(struct video_capability));
4157 sprintf(b->name, "%s USB Camera",
4158 symbolic(brglist, ov->bridge));
4159 b->type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE;
4160 b->channels = ov->num_inputs;
4162 b->maxwidth = ov->maxwidth;
4163 b->maxheight = ov->maxheight;
4164 b->minwidth = ov->minwidth;
4165 b->minheight = ov->minheight;
4171 struct video_channel *v = arg;
4173 PDEBUG(4, "VIDIOCGCHAN");
4175 if ((unsigned)(v->channel) >= ov->num_inputs) {
4176 err("Invalid channel (%d)", v->channel);
4181 v->type = VIDEO_TYPE_CAMERA;
4183 // v->flags |= (ov->has_decoder) ? VIDEO_VC_NORM : 0;
4185 decoder_get_input_name(ov, v->channel, v->name);
4191 struct video_channel *v = arg;
4194 PDEBUG(4, "VIDIOCSCHAN");
4196 /* Make sure it's not a camera */
4197 if (!ov->has_decoder) {
4198 if (v->channel == 0)
4204 if (v->norm != VIDEO_MODE_PAL &&
4205 v->norm != VIDEO_MODE_NTSC &&
4206 v->norm != VIDEO_MODE_SECAM &&
4207 v->norm != VIDEO_MODE_AUTO) {
4208 err("Invalid norm (%d)", v->norm);
4212 if ((unsigned)(v->channel) >= ov->num_inputs) {
4213 err("Invalid channel (%d)", v->channel);
4217 err = decoder_set_input(ov, v->channel);
4221 err = decoder_set_norm(ov, v->norm);
4229 struct video_picture *p = arg;
4231 PDEBUG(4, "VIDIOCGPICT");
4233 memset(p, 0, sizeof(struct video_picture));
4234 if (sensor_get_picture(ov, p))
4237 /* Can we get these from frame[0]? -claudio? */
4238 p->depth = ov->frame[0].depth;
4239 p->palette = ov->frame[0].format;
4245 struct video_picture *p = arg;
4248 PDEBUG(4, "VIDIOCSPICT");
4250 if (!get_depth(p->palette))
4253 if (sensor_set_picture(ov, p))
4256 if (force_palette && p->palette != force_palette) {
4257 info("Palette rejected (%s)",
4258 symbolic(v4l1_plist, p->palette));
4262 // FIXME: Format should be independent of frames
4263 if (p->palette != ov->frame[0].format) {
4264 PDEBUG(4, "Detected format change");
4266 rc = ov51x_wait_frames_inactive(ov);
4270 mode_init_regs(ov, ov->frame[0].width,
4271 ov->frame[0].height, p->palette, ov->sub_flag);
4274 PDEBUG(4, "Setting depth=%d, palette=%s",
4275 p->depth, symbolic(v4l1_plist, p->palette));
4277 for (i = 0; i < OV511_NUMFRAMES; i++) {
4278 ov->frame[i].depth = p->depth;
4279 ov->frame[i].format = p->palette;
4284 case VIDIOCGCAPTURE:
4288 PDEBUG(4, "VIDIOCGCAPTURE");
4293 case VIDIOCSCAPTURE:
4295 struct video_capture *vc = arg;
4297 PDEBUG(4, "VIDIOCSCAPTURE");
4313 if (vc->height == 0)
4318 ov->subw = vc->width;
4319 ov->subh = vc->height;
4325 struct video_window *vw = arg;
4328 PDEBUG(4, "VIDIOCSWIN: %dx%d", vw->width, vw->height);
4335 if (vw->height != ov->maxheight)
4337 if (vw->width != ov->maxwidth)
4341 rc = ov51x_wait_frames_inactive(ov);
4345 rc = mode_init_regs(ov, vw->width, vw->height,
4346 ov->frame[0].format, ov->sub_flag);
4350 for (i = 0; i < OV511_NUMFRAMES; i++) {
4351 ov->frame[i].width = vw->width;
4352 ov->frame[i].height = vw->height;
4359 struct video_window *vw = arg;
4361 memset(vw, 0, sizeof(struct video_window));
4362 vw->x = 0; /* FIXME */
4364 vw->width = ov->frame[0].width;
4365 vw->height = ov->frame[0].height;
4368 PDEBUG(4, "VIDIOCGWIN: %dx%d", vw->width, vw->height);
4374 struct video_mbuf *vm = arg;
4377 PDEBUG(4, "VIDIOCGMBUF");
4379 memset(vm, 0, sizeof(struct video_mbuf));
4380 vm->size = OV511_NUMFRAMES
4381 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4382 vm->frames = OV511_NUMFRAMES;
4385 for (i = 1; i < OV511_NUMFRAMES; i++) {
4386 vm->offsets[i] = vm->offsets[i-1]
4387 + MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4392 case VIDIOCMCAPTURE:
4394 struct video_mmap *vm = arg;
4396 unsigned int f = vm->frame;
4398 PDEBUG(4, "VIDIOCMCAPTURE: frame: %d, %dx%d, %s", f, vm->width,
4399 vm->height, symbolic(v4l1_plist, vm->format));
4401 depth = get_depth(vm->format);
4403 PDEBUG(2, "VIDIOCMCAPTURE: invalid format (%s)",
4404 symbolic(v4l1_plist, vm->format));
4408 if (f >= OV511_NUMFRAMES) {
4409 err("VIDIOCMCAPTURE: invalid frame (%d)", f);
4413 if (vm->width > ov->maxwidth
4414 || vm->height > ov->maxheight) {
4415 err("VIDIOCMCAPTURE: requested dimensions too big");
4419 if (ov->frame[f].grabstate == FRAME_GRABBING) {
4420 PDEBUG(4, "VIDIOCMCAPTURE: already grabbing");
4424 if (force_palette && (vm->format != force_palette)) {
4425 PDEBUG(2, "palette rejected (%s)",
4426 symbolic(v4l1_plist, vm->format));
4430 if ((ov->frame[f].width != vm->width) ||
4431 (ov->frame[f].height != vm->height) ||
4432 (ov->frame[f].format != vm->format) ||
4433 (ov->frame[f].sub_flag != ov->sub_flag) ||
4434 (ov->frame[f].depth != depth)) {
4435 PDEBUG(4, "VIDIOCMCAPTURE: change in image parameters");
4437 rc = ov51x_wait_frames_inactive(ov);
4441 rc = mode_init_regs(ov, vm->width, vm->height,
4442 vm->format, ov->sub_flag);
4445 PDEBUG(1, "Got error while initializing regs ");
4449 ov->frame[f].width = vm->width;
4450 ov->frame[f].height = vm->height;
4451 ov->frame[f].format = vm->format;
4452 ov->frame[f].sub_flag = ov->sub_flag;
4453 ov->frame[f].depth = depth;
4456 /* Mark it as ready */
4457 ov->frame[f].grabstate = FRAME_READY;
4459 PDEBUG(4, "VIDIOCMCAPTURE: renewing frame %d", f);
4461 return ov51x_new_frame(ov, f);
4465 unsigned int fnum = *((unsigned int *) arg);
4466 struct ov511_frame *frame;
4469 if (fnum >= OV511_NUMFRAMES) {
4470 err("VIDIOCSYNC: invalid frame (%d)", fnum);
4474 frame = &ov->frame[fnum];
4476 PDEBUG(4, "syncing to frame %d, grabstate = %d", fnum,
4479 switch (frame->grabstate) {
4483 case FRAME_GRABBING:
4489 rc = wait_event_interruptible(frame->wq,
4490 (frame->grabstate == FRAME_DONE)
4491 || (frame->grabstate == FRAME_ERROR));
4496 if (frame->grabstate == FRAME_ERROR) {
4497 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4503 if (ov->snap_enabled && !frame->snapshot) {
4504 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4509 frame->grabstate = FRAME_UNUSED;
4511 /* Reset the hardware snapshot button */
4512 /* FIXME - Is this the best place for this? */
4513 if ((ov->snap_enabled) && (frame->snapshot)) {
4514 frame->snapshot = 0;
4515 ov51x_clear_snapshot(ov);
4518 /* Decompression, format conversion, etc... */
4519 ov51x_postprocess(ov, frame);
4528 struct video_buffer *vb = arg;
4530 PDEBUG(4, "VIDIOCGFBUF");
4532 memset(vb, 0, sizeof(struct video_buffer));
4538 struct video_unit *vu = arg;
4540 PDEBUG(4, "VIDIOCGUNIT");
4542 memset(vu, 0, sizeof(struct video_unit));
4544 vu->video = ov->vdev->minor;
4545 vu->vbi = VIDEO_NO_UNIT;
4546 vu->radio = VIDEO_NO_UNIT;
4547 vu->audio = VIDEO_NO_UNIT;
4548 vu->teletext = VIDEO_NO_UNIT;
4554 struct ov511_i2c_struct *w = arg;
4556 return i2c_w_slave(ov, w->slave, w->reg, w->value, w->mask);
4560 struct ov511_i2c_struct *r = arg;
4563 rc = i2c_r_slave(ov, r->slave, r->reg);
4571 PDEBUG(3, "Unsupported IOCtl: 0x%X", cmd);
4572 return -ENOIOCTLCMD;
4579 ov51x_v4l1_ioctl(struct inode *inode, struct file *file,
4580 unsigned int cmd, unsigned long arg)
4582 struct video_device *vdev = file->private_data;
4583 struct usb_ov511 *ov = video_get_drvdata(vdev);
4586 if (down_interruptible(&ov->lock))
4589 rc = video_usercopy(inode, file, cmd, arg, ov51x_v4l1_ioctl_internal);
4596 ov51x_v4l1_read(struct file *file, char *buf, size_t cnt, loff_t *ppos)
4598 struct video_device *vdev = file->private_data;
4599 int noblock = file->f_flags&O_NONBLOCK;
4600 unsigned long count = cnt;
4601 struct usb_ov511 *ov = video_get_drvdata(vdev);
4602 int i, rc = 0, frmx = -1;
4603 struct ov511_frame *frame;
4605 if (down_interruptible(&ov->lock))
4608 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock);
4610 if (!vdev || !buf) {
4620 // FIXME: Only supports two frames
4621 /* See if a frame is completed, then use it. */
4622 if (ov->frame[0].grabstate >= FRAME_DONE) /* _DONE or _ERROR */
4624 else if (ov->frame[1].grabstate >= FRAME_DONE)/* _DONE or _ERROR */
4627 /* If nonblocking we return immediately */
4628 if (noblock && (frmx == -1)) {
4633 /* If no FRAME_DONE, look for a FRAME_GRABBING state. */
4634 /* See if a frame is in process (grabbing), then use it. */
4636 if (ov->frame[0].grabstate == FRAME_GRABBING)
4638 else if (ov->frame[1].grabstate == FRAME_GRABBING)
4642 /* If no frame is active, start one. */
4644 if ((rc = ov51x_new_frame(ov, frmx = 0))) {
4645 err("read: ov51x_new_frame error");
4650 frame = &ov->frame[frmx];
4658 /* Wait while we're grabbing the image */
4659 PDEBUG(4, "Waiting image grabbing");
4660 rc = wait_event_interruptible(frame->wq,
4661 (frame->grabstate == FRAME_DONE)
4662 || (frame->grabstate == FRAME_ERROR));
4667 PDEBUG(4, "Got image, frame->grabstate = %d", frame->grabstate);
4668 PDEBUG(4, "bytes_recvd = %d", frame->bytes_recvd);
4670 if (frame->grabstate == FRAME_ERROR) {
4671 frame->bytes_read = 0;
4672 err("** ick! ** Errored frame %d", ov->curframe);
4673 if (ov51x_new_frame(ov, frmx)) {
4674 err("read: ov51x_new_frame error");
4681 /* Repeat until we get a snapshot frame */
4682 if (ov->snap_enabled)
4683 PDEBUG(4, "Waiting snapshot frame");
4684 if (ov->snap_enabled && !frame->snapshot) {
4685 frame->bytes_read = 0;
4686 if ((rc = ov51x_new_frame(ov, frmx))) {
4687 err("read: ov51x_new_frame error");
4693 /* Clear the snapshot */
4694 if (ov->snap_enabled && frame->snapshot) {
4695 frame->snapshot = 0;
4696 ov51x_clear_snapshot(ov);
4699 /* Decompression, format conversion, etc... */
4700 ov51x_postprocess(ov, frame);
4702 PDEBUG(4, "frmx=%d, bytes_read=%ld, length=%ld", frmx,
4704 get_frame_length(frame));
4706 /* copy bytes to user space; we allow for partials reads */
4707 // if ((count + frame->bytes_read)
4708 // > get_frame_length((struct ov511_frame *)frame))
4709 // count = frame->scanlength - frame->bytes_read;
4711 /* FIXME - count hardwired to be one frame... */
4712 count = get_frame_length(frame);
4714 PDEBUG(4, "Copy to user space: %ld bytes", count);
4715 if ((i = copy_to_user(buf, frame->data + frame->bytes_read, count))) {
4716 PDEBUG(4, "Copy failed! %d bytes not copied", i);
4721 frame->bytes_read += count;
4722 PDEBUG(4, "{copy} count used=%ld, new bytes_read=%ld",
4723 count, frame->bytes_read);
4725 /* If all data have been read... */
4726 if (frame->bytes_read
4727 >= get_frame_length(frame)) {
4728 frame->bytes_read = 0;
4730 // FIXME: Only supports two frames
4731 /* Mark it as available to be used again. */
4732 ov->frame[frmx].grabstate = FRAME_UNUSED;
4733 if ((rc = ov51x_new_frame(ov, !frmx))) {
4734 err("ov51x_new_frame returned error");
4739 PDEBUG(4, "read finished, returning %ld (sweet)", count);
4750 ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4752 struct video_device *vdev = file->private_data;
4753 unsigned long start = vma->vm_start;
4754 unsigned long size = vma->vm_end - vma->vm_start;
4755 struct usb_ov511 *ov = video_get_drvdata(vdev);
4756 unsigned long page, pos;
4758 if (ov->dev == NULL)
4761 PDEBUG(4, "mmap: %ld (%lX) bytes", size, size);
4763 if (size > (((OV511_NUMFRAMES
4764 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
4765 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4768 if (down_interruptible(&ov->lock))
4771 pos = (unsigned long)ov->fbuf;
4773 page = kvirt_to_pa(pos);
4774 if (remap_page_range(vma, start, page, PAGE_SIZE,
4781 if (size > PAGE_SIZE)
4791 static struct file_operations ov511_fops = {
4792 .owner = THIS_MODULE,
4793 .open = ov51x_v4l1_open,
4794 .release = ov51x_v4l1_close,
4795 .read = ov51x_v4l1_read,
4796 .mmap = ov51x_v4l1_mmap,
4797 .ioctl = ov51x_v4l1_ioctl,
4798 .llseek = no_llseek,
4801 static struct video_device vdev_template = {
4802 .owner = THIS_MODULE,
4803 .name = "OV511 USB Camera",
4804 .type = VID_TYPE_CAPTURE,
4805 .hardware = VID_HARDWARE_OV511,
4806 .fops = &ov511_fops,
4807 .release = video_device_release,
4811 /****************************************************************************
4813 * OV511 and sensor configuration
4815 ***************************************************************************/
4817 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
4818 * the same register settings as the OV7610, since they are very similar.
4821 ov7xx0_configure(struct usb_ov511 *ov)
4826 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
4828 * Register 0x0f in the 7610 has the following effects:
4830 * 0x85 (AEC method 1): Best overall, good contrast range
4831 * 0x45 (AEC method 2): Very overexposed
4832 * 0xa5 (spec sheet default): Ok, but the black level is
4833 * shifted resulting in loss of contrast
4834 * 0x05 (old driver setting): very overexposed, too much
4837 static struct ov511_regvals aRegvalsNorm7610[] = {
4838 { OV511_I2C_BUS, 0x10, 0xff },
4839 { OV511_I2C_BUS, 0x16, 0x06 },
4840 { OV511_I2C_BUS, 0x28, 0x24 },
4841 { OV511_I2C_BUS, 0x2b, 0xac },
4842 { OV511_I2C_BUS, 0x12, 0x00 },
4843 { OV511_I2C_BUS, 0x38, 0x81 },
4844 { OV511_I2C_BUS, 0x28, 0x24 }, /* 0c */
4845 { OV511_I2C_BUS, 0x0f, 0x85 }, /* lg's setting */
4846 { OV511_I2C_BUS, 0x15, 0x01 },
4847 { OV511_I2C_BUS, 0x20, 0x1c },
4848 { OV511_I2C_BUS, 0x23, 0x2a },
4849 { OV511_I2C_BUS, 0x24, 0x10 },
4850 { OV511_I2C_BUS, 0x25, 0x8a },
4851 { OV511_I2C_BUS, 0x26, 0xa2 },
4852 { OV511_I2C_BUS, 0x27, 0xc2 },
4853 { OV511_I2C_BUS, 0x2a, 0x04 },
4854 { OV511_I2C_BUS, 0x2c, 0xfe },
4855 { OV511_I2C_BUS, 0x2d, 0x93 },
4856 { OV511_I2C_BUS, 0x30, 0x71 },
4857 { OV511_I2C_BUS, 0x31, 0x60 },
4858 { OV511_I2C_BUS, 0x32, 0x26 },
4859 { OV511_I2C_BUS, 0x33, 0x20 },
4860 { OV511_I2C_BUS, 0x34, 0x48 },
4861 { OV511_I2C_BUS, 0x12, 0x24 },
4862 { OV511_I2C_BUS, 0x11, 0x01 },
4863 { OV511_I2C_BUS, 0x0c, 0x24 },
4864 { OV511_I2C_BUS, 0x0d, 0x24 },
4865 { OV511_DONE_BUS, 0x0, 0x00 },
4868 static struct ov511_regvals aRegvalsNorm7620[] = {
4869 { OV511_I2C_BUS, 0x00, 0x00 },
4870 { OV511_I2C_BUS, 0x01, 0x80 },
4871 { OV511_I2C_BUS, 0x02, 0x80 },
4872 { OV511_I2C_BUS, 0x03, 0xc0 },
4873 { OV511_I2C_BUS, 0x06, 0x60 },
4874 { OV511_I2C_BUS, 0x07, 0x00 },
4875 { OV511_I2C_BUS, 0x0c, 0x24 },
4876 { OV511_I2C_BUS, 0x0c, 0x24 },
4877 { OV511_I2C_BUS, 0x0d, 0x24 },
4878 { OV511_I2C_BUS, 0x11, 0x01 },
4879 { OV511_I2C_BUS, 0x12, 0x24 },
4880 { OV511_I2C_BUS, 0x13, 0x01 },
4881 { OV511_I2C_BUS, 0x14, 0x84 },
4882 { OV511_I2C_BUS, 0x15, 0x01 },
4883 { OV511_I2C_BUS, 0x16, 0x03 },
4884 { OV511_I2C_BUS, 0x17, 0x2f },
4885 { OV511_I2C_BUS, 0x18, 0xcf },
4886 { OV511_I2C_BUS, 0x19, 0x06 },
4887 { OV511_I2C_BUS, 0x1a, 0xf5 },
4888 { OV511_I2C_BUS, 0x1b, 0x00 },
4889 { OV511_I2C_BUS, 0x20, 0x18 },
4890 { OV511_I2C_BUS, 0x21, 0x80 },
4891 { OV511_I2C_BUS, 0x22, 0x80 },
4892 { OV511_I2C_BUS, 0x23, 0x00 },
4893 { OV511_I2C_BUS, 0x26, 0xa2 },
4894 { OV511_I2C_BUS, 0x27, 0xea },
4895 { OV511_I2C_BUS, 0x28, 0x20 },
4896 { OV511_I2C_BUS, 0x29, 0x00 },
4897 { OV511_I2C_BUS, 0x2a, 0x10 },
4898 { OV511_I2C_BUS, 0x2b, 0x00 },
4899 { OV511_I2C_BUS, 0x2c, 0x88 },
4900 { OV511_I2C_BUS, 0x2d, 0x91 },
4901 { OV511_I2C_BUS, 0x2e, 0x80 },
4902 { OV511_I2C_BUS, 0x2f, 0x44 },
4903 { OV511_I2C_BUS, 0x60, 0x27 },
4904 { OV511_I2C_BUS, 0x61, 0x02 },
4905 { OV511_I2C_BUS, 0x62, 0x5f },
4906 { OV511_I2C_BUS, 0x63, 0xd5 },
4907 { OV511_I2C_BUS, 0x64, 0x57 },
4908 { OV511_I2C_BUS, 0x65, 0x83 },
4909 { OV511_I2C_BUS, 0x66, 0x55 },
4910 { OV511_I2C_BUS, 0x67, 0x92 },
4911 { OV511_I2C_BUS, 0x68, 0xcf },
4912 { OV511_I2C_BUS, 0x69, 0x76 },
4913 { OV511_I2C_BUS, 0x6a, 0x22 },
4914 { OV511_I2C_BUS, 0x6b, 0x00 },
4915 { OV511_I2C_BUS, 0x6c, 0x02 },
4916 { OV511_I2C_BUS, 0x6d, 0x44 },
4917 { OV511_I2C_BUS, 0x6e, 0x80 },
4918 { OV511_I2C_BUS, 0x6f, 0x1d },
4919 { OV511_I2C_BUS, 0x70, 0x8b },
4920 { OV511_I2C_BUS, 0x71, 0x00 },
4921 { OV511_I2C_BUS, 0x72, 0x14 },
4922 { OV511_I2C_BUS, 0x73, 0x54 },
4923 { OV511_I2C_BUS, 0x74, 0x00 },
4924 { OV511_I2C_BUS, 0x75, 0x8e },
4925 { OV511_I2C_BUS, 0x76, 0x00 },
4926 { OV511_I2C_BUS, 0x77, 0xff },
4927 { OV511_I2C_BUS, 0x78, 0x80 },
4928 { OV511_I2C_BUS, 0x79, 0x80 },
4929 { OV511_I2C_BUS, 0x7a, 0x80 },
4930 { OV511_I2C_BUS, 0x7b, 0xe2 },
4931 { OV511_I2C_BUS, 0x7c, 0x00 },
4932 { OV511_DONE_BUS, 0x0, 0x00 },
4935 PDEBUG(4, "starting configuration");
4937 /* This looks redundant, but is necessary for WebCam 3 */
4938 ov->primary_i2c_slave = OV7xx0_SID;
4939 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
4942 if (init_ov_sensor(ov) >= 0) {
4943 PDEBUG(1, "OV7xx0 sensor initalized (method 1)");
4945 /* Reset the 76xx */
4946 if (i2c_w(ov, 0x12, 0x80) < 0)
4949 /* Wait for it to initialize */
4950 schedule_timeout(1 + 150 * HZ / 1000);
4954 while (i <= i2c_detect_tries) {
4955 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
4956 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
4964 // Was (i == i2c_detect_tries) previously. This obviously used to always report
4965 // success. Whether anyone actually depended on that bug is unknown
4966 if ((i >= i2c_detect_tries) && (success == 0)) {
4967 err("Failed to read sensor ID. You might not have an");
4968 err("OV7610/20, or it may be not responding. Report");
4969 err("this to " EMAIL);
4970 err("This is only a warning. You can attempt to use");
4971 err("your camera anyway");
4972 // Only issue a warning for now
4975 PDEBUG(1, "OV7xx0 initialized (method 2, %dx)", i+1);
4979 /* Detect sensor (sub)type */
4980 rc = i2c_r(ov, OV7610_REG_COM_I);
4983 err("Error detecting sensor type");
4985 } else if ((rc & 3) == 3) {
4986 info("Sensor is an OV7610");
4987 ov->sensor = SEN_OV7610;
4988 } else if ((rc & 3) == 1) {
4989 /* I don't know what's different about the 76BE yet. */
4990 if (i2c_r(ov, 0x15) & 1)
4991 info("Sensor is an OV7620AE");
4993 info("Sensor is an OV76BE");
4995 /* OV511+ will return all zero isoc data unless we
4996 * configure the sensor as a 7620. Someone needs to
4997 * find the exact reg. setting that causes this. */
4998 if (ov->bridge == BRG_OV511PLUS) {
4999 info("Enabling 511+/7620AE workaround");
5000 ov->sensor = SEN_OV7620;
5002 ov->sensor = SEN_OV76BE;
5004 } else if ((rc & 3) == 0) {
5005 info("Sensor is an OV7620");
5006 ov->sensor = SEN_OV7620;
5008 err("Unknown image sensor version: %d", rc & 3);
5012 if (ov->sensor == SEN_OV7620) {
5013 PDEBUG(4, "Writing 7620 registers");
5014 if (write_regvals(ov, aRegvalsNorm7620))
5017 PDEBUG(4, "Writing 7610 registers");
5018 if (write_regvals(ov, aRegvalsNorm7610))
5022 /* Set sensor-specific vars */
5024 ov->maxheight = 480;
5028 // FIXME: These do not match the actual settings yet
5029 ov->brightness = 0x80 << 8;
5030 ov->contrast = 0x80 << 8;
5031 ov->colour = 0x80 << 8;
5032 ov->hue = 0x80 << 8;
5037 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
5039 ov6xx0_configure(struct usb_ov511 *ov)
5043 static struct ov511_regvals aRegvalsNorm6x20[] = {
5044 { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
5045 { OV511_I2C_BUS, 0x11, 0x01 },
5046 { OV511_I2C_BUS, 0x03, 0x60 },
5047 { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
5048 { OV511_I2C_BUS, 0x07, 0xa8 },
5049 /* The ratio of 0x0c and 0x0d controls the white point */
5050 { OV511_I2C_BUS, 0x0c, 0x24 },
5051 { OV511_I2C_BUS, 0x0d, 0x24 },
5052 { OV511_I2C_BUS, 0x0f, 0x15 }, /* COMS */
5053 { OV511_I2C_BUS, 0x10, 0x75 }, /* AEC Exposure time */
5054 { OV511_I2C_BUS, 0x12, 0x24 }, /* Enable AGC */
5055 { OV511_I2C_BUS, 0x14, 0x04 },
5056 /* 0x16: 0x06 helps frame stability with moving objects */
5057 { OV511_I2C_BUS, 0x16, 0x06 },
5058 // { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
5059 { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
5060 /* 0x28: 0x05 Selects RGB format if RGB on */
5061 { OV511_I2C_BUS, 0x28, 0x05 },
5062 { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
5063 // { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
5064 { OV511_I2C_BUS, 0x2d, 0x99 },
5065 { OV511_I2C_BUS, 0x33, 0xa0 }, /* Color Procesing Parameter */
5066 { OV511_I2C_BUS, 0x34, 0xd2 }, /* Max A/D range */
5067 { OV511_I2C_BUS, 0x38, 0x8b },
5068 { OV511_I2C_BUS, 0x39, 0x40 },
5070 { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
5071 { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
5072 { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
5074 { OV511_I2C_BUS, 0x3d, 0x80 },
5075 /* These next two registers (0x4a, 0x4b) are undocumented. They
5076 * control the color balance */
5077 { OV511_I2C_BUS, 0x4a, 0x80 },
5078 { OV511_I2C_BUS, 0x4b, 0x80 },
5079 { OV511_I2C_BUS, 0x4d, 0xd2 }, /* This reduces noise a bit */
5080 { OV511_I2C_BUS, 0x4e, 0xc1 },
5081 { OV511_I2C_BUS, 0x4f, 0x04 },
5082 // Do 50-53 have any effect?
5083 // Toggle 0x12[2] off and on here?
5084 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
5087 static struct ov511_regvals aRegvalsNorm6x30[] = {
5088 /*OK*/ { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
5089 { OV511_I2C_BUS, 0x11, 0x00 },
5090 /*OK*/ { OV511_I2C_BUS, 0x03, 0x60 },
5091 /*0A?*/ { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
5092 { OV511_I2C_BUS, 0x07, 0xa8 },
5093 /* The ratio of 0x0c and 0x0d controls the white point */
5094 /*OK*/ { OV511_I2C_BUS, 0x0c, 0x24 },
5095 /*OK*/ { OV511_I2C_BUS, 0x0d, 0x24 },
5096 /*A*/ { OV511_I2C_BUS, 0x0e, 0x20 },
5097 // /*04?*/ { OV511_I2C_BUS, 0x14, 0x80 },
5098 { OV511_I2C_BUS, 0x16, 0x03 },
5099 // /*OK*/ { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
5100 // 21 & 22? The suggested values look wrong. Go with default
5101 /*A*/ { OV511_I2C_BUS, 0x23, 0xc0 },
5102 /*A*/ { OV511_I2C_BUS, 0x25, 0x9a }, // Check this against default
5103 // /*OK*/ { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
5105 /* 0x28: 0x05 Selects RGB format if RGB on */
5106 // /*04?*/ { OV511_I2C_BUS, 0x28, 0x05 },
5107 // /*04?*/ { OV511_I2C_BUS, 0x28, 0x45 }, // DEBUG: Tristate UV bus
5109 /*OK*/ { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
5110 // /*OK*/ { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
5111 { OV511_I2C_BUS, 0x2d, 0x99 },
5112 // /*A*/ { OV511_I2C_BUS, 0x33, 0x26 }, // Reserved bits on 6620
5113 // /*d2?*/ { OV511_I2C_BUS, 0x34, 0x03 }, /* Max A/D range */
5114 // /*8b?*/ { OV511_I2C_BUS, 0x38, 0x83 },
5115 // /*40?*/ { OV511_I2C_BUS, 0x39, 0xc0 }, // 6630 adds bit 7
5116 // { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
5117 // { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
5118 // { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
5119 { OV511_I2C_BUS, 0x3d, 0x80 },
5120 // /*A*/ { OV511_I2C_BUS, 0x3f, 0x0e },
5122 /* These next two registers (0x4a, 0x4b) are undocumented. They
5123 * control the color balance */
5124 // /*OK?*/ { OV511_I2C_BUS, 0x4a, 0x80 }, // Check these
5125 // /*OK?*/ { OV511_I2C_BUS, 0x4b, 0x80 },
5126 { OV511_I2C_BUS, 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
5127 /*c1?*/ { OV511_I2C_BUS, 0x4e, 0x40 },
5129 /* UV average mode, color killer: strongest */
5130 { OV511_I2C_BUS, 0x4f, 0x07 },
5132 { OV511_I2C_BUS, 0x54, 0x23 }, /* Max AGC gain: 18dB */
5133 { OV511_I2C_BUS, 0x57, 0x81 }, /* (default) */
5134 { OV511_I2C_BUS, 0x59, 0x01 }, /* AGC dark current comp: +1 */
5135 { OV511_I2C_BUS, 0x5a, 0x2c }, /* (undocumented) */
5136 { OV511_I2C_BUS, 0x5b, 0x0f }, /* AWB chrominance levels */
5137 // { OV511_I2C_BUS, 0x5c, 0x10 },
5138 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
5141 PDEBUG(4, "starting sensor configuration");
5143 if (init_ov_sensor(ov) < 0) {
5144 err("Failed to read sensor ID. You might not have an OV6xx0,");
5145 err("or it may be not responding. Report this to " EMAIL);
5148 PDEBUG(1, "OV6xx0 sensor detected");
5151 /* Detect sensor (sub)type */
5152 rc = i2c_r(ov, OV7610_REG_COM_I);
5155 err("Error detecting sensor type");
5159 if ((rc & 3) == 0) {
5160 ov->sensor = SEN_OV6630;
5161 info("Sensor is an OV6630");
5162 } else if ((rc & 3) == 1) {
5163 ov->sensor = SEN_OV6620;
5164 info("Sensor is an OV6620");
5165 } else if ((rc & 3) == 2) {
5166 ov->sensor = SEN_OV6630;
5167 info("Sensor is an OV6630AE");
5168 } else if ((rc & 3) == 3) {
5169 ov->sensor = SEN_OV6630;
5170 info("Sensor is an OV6630AF");
5173 /* Set sensor-specific vars */
5175 ov->maxheight = 288;
5179 // FIXME: These do not match the actual settings yet
5180 ov->brightness = 0x80 << 8;
5181 ov->contrast = 0x80 << 8;
5182 ov->colour = 0x80 << 8;
5183 ov->hue = 0x80 << 8;
5185 if (ov->sensor == SEN_OV6620) {
5186 PDEBUG(4, "Writing 6x20 registers");
5187 if (write_regvals(ov, aRegvalsNorm6x20))
5190 PDEBUG(4, "Writing 6x30 registers");
5191 if (write_regvals(ov, aRegvalsNorm6x30))
5198 /* This initializes the KS0127 and KS0127B video decoders. */
5200 ks0127_configure(struct usb_ov511 *ov)
5204 // FIXME: I don't know how to sync or reset it yet
5206 if (ov51x_init_ks_sensor(ov) < 0) {
5207 err("Failed to initialize the KS0127");
5210 PDEBUG(1, "KS012x(B) sensor detected");
5214 /* Detect decoder subtype */
5215 rc = i2c_r(ov, 0x00);
5217 err("Error detecting sensor type");
5219 } else if (rc & 0x08) {
5220 rc = i2c_r(ov, 0x3d);
5222 err("Error detecting sensor type");
5224 } else if ((rc & 0x0f) == 0) {
5225 info("Sensor is a KS0127");
5226 ov->sensor = SEN_KS0127;
5227 } else if ((rc & 0x0f) == 9) {
5228 info("Sensor is a KS0127B Rev. A");
5229 ov->sensor = SEN_KS0127B;
5232 err("Error: Sensor is an unsupported KS0122");
5236 /* Set sensor-specific vars */
5238 ov->maxheight = 480;
5242 // FIXME: These do not match the actual settings yet
5243 ov->brightness = 0x80 << 8;
5244 ov->contrast = 0x80 << 8;
5245 ov->colour = 0x80 << 8;
5246 ov->hue = 0x80 << 8;
5248 /* This device is not supported yet. Bail out now... */
5249 err("This sensor is not supported yet.");
5255 /* This initializes the SAA7111A video decoder. */
5257 saa7111a_configure(struct usb_ov511 *ov)
5261 /* Since there is no register reset command, all registers must be
5262 * written, otherwise gives erratic results */
5263 static struct ov511_regvals aRegvalsNormSAA7111A[] = {
5264 { OV511_I2C_BUS, 0x06, 0xce },
5265 { OV511_I2C_BUS, 0x07, 0x00 },
5266 { OV511_I2C_BUS, 0x10, 0x44 }, /* YUV422, 240/286 lines */
5267 { OV511_I2C_BUS, 0x0e, 0x01 }, /* NTSC M or PAL BGHI */
5268 { OV511_I2C_BUS, 0x00, 0x00 },
5269 { OV511_I2C_BUS, 0x01, 0x00 },
5270 { OV511_I2C_BUS, 0x03, 0x23 },
5271 { OV511_I2C_BUS, 0x04, 0x00 },
5272 { OV511_I2C_BUS, 0x05, 0x00 },
5273 { OV511_I2C_BUS, 0x08, 0xc8 }, /* Auto field freq */
5274 { OV511_I2C_BUS, 0x09, 0x01 }, /* Chrom. trap off, APER=0.25 */
5275 { OV511_I2C_BUS, 0x0a, 0x80 }, /* BRIG=128 */
5276 { OV511_I2C_BUS, 0x0b, 0x40 }, /* CONT=1.0 */
5277 { OV511_I2C_BUS, 0x0c, 0x40 }, /* SATN=1.0 */
5278 { OV511_I2C_BUS, 0x0d, 0x00 }, /* HUE=0 */
5279 { OV511_I2C_BUS, 0x0f, 0x00 },
5280 { OV511_I2C_BUS, 0x11, 0x0c },
5281 { OV511_I2C_BUS, 0x12, 0x00 },
5282 { OV511_I2C_BUS, 0x13, 0x00 },
5283 { OV511_I2C_BUS, 0x14, 0x00 },
5284 { OV511_I2C_BUS, 0x15, 0x00 },
5285 { OV511_I2C_BUS, 0x16, 0x00 },
5286 { OV511_I2C_BUS, 0x17, 0x00 },
5287 { OV511_I2C_BUS, 0x02, 0xc0 }, /* Composite input 0 */
5288 { OV511_DONE_BUS, 0x0, 0x00 },
5291 // FIXME: I don't know how to sync or reset it yet
5293 if (ov51x_init_saa_sensor(ov) < 0) {
5294 err("Failed to initialize the SAA7111A");
5297 PDEBUG(1, "SAA7111A sensor detected");
5301 /* 640x480 not supported with PAL */
5304 ov->maxheight = 240; /* Even field only */
5307 ov->maxheight = 480; /* Even/Odd fields */
5311 ov->minheight = 240; /* Even field only */
5313 ov->has_decoder = 1;
5315 ov->norm = VIDEO_MODE_AUTO;
5316 ov->stop_during_set = 0; /* Decoder guarantees stable image */
5318 /* Decoder doesn't change these values, so we use these instead of
5319 * acutally reading the registers (which doesn't work) */
5320 ov->brightness = 0x80 << 8;
5321 ov->contrast = 0x40 << 9;
5322 ov->colour = 0x40 << 9;
5325 PDEBUG(4, "Writing SAA7111A registers");
5326 if (write_regvals(ov, aRegvalsNormSAA7111A))
5329 /* Detect version of decoder. This must be done after writing the
5330 * initial regs or the decoder will lock up. */
5331 rc = i2c_r(ov, 0x00);
5334 err("Error detecting sensor version");
5337 info("Sensor is an SAA7111A (version 0x%x)", rc);
5338 ov->sensor = SEN_SAA7111A;
5341 // FIXME: Fix this for OV518(+)
5342 /* Latch to negative edge of clock. Otherwise, we get incorrect
5343 * colors and jitter in the digital signal. */
5344 if (ov->bclass == BCL_OV511)
5345 reg_w(ov, 0x11, 0x00);
5347 warn("SAA7111A not yet supported with OV518/OV518+");
5352 /* This initializes the OV511/OV511+ and the sensor */
5354 ov511_configure(struct usb_ov511 *ov)
5356 static struct ov511_regvals aRegvalsInit511[] = {
5357 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5358 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5359 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5360 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5361 { OV511_REG_BUS, R51x_SYS_RESET, 0x3f },
5362 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5363 { OV511_REG_BUS, R51x_SYS_RESET, 0x3d },
5364 { OV511_DONE_BUS, 0x0, 0x00},
5367 static struct ov511_regvals aRegvalsNorm511[] = {
5368 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0x01 },
5369 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5370 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5371 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5372 { OV511_REG_BUS, R511_FIFO_OPTS, 0x1f },
5373 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5374 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5375 { OV511_DONE_BUS, 0x0, 0x00 },
5378 static struct ov511_regvals aRegvalsNorm511Plus[] = {
5379 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0xff },
5380 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5381 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5382 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5383 { OV511_REG_BUS, R511_FIFO_OPTS, 0xff },
5384 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5385 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5386 { OV511_DONE_BUS, 0x0, 0x00 },
5391 ov->customid = reg_r(ov, R511_SYS_CUST_ID);
5392 if (ov->customid < 0) {
5393 err("Unable to read camera bridge registers");
5397 PDEBUG (1, "CustomID = %d", ov->customid);
5398 ov->desc = symbolic(camlist, ov->customid);
5399 info("model: %s", ov->desc);
5401 if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) {
5402 err("Camera type (%d) not recognized", ov->customid);
5403 err("Please notify " EMAIL " of the name,");
5404 err("manufacturer, model, and this number of your camera.");
5405 err("Also include the output of the detection process.");
5408 if (ov->customid == 70) /* USB Life TV (PAL/SECAM) */
5411 if (write_regvals(ov, aRegvalsInit511))
5414 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5415 ov51x_led_control(ov, 0);
5417 /* The OV511+ has undocumented bits in the flow control register.
5418 * Setting it to 0xff fixes the corruption with moving objects. */
5419 if (ov->bridge == BRG_OV511) {
5420 if (write_regvals(ov, aRegvalsNorm511))
5422 } else if (ov->bridge == BRG_OV511PLUS) {
5423 if (write_regvals(ov, aRegvalsNorm511Plus))
5426 err("Invalid bridge");
5429 if (ov511_init_compression(ov))
5432 ov->packet_numbering = 1;
5433 ov511_set_packet_size(ov, 0);
5435 ov->snap_enabled = snapshot;
5438 PDEBUG(3, "Testing for 0V7xx0");
5439 ov->primary_i2c_slave = OV7xx0_SID;
5440 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5443 if (i2c_w(ov, 0x12, 0x80) < 0) {
5445 PDEBUG(3, "Testing for 0V6xx0");
5446 ov->primary_i2c_slave = OV6xx0_SID;
5447 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5450 if (i2c_w(ov, 0x12, 0x80) < 0) {
5452 PDEBUG(3, "Testing for 0V8xx0");
5453 ov->primary_i2c_slave = OV8xx0_SID;
5454 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5457 if (i2c_w(ov, 0x12, 0x80) < 0) {
5458 /* Test for SAA7111A */
5459 PDEBUG(3, "Testing for SAA7111A");
5460 ov->primary_i2c_slave = SAA7111A_SID;
5461 if (ov51x_set_slave_ids(ov, SAA7111A_SID) < 0)
5464 if (i2c_w(ov, 0x0d, 0x00) < 0) {
5465 /* Test for KS0127 */
5466 PDEBUG(3, "Testing for KS0127");
5467 ov->primary_i2c_slave = KS0127_SID;
5468 if (ov51x_set_slave_ids(ov, KS0127_SID) < 0)
5471 if (i2c_w(ov, 0x10, 0x00) < 0) {
5472 err("Can't determine sensor slave IDs");
5475 if (ks0127_configure(ov) < 0) {
5476 err("Failed to configure KS0127");
5481 if (saa7111a_configure(ov) < 0) {
5482 err("Failed to configure SAA7111A");
5487 err("Detected unsupported OV8xx0 sensor");
5491 if (ov6xx0_configure(ov) < 0) {
5492 err("Failed to configure OV6xx0");
5497 if (ov7xx0_configure(ov) < 0) {
5498 err("Failed to configure OV7xx0");
5506 err("OV511 Config failed");
5511 /* This initializes the OV518/OV518+ and the sensor */
5513 ov518_configure(struct usb_ov511 *ov)
5515 /* For 518 and 518+ */
5516 static struct ov511_regvals aRegvalsInit518[] = {
5517 { OV511_REG_BUS, R51x_SYS_RESET, 0x40 },
5518 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5519 { OV511_REG_BUS, R51x_SYS_RESET, 0x3e },
5520 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5521 { OV511_REG_BUS, R51x_SYS_RESET, 0x00 },
5522 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5523 { OV511_REG_BUS, 0x46, 0x00 },
5524 { OV511_REG_BUS, 0x5d, 0x03 },
5525 { OV511_DONE_BUS, 0x0, 0x00},
5528 static struct ov511_regvals aRegvalsNorm518[] = {
5529 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5530 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5531 { OV511_REG_BUS, 0x31, 0x0f },
5532 { OV511_REG_BUS, 0x5d, 0x03 },
5533 { OV511_REG_BUS, 0x24, 0x9f },
5534 { OV511_REG_BUS, 0x25, 0x90 },
5535 { OV511_REG_BUS, 0x20, 0x00 },
5536 { OV511_REG_BUS, 0x51, 0x04 },
5537 { OV511_REG_BUS, 0x71, 0x19 },
5538 { OV511_DONE_BUS, 0x0, 0x00 },
5541 static struct ov511_regvals aRegvalsNorm518Plus[] = {
5542 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5543 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5544 { OV511_REG_BUS, 0x31, 0x0f },
5545 { OV511_REG_BUS, 0x5d, 0x03 },
5546 { OV511_REG_BUS, 0x24, 0x9f },
5547 { OV511_REG_BUS, 0x25, 0x90 },
5548 { OV511_REG_BUS, 0x20, 0x60 },
5549 { OV511_REG_BUS, 0x51, 0x02 },
5550 { OV511_REG_BUS, 0x71, 0x19 },
5551 { OV511_REG_BUS, 0x40, 0xff },
5552 { OV511_REG_BUS, 0x41, 0x42 },
5553 { OV511_REG_BUS, 0x46, 0x00 },
5554 { OV511_REG_BUS, 0x33, 0x04 },
5555 { OV511_REG_BUS, 0x21, 0x19 },
5556 { OV511_REG_BUS, 0x3f, 0x10 },
5557 { OV511_DONE_BUS, 0x0, 0x00 },
5562 /* First 5 bits of custom ID reg are a revision ID on OV518 */
5563 info("Device revision %d", 0x1F & reg_r(ov, R511_SYS_CUST_ID));
5565 /* Give it the default description */
5566 ov->desc = symbolic(camlist, 0);
5568 if (write_regvals(ov, aRegvalsInit518))
5571 /* Set LED GPIO pin to output mode */
5572 if (reg_w_mask(ov, 0x57, 0x00, 0x02) < 0)
5575 /* LED is off by default with OV518; have to explicitly turn it on */
5576 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5577 ov51x_led_control(ov, 0);
5579 ov51x_led_control(ov, 1);
5581 /* Don't require compression if dumppix is enabled; otherwise it's
5582 * required. OV518 has no uncompressed mode, to save RAM. */
5583 if (!dumppix && !ov->compress) {
5585 warn("Compression required with OV518...enabling");
5588 if (ov->bridge == BRG_OV518) {
5589 if (write_regvals(ov, aRegvalsNorm518))
5591 } else if (ov->bridge == BRG_OV518PLUS) {
5592 if (write_regvals(ov, aRegvalsNorm518Plus))
5595 err("Invalid bridge");
5598 if (reg_w(ov, 0x2f, 0x80) < 0)
5601 if (ov518_init_compression(ov))
5604 if (ov->bridge == BRG_OV518)
5606 struct usb_interface *ifp;
5607 struct usb_host_interface *alt;
5610 ifp = usb_ifnum_to_if(ov->dev, 0);
5612 alt = usb_altnum_to_altsetting(ifp, 7);
5614 mxps = alt->endpoint[0].desc.wMaxPacketSize;
5617 /* Some OV518s have packet numbering by default, some don't */
5619 ov->packet_numbering = 1;
5621 ov->packet_numbering = 0;
5623 /* OV518+ has packet numbering turned on by default */
5624 ov->packet_numbering = 1;
5627 ov518_set_packet_size(ov, 0);
5629 ov->snap_enabled = snapshot;
5632 ov->primary_i2c_slave = OV7xx0_SID;
5633 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5636 /* The OV518 must be more aggressive about sensor detection since
5637 * I2C write will never fail if the sensor is not present. We have
5638 * to try to initialize the sensor to detect its presence */
5640 if (init_ov_sensor(ov) < 0) {
5642 ov->primary_i2c_slave = OV6xx0_SID;
5643 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5646 if (init_ov_sensor(ov) < 0) {
5648 ov->primary_i2c_slave = OV8xx0_SID;
5649 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5652 if (init_ov_sensor(ov) < 0) {
5653 err("Can't determine sensor slave IDs");
5656 err("Detected unsupported OV8xx0 sensor");
5660 if (ov6xx0_configure(ov) < 0) {
5661 err("Failed to configure OV6xx0");
5666 if (ov7xx0_configure(ov) < 0) {
5667 err("Failed to configure OV7xx0");
5673 ov->maxheight = 288;
5675 // The OV518 cannot go as low as the sensor can
5677 ov->minheight = 120;
5682 err("OV518 Config failed");
5687 /****************************************************************************
5689 ***************************************************************************/
5691 static inline struct usb_ov511 *cd_to_ov(struct class_device *cd)
5693 struct video_device *vdev = to_video_device(cd);
5694 return video_get_drvdata(vdev);
5697 static ssize_t show_custom_id(struct class_device *cd, char *buf)
5699 struct usb_ov511 *ov = cd_to_ov(cd);
5700 return sprintf(buf, "%d\n", ov->customid);
5702 static CLASS_DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
5704 static ssize_t show_model(struct class_device *cd, char *buf)
5706 struct usb_ov511 *ov = cd_to_ov(cd);
5707 return sprintf(buf, "%s\n", ov->desc);
5709 static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
5711 static ssize_t show_bridge(struct class_device *cd, char *buf)
5713 struct usb_ov511 *ov = cd_to_ov(cd);
5714 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
5716 static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
5718 static ssize_t show_sensor(struct class_device *cd, char *buf)
5720 struct usb_ov511 *ov = cd_to_ov(cd);
5721 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
5723 static CLASS_DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
5725 static ssize_t show_brightness(struct class_device *cd, char *buf)
5727 struct usb_ov511 *ov = cd_to_ov(cd);
5732 sensor_get_brightness(ov, &x);
5733 return sprintf(buf, "%d\n", x >> 8);
5735 static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
5737 static ssize_t show_saturation(struct class_device *cd, char *buf)
5739 struct usb_ov511 *ov = cd_to_ov(cd);
5744 sensor_get_saturation(ov, &x);
5745 return sprintf(buf, "%d\n", x >> 8);
5747 static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
5749 static ssize_t show_contrast(struct class_device *cd, char *buf)
5751 struct usb_ov511 *ov = cd_to_ov(cd);
5756 sensor_get_contrast(ov, &x);
5757 return sprintf(buf, "%d\n", x >> 8);
5759 static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
5761 static ssize_t show_hue(struct class_device *cd, char *buf)
5763 struct usb_ov511 *ov = cd_to_ov(cd);
5768 sensor_get_hue(ov, &x);
5769 return sprintf(buf, "%d\n", x >> 8);
5771 static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5773 static ssize_t show_exposure(struct class_device *cd, char *buf)
5775 struct usb_ov511 *ov = cd_to_ov(cd);
5780 sensor_get_exposure(ov, &exp);
5781 return sprintf(buf, "%d\n", exp >> 8);
5783 static CLASS_DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
5785 static void ov_create_sysfs(struct video_device *vdev)
5787 video_device_create_file(vdev, &class_device_attr_custom_id);
5788 video_device_create_file(vdev, &class_device_attr_model);
5789 video_device_create_file(vdev, &class_device_attr_bridge);
5790 video_device_create_file(vdev, &class_device_attr_sensor);
5791 video_device_create_file(vdev, &class_device_attr_brightness);
5792 video_device_create_file(vdev, &class_device_attr_saturation);
5793 video_device_create_file(vdev, &class_device_attr_contrast);
5794 video_device_create_file(vdev, &class_device_attr_hue);
5795 video_device_create_file(vdev, &class_device_attr_exposure);
5798 /****************************************************************************
5800 ***************************************************************************/
5803 ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5805 struct usb_device *dev = interface_to_usbdev(intf);
5806 struct usb_interface_descriptor *idesc;
5807 struct usb_ov511 *ov;
5810 PDEBUG(1, "probing for device...");
5812 /* We don't handle multi-config cameras */
5813 if (dev->descriptor.bNumConfigurations != 1)
5816 idesc = &intf->cur_altsetting->desc;
5818 if (idesc->bInterfaceClass != 0xFF)
5820 if (idesc->bInterfaceSubClass != 0x00)
5823 if ((ov = kmalloc(sizeof(*ov), GFP_KERNEL)) == NULL) {
5824 err("couldn't kmalloc ov struct");
5828 memset(ov, 0, sizeof(*ov));
5831 ov->iface = idesc->bInterfaceNumber;
5832 ov->led_policy = led;
5833 ov->compress = compress;
5834 ov->lightfreq = lightfreq;
5835 ov->num_inputs = 1; /* Video decoder init functs. change this */
5836 ov->stop_during_set = !fastset;
5837 ov->backlight = backlight;
5838 ov->mirror = mirror;
5839 ov->auto_brt = autobright;
5840 ov->auto_gain = autogain;
5841 ov->auto_exp = autoexp;
5843 switch (dev->descriptor.idProduct) {
5845 ov->bridge = BRG_OV511;
5846 ov->bclass = BCL_OV511;
5848 case PROD_OV511PLUS:
5849 ov->bridge = BRG_OV511PLUS;
5850 ov->bclass = BCL_OV511;
5853 ov->bridge = BRG_OV518;
5854 ov->bclass = BCL_OV518;
5856 case PROD_OV518PLUS:
5857 ov->bridge = BRG_OV518PLUS;
5858 ov->bclass = BCL_OV518;
5861 if (dev->descriptor.idVendor != VEND_MATTEL)
5863 ov->bridge = BRG_OV511PLUS;
5864 ov->bclass = BCL_OV511;
5867 err("Unknown product ID 0x%04x", dev->descriptor.idProduct);
5871 info("USB %s video device found", symbolic(brglist, ov->bridge));
5873 init_waitqueue_head(&ov->wq);
5875 init_MUTEX(&ov->lock); /* to 1 == available */
5876 init_MUTEX(&ov->buf_lock);
5877 init_MUTEX(&ov->param_lock);
5878 init_MUTEX(&ov->i2c_lock);
5879 init_MUTEX(&ov->cbuf_lock);
5881 ov->buf_state = BUF_NOT_ALLOCATED;
5883 if (usb_make_path(dev, ov->usb_path, OV511_USB_PATH_LEN) < 0) {
5884 err("usb_make_path error");
5888 /* Allocate control transfer buffer. */
5889 /* Must be kmalloc()'ed, for DMA compatibility */
5890 ov->cbuf = kmalloc(OV511_CBUF_SIZE, GFP_KERNEL);
5894 if (ov->bclass == BCL_OV518) {
5895 if (ov518_configure(ov) < 0)
5898 if (ov511_configure(ov) < 0)
5902 for (i = 0; i < OV511_NUMFRAMES; i++) {
5903 ov->frame[i].framenum = i;
5904 init_waitqueue_head(&ov->frame[i].wq);
5907 for (i = 0; i < OV511_NUMSBUF; i++) {
5908 ov->sbuf[i].ov = ov;
5909 spin_lock_init(&ov->sbuf[i].lock);
5913 /* Unnecessary? (This is done on open(). Need to make sure variables
5914 * are properly initialized without this before removing it, though). */
5915 if (ov51x_set_default_params(ov) < 0)
5920 if (ov->bclass == BCL_OV511)
5921 ov511_dump_regs(ov);
5923 ov518_dump_regs(ov);
5927 ov->vdev = video_device_alloc();
5931 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
5932 ov->vdev->dev = &dev->dev;
5933 video_set_drvdata(ov->vdev, ov);
5935 for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) {
5936 /* Minor 0 cannot be specified; assume user wants autodetect */
5937 if (unit_video[i] == 0)
5940 if (video_register_device(ov->vdev, VFL_TYPE_GRABBER,
5941 unit_video[i]) >= 0) {
5946 /* Use the next available one */
5947 if ((ov->vdev->minor == -1) &&
5948 video_register_device(ov->vdev, VFL_TYPE_GRABBER, -1) < 0) {
5949 err("video_register_device failed");
5953 info("Device at %s registered to minor %d", ov->usb_path,
5956 usb_set_intfdata(intf, ov);
5957 ov_create_sysfs(ov->vdev);
5962 if (-1 == ov->vdev->minor)
5963 video_device_release(ov->vdev);
5965 video_unregister_device(ov->vdev);
5970 down(&ov->cbuf_lock);
5982 err("Camera initialization failed");
5987 ov51x_disconnect(struct usb_interface *intf)
5989 struct usb_ov511 *ov = usb_get_intfdata(intf);
5994 usb_set_intfdata (intf, NULL);
6000 video_unregister_device(ov->vdev);
6002 for (n = 0; n < OV511_NUMFRAMES; n++)
6003 ov->frame[n].grabstate = FRAME_ERROR;
6007 /* This will cause the process to request another frame */
6008 for (n = 0; n < OV511_NUMFRAMES; n++)
6009 wake_up_interruptible(&ov->frame[n].wq);
6011 wake_up_interruptible(&ov->wq);
6014 ov51x_unlink_isoc(ov);
6018 /* Free the memory */
6019 if (ov && !ov->user) {
6020 down(&ov->cbuf_lock);
6030 PDEBUG(3, "Disconnect complete");
6033 static struct usb_driver ov511_driver = {
6034 .owner = THIS_MODULE,
6036 .id_table = device_table,
6037 .probe = ov51x_probe,
6038 .disconnect = ov51x_disconnect
6041 /****************************************************************************
6045 ***************************************************************************/
6047 /* Returns 0 for success */
6049 ov511_register_decomp_module(int ver, struct ov51x_decomp_ops *ops, int ov518,
6052 if (ver != DECOMP_INTERFACE_VER) {
6053 err("Decompression module has incompatible");
6054 err("interface version %d", ver);
6055 err("Interface version %d is required", DECOMP_INTERFACE_VER);
6062 if (mmx && !ov51x_mmx_available) {
6063 err("MMX not available on this system or kernel");
6071 if (ov518_mmx_decomp_ops)
6074 ov518_mmx_decomp_ops = ops;
6076 if (ov518_decomp_ops)
6079 ov518_decomp_ops = ops;
6083 if (ov511_mmx_decomp_ops)
6086 ov511_mmx_decomp_ops = ops;
6088 if (ov511_decomp_ops)
6091 ov511_decomp_ops = ops;
6104 ov511_deregister_decomp_module(int ov518, int mmx)
6110 ov518_mmx_decomp_ops = NULL;
6112 ov518_decomp_ops = NULL;
6115 ov511_mmx_decomp_ops = NULL;
6117 ov511_decomp_ops = NULL;
6124 usb_ov511_init(void)
6128 retval = usb_register(&ov511_driver);
6132 info(DRIVER_VERSION " : " DRIVER_DESC);
6139 usb_ov511_exit(void)
6141 usb_deregister(&ov511_driver);
6142 info("driver deregistered");
6146 module_init(usb_ov511_init);
6147 module_exit(usb_ov511_exit);
6149 EXPORT_SYMBOL(ov511_register_decomp_module);
6150 EXPORT_SYMBOL(ov511_deregister_decomp_module);