pwc-if.c 44.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/* Linux driver for Philips webcam
   USB and Video4Linux interface part.
   (C) 1999-2004 Nemosoft Unv.
4
   (C) 2004-2006 Luc Saillard (luc@saillard.org)
L
Linus Torvalds 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

   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

*/

28
/*
L
Linus Torvalds 已提交
29 30 31
   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
32
   is thus not distributed in source form. The binary pwcx.o module
L
Linus Torvalds 已提交
33
   contains the code that falls under the NDA.
34 35

   In case you're wondering: 'pwc' stands for "Philips WebCam", but
L
Linus Torvalds 已提交
36 37 38
   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).
39

L
Linus Torvalds 已提交
40 41 42
   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 *
43
   vdev: struct video_device (member of pwc_dev)
L
Linus Torvalds 已提交
44 45 46 47 48 49 50 51 52 53 54 55
   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
56
   - Pham Thanh Nam: webcam snapshot button as an event input device
L
Linus Torvalds 已提交
57 58 59 60 61 62 63 64
*/

#include <linux/errno.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/slab.h>
65 66 67
#ifdef CONFIG_USB_PWC_INPUT_EVDEV
#include <linux/usb/input.h>
#endif
L
Linus Torvalds 已提交
68 69
#include <linux/vmalloc.h>
#include <asm/io.h>
70
#include <linux/kernel.h>		/* simple_strtol() */
L
Linus Torvalds 已提交
71 72 73 74

#include "pwc.h"
#include "pwc-kiara.h"
#include "pwc-timon.h"
75 76
#include "pwc-dec23.h"
#include "pwc-dec1.h"
L
Linus Torvalds 已提交
77 78 79 80 81
#include "pwc-uncompress.h"

/* Function prototypes and driver templates */

/* hotplug device table support */
82
static const struct usb_device_id pwc_device_table [] = {
L
Linus Torvalds 已提交
83 84 85 86 87 88 89
	{ 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) },
90
	{ USB_DEVICE(0x0471, 0x0311) }, /* Philips ToUcam PRO II */
L
Linus Torvalds 已提交
91 92
	{ USB_DEVICE(0x0471, 0x0312) },
	{ USB_DEVICE(0x0471, 0x0313) }, /* the 'new' 720K */
93
	{ USB_DEVICE(0x0471, 0x0329) }, /* Philips SPC 900NC PC Camera */
L
Linus Torvalds 已提交
94 95 96 97 98 99 100
	{ 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 */
101 102
	{ USB_DEVICE(0x046D, 0x08B6) }, /* Cisco VT Camera */
	{ USB_DEVICE(0x046D, 0x08B7) }, /* Logitech ViewPort AV 100 */
L
Linus Torvalds 已提交
103
	{ USB_DEVICE(0x046D, 0x08B8) }, /* Logitech (reserved) */
104 105 106
	{ USB_DEVICE(0x055D, 0x9000) }, /* Samsung MPC-C10 */
	{ USB_DEVICE(0x055D, 0x9001) }, /* Samsung MPC-C30 */
	{ USB_DEVICE(0x055D, 0x9002) },	/* Samsung SNC-35E (Ver3.0) */
L
Linus Torvalds 已提交
107 108 109 110 111 112 113 114 115 116 117 118
	{ 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);
119
static void pwc_isoc_cleanup(struct pwc_device *pdev);
L
Linus Torvalds 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132

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;
133
#ifdef CONFIG_USB_PWC_DEBUG
134
	int pwc_trace = PWC_DEBUG_LEVEL;
135
#endif
136 137
static int power_save;
static int led_on = 100, led_off; /* defaults to LED that is on while in use */
138
static int pwc_preferred_compression = 1; /* 0..3 = uncompressed..high */
L
Linus Torvalds 已提交
139 140 141 142 143 144 145 146 147
static struct {
	int type;
	char serial_number[30];
	int device_node;
	struct pwc_device *pdev;
} device_hint[MAX_DEV_HINTS];

/***/

148 149
static int pwc_video_open(struct file *file);
static int pwc_video_close(struct file *file);
150
static ssize_t pwc_video_read(struct file *file, char __user *buf,
L
Linus Torvalds 已提交
151 152 153
			  size_t count, loff_t *ppos);
static unsigned int pwc_video_poll(struct file *file, poll_table *wait);
static int  pwc_video_mmap(struct file *file, struct vm_area_struct *vma);
154
static void pwc_video_release(struct video_device *vfd);
L
Linus Torvalds 已提交
155

156
static const struct v4l2_file_operations pwc_fops = {
L
Linus Torvalds 已提交
157 158 159 160 161 162
	.owner =	THIS_MODULE,
	.open =		pwc_video_open,
	.release =     	pwc_video_close,
	.read =		pwc_video_read,
	.poll =		pwc_video_poll,
	.mmap =		pwc_video_mmap,
163
	.unlocked_ioctl = video_ioctl2,
L
Linus Torvalds 已提交
164 165 166
};
static struct video_device pwc_template = {
	.name =		"Philips Webcam",	/* Filled in later */
167
	.release =	pwc_video_release,
L
Linus Torvalds 已提交
168
	.fops =         &pwc_fops,
169
	.ioctl_ops =	&pwc_ioctl_ops,
L
Linus Torvalds 已提交
170 171 172 173 174 175 176
};

/***************************************************************************/
/* Private functions */

static int pwc_allocate_buffers(struct pwc_device *pdev)
{
177
	int i, err;
L
Linus Torvalds 已提交
178 179
	void *kbuf;

180
	PWC_DEBUG_MEMORY(">> pwc_allocate_buffers(pdev = 0x%p)\n", pdev);
L
Linus Torvalds 已提交
181

182
	/* Allocate Isochronuous pipe buffers */
L
Linus Torvalds 已提交
183 184
	for (i = 0; i < MAX_ISO_BUFS; i++) {
		if (pdev->sbuf[i].data == NULL) {
185
			kbuf = kzalloc(ISO_BUFFER_SIZE, GFP_KERNEL);
L
Linus Torvalds 已提交
186
			if (kbuf == NULL) {
187
				PWC_ERROR("Failed to allocate iso buffer %d.\n", i);
L
Linus Torvalds 已提交
188 189
				return -ENOMEM;
			}
190
			PWC_DEBUG_MEMORY("Allocated iso buffer at %p.\n", kbuf);
L
Linus Torvalds 已提交
191 192 193 194 195
			pdev->sbuf[i].data = kbuf;
		}
	}

	/* Allocate decompressor table space */
196 197 198 199 200 201 202 203 204
	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;
	}
205

206
	PWC_DEBUG_MEMORY("<< pwc_allocate_buffers()\n");
L
Linus Torvalds 已提交
207 208 209 210 211 212 213
	return 0;
}

static void pwc_free_buffers(struct pwc_device *pdev)
{
	int i;

214
	PWC_DEBUG_MEMORY("Entering free_buffers(%p).\n", pdev);
L
Linus Torvalds 已提交
215 216 217 218

	/* Release Iso-pipe buffers */
	for (i = 0; i < MAX_ISO_BUFS; i++)
		if (pdev->sbuf[i].data != NULL) {
219
			PWC_DEBUG_MEMORY("Freeing ISO buffer at %p.\n", pdev->sbuf[i].data);
L
Linus Torvalds 已提交
220 221 222 223 224 225
			kfree(pdev->sbuf[i].data);
			pdev->sbuf[i].data = NULL;
		}

	/* Intermediate decompression buffer & tables */
	if (pdev->decompress_data != NULL) {
226
		PWC_DEBUG_MEMORY("Freeing decompression buffer at %p.\n", pdev->decompress_data);
L
Linus Torvalds 已提交
227 228 229 230
		kfree(pdev->decompress_data);
		pdev->decompress_data = NULL;
	}

231
	PWC_DEBUG_MEMORY("Leaving free_buffers().\n");
L
Linus Torvalds 已提交
232 233
}

234
struct pwc_frame_buf *pwc_get_next_fill_buf(struct pwc_device *pdev)
L
Linus Torvalds 已提交
235
{
236 237 238 239 240 241 242 243 244 245 246 247
	unsigned long flags = 0;
	struct pwc_frame_buf *buf = NULL;

	spin_lock_irqsave(&pdev->queued_bufs_lock, flags);
	if (list_empty(&pdev->queued_bufs))
		goto leave;

	buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, list);
	list_del(&buf->list);
leave:
	spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
	return buf;
248 249
}

250 251 252 253 254 255 256 257 258 259 260
static void pwc_snapshot_button(struct pwc_device *pdev, int down)
{
	if (down) {
		PWC_TRACE("Snapshot button pressed.\n");
		pdev->snapshot_button_status = 1;
	} else {
		PWC_TRACE("Snapshot button released.\n");
	}

#ifdef CONFIG_USB_PWC_INPUT_EVDEV
	if (pdev->button_dev) {
261
		input_report_key(pdev->button_dev, KEY_CAMERA, down);
262 263 264 265 266
		input_sync(pdev->button_dev);
	}
#endif
}

267
static void pwc_frame_complete(struct pwc_device *pdev)
268
{
269
	struct pwc_frame_buf *fbuf = pdev->fill_buf;
270 271 272 273 274 275 276 277 278 279 280 281 282

	/* 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;
		}
		if ((ptr[0] ^ pdev->vmirror) & 0x01) {
283
			pwc_snapshot_button(pdev, ptr[0] & 0x01);
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
		}
		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++;
303
	} else if (pdev->type == 740 || pdev->type == 720) {
304 305
		unsigned char *ptr = (unsigned char *)fbuf->data;
		if ((ptr[0] ^ pdev->vmirror) & 0x01) {
306
			pwc_snapshot_button(pdev, ptr[0] & 0x01);
307 308 309 310
		}
		pdev->vmirror = ptr[0] & 0x03;
	}

311 312
	/* In case we were instructed to drop the frame, do so silently. */
	if (pdev->drop_frames > 0) {
313
		pdev->drop_frames--;
314
	} else {
315 316 317 318
		/* Check for underflow first */
		if (fbuf->filled < pdev->frame_total_size) {
			PWC_DEBUG_FLOW("Frame buffer underflow (%d bytes);"
				       " discarded.\n", fbuf->filled);
319 320 321 322 323 324
		} else {
			fbuf->vb.v4l2_buf.field = V4L2_FIELD_NONE;
			fbuf->vb.v4l2_buf.sequence = pdev->vframe_count;
			vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
			pdev->fill_buf = NULL;
			pdev->vsync = 0;
325 326 327 328
		}
	} /* !drop_frames */
	pdev->vframe_count++;
}
L
Linus Torvalds 已提交
329 330 331 332

/* 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.
 */
333
static void pwc_isoc_handler(struct urb *urb)
L
Linus Torvalds 已提交
334
{
335
	struct pwc_device *pdev = (struct pwc_device *)urb->context;
L
Linus Torvalds 已提交
336
	int i, fst, flen;
337
	unsigned char *iso_buf = NULL;
L
Linus Torvalds 已提交
338

339 340
	if (urb->status == -ENOENT || urb->status == -ECONNRESET ||
	    urb->status == -ESHUTDOWN) {
341
		PWC_DEBUG_OPEN("URB (%p) unlinked %ssynchronuously.\n", urb, urb->status == -ENOENT ? "" : "a");
L
Linus Torvalds 已提交
342 343
		return;
	}
344 345 346 347 348

	if (pdev->fill_buf == NULL)
		pdev->fill_buf = pwc_get_next_fill_buf(pdev);

	if (urb->status != 0) {
L
Linus Torvalds 已提交
349 350 351 352 353 354 355 356 357
		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;
358
			case -ETIME:		errmsg = "Device does not respond"; break;
L
Linus Torvalds 已提交
359
		}
360 361 362
		PWC_ERROR("pwc_isoc_handler() called with status %d [%s].\n",
			  urb->status, errmsg);
		/* Give up after a number of contiguous errors */
L
Linus Torvalds 已提交
363 364
		if (++pdev->visoc_errors > MAX_ISOC_ERRORS)
		{
365 366 367 368 369 370
			PWC_ERROR("Too many ISOC errors, bailing out.\n");
			if (pdev->fill_buf) {
				vb2_buffer_done(&pdev->fill_buf->vb,
						VB2_BUF_STATE_ERROR);
				pdev->fill_buf = NULL;
			}
L
Linus Torvalds 已提交
371
		}
372
		pdev->vsync = 0; /* Drop the current frame */
L
Linus Torvalds 已提交
373 374 375 376 377 378 379
		goto handler_end;
	}

	/* Reset ISOC error counter. We did get here, after all. */
	pdev->visoc_errors = 0;

	/* vsync: 0 = don't copy data
380 381
		  1 = sync-hunt
		  2 = synched
L
Linus Torvalds 已提交
382 383 384 385 386 387
	 */
	/* 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;
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
		if (fst != 0) {
			PWC_ERROR("Iso frame %d has error %d\n", i, fst);
			continue;
		}
		if (flen > 0 && pdev->vsync) {
			struct pwc_frame_buf *fbuf = pdev->fill_buf;

			if (pdev->vsync == 1) {
				do_gettimeofday(&fbuf->vb.v4l2_buf.timestamp);
				pdev->vsync = 2;
			}

			if (flen + fbuf->filled > pdev->frame_total_size) {
				PWC_ERROR("Frame overflow (%d > %d)\n",
					  flen + fbuf->filled,
					  pdev->frame_total_size);
				pdev->vsync = 0; /* Let's wait for an EOF */
			} else {
				memcpy(fbuf->data + fbuf->filled, iso_buf,
				       flen);
L
Linus Torvalds 已提交
408
				fbuf->filled += flen;
409 410 411 412 413 414 415 416 417 418
			}
		}
		if (flen < pdev->vlast_packet_size) {
			/* Shorter packet... end of frame */
			if (pdev->vsync == 2)
				pwc_frame_complete(pdev);
			if (pdev->fill_buf == NULL)
				pdev->fill_buf = pwc_get_next_fill_buf(pdev);
			if (pdev->fill_buf) {
				pdev->fill_buf->filled = 0;
L
Linus Torvalds 已提交
419
				pdev->vsync = 1;
420
			}
L
Linus Torvalds 已提交
421
		}
422
		pdev->vlast_packet_size = flen;
L
Linus Torvalds 已提交
423 424 425 426 427
	}

handler_end:
	i = usb_submit_urb(urb, GFP_ATOMIC);
	if (i != 0)
428
		PWC_ERROR("Error (%d) re-submitting urb in pwc_isoc_handler.\n", i);
L
Linus Torvalds 已提交
429 430
}

431
static int pwc_isoc_init(struct pwc_device *pdev)
L
Linus Torvalds 已提交
432 433 434 435 436 437 438 439 440 441
{
	struct usb_device *udev;
	struct urb *urb;
	int i, j, ret;
	struct usb_interface *intf;
	struct usb_host_interface *idesc = NULL;

	if (pdev->iso_init)
		return 0;
	pdev->vsync = 0;
442 443
	pdev->fill_buf = NULL;
	pdev->vframe_count = 0;
L
Linus Torvalds 已提交
444 445 446 447 448 449 450
	udev = pdev->udev;

	/* Get the current alternate interface, adjust packet size */
	intf = usb_ifnum_to_if(udev, 0);
	if (intf)
		idesc = usb_altnum_to_altsetting(intf, pdev->valternate);
	if (!idesc)
451
		return -EIO;
L
Linus Torvalds 已提交
452 453 454

	/* Search video endpoint */
	pdev->vmax_packet_size = -1;
455
	for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
L
Linus Torvalds 已提交
456 457 458 459
		if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->vendpoint) {
			pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize);
			break;
		}
460
	}
461

L
Linus Torvalds 已提交
462
	if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) {
463
		PWC_ERROR("Failed to find packet size for video endpoint in current alternate setting.\n");
464
		return -ENFILE; /* Odd error, that should be noticeable */
L
Linus Torvalds 已提交
465 466 467 468
	}

	/* Set alternate interface */
	ret = 0;
469
	PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate);
L
Linus Torvalds 已提交
470 471 472 473 474 475 476
	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) {
477
			PWC_ERROR("Failed to allocate urb %d\n", i);
L
Linus Torvalds 已提交
478 479 480 481
			ret = -ENOMEM;
			break;
		}
		pdev->sbuf[i].urb = urb;
482
		PWC_DEBUG_MEMORY("Allocated URB at 0x%p\n", urb);
L
Linus Torvalds 已提交
483 484 485
	}
	if (ret) {
		/* De-allocate in reverse order */
M
Mariusz Kozlowski 已提交
486
		while (i--) {
M
Mariusz Kozlowski 已提交
487
			usb_free_urb(pdev->sbuf[i].urb);
L
Linus Torvalds 已提交
488 489 490 491 492
			pdev->sbuf[i].urb = NULL;
		}
		return ret;
	}

493
	/* init URB structure */
L
Linus Torvalds 已提交
494 495 496 497 498
	for (i = 0; i < MAX_ISO_BUFS; i++) {
		urb = pdev->sbuf[i].urb;

		urb->interval = 1; // devik
		urb->dev = udev;
499
		urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint);
L
Linus Torvalds 已提交
500
		urb->transfer_flags = URB_ISO_ASAP;
501 502 503 504
		urb->transfer_buffer = pdev->sbuf[i].data;
		urb->transfer_buffer_length = ISO_BUFFER_SIZE;
		urb->complete = pwc_isoc_handler;
		urb->context = pdev;
L
Linus Torvalds 已提交
505 506 507 508 509 510 511 512 513 514 515
		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);
516
		if (ret) {
517
			PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret);
518 519 520 521 522
			pdev->iso_init = 1;
			pwc_isoc_cleanup(pdev);
			return ret;
		}
		PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->sbuf[i].urb);
L
Linus Torvalds 已提交
523 524 525 526
	}

	/* All is done... */
	pdev->iso_init = 1;
527
	PWC_DEBUG_OPEN("<< pwc_isoc_init()\n");
L
Linus Torvalds 已提交
528 529 530
	return 0;
}

531
static void pwc_iso_stop(struct pwc_device *pdev)
L
Linus Torvalds 已提交
532 533 534 535 536 537 538 539
{
	int i;

	/* Unlinking ISOC buffers one by one */
	for (i = 0; i < MAX_ISO_BUFS; i++) {
		struct urb *urb;

		urb = pdev->sbuf[i].urb;
A
Al Viro 已提交
540
		if (urb) {
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
			PWC_DEBUG_MEMORY("Unlinking URB %p\n", urb);
			usb_kill_urb(urb);
		}
	}
}

static void pwc_iso_free(struct pwc_device *pdev)
{
	int i;

	/* Freeing ISOC buffers one by one */
	for (i = 0; i < MAX_ISO_BUFS; i++) {
		struct urb *urb;

		urb = pdev->sbuf[i].urb;
A
Al Viro 已提交
556
		if (urb) {
557
			PWC_DEBUG_MEMORY("Freeing URB\n");
L
Linus Torvalds 已提交
558 559 560 561
			usb_free_urb(urb);
			pdev->sbuf[i].urb = NULL;
		}
	}
562 563
}

564
static void pwc_isoc_cleanup(struct pwc_device *pdev)
565 566
{
	PWC_DEBUG_OPEN(">> pwc_isoc_cleanup()\n");
567

568 569 570 571 572
	if (pdev->iso_init == 0)
		return;

	pwc_iso_stop(pdev);
	pwc_iso_free(pdev);
L
Linus Torvalds 已提交
573 574

	/* Stop camera, but only if we are sure the camera is still there (unplug
575
	   is signalled by EPIPE)
L
Linus Torvalds 已提交
576
	 */
577
	if (pdev->error_status != EPIPE) {
578
		PWC_DEBUG_OPEN("Setting alternate interface 0.\n");
L
Linus Torvalds 已提交
579 580 581 582
		usb_set_interface(pdev->udev, 0, 0);
	}

	pdev->iso_init = 0;
583
	PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n");
L
Linus Torvalds 已提交
584 585
}

586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
/*
 * Release all queued buffers, no need to take queued_bufs_lock, since all
 * iso urbs have been killed when we're called so pwc_isoc_handler won't run.
 */
static void pwc_cleanup_queued_bufs(struct pwc_device *pdev)
{
	while (!list_empty(&pdev->queued_bufs)) {
		struct pwc_frame_buf *buf;

		buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf,
				 list);
		list_del(&buf->list);
		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
	}
}

602 603 604
/*********
 * sysfs
 *********/
605
static struct pwc_device *cd_to_pwc(struct device *cd)
606 607 608 609 610
{
	struct video_device *vdev = to_video_device(cd);
	return video_get_drvdata(vdev);
}

611 612
static ssize_t show_pan_tilt(struct device *class_dev,
			     struct device_attribute *attr, char *buf)
613 614 615 616 617
{
	struct pwc_device *pdev = cd_to_pwc(class_dev);
	return sprintf(buf, "%d %d\n", pdev->pan_angle, pdev->tilt_angle);
}

618 619 620
static ssize_t store_pan_tilt(struct device *class_dev,
			      struct device_attribute *attr,
			      const char *buf, size_t count)
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
{
	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);
}
636 637
static DEVICE_ATTR(pan_tilt, S_IRUGO | S_IWUSR, show_pan_tilt,
		   store_pan_tilt);
638

639 640
static ssize_t show_snapshot_button_status(struct device *class_dev,
					   struct device_attribute *attr, char *buf)
641 642 643 644 645 646 647
{
	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);
}

648 649
static DEVICE_ATTR(button, S_IRUGO | S_IWUSR, show_snapshot_button_status,
		   NULL);
650

651
static int pwc_create_sysfs_files(struct pwc_device *pdev)
652
{
653 654
	int rc;

655
	rc = device_create_file(&pdev->vdev.dev, &dev_attr_button);
656 657 658
	if (rc)
		goto err;
	if (pdev->features & FEATURE_MOTOR_PANTILT) {
659
		rc = device_create_file(&pdev->vdev.dev, &dev_attr_pan_tilt);
660 661
		if (rc)
			goto err_button;
662 663 664 665 666
	}

	return 0;

err_button:
667
	device_remove_file(&pdev->vdev.dev, &dev_attr_button);
668
err:
669
	PWC_ERROR("Could not create sysfs files.\n");
670
	return rc;
671 672
}

673
static void pwc_remove_sysfs_files(struct pwc_device *pdev)
674 675
{
	if (pdev->features & FEATURE_MOTOR_PANTILT)
676 677
		device_remove_file(&pdev->vdev.dev, &dev_attr_pan_tilt);
	device_remove_file(&pdev->vdev.dev, &dev_attr_button);
678 679
}

680
#ifdef CONFIG_USB_PWC_DEBUG
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
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:
705
			return "unknown type of sensor";
706 707 708
	}
}
#endif
L
Linus Torvalds 已提交
709 710 711 712

/***************************************************************************/
/* Video4Linux functions */

713
static int pwc_video_open(struct file *file)
L
Linus Torvalds 已提交
714
{
715
	int i, ret;
L
Linus Torvalds 已提交
716 717 718
	struct video_device *vdev = video_devdata(file);
	struct pwc_device *pdev;

719
	PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev);
720

721
	pdev = video_get_drvdata(vdev);
722 723
	if (pdev->vopen) {
		PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n");
L
Linus Torvalds 已提交
724
		return -EBUSY;
725
	}
726

727
	pwc_construct(pdev); /* set min/max sizes correct */
L
Linus Torvalds 已提交
728
	if (!pdev->usb_init) {
729
		PWC_DEBUG_OPEN("Doing first time initialization.\n");
L
Linus Torvalds 已提交
730
		pdev->usb_init = 1;
731

732 733 734
		/* Query sensor type */
		ret = pwc_get_cmos_sensor(pdev, &i);
		if (ret >= 0)
L
Linus Torvalds 已提交
735
		{
736
			PWC_DEBUG_OPEN("This %s camera is equipped with a %s (%d).\n",
737
					pdev->vdev.name,
738
					pwc_sensor_type_to_string(i), i);
L
Linus Torvalds 已提交
739 740 741 742 743 744 745
		}
	}

	/* Turn on camera */
	if (power_save) {
		i = pwc_camera_power(pdev, 1);
		if (i < 0)
746
			PWC_DEBUG_OPEN("Failed to restore power to the camera! (%d)\n", i);
L
Linus Torvalds 已提交
747 748 749
	}
	/* Set LED on/off time */
	if (pwc_set_leds(pdev, led_on, led_off) < 0)
750
		PWC_DEBUG_OPEN("Failed to set LED on/off time.\n");
751

L
Linus Torvalds 已提交
752 753 754 755

	/* So far, so good. Allocate memory. */
	i = pwc_allocate_buffers(pdev);
	if (i < 0) {
756 757
		PWC_DEBUG_OPEN("Failed to allocate buffers memory.\n");
		pwc_free_buffers(pdev);
L
Linus Torvalds 已提交
758 759
		return i;
	}
760

L
Linus Torvalds 已提交
761 762 763 764 765 766 767 768
	/* Reset buffers & parameters */
	pdev->visoc_errors = 0;
	pdev->error_status = 0;
	pwc_construct(pdev); /* set min/max sizes correct */

	/* Set some defaults */
	pdev->vsnapshot = 0;

769
	/* Set video size, first try the last used video size
L
Linus Torvalds 已提交
770 771 772 773 774
	   (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)	{
775 776 777 778
		unsigned int default_resolution;
		PWC_DEBUG_OPEN("First attempt at set_video_mode failed.\n");
		if (pdev->type>= 730)
			default_resolution = PSZ_QSIF;
L
Linus Torvalds 已提交
779
		else
780 781 782 783 784 785 786 787
			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);
L
Linus Torvalds 已提交
788 789
	}
	if (i) {
790 791
		PWC_DEBUG_OPEN("Second attempt at set_video_mode failed.\n");
		pwc_free_buffers(pdev);
L
Linus Torvalds 已提交
792 793
		return i;
	}
794

795 796 797 798
	/* Initialize the webcam to sane value */
	pwc_set_brightness(pdev, 0x7fff);
	pwc_set_agc(pdev, 1, 0);

L
Linus Torvalds 已提交
799 800
	pdev->vopen++;
	file->private_data = vdev;
801
	PWC_DEBUG_OPEN("<< video_open() returns 0.\n");
L
Linus Torvalds 已提交
802 803 804
	return 0;
}

805
static void pwc_video_release(struct video_device *vfd)
806
{
807 808
	struct pwc_device *pdev = container_of(vfd, struct pwc_device, vdev);
	int hint;
809

810 811 812 813
	/* 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;
814 815

	kfree(pdev);
816 817
}

L
Linus Torvalds 已提交
818
/* Note that all cleanup is done in the reverse order as in _open */
819
static int pwc_video_close(struct file *file)
L
Linus Torvalds 已提交
820 821 822
{
	struct video_device *vdev = file->private_data;
	struct pwc_device *pdev;
823
	int i;
L
Linus Torvalds 已提交
824

825
	PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev);
L
Linus Torvalds 已提交
826

827
	pdev = video_get_drvdata(vdev);
L
Linus Torvalds 已提交
828
	if (pdev->vopen == 0)
829
		PWC_DEBUG_MODULE("video_close() called on closed device?\n");
L
Linus Torvalds 已提交
830

831 832 833 834
	if (DEVICE_USE_CODEC1(pdev->type))
	    pwc_dec1_exit();
	else
	    pwc_dec23_exit();
L
Linus Torvalds 已提交
835

836
	vb2_queue_release(&pdev->vb_queue);
L
Linus Torvalds 已提交
837 838 839
	pwc_free_buffers(pdev);

	/* Turn off LEDS and power down camera, but only when not unplugged */
840
	if (!pdev->unplugged) {
L
Linus Torvalds 已提交
841 842
		/* Turn LEDs off */
		if (pwc_set_leds(pdev, 0, 0) < 0)
843
			PWC_DEBUG_MODULE("Failed to set LED on/off time.\n");
L
Linus Torvalds 已提交
844 845 846
		if (power_save) {
			i = pwc_camera_power(pdev, 0);
			if (i < 0)
847
				PWC_ERROR("Failed to power down camera (%d)\n", i);
L
Linus Torvalds 已提交
848
		}
849
		pdev->vopen--;
850
		PWC_DEBUG_OPEN("<< video_close() vopen=%d\n", pdev->vopen);
L
Linus Torvalds 已提交
851
	}
852

L
Linus Torvalds 已提交
853 854 855
	return 0;
}

856
static ssize_t pwc_video_read(struct file *file, char __user *buf,
857
			      size_t count, loff_t *ppos)
L
Linus Torvalds 已提交
858 859
{
	struct video_device *vdev = file->private_data;
860
	struct pwc_device *pdev = video_get_drvdata(vdev);
L
Linus Torvalds 已提交
861

862 863
	if (pdev->error_status)
		return -pdev->error_status;
864

865 866 867
	return vb2_read(&pdev->vb_queue, buf, count, ppos,
			file->f_flags & O_NONBLOCK);
}
L
Linus Torvalds 已提交
868

869 870 871 872
static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
{
	struct video_device *vdev = file->private_data;
	struct pwc_device *pdev = video_get_drvdata(vdev);
873

874 875
	if (pdev->error_status)
		return POLL_ERR;
L
Linus Torvalds 已提交
876

877
	return vb2_poll(&pdev->vb_queue, file, wait);
L
Linus Torvalds 已提交
878 879
}

880
static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
L
Linus Torvalds 已提交
881 882
{
	struct video_device *vdev = file->private_data;
883
	struct pwc_device *pdev = video_get_drvdata(vdev);
L
Linus Torvalds 已提交
884

885 886
	return vb2_mmap(&pdev->vb_queue, vma);
}
L
Linus Torvalds 已提交
887

888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
/***************************************************************************/
/* Videobuf2 operations */

static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
				unsigned int *nplanes, unsigned long sizes[],
				void *alloc_ctxs[])
{
	struct pwc_device *pdev = vb2_get_drv_priv(vq);

	if (*nbuffers < MIN_FRAMES)
		*nbuffers = MIN_FRAMES;
	else if (*nbuffers > MAX_FRAMES)
		*nbuffers = MAX_FRAMES;

	*nplanes = 1;

	sizes[0] = PAGE_ALIGN((pdev->abs_max.x * pdev->abs_max.y * 3) / 2);

	return 0;
}

static int buffer_init(struct vb2_buffer *vb)
{
	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
912

913 914 915 916 917 918 919 920 921 922 923 924 925
	/* need vmalloc since frame buffer > 128K */
	buf->data = vzalloc(PWC_FRAME_SIZE);
	if (buf->data == NULL)
		return -ENOMEM;

	return 0;
}

static int buffer_prepare(struct vb2_buffer *vb)
{
	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);

	/* Don't allow queing new buffers after device disconnection */
L
Linus Torvalds 已提交
926
	if (pdev->error_status)
927
		return -pdev->error_status;
L
Linus Torvalds 已提交
928 929 930 931

	return 0;
}

932
static int buffer_finish(struct vb2_buffer *vb)
L
Linus Torvalds 已提交
933
{
934 935
	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
936

937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
	/*
	 * Application has called dqbuf and is getting back a buffer we've
	 * filled, take the pwc data we've stored in buf->data and decompress
	 * it into a usable format, storing the result in the vb2_buffer
	 */
	return pwc_decompress(pdev, buf);
}

static void buffer_cleanup(struct vb2_buffer *vb)
{
	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);

	vfree(buf->data);
}

static void buffer_queue(struct vb2_buffer *vb)
{
	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
	unsigned long flags = 0;

	spin_lock_irqsave(&pdev->queued_bufs_lock, flags);
	list_add_tail(&buf->list, &pdev->queued_bufs);
	spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
}

static int start_streaming(struct vb2_queue *vq)
{
	struct pwc_device *pdev = vb2_get_drv_priv(vq);

	return pwc_isoc_init(pdev);
}

static int stop_streaming(struct vb2_queue *vq)
{
	struct pwc_device *pdev = vb2_get_drv_priv(vq);

	pwc_isoc_cleanup(pdev);
	pwc_cleanup_queued_bufs(pdev);
976

L
Linus Torvalds 已提交
977 978 979
	return 0;
}

980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
static void pwc_lock(struct vb2_queue *vq)
{
	struct pwc_device *pdev = vb2_get_drv_priv(vq);
	mutex_lock(&pdev->modlock);
}

static void pwc_unlock(struct vb2_queue *vq)
{
	struct pwc_device *pdev = vb2_get_drv_priv(vq);
	mutex_unlock(&pdev->modlock);
}

static struct vb2_ops pwc_vb_queue_ops = {
	.queue_setup		= queue_setup,
	.buf_init		= buffer_init,
	.buf_prepare		= buffer_prepare,
	.buf_finish		= buffer_finish,
	.buf_cleanup		= buffer_cleanup,
	.buf_queue		= buffer_queue,
	.start_streaming	= start_streaming,
	.stop_streaming		= stop_streaming,
	.wait_prepare		= pwc_unlock,
	.wait_finish		= pwc_lock,
};

L
Linus Torvalds 已提交
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
/***************************************************************************/
/* 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;
1017
	int hint, rc;
L
Linus Torvalds 已提交
1018 1019 1020 1021
	int features = 0;
	int video_nr = -1; /* default: use next available device */
	char serial_number[30], *name;

1022 1023 1024
	vendor_id = le16_to_cpu(udev->descriptor.idVendor);
	product_id = le16_to_cpu(udev->descriptor.idProduct);

L
Linus Torvalds 已提交
1025
	/* Check if we can handle this device */
1026 1027
	PWC_DEBUG_PROBE("probe() called [%04X %04X], if %d\n",
		vendor_id, product_id,
L
Linus Torvalds 已提交
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
		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:
1040
			PWC_INFO("Philips PCA645VC USB webcam detected.\n");
L
Linus Torvalds 已提交
1041 1042 1043 1044
			name = "Philips 645 webcam";
			type_id = 645;
			break;
		case 0x0303:
1045
			PWC_INFO("Philips PCA646VC USB webcam detected.\n");
L
Linus Torvalds 已提交
1046 1047 1048 1049
			name = "Philips 646 webcam";
			type_id = 646;
			break;
		case 0x0304:
1050
			PWC_INFO("Askey VC010 type 2 USB webcam detected.\n");
L
Linus Torvalds 已提交
1051 1052 1053 1054
			name = "Askey VC010 webcam";
			type_id = 646;
			break;
		case 0x0307:
1055
			PWC_INFO("Philips PCVC675K (Vesta) USB webcam detected.\n");
L
Linus Torvalds 已提交
1056 1057 1058 1059
			name = "Philips 675 webcam";
			type_id = 675;
			break;
		case 0x0308:
1060
			PWC_INFO("Philips PCVC680K (Vesta Pro) USB webcam detected.\n");
L
Linus Torvalds 已提交
1061 1062 1063 1064
			name = "Philips 680 webcam";
			type_id = 680;
			break;
		case 0x030C:
1065
			PWC_INFO("Philips PCVC690K (Vesta Pro Scan) USB webcam detected.\n");
L
Linus Torvalds 已提交
1066 1067 1068 1069
			name = "Philips 690 webcam";
			type_id = 690;
			break;
		case 0x0310:
1070
			PWC_INFO("Philips PCVC730K (ToUCam Fun)/PCVC830 (ToUCam II) USB webcam detected.\n");
L
Linus Torvalds 已提交
1071 1072 1073 1074
			name = "Philips 730 webcam";
			type_id = 730;
			break;
		case 0x0311:
1075
			PWC_INFO("Philips PCVC740K (ToUCam Pro)/PCVC840 (ToUCam II) USB webcam detected.\n");
L
Linus Torvalds 已提交
1076 1077 1078 1079
			name = "Philips 740 webcam";
			type_id = 740;
			break;
		case 0x0312:
1080
			PWC_INFO("Philips PCVC750K (ToUCam Pro Scan) USB webcam detected.\n");
L
Linus Torvalds 已提交
1081 1082 1083 1084
			name = "Philips 750 webcam";
			type_id = 750;
			break;
		case 0x0313:
1085
			PWC_INFO("Philips PCVC720K/40 (ToUCam XS) USB webcam detected.\n");
L
Linus Torvalds 已提交
1086 1087 1088
			name = "Philips 720K/40 webcam";
			type_id = 720;
			break;
1089 1090 1091
		case 0x0329:
			PWC_INFO("Philips SPC 900NC USB webcam detected.\n");
			name = "Philips SPC 900NC webcam";
1092
			type_id = 740;
1093
			break;
L
Linus Torvalds 已提交
1094 1095 1096 1097 1098 1099 1100 1101
		default:
			return -ENODEV;
			break;
		}
	}
	else if (vendor_id == 0x069A) {
		switch(product_id) {
		case 0x0001:
1102
			PWC_INFO("Askey VC010 type 1 USB webcam detected.\n");
L
Linus Torvalds 已提交
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
			name = "Askey VC010 webcam";
			type_id = 645;
			break;
		default:
			return -ENODEV;
			break;
		}
	}
	else if (vendor_id == 0x046d) {
		switch(product_id) {
		case 0x08b0:
1114
			PWC_INFO("Logitech QuickCam Pro 3000 USB webcam detected.\n");
L
Linus Torvalds 已提交
1115 1116 1117 1118
			name = "Logitech QuickCam Pro 3000";
			type_id = 740; /* CCD sensor */
			break;
		case 0x08b1:
1119
			PWC_INFO("Logitech QuickCam Notebook Pro USB webcam detected.\n");
L
Linus Torvalds 已提交
1120 1121 1122 1123
			name = "Logitech QuickCam Notebook Pro";
			type_id = 740; /* CCD sensor */
			break;
		case 0x08b2:
1124
			PWC_INFO("Logitech QuickCam 4000 Pro USB webcam detected.\n");
L
Linus Torvalds 已提交
1125 1126 1127 1128
			name = "Logitech QuickCam Pro 4000";
			type_id = 740; /* CCD sensor */
			break;
		case 0x08b3:
1129
			PWC_INFO("Logitech QuickCam Zoom USB webcam detected.\n");
L
Linus Torvalds 已提交
1130 1131 1132 1133
			name = "Logitech QuickCam Zoom";
			type_id = 740; /* CCD sensor */
			break;
		case 0x08B4:
1134
			PWC_INFO("Logitech QuickCam Zoom (new model) USB webcam detected.\n");
L
Linus Torvalds 已提交
1135 1136
			name = "Logitech QuickCam Zoom";
			type_id = 740; /* CCD sensor */
1137
			power_save = 1;
L
Linus Torvalds 已提交
1138 1139
			break;
		case 0x08b5:
1140
			PWC_INFO("Logitech QuickCam Orbit/Sphere USB webcam detected.\n");
L
Linus Torvalds 已提交
1141 1142 1143 1144 1145
			name = "Logitech QuickCam Orbit";
			type_id = 740; /* CCD sensor */
			features |= FEATURE_MOTOR_PANTILT;
			break;
		case 0x08b6:
1146 1147 1148 1149
			PWC_INFO("Logitech/Cisco VT Camera webcam detected.\n");
			name = "Cisco VT Camera";
			type_id = 740; /* CCD sensor */
			break;
L
Linus Torvalds 已提交
1150
		case 0x08b7:
1151 1152 1153 1154 1155
			PWC_INFO("Logitech ViewPort AV 100 webcam detected.\n");
			name = "Logitech ViewPort AV 100";
			type_id = 740; /* CCD sensor */
			break;
		case 0x08b8: /* Where this released? */
1156
			PWC_INFO("Logitech QuickCam detected (reserved ID).\n");
L
Linus Torvalds 已提交
1157 1158 1159
			name = "Logitech QuickCam (res.)";
			type_id = 730; /* Assuming CMOS */
			break;
1160
		default:
L
Linus Torvalds 已提交
1161
			return -ENODEV;
1162 1163 1164
			break;
		}
	}
L
Linus Torvalds 已提交
1165 1166 1167 1168 1169 1170 1171
	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:
1172
			PWC_INFO("Samsung MPC-C10 USB webcam detected.\n");
L
Linus Torvalds 已提交
1173 1174 1175 1176
			name = "Samsung MPC-C10";
			type_id = 675;
			break;
		case 0x9001:
1177
			PWC_INFO("Samsung MPC-C30 USB webcam detected.\n");
L
Linus Torvalds 已提交
1178 1179 1180
			name = "Samsung MPC-C30";
			type_id = 675;
			break;
1181 1182 1183 1184 1185
		case 0x9002:
			PWC_INFO("Samsung SNC-35E (v3.0) USB webcam detected.\n");
			name = "Samsung MPC-C30";
			type_id = 740;
			break;
L
Linus Torvalds 已提交
1186 1187 1188 1189 1190 1191 1192 1193
		default:
			return -ENODEV;
			break;
		}
	}
	else if (vendor_id == 0x041e) {
		switch(product_id) {
		case 0x400c:
1194
			PWC_INFO("Creative Labs Webcam 5 detected.\n");
L
Linus Torvalds 已提交
1195 1196 1197 1198
			name = "Creative Labs Webcam 5";
			type_id = 730;
			break;
		case 0x4011:
1199
			PWC_INFO("Creative Labs Webcam Pro Ex detected.\n");
L
Linus Torvalds 已提交
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
			name = "Creative Labs Webcam Pro Ex";
			type_id = 740;
			break;
		default:
			return -ENODEV;
			break;
		}
	}
	else if (vendor_id == 0x04cc) {
		switch(product_id) {
		case 0x8116:
1211
			PWC_INFO("Sotec Afina Eye USB webcam detected.\n");
L
Linus Torvalds 已提交
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
			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 */
1224
			PWC_INFO("AME Co. Afina Eye USB webcam detected.\n");
L
Linus Torvalds 已提交
1225 1226 1227 1228 1229 1230 1231
			name = "AME Co. Afina Eye";
			type_id = 750;
			break;
		default:
			return -ENODEV;
			break;
		}
1232

L
Linus Torvalds 已提交
1233 1234 1235 1236
	}
	else if (vendor_id == 0x0d81) {
		switch(product_id) {
		case 0x1900:
1237
			PWC_INFO("Visionite VCS-UC300 USB webcam detected.\n");
L
Linus Torvalds 已提交
1238 1239 1240 1241
			name = "Visionite VCS-UC300";
			type_id = 740; /* CCD sensor */
			break;
		case 0x1910:
1242
			PWC_INFO("Visionite VCS-UM100 USB webcam detected.\n");
L
Linus Torvalds 已提交
1243 1244 1245 1246 1247 1248 1249 1250
			name = "Visionite VCS-UM100";
			type_id = 730; /* CMOS sensor */
			break;
		default:
			return -ENODEV;
			break;
		}
	}
1251
	else
L
Linus Torvalds 已提交
1252 1253 1254 1255
		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);
1256
	PWC_DEBUG_PROBE("Device serial number is %s\n", serial_number);
L
Linus Torvalds 已提交
1257 1258

	if (udev->descriptor.bNumConfigurations > 1)
1259
		PWC_WARNING("Warning: more than 1 configuration available.\n");
L
Linus Torvalds 已提交
1260 1261

	/* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */
1262
	pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL);
L
Linus Torvalds 已提交
1263
	if (pdev == NULL) {
1264
		PWC_ERROR("Oops, could not allocate memory for pwc_device.\n");
L
Linus Torvalds 已提交
1265 1266 1267 1268 1269 1270 1271
		return -ENOMEM;
	}
	pdev->type = type_id;
	pdev->vsize = default_size;
	pdev->vframes = default_fps;
	strcpy(pdev->serial, serial_number);
	pdev->features = features;
1272
	if (vendor_id == 0x046D && product_id == 0x08B5) {
L
Linus Torvalds 已提交
1273
		/* Logitech QuickCam Orbit
1274 1275 1276
		   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
		  */
L
Linus Torvalds 已提交
1277 1278 1279 1280 1281 1282
		pdev->angle_range.pan_min  = -7000;
		pdev->angle_range.pan_max  =  7000;
		pdev->angle_range.tilt_min = -3000;
		pdev->angle_range.tilt_max =  2500;
	}

1283
	mutex_init(&pdev->modlock);
1284 1285
	spin_lock_init(&pdev->queued_bufs_lock);
	INIT_LIST_HEAD(&pdev->queued_bufs);
L
Linus Torvalds 已提交
1286 1287 1288 1289

	pdev->udev = udev;
	pdev->vcompression = pwc_preferred_compression;

1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
	/* Init videobuf2 queue structure */
	memset(&pdev->vb_queue, 0, sizeof(pdev->vb_queue));
	pdev->vb_queue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	pdev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
	pdev->vb_queue.drv_priv = pdev;
	pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf);
	pdev->vb_queue.ops = &pwc_vb_queue_ops;
	pdev->vb_queue.mem_ops = &vb2_vmalloc_memops;
	vb2_queue_init(&pdev->vb_queue);

1300 1301 1302 1303 1304 1305
	/* Init video_device structure */
	memcpy(&pdev->vdev, &pwc_template, sizeof(pwc_template));
	pdev->vdev.parent = &intf->dev;
	pdev->vdev.lock = &pdev->modlock;
	strcpy(pdev->vdev.name, name);
	video_set_drvdata(&pdev->vdev, pdev);
L
Linus Torvalds 已提交
1306 1307

	pdev->release = le16_to_cpu(udev->descriptor.bcdDevice);
1308
	PWC_DEBUG_PROBE("Release: %04x\n", pdev->release);
L
Linus Torvalds 已提交
1309 1310 1311 1312 1313 1314 1315

	/* 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)) {
1316 1317 1318 1319
				/* 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;
L
Linus Torvalds 已提交
1320 1321 1322 1323 1324
			}
		}
	}

	/* occupy slot */
1325
	if (hint < MAX_DEV_HINTS)
L
Linus Torvalds 已提交
1326 1327
		device_hint[hint].pdev = pdev;

1328
	PWC_DEBUG_PROBE("probe() function returning struct at 0x%p.\n", pdev);
1329
	usb_set_intfdata(intf, pdev);
1330 1331 1332 1333 1334

	/* Set the leds off */
	pwc_set_leds(pdev, 0, 0);
	pwc_camera_power(pdev, 0);

1335
	rc = video_register_device(&pdev->vdev, VFL_TYPE_GRABBER, video_nr);
1336 1337
	if (rc < 0) {
		PWC_ERROR("Failed to register as video device (%d).\n", rc);
1338
		goto err_free_mem;
1339
	}
1340
	rc = pwc_create_sysfs_files(pdev);
1341 1342 1343
	if (rc)
		goto err_video_unreg;

1344
	PWC_INFO("Registered as %s.\n", video_device_node_name(&pdev->vdev));
1345

1346 1347 1348 1349 1350
#ifdef CONFIG_USB_PWC_INPUT_EVDEV
	/* register webcam snapshot button input device */
	pdev->button_dev = input_allocate_device();
	if (!pdev->button_dev) {
		PWC_ERROR("Err, insufficient memory for webcam snapshot button device.");
1351
		rc = -ENOMEM;
1352
		pwc_remove_sysfs_files(pdev);
1353
		goto err_video_unreg;
1354 1355
	}

1356 1357 1358
	usb_make_path(udev, pdev->button_phys, sizeof(pdev->button_phys));
	strlcat(pdev->button_phys, "/input0", sizeof(pdev->button_phys));

1359
	pdev->button_dev->name = "PWC snapshot button";
1360
	pdev->button_dev->phys = pdev->button_phys;
1361 1362 1363
	usb_to_input_id(pdev->udev, &pdev->button_dev->id);
	pdev->button_dev->dev.parent = &pdev->udev->dev;
	pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY);
1364
	pdev->button_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
1365 1366 1367 1368 1369

	rc = input_register_device(pdev->button_dev);
	if (rc) {
		input_free_device(pdev->button_dev);
		pdev->button_dev = NULL;
1370
		pwc_remove_sysfs_files(pdev);
1371
		goto err_video_unreg;
1372 1373 1374
	}
#endif

L
Linus Torvalds 已提交
1375
	return 0;
1376

1377
err_video_unreg:
1378 1379
	if (hint < MAX_DEV_HINTS)
		device_hint[hint].pdev = NULL;
1380
	video_unregister_device(&pdev->vdev);
1381 1382
err_free_mem:
	kfree(pdev);
1383
	return rc;
L
Linus Torvalds 已提交
1384 1385
}

1386
/* The user yanked out the cable... */
L
Linus Torvalds 已提交
1387 1388
static void usb_pwc_disconnect(struct usb_interface *intf)
{
1389
	struct pwc_device *pdev  = usb_get_intfdata(intf);
L
Linus Torvalds 已提交
1390

H
Hans Verkuil 已提交
1391
	mutex_lock(&pdev->modlock);
L
Linus Torvalds 已提交
1392
	usb_set_intfdata (intf, NULL);
1393

L
Linus Torvalds 已提交
1394
	/* We got unplugged; this is signalled by an EPIPE error code */
1395 1396
	pdev->error_status = EPIPE;
	pdev->unplugged = 1;
L
Linus Torvalds 已提交
1397

1398 1399
	/* No need to keep the urbs around after disconnection */
	pwc_isoc_cleanup(pdev);
1400
	pwc_cleanup_queued_bufs(pdev);
L
Linus Torvalds 已提交
1401

H
Hans Verkuil 已提交
1402
	mutex_unlock(&pdev->modlock);
1403 1404 1405 1406 1407 1408 1409 1410

	pwc_remove_sysfs_files(pdev);
	video_unregister_device(&pdev->vdev);

#ifdef CONFIG_USB_PWC_INPUT_EVDEV
	if (pdev->button_dev)
		input_unregister_device(pdev->button_dev);
#endif
L
Linus Torvalds 已提交
1411 1412 1413
}


1414 1415
/*
 * Initialization code & module stuff
L
Linus Torvalds 已提交
1416 1417
 */

1418 1419
static char *size;
static int fps;
L
Linus Torvalds 已提交
1420 1421
static int compression = -1;
static int leds[2] = { -1, -1 };
1422
static unsigned int leds_nargs;
1423
static char *dev_hint[MAX_DEV_HINTS];
1424
static unsigned int dev_hint_nargs;
1425 1426 1427

module_param(size, charp, 0444);
module_param(fps, int, 0444);
1428
#ifdef CONFIG_USB_PWC_DEBUG
1429 1430 1431 1432 1433 1434
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);
L
Linus Torvalds 已提交
1435 1436 1437

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");
1438
#ifdef CONFIG_USB_PWC_DEBUG
L
Linus Torvalds 已提交
1439
MODULE_PARM_DESC(trace, "For debugging purposes");
1440
#endif
L
Linus Torvalds 已提交
1441 1442 1443 1444 1445 1446 1447 1448
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");
1449 1450
MODULE_ALIAS("pwcx");
MODULE_VERSION( PWC_VERSION );
L
Linus Torvalds 已提交
1451 1452 1453 1454 1455 1456

static int __init usb_pwc_init(void)
{
	int i, sz;
	char *sizenames[PSZ_MAX] = { "sqcif", "qsif", "qcif", "sif", "cif", "vga" };

1457 1458 1459 1460
	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");
L
Linus Torvalds 已提交
1461 1462 1463

	if (fps) {
		if (fps < 4 || fps > 30) {
1464
			PWC_ERROR("Framerate out of bounds (4-30).\n");
L
Linus Torvalds 已提交
1465 1466 1467
			return -EINVAL;
		}
		default_fps = fps;
1468
		PWC_DEBUG_MODULE("Default framerate set to %d.\n", default_fps);
L
Linus Torvalds 已提交
1469 1470
	}

1471
	if (size) {
L
Linus Torvalds 已提交
1472 1473 1474 1475 1476 1477 1478 1479
		/* 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) {
1480
			PWC_ERROR("Size not recognized; try size=[sqcif | qsif | qcif | sif | cif | vga].\n");
L
Linus Torvalds 已提交
1481 1482
			return -EINVAL;
		}
1483
		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);
L
Linus Torvalds 已提交
1484
	}
1485
#ifdef CONFIG_USB_PWC_DEBUG
1486 1487
	if (pwc_trace >= 0) {
		PWC_DEBUG_MODULE("Trace options: 0x%04x\n", pwc_trace);
L
Linus Torvalds 已提交
1488
	}
1489
#endif
L
Linus Torvalds 已提交
1490 1491
	if (compression >= 0) {
		if (compression > 3) {
1492
			PWC_ERROR("Invalid compression setting; use a number between 0 (uncompressed) and 3 (high).\n");
L
Linus Torvalds 已提交
1493 1494 1495
			return -EINVAL;
		}
		pwc_preferred_compression = compression;
1496
		PWC_DEBUG_MODULE("Preferred compression set to %d.\n", pwc_preferred_compression);
L
Linus Torvalds 已提交
1497 1498
	}
	if (power_save)
1499
		PWC_DEBUG_MODULE("Enabling power save on open/close.\n");
L
Linus Torvalds 已提交
1500 1501 1502 1503 1504
	if (leds[0] >= 0)
		led_on = leds[0];
	if (leds[1] >= 0)
		led_off = leds[1];

1505
	/* Big device node whoopla. Basically, it allows you to assign a
L
Linus Torvalds 已提交
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
	   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) {
1530
				PWC_ERROR("Malformed camera hint: the colon must be after the dot.\n");
L
Linus Torvalds 已提交
1531 1532 1533 1534 1535 1536
				return -EINVAL;
			}

			if (*colon == '\0') {
				/* No colon */
				if (*dot != '\0') {
1537
					PWC_ERROR("Malformed camera hint: no colon + device node given.\n");
L
Linus Torvalds 已提交
1538 1539 1540 1541
					return -EINVAL;
				}
				else {
					/* No type or serial number specified, just a number. */
1542 1543
					device_hint[i].device_node =
						simple_strtol(s, NULL, 10);
L
Linus Torvalds 已提交
1544 1545 1546 1547
				}
			}
			else {
				/* There's a colon, so we have at least a type and a device node */
1548 1549 1550 1551
				device_hint[i].type =
					simple_strtol(s, NULL, 10);
				device_hint[i].device_node =
					simple_strtol(colon + 1, NULL, 10);
L
Linus Torvalds 已提交
1552 1553 1554
				if (*dot != '\0') {
					/* There's a serial number as well */
					int k;
1555

L
Linus Torvalds 已提交
1556 1557 1558 1559 1560 1561 1562 1563 1564
					dot++;
					k = 0;
					while (*dot != ':' && k < 29) {
						device_hint[i].serial_number[k++] = *dot;
						dot++;
					}
					device_hint[i].serial_number[k] = '\0';
				}
			}
1565 1566 1567 1568
			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);
L
Linus Torvalds 已提交
1569 1570 1571 1572 1573
		}
		else
			device_hint[i].type = 0; /* not filled */
	} /* ..for MAX_DEV_HINTS */

1574
	PWC_DEBUG_PROBE("Registering driver at address 0x%p.\n", &pwc_driver);
L
Linus Torvalds 已提交
1575 1576 1577 1578 1579
	return usb_register(&pwc_driver);
}

static void __exit usb_pwc_exit(void)
{
1580
	PWC_DEBUG_MODULE("Deregistering driver.\n");
L
Linus Torvalds 已提交
1581
	usb_deregister(&pwc_driver);
1582
	PWC_INFO("Philips webcam module removed.\n");
L
Linus Torvalds 已提交
1583 1584 1585 1586 1587
}

module_init(usb_pwc_init);
module_exit(usb_pwc_exit);

1588
/* vim: set cino= formatoptions=croql cindent shiftwidth=8 tabstop=8: */