^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Linux driver for Philips webcam
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) USB and Video4Linux interface part.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) (C) 1999-2004 Nemosoft Unv.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) (C) 2004-2006 Luc Saillard (luc@saillard.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) (C) 2011 Hans de Goede <hdegoede@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) driver and thus may have bugs that are not present in the original version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Please send bug reports and support requests to <luc@saillard.org>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) The decompression routines have been implemented by reverse-engineering the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) Nemosoft binary pwcx module. Caveat emptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) This code forms the interface between the USB layers and the Philips
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) specific stuff. Some adanved stuff of the driver falls under an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) NDA, signed between me and Philips B.V., Eindhoven, the Netherlands, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) is thus not distributed in source form. The binary pwcx.o module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) contains the code that falls under the NDA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) In case you're wondering: 'pwc' stands for "Philips WebCam", but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) I really didn't want to type 'philips_web_cam' every time (I'm lazy as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) any Linux kernel hacker, but I don't like uncomprehensible abbreviations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) without explanation).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) Oh yes, convention: to disctinguish between all the various pointers to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) device-structures, I use these names for the pointer variables:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) udev: struct usb_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) vdev: struct video_device (member of pwc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) pdev: struct pwc_devive *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* Contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) - Alvarado: adding whitebalance code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) - Alistar Moire: QuickCam 3000 Pro device/product ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) - Tony Hoyle: Creative Labs Webcam 5 device/product ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) - Mark Burazin: solving hang in VIDIOCSYNC when camera gets unplugged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) - Jk Fang: Sotec Afina Eye ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) - Xavier Roche: QuickCam Pro 4000 ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) - Jens Knudsen: QuickCam Zoom ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) - J. Debert: QuickCam for Notebooks ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) - Pham Thanh Nam: webcam snapshot button as an event input device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #ifdef CONFIG_USB_PWC_INPUT_EVDEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <linux/kernel.h> /* simple_strtol() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include "pwc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include "pwc-kiara.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include "pwc-timon.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include "pwc-dec23.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include "pwc-dec1.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <trace/events/pwc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Function prototypes and driver templates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* hotplug device table support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static const struct usb_device_id pwc_device_table [] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) { USB_DEVICE(0x041E, 0x400C) }, /* Creative Webcam 5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) { USB_DEVICE(0x041E, 0x4011) }, /* Creative Webcam Pro Ex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) { USB_DEVICE(0x046D, 0x08B0) }, /* Logitech QuickCam 3000 Pro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) { USB_DEVICE(0x046D, 0x08B1) }, /* Logitech QuickCam Notebook Pro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) { USB_DEVICE(0x046D, 0x08B2) }, /* Logitech QuickCam 4000 Pro */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) { USB_DEVICE(0x046D, 0x08B3) }, /* Logitech QuickCam Zoom (old model) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) { USB_DEVICE(0x046D, 0x08B4) }, /* Logitech QuickCam Zoom (new model) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) { USB_DEVICE(0x046D, 0x08B5) }, /* Logitech QuickCam Orbit/Sphere */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) { USB_DEVICE(0x046D, 0x08B6) }, /* Logitech/Cisco VT Camera */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) { USB_DEVICE(0x046D, 0x08B7) }, /* Logitech ViewPort AV 100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) { USB_DEVICE(0x046D, 0x08B8) }, /* Logitech QuickCam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) { USB_DEVICE(0x0471, 0x0302) }, /* Philips PCA645VC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) { USB_DEVICE(0x0471, 0x0303) }, /* Philips PCA646VC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) { USB_DEVICE(0x0471, 0x0304) }, /* Askey VC010 type 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) { USB_DEVICE(0x0471, 0x0307) }, /* Philips PCVC675K (Vesta) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) { USB_DEVICE(0x0471, 0x0308) }, /* Philips PCVC680K (Vesta Pro) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) { USB_DEVICE(0x0471, 0x030C) }, /* Philips PCVC690K (Vesta Pro Scan) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) { USB_DEVICE(0x0471, 0x0310) }, /* Philips PCVC730K (ToUCam Fun)/PCVC830 (ToUCam II) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) { USB_DEVICE(0x0471, 0x0311) }, /* Philips PCVC740K (ToUCam Pro)/PCVC840 (ToUCam II) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) { USB_DEVICE(0x0471, 0x0312) }, /* Philips PCVC750K (ToUCam Pro Scan) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) { USB_DEVICE(0x0471, 0x0313) }, /* Philips PCVC720K/40 (ToUCam XS) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) { USB_DEVICE(0x0471, 0x0329) }, /* Philips SPC 900NC webcam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) { USB_DEVICE(0x0471, 0x032C) }, /* Philips SPC 880NC webcam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) { USB_DEVICE(0x04CC, 0x8116) }, /* Sotec Afina Eye */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) { USB_DEVICE(0x055D, 0x9000) }, /* Samsung MPC-C10 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) { USB_DEVICE(0x055D, 0x9001) }, /* Samsung MPC-C30 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) { USB_DEVICE(0x055D, 0x9002) }, /* Samsung SNC-35E (Ver3.0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) { USB_DEVICE(0x069A, 0x0001) }, /* Askey VC010 type 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) { USB_DEVICE(0x06BE, 0x8116) }, /* AME Co. Afina Eye */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) { USB_DEVICE(0x0d81, 0x1900) }, /* Visionite VCS-UC300 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) { USB_DEVICE(0x0d81, 0x1910) }, /* Visionite VCS-UM100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) MODULE_DEVICE_TABLE(usb, pwc_device_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static void usb_pwc_disconnect(struct usb_interface *intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static void pwc_isoc_cleanup(struct pwc_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static struct usb_driver pwc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .name = "Philips webcam", /* name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .id_table = pwc_device_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .probe = usb_pwc_probe, /* probe() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .disconnect = usb_pwc_disconnect, /* disconnect() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define MAX_DEV_HINTS 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define MAX_ISOC_ERRORS 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #ifdef CONFIG_USB_PWC_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int pwc_trace = PWC_DEBUG_LEVEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int power_save = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int leds[2] = { 100, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static const struct v4l2_file_operations pwc_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .open = v4l2_fh_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .release = vb2_fop_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .read = vb2_fop_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .poll = vb2_fop_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .mmap = vb2_fop_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .unlocked_ioctl = video_ioctl2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static const struct video_device pwc_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .name = "Philips Webcam", /* Filled in later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .release = video_device_release_empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .fops = &pwc_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .ioctl_ops = &pwc_ioctl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Private functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void *pwc_alloc_urb_buffer(struct usb_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) size_t size, dma_addr_t *dma_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct device *dmadev = dev->bus->sysdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void *buffer = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (!buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) *dma_handle = dma_map_single(dmadev, buffer, size, DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (dma_mapping_error(dmadev, *dma_handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static void pwc_free_urb_buffer(struct usb_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dma_addr_t dma_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct device *dmadev = dev->bus->sysdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dma_unmap_single(dmadev, dma_handle, size, DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static struct pwc_frame_buf *pwc_get_next_fill_buf(struct pwc_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct pwc_frame_buf *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) spin_lock_irqsave(&pdev->queued_bufs_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (list_empty(&pdev->queued_bufs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) goto leave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) list_del(&buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) leave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static void pwc_snapshot_button(struct pwc_device *pdev, int down)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) PWC_TRACE("Snapshot button pressed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) PWC_TRACE("Snapshot button released.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #ifdef CONFIG_USB_PWC_INPUT_EVDEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (pdev->button_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) input_report_key(pdev->button_dev, KEY_CAMERA, down);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) input_sync(pdev->button_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static void pwc_frame_complete(struct pwc_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct pwc_frame_buf *fbuf = pdev->fill_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* The ToUCam Fun CMOS sensor causes the firmware to send 2 or 3 bogus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) frames on the USB wire after an exposure change. This conditition is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) however detected in the cam and a bit is set in the header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (pdev->type == 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) unsigned char *ptr = (unsigned char *)fbuf->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (ptr[1] == 1 && ptr[0] & 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) PWC_TRACE("Hyundai CMOS sensor bug. Dropping frame.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) pdev->drop_frames += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if ((ptr[0] ^ pdev->vmirror) & 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pwc_snapshot_button(pdev, ptr[0] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if ((ptr[0] ^ pdev->vmirror) & 0x02) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (ptr[0] & 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) PWC_TRACE("Image is mirrored.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) PWC_TRACE("Image is normal.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pdev->vmirror = ptr[0] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /* Sometimes the trailer of the 730 is still sent as a 4 byte packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) after a short frame; this condition is filtered out specifically. A 4 byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) frame doesn't make sense anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) So we get either this sequence:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) drop_bit set -> 4 byte frame -> short frame -> good frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) Or this one:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) drop_bit set -> short frame -> good frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) So we drop either 3 or 2 frames in all!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (fbuf->filled == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) pdev->drop_frames++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) } else if (pdev->type == 740 || pdev->type == 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) unsigned char *ptr = (unsigned char *)fbuf->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if ((ptr[0] ^ pdev->vmirror) & 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) pwc_snapshot_button(pdev, ptr[0] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) pdev->vmirror = ptr[0] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* In case we were instructed to drop the frame, do so silently. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (pdev->drop_frames > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) pdev->drop_frames--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* Check for underflow first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (fbuf->filled < pdev->frame_total_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) PWC_DEBUG_FLOW("Frame buffer underflow (%d bytes); discarded.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) fbuf->filled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) fbuf->vb.field = V4L2_FIELD_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) fbuf->vb.sequence = pdev->vframe_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) pdev->fill_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) pdev->vsync = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) } /* !drop_frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) pdev->vframe_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* This gets called for the Isochronous pipe (video). This is done in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * interrupt time, so it has to be fast, not crash, and not stall. Neat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static void pwc_isoc_handler(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct pwc_device *pdev = (struct pwc_device *)urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct device *dmadev = urb->dev->bus->sysdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int i, fst, flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) unsigned char *iso_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) trace_pwc_handler_enter(urb, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (urb->status == -ENOENT || urb->status == -ECONNRESET ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) urb->status == -ESHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) PWC_DEBUG_OPEN("URB (%p) unlinked %ssynchronously.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) urb, urb->status == -ENOENT ? "" : "a");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (pdev->fill_buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) pdev->fill_buf = pwc_get_next_fill_buf(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (urb->status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) const char *errmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) errmsg = "Unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) switch(urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) case -ENOSR: errmsg = "Buffer error (overrun)"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) case -EPIPE: errmsg = "Stalled (device not responding)"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) case -EOVERFLOW: errmsg = "Babble (bad cable?)"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) case -EPROTO: errmsg = "Bit-stuff error (bad cable?)"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) case -EILSEQ: errmsg = "CRC/Timeout (could be anything)"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) case -ETIME: errmsg = "Device does not respond"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) PWC_ERROR("pwc_isoc_handler() called with status %d [%s].\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) urb->status, errmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /* Give up after a number of contiguous errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (++pdev->visoc_errors > MAX_ISOC_ERRORS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) PWC_ERROR("Too many ISOC errors, bailing out.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (pdev->fill_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) vb2_buffer_done(&pdev->fill_buf->vb.vb2_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) VB2_BUF_STATE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) pdev->fill_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) pdev->vsync = 0; /* Drop the current frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) goto handler_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* Reset ISOC error counter. We did get here, after all. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) pdev->visoc_errors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dma_sync_single_for_cpu(dmadev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) urb->transfer_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* vsync: 0 = don't copy data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 1 = sync-hunt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 2 = synched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* Compact data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) for (i = 0; i < urb->number_of_packets; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) fst = urb->iso_frame_desc[i].status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) flen = urb->iso_frame_desc[i].actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) iso_buf = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (fst != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) PWC_ERROR("Iso frame %d has error %d\n", i, fst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (flen > 0 && pdev->vsync) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct pwc_frame_buf *fbuf = pdev->fill_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (pdev->vsync == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) fbuf->vb.vb2_buf.timestamp = ktime_get_ns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) pdev->vsync = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (flen + fbuf->filled > pdev->frame_total_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) PWC_ERROR("Frame overflow (%d > %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) flen + fbuf->filled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) pdev->frame_total_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) pdev->vsync = 0; /* Let's wait for an EOF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) memcpy(fbuf->data + fbuf->filled, iso_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) flen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) fbuf->filled += flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (flen < pdev->vlast_packet_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Shorter packet... end of frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (pdev->vsync == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) pwc_frame_complete(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (pdev->fill_buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) pdev->fill_buf = pwc_get_next_fill_buf(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (pdev->fill_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) pdev->fill_buf->filled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) pdev->vsync = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) pdev->vlast_packet_size = flen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) dma_sync_single_for_device(dmadev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) urb->transfer_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) handler_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) trace_pwc_handler_exit(urb, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) i = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (i != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) PWC_ERROR("Error (%d) re-submitting urb in pwc_isoc_handler.\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* Both v4l2_lock and vb_queue_lock should be locked when calling this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static int pwc_isoc_init(struct pwc_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int i, j, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct usb_host_interface *idesc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int compression = 0; /* 0..3 = uncompressed..high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) pdev->vsync = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) pdev->vlast_packet_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) pdev->fill_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) pdev->vframe_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) pdev->visoc_errors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) udev = pdev->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /* We first try with low compression and then retry with a higher
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) compression setting if there is not enough bandwidth. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ret = pwc_set_video_mode(pdev, pdev->width, pdev->height, pdev->pixfmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) pdev->vframes, &compression, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* Get the current alternate interface, adjust packet size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) intf = usb_ifnum_to_if(udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) idesc = usb_altnum_to_altsetting(intf, pdev->valternate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (!idesc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /* Search video endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) pdev->vmax_packet_size = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) for (i = 0; i < idesc->desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if ((idesc->endpoint[i].desc.bEndpointAddress & 0xF) == pdev->vendpoint) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) pdev->vmax_packet_size = le16_to_cpu(idesc->endpoint[i].desc.wMaxPacketSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (pdev->vmax_packet_size < 0 || pdev->vmax_packet_size > ISO_MAX_FRAME_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) PWC_ERROR("Failed to find packet size for video endpoint in current alternate setting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return -ENFILE; /* Odd error, that should be noticeable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /* Set alternate interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) PWC_DEBUG_OPEN("Setting alternate interface %d\n", pdev->valternate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) ret = usb_set_interface(pdev->udev, 0, pdev->valternate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (ret == -ENOSPC && compression < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) compression++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* Allocate and init Isochronuous urbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) for (i = 0; i < MAX_ISO_BUFS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) urb = usb_alloc_urb(ISO_FRAMES_PER_DESC, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (urb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) pwc_isoc_cleanup(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) pdev->urbs[i] = urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) PWC_DEBUG_MEMORY("Allocated URB at 0x%p\n", urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) urb->interval = 1; // devik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) urb->dev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) urb->pipe = usb_rcvisocpipe(udev, pdev->vendpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) urb->transfer_buffer_length = ISO_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) urb->transfer_buffer = pwc_alloc_urb_buffer(udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) &urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) if (urb->transfer_buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) PWC_ERROR("Failed to allocate urb buffer %d\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) pwc_isoc_cleanup(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) urb->complete = pwc_isoc_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) urb->context = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) urb->start_frame = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) urb->number_of_packets = ISO_FRAMES_PER_DESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) for (j = 0; j < ISO_FRAMES_PER_DESC; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) urb->iso_frame_desc[j].offset = j * ISO_MAX_FRAME_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) urb->iso_frame_desc[j].length = pdev->vmax_packet_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) for (i = 0; i < MAX_ISO_BUFS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ret = usb_submit_urb(pdev->urbs[i], GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (ret == -ENOSPC && compression < 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) compression++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) pwc_isoc_cleanup(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) pwc_isoc_cleanup(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* All is done... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) PWC_DEBUG_OPEN("<< pwc_isoc_init()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static void pwc_iso_stop(struct pwc_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* Unlinking ISOC buffers one by one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) for (i = 0; i < MAX_ISO_BUFS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (pdev->urbs[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) PWC_DEBUG_MEMORY("Unlinking URB %p\n", pdev->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) usb_kill_urb(pdev->urbs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static void pwc_iso_free(struct pwc_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* Freeing ISOC buffers one by one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) for (i = 0; i < MAX_ISO_BUFS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct urb *urb = pdev->urbs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) PWC_DEBUG_MEMORY("Freeing URB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (urb->transfer_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) pwc_free_urb_buffer(urb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) urb->transfer_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) pdev->urbs[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* Both v4l2_lock and vb_queue_lock should be locked when calling this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static void pwc_isoc_cleanup(struct pwc_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) PWC_DEBUG_OPEN(">> pwc_isoc_cleanup()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) pwc_iso_stop(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) pwc_iso_free(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) usb_set_interface(pdev->udev, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /* Must be called with vb_queue_lock hold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static void pwc_cleanup_queued_bufs(struct pwc_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) enum vb2_buffer_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) spin_lock_irqsave(&pdev->queued_bufs_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) while (!list_empty(&pdev->queued_bufs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct pwc_frame_buf *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) list_del(&buf->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) vb2_buffer_done(&buf->vb.vb2_buf, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #ifdef CONFIG_USB_PWC_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static const char *pwc_sensor_type_to_string(unsigned int sensor_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) switch(sensor_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) case 0x00:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) return "Hyundai CMOS sensor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) case 0x20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return "Sony CCD sensor + TDA8787";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) case 0x2E:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return "Sony CCD sensor + Exas 98L59";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) case 0x2F:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return "Sony CCD sensor + ADI 9804";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) case 0x30:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return "Sharp CCD sensor + TDA8787";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) case 0x3E:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return "Sharp CCD sensor + Exas 98L59";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) case 0x3F:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return "Sharp CCD sensor + ADI 9804";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return "UPA 1021 sensor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) case 0x100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return "VGA sensor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) case 0x101:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return "PAL MR sensor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return "unknown type of sensor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* Video4Linux functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static void pwc_video_release(struct v4l2_device *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) v4l2_ctrl_handler_free(&pdev->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) v4l2_device_unregister(&pdev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) kfree(pdev->ctrl_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) kfree(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /* Videobuf2 operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static int queue_setup(struct vb2_queue *vq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) unsigned int *nbuffers, unsigned int *nplanes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) unsigned int sizes[], struct device *alloc_devs[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct pwc_device *pdev = vb2_get_drv_priv(vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (*nbuffers < MIN_FRAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) *nbuffers = MIN_FRAMES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) else if (*nbuffers > MAX_FRAMES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) *nbuffers = MAX_FRAMES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) *nplanes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) size = pwc_get_size(pdev, MAX_WIDTH, MAX_HEIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) sizes[0] = PAGE_ALIGN(pwc_image_sizes[size][0] *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) pwc_image_sizes[size][1] * 3 / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static int buffer_init(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct pwc_frame_buf *buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) container_of(vbuf, struct pwc_frame_buf, vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* need vmalloc since frame buffer > 128K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) buf->data = vzalloc(PWC_FRAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) if (buf->data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static int buffer_prepare(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) /* Don't allow queueing new buffers after device disconnection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (!pdev->udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static void buffer_finish(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct pwc_frame_buf *buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) container_of(vbuf, struct pwc_frame_buf, vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (vb->state == VB2_BUF_STATE_DONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * Application has called dqbuf and is getting back a buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * we've filled, take the pwc data we've stored in buf->data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * and decompress it into a usable format, storing the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * in the vb2_buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pwc_decompress(pdev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static void buffer_cleanup(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) struct pwc_frame_buf *buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) container_of(vbuf, struct pwc_frame_buf, vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) vfree(buf->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) static void buffer_queue(struct vb2_buffer *vb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) struct pwc_frame_buf *buf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) container_of(vbuf, struct pwc_frame_buf, vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* Check the device has not disconnected between prep and queuing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if (!pdev->udev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) spin_lock_irqsave(&pdev->queued_bufs_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) list_add_tail(&buf->list, &pdev->queued_bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static int start_streaming(struct vb2_queue *vq, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct pwc_device *pdev = vb2_get_drv_priv(vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!pdev->udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (mutex_lock_interruptible(&pdev->v4l2_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* Turn on camera and set LEDS on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) pwc_camera_power(pdev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) pwc_set_leds(pdev, leds[0], leds[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) r = pwc_isoc_init(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /* If we failed turn camera and LEDS back off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) pwc_set_leds(pdev, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) pwc_camera_power(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* And cleanup any queued bufs!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_QUEUED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) mutex_unlock(&pdev->v4l2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) static void stop_streaming(struct vb2_queue *vq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) struct pwc_device *pdev = vb2_get_drv_priv(vq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) mutex_lock(&pdev->v4l2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (pdev->udev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) pwc_set_leds(pdev, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) pwc_camera_power(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) pwc_isoc_cleanup(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (pdev->fill_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) vb2_buffer_done(&pdev->fill_buf->vb.vb2_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) VB2_BUF_STATE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) mutex_unlock(&pdev->v4l2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static const struct vb2_ops pwc_vb_queue_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) .queue_setup = queue_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .buf_init = buffer_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .buf_prepare = buffer_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) .buf_finish = buffer_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .buf_cleanup = buffer_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) .buf_queue = buffer_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .start_streaming = start_streaming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .stop_streaming = stop_streaming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) .wait_prepare = vb2_ops_wait_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) .wait_finish = vb2_ops_wait_finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) /***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) /* USB functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) /* This function gets called when a new device is plugged in or the usb core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) * is loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) struct pwc_device *pdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) int vendor_id, product_id, type_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) int features = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) int compression = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) int my_power_save = power_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) char serial_number[30], *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) vendor_id = le16_to_cpu(udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) product_id = le16_to_cpu(udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /* Check if we can handle this device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) PWC_DEBUG_PROBE("probe() called [%04X %04X], if %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) vendor_id, product_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) intf->altsetting->desc.bInterfaceNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) /* the interfaces are probed one by one. We are only interested in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) video interface (0) now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) Interface 1 is the Audio Control, and interface 2 Audio itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (intf->altsetting->desc.bInterfaceNumber > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (vendor_id == 0x0471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) switch (product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) case 0x0302:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) PWC_INFO("Philips PCA645VC USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) name = "Philips 645 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) type_id = 645;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) case 0x0303:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) PWC_INFO("Philips PCA646VC USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) name = "Philips 646 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) type_id = 646;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) case 0x0304:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) PWC_INFO("Askey VC010 type 2 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) name = "Askey VC010 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) type_id = 646;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) case 0x0307:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) PWC_INFO("Philips PCVC675K (Vesta) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) name = "Philips 675 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) type_id = 675;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) case 0x0308:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) PWC_INFO("Philips PCVC680K (Vesta Pro) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) name = "Philips 680 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) type_id = 680;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) case 0x030C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) PWC_INFO("Philips PCVC690K (Vesta Pro Scan) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) name = "Philips 690 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) type_id = 690;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) case 0x0310:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) PWC_INFO("Philips PCVC730K (ToUCam Fun)/PCVC830 (ToUCam II) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) name = "Philips 730 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) type_id = 730;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) case 0x0311:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) PWC_INFO("Philips PCVC740K (ToUCam Pro)/PCVC840 (ToUCam II) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) name = "Philips 740 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) type_id = 740;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) case 0x0312:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) PWC_INFO("Philips PCVC750K (ToUCam Pro Scan) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) name = "Philips 750 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) type_id = 750;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) case 0x0313:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) PWC_INFO("Philips PCVC720K/40 (ToUCam XS) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) name = "Philips 720K/40 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) type_id = 720;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) case 0x0329:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) PWC_INFO("Philips SPC 900NC USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) name = "Philips SPC 900NC webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) type_id = 740;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) case 0x032C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) PWC_INFO("Philips SPC 880NC USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) name = "Philips SPC 880NC webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) type_id = 740;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) else if (vendor_id == 0x069A) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) case 0x0001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) PWC_INFO("Askey VC010 type 1 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) name = "Askey VC010 webcam";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) type_id = 645;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) else if (vendor_id == 0x046d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) case 0x08b0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) PWC_INFO("Logitech QuickCam Pro 3000 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) name = "Logitech QuickCam Pro 3000";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) case 0x08b1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) PWC_INFO("Logitech QuickCam Notebook Pro USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) name = "Logitech QuickCam Notebook Pro";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) case 0x08b2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) PWC_INFO("Logitech QuickCam 4000 Pro USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) name = "Logitech QuickCam Pro 4000";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (my_power_save == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) my_power_save = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) case 0x08b3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) PWC_INFO("Logitech QuickCam Zoom USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) name = "Logitech QuickCam Zoom";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) case 0x08B4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) PWC_INFO("Logitech QuickCam Zoom (new model) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) name = "Logitech QuickCam Zoom";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (my_power_save == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) my_power_save = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) case 0x08b5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) PWC_INFO("Logitech QuickCam Orbit/Sphere USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) name = "Logitech QuickCam Orbit";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) if (my_power_save == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) my_power_save = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) features |= FEATURE_MOTOR_PANTILT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) case 0x08b6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) PWC_INFO("Logitech/Cisco VT Camera webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) name = "Cisco VT Camera";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) case 0x08b7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) PWC_INFO("Logitech ViewPort AV 100 webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) name = "Logitech ViewPort AV 100";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) case 0x08b8: /* Where this released? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) PWC_INFO("Logitech QuickCam detected (reserved ID).\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) name = "Logitech QuickCam (res.)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) type_id = 730; /* Assuming CMOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) else if (vendor_id == 0x055d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) /* I don't know the difference between the C10 and the C30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) I suppose the difference is the sensor, but both cameras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) work equally well with a type_id of 675
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) case 0x9000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) PWC_INFO("Samsung MPC-C10 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) name = "Samsung MPC-C10";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) type_id = 675;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) case 0x9001:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) PWC_INFO("Samsung MPC-C30 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) name = "Samsung MPC-C30";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) type_id = 675;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) case 0x9002:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) PWC_INFO("Samsung SNC-35E (v3.0) USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) name = "Samsung MPC-C30";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) type_id = 740;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) else if (vendor_id == 0x041e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) case 0x400c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) PWC_INFO("Creative Labs Webcam 5 detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) name = "Creative Labs Webcam 5";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) type_id = 730;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (my_power_save == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) my_power_save = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) case 0x4011:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) PWC_INFO("Creative Labs Webcam Pro Ex detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) name = "Creative Labs Webcam Pro Ex";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) type_id = 740;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) else if (vendor_id == 0x04cc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) case 0x8116:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) PWC_INFO("Sotec Afina Eye USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) name = "Sotec Afina Eye";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) type_id = 730;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) else if (vendor_id == 0x06be) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) case 0x8116:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) /* This is essentially the same cam as the Sotec Afina Eye */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) PWC_INFO("AME Co. Afina Eye USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) name = "AME Co. Afina Eye";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) type_id = 750;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) else if (vendor_id == 0x0d81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) switch(product_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) case 0x1900:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) PWC_INFO("Visionite VCS-UC300 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) name = "Visionite VCS-UC300";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) type_id = 740; /* CCD sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) case 0x1910:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) PWC_INFO("Visionite VCS-UM100 USB webcam detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) name = "Visionite VCS-UM100";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) type_id = 730; /* CMOS sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return -ENODEV; /* Not any of the know types; but the list keeps growing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) if (my_power_save == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) my_power_save = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) memset(serial_number, 0, 30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) usb_string(udev, udev->descriptor.iSerialNumber, serial_number, 29);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) PWC_DEBUG_PROBE("Device serial number is %s\n", serial_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (udev->descriptor.bNumConfigurations > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) PWC_WARNING("Warning: more than 1 configuration available.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) /* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (pdev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) PWC_ERROR("Oops, could not allocate memory for pwc_device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) pdev->type = type_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) pdev->features = features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) pwc_construct(pdev); /* set min/max sizes correct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) mutex_init(&pdev->v4l2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) mutex_init(&pdev->vb_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) spin_lock_init(&pdev->queued_bufs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) INIT_LIST_HEAD(&pdev->queued_bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) pdev->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) pdev->power_save = my_power_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /* Init videobuf2 queue structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) pdev->vb_queue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) pdev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) pdev->vb_queue.drv_priv = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) pdev->vb_queue.ops = &pwc_vb_queue_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) pdev->vb_queue.mem_ops = &vb2_vmalloc_memops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) pdev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) rc = vb2_queue_init(&pdev->vb_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) PWC_ERROR("Oops, could not initialize vb2 queue.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) /* Init video_device structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) pdev->vdev = pwc_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) strscpy(pdev->vdev.name, name, sizeof(pdev->vdev.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) pdev->vdev.queue = &pdev->vb_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) pdev->vdev.queue->lock = &pdev->vb_queue_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) video_set_drvdata(&pdev->vdev, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) pdev->release = le16_to_cpu(udev->descriptor.bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) PWC_DEBUG_PROBE("Release: %04x\n", pdev->release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) /* Allocate USB command buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) pdev->ctrl_buf = kmalloc(sizeof(pdev->cmd_buf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (!pdev->ctrl_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) PWC_ERROR("Oops, could not allocate memory for pwc_device.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) #ifdef CONFIG_USB_PWC_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) /* Query sensor type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (pwc_get_cmos_sensor(pdev, &rc) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) PWC_DEBUG_OPEN("This %s camera is equipped with a %s (%d).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) pdev->vdev.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) pwc_sensor_type_to_string(rc), rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) /* Set the leds off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) pwc_set_leds(pdev, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* Setup initial videomode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) rc = pwc_set_video_mode(pdev, MAX_WIDTH, MAX_HEIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) V4L2_PIX_FMT_YUV420, 30, &compression, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) /* Register controls (and read default values from camera */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) rc = pwc_init_controls(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) PWC_ERROR("Failed to register v4l2 controls (%d).\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) /* And powerdown the camera until streaming starts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) pwc_camera_power(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) /* Register the v4l2_device structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) pdev->v4l2_dev.release = pwc_video_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) rc = v4l2_device_register(&intf->dev, &pdev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) PWC_ERROR("Failed to register v4l2-device (%d).\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) goto err_free_controls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) pdev->v4l2_dev.ctrl_handler = &pdev->ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) pdev->vdev.v4l2_dev = &pdev->v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) pdev->vdev.lock = &pdev->v4l2_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) pdev->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) V4L2_CAP_READWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) rc = video_register_device(&pdev->vdev, VFL_TYPE_VIDEO, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) PWC_ERROR("Failed to register as video device (%d).\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) goto err_unregister_v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) PWC_INFO("Registered as %s.\n", video_device_node_name(&pdev->vdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) #ifdef CONFIG_USB_PWC_INPUT_EVDEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) /* register webcam snapshot button input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) pdev->button_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) if (!pdev->button_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) goto err_video_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) usb_make_path(udev, pdev->button_phys, sizeof(pdev->button_phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) strlcat(pdev->button_phys, "/input0", sizeof(pdev->button_phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) pdev->button_dev->name = "PWC snapshot button";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) pdev->button_dev->phys = pdev->button_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) usb_to_input_id(pdev->udev, &pdev->button_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) pdev->button_dev->dev.parent = &pdev->udev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) pdev->button_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) rc = input_register_device(pdev->button_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) input_free_device(pdev->button_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) pdev->button_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) goto err_video_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) #ifdef CONFIG_USB_PWC_INPUT_EVDEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) err_video_unreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) video_unregister_device(&pdev->vdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) err_unregister_v4l2_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) v4l2_device_unregister(&pdev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) err_free_controls:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) v4l2_ctrl_handler_free(&pdev->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) kfree(pdev->ctrl_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) kfree(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) /* The user yanked out the cable... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) static void usb_pwc_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) struct v4l2_device *v = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) mutex_lock(&pdev->vb_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) mutex_lock(&pdev->v4l2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) /* No need to keep the urbs around after disconnection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) if (pdev->vb_queue.streaming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) pwc_isoc_cleanup(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) pdev->udev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) v4l2_device_disconnect(&pdev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) video_unregister_device(&pdev->vdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) mutex_unlock(&pdev->v4l2_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) mutex_unlock(&pdev->vb_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) #ifdef CONFIG_USB_PWC_INPUT_EVDEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) if (pdev->button_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) input_unregister_device(pdev->button_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) v4l2_device_put(&pdev->v4l2_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) * Initialization code & module stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) static unsigned int leds_nargs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) #ifdef CONFIG_USB_PWC_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) module_param_named(trace, pwc_trace, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) module_param(power_save, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) module_param_array(leds, int, &leds_nargs, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) #ifdef CONFIG_USB_PWC_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) MODULE_PARM_DESC(trace, "For debugging purposes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) MODULE_PARM_DESC(power_save, "Turn power saving for new cameras on or off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) MODULE_PARM_DESC(leds, "LED on,off time in milliseconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) MODULE_DESCRIPTION("Philips & OEM USB webcam driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) MODULE_AUTHOR("Luc Saillard <luc@saillard.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) MODULE_ALIAS("pwcx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) MODULE_VERSION( PWC_VERSION );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) module_usb_driver(pwc_driver);