Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Main USB camera driver |
| 3 | * |
| 4 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software Foundation, |
| 18 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #define MODULE_NAME "gspca" |
| 22 | |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/fs.h> |
| 25 | #include <linux/vmalloc.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/string.h> |
| 30 | #include <linux/pagemap.h> |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 31 | #include <linux/io.h> |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 32 | #include <asm/page.h> |
Jean-Francois Moine | 956e42d | 2008-07-01 10:03:42 -0300 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 34 | #include <linux/jiffies.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 35 | #include <media/v4l2-ioctl.h> |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 36 | |
| 37 | #include "gspca.h" |
| 38 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 39 | /* global values */ |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 40 | #define DEF_NURBS 2 /* default number of URBs */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 41 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 42 | MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); |
| 43 | MODULE_DESCRIPTION("GSPCA USB Camera Driver"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | |
Jean-Francois Moine | bb64e86 | 2008-07-19 06:49:28 -0300 | [diff] [blame] | 46 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 2, 0) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 47 | |
| 48 | static int video_nr = -1; |
| 49 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 50 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 51 | int gspca_debug = D_ERR | D_PROBE; |
| 52 | EXPORT_SYMBOL(gspca_debug); |
| 53 | |
| 54 | static void PDEBUG_MODE(char *txt, __u32 pixfmt, int w, int h) |
| 55 | { |
| 56 | if ((pixfmt >> 24) >= '0' && (pixfmt >> 24) <= 'z') { |
| 57 | PDEBUG(D_CONF|D_STREAM, "%s %c%c%c%c %dx%d", |
| 58 | txt, |
| 59 | pixfmt & 0xff, |
| 60 | (pixfmt >> 8) & 0xff, |
| 61 | (pixfmt >> 16) & 0xff, |
| 62 | pixfmt >> 24, |
| 63 | w, h); |
| 64 | } else { |
| 65 | PDEBUG(D_CONF|D_STREAM, "%s 0x%08x %dx%d", |
| 66 | txt, |
| 67 | pixfmt, |
| 68 | w, h); |
| 69 | } |
| 70 | } |
| 71 | #else |
| 72 | #define PDEBUG_MODE(txt, pixfmt, w, h) |
| 73 | #endif |
| 74 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 75 | /* specific memory types - !! should different from V4L2_MEMORY_xxx */ |
| 76 | #define GSPCA_MEMORY_NO 0 /* V4L2_MEMORY_xxx starts from 1 */ |
| 77 | #define GSPCA_MEMORY_READ 7 |
| 78 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 79 | #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] | 80 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 81 | /* |
| 82 | * VMA operations. |
| 83 | */ |
| 84 | static void gspca_vm_open(struct vm_area_struct *vma) |
| 85 | { |
| 86 | struct gspca_frame *frame = vma->vm_private_data; |
| 87 | |
| 88 | frame->vma_use_count++; |
| 89 | frame->v4l2_buf.flags |= V4L2_BUF_FLAG_MAPPED; |
| 90 | } |
| 91 | |
| 92 | static void gspca_vm_close(struct vm_area_struct *vma) |
| 93 | { |
| 94 | struct gspca_frame *frame = vma->vm_private_data; |
| 95 | |
| 96 | if (--frame->vma_use_count <= 0) |
| 97 | frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_MAPPED; |
| 98 | } |
| 99 | |
| 100 | static struct vm_operations_struct gspca_vm_ops = { |
| 101 | .open = gspca_vm_open, |
| 102 | .close = gspca_vm_close, |
| 103 | }; |
| 104 | |
| 105 | /* |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 106 | * fill a video frame from an URB and resubmit |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 107 | */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 108 | static void fill_frame(struct gspca_dev *gspca_dev, |
| 109 | struct urb *urb) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 110 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 111 | struct gspca_frame *frame; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 112 | __u8 *data; /* address of data in the iso message */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 113 | int i, j, len, st; |
| 114 | cam_pkt_op pkt_scan; |
| 115 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 116 | if (urb->status != 0) { |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame^] | 117 | if (!gspca_dev->frozen) |
| 118 | PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 119 | return; /* disconnection ? */ |
| 120 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 121 | pkt_scan = gspca_dev->sd_desc->pkt_scan; |
| 122 | for (i = 0; i < urb->number_of_packets; i++) { |
| 123 | |
| 124 | /* check the availability of the frame buffer */ |
| 125 | j = gspca_dev->fr_i; |
| 126 | j = gspca_dev->fr_queue[j]; |
| 127 | frame = &gspca_dev->frame[j]; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 128 | if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 129 | != V4L2_BUF_FLAG_QUEUED) { |
| 130 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | /* check the packet status and length */ |
| 135 | len = urb->iso_frame_desc[i].actual_length; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 136 | if (len == 0) |
| 137 | continue; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 138 | st = urb->iso_frame_desc[i].status; |
| 139 | if (st) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 140 | PDEBUG(D_ERR, |
| 141 | "ISOC data error: [%d] len=%d, status=%d", |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 142 | i, len, st); |
| 143 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 144 | continue; |
| 145 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 146 | |
| 147 | /* let the packet be analyzed by the subdriver */ |
| 148 | PDEBUG(D_PACK, "packet [%d] o:%d l:%d", |
| 149 | i, urb->iso_frame_desc[i].offset, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 150 | data = (__u8 *) urb->transfer_buffer |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 151 | + urb->iso_frame_desc[i].offset; |
| 152 | pkt_scan(gspca_dev, frame, data, len); |
| 153 | } |
| 154 | |
| 155 | /* resubmit the URB */ |
| 156 | urb->status = 0; |
| 157 | st = usb_submit_urb(urb, GFP_ATOMIC); |
| 158 | if (st < 0) |
| 159 | PDEBUG(D_ERR|D_PACK, "usb_submit_urb() ret %d", st); |
| 160 | } |
| 161 | |
| 162 | /* |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 163 | * ISOC message interrupt from the USB device |
| 164 | * |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 165 | * 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] | 166 | */ |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 167 | static void isoc_irq(struct urb *urb |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 168 | ) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 169 | { |
| 170 | struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; |
| 171 | |
Hans de Goede | 3647fea | 2008-07-15 05:36:30 -0300 | [diff] [blame] | 172 | PDEBUG(D_PACK, "isoc irq"); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 173 | if (!gspca_dev->streaming) |
| 174 | return; |
| 175 | fill_frame(gspca_dev, urb); |
| 176 | } |
| 177 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 178 | /* |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 179 | * add data to the current frame |
| 180 | * |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 181 | * This function is called by the subdrivers at interrupt level. |
| 182 | * |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 183 | * To build a frame, these ones must add |
| 184 | * - one FIRST_PACKET |
| 185 | * - 0 or many INTER_PACKETs |
| 186 | * - one LAST_PACKET |
| 187 | * DISCARD_PACKET invalidates the whole frame. |
| 188 | * On LAST_PACKET, a new frame is returned. |
| 189 | */ |
| 190 | struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev, |
| 191 | int packet_type, |
| 192 | struct gspca_frame *frame, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 193 | const __u8 *data, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 194 | int len) |
| 195 | { |
| 196 | int i, j; |
| 197 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 198 | PDEBUG(D_PACK, "add t:%d l:%d", packet_type, len); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 199 | |
| 200 | /* when start of a new frame, if the current frame buffer |
| 201 | * is not queued, discard the whole frame */ |
| 202 | if (packet_type == FIRST_PACKET) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 203 | if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS) |
| 204 | != V4L2_BUF_FLAG_QUEUED) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 205 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 206 | return frame; |
| 207 | } |
| 208 | frame->data_end = frame->data; |
| 209 | jiffies_to_timeval(get_jiffies_64(), |
| 210 | &frame->v4l2_buf.timestamp); |
| 211 | frame->v4l2_buf.sequence = ++gspca_dev->sequence; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 212 | } else if (gspca_dev->last_packet_type == DISCARD_PACKET) { |
Jean-Francois Moine | 06ca78f | 2008-07-22 03:45:08 -0300 | [diff] [blame] | 213 | if (packet_type == LAST_PACKET) |
| 214 | gspca_dev->last_packet_type = packet_type; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 215 | return frame; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 216 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 217 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 218 | /* append the packet to the frame buffer */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 219 | if (len > 0) { |
| 220 | if (frame->data_end - frame->data + len |
| 221 | > frame->v4l2_buf.length) { |
Mauro Carvalho Chehab | a9e1113 | 2008-07-09 05:26:26 -0300 | [diff] [blame] | 222 | PDEBUG(D_ERR|D_PACK, "frame overflow %zd > %d", |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 223 | frame->data_end - frame->data + len, |
| 224 | frame->v4l2_buf.length); |
| 225 | packet_type = DISCARD_PACKET; |
| 226 | } else { |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 227 | memcpy(frame->data_end, data, len); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 228 | frame->data_end += len; |
| 229 | } |
| 230 | } |
| 231 | gspca_dev->last_packet_type = packet_type; |
| 232 | |
| 233 | /* if last packet, wake the application and advance in the queue */ |
| 234 | if (packet_type == LAST_PACKET) { |
| 235 | frame->v4l2_buf.bytesused = frame->data_end - frame->data; |
| 236 | frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED; |
| 237 | frame->v4l2_buf.flags |= V4L2_BUF_FLAG_DONE; |
| 238 | atomic_inc(&gspca_dev->nevent); |
| 239 | wake_up_interruptible(&gspca_dev->wq); /* event = new frame */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 240 | i = (gspca_dev->fr_i + 1) % gspca_dev->nframes; |
| 241 | gspca_dev->fr_i = i; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 242 | PDEBUG(D_FRAM, "frame complete len:%d q:%d i:%d o:%d", |
| 243 | frame->v4l2_buf.bytesused, |
| 244 | gspca_dev->fr_q, |
| 245 | i, |
| 246 | gspca_dev->fr_o); |
| 247 | j = gspca_dev->fr_queue[i]; |
| 248 | frame = &gspca_dev->frame[j]; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 249 | } |
| 250 | return frame; |
| 251 | } |
| 252 | EXPORT_SYMBOL(gspca_frame_add); |
| 253 | |
| 254 | static int gspca_is_compressed(__u32 format) |
| 255 | { |
| 256 | switch (format) { |
| 257 | case V4L2_PIX_FMT_MJPEG: |
| 258 | case V4L2_PIX_FMT_JPEG: |
Jean-Francois Moine | 50a871f | 2008-06-30 19:47:33 -0300 | [diff] [blame] | 259 | case V4L2_PIX_FMT_SPCA561: |
Hans de Goede | ab8f12c | 2008-07-04 18:29:32 -0300 | [diff] [blame] | 260 | case V4L2_PIX_FMT_PAC207: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 261 | return 1; |
| 262 | } |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | static void *rvmalloc(unsigned long size) |
| 267 | { |
| 268 | void *mem; |
| 269 | unsigned long adr; |
| 270 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 271 | /* size = PAGE_ALIGN(size); (already done) */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 272 | mem = vmalloc_32(size); |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 273 | if (mem != NULL) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 274 | adr = (unsigned long) mem; |
| 275 | while ((long) size > 0) { |
| 276 | SetPageReserved(vmalloc_to_page((void *) adr)); |
| 277 | adr += PAGE_SIZE; |
| 278 | size -= PAGE_SIZE; |
| 279 | } |
| 280 | } |
| 281 | return mem; |
| 282 | } |
| 283 | |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 284 | static void rvfree(void *mem, long size) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 285 | { |
| 286 | unsigned long adr; |
| 287 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 288 | adr = (unsigned long) mem; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 289 | while (size > 0) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 290 | ClearPageReserved(vmalloc_to_page((void *) adr)); |
| 291 | adr += PAGE_SIZE; |
| 292 | size -= PAGE_SIZE; |
| 293 | } |
| 294 | vfree(mem); |
| 295 | } |
| 296 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 297 | static int frame_alloc(struct gspca_dev *gspca_dev, |
| 298 | unsigned int count) |
| 299 | { |
| 300 | struct gspca_frame *frame; |
| 301 | unsigned int frsz; |
| 302 | int i; |
| 303 | |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 304 | i = gspca_dev->curr_mode; |
| 305 | frsz = gspca_dev->cam.cam_mode[i].sizeimage; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 306 | PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 307 | frsz = PAGE_ALIGN(frsz); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 308 | gspca_dev->frsz = frsz; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 309 | if (count > GSPCA_MAX_FRAMES) |
| 310 | count = GSPCA_MAX_FRAMES; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 311 | gspca_dev->frbuf = rvmalloc(frsz * count); |
| 312 | if (!gspca_dev->frbuf) { |
| 313 | err("frame alloc failed"); |
| 314 | return -ENOMEM; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 315 | } |
| 316 | gspca_dev->nframes = count; |
| 317 | for (i = 0; i < count; i++) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 318 | frame = &gspca_dev->frame[i]; |
| 319 | frame->v4l2_buf.index = i; |
| 320 | frame->v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 321 | frame->v4l2_buf.flags = 0; |
| 322 | frame->v4l2_buf.field = V4L2_FIELD_NONE; |
| 323 | frame->v4l2_buf.length = frsz; |
| 324 | frame->v4l2_buf.memory = gspca_dev->memory; |
| 325 | frame->v4l2_buf.sequence = 0; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 326 | frame->data = frame->data_end = |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 327 | gspca_dev->frbuf + i * frsz; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 328 | frame->v4l2_buf.m.offset = i * frsz; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 329 | } |
| 330 | gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; |
| 331 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 332 | gspca_dev->sequence = 0; |
| 333 | atomic_set(&gspca_dev->nevent, 0); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 334 | return 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static void frame_free(struct gspca_dev *gspca_dev) |
| 338 | { |
| 339 | int i; |
| 340 | |
| 341 | PDEBUG(D_STREAM, "frame free"); |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 342 | if (gspca_dev->frbuf != NULL) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 343 | rvfree(gspca_dev->frbuf, |
| 344 | gspca_dev->nframes * gspca_dev->frsz); |
| 345 | gspca_dev->frbuf = NULL; |
| 346 | for (i = 0; i < gspca_dev->nframes; i++) |
| 347 | gspca_dev->frame[i].data = NULL; |
| 348 | } |
| 349 | gspca_dev->nframes = 0; |
| 350 | } |
| 351 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 352 | static void destroy_urbs(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 353 | { |
| 354 | struct urb *urb; |
| 355 | unsigned int i; |
| 356 | |
| 357 | PDEBUG(D_STREAM, "kill transfer"); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 358 | for (i = 0; i < MAX_NURBS; ++i) { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 359 | urb = gspca_dev->urb[i]; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 360 | if (urb == NULL) |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 361 | break; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 362 | |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 363 | gspca_dev->urb[i] = NULL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 364 | usb_kill_urb(urb); |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 365 | if (urb->transfer_buffer != NULL) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 366 | usb_buffer_free(gspca_dev->dev, |
| 367 | urb->transfer_buffer_length, |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 368 | urb->transfer_buffer, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 369 | urb->transfer_dma); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 370 | usb_free_urb(urb); |
| 371 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* |
| 375 | * search an input isochronous endpoint in an alternate setting |
| 376 | */ |
| 377 | static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt, |
| 378 | __u8 epaddr) |
| 379 | { |
| 380 | struct usb_host_endpoint *ep; |
| 381 | int i, attr; |
| 382 | |
| 383 | epaddr |= USB_DIR_IN; |
| 384 | for (i = 0; i < alt->desc.bNumEndpoints; i++) { |
| 385 | ep = &alt->endpoint[i]; |
| 386 | if (ep->desc.bEndpointAddress == epaddr) { |
| 387 | attr = ep->desc.bmAttributes |
| 388 | & USB_ENDPOINT_XFERTYPE_MASK; |
| 389 | if (attr == USB_ENDPOINT_XFER_ISOC) |
| 390 | return ep; |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * search an input isochronous endpoint |
| 399 | * |
| 400 | * The endpoint is defined by the subdriver. |
| 401 | * Use only the first isoc (some Zoran - 0x0572:0x0001 - have two such ep). |
| 402 | * This routine may be called many times when the bandwidth is too small |
| 403 | * (the bandwidth is checked on urb submit). |
| 404 | */ |
Adrian Bunk | 903e10a | 2008-07-22 02:35:05 -0300 | [diff] [blame] | 405 | static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 406 | { |
| 407 | struct usb_interface *intf; |
| 408 | struct usb_host_endpoint *ep; |
| 409 | int i, ret; |
| 410 | |
| 411 | intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 412 | ep = NULL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 413 | i = gspca_dev->alt; /* previous alt setting */ |
| 414 | while (--i > 0) { /* alt 0 is unusable */ |
| 415 | ep = alt_isoc(&intf->altsetting[i], gspca_dev->cam.epaddr); |
| 416 | if (ep) |
| 417 | break; |
| 418 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 419 | if (ep == NULL) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 420 | err("no ISOC endpoint found"); |
| 421 | return NULL; |
| 422 | } |
| 423 | PDEBUG(D_STREAM, "use ISOC alt %d ep 0x%02x", |
| 424 | i, ep->desc.bEndpointAddress); |
| 425 | ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i); |
| 426 | if (ret < 0) { |
| 427 | err("set interface err %d", ret); |
| 428 | return NULL; |
| 429 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 430 | gspca_dev->alt = i; /* memorize the current alt setting */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 431 | return ep; |
| 432 | } |
| 433 | |
| 434 | /* |
| 435 | * create the isochronous URBs |
| 436 | */ |
| 437 | static int create_urbs(struct gspca_dev *gspca_dev, |
| 438 | struct usb_host_endpoint *ep) |
| 439 | { |
| 440 | struct urb *urb; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 441 | int n, nurbs, i, psize, npkt, bsize; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 442 | |
| 443 | /* calculate the packet size and the number of packets */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 444 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 445 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 446 | /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ |
| 447 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); |
| 448 | npkt = ISO_MAX_SIZE / psize; |
| 449 | if (npkt > ISO_MAX_PKT) |
| 450 | npkt = ISO_MAX_PKT; |
| 451 | bsize = psize * npkt; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 452 | PDEBUG(D_STREAM, |
| 453 | "isoc %d pkts size %d (bsize:%d)", npkt, psize, bsize); |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 454 | nurbs = DEF_NURBS; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 455 | gspca_dev->nurbs = nurbs; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 456 | for (n = 0; n < nurbs; n++) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 457 | urb = usb_alloc_urb(npkt, GFP_KERNEL); |
| 458 | if (!urb) { |
| 459 | err("usb_alloc_urb failed"); |
| 460 | return -ENOMEM; |
| 461 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 462 | urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 463 | bsize, |
| 464 | GFP_KERNEL, |
| 465 | &urb->transfer_dma); |
| 466 | |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 467 | if (urb->transfer_buffer == NULL) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 468 | usb_free_urb(urb); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 469 | destroy_urbs(gspca_dev); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 470 | err("usb_buffer_urb failed"); |
| 471 | return -ENOMEM; |
| 472 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 473 | gspca_dev->urb[n] = urb; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 474 | urb->dev = gspca_dev->dev; |
| 475 | urb->context = gspca_dev; |
| 476 | urb->pipe = usb_rcvisocpipe(gspca_dev->dev, |
| 477 | ep->desc.bEndpointAddress); |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 478 | urb->transfer_flags = URB_ISO_ASAP |
| 479 | | URB_NO_TRANSFER_DMA_MAP; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 480 | urb->interval = ep->desc.bInterval; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 481 | urb->complete = isoc_irq; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 482 | urb->number_of_packets = npkt; |
| 483 | urb->transfer_buffer_length = bsize; |
| 484 | for (i = 0; i < npkt; i++) { |
| 485 | urb->iso_frame_desc[i].length = psize; |
| 486 | urb->iso_frame_desc[i].offset = psize * i; |
| 487 | } |
| 488 | } |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | * start the USB transfer |
| 494 | */ |
| 495 | static int gspca_init_transfer(struct gspca_dev *gspca_dev) |
| 496 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 497 | struct usb_host_endpoint *ep; |
| 498 | int n, ret; |
| 499 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 500 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 501 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 502 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 503 | /* set the higher alternate setting and |
| 504 | * loop until urb submit succeeds */ |
| 505 | gspca_dev->alt = gspca_dev->nbalt; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 506 | for (;;) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 507 | PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 508 | ep = get_isoc_ep(gspca_dev); |
| 509 | if (ep == NULL) { |
| 510 | ret = -EIO; |
| 511 | goto out; |
| 512 | } |
| 513 | ret = create_urbs(gspca_dev, ep); |
| 514 | if (ret < 0) |
| 515 | goto out; |
| 516 | |
| 517 | /* start the cam */ |
| 518 | gspca_dev->sd_desc->start(gspca_dev); |
| 519 | gspca_dev->streaming = 1; |
| 520 | atomic_set(&gspca_dev->nevent, 0); |
| 521 | |
| 522 | /* submit the URBs */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 523 | for (n = 0; n < gspca_dev->nurbs; n++) { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 524 | ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 525 | if (ret < 0) { |
| 526 | PDEBUG(D_ERR|D_STREAM, |
| 527 | "usb_submit_urb [%d] err %d", n, ret); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 528 | gspca_dev->streaming = 0; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 529 | destroy_urbs(gspca_dev); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 530 | if (ret == -ENOSPC) |
| 531 | break; /* try the previous alt */ |
| 532 | goto out; |
| 533 | } |
| 534 | } |
| 535 | if (ret >= 0) |
| 536 | break; |
| 537 | } |
| 538 | out: |
| 539 | mutex_unlock(&gspca_dev->usb_lock); |
| 540 | return ret; |
| 541 | } |
| 542 | |
| 543 | static int gspca_set_alt0(struct gspca_dev *gspca_dev) |
| 544 | { |
| 545 | int ret; |
| 546 | |
| 547 | ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0); |
| 548 | if (ret < 0) |
| 549 | PDEBUG(D_ERR|D_STREAM, "set interface 0 err %d", ret); |
| 550 | return ret; |
| 551 | } |
| 552 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 553 | /* Note both the queue and the usb lock should be hold when calling this */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 554 | static void gspca_stream_off(struct gspca_dev *gspca_dev) |
| 555 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 556 | gspca_dev->streaming = 0; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 557 | atomic_set(&gspca_dev->nevent, 0); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 558 | if (gspca_dev->present) { |
| 559 | gspca_dev->sd_desc->stopN(gspca_dev); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 560 | destroy_urbs(gspca_dev); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 561 | gspca_set_alt0(gspca_dev); |
| 562 | gspca_dev->sd_desc->stop0(gspca_dev); |
| 563 | PDEBUG(D_STREAM, "stream off OK"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 564 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 565 | } |
| 566 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 567 | static void gspca_set_default_mode(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 568 | { |
| 569 | int i; |
| 570 | |
| 571 | i = gspca_dev->cam.nmodes - 1; /* take the highest mode */ |
| 572 | gspca_dev->curr_mode = i; |
| 573 | gspca_dev->width = gspca_dev->cam.cam_mode[i].width; |
| 574 | gspca_dev->height = gspca_dev->cam.cam_mode[i].height; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 575 | gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static int wxh_to_mode(struct gspca_dev *gspca_dev, |
| 579 | int width, int height) |
| 580 | { |
| 581 | int i; |
| 582 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 583 | for (i = gspca_dev->cam.nmodes; --i > 0; ) { |
| 584 | if (width >= gspca_dev->cam.cam_mode[i].width |
| 585 | && height >= gspca_dev->cam.cam_mode[i].height) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 586 | break; |
| 587 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 588 | return i; |
| 589 | } |
| 590 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 591 | /* |
| 592 | * search a mode with the right pixel format |
| 593 | */ |
| 594 | static int gspca_get_mode(struct gspca_dev *gspca_dev, |
| 595 | int mode, |
| 596 | int pixfmt) |
| 597 | { |
| 598 | int modeU, modeD; |
| 599 | |
| 600 | modeU = modeD = mode; |
| 601 | while ((modeU < gspca_dev->cam.nmodes) || modeD >= 0) { |
| 602 | if (--modeD >= 0) { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 603 | if (gspca_dev->cam.cam_mode[modeD].pixelformat |
| 604 | == pixfmt) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 605 | return modeD; |
| 606 | } |
| 607 | if (++modeU < gspca_dev->cam.nmodes) { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 608 | if (gspca_dev->cam.cam_mode[modeU].pixelformat |
| 609 | == pixfmt) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 610 | return modeU; |
| 611 | } |
| 612 | } |
| 613 | return -EINVAL; |
| 614 | } |
| 615 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 616 | 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] | 617 | struct v4l2_fmtdesc *fmtdesc) |
| 618 | { |
| 619 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 620 | int i, j, index; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 621 | __u32 fmt_tb[8]; |
| 622 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 623 | /* give an index to each format */ |
| 624 | index = 0; |
| 625 | j = 0; |
| 626 | for (i = gspca_dev->cam.nmodes; --i >= 0; ) { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 627 | fmt_tb[index] = gspca_dev->cam.cam_mode[i].pixelformat; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 628 | j = 0; |
| 629 | for (;;) { |
| 630 | if (fmt_tb[j] == fmt_tb[index]) |
| 631 | break; |
| 632 | j++; |
| 633 | } |
| 634 | if (j == index) { |
| 635 | if (fmtdesc->index == index) |
| 636 | break; /* new format */ |
| 637 | index++; |
| 638 | if (index >= sizeof fmt_tb / sizeof fmt_tb[0]) |
| 639 | return -EINVAL; |
| 640 | } |
| 641 | } |
| 642 | if (i < 0) |
| 643 | return -EINVAL; /* no more format */ |
| 644 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 645 | fmtdesc->pixelformat = fmt_tb[index]; |
| 646 | if (gspca_is_compressed(fmt_tb[index])) |
| 647 | fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 648 | fmtdesc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 649 | fmtdesc->description[0] = fmtdesc->pixelformat & 0xff; |
| 650 | fmtdesc->description[1] = (fmtdesc->pixelformat >> 8) & 0xff; |
| 651 | fmtdesc->description[2] = (fmtdesc->pixelformat >> 16) & 0xff; |
| 652 | fmtdesc->description[3] = fmtdesc->pixelformat >> 24; |
| 653 | fmtdesc->description[4] = '\0'; |
| 654 | return 0; |
| 655 | } |
| 656 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 657 | 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] | 658 | struct v4l2_format *fmt) |
| 659 | { |
| 660 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 661 | int mode; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 662 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 663 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 664 | return -EINVAL; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 665 | mode = gspca_dev->curr_mode; |
| 666 | memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode], |
| 667 | sizeof fmt->fmt.pix); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 668 | return 0; |
| 669 | } |
| 670 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 671 | static int try_fmt_vid_cap(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 672 | struct v4l2_format *fmt) |
| 673 | { |
Hans de Goede | 24c530b | 2008-07-04 17:55:18 -0300 | [diff] [blame] | 674 | int w, h, mode, mode2; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 675 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 676 | if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 677 | return -EINVAL; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 678 | w = fmt->fmt.pix.width; |
| 679 | h = fmt->fmt.pix.height; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 680 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 681 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 682 | if (gspca_debug & D_CONF) |
| 683 | PDEBUG_MODE("try fmt cap", fmt->fmt.pix.pixelformat, w, h); |
| 684 | #endif |
| 685 | /* search the closest mode for width and height */ |
| 686 | mode = wxh_to_mode(gspca_dev, w, h); |
| 687 | |
| 688 | /* OK if right palette */ |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 689 | if (gspca_dev->cam.cam_mode[mode].pixelformat |
| 690 | != fmt->fmt.pix.pixelformat) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 691 | |
| 692 | /* else, search the closest mode with the same pixel format */ |
| 693 | mode2 = gspca_get_mode(gspca_dev, mode, |
| 694 | fmt->fmt.pix.pixelformat); |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 695 | if (mode2 >= 0) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 696 | mode = mode2; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 697 | /* else |
| 698 | ; * no chance, return this mode */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 699 | } |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 700 | memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode], |
| 701 | sizeof fmt->fmt.pix); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 702 | return mode; /* used when s_fmt */ |
| 703 | } |
| 704 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 705 | static int vidioc_try_fmt_vid_cap(struct file *file, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 706 | void *priv, |
| 707 | struct v4l2_format *fmt) |
| 708 | { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 709 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 710 | int ret; |
| 711 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 712 | ret = try_fmt_vid_cap(gspca_dev, fmt); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 713 | if (ret < 0) |
| 714 | return ret; |
| 715 | return 0; |
| 716 | } |
| 717 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 718 | 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] | 719 | struct v4l2_format *fmt) |
| 720 | { |
| 721 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 722 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 723 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 724 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 725 | return -ERESTARTSYS; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 726 | |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 727 | ret = try_fmt_vid_cap(gspca_dev, fmt); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 728 | if (ret < 0) |
| 729 | goto out; |
| 730 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 731 | if (gspca_dev->nframes != 0 |
| 732 | && fmt->fmt.pix.sizeimage > gspca_dev->frsz) { |
| 733 | ret = -EINVAL; |
| 734 | goto out; |
| 735 | } |
| 736 | |
Jean-Francois Moine | 50a871f | 2008-06-30 19:47:33 -0300 | [diff] [blame] | 737 | if (ret == gspca_dev->curr_mode) { |
| 738 | ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 739 | goto out; /* same mode */ |
Jean-Francois Moine | 50a871f | 2008-06-30 19:47:33 -0300 | [diff] [blame] | 740 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 741 | |
| 742 | if (gspca_dev->streaming) { |
| 743 | ret = -EBUSY; |
| 744 | goto out; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 745 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 746 | gspca_dev->width = fmt->fmt.pix.width; |
| 747 | gspca_dev->height = fmt->fmt.pix.height; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 748 | gspca_dev->pixfmt = fmt->fmt.pix.pixelformat; |
| 749 | gspca_dev->curr_mode = ret; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 750 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 751 | ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 752 | out: |
| 753 | mutex_unlock(&gspca_dev->queue_lock); |
| 754 | return ret; |
| 755 | } |
| 756 | |
| 757 | static int dev_open(struct inode *inode, struct file *file) |
| 758 | { |
| 759 | struct gspca_dev *gspca_dev; |
| 760 | int ret; |
| 761 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 762 | PDEBUG(D_STREAM, "%s open", current->comm); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 763 | gspca_dev = (struct gspca_dev *) video_devdata(file); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 764 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 765 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 766 | if (!gspca_dev->present) { |
| 767 | ret = -ENODEV; |
| 768 | goto out; |
| 769 | } |
| 770 | |
| 771 | /* if not done yet, initialize the sensor */ |
| 772 | if (gspca_dev->users == 0) { |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 773 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) { |
| 774 | ret = -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 775 | goto out; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 776 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 777 | ret = gspca_dev->sd_desc->open(gspca_dev); |
| 778 | mutex_unlock(&gspca_dev->usb_lock); |
| 779 | if (ret != 0) { |
| 780 | PDEBUG(D_ERR|D_CONF, "init device failed %d", ret); |
| 781 | goto out; |
| 782 | } |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 783 | } else if (gspca_dev->users > 4) { /* (arbitrary value) */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 784 | ret = -EBUSY; |
| 785 | goto out; |
| 786 | } |
| 787 | gspca_dev->users++; |
| 788 | file->private_data = gspca_dev; |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 789 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 790 | /* activate the v4l2 debug */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 791 | if (gspca_debug & D_V4L2) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 792 | gspca_dev->vdev.debug |= 3; |
| 793 | else |
| 794 | gspca_dev->vdev.debug &= ~3; |
| 795 | #endif |
| 796 | out: |
| 797 | mutex_unlock(&gspca_dev->queue_lock); |
| 798 | if (ret != 0) |
| 799 | PDEBUG(D_ERR|D_STREAM, "open failed err %d", ret); |
| 800 | else |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 801 | PDEBUG(D_STREAM, "open done"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | static int dev_close(struct inode *inode, struct file *file) |
| 806 | { |
| 807 | struct gspca_dev *gspca_dev = file->private_data; |
| 808 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 809 | PDEBUG(D_STREAM, "%s close", current->comm); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 810 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 811 | return -ERESTARTSYS; |
| 812 | gspca_dev->users--; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 813 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 814 | /* if the file did the capture, free the streaming resources */ |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 815 | if (gspca_dev->capt_file == file) { |
| 816 | mutex_lock(&gspca_dev->usb_lock); |
| 817 | if (gspca_dev->streaming) |
| 818 | gspca_stream_off(gspca_dev); |
| 819 | gspca_dev->sd_desc->close(gspca_dev); |
| 820 | mutex_unlock(&gspca_dev->usb_lock); |
| 821 | frame_free(gspca_dev); |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 822 | gspca_dev->capt_file = NULL; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 823 | gspca_dev->memory = GSPCA_MEMORY_NO; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 824 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 825 | file->private_data = NULL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 826 | mutex_unlock(&gspca_dev->queue_lock); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 827 | PDEBUG(D_STREAM, "close done"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int vidioc_querycap(struct file *file, void *priv, |
| 832 | struct v4l2_capability *cap) |
| 833 | { |
| 834 | struct gspca_dev *gspca_dev = priv; |
| 835 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 836 | memset(cap, 0, sizeof *cap); |
| 837 | strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver); |
Jean-Francois Moine | c6edaf1 | 2008-07-23 03:24:06 -0300 | [diff] [blame] | 838 | /* strncpy(cap->card, gspca_dev->cam.dev_name, sizeof cap->card); */ |
| 839 | if (gspca_dev->dev->product != NULL) { |
| 840 | strncpy(cap->card, gspca_dev->dev->product, |
| 841 | sizeof cap->card); |
| 842 | } else { |
| 843 | snprintf(cap->card, sizeof cap->card, |
| 844 | "USB Camera (%04x:%04x)", |
| 845 | le16_to_cpu(gspca_dev->dev->descriptor.idVendor), |
| 846 | le16_to_cpu(gspca_dev->dev->descriptor.idProduct)); |
| 847 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 848 | strncpy(cap->bus_info, gspca_dev->dev->bus->bus_name, |
| 849 | sizeof cap->bus_info); |
| 850 | cap->version = DRIVER_VERSION_NUMBER; |
| 851 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
| 852 | | V4L2_CAP_STREAMING |
| 853 | | V4L2_CAP_READWRITE; |
| 854 | return 0; |
| 855 | } |
| 856 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 857 | /* the use of V4L2_CTRL_FLAG_NEXT_CTRL asks for the controls to be sorted */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 858 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 859 | struct v4l2_queryctrl *q_ctrl) |
| 860 | { |
| 861 | struct gspca_dev *gspca_dev = priv; |
| 862 | int i; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 863 | u32 id; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 864 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 865 | id = q_ctrl->id; |
| 866 | if (id & V4L2_CTRL_FLAG_NEXT_CTRL) { |
| 867 | id &= V4L2_CTRL_ID_MASK; |
| 868 | id++; |
| 869 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
| 870 | if (id >= gspca_dev->sd_desc->ctrls[i].qctrl.id) { |
| 871 | memcpy(q_ctrl, |
| 872 | &gspca_dev->sd_desc->ctrls[i].qctrl, |
| 873 | sizeof *q_ctrl); |
| 874 | return 0; |
| 875 | } |
| 876 | } |
| 877 | return -EINVAL; |
| 878 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 879 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 880 | if (id == gspca_dev->sd_desc->ctrls[i].qctrl.id) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 881 | memcpy(q_ctrl, |
| 882 | &gspca_dev->sd_desc->ctrls[i].qctrl, |
| 883 | sizeof *q_ctrl); |
| 884 | return 0; |
| 885 | } |
| 886 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 887 | if (id >= V4L2_CID_BASE |
| 888 | && id <= V4L2_CID_LASTP1) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 889 | q_ctrl->flags |= V4L2_CTRL_FLAG_DISABLED; |
| 890 | return 0; |
| 891 | } |
| 892 | return -EINVAL; |
| 893 | } |
| 894 | |
| 895 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 896 | struct v4l2_control *ctrl) |
| 897 | { |
| 898 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 899 | const struct ctrl *ctrls; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 900 | int i, ret; |
| 901 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 902 | for (i = 0, ctrls = gspca_dev->sd_desc->ctrls; |
| 903 | i < gspca_dev->sd_desc->nctrls; |
| 904 | i++, ctrls++) { |
| 905 | if (ctrl->id != ctrls->qctrl.id) |
| 906 | continue; |
| 907 | if (ctrl->value < ctrls->qctrl.minimum |
Rabin Vincent | fcf5cb2 | 2008-08-03 07:58:54 -0300 | [diff] [blame] | 908 | || ctrl->value > ctrls->qctrl.maximum) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 909 | return -ERANGE; |
| 910 | PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 911 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 912 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 913 | ret = ctrls->set(gspca_dev, ctrl->value); |
| 914 | mutex_unlock(&gspca_dev->usb_lock); |
| 915 | return ret; |
| 916 | } |
| 917 | return -EINVAL; |
| 918 | } |
| 919 | |
| 920 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 921 | struct v4l2_control *ctrl) |
| 922 | { |
| 923 | struct gspca_dev *gspca_dev = priv; |
| 924 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 925 | const struct ctrl *ctrls; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 926 | int i, ret; |
| 927 | |
| 928 | for (i = 0, ctrls = gspca_dev->sd_desc->ctrls; |
| 929 | i < gspca_dev->sd_desc->nctrls; |
| 930 | i++, ctrls++) { |
| 931 | if (ctrl->id != ctrls->qctrl.id) |
| 932 | continue; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 933 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 934 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 935 | ret = ctrls->get(gspca_dev, &ctrl->value); |
| 936 | mutex_unlock(&gspca_dev->usb_lock); |
| 937 | return ret; |
| 938 | } |
| 939 | return -EINVAL; |
| 940 | } |
| 941 | |
| 942 | static int vidioc_querymenu(struct file *file, void *priv, |
| 943 | struct v4l2_querymenu *qmenu) |
| 944 | { |
| 945 | struct gspca_dev *gspca_dev = priv; |
| 946 | |
| 947 | if (!gspca_dev->sd_desc->querymenu) |
| 948 | return -EINVAL; |
| 949 | return gspca_dev->sd_desc->querymenu(gspca_dev, qmenu); |
| 950 | } |
| 951 | |
| 952 | static int vidioc_enum_input(struct file *file, void *priv, |
| 953 | struct v4l2_input *input) |
| 954 | { |
| 955 | struct gspca_dev *gspca_dev = priv; |
| 956 | |
| 957 | if (input->index != 0) |
| 958 | return -EINVAL; |
| 959 | memset(input, 0, sizeof *input); |
| 960 | input->type = V4L2_INPUT_TYPE_CAMERA; |
| 961 | strncpy(input->name, gspca_dev->sd_desc->name, |
| 962 | sizeof input->name); |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) |
| 967 | { |
| 968 | *i = 0; |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | static int vidioc_s_input(struct file *file, void *priv, unsigned int i) |
| 973 | { |
| 974 | if (i > 0) |
| 975 | return -EINVAL; |
| 976 | return (0); |
| 977 | } |
| 978 | |
| 979 | static int vidioc_reqbufs(struct file *file, void *priv, |
| 980 | struct v4l2_requestbuffers *rb) |
| 981 | { |
| 982 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 983 | int i, ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 984 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 985 | if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 986 | return -EINVAL; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 987 | switch (rb->memory) { |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 988 | case GSPCA_MEMORY_READ: /* (internal call) */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 989 | case V4L2_MEMORY_MMAP: |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 990 | case V4L2_MEMORY_USERPTR: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 991 | break; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 992 | default: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 993 | return -EINVAL; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 994 | } |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 995 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 996 | return -ERESTARTSYS; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 997 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 998 | if (gspca_dev->memory != GSPCA_MEMORY_NO |
| 999 | && gspca_dev->memory != rb->memory) { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1000 | ret = -EBUSY; |
| 1001 | goto out; |
| 1002 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1003 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1004 | /* only one file may do the capture */ |
| 1005 | if (gspca_dev->capt_file != NULL |
| 1006 | && gspca_dev->capt_file != file) { |
| 1007 | ret = -EBUSY; |
| 1008 | goto out; |
| 1009 | } |
| 1010 | |
| 1011 | /* if allocated, the buffers must not be mapped */ |
| 1012 | for (i = 0; i < gspca_dev->nframes; i++) { |
| 1013 | if (gspca_dev->frame[i].vma_use_count) { |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1014 | ret = -EBUSY; |
| 1015 | goto out; |
| 1016 | } |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | /* stop streaming */ |
| 1020 | if (gspca_dev->streaming) { |
| 1021 | mutex_lock(&gspca_dev->usb_lock); |
| 1022 | gspca_stream_off(gspca_dev); |
| 1023 | mutex_unlock(&gspca_dev->usb_lock); |
| 1024 | } |
| 1025 | |
| 1026 | /* free the previous allocated buffers, if any */ |
| 1027 | if (gspca_dev->nframes != 0) { |
| 1028 | frame_free(gspca_dev); |
| 1029 | gspca_dev->capt_file = NULL; |
| 1030 | } |
| 1031 | if (rb->count == 0) /* unrequest */ |
| 1032 | goto out; |
| 1033 | gspca_dev->memory = rb->memory; |
| 1034 | ret = frame_alloc(gspca_dev, rb->count); |
| 1035 | if (ret == 0) { |
| 1036 | rb->count = gspca_dev->nframes; |
| 1037 | gspca_dev->capt_file = file; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1038 | } |
| 1039 | out: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1040 | mutex_unlock(&gspca_dev->queue_lock); |
| 1041 | PDEBUG(D_STREAM, "reqbufs st:%d c:%d", ret, rb->count); |
| 1042 | return ret; |
| 1043 | } |
| 1044 | |
| 1045 | static int vidioc_querybuf(struct file *file, void *priv, |
| 1046 | struct v4l2_buffer *v4l2_buf) |
| 1047 | { |
| 1048 | struct gspca_dev *gspca_dev = priv; |
| 1049 | struct gspca_frame *frame; |
| 1050 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1051 | if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE |
| 1052 | || v4l2_buf->index < 0 |
| 1053 | || v4l2_buf->index >= gspca_dev->nframes) |
| 1054 | return -EINVAL; |
| 1055 | |
| 1056 | frame = &gspca_dev->frame[v4l2_buf->index]; |
| 1057 | memcpy(v4l2_buf, &frame->v4l2_buf, sizeof *v4l2_buf); |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | static int vidioc_streamon(struct file *file, void *priv, |
| 1062 | enum v4l2_buf_type buf_type) |
| 1063 | { |
| 1064 | struct gspca_dev *gspca_dev = priv; |
| 1065 | int ret; |
| 1066 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1067 | if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1068 | return -EINVAL; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1069 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1070 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1071 | if (!gspca_dev->present) { |
| 1072 | ret = -ENODEV; |
| 1073 | goto out; |
| 1074 | } |
| 1075 | if (gspca_dev->nframes == 0) { |
| 1076 | ret = -EINVAL; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | if (!gspca_dev->streaming) { |
| 1080 | ret = gspca_init_transfer(gspca_dev); |
| 1081 | if (ret < 0) |
| 1082 | goto out; |
| 1083 | } |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 1084 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1085 | if (gspca_debug & D_STREAM) { |
| 1086 | PDEBUG_MODE("stream on OK", |
| 1087 | gspca_dev->pixfmt, |
| 1088 | gspca_dev->width, |
| 1089 | gspca_dev->height); |
| 1090 | } |
| 1091 | #endif |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1092 | ret = 0; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1093 | out: |
| 1094 | mutex_unlock(&gspca_dev->queue_lock); |
| 1095 | return ret; |
| 1096 | } |
| 1097 | |
| 1098 | static int vidioc_streamoff(struct file *file, void *priv, |
| 1099 | enum v4l2_buf_type buf_type) |
| 1100 | { |
| 1101 | struct gspca_dev *gspca_dev = priv; |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1102 | int i, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1103 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1104 | if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1105 | return -EINVAL; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1106 | if (!gspca_dev->streaming) |
| 1107 | return 0; |
| 1108 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1109 | return -ERESTARTSYS; |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1110 | |
| 1111 | /* stop streaming */ |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1112 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) { |
| 1113 | ret = -ERESTARTSYS; |
| 1114 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1115 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1116 | gspca_stream_off(gspca_dev); |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1117 | mutex_unlock(&gspca_dev->usb_lock); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1118 | |
| 1119 | /* empty the application queues */ |
| 1120 | for (i = 0; i < gspca_dev->nframes; i++) |
| 1121 | gspca_dev->frame[i].v4l2_buf.flags &= ~BUF_ALL_FLAGS; |
| 1122 | gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; |
| 1123 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 1124 | gspca_dev->sequence = 0; |
| 1125 | atomic_set(&gspca_dev->nevent, 0); |
| 1126 | ret = 0; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1127 | out: |
| 1128 | mutex_unlock(&gspca_dev->queue_lock); |
| 1129 | return ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static int vidioc_g_jpegcomp(struct file *file, void *priv, |
| 1133 | struct v4l2_jpegcompression *jpegcomp) |
| 1134 | { |
| 1135 | struct gspca_dev *gspca_dev = priv; |
| 1136 | int ret; |
| 1137 | |
| 1138 | if (!gspca_dev->sd_desc->get_jcomp) |
| 1139 | return -EINVAL; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1140 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1141 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1142 | ret = gspca_dev->sd_desc->get_jcomp(gspca_dev, jpegcomp); |
| 1143 | mutex_unlock(&gspca_dev->usb_lock); |
| 1144 | return ret; |
| 1145 | } |
| 1146 | |
| 1147 | static int vidioc_s_jpegcomp(struct file *file, void *priv, |
| 1148 | struct v4l2_jpegcompression *jpegcomp) |
| 1149 | { |
| 1150 | struct gspca_dev *gspca_dev = priv; |
| 1151 | int ret; |
| 1152 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1153 | if (mutex_lock_interruptible(&gspca_dev->usb_lock)) |
| 1154 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1155 | if (!gspca_dev->sd_desc->set_jcomp) |
| 1156 | return -EINVAL; |
| 1157 | ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp); |
| 1158 | mutex_unlock(&gspca_dev->usb_lock); |
| 1159 | return ret; |
| 1160 | } |
| 1161 | |
| 1162 | static int vidioc_g_parm(struct file *filp, void *priv, |
| 1163 | struct v4l2_streamparm *parm) |
| 1164 | { |
| 1165 | struct gspca_dev *gspca_dev = priv; |
| 1166 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1167 | memset(parm, 0, sizeof *parm); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1168 | parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1169 | parm->parm.capture.readbuffers = gspca_dev->nbufread; |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | static int vidioc_s_parm(struct file *filp, void *priv, |
| 1174 | struct v4l2_streamparm *parm) |
| 1175 | { |
| 1176 | struct gspca_dev *gspca_dev = priv; |
| 1177 | int n; |
| 1178 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1179 | n = parm->parm.capture.readbuffers; |
| 1180 | if (n == 0 || n > GSPCA_MAX_FRAMES) |
| 1181 | parm->parm.capture.readbuffers = gspca_dev->nbufread; |
| 1182 | else |
| 1183 | gspca_dev->nbufread = n; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1184 | return 0; |
| 1185 | } |
| 1186 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1187 | static int vidioc_s_std(struct file *filp, void *priv, |
| 1188 | v4l2_std_id *parm) |
| 1189 | { |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1193 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1194 | static int vidiocgmbuf(struct file *file, void *priv, |
| 1195 | struct video_mbuf *mbuf) |
| 1196 | { |
| 1197 | struct gspca_dev *gspca_dev = file->private_data; |
| 1198 | int i; |
| 1199 | |
| 1200 | PDEBUG(D_STREAM, "cgmbuf"); |
| 1201 | if (gspca_dev->nframes == 0) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1202 | int ret; |
| 1203 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1204 | { |
| 1205 | struct v4l2_format fmt; |
| 1206 | |
| 1207 | memset(&fmt, 0, sizeof fmt); |
| 1208 | fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1209 | i = gspca_dev->cam.nmodes - 1; /* highest mode */ |
| 1210 | fmt.fmt.pix.width = gspca_dev->cam.cam_mode[i].width; |
| 1211 | fmt.fmt.pix.height = gspca_dev->cam.cam_mode[i].height; |
| 1212 | fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR24; |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1213 | ret = vidioc_s_fmt_vid_cap(file, priv, &fmt); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1214 | if (ret != 0) |
| 1215 | return ret; |
| 1216 | } |
| 1217 | { |
| 1218 | struct v4l2_requestbuffers rb; |
| 1219 | |
| 1220 | memset(&rb, 0, sizeof rb); |
| 1221 | rb.count = 4; |
| 1222 | rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1223 | rb.memory = V4L2_MEMORY_MMAP; |
| 1224 | ret = vidioc_reqbufs(file, priv, &rb); |
| 1225 | if (ret != 0) |
| 1226 | return ret; |
| 1227 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1228 | } |
| 1229 | mbuf->frames = gspca_dev->nframes; |
| 1230 | mbuf->size = gspca_dev->frsz * gspca_dev->nframes; |
| 1231 | for (i = 0; i < mbuf->frames; i++) |
| 1232 | mbuf->offsets[i] = gspca_dev->frame[i].v4l2_buf.m.offset; |
| 1233 | return 0; |
| 1234 | } |
| 1235 | #endif |
| 1236 | |
| 1237 | static int dev_mmap(struct file *file, struct vm_area_struct *vma) |
| 1238 | { |
| 1239 | struct gspca_dev *gspca_dev = file->private_data; |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 1240 | struct gspca_frame *frame; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1241 | struct page *page; |
| 1242 | unsigned long addr, start, size; |
| 1243 | int i, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1244 | |
| 1245 | start = vma->vm_start; |
| 1246 | size = vma->vm_end - vma->vm_start; |
| 1247 | PDEBUG(D_STREAM, "mmap start:%08x size:%d", (int) start, (int) size); |
| 1248 | |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1249 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1250 | return -ERESTARTSYS; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1251 | if (!gspca_dev->present) { |
| 1252 | ret = -ENODEV; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1253 | goto out; |
| 1254 | } |
| 1255 | if (gspca_dev->capt_file != file) { |
| 1256 | ret = -EINVAL; |
| 1257 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1258 | } |
| 1259 | |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 1260 | frame = NULL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1261 | for (i = 0; i < gspca_dev->nframes; ++i) { |
| 1262 | if (gspca_dev->frame[i].v4l2_buf.memory != V4L2_MEMORY_MMAP) { |
| 1263 | PDEBUG(D_STREAM, "mmap bad memory type"); |
| 1264 | break; |
| 1265 | } |
| 1266 | if ((gspca_dev->frame[i].v4l2_buf.m.offset >> PAGE_SHIFT) |
| 1267 | == vma->vm_pgoff) { |
| 1268 | frame = &gspca_dev->frame[i]; |
| 1269 | break; |
| 1270 | } |
| 1271 | } |
Harvey Harrison | efab821 | 2008-07-05 06:12:47 -0300 | [diff] [blame] | 1272 | if (frame == NULL) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1273 | PDEBUG(D_STREAM, "mmap no frame buffer found"); |
| 1274 | ret = -EINVAL; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1275 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1276 | } |
| 1277 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1278 | /* v4l1 maps all the buffers */ |
| 1279 | if (i != 0 |
| 1280 | || size != frame->v4l2_buf.length * gspca_dev->nframes) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1281 | #endif |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1282 | if (size != frame->v4l2_buf.length) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1283 | PDEBUG(D_STREAM, "mmap bad size"); |
| 1284 | ret = -EINVAL; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1285 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | /* |
| 1289 | * - VM_IO marks the area as being a mmaped region for I/O to a |
| 1290 | * device. It also prevents the region from being core dumped. |
| 1291 | */ |
| 1292 | vma->vm_flags |= VM_IO; |
| 1293 | |
| 1294 | addr = (unsigned long) frame->data; |
| 1295 | while (size > 0) { |
| 1296 | page = vmalloc_to_page((void *) addr); |
| 1297 | ret = vm_insert_page(vma, start, page); |
| 1298 | if (ret < 0) |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1299 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1300 | start += PAGE_SIZE; |
| 1301 | addr += PAGE_SIZE; |
| 1302 | size -= PAGE_SIZE; |
| 1303 | } |
| 1304 | |
| 1305 | vma->vm_ops = &gspca_vm_ops; |
| 1306 | vma->vm_private_data = frame; |
| 1307 | gspca_vm_open(vma); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1308 | ret = 0; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1309 | out: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1310 | mutex_unlock(&gspca_dev->queue_lock); |
| 1311 | return ret; |
| 1312 | } |
| 1313 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1314 | /* |
| 1315 | * wait for a video frame |
| 1316 | * |
| 1317 | * If a frame is ready, its index is returned. |
| 1318 | */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1319 | static int frame_wait(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1320 | int nonblock_ing) |
| 1321 | { |
| 1322 | struct gspca_frame *frame; |
| 1323 | int i, j, ret; |
| 1324 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1325 | /* check if a frame is ready */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1326 | i = gspca_dev->fr_o; |
| 1327 | j = gspca_dev->fr_queue[i]; |
| 1328 | frame = &gspca_dev->frame[j]; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1329 | if (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) { |
| 1330 | atomic_dec(&gspca_dev->nevent); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1331 | goto ok; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1332 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1333 | if (nonblock_ing) /* no frame yet */ |
| 1334 | return -EAGAIN; |
| 1335 | |
| 1336 | /* wait till a frame is ready */ |
| 1337 | for (;;) { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1338 | ret = wait_event_interruptible_timeout(gspca_dev->wq, |
| 1339 | atomic_read(&gspca_dev->nevent) > 0, |
| 1340 | msecs_to_jiffies(3000)); |
| 1341 | if (ret <= 0) { |
| 1342 | if (ret < 0) |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1343 | return ret; /* interrupt */ |
| 1344 | return -EIO; /* timeout */ |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1345 | } |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1346 | atomic_dec(&gspca_dev->nevent); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1347 | if (!gspca_dev->streaming || !gspca_dev->present) |
| 1348 | return -EIO; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1349 | i = gspca_dev->fr_o; |
| 1350 | j = gspca_dev->fr_queue[i]; |
| 1351 | frame = &gspca_dev->frame[j]; |
| 1352 | if (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) |
| 1353 | break; |
| 1354 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1355 | ok: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1356 | gspca_dev->fr_o = (i + 1) % gspca_dev->nframes; |
| 1357 | PDEBUG(D_FRAM, "frame wait q:%d i:%d o:%d", |
| 1358 | gspca_dev->fr_q, |
| 1359 | gspca_dev->fr_i, |
| 1360 | gspca_dev->fr_o); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1361 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 1362 | if (gspca_dev->sd_desc->dq_callback) { |
| 1363 | mutex_lock(&gspca_dev->usb_lock); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1364 | gspca_dev->sd_desc->dq_callback(gspca_dev); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 1365 | mutex_unlock(&gspca_dev->usb_lock); |
| 1366 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1367 | return j; |
| 1368 | } |
| 1369 | |
| 1370 | /* |
| 1371 | * dequeue a video buffer |
| 1372 | * |
| 1373 | * If nonblock_ing is false, block until a buffer is available. |
| 1374 | */ |
| 1375 | static int vidioc_dqbuf(struct file *file, void *priv, |
| 1376 | struct v4l2_buffer *v4l2_buf) |
| 1377 | { |
| 1378 | struct gspca_dev *gspca_dev = priv; |
| 1379 | struct gspca_frame *frame; |
| 1380 | int i, ret; |
| 1381 | |
| 1382 | PDEBUG(D_FRAM, "dqbuf"); |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1383 | if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1384 | return -EINVAL; |
| 1385 | if (v4l2_buf->memory != gspca_dev->memory) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1386 | return -EINVAL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1387 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1388 | /* if not streaming, be sure the application will not loop forever */ |
| 1389 | if (!(file->f_flags & O_NONBLOCK) |
| 1390 | && !gspca_dev->streaming && gspca_dev->users == 1) |
| 1391 | return -EINVAL; |
| 1392 | |
| 1393 | /* only the capturing file may dequeue */ |
| 1394 | if (gspca_dev->capt_file != file) |
| 1395 | return -EINVAL; |
| 1396 | |
| 1397 | /* only one dequeue / read at a time */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1398 | if (mutex_lock_interruptible(&gspca_dev->read_lock)) |
| 1399 | return -ERESTARTSYS; |
| 1400 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1401 | ret = frame_wait(gspca_dev, file->f_flags & O_NONBLOCK); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1402 | if (ret < 0) |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1403 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1404 | i = ret; /* frame index */ |
| 1405 | frame = &gspca_dev->frame[i]; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1406 | if (gspca_dev->memory == V4L2_MEMORY_USERPTR) { |
| 1407 | if (copy_to_user((__u8 *) frame->v4l2_buf.m.userptr, |
| 1408 | frame->data, |
| 1409 | frame->v4l2_buf.bytesused)) { |
| 1410 | PDEBUG(D_ERR|D_STREAM, |
| 1411 | "dqbuf cp to user failed"); |
| 1412 | ret = -EFAULT; |
| 1413 | goto out; |
| 1414 | } |
| 1415 | } |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1416 | frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_DONE; |
| 1417 | memcpy(v4l2_buf, &frame->v4l2_buf, sizeof *v4l2_buf); |
| 1418 | PDEBUG(D_FRAM, "dqbuf %d", i); |
| 1419 | ret = 0; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1420 | out: |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1421 | mutex_unlock(&gspca_dev->read_lock); |
| 1422 | return ret; |
| 1423 | } |
| 1424 | |
| 1425 | /* |
| 1426 | * queue a video buffer |
| 1427 | * |
| 1428 | * Attempting to queue a buffer that has already been |
| 1429 | * queued will return -EINVAL. |
| 1430 | */ |
| 1431 | static int vidioc_qbuf(struct file *file, void *priv, |
| 1432 | struct v4l2_buffer *v4l2_buf) |
| 1433 | { |
| 1434 | struct gspca_dev *gspca_dev = priv; |
| 1435 | struct gspca_frame *frame; |
| 1436 | int i, index, ret; |
| 1437 | |
| 1438 | PDEBUG(D_FRAM, "qbuf %d", v4l2_buf->index); |
| 1439 | if (v4l2_buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1440 | return -EINVAL; |
| 1441 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1442 | if (mutex_lock_interruptible(&gspca_dev->queue_lock)) |
| 1443 | return -ERESTARTSYS; |
| 1444 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1445 | index = v4l2_buf->index; |
| 1446 | if ((unsigned) index >= gspca_dev->nframes) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1447 | PDEBUG(D_FRAM, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1448 | "qbuf idx %d >= %d", index, gspca_dev->nframes); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1449 | ret = -EINVAL; |
| 1450 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1451 | } |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1452 | if (v4l2_buf->memory != gspca_dev->memory) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1453 | PDEBUG(D_FRAM, "qbuf bad memory type"); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1454 | ret = -EINVAL; |
| 1455 | goto out; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1456 | } |
| 1457 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1458 | frame = &gspca_dev->frame[index]; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1459 | if (frame->v4l2_buf.flags & BUF_ALL_FLAGS) { |
| 1460 | PDEBUG(D_FRAM, "qbuf bad state"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1461 | ret = -EINVAL; |
| 1462 | goto out; |
| 1463 | } |
| 1464 | |
| 1465 | frame->v4l2_buf.flags |= V4L2_BUF_FLAG_QUEUED; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1466 | /* frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_DONE; */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1467 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1468 | if (frame->v4l2_buf.memory == V4L2_MEMORY_USERPTR) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1469 | frame->v4l2_buf.m.userptr = v4l2_buf->m.userptr; |
| 1470 | frame->v4l2_buf.length = v4l2_buf->length; |
| 1471 | } |
| 1472 | |
| 1473 | /* put the buffer in the 'queued' queue */ |
| 1474 | i = gspca_dev->fr_q; |
| 1475 | gspca_dev->fr_queue[i] = index; |
| 1476 | gspca_dev->fr_q = (i + 1) % gspca_dev->nframes; |
| 1477 | PDEBUG(D_FRAM, "qbuf q:%d i:%d o:%d", |
| 1478 | gspca_dev->fr_q, |
| 1479 | gspca_dev->fr_i, |
| 1480 | gspca_dev->fr_o); |
| 1481 | |
| 1482 | v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED; |
| 1483 | v4l2_buf->flags &= ~V4L2_BUF_FLAG_DONE; |
| 1484 | ret = 0; |
| 1485 | out: |
| 1486 | mutex_unlock(&gspca_dev->queue_lock); |
| 1487 | return ret; |
| 1488 | } |
| 1489 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1490 | /* |
| 1491 | * allocate the resources for read() |
| 1492 | */ |
| 1493 | static int read_alloc(struct gspca_dev *gspca_dev, |
| 1494 | struct file *file) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1495 | { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1496 | struct v4l2_buffer v4l2_buf; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1497 | int i, ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1498 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1499 | PDEBUG(D_STREAM, "read alloc"); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1500 | if (gspca_dev->nframes == 0) { |
| 1501 | struct v4l2_requestbuffers rb; |
| 1502 | |
| 1503 | memset(&rb, 0, sizeof rb); |
| 1504 | rb.count = gspca_dev->nbufread; |
| 1505 | rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1506 | rb.memory = GSPCA_MEMORY_READ; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1507 | ret = vidioc_reqbufs(file, gspca_dev, &rb); |
| 1508 | if (ret != 0) { |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1509 | PDEBUG(D_STREAM, "read reqbuf err %d", ret); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1510 | return ret; |
| 1511 | } |
| 1512 | memset(&v4l2_buf, 0, sizeof v4l2_buf); |
| 1513 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1514 | v4l2_buf.memory = GSPCA_MEMORY_READ; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1515 | for (i = 0; i < gspca_dev->nbufread; i++) { |
| 1516 | v4l2_buf.index = i; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1517 | ret = vidioc_qbuf(file, gspca_dev, &v4l2_buf); |
| 1518 | if (ret != 0) { |
| 1519 | PDEBUG(D_STREAM, "read qbuf err: %d", ret); |
| 1520 | return ret; |
| 1521 | } |
| 1522 | } |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1523 | gspca_dev->memory = GSPCA_MEMORY_READ; |
| 1524 | } |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1525 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1526 | /* start streaming */ |
| 1527 | ret = vidioc_streamon(file, gspca_dev, V4L2_BUF_TYPE_VIDEO_CAPTURE); |
| 1528 | if (ret != 0) |
| 1529 | PDEBUG(D_STREAM, "read streamon err %d", ret); |
| 1530 | return ret; |
| 1531 | } |
| 1532 | |
| 1533 | static unsigned int dev_poll(struct file *file, poll_table *wait) |
| 1534 | { |
| 1535 | struct gspca_dev *gspca_dev = file->private_data; |
| 1536 | int i, ret; |
| 1537 | |
| 1538 | PDEBUG(D_FRAM, "poll"); |
| 1539 | |
| 1540 | poll_wait(file, &gspca_dev->wq, wait); |
| 1541 | if (!gspca_dev->present) |
| 1542 | return POLLERR; |
| 1543 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1544 | /* if reqbufs is not done, the user would use read() */ |
| 1545 | if (gspca_dev->nframes == 0) { |
| 1546 | if (gspca_dev->memory != GSPCA_MEMORY_NO) |
| 1547 | return POLLERR; /* not the 1st time */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1548 | ret = read_alloc(gspca_dev, file); |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1549 | if (ret != 0) |
| 1550 | return POLLERR; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | if (mutex_lock_interruptible(&gspca_dev->queue_lock) != 0) |
| 1554 | return POLLERR; |
| 1555 | if (!gspca_dev->present) { |
| 1556 | ret = POLLERR; |
| 1557 | goto out; |
| 1558 | } |
| 1559 | |
Jean-Francois Moine | 5b77ae7 | 2008-07-12 09:28:04 -0300 | [diff] [blame] | 1560 | /* check the next incoming buffer */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1561 | i = gspca_dev->fr_o; |
| 1562 | i = gspca_dev->fr_queue[i]; |
| 1563 | if (gspca_dev->frame[i].v4l2_buf.flags & V4L2_BUF_FLAG_DONE) |
| 1564 | ret = POLLIN | POLLRDNORM; /* something to read */ |
| 1565 | else |
| 1566 | ret = 0; |
| 1567 | out: |
| 1568 | mutex_unlock(&gspca_dev->queue_lock); |
| 1569 | return ret; |
| 1570 | } |
| 1571 | |
| 1572 | static ssize_t dev_read(struct file *file, char __user *data, |
| 1573 | size_t count, loff_t *ppos) |
| 1574 | { |
| 1575 | struct gspca_dev *gspca_dev = file->private_data; |
| 1576 | struct gspca_frame *frame; |
| 1577 | struct v4l2_buffer v4l2_buf; |
| 1578 | struct timeval timestamp; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1579 | int n, ret, ret2; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1580 | |
Mauro Carvalho Chehab | a9e1113 | 2008-07-09 05:26:26 -0300 | [diff] [blame] | 1581 | PDEBUG(D_FRAM, "read (%zd)", count); |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1582 | if (!gspca_dev->present) |
| 1583 | return -ENODEV; |
| 1584 | switch (gspca_dev->memory) { |
| 1585 | case GSPCA_MEMORY_NO: /* first time */ |
| 1586 | ret = read_alloc(gspca_dev, file); |
| 1587 | if (ret != 0) |
| 1588 | return ret; |
| 1589 | break; |
| 1590 | case GSPCA_MEMORY_READ: |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1591 | if (gspca_dev->capt_file == file) |
| 1592 | break; |
| 1593 | /* fall thru */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1594 | default: |
| 1595 | return -EINVAL; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | /* get a frame */ |
| 1599 | jiffies_to_timeval(get_jiffies_64(), ×tamp); |
| 1600 | timestamp.tv_sec--; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1601 | n = 2; |
| 1602 | for (;;) { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1603 | memset(&v4l2_buf, 0, sizeof v4l2_buf); |
| 1604 | v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1605 | v4l2_buf.memory = GSPCA_MEMORY_READ; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1606 | ret = vidioc_dqbuf(file, gspca_dev, &v4l2_buf); |
| 1607 | if (ret != 0) { |
| 1608 | PDEBUG(D_STREAM, "read dqbuf err %d", ret); |
| 1609 | return ret; |
| 1610 | } |
| 1611 | |
| 1612 | /* if the process slept for more than 1 second, |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1613 | * get anewer frame */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1614 | frame = &gspca_dev->frame[v4l2_buf.index]; |
Jean-Francois Moine | 82643d0 | 2008-07-02 09:14:56 -0300 | [diff] [blame] | 1615 | if (--n < 0) |
| 1616 | break; /* avoid infinite loop */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1617 | if (frame->v4l2_buf.timestamp.tv_sec >= timestamp.tv_sec) |
| 1618 | break; |
| 1619 | ret = vidioc_qbuf(file, gspca_dev, &v4l2_buf); |
| 1620 | if (ret != 0) { |
| 1621 | PDEBUG(D_STREAM, "read qbuf err %d", ret); |
| 1622 | return ret; |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | /* copy the frame */ |
Jean-Francois Moine | ac0d6df | 2008-07-08 06:58:15 -0300 | [diff] [blame] | 1627 | if (count > frame->v4l2_buf.bytesused) |
| 1628 | count = frame->v4l2_buf.bytesused; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1629 | ret = copy_to_user(data, frame->data, count); |
| 1630 | if (ret != 0) { |
| 1631 | PDEBUG(D_ERR|D_STREAM, |
Mauro Carvalho Chehab | a9e1113 | 2008-07-09 05:26:26 -0300 | [diff] [blame] | 1632 | "read cp to user lack %d / %zd", ret, count); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1633 | ret = -EFAULT; |
| 1634 | goto out; |
| 1635 | } |
| 1636 | ret = count; |
| 1637 | out: |
| 1638 | /* in each case, requeue the buffer */ |
| 1639 | ret2 = vidioc_qbuf(file, gspca_dev, &v4l2_buf); |
| 1640 | if (ret2 != 0) |
| 1641 | return ret2; |
| 1642 | return ret; |
| 1643 | } |
| 1644 | |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1645 | static void dev_release(struct video_device *vfd) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1646 | { |
| 1647 | /* nothing */ |
| 1648 | } |
| 1649 | |
| 1650 | static struct file_operations dev_fops = { |
| 1651 | .owner = THIS_MODULE, |
| 1652 | .open = dev_open, |
| 1653 | .release = dev_close, |
| 1654 | .read = dev_read, |
| 1655 | .mmap = dev_mmap, |
| 1656 | .ioctl = video_ioctl2, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1657 | #ifdef CONFIG_COMPAT |
| 1658 | .compat_ioctl = v4l_compat_ioctl32, |
| 1659 | #endif |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1660 | .llseek = no_llseek, |
| 1661 | .poll = dev_poll, |
| 1662 | }; |
| 1663 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1664 | static const struct v4l2_ioctl_ops dev_ioctl_ops = { |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1665 | .vidioc_querycap = vidioc_querycap, |
| 1666 | .vidioc_dqbuf = vidioc_dqbuf, |
| 1667 | .vidioc_qbuf = vidioc_qbuf, |
Mauro Carvalho Chehab | e078770 | 2008-07-01 04:06:22 -0300 | [diff] [blame] | 1668 | .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, |
| 1669 | .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, |
| 1670 | .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, |
| 1671 | .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1672 | .vidioc_streamon = vidioc_streamon, |
| 1673 | .vidioc_queryctrl = vidioc_queryctrl, |
| 1674 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 1675 | .vidioc_s_ctrl = vidioc_s_ctrl, |
| 1676 | .vidioc_querymenu = vidioc_querymenu, |
| 1677 | .vidioc_enum_input = vidioc_enum_input, |
| 1678 | .vidioc_g_input = vidioc_g_input, |
| 1679 | .vidioc_s_input = vidioc_s_input, |
| 1680 | .vidioc_reqbufs = vidioc_reqbufs, |
| 1681 | .vidioc_querybuf = vidioc_querybuf, |
| 1682 | .vidioc_streamoff = vidioc_streamoff, |
| 1683 | .vidioc_g_jpegcomp = vidioc_g_jpegcomp, |
| 1684 | .vidioc_s_jpegcomp = vidioc_s_jpegcomp, |
| 1685 | .vidioc_g_parm = vidioc_g_parm, |
| 1686 | .vidioc_s_parm = vidioc_s_parm, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1687 | .vidioc_s_std = vidioc_s_std, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1688 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 1689 | .vidiocgmbuf = vidiocgmbuf, |
| 1690 | #endif |
| 1691 | }; |
| 1692 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1693 | static struct video_device gspca_template = { |
| 1694 | .name = "gspca main driver", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 1695 | .fops = &dev_fops, |
| 1696 | .ioctl_ops = &dev_ioctl_ops, |
| 1697 | .release = dev_release, /* mandatory */ |
| 1698 | .minor = -1, |
| 1699 | }; |
| 1700 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1701 | /* |
| 1702 | * probe and create a new gspca device |
| 1703 | * |
| 1704 | * This function must be called by the sub-driver when it is |
| 1705 | * called for probing a new device. |
| 1706 | */ |
| 1707 | int gspca_dev_probe(struct usb_interface *intf, |
| 1708 | const struct usb_device_id *id, |
| 1709 | const struct sd_desc *sd_desc, |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1710 | int dev_size, |
| 1711 | struct module *module) |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1712 | { |
| 1713 | struct usb_interface_descriptor *interface; |
| 1714 | struct gspca_dev *gspca_dev; |
| 1715 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1716 | int ret; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1717 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1718 | PDEBUG(D_PROBE, "probing %04x:%04x", id->idVendor, id->idProduct); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1719 | |
| 1720 | /* we don't handle multi-config cameras */ |
| 1721 | if (dev->descriptor.bNumConfigurations != 1) |
| 1722 | return -ENODEV; |
| 1723 | interface = &intf->cur_altsetting->desc; |
| 1724 | if (interface->bInterfaceNumber > 0) |
| 1725 | return -ENODEV; |
| 1726 | |
| 1727 | /* create the device */ |
| 1728 | if (dev_size < sizeof *gspca_dev) |
| 1729 | dev_size = sizeof *gspca_dev; |
| 1730 | gspca_dev = kzalloc(dev_size, GFP_KERNEL); |
| 1731 | if (gspca_dev == NULL) { |
| 1732 | err("couldn't kzalloc gspca struct"); |
| 1733 | return -EIO; |
| 1734 | } |
| 1735 | gspca_dev->dev = dev; |
| 1736 | gspca_dev->iface = interface->bInterfaceNumber; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1737 | gspca_dev->nbalt = intf->num_altsetting; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1738 | gspca_dev->sd_desc = sd_desc; |
| 1739 | /* gspca_dev->users = 0; (done by kzalloc) */ |
| 1740 | gspca_dev->nbufread = 2; |
| 1741 | |
| 1742 | /* configure the subdriver */ |
| 1743 | ret = gspca_dev->sd_desc->config(gspca_dev, id); |
| 1744 | if (ret < 0) |
| 1745 | goto out; |
| 1746 | ret = gspca_set_alt0(gspca_dev); |
| 1747 | if (ret < 0) |
| 1748 | goto out; |
| 1749 | gspca_set_default_mode(gspca_dev); |
| 1750 | |
| 1751 | mutex_init(&gspca_dev->usb_lock); |
| 1752 | mutex_init(&gspca_dev->read_lock); |
| 1753 | mutex_init(&gspca_dev->queue_lock); |
| 1754 | init_waitqueue_head(&gspca_dev->wq); |
| 1755 | |
| 1756 | /* init video stuff */ |
| 1757 | memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template); |
Hans Verkuil | 5e85e73 | 2008-07-20 06:31:39 -0300 | [diff] [blame] | 1758 | gspca_dev->vdev.parent = &dev->dev; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1759 | memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops); |
| 1760 | gspca_dev->vdev.fops = &gspca_dev->fops; |
| 1761 | gspca_dev->fops.owner = module; /* module protection */ |
Oliver Neukum | ee56a4d | 2008-07-27 14:01:59 -0300 | [diff] [blame] | 1762 | gspca_dev->present = 1; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1763 | ret = video_register_device(&gspca_dev->vdev, |
| 1764 | VFL_TYPE_GRABBER, |
| 1765 | video_nr); |
| 1766 | if (ret < 0) { |
| 1767 | err("video_register_device err %d", ret); |
| 1768 | goto out; |
| 1769 | } |
| 1770 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1771 | usb_set_intfdata(intf, gspca_dev); |
| 1772 | PDEBUG(D_PROBE, "probe ok"); |
| 1773 | return 0; |
| 1774 | out: |
| 1775 | kfree(gspca_dev); |
| 1776 | return ret; |
| 1777 | } |
| 1778 | EXPORT_SYMBOL(gspca_dev_probe); |
| 1779 | |
| 1780 | /* |
| 1781 | * USB disconnection |
| 1782 | * |
| 1783 | * This function must be called by the sub-driver |
| 1784 | * when the device disconnects, after the specific resources are freed. |
| 1785 | */ |
| 1786 | void gspca_disconnect(struct usb_interface *intf) |
| 1787 | { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 1788 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1789 | |
| 1790 | if (!gspca_dev) |
| 1791 | return; |
| 1792 | gspca_dev->present = 0; |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1793 | mutex_lock(&gspca_dev->queue_lock); |
| 1794 | mutex_lock(&gspca_dev->usb_lock); |
| 1795 | gspca_dev->streaming = 0; |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1796 | destroy_urbs(gspca_dev); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1797 | mutex_unlock(&gspca_dev->usb_lock); |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 1798 | mutex_unlock(&gspca_dev->queue_lock); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1799 | while (gspca_dev->users != 0) { /* wait until fully closed */ |
| 1800 | atomic_inc(&gspca_dev->nevent); |
| 1801 | wake_up_interruptible(&gspca_dev->wq); /* wake processes */ |
| 1802 | schedule(); |
| 1803 | } |
| 1804 | /* We don't want people trying to open up the device */ |
| 1805 | video_unregister_device(&gspca_dev->vdev); |
| 1806 | /* Free the memory */ |
| 1807 | kfree(gspca_dev); |
| 1808 | PDEBUG(D_PROBE, "disconnect complete"); |
| 1809 | } |
| 1810 | EXPORT_SYMBOL(gspca_disconnect); |
| 1811 | |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame^] | 1812 | #ifdef CONFIG_PM |
| 1813 | int gspca_suspend(struct usb_interface *intf, pm_message_t message) |
| 1814 | { |
| 1815 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); |
| 1816 | |
| 1817 | if (!gspca_dev->streaming) |
| 1818 | return 0; |
| 1819 | gspca_dev->frozen = 1; /* avoid urb error messages */ |
| 1820 | gspca_dev->sd_desc->stopN(gspca_dev); |
| 1821 | destroy_urbs(gspca_dev); |
| 1822 | gspca_set_alt0(gspca_dev); |
| 1823 | gspca_dev->sd_desc->stop0(gspca_dev); |
| 1824 | return 0; |
| 1825 | } |
| 1826 | EXPORT_SYMBOL(gspca_suspend); |
| 1827 | |
| 1828 | int gspca_resume(struct usb_interface *intf) |
| 1829 | { |
| 1830 | struct gspca_dev *gspca_dev = usb_get_intfdata(intf); |
| 1831 | |
| 1832 | gspca_dev->frozen = 0; |
| 1833 | if (!gspca_dev->streaming) |
| 1834 | return 0; |
| 1835 | return gspca_init_transfer(gspca_dev); |
| 1836 | } |
| 1837 | EXPORT_SYMBOL(gspca_resume); |
| 1838 | #endif |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 1839 | /* -- cam driver utility functions -- */ |
| 1840 | |
| 1841 | /* auto gain and exposure algorithm based on the knee algorithm described here: |
| 1842 | http://ytse.tricolour.net/docs/LowLightOptimization.html |
| 1843 | |
| 1844 | Returns 0 if no changes were made, 1 if the gain and or exposure settings |
| 1845 | where changed. */ |
| 1846 | int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum, |
| 1847 | int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee) |
| 1848 | { |
| 1849 | int i, steps, gain, orig_gain, exposure, orig_exposure, autogain; |
| 1850 | const struct ctrl *gain_ctrl = NULL; |
| 1851 | const struct ctrl *exposure_ctrl = NULL; |
| 1852 | const struct ctrl *autogain_ctrl = NULL; |
| 1853 | int retval = 0; |
| 1854 | |
| 1855 | for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { |
| 1856 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN) |
| 1857 | gain_ctrl = &gspca_dev->sd_desc->ctrls[i]; |
| 1858 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE) |
| 1859 | exposure_ctrl = &gspca_dev->sd_desc->ctrls[i]; |
| 1860 | if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_AUTOGAIN) |
| 1861 | autogain_ctrl = &gspca_dev->sd_desc->ctrls[i]; |
| 1862 | } |
| 1863 | if (!gain_ctrl || !exposure_ctrl || !autogain_ctrl) { |
| 1864 | PDEBUG(D_ERR, "Error: gspca_auto_gain_n_exposure called " |
| 1865 | "on cam without (auto)gain/exposure"); |
| 1866 | return 0; |
| 1867 | } |
| 1868 | |
| 1869 | if (gain_ctrl->get(gspca_dev, &gain) || |
| 1870 | exposure_ctrl->get(gspca_dev, &exposure) || |
| 1871 | autogain_ctrl->get(gspca_dev, &autogain) || !autogain) |
| 1872 | return 0; |
| 1873 | |
| 1874 | orig_gain = gain; |
| 1875 | orig_exposure = exposure; |
| 1876 | |
| 1877 | /* If we are of a multiple of deadzone, do multiple steps to reach the |
| 1878 | desired lumination fast (with the risc of a slight overshoot) */ |
| 1879 | steps = abs(desired_avg_lum - avg_lum) / deadzone; |
| 1880 | |
| 1881 | PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d\n", |
| 1882 | avg_lum, desired_avg_lum, steps); |
| 1883 | |
| 1884 | for (i = 0; i < steps; i++) { |
| 1885 | if (avg_lum > desired_avg_lum) { |
| 1886 | if (gain > gain_knee) |
| 1887 | gain--; |
| 1888 | else if (exposure > exposure_knee) |
| 1889 | exposure--; |
| 1890 | else if (gain > gain_ctrl->qctrl.default_value) |
| 1891 | gain--; |
| 1892 | else if (exposure > exposure_ctrl->qctrl.minimum) |
| 1893 | exposure--; |
| 1894 | else if (gain > gain_ctrl->qctrl.minimum) |
| 1895 | gain--; |
| 1896 | else |
| 1897 | break; |
| 1898 | } else { |
| 1899 | if (gain < gain_ctrl->qctrl.default_value) |
| 1900 | gain++; |
| 1901 | else if (exposure < exposure_knee) |
| 1902 | exposure++; |
| 1903 | else if (gain < gain_knee) |
| 1904 | gain++; |
| 1905 | else if (exposure < exposure_ctrl->qctrl.maximum) |
| 1906 | exposure++; |
| 1907 | else if (gain < gain_ctrl->qctrl.maximum) |
| 1908 | gain++; |
| 1909 | else |
| 1910 | break; |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | if (gain != orig_gain) { |
| 1915 | gain_ctrl->set(gspca_dev, gain); |
| 1916 | retval = 1; |
| 1917 | } |
| 1918 | if (exposure != orig_exposure) { |
| 1919 | exposure_ctrl->set(gspca_dev, exposure); |
| 1920 | retval = 1; |
| 1921 | } |
| 1922 | |
| 1923 | return retval; |
| 1924 | } |
| 1925 | EXPORT_SYMBOL(gspca_auto_gain_n_exposure); |
| 1926 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1927 | /* -- module insert / remove -- */ |
| 1928 | static int __init gspca_init(void) |
| 1929 | { |
Jean-Francois Moine | bb64e86 | 2008-07-19 06:49:28 -0300 | [diff] [blame] | 1930 | info("main v%d.%d.%d registered", |
| 1931 | (DRIVER_VERSION_NUMBER >> 16) & 0xff, |
| 1932 | (DRIVER_VERSION_NUMBER >> 8) & 0xff, |
| 1933 | DRIVER_VERSION_NUMBER & 0xff); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1934 | return 0; |
| 1935 | } |
| 1936 | static void __exit gspca_exit(void) |
| 1937 | { |
| 1938 | info("main deregistered"); |
| 1939 | } |
| 1940 | |
| 1941 | module_init(gspca_init); |
| 1942 | module_exit(gspca_exit); |
| 1943 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 1944 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1945 | module_param_named(debug, gspca_debug, int, 0644); |
| 1946 | MODULE_PARM_DESC(debug, |
| 1947 | "Debug (bit) 0x01:error 0x02:probe 0x04:config" |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 1948 | " 0x08:stream 0x10:frame 0x20:packet 0x40:USBin 0x80:USBout" |
| 1949 | " 0x0100: v4l2"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1950 | #endif |