Lines Matching +full:- +full:alt

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>
45 MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
72 /* specific memory types - !! should be different from V4L2_MEMORY_xxx */
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()
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()
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()
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()
173 ret = -ENOMEM; in alloc_and_submit_int_urb()
178 GFP_KERNEL, &urb->transfer_dma); 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()
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()
234 urb = gspca_dev->int_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()
290 gspca_dev->last_packet_type = DISCARD_PACKET; 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()
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()
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()
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()
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()
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()
447 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_frame_add()
448 list_del(&buf->list); in gspca_frame_add()
449 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_frame_add()
450 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in gspca_frame_add()
451 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, in gspca_frame_add()
452 gspca_dev->image_len); in gspca_frame_add()
453 buf->vb.sequence = gspca_dev->sequence++; in gspca_frame_add()
454 buf->vb.field = V4L2_FIELD_NONE; in gspca_frame_add()
456 gspca_dev->image_len); in gspca_frame_add()
457 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); in gspca_frame_add()
458 gspca_dev->image = NULL; in gspca_frame_add()
459 gspca_dev->image_len = 0; in gspca_frame_add()
473 * be anyone trying to access gspca_dev->urb[i] in destroy_urbs()
476 usb_kill_urb(gspca_dev->urb[i]); in destroy_urbs()
480 urb = gspca_dev->urb[i]; in destroy_urbs()
483 gspca_dev->urb[i] = NULL; in destroy_urbs()
484 usb_free_coherent(gspca_dev->dev, in destroy_urbs()
485 urb->transfer_buffer_length, in destroy_urbs()
486 urb->transfer_buffer, in destroy_urbs()
487 urb->transfer_dma); in destroy_urbs()
496 if (gspca_dev->alt == 0) in gspca_set_alt0()
498 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0); in gspca_set_alt0()
500 pr_err("set alt 0 err %d\n", ret); in gspca_set_alt0()
510 static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt, in alt_xfer() argument
516 for (i = 0; i < alt->desc.bNumEndpoints; i++) { in alt_xfer()
517 ep = &alt->endpoint[i]; in alt_xfer()
518 attr = ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; in alt_xfer()
520 && ep->desc.wMaxPacketSize != 0 in alt_xfer()
521 && usb_endpoint_dir_in(&ep->desc) in alt_xfer()
522 && (xfer_ep < 0 || ep->desc.bEndpointAddress == xfer_ep)) in alt_xfer()
534 bandwidth = gspca_dev->pixfmt.sizeimage; in which_bandwidth()
537 if (!gspca_dev->cam.needs_full_bandwidth && in which_bandwidth()
538 bandwidth < gspca_dev->pixfmt.width * in which_bandwidth()
539 gspca_dev->pixfmt.height) in which_bandwidth()
543 if (gspca_dev->sd_desc->get_streamparm) { in which_bandwidth()
546 gspca_dev->sd_desc->get_streamparm(gspca_dev, &parm); in which_bandwidth()
553 if (gspca_dev->pixfmt.width >= 640 in which_bandwidth()
554 && gspca_dev->dev->speed == USB_SPEED_FULL) in which_bandwidth()
567 u32 alt; member
583 nbalt = intf->num_altsetting; in build_isoc_ep_tb()
591 ep_tb->bandwidth = 2000 * 2000 * 120; in build_isoc_ep_tb()
594 ep = alt_xfer(&intf->altsetting[j], in build_isoc_ep_tb()
596 gspca_dev->xfer_ep); in build_isoc_ep_tb()
599 if (ep->desc.bInterval == 0) { in build_isoc_ep_tb()
600 pr_err("alt %d iso endp with 0 interval\n", j); in build_isoc_ep_tb()
603 psize = le16_to_cpu(ep->desc.wMaxPacketSize); in build_isoc_ep_tb()
606 if (gspca_dev->dev->speed == USB_SPEED_HIGH in build_isoc_ep_tb()
607 || gspca_dev->dev->speed >= USB_SPEED_SUPER) in build_isoc_ep_tb()
609 bandwidth /= 1 << (ep->desc.bInterval - 1); in build_isoc_ep_tb()
612 if (bandwidth < ep_tb->bandwidth) { in build_isoc_ep_tb()
613 ep_tb->bandwidth = bandwidth; in build_isoc_ep_tb()
614 ep_tb->alt = j; in build_isoc_ep_tb()
620 gspca_dbg(gspca_dev, D_STREAM, "alt %d bandwidth %d\n", in build_isoc_ep_tb()
621 ep_tb->alt, ep_tb->bandwidth); in build_isoc_ep_tb()
622 last_bw = ep_tb->bandwidth; in build_isoc_ep_tb()
632 * and has more than 1 alt setting in build_isoc_ep_tb()
633 * then skip the highest alt setting to spare bandwidth for the mic in build_isoc_ep_tb()
635 if (gspca_dev->audio && in build_isoc_ep_tb()
636 gspca_dev->dev->speed == USB_SPEED_FULL && in build_isoc_ep_tb()
639 gspca_dbg(gspca_dev, D_STREAM, "dev has usb audio, skipping highest alt\n"); in build_isoc_ep_tb()
640 i--; in build_isoc_ep_tb()
641 ep_tb--; in build_isoc_ep_tb()
646 ep_tb--; in build_isoc_ep_tb()
648 ep_tb--; in build_isoc_ep_tb()
649 if (ep_tb->bandwidth < bandwidth) in build_isoc_ep_tb()
651 i--; in build_isoc_ep_tb()
666 psize = le16_to_cpu(ep->desc.wMaxPacketSize); in create_urbs()
668 if (!gspca_dev->cam.bulk) { /* isoc */ in create_urbs()
670 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ in create_urbs()
671 if (gspca_dev->pkt_size == 0) in create_urbs()
674 psize = gspca_dev->pkt_size; in create_urbs()
675 npkt = gspca_dev->cam.npkt; in create_urbs()
685 bsize = gspca_dev->cam.bulk_size; in create_urbs()
689 if (gspca_dev->cam.bulk_nurbs != 0) in create_urbs()
690 nurbs = gspca_dev->cam.bulk_nurbs; in create_urbs()
698 return -ENOMEM; in create_urbs()
699 gspca_dev->urb[n] = urb; in create_urbs()
700 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev, in create_urbs()
703 &urb->transfer_dma); in create_urbs()
705 if (urb->transfer_buffer == NULL) { in create_urbs()
707 return -ENOMEM; in create_urbs()
709 urb->dev = gspca_dev->dev; in create_urbs()
710 urb->context = gspca_dev; in create_urbs()
711 urb->transfer_buffer_length = bsize; in create_urbs()
713 urb->pipe = usb_rcvisocpipe(gspca_dev->dev, in create_urbs()
714 ep->desc.bEndpointAddress); in create_urbs()
715 urb->transfer_flags = URB_ISO_ASAP in create_urbs()
717 urb->interval = 1 << (ep->desc.bInterval - 1); in create_urbs()
718 urb->complete = isoc_irq; in create_urbs()
719 urb->number_of_packets = npkt; in create_urbs()
721 urb->iso_frame_desc[i].length = psize; in create_urbs()
722 urb->iso_frame_desc[i].offset = psize * i; in create_urbs()
725 urb->pipe = usb_rcvbulkpipe(gspca_dev->dev, in create_urbs()
726 ep->desc.bEndpointAddress); in create_urbs()
727 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; in create_urbs()
728 urb->complete = bulk_irq; in create_urbs()
737 gspca_dev->streaming = false; in gspca_stream_off()
738 gspca_dev->usb_err = 0; in gspca_stream_off()
739 if (gspca_dev->sd_desc->stopN) in gspca_stream_off()
740 gspca_dev->sd_desc->stopN(gspca_dev); in gspca_stream_off()
744 if (gspca_dev->present) in gspca_stream_off()
746 if (gspca_dev->sd_desc->stop0) in gspca_stream_off()
747 gspca_dev->sd_desc->stop0(gspca_dev); in gspca_stream_off()
760 int n, ret, xfer, alt, alt_idx; in gspca_init_transfer() local
763 gspca_dev->image = NULL; in gspca_init_transfer()
764 gspca_dev->image_len = 0; in gspca_init_transfer()
765 gspca_dev->last_packet_type = DISCARD_PACKET; in gspca_init_transfer()
767 gspca_dev->usb_err = 0; in gspca_init_transfer()
770 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); in gspca_init_transfer()
771 gspca_dev->alt = gspca_dev->cam.bulk ? intf->num_altsetting : 0; in gspca_init_transfer()
772 if (gspca_dev->sd_desc->isoc_init) { in gspca_init_transfer()
773 ret = gspca_dev->sd_desc->isoc_init(gspca_dev); in gspca_init_transfer()
777 xfer = gspca_dev->cam.bulk ? USB_ENDPOINT_XFER_BULK in gspca_init_transfer()
781 if (gspca_dev->alt != 0) { in gspca_init_transfer()
782 gspca_dev->alt--; /* (previous version compatibility) */ in gspca_init_transfer()
783 ep = alt_xfer(&intf->altsetting[gspca_dev->alt], xfer, in gspca_init_transfer()
784 gspca_dev->xfer_ep); in gspca_init_transfer()
786 pr_err("bad altsetting %d\n", gspca_dev->alt); in gspca_init_transfer()
787 return -EIO; in gspca_init_transfer()
789 ep_tb[0].alt = gspca_dev->alt; in gspca_init_transfer()
797 return -EIO; in gspca_init_transfer()
805 gspca_dev->alt = ep_tb[--alt_idx].alt; in gspca_init_transfer()
806 alt = -1; in gspca_init_transfer()
808 if (alt != gspca_dev->alt) { in gspca_init_transfer()
809 alt = gspca_dev->alt; in gspca_init_transfer()
810 if (intf->num_altsetting > 1) { in gspca_init_transfer()
811 ret = usb_set_interface(gspca_dev->dev, in gspca_init_transfer()
812 gspca_dev->iface, in gspca_init_transfer()
813 alt); in gspca_init_transfer()
815 if (ret == -ENOSPC) in gspca_init_transfer()
817 pr_err("set alt %d err %d\n", alt, ret); in gspca_init_transfer()
822 if (!gspca_dev->cam.no_urb_create) { in gspca_init_transfer()
823 gspca_dbg(gspca_dev, D_STREAM, "init transfer alt %d\n", in gspca_init_transfer()
824 alt); in gspca_init_transfer()
826 alt_xfer(&intf->altsetting[alt], xfer, in gspca_init_transfer()
827 gspca_dev->xfer_ep)); in gspca_init_transfer()
835 if (gspca_dev->cam.bulk) in gspca_init_transfer()
836 usb_clear_halt(gspca_dev->dev, in gspca_init_transfer()
837 gspca_dev->urb[0]->pipe); in gspca_init_transfer()
840 ret = gspca_dev->sd_desc->start(gspca_dev); in gspca_init_transfer()
845 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler); in gspca_init_transfer()
846 gspca_dev->streaming = true; in gspca_init_transfer()
849 if (gspca_dev->cam.bulk && gspca_dev->cam.bulk_nurbs == 0) in gspca_init_transfer()
854 urb = gspca_dev->urb[n]; in gspca_init_transfer()
867 if (ret != -ENOSPC) { in gspca_init_transfer()
868 pr_err("usb_submit_urb alt %d err %d\n", in gspca_init_transfer()
869 gspca_dev->alt, ret); in gspca_init_transfer()
876 gspca_err(gspca_dev, "alt %d - bandwidth not wide enough, trying again\n", in gspca_init_transfer()
877 alt); in gspca_init_transfer()
879 if (gspca_dev->sd_desc->isoc_nego) { in gspca_init_transfer()
880 ret = gspca_dev->sd_desc->isoc_nego(gspca_dev); in gspca_init_transfer()
886 ret = -EIO; in gspca_init_transfer()
889 gspca_dev->alt = ep_tb[--alt_idx].alt; in gspca_init_transfer()
901 i = gspca_dev->cam.nmodes - 1; /* take the highest mode */ in gspca_set_default_mode()
902 gspca_dev->curr_mode = i; in gspca_set_default_mode()
903 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i]; in gspca_set_default_mode()
906 v4l2_ctrl_handler_setup(gspca_dev->vdev.ctrl_handler); in gspca_set_default_mode()
914 for (i = 0; i < gspca_dev->cam.nmodes; i++) { in wxh_to_mode()
915 if (width == gspca_dev->cam.cam_mode[i].width in wxh_to_mode()
916 && height == gspca_dev->cam.cam_mode[i].height in wxh_to_mode()
917 && pixelformat == gspca_dev->cam.cam_mode[i].pixelformat) in wxh_to_mode()
920 return -EINVAL; in wxh_to_mode()
928 for (i = gspca_dev->cam.nmodes; --i >= 0; ) { in wxh_to_nearest_mode()
929 if (width >= gspca_dev->cam.cam_mode[i].width in wxh_to_nearest_mode()
930 && height >= gspca_dev->cam.cam_mode[i].height in wxh_to_nearest_mode()
931 && pixelformat == gspca_dev->cam.cam_mode[i].pixelformat) in wxh_to_nearest_mode()
934 for (i = gspca_dev->cam.nmodes; --i > 0; ) { in wxh_to_nearest_mode()
935 if (width >= gspca_dev->cam.cam_mode[i].width in wxh_to_nearest_mode()
936 && height >= gspca_dev->cam.cam_mode[i].height) in wxh_to_nearest_mode()
952 while ((modeU < gspca_dev->cam.nmodes) || modeD >= 0) { in gspca_get_mode()
953 if (--modeD >= 0) { in gspca_get_mode()
954 if (gspca_dev->cam.cam_mode[modeD].pixelformat in gspca_get_mode()
958 if (++modeU < gspca_dev->cam.nmodes) { in gspca_get_mode()
959 if (gspca_dev->cam.cam_mode[modeU].pixelformat in gspca_get_mode()
964 return -EINVAL; in gspca_get_mode()
973 gspca_dev->usb_err = 0; in vidioc_g_chip_info()
974 if (gspca_dev->sd_desc->get_chip_info) in vidioc_g_chip_info()
975 return gspca_dev->sd_desc->get_chip_info(gspca_dev, chip); in vidioc_g_chip_info()
976 return chip->match.addr ? -EINVAL : 0; in vidioc_g_chip_info()
984 gspca_dev->usb_err = 0; in vidioc_g_register()
985 return gspca_dev->sd_desc->get_register(gspca_dev, reg); in vidioc_g_register()
993 gspca_dev->usb_err = 0; in vidioc_s_register()
994 return gspca_dev->sd_desc->set_register(gspca_dev, reg); in vidioc_s_register()
1007 for (i = gspca_dev->cam.nmodes; --i >= 0; ) { in vidioc_enum_fmt_vid_cap()
1008 fmt_tb[index] = gspca_dev->cam.cam_mode[i].pixelformat; in vidioc_enum_fmt_vid_cap()
1016 if (fmtdesc->index == index) in vidioc_enum_fmt_vid_cap()
1020 return -EINVAL; in vidioc_enum_fmt_vid_cap()
1024 return -EINVAL; /* no more format */ in vidioc_enum_fmt_vid_cap()
1026 fmtdesc->pixelformat = fmt_tb[index]; in vidioc_enum_fmt_vid_cap()
1034 u32 priv = fmt->fmt.pix.priv; in vidioc_g_fmt_vid_cap()
1036 fmt->fmt.pix = gspca_dev->pixfmt; in vidioc_g_fmt_vid_cap()
1038 fmt->fmt.pix.priv = priv; in vidioc_g_fmt_vid_cap()
1047 w = fmt->fmt.pix.width; in try_fmt_vid_cap()
1048 h = fmt->fmt.pix.height; in try_fmt_vid_cap()
1051 fmt->fmt.pix.pixelformat, w, h); in try_fmt_vid_cap()
1054 mode = wxh_to_nearest_mode(gspca_dev, w, h, fmt->fmt.pix.pixelformat); in try_fmt_vid_cap()
1057 if (gspca_dev->cam.cam_mode[mode].pixelformat in try_fmt_vid_cap()
1058 != fmt->fmt.pix.pixelformat) { in try_fmt_vid_cap()
1062 fmt->fmt.pix.pixelformat); in try_fmt_vid_cap()
1066 fmt->fmt.pix = gspca_dev->cam.cam_mode[mode]; in try_fmt_vid_cap()
1067 if (gspca_dev->sd_desc->try_fmt) { in try_fmt_vid_cap()
1069 fmt->fmt.pix.width = w; in try_fmt_vid_cap()
1070 fmt->fmt.pix.height = h; in try_fmt_vid_cap()
1071 gspca_dev->sd_desc->try_fmt(gspca_dev, fmt); in try_fmt_vid_cap()
1080 u32 priv = fmt->fmt.pix.priv; in vidioc_try_fmt_vid_cap()
1083 return -EINVAL; in vidioc_try_fmt_vid_cap()
1085 fmt->fmt.pix.priv = priv; in vidioc_try_fmt_vid_cap()
1093 u32 priv = fmt->fmt.pix.priv; in vidioc_s_fmt_vid_cap()
1096 if (vb2_is_busy(&gspca_dev->queue)) in vidioc_s_fmt_vid_cap()
1097 return -EBUSY; in vidioc_s_fmt_vid_cap()
1101 return -EINVAL; in vidioc_s_fmt_vid_cap()
1103 gspca_dev->curr_mode = mode; in vidioc_s_fmt_vid_cap()
1104 if (gspca_dev->sd_desc->try_fmt) in vidioc_s_fmt_vid_cap()
1106 gspca_dev->pixfmt = fmt->fmt.pix; in vidioc_s_fmt_vid_cap()
1108 gspca_dev->pixfmt = gspca_dev->cam.cam_mode[mode]; in vidioc_s_fmt_vid_cap()
1110 fmt->fmt.pix.priv = priv; in vidioc_s_fmt_vid_cap()
1121 if (gspca_dev->sd_desc->enum_framesizes) in vidioc_enum_framesizes()
1122 return gspca_dev->sd_desc->enum_framesizes(gspca_dev, fsize); in vidioc_enum_framesizes()
1124 for (i = 0; i < gspca_dev->cam.nmodes; i++) { in vidioc_enum_framesizes()
1125 if (fsize->pixel_format != in vidioc_enum_framesizes()
1126 gspca_dev->cam.cam_mode[i].pixelformat) in vidioc_enum_framesizes()
1129 if (fsize->index == index) { in vidioc_enum_framesizes()
1130 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; in vidioc_enum_framesizes()
1131 fsize->discrete.width = in vidioc_enum_framesizes()
1132 gspca_dev->cam.cam_mode[i].width; in vidioc_enum_framesizes()
1133 fsize->discrete.height = in vidioc_enum_framesizes()
1134 gspca_dev->cam.cam_mode[i].height; in vidioc_enum_framesizes()
1140 return -EINVAL; in vidioc_enum_framesizes()
1150 mode = wxh_to_mode(gspca_dev, fival->width, fival->height, in vidioc_enum_frameintervals()
1151 fival->pixel_format); in vidioc_enum_frameintervals()
1153 return -EINVAL; in vidioc_enum_frameintervals()
1155 if (gspca_dev->cam.mode_framerates == NULL || in vidioc_enum_frameintervals()
1156 gspca_dev->cam.mode_framerates[mode].nrates == 0) in vidioc_enum_frameintervals()
1157 return -EINVAL; in vidioc_enum_frameintervals()
1159 if (fival->pixel_format != in vidioc_enum_frameintervals()
1160 gspca_dev->cam.cam_mode[mode].pixelformat) in vidioc_enum_frameintervals()
1161 return -EINVAL; in vidioc_enum_frameintervals()
1163 for (i = 0; i < gspca_dev->cam.mode_framerates[mode].nrates; i++) { in vidioc_enum_frameintervals()
1164 if (fival->index == i) { in vidioc_enum_frameintervals()
1165 fival->type = V4L2_FRMIVAL_TYPE_DISCRETE; in vidioc_enum_frameintervals()
1166 fival->discrete.numerator = 1; in vidioc_enum_frameintervals()
1167 fival->discrete.denominator = in vidioc_enum_frameintervals()
1168 gspca_dev->cam.mode_framerates[mode].rates[i]; in vidioc_enum_frameintervals()
1173 return -EINVAL; in vidioc_enum_frameintervals()
1181 v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler); in gspca_release()
1182 v4l2_device_unregister(&gspca_dev->v4l2_dev); in gspca_release()
1183 kfree(gspca_dev->usb_buf); in gspca_release()
1192 strscpy((char *)cap->driver, gspca_dev->sd_desc->name, in vidioc_querycap()
1193 sizeof(cap->driver)); in vidioc_querycap()
1194 if (gspca_dev->dev->product != NULL) { in vidioc_querycap()
1195 strscpy((char *)cap->card, gspca_dev->dev->product, in vidioc_querycap()
1196 sizeof(cap->card)); in vidioc_querycap()
1198 snprintf((char *) cap->card, sizeof cap->card, in vidioc_querycap()
1200 le16_to_cpu(gspca_dev->dev->descriptor.idVendor), in vidioc_querycap()
1201 le16_to_cpu(gspca_dev->dev->descriptor.idProduct)); in vidioc_querycap()
1203 usb_make_path(gspca_dev->dev, (char *) cap->bus_info, in vidioc_querycap()
1204 sizeof(cap->bus_info)); in vidioc_querycap()
1213 if (input->index != 0) in vidioc_enum_input()
1214 return -EINVAL; in vidioc_enum_input()
1215 input->type = V4L2_INPUT_TYPE_CAMERA; in vidioc_enum_input()
1216 input->status = gspca_dev->cam.input_flags; in vidioc_enum_input()
1217 strscpy(input->name, gspca_dev->sd_desc->name, in vidioc_enum_input()
1218 sizeof input->name); in vidioc_enum_input()
1231 return -EINVAL; in vidioc_s_input()
1240 gspca_dev->usb_err = 0; in vidioc_g_jpegcomp()
1241 return gspca_dev->sd_desc->get_jcomp(gspca_dev, jpegcomp); in vidioc_g_jpegcomp()
1249 gspca_dev->usb_err = 0; in vidioc_s_jpegcomp()
1250 return gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp); in vidioc_s_jpegcomp()
1258 parm->parm.capture.readbuffers = gspca_dev->queue.min_buffers_needed; in vidioc_g_parm()
1260 if (!gspca_dev->sd_desc->get_streamparm) in vidioc_g_parm()
1263 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_g_parm()
1264 gspca_dev->usb_err = 0; in vidioc_g_parm()
1265 gspca_dev->sd_desc->get_streamparm(gspca_dev, parm); in vidioc_g_parm()
1266 return gspca_dev->usb_err; in vidioc_g_parm()
1274 parm->parm.capture.readbuffers = gspca_dev->queue.min_buffers_needed; in vidioc_s_parm()
1276 if (!gspca_dev->sd_desc->set_streamparm) { in vidioc_s_parm()
1277 parm->parm.capture.capability = 0; in vidioc_s_parm()
1281 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vidioc_s_parm()
1282 gspca_dev->usb_err = 0; in vidioc_s_parm()
1283 gspca_dev->sd_desc->set_streamparm(gspca_dev, parm); in vidioc_s_parm()
1284 return gspca_dev->usb_err; in vidioc_s_parm()
1292 unsigned int size = PAGE_ALIGN(gspca_dev->pixfmt.sizeimage); in gspca_queue_setup()
1295 return sizes[0] < size ? -EINVAL : 0; in gspca_queue_setup()
1303 struct gspca_dev *gspca_dev = vb2_get_drv_priv(vb->vb2_queue); in gspca_buffer_prepare()
1304 unsigned long size = PAGE_ALIGN(gspca_dev->pixfmt.sizeimage); in gspca_buffer_prepare()
1309 return -EINVAL; in gspca_buffer_prepare()
1316 struct gspca_dev *gspca_dev = vb2_get_drv_priv(vb->vb2_queue); in gspca_buffer_finish()
1318 if (!gspca_dev->sd_desc->dq_callback) in gspca_buffer_finish()
1321 gspca_dev->usb_err = 0; in gspca_buffer_finish()
1322 if (gspca_dev->present) in gspca_buffer_finish()
1323 gspca_dev->sd_desc->dq_callback(gspca_dev); in gspca_buffer_finish()
1328 struct gspca_dev *gspca_dev = vb2_get_drv_priv(vb->vb2_queue); in gspca_buffer_queue()
1332 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_buffer_queue()
1333 list_add_tail(&buf->list, &gspca_dev->buf_list); in gspca_buffer_queue()
1334 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_buffer_queue()
1343 spin_lock_irqsave(&gspca_dev->qlock, flags); in gspca_return_all_buffers()
1344 list_for_each_entry_safe(buf, node, &gspca_dev->buf_list, list) { in gspca_return_all_buffers()
1345 vb2_buffer_done(&buf->vb.vb2_buf, state); in gspca_return_all_buffers()
1346 list_del(&buf->list); in gspca_return_all_buffers()
1348 spin_unlock_irqrestore(&gspca_dev->qlock, flags); in gspca_return_all_buffers()
1356 gspca_dev->sequence = 0; in gspca_start_streaming()
1439 * This function must be called by the sub-driver when it is
1453 pr_info("%s-" GSPCA_VERSION " probing %04x:%04x\n", in gspca_dev_probe2()
1454 sd_desc->name, id->idVendor, id->idProduct); in gspca_dev_probe2()
1462 return -ENOMEM; in gspca_dev_probe2()
1464 gspca_dev->usb_buf = kzalloc(USB_BUF_SZ, GFP_KERNEL); in gspca_dev_probe2()
1465 if (!gspca_dev->usb_buf) { in gspca_dev_probe2()
1467 ret = -ENOMEM; in gspca_dev_probe2()
1470 gspca_dev->dev = dev; in gspca_dev_probe2()
1471 gspca_dev->iface = intf->cur_altsetting->desc.bInterfaceNumber; in gspca_dev_probe2()
1472 gspca_dev->xfer_ep = -1; in gspca_dev_probe2()
1475 if (dev->actconfig->desc.bNumInterfaces != 1) { in gspca_dev_probe2()
1479 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { in gspca_dev_probe2()
1480 intf2 = dev->actconfig->interface[i]; in gspca_dev_probe2()
1482 && intf2->altsetting != NULL in gspca_dev_probe2()
1483 && intf2->altsetting->desc.bInterfaceClass == in gspca_dev_probe2()
1485 gspca_dev->audio = 1; in gspca_dev_probe2()
1491 gspca_dev->v4l2_dev.release = gspca_release; in gspca_dev_probe2()
1492 ret = v4l2_device_register(&intf->dev, &gspca_dev->v4l2_dev); in gspca_dev_probe2()
1495 gspca_dev->present = true; in gspca_dev_probe2()
1496 gspca_dev->sd_desc = sd_desc; in gspca_dev_probe2()
1497 gspca_dev->empty_packet = -1; /* don't check the empty packets */ in gspca_dev_probe2()
1498 gspca_dev->vdev = gspca_template; in gspca_dev_probe2()
1499 gspca_dev->vdev.v4l2_dev = &gspca_dev->v4l2_dev; in gspca_dev_probe2()
1500 gspca_dev->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | in gspca_dev_probe2()
1502 video_set_drvdata(&gspca_dev->vdev, gspca_dev); in gspca_dev_probe2()
1503 gspca_dev->module = module; in gspca_dev_probe2()
1505 mutex_init(&gspca_dev->usb_lock); in gspca_dev_probe2()
1506 gspca_dev->vdev.lock = &gspca_dev->usb_lock; in gspca_dev_probe2()
1507 init_waitqueue_head(&gspca_dev->wq); in gspca_dev_probe2()
1510 q = &gspca_dev->queue; in gspca_dev_probe2()
1511 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in gspca_dev_probe2()
1512 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; in gspca_dev_probe2()
1513 q->drv_priv = gspca_dev; in gspca_dev_probe2()
1514 q->buf_struct_size = sizeof(struct gspca_buffer); in gspca_dev_probe2()
1515 q->ops = &gspca_qops; in gspca_dev_probe2()
1516 q->mem_ops = &vb2_vmalloc_memops; in gspca_dev_probe2()
1517 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in gspca_dev_probe2()
1518 q->min_buffers_needed = 2; in gspca_dev_probe2()
1519 q->lock = &gspca_dev->usb_lock; in gspca_dev_probe2()
1523 gspca_dev->vdev.queue = q; in gspca_dev_probe2()
1525 INIT_LIST_HEAD(&gspca_dev->buf_list); in gspca_dev_probe2()
1526 spin_lock_init(&gspca_dev->qlock); in gspca_dev_probe2()
1529 ret = sd_desc->config(gspca_dev, id); in gspca_dev_probe2()
1532 ret = sd_desc->init(gspca_dev); in gspca_dev_probe2()
1535 if (sd_desc->init_controls) in gspca_dev_probe2()
1536 ret = sd_desc->init_controls(gspca_dev); in gspca_dev_probe2()
1546 if (!gspca_dev->sd_desc->get_register) in gspca_dev_probe2()
1547 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_G_REGISTER); in gspca_dev_probe2()
1548 if (!gspca_dev->sd_desc->set_register) in gspca_dev_probe2()
1549 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_S_REGISTER); in gspca_dev_probe2()
1551 if (!gspca_dev->sd_desc->get_jcomp) in gspca_dev_probe2()
1552 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_G_JPEGCOMP); in gspca_dev_probe2()
1553 if (!gspca_dev->sd_desc->set_jcomp) in gspca_dev_probe2()
1554 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_S_JPEGCOMP); in gspca_dev_probe2()
1557 ret = video_register_device(&gspca_dev->vdev, in gspca_dev_probe2()
1559 -1); in gspca_dev_probe2()
1567 video_device_node_name(&gspca_dev->vdev)); in gspca_dev_probe2()
1574 if (gspca_dev->input_dev) in gspca_dev_probe2()
1575 input_unregister_device(gspca_dev->input_dev); in gspca_dev_probe2()
1577 v4l2_ctrl_handler_free(gspca_dev->vdev.ctrl_handler); in gspca_dev_probe2()
1578 kfree(gspca_dev->usb_buf); in gspca_dev_probe2()
1593 /* we don't handle multi-config cameras */ in gspca_dev_probe()
1594 if (dev->descriptor.bNumConfigurations != 1) { in gspca_dev_probe()
1596 id->idVendor, id->idProduct); in gspca_dev_probe()
1597 return -ENODEV; in gspca_dev_probe()
1601 if (dev->actconfig->desc.bNumInterfaces != 1 in gspca_dev_probe()
1602 && intf->cur_altsetting->desc.bInterfaceNumber != 0) in gspca_dev_probe()
1603 return -ENODEV; in gspca_dev_probe()
1612 * This function must be called by the sub-driver
1623 video_device_node_name(&gspca_dev->vdev)); in gspca_disconnect()
1625 mutex_lock(&gspca_dev->usb_lock); in gspca_disconnect()
1626 gspca_dev->present = false; in gspca_disconnect()
1630 vb2_queue_error(&gspca_dev->queue); in gspca_disconnect()
1633 input_dev = gspca_dev->input_dev; in gspca_disconnect()
1635 gspca_dev->input_dev = NULL; in gspca_disconnect()
1640 v4l2_device_disconnect(&gspca_dev->v4l2_dev); in gspca_disconnect()
1641 video_unregister_device(&gspca_dev->vdev); in gspca_disconnect()
1643 mutex_unlock(&gspca_dev->usb_lock); in gspca_disconnect()
1646 v4l2_device_put(&gspca_dev->v4l2_dev); in gspca_disconnect()
1657 if (!vb2_start_streaming_called(&gspca_dev->queue)) in gspca_suspend()
1660 mutex_lock(&gspca_dev->usb_lock); in gspca_suspend()
1661 gspca_dev->frozen = 1; /* avoid urb error messages */ in gspca_suspend()
1662 gspca_dev->usb_err = 0; in gspca_suspend()
1663 if (gspca_dev->sd_desc->stopN) in gspca_suspend()
1664 gspca_dev->sd_desc->stopN(gspca_dev); in gspca_suspend()
1667 if (gspca_dev->sd_desc->stop0) in gspca_suspend()
1668 gspca_dev->sd_desc->stop0(gspca_dev); in gspca_suspend()
1669 mutex_unlock(&gspca_dev->usb_lock); in gspca_suspend()
1680 mutex_lock(&gspca_dev->usb_lock); in gspca_resume()
1681 gspca_dev->frozen = 0; in gspca_resume()
1682 gspca_dev->usb_err = 0; in gspca_resume()
1683 gspca_dev->sd_desc->init(gspca_dev); in gspca_resume()
1686 * only write to the device registers on s_ctrl when streaming -> in gspca_resume()
1689 streaming = vb2_start_streaming_called(&gspca_dev->queue); in gspca_resume()
1694 mutex_unlock(&gspca_dev->usb_lock); in gspca_resume()
1701 /* -- module insert / remove -- */