2008-11-22 03:23:39 -05:00
|
|
|
/*
|
|
|
|
* ov534/ov772x gspca driver
|
|
|
|
* Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
|
2008-12-10 03:45:14 -05:00
|
|
|
* Copyright (C) 2008 Jim Paris <jim@jtan.com>
|
2008-11-22 03:23:39 -05:00
|
|
|
*
|
|
|
|
* Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
|
|
|
|
* USB protocol reverse engineered by Jim Paris <jim@jtan.com>
|
|
|
|
* https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MODULE_NAME "ov534"
|
|
|
|
|
|
|
|
#include "gspca.h"
|
|
|
|
|
|
|
|
#define OV534_REG_ADDRESS 0xf1 /* ? */
|
|
|
|
#define OV534_REG_SUBADDR 0xf2
|
|
|
|
#define OV534_REG_WRITE 0xf3
|
|
|
|
#define OV534_REG_READ 0xf4
|
|
|
|
#define OV534_REG_OPERATION 0xf5
|
|
|
|
#define OV534_REG_STATUS 0xf6
|
|
|
|
|
|
|
|
#define OV534_OP_WRITE_3 0x37
|
|
|
|
#define OV534_OP_WRITE_2 0x33
|
|
|
|
#define OV534_OP_READ_2 0xf9
|
|
|
|
|
|
|
|
#define CTRL_TIMEOUT 500
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
|
|
|
|
MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/* specific webcam descriptor */
|
|
|
|
struct sd {
|
|
|
|
struct gspca_dev gspca_dev; /* !! must be the first item */
|
2008-12-04 03:06:08 -05:00
|
|
|
__u32 last_fid;
|
|
|
|
__u32 last_pts;
|
2008-12-10 04:06:20 -05:00
|
|
|
int frame_rate;
|
2008-11-22 03:23:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* V4L2 controls supported by the driver */
|
|
|
|
static struct ctrl sd_ctrls[] = {
|
|
|
|
};
|
|
|
|
|
2008-12-29 05:49:41 -05:00
|
|
|
static const struct v4l2_pix_format vga_mode[] = {
|
2008-11-22 03:23:39 -05:00
|
|
|
{640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
|
|
|
|
.bytesperline = 640 * 2,
|
|
|
|
.sizeimage = 640 * 480 * 2,
|
|
|
|
.colorspace = V4L2_COLORSPACE_JPEG,
|
|
|
|
.priv = 0},
|
|
|
|
};
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
|
2008-11-22 03:23:39 -05:00
|
|
|
{
|
2008-12-29 04:19:43 -05:00
|
|
|
struct usb_device *udev = gspca_dev->dev;
|
2008-11-22 03:23:39 -05:00
|
|
|
int ret;
|
|
|
|
|
2008-12-03 12:10:01 -05:00
|
|
|
PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
|
2008-12-29 04:19:43 -05:00
|
|
|
gspca_dev->usb_buf[0] = val;
|
2008-11-22 03:23:39 -05:00
|
|
|
ret = usb_control_msg(udev,
|
|
|
|
usb_sndctrlpipe(udev, 0),
|
|
|
|
0x1,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
2008-12-29 04:19:43 -05:00
|
|
|
0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
|
2008-11-22 03:23:39 -05:00
|
|
|
if (ret < 0)
|
|
|
|
PDEBUG(D_ERR, "write failed");
|
|
|
|
}
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
|
2008-11-22 03:23:39 -05:00
|
|
|
{
|
2008-12-29 04:19:43 -05:00
|
|
|
struct usb_device *udev = gspca_dev->dev;
|
2008-11-22 03:23:39 -05:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = usb_control_msg(udev,
|
|
|
|
usb_rcvctrlpipe(udev, 0),
|
|
|
|
0x1,
|
|
|
|
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
2008-12-29 04:19:43 -05:00
|
|
|
0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
|
|
|
|
PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
|
2008-11-22 03:23:39 -05:00
|
|
|
if (ret < 0)
|
|
|
|
PDEBUG(D_ERR, "read failed");
|
2008-12-29 04:19:43 -05:00
|
|
|
return gspca_dev->usb_buf[0];
|
2008-11-22 03:23:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
|
|
|
|
* (direction and output)? */
|
2008-12-29 04:19:43 -05:00
|
|
|
static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
|
2008-11-22 03:23:39 -05:00
|
|
|
{
|
2008-12-03 12:10:01 -05:00
|
|
|
u8 data;
|
2008-11-22 03:23:39 -05:00
|
|
|
|
|
|
|
PDEBUG(D_CONF, "led status: %d", status);
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
data = ov534_reg_read(gspca_dev, 0x21);
|
2008-11-22 03:23:39 -05:00
|
|
|
data |= 0x80;
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_reg_write(gspca_dev, 0x21, data);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
data = ov534_reg_read(gspca_dev, 0x23);
|
2008-11-22 03:23:39 -05:00
|
|
|
if (status)
|
|
|
|
data |= 0x80;
|
|
|
|
else
|
|
|
|
data &= ~(0x80);
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_reg_write(gspca_dev, 0x23, data);
|
2008-11-22 03:23:39 -05:00
|
|
|
}
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
static int sccb_check_status(struct gspca_dev *gspca_dev)
|
2008-11-22 03:23:39 -05:00
|
|
|
{
|
2008-12-03 12:10:01 -05:00
|
|
|
u8 data;
|
2008-11-22 03:23:39 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
2008-12-29 04:19:43 -05:00
|
|
|
data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-03 12:10:01 -05:00
|
|
|
switch (data) {
|
2008-11-22 03:23:39 -05:00
|
|
|
case 0x00:
|
|
|
|
return 1;
|
|
|
|
case 0x04:
|
|
|
|
return 0;
|
|
|
|
case 0x03:
|
|
|
|
break;
|
|
|
|
default:
|
2008-12-28 04:51:37 -05:00
|
|
|
PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
|
2008-11-22 03:23:39 -05:00
|
|
|
data, i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
static void sccb_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
|
2008-11-22 03:23:39 -05:00
|
|
|
{
|
2008-12-03 12:10:01 -05:00
|
|
|
PDEBUG(D_USBO, "reg: 0x%04x, val: 0x%02x", reg, val);
|
2008-12-29 04:19:43 -05:00
|
|
|
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);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
if (!sccb_check_status(gspca_dev))
|
2008-11-22 03:23:39 -05:00
|
|
|
PDEBUG(D_ERR, "sccb_reg_write failed");
|
|
|
|
}
|
|
|
|
|
2008-12-14 03:50:24 -05:00
|
|
|
#ifdef GSPCA_DEBUG
|
2008-12-29 04:19:43 -05:00
|
|
|
static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
|
2008-12-14 03:48:07 -05:00
|
|
|
{
|
2008-12-29 04:19:43 -05:00
|
|
|
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))
|
2008-12-14 03:48:07 -05:00
|
|
|
PDEBUG(D_ERR, "sccb_reg_read failed 1");
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
|
|
|
|
if (!sccb_check_status(gspca_dev))
|
2008-12-14 03:48:07 -05:00
|
|
|
PDEBUG(D_ERR, "sccb_reg_read failed 2");
|
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
return ov534_reg_read(gspca_dev, OV534_REG_READ);
|
2008-12-14 03:48:07 -05:00
|
|
|
}
|
2008-12-14 03:50:24 -05:00
|
|
|
#endif
|
2008-12-14 03:48:07 -05:00
|
|
|
|
2008-12-04 02:28:27 -05:00
|
|
|
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 },
|
2008-12-10 03:45:14 -05:00
|
|
|
{ 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
|
|
|
|
{ 0x1d, 0x00 }, /* payload size */
|
2008-12-04 02:36:14 -05:00
|
|
|
{ 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
|
|
|
|
{ 0x1d, 0x58 }, /* frame size */
|
|
|
|
{ 0x1d, 0x00 }, /* frame size */
|
2008-12-04 02:28:27 -05:00
|
|
|
|
2008-12-10 03:47:44 -05:00
|
|
|
{ 0x1c, 0x0a },
|
|
|
|
{ 0x1d, 0x08 }, /* turn on UVC header */
|
|
|
|
{ 0x1d, 0x0e }, /* .. */
|
|
|
|
|
2008-12-04 02:28:27 -05:00
|
|
|
{ 0x8d, 0x1c },
|
|
|
|
{ 0x8e, 0x80 },
|
|
|
|
{ 0xe5, 0x04 },
|
|
|
|
|
|
|
|
{ 0xc0, 0x50 },
|
|
|
|
{ 0xc1, 0x3c },
|
|
|
|
{ 0xc2, 0x0c },
|
|
|
|
};
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-04 02:28:27 -05:00
|
|
|
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 }
|
|
|
|
};
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-10 04:06:20 -05:00
|
|
|
/* 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:
|
2008-12-29 04:19:43 -05:00
|
|
|
sccb_reg_write(gspca_dev, 0x11, 0x01);
|
|
|
|
sccb_reg_write(gspca_dev, 0x0d, 0x41);
|
|
|
|
ov534_reg_write(gspca_dev, 0xe5, 0x02);
|
2008-12-10 04:06:20 -05:00
|
|
|
break;
|
|
|
|
case 40:
|
2008-12-29 04:19:43 -05:00
|
|
|
sccb_reg_write(gspca_dev, 0x11, 0x02);
|
|
|
|
sccb_reg_write(gspca_dev, 0x0d, 0xc1);
|
|
|
|
ov534_reg_write(gspca_dev, 0xe5, 0x04);
|
2008-12-10 04:06:20 -05:00
|
|
|
break;
|
|
|
|
/* case 30: */
|
|
|
|
default:
|
|
|
|
fr = 30;
|
2008-12-29 04:19:43 -05:00
|
|
|
sccb_reg_write(gspca_dev, 0x11, 0x04);
|
|
|
|
sccb_reg_write(gspca_dev, 0x0d, 0x81);
|
|
|
|
ov534_reg_write(gspca_dev, 0xe5, 0x02);
|
2008-12-10 04:06:20 -05:00
|
|
|
break;
|
|
|
|
case 15:
|
2008-12-29 04:19:43 -05:00
|
|
|
sccb_reg_write(gspca_dev, 0x11, 0x03);
|
|
|
|
sccb_reg_write(gspca_dev, 0x0d, 0x41);
|
|
|
|
ov534_reg_write(gspca_dev, 0xe5, 0x04);
|
2008-12-10 04:06:20 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sd->frame_rate = fr;
|
|
|
|
PDEBUG(D_PROBE, "frame_rate: %d", fr);
|
|
|
|
}
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-04 02:28:27 -05:00
|
|
|
/* setup method */
|
2008-12-29 04:19:43 -05:00
|
|
|
static void ov534_setup(struct gspca_dev *gspca_dev)
|
2008-12-04 02:28:27 -05:00
|
|
|
{
|
|
|
|
int i;
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-04 02:28:27 -05:00
|
|
|
/* Initialize bridge chip */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ov534_reg_initdata); i++)
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_reg_write(gspca_dev, ov534_reg_initdata[i][0],
|
2008-12-04 02:28:27 -05:00
|
|
|
ov534_reg_initdata[i][1]);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-14 03:48:07 -05:00
|
|
|
PDEBUG(D_PROBE, "sensor is ov%02x%02x",
|
2008-12-29 04:19:43 -05:00
|
|
|
sccb_reg_read(gspca_dev, 0x0a),
|
|
|
|
sccb_reg_read(gspca_dev, 0x0b));
|
2008-12-14 03:48:07 -05:00
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_set_led(gspca_dev, 1);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-04 02:28:27 -05:00
|
|
|
/* Initialize sensor */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ov772x_reg_initdata); i++)
|
2008-12-29 04:19:43 -05:00
|
|
|
sccb_reg_write(gspca_dev, ov772x_reg_initdata[i][0],
|
2008-12-04 02:28:27 -05:00
|
|
|
ov772x_reg_initdata[i][1]);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_reg_write(gspca_dev, 0xe0, 0x09);
|
|
|
|
ov534_set_led(gspca_dev, 0);
|
2008-11-22 03:23:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called at probe time */
|
|
|
|
static int sd_config(struct gspca_dev *gspca_dev,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct cam *cam;
|
|
|
|
|
|
|
|
cam = &gspca_dev->cam;
|
|
|
|
|
|
|
|
cam->cam_mode = vga_mode;
|
|
|
|
cam->nmodes = ARRAY_SIZE(vga_mode);
|
|
|
|
|
2008-12-10 03:45:14 -05:00
|
|
|
cam->bulk_size = 16384;
|
2008-11-22 03:23:39 -05:00
|
|
|
cam->bulk_nurbs = 2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function is called at probe and resume time */
|
|
|
|
static int sd_init(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_setup(gspca_dev);
|
2008-12-10 04:06:20 -05:00
|
|
|
ov534_set_frame_rate(gspca_dev);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sd_start(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
/* start streaming data */
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_set_led(gspca_dev, 1);
|
|
|
|
ov534_reg_write(gspca_dev, 0xe0, 0x00);
|
2008-11-22 03:23:39 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sd_stopN(struct gspca_dev *gspca_dev)
|
|
|
|
{
|
|
|
|
/* stop streaming data */
|
2008-12-29 04:19:43 -05:00
|
|
|
ov534_reg_write(gspca_dev, 0xe0, 0x09);
|
|
|
|
ov534_set_led(gspca_dev, 0);
|
2008-11-22 03:23:39 -05:00
|
|
|
}
|
|
|
|
|
2008-12-04 02:52:40 -05:00
|
|
|
/* 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)
|
|
|
|
|
2008-11-22 03:23:39 -05:00
|
|
|
static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame,
|
|
|
|
__u8 *data, int len)
|
|
|
|
{
|
2008-12-04 03:06:08 -05:00
|
|
|
struct sd *sd = (struct sd *) gspca_dev;
|
2008-12-04 02:52:40 -05:00
|
|
|
__u32 this_pts;
|
|
|
|
int this_fid;
|
2008-12-10 03:45:14 -05:00
|
|
|
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;
|
2008-12-04 02:52:40 -05:00
|
|
|
|
2008-12-14 03:41:56 -05:00
|
|
|
/* Payloads are prefixed with a UVC-style header. We
|
2008-12-04 02:52:40 -05:00
|
|
|
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. */
|
2008-12-04 03:06:08 -05:00
|
|
|
if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
|
2008-12-04 02:52:40 -05:00
|
|
|
gspca_frame_add(gspca_dev, FIRST_PACKET, frame, NULL, 0);
|
2008-12-04 03:06:08 -05:00
|
|
|
sd->last_pts = this_pts;
|
|
|
|
sd->last_fid = this_fid;
|
2008-12-04 02:52:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
2008-12-04 03:06:08 -05:00
|
|
|
sd->last_pts = 0;
|
2008-12-04 02:52:40 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-10 03:45:14 -05:00
|
|
|
/* Done this payload */
|
|
|
|
goto scan_next;
|
2008-12-04 02:52:40 -05:00
|
|
|
|
|
|
|
discard:
|
|
|
|
/* Discard data until a new frame starts. */
|
|
|
|
gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0);
|
2008-12-10 03:45:14 -05:00
|
|
|
goto scan_next;
|
2008-11-22 03:23:39 -05:00
|
|
|
}
|
|
|
|
|
2008-12-10 04:06:20 -05:00
|
|
|
/* get stream parameters (framerate) */
|
2008-12-21 13:02:54 -05:00
|
|
|
static int sd_get_streamparm(struct gspca_dev *gspca_dev,
|
|
|
|
struct v4l2_streamparm *parm)
|
2008-12-10 04:06:20 -05:00
|
|
|
{
|
|
|
|
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) */
|
2008-12-21 13:02:54 -05:00
|
|
|
static int sd_set_streamparm(struct gspca_dev *gspca_dev,
|
|
|
|
struct v4l2_streamparm *parm)
|
2008-12-10 04:06:20 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-22 03:23:39 -05:00
|
|
|
/* sub-driver description */
|
|
|
|
static const struct sd_desc sd_desc = {
|
|
|
|
.name = MODULE_NAME,
|
|
|
|
.ctrls = sd_ctrls,
|
|
|
|
.nctrls = ARRAY_SIZE(sd_ctrls),
|
|
|
|
.config = sd_config,
|
|
|
|
.init = sd_init,
|
|
|
|
.start = sd_start,
|
|
|
|
.stopN = sd_stopN,
|
|
|
|
.pkt_scan = sd_pkt_scan,
|
2008-12-10 04:06:20 -05:00
|
|
|
.get_streamparm = sd_get_streamparm,
|
|
|
|
.set_streamparm = sd_set_streamparm,
|
2008-11-22 03:23:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -- module initialisation -- */
|
|
|
|
static const __devinitdata struct usb_device_id device_table[] = {
|
|
|
|
{USB_DEVICE(0x06f8, 0x3002)}, /* Hercules Blog Webcam */
|
|
|
|
{USB_DEVICE(0x06f8, 0x3003)}, /* Hercules Dualpix HD Weblog */
|
|
|
|
{USB_DEVICE(0x1415, 0x2000)}, /* Sony HD Eye for PS3 (SLEH 00201) */
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, device_table);
|
|
|
|
|
|
|
|
/* -- device connect -- */
|
|
|
|
static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
|
|
|
|
THIS_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver sd_driver = {
|
|
|
|
.name = MODULE_NAME,
|
|
|
|
.id_table = device_table,
|
|
|
|
.probe = sd_probe,
|
|
|
|
.disconnect = gspca_disconnect,
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
.suspend = gspca_suspend,
|
|
|
|
.resume = gspca_resume,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -- module insert / remove -- */
|
|
|
|
static int __init sd_mod_init(void)
|
|
|
|
{
|
|
|
|
if (usb_register(&sd_driver) < 0)
|
|
|
|
return -1;
|
|
|
|
PDEBUG(D_PROBE, "registered");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sd_mod_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&sd_driver);
|
|
|
|
PDEBUG(D_PROBE, "deregistered");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(sd_mod_init);
|
|
|
|
module_exit(sd_mod_exit);
|