2005-04-16 22:20:36 +00:00
|
|
|
/* Linux driver for Philips webcam
|
|
|
|
USB and Video4Linux interface part.
|
|
|
|
(C) 1999-2004 Nemosoft Unv.
|
2006-04-24 13:29:46 +00:00
|
|
|
(C) 2004-2006 Luc Saillard (luc@saillard.org)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
|
|
|
|
driver and thus may have bugs that are not present in the original version.
|
|
|
|
Please send bug reports and support requests to <luc@saillard.org>.
|
|
|
|
The decompression routines have been implemented by reverse-engineering the
|
|
|
|
Nemosoft binary pwcx module. Caveat emptor.
|
|
|
|
|
|
|
|
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
|
|
|
|
(at your option) 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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
This code forms the interface between the USB layers and the Philips
|
|
|
|
specific stuff. Some adanved stuff of the driver falls under an
|
|
|
|
NDA, signed between me and Philips B.V., Eindhoven, the Netherlands, and
|
2006-03-25 12:19:53 +00:00
|
|
|
is thus not distributed in source form. The binary pwcx.o module
|
2005-04-16 22:20:36 +00:00
|
|
|
contains the code that falls under the NDA.
|
2006-03-25 12:19:53 +00:00
|
|
|
|
|
|
|
In case you're wondering: 'pwc' stands for "Philips WebCam", but
|
2005-04-16 22:20:36 +00:00
|
|
|
I really didn't want to type 'philips_web_cam' every time (I'm lazy as
|
|
|
|
any Linux kernel hacker, but I don't like uncomprehensible abbreviations
|
|
|
|
without explanation).
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
Oh yes, convention: to disctinguish between all the various pointers to
|
|
|
|
device-structures, I use these names for the pointer variables:
|
|
|
|
udev: struct usb_device *
|
|
|
|
vdev: struct video_device *
|
|
|
|
pdev: struct pwc_devive *
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Contributors:
|
|
|
|
- Alvarado: adding whitebalance code
|
|
|
|
- Alistar Moire: QuickCam 3000 Pro device/product ID
|
|
|
|
- Tony Hoyle: Creative Labs Webcam 5 device/product ID
|
|
|
|
- Mark Burazin: solving hang in VIDIOCSYNC when camera gets unplugged
|
|
|
|
- Jk Fang: Sotec Afina Eye ID
|
|
|
|
- Xavier Roche: QuickCam Pro 4000 ID
|
|
|
|
- Jens Knudsen: QuickCam Zoom ID
|
|
|
|
- J. Debert: QuickCam for Notebooks ID
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2006-04-24 13:29:46 +00:00
|
|
|
#include <linux/version.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/io.h>
|
2006-04-24 13:29:46 +00:00
|
|
|
#include <linux/moduleparam.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "pwc.h"
|
|
|
|
#include "pwc-kiara.h"
|
|
|
|
#include "pwc-timon.h"
|
2006-04-24 13:29:46 +00:00
|
|
|
#include "pwc-dec23.h"
|
|
|
|
#include "pwc-dec1.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "pwc-uncompress.h"
|
|
|
|
|
|
|
|
/* Function prototypes and driver templates */
|
|
|
|
|
|
|
|
/* hotplug device table support */
|
2006-04-24 13:29:46 +00:00
|
|
|
static const struct usb_device_id pwc_device_table [] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(0x0471, 0x0302) }, /* Philips models */
|
|
|
|
{ USB_DEVICE(0x0471, 0x0303) },
|
|
|
|
{ USB_DEVICE(0x0471, 0x0304) },
|
|
|
|
{ USB_DEVICE(0x0471, 0x0307) },
|
|
|
|
{ USB_DEVICE(0x0471, 0x0308) },
|
|
|
|
{ USB_DEVICE(0x0471, 0x030C) },
|
|
|
|
{ USB_DEVICE(0x0471, 0x0310) },
|
2006-04-24 13:29:46 +00:00
|
|
|
{ USB_DEVICE(0x0471, 0x0311) }, /* Philips ToUcam PRO II */
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(0x0471, 0x0312) },
|
|
|
|
{ USB_DEVICE(0x0471, 0x0313) }, /* the 'new' 720K */
|
2006-04-24 13:29:46 +00:00
|
|
|
{ USB_DEVICE(0x0471, 0x0329) }, /* Philips SPC 900NC PC Camera */
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(0x069A, 0x0001) }, /* Askey */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B0) }, /* Logitech QuickCam Pro 3000 */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B1) }, /* Logitech QuickCam Notebook Pro */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B2) }, /* Logitech QuickCam Pro 4000 */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B3) }, /* Logitech QuickCam Zoom (old model) */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B4) }, /* Logitech QuickCam Zoom (new model) */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B5) }, /* Logitech QuickCam Orbit/Sphere */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B6) }, /* Logitech (reserved) */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B7) }, /* Logitech (reserved) */
|
|
|
|
{ USB_DEVICE(0x046D, 0x08B8) }, /* Logitech (reserved) */
|
2006-04-24 13:29:46 +00:00
|
|
|
{ USB_DEVICE(0x055D, 0x9000) }, /* Samsung MPC-C10 */
|
|
|
|
{ USB_DEVICE(0x055D, 0x9001) }, /* Samsung MPC-C30 */
|
|
|
|
{ USB_DEVICE(0x055D, 0x9002) }, /* Samsung SNC-35E (Ver3.0) */
|
2005-04-16 22:20:36 +00:00
|
|
|
{ USB_DEVICE(0x041E, 0x400C) }, /* Creative Webcam 5 */
|
|
|
|
{ USB_DEVICE(0x041E, 0x4011) }, /* Creative Webcam Pro Ex */
|
|
|
|
{ USB_DEVICE(0x04CC, 0x8116) }, /* Afina Eye */
|
|
|
|
{ USB_DEVICE(0x06BE, 0x8116) }, /* new Afina Eye */
|
|
|
|
{ USB_DEVICE(0x0d81, 0x1910) }, /* Visionite */
|
|
|
|
{ USB_DEVICE(0x0d81, 0x1900) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, pwc_device_table);
|
|
|
|
|
|
|
|
static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id *id);
|
|
|
|
static void usb_pwc_disconnect(struct usb_interface *intf);
|
|
|
|
|
|
|
|
static struct usb_driver pwc_driver = {
|
|
|
|
.name = "Philips webcam", /* name */
|
|
|
|
.id_table = pwc_device_table,
|
|
|
|
.probe = usb_pwc_probe, /* probe() */
|
|
|
|
.disconnect = usb_pwc_disconnect, /* disconnect() */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_DEV_HINTS 20
|
|
|
|
#define MAX_ISOC_ERRORS 20
|
|
|
|
|
|
|
|
static int default_size = PSZ_QCIF;
|
|
|
|
static int default_fps = 10;
|
|
|
|
static int default_fbufs = 3; /* Default number of frame buffers */
|
2006-04-24 13:29:46 +00:00
|
|
|
int pwc_mbufs = 2; /* Default number of mmap() buffers */
|
2007-01-31 02:26:01 +00:00
|
|
|
#ifdef CONFIG_USB_PWC_DEBUG
|
2006-04-24 13:29:46 +00:00
|
|
|
int pwc_trace = PWC_DEBUG_LEVEL;
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
static int power_save = 0;
|
|
|
|
static int led_on = 100, led_off = 0; /* defaults to LED that is on while in use */
|
2006-06-23 09:49:34 +00:00
|
|
|
static int pwc_preferred_compression = 1; /* 0..3 = uncompressed..high */
|
2005-04-16 22:20:36 +00:00
|
|
|
static struct {
|
|
|
|
int type;
|
|
|
|
char serial_number[30];
|
|
|
|
int device_node;
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
} device_hint[MAX_DEV_HINTS];
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
static int pwc_video_open(struct inode *inode, struct file *file);
|
|
|
|
static int pwc_video_close(struct inode *inode, struct file *file);
|
2006-04-24 13:29:46 +00:00
|
|
|
static ssize_t pwc_video_read(struct file *file, char __user *buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
size_t count, loff_t *ppos);
|
|
|
|
static unsigned int pwc_video_poll(struct file *file, poll_table *wait);
|
|
|
|
static int pwc_video_ioctl(struct inode *inode, struct file *file,
|
|
|
|
unsigned int ioctlnr, unsigned long arg);
|
|
|
|
static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma);
|
|
|
|
|
2007-02-12 08:55:33 +00:00
|
|
|
static const struct file_operations pwc_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = pwc_video_open,
|
|
|
|
.release = pwc_video_close,
|
|
|
|
.read = pwc_video_read,
|
|
|
|
.poll = pwc_video_poll,
|
|
|
|
.mmap = pwc_video_mmap,
|
|
|
|
.ioctl = pwc_video_ioctl,
|
2006-08-08 12:10:10 +00:00
|
|
|
.compat_ioctl = v4l_compat_ioctl32,
|
2005-04-16 22:20:36 +00:00
|
|
|
.llseek = no_llseek,
|
|
|
|
};
|
|
|
|
static struct video_device pwc_template = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "Philips Webcam", /* Filled in later */
|
|
|
|
.type = VID_TYPE_CAPTURE,
|
|
|
|
.hardware = VID_HARDWARE_PWC,
|
|
|
|
.release = video_device_release,
|
|
|
|
.fops = &pwc_fops,
|
|
|
|
.minor = -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
/* Okay, this is some magic that I worked out and the reasoning behind it...
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
The biggest problem with any USB device is of course: "what to do
|
2005-04-16 22:20:36 +00:00
|
|
|
when the user unplugs the device while it is in use by an application?"
|
|
|
|
We have several options:
|
|
|
|
1) Curse them with the 7 plagues when they do (requires divine intervention)
|
|
|
|
2) Tell them not to (won't work: they'll do it anyway)
|
|
|
|
3) Oops the kernel (this will have a negative effect on a user's uptime)
|
|
|
|
4) Do something sensible.
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
Of course, we go for option 4.
|
|
|
|
|
|
|
|
It happens that this device will be linked to two times, once from
|
|
|
|
usb_device and once from the video_device in their respective 'private'
|
|
|
|
pointers. This is done when the device is probed() and all initialization
|
|
|
|
succeeded. The pwc_device struct links back to both structures.
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
When a device is unplugged while in use it will be removed from the
|
|
|
|
list of known USB devices; I also de-register it as a V4L device, but
|
2005-04-16 22:20:36 +00:00
|
|
|
unfortunately I can't free the memory since the struct is still in use
|
|
|
|
by the file descriptor. This free-ing is then deferend until the first
|
|
|
|
opportunity. Crude, but it works.
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
A small 'advantage' is that if a user unplugs the cam and plugs it back
|
|
|
|
in, it should get assigned the same video device minor, but unfortunately
|
2006-03-25 12:19:53 +00:00
|
|
|
it's non-trivial to re-link the cam back to the video device... (that
|
2005-04-16 22:20:36 +00:00
|
|
|
would surely be magic! :))
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Private functions */
|
|
|
|
|
|
|
|
/* Here we want the physical address of the memory.
|
|
|
|
* This is used when initializing the contents of the area.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
|
|
|
|
static void *pwc_rvmalloc(unsigned long size)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
void * mem;
|
|
|
|
unsigned long adr;
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
mem=vmalloc_32(size);
|
2006-04-24 13:29:46 +00:00
|
|
|
if (!mem)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(mem, 0, size); /* Clear the ram out, no junk to the user */
|
|
|
|
adr=(unsigned long) mem;
|
|
|
|
while (size > 0)
|
|
|
|
{
|
|
|
|
SetPageReserved(vmalloc_to_page((void *)adr));
|
|
|
|
adr += PAGE_SIZE;
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
static void pwc_rvfree(void * mem, unsigned long size)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-25 12:19:53 +00:00
|
|
|
unsigned long adr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
if (!mem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
adr=(unsigned long) mem;
|
|
|
|
while ((long) size > 0)
|
|
|
|
{
|
|
|
|
ClearPageReserved(vmalloc_to_page((void *)adr));
|
|
|
|
adr += PAGE_SIZE;
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
}
|
|
|
|
vfree(mem);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int pwc_allocate_buffers(struct pwc_device *pdev)
|
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
int i, err;
|
2005-04-16 22:20:36 +00:00
|
|
|
void *kbuf;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY(">> pwc_allocate_buffers(pdev = 0x%p)\n", pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (pdev == NULL)
|
|
|
|
return -ENXIO;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/* Allocate Isochronuous pipe buffers */
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
|
|
|
if (pdev->sbuf[i].data == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
kbuf = kzalloc(ISO_BUFFER_SIZE, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (kbuf == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to allocate iso buffer %d.\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Allocated iso buffer at %p.\n", kbuf);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->sbuf[i].data = kbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate frame buffer structure */
|
|
|
|
if (pdev->fbuf == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
kbuf = kzalloc(default_fbufs * sizeof(struct pwc_frame_buf), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (kbuf == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to allocate frame buffer structure.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Allocated frame buffer structure at %p.\n", kbuf);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->fbuf = kbuf;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* create frame buffers, and make circular ring */
|
|
|
|
for (i = 0; i < default_fbufs; i++) {
|
|
|
|
if (pdev->fbuf[i].data == NULL) {
|
|
|
|
kbuf = vmalloc(PWC_FRAME_SIZE); /* need vmalloc since frame buffer > 128K */
|
|
|
|
if (kbuf == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to allocate frame buffer %d.\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Allocated frame buffer %d at %p.\n", i, kbuf);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->fbuf[i].data = kbuf;
|
2006-04-24 13:29:46 +00:00
|
|
|
memset(kbuf, 0, PWC_FRAME_SIZE);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Allocate decompressor table space */
|
2006-04-24 13:29:46 +00:00
|
|
|
if (DEVICE_USE_CODEC1(pdev->type))
|
|
|
|
err = pwc_dec1_alloc(pdev);
|
|
|
|
else
|
|
|
|
err = pwc_dec23_alloc(pdev);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
PWC_ERROR("Failed to allocate decompress table.\n");
|
|
|
|
return err;
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Allocate image buffer; double buffer for mmap() */
|
2006-04-24 13:29:46 +00:00
|
|
|
kbuf = pwc_rvmalloc(pwc_mbufs * pdev->len_per_image);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (kbuf == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to allocate image buffer(s). needed (%d)\n",
|
|
|
|
pwc_mbufs * pdev->len_per_image);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Allocated image buffer at %p.\n", kbuf);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->image_data = kbuf;
|
2006-04-24 13:29:46 +00:00
|
|
|
for (i = 0; i < pwc_mbufs; i++) {
|
|
|
|
pdev->images[i].offset = i * pdev->len_per_image;
|
|
|
|
pdev->images[i].vma_use_count = 0;
|
|
|
|
}
|
|
|
|
for (; i < MAX_IMAGES; i++) {
|
|
|
|
pdev->images[i].offset = 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kbuf = NULL;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("<< pwc_allocate_buffers()\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pwc_free_buffers(struct pwc_device *pdev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Entering free_buffers(%p).\n", pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (pdev == NULL)
|
|
|
|
return;
|
|
|
|
/* Release Iso-pipe buffers */
|
|
|
|
for (i = 0; i < MAX_ISO_BUFS; i++)
|
|
|
|
if (pdev->sbuf[i].data != NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Freeing ISO buffer at %p.\n", pdev->sbuf[i].data);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(pdev->sbuf[i].data);
|
|
|
|
pdev->sbuf[i].data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The same for frame buffers */
|
|
|
|
if (pdev->fbuf != NULL) {
|
|
|
|
for (i = 0; i < default_fbufs; i++) {
|
|
|
|
if (pdev->fbuf[i].data != NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Freeing frame buffer %d at %p.\n", i, pdev->fbuf[i].data);
|
2005-04-16 22:20:36 +00:00
|
|
|
vfree(pdev->fbuf[i].data);
|
|
|
|
pdev->fbuf[i].data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kfree(pdev->fbuf);
|
|
|
|
pdev->fbuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Intermediate decompression buffer & tables */
|
|
|
|
if (pdev->decompress_data != NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Freeing decompression buffer at %p.\n", pdev->decompress_data);
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(pdev->decompress_data);
|
|
|
|
pdev->decompress_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release image buffers */
|
|
|
|
if (pdev->image_data != NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Freeing image buffer at %p.\n", pdev->image_data);
|
|
|
|
pwc_rvfree(pdev->image_data, pwc_mbufs * pdev->len_per_image);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
pdev->image_data = NULL;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Leaving free_buffers().\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
/* The frame & image buffer mess.
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
Yes, this is a mess. Well, it used to be simple, but alas... In this
|
|
|
|
module, 3 buffers schemes are used to get the data from the USB bus to
|
|
|
|
the user program. The first scheme involves the ISO buffers (called thus
|
|
|
|
since they transport ISO data from the USB controller), and not really
|
2006-03-25 12:19:53 +00:00
|
|
|
interesting. Suffices to say the data from this buffer is quickly
|
2005-04-16 22:20:36 +00:00
|
|
|
gathered in an interrupt handler (pwc_isoc_handler) and placed into the
|
|
|
|
frame buffer.
|
|
|
|
|
|
|
|
The frame buffer is the second scheme, and is the central element here.
|
|
|
|
It collects the data from a single frame from the camera (hence, the
|
|
|
|
name). Frames are delimited by the USB camera with a short USB packet,
|
|
|
|
so that's easy to detect. The frame buffers form a list that is filled
|
|
|
|
by the camera+USB controller and drained by the user process through
|
|
|
|
either read() or mmap().
|
|
|
|
|
|
|
|
The image buffer is the third scheme, in which frames are decompressed
|
|
|
|
and converted into planar format. For mmap() there is more than
|
|
|
|
one image buffer available.
|
|
|
|
|
|
|
|
The frame buffers provide the image buffering. In case the user process
|
|
|
|
is a bit slow, this introduces lag and some undesired side-effects.
|
|
|
|
The problem arises when the frame buffer is full. I used to drop the last
|
|
|
|
frame, which makes the data in the queue stale very quickly. But dropping
|
|
|
|
the frame at the head of the queue proved to be a litte bit more difficult.
|
|
|
|
I tried a circular linked scheme, but this introduced more problems than
|
|
|
|
it solved.
|
|
|
|
|
|
|
|
Because filling and draining are completely asynchronous processes, this
|
|
|
|
requires some fiddling with pointers and mutexes.
|
|
|
|
|
|
|
|
Eventually, I came up with a system with 2 lists: an 'empty' frame list
|
|
|
|
and a 'full' frame list:
|
|
|
|
* Initially, all frame buffers but one are on the 'empty' list; the one
|
|
|
|
remaining buffer is our initial fill frame.
|
2006-03-25 12:19:53 +00:00
|
|
|
* If a frame is needed for filling, we try to take it from the 'empty'
|
|
|
|
list, unless that list is empty, in which case we take the buffer at
|
2005-04-16 22:20:36 +00:00
|
|
|
the head of the 'full' list.
|
|
|
|
* When our fill buffer has been filled, it is appended to the 'full'
|
|
|
|
list.
|
|
|
|
* If a frame is needed by read() or mmap(), it is taken from the head of
|
|
|
|
the 'full' list, handled, and then appended to the 'empty' list. If no
|
|
|
|
buffer is present on the 'full' list, we wait.
|
|
|
|
The advantage is that the buffer that is currently being decompressed/
|
|
|
|
converted, is on neither list, and thus not in our way (any other scheme
|
|
|
|
I tried had the problem of old data lingering in the queue).
|
|
|
|
|
|
|
|
Whatever strategy you choose, it always remains a tradeoff: with more
|
|
|
|
frame buffers the chances of a missed frame are reduced. On the other
|
|
|
|
hand, on slower machines it introduces lag because the queue will
|
|
|
|
always be full.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Find next frame buffer to fill. Take from empty or full list, whichever comes first.
|
|
|
|
*/
|
2006-04-24 13:29:46 +00:00
|
|
|
static int pwc_next_fill_frame(struct pwc_device *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
spin_lock_irqsave(&pdev->ptrlock, flags);
|
|
|
|
if (pdev->fill_frame != NULL) {
|
|
|
|
/* append to 'full' list */
|
|
|
|
if (pdev->full_frames == NULL) {
|
|
|
|
pdev->full_frames = pdev->fill_frame;
|
|
|
|
pdev->full_frames_tail = pdev->full_frames;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pdev->full_frames_tail->next = pdev->fill_frame;
|
|
|
|
pdev->full_frames_tail = pdev->fill_frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pdev->empty_frames != NULL) {
|
|
|
|
/* We have empty frames available. That's easy */
|
|
|
|
pdev->fill_frame = pdev->empty_frames;
|
|
|
|
pdev->empty_frames = pdev->empty_frames->next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Hmm. Take it from the full list */
|
|
|
|
/* sanity check */
|
|
|
|
if (pdev->full_frames == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Neither empty or full frames available!\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&pdev->ptrlock, flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
pdev->fill_frame = pdev->full_frames;
|
|
|
|
pdev->full_frames = pdev->full_frames->next;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
pdev->fill_frame->next = NULL;
|
|
|
|
spin_unlock_irqrestore(&pdev->ptrlock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Reset all buffers, pointers and lists, except for the image_used[] buffer.
|
|
|
|
|
|
|
|
If the image_used[] buffer is cleared too, mmap()/VIDIOCSYNC will run into trouble.
|
|
|
|
*/
|
|
|
|
static void pwc_reset_buffers(struct pwc_device *pdev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY(">> %s __enter__\n", __FUNCTION__);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&pdev->ptrlock, flags);
|
|
|
|
pdev->full_frames = NULL;
|
|
|
|
pdev->full_frames_tail = NULL;
|
|
|
|
for (i = 0; i < default_fbufs; i++) {
|
|
|
|
pdev->fbuf[i].filled = 0;
|
|
|
|
if (i > 0)
|
|
|
|
pdev->fbuf[i].next = &pdev->fbuf[i - 1];
|
|
|
|
else
|
|
|
|
pdev->fbuf->next = NULL;
|
|
|
|
}
|
|
|
|
pdev->empty_frames = &pdev->fbuf[default_fbufs - 1];
|
|
|
|
pdev->empty_frames_tail = pdev->fbuf;
|
|
|
|
pdev->read_frame = NULL;
|
|
|
|
pdev->fill_frame = pdev->empty_frames;
|
|
|
|
pdev->empty_frames = pdev->empty_frames->next;
|
|
|
|
|
|
|
|
pdev->image_read_pos = 0;
|
|
|
|
pdev->fill_image = 0;
|
|
|
|
spin_unlock_irqrestore(&pdev->ptrlock, flags);
|
2006-04-24 13:29:46 +00:00
|
|
|
|
|
|
|
PWC_DEBUG_MEMORY("<< %s __leaving__\n", __FUNCTION__);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Do all the handling for getting one frame: get pointer, decompress, advance pointers.
|
|
|
|
*/
|
2006-04-24 13:29:46 +00:00
|
|
|
int pwc_handle_frame(struct pwc_device *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pdev->ptrlock, flags);
|
|
|
|
/* First grab our read_frame; this is removed from all lists, so
|
|
|
|
we can release the lock after this without problems */
|
|
|
|
if (pdev->read_frame != NULL) {
|
|
|
|
/* This can't theoretically happen */
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Huh? Read frame still in use?\n");
|
|
|
|
spin_unlock_irqrestore(&pdev->ptrlock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pdev->full_frames == NULL) {
|
|
|
|
PWC_ERROR("Woops. No frames ready.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-04-24 13:29:46 +00:00
|
|
|
pdev->read_frame = pdev->full_frames;
|
|
|
|
pdev->full_frames = pdev->full_frames->next;
|
|
|
|
pdev->read_frame->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdev->read_frame != NULL) {
|
|
|
|
/* Decompression is a lenghty process, so it's outside of the lock.
|
|
|
|
This gives the isoc_handler the opportunity to fill more frames
|
|
|
|
in the mean time.
|
|
|
|
*/
|
|
|
|
spin_unlock_irqrestore(&pdev->ptrlock, flags);
|
|
|
|
ret = pwc_decompress(pdev);
|
|
|
|
spin_lock_irqsave(&pdev->ptrlock, flags);
|
|
|
|
|
|
|
|
/* We're done with read_buffer, tack it to the end of the empty buffer list */
|
|
|
|
if (pdev->empty_frames == NULL) {
|
|
|
|
pdev->empty_frames = pdev->read_frame;
|
|
|
|
pdev->empty_frames_tail = pdev->empty_frames;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-04-24 13:29:46 +00:00
|
|
|
pdev->empty_frames_tail->next = pdev->read_frame;
|
|
|
|
pdev->empty_frames_tail = pdev->read_frame;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
pdev->read_frame = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&pdev->ptrlock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Advance pointers of image buffer (after each user request)
|
|
|
|
*/
|
2006-04-24 13:29:46 +00:00
|
|
|
void pwc_next_image(struct pwc_device *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
pdev->image_used[pdev->fill_image] = 0;
|
2006-04-24 13:29:46 +00:00
|
|
|
pdev->fill_image = (pdev->fill_image + 1) % pwc_mbufs;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/**
|
|
|
|
* Print debug information when a frame is discarded because all of our buffer
|
|
|
|
* is full
|
|
|
|
*/
|
|
|
|
static void pwc_frame_dumped(struct pwc_device *pdev)
|
|
|
|
{
|
|
|
|
pdev->vframes_dumped++;
|
|
|
|
if (pdev->vframe_count < FRAME_LOWMARK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pdev->vframes_dumped < 20)
|
|
|
|
PWC_DEBUG_FLOW("Dumping frame %d\n", pdev->vframe_count);
|
|
|
|
else if (pdev->vframes_dumped == 20)
|
|
|
|
PWC_DEBUG_FLOW("Dumping frame %d (last message)\n",
|
|
|
|
pdev->vframe_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_buf *fbuf)
|
|
|
|
{
|
|
|
|
int awake = 0;
|
|
|
|
|
|
|
|
/* The ToUCam Fun CMOS sensor causes the firmware to send 2 or 3 bogus
|
|
|
|
frames on the USB wire after an exposure change. This conditition is
|
|
|
|
however detected in the cam and a bit is set in the header.
|
|
|
|
*/
|
|
|
|
if (pdev->type == 730) {
|
|
|
|
unsigned char *ptr = (unsigned char *)fbuf->data;
|
|
|
|
|
|
|
|
if (ptr[1] == 1 && ptr[0] & 0x10) {
|
|
|
|
PWC_TRACE("Hyundai CMOS sensor bug. Dropping frame.\n");
|
|
|
|
pdev->drop_frames += 2;
|
|
|
|
pdev->vframes_error++;
|
|
|
|
}
|
|
|
|
if ((ptr[0] ^ pdev->vmirror) & 0x01) {
|
|
|
|
if (ptr[0] & 0x01) {
|
|
|
|
pdev->snapshot_button_status = 1;
|
|
|
|
PWC_TRACE("Snapshot button pressed.\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PWC_TRACE("Snapshot button released.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((ptr[0] ^ pdev->vmirror) & 0x02) {
|
|
|
|
if (ptr[0] & 0x02)
|
|
|
|
PWC_TRACE("Image is mirrored.\n");
|
|
|
|
else
|
|
|
|
PWC_TRACE("Image is normal.\n");
|
|
|
|
}
|
|
|
|
pdev->vmirror = ptr[0] & 0x03;
|
|
|
|
/* Sometimes the trailer of the 730 is still sent as a 4 byte packet
|
|
|
|
after a short frame; this condition is filtered out specifically. A 4 byte
|
|
|
|
frame doesn't make sense anyway.
|
|
|
|
So we get either this sequence:
|
|
|
|
drop_bit set -> 4 byte frame -> short frame -> good frame
|
|
|
|
Or this one:
|
|
|
|
drop_bit set -> short frame -> good frame
|
|
|
|
So we drop either 3 or 2 frames in all!
|
|
|
|
*/
|
|
|
|
if (fbuf->filled == 4)
|
|
|
|
pdev->drop_frames++;
|
|
|
|
}
|
|
|
|
else if (pdev->type == 740 || pdev->type == 720) {
|
|
|
|
unsigned char *ptr = (unsigned char *)fbuf->data;
|
|
|
|
if ((ptr[0] ^ pdev->vmirror) & 0x01) {
|
|
|
|
if (ptr[0] & 0x01) {
|
|
|
|
pdev->snapshot_button_status = 1;
|
|
|
|
PWC_TRACE("Snapshot button pressed.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PWC_TRACE("Snapshot button released.\n");
|
|
|
|
}
|
|
|
|
pdev->vmirror = ptr[0] & 0x03;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In case we were instructed to drop the frame, do so silently.
|
|
|
|
The buffer pointers are not updated either (but the counters are reset below).
|
|
|
|
*/
|
|
|
|
if (pdev->drop_frames > 0)
|
|
|
|
pdev->drop_frames--;
|
|
|
|
else {
|
|
|
|
/* Check for underflow first */
|
|
|
|
if (fbuf->filled < pdev->frame_total_size) {
|
|
|
|
PWC_DEBUG_FLOW("Frame buffer underflow (%d bytes);"
|
|
|
|
" discarded.\n", fbuf->filled);
|
|
|
|
pdev->vframes_error++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Send only once per EOF */
|
|
|
|
awake = 1; /* delay wake_ups */
|
|
|
|
|
|
|
|
/* Find our next frame to fill. This will always succeed, since we
|
|
|
|
* nick a frame from either empty or full list, but if we had to
|
|
|
|
* take it from the full list, it means a frame got dropped.
|
|
|
|
*/
|
|
|
|
if (pwc_next_fill_frame(pdev))
|
|
|
|
pwc_frame_dumped(pdev);
|
|
|
|
|
|
|
|
}
|
|
|
|
} /* !drop_frames */
|
|
|
|
pdev->vframe_count++;
|
|
|
|
return awake;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* This gets called for the Isochronous pipe (video). This is done in
|
|
|
|
* interrupt time, so it has to be fast, not crash, and not stall. Neat.
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static void pwc_isoc_handler(struct urb *urb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
int i, fst, flen;
|
|
|
|
int awake;
|
|
|
|
struct pwc_frame_buf *fbuf;
|
|
|
|
unsigned char *fillptr = NULL, *iso_buf = NULL;
|
|
|
|
|
|
|
|
awake = 0;
|
|
|
|
pdev = (struct pwc_device *)urb->context;
|
|
|
|
if (pdev == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("isoc_handler() called with NULL device?!\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("URB (%p) unlinked %ssynchronuously.\n", urb, urb->status == -ENOENT ? "" : "a");
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (urb->status != -EINPROGRESS && urb->status != 0) {
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
errmsg = "Unknown";
|
|
|
|
switch(urb->status) {
|
|
|
|
case -ENOSR: errmsg = "Buffer error (overrun)"; break;
|
|
|
|
case -EPIPE: errmsg = "Stalled (device not responding)"; break;
|
|
|
|
case -EOVERFLOW: errmsg = "Babble (bad cable?)"; break;
|
|
|
|
case -EPROTO: errmsg = "Bit-stuff error (bad cable?)"; break;
|
|
|
|
case -EILSEQ: errmsg = "CRC/Timeout (could be anything)"; break;
|
2006-09-19 05:49:02 +00:00
|
|
|
case -ETIME: errmsg = "Device does not respond"; break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_FLOW("pwc_isoc_handler() called with status %d [%s].\n", urb->status, errmsg);
|
2006-03-25 12:19:53 +00:00
|
|
|
/* Give up after a number of contiguous errors on the USB bus.
|
2005-04-16 22:20:36 +00:00
|
|
|
Appearantly something is wrong so we simulate an unplug event.
|
|
|
|
*/
|
|
|
|
if (++pdev->visoc_errors > MAX_ISOC_ERRORS)
|
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Too many ISOC errors, bailing out.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->error_status = EIO;
|
|
|
|
awake = 1;
|
|
|
|
wake_up_interruptible(&pdev->frameq);
|
|
|
|
}
|
|
|
|
goto handler_end; // ugly, but practical
|
|
|
|
}
|
|
|
|
|
|
|
|
fbuf = pdev->fill_frame;
|
|
|
|
if (fbuf == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("pwc_isoc_handler without valid fill frame.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
awake = 1;
|
|
|
|
goto handler_end;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fillptr = fbuf->data + fbuf->filled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset ISOC error counter. We did get here, after all. */
|
|
|
|
pdev->visoc_errors = 0;
|
|
|
|
|
|
|
|
/* vsync: 0 = don't copy data
|
2006-03-25 12:19:53 +00:00
|
|
|
1 = sync-hunt
|
|
|
|
2 = synched
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
/* Compact data */
|
|
|
|
for (i = 0; i < urb->number_of_packets; i++) {
|
|
|
|
fst = urb->iso_frame_desc[i].status;
|
|
|
|
flen = urb->iso_frame_desc[i].actual_length;
|
|
|
|
iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
|
|
|
|
if (fst == 0) {
|
|
|
|
if (flen > 0) { /* if valid data... */
|
|
|
|
if (pdev->vsync > 0) { /* ...and we are not sync-hunting... */
|
|
|
|
pdev->vsync = 2;
|
|
|
|
|
|
|
|
/* ...copy data to frame buffer, if possible */
|
|
|
|
if (flen + fbuf->filled > pdev->frame_total_size) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_FLOW("Frame buffer overflow (flen = %d, frame_total_size = %d).\n", flen, pdev->frame_total_size);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->vsync = 0; /* Hmm, let's wait for an EOF (end-of-frame) */
|
|
|
|
pdev->vframes_error++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memmove(fillptr, iso_buf, flen);
|
|
|
|
fillptr += flen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fbuf->filled += flen;
|
|
|
|
} /* ..flen > 0 */
|
|
|
|
|
|
|
|
if (flen < pdev->vlast_packet_size) {
|
2006-03-25 12:19:53 +00:00
|
|
|
/* Shorter packet... We probably have the end of an image-frame;
|
2005-04-16 22:20:36 +00:00
|
|
|
wake up read() process and let select()/poll() do something.
|
|
|
|
Decompression is done in user time over there.
|
2006-04-24 13:29:46 +00:00
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pdev->vsync == 2) {
|
2006-04-24 13:29:46 +00:00
|
|
|
if (pwc_rcv_short_packet(pdev, fbuf)) {
|
|
|
|
awake = 1;
|
|
|
|
fbuf = pdev->fill_frame;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fbuf->filled = 0;
|
|
|
|
fillptr = fbuf->data;
|
|
|
|
pdev->vsync = 1;
|
2006-04-24 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->vlast_packet_size = flen;
|
|
|
|
} /* ..status == 0 */
|
|
|
|
else {
|
2006-04-24 13:29:46 +00:00
|
|
|
/* This is normally not interesting to the user, unless
|
|
|
|
* you are really debugging something */
|
2005-04-16 22:20:36 +00:00
|
|
|
static int iso_error = 0;
|
|
|
|
iso_error++;
|
|
|
|
if (iso_error < 20)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_FLOW("Iso frame %d of USB has error %d\n", i, fst);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handler_end:
|
|
|
|
if (awake)
|
|
|
|
wake_up_interruptible(&pdev->frameq);
|
|
|
|
|
|
|
|
urb->dev = pdev->udev;
|
|
|
|
i = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (i != 0)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Error (%d) re-submitting urb in pwc_isoc_handler.\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
int pwc_isoc_init(struct pwc_device *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct usb_device *udev;
|
|
|
|
struct urb *urb;
|
|
|
|
int i, j, ret;
|
|
|
|
|
|
|
|
struct usb_interface *intf;
|
|
|
|
struct usb_host_interface *idesc = NULL;
|
|
|
|
|
|
|
|
if (pdev == NULL)
|
|
|
|
return -EFAULT;
|
|
|
|
if (pdev->iso_init)
|
|
|
|
return 0;
|
|
|
|
pdev->vsync = 0;
|
|
|
|
udev = pdev->udev;
|
|
|
|
|
|
|
|
/* Get the current alternate interface, adjust packet size */
|
|
|
|
if (!udev->actconfig)
|
|
|
|
return -EFAULT;
|
|
|
|
intf = usb_ifnum_to_if(udev, 0);
|
|
|
|
if (intf)
|
|
|
|
idesc = usb_altnum_to_altsetting(intf, pdev->valternate);
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!idesc)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* Search video endpoint */
|
|
|
|
pdev->vmax_packet_size = -1;
|
2006-04-24 13:29:46 +00:00
|
|
|
for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->vendpoint) {
|
|
|
|
pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to find packet size for video endpoint in current alternate setting.\n");
|
2005-05-04 01:07:24 +00:00
|
|
|
return -ENFILE; /* Odd error, that should be noticeable */
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set alternate interface */
|
|
|
|
ret = 0;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate);
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = usb_set_interface(pdev->udev, 0, pdev->valternate);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
|
|
|
urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
|
|
|
|
if (urb == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to allocate urb %d\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pdev->sbuf[i].urb = urb;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Allocated URB at 0x%p\n", urb);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
/* De-allocate in reverse order */
|
2006-11-16 15:38:57 +00:00
|
|
|
while (i--) {
|
2006-11-08 14:34:55 +00:00
|
|
|
usb_free_urb(pdev->sbuf[i].urb);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->sbuf[i].urb = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
/* init URB structure */
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
|
|
|
urb = pdev->sbuf[i].urb;
|
|
|
|
|
|
|
|
urb->interval = 1; // devik
|
|
|
|
urb->dev = udev;
|
2006-03-25 12:19:53 +00:00
|
|
|
urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint);
|
2005-04-16 22:20:36 +00:00
|
|
|
urb->transfer_flags = URB_ISO_ASAP;
|
2006-03-25 12:19:53 +00:00
|
|
|
urb->transfer_buffer = pdev->sbuf[i].data;
|
|
|
|
urb->transfer_buffer_length = ISO_BUFFER_SIZE;
|
|
|
|
urb->complete = pwc_isoc_handler;
|
|
|
|
urb->context = pdev;
|
2005-04-16 22:20:36 +00:00
|
|
|
urb->start_frame = 0;
|
|
|
|
urb->number_of_packets = ISO_FRAMES_PER_DESC;
|
|
|
|
for (j = 0; j < ISO_FRAMES_PER_DESC; j++) {
|
|
|
|
urb->iso_frame_desc[j].offset = j * ISO_MAX_FRAME_SIZE;
|
|
|
|
urb->iso_frame_desc[j].length = pdev->vmax_packet_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* link */
|
|
|
|
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
|
|
|
ret = usb_submit_urb(pdev->sbuf[i].urb, GFP_KERNEL);
|
|
|
|
if (ret)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->sbuf[i].urb);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* All is done... */
|
|
|
|
pdev->iso_init = 1;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("<< pwc_isoc_init()\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
void pwc_isoc_cleanup(struct pwc_device *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN(">> pwc_isoc_cleanup()\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pdev == NULL)
|
|
|
|
return;
|
2006-04-24 13:29:46 +00:00
|
|
|
if (pdev->iso_init == 0)
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Unlinking ISOC buffers one by one */
|
|
|
|
for (i = 0; i < MAX_ISO_BUFS; i++) {
|
|
|
|
struct urb *urb;
|
|
|
|
|
|
|
|
urb = pdev->sbuf[i].urb;
|
|
|
|
if (urb != 0) {
|
|
|
|
if (pdev->iso_init) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Unlinking URB %p\n", urb);
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_kill_urb(urb);
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY("Freeing URB\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_free_urb(urb);
|
|
|
|
pdev->sbuf[i].urb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop camera, but only if we are sure the camera is still there (unplug
|
2006-03-25 12:19:53 +00:00
|
|
|
is signalled by EPIPE)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
if (pdev->error_status && pdev->error_status != EPIPE) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Setting alternate interface 0.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_set_interface(pdev->udev, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev->iso_init = 0;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot)
|
|
|
|
{
|
|
|
|
int ret, start;
|
|
|
|
|
|
|
|
/* Stop isoc stuff */
|
|
|
|
pwc_isoc_cleanup(pdev);
|
|
|
|
/* Reset parameters */
|
|
|
|
pwc_reset_buffers(pdev);
|
|
|
|
/* Try to set video mode... */
|
|
|
|
start = ret = pwc_set_video_mode(pdev, width, height, new_fps, new_compression, new_snapshot);
|
2006-03-25 12:19:53 +00:00
|
|
|
if (ret) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_FLOW("pwc_set_video_mode attempt 1 failed.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
/* That failed... restore old mode (we know that worked) */
|
|
|
|
start = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot);
|
|
|
|
if (start) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_FLOW("pwc_set_video_mode attempt 2 failed.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (start == 0)
|
|
|
|
{
|
|
|
|
if (pwc_isoc_init(pdev) < 0)
|
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_WARNING("Failed to restart ISOC transfers in pwc_try_video_mode.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ret = -EAGAIN; /* let's try again, who knows if it works a second time */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pdev->drop_frames++; /* try to avoid garbage during switch */
|
|
|
|
return ret; /* Return original error code */
|
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/*********
|
|
|
|
* sysfs
|
|
|
|
*********/
|
|
|
|
static struct pwc_device *cd_to_pwc(struct class_device *cd)
|
|
|
|
{
|
|
|
|
struct video_device *vdev = to_video_device(cd);
|
|
|
|
return video_get_drvdata(vdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_pan_tilt(struct class_device *class_dev, char *buf)
|
|
|
|
{
|
|
|
|
struct pwc_device *pdev = cd_to_pwc(class_dev);
|
|
|
|
return sprintf(buf, "%d %d\n", pdev->pan_angle, pdev->tilt_angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_pan_tilt(struct class_device *class_dev, const char *buf,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
struct pwc_device *pdev = cd_to_pwc(class_dev);
|
|
|
|
int pan, tilt;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
if (strncmp(buf, "reset", 5) == 0)
|
|
|
|
ret = pwc_mpt_reset(pdev, 0x3);
|
|
|
|
|
|
|
|
else if (sscanf(buf, "%d %d", &pan, &tilt) > 0)
|
|
|
|
ret = pwc_mpt_set_angle(pdev, pan, tilt);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return strlen(buf);
|
|
|
|
}
|
|
|
|
static CLASS_DEVICE_ATTR(pan_tilt, S_IRUGO | S_IWUSR, show_pan_tilt,
|
|
|
|
store_pan_tilt);
|
|
|
|
|
|
|
|
static ssize_t show_snapshot_button_status(struct class_device *class_dev, char *buf)
|
|
|
|
{
|
|
|
|
struct pwc_device *pdev = cd_to_pwc(class_dev);
|
|
|
|
int status = pdev->snapshot_button_status;
|
|
|
|
pdev->snapshot_button_status = 0;
|
|
|
|
return sprintf(buf, "%d\n", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CLASS_DEVICE_ATTR(button, S_IRUGO | S_IWUSR, show_snapshot_button_status,
|
|
|
|
NULL);
|
|
|
|
|
2006-10-13 10:17:32 +00:00
|
|
|
static int pwc_create_sysfs_files(struct video_device *vdev)
|
2006-04-24 13:29:46 +00:00
|
|
|
{
|
|
|
|
struct pwc_device *pdev = video_get_drvdata(vdev);
|
2006-10-13 10:17:32 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = video_device_create_file(vdev, &class_device_attr_button);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
if (pdev->features & FEATURE_MOTOR_PANTILT) {
|
|
|
|
rc = video_device_create_file(vdev,&class_device_attr_pan_tilt);
|
|
|
|
if (rc) goto err_button;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_button:
|
|
|
|
video_device_remove_file(vdev, &class_device_attr_button);
|
|
|
|
err:
|
|
|
|
return rc;
|
2006-04-24 13:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pwc_remove_sysfs_files(struct video_device *vdev)
|
|
|
|
{
|
|
|
|
struct pwc_device *pdev = video_get_drvdata(vdev);
|
|
|
|
if (pdev->features & FEATURE_MOTOR_PANTILT)
|
|
|
|
video_device_remove_file(vdev, &class_device_attr_pan_tilt);
|
|
|
|
video_device_remove_file(vdev, &class_device_attr_button);
|
|
|
|
}
|
|
|
|
|
2007-01-31 02:26:01 +00:00
|
|
|
#ifdef CONFIG_USB_PWC_DEBUG
|
2006-04-24 13:29:46 +00:00
|
|
|
static const char *pwc_sensor_type_to_string(unsigned int sensor_type)
|
|
|
|
{
|
|
|
|
switch(sensor_type) {
|
|
|
|
case 0x00:
|
|
|
|
return "Hyundai CMOS sensor";
|
|
|
|
case 0x20:
|
|
|
|
return "Sony CCD sensor + TDA8787";
|
|
|
|
case 0x2E:
|
|
|
|
return "Sony CCD sensor + Exas 98L59";
|
|
|
|
case 0x2F:
|
|
|
|
return "Sony CCD sensor + ADI 9804";
|
|
|
|
case 0x30:
|
|
|
|
return "Sharp CCD sensor + TDA8787";
|
|
|
|
case 0x3E:
|
|
|
|
return "Sharp CCD sensor + Exas 98L59";
|
|
|
|
case 0x3F:
|
|
|
|
return "Sharp CCD sensor + ADI 9804";
|
|
|
|
case 0x40:
|
|
|
|
return "UPA 1021 sensor";
|
|
|
|
case 0x100:
|
|
|
|
return "VGA sensor";
|
|
|
|
case 0x101:
|
|
|
|
return "PAL MR sensor";
|
|
|
|
default:
|
2006-06-20 03:30:57 +00:00
|
|
|
return "unknown type of sensor";
|
2006-04-24 13:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Video4Linux functions */
|
|
|
|
|
|
|
|
static int pwc_video_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
int i, ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct video_device *vdev = video_devdata(file);
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev);
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev = (struct pwc_device *)vdev->priv;
|
2006-11-30 04:26:46 +00:00
|
|
|
BUG_ON(!pdev);
|
2006-04-24 13:29:46 +00:00
|
|
|
if (pdev->vopen) {
|
|
|
|
PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
2006-04-24 13:29:46 +00:00
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
down(&pdev->modlock);
|
|
|
|
if (!pdev->usb_init) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Doing first time initialization.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->usb_init = 1;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/* Query sensor type */
|
|
|
|
ret = pwc_get_cmos_sensor(pdev, &i);
|
|
|
|
if (ret >= 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("This %s camera is equipped with a %s (%d).\n",
|
|
|
|
pdev->vdev->name,
|
|
|
|
pwc_sensor_type_to_string(i), i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn on camera */
|
|
|
|
if (power_save) {
|
|
|
|
i = pwc_camera_power(pdev, 1);
|
|
|
|
if (i < 0)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Failed to restore power to the camera! (%d)\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
/* Set LED on/off time */
|
|
|
|
if (pwc_set_leds(pdev, led_on, led_off) < 0)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Failed to set LED on/off time.\n");
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
pwc_construct(pdev); /* set min/max sizes correct */
|
|
|
|
|
|
|
|
/* So far, so good. Allocate memory. */
|
|
|
|
i = pwc_allocate_buffers(pdev);
|
|
|
|
if (i < 0) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Failed to allocate buffers memory.\n");
|
|
|
|
pwc_free_buffers(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
up(&pdev->modlock);
|
|
|
|
return i;
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Reset buffers & parameters */
|
|
|
|
pwc_reset_buffers(pdev);
|
2006-04-24 13:29:46 +00:00
|
|
|
for (i = 0; i < pwc_mbufs; i++)
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->image_used[i] = 0;
|
|
|
|
pdev->vframe_count = 0;
|
|
|
|
pdev->vframes_dumped = 0;
|
|
|
|
pdev->vframes_error = 0;
|
|
|
|
pdev->visoc_errors = 0;
|
|
|
|
pdev->error_status = 0;
|
|
|
|
pwc_construct(pdev); /* set min/max sizes correct */
|
|
|
|
|
|
|
|
/* Set some defaults */
|
|
|
|
pdev->vsnapshot = 0;
|
|
|
|
|
|
|
|
/* Start iso pipe for video; first try the last used video size
|
|
|
|
(or the default one); if that fails try QCIF/10 or QSIF/10;
|
|
|
|
it that fails too, give up.
|
|
|
|
*/
|
|
|
|
i = pwc_set_video_mode(pdev, pwc_image_sizes[pdev->vsize].x, pwc_image_sizes[pdev->vsize].y, pdev->vframes, pdev->vcompression, 0);
|
|
|
|
if (i) {
|
2006-04-24 13:29:46 +00:00
|
|
|
unsigned int default_resolution;
|
|
|
|
PWC_DEBUG_OPEN("First attempt at set_video_mode failed.\n");
|
|
|
|
if (pdev->type>= 730)
|
|
|
|
default_resolution = PSZ_QSIF;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2006-04-24 13:29:46 +00:00
|
|
|
default_resolution = PSZ_QCIF;
|
|
|
|
|
|
|
|
i = pwc_set_video_mode(pdev,
|
|
|
|
pwc_image_sizes[default_resolution].x,
|
|
|
|
pwc_image_sizes[default_resolution].y,
|
|
|
|
10,
|
|
|
|
pdev->vcompression,
|
|
|
|
0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (i) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Second attempt at set_video_mode failed.\n");
|
|
|
|
pwc_free_buffers(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
up(&pdev->modlock);
|
|
|
|
return i;
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
i = pwc_isoc_init(pdev);
|
|
|
|
if (i) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("Failed to init ISOC stuff = %d.\n", i);
|
|
|
|
pwc_isoc_cleanup(pdev);
|
|
|
|
pwc_free_buffers(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
up(&pdev->modlock);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/* Initialize the webcam to sane value */
|
|
|
|
pwc_set_brightness(pdev, 0x7fff);
|
|
|
|
pwc_set_agc(pdev, 1, 0);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->vopen++;
|
|
|
|
file->private_data = vdev;
|
|
|
|
up(&pdev->modlock);
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN("<< video_open() returns 0.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that all cleanup is done in the reverse order as in _open */
|
|
|
|
static int pwc_video_close(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct video_device *vdev = file->private_data;
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
int i;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
pdev = (struct pwc_device *)vdev->priv;
|
|
|
|
if (pdev->vopen == 0)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("video_close() called on closed device?\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Dump statistics, but only if a reasonable amount of frames were
|
|
|
|
processed (to prevent endless log-entries in case of snap-shot
|
|
|
|
programs)
|
|
|
|
*/
|
|
|
|
if (pdev->vframe_count > 20)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Closing video device: %d frames received, dumped %d frames, %d frames with errors.\n", pdev->vframe_count, pdev->vframes_dumped, pdev->vframes_error);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
if (DEVICE_USE_CODEC1(pdev->type))
|
|
|
|
pwc_dec1_exit();
|
|
|
|
else
|
|
|
|
pwc_dec23_exit();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
pwc_isoc_cleanup(pdev);
|
|
|
|
pwc_free_buffers(pdev);
|
|
|
|
|
|
|
|
/* Turn off LEDS and power down camera, but only when not unplugged */
|
|
|
|
if (pdev->error_status != EPIPE) {
|
|
|
|
/* Turn LEDs off */
|
|
|
|
if (pwc_set_leds(pdev, 0, 0) < 0)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Failed to set LED on/off time.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (power_save) {
|
|
|
|
i = pwc_camera_power(pdev, 0);
|
|
|
|
if (i < 0)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to power down camera (%d)\n", i);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
pdev->vopen--;
|
|
|
|
PWC_DEBUG_OPEN("<< video_close() vopen=%d\n", pdev->vopen);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: what about two parallel reads ????
|
|
|
|
* ANSWER: Not supported. You can't open the device more than once,
|
2006-03-25 12:19:53 +00:00
|
|
|
despite what the V4L1 interface says. First, I don't see
|
|
|
|
the need, second there's no mechanism of alerting the
|
|
|
|
2nd/3rd/... process of events like changing image size.
|
|
|
|
And I don't see the point of blocking that for the
|
|
|
|
2nd/3rd/... process.
|
|
|
|
In multi-threaded environments reading parallel from any
|
|
|
|
device is tricky anyhow.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
static ssize_t pwc_video_read(struct file *file, char __user *buf,
|
2005-04-16 22:20:36 +00:00
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct video_device *vdev = file->private_data;
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
int noblock = file->f_flags & O_NONBLOCK;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
2006-03-25 12:19:53 +00:00
|
|
|
int bytes_to_read;
|
2006-04-24 13:29:46 +00:00
|
|
|
void *image_buffer_addr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_READ("pwc_video_read(vdev=0x%p, buf=%p, count=%zd) called.\n",
|
|
|
|
vdev, buf, count);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (vdev == NULL)
|
|
|
|
return -EFAULT;
|
|
|
|
pdev = vdev->priv;
|
|
|
|
if (pdev == NULL)
|
|
|
|
return -EFAULT;
|
|
|
|
if (pdev->error_status)
|
|
|
|
return -pdev->error_status; /* Something happened, report what. */
|
|
|
|
|
|
|
|
/* In case we're doing partial reads, we don't have to wait for a frame */
|
|
|
|
if (pdev->image_read_pos == 0) {
|
|
|
|
/* Do wait queueing according to the (doc)book */
|
|
|
|
add_wait_queue(&pdev->frameq, &wait);
|
|
|
|
while (pdev->full_frames == NULL) {
|
|
|
|
/* Check for unplugged/etc. here */
|
|
|
|
if (pdev->error_status) {
|
|
|
|
remove_wait_queue(&pdev->frameq, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
return -pdev->error_status ;
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
if (noblock) {
|
|
|
|
remove_wait_queue(&pdev->frameq, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
}
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
remove_wait_queue(&pdev->frameq, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
}
|
|
|
|
schedule();
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
remove_wait_queue(&pdev->frameq, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Decompress and release frame */
|
|
|
|
if (pwc_handle_frame(pdev))
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_READ("Copying data to user space.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pdev->vpalette == VIDEO_PALETTE_RAW)
|
2006-04-24 13:29:46 +00:00
|
|
|
bytes_to_read = pdev->frame_size + sizeof(struct pwc_raw_frame);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2006-03-25 12:19:53 +00:00
|
|
|
bytes_to_read = pdev->view.size;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* copy bytes to user space; we allow for partial reads */
|
|
|
|
if (count + pdev->image_read_pos > bytes_to_read)
|
|
|
|
count = bytes_to_read - pdev->image_read_pos;
|
2006-04-24 13:29:46 +00:00
|
|
|
image_buffer_addr = pdev->image_data;
|
|
|
|
image_buffer_addr += pdev->images[pdev->fill_image].offset;
|
|
|
|
image_buffer_addr += pdev->image_read_pos;
|
|
|
|
if (copy_to_user(buf, image_buffer_addr, count))
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
pdev->image_read_pos += count;
|
|
|
|
if (pdev->image_read_pos >= bytes_to_read) { /* All data has been read */
|
|
|
|
pdev->image_read_pos = 0;
|
|
|
|
pwc_next_image(pdev);
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
|
|
|
|
{
|
|
|
|
struct video_device *vdev = file->private_data;
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
|
|
|
|
if (vdev == NULL)
|
|
|
|
return -EFAULT;
|
|
|
|
pdev = vdev->priv;
|
|
|
|
if (pdev == NULL)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
poll_wait(file, &pdev->frameq, wait);
|
|
|
|
if (pdev->error_status)
|
|
|
|
return POLLERR;
|
|
|
|
if (pdev->full_frames != NULL) /* we have frames waiting */
|
|
|
|
return (POLLIN | POLLRDNORM);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pwc_video_ioctl(struct inode *inode, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
return video_usercopy(inode, file, cmd, arg, pwc_video_do_ioctl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct video_device *vdev = file->private_data;
|
|
|
|
struct pwc_device *pdev;
|
2006-04-24 13:29:46 +00:00
|
|
|
unsigned long start;
|
|
|
|
unsigned long size;
|
|
|
|
unsigned long page, pos = 0;
|
|
|
|
int index;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MEMORY(">> %s\n", __FUNCTION__);
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev = vdev->priv;
|
2006-04-24 13:29:46 +00:00
|
|
|
size = vma->vm_end - vma->vm_start;
|
|
|
|
start = vma->vm_start;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/* Find the idx buffer for this mapping */
|
|
|
|
for (index = 0; index < pwc_mbufs; index++) {
|
|
|
|
pos = pdev->images[index].offset;
|
|
|
|
if ((pos>>PAGE_SHIFT) == vma->vm_pgoff)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (index == MAX_IMAGES)
|
|
|
|
return -EINVAL;
|
|
|
|
if (index == 0) {
|
|
|
|
/*
|
|
|
|
* Special case for v4l1. In v4l1, we map only one big buffer,
|
|
|
|
* but in v4l2 each buffer is mapped
|
|
|
|
*/
|
|
|
|
unsigned long total_size;
|
|
|
|
total_size = pwc_mbufs * pdev->len_per_image;
|
|
|
|
if (size != pdev->len_per_image && size != total_size) {
|
|
|
|
PWC_ERROR("Wrong size (%lu) needed to be len_per_image=%d or total_size=%lu\n",
|
|
|
|
size, pdev->len_per_image, total_size);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else if (size > pdev->len_per_image)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vma->vm_flags |= VM_IO; /* from 2.6.9-acX */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
pos += (unsigned long)pdev->image_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
while (size > 0) {
|
|
|
|
page = vmalloc_to_pfn((void *)pos);
|
|
|
|
if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
|
|
|
|
return -EAGAIN;
|
|
|
|
start += PAGE_SIZE;
|
|
|
|
pos += PAGE_SIZE;
|
|
|
|
if (size > PAGE_SIZE)
|
|
|
|
size -= PAGE_SIZE;
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* USB functions */
|
|
|
|
|
|
|
|
/* This function gets called when a new device is plugged in or the usb core
|
|
|
|
* is loaded.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
|
|
struct pwc_device *pdev = NULL;
|
|
|
|
int vendor_id, product_id, type_id;
|
2006-10-13 10:17:32 +00:00
|
|
|
int i, hint, rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
int features = 0;
|
|
|
|
int video_nr = -1; /* default: use next available device */
|
|
|
|
char serial_number[30], *name;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
vendor_id = le16_to_cpu(udev->descriptor.idVendor);
|
|
|
|
product_id = le16_to_cpu(udev->descriptor.idProduct);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Check if we can handle this device */
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_PROBE("probe() called [%04X %04X], if %d\n",
|
|
|
|
vendor_id, product_id,
|
2005-04-16 22:20:36 +00:00
|
|
|
intf->altsetting->desc.bInterfaceNumber);
|
|
|
|
|
|
|
|
/* the interfaces are probed one by one. We are only interested in the
|
|
|
|
video interface (0) now.
|
|
|
|
Interface 1 is the Audio Control, and interface 2 Audio itself.
|
|
|
|
*/
|
|
|
|
if (intf->altsetting->desc.bInterfaceNumber > 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (vendor_id == 0x0471) {
|
|
|
|
switch (product_id) {
|
|
|
|
case 0x0302:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCA645VC USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 645 webcam";
|
|
|
|
type_id = 645;
|
|
|
|
break;
|
|
|
|
case 0x0303:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCA646VC USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 646 webcam";
|
|
|
|
type_id = 646;
|
|
|
|
break;
|
|
|
|
case 0x0304:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Askey VC010 type 2 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Askey VC010 webcam";
|
|
|
|
type_id = 646;
|
|
|
|
break;
|
|
|
|
case 0x0307:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC675K (Vesta) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 675 webcam";
|
|
|
|
type_id = 675;
|
|
|
|
break;
|
|
|
|
case 0x0308:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC680K (Vesta Pro) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 680 webcam";
|
|
|
|
type_id = 680;
|
|
|
|
break;
|
|
|
|
case 0x030C:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC690K (Vesta Pro Scan) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 690 webcam";
|
|
|
|
type_id = 690;
|
|
|
|
break;
|
|
|
|
case 0x0310:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC730K (ToUCam Fun)/PCVC830 (ToUCam II) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 730 webcam";
|
|
|
|
type_id = 730;
|
|
|
|
break;
|
|
|
|
case 0x0311:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC740K (ToUCam Pro)/PCVC840 (ToUCam II) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 740 webcam";
|
|
|
|
type_id = 740;
|
|
|
|
break;
|
|
|
|
case 0x0312:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC750K (ToUCam Pro Scan) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 750 webcam";
|
|
|
|
type_id = 750;
|
|
|
|
break;
|
|
|
|
case 0x0313:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips PCVC720K/40 (ToUCam XS) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Philips 720K/40 webcam";
|
|
|
|
type_id = 720;
|
|
|
|
break;
|
2006-04-24 13:29:46 +00:00
|
|
|
case 0x0329:
|
|
|
|
PWC_INFO("Philips SPC 900NC USB webcam detected.\n");
|
|
|
|
name = "Philips SPC 900NC webcam";
|
|
|
|
type_id = 720;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vendor_id == 0x069A) {
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x0001:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Askey VC010 type 1 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Askey VC010 webcam";
|
|
|
|
type_id = 645;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vendor_id == 0x046d) {
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x08b0:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam Pro 3000 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam Pro 3000";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
break;
|
|
|
|
case 0x08b1:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam Notebook Pro USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam Notebook Pro";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
break;
|
|
|
|
case 0x08b2:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam 4000 Pro USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam Pro 4000";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
break;
|
|
|
|
case 0x08b3:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam Zoom USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam Zoom";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
break;
|
|
|
|
case 0x08B4:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam Zoom (new model) USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam Zoom";
|
|
|
|
type_id = 740; /* CCD sensor */
|
2006-04-24 13:29:46 +00:00
|
|
|
power_save = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case 0x08b5:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam Orbit/Sphere USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam Orbit";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
features |= FEATURE_MOTOR_PANTILT;
|
|
|
|
break;
|
|
|
|
case 0x08b6:
|
V4L/DVB (5461): Pwc: cisco VT Camera support
I have a Cisco VT Camera, and it was just collecting dust. I decided to
try connecting it to my Linux box at home.
Just a disgression about the product. The Cisco VT Camera is a webcam
Cisco sold to work with their IP phone hardware and software. It's mostly
useless on Windows, as it interfaces only to Cisco software. You can find
some for cheap on eBay...
Physically, it's just a Logitech Pro 4000. The only difference with the
Pro 4000 is the Cisco logo and that it's grey like the Pro 3000. I believe
Cisco is now selling the Cisco VT Camera II, which look to be something
else...
So, assuming that it was a Pro 4000 inside, I created the little patch
attached.
I'm new to webcam under Linux, but I managed to get an image from it using
xawtv, and the image looked all right, so I consider that a success. The
imaged seemed a bit small and I could not get the microphone driver loaded,
but I assume it's my lack of experience. Note that I did not try any other
type_id, but this one works great.
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
2007-03-21 19:29:16 +00:00
|
|
|
PWC_INFO("Logitech/Cisco VT Camera webcam detected.\n");
|
|
|
|
name = "Cisco VT Camera";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case 0x08b7:
|
|
|
|
case 0x08b8:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Logitech QuickCam detected (reserved ID).\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Logitech QuickCam (res.)";
|
|
|
|
type_id = 730; /* Assuming CMOS */
|
|
|
|
break;
|
2006-03-25 12:19:53 +00:00
|
|
|
default:
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
2006-03-25 12:19:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
else if (vendor_id == 0x055d) {
|
|
|
|
/* I don't know the difference between the C10 and the C30;
|
|
|
|
I suppose the difference is the sensor, but both cameras
|
|
|
|
work equally well with a type_id of 675
|
|
|
|
*/
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x9000:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Samsung MPC-C10 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Samsung MPC-C10";
|
|
|
|
type_id = 675;
|
|
|
|
break;
|
|
|
|
case 0x9001:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Samsung MPC-C30 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Samsung MPC-C30";
|
|
|
|
type_id = 675;
|
|
|
|
break;
|
2006-04-24 13:29:46 +00:00
|
|
|
case 0x9002:
|
|
|
|
PWC_INFO("Samsung SNC-35E (v3.0) USB webcam detected.\n");
|
|
|
|
name = "Samsung MPC-C30";
|
|
|
|
type_id = 740;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vendor_id == 0x041e) {
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x400c:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Creative Labs Webcam 5 detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Creative Labs Webcam 5";
|
|
|
|
type_id = 730;
|
|
|
|
break;
|
|
|
|
case 0x4011:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Creative Labs Webcam Pro Ex detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Creative Labs Webcam Pro Ex";
|
|
|
|
type_id = 740;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vendor_id == 0x04cc) {
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x8116:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Sotec Afina Eye USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Sotec Afina Eye";
|
|
|
|
type_id = 730;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vendor_id == 0x06be) {
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x8116:
|
|
|
|
/* This is essentially the same cam as the Sotec Afina Eye */
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("AME Co. Afina Eye USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "AME Co. Afina Eye";
|
|
|
|
type_id = 750;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else if (vendor_id == 0x0d81) {
|
|
|
|
switch(product_id) {
|
|
|
|
case 0x1900:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Visionite VCS-UC300 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Visionite VCS-UC300";
|
|
|
|
type_id = 740; /* CCD sensor */
|
|
|
|
break;
|
|
|
|
case 0x1910:
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Visionite VCS-UM100 USB webcam detected.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
name = "Visionite VCS-UM100";
|
|
|
|
type_id = 730; /* CMOS sensor */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
else
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV; /* Not any of the know types; but the list keeps growing. */
|
|
|
|
|
|
|
|
memset(serial_number, 0, 30);
|
|
|
|
usb_string(udev, udev->descriptor.iSerialNumber, serial_number, 29);
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_PROBE("Device serial number is %s\n", serial_number);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (udev->descriptor.bNumConfigurations > 1)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_WARNING("Warning: more than 1 configuration available.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */
|
2006-02-27 20:29:43 +00:00
|
|
|
pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pdev == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Oops, could not allocate memory for pwc_device.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
pdev->type = type_id;
|
|
|
|
pdev->vsize = default_size;
|
|
|
|
pdev->vframes = default_fps;
|
|
|
|
strcpy(pdev->serial, serial_number);
|
|
|
|
pdev->features = features;
|
|
|
|
if (vendor_id == 0x046D && product_id == 0x08B5)
|
|
|
|
{
|
|
|
|
/* Logitech QuickCam Orbit
|
2006-03-25 12:19:53 +00:00
|
|
|
The ranges have been determined experimentally; they may differ from cam to cam.
|
|
|
|
Also, the exact ranges left-right and up-down are different for my cam
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->angle_range.pan_min = -7000;
|
|
|
|
pdev->angle_range.pan_max = 7000;
|
|
|
|
pdev->angle_range.tilt_min = -3000;
|
|
|
|
pdev->angle_range.tilt_max = 2500;
|
|
|
|
}
|
|
|
|
|
|
|
|
init_MUTEX(&pdev->modlock);
|
|
|
|
spin_lock_init(&pdev->ptrlock);
|
|
|
|
|
|
|
|
pdev->udev = udev;
|
|
|
|
init_waitqueue_head(&pdev->frameq);
|
|
|
|
pdev->vcompression = pwc_preferred_compression;
|
|
|
|
|
|
|
|
/* Allocate video_device structure */
|
|
|
|
pdev->vdev = video_device_alloc();
|
|
|
|
if (pdev->vdev == 0)
|
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Err, cannot allocate video_device struture. Failing probe.");
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(pdev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template));
|
2006-04-24 13:29:46 +00:00
|
|
|
pdev->vdev->dev = &(udev->dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
strcpy(pdev->vdev->name, name);
|
|
|
|
pdev->vdev->owner = THIS_MODULE;
|
|
|
|
video_set_drvdata(pdev->vdev, pdev);
|
|
|
|
|
|
|
|
pdev->release = le16_to_cpu(udev->descriptor.bcdDevice);
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_PROBE("Release: %04x\n", pdev->release);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Now search device_hint[] table for a match, so we can hint a node number. */
|
|
|
|
for (hint = 0; hint < MAX_DEV_HINTS; hint++) {
|
|
|
|
if (((device_hint[hint].type == -1) || (device_hint[hint].type == pdev->type)) &&
|
|
|
|
(device_hint[hint].pdev == NULL)) {
|
|
|
|
/* so far, so good... try serial number */
|
|
|
|
if ((device_hint[hint].serial_number[0] == '*') || !strcmp(device_hint[hint].serial_number, serial_number)) {
|
2006-06-20 03:30:57 +00:00
|
|
|
/* match! */
|
|
|
|
video_nr = device_hint[hint].device_node;
|
|
|
|
PWC_DEBUG_PROBE("Found hint, will try to register as /dev/video%d\n", video_nr);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev->vdev->release = video_device_release;
|
|
|
|
i = video_register_device(pdev->vdev, VFL_TYPE_GRABBER, video_nr);
|
|
|
|
if (i < 0) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Failed to register as video device (%d).\n", i);
|
2006-10-13 10:17:32 +00:00
|
|
|
rc = i;
|
|
|
|
goto err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Registered as /dev/video%d.\n", pdev->vdev->minor & 0x3F);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* occupy slot */
|
2006-03-25 12:19:53 +00:00
|
|
|
if (hint < MAX_DEV_HINTS)
|
2005-04-16 22:20:36 +00:00
|
|
|
device_hint[hint].pdev = pdev;
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_PROBE("probe() function returning struct at 0x%p.\n", pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_set_intfdata (intf, pdev);
|
2006-10-13 10:17:32 +00:00
|
|
|
rc = pwc_create_sysfs_files(pdev->vdev);
|
|
|
|
if (rc)
|
|
|
|
goto err_unreg;
|
2006-04-24 13:29:46 +00:00
|
|
|
|
|
|
|
/* Set the leds off */
|
|
|
|
pwc_set_leds(pdev, 0, 0);
|
|
|
|
pwc_camera_power(pdev, 0);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2006-10-13 10:17:32 +00:00
|
|
|
|
|
|
|
err_unreg:
|
|
|
|
if (hint < MAX_DEV_HINTS)
|
|
|
|
device_hint[hint].pdev = NULL;
|
|
|
|
video_unregister_device(pdev->vdev);
|
|
|
|
err:
|
|
|
|
video_device_release(pdev->vdev); /* Drip... drip... drip... */
|
|
|
|
kfree(pdev); /* Oops, no memory leaks please */
|
|
|
|
return rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The user janked out the cable... */
|
|
|
|
static void usb_pwc_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct pwc_device *pdev;
|
|
|
|
int hint;
|
|
|
|
|
|
|
|
lock_kernel();
|
|
|
|
pdev = usb_get_intfdata (intf);
|
|
|
|
usb_set_intfdata (intf, NULL);
|
|
|
|
if (pdev == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("pwc_disconnect() Called without private pointer.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto disconnect_out;
|
|
|
|
}
|
|
|
|
if (pdev->udev == NULL) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("pwc_disconnect() already called for %p\n", pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto disconnect_out;
|
|
|
|
}
|
|
|
|
if (pdev->udev != interface_to_usbdev(intf)) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("pwc_disconnect() Woops: pointer mismatch udev/pdev.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
goto disconnect_out;
|
|
|
|
}
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* We got unplugged; this is signalled by an EPIPE error code */
|
|
|
|
if (pdev->vopen) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Disconnected while webcam is in use!\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
pdev->error_status = EPIPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Alert waiting processes */
|
|
|
|
wake_up_interruptible(&pdev->frameq);
|
|
|
|
/* Wait until device is closed */
|
|
|
|
while (pdev->vopen)
|
|
|
|
schedule();
|
|
|
|
/* Device is now closed, so we can safely unregister it */
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_PROBE("Unregistering video device in disconnect().\n");
|
|
|
|
pwc_remove_sysfs_files(pdev->vdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
video_unregister_device(pdev->vdev);
|
|
|
|
|
|
|
|
/* Free memory (don't set pdev to 0 just yet) */
|
|
|
|
kfree(pdev);
|
|
|
|
|
|
|
|
disconnect_out:
|
|
|
|
/* search device_hint[] table if we occupy a slot, by any chance */
|
|
|
|
for (hint = 0; hint < MAX_DEV_HINTS; hint++)
|
|
|
|
if (device_hint[hint].pdev == pdev)
|
|
|
|
device_hint[hint].pdev = NULL;
|
|
|
|
|
|
|
|
unlock_kernel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* *grunt* We have to do atoi ourselves :-( */
|
|
|
|
static int pwc_atoi(const char *s)
|
|
|
|
{
|
|
|
|
int k = 0;
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
while (*s != '\0' && *s >= '0' && *s <= '9') {
|
|
|
|
k = 10 * k + (*s - '0');
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-25 12:19:53 +00:00
|
|
|
/*
|
|
|
|
* Initialization code & module stuff
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
static char *size;
|
|
|
|
static int fps;
|
|
|
|
static int fbufs;
|
|
|
|
static int mbufs;
|
2005-04-16 22:20:36 +00:00
|
|
|
static int compression = -1;
|
|
|
|
static int leds[2] = { -1, -1 };
|
2006-04-24 13:29:46 +00:00
|
|
|
static int leds_nargs;
|
|
|
|
static char *dev_hint[MAX_DEV_HINTS];
|
|
|
|
static int dev_hint_nargs;
|
|
|
|
|
|
|
|
module_param(size, charp, 0444);
|
|
|
|
module_param(fps, int, 0444);
|
|
|
|
module_param(fbufs, int, 0444);
|
|
|
|
module_param(mbufs, int, 0444);
|
2007-01-31 02:26:01 +00:00
|
|
|
#ifdef CONFIG_USB_PWC_DEBUG
|
2006-04-24 13:29:46 +00:00
|
|
|
module_param_named(trace, pwc_trace, int, 0644);
|
|
|
|
#endif
|
|
|
|
module_param(power_save, int, 0444);
|
|
|
|
module_param(compression, int, 0444);
|
|
|
|
module_param_array(leds, int, &leds_nargs, 0444);
|
|
|
|
module_param_array(dev_hint, charp, &dev_hint_nargs, 0444);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
MODULE_PARM_DESC(size, "Initial image size. One of sqcif, qsif, qcif, sif, cif, vga");
|
|
|
|
MODULE_PARM_DESC(fps, "Initial frames per second. Varies with model, useful range 5-30");
|
|
|
|
MODULE_PARM_DESC(fbufs, "Number of internal frame buffers to reserve");
|
|
|
|
MODULE_PARM_DESC(mbufs, "Number of external (mmap()ed) image buffers");
|
|
|
|
MODULE_PARM_DESC(trace, "For debugging purposes");
|
|
|
|
MODULE_PARM_DESC(power_save, "Turn power save feature in camera on or off");
|
|
|
|
MODULE_PARM_DESC(compression, "Preferred compression quality. Range 0 (uncompressed) to 3 (high compression)");
|
|
|
|
MODULE_PARM_DESC(leds, "LED on,off time in milliseconds");
|
|
|
|
MODULE_PARM_DESC(dev_hint, "Device node hints");
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Philips & OEM USB webcam driver");
|
|
|
|
MODULE_AUTHOR("Luc Saillard <luc@saillard.org>");
|
|
|
|
MODULE_LICENSE("GPL");
|
2006-04-24 13:29:46 +00:00
|
|
|
MODULE_ALIAS("pwcx");
|
|
|
|
MODULE_VERSION( PWC_VERSION );
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int __init usb_pwc_init(void)
|
|
|
|
{
|
|
|
|
int i, sz;
|
|
|
|
char *sizenames[PSZ_MAX] = { "sqcif", "qsif", "qcif", "sif", "cif", "vga" };
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips webcam module version " PWC_VERSION " loaded.\n");
|
|
|
|
PWC_INFO("Supports Philips PCA645/646, PCVC675/680/690, PCVC720[40]/730/740/750 & PCVC830/840.\n");
|
|
|
|
PWC_INFO("Also supports the Askey VC010, various Logitech Quickcams, Samsung MPC-C10 and MPC-C30,\n");
|
|
|
|
PWC_INFO("the Creative WebCam 5 & Pro Ex, SOTEC Afina Eye and Visionite VCS-UC300 and VCS-UM100.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (fps) {
|
|
|
|
if (fps < 4 || fps > 30) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Framerate out of bounds (4-30).\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
default_fps = fps;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Default framerate set to %d.\n", default_fps);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
if (size) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* string; try matching with array */
|
|
|
|
for (sz = 0; sz < PSZ_MAX; sz++) {
|
|
|
|
if (!strcmp(sizenames[sz], size)) { /* Found! */
|
|
|
|
default_size = sz;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sz == PSZ_MAX) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Size not recognized; try size=[sqcif | qsif | qcif | sif | cif | vga].\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Default image size set to %s [%dx%d].\n", sizenames[default_size], pwc_image_sizes[default_size].x, pwc_image_sizes[default_size].y);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (mbufs) {
|
|
|
|
if (mbufs < 1 || mbufs > MAX_IMAGES) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Illegal number of mmap() buffers; use a number between 1 and %d.\n", MAX_IMAGES);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
pwc_mbufs = mbufs;
|
|
|
|
PWC_DEBUG_MODULE("Number of image buffers set to %d.\n", pwc_mbufs);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (fbufs) {
|
|
|
|
if (fbufs < 2 || fbufs > MAX_FRAMES) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Illegal number of frame buffers; use a number between 2 and %d.\n", MAX_FRAMES);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
default_fbufs = fbufs;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Number of frame buffers set to %d.\n", default_fbufs);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-01-31 02:26:01 +00:00
|
|
|
#ifdef CONFIG_USB_PWC_DEBUG
|
2006-04-24 13:29:46 +00:00
|
|
|
if (pwc_trace >= 0) {
|
|
|
|
PWC_DEBUG_MODULE("Trace options: 0x%04x\n", pwc_trace);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
if (compression >= 0) {
|
|
|
|
if (compression > 3) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Invalid compression setting; use a number between 0 (uncompressed) and 3 (high).\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
pwc_preferred_compression = compression;
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Preferred compression set to %d.\n", pwc_preferred_compression);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (power_save)
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Enabling power save on open/close.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
if (leds[0] >= 0)
|
|
|
|
led_on = leds[0];
|
|
|
|
if (leds[1] >= 0)
|
|
|
|
led_off = leds[1];
|
|
|
|
|
2005-05-04 01:07:24 +00:00
|
|
|
/* Big device node whoopla. Basically, it allows you to assign a
|
2005-04-16 22:20:36 +00:00
|
|
|
device node (/dev/videoX) to a camera, based on its type
|
|
|
|
& serial number. The format is [type[.serialnumber]:]node.
|
|
|
|
|
|
|
|
Any camera that isn't matched by these rules gets the next
|
|
|
|
available free device node.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_DEV_HINTS; i++) {
|
|
|
|
char *s, *colon, *dot;
|
|
|
|
|
|
|
|
/* This loop also initializes the array */
|
|
|
|
device_hint[i].pdev = NULL;
|
|
|
|
s = dev_hint[i];
|
|
|
|
if (s != NULL && *s != '\0') {
|
|
|
|
device_hint[i].type = -1; /* wildcard */
|
|
|
|
strcpy(device_hint[i].serial_number, "*");
|
|
|
|
|
|
|
|
/* parse string: chop at ':' & '/' */
|
|
|
|
colon = dot = s;
|
|
|
|
while (*colon != '\0' && *colon != ':')
|
|
|
|
colon++;
|
|
|
|
while (*dot != '\0' && *dot != '.')
|
|
|
|
dot++;
|
|
|
|
/* Few sanity checks */
|
|
|
|
if (*dot != '\0' && dot > colon) {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Malformed camera hint: the colon must be after the dot.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*colon == '\0') {
|
|
|
|
/* No colon */
|
|
|
|
if (*dot != '\0') {
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_ERROR("Malformed camera hint: no colon + device node given.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* No type or serial number specified, just a number. */
|
|
|
|
device_hint[i].device_node = pwc_atoi(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* There's a colon, so we have at least a type and a device node */
|
|
|
|
device_hint[i].type = pwc_atoi(s);
|
|
|
|
device_hint[i].device_node = pwc_atoi(colon + 1);
|
|
|
|
if (*dot != '\0') {
|
|
|
|
/* There's a serial number as well */
|
|
|
|
int k;
|
2006-03-25 12:19:53 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
dot++;
|
|
|
|
k = 0;
|
|
|
|
while (*dot != ':' && k < 29) {
|
|
|
|
device_hint[i].serial_number[k++] = *dot;
|
|
|
|
dot++;
|
|
|
|
}
|
|
|
|
device_hint[i].serial_number[k] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_TRACE("device_hint[%d]:\n", i);
|
|
|
|
PWC_TRACE(" type : %d\n", device_hint[i].type);
|
|
|
|
PWC_TRACE(" serial# : %s\n", device_hint[i].serial_number);
|
|
|
|
PWC_TRACE(" node : %d\n", device_hint[i].device_node);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
device_hint[i].type = 0; /* not filled */
|
|
|
|
} /* ..for MAX_DEV_HINTS */
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_PROBE("Registering driver at address 0x%p.\n", &pwc_driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
return usb_register(&pwc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit usb_pwc_exit(void)
|
|
|
|
{
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_DEBUG_MODULE("Deregistering driver.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
usb_deregister(&pwc_driver);
|
2006-04-24 13:29:46 +00:00
|
|
|
PWC_INFO("Philips webcam module removed.\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(usb_pwc_init);
|
|
|
|
module_exit(usb_pwc_exit);
|
|
|
|
|
2006-04-24 13:29:46 +00:00
|
|
|
/* vim: set cino= formatoptions=croql cindent shiftwidth=8 tabstop=8: */
|