* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-static const char version[] = "1.17";
+static const char version[] = "1.25";
#define __NO_VERSION__
#define MAX_FRAME_SIZE (640 * 480 * 3)
#define MAX_DATA_SIZE (MAX_FRAME_SIZE + sizeof(struct timeval))
-#define DEFAULT_WIDTH 640
-#define DEFAULT_HEIGHT 480
-
#define GET_SEGSIZE(p) ((p) == VIDEO_PALETTE_GREY ? 256 : 384)
-#define GET_DEPTH(p) ((p) == VIDEO_PALETTE_GREY ? 8 : 24)
+#define GET_DEPTH(p) ((p) == VIDEO_PALETTE_GREY ? 8 : \
+ ((p) == VIDEO_PALETTE_YUV422 ? 16 : 24))
/* PARAMETER VARIABLES: */
static int autoadjust = 1; /* CCD dynamically changes exposure, etc... */
* programs that expect RGB data (e.g. gqcam) to work with this driver. */
static int force_rgb = 0;
+/* Number of seconds before inactive buffers are deallocated */
+static int buf_timeout = 5;
+
+/* Number of cameras to stream from simultaneously */
+static int cams = 1;
+
+/* Prevent apps from timing out if frame is not done in time */
+static int retry_sync = 0;
+
+/* Enable compression. This is for experimentation only; compressed images
+ * still cannot be decoded yet. */
+static int compress = 0;
+
+/* Display test pattern - doesn't work yet either */
+static int testpat = 0;
+
MODULE_PARM(autoadjust, "i");
+MODULE_PARM_DESC(autoadjust, "CCD dynamically changes exposure");
MODULE_PARM(debug, "i");
+MODULE_PARM_DESC(debug, "Debug level: 0=none, 1=init/detection, 2=warning, 3=config/control, 4=function call, 5=max");
MODULE_PARM(fix_rgb_offset, "i");
+MODULE_PARM_DESC(fix_rgb_offset, "Fix vertical misalignment of red and blue at 640x480");
MODULE_PARM(snapshot, "i");
+MODULE_PARM_DESC(snapshot, "Enable snapshot mode");
MODULE_PARM(sensor, "i");
+MODULE_PARM_DESC(sensor, "Override sensor detection");
MODULE_PARM(i2c_detect_tries, "i");
+MODULE_PARM_DESC(i2c_detect_tries, "Number of tries to detect sensor");
MODULE_PARM(aperture, "i");
+MODULE_PARM_DESC(aperture, "Read the OV7610/7620 specs");
MODULE_PARM(force_rgb, "i");
-
-MODULE_AUTHOR("Mark McClelland <mmcclelland@delphi.com> & Bret Wallach & Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha <cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>");
+MODULE_PARM_DESC(force_rgb, "Read RGB instead of BGR");
+MODULE_PARM(buf_timeout, "i");
+MODULE_PARM_DESC(buf_timeout, "Number of seconds before buffer deallocation");
+MODULE_PARM(cams, "i");
+MODULE_PARM_DESC(cams, "Number of simultaneous cameras");
+MODULE_PARM(retry_sync, "i");
+MODULE_PARM_DESC(retry_sync, "Prevent apps from timing out");
+MODULE_PARM(compress, "i");
+MODULE_PARM_DESC(compress, "Turn on compression (not functional yet)");
+MODULE_PARM(testpat, "i");
+MODULE_PARM_DESC(testpat, "Replace image with vertical bar testpattern (only partially working)");
+
+MODULE_AUTHOR("Mark McClelland <mwm@i.am> & Bret Wallach & Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha <cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>");
MODULE_DESCRIPTION("OV511 USB Camera Driver");
char kernel_version[] = UTS_RELEASE;
static struct usb_driver ov511_driver;
+/* I know, I know, global variables suck. This is only a temporary hack */
+int output_offset;
+
/**********************************************************************
* List of known OV511-based cameras
**********************************************************************/
{ -1, NULL }
};
+#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)
static struct palette_list plist[] = {
{ VIDEO_PALETTE_GREY, "GREY" },
{ VIDEO_PALETTE_HI240, "HI240" },
{ VIDEO_PALETTE_YUV410P,"YUV410P" },
{ -1, NULL }
};
+#endif
/**********************************************************************
*
PDEBUG(5, "reg write: 0x%02X:0x%02X, 0x%x", reg, value, rc);
if (rc < 0)
- err("ov511_reg_write: error %d", rc);
+ err("reg write: error %d", rc);
return rc;
}
PDEBUG(5, "reg read: 0x%02X:0x%02X", reg, buffer[0]);
if (rc < 0) {
- err("ov511_reg_read: error %d", rc);
+ err("reg read: error %d", rc);
return rc;
} else {
return buffer[0];
return 0;
error:
- err("ov511_i2c_write: error %d", rc);
+ err("i2c write: error %d", rc);
return rc;
}
return value;
error:
- err("ov511_i2c_read: error %d", rc);
+ err("i2c read: error %d", rc);
return rc;
}
return 0;
error:
- err("ov511_write_regvals: error %d", rc);
+ err("write regvals: error %d", rc);
return rc;
}
static void ov511_dump_i2c_regs(struct usb_device *dev)
{
PDEBUG(3, "I2C REGS");
- ov511_dump_i2c_range(dev, 0x00, 0x38);
+ ov511_dump_i2c_range(dev, 0x00, 0x7C);
}
+#if 0
static void ov511_dump_reg_range(struct usb_device *dev, int reg1, int regn)
{
int i;
}
}
-#if 0
static void ov511_dump_regs(struct usb_device *dev)
{
PDEBUG(1, "CAMERA INTERFACE REGS");
PDEBUG(1, "I2C REGS");
ov511_dump_reg_range(dev, 0x40, 0x49);
PDEBUG(1, "SYSTEM CONTROL REGS");
- ov511_dump_reg_range(dev, 0x50, 0x53);
+ ov511_dump_reg_range(dev, 0x50, 0x55);
ov511_dump_reg_range(dev, 0x5e, 0x5f);
PDEBUG(1, "OmniCE REGS");
ov511_dump_reg_range(dev, 0x70, 0x79);
if (ov511->bridge == BRG_OV511) {
if (size == 0) alt = OV511_ALT_SIZE_0;
else if (size == 257) alt = OV511_ALT_SIZE_257;
-// else if (size == 512) alt = OV511_ALT_SIZE_512;
else if (size == 513) alt = OV511_ALT_SIZE_513;
-// else if (size == 768) alt = OV511_ALT_SIZE_768;
else if (size == 769) alt = OV511_ALT_SIZE_769;
-// else if (size == 992) alt = OV511_ALT_SIZE_992;
else if (size == 993) alt = OV511_ALT_SIZE_993;
else {
err("Set packet size: invalid size (%d)", size);
if (ov511_i2c_write(dev, OV7610_REG_COM_B, ret & 0xfe) < 0)
return -EIO;
#endif
- if (ov511->sensor == SEN_OV7610 || ov511->sensor == SEN_OV7620AE)
- if(ov511_i2c_write(dev, OV7610_REG_SAT, p->colour >> 8) < 0)
+ if (ov511->sensor == SEN_OV7610 || ov511->sensor == SEN_OV7620AE
+ || ov511->sensor == SEN_OV6620)
+ if (ov511_i2c_write(dev, OV7610_REG_SAT, p->colour >> 8) < 0)
return -EIO;
- if (ov511->sensor == SEN_OV7610) {
- if(ov511_i2c_write(dev, OV7610_REG_CNT, p->contrast >> 8) < 0)
+ if (ov511->sensor == SEN_OV7610 || ov511->sensor == SEN_OV6620) {
+ if (ov511_i2c_write(dev, OV7610_REG_CNT, p->contrast >> 8) < 0)
return -EIO;
- if(ov511_i2c_write(dev, OV7610_REG_BRT, p->brightness >> 8) < 0)
+ if (ov511_i2c_write(dev, OV7610_REG_RED, 0xFF - (p->hue >> 8)) < 0)
+ return -EIO;
+
+ if (ov511_i2c_write(dev, OV7610_REG_BLUE, p->hue >> 8) < 0)
+ return -EIO;
+
+ if (ov511_i2c_write(dev, OV7610_REG_BRT, p->brightness >> 8) < 0)
return -EIO;
} else if ((ov511->sensor == SEN_OV7620)
|| (ov511->sensor == SEN_OV7620AE)) {
PDEBUG(1, "con=%d brt=%d", ov511_i2c_read(dev, OV7610_REG_CNT),
ov511_i2c_read(dev, OV7610_REG_BRT));
- if(ov511_i2c_write(dev, OV7610_REG_CNT, p->contrast >> 8) < 0)
+ if (ov511_i2c_write(dev, OV7610_REG_CNT, p->contrast >> 8) < 0)
return -EIO;
#endif
}
if (ov511_stop(dev) < 0)
return -EIO;
- if((ret = ov511_i2c_read(dev, OV7610_REG_SAT)) < 0) return -EIO;
+ if ((ret = ov511_i2c_read(dev, OV7610_REG_SAT)) < 0) return -EIO;
p->colour = ret << 8;
- if((ret = ov511_i2c_read(dev, OV7610_REG_CNT)) < 0) return -EIO;
+ if ((ret = ov511_i2c_read(dev, OV7610_REG_CNT)) < 0) return -EIO;
p->contrast = ret << 8;
- if((ret = ov511_i2c_read(dev, OV7610_REG_BRT)) < 0) return -EIO;
+ if ((ret = ov511_i2c_read(dev, OV7610_REG_BRT)) < 0) return -EIO;
p->brightness = ret << 8;
- p->hue = 0x8000;
+ /* This may not be the best way to do it */
+ if ((ret = ov511_i2c_read(dev, OV7610_REG_BLUE)) < 0) return -EIO;
+ p->hue = ret << 8;
+
p->whiteness = 105 << 8;
/* Can we get these from frame[0]? -claudio? */
return 0;
}
-/* FIXME: 176x144, 160x140 */
/* LNCNT values fixed by Lawrence Glaister <lg@jfm.bc.ca> */
static struct mode_list mlist[] = {
- /* W H C PXCNT LNCNT PXDIV LNDIV M420 COMA COMC COML */
- { 640, 480, 0, 0x4f, 0x3b, 0x00, 0x00, 0x03, 0x24, 0x04, 0x9e },
- { 640, 480, 1, 0x4f, 0x3b, 0x00, 0x00, 0x03, 0x24, 0x04, 0x9e },
- { 320, 240, 0, 0x27, 0x1d, 0x00, 0x00, 0x03, 0x04, 0x24, 0x1e },
- { 320, 240, 1, 0x27, 0x1d, 0x00, 0x00, 0x03, 0x04, 0x24, 0x1e },
- { 352, 288, 0, 0x2b, 0x25, 0x00, 0x00, 0x03, 0x04, 0x04, 0x1e },
- { 352, 288, 1, 0x2b, 0x25, 0x00, 0x00, 0x03, 0x04, 0x04, 0x1e },
- { 384, 288, 0, 0x2f, 0x25, 0x00, 0x00, 0x03, 0x04, 0x04, 0x1e },
- { 384, 288, 1, 0x2f, 0x25, 0x00, 0x00, 0x03, 0x04, 0x04, 0x1e },
- { 448, 336, 0, 0x37, 0x29, 0x00, 0x00, 0x03, 0x04, 0x04, 0x1e },
- { 448, 336, 1 ,0x37, 0x29, 0x00, 0x00, 0x03, 0x04, 0x04, 0x1e },
+ /* W H C PXCNT LNCNT PXDIV LNDIV M420 COMA COML */
+ { 640, 480, 0, 0x4f, 0x3b, 0x00, 0x00, 0x03, 0x24, 0x9e },
+ { 640, 480, 1, 0x4f, 0x3b, 0x00, 0x00, 0x03, 0x24, 0x9e },
+ { 320, 240, 0, 0x27, 0x1d, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 320, 240, 1, 0x27, 0x1d, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 352, 288, 0, 0x2b, 0x25, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 352, 288, 1, 0x2b, 0x25, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 384, 288, 0, 0x2f, 0x25, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 384, 288, 1, 0x2f, 0x25, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 448, 336, 0, 0x37, 0x29, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 448, 336, 1, 0x37, 0x29, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 176, 144, 0, 0x15, 0x12, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 176, 144, 1, 0x15, 0x12, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 160, 120, 0, 0x13, 0x0e, 0x00, 0x00, 0x03, 0x04, 0x1e },
+ { 160, 120, 1, 0x13, 0x0e, 0x00, 0x00, 0x03, 0x04, 0x1e },
{ 0, 0 }
};
{
int i;
struct usb_device *dev = ov511->dev;
- int hwsbase = 0, hwebase = 0;
+ int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
+ int hwscale = 0, vwscale = 0;
PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
width, height, mode, sub_flag);
ov511_reg_write(dev, 0x16, 0x00);
if (ov511->sensor == SEN_OV7610
|| ov511->sensor == SEN_OV7620AE) {
- /* these aren't valid on the OV7620 */
+ /* these aren't valid on the OV6620/OV7620 */
ov511_i2c_write(dev, 0x0e, 0x44);
}
ov511_i2c_write(dev, 0x13, autoadjust ? 0x21 : 0x20);
ov511_reg_write(dev, 0x16, 0x01);
if (ov511->sensor == SEN_OV7610
|| ov511->sensor == SEN_OV7620AE) {
- /* not valid on the OV7620 */
+ /* not valid on the OV6620/OV7620 */
ov511_i2c_write(dev, 0x0e, 0x04);
}
ov511_i2c_write(dev, 0x13, autoadjust ? 0x01 : 0x00);
case SEN_OV7620AE:
hwsbase = 0x38;
hwebase = 0x3a;
+ vwsbase = vwebase = 0x05;
+ break;
+ case SEN_OV6620:
+ hwsbase = 0x38;
+ hwebase = 0x39;
+ vwsbase = 0x03;
+ vwebase = 0x04;
break;
case SEN_OV7620:
hwsbase = 0x2c;
hwebase = 0x2d;
+ vwsbase = vwebase = 0x05;
break;
default:
- hwsbase = 0;
- hwebase = 0;
- break;
+ err("Invalid sensor");
+ return -EINVAL;
}
+ /* Bit 5 of COM C register varies with sensor */
+ if (ov511->sensor == SEN_OV6620) {
+ if (width > 176 && height > 144) { /* CIF */
+ ov511_i2c_write(dev, 0x14, 0x04);
+ hwscale = 1;
+ vwscale = 1; /* The datasheet says 0; it's wrong */
+ hwsize = 352;
+ vwsize = 288;
+ } else { /* QCIF */
+ ov511_i2c_write(dev, 0x14, 0x24);
+ hwsize = 176;
+ vwsize = 144;
+ }
+ }
+ else {
+ if (width > 320 && height > 240) { /* VGA */
+ ov511_i2c_write(dev, 0x14, 0x04);
+ hwscale = 2;
+ vwscale = 1;
+ hwsize = 640;
+ vwsize = 480;
+ } else { /* QVGA */
+ ov511_i2c_write(dev, 0x14, 0x24);
+ hwscale = 1;
+ hwsize = 320;
+ vwsize = 240;
+ }
+ }
+
+ /* FIXME! - This needs to be changed to support 160x120 and 6620!!! */
if (sub_flag) {
- ov511_i2c_write(dev, 0x17, hwsbase+(ov511->subx>>2));
- ov511_i2c_write(dev, 0x18, hwebase+((ov511->subx+ov511->subw)>>2));
- ov511_i2c_write(dev, 0x19, 0x5+(ov511->suby>>1));
- ov511_i2c_write(dev, 0x1a, 0x5+((ov511->suby+ov511->subh)>>1));
+ ov511_i2c_write(dev, 0x17, hwsbase+(ov511->subx>>hwscale));
+ ov511_i2c_write(dev, 0x18, hwebase+((ov511->subx+ov511->subw)>>hwscale));
+ ov511_i2c_write(dev, 0x19, vwsbase+(ov511->suby>>vwscale));
+ ov511_i2c_write(dev, 0x1a, vwebase+((ov511->suby+ov511->subh)>>vwscale));
} else {
ov511_i2c_write(dev, 0x17, hwsbase);
- ov511_i2c_write(dev, 0x18, hwebase + (640>>2));
- ov511_i2c_write(dev, 0x19, 0x5);
- ov511_i2c_write(dev, 0x1a, 5 + (480>>1));
+ ov511_i2c_write(dev, 0x18, hwebase + (hwsize>>hwscale));
+ ov511_i2c_write(dev, 0x19, vwsbase);
+ ov511_i2c_write(dev, 0x1a, vwebase + (vwsize>>vwscale));
}
for (i = 0; mlist[i].width; i++) {
#ifdef OV511_GBR422
ov511_i2c_write(dev, 0x12, mlist[i].common_A | 0x08);
#else
- ov511_i2c_write(dev, 0x12, mlist[i].common_A);
+ ov511_i2c_write(dev, 0x12, mlist[i].common_A | (testpat?0x02:0x00));
#endif
- ov511_i2c_write(dev, 0x14, mlist[i].common_C);
- /* 7620 doesn't have register 0x35, so play it safe */
- if (ov511->sensor != SEN_OV7620)
+ /* 7620/6620 don't have register 0x35, so play it safe */
+ if (ov511->sensor == SEN_OV7610 ||
+ ov511->sensor == SEN_OV7620AE)
ov511_i2c_write(dev, 0x35, mlist[i].common_L);
break;
}
+ if (compress) {
+ ov511_reg_write(dev, 0x78, 0x03); // Turn on Y compression
+ ov511_reg_write(dev, 0x79, 0x00); // Disable LUTs
+ }
+
if (ov511_restart(ov511->dev) < 0)
return -EIO;
*
* To avoid floating point arithmetic, the color conversion
* coefficients are scaled into 16.16 fixed-point integers.
+ * They were determined as follows:
+ *
+ * double brightness = 1.0; (0->black; 1->full scale)
+ * double saturation = 1.0; (0->greyscale; 1->full color)
+ * double fixScale = brightness * 256 * 256;
+ * int rvScale = (int)(1.402 * saturation * fixScale);
+ * int guScale = (int)(-0.344136 * saturation * fixScale);
+ * int gvScale = (int)(-0.714136 * saturation * fixScale);
+ * int buScale = (int)(1.772 * saturation * fixScale);
+ * int yScale = (int)(fixScale);
*/
/* LIMIT: convert a 16.16 fixed-point value to a byte, with clipping. */
ov511_move_420_block(int yTL, int yTR, int yBL, int yBR, int u, int v,
int rowPixels, unsigned char * rgb)
{
- const int rvScale = (1402000 * 1024) / 16525; /* 1.402 */
- const int guScale = (-344136 * 1024) / 16525; /* -.344136 */
- const int gvScale = (-714136 * 1024) / 16525; /* -.714136 */
- const int buScale = (1772000 * 1024) / 16525; /* 1.772 */
- const int yScale = (1000000 * 1024) / 16525; /* 1.0 */
+ const int rvScale = 91881;
+ const int guScale = -22553;
+ const int gvScale = -46801;
+ const int buScale = 116129;
+ const int yScale = 65536;
int r, g, b;
g = guScale * u + gvScale * v;
#undef OV511_DUMPPIX
+/* #define this and OV511_DUMPPIX to disable parsing of UV data */
+#undef OV511_FORCE_MONO
+
#ifdef OV511_GBR422
static void
ov511_parse_data_rgb24(unsigned char *pIn0, unsigned char *pOut0,
- int iOutY, int iOutUV, int iHalf, int iWidth)
+ int iOutY, int iOutUV, int iHalf, int iWidth)
{
int k, l, m;
unsigned char *pIn;
static void
ov511_parse_data_rgb24(unsigned char *pIn0, unsigned char *pOut0,
- int iOutY, int iOutUV, int iHalf, int iWidth)
+ int iOutY, int iOutUV, int iHalf, int iWidth)
{
#ifndef OV511_DUMPPIX
int k, l, m;
}
}
#else
+
+#ifndef OV511_FORCE_MONO
/* Just dump pix data straight out for debug */
int i, j;
}
pOut0 += (iWidth - WDIV) * 3;
}
+#else
+
+#if 1
+ /* This converts the Y data to "black-and-white" RGB data */
+ /* Useful for experimenting with compression */
+ int k, l, m;
+ unsigned char *pIn, *pOut, *pOut1;
+
+ pIn = pIn0 + 128;
+ pOut = pOut0 + iOutY;
+ for (k = 0; k < 4; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) {
+ for (m = 0; m < 8; m++) {
+ *pOut1++ = *pIn;
+ *pOut1++ = *pIn;
+ *pOut1++ = *pIn++;
+ }
+ pOut1 += (iWidth - 8) * 3;
+ }
+ pOut += 8 * 3;
+ }
+#else
+ /* This will dump the Y channel data stream as-is */
+ int count;
+ unsigned char *pIn, *pOut;
+
+ pIn = pIn0 + 128;
+ pOut = pOut0 + output_offset;
+ for (count = 0; count < 256; count++) {
+ *pOut++ = *pIn;
+ *pOut++ = *pIn;
+ *pOut++ = *pIn++;
+ output_offset += 3;
+ }
+#endif
+
+#endif
+
#endif
}
#endif
+/* This converts YUV420 segments to YUYV */
+static void
+ov511_parse_data_yuv422(unsigned char *pIn0, unsigned char *pOut0,
+ int iOutY, int iOutUV, int iWidth)
+{
+ int k, l, m;
+ unsigned char *pIn, *pOut, *pOut1;
+
+ pIn = pIn0 + 128;
+ pOut = pOut0 + iOutY;
+ for (k = 0; k < 4; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) {
+ for (m = 0; m < 8; m++) {
+ *pOut1 = (*pIn++);
+ pOut1 += 2;
+ }
+ pOut1 += (iWidth - 8) * 2;
+ }
+ pOut += 8 * 2;
+ }
+
+ pIn = pIn0;
+ pOut = pOut0 + iOutUV + 1;
+ for (l = 0; l < 8; l++) {
+ for (m=0; m<8; m++) {
+ int v = *(pIn+64);
+ int u = *pIn++;
+
+ *pOut = u;
+ *(pOut+2) = v;
+ *(pOut+iWidth) = u;
+ *(pOut+iWidth+2) = v;
+ pOut += 4;
+ }
+ pOut += (iWidth*4 - 32);
+ }
+}
+
+static void
+ov511_parse_data_yuv420(unsigned char *pIn0, unsigned char *pOut0,
+ int iOutY, int iOutUV, int iWidth, int iHeight)
+{
+ int k, l, m;
+ unsigned char *pIn;
+ unsigned char *pOut, *pOut1;
+ unsigned a = iWidth * iHeight;
+ unsigned w = iWidth / 2;
+
+ pIn = pIn0;
+ pOut = pOut0 + iOutUV + a;
+ for (k = 0; k < 8; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) *pOut1++ = *pIn++;
+ pOut += w;
+ }
+
+ pIn = pIn0 + 64;
+ pOut = pOut0 + iOutUV + a + a/4;
+ for (k = 0; k < 8; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) *pOut1++ = *pIn++;
+ pOut += w;
+ }
+
+ pIn = pIn0 + 128;
+ pOut = pOut0 + iOutY;
+ for (k = 0; k < 4; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) {
+ for (m = 0; m < 8; m++)
+ *pOut1++ =*pIn++;
+ pOut1 += iWidth - 8;
+ }
+ pOut += 8;
+ }
+}
+
+static void
+ov511_parse_data_yuv422p(unsigned char *pIn0, unsigned char *pOut0,
+ int iOutY, int iOutUV, int iWidth, int iHeight)
+{
+ int k, l, m;
+ unsigned char *pIn;
+ unsigned char *pOut, *pOut1;
+ unsigned a = iWidth * iHeight;
+ unsigned w = iWidth / 2;
+
+ pIn = pIn0;
+ pOut = pOut0 + iOutUV + a;
+ for (k = 0; k < 8; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) {
+ *pOut1 = *(pOut1 + w) = *pIn++;
+ pOut1++;
+ }
+ pOut += iWidth;
+ }
+
+ pIn = pIn0 + 64;
+ pOut = pOut0 + iOutUV + a + a/2;
+ for (k = 0; k < 8; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) {
+ *pOut1 = *(pOut1 + w) = *pIn++;
+ pOut1++;
+ }
+ pOut += iWidth;
+ }
+
+ pIn = pIn0 + 128;
+ pOut = pOut0 + iOutY;
+ for (k = 0; k < 4; k++) {
+ pOut1 = pOut;
+ for (l = 0; l < 8; l++) {
+ for (m = 0; m < 8; m++)
+ *pOut1++ =*pIn++;
+ pOut1 += iWidth - 8;
+ }
+ pOut += 8;
+ }
+}
+
/*
* For 640x480 RAW BW images, data shows up in 1200 256 byte segments.
* The segments represent 4 squares of 8x8 pixels as follows:
/* Frame start */
PDEBUG(4, "Frame start, framenum = %d", ov511->curframe);
+ output_offset = 0;
+
/* Check to see if it's a snapshot frame */
/* FIXME?? Should the snapshot reset go here? Performance? */
if (cdata[8] & 0x02) {
frame->segment < frame->width * frame->height / 256) {
int iSegY, iSegUV;
int iY, jY, iUV, jUV;
- int iOutY, iOutUV;
+ int iOutY, iOutYP, iOutUV, iOutUVP;
unsigned char *pOut;
iSegY = iSegUV = frame->segment;
*/
iY = iSegY / (frame->width / WDIV);
jY = iSegY - iY * (frame->width / WDIV);
- iOutY = (iY*HDIV*frame->width + jY*WDIV) * (frame->depth >> 3);
+ iOutYP = iY*HDIV*frame->width + jY*WDIV;
+ iOutY = iOutYP * (frame->depth >> 3);
iUV = iSegUV / (frame->width / WDIV * 2);
jUV = iSegUV - iUV * (frame->width / WDIV * 2);
- iOutUV = (iUV*HDIV*2*frame->width + jUV*WDIV/2) * (frame->depth >> 3);
+ iOutUVP = iUV*HDIV*2*frame->width + jUV*WDIV/2;
+ iOutUV = iOutUVP * (frame->depth >> 3);
switch (frame->format) {
case VIDEO_PALETTE_GREY:
ov511_parse_data_rgb24 (pData, pOut, iOutY, iOutUV,
iY & 1, frame->width);
break;
+ case VIDEO_PALETTE_YUV422:
+ case VIDEO_PALETTE_YUYV:
+ ov511_parse_data_yuv422(pData, pOut, iOutY, iOutUV, frame->width);
+ break;
+ case VIDEO_PALETTE_YUV420:
+ ov511_parse_data_yuv420 (pData, pOut, iOutYP, iUV*HDIV*frame->width/2 + jUV*WDIV/4,
+ frame->width, frame->height);
+ break;
+ case VIDEO_PALETTE_YUV422P:
+ ov511_parse_data_yuv422p (pData, pOut, iOutYP, iOutUVP/2,
+ frame->width, frame->height);
+ break;
+ default:
+ err("Unsupported format: %d", frame->format);
}
pData = &cdata[iPix];
return;
if (!ov511->streaming) {
- PDEBUG(2, "hmmm... not streaming, but got interrupt");
+ PDEBUG(4, "hmmm... not streaming, but got interrupt");
return;
}
static int ov511_init_isoc(struct usb_ov511 *ov511)
{
urb_t *urb;
- int fx, err;
+ int fx, err, n, size;
PDEBUG(3, "*** Initializing capture ***");
ov511->scratchlen = 0;
if (ov511->bridge == BRG_OV511)
- ov511_set_packet_size(ov511, 993);
+ if (cams == 1) size = 993;
+ else if (cams == 2) size = 513;
+ else if (cams == 3 || cams == 4) size = 257;
+ else {
+ err("\"cams\" parameter too high!");
+ return -1;
+ }
else if (ov511->bridge == BRG_OV511PLUS)
- ov511_set_packet_size(ov511, 961);
- else
+ if (cams == 1) size = 961;
+ else if (cams == 2) size = 513;
+ else if (cams == 3 || cams == 4) size = 257;
+ else if (cams >= 5 && cams <= 8) size = 129;
+ else if (cams >= 9 && cams <= 31) size = 33;
+ else {
+ err("\"cams\" parameter too high!");
+ return -1;
+ }
+ else {
err("invalid bridge type");
+ return -1;
+ }
+
+ ov511_set_packet_size(ov511, size);
- /* We double buffer the Iso lists */
- urb = usb_alloc_urb(FRAMES_PER_DESC);
+ for (n = 0; n < OV511_NUMSBUF; n++) {
+ urb = usb_alloc_urb(FRAMES_PER_DESC);
- if (!urb) {
- err("ov511_init_isoc: usb_alloc_urb ret. NULL");
- return -ENOMEM;
- }
- ov511->sbuf[0].urb = urb;
- urb->dev = ov511->dev;
- urb->context = ov511;
- urb->pipe = usb_rcvisocpipe(ov511->dev, OV511_ENDPOINT_ADDRESS);
- urb->transfer_flags = USB_ISO_ASAP;
- urb->transfer_buffer = ov511->sbuf[0].data;
- urb->complete = ov511_isoc_irq;
- urb->number_of_packets = FRAMES_PER_DESC;
- urb->transfer_buffer_length = ov511->packet_size * FRAMES_PER_DESC;
- for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
- urb->iso_frame_desc[fx].offset = ov511->packet_size * fx;
- urb->iso_frame_desc[fx].length = ov511->packet_size;
- }
-
- urb = usb_alloc_urb(FRAMES_PER_DESC);
- if (!urb) {
- err("ov511_init_isoc: usb_alloc_urb ret. NULL");
- return -ENOMEM;
- }
- ov511->sbuf[1].urb = urb;
- urb->dev = ov511->dev;
- urb->context = ov511;
- urb->pipe = usb_rcvisocpipe(ov511->dev, OV511_ENDPOINT_ADDRESS);
- urb->transfer_flags = USB_ISO_ASAP;
- urb->transfer_buffer = ov511->sbuf[1].data;
- urb->complete = ov511_isoc_irq;
- urb->number_of_packets = FRAMES_PER_DESC;
- urb->transfer_buffer_length = ov511->packet_size * FRAMES_PER_DESC;
- for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
- urb->iso_frame_desc[fx].offset = ov511->packet_size * fx;
- urb->iso_frame_desc[fx].length = ov511->packet_size;
+ if (!urb) {
+ err("init isoc: usb_alloc_urb ret. NULL");
+ return -ENOMEM;
+ }
+ ov511->sbuf[n].urb = urb;
+ urb->dev = ov511->dev;
+ urb->context = ov511;
+ urb->pipe = usb_rcvisocpipe(ov511->dev, OV511_ENDPOINT_ADDRESS);
+ urb->transfer_flags = USB_ISO_ASAP;
+ urb->transfer_buffer = ov511->sbuf[n].data;
+ urb->complete = ov511_isoc_irq;
+ urb->number_of_packets = FRAMES_PER_DESC;
+ urb->transfer_buffer_length = ov511->packet_size * FRAMES_PER_DESC;
+ for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
+ urb->iso_frame_desc[fx].offset = ov511->packet_size * fx;
+ urb->iso_frame_desc[fx].length = ov511->packet_size;
+ }
}
- ov511->sbuf[1].urb->next = ov511->sbuf[0].urb;
- ov511->sbuf[0].urb->next = ov511->sbuf[1].urb;
+ ov511->sbuf[OV511_NUMSBUF - 1].urb->next = ov511->sbuf[0].urb;
+ for (n = 0; n < OV511_NUMSBUF - 1; n++)
+ ov511->sbuf[n].urb->next = ov511->sbuf[n+1].urb;
- err = usb_submit_urb(ov511->sbuf[0].urb);
- if (err)
- err("ov511_init_isoc: usb_submit_urb(0) ret %d", err);
- err = usb_submit_urb(ov511->sbuf[1].urb);
- if (err)
- err("ov511_init_isoc: usb_submit_urb(1) ret %d", err);
+ for (n = 0; n < OV511_NUMSBUF; n++) {
+ err = usb_submit_urb(ov511->sbuf[n].urb);
+ if (err)
+ err("init isoc: usb_submit_urb(%d) ret %d", n, err);
+ }
ov511->streaming = 1;
static void ov511_stop_isoc(struct usb_ov511 *ov511)
{
+ int n;
+
if (!ov511->streaming || !ov511->dev)
return;
ov511->streaming = 0;
/* Unschedule all of the iso td's */
- if (ov511->sbuf[1].urb) {
- ov511->sbuf[1].urb->next = NULL;
- usb_unlink_urb(ov511->sbuf[1].urb);
- usb_free_urb(ov511->sbuf[1].urb);
- ov511->sbuf[1].urb = NULL;
- }
- if (ov511->sbuf[0].urb) {
- ov511->sbuf[0].urb->next = NULL;
- usb_unlink_urb(ov511->sbuf[0].urb);
- usb_free_urb(ov511->sbuf[0].urb);
- ov511->sbuf[0].urb = NULL;
+ for (n = OV511_NUMSBUF - 1; n >= 0; n--) {
+ if (ov511->sbuf[n].urb) {
+ ov511->sbuf[n].urb->next = NULL;
+ usb_unlink_urb(ov511->sbuf[n].urb);
+ usb_free_urb(ov511->sbuf[n].urb);
+ ov511->sbuf[n].urb = NULL;
+ }
}
}
static int ov511_new_frame(struct usb_ov511 *ov511, int framenum)
{
struct ov511_frame *frame;
- int width, height;
PDEBUG(4, "ov511->curframe = %d, framenum = %d", ov511->curframe,
framenum);
return 0;
frame = &ov511->frame[framenum];
- width = frame->width;
- height = frame->height;
- PDEBUG (4, "framenum = %d, width = %d, height = %d", framenum, width,
- height);
+ PDEBUG (4, "framenum = %d, width = %d, height = %d", framenum,
+ frame->width, frame->height);
frame->grabstate = FRAME_GRABBING;
frame->scanstate = STATE_SCANNING;
ov511->curframe = framenum;
/* Make sure it's not too big */
- if (width > DEFAULT_WIDTH)
- width = DEFAULT_WIDTH;
+ if (frame->width > ov511->maxwidth)
+ frame->width = ov511->maxwidth;
- width &= ~7L; /* Multiple of 8 */
+ frame->width &= ~7L; /* Multiple of 8 */
- if (height > DEFAULT_HEIGHT)
- height = DEFAULT_HEIGHT;
+ if (frame->height > ov511->maxheight)
+ frame->height = ov511->maxheight;
- width &= ~3L; /* Multiple of 4 */
+ frame->height &= ~3L; /* Multiple of 4 */
return 0;
}
+/****************************************************************************
+ *
+ * Buffer management
+ *
+ ***************************************************************************/
+static int ov511_alloc(struct usb_ov511 *ov511)
+{
+ int i;
+
+ PDEBUG(4, "entered");
+ down(&ov511->buf_lock);
+
+ if (ov511->buf_state == BUF_PEND_DEALLOC) {
+ ov511->buf_state = BUF_ALLOCATED;
+ del_timer(&ov511->buf_timer);
+ }
+
+ if (ov511->buf_state == BUF_ALLOCATED)
+ goto out;
+
+ ov511->fbuf = rvmalloc(OV511_NUMFRAMES * MAX_DATA_SIZE);
+ if (!ov511->fbuf)
+ goto error;
+
+ for (i = 0; i < OV511_NUMFRAMES; i++) {
+ ov511->frame[i].grabstate = FRAME_UNUSED;
+ ov511->frame[i].data = ov511->fbuf + i * MAX_DATA_SIZE;
+ PDEBUG(4, "frame[%d] @ %p", i, ov511->frame[i].data);
+
+ ov511->sbuf[i].data = kmalloc(FRAMES_PER_DESC *
+ MAX_FRAME_SIZE_PER_DESC, GFP_KERNEL);
+ if (!ov511->sbuf[i].data) {
+ while (--i) {
+ kfree(ov511->sbuf[i].data);
+ ov511->sbuf[i].data = NULL;
+ }
+ rvfree(ov511->fbuf, OV511_NUMFRAMES * MAX_DATA_SIZE);
+ ov511->fbuf = NULL;
+ goto error;
+ }
+ PDEBUG(4, "sbuf[%d] @ %p", i, ov511->sbuf[i].data);
+ }
+ ov511->buf_state = BUF_ALLOCATED;
+out:
+ up(&ov511->buf_lock);
+ PDEBUG(4, "leaving");
+ return 0;
+error:
+ ov511->buf_state = BUF_NOT_ALLOCATED;
+ up(&ov511->buf_lock);
+ PDEBUG(4, "errored");
+ return -ENOMEM;
+}
+
+/*
+ * - You must acquire buf_lock before entering this function.
+ * - Because this code will free any non-null pointer, you must be sure to null
+ * them if you explicitly free them somewhere else!
+ */
+static void ov511_do_dealloc(struct usb_ov511 *ov511)
+{
+ int i;
+ PDEBUG(4, "entered");
+
+ if (ov511->fbuf) {
+ rvfree(ov511->fbuf, OV511_NUMFRAMES * MAX_DATA_SIZE);
+ ov511->fbuf = NULL;
+ }
+
+ for (i = 0; i < OV511_NUMFRAMES; i++) {
+ if (ov511->sbuf[i].data) {
+ kfree(ov511->sbuf[i].data);
+ ov511->sbuf[i].data = NULL;
+ }
+ }
+
+ PDEBUG(4, "buffer memory deallocated");
+ ov511->buf_state = BUF_NOT_ALLOCATED;
+ PDEBUG(4, "leaving");
+}
+
+static void ov511_buf_callback(unsigned long data)
+{
+ struct usb_ov511 *ov511 = (struct usb_ov511 *)data;
+ PDEBUG(4, "entered");
+ down(&ov511->buf_lock);
+
+ if (ov511->buf_state == BUF_PEND_DEALLOC)
+ ov511_do_dealloc(ov511);
+
+ up(&ov511->buf_lock);
+ PDEBUG(4, "leaving");
+}
+
+static void ov511_dealloc(struct usb_ov511 *ov511, int now)
+{
+ struct timer_list *bt = &(ov511->buf_timer);
+ PDEBUG(4, "entered");
+ down(&ov511->buf_lock);
+
+ PDEBUG(4, "deallocating buffer memory %s", now ? "now" : "later");
+
+ if (ov511->buf_state == BUF_PEND_DEALLOC) {
+ ov511->buf_state = BUF_ALLOCATED;
+ del_timer(bt);
+ }
+
+ if (now)
+ ov511_do_dealloc(ov511);
+ else {
+ ov511->buf_state = BUF_PEND_DEALLOC;
+ init_timer(bt);
+ bt->function = ov511_buf_callback;
+ bt->data = (unsigned long)ov511;
+ bt->expires = jiffies + buf_timeout * HZ;
+ add_timer(bt);
+ }
+ up(&ov511->buf_lock);
+ PDEBUG(4, "leaving");
+}
+
/****************************************************************************
*
* V4L API
static int ov511_open(struct video_device *dev, int flags)
{
struct usb_ov511 *ov511 = (struct usb_ov511 *)dev;
- int i, err = 0;
+ int err = 0;
MOD_INC_USE_COUNT;
PDEBUG(4, "opening");
goto out;
err = -ENOMEM;
-
- /* Allocate memory for the frame buffers */
- ov511->fbuf = rvmalloc(OV511_NUMFRAMES * MAX_DATA_SIZE);
- if (!ov511->fbuf)
+ if (ov511_alloc(ov511))
goto out;
ov511->sub_flag = 0;
- for (i = 0; i < OV511_NUMFRAMES; i++) {
- ov511->frame[i].grabstate = FRAME_UNUSED;
- ov511->frame[i].data = ov511->fbuf + i * MAX_DATA_SIZE;
- PDEBUG(4, "frame [%d] @ %p", i, ov511->frame[0].data);
-
- ov511->sbuf[i].data = kmalloc(FRAMES_PER_DESC *
- MAX_FRAME_SIZE_PER_DESC, GFP_KERNEL);
- if (!ov511->sbuf[i].data) {
-open_free_ret:
- while (--i) kfree(ov511->sbuf[i].data);
- rvfree(ov511->fbuf, 2 * MAX_DATA_SIZE);
- goto out;
- }
- PDEBUG(4, "sbuf[%d] @ %p", i, ov511->sbuf[i].data);
- }
-
err = ov511_init_isoc(ov511);
- if (err)
- goto open_free_ret;
+ if (err) {
+ ov511_dealloc(ov511, 0);
+ goto out;
+ }
ov511->user++;
static void ov511_close(struct video_device *dev)
{
struct usb_ov511 *ov511 = (struct usb_ov511 *)dev;
- int i;
PDEBUG(4, "ov511_close");
- down(&ov511->lock);
- ov511->user--;
+ down(&ov511->lock);
+ ov511->user--;
ov511_stop_isoc(ov511);
- rvfree(ov511->fbuf, OV511_NUMFRAMES * MAX_DATA_SIZE);
- for (i = 0; i < OV511_NUMFRAMES; i++)
- kfree(ov511->sbuf[i].data);
+ if (ov511->dev)
+ ov511_dealloc(ov511, 0);
up(&ov511->lock);
if (!ov511->dev) {
+ ov511_dealloc(ov511, 1);
video_unregister_device(&ov511->vdev);
kfree(ov511);
+ ov511 = NULL;
}
MOD_DEC_USE_COUNT;
-
}
static int ov511_init_done(struct video_device *dev)
b.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE;
b.channels = 1;
b.audios = 0;
- b.maxwidth = DEFAULT_WIDTH;
- b.maxheight = DEFAULT_HEIGHT;
+ b.maxwidth = ov511->maxwidth;
+ b.maxheight = ov511->maxheight;
b.minwidth = 32;
b.minheight = 16;
if (copy_from_user(&p, arg, sizeof(p)))
return -EFAULT;
+ if (p.palette != VIDEO_PALETTE_GREY &&
+ p.palette != VIDEO_PALETTE_RGB24 &&
+ p.palette != VIDEO_PALETTE_YUV422 &&
+ p.palette != VIDEO_PALETTE_YUYV &&
+ p.palette != VIDEO_PALETTE_YUV420 &&
+ p.palette != VIDEO_PALETTE_YUV422P)
+ return -EINVAL;
+
if (ov7610_set_picture(ov511, &p))
return -EIO;
- /* FIXME: check validity */
-
PDEBUG(4, "Setting depth=%d, palette=%d", p.depth, p.palette);
for (i = 0; i < OV511_NUMFRAMES; i++) {
ov511->frame[i].depth = p.depth;
return -EINVAL;
if (vw.clipcount)
return -EINVAL;
- if (vw.height != DEFAULT_HEIGHT)
+ if (vw.height != ov511->maxheight)
return -EINVAL;
- if (vw.width != DEFAULT_WIDTH)
+ if (vw.width != ov511->maxwidth)
return -EINVAL;
#endif
struct video_mbuf vm;
memset(&vm, 0, sizeof(vm));
- vm.size = 2 * MAX_DATA_SIZE;
- vm.frames = 2;
+ vm.size = OV511_NUMFRAMES * MAX_DATA_SIZE;
+ vm.frames = OV511_NUMFRAMES;
vm.offsets[0] = 0;
vm.offsets[1] = MAX_FRAME_SIZE + sizeof (struct timeval);
if (copy_from_user((void *)&vm, (void *)arg, sizeof(vm)))
return -EFAULT;
- PDEBUG(4, "MCAPTURE");
+ PDEBUG(4, "CMCAPTURE");
PDEBUG(4, "frame: %d, size: %dx%d, format: %d",
vm.frame, vm.width, vm.height, vm.format);
if (vm.format != VIDEO_PALETTE_RGB24 &&
+ vm.format != VIDEO_PALETTE_YUV422 &&
+ vm.format != VIDEO_PALETTE_YUYV &&
+ vm.format != VIDEO_PALETTE_YUV420 &&
+ vm.format != VIDEO_PALETTE_YUV422P &&
vm.format != VIDEO_PALETTE_GREY)
return -EINVAL;
if ((vm.frame != 0) && (vm.frame != 1))
return -EINVAL;
+ if (vm.width > ov511->maxwidth || vm.height > ov511->maxheight)
+ return -EINVAL;
+
if (ov511->frame[vm.frame].grabstate == FRAME_GRABBING)
return -EBUSY;
init_waitqueue_head(&ov511->frame[frame].wq);
#endif
interruptible_sleep_on(&ov511->frame[frame].wq);
- if (signal_pending(current))
- return -EINTR;
+ if (signal_pending(current)) {
+ if (retry_sync) {
+ PDEBUG(3, "***retry sync***");
+
+ /* Polling apps will destroy frames with that! */
+ ov511_new_frame(ov511, frame);
+ ov511->curframe = -1;
+
+ /* This will request another frame. */
+ if (waitqueue_active(&ov511->frame[frame].wq))
+ wake_up_interruptible(&ov511->frame[frame].wq);
+
+ return 0;
+ } else {
+ return -EINTR;
+ }
+ }
} while (ov511->frame[frame].grabstate == FRAME_GRABBING);
if (ov511->frame[frame].grabstate == FRAME_ERROR) {
return 0;
}
case VIDIOCKEY:
- return 0;
+ return 0;
case VIDIOCCAPTURE:
return -EINVAL;
case VIDIOCSFBUF:
return -EINVAL;
case VIDIOCGTUNER:
case VIDIOCSTUNER:
- return -EINVAL;
+ return -EINVAL;
case VIDIOCGFREQ:
case VIDIOCSFREQ:
return -EINVAL;
frame->bytes_read = 0;
err("** ick! ** Errored frame %d", ov511->curframe);
if (ov511_new_frame(ov511, frmx))
- err("ov511_read: ov511_new_frame error");
+ err("read: ov511_new_frame error");
goto restart;
}
{ OV511_I2C_BUS, 0x16, 0x06 },
{ OV511_I2C_BUS, 0x28, 0x24 },
{ OV511_I2C_BUS, 0x2b, 0xac },
- { OV511_I2C_BUS, 0x05, 0x00 },
- { OV511_I2C_BUS, 0x06, 0x00 },
{ OV511_I2C_BUS, 0x12, 0x00 },
{ OV511_I2C_BUS, 0x38, 0x81 },
{ OV511_I2C_BUS, 0x28, 0x24 }, /* 0c */
- { OV511_I2C_BUS, 0x05, 0x00 },
{ OV511_I2C_BUS, 0x0f, 0x85 }, /* lg's setting */
{ OV511_I2C_BUS, 0x15, 0x01 },
{ OV511_I2C_BUS, 0x20, 0x1c },
{ OV511_I2C_BUS, 0x24, 0x10 },
{ OV511_I2C_BUS, 0x25, 0x8a },
{ OV511_I2C_BUS, 0x27, 0xc2 },
- { OV511_I2C_BUS, 0x29, 0x03 }, /* 91 */
{ OV511_I2C_BUS, 0x2a, 0x04 },
{ OV511_I2C_BUS, 0x2c, 0xfe },
{ OV511_I2C_BUS, 0x30, 0x71 },
{ OV511_I2C_BUS, 0x2b, 0xac },
{ OV511_I2C_BUS, 0x12, 0x00 },
{ OV511_I2C_BUS, 0x28, 0x24 },
- { OV511_I2C_BUS, 0x05, 0x00 },
{ OV511_I2C_BUS, 0x0f, 0x85 }, /* lg's setting */
{ OV511_I2C_BUS, 0x15, 0x01 },
{ OV511_I2C_BUS, 0x23, 0x00 },
{ OV511_I2C_BUS, 0x24, 0x10 },
{ OV511_I2C_BUS, 0x25, 0x8a },
{ OV511_I2C_BUS, 0x27, 0xe2 },
- { OV511_I2C_BUS, 0x29, 0x03 },
{ OV511_I2C_BUS, 0x2a, 0x00 },
{ OV511_I2C_BUS, 0x2c, 0xfe },
{ OV511_I2C_BUS, 0x30, 0x71 },
PDEBUG (4, "starting configuration");
- if(ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_WRITE,
- OV7610_I2C_WRITE_ID) < 0)
+ /* This looks redundant, but is necessary for WebCam 3 */
+ if (ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_WRITE,
+ OV7610_I2C_WRITE_ID) < 0)
return -1;
- if(ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_READ,
- OV7610_I2C_READ_ID) < 0)
+ if (ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_READ,
+ OV7610_I2C_READ_ID) < 0)
return -1;
if (ov511_reset(dev, OV511_RESET_NOREGS) < 0)
return -1;
-
+
/* Reset the 76xx */
if (ov511_i2c_write(dev, 0x12, 0x80) < 0) return -1;
+ /* Wait for it to initialize */
+ schedule_timeout (1 + 150 * HZ / 1000);
+
for (i = 0, success = 0; i < i2c_detect_tries && !success; i++) {
if ((ov511_i2c_read(dev, OV7610_REG_ID_HIGH) == 0x7F) &&
- (ov511_i2c_read(dev, OV7610_REG_ID_LOW) == 0xA2))
+ (ov511_i2c_read(dev, OV7610_REG_ID_LOW) == 0xA2)) {
success = 1;
+ continue;
+ }
- /* Dummy read to sync I2C */
- if (ov511_i2c_read(dev, 0x00) < 0) return -1;
+ /* Reset the 76xx */
+ if (ov511_i2c_write(dev, 0x12, 0x80) < 0) return -1;
/* Wait for it to initialize */
schedule_timeout (1 + 150 * HZ / 1000);
+ /* Dummy read to sync I2C */
+ if (ov511_i2c_read(dev, 0x00) < 0) return -1;
}
if (success) {
- PDEBUG(1, "I2C synced in %d attempt(s)", i);
+ PDEBUG(1, "I2C synced in %d attempt(s) (method 1)", i);
} else {
- err("Failed to read sensor ID. You might not have an OV76xx,");
- err("or it may be not responding. Report this to");
- err("mmcclelland@delphi.com");
- return -1;
+ /* Reset the 76xx */
+ if (ov511_i2c_write(dev, 0x12, 0x80) < 0) return -1;
+
+ /* Wait for it to initialize */
+ schedule_timeout (1 + 150 * HZ / 1000);
+
+ i = 0;
+ success = 0;
+ while (i <= i2c_detect_tries) {
+ if ((ov511_i2c_read(dev, OV7610_REG_ID_HIGH) == 0x7F) &&
+ (ov511_i2c_read(dev, OV7610_REG_ID_LOW) == 0xA2)) {
+ success = 1;
+ break;
+ } else {
+ i++;
+ }
+ }
+
+ if ((i == i2c_detect_tries) && (success == 0)) {
+ err("Failed to read sensor ID. You might not have an OV7610/20,");
+ err("or it may be not responding. Report this to");
+ err("mwm@i.am");
+ return -1;
+ } else {
+ PDEBUG(1, "I2C synced in %d attempt(s) (method 2)", i+1);
+ }
}
/* Detect sensor if user didn't use override param */
return -1;
}
+ /* Set sensor-specific vars */
+ ov511->maxwidth = 640;
+ ov511->maxheight = 480;
+
+ if (aperture < 0) { /* go with the default */
+ if (ov511_i2c_write(dev, 0x26, 0xa2) < 0) return -1;
+ } else if (aperture <= 0xf) { /* user overrode default */
+ if (ov511_i2c_write(dev, 0x26, (aperture << 4) + 2) < 0)
+ return -1;
+ } else {
+ err("Invalid setting for aperture; legal value: 0 - 15");
+ return -1;
+ }
+
+ if (autoadjust) {
+ if (ov511_i2c_write(dev, 0x13, 0x01) < 0) return -1;
+ if (ov511_i2c_write(dev, 0x2d,
+ ov511->sensor==SEN_OV7620?0x91:0x93) < 0) return -1;
+ } else {
+ if (ov511_i2c_write(dev, 0x13, 0x00) < 0) return -1;
+ if (ov511_i2c_write(dev, 0x2d,
+ ov511->sensor==SEN_OV7620?0x81:0x83) < 0) return -1;
+ ov511_i2c_write(dev, 0x28, ov511_i2c_read(dev, 0x28) | 8);
+ }
+
+ return 0;
+}
+
+static int ov6xx0_configure(struct usb_ov511 *ov511)
+{
+ struct usb_device *dev = ov511->dev;
+ int i, success, rc;
+
+ static struct ov511_regvals aRegvalsNorm6x20[] = {
+ { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
+ { OV511_I2C_BUS, 0x11, 0x01 },
+ { OV511_I2C_BUS, 0x03, 0xd0 },
+ { OV511_I2C_BUS, 0x05, 0x7f },
+ { OV511_I2C_BUS, 0x07, 0xa8 },
+ { OV511_I2C_BUS, 0x0c, 0x24 },
+ { OV511_I2C_BUS, 0x0d, 0x24 },
+ { OV511_I2C_BUS, 0x10, 0xff }, /* ? */
+ { OV511_I2C_BUS, 0x14, 0x04 },
+ { OV511_I2C_BUS, 0x16, 0x06 }, /* ? */
+ { OV511_I2C_BUS, 0x19, 0x04 },
+ { OV511_I2C_BUS, 0x1a, 0x93 },
+ { OV511_I2C_BUS, 0x20, 0x28 },
+ { OV511_I2C_BUS, 0x27, 0xa2 },
+ { OV511_I2C_BUS, 0x28, 0x24 },
+ { OV511_I2C_BUS, 0x2a, 0x04 }, /* 84? */
+ { OV511_I2C_BUS, 0x2b, 0xac }, /* a8? */
+ { OV511_I2C_BUS, 0x2d, 0x95 },
+ { OV511_I2C_BUS, 0x33, 0x28 },
+ { OV511_I2C_BUS, 0x34, 0xc7 },
+ { OV511_I2C_BUS, 0x38, 0x8b },
+ { OV511_I2C_BUS, 0x3c, 0x5c },
+ { OV511_I2C_BUS, 0x3d, 0x80 },
+ { OV511_I2C_BUS, 0x3f, 0x00 },
+ { OV511_I2C_BUS, 0x4a, 0x80 }, /* undocumented */
+ { OV511_I2C_BUS, 0x4b, 0x80 }, /* undocumented */
+ { OV511_I2C_BUS, 0x4d, 0xd2 },
+ { OV511_I2C_BUS, 0x4e, 0xc1 },
+ { OV511_I2C_BUS, 0x4f, 0x04 },
+ { OV511_DONE_BUS, 0x0, 0x00 },
+ };
+
+ PDEBUG (4, "starting sensor configuration");
+
+ /* Reset the 6xx0 */
+ if (ov511_i2c_write(dev, 0x12, 0x80) < 0) return -1;
+
+ /* Wait for it to initialize */
+ schedule_timeout (1 + 150 * HZ / 1000);
+
+ for (i = 0, success = 0; i < i2c_detect_tries && !success; i++) {
+ if ((ov511_i2c_read(dev, OV7610_REG_ID_HIGH) == 0x7F) &&
+ (ov511_i2c_read(dev, OV7610_REG_ID_LOW) == 0xA2)) {
+ success = 1;
+ continue;
+ }
+
+ /* Reset the 6xx0 */
+ if (ov511_i2c_write(dev, 0x12, 0x80) < 0) return -1;
+ /* Wait for it to initialize */
+ schedule_timeout (1 + 150 * HZ / 1000);
+ /* Dummy read to sync I2C */
+ if (ov511_i2c_read(dev, 0x00) < 0) return -1;
+ }
+
+ if (success) {
+ PDEBUG(1, "I2C synced in %d attempt(s)", i);
+ } else {
+ err("Failed to read sensor ID. You might not have an OV6xx0,");
+ err("or it may be not responding. Report this to");
+ err("mwm@i.am");
+ return -1;
+ }
+
+ /* Detect sensor if user didn't use override param */
+ if (sensor == 0) {
+ rc = ov511_i2c_read(dev, OV7610_REG_COM_I);
+
+ if (rc < 0) {
+ err("Error detecting sensor type");
+ return -1;
+ } else {
+ info("Sensor is an OV6xx0 (version %d)", rc & 3);
+ ov511->sensor = SEN_OV6620;
+ }
+ } else { /* sensor != 0; user overrode detection */
+ ov511->sensor = sensor;
+ info("Sensor set to type %d", ov511->sensor);
+ }
+
+ /* Set sensor-specific vars */
+ ov511->maxwidth = 352;
+ ov511->maxheight = 288;
+
+ PDEBUG(4, "Writing 6x20 registers");
+ if (ov511_write_regvals(dev, aRegvalsNorm6x20))
+ return -1;
+
if (aperture < 0) { /* go with the default */
if (ov511_i2c_write(dev, 0x26, 0xa2) < 0) return -1;
} else if (aperture <= 0xf) { /* user overrode default */
{ OV511_REG_BUS, OV511_REG_DRAM_ENABLE_FLOW_CONTROL, 0x01 },
{ OV511_REG_BUS, OV511_REG_SYSTEM_SNAPSHOT, 0x02 },
{ OV511_REG_BUS, OV511_REG_SYSTEM_SNAPSHOT, 0x00 },
- { OV511_REG_BUS, OV511_REG_FIFO_BITMASK, 0x1f }, /* 0f */
- { OV511_REG_BUS, OV511_OMNICE_PREDICTION_HORIZ_Y, 0x3f },
- { OV511_REG_BUS, OV511_OMNICE_PREDICTION_HORIZ_UV, 0x3f },
- { OV511_REG_BUS, OV511_OMNICE_PREDICTION_VERT_Y, 0x01 },
+ { OV511_REG_BUS, OV511_REG_FIFO_BITMASK, 0x1f },
+ { OV511_REG_BUS, OV511_OMNICE_PREDICTION_HORIZ_Y, 0x08 },
+ { OV511_REG_BUS, OV511_OMNICE_PREDICTION_HORIZ_UV, 0x01 },
+ { OV511_REG_BUS, OV511_OMNICE_PREDICTION_VERT_Y, 0x08 },
{ OV511_REG_BUS, OV511_OMNICE_PREDICTION_VERT_UV, 0x01 },
{ OV511_REG_BUS, OV511_OMNICE_QUANTIZATION_HORIZ_Y, 0x01 },
{ OV511_REG_BUS, OV511_OMNICE_QUANTIZATION_HORIZ_UV, 0x01 },
memcpy(&ov511->vdev, &ov511_template, sizeof(ov511_template));
- init_waitqueue_head(&ov511->frame[0].wq);
- init_waitqueue_head(&ov511->frame[1].wq);
+ for (i = 0; i < OV511_NUMFRAMES; i++)
+ init_waitqueue_head(&ov511->frame[i].wq);
+
init_waitqueue_head(&ov511->wq);
if (video_register_device(&ov511->vdev, VFL_TYPE_GRABBER) == -1) {
ov511->snap_enabled = snapshot;
+ /* Test for 76xx */
+ if (ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_WRITE,
+ OV7610_I2C_WRITE_ID) < 0)
+ goto error;
+
+ if (ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_READ,
+ OV7610_I2C_READ_ID) < 0)
+ goto error;
+
+ if (ov511_reset(dev, OV511_RESET_NOREGS) < 0)
+ goto error;
+
+ if (ov511_i2c_write(dev, 0x12, 0x80) < 0) {
+ /* Test for 6xx0 */
+ if (ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_WRITE,
+ OV6xx0_I2C_WRITE_ID) < 0)
+ goto error;
+
+ if (ov511_reg_write(dev, OV511_REG_I2C_SLAVE_ID_READ,
+ OV6xx0_I2C_READ_ID) < 0)
+ goto error;
+
+ if (ov511_reset(dev, OV511_RESET_NOREGS) < 0)
+ goto error;
+
+ if (ov511_i2c_write(dev, 0x12, 0x80) < 0) {
+ err("Can't determine sensor slave IDs");
+ goto error;
+ }
+
+ if(ov6xx0_configure(ov511) < 0) {
+ err("failed to configure OV6xx0");
+ goto error;
+ }
+ } else {
+ if(ov76xx_configure(ov511) < 0) {
+ err("failed to configure OV76xx");
+ goto error;
+ }
+ }
+
/* Set default sizes in case IOCTL (VIDIOCMCAPTURE) is not used
* (using read() instead). */
for (i = 0; i < OV511_NUMFRAMES; i++) {
- ov511->frame[i].width = DEFAULT_WIDTH;
- ov511->frame[i].height = DEFAULT_HEIGHT;
+ ov511->frame[i].width = ov511->maxwidth;
+ ov511->frame[i].height = ov511->maxheight;
ov511->frame[i].depth = 24;
ov511->frame[i].bytes_read = 0;
ov511->frame[i].segment = 0;
ov511->frame[i].segsize = GET_SEGSIZE(ov511->frame[i].format);
}
- /* Initialize to DEFAULT_WIDTH, DEFAULT_HEIGHT, YUV4:2:0 */
-
- if(ov76xx_configure(ov511) < 0) {
- err("failed to configure OV76xx");
- goto error;
- }
-
- if (ov511_mode_init_regs(ov511, DEFAULT_WIDTH, DEFAULT_HEIGHT,
+ /* Initialize to max width/height, RGB24 */
+ if (ov511_mode_init_regs(ov511, ov511->maxwidth, ov511->maxheight,
VIDEO_PALETTE_RGB24, 0) < 0)
goto error;
interface = &dev->actconfig->interface[ifnum].altsetting[0];
/* Is it an OV511/OV511+? */
- if (dev->descriptor.idVendor != 0x05a9)
+ if (dev->descriptor.idVendor != 0x05a9
+ && dev->descriptor.idVendor != 0x0813)
return NULL;
if (dev->descriptor.idProduct != 0x0511
- && dev->descriptor.idProduct != 0xA511)
+ && dev->descriptor.idProduct != 0xA511
+ && dev->descriptor.idProduct != 0x0002)
return NULL;
/* Checking vendor/product should be enough, but what the hell */
info("USB OV511+ camera found");
ov511->bridge = BRG_OV511PLUS;
break;
+ case 0x0002:
+ if (dev->descriptor.idVendor != 0x0813)
+ goto error;
+ info("Intel Play Me2Cam (OV511+) found");
+ ov511->bridge = BRG_OV511PLUS;
+ break;
+ default:
+ err("Unknown product ID");
+ goto error;
}
ov511->customid = ov511_reg_read(dev, OV511_REG_SYSTEM_CUSTOM_ID);
if (clist[i].id == -1) {
err("Camera type (%d) not recognized", ov511->customid);
- err("Please contact mmcclelland@delphi.com to request");
+ err("Please contact mwm@i.am to request");
err("support for your camera.");
}
if (!ov511_configure(ov511)) {
ov511->user = 0;
init_MUTEX(&ov511->lock); /* to 1 == available */
+ init_MUTEX(&ov511->buf_lock);
+ ov511->buf_state = BUF_NOT_ALLOCATED;
} else {
err("Failed to configure camera");
goto error;
static void ov511_disconnect(struct usb_device *dev, void *ptr)
{
struct usb_ov511 *ov511 = (struct usb_ov511 *) ptr;
+ int n;
MOD_INC_USE_COUNT;
+ PDEBUG(3, "");
+
/* We don't want people trying to open up the device */
if (!ov511->user)
video_unregister_device(&ov511->vdev);
+ else
+ PDEBUG(3, "Device open...deferring video_unregister_device");
- usb_driver_release_interface(&ov511_driver,
- &ov511->dev->actconfig->interface[ov511->iface]);
+ for (n = 0; n < OV511_NUMFRAMES; n++)
+ ov511->frame[n].grabstate = FRAME_ERROR;
- ov511->dev = NULL;
- ov511->frame[0].grabstate = FRAME_ERROR;
- ov511->frame[1].grabstate = FRAME_ERROR;
ov511->curframe = -1;
/* This will cause the process to request another frame */
- if (waitqueue_active(&ov511->frame[0].wq))
- wake_up_interruptible(&ov511->frame[0].wq);
- if (waitqueue_active(&ov511->frame[1].wq))
- wake_up_interruptible(&ov511->frame[1].wq);
+ for (n = 0; n < OV511_NUMFRAMES; n++)
+ if (waitqueue_active(&ov511->frame[n].wq))
+ wake_up_interruptible(&ov511->frame[n].wq);
if (waitqueue_active(&ov511->wq))
wake_up_interruptible(&ov511->wq);
ov511->streaming = 0;
/* Unschedule all of the iso td's */
- if (ov511->sbuf[1].urb) {
- ov511->sbuf[1].urb->next = NULL;
- usb_unlink_urb(ov511->sbuf[1].urb);
- usb_free_urb(ov511->sbuf[1].urb);
- ov511->sbuf[1].urb = NULL;
- }
- if (ov511->sbuf[0].urb) {
- ov511->sbuf[0].urb->next = NULL;
- usb_unlink_urb(ov511->sbuf[0].urb);
- usb_free_urb(ov511->sbuf[0].urb);
- ov511->sbuf[0].urb = NULL;
+ for (n = OV511_NUMSBUF - 1; n >= 0; n--) {
+ if (ov511->sbuf[n].urb) {
+ ov511->sbuf[n].urb->next = NULL;
+ usb_unlink_urb(ov511->sbuf[n].urb);
+ usb_free_urb(ov511->sbuf[n].urb);
+ ov511->sbuf[n].urb = NULL;
+ }
}
+ usb_driver_release_interface(&ov511_driver,
+ &ov511->dev->actconfig->interface[ov511->iface]);
+ ov511->dev = NULL;
+
#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)
destroy_proc_ov511_cam(ov511);
#endif
/* Free the memory */
if (ov511 && !ov511->user) {
+ ov511_dealloc(ov511, 1);
kfree(ov511);
ov511 = NULL;
}
static void __exit usb_ov511_exit(void)
{
usb_deregister(&ov511_driver);
- info("ov511 driver deregistered");
+ info("driver deregistered");
#if defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS)
proc_ov511_destroy();