Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Main USB camera driver |
| 3 | * |
Jean-François Moine | 59929ce | 2011-03-14 05:33:01 -0300 | [diff] [blame] | 4 | * Copyright (C) 2008-2011 Jean-François Moine <http://moinejf.free.fr> |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 5 | * |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 6 | * Camera button input handling by Márton Németh |
| 7 | * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu> |
| 8 | * |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 17 | * for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software Foundation, |
| 21 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 25 | |
Jean-François Moine | f22123f | 2011-09-23 05:17:10 -0300 | [diff] [blame] | 26 | #define GSPCA_VERSION "2.14.0" |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 27 | |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/fs.h> |
| 30 | #include <linux/vmalloc.h> |
| 31 | #include <linux/sched.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/mm.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/pagemap.h> |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 36 | #include <linux/io.h> |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 37 | #include <asm/page.h> |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 38 | #include <linux/uaccess.h> |
Paulo Assis | 2f51d00 | 2010-03-07 06:56:56 -0300 | [diff] [blame] | 39 | #include <linux/ktime.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 40 | #include <media/v4l2-ioctl.h> |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 41 | |
| 42 | #include "gspca.h" |
| 43 | |
Randy Dunlap | f762801 | 2010-03-30 14:32:04 -0300 | [diff] [blame] | 44 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 45 | #include <linux/input.h> |
| 46 | #include <linux/usb/input.h> |
Jean-François Moine | e070bf9 | 2010-02-18 15:02:51 -0300 | [diff] [blame] | 47 | #endif |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 48 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 49 | /* global values */ |
Jean-Francois Moine | 8fee845 | 2009-01-17 04:46:38 -0300 | [diff] [blame] | 50 | #define DEF_NURBS 3 /* default number of URBs */ |
| 51 | #if DEF_NURBS > MAX_NURBS |
| 52 | #error "DEF_NURBS too big" |
| 53 | #endif |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 54 | |
Jean-François Moine | 27c6f9e | 2010-04-02 06:59:13 -0300 | [diff] [blame] | 55 | MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 56 | MODULE_DESCRIPTION("GSPCA USB Camera Driver"); |
| 57 | MODULE_LICENSE("GPL"); |
Jean-François Moine | f22123f | 2011-09-23 05:17:10 -0300 | [diff] [blame] | 58 | MODULE_VERSION(GSPCA_VERSION); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 59 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 60 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 61 | int gspca_debug = D_ERR | D_PROBE; |
| 62 | EXPORT_SYMBOL(gspca_debug); |
| 63 | |
| 64 | static void PDEBUG_MODE(char *txt, __u32 pixfmt, int w, int h) |
| 65 | { |
| 66 | if ((pixfmt >> 24) >= '0' && (pixfmt >> 24) <= 'z') { |
| 67 | PDEBUG(D_CONF|D_STREAM, "%s %c%c%c%c %dx%d", |
| 68 | txt, |
| 69 | pixfmt & 0xff, |
| 70 | (pixfmt >> 8) & 0xff, |
| 71 | (pixfmt >> 16) & 0xff, |
| 72 | pixfmt >> 24, |
| 73 | w, h); |
| 74 | } else { |
| 75 | PDEBUG(D_CONF|D_STREAM, "%s 0x%08x %dx%d", |
| 76 | txt, |
| 77 | pixfmt, |
| 78 | w, h); |
| 79 | } |
| 80 | } |
| 81 | #else |
| 82 | #define PDEBUG_MODE(txt, pixfmt, w, h) |
| 83 | #endif |
| 84 | |
Jean-Francois Moine | 77ee331 | 2009-11-07 15:30:50 -0300 | [diff] [blame] | 85 | /* specific memory types - !! should be different from V4L2_MEMORY_xxx */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 86 | #define GSPCA_MEMORY_NO 0 /* V4L2_MEMORY_xxx starts from 1 */ |
| 87 | #define GSPCA_MEMORY_READ 7 |
| 88 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 89 | #define BUF_ALL_FLAGS (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 90 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 91 | /* |
| 92 | * VMA operations. |
| 93 | */ |
| 94 | static void gspca_vm_open(struct vm_area_struct *vma) |
| 95 | { |
| 96 | struct gspca_frame *frame = vma->vm_private_data; |
| 97 | |
| 98 | frame->vma_use_count++; |
| 99 | frame->v4l2_buf.flags |= V4L2_BUF_FLAG_MAPPED; |
| 100 | } |
| 101 | |
| 102 | static void gspca_vm_close(struct vm_area_struct *vma) |
| 103 | { |
| 104 | struct gspca_frame *frame = vma->vm_private_data; |
| 105 | |
| 106 | if (--frame->vma_use_count <= 0) |
| 107 | frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_MAPPED; |
| 108 | } |
| 109 | |
Alexey Dobriyan | f0f37e2f | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 110 | static const struct vm_operations_struct gspca_vm_ops = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 111 | .open = gspca_vm_open, |
| 112 | .close = gspca_vm_close, |
| 113 | }; |
| 114 | |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 115 | /* |
| 116 | * Input and interrupt endpoint handling functions |
| 117 | */ |
Randy Dunlap | f762801 | 2010-03-30 14:32:04 -0300 | [diff] [blame] | 118 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 119 | static void int_irq(struct urb *urb) |
| 120 | { |
| 121 | struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; |
| 122 | int ret; |
| 123 | |
| 124 | ret = urb->status; |
| 125 | switch (ret) { |
| 126 | case 0: |
| 127 | if (gspca_dev->sd_desc->int_pkt_scan(gspca_dev, |
| 128 | urb->transfer_buffer, urb->actual_length) < 0) { |
| 129 | PDEBUG(D_ERR, "Unknown packet received"); |
| 130 | } |
| 131 | break; |
| 132 | |
| 133 | case -ENOENT: |
| 134 | case -ECONNRESET: |
| 135 | case -ENODEV: |
| 136 | case -ESHUTDOWN: |
| 137 | /* Stop is requested either by software or hardware is gone, |
| 138 | * keep the ret value non-zero and don't resubmit later. |
| 139 | */ |
| 140 | break; |
| 141 | |
| 142 | default: |
| 143 | PDEBUG(D_ERR, "URB error %i, resubmitting", urb->status); |
| 144 | urb->status = 0; |
| 145 | ret = 0; |
| 146 | } |
| 147 | |
| 148 | if (ret == 0) { |
| 149 | ret = usb_submit_urb(urb, GFP_ATOMIC); |
| 150 | if (ret < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 151 | pr_err("Resubmit URB failed with error %i\n", ret); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | static int gspca_input_connect(struct gspca_dev *dev) |
| 156 | { |
| 157 | struct input_dev *input_dev; |
| 158 | int err = 0; |
| 159 | |
| 160 | dev->input_dev = NULL; |
Hans de Goede | ac82f59 | 2010-02-19 04:28:39 -0300 | [diff] [blame] | 161 | if (dev->sd_desc->int_pkt_scan || dev->sd_desc->other_input) { |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 162 | input_dev = input_allocate_device(); |
| 163 | if (!input_dev) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | usb_make_path(dev->dev, dev->phys, sizeof(dev->phys)); |
| 167 | strlcat(dev->phys, "/input0", sizeof(dev->phys)); |
| 168 | |
| 169 | input_dev->name = dev->sd_desc->name; |
| 170 | input_dev->phys = dev->phys; |
| 171 | |
| 172 | usb_to_input_id(dev->dev, &input_dev->id); |
| 173 | |
| 174 | input_dev->evbit[0] = BIT_MASK(EV_KEY); |
| 175 | input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA); |
| 176 | input_dev->dev.parent = &dev->dev->dev; |
| 177 | |
| 178 | err = input_register_device(input_dev); |
| 179 | if (err) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 180 | pr_err("Input device registration failed with error %i\n", |
| 181 | err); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 182 | input_dev->dev.parent = NULL; |
| 183 | input_free_device(input_dev); |
| 184 | } else { |
| 185 | dev->input_dev = input_dev; |
| 186 | } |
Hans de Goede | 10ee240 | 2010-02-19 04:41:40 -0300 | [diff] [blame] | 187 | } |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 188 | |
| 189 | return err; |
| 190 | } |
| 191 | |
| 192 | static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev, |
| 193 | struct usb_endpoint_descriptor *ep) |
| 194 | { |
| 195 | unsigned int buffer_len; |
| 196 | int interval; |
| 197 | struct urb *urb; |
| 198 | struct usb_device *dev; |
| 199 | void *buffer = NULL; |
| 200 | int ret = -EINVAL; |
| 201 | |
Jean-François Moine | b26d6e2 | 2010-04-29 06:01:53 -0300 | [diff] [blame] | 202 | buffer_len = le16_to_cpu(ep->wMaxPacketSize); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 203 | interval = ep->bInterval; |
Jean-François Moine | c4dc692 | 2010-07-14 06:26:54 -0300 | [diff] [blame] | 204 | PDEBUG(D_CONF, "found int in endpoint: 0x%x, " |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 205 | "buffer_len=%u, interval=%u", |
| 206 | ep->bEndpointAddress, buffer_len, interval); |
| 207 | |
| 208 | dev = gspca_dev->dev; |
| 209 | |
| 210 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 211 | if (!urb) { |
| 212 | ret = -ENOMEM; |
| 213 | goto error; |
| 214 | } |
| 215 | |
Linus Torvalds | 7a9b149 | 2010-05-20 21:26:12 -0700 | [diff] [blame] | 216 | buffer = usb_alloc_coherent(dev, buffer_len, |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 217 | GFP_KERNEL, &urb->transfer_dma); |
| 218 | if (!buffer) { |
| 219 | ret = -ENOMEM; |
| 220 | goto error_buffer; |
| 221 | } |
| 222 | usb_fill_int_urb(urb, dev, |
| 223 | usb_rcvintpipe(dev, ep->bEndpointAddress), |
| 224 | buffer, buffer_len, |
| 225 | int_irq, (void *)gspca_dev, interval); |
Jason Wang | 882787f | 2010-09-03 06:57:19 -0300 | [diff] [blame] | 226 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 227 | ret = usb_submit_urb(urb, GFP_KERNEL); |
| 228 | if (ret < 0) { |
Jean-François Moine | c4dc692 | 2010-07-14 06:26:54 -0300 | [diff] [blame] | 229 | PDEBUG(D_ERR, "submit int URB failed with error %i", ret); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 230 | goto error_submit; |
| 231 | } |
Hans de Goede | 2661da4 | 2010-10-26 05:16:32 -0300 | [diff] [blame] | 232 | gspca_dev->int_urb = urb; |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 233 | return ret; |
| 234 | |
| 235 | error_submit: |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 236 | usb_free_coherent(dev, |
| 237 | urb->transfer_buffer_length, |
| 238 | urb->transfer_buffer, |
| 239 | urb->transfer_dma); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 240 | error_buffer: |
| 241 | usb_free_urb(urb); |
| 242 | error: |
| 243 | return ret; |
| 244 | } |
| 245 | |
Hans de Goede | 10ee240 | 2010-02-19 04:41:40 -0300 | [diff] [blame] | 246 | static void gspca_input_create_urb(struct gspca_dev *gspca_dev) |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 247 | { |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 248 | struct usb_interface *intf; |
| 249 | struct usb_host_interface *intf_desc; |
| 250 | struct usb_endpoint_descriptor *ep; |
| 251 | int i; |
| 252 | |
| 253 | if (gspca_dev->sd_desc->int_pkt_scan) { |
| 254 | intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); |
| 255 | intf_desc = intf->cur_altsetting; |
| 256 | for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) { |
| 257 | ep = &intf_desc->endpoint[i].desc; |
| 258 | if (usb_endpoint_dir_in(ep) && |
| 259 | usb_endpoint_xfer_int(ep)) { |
| 260 | |
Hans de Goede | 10ee240 | 2010-02-19 04:41:40 -0300 | [diff] [blame] | 261 | alloc_and_submit_int_urb(gspca_dev, ep); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 262 | break; |
| 263 | } |
| 264 | } |
| 265 | } |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static void gspca_input_destroy_urb(struct gspca_dev *gspca_dev) |
| 269 | { |
| 270 | struct urb *urb; |
| 271 | |
| 272 | urb = gspca_dev->int_urb; |
| 273 | if (urb) { |
| 274 | gspca_dev->int_urb = NULL; |
| 275 | usb_kill_urb(urb); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 276 | usb_free_coherent(gspca_dev->dev, |
| 277 | urb->transfer_buffer_length, |
| 278 | urb->transfer_buffer, |
| 279 | urb->transfer_dma); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 280 | usb_free_urb(urb); |
| 281 | } |
| 282 | } |
Randy Dunlap | f762801 | 2010-03-30 14:32:04 -0300 | [diff] [blame] | 283 | #else |
| 284 | static inline void gspca_input_destroy_urb(struct gspca_dev *gspca_dev) |
| 285 | { |
| 286 | } |
| 287 | |
| 288 | static inline void gspca_input_create_urb(struct gspca_dev *gspca_dev) |
| 289 | { |
| 290 | } |
| 291 | |
| 292 | static inline int gspca_input_connect(struct gspca_dev *dev) |
| 293 | { |
| 294 | return 0; |
| 295 | } |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 296 | #endif |
| 297 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 298 | /* |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 299 | * fill a video frame from an URB and resubmit |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 300 | */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 301 | static void fill_frame(struct gspca_dev *gspca_dev, |
| 302 | struct urb *urb) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 303 | { |
Jean-Francois Moine | 8d584a5 | 2009-01-13 06:07:59 -0300 | [diff] [blame] | 304 | u8 *data; /* address of data in the iso message */ |
Jean-Francois Moine | 1b60e1a | 2008-09-20 05:44:21 -0300 | [diff] [blame] | 305 | int i, len, st; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 306 | cam_pkt_op pkt_scan; |
| 307 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 308 | if (urb->status != 0) { |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 309 | if (urb->status == -ESHUTDOWN) |
| 310 | return; /* disconnection */ |
Jean-Francois Moine | 62ee8ee | 2008-09-03 17:12:13 -0300 | [diff] [blame] | 311 | #ifdef CONFIG_PM |
Hans de Goede | 6a540bd | 2009-10-24 15:02:14 -0300 | [diff] [blame] | 312 | if (gspca_dev->frozen) |
| 313 | return; |
Jean-Francois Moine | 62ee8ee | 2008-09-03 17:12:13 -0300 | [diff] [blame] | 314 | #endif |
Hans de Goede | 6a540bd | 2009-10-24 15:02:14 -0300 | [diff] [blame] | 315 | PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); |
Jean-Francois Moine | 8157852 | 2009-11-13 07:15:08 -0300 | [diff] [blame] | 316 | urb->status = 0; |
Hans de Goede | bf926ad | 2009-10-23 06:56:06 -0300 | [diff] [blame] | 317 | goto resubmit; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 318 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 319 | pkt_scan = gspca_dev->sd_desc->pkt_scan; |
| 320 | for (i = 0; i < urb->number_of_packets; i++) { |
Mauro Carvalho Chehab | 95f18be | 2010-12-27 12:00:03 -0300 | [diff] [blame] | 321 | len = urb->iso_frame_desc[i].actual_length; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 322 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 323 | /* check the packet status and length */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 324 | st = urb->iso_frame_desc[i].status; |
| 325 | if (st) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 326 | pr_err("ISOC data error: [%d] len=%d, status=%d\n", |
| 327 | i, len, st); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 328 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 329 | continue; |
| 330 | } |
Jean-François Moine | 76ebc16 | 2010-12-25 13:22:21 -0300 | [diff] [blame] | 331 | if (len == 0) { |
| 332 | if (gspca_dev->empty_packet == 0) |
| 333 | gspca_dev->empty_packet = 1; |
| 334 | continue; |
| 335 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 336 | |
| 337 | /* let the packet be analyzed by the subdriver */ |
| 338 | PDEBUG(D_PACK, "packet [%d] o:%d l:%d", |
| 339 | i, urb->iso_frame_desc[i].offset, len); |
Jean-Francois Moine | 8d584a5 | 2009-01-13 06:07:59 -0300 | [diff] [blame] | 340 | data = (u8 *) urb->transfer_buffer |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 341 | + urb->iso_frame_desc[i].offset; |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 342 | pkt_scan(gspca_dev, data, len); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 343 | } |
| 344 | |
Hans de Goede | bf926ad | 2009-10-23 06:56:06 -0300 | [diff] [blame] | 345 | resubmit: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 346 | /* resubmit the URB */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 347 | st = usb_submit_urb(urb, GFP_ATOMIC); |
| 348 | if (st < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 349 | pr_err("usb_submit_urb() ret %d\n", st); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /* |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 353 | * ISOC message interrupt from the USB device |
| 354 | * |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 355 | * Analyse each packet and call the subdriver for copy to the frame buffer. |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 356 | */ |
Jean-Francois Moine | 8d584a5 | 2009-01-13 06:07:59 -0300 | [diff] [blame] | 357 | static void isoc_irq(struct urb *urb) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 358 | { |
| 359 | struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; |
| 360 | |
Hans de Goede | 3647fea | 2008-07-15 05:36:30 -0300 | [diff] [blame] | 361 | PDEBUG(D_PACK, "isoc irq"); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 362 | if (!gspca_dev->streaming) |
| 363 | return; |
| 364 | fill_frame(gspca_dev, urb); |
| 365 | } |
| 366 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 367 | /* |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 368 | * bulk message interrupt from the USB device |
| 369 | */ |
Jean-Francois Moine | 8d584a5 | 2009-01-13 06:07:59 -0300 | [diff] [blame] | 370 | static void bulk_irq(struct urb *urb) |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 371 | { |
| 372 | struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 373 | int st; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 374 | |
| 375 | PDEBUG(D_PACK, "bulk irq"); |
| 376 | if (!gspca_dev->streaming) |
| 377 | return; |
Jean-Francois Moine | 880ae24 | 2008-11-18 04:19:52 -0300 | [diff] [blame] | 378 | switch (urb->status) { |
| 379 | case 0: |
| 380 | break; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 381 | case -ESHUTDOWN: |
| 382 | return; /* disconnection */ |
Jean-Francois Moine | 880ae24 | 2008-11-18 04:19:52 -0300 | [diff] [blame] | 383 | default: |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 384 | #ifdef CONFIG_PM |
Hans de Goede | 6a540bd | 2009-10-24 15:02:14 -0300 | [diff] [blame] | 385 | if (gspca_dev->frozen) |
| 386 | return; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 387 | #endif |
Hans de Goede | 6a540bd | 2009-10-24 15:02:14 -0300 | [diff] [blame] | 388 | PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); |
Jean-Francois Moine | 8157852 | 2009-11-13 07:15:08 -0300 | [diff] [blame] | 389 | urb->status = 0; |
Hans de Goede | bf926ad | 2009-10-23 06:56:06 -0300 | [diff] [blame] | 390 | goto resubmit; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 391 | } |
| 392 | |
Jean-Francois Moine | d131c3c | 2009-11-13 08:16:02 -0300 | [diff] [blame] | 393 | PDEBUG(D_PACK, "packet l:%d", urb->actual_length); |
| 394 | gspca_dev->sd_desc->pkt_scan(gspca_dev, |
Jean-Francois Moine | d131c3c | 2009-11-13 08:16:02 -0300 | [diff] [blame] | 395 | urb->transfer_buffer, |
| 396 | urb->actual_length); |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 397 | |
Hans de Goede | bf926ad | 2009-10-23 06:56:06 -0300 | [diff] [blame] | 398 | resubmit: |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 399 | /* resubmit the URB */ |
| 400 | if (gspca_dev->cam.bulk_nurbs != 0) { |
| 401 | st = usb_submit_urb(urb, GFP_ATOMIC); |
| 402 | if (st < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 403 | pr_err("usb_submit_urb() ret %d\n", st); |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 404 | } |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 408 | * add data to the current frame |
| 409 | * |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 410 | * This function is called by the subdrivers at interrupt level. |
| 411 | * |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 412 | * To build a frame, these ones must add |
| 413 | * - one FIRST_PACKET |
| 414 | * - 0 or many INTER_PACKETs |
| 415 | * - one LAST_PACKET |
| 416 | * DISCARD_PACKET invalidates the whole frame. |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 417 | */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 418 | void gspca_frame_add(struct gspca_dev *gspca_dev, |
| 419 | enum gspca_packet_type packet_type, |
| 420 | const u8 *data, |
| 421 | int len) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 422 | { |
Jean-Francois Moine | 3ec342f | 2009-11-13 07:38:16 -0300 | [diff] [blame] | 423 | struct gspca_frame *frame; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 424 | int i, j; |
| 425 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 426 | PDEBUG(D_PACK, "add t:%d l:%d", packet_type, len); |
Jean-Francois Moine | d131c3c | 2009-11-13 08:16:02 -0300 | [diff] [blame] | 427 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 428 | if (packet_type == FIRST_PACKET) { |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 429 | i = atomic_read(&gspca_dev->fr_i); |
| 430 | |
| 431 | /* if there are no queued buffer, discard the whole frame */ |
| 432 | if (i == atomic_read(&gspca_dev->fr_q)) { |
| 433 | gspca_dev->last_packet_type = DISCARD_PACKET; |
Jean-François Moine | 2e0544a | 2010-10-16 13:59:13 -0300 | [diff] [blame] | 434 | gspca_dev->sequence++; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 435 | return; |
| 436 | } |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 437 | j = gspca_dev->fr_queue[i]; |
| 438 | frame = &gspca_dev->frame[j]; |
Paulo Assis | 2f51d00 | 2010-03-07 06:56:56 -0300 | [diff] [blame] | 439 | frame->v4l2_buf.timestamp = ktime_to_timeval(ktime_get()); |
Jean-François Moine | 2e0544a | 2010-10-16 13:59:13 -0300 | [diff] [blame] | 440 | frame->v4l2_buf.sequence = gspca_dev->sequence++; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 441 | gspca_dev->image = frame->data; |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 442 | gspca_dev->image_len = 0; |
Jean-François Moine | fe988f5 | 2010-07-29 02:46:02 -0300 | [diff] [blame] | 443 | } else { |
| 444 | switch (gspca_dev->last_packet_type) { |
| 445 | case DISCARD_PACKET: |
Hans de Goede | fa4376d | 2011-06-05 03:44:43 -0300 | [diff] [blame] | 446 | if (packet_type == LAST_PACKET) { |
Jean-François Moine | fe988f5 | 2010-07-29 02:46:02 -0300 | [diff] [blame] | 447 | gspca_dev->last_packet_type = packet_type; |
Hans de Goede | fa4376d | 2011-06-05 03:44:43 -0300 | [diff] [blame] | 448 | gspca_dev->image = NULL; |
| 449 | gspca_dev->image_len = 0; |
| 450 | } |
Jean-François Moine | fe988f5 | 2010-07-29 02:46:02 -0300 | [diff] [blame] | 451 | return; |
| 452 | case LAST_PACKET: |
| 453 | return; |
| 454 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 455 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 456 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 457 | /* append the packet to the frame buffer */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 458 | if (len > 0) { |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 459 | if (gspca_dev->image_len + len > gspca_dev->frsz) { |
| 460 | PDEBUG(D_ERR|D_PACK, "frame overflow %d > %d", |
| 461 | gspca_dev->image_len + len, |
| 462 | gspca_dev->frsz); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 463 | packet_type = DISCARD_PACKET; |
| 464 | } else { |
Jean-François Moine | fe988f5 | 2010-07-29 02:46:02 -0300 | [diff] [blame] | 465 | /* !! image is NULL only when last pkt is LAST or DISCARD |
| 466 | if (gspca_dev->image == NULL) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 467 | pr_err("gspca_frame_add() image == NULL\n"); |
Jean-François Moine | fe988f5 | 2010-07-29 02:46:02 -0300 | [diff] [blame] | 468 | return; |
| 469 | } |
| 470 | */ |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 471 | memcpy(gspca_dev->image + gspca_dev->image_len, |
| 472 | data, len); |
| 473 | gspca_dev->image_len += len; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | gspca_dev->last_packet_type = packet_type; |
| 477 | |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 478 | /* if last packet, invalidate packet concatenation until |
| 479 | * next first packet, wake up the application and advance |
| 480 | * in the queue */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 481 | if (packet_type == LAST_PACKET) { |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 482 | i = atomic_read(&gspca_dev->fr_i); |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 483 | j = gspca_dev->fr_queue[i]; |
| 484 | frame = &gspca_dev->frame[j]; |
| 485 | frame->v4l2_buf.bytesused = gspca_dev->image_len; |
Jean-François Moine | 02bbcb9 | 2010-07-06 04:16:40 -0300 | [diff] [blame] | 486 | frame->v4l2_buf.flags = (frame->v4l2_buf.flags |
| 487 | | V4L2_BUF_FLAG_DONE) |
| 488 | & ~V4L2_BUF_FLAG_QUEUED; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 489 | i = (i + 1) % GSPCA_MAX_FRAMES; |
| 490 | atomic_set(&gspca_dev->fr_i, i); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 491 | wake_up_interruptible(&gspca_dev->wq); /* event = new frame */ |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 492 | PDEBUG(D_FRAM, "frame complete len:%d", |
| 493 | frame->v4l2_buf.bytesused); |
| 494 | gspca_dev->image = NULL; |
| 495 | gspca_dev->image_len = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 496 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 497 | } |
| 498 | EXPORT_SYMBOL(gspca_frame_add); |
| 499 | |
Hans de Goede | d642de2 | 2010-12-31 04:51:36 -0300 | [diff] [blame] | 500 | static int frame_alloc(struct gspca_dev *gspca_dev, struct file *file, |
| 501 | enum v4l2_memory memory, unsigned int count) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 502 | { |
| 503 | struct gspca_frame *frame; |
| 504 | unsigned int frsz; |
| 505 | int i; |
| 506 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 507 | i = gspca_dev->curr_mode; |
| 508 | frsz = gspca_dev->cam.cam_mode[i].sizeimage; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 509 | PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 510 | frsz = PAGE_ALIGN(frsz); |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 511 | if (count >= GSPCA_MAX_FRAMES) |
| 512 | count = GSPCA_MAX_FRAMES - 1; |
Jean-François Moine | e795d91 | 2010-06-24 05:14:22 -0300 | [diff] [blame] | 513 | gspca_dev->frbuf = vmalloc_32(frsz * count); |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 514 | if (!gspca_dev->frbuf) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 515 | pr_err("frame alloc failed\n"); |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 516 | return -ENOMEM; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 517 | } |
Hans de Goede | d642de2 | 2010-12-31 04:51:36 -0300 | [diff] [blame] | 518 | gspca_dev->capt_file = file; |
| 519 | gspca_dev->memory = memory; |
| 520 | gspca_dev->frsz = frsz; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 521 | gspca_dev->nframes = count; |
| 522 | for (i = 0; i < count; i++) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 523 | frame = &gspca_dev->frame[i]; |
| 524 | frame->v4l2_buf.index = i; |
| 525 | frame->v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 526 | frame->v4l2_buf.flags = 0; |
| 527 | frame->v4l2_buf.field = V4L2_FIELD_NONE; |
| 528 | frame->v4l2_buf.length = frsz; |
Hans de Goede | d642de2 | 2010-12-31 04:51:36 -0300 | [diff] [blame] | 529 | frame->v4l2_buf.memory = memory; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 530 | frame->v4l2_buf.sequence = 0; |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 531 | frame->data = gspca_dev->frbuf + i * frsz; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 532 | frame->v4l2_buf.m.offset = i * frsz; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 533 | } |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 534 | atomic_set(&gspca_dev->fr_q, 0); |
| 535 | atomic_set(&gspca_dev->fr_i, 0); |
| 536 | gspca_dev->fr_o = 0; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 537 | return 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static void frame_free(struct gspca_dev *gspca_dev) |
| 541 | { |
| 542 | int i; |
| 543 | |
| 544 | PDEBUG(D_STREAM, "frame free"); |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 545 | if (gspca_dev->frbuf != NULL) { |
Jean-François Moine | e795d91 | 2010-06-24 05:14:22 -0300 | [diff] [blame] | 546 | vfree(gspca_dev->frbuf); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 547 | gspca_dev->frbuf = NULL; |
| 548 | for (i = 0; i < gspca_dev->nframes; i++) |
| 549 | gspca_dev->frame[i].data = NULL; |
| 550 | } |
| 551 | gspca_dev->nframes = 0; |
Hans de Goede | d642de2 | 2010-12-31 04:51:36 -0300 | [diff] [blame] | 552 | gspca_dev->frsz = 0; |
| 553 | gspca_dev->capt_file = NULL; |
| 554 | gspca_dev->memory = GSPCA_MEMORY_NO; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 555 | } |
| 556 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 557 | static void destroy_urbs(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 558 | { |
| 559 | struct urb *urb; |
| 560 | unsigned int i; |
| 561 | |
| 562 | PDEBUG(D_STREAM, "kill transfer"); |
Erik Andrén | 4473281 | 2008-10-13 15:52:46 -0300 | [diff] [blame] | 563 | for (i = 0; i < MAX_NURBS; i++) { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 564 | urb = gspca_dev->urb[i]; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 565 | if (urb == NULL) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 566 | break; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 567 | |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 568 | gspca_dev->urb[i] = NULL; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 569 | usb_kill_urb(urb); |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 570 | if (urb->transfer_buffer != NULL) |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 571 | usb_free_coherent(gspca_dev->dev, |
| 572 | urb->transfer_buffer_length, |
| 573 | urb->transfer_buffer, |
| 574 | urb->transfer_dma); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 575 | usb_free_urb(urb); |
| 576 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 577 | } |
| 578 | |
Jean-François Moine | e4dac28 | 2010-04-09 06:11:36 -0300 | [diff] [blame] | 579 | static int gspca_set_alt0(struct gspca_dev *gspca_dev) |
| 580 | { |
| 581 | int ret; |
| 582 | |
| 583 | if (gspca_dev->alt == 0) |
| 584 | return 0; |
| 585 | ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0); |
| 586 | if (ret < 0) |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 587 | pr_err("set alt 0 err %d\n", ret); |
Jean-François Moine | e4dac28 | 2010-04-09 06:11:36 -0300 | [diff] [blame] | 588 | return ret; |
| 589 | } |
| 590 | |
| 591 | /* Note: both the queue and the usb locks should be held when calling this */ |
| 592 | static void gspca_stream_off(struct gspca_dev *gspca_dev) |
| 593 | { |
| 594 | gspca_dev->streaming = 0; |
| 595 | if (gspca_dev->present) { |
| 596 | if (gspca_dev->sd_desc->stopN) |
| 597 | gspca_dev->sd_desc->stopN(gspca_dev); |
| 598 | destroy_urbs(gspca_dev); |
| 599 | gspca_input_destroy_urb(gspca_dev); |
| 600 | gspca_set_alt0(gspca_dev); |
| 601 | gspca_input_create_urb(gspca_dev); |
| 602 | } |
| 603 | |
| 604 | /* always call stop0 to free the subdriver's resources */ |
| 605 | if (gspca_dev->sd_desc->stop0) |
| 606 | gspca_dev->sd_desc->stop0(gspca_dev); |
| 607 | PDEBUG(D_STREAM, "stream off OK"); |
| 608 | } |
| 609 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 610 | /* |
Frank Zago | 219423c | 2008-09-26 07:43:54 -0300 | [diff] [blame] | 611 | * look for an input transfer endpoint in an alternate setting |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 612 | */ |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 613 | static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt, |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 614 | int xfer) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 615 | { |
| 616 | struct usb_host_endpoint *ep; |
| 617 | int i, attr; |
| 618 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 619 | for (i = 0; i < alt->desc.bNumEndpoints; i++) { |
| 620 | ep = &alt->endpoint[i]; |
Jean-Francois Moine | 50e06de | 2008-12-31 08:13:46 -0300 | [diff] [blame] | 621 | attr = ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
Jean-Francois Moine | 30d35e4 | 2009-04-21 13:57:31 -0300 | [diff] [blame] | 622 | if (attr == xfer |
Patrice Chotard | 7106225 | 2011-03-21 16:58:56 -0300 | [diff] [blame] | 623 | && ep->desc.wMaxPacketSize != 0 |
| 624 | && usb_endpoint_dir_in(&ep->desc)) |
Jean-Francois Moine | 50e06de | 2008-12-31 08:13:46 -0300 | [diff] [blame] | 625 | return ep; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 626 | } |
| 627 | return NULL; |
| 628 | } |
| 629 | |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 630 | /* compute the minimum bandwidth for the current transfer */ |
| 631 | static u32 which_bandwidth(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 632 | { |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 633 | u32 bandwidth; |
| 634 | int i; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 635 | |
Jean-François Moine | 18bef42 | 2012-01-04 13:44:02 -0300 | [diff] [blame] | 636 | /* get the (max) image size */ |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 637 | i = gspca_dev->curr_mode; |
| 638 | bandwidth = gspca_dev->cam.cam_mode[i].sizeimage; |
| 639 | |
Jean-François Moine | 18bef42 | 2012-01-04 13:44:02 -0300 | [diff] [blame] | 640 | /* if the image is compressed, estimate its mean size */ |
Hans de Goede | eb3fb7c | 2012-01-01 16:35:01 -0300 | [diff] [blame] | 641 | if (!gspca_dev->cam.needs_full_bandwidth && |
| 642 | bandwidth < gspca_dev->cam.cam_mode[i].width * |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 643 | gspca_dev->cam.cam_mode[i].height) |
Jean-François Moine | 18bef42 | 2012-01-04 13:44:02 -0300 | [diff] [blame] | 644 | bandwidth = bandwidth * 3 / 8; /* 0.375 */ |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 645 | |
| 646 | /* estimate the frame rate */ |
| 647 | if (gspca_dev->sd_desc->get_streamparm) { |
| 648 | struct v4l2_streamparm parm; |
| 649 | |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 650 | gspca_dev->sd_desc->get_streamparm(gspca_dev, &parm); |
| 651 | bandwidth *= parm.parm.capture.timeperframe.denominator; |
Hans de Goede | 1153f04 | 2011-12-30 09:13:07 -0300 | [diff] [blame] | 652 | bandwidth /= parm.parm.capture.timeperframe.numerator; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 653 | } else { |
Jean-François Moine | 18bef42 | 2012-01-04 13:44:02 -0300 | [diff] [blame] | 654 | |
| 655 | /* don't hope more than 15 fps with USB 1.1 and |
| 656 | * image resolution >= 640x480 */ |
| 657 | if (gspca_dev->width >= 640 |
| 658 | && gspca_dev->dev->speed == USB_SPEED_FULL) |
| 659 | bandwidth *= 15; /* 15 fps */ |
| 660 | else |
| 661 | bandwidth *= 30; /* 30 fps */ |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | PDEBUG(D_STREAM, "min bandwidth: %d", bandwidth); |
| 665 | return bandwidth; |
| 666 | } |
| 667 | |
| 668 | /* endpoint table */ |
| 669 | #define MAX_ALT 16 |
| 670 | struct ep_tb_s { |
| 671 | u32 alt; |
| 672 | u32 bandwidth; |
| 673 | }; |
| 674 | |
| 675 | /* |
| 676 | * build the table of the endpoints |
| 677 | * and compute the minimum bandwidth for the image transfer |
| 678 | */ |
Hans de Goede | 66957b8 | 2011-12-30 07:58:10 -0300 | [diff] [blame] | 679 | static int build_isoc_ep_tb(struct gspca_dev *gspca_dev, |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 680 | struct usb_interface *intf, |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 681 | struct ep_tb_s *ep_tb) |
| 682 | { |
| 683 | struct usb_host_endpoint *ep; |
| 684 | int i, j, nbalt, psize, found; |
| 685 | u32 bandwidth, last_bw; |
| 686 | |
| 687 | nbalt = intf->num_altsetting; |
| 688 | if (nbalt > MAX_ALT) |
| 689 | nbalt = MAX_ALT; /* fixme: should warn */ |
| 690 | |
| 691 | /* build the endpoint table */ |
| 692 | i = 0; |
| 693 | last_bw = 0; |
| 694 | for (;;) { |
| 695 | ep_tb->bandwidth = 2000 * 2000 * 120; |
| 696 | found = 0; |
| 697 | for (j = 0; j < nbalt; j++) { |
Hans de Goede | 66957b8 | 2011-12-30 07:58:10 -0300 | [diff] [blame] | 698 | ep = alt_xfer(&intf->altsetting[j], |
| 699 | USB_ENDPOINT_XFER_ISOC); |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 700 | if (ep == NULL) |
| 701 | continue; |
Hans de Goede | d0d3435 | 2011-12-30 08:20:50 -0300 | [diff] [blame] | 702 | if (ep->desc.bInterval == 0) { |
| 703 | pr_err("alt %d iso endp with 0 interval\n", j); |
| 704 | continue; |
| 705 | } |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 706 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); |
Hans de Goede | 66957b8 | 2011-12-30 07:58:10 -0300 | [diff] [blame] | 707 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); |
Hans de Goede | d0d3435 | 2011-12-30 08:20:50 -0300 | [diff] [blame] | 708 | bandwidth = psize * 1000; |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 709 | if (gspca_dev->dev->speed == USB_SPEED_HIGH |
| 710 | || gspca_dev->dev->speed == USB_SPEED_SUPER) |
| 711 | bandwidth *= 8; |
Hans de Goede | d0d3435 | 2011-12-30 08:20:50 -0300 | [diff] [blame] | 712 | bandwidth /= 1 << (ep->desc.bInterval - 1); |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 713 | if (bandwidth <= last_bw) |
| 714 | continue; |
| 715 | if (bandwidth < ep_tb->bandwidth) { |
| 716 | ep_tb->bandwidth = bandwidth; |
| 717 | ep_tb->alt = j; |
| 718 | found = 1; |
| 719 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 720 | } |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 721 | if (!found) |
| 722 | break; |
| 723 | PDEBUG(D_STREAM, "alt %d bandwidth %d", |
| 724 | ep_tb->alt, ep_tb->bandwidth); |
| 725 | last_bw = ep_tb->bandwidth; |
| 726 | i++; |
| 727 | ep_tb++; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 728 | } |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 729 | |
Hans de Goede | 2d39059 | 2011-12-30 18:26:53 -0300 | [diff] [blame] | 730 | /* |
| 731 | * If the camera: |
| 732 | * has a usb audio class interface (a built in usb mic); and |
| 733 | * is a usb 1 full speed device; and |
| 734 | * uses the max full speed iso bandwidth; and |
| 735 | * and has more than 1 alt setting |
| 736 | * then skip the highest alt setting to spare bandwidth for the mic |
| 737 | */ |
| 738 | if (gspca_dev->audio && |
| 739 | gspca_dev->dev->speed == USB_SPEED_FULL && |
| 740 | last_bw >= 1000000 && |
| 741 | i > 1) { |
| 742 | PDEBUG(D_STREAM, "dev has usb audio, skipping highest alt"); |
| 743 | i--; |
| 744 | ep_tb--; |
| 745 | } |
| 746 | |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 747 | /* get the requested bandwidth and start at the highest atlsetting */ |
| 748 | bandwidth = which_bandwidth(gspca_dev); |
| 749 | ep_tb--; |
| 750 | while (i > 1) { |
| 751 | ep_tb--; |
| 752 | if (ep_tb->bandwidth < bandwidth) |
| 753 | break; |
| 754 | i--; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 755 | } |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 756 | return i; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /* |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 760 | * create the URBs for image transfer |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 761 | */ |
| 762 | static int create_urbs(struct gspca_dev *gspca_dev, |
| 763 | struct usb_host_endpoint *ep) |
| 764 | { |
| 765 | struct urb *urb; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 766 | int n, nurbs, i, psize, npkt, bsize; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 767 | |
| 768 | /* calculate the packet size and the number of packets */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 769 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 770 | |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 771 | if (!gspca_dev->cam.bulk) { /* isoc */ |
Jean-Francois Moine | 95d9142 | 2008-09-29 05:57:32 -0300 | [diff] [blame] | 772 | |
| 773 | /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 774 | if (gspca_dev->pkt_size == 0) |
| 775 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); |
| 776 | else |
| 777 | psize = gspca_dev->pkt_size; |
Jean-Francois Moine | 49cb6b0 | 2009-04-25 13:29:01 -0300 | [diff] [blame] | 778 | npkt = gspca_dev->cam.npkt; |
| 779 | if (npkt == 0) |
| 780 | npkt = 32; /* default value */ |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 781 | bsize = psize * npkt; |
| 782 | PDEBUG(D_STREAM, |
| 783 | "isoc %d pkts size %d = bsize:%d", |
| 784 | npkt, psize, bsize); |
Jean-Francois Moine | 51977a8 | 2008-09-08 03:22:42 -0300 | [diff] [blame] | 785 | nurbs = DEF_NURBS; |
Jean-Francois Moine | 95d9142 | 2008-09-29 05:57:32 -0300 | [diff] [blame] | 786 | } else { /* bulk */ |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 787 | npkt = 0; |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 788 | bsize = gspca_dev->cam.bulk_size; |
Jean-Francois Moine | 95d9142 | 2008-09-29 05:57:32 -0300 | [diff] [blame] | 789 | if (bsize == 0) |
| 790 | bsize = psize; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 791 | PDEBUG(D_STREAM, "bulk bsize:%d", bsize); |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 792 | if (gspca_dev->cam.bulk_nurbs != 0) |
| 793 | nurbs = gspca_dev->cam.bulk_nurbs; |
| 794 | else |
| 795 | nurbs = 1; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 796 | } |
| 797 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 798 | for (n = 0; n < nurbs; n++) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 799 | urb = usb_alloc_urb(npkt, GFP_KERNEL); |
| 800 | if (!urb) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 801 | pr_err("usb_alloc_urb failed\n"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 802 | return -ENOMEM; |
| 803 | } |
Jean-Francois Moine | db87087 | 2009-12-15 05:16:04 -0300 | [diff] [blame] | 804 | gspca_dev->urb[n] = urb; |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 805 | urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 806 | bsize, |
| 807 | GFP_KERNEL, |
| 808 | &urb->transfer_dma); |
| 809 | |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 810 | if (urb->transfer_buffer == NULL) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 811 | pr_err("usb_alloc_coherent failed\n"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 812 | return -ENOMEM; |
| 813 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 814 | urb->dev = gspca_dev->dev; |
| 815 | urb->context = gspca_dev; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 816 | urb->transfer_buffer_length = bsize; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 817 | if (npkt != 0) { /* ISOC */ |
| 818 | urb->pipe = usb_rcvisocpipe(gspca_dev->dev, |
| 819 | ep->desc.bEndpointAddress); |
Frank Zago | 6c49da7 | 2008-09-28 07:43:00 -0300 | [diff] [blame] | 820 | urb->transfer_flags = URB_ISO_ASAP |
| 821 | | URB_NO_TRANSFER_DMA_MAP; |
Hans de Goede | 51e23be | 2012-01-01 13:34:58 -0300 | [diff] [blame] | 822 | urb->interval = 1 << (ep->desc.bInterval - 1); |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 823 | urb->complete = isoc_irq; |
| 824 | urb->number_of_packets = npkt; |
| 825 | for (i = 0; i < npkt; i++) { |
| 826 | urb->iso_frame_desc[i].length = psize; |
| 827 | urb->iso_frame_desc[i].offset = psize * i; |
| 828 | } |
| 829 | } else { /* bulk */ |
| 830 | urb->pipe = usb_rcvbulkpipe(gspca_dev->dev, |
Jean-François Moine | a23c194 | 2010-10-29 07:57:03 -0300 | [diff] [blame] | 831 | ep->desc.bEndpointAddress); |
Frank Zago | 6c49da7 | 2008-09-28 07:43:00 -0300 | [diff] [blame] | 832 | urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; |
Jean-Francois Moine | 0be01004 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 833 | urb->complete = bulk_irq; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 834 | } |
| 835 | } |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | /* |
| 840 | * start the USB transfer |
| 841 | */ |
| 842 | static int gspca_init_transfer(struct gspca_dev *gspca_dev) |
| 843 | { |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 844 | struct usb_interface *intf; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 845 | struct usb_host_endpoint *ep; |
Jean-Francois Moine | db87087 | 2009-12-15 05:16:04 -0300 | [diff] [blame] | 846 | struct urb *urb; |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 847 | struct ep_tb_s ep_tb[MAX_ALT]; |
| 848 | int n, ret, xfer, alt, alt_idx; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 849 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 850 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 851 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 852 | |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 853 | if (!gspca_dev->present) { |
| 854 | ret = -ENODEV; |
Hans de Goede | 314b3e0 | 2010-10-26 05:15:46 -0300 | [diff] [blame] | 855 | goto unlock; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 856 | } |
| 857 | |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 858 | /* reset the streaming variables */ |
| 859 | gspca_dev->image = NULL; |
| 860 | gspca_dev->image_len = 0; |
| 861 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 862 | gspca_dev->sequence = 0; |
| 863 | |
Jean-Francois Moine | ab6c8cf | 2010-01-13 15:34:27 -0300 | [diff] [blame] | 864 | gspca_dev->usb_err = 0; |
| 865 | |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 866 | /* do the specific subdriver stuff before endpoint selection */ |
Hans de Goede | 47faa6f | 2011-12-29 16:43:12 -0300 | [diff] [blame] | 867 | intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); |
| 868 | gspca_dev->alt = gspca_dev->cam.bulk ? intf->num_altsetting : 0; |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 869 | if (gspca_dev->sd_desc->isoc_init) { |
| 870 | ret = gspca_dev->sd_desc->isoc_init(gspca_dev); |
| 871 | if (ret < 0) |
Hans de Goede | 314b3e0 | 2010-10-26 05:15:46 -0300 | [diff] [blame] | 872 | goto unlock; |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 873 | } |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 874 | xfer = gspca_dev->cam.bulk ? USB_ENDPOINT_XFER_BULK |
| 875 | : USB_ENDPOINT_XFER_ISOC; |
Hans de Goede | 314b3e0 | 2010-10-26 05:15:46 -0300 | [diff] [blame] | 876 | |
Hans de Goede | 66957b8 | 2011-12-30 07:58:10 -0300 | [diff] [blame] | 877 | /* if bulk or the subdriver forced an altsetting, get the endpoint */ |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 878 | if (gspca_dev->alt != 0) { |
| 879 | gspca_dev->alt--; /* (previous version compatibility) */ |
| 880 | ep = alt_xfer(&intf->altsetting[gspca_dev->alt], xfer); |
| 881 | if (ep == NULL) { |
| 882 | pr_err("bad altsetting %d\n", gspca_dev->alt); |
| 883 | ret = -EIO; |
| 884 | goto out; |
| 885 | } |
| 886 | ep_tb[0].alt = gspca_dev->alt; |
| 887 | alt_idx = 1; |
| 888 | } else { |
| 889 | |
| 890 | /* else, compute the minimum bandwidth |
| 891 | * and build the endpoint table */ |
Hans de Goede | 66957b8 | 2011-12-30 07:58:10 -0300 | [diff] [blame] | 892 | alt_idx = build_isoc_ep_tb(gspca_dev, intf, ep_tb); |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 893 | if (alt_idx <= 0) { |
| 894 | pr_err("no transfer endpoint found\n"); |
| 895 | ret = -EIO; |
| 896 | goto unlock; |
| 897 | } |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 898 | } |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 899 | |
| 900 | /* set the highest alternate setting and |
| 901 | * loop until urb submit succeeds */ |
| 902 | gspca_input_destroy_urb(gspca_dev); |
| 903 | |
| 904 | gspca_dev->alt = ep_tb[--alt_idx].alt; |
| 905 | alt = -1; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 906 | for (;;) { |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 907 | if (alt != gspca_dev->alt) { |
| 908 | alt = gspca_dev->alt; |
Jean-François Moine | 6121ca5 | 2011-11-30 05:54:16 -0300 | [diff] [blame] | 909 | if (intf->num_altsetting > 1) { |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 910 | ret = usb_set_interface(gspca_dev->dev, |
| 911 | gspca_dev->iface, |
| 912 | alt); |
| 913 | if (ret < 0) { |
Jean-François Moine | 4274d84 | 2011-08-10 07:40:47 -0300 | [diff] [blame] | 914 | if (ret == -ENOSPC) |
| 915 | goto retry; /*fixme: ugly*/ |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 916 | pr_err("set alt %d err %d\n", alt, ret); |
| 917 | goto out; |
| 918 | } |
| 919 | } |
| 920 | } |
Jean-Francois Moine | 47aaca9 | 2009-12-15 05:23:04 -0300 | [diff] [blame] | 921 | if (!gspca_dev->cam.no_urb_create) { |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 922 | PDEBUG(D_STREAM, "init transfer alt %d", alt); |
| 923 | ret = create_urbs(gspca_dev, |
| 924 | alt_xfer(&intf->altsetting[alt], xfer)); |
Jean-Francois Moine | 47aaca9 | 2009-12-15 05:23:04 -0300 | [diff] [blame] | 925 | if (ret < 0) { |
| 926 | destroy_urbs(gspca_dev); |
| 927 | goto out; |
| 928 | } |
Jean-Francois Moine | db87087 | 2009-12-15 05:16:04 -0300 | [diff] [blame] | 929 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 930 | |
Jean-Francois Moine | 8fe2f1d | 2008-10-22 14:51:56 -0300 | [diff] [blame] | 931 | /* clear the bulk endpoint */ |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 932 | if (gspca_dev->cam.bulk) |
Jean-Francois Moine | 8fe2f1d | 2008-10-22 14:51:56 -0300 | [diff] [blame] | 933 | usb_clear_halt(gspca_dev->dev, |
Jean-Francois Moine | 50e06de | 2008-12-31 08:13:46 -0300 | [diff] [blame] | 934 | gspca_dev->urb[0]->pipe); |
Jean-Francois Moine | 8fe2f1d | 2008-10-22 14:51:56 -0300 | [diff] [blame] | 935 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 936 | /* start the cam */ |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 937 | ret = gspca_dev->sd_desc->start(gspca_dev); |
| 938 | if (ret < 0) { |
| 939 | destroy_urbs(gspca_dev); |
| 940 | goto out; |
| 941 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 942 | gspca_dev->streaming = 1; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 943 | |
Antonio Ospite | dff369a | 2008-11-14 07:53:32 -0300 | [diff] [blame] | 944 | /* some bulk transfers are started by the subdriver */ |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 945 | if (gspca_dev->cam.bulk && gspca_dev->cam.bulk_nurbs == 0) |
Jean-Francois Moine | 51977a8 | 2008-09-08 03:22:42 -0300 | [diff] [blame] | 946 | break; |
| 947 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 948 | /* submit the URBs */ |
Jean-Francois Moine | db87087 | 2009-12-15 05:16:04 -0300 | [diff] [blame] | 949 | for (n = 0; n < MAX_NURBS; n++) { |
| 950 | urb = gspca_dev->urb[n]; |
| 951 | if (urb == NULL) |
| 952 | break; |
| 953 | ret = usb_submit_urb(urb, GFP_KERNEL); |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 954 | if (ret < 0) |
| 955 | break; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 956 | } |
| 957 | if (ret >= 0) |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 958 | break; /* transfer is started */ |
| 959 | |
| 960 | /* something when wrong |
| 961 | * stop the webcam and free the transfer resources */ |
Jean-François Moine | e4dac28 | 2010-04-09 06:11:36 -0300 | [diff] [blame] | 962 | gspca_stream_off(gspca_dev); |
Jean-Francois Moine | 4bdf4a8 | 2009-11-10 14:49:43 -0300 | [diff] [blame] | 963 | if (ret != -ENOSPC) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 964 | pr_err("usb_submit_urb alt %d err %d\n", |
| 965 | gspca_dev->alt, ret); |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 966 | goto out; |
Jean-Francois Moine | 4bdf4a8 | 2009-11-10 14:49:43 -0300 | [diff] [blame] | 967 | } |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 968 | |
| 969 | /* the bandwidth is not wide enough |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 970 | * negotiate or try a lower alternate setting */ |
Jean-François Moine | 4274d84 | 2011-08-10 07:40:47 -0300 | [diff] [blame] | 971 | retry: |
Jean-Francois Moine | 4bdf4a8 | 2009-11-10 14:49:43 -0300 | [diff] [blame] | 972 | PDEBUG(D_ERR|D_STREAM, |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 973 | "alt %d - bandwidth not wide enough - trying again", |
| 974 | alt); |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 975 | msleep(20); /* wait for kill complete */ |
| 976 | if (gspca_dev->sd_desc->isoc_nego) { |
| 977 | ret = gspca_dev->sd_desc->isoc_nego(gspca_dev); |
| 978 | if (ret < 0) |
| 979 | goto out; |
| 980 | } else { |
Jean-François Moine | 27b1202 | 2011-08-10 07:38:48 -0300 | [diff] [blame] | 981 | if (alt_idx <= 0) { |
| 982 | pr_err("no transfer endpoint found\n"); |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 983 | ret = -EIO; |
| 984 | goto out; |
| 985 | } |
Mauro Carvalho Chehab | ac97ecc | 2011-12-31 11:32:03 -0200 | [diff] [blame] | 986 | gspca_dev->alt = ep_tb[--alt_idx].alt; |
Jean-Francois Moine | 1f53b0b | 2009-06-30 07:07:01 -0300 | [diff] [blame] | 987 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 988 | } |
| 989 | out: |
Hans de Goede | 314b3e0 | 2010-10-26 05:15:46 -0300 | [diff] [blame] | 990 | gspca_input_create_urb(gspca_dev); |
| 991 | unlock: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 992 | mutex_unlock(&gspca_dev->usb_lock); |
| 993 | return ret; |
| 994 | } |
| 995 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 996 | static void gspca_set_default_mode(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 997 | { |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 998 | struct gspca_ctrl *ctrl; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 999 | int i; |
| 1000 | |
| 1001 | i = gspca_dev->cam.nmodes - 1; /* take the highest mode */ |
| 1002 | gspca_dev->curr_mode = i; |
| 1003 | gspca_dev->width = gspca_dev->cam.cam_mode[i].width; |
| 1004 | gspca_dev->height = gspca_dev->cam.cam_mode[i].height; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1005 | gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1006 | |
| 1007 | /* set the current control values to their default values |
| 1008 | * which may have changed in sd_init() */ |
| 1009 | ctrl = gspca_dev->cam.ctrls; |
| 1010 | if (ctrl != NULL) { |
| 1011 | for (i = 0; |
| 1012 | i < gspca_dev->sd_desc->nctrls; |
| 1013 | i++, ctrl++) |
| 1014 | ctrl->val = ctrl->def; |
| 1015 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | static int wxh_to_mode(struct gspca_dev *gspca_dev, |
| 1019 | int width, int height) |
| 1020 | { |
| 1021 | int i; |
| 1022 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1023 | for (i = gspca_dev->cam.nmodes; --i > 0; ) { |
| 1024 | if (width >= gspca_dev->cam.cam_mode[i].width |
| 1025 | && height >= gspca_dev->cam.cam_mode[i].height) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1026 | break; |
| 1027 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1028 | return i; |
| 1029 | } |
| 1030 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1031 | /* |
| 1032 | * search a mode with the right pixel format |
| 1033 | */ |
| 1034 | static int gspca_get_mode(struct gspca_dev *gspca_dev, |
| 1035 | int mode, |
| 1036 | int pixfmt) |
| 1037 | { |
| 1038 | int modeU, modeD; |
| 1039 | |
| 1040 | modeU = modeD = mode; |
| 1041 | while ((modeU < gspca_dev->cam.nmodes) || modeD >= 0) { |
| 1042 | if (--modeD >= 0) { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1043 | if (gspca_dev->cam.cam_mode[modeD].pixelformat |
| 1044 | == pixfmt) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1045 | return modeD; |
| 1046 | } |
| 1047 | if (++modeU < gspca_dev->cam.nmodes) { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1048 | if (gspca_dev->cam.cam_mode[modeU].pixelformat |
| 1049 | == pixfmt) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1050 | return modeU; |
| 1051 | } |
| 1052 | } |
| 1053 | return -EINVAL; |
| 1054 | } |
| 1055 | |
Brian Johnson | af1d9af | 2009-07-19 05:29:20 -0300 | [diff] [blame] | 1056 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1057 | static int vidioc_g_register(struct file *file, void *priv, |
| 1058 | struct v4l2_dbg_register *reg) |
| 1059 | { |
| 1060 | int ret; |
| 1061 | struct gspca_dev *gspca_dev = priv; |
| 1062 | |
| 1063 | if (!gspca_dev->sd_desc->get_chip_ident) |
| 1064 | return -EINVAL; |
| 1065 | |
| 1066 | if (!gspca_dev->sd_desc->get_register) |
| 1067 | return -EINVAL; |
| 1068 | |
| 1069 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1070 | return -ERESTARTSYS; |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1071 | gspca_dev->usb_err = 0; |
Brian Johnson | af1d9af | 2009-07-19 05:29:20 -0300 | [diff] [blame] | 1072 | if (gspca_dev->present) |
| 1073 | ret = gspca_dev->sd_desc->get_register(gspca_dev, reg); |
| 1074 | else |
| 1075 | ret = -ENODEV; |
| 1076 | mutex_unlock(&gspca_dev->usb_lock); |
| 1077 | |
| 1078 | return ret; |
| 1079 | } |
| 1080 | |
| 1081 | static int vidioc_s_register(struct file *file, void *priv, |
| 1082 | struct v4l2_dbg_register *reg) |
| 1083 | { |
| 1084 | int ret; |
| 1085 | struct gspca_dev *gspca_dev = priv; |
| 1086 | |
| 1087 | if (!gspca_dev->sd_desc->get_chip_ident) |
| 1088 | return -EINVAL; |
| 1089 | |
| 1090 | if (!gspca_dev->sd_desc->set_register) |
| 1091 | return -EINVAL; |
| 1092 | |
| 1093 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1094 | return -ERESTARTSYS; |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1095 | gspca_dev->usb_err = 0; |
Brian Johnson | af1d9af | 2009-07-19 05:29:20 -0300 | [diff] [blame] | 1096 | if (gspca_dev->present) |
| 1097 | ret = gspca_dev->sd_desc->set_register(gspca_dev, reg); |
| 1098 | else |
| 1099 | ret = -ENODEV; |
| 1100 | mutex_unlock(&gspca_dev->usb_lock); |
| 1101 | |
| 1102 | return ret; |
| 1103 | } |
| 1104 | #endif |
| 1105 | |
| 1106 | static int vidioc_g_chip_ident(struct file *file, void *priv, |
| 1107 | struct v4l2_dbg_chip_ident *chip) |
| 1108 | { |
| 1109 | int ret; |
| 1110 | struct gspca_dev *gspca_dev = priv; |
| 1111 | |
| 1112 | if (!gspca_dev->sd_desc->get_chip_ident) |
| 1113 | return -EINVAL; |
| 1114 | |
| 1115 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1116 | return -ERESTARTSYS; |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1117 | gspca_dev->usb_err = 0; |
Brian Johnson | af1d9af | 2009-07-19 05:29:20 -0300 | [diff] [blame] | 1118 | if (gspca_dev->present) |
| 1119 | ret = gspca_dev->sd_desc->get_chip_ident(gspca_dev, chip); |
| 1120 | else |
| 1121 | ret = -ENODEV; |
| 1122 | mutex_unlock(&gspca_dev->usb_lock); |
| 1123 | |
| 1124 | return ret; |
| 1125 | } |
| 1126 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1127 | static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1128 | struct v4l2_fmtdesc *fmtdesc) |
| 1129 | { |
| 1130 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1131 | int i, j, index; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1132 | __u32 fmt_tb[8]; |
| 1133 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1134 | /* give an index to each format */ |
| 1135 | index = 0; |
| 1136 | j = 0; |
| 1137 | for (i = gspca_dev->cam.nmodes; --i >= 0; ) { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1138 | fmt_tb[index] = gspca_dev->cam.cam_mode[i].pixelformat; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1139 | j = 0; |
| 1140 | for (;;) { |
| 1141 | if (fmt_tb[j] == fmt_tb[index]) |
| 1142 | break; |
| 1143 | j++; |
| 1144 | } |
| 1145 | if (j == index) { |
| 1146 | if (fmtdesc->index == index) |
| 1147 | break; /* new format */ |
| 1148 | index++; |
Julia Lawall | 8029712 | 2008-11-12 23:18:21 -0300 | [diff] [blame] | 1149 | if (index >= ARRAY_SIZE(fmt_tb)) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1150 | return -EINVAL; |
| 1151 | } |
| 1152 | } |
| 1153 | if (i < 0) |
| 1154 | return -EINVAL; /* no more format */ |
| 1155 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1156 | fmtdesc->pixelformat = fmt_tb[index]; |
Jean-François Moine | b796fb6 | 2011-08-10 07:32:57 -0300 | [diff] [blame] | 1157 | if (gspca_dev->cam.cam_mode[i].sizeimage < |
| 1158 | gspca_dev->cam.cam_mode[i].width * |
| 1159 | gspca_dev->cam.cam_mode[i].height) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1160 | fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED; |
| 1161 | fmtdesc->description[0] = fmtdesc->pixelformat & 0xff; |
| 1162 | fmtdesc->description[1] = (fmtdesc->pixelformat >> 8) & 0xff; |
| 1163 | fmtdesc->description[2] = (fmtdesc->pixelformat >> 16) & 0xff; |
| 1164 | fmtdesc->description[3] = fmtdesc->pixelformat >> 24; |
| 1165 | fmtdesc->description[4] = '\0'; |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1169 | static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1170 | struct v4l2_format *fmt) |
| 1171 | { |
| 1172 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1173 | int mode; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1174 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1175 | mode = gspca_dev->curr_mode; |
| 1176 | memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode], |
| 1177 | sizeof fmt->fmt.pix); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1178 | return 0; |
| 1179 | } |
| 1180 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1181 | static int try_fmt_vid_cap(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1182 | struct v4l2_format *fmt) |
| 1183 | { |
Hans de Goede | 24c530b | 2008-07-04 17:55:18 -0300 | [diff] [blame] | 1184 | int w, h, mode, mode2; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1185 | |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1186 | w = fmt->fmt.pix.width; |
| 1187 | h = fmt->fmt.pix.height; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1188 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 1189 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1190 | if (gspca_debug & D_CONF) |
| 1191 | PDEBUG_MODE("try fmt cap", fmt->fmt.pix.pixelformat, w, h); |
| 1192 | #endif |
| 1193 | /* search the closest mode for width and height */ |
| 1194 | mode = wxh_to_mode(gspca_dev, w, h); |
| 1195 | |
| 1196 | /* OK if right palette */ |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1197 | if (gspca_dev->cam.cam_mode[mode].pixelformat |
| 1198 | != fmt->fmt.pix.pixelformat) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1199 | |
| 1200 | /* else, search the closest mode with the same pixel format */ |
| 1201 | mode2 = gspca_get_mode(gspca_dev, mode, |
| 1202 | fmt->fmt.pix.pixelformat); |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1203 | if (mode2 >= 0) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1204 | mode = mode2; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1205 | /* else |
| 1206 | ; * no chance, return this mode */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1207 | } |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 1208 | memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode], |
| 1209 | sizeof fmt->fmt.pix); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1210 | return mode; /* used when s_fmt */ |
| 1211 | } |
| 1212 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1213 | static int vidioc_try_fmt_vid_cap(struct file *file, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1214 | void *priv, |
| 1215 | struct v4l2_format *fmt) |
| 1216 | { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1217 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1218 | int ret; |
| 1219 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1220 | ret = try_fmt_vid_cap(gspca_dev, fmt); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1221 | if (ret < 0) |
| 1222 | return ret; |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1226 | static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1227 | struct v4l2_format *fmt) |
| 1228 | { |
| 1229 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1230 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1231 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1232 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1233 | return -ERESTARTSYS; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1234 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1235 | ret = try_fmt_vid_cap(gspca_dev, fmt); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1236 | if (ret < 0) |
| 1237 | goto out; |
| 1238 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1239 | if (gspca_dev->nframes != 0 |
| 1240 | && fmt->fmt.pix.sizeimage > gspca_dev->frsz) { |
| 1241 | ret = -EINVAL; |
| 1242 | goto out; |
| 1243 | } |
| 1244 | |
Jean-Francois Moine | 50a871f | 2008-06-30 19:47:33 -0300 | [diff] [blame] | 1245 | if (ret == gspca_dev->curr_mode) { |
| 1246 | ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1247 | goto out; /* same mode */ |
Jean-Francois Moine | 50a871f | 2008-06-30 19:47:33 -0300 | [diff] [blame] | 1248 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1249 | |
| 1250 | if (gspca_dev->streaming) { |
| 1251 | ret = -EBUSY; |
| 1252 | goto out; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1253 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1254 | gspca_dev->width = fmt->fmt.pix.width; |
| 1255 | gspca_dev->height = fmt->fmt.pix.height; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1256 | gspca_dev->pixfmt = fmt->fmt.pix.pixelformat; |
| 1257 | gspca_dev->curr_mode = ret; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1258 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1259 | ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1260 | out: |
| 1261 | mutex_unlock(&gspca_dev->queue_lock); |
| 1262 | return ret; |
| 1263 | } |
| 1264 | |
Hans de Goede | 11c635a | 2009-05-25 15:04:22 -0300 | [diff] [blame] | 1265 | static int vidioc_enum_framesizes(struct file *file, void *priv, |
| 1266 | struct v4l2_frmsizeenum *fsize) |
| 1267 | { |
| 1268 | struct gspca_dev *gspca_dev = priv; |
| 1269 | int i; |
| 1270 | __u32 index = 0; |
| 1271 | |
| 1272 | for (i = 0; i < gspca_dev->cam.nmodes; i++) { |
| 1273 | if (fsize->pixel_format != |
| 1274 | gspca_dev->cam.cam_mode[i].pixelformat) |
| 1275 | continue; |
| 1276 | |
| 1277 | if (fsize->index == index) { |
| 1278 | fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 1279 | fsize->discrete.width = |
| 1280 | gspca_dev->cam.cam_mode[i].width; |
| 1281 | fsize->discrete.height = |
| 1282 | gspca_dev->cam.cam_mode[i].height; |
| 1283 | return 0; |
| 1284 | } |
| 1285 | index++; |
| 1286 | } |
| 1287 | |
| 1288 | return -EINVAL; |
| 1289 | } |
| 1290 | |
Antonio Ospite | 28ffe77 | 2009-12-02 06:18:46 -0300 | [diff] [blame] | 1291 | static int vidioc_enum_frameintervals(struct file *filp, void *priv, |
| 1292 | struct v4l2_frmivalenum *fival) |
| 1293 | { |
| 1294 | struct gspca_dev *gspca_dev = priv; |
| 1295 | int mode = wxh_to_mode(gspca_dev, fival->width, fival->height); |
| 1296 | __u32 i; |
| 1297 | |
| 1298 | if (gspca_dev->cam.mode_framerates == NULL || |
| 1299 | gspca_dev->cam.mode_framerates[mode].nrates == 0) |
| 1300 | return -EINVAL; |
| 1301 | |
| 1302 | if (fival->pixel_format != |
| 1303 | gspca_dev->cam.cam_mode[mode].pixelformat) |
| 1304 | return -EINVAL; |
| 1305 | |
| 1306 | for (i = 0; i < gspca_dev->cam.mode_framerates[mode].nrates; i++) { |
| 1307 | if (fival->index == i) { |
| 1308 | fival->type = V4L2_FRMSIZE_TYPE_DISCRETE; |
| 1309 | fival->discrete.numerator = 1; |
| 1310 | fival->discrete.denominator = |
| 1311 | gspca_dev->cam.mode_framerates[mode].rates[i]; |
| 1312 | return 0; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | return -EINVAL; |
| 1317 | } |
| 1318 | |
Hans de Goede | d018230 | 2008-11-19 17:10:47 -0300 | [diff] [blame] | 1319 | static void gspca_release(struct video_device *vfd) |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 1320 | { |
Hans de Goede | d018230 | 2008-11-19 17:10:47 -0300 | [diff] [blame] | 1321 | struct gspca_dev *gspca_dev = container_of(vfd, struct gspca_dev, vdev); |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 1322 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1323 | PDEBUG(D_PROBE, "%s released", |
| 1324 | video_device_node_name(&gspca_dev->vdev)); |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 1325 | |
| 1326 | kfree(gspca_dev->usb_buf); |
| 1327 | kfree(gspca_dev); |
| 1328 | } |
| 1329 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1330 | static int dev_open(struct file *file) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1331 | { |
| 1332 | struct gspca_dev *gspca_dev; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1333 | |
Jean-Francois Moine | 0d07e24 | 2009-10-01 13:44:49 -0300 | [diff] [blame] | 1334 | PDEBUG(D_STREAM, "[%s] open", current->comm); |
Jean-Francois Moine | a12ca6a | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 1335 | gspca_dev = (struct gspca_dev *) video_devdata(file); |
Hans de Goede | 7f6eb11 | 2010-12-30 20:20:09 -0300 | [diff] [blame] | 1336 | if (!gspca_dev->present) |
| 1337 | return -ENODEV; |
Jean-Francois Moine | 5c4fa002 | 2008-11-18 15:52:31 -0300 | [diff] [blame] | 1338 | |
| 1339 | /* protect the subdriver against rmmod */ |
Hans de Goede | 7f6eb11 | 2010-12-30 20:20:09 -0300 | [diff] [blame] | 1340 | if (!try_module_get(gspca_dev->module)) |
| 1341 | return -ENODEV; |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 1342 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1343 | file->private_data = gspca_dev; |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 1344 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1345 | /* activate the v4l2 debug */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1346 | if (gspca_debug & D_V4L2) |
Jean-Francois Moine | a12ca6a | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 1347 | gspca_dev->vdev.debug |= V4L2_DEBUG_IOCTL |
Frank Zago | 9de436c | 2008-09-15 05:20:38 -0300 | [diff] [blame] | 1348 | | V4L2_DEBUG_IOCTL_ARG; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1349 | else |
Jean-Francois Moine | a12ca6a | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 1350 | gspca_dev->vdev.debug &= ~(V4L2_DEBUG_IOCTL |
Frank Zago | 9de436c | 2008-09-15 05:20:38 -0300 | [diff] [blame] | 1351 | | V4L2_DEBUG_IOCTL_ARG); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1352 | #endif |
Hans de Goede | 7f6eb11 | 2010-12-30 20:20:09 -0300 | [diff] [blame] | 1353 | return 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1354 | } |
| 1355 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1356 | static int dev_close(struct file *file) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1357 | { |
| 1358 | struct gspca_dev *gspca_dev = file->private_data; |
| 1359 | |
Jean-Francois Moine | 0d07e24 | 2009-10-01 13:44:49 -0300 | [diff] [blame] | 1360 | PDEBUG(D_STREAM, "[%s] close", current->comm); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1361 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1362 | return -ERESTARTSYS; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1363 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1364 | /* if the file did the capture, free the streaming resources */ |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1365 | if (gspca_dev->capt_file == file) { |
Jean-Francois Moine | a1e8288 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 1366 | if (gspca_dev->streaming) { |
| 1367 | mutex_lock(&gspca_dev->usb_lock); |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1368 | gspca_dev->usb_err = 0; |
Jean-Francois Moine | a1e8288 | 2008-09-03 17:12:17 -0300 | [diff] [blame] | 1369 | gspca_stream_off(gspca_dev); |
| 1370 | mutex_unlock(&gspca_dev->usb_lock); |
| 1371 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1372 | frame_free(gspca_dev); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1373 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1374 | file->private_data = NULL; |
Jean-Francois Moine | 5c4fa002 | 2008-11-18 15:52:31 -0300 | [diff] [blame] | 1375 | module_put(gspca_dev->module); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1376 | mutex_unlock(&gspca_dev->queue_lock); |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 1377 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1378 | PDEBUG(D_STREAM, "close done"); |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 1379 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | static int vidioc_querycap(struct file *file, void *priv, |
| 1384 | struct v4l2_capability *cap) |
| 1385 | { |
| 1386 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1387 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1388 | |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1389 | /* protect the access to the usb device */ |
| 1390 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1391 | return -ERESTARTSYS; |
| 1392 | if (!gspca_dev->present) { |
| 1393 | ret = -ENODEV; |
| 1394 | goto out; |
| 1395 | } |
Hans de Goede | e7d712c | 2011-06-05 14:58:46 -0300 | [diff] [blame] | 1396 | strlcpy((char *) cap->driver, gspca_dev->sd_desc->name, |
Jean-François Moine | d851859 | 2010-12-28 06:55:01 -0300 | [diff] [blame] | 1397 | sizeof cap->driver); |
Jean-Francois Moine | c6edaf1 | 2008-07-23 03:24:06 -0300 | [diff] [blame] | 1398 | if (gspca_dev->dev->product != NULL) { |
Hans de Goede | e7d712c | 2011-06-05 14:58:46 -0300 | [diff] [blame] | 1399 | strlcpy((char *) cap->card, gspca_dev->dev->product, |
Jean-Francois Moine | c6edaf1 | 2008-07-23 03:24:06 -0300 | [diff] [blame] | 1400 | sizeof cap->card); |
| 1401 | } else { |
Jean-François Moine | d851859 | 2010-12-28 06:55:01 -0300 | [diff] [blame] | 1402 | snprintf((char *) cap->card, sizeof cap->card, |
Jean-Francois Moine | c6edaf1 | 2008-07-23 03:24:06 -0300 | [diff] [blame] | 1403 | "USB Camera (%04x:%04x)", |
| 1404 | le16_to_cpu(gspca_dev->dev->descriptor.idVendor), |
| 1405 | le16_to_cpu(gspca_dev->dev->descriptor.idProduct)); |
| 1406 | } |
Jean-François Moine | d851859 | 2010-12-28 06:55:01 -0300 | [diff] [blame] | 1407 | usb_make_path(gspca_dev->dev, (char *) cap->bus_info, |
| 1408 | sizeof(cap->bus_info)); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1409 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
| 1410 | | V4L2_CAP_STREAMING |
| 1411 | | V4L2_CAP_READWRITE; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1412 | ret = 0; |
| 1413 | out: |
| 1414 | mutex_unlock(&gspca_dev->usb_lock); |
| 1415 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1416 | } |
| 1417 | |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1418 | static int get_ctrl(struct gspca_dev *gspca_dev, |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1419 | int id) |
| 1420 | { |
| 1421 | const struct ctrl *ctrls; |
| 1422 | int i; |
| 1423 | |
| 1424 | for (i = 0, ctrls = gspca_dev->sd_desc->ctrls; |
| 1425 | i < gspca_dev->sd_desc->nctrls; |
| 1426 | i++, ctrls++) { |
| 1427 | if (gspca_dev->ctrl_dis & (1 << i)) |
| 1428 | continue; |
| 1429 | if (id == ctrls->qctrl.id) |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1430 | return i; |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1431 | } |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1432 | return -1; |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1433 | } |
| 1434 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1435 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 1436 | struct v4l2_queryctrl *q_ctrl) |
| 1437 | { |
| 1438 | struct gspca_dev *gspca_dev = priv; |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1439 | const struct ctrl *ctrls; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1440 | struct gspca_ctrl *gspca_ctrl; |
| 1441 | int i, idx; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1442 | u32 id; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1443 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1444 | id = q_ctrl->id; |
| 1445 | if (id & V4L2_CTRL_FLAG_NEXT_CTRL) { |
| 1446 | id &= V4L2_CTRL_ID_MASK; |
| 1447 | id++; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1448 | idx = -1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1449 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1450 | if (gspca_dev->ctrl_dis & (1 << i)) |
Jean-Francois Moine | f50ba1b | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 1451 | continue; |
Hans de Goede | b8bfb5f | 2009-06-13 18:56:22 -0300 | [diff] [blame] | 1452 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id < id) |
Jean-Francois Moine | f50ba1b | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 1453 | continue; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1454 | if (idx >= 0 |
| 1455 | && gspca_dev->sd_desc->ctrls[i].qctrl.id |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 1456 | > gspca_dev->sd_desc->ctrls[idx].qctrl.id) |
Hans de Goede | b8bfb5f | 2009-06-13 18:56:22 -0300 | [diff] [blame] | 1457 | continue; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1458 | idx = i; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1459 | } |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1460 | } else { |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1461 | idx = get_ctrl(gspca_dev, id); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1462 | } |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1463 | if (idx < 0) |
| 1464 | return -EINVAL; |
| 1465 | ctrls = &gspca_dev->sd_desc->ctrls[idx]; |
| 1466 | memcpy(q_ctrl, &ctrls->qctrl, sizeof *q_ctrl); |
| 1467 | if (gspca_dev->cam.ctrls != NULL) { |
| 1468 | gspca_ctrl = &gspca_dev->cam.ctrls[idx]; |
| 1469 | q_ctrl->default_value = gspca_ctrl->def; |
| 1470 | q_ctrl->minimum = gspca_ctrl->min; |
| 1471 | q_ctrl->maximum = gspca_ctrl->max; |
| 1472 | } |
| 1473 | if (gspca_dev->ctrl_inac & (1 << idx)) |
Jean-Francois Moine | 4af8566 | 2009-11-12 15:59:27 -0300 | [diff] [blame] | 1474 | q_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; |
Jean-Francois Moine | f50ba1b | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 1475 | return 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 1479 | struct v4l2_control *ctrl) |
| 1480 | { |
| 1481 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1482 | const struct ctrl *ctrls; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1483 | struct gspca_ctrl *gspca_ctrl; |
| 1484 | int idx, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1485 | |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1486 | idx = get_ctrl(gspca_dev, ctrl->id); |
| 1487 | if (idx < 0) |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1488 | return -EINVAL; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1489 | if (gspca_dev->ctrl_inac & (1 << idx)) |
| 1490 | return -EINVAL; |
| 1491 | ctrls = &gspca_dev->sd_desc->ctrls[idx]; |
| 1492 | if (gspca_dev->cam.ctrls != NULL) { |
| 1493 | gspca_ctrl = &gspca_dev->cam.ctrls[idx]; |
| 1494 | if (ctrl->value < gspca_ctrl->min |
| 1495 | || ctrl->value > gspca_ctrl->max) |
| 1496 | return -ERANGE; |
| 1497 | } else { |
| 1498 | gspca_ctrl = NULL; |
| 1499 | if (ctrl->value < ctrls->qctrl.minimum |
| 1500 | || ctrl->value > ctrls->qctrl.maximum) |
| 1501 | return -ERANGE; |
| 1502 | } |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1503 | PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value); |
| 1504 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1505 | return -ERESTARTSYS; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1506 | if (!gspca_dev->present) { |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1507 | ret = -ENODEV; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1508 | goto out; |
| 1509 | } |
| 1510 | gspca_dev->usb_err = 0; |
| 1511 | if (ctrls->set != NULL) { |
| 1512 | ret = ctrls->set(gspca_dev, ctrl->value); |
| 1513 | goto out; |
| 1514 | } |
| 1515 | if (gspca_ctrl != NULL) { |
| 1516 | gspca_ctrl->val = ctrl->value; |
| 1517 | if (ctrls->set_control != NULL |
| 1518 | && gspca_dev->streaming) |
| 1519 | ctrls->set_control(gspca_dev); |
| 1520 | } |
| 1521 | ret = gspca_dev->usb_err; |
| 1522 | out: |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1523 | mutex_unlock(&gspca_dev->usb_lock); |
| 1524 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 1528 | struct v4l2_control *ctrl) |
| 1529 | { |
| 1530 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1531 | const struct ctrl *ctrls; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1532 | int idx, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1533 | |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1534 | idx = get_ctrl(gspca_dev, ctrl->id); |
| 1535 | if (idx < 0) |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1536 | return -EINVAL; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1537 | ctrls = &gspca_dev->sd_desc->ctrls[idx]; |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1538 | |
| 1539 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1540 | return -ERESTARTSYS; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1541 | if (!gspca_dev->present) { |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1542 | ret = -ENODEV; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 1543 | goto out; |
| 1544 | } |
| 1545 | gspca_dev->usb_err = 0; |
| 1546 | if (ctrls->get != NULL) { |
| 1547 | ret = ctrls->get(gspca_dev, &ctrl->value); |
| 1548 | goto out; |
| 1549 | } |
| 1550 | if (gspca_dev->cam.ctrls != NULL) |
| 1551 | ctrl->value = gspca_dev->cam.ctrls[idx].val; |
| 1552 | ret = 0; |
| 1553 | out: |
Hans de Goede | a0001a2 | 2009-06-10 04:52:18 -0300 | [diff] [blame] | 1554 | mutex_unlock(&gspca_dev->usb_lock); |
| 1555 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | static int vidioc_querymenu(struct file *file, void *priv, |
| 1559 | struct v4l2_querymenu *qmenu) |
| 1560 | { |
| 1561 | struct gspca_dev *gspca_dev = priv; |
| 1562 | |
| 1563 | if (!gspca_dev->sd_desc->querymenu) |
| 1564 | return -EINVAL; |
| 1565 | return gspca_dev->sd_desc->querymenu(gspca_dev, qmenu); |
| 1566 | } |
| 1567 | |
| 1568 | static int vidioc_enum_input(struct file *file, void *priv, |
| 1569 | struct v4l2_input *input) |
| 1570 | { |
| 1571 | struct gspca_dev *gspca_dev = priv; |
| 1572 | |
| 1573 | if (input->index != 0) |
| 1574 | return -EINVAL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1575 | input->type = V4L2_INPUT_TYPE_CAMERA; |
Adam Baker | dfa76fa | 2009-03-29 19:17:10 -0300 | [diff] [blame] | 1576 | input->status = gspca_dev->cam.input_flags; |
Hans de Goede | e7d712c | 2011-06-05 14:58:46 -0300 | [diff] [blame] | 1577 | strlcpy(input->name, gspca_dev->sd_desc->name, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1578 | sizeof input->name); |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
| 1582 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 1583 | { |
| 1584 | *i = 0; |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
| 1588 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 1589 | { |
| 1590 | if (i > 0) |
| 1591 | return -EINVAL; |
| 1592 | return (0); |
| 1593 | } |
| 1594 | |
| 1595 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 1596 | struct v4l2_requestbuffers *rb) |
| 1597 | { |
| 1598 | struct gspca_dev *gspca_dev = priv; |
Jean-François Moine | 832d0a9 | 2010-04-09 06:07:58 -0300 | [diff] [blame] | 1599 | int i, ret = 0, streaming; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1600 | |
Jean-François Moine | a2ba6f2 | 2010-07-14 06:21:16 -0300 | [diff] [blame] | 1601 | i = rb->memory; /* (avoid compilation warning) */ |
| 1602 | switch (i) { |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1603 | case GSPCA_MEMORY_READ: /* (internal call) */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1604 | case V4L2_MEMORY_MMAP: |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1605 | case V4L2_MEMORY_USERPTR: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1606 | break; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1607 | default: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1608 | return -EINVAL; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1609 | } |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1610 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1611 | return -ERESTARTSYS; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1612 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1613 | if (gspca_dev->memory != GSPCA_MEMORY_NO |
Hans de Goede | ce5610b | 2010-12-31 07:41:54 -0300 | [diff] [blame] | 1614 | && gspca_dev->memory != GSPCA_MEMORY_READ |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1615 | && gspca_dev->memory != rb->memory) { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1616 | ret = -EBUSY; |
| 1617 | goto out; |
| 1618 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1619 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1620 | /* only one file may do the capture */ |
| 1621 | if (gspca_dev->capt_file != NULL |
| 1622 | && gspca_dev->capt_file != file) { |
| 1623 | ret = -EBUSY; |
| 1624 | goto out; |
| 1625 | } |
| 1626 | |
| 1627 | /* if allocated, the buffers must not be mapped */ |
| 1628 | for (i = 0; i < gspca_dev->nframes; i++) { |
| 1629 | if (gspca_dev->frame[i].vma_use_count) { |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1630 | ret = -EBUSY; |
| 1631 | goto out; |
| 1632 | } |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | /* stop streaming */ |
Jean-François Moine | 832d0a9 | 2010-04-09 06:07:58 -0300 | [diff] [blame] | 1636 | streaming = gspca_dev->streaming; |
| 1637 | if (streaming) { |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1638 | mutex_lock(&gspca_dev->usb_lock); |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1639 | gspca_dev->usb_err = 0; |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1640 | gspca_stream_off(gspca_dev); |
| 1641 | mutex_unlock(&gspca_dev->usb_lock); |
Jean-François Moine | 59929ce | 2011-03-14 05:33:01 -0300 | [diff] [blame] | 1642 | |
| 1643 | /* Don't restart the stream when switching from read |
| 1644 | * to mmap mode */ |
| 1645 | if (gspca_dev->memory == GSPCA_MEMORY_READ) |
| 1646 | streaming = 0; |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | /* free the previous allocated buffers, if any */ |
Hans de Goede | d642de2 | 2010-12-31 04:51:36 -0300 | [diff] [blame] | 1650 | if (gspca_dev->nframes != 0) |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1651 | frame_free(gspca_dev); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1652 | if (rb->count == 0) /* unrequest */ |
| 1653 | goto out; |
Hans de Goede | d642de2 | 2010-12-31 04:51:36 -0300 | [diff] [blame] | 1654 | ret = frame_alloc(gspca_dev, file, rb->memory, rb->count); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1655 | if (ret == 0) { |
| 1656 | rb->count = gspca_dev->nframes; |
Jean-François Moine | 832d0a9 | 2010-04-09 06:07:58 -0300 | [diff] [blame] | 1657 | if (streaming) |
| 1658 | ret = gspca_init_transfer(gspca_dev); |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1659 | } |
| 1660 | out: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1661 | mutex_unlock(&gspca_dev->queue_lock); |
| 1662 | PDEBUG(D_STREAM, "reqbufs st:%d c:%d", ret, rb->count); |
| 1663 | return ret; |
| 1664 | } |
| 1665 | |
| 1666 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1667 | struct v4l2_buffer *v4l2_buf) |
| 1668 | { |
| 1669 | struct gspca_dev *gspca_dev = priv; |
| 1670 | struct gspca_frame *frame; |
| 1671 | |
Jean-Francois Moine | 13752bd | 2008-12-19 15:08:51 -0300 | [diff] [blame] | 1672 | if (v4l2_buf->index < 0 |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1673 | || v4l2_buf->index >= gspca_dev->nframes) |
| 1674 | return -EINVAL; |
| 1675 | |
| 1676 | frame = &gspca_dev->frame[v4l2_buf->index]; |
| 1677 | memcpy(v4l2_buf, &frame->v4l2_buf, sizeof *v4l2_buf); |
| 1678 | return 0; |
| 1679 | } |
| 1680 | |
| 1681 | static int vidioc_streamon(struct file *file, void *priv, |
| 1682 | enum v4l2_buf_type buf_type) |
| 1683 | { |
| 1684 | struct gspca_dev *gspca_dev = priv; |
| 1685 | int ret; |
| 1686 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1687 | if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1688 | return -EINVAL; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1689 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1690 | return -ERESTARTSYS; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1691 | |
Jean-François Moine | 18bf99a | 2010-04-09 06:06:11 -0300 | [diff] [blame] | 1692 | /* check the capture file */ |
| 1693 | if (gspca_dev->capt_file != file) { |
| 1694 | ret = -EBUSY; |
| 1695 | goto out; |
| 1696 | } |
| 1697 | |
Jean-Francois Moine | 1edabe7 | 2008-12-19 15:17:25 -0300 | [diff] [blame] | 1698 | if (gspca_dev->nframes == 0 |
| 1699 | || !(gspca_dev->frame[0].v4l2_buf.flags & V4L2_BUF_FLAG_QUEUED)) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1700 | ret = -EINVAL; |
| 1701 | goto out; |
| 1702 | } |
| 1703 | if (!gspca_dev->streaming) { |
| 1704 | ret = gspca_init_transfer(gspca_dev); |
| 1705 | if (ret < 0) |
| 1706 | goto out; |
| 1707 | } |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 1708 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1709 | if (gspca_debug & D_STREAM) { |
| 1710 | PDEBUG_MODE("stream on OK", |
| 1711 | gspca_dev->pixfmt, |
| 1712 | gspca_dev->width, |
| 1713 | gspca_dev->height); |
| 1714 | } |
| 1715 | #endif |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1716 | ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1717 | out: |
| 1718 | mutex_unlock(&gspca_dev->queue_lock); |
| 1719 | return ret; |
| 1720 | } |
| 1721 | |
| 1722 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1723 | enum v4l2_buf_type buf_type) |
| 1724 | { |
| 1725 | struct gspca_dev *gspca_dev = priv; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 1726 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1727 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1728 | if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1729 | return -EINVAL; |
Hans de Goede | 4e770f7 | 2010-12-30 13:11:21 -0300 | [diff] [blame] | 1730 | |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1731 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1732 | return -ERESTARTSYS; |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1733 | |
Hans de Goede | 4e770f7 | 2010-12-30 13:11:21 -0300 | [diff] [blame] | 1734 | if (!gspca_dev->streaming) { |
| 1735 | ret = 0; |
| 1736 | goto out; |
| 1737 | } |
| 1738 | |
Jean-François Moine | 18bf99a | 2010-04-09 06:06:11 -0300 | [diff] [blame] | 1739 | /* check the capture file */ |
| 1740 | if (gspca_dev->capt_file != file) { |
| 1741 | ret = -EBUSY; |
| 1742 | goto out; |
| 1743 | } |
| 1744 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1745 | /* stop streaming */ |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1746 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) { |
| 1747 | ret = -ERESTARTSYS; |
| 1748 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1749 | } |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1750 | gspca_dev->usb_err = 0; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1751 | gspca_stream_off(gspca_dev); |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1752 | mutex_unlock(&gspca_dev->usb_lock); |
Hans de Goede | 0d0ae15 | 2010-12-31 17:17:51 -0300 | [diff] [blame] | 1753 | /* In case another thread is waiting in dqbuf */ |
| 1754 | wake_up_interruptible(&gspca_dev->wq); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1755 | |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 1756 | /* empty the transfer queues */ |
| 1757 | atomic_set(&gspca_dev->fr_q, 0); |
| 1758 | atomic_set(&gspca_dev->fr_i, 0); |
| 1759 | gspca_dev->fr_o = 0; |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1760 | ret = 0; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1761 | out: |
| 1762 | mutex_unlock(&gspca_dev->queue_lock); |
| 1763 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | static int vidioc_g_jpegcomp(struct file *file, void *priv, |
| 1767 | struct v4l2_jpegcompression *jpegcomp) |
| 1768 | { |
| 1769 | struct gspca_dev *gspca_dev = priv; |
| 1770 | int ret; |
| 1771 | |
| 1772 | if (!gspca_dev->sd_desc->get_jcomp) |
| 1773 | return -EINVAL; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1774 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1775 | return -ERESTARTSYS; |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1776 | gspca_dev->usb_err = 0; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1777 | if (gspca_dev->present) |
| 1778 | ret = gspca_dev->sd_desc->get_jcomp(gspca_dev, jpegcomp); |
| 1779 | else |
| 1780 | ret = -ENODEV; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1781 | mutex_unlock(&gspca_dev->usb_lock); |
| 1782 | return ret; |
| 1783 | } |
| 1784 | |
| 1785 | static int vidioc_s_jpegcomp(struct file *file, void *priv, |
| 1786 | struct v4l2_jpegcompression *jpegcomp) |
| 1787 | { |
| 1788 | struct gspca_dev *gspca_dev = priv; |
| 1789 | int ret; |
| 1790 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1791 | if (!gspca_dev->sd_desc->set_jcomp) |
| 1792 | return -EINVAL; |
Jim Paris | f86d4a9 | 2008-12-10 05:50:44 -0300 | [diff] [blame] | 1793 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1794 | return -ERESTARTSYS; |
Jean-Francois Moine | 8c4ebae | 2009-12-02 07:14:33 -0300 | [diff] [blame] | 1795 | gspca_dev->usb_err = 0; |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1796 | if (gspca_dev->present) |
| 1797 | ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp); |
| 1798 | else |
| 1799 | ret = -ENODEV; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1800 | mutex_unlock(&gspca_dev->usb_lock); |
| 1801 | return ret; |
| 1802 | } |
| 1803 | |
| 1804 | static int vidioc_g_parm(struct file *filp, void *priv, |
| 1805 | struct v4l2_streamparm *parm) |
| 1806 | { |
| 1807 | struct gspca_dev *gspca_dev = priv; |
| 1808 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1809 | parm->parm.capture.readbuffers = gspca_dev->nbufread; |
Jim Paris | 627a5ef | 2008-12-10 06:02:42 -0300 | [diff] [blame] | 1810 | |
| 1811 | if (gspca_dev->sd_desc->get_streamparm) { |
| 1812 | int ret; |
| 1813 | |
| 1814 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1815 | return -ERESTARTSYS; |
Jean-François Moine | 668f44a | 2010-12-25 13:46:14 -0300 | [diff] [blame] | 1816 | if (gspca_dev->present) { |
| 1817 | gspca_dev->usb_err = 0; |
| 1818 | gspca_dev->sd_desc->get_streamparm(gspca_dev, parm); |
| 1819 | ret = gspca_dev->usb_err; |
| 1820 | } else { |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1821 | ret = -ENODEV; |
Jean-François Moine | 668f44a | 2010-12-25 13:46:14 -0300 | [diff] [blame] | 1822 | } |
Jim Paris | 627a5ef | 2008-12-10 06:02:42 -0300 | [diff] [blame] | 1823 | mutex_unlock(&gspca_dev->usb_lock); |
| 1824 | return ret; |
| 1825 | } |
| 1826 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | static int vidioc_s_parm(struct file *filp, void *priv, |
| 1831 | struct v4l2_streamparm *parm) |
| 1832 | { |
| 1833 | struct gspca_dev *gspca_dev = priv; |
| 1834 | int n; |
| 1835 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1836 | n = parm->parm.capture.readbuffers; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 1837 | if (n == 0 || n >= GSPCA_MAX_FRAMES) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1838 | parm->parm.capture.readbuffers = gspca_dev->nbufread; |
| 1839 | else |
| 1840 | gspca_dev->nbufread = n; |
Jim Paris | 627a5ef | 2008-12-10 06:02:42 -0300 | [diff] [blame] | 1841 | |
| 1842 | if (gspca_dev->sd_desc->set_streamparm) { |
| 1843 | int ret; |
| 1844 | |
| 1845 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1846 | return -ERESTARTSYS; |
Jean-François Moine | 668f44a | 2010-12-25 13:46:14 -0300 | [diff] [blame] | 1847 | if (gspca_dev->present) { |
| 1848 | gspca_dev->usb_err = 0; |
| 1849 | gspca_dev->sd_desc->set_streamparm(gspca_dev, parm); |
| 1850 | ret = gspca_dev->usb_err; |
| 1851 | } else { |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 1852 | ret = -ENODEV; |
Jean-François Moine | 668f44a | 2010-12-25 13:46:14 -0300 | [diff] [blame] | 1853 | } |
Jim Paris | 627a5ef | 2008-12-10 06:02:42 -0300 | [diff] [blame] | 1854 | mutex_unlock(&gspca_dev->usb_lock); |
| 1855 | return ret; |
| 1856 | } |
| 1857 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1858 | return 0; |
| 1859 | } |
| 1860 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1861 | static int dev_mmap(struct file *file, struct vm_area_struct *vma) |
| 1862 | { |
| 1863 | struct gspca_dev *gspca_dev = file->private_data; |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 1864 | struct gspca_frame *frame; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1865 | struct page *page; |
| 1866 | unsigned long addr, start, size; |
| 1867 | int i, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1868 | |
| 1869 | start = vma->vm_start; |
| 1870 | size = vma->vm_end - vma->vm_start; |
| 1871 | PDEBUG(D_STREAM, "mmap start:%08x size:%d", (int) start, (int) size); |
| 1872 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1873 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1874 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1875 | if (!gspca_dev->present) { |
| 1876 | ret = -ENODEV; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1877 | goto out; |
| 1878 | } |
| 1879 | if (gspca_dev->capt_file != file) { |
| 1880 | ret = -EINVAL; |
| 1881 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1882 | } |
| 1883 | |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 1884 | frame = NULL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1885 | for (i = 0; i < gspca_dev->nframes; ++i) { |
| 1886 | if (gspca_dev->frame[i].v4l2_buf.memory != V4L2_MEMORY_MMAP) { |
| 1887 | PDEBUG(D_STREAM, "mmap bad memory type"); |
| 1888 | break; |
| 1889 | } |
| 1890 | if ((gspca_dev->frame[i].v4l2_buf.m.offset >> PAGE_SHIFT) |
| 1891 | == vma->vm_pgoff) { |
| 1892 | frame = &gspca_dev->frame[i]; |
| 1893 | break; |
| 1894 | } |
| 1895 | } |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 1896 | if (frame == NULL) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1897 | PDEBUG(D_STREAM, "mmap no frame buffer found"); |
| 1898 | ret = -EINVAL; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1899 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1900 | } |
Jean-François Moine | 38bff69 | 2010-06-24 05:19:58 -0300 | [diff] [blame] | 1901 | if (size != frame->v4l2_buf.length) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1902 | PDEBUG(D_STREAM, "mmap bad size"); |
| 1903 | ret = -EINVAL; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1904 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | /* |
| 1908 | * - VM_IO marks the area as being a mmaped region for I/O to a |
| 1909 | * device. It also prevents the region from being core dumped. |
| 1910 | */ |
| 1911 | vma->vm_flags |= VM_IO; |
| 1912 | |
| 1913 | addr = (unsigned long) frame->data; |
| 1914 | while (size > 0) { |
| 1915 | page = vmalloc_to_page((void *) addr); |
| 1916 | ret = vm_insert_page(vma, start, page); |
| 1917 | if (ret < 0) |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1918 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1919 | start += PAGE_SIZE; |
| 1920 | addr += PAGE_SIZE; |
| 1921 | size -= PAGE_SIZE; |
| 1922 | } |
| 1923 | |
Jean-Francois Moine | d50e257 | 2009-11-26 15:36:40 -0300 | [diff] [blame] | 1924 | vma->vm_ops = &gspca_vm_ops; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1925 | vma->vm_private_data = frame; |
| 1926 | gspca_vm_open(vma); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1927 | ret = 0; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1928 | out: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1929 | mutex_unlock(&gspca_dev->queue_lock); |
| 1930 | return ret; |
| 1931 | } |
| 1932 | |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1933 | static int frame_ready_nolock(struct gspca_dev *gspca_dev, struct file *file, |
| 1934 | enum v4l2_memory memory) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1935 | { |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1936 | if (!gspca_dev->present) |
| 1937 | return -ENODEV; |
| 1938 | if (gspca_dev->capt_file != file || gspca_dev->memory != memory || |
| 1939 | !gspca_dev->streaming) |
| 1940 | return -EINVAL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1941 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1942 | /* check if a frame is ready */ |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1943 | return gspca_dev->fr_o != atomic_read(&gspca_dev->fr_i); |
| 1944 | } |
Hans de Goede | 181b704 | 2008-11-19 17:16:26 -0300 | [diff] [blame] | 1945 | |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1946 | static int frame_ready(struct gspca_dev *gspca_dev, struct file *file, |
| 1947 | enum v4l2_memory memory) |
| 1948 | { |
| 1949 | int ret; |
Hans de Goede | 181b704 | 2008-11-19 17:16:26 -0300 | [diff] [blame] | 1950 | |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1951 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1952 | return -ERESTARTSYS; |
| 1953 | ret = frame_ready_nolock(gspca_dev, file, memory); |
| 1954 | mutex_unlock(&gspca_dev->queue_lock); |
| 1955 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /* |
| 1959 | * dequeue a video buffer |
| 1960 | * |
| 1961 | * If nonblock_ing is false, block until a buffer is available. |
| 1962 | */ |
| 1963 | static int vidioc_dqbuf(struct file *file, void *priv, |
| 1964 | struct v4l2_buffer *v4l2_buf) |
| 1965 | { |
| 1966 | struct gspca_dev *gspca_dev = priv; |
| 1967 | struct gspca_frame *frame; |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1968 | int i, j, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1969 | |
| 1970 | PDEBUG(D_FRAM, "dqbuf"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1971 | |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1972 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1973 | return -ERESTARTSYS; |
| 1974 | |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 1975 | for (;;) { |
| 1976 | ret = frame_ready_nolock(gspca_dev, file, v4l2_buf->memory); |
| 1977 | if (ret < 0) |
| 1978 | goto out; |
| 1979 | if (ret > 0) |
| 1980 | break; |
| 1981 | |
| 1982 | mutex_unlock(&gspca_dev->queue_lock); |
| 1983 | |
| 1984 | if (file->f_flags & O_NONBLOCK) |
| 1985 | return -EAGAIN; |
| 1986 | |
| 1987 | /* wait till a frame is ready */ |
| 1988 | ret = wait_event_interruptible_timeout(gspca_dev->wq, |
| 1989 | frame_ready(gspca_dev, file, v4l2_buf->memory), |
| 1990 | msecs_to_jiffies(3000)); |
| 1991 | if (ret < 0) |
| 1992 | return ret; |
| 1993 | if (ret == 0) |
| 1994 | return -EIO; |
| 1995 | |
| 1996 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1997 | return -ERESTARTSYS; |
| 1998 | } |
| 1999 | |
| 2000 | i = gspca_dev->fr_o; |
| 2001 | j = gspca_dev->fr_queue[i]; |
| 2002 | frame = &gspca_dev->frame[j]; |
| 2003 | |
| 2004 | gspca_dev->fr_o = (i + 1) % GSPCA_MAX_FRAMES; |
| 2005 | |
| 2006 | if (gspca_dev->sd_desc->dq_callback) { |
| 2007 | mutex_lock(&gspca_dev->usb_lock); |
| 2008 | gspca_dev->usb_err = 0; |
| 2009 | if (gspca_dev->present) |
| 2010 | gspca_dev->sd_desc->dq_callback(gspca_dev); |
| 2011 | mutex_unlock(&gspca_dev->usb_lock); |
| 2012 | } |
| 2013 | |
Hans de Goede | 4a82bc6 | 2010-12-30 20:00:17 -0300 | [diff] [blame] | 2014 | frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_DONE; |
| 2015 | memcpy(v4l2_buf, &frame->v4l2_buf, sizeof *v4l2_buf); |
| 2016 | PDEBUG(D_FRAM, "dqbuf %d", j); |
| 2017 | ret = 0; |
| 2018 | |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2019 | if (gspca_dev->memory == V4L2_MEMORY_USERPTR) { |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2020 | if (copy_to_user((__u8 __user *) frame->v4l2_buf.m.userptr, |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2021 | frame->data, |
| 2022 | frame->v4l2_buf.bytesused)) { |
| 2023 | PDEBUG(D_ERR|D_STREAM, |
| 2024 | "dqbuf cp to user failed"); |
| 2025 | ret = -EFAULT; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2026 | } |
| 2027 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 2028 | out: |
Hans de Goede | 27074ef | 2010-12-30 19:54:33 -0300 | [diff] [blame] | 2029 | mutex_unlock(&gspca_dev->queue_lock); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2030 | return ret; |
| 2031 | } |
| 2032 | |
| 2033 | /* |
| 2034 | * queue a video buffer |
| 2035 | * |
| 2036 | * Attempting to queue a buffer that has already been |
| 2037 | * queued will return -EINVAL. |
| 2038 | */ |
| 2039 | static int vidioc_qbuf(struct file *file, void *priv, |
| 2040 | struct v4l2_buffer *v4l2_buf) |
| 2041 | { |
| 2042 | struct gspca_dev *gspca_dev = priv; |
| 2043 | struct gspca_frame *frame; |
| 2044 | int i, index, ret; |
| 2045 | |
| 2046 | PDEBUG(D_FRAM, "qbuf %d", v4l2_buf->index); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2047 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2048 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 2049 | return -ERESTARTSYS; |
| 2050 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2051 | index = v4l2_buf->index; |
| 2052 | if ((unsigned) index >= gspca_dev->nframes) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2053 | PDEBUG(D_FRAM, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2054 | "qbuf idx %d >= %d", index, gspca_dev->nframes); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2055 | ret = -EINVAL; |
| 2056 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2057 | } |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2058 | if (v4l2_buf->memory != gspca_dev->memory) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2059 | PDEBUG(D_FRAM, "qbuf bad memory type"); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2060 | ret = -EINVAL; |
| 2061 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2062 | } |
| 2063 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2064 | frame = &gspca_dev->frame[index]; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2065 | if (frame->v4l2_buf.flags & BUF_ALL_FLAGS) { |
| 2066 | PDEBUG(D_FRAM, "qbuf bad state"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2067 | ret = -EINVAL; |
| 2068 | goto out; |
| 2069 | } |
| 2070 | |
| 2071 | frame->v4l2_buf.flags |= V4L2_BUF_FLAG_QUEUED; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2072 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2073 | if (frame->v4l2_buf.memory == V4L2_MEMORY_USERPTR) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2074 | frame->v4l2_buf.m.userptr = v4l2_buf->m.userptr; |
| 2075 | frame->v4l2_buf.length = v4l2_buf->length; |
| 2076 | } |
| 2077 | |
| 2078 | /* put the buffer in the 'queued' queue */ |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 2079 | i = atomic_read(&gspca_dev->fr_q); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2080 | gspca_dev->fr_queue[i] = index; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 2081 | atomic_set(&gspca_dev->fr_q, (i + 1) % GSPCA_MAX_FRAMES); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2082 | |
| 2083 | v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED; |
| 2084 | v4l2_buf->flags &= ~V4L2_BUF_FLAG_DONE; |
| 2085 | ret = 0; |
| 2086 | out: |
| 2087 | mutex_unlock(&gspca_dev->queue_lock); |
| 2088 | return ret; |
| 2089 | } |
| 2090 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2091 | /* |
| 2092 | * allocate the resources for read() |
| 2093 | */ |
| 2094 | static int read_alloc(struct gspca_dev *gspca_dev, |
| 2095 | struct file *file) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2096 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2097 | struct v4l2_buffer v4l2_buf; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2098 | int i, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2099 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2100 | PDEBUG(D_STREAM, "read alloc"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2101 | if (gspca_dev->nframes == 0) { |
| 2102 | struct v4l2_requestbuffers rb; |
| 2103 | |
| 2104 | memset(&rb, 0, sizeof rb); |
| 2105 | rb.count = gspca_dev->nbufread; |
| 2106 | rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2107 | rb.memory = GSPCA_MEMORY_READ; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2108 | ret = vidioc_reqbufs(file, gspca_dev, &rb); |
| 2109 | if (ret != 0) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2110 | PDEBUG(D_STREAM, "read reqbuf err %d", ret); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2111 | return ret; |
| 2112 | } |
| 2113 | memset(&v4l2_buf, 0, sizeof v4l2_buf); |
| 2114 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2115 | v4l2_buf.memory = GSPCA_MEMORY_READ; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2116 | for (i = 0; i < gspca_dev->nbufread; i++) { |
| 2117 | v4l2_buf.index = i; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2118 | ret = vidioc_qbuf(file, gspca_dev, &v4l2_buf); |
| 2119 | if (ret != 0) { |
| 2120 | PDEBUG(D_STREAM, "read qbuf err: %d", ret); |
| 2121 | return ret; |
| 2122 | } |
| 2123 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2124 | gspca_dev->memory = GSPCA_MEMORY_READ; |
| 2125 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 2126 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2127 | /* start streaming */ |
| 2128 | ret = vidioc_streamon(file, gspca_dev, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 2129 | if (ret != 0) |
| 2130 | PDEBUG(D_STREAM, "read streamon err %d", ret); |
| 2131 | return ret; |
| 2132 | } |
| 2133 | |
| 2134 | static unsigned int dev_poll(struct file *file, poll_table *wait) |
| 2135 | { |
| 2136 | struct gspca_dev *gspca_dev = file->private_data; |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 2137 | int ret; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2138 | |
| 2139 | PDEBUG(D_FRAM, "poll"); |
| 2140 | |
| 2141 | poll_wait(file, &gspca_dev->wq, wait); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2142 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2143 | /* if reqbufs is not done, the user would use read() */ |
Hans de Goede | ee36299 | 2010-12-31 05:05:56 -0300 | [diff] [blame] | 2144 | if (gspca_dev->memory == GSPCA_MEMORY_NO) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2145 | ret = read_alloc(gspca_dev, file); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 2146 | if (ret != 0) |
| 2147 | return POLLERR; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | if (mutex_lock_interruptible(&gspca_dev->queue_lock) != 0) |
| 2151 | return POLLERR; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2152 | |
Jean-François Moine | f7059ea | 2010-07-06 04:32:27 -0300 | [diff] [blame] | 2153 | /* check if an image has been received */ |
| 2154 | if (gspca_dev->fr_o != atomic_read(&gspca_dev->fr_i)) |
| 2155 | ret = POLLIN | POLLRDNORM; /* yes */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2156 | else |
| 2157 | ret = 0; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2158 | mutex_unlock(&gspca_dev->queue_lock); |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 2159 | if (!gspca_dev->present) |
| 2160 | return POLLHUP; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2161 | return ret; |
| 2162 | } |
| 2163 | |
| 2164 | static ssize_t dev_read(struct file *file, char __user *data, |
| 2165 | size_t count, loff_t *ppos) |
| 2166 | { |
| 2167 | struct gspca_dev *gspca_dev = file->private_data; |
| 2168 | struct gspca_frame *frame; |
| 2169 | struct v4l2_buffer v4l2_buf; |
| 2170 | struct timeval timestamp; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 2171 | int n, ret, ret2; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2172 | |
Mauro Carvalho Chehab | a9e1113 | 2008-07-09 05:26:26 -0300 | [diff] [blame] | 2173 | PDEBUG(D_FRAM, "read (%zd)", count); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2174 | if (!gspca_dev->present) |
| 2175 | return -ENODEV; |
Hans de Goede | ee36299 | 2010-12-31 05:05:56 -0300 | [diff] [blame] | 2176 | if (gspca_dev->memory == GSPCA_MEMORY_NO) { /* first time ? */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2177 | ret = read_alloc(gspca_dev, file); |
| 2178 | if (ret != 0) |
| 2179 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /* get a frame */ |
Paulo Assis | 2f51d00 | 2010-03-07 06:56:56 -0300 | [diff] [blame] | 2183 | timestamp = ktime_to_timeval(ktime_get()); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2184 | timestamp.tv_sec--; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 2185 | n = 2; |
| 2186 | for (;;) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2187 | memset(&v4l2_buf, 0, sizeof v4l2_buf); |
| 2188 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2189 | v4l2_buf.memory = GSPCA_MEMORY_READ; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2190 | ret = vidioc_dqbuf(file, gspca_dev, &v4l2_buf); |
| 2191 | if (ret != 0) { |
| 2192 | PDEBUG(D_STREAM, "read dqbuf err %d", ret); |
| 2193 | return ret; |
| 2194 | } |
| 2195 | |
| 2196 | /* if the process slept for more than 1 second, |
Frank Zago | 219423c | 2008-09-26 07:43:54 -0300 | [diff] [blame] | 2197 | * get a newer frame */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2198 | frame = &gspca_dev->frame[v4l2_buf.index]; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 2199 | if (--n < 0) |
| 2200 | break; /* avoid infinite loop */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2201 | if (frame->v4l2_buf.timestamp.tv_sec >= timestamp.tv_sec) |
| 2202 | break; |
| 2203 | ret = vidioc_qbuf(file, gspca_dev, &v4l2_buf); |
| 2204 | if (ret != 0) { |
| 2205 | PDEBUG(D_STREAM, "read qbuf err %d", ret); |
| 2206 | return ret; |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | /* copy the frame */ |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 2211 | if (count > frame->v4l2_buf.bytesused) |
| 2212 | count = frame->v4l2_buf.bytesused; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2213 | ret = copy_to_user(data, frame->data, count); |
| 2214 | if (ret != 0) { |
| 2215 | PDEBUG(D_ERR|D_STREAM, |
Mauro Carvalho Chehab | a9e1113 | 2008-07-09 05:26:26 -0300 | [diff] [blame] | 2216 | "read cp to user lack %d / %zd", ret, count); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2217 | ret = -EFAULT; |
| 2218 | goto out; |
| 2219 | } |
| 2220 | ret = count; |
| 2221 | out: |
| 2222 | /* in each case, requeue the buffer */ |
| 2223 | ret2 = vidioc_qbuf(file, gspca_dev, &v4l2_buf); |
| 2224 | if (ret2 != 0) |
| 2225 | return ret2; |
| 2226 | return ret; |
| 2227 | } |
| 2228 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 2229 | static struct v4l2_file_operations dev_fops = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2230 | .owner = THIS_MODULE, |
| 2231 | .open = dev_open, |
| 2232 | .release = dev_close, |
| 2233 | .read = dev_read, |
| 2234 | .mmap = dev_mmap, |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 2235 | .unlocked_ioctl = video_ioctl2, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2236 | .poll = dev_poll, |
| 2237 | }; |
| 2238 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2239 | static const struct v4l2_ioctl_ops dev_ioctl_ops = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2240 | .vidioc_querycap = vidioc_querycap, |
| 2241 | .vidioc_dqbuf = vidioc_dqbuf, |
| 2242 | .vidioc_qbuf = vidioc_qbuf, |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 2243 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 2244 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 2245 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 2246 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2247 | .vidioc_streamon = vidioc_streamon, |
| 2248 | .vidioc_queryctrl = vidioc_queryctrl, |
| 2249 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 2250 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 2251 | .vidioc_querymenu = vidioc_querymenu, |
| 2252 | .vidioc_enum_input = vidioc_enum_input, |
| 2253 | .vidioc_g_input = vidioc_g_input, |
| 2254 | .vidioc_s_input = vidioc_s_input, |
| 2255 | .vidioc_reqbufs = vidioc_reqbufs, |
| 2256 | .vidioc_querybuf = vidioc_querybuf, |
| 2257 | .vidioc_streamoff = vidioc_streamoff, |
| 2258 | .vidioc_g_jpegcomp = vidioc_g_jpegcomp, |
| 2259 | .vidioc_s_jpegcomp = vidioc_s_jpegcomp, |
| 2260 | .vidioc_g_parm = vidioc_g_parm, |
| 2261 | .vidioc_s_parm = vidioc_s_parm, |
Hans de Goede | 11c635a | 2009-05-25 15:04:22 -0300 | [diff] [blame] | 2262 | .vidioc_enum_framesizes = vidioc_enum_framesizes, |
Antonio Ospite | 28ffe77 | 2009-12-02 06:18:46 -0300 | [diff] [blame] | 2263 | .vidioc_enum_frameintervals = vidioc_enum_frameintervals, |
Brian Johnson | af1d9af | 2009-07-19 05:29:20 -0300 | [diff] [blame] | 2264 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 2265 | .vidioc_g_register = vidioc_g_register, |
| 2266 | .vidioc_s_register = vidioc_s_register, |
| 2267 | #endif |
| 2268 | .vidioc_g_chip_ident = vidioc_g_chip_ident, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2269 | }; |
| 2270 | |
Jean-François Moine | 59929ce | 2011-03-14 05:33:01 -0300 | [diff] [blame] | 2271 | static const struct video_device gspca_template = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2272 | .name = "gspca main driver", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2273 | .fops = &dev_fops, |
| 2274 | .ioctl_ops = &dev_ioctl_ops, |
Hans de Goede | d018230 | 2008-11-19 17:10:47 -0300 | [diff] [blame] | 2275 | .release = gspca_release, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 2276 | }; |
| 2277 | |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 2278 | /* initialize the controls */ |
| 2279 | static void ctrls_init(struct gspca_dev *gspca_dev) |
| 2280 | { |
| 2281 | struct gspca_ctrl *ctrl; |
| 2282 | int i; |
| 2283 | |
| 2284 | for (i = 0, ctrl = gspca_dev->cam.ctrls; |
| 2285 | i < gspca_dev->sd_desc->nctrls; |
| 2286 | i++, ctrl++) { |
| 2287 | ctrl->def = gspca_dev->sd_desc->ctrls[i].qctrl.default_value; |
| 2288 | ctrl->val = ctrl->def; |
| 2289 | ctrl->min = gspca_dev->sd_desc->ctrls[i].qctrl.minimum; |
| 2290 | ctrl->max = gspca_dev->sd_desc->ctrls[i].qctrl.maximum; |
| 2291 | } |
| 2292 | } |
| 2293 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2294 | /* |
| 2295 | * probe and create a new gspca device |
| 2296 | * |
| 2297 | * This function must be called by the sub-driver when it is |
| 2298 | * called for probing a new device. |
| 2299 | */ |
Jean-François Moine | 4462864 | 2010-06-05 07:47:36 -0300 | [diff] [blame] | 2300 | int gspca_dev_probe2(struct usb_interface *intf, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2301 | const struct usb_device_id *id, |
| 2302 | const struct sd_desc *sd_desc, |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2303 | int dev_size, |
| 2304 | struct module *module) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2305 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2306 | struct gspca_dev *gspca_dev; |
| 2307 | struct usb_device *dev = interface_to_usbdev(intf); |
| 2308 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2309 | |
Jean-François Moine | ee7dd4e | 2011-09-23 05:25:28 -0300 | [diff] [blame] | 2310 | pr_info("%s-" GSPCA_VERSION " probing %04x:%04x\n", |
| 2311 | sd_desc->name, id->idVendor, id->idProduct); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2312 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2313 | /* create the device */ |
| 2314 | if (dev_size < sizeof *gspca_dev) |
| 2315 | dev_size = sizeof *gspca_dev; |
| 2316 | gspca_dev = kzalloc(dev_size, GFP_KERNEL); |
Erik Andren | e293e59 | 2008-10-03 08:46:50 -0300 | [diff] [blame] | 2317 | if (!gspca_dev) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 2318 | pr_err("couldn't kzalloc gspca struct\n"); |
Erik Andren | e293e59 | 2008-10-03 08:46:50 -0300 | [diff] [blame] | 2319 | return -ENOMEM; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2320 | } |
Jean-Francois Moine | 8295d99 | 2008-09-03 17:12:19 -0300 | [diff] [blame] | 2321 | gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL); |
| 2322 | if (!gspca_dev->usb_buf) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 2323 | pr_err("out of memory\n"); |
Erik Andren | e293e59 | 2008-10-03 08:46:50 -0300 | [diff] [blame] | 2324 | ret = -ENOMEM; |
Jean-Francois Moine | 8295d99 | 2008-09-03 17:12:19 -0300 | [diff] [blame] | 2325 | goto out; |
| 2326 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2327 | gspca_dev->dev = dev; |
Jean-François Moine | 4462864 | 2010-06-05 07:47:36 -0300 | [diff] [blame] | 2328 | gspca_dev->iface = intf->cur_altsetting->desc.bInterfaceNumber; |
Jean-François Moine | 35680ba | 2010-07-14 06:30:18 -0300 | [diff] [blame] | 2329 | |
| 2330 | /* check if any audio device */ |
Hans de Goede | 5dae603 | 2012-01-01 17:20:14 -0300 | [diff] [blame] | 2331 | if (dev->actconfig->desc.bNumInterfaces != 1) { |
Jean-François Moine | 35680ba | 2010-07-14 06:30:18 -0300 | [diff] [blame] | 2332 | int i; |
| 2333 | struct usb_interface *intf2; |
| 2334 | |
Hans de Goede | 5dae603 | 2012-01-01 17:20:14 -0300 | [diff] [blame] | 2335 | for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { |
| 2336 | intf2 = dev->actconfig->interface[i]; |
Jean-François Moine | 35680ba | 2010-07-14 06:30:18 -0300 | [diff] [blame] | 2337 | if (intf2 != NULL |
| 2338 | && intf2->altsetting != NULL |
| 2339 | && intf2->altsetting->desc.bInterfaceClass == |
| 2340 | USB_CLASS_AUDIO) { |
| 2341 | gspca_dev->audio = 1; |
| 2342 | break; |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2347 | gspca_dev->sd_desc = sd_desc; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2348 | gspca_dev->nbufread = 2; |
Jean-Francois Moine | ff37474 | 2008-10-23 07:29:51 -0300 | [diff] [blame] | 2349 | gspca_dev->empty_packet = -1; /* don't check the empty packets */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2350 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2351 | /* configure the subdriver and initialize the USB device */ |
Jean-Francois Moine | ba38ee8 | 2008-11-22 04:27:34 -0300 | [diff] [blame] | 2352 | ret = sd_desc->config(gspca_dev, id); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2353 | if (ret < 0) |
| 2354 | goto out; |
Jean-François Moine | 6a33091 | 2010-10-02 04:12:25 -0300 | [diff] [blame] | 2355 | if (gspca_dev->cam.ctrls != NULL) |
| 2356 | ctrls_init(gspca_dev); |
Jean-Francois Moine | ba38ee8 | 2008-11-22 04:27:34 -0300 | [diff] [blame] | 2357 | ret = sd_desc->init(gspca_dev); |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2358 | if (ret < 0) |
| 2359 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2360 | gspca_set_default_mode(gspca_dev); |
| 2361 | |
Hans de Goede | 10ee240 | 2010-02-19 04:41:40 -0300 | [diff] [blame] | 2362 | ret = gspca_input_connect(gspca_dev); |
| 2363 | if (ret) |
| 2364 | goto out; |
| 2365 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2366 | mutex_init(&gspca_dev->usb_lock); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2367 | mutex_init(&gspca_dev->queue_lock); |
| 2368 | init_waitqueue_head(&gspca_dev->wq); |
| 2369 | |
| 2370 | /* init video stuff */ |
Jean-Francois Moine | ba38ee8 | 2008-11-22 04:27:34 -0300 | [diff] [blame] | 2371 | memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template); |
Hans de Goede | 2444163 | 2009-03-27 16:08:20 -0300 | [diff] [blame] | 2372 | gspca_dev->vdev.parent = &intf->dev; |
Jean-Francois Moine | 5c4fa002 | 2008-11-18 15:52:31 -0300 | [diff] [blame] | 2373 | gspca_dev->module = module; |
Oliver Neukum | ee56a4d | 2008-07-27 14:01:59 -0300 | [diff] [blame] | 2374 | gspca_dev->present = 1; |
Jean-Francois Moine | a12ca6a | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 2375 | ret = video_register_device(&gspca_dev->vdev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2376 | VFL_TYPE_GRABBER, |
Jean-Francois Moine | 8d584a5 | 2009-01-13 06:07:59 -0300 | [diff] [blame] | 2377 | -1); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2378 | if (ret < 0) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 2379 | pr_err("video_register_device err %d\n", ret); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2380 | goto out; |
| 2381 | } |
| 2382 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2383 | usb_set_intfdata(intf, gspca_dev); |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2384 | PDEBUG(D_PROBE, "%s created", video_device_node_name(&gspca_dev->vdev)); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2385 | |
Hans de Goede | 10ee240 | 2010-02-19 04:41:40 -0300 | [diff] [blame] | 2386 | gspca_input_create_urb(gspca_dev); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2387 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2388 | return 0; |
| 2389 | out: |
Randy Dunlap | f762801 | 2010-03-30 14:32:04 -0300 | [diff] [blame] | 2390 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Hans de Goede | 10ee240 | 2010-02-19 04:41:40 -0300 | [diff] [blame] | 2391 | if (gspca_dev->input_dev) |
| 2392 | input_unregister_device(gspca_dev->input_dev); |
Hans de Goede | e763752 | 2010-02-19 05:11:09 -0300 | [diff] [blame] | 2393 | #endif |
Jean-Francois Moine | e07a1d8 | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 2394 | kfree(gspca_dev->usb_buf); |
| 2395 | kfree(gspca_dev); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2396 | return ret; |
| 2397 | } |
Jean-François Moine | 4462864 | 2010-06-05 07:47:36 -0300 | [diff] [blame] | 2398 | EXPORT_SYMBOL(gspca_dev_probe2); |
| 2399 | |
| 2400 | /* same function as the previous one, but check the interface */ |
| 2401 | int gspca_dev_probe(struct usb_interface *intf, |
| 2402 | const struct usb_device_id *id, |
| 2403 | const struct sd_desc *sd_desc, |
| 2404 | int dev_size, |
| 2405 | struct module *module) |
| 2406 | { |
| 2407 | struct usb_device *dev = interface_to_usbdev(intf); |
| 2408 | |
| 2409 | /* we don't handle multi-config cameras */ |
| 2410 | if (dev->descriptor.bNumConfigurations != 1) { |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 2411 | pr_err("%04x:%04x too many config\n", |
| 2412 | id->idVendor, id->idProduct); |
Jean-François Moine | 4462864 | 2010-06-05 07:47:36 -0300 | [diff] [blame] | 2413 | return -ENODEV; |
| 2414 | } |
| 2415 | |
| 2416 | /* the USB video interface must be the first one */ |
Hans de Goede | 5dae603 | 2012-01-01 17:20:14 -0300 | [diff] [blame] | 2417 | if (dev->actconfig->desc.bNumInterfaces != 1 |
Jean-François Moine | c4dc692 | 2010-07-14 06:26:54 -0300 | [diff] [blame] | 2418 | && intf->cur_altsetting->desc.bInterfaceNumber != 0) |
Jean-François Moine | 4462864 | 2010-06-05 07:47:36 -0300 | [diff] [blame] | 2419 | return -ENODEV; |
Jean-François Moine | 4462864 | 2010-06-05 07:47:36 -0300 | [diff] [blame] | 2420 | |
| 2421 | return gspca_dev_probe2(intf, id, sd_desc, dev_size, module); |
| 2422 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2423 | EXPORT_SYMBOL(gspca_dev_probe); |
| 2424 | |
| 2425 | /* |
| 2426 | * USB disconnection |
| 2427 | * |
| 2428 | * This function must be called by the sub-driver |
| 2429 | * when the device disconnects, after the specific resources are freed. |
| 2430 | */ |
| 2431 | void gspca_disconnect(struct usb_interface *intf) |
| 2432 | { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 2433 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); |
Randy Dunlap | f762801 | 2010-03-30 14:32:04 -0300 | [diff] [blame] | 2434 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2435 | struct input_dev *input_dev; |
Jean-François Moine | e070bf9 | 2010-02-18 15:02:51 -0300 | [diff] [blame] | 2436 | #endif |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2437 | |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 2438 | PDEBUG(D_PROBE, "%s disconnect", |
| 2439 | video_device_node_name(&gspca_dev->vdev)); |
Adam Baker | ad28127 | 2009-02-04 15:33:21 -0300 | [diff] [blame] | 2440 | mutex_lock(&gspca_dev->usb_lock); |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 2441 | |
Hans de Goede | 4e770f7 | 2010-12-30 13:11:21 -0300 | [diff] [blame] | 2442 | gspca_dev->present = 0; |
| 2443 | wake_up_interruptible(&gspca_dev->wq); |
| 2444 | |
| 2445 | destroy_urbs(gspca_dev); |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 2446 | |
Randy Dunlap | f762801 | 2010-03-30 14:32:04 -0300 | [diff] [blame] | 2447 | #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2448 | gspca_input_destroy_urb(gspca_dev); |
| 2449 | input_dev = gspca_dev->input_dev; |
| 2450 | if (input_dev) { |
| 2451 | gspca_dev->input_dev = NULL; |
| 2452 | input_unregister_device(input_dev); |
| 2453 | } |
Jean-François Moine | e070bf9 | 2010-02-18 15:02:51 -0300 | [diff] [blame] | 2454 | #endif |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2455 | |
Jean-Francois Moine | 090264e | 2009-02-12 08:05:45 -0300 | [diff] [blame] | 2456 | /* the device is freed at exit of this function */ |
| 2457 | gspca_dev->dev = NULL; |
Adam Baker | ad28127 | 2009-02-04 15:33:21 -0300 | [diff] [blame] | 2458 | mutex_unlock(&gspca_dev->usb_lock); |
Jean-Francois Moine | 6e4ae87 | 2008-11-22 05:35:49 -0300 | [diff] [blame] | 2459 | |
Frank Zago | 6b060ff | 2008-09-28 08:12:22 -0300 | [diff] [blame] | 2460 | usb_set_intfdata(intf, NULL); |
| 2461 | |
Jean-Francois Moine | a12ca6a | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 2462 | /* release the device */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2463 | /* (this will call gspca_release() immediately or on last close) */ |
Jean-Francois Moine | a12ca6a | 2008-11-19 06:37:53 -0300 | [diff] [blame] | 2464 | video_unregister_device(&gspca_dev->vdev); |
Jean-Francois Moine | 3145b8c | 2008-10-05 04:22:10 -0300 | [diff] [blame] | 2465 | |
Jean-Francois Moine | 0d07e24 | 2009-10-01 13:44:49 -0300 | [diff] [blame] | 2466 | /* PDEBUG(D_PROBE, "disconnect complete"); */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2467 | } |
| 2468 | EXPORT_SYMBOL(gspca_disconnect); |
| 2469 | |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 2470 | #ifdef CONFIG_PM |
| 2471 | int gspca_suspend(struct usb_interface *intf, pm_message_t message) |
| 2472 | { |
| 2473 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); |
| 2474 | |
| 2475 | if (!gspca_dev->streaming) |
| 2476 | return 0; |
| 2477 | gspca_dev->frozen = 1; /* avoid urb error messages */ |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2478 | if (gspca_dev->sd_desc->stopN) |
| 2479 | gspca_dev->sd_desc->stopN(gspca_dev); |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 2480 | destroy_urbs(gspca_dev); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2481 | gspca_input_destroy_urb(gspca_dev); |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 2482 | gspca_set_alt0(gspca_dev); |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2483 | if (gspca_dev->sd_desc->stop0) |
| 2484 | gspca_dev->sd_desc->stop0(gspca_dev); |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 2485 | return 0; |
| 2486 | } |
| 2487 | EXPORT_SYMBOL(gspca_suspend); |
| 2488 | |
| 2489 | int gspca_resume(struct usb_interface *intf) |
| 2490 | { |
| 2491 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); |
| 2492 | |
| 2493 | gspca_dev->frozen = 0; |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2494 | gspca_dev->sd_desc->init(gspca_dev); |
Márton Németh | 0274d42 | 2010-01-28 06:39:49 -0300 | [diff] [blame] | 2495 | gspca_input_create_urb(gspca_dev); |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2496 | if (gspca_dev->streaming) |
| 2497 | return gspca_init_transfer(gspca_dev); |
Jean-Francois Moine | 1e89e2da | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 2498 | return 0; |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 2499 | } |
| 2500 | EXPORT_SYMBOL(gspca_resume); |
| 2501 | #endif |
Hans de Goede | dcef3237 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 2502 | /* -- cam driver utility functions -- */ |
| 2503 | |
| 2504 | /* auto gain and exposure algorithm based on the knee algorithm described here: |
| 2505 | http://ytse.tricolour.net/docs/LowLightOptimization.html |
| 2506 | |
| 2507 | Returns 0 if no changes were made, 1 if the gain and or exposure settings |
| 2508 | where changed. */ |
| 2509 | int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum, |
| 2510 | int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee) |
| 2511 | { |
| 2512 | int i, steps, gain, orig_gain, exposure, orig_exposure, autogain; |
| 2513 | const struct ctrl *gain_ctrl = NULL; |
| 2514 | const struct ctrl *exposure_ctrl = NULL; |
| 2515 | const struct ctrl *autogain_ctrl = NULL; |
| 2516 | int retval = 0; |
| 2517 | |
| 2518 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
Hans de Goede | 26984b0 | 2010-02-01 13:18:37 -0300 | [diff] [blame] | 2519 | if (gspca_dev->ctrl_dis & (1 << i)) |
| 2520 | continue; |
Hans de Goede | dcef3237 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 2521 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN) |
| 2522 | gain_ctrl = &gspca_dev->sd_desc->ctrls[i]; |
| 2523 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE) |
| 2524 | exposure_ctrl = &gspca_dev->sd_desc->ctrls[i]; |
| 2525 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_AUTOGAIN) |
| 2526 | autogain_ctrl = &gspca_dev->sd_desc->ctrls[i]; |
| 2527 | } |
| 2528 | if (!gain_ctrl || !exposure_ctrl || !autogain_ctrl) { |
| 2529 | PDEBUG(D_ERR, "Error: gspca_auto_gain_n_exposure called " |
| 2530 | "on cam without (auto)gain/exposure"); |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
| 2534 | if (gain_ctrl->get(gspca_dev, &gain) || |
| 2535 | exposure_ctrl->get(gspca_dev, &exposure) || |
| 2536 | autogain_ctrl->get(gspca_dev, &autogain) || !autogain) |
| 2537 | return 0; |
| 2538 | |
| 2539 | orig_gain = gain; |
| 2540 | orig_exposure = exposure; |
| 2541 | |
| 2542 | /* If we are of a multiple of deadzone, do multiple steps to reach the |
| 2543 | desired lumination fast (with the risc of a slight overshoot) */ |
| 2544 | steps = abs(desired_avg_lum - avg_lum) / deadzone; |
| 2545 | |
Jean-Francois Moine | 1c44d81 | 2008-11-10 05:56:55 -0300 | [diff] [blame] | 2546 | PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d", |
Hans de Goede | dcef3237 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 2547 | avg_lum, desired_avg_lum, steps); |
| 2548 | |
| 2549 | for (i = 0; i < steps; i++) { |
| 2550 | if (avg_lum > desired_avg_lum) { |
| 2551 | if (gain > gain_knee) |
| 2552 | gain--; |
| 2553 | else if (exposure > exposure_knee) |
| 2554 | exposure--; |
| 2555 | else if (gain > gain_ctrl->qctrl.default_value) |
| 2556 | gain--; |
| 2557 | else if (exposure > exposure_ctrl->qctrl.minimum) |
| 2558 | exposure--; |
| 2559 | else if (gain > gain_ctrl->qctrl.minimum) |
| 2560 | gain--; |
| 2561 | else |
| 2562 | break; |
| 2563 | } else { |
| 2564 | if (gain < gain_ctrl->qctrl.default_value) |
| 2565 | gain++; |
| 2566 | else if (exposure < exposure_knee) |
| 2567 | exposure++; |
| 2568 | else if (gain < gain_knee) |
| 2569 | gain++; |
| 2570 | else if (exposure < exposure_ctrl->qctrl.maximum) |
| 2571 | exposure++; |
| 2572 | else if (gain < gain_ctrl->qctrl.maximum) |
| 2573 | gain++; |
| 2574 | else |
| 2575 | break; |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | if (gain != orig_gain) { |
| 2580 | gain_ctrl->set(gspca_dev, gain); |
| 2581 | retval = 1; |
| 2582 | } |
| 2583 | if (exposure != orig_exposure) { |
| 2584 | exposure_ctrl->set(gspca_dev, exposure); |
| 2585 | retval = 1; |
| 2586 | } |
| 2587 | |
| 2588 | return retval; |
| 2589 | } |
| 2590 | EXPORT_SYMBOL(gspca_auto_gain_n_exposure); |
| 2591 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2592 | /* -- module insert / remove -- */ |
| 2593 | static int __init gspca_init(void) |
| 2594 | { |
Jean-François Moine | f22123f | 2011-09-23 05:17:10 -0300 | [diff] [blame] | 2595 | pr_info("v" GSPCA_VERSION " registered\n"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2596 | return 0; |
| 2597 | } |
| 2598 | static void __exit gspca_exit(void) |
| 2599 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | module_init(gspca_init); |
| 2603 | module_exit(gspca_exit); |
| 2604 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 2605 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 2606 | module_param_named(debug, gspca_debug, int, 0644); |
| 2607 | MODULE_PARM_DESC(debug, |
| 2608 | "Debug (bit) 0x01:error 0x02:probe 0x04:config" |
Jean-François Moine | f8e5677 | 2011-05-17 04:10:32 -0300 | [diff] [blame] | 2609 | " 0x08:stream 0x10:frame 0x20:packet" |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 2610 | " 0x0100: v4l2"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2611 | #endif |