summaryrefslogtreecommitdiff
path: root/linux/drivers/media/video/gspca/ov534.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/drivers/media/video/gspca/ov534.c')
-rw-r--r--linux/drivers/media/video/gspca/ov534.c662
1 files changed, 379 insertions, 283 deletions
diff --git a/linux/drivers/media/video/gspca/ov534.c b/linux/drivers/media/video/gspca/ov534.c
index a574be09b..3bf15e401 100644
--- a/linux/drivers/media/video/gspca/ov534.c
+++ b/linux/drivers/media/video/gspca/ov534.c
@@ -1,6 +1,7 @@
/*
* ov534/ov772x gspca driver
* Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
+ * Copyright (C) 2008 Jim Paris <jim@jtan.com>
*
* Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
* USB protocol reverse engineered by Jim Paris <jim@jtan.com>
@@ -42,20 +43,19 @@ MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
MODULE_LICENSE("GPL");
-/* global parameters */
-static int frame_rate;
-
/* specific webcam descriptor */
struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */
- __u8 frame_rate;
+ __u32 last_fid;
+ __u32 last_pts;
+ int frame_rate;
};
/* V4L2 controls supported by the driver */
static struct ctrl sd_ctrls[] = {
};
-static struct v4l2_pix_format vga_mode[] = {
+static const struct v4l2_pix_format vga_mode[] = {
{640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
.bytesperline = 640 * 2,
.sizeimage = 640 * 480 * 2,
@@ -63,80 +63,68 @@ static struct v4l2_pix_format vga_mode[] = {
.priv = 0},
};
-static void ov534_reg_write(struct usb_device *udev, u16 reg, u16 val)
+static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
{
- u16 data = val;
+ struct usb_device *udev = gspca_dev->dev;
int ret;
- PDEBUG(D_USBO, "reg=0x%04x, val=0%04x", reg, val);
+ PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
+ gspca_dev->usb_buf[0] = val;
ret = usb_control_msg(udev,
usb_sndctrlpipe(udev, 0),
0x1,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
- 0x0, reg, &data, 1, CTRL_TIMEOUT);
+ 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
if (ret < 0)
PDEBUG(D_ERR, "write failed");
}
-static u16 ov534_reg_read(struct usb_device *udev, u16 reg)
+static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
{
- u16 data;
+ struct usb_device *udev = gspca_dev->dev;
int ret;
ret = usb_control_msg(udev,
usb_rcvctrlpipe(udev, 0),
0x1,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
- 0x0, reg, &data, 1, CTRL_TIMEOUT);
- PDEBUG(D_USBI, "reg=0x%04x, data=0x%04x", reg, data);
+ 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
+ PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
if (ret < 0)
PDEBUG(D_ERR, "read failed");
- return data;
-}
-
-static void ov534_reg_verify_write(struct usb_device *udev, u16 reg, u16 val)
-{
- u16 data;
-
- ov534_reg_write(udev, reg, val);
- data = ov534_reg_read(udev, reg);
- if (data != val) {
- PDEBUG(D_ERR | D_USBO,
- "unexpected result from read: 0x%04x != 0x%04x", val,
- data);
- }
+ return gspca_dev->usb_buf[0];
}
/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
* (direction and output)? */
-static void ov534_set_led(struct usb_device *udev, int status)
+static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
{
- u16 data;
+ u8 data;
PDEBUG(D_CONF, "led status: %d", status);
- data = ov534_reg_read(udev, 0x21);
+ data = ov534_reg_read(gspca_dev, 0x21);
data |= 0x80;
- ov534_reg_write(udev, 0x21, data);
+ ov534_reg_write(gspca_dev, 0x21, data);
- data = ov534_reg_read(udev, 0x23);
+ data = ov534_reg_read(gspca_dev, 0x23);
if (status)
data |= 0x80;
else
data &= ~(0x80);
- ov534_reg_write(udev, 0x23, data);
+ ov534_reg_write(gspca_dev, 0x23, data);
}
-static int sccb_check_status(struct usb_device *udev)
+static int sccb_check_status(struct gspca_dev *gspca_dev)
{
- u16 data;
+ u8 data;
int i;
for (i = 0; i < 5; i++) {
- data = ov534_reg_read(udev, OV534_REG_STATUS);
+ data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
- switch (data & 0xFF) {
+ switch (data) {
case 0x00:
return 1;
case 0x04:
@@ -144,195 +132,243 @@ static int sccb_check_status(struct usb_device *udev)
case 0x03:
break;
default:
- PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5\n",
+ PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
data, i + 1);
}
}
return 0;
}
-static void sccb_reg_write(struct usb_device *udev, u16 reg, u16 val)
+static void sccb_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
{
- PDEBUG(D_USBO, "reg: 0x%04x, val: 0x%04x", reg, val);
- ov534_reg_write(udev, OV534_REG_SUBADDR, reg);
- ov534_reg_write(udev, OV534_REG_WRITE, val);
- ov534_reg_write(udev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
+ PDEBUG(D_USBO, "reg: 0x%04x, val: 0x%02x", reg, val);
+ ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
+ ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
+ ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
- if (!sccb_check_status(udev))
+ if (!sccb_check_status(gspca_dev))
PDEBUG(D_ERR, "sccb_reg_write failed");
}
+#ifdef GSPCA_DEBUG
+static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
+{
+ ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
+ ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
+ if (!sccb_check_status(gspca_dev))
+ PDEBUG(D_ERR, "sccb_reg_read failed 1");
+
+ ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
+ if (!sccb_check_status(gspca_dev))
+ PDEBUG(D_ERR, "sccb_reg_read failed 2");
+
+ return ov534_reg_read(gspca_dev, OV534_REG_READ);
+}
+#endif
+
+static const __u8 ov534_reg_initdata[][2] = {
+ { 0xe7, 0x3a },
+
+ { OV534_REG_ADDRESS, 0x42 }, /* select OV772x sensor */
+
+ { 0xc2, 0x0c },
+ { 0x88, 0xf8 },
+ { 0xc3, 0x69 },
+ { 0x89, 0xff },
+ { 0x76, 0x03 },
+ { 0x92, 0x01 },
+ { 0x93, 0x18 },
+ { 0x94, 0x10 },
+ { 0x95, 0x10 },
+ { 0xe2, 0x00 },
+ { 0xe7, 0x3e },
+
+ { 0x96, 0x00 },
+
+ { 0x97, 0x20 },
+ { 0x97, 0x20 },
+ { 0x97, 0x20 },
+ { 0x97, 0x0a },
+ { 0x97, 0x3f },
+ { 0x97, 0x4a },
+ { 0x97, 0x20 },
+ { 0x97, 0x15 },
+ { 0x97, 0x0b },
+
+ { 0x8e, 0x40 },
+ { 0x1f, 0x81 },
+ { 0x34, 0x05 },
+ { 0xe3, 0x04 },
+ { 0x88, 0x00 },
+ { 0x89, 0x00 },
+ { 0x76, 0x00 },
+ { 0xe7, 0x2e },
+ { 0x31, 0xf9 },
+ { 0x25, 0x42 },
+ { 0x21, 0xf0 },
+
+ { 0x1c, 0x00 },
+ { 0x1d, 0x40 },
+ { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
+ { 0x1d, 0x00 }, /* payload size */
+ { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
+ { 0x1d, 0x58 }, /* frame size */
+ { 0x1d, 0x00 }, /* frame size */
+
+ { 0x1c, 0x0a },
+ { 0x1d, 0x08 }, /* turn on UVC header */
+ { 0x1d, 0x0e }, /* .. */
+
+ { 0x8d, 0x1c },
+ { 0x8e, 0x80 },
+ { 0xe5, 0x04 },
+
+ { 0xc0, 0x50 },
+ { 0xc1, 0x3c },
+ { 0xc2, 0x0c },
+};
+
+static const __u8 ov772x_reg_initdata[][2] = {
+ { 0x12, 0x80 },
+ { 0x11, 0x01 },
+
+ { 0x3d, 0x03 },
+ { 0x17, 0x26 },
+ { 0x18, 0xa0 },
+ { 0x19, 0x07 },
+ { 0x1a, 0xf0 },
+ { 0x32, 0x00 },
+ { 0x29, 0xa0 },
+ { 0x2c, 0xf0 },
+ { 0x65, 0x20 },
+ { 0x11, 0x01 },
+ { 0x42, 0x7f },
+ { 0x63, 0xe0 },
+ { 0x64, 0xff },
+ { 0x66, 0x00 },
+ { 0x13, 0xf0 },
+ { 0x0d, 0x41 },
+ { 0x0f, 0xc5 },
+ { 0x14, 0x11 },
+
+ { 0x22, 0x7f },
+ { 0x23, 0x03 },
+ { 0x24, 0x40 },
+ { 0x25, 0x30 },
+ { 0x26, 0xa1 },
+ { 0x2a, 0x00 },
+ { 0x2b, 0x00 },
+ { 0x6b, 0xaa },
+ { 0x13, 0xff },
+
+ { 0x90, 0x05 },
+ { 0x91, 0x01 },
+ { 0x92, 0x03 },
+ { 0x93, 0x00 },
+ { 0x94, 0x60 },
+ { 0x95, 0x3c },
+ { 0x96, 0x24 },
+ { 0x97, 0x1e },
+ { 0x98, 0x62 },
+ { 0x99, 0x80 },
+ { 0x9a, 0x1e },
+ { 0x9b, 0x08 },
+ { 0x9c, 0x20 },
+ { 0x9e, 0x81 },
+
+ { 0xa6, 0x04 },
+ { 0x7e, 0x0c },
+ { 0x7f, 0x16 },
+ { 0x80, 0x2a },
+ { 0x81, 0x4e },
+ { 0x82, 0x61 },
+ { 0x83, 0x6f },
+ { 0x84, 0x7b },
+ { 0x85, 0x86 },
+ { 0x86, 0x8e },
+ { 0x87, 0x97 },
+ { 0x88, 0xa4 },
+ { 0x89, 0xaf },
+ { 0x8a, 0xc5 },
+ { 0x8b, 0xd7 },
+ { 0x8c, 0xe8 },
+ { 0x8d, 0x20 },
+
+ { 0x0c, 0x90 },
+
+ { 0x2b, 0x00 },
+ { 0x22, 0x7f },
+ { 0x23, 0x03 },
+ { 0x11, 0x01 },
+ { 0x0c, 0xd0 },
+ { 0x64, 0xff },
+ { 0x0d, 0x41 },
+
+ { 0x14, 0x41 },
+ { 0x0e, 0xcd },
+ { 0xac, 0xbf },
+ { 0x8e, 0x00 },
+ { 0x0c, 0xd0 }
+};
+
+/* set framerate */
+static void ov534_set_frame_rate(struct gspca_dev *gspca_dev)
+{
+ struct sd *sd = (struct sd *) gspca_dev;
+ int fr = sd->frame_rate;
+
+ switch (fr) {
+ case 50:
+ sccb_reg_write(gspca_dev, 0x11, 0x01);
+ sccb_reg_write(gspca_dev, 0x0d, 0x41);
+ ov534_reg_write(gspca_dev, 0xe5, 0x02);
+ break;
+ case 40:
+ sccb_reg_write(gspca_dev, 0x11, 0x02);
+ sccb_reg_write(gspca_dev, 0x0d, 0xc1);
+ ov534_reg_write(gspca_dev, 0xe5, 0x04);
+ break;
+/* case 30: */
+ default:
+ fr = 30;
+ sccb_reg_write(gspca_dev, 0x11, 0x04);
+ sccb_reg_write(gspca_dev, 0x0d, 0x81);
+ ov534_reg_write(gspca_dev, 0xe5, 0x02);
+ break;
+ case 15:
+ sccb_reg_write(gspca_dev, 0x11, 0x03);
+ sccb_reg_write(gspca_dev, 0x0d, 0x41);
+ ov534_reg_write(gspca_dev, 0xe5, 0x04);
+ break;
+ }
+
+ sd->frame_rate = fr;
+ PDEBUG(D_PROBE, "frame_rate: %d", fr);
+}
+
/* setup method */
-static void ov534_setup(struct usb_device *udev)
+static void ov534_setup(struct gspca_dev *gspca_dev)
{
- ov534_reg_verify_write(udev, 0xe7, 0x3a);
-
- ov534_reg_write(udev, OV534_REG_ADDRESS, 0x60);
- ov534_reg_write(udev, OV534_REG_ADDRESS, 0x60);
- ov534_reg_write(udev, OV534_REG_ADDRESS, 0x60);
- ov534_reg_write(udev, OV534_REG_ADDRESS, 0x42);
-
- ov534_reg_verify_write(udev, 0xc2, 0x0c);
- ov534_reg_verify_write(udev, 0x88, 0xf8);
- ov534_reg_verify_write(udev, 0xc3, 0x69);
- ov534_reg_verify_write(udev, 0x89, 0xff);
- ov534_reg_verify_write(udev, 0x76, 0x03);
- ov534_reg_verify_write(udev, 0x92, 0x01);
- ov534_reg_verify_write(udev, 0x93, 0x18);
- ov534_reg_verify_write(udev, 0x94, 0x10);
- ov534_reg_verify_write(udev, 0x95, 0x10);
- ov534_reg_verify_write(udev, 0xe2, 0x00);
- ov534_reg_verify_write(udev, 0xe7, 0x3e);
-
- ov534_reg_write(udev, 0x1c, 0x0a);
- ov534_reg_write(udev, 0x1d, 0x22);
- ov534_reg_write(udev, 0x1d, 0x06);
-
- ov534_reg_verify_write(udev, 0x96, 0x00);
-
- ov534_reg_write(udev, 0x97, 0x20);
- ov534_reg_write(udev, 0x97, 0x20);
- ov534_reg_write(udev, 0x97, 0x20);
- ov534_reg_write(udev, 0x97, 0x0a);
- ov534_reg_write(udev, 0x97, 0x3f);
- ov534_reg_write(udev, 0x97, 0x4a);
- ov534_reg_write(udev, 0x97, 0x20);
- ov534_reg_write(udev, 0x97, 0x15);
- ov534_reg_write(udev, 0x97, 0x0b);
-
- ov534_reg_verify_write(udev, 0x8e, 0x40);
- ov534_reg_verify_write(udev, 0x1f, 0x81);
- ov534_reg_verify_write(udev, 0x34, 0x05);
- ov534_reg_verify_write(udev, 0xe3, 0x04);
- ov534_reg_verify_write(udev, 0x88, 0x00);
- ov534_reg_verify_write(udev, 0x89, 0x00);
- ov534_reg_verify_write(udev, 0x76, 0x00);
- ov534_reg_verify_write(udev, 0xe7, 0x2e);
- ov534_reg_verify_write(udev, 0x31, 0xf9);
- ov534_reg_verify_write(udev, 0x25, 0x42);
- ov534_reg_verify_write(udev, 0x21, 0xf0);
-
- ov534_reg_write(udev, 0x1c, 0x00);
- ov534_reg_write(udev, 0x1d, 0x40);
- ov534_reg_write(udev, 0x1d, 0x02);
- ov534_reg_write(udev, 0x1d, 0x00);
- ov534_reg_write(udev, 0x1d, 0x02);
- ov534_reg_write(udev, 0x1d, 0x57);
- ov534_reg_write(udev, 0x1d, 0xff);
-
- ov534_reg_verify_write(udev, 0x8d, 0x1c);
- ov534_reg_verify_write(udev, 0x8e, 0x80);
- ov534_reg_verify_write(udev, 0xe5, 0x04);
-
- ov534_set_led(udev, 1);
-
- sccb_reg_write(udev, 0x12, 0x80);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x11, 0x01);
-
- ov534_set_led(udev, 0);
-
- sccb_reg_write(udev, 0x3d, 0x03);
- sccb_reg_write(udev, 0x17, 0x26);
- sccb_reg_write(udev, 0x18, 0xa0);
- sccb_reg_write(udev, 0x19, 0x07);
- sccb_reg_write(udev, 0x1a, 0xf0);
- sccb_reg_write(udev, 0x32, 0x00);
- sccb_reg_write(udev, 0x29, 0xa0);
- sccb_reg_write(udev, 0x2c, 0xf0);
- sccb_reg_write(udev, 0x65, 0x20);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x42, 0x7f);
- sccb_reg_write(udev, 0x63, 0xe0);
- sccb_reg_write(udev, 0x64, 0xff);
- sccb_reg_write(udev, 0x66, 0x00);
- sccb_reg_write(udev, 0x13, 0xf0);
- sccb_reg_write(udev, 0x0d, 0x41);
- sccb_reg_write(udev, 0x0f, 0xc5);
- sccb_reg_write(udev, 0x14, 0x11);
-
- ov534_set_led(udev, 1);
-
- sccb_reg_write(udev, 0x22, 0x7f);
- sccb_reg_write(udev, 0x23, 0x03);
- sccb_reg_write(udev, 0x24, 0x40);
- sccb_reg_write(udev, 0x25, 0x30);
- sccb_reg_write(udev, 0x26, 0xa1);
- sccb_reg_write(udev, 0x2a, 0x00);
- sccb_reg_write(udev, 0x2b, 0x00);
- sccb_reg_write(udev, 0x6b, 0xaa);
- sccb_reg_write(udev, 0x13, 0xff);
-
- ov534_set_led(udev, 0);
-
- sccb_reg_write(udev, 0x90, 0x05);
- sccb_reg_write(udev, 0x91, 0x01);
- sccb_reg_write(udev, 0x92, 0x03);
- sccb_reg_write(udev, 0x93, 0x00);
- sccb_reg_write(udev, 0x94, 0x60);
- sccb_reg_write(udev, 0x95, 0x3c);
- sccb_reg_write(udev, 0x96, 0x24);
- sccb_reg_write(udev, 0x97, 0x1e);
- sccb_reg_write(udev, 0x98, 0x62);
- sccb_reg_write(udev, 0x99, 0x80);
- sccb_reg_write(udev, 0x9a, 0x1e);
- sccb_reg_write(udev, 0x9b, 0x08);
- sccb_reg_write(udev, 0x9c, 0x20);
- sccb_reg_write(udev, 0x9e, 0x81);
-
- ov534_set_led(udev, 1);
-
- sccb_reg_write(udev, 0xa6, 0x04);
- sccb_reg_write(udev, 0x7e, 0x0c);
- sccb_reg_write(udev, 0x7f, 0x16);
- sccb_reg_write(udev, 0x80, 0x2a);
- sccb_reg_write(udev, 0x81, 0x4e);
- sccb_reg_write(udev, 0x82, 0x61);
- sccb_reg_write(udev, 0x83, 0x6f);
- sccb_reg_write(udev, 0x84, 0x7b);
- sccb_reg_write(udev, 0x85, 0x86);
- sccb_reg_write(udev, 0x86, 0x8e);
- sccb_reg_write(udev, 0x87, 0x97);
- sccb_reg_write(udev, 0x88, 0xa4);
- sccb_reg_write(udev, 0x89, 0xaf);
- sccb_reg_write(udev, 0x8a, 0xc5);
- sccb_reg_write(udev, 0x8b, 0xd7);
- sccb_reg_write(udev, 0x8c, 0xe8);
- sccb_reg_write(udev, 0x8d, 0x20);
-
- sccb_reg_write(udev, 0x0c, 0x90);
-
- ov534_reg_verify_write(udev, 0xc0, 0x50);
- ov534_reg_verify_write(udev, 0xc1, 0x3c);
- ov534_reg_verify_write(udev, 0xc2, 0x0c);
-
- ov534_set_led(udev, 1);
-
- sccb_reg_write(udev, 0x2b, 0x00);
- sccb_reg_write(udev, 0x22, 0x7f);
- sccb_reg_write(udev, 0x23, 0x03);
- sccb_reg_write(udev, 0x11, 0x01);
- sccb_reg_write(udev, 0x0c, 0xd0);
- sccb_reg_write(udev, 0x64, 0xff);
- sccb_reg_write(udev, 0x0d, 0x41);
-
- sccb_reg_write(udev, 0x14, 0x41);
- sccb_reg_write(udev, 0x0e, 0xcd);
- sccb_reg_write(udev, 0xac, 0xbf);
- sccb_reg_write(udev, 0x8e, 0x00);
- sccb_reg_write(udev, 0x0c, 0xd0);
-
- ov534_reg_write(udev, 0xe0, 0x09);
- ov534_set_led(udev, 0);
+ int i;
+
+ /* Initialize bridge chip */
+ for (i = 0; i < ARRAY_SIZE(ov534_reg_initdata); i++)
+ ov534_reg_write(gspca_dev, ov534_reg_initdata[i][0],
+ ov534_reg_initdata[i][1]);
+
+ PDEBUG(D_PROBE, "sensor is ov%02x%02x",
+ sccb_reg_read(gspca_dev, 0x0a),
+ sccb_reg_read(gspca_dev, 0x0b));
+
+ ov534_set_led(gspca_dev, 1);
+
+ /* Initialize sensor */
+ for (i = 0; i < ARRAY_SIZE(ov772x_reg_initdata); i++)
+ sccb_reg_write(gspca_dev, ov772x_reg_initdata[i][0],
+ ov772x_reg_initdata[i][1]);
+
+ ov534_reg_write(gspca_dev, 0xe0, 0x09);
+ ov534_set_led(gspca_dev, 0);
}
/* this function is called at probe time */
@@ -347,70 +383,26 @@ static int sd_config(struct gspca_dev *gspca_dev,
cam->cam_mode = vga_mode;
cam->nmodes = ARRAY_SIZE(vga_mode);
- cam->bulk_size = vga_mode[0].sizeimage;
+ cam->bulk_size = 16384;
cam->bulk_nurbs = 2;
- PDEBUG(D_PROBE, "bulk_size = %d", cam->bulk_size);
-
return 0;
}
/* this function is called at probe and resume time */
static int sd_init(struct gspca_dev *gspca_dev)
{
- struct sd *sd = (struct sd *)gspca_dev;
- ov534_setup(gspca_dev->dev);
-
- if (frame_rate > 0)
- sd->frame_rate = frame_rate;
-
- PDEBUG(D_PROBE, "frame_rate = %d", sd->frame_rate);
-
- switch (sd->frame_rate) {
- case 50:
- sccb_reg_write(gspca_dev->dev, 0x11, 0x01);
- sccb_check_status(gspca_dev->dev);
- sccb_reg_write(gspca_dev->dev, 0x0d, 0x41);
- sccb_check_status(gspca_dev->dev);
- ov534_reg_verify_write(gspca_dev->dev, 0xe5, 0x02);
- break;
- case 40:
- sccb_reg_write(gspca_dev->dev, 0x11, 0x02);
- sccb_check_status(gspca_dev->dev);
- sccb_reg_write(gspca_dev->dev, 0x0d, 0xc1);
- sccb_check_status(gspca_dev->dev);
- ov534_reg_verify_write(gspca_dev->dev, 0xe5, 0x04);
- break;
- case 30:
- default:
- sccb_reg_write(gspca_dev->dev, 0x11, 0x04);
- sccb_check_status(gspca_dev->dev);
- sccb_reg_write(gspca_dev->dev, 0x0d, 0x81);
- sccb_check_status(gspca_dev->dev);
- ov534_reg_verify_write(gspca_dev->dev, 0xe5, 0x02);
- break;
- case 15:
- sccb_reg_write(gspca_dev->dev, 0x11, 0x03);
- sccb_check_status(gspca_dev->dev);
- sccb_reg_write(gspca_dev->dev, 0x0d, 0x41);
- sccb_check_status(gspca_dev->dev);
- ov534_reg_verify_write(gspca_dev->dev, 0xe5, 0x04);
- break;
- };
+ ov534_setup(gspca_dev);
+ ov534_set_frame_rate(gspca_dev);
return 0;
}
static int sd_start(struct gspca_dev *gspca_dev)
{
- PDEBUG(D_PROBE, "width = %d, height = %d",
- gspca_dev->width, gspca_dev->height);
-
- gspca_dev->cam.bulk_size = gspca_dev->width * gspca_dev->height * 2;
-
/* start streaming data */
- ov534_set_led(gspca_dev->dev, 1);
- ov534_reg_write(gspca_dev->dev, 0xe0, 0x00);
+ ov534_set_led(gspca_dev, 1);
+ ov534_reg_write(gspca_dev, 0xe0, 0x00);
return 0;
}
@@ -418,29 +410,134 @@ static int sd_start(struct gspca_dev *gspca_dev)
static void sd_stopN(struct gspca_dev *gspca_dev)
{
/* stop streaming data */
- ov534_reg_write(gspca_dev->dev, 0xe0, 0x09);
- ov534_set_led(gspca_dev->dev, 0);
+ ov534_reg_write(gspca_dev, 0xe0, 0x09);
+ ov534_set_led(gspca_dev, 0);
}
+/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
+#define UVC_STREAM_EOH (1 << 7)
+#define UVC_STREAM_ERR (1 << 6)
+#define UVC_STREAM_STI (1 << 5)
+#define UVC_STREAM_RES (1 << 4)
+#define UVC_STREAM_SCR (1 << 3)
+#define UVC_STREAM_PTS (1 << 2)
+#define UVC_STREAM_EOF (1 << 1)
+#define UVC_STREAM_FID (1 << 0)
+
static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame,
__u8 *data, int len)
{
- /*
- * The current camera setup doesn't stream the last pixel, so we set it
- * to a dummy value
- */
- __u8 last_pixel[4] = { 0, 0, 0, 0 };
- int framesize = gspca_dev->cam.bulk_size;
-
- if (len == framesize - 4) {
- frame =
- gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
- frame =
- gspca_frame_add(gspca_dev, LAST_PACKET, frame, last_pixel,
- 4);
- } else
- PDEBUG(D_PACK, "packet len = %d, framesize = %d", len,
- framesize);
+ struct sd *sd = (struct sd *) gspca_dev;
+ __u32 this_pts;
+ int this_fid;
+ int remaining_len = len;
+ __u8 *next_data = data;
+
+scan_next:
+ if (remaining_len <= 0)
+ return;
+
+ data = next_data;
+ len = min(remaining_len, 2048);
+ remaining_len -= len;
+ next_data += len;
+
+ /* Payloads are prefixed with a UVC-style header. We
+ consider a frame to start when the FID toggles, or the PTS
+ changes. A frame ends when EOF is set, and we've received
+ the correct number of bytes. */
+
+ /* Verify UVC header. Header length is always 12 */
+ if (data[0] != 12 || len < 12) {
+ PDEBUG(D_PACK, "bad header");
+ goto discard;
+ }
+
+ /* Check errors */
+ if (data[1] & UVC_STREAM_ERR) {
+ PDEBUG(D_PACK, "payload error");
+ goto discard;
+ }
+
+ /* Extract PTS and FID */
+ if (!(data[1] & UVC_STREAM_PTS)) {
+ PDEBUG(D_PACK, "PTS not present");
+ goto discard;
+ }
+ this_pts = (data[5] << 24) | (data[4] << 16) | (data[3] << 8) | data[2];
+ this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
+
+ /* If PTS or FID has changed, start a new frame. */
+ if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
+ gspca_frame_add(gspca_dev, FIRST_PACKET, frame, NULL, 0);
+ sd->last_pts = this_pts;
+ sd->last_fid = this_fid;
+ }
+
+ /* Add the data from this payload */
+ gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+ data + 12, len - 12);
+
+ /* If this packet is marked as EOF, end the frame */
+ if (data[1] & UVC_STREAM_EOF) {
+ sd->last_pts = 0;
+
+ if ((frame->data_end - frame->data) !=
+ (gspca_dev->width * gspca_dev->height * 2)) {
+ PDEBUG(D_PACK, "short frame");
+ goto discard;
+ }
+
+ gspca_frame_add(gspca_dev, LAST_PACKET, frame, NULL, 0);
+ }
+
+ /* Done this payload */
+ goto scan_next;
+
+discard:
+ /* Discard data until a new frame starts. */
+ gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0);
+ goto scan_next;
+}
+
+/* get stream parameters (framerate) */
+static int sd_get_streamparm(struct gspca_dev *gspca_dev,
+ struct v4l2_streamparm *parm)
+{
+ struct v4l2_captureparm *cp = &parm->parm.capture;
+ struct v4l2_fract *tpf = &cp->timeperframe;
+ struct sd *sd = (struct sd *) gspca_dev;
+
+ if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+ return -EINVAL;
+
+ cp->capability |= V4L2_CAP_TIMEPERFRAME;
+ tpf->numerator = 1;
+ tpf->denominator = sd->frame_rate;
+
+ return 0;
+}
+
+/* set stream parameters (framerate) */
+static int sd_set_streamparm(struct gspca_dev *gspca_dev,
+ struct v4l2_streamparm *parm)
+{
+ struct v4l2_captureparm *cp = &parm->parm.capture;
+ struct v4l2_fract *tpf = &cp->timeperframe;
+ struct sd *sd = (struct sd *) gspca_dev;
+
+ if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+ return -EINVAL;
+
+ /* Set requested framerate */
+ sd->frame_rate = tpf->denominator / tpf->numerator;
+ ov534_set_frame_rate(gspca_dev);
+
+ /* Return the actual framerate */
+ tpf->numerator = 1;
+ tpf->denominator = sd->frame_rate;
+
+ return 0;
}
/* sub-driver description */
@@ -453,6 +550,8 @@ static const struct sd_desc sd_desc = {
.start = sd_start,
.stopN = sd_stopN,
.pkt_scan = sd_pkt_scan,
+ .get_streamparm = sd_get_streamparm,
+ .set_streamparm = sd_set_streamparm,
};
/* -- module initialisation -- */
@@ -500,6 +599,3 @@ static void __exit sd_mod_exit(void)
module_init(sd_mod_init);
module_exit(sd_mod_exit);
-
-module_param(frame_rate, int, 0644);
-MODULE_PARM_DESC(frame_rate, "Frame rate (15, 30, 40, 50)");