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