Lines Matching +full:cam +full:- +full:if
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2008-2011 Jean-François Moine <http://moinejf.free.fr>
8 * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu>
27 #include <media/v4l2-ioctl.h>
28 #include <media/v4l2-ctrls.h>
29 #include <media/v4l2-fh.h>
30 #include <media/v4l2-event.h>
34 #if IS_ENABLED(CONFIG_INPUT)
41 #if DEF_NURBS > MAX_NURBS
45 MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
56 if ((pixfmt >> 24) >= '0' && (pixfmt >> 24) <= 'z') { in PDEBUG_MODE()
72 /* specific memory types - !! should be different from V4L2_MEMORY_xxx */
79 #if IS_ENABLED(CONFIG_INPUT)
82 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; in int_irq()
85 ret = urb->status; in int_irq()
88 if (gspca_dev->sd_desc->int_pkt_scan(gspca_dev, in int_irq()
89 urb->transfer_buffer, urb->actual_length) < 0) { in int_irq()
94 case -ENOENT: in int_irq()
95 case -ECONNRESET: in int_irq()
96 case -ENODEV: in int_irq()
97 case -ESHUTDOWN: in int_irq()
99 * keep the ret value non-zero and don't resubmit later. in int_irq()
105 urb->status); in int_irq()
106 urb->status = 0; in int_irq()
110 if (ret == 0) { in int_irq()
112 if (ret < 0) in int_irq()
122 dev->input_dev = NULL; in gspca_input_connect()
123 if (dev->sd_desc->int_pkt_scan || dev->sd_desc->other_input) { in gspca_input_connect()
125 if (!input_dev) in gspca_input_connect()
126 return -ENOMEM; in gspca_input_connect()
128 usb_make_path(dev->dev, dev->phys, sizeof(dev->phys)); in gspca_input_connect()
129 strlcat(dev->phys, "/input0", sizeof(dev->phys)); in gspca_input_connect()
131 input_dev->name = dev->sd_desc->name; in gspca_input_connect()
132 input_dev->phys = dev->phys; in gspca_input_connect()
134 usb_to_input_id(dev->dev, &input_dev->id); in gspca_input_connect()
136 input_dev->evbit[0] = BIT_MASK(EV_KEY); in gspca_input_connect()
137 input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA); in gspca_input_connect()
138 input_dev->dev.parent = &dev->dev->dev; in gspca_input_connect()
141 if (err) { in gspca_input_connect()
144 input_dev->dev.parent = NULL; in gspca_input_connect()
147 dev->input_dev = input_dev; in gspca_input_connect()
162 int ret = -EINVAL; in alloc_and_submit_int_urb()
164 buffer_len = le16_to_cpu(ep->wMaxPacketSize); in alloc_and_submit_int_urb()
165 interval = ep->bInterval; in alloc_and_submit_int_urb()
167 ep->bEndpointAddress, buffer_len, interval); in alloc_and_submit_int_urb()
169 dev = gspca_dev->dev; in alloc_and_submit_int_urb()
172 if (!urb) { in alloc_and_submit_int_urb()
173 ret = -ENOMEM; in alloc_and_submit_int_urb()
178 GFP_KERNEL, &urb->transfer_dma); in alloc_and_submit_int_urb()
179 if (!buffer) { in alloc_and_submit_int_urb()
180 ret = -ENOMEM; in alloc_and_submit_int_urb()
184 usb_rcvintpipe(dev, ep->bEndpointAddress), in alloc_and_submit_int_urb()
187 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in alloc_and_submit_int_urb()
189 if (ret < 0) { in alloc_and_submit_int_urb()
194 gspca_dev->int_urb = urb; in alloc_and_submit_int_urb()
199 urb->transfer_buffer_length, in alloc_and_submit_int_urb()
200 urb->transfer_buffer, in alloc_and_submit_int_urb()
201 urb->transfer_dma); in alloc_and_submit_int_urb()
215 if (gspca_dev->sd_desc->int_pkt_scan) { in gspca_input_create_urb()
216 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); in gspca_input_create_urb()
217 intf_desc = intf->cur_altsetting; in gspca_input_create_urb()
218 for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) { in gspca_input_create_urb()
219 ep = &intf_desc->endpoint[i].desc; in gspca_input_create_urb()
220 if (usb_endpoint_dir_in(ep) && in gspca_input_create_urb()
234 urb = gspca_dev->int_urb; in gspca_input_destroy_urb()
235 if (urb) { in gspca_input_destroy_urb()
236 gspca_dev->int_urb = NULL; in gspca_input_destroy_urb()
238 usb_free_coherent(gspca_dev->dev, in gspca_input_destroy_urb()
239 urb->transfer_buffer_length, in gspca_input_destroy_urb()
240 urb->transfer_buffer, in gspca_input_destroy_urb()
241 urb->transfer_dma); in gspca_input_destroy_urb()
270 if (urb->status != 0) { in fill_frame()
271 if (urb->status == -ESHUTDOWN) in fill_frame()
274 if (gspca_dev->frozen) in fill_frame()
277 gspca_err(gspca_dev, "urb status: %d\n", urb->status); in fill_frame()
278 urb->status = 0; in fill_frame()
281 pkt_scan = gspca_dev->sd_desc->pkt_scan; in fill_frame()
282 for (i = 0; i < urb->number_of_packets; i++) { in fill_frame()
283 len = urb->iso_frame_desc[i].actual_length; in fill_frame()
286 st = urb->iso_frame_desc[i].status; in fill_frame()
287 if (st) { in fill_frame()
290 gspca_dev->last_packet_type = DISCARD_PACKET; in fill_frame()
293 if (len == 0) { in fill_frame()
294 if (gspca_dev->empty_packet == 0) in fill_frame()
295 gspca_dev->empty_packet = 1; in fill_frame()
301 i, urb->iso_frame_desc[i].offset, len); in fill_frame()
302 data = (u8 *) urb->transfer_buffer in fill_frame()
303 + urb->iso_frame_desc[i].offset; in fill_frame()
308 if (!gspca_dev->streaming) in fill_frame()
312 if (st < 0) in fill_frame()
323 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; in isoc_irq()
326 if (!gspca_dev->streaming) in isoc_irq()
336 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; in bulk_irq()
340 if (!gspca_dev->streaming) in bulk_irq()
342 switch (urb->status) { in bulk_irq()
345 case -ESHUTDOWN: in bulk_irq()
349 if (gspca_dev->frozen) in bulk_irq()
352 gspca_err(gspca_dev, "urb status: %d\n", urb->status); in bulk_irq()
353 urb->status = 0; in bulk_irq()
357 gspca_dbg(gspca_dev, D_PACK, "packet l:%d\n", urb->actual_length); in bulk_irq()
358 gspca_dev->sd_desc->pkt_scan(gspca_dev, in bulk_irq()
359 urb->transfer_buffer, in bulk_irq()
360 urb->actual_length); in bulk_irq()
363 if (!gspca_dev->streaming) in bulk_irq()
366 if (gspca_dev->cam.bulk_nurbs != 0) { in bulk_irq()
368 if (st < 0) in bulk_irq()
379 * - one FIRST_PACKET
380 * - 0 or many INTER_PACKETs
381 * - one LAST_PACKET
394 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_frame_add()
395 buf = list_first_entry_or_null(&gspca_dev->buf_list, in gspca_frame_add()
397 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_frame_add()
399 if (packet_type == FIRST_PACKET) { in gspca_frame_add()
400 /* if there is no queued buffer, discard the whole frame */ in gspca_frame_add()
401 if (!buf) { in gspca_frame_add()
402 gspca_dev->last_packet_type = DISCARD_PACKET; in gspca_frame_add()
403 gspca_dev->sequence++; in gspca_frame_add()
406 gspca_dev->image = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in gspca_frame_add()
407 gspca_dev->image_len = 0; in gspca_frame_add()
409 switch (gspca_dev->last_packet_type) { in gspca_frame_add()
411 if (packet_type == LAST_PACKET) { in gspca_frame_add()
412 gspca_dev->last_packet_type = packet_type; in gspca_frame_add()
413 gspca_dev->image = NULL; in gspca_frame_add()
414 gspca_dev->image_len = 0; in gspca_frame_add()
423 if (len > 0) { in gspca_frame_add()
424 if (gspca_dev->image_len + len > PAGE_ALIGN(gspca_dev->pixfmt.sizeimage)) { in gspca_frame_add()
426 gspca_dev->image_len + len, in gspca_frame_add()
427 PAGE_ALIGN(gspca_dev->pixfmt.sizeimage)); in gspca_frame_add()
431 if (gspca_dev->image == NULL) { in gspca_frame_add()
436 memcpy(gspca_dev->image + gspca_dev->image_len, in gspca_frame_add()
438 gspca_dev->image_len += len; in gspca_frame_add()
441 gspca_dev->last_packet_type = packet_type; in gspca_frame_add()
443 /* if last packet, invalidate packet concatenation until in gspca_frame_add()
446 if (packet_type == LAST_PACKET) { in gspca_frame_add()
447 if (gspca_dev->image_len > gspca_dev->pixfmt.sizeimage) in gspca_frame_add()
448 gspca_dev->image_len = gspca_dev->pixfmt.sizeimage; in gspca_frame_add()
449 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_frame_add()
450 list_del(&buf->list); in gspca_frame_add()
451 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_frame_add()
452 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in gspca_frame_add()
453 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, in gspca_frame_add()
454 gspca_dev->image_len); in gspca_frame_add()
455 buf->vb.sequence = gspca_dev->sequence++; in gspca_frame_add()
456 buf->vb.field = V4L2_FIELD_NONE; in gspca_frame_add()
458 gspca_dev->image_len); in gspca_frame_add()
459 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in gspca_frame_add()
460 gspca_dev->image = NULL; in gspca_frame_add()
461 gspca_dev->image_len = 0; in gspca_frame_add()
475 * be anyone trying to access gspca_dev->urb[i] in destroy_urbs()
478 usb_kill_urb(gspca_dev->urb[i]); in destroy_urbs()
482 urb = gspca_dev->urb[i]; in destroy_urbs()
483 if (!urb) in destroy_urbs()
485 gspca_dev->urb[i] = NULL; in destroy_urbs()
486 usb_free_coherent(gspca_dev->dev, in destroy_urbs()
487 urb->transfer_buffer_length, in destroy_urbs()
488 urb->transfer_buffer, in destroy_urbs()
489 urb->transfer_dma); in destroy_urbs()
498 if (gspca_dev->alt == 0) in gspca_set_alt0()
500 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0); in gspca_set_alt0()
501 if (ret < 0) in gspca_set_alt0()
509 * If xfer_ep is invalid, return the first valid ep found, otherwise
518 for (i = 0; i < alt->desc.bNumEndpoints; i++) { in alt_xfer()
519 ep = &alt->endpoint[i]; in alt_xfer()
520 attr = ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; in alt_xfer()
521 if (attr == xfer in alt_xfer()
522 && ep->desc.wMaxPacketSize != 0 in alt_xfer()
523 && usb_endpoint_dir_in(&ep->desc) in alt_xfer()
524 && (xfer_ep < 0 || ep->desc.bEndpointAddress == xfer_ep)) in alt_xfer()
536 bandwidth = gspca_dev->pixfmt.sizeimage; in which_bandwidth()
538 /* if the image is compressed, estimate its mean size */ in which_bandwidth()
539 if (!gspca_dev->cam.needs_full_bandwidth && in which_bandwidth()
540 bandwidth < gspca_dev->pixfmt.width * in which_bandwidth()
541 gspca_dev->pixfmt.height) in which_bandwidth()
545 if (gspca_dev->sd_desc->get_streamparm) { in which_bandwidth()
548 gspca_dev->sd_desc->get_streamparm(gspca_dev, &parm); in which_bandwidth()
555 if (gspca_dev->pixfmt.width >= 640 in which_bandwidth()
556 && gspca_dev->dev->speed == USB_SPEED_FULL) in which_bandwidth()
585 nbalt = intf->num_altsetting; in build_isoc_ep_tb()
586 if (nbalt > MAX_ALT) in build_isoc_ep_tb()
593 ep_tb->bandwidth = 2000 * 2000 * 120; in build_isoc_ep_tb()
596 ep = alt_xfer(&intf->altsetting[j], in build_isoc_ep_tb()
598 gspca_dev->xfer_ep); in build_isoc_ep_tb()
599 if (ep == NULL) in build_isoc_ep_tb()
601 if (ep->desc.bInterval == 0) { in build_isoc_ep_tb()
605 psize = le16_to_cpu(ep->desc.wMaxPacketSize); in build_isoc_ep_tb()
608 if (gspca_dev->dev->speed == USB_SPEED_HIGH in build_isoc_ep_tb()
609 || gspca_dev->dev->speed >= USB_SPEED_SUPER) in build_isoc_ep_tb()
611 bandwidth /= 1 << (ep->desc.bInterval - 1); in build_isoc_ep_tb()
612 if (bandwidth <= last_bw) in build_isoc_ep_tb()
614 if (bandwidth < ep_tb->bandwidth) { in build_isoc_ep_tb()
615 ep_tb->bandwidth = bandwidth; in build_isoc_ep_tb()
616 ep_tb->alt = j; in build_isoc_ep_tb()
620 if (!found) in build_isoc_ep_tb()
623 ep_tb->alt, ep_tb->bandwidth); in build_isoc_ep_tb()
624 last_bw = ep_tb->bandwidth; in build_isoc_ep_tb()
630 * If the camera: in build_isoc_ep_tb()
637 if (gspca_dev->audio && in build_isoc_ep_tb()
638 gspca_dev->dev->speed == USB_SPEED_FULL && in build_isoc_ep_tb()
642 i--; in build_isoc_ep_tb()
643 ep_tb--; in build_isoc_ep_tb()
648 ep_tb--; in build_isoc_ep_tb()
650 ep_tb--; in build_isoc_ep_tb()
651 if (ep_tb->bandwidth < bandwidth) in build_isoc_ep_tb()
653 i--; in build_isoc_ep_tb()
668 psize = le16_to_cpu(ep->desc.wMaxPacketSize); in create_urbs()
670 if (!gspca_dev->cam.bulk) { /* isoc */ in create_urbs()
672 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ in create_urbs()
673 if (gspca_dev->pkt_size == 0) in create_urbs()
676 psize = gspca_dev->pkt_size; in create_urbs()
677 npkt = gspca_dev->cam.npkt; in create_urbs()
678 if (npkt == 0) in create_urbs()
687 bsize = gspca_dev->cam.bulk_size; in create_urbs()
688 if (bsize == 0) in create_urbs()
691 if (gspca_dev->cam.bulk_nurbs != 0) in create_urbs()
692 nurbs = gspca_dev->cam.bulk_nurbs; in create_urbs()
699 if (!urb) in create_urbs()
700 return -ENOMEM; in create_urbs()
701 gspca_dev->urb[n] = urb; in create_urbs()
702 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev, in create_urbs()
705 &urb->transfer_dma); in create_urbs()
707 if (urb->transfer_buffer == NULL) { in create_urbs()
709 return -ENOMEM; in create_urbs()
711 urb->dev = gspca_dev->dev; in create_urbs()
712 urb->context = gspca_dev; in create_urbs()
713 urb->transfer_buffer_length = bsize; in create_urbs()
714 if (npkt != 0) { /* ISOC */ in create_urbs()
715 urb->pipe = usb_rcvisocpipe(gspca_dev->dev, in create_urbs()
716 ep->desc.bEndpointAddress); in create_urbs()
717 urb->transfer_flags = URB_ISO_ASAP in create_urbs()
719 urb->interval = 1 << (ep->desc.bInterval - 1); in create_urbs()
720 urb->complete = isoc_irq; in create_urbs()
721 urb->number_of_packets = npkt; in create_urbs()
723 urb->iso_frame_desc[i].length = psize; in create_urbs()
724 urb->iso_frame_desc[i].offset = psize * i; in create_urbs()
727 urb->pipe = usb_rcvbulkpipe(gspca_dev->dev, in create_urbs()
728 ep->desc.bEndpointAddress); in create_urbs()
729 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; in create_urbs()
730 urb->complete = bulk_irq; in create_urbs()
739 gspca_dev->streaming = false; in gspca_stream_off()
740 gspca_dev->usb_err = 0; in gspca_stream_off()
741 if (gspca_dev->sd_desc->stopN) in gspca_stream_off()
742 gspca_dev->sd_desc->stopN(gspca_dev); in gspca_stream_off()
746 if (gspca_dev->present) in gspca_stream_off()
748 if (gspca_dev->sd_desc->stop0) in gspca_stream_off()
749 gspca_dev->sd_desc->stop0(gspca_dev); in gspca_stream_off()
765 gspca_dev->image = NULL; in gspca_init_transfer()
766 gspca_dev->image_len = 0; in gspca_init_transfer()
767 gspca_dev->last_packet_type = DISCARD_PACKET; in gspca_init_transfer()
769 gspca_dev->usb_err = 0; in gspca_init_transfer()
772 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); in gspca_init_transfer()
773 gspca_dev->alt = gspca_dev->cam.bulk ? intf->num_altsetting : 0; in gspca_init_transfer()
774 if (gspca_dev->sd_desc->isoc_init) { in gspca_init_transfer()
775 ret = gspca_dev->sd_desc->isoc_init(gspca_dev); in gspca_init_transfer()
776 if (ret < 0) in gspca_init_transfer()
779 xfer = gspca_dev->cam.bulk ? USB_ENDPOINT_XFER_BULK in gspca_init_transfer()
782 /* if bulk or the subdriver forced an altsetting, get the endpoint */ in gspca_init_transfer()
783 if (gspca_dev->alt != 0) { in gspca_init_transfer()
784 gspca_dev->alt--; /* (previous version compatibility) */ in gspca_init_transfer()
785 ep = alt_xfer(&intf->altsetting[gspca_dev->alt], xfer, in gspca_init_transfer()
786 gspca_dev->xfer_ep); in gspca_init_transfer()
787 if (ep == NULL) { in gspca_init_transfer()
788 pr_err("bad altsetting %d\n", gspca_dev->alt); in gspca_init_transfer()
789 return -EIO; in gspca_init_transfer()
791 ep_tb[0].alt = gspca_dev->alt; in gspca_init_transfer()
797 if (alt_idx <= 0) { in gspca_init_transfer()
799 return -EIO; in gspca_init_transfer()
807 gspca_dev->alt = ep_tb[--alt_idx].alt; in gspca_init_transfer()
808 alt = -1; in gspca_init_transfer()
810 if (alt != gspca_dev->alt) { in gspca_init_transfer()
811 alt = gspca_dev->alt; in gspca_init_transfer()
812 if (intf->num_altsetting > 1) { in gspca_init_transfer()
813 ret = usb_set_interface(gspca_dev->dev, in gspca_init_transfer()
814 gspca_dev->iface, in gspca_init_transfer()
816 if (ret < 0) { in gspca_init_transfer()
817 if (ret == -ENOSPC) in gspca_init_transfer()
824 if (!gspca_dev->cam.no_urb_create) { in gspca_init_transfer()
828 alt_xfer(&intf->altsetting[alt], xfer, in gspca_init_transfer()
829 gspca_dev->xfer_ep)); in gspca_init_transfer()
830 if (ret < 0) { in gspca_init_transfer()
837 if (gspca_dev->cam.bulk) in gspca_init_transfer()
838 usb_clear_halt(gspca_dev->dev, in gspca_init_transfer()
839 gspca_dev->urb[0]->pipe); in gspca_init_transfer()
841 /* start the cam */ in gspca_init_transfer()
842 ret = gspca_dev->sd_desc->start(gspca_dev); in gspca_init_transfer()
843 if (ret < 0) { in gspca_init_transfer()
847 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler); in gspca_init_transfer()
848 gspca_dev->streaming = true; in gspca_init_transfer()
851 if (gspca_dev->cam.bulk && gspca_dev->cam.bulk_nurbs == 0) in gspca_init_transfer()
856 urb = gspca_dev->urb[n]; in gspca_init_transfer()
857 if (urb == NULL) in gspca_init_transfer()
860 if (ret < 0) in gspca_init_transfer()
863 if (ret >= 0) in gspca_init_transfer()
869 if (ret != -ENOSPC) { in gspca_init_transfer()
871 gspca_dev->alt, ret); in gspca_init_transfer()
878 gspca_err(gspca_dev, "alt %d - bandwidth not wide enough, trying again\n", in gspca_init_transfer()
881 if (gspca_dev->sd_desc->isoc_nego) { in gspca_init_transfer()
882 ret = gspca_dev->sd_desc->isoc_nego(gspca_dev); in gspca_init_transfer()
883 if (ret < 0) in gspca_init_transfer()
886 if (alt_idx <= 0) { in gspca_init_transfer()
888 ret = -EIO; in gspca_init_transfer()
891 gspca_dev->alt = ep_tb[--alt_idx].alt; in gspca_init_transfer()
903 i = gspca_dev->cam.nmodes - 1; /* take the highest mode */ in gspca_set_default_mode()
904 gspca_dev->curr_mode = i; in gspca_set_default_mode()
905 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i]; in gspca_set_default_mode()
907 /* does nothing if ctrl_handler == NULL */ in gspca_set_default_mode()
908 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler); in gspca_set_default_mode()
916 for (i = 0; i < gspca_dev->cam.nmodes; i++) { in wxh_to_mode()
917 if (width == gspca_dev->cam.cam_mode[i].width in wxh_to_mode()
918 && height == gspca_dev->cam.cam_mode[i].height in wxh_to_mode()
919 && pixelformat == gspca_dev->cam.cam_mode[i].pixelformat) in wxh_to_mode()
922 return -EINVAL; in wxh_to_mode()
930 for (i = gspca_dev->cam.nmodes; --i >= 0; ) { in wxh_to_nearest_mode()
931 if (width >= gspca_dev->cam.cam_mode[i].width in wxh_to_nearest_mode()
932 && height >= gspca_dev->cam.cam_mode[i].height in wxh_to_nearest_mode()
933 && pixelformat == gspca_dev->cam.cam_mode[i].pixelformat) in wxh_to_nearest_mode()
936 for (i = gspca_dev->cam.nmodes; --i > 0; ) { in wxh_to_nearest_mode()
937 if (width >= gspca_dev->cam.cam_mode[i].width in wxh_to_nearest_mode()
938 && height >= gspca_dev->cam.cam_mode[i].height) in wxh_to_nearest_mode()
954 while ((modeU < gspca_dev->cam.nmodes) || modeD >= 0) { in gspca_get_mode()
955 if (--modeD >= 0) { in gspca_get_mode()
956 if (gspca_dev->cam.cam_mode[modeD].pixelformat in gspca_get_mode()
960 if (++modeU < gspca_dev->cam.nmodes) { in gspca_get_mode()
961 if (gspca_dev->cam.cam_mode[modeU].pixelformat in gspca_get_mode()
966 return -EINVAL; in gspca_get_mode()
975 gspca_dev->usb_err = 0; in vidioc_g_chip_info()
976 if (gspca_dev->sd_desc->get_chip_info) in vidioc_g_chip_info()
977 return gspca_dev->sd_desc->get_chip_info(gspca_dev, chip); in vidioc_g_chip_info()
978 return chip->match.addr ? -EINVAL : 0; in vidioc_g_chip_info()
986 gspca_dev->usb_err = 0; in vidioc_g_register()
987 return gspca_dev->sd_desc->get_register(gspca_dev, reg); in vidioc_g_register()
995 gspca_dev->usb_err = 0; in vidioc_s_register()
996 return gspca_dev->sd_desc->set_register(gspca_dev, reg); in vidioc_s_register()
1009 for (i = gspca_dev->cam.nmodes; --i >= 0; ) { in vidioc_enum_fmt_vid_cap()
1010 fmt_tb[index] = gspca_dev->cam.cam_mode[i].pixelformat; in vidioc_enum_fmt_vid_cap()
1013 if (fmt_tb[j] == fmt_tb[index]) in vidioc_enum_fmt_vid_cap()
1017 if (j == index) { in vidioc_enum_fmt_vid_cap()
1018 if (fmtdesc->index == index) in vidioc_enum_fmt_vid_cap()
1021 if (index >= ARRAY_SIZE(fmt_tb)) in vidioc_enum_fmt_vid_cap()
1022 return -EINVAL; in vidioc_enum_fmt_vid_cap()
1025 if (i < 0) in vidioc_enum_fmt_vid_cap()
1026 return -EINVAL; /* no more format */ in vidioc_enum_fmt_vid_cap()
1028 fmtdesc->pixelformat = fmt_tb[index]; in vidioc_enum_fmt_vid_cap()
1036 u32 priv = fmt->fmt.pix.priv; in vidioc_g_fmt_vid_cap()
1038 fmt->fmt.pix = gspca_dev->pixfmt; in vidioc_g_fmt_vid_cap()
1040 fmt->fmt.pix.priv = priv; in vidioc_g_fmt_vid_cap()
1049 w = fmt->fmt.pix.width; in try_fmt_vid_cap()
1050 h = fmt->fmt.pix.height; in try_fmt_vid_cap()
1053 fmt->fmt.pix.pixelformat, w, h); in try_fmt_vid_cap()
1056 mode = wxh_to_nearest_mode(gspca_dev, w, h, fmt->fmt.pix.pixelformat); in try_fmt_vid_cap()
1058 /* OK if right palette */ in try_fmt_vid_cap()
1059 if (gspca_dev->cam.cam_mode[mode].pixelformat in try_fmt_vid_cap()
1060 != fmt->fmt.pix.pixelformat) { in try_fmt_vid_cap()
1064 fmt->fmt.pix.pixelformat); in try_fmt_vid_cap()
1065 if (mode2 >= 0) in try_fmt_vid_cap()
1068 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode]; in try_fmt_vid_cap()
1069 if (gspca_dev->sd_desc->try_fmt) { in try_fmt_vid_cap()
1071 fmt->fmt.pix.width = w; in try_fmt_vid_cap()
1072 fmt->fmt.pix.height = h; in try_fmt_vid_cap()
1073 gspca_dev->sd_desc->try_fmt(gspca_dev, fmt); in try_fmt_vid_cap()
1082 u32 priv = fmt->fmt.pix.priv; in vidioc_try_fmt_vid_cap()
1084 if (try_fmt_vid_cap(gspca_dev, fmt) < 0) in vidioc_try_fmt_vid_cap()
1085 return -EINVAL; in vidioc_try_fmt_vid_cap()
1087 fmt->fmt.pix.priv = priv; in vidioc_try_fmt_vid_cap()
1095 u32 priv = fmt->fmt.pix.priv; in vidioc_s_fmt_vid_cap()
1098 if (vb2_is_busy(&gspca_dev->queue)) in vidioc_s_fmt_vid_cap()
1099 return -EBUSY; in vidioc_s_fmt_vid_cap()
1102 if (mode < 0) in vidioc_s_fmt_vid_cap()
1103 return -EINVAL; in vidioc_s_fmt_vid_cap()
1105 gspca_dev->curr_mode = mode; in vidioc_s_fmt_vid_cap()
1106 if (gspca_dev->sd_desc->try_fmt) in vidioc_s_fmt_vid_cap()
1108 gspca_dev->pixfmt = fmt->fmt.pix; in vidioc_s_fmt_vid_cap()
1110 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[mode]; in vidioc_s_fmt_vid_cap()
1112 fmt->fmt.pix.priv = priv; in vidioc_s_fmt_vid_cap()
1123 if (gspca_dev->sd_desc->enum_framesizes) in vidioc_enum_framesizes()
1124 return gspca_dev->sd_desc->enum_framesizes(gspca_dev, fsize); in vidioc_enum_framesizes()
1126 for (i = 0; i < gspca_dev->cam.nmodes; i++) { in vidioc_enum_framesizes()
1127 if (fsize->pixel_format != in vidioc_enum_framesizes()
1128 gspca_dev->cam.cam_mode[i].pixelformat) in vidioc_enum_framesizes()
1131 if (fsize->index == index) { in vidioc_enum_framesizes()
1132 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; in vidioc_enum_framesizes()
1133 fsize->discrete.width = in vidioc_enum_framesizes()
1134 gspca_dev->cam.cam_mode[i].width; in vidioc_enum_framesizes()
1135 fsize->discrete.height = in vidioc_enum_framesizes()
1136 gspca_dev->cam.cam_mode[i].height; in vidioc_enum_framesizes()
1142 return -EINVAL; in vidioc_enum_framesizes()
1152 mode = wxh_to_mode(gspca_dev, fival->width, fival->height, in vidioc_enum_frameintervals()
1153 fival->pixel_format); in vidioc_enum_frameintervals()
1154 if (mode < 0) in vidioc_enum_frameintervals()
1155 return -EINVAL; in vidioc_enum_frameintervals()
1157 if (gspca_dev->cam.mode_framerates == NULL || in vidioc_enum_frameintervals()
1158 gspca_dev->cam.mode_framerates[mode].nrates == 0) in vidioc_enum_frameintervals()
1159 return -EINVAL; in vidioc_enum_frameintervals()
1161 if (fival->pixel_format != in vidioc_enum_frameintervals()
1162 gspca_dev->cam.cam_mode[mode].pixelformat) in vidioc_enum_frameintervals()
1163 return -EINVAL; in vidioc_enum_frameintervals()
1165 for (i = 0; i < gspca_dev->cam.mode_framerates[mode].nrates; i++) { in vidioc_enum_frameintervals()
1166 if (fival->index == i) { in vidioc_enum_frameintervals()
1167 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; in vidioc_enum_frameintervals()
1168 fival->discrete.numerator = 1; in vidioc_enum_frameintervals()
1169 fival->discrete.denominator = in vidioc_enum_frameintervals()
1170 gspca_dev->cam.mode_framerates[mode].rates[i]; in vidioc_enum_frameintervals()
1175 return -EINVAL; in vidioc_enum_frameintervals()
1183 v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler); in gspca_release()
1184 v4l2_device_unregister(&gspca_dev->v4l2_dev); in gspca_release()
1185 kfree(gspca_dev->usb_buf); in gspca_release()
1194 strscpy((char *)cap->driver, gspca_dev->sd_desc->name, in vidioc_querycap()
1195 sizeof(cap->driver)); in vidioc_querycap()
1196 if (gspca_dev->dev->product != NULL) { in vidioc_querycap()
1197 strscpy((char *)cap->card, gspca_dev->dev->product, in vidioc_querycap()
1198 sizeof(cap->card)); in vidioc_querycap()
1200 snprintf((char *) cap->card, sizeof cap->card, in vidioc_querycap()
1202 le16_to_cpu(gspca_dev->dev->descriptor.idVendor), in vidioc_querycap()
1203 le16_to_cpu(gspca_dev->dev->descriptor.idProduct)); in vidioc_querycap()
1205 usb_make_path(gspca_dev->dev, (char *) cap->bus_info, in vidioc_querycap()
1206 sizeof(cap->bus_info)); in vidioc_querycap()
1215 if (input->index != 0) in vidioc_enum_input()
1216 return -EINVAL; in vidioc_enum_input()
1217 input->type = V4L2_INPUT_TYPE_CAMERA; in vidioc_enum_input()
1218 input->status = gspca_dev->cam.input_flags; in vidioc_enum_input()
1219 strscpy(input->name, gspca_dev->sd_desc->name, in vidioc_enum_input()
1220 sizeof input->name); in vidioc_enum_input()
1232 if (i > 0) in vidioc_s_input()
1233 return -EINVAL; in vidioc_s_input()
1242 gspca_dev->usb_err = 0; in vidioc_g_jpegcomp()
1243 return gspca_dev->sd_desc->get_jcomp(gspca_dev, jpegcomp); in vidioc_g_jpegcomp()
1251 gspca_dev->usb_err = 0; in vidioc_s_jpegcomp()
1252 return gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp); in vidioc_s_jpegcomp()
1260 parm->parm.capture.readbuffers = gspca_dev->queue.min_queued_buffers; in vidioc_g_parm()
1262 if (!gspca_dev->sd_desc->get_streamparm) in vidioc_g_parm()
1265 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_g_parm()
1266 gspca_dev->usb_err = 0; in vidioc_g_parm()
1267 gspca_dev->sd_desc->get_streamparm(gspca_dev, parm); in vidioc_g_parm()
1268 return gspca_dev->usb_err; in vidioc_g_parm()
1276 parm->parm.capture.readbuffers = gspca_dev->queue.min_queued_buffers; in vidioc_s_parm()
1278 if (!gspca_dev->sd_desc->set_streamparm) { in vidioc_s_parm()
1279 parm->parm.capture.capability = 0; in vidioc_s_parm()
1283 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_s_parm()
1284 gspca_dev->usb_err = 0; in vidioc_s_parm()
1285 gspca_dev->sd_desc->set_streamparm(gspca_dev, parm); in vidioc_s_parm()
1286 return gspca_dev->usb_err; in vidioc_s_parm()
1294 unsigned int size = PAGE_ALIGN(gspca_dev->pixfmt.sizeimage); in gspca_queue_setup()
1296 if (*nplanes) in gspca_queue_setup()
1297 return sizes[0] < size ? -EINVAL : 0; in gspca_queue_setup()
1305 struct gspca_dev *gspca_dev = vb2_get_drv_priv(vb->vb2_queue); in gspca_buffer_prepare()
1306 unsigned long size = PAGE_ALIGN(gspca_dev->pixfmt.sizeimage); in gspca_buffer_prepare()
1308 if (vb2_plane_size(vb, 0) < size) { in gspca_buffer_prepare()
1311 return -EINVAL; in gspca_buffer_prepare()
1318 struct gspca_dev *gspca_dev = vb2_get_drv_priv(vb->vb2_queue); in gspca_buffer_finish()
1320 if (!gspca_dev->sd_desc->dq_callback) in gspca_buffer_finish()
1323 gspca_dev->usb_err = 0; in gspca_buffer_finish()
1324 if (gspca_dev->present) in gspca_buffer_finish()
1325 gspca_dev->sd_desc->dq_callback(gspca_dev); in gspca_buffer_finish()
1330 struct gspca_dev *gspca_dev = vb2_get_drv_priv(vb->vb2_queue); in gspca_buffer_queue()
1334 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_buffer_queue()
1335 list_add_tail(&buf->list, &gspca_dev->buf_list); in gspca_buffer_queue()
1336 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_buffer_queue()
1345 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_return_all_buffers()
1346 list_for_each_entry_safe(buf, node, &gspca_dev->buf_list, list) { in gspca_return_all_buffers()
1347 vb2_buffer_done(&buf->vb.vb2_buf, state); in gspca_return_all_buffers()
1348 list_del(&buf->list); in gspca_return_all_buffers()
1350 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_return_all_buffers()
1358 gspca_dev->sequence = 0; in gspca_start_streaming()
1361 if (ret) in gspca_start_streaming()
1441 * This function must be called by the sub-driver when it is
1455 pr_info("%s-" GSPCA_VERSION " probing %04x:%04x\n", in gspca_dev_probe2()
1456 sd_desc->name, id->idVendor, id->idProduct); in gspca_dev_probe2()
1459 if (dev_size < sizeof *gspca_dev) in gspca_dev_probe2()
1462 if (!gspca_dev) { in gspca_dev_probe2()
1464 return -ENOMEM; in gspca_dev_probe2()
1466 gspca_dev->usb_buf = kzalloc(USB_BUF_SZ, GFP_KERNEL); in gspca_dev_probe2()
1467 if (!gspca_dev->usb_buf) { in gspca_dev_probe2()
1469 ret = -ENOMEM; in gspca_dev_probe2()
1472 gspca_dev->dev = dev; in gspca_dev_probe2()
1473 gspca_dev->iface = intf->cur_altsetting->desc.bInterfaceNumber; in gspca_dev_probe2()
1474 gspca_dev->xfer_ep = -1; in gspca_dev_probe2()
1476 /* check if any audio device */ in gspca_dev_probe2()
1477 if (dev->actconfig->desc.bNumInterfaces != 1) { in gspca_dev_probe2()
1481 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { in gspca_dev_probe2()
1482 intf2 = dev->actconfig->interface[i]; in gspca_dev_probe2()
1483 if (intf2 != NULL in gspca_dev_probe2()
1484 && intf2->altsetting != NULL in gspca_dev_probe2()
1485 && intf2->altsetting->desc.bInterfaceClass == in gspca_dev_probe2()
1487 gspca_dev->audio = 1; in gspca_dev_probe2()
1493 gspca_dev->v4l2_dev.release = gspca_release; in gspca_dev_probe2()
1494 ret = v4l2_device_register(&intf->dev, &gspca_dev->v4l2_dev); in gspca_dev_probe2()
1495 if (ret) in gspca_dev_probe2()
1497 gspca_dev->present = true; in gspca_dev_probe2()
1498 gspca_dev->sd_desc = sd_desc; in gspca_dev_probe2()
1499 gspca_dev->empty_packet = -1; /* don't check the empty packets */ in gspca_dev_probe2()
1500 gspca_dev->vdev = gspca_template; in gspca_dev_probe2()
1501 gspca_dev->vdev.v4l2_dev = &gspca_dev->v4l2_dev; in gspca_dev_probe2()
1502 gspca_dev->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | in gspca_dev_probe2()
1504 video_set_drvdata(&gspca_dev->vdev, gspca_dev); in gspca_dev_probe2()
1505 gspca_dev->module = module; in gspca_dev_probe2()
1507 mutex_init(&gspca_dev->usb_lock); in gspca_dev_probe2()
1508 gspca_dev->vdev.lock = &gspca_dev->usb_lock; in gspca_dev_probe2()
1509 init_waitqueue_head(&gspca_dev->wq); in gspca_dev_probe2()
1512 q = &gspca_dev->queue; in gspca_dev_probe2()
1513 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in gspca_dev_probe2()
1514 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; in gspca_dev_probe2()
1515 q->drv_priv = gspca_dev; in gspca_dev_probe2()
1516 q->buf_struct_size = sizeof(struct gspca_buffer); in gspca_dev_probe2()
1517 q->ops = &gspca_qops; in gspca_dev_probe2()
1518 q->mem_ops = &vb2_vmalloc_memops; in gspca_dev_probe2()
1519 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in gspca_dev_probe2()
1520 q->min_queued_buffers = 2; in gspca_dev_probe2()
1521 q->lock = &gspca_dev->usb_lock; in gspca_dev_probe2()
1523 if (ret) in gspca_dev_probe2()
1525 gspca_dev->vdev.queue = q; in gspca_dev_probe2()
1527 INIT_LIST_HEAD(&gspca_dev->buf_list); in gspca_dev_probe2()
1528 spin_lock_init(&gspca_dev->qlock); in gspca_dev_probe2()
1531 ret = sd_desc->config(gspca_dev, id); in gspca_dev_probe2()
1532 if (ret < 0) in gspca_dev_probe2()
1534 ret = sd_desc->init(gspca_dev); in gspca_dev_probe2()
1535 if (ret < 0) in gspca_dev_probe2()
1537 if (sd_desc->init_controls) in gspca_dev_probe2()
1538 ret = sd_desc->init_controls(gspca_dev); in gspca_dev_probe2()
1539 if (ret < 0) in gspca_dev_probe2()
1544 if (ret) in gspca_dev_probe2()
1548 if (!gspca_dev->sd_desc->get_register) in gspca_dev_probe2()
1549 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_G_REGISTER); in gspca_dev_probe2()
1550 if (!gspca_dev->sd_desc->set_register) in gspca_dev_probe2()
1551 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_S_REGISTER); in gspca_dev_probe2()
1553 if (!gspca_dev->sd_desc->get_jcomp) in gspca_dev_probe2()
1554 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_G_JPEGCOMP); in gspca_dev_probe2()
1555 if (!gspca_dev->sd_desc->set_jcomp) in gspca_dev_probe2()
1556 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_S_JPEGCOMP); in gspca_dev_probe2()
1559 ret = video_register_device(&gspca_dev->vdev, in gspca_dev_probe2()
1561 -1); in gspca_dev_probe2()
1562 if (ret < 0) { in gspca_dev_probe2()
1569 video_device_node_name(&gspca_dev->vdev)); in gspca_dev_probe2()
1575 #if IS_ENABLED(CONFIG_INPUT) in gspca_dev_probe2()
1576 if (gspca_dev->input_dev) in gspca_dev_probe2()
1577 input_unregister_device(gspca_dev->input_dev); in gspca_dev_probe2()
1579 v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler); in gspca_dev_probe2()
1580 v4l2_device_unregister(&gspca_dev->v4l2_dev); in gspca_dev_probe2()
1581 if (sd_desc->probe_error) in gspca_dev_probe2()
1582 sd_desc->probe_error(gspca_dev); in gspca_dev_probe2()
1583 kfree(gspca_dev->usb_buf); in gspca_dev_probe2()
1598 /* we don't handle multi-config cameras */ in gspca_dev_probe()
1599 if (dev->descriptor.bNumConfigurations != 1) { in gspca_dev_probe()
1601 id->idVendor, id->idProduct); in gspca_dev_probe()
1602 return -ENODEV; in gspca_dev_probe()
1606 if (dev->actconfig->desc.bNumInterfaces != 1 in gspca_dev_probe()
1607 && intf->cur_altsetting->desc.bInterfaceNumber != 0) in gspca_dev_probe()
1608 return -ENODEV; in gspca_dev_probe()
1617 * This function must be called by the sub-driver
1623 #if IS_ENABLED(CONFIG_INPUT) in gspca_disconnect()
1628 video_device_node_name(&gspca_dev->vdev)); in gspca_disconnect()
1630 mutex_lock(&gspca_dev->usb_lock); in gspca_disconnect()
1631 gspca_dev->present = false; in gspca_disconnect()
1635 vb2_queue_error(&gspca_dev->queue); in gspca_disconnect()
1637 #if IS_ENABLED(CONFIG_INPUT) in gspca_disconnect()
1638 input_dev = gspca_dev->input_dev; in gspca_disconnect()
1639 if (input_dev) { in gspca_disconnect()
1640 gspca_dev->input_dev = NULL; in gspca_disconnect()
1645 v4l2_device_disconnect(&gspca_dev->v4l2_dev); in gspca_disconnect()
1646 video_unregister_device(&gspca_dev->vdev); in gspca_disconnect()
1648 mutex_unlock(&gspca_dev->usb_lock); in gspca_disconnect()
1651 v4l2_device_put(&gspca_dev->v4l2_dev); in gspca_disconnect()
1662 if (!vb2_start_streaming_called(&gspca_dev->queue)) in gspca_suspend()
1665 mutex_lock(&gspca_dev->usb_lock); in gspca_suspend()
1666 gspca_dev->frozen = 1; /* avoid urb error messages */ in gspca_suspend()
1667 gspca_dev->usb_err = 0; in gspca_suspend()
1668 if (gspca_dev->sd_desc->stopN) in gspca_suspend()
1669 gspca_dev->sd_desc->stopN(gspca_dev); in gspca_suspend()
1672 if (gspca_dev->sd_desc->stop0) in gspca_suspend()
1673 gspca_dev->sd_desc->stop0(gspca_dev); in gspca_suspend()
1674 mutex_unlock(&gspca_dev->usb_lock); in gspca_suspend()
1685 mutex_lock(&gspca_dev->usb_lock); in gspca_resume()
1686 gspca_dev->frozen = 0; in gspca_resume()
1687 gspca_dev->usb_err = 0; in gspca_resume()
1688 gspca_dev->sd_desc->init(gspca_dev); in gspca_resume()
1691 * only write to the device registers on s_ctrl when streaming -> in gspca_resume()
1694 streaming = vb2_start_streaming_called(&gspca_dev->queue); in gspca_resume()
1695 if (streaming) in gspca_resume()
1699 mutex_unlock(&gspca_dev->usb_lock); in gspca_resume()
1706 /* -- module insert / remove -- */