Lines Matching +full:odd +full:- +full:numbered
30 * Fushicai USBTV007 Audio-Video Grabber Driver
33 * http://www.fushicai.com/products_detail/&productId=d05449ee-b690-42f9-a661-aa7353894bed.html
42 * reverse-engineering activity
45 #include <media/v4l2-ioctl.h>
46 #include <media/videobuf2-v4l2.h>
76 usbtv->width = params->cap_width; in usbtv_configure_for_norm()
77 usbtv->height = params->cap_height; in usbtv_configure_for_norm()
78 usbtv->n_chunks = usbtv->width * usbtv->height in usbtv_configure_for_norm()
80 usbtv->norm = norm; in usbtv_configure_for_norm()
82 ret = -EINVAL; in usbtv_configure_for_norm()
115 ret = -EINVAL; in usbtv_select_input()
119 usbtv->input = input; in usbtv_select_input()
126 /* NTSC M/M-JP/M-KR */ in usbtv_norm_to_16f_reg()
256 ret = -EINVAL; in usbtv_select_norm()
340 ret = usbtv_select_norm(usbtv, usbtv->norm); in usbtv_setup_capture()
344 ret = usbtv_select_input(usbtv, usbtv->input); in usbtv_setup_capture()
348 ret = v4l2_ctrl_handler_setup(&usbtv->ctrl); in usbtv_setup_capture()
365 * takes 1.5 chunks to make a 720 pixel-wide line for the frame.
366 * The image is interlaced, so there is a "scan" of odd lines, followed
367 * by "scan" of even numbered lines.
370 * the rows based on "odd" value.
375 static void usbtv_chunk_to_vbuf(u32 *frame, __be32 *src, int chunk_no, int odd) in usbtv_chunk_to_vbuf() argument
382 int part_index = (line * 2 + !odd) * 3 + (part_no % 3); in usbtv_chunk_to_vbuf()
391 /* Called for each 256-byte image chunk.
396 int frame_id, odd, chunk_no; in usbtv_image_chunk() local
405 odd = USBTV_ODD(chunk); in usbtv_image_chunk()
407 if (chunk_no >= usbtv->n_chunks) in usbtv_image_chunk()
412 usbtv->frame_id = frame_id; in usbtv_image_chunk()
413 usbtv->chunks_done = 0; in usbtv_image_chunk()
416 if (usbtv->frame_id != frame_id) in usbtv_image_chunk()
419 spin_lock_irqsave(&usbtv->buflock, flags); in usbtv_image_chunk()
420 if (list_empty(&usbtv->bufs)) { in usbtv_image_chunk()
422 spin_unlock_irqrestore(&usbtv->buflock, flags); in usbtv_image_chunk()
427 buf = list_first_entry(&usbtv->bufs, struct usbtv_buf, list); in usbtv_image_chunk()
428 frame = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in usbtv_image_chunk()
431 usbtv_chunk_to_vbuf(frame, &chunk[1], chunk_no, odd); in usbtv_image_chunk()
432 usbtv->chunks_done++; in usbtv_image_chunk()
435 if (chunk_no == usbtv->n_chunks-1) { in usbtv_image_chunk()
437 if (odd && !usbtv->last_odd) { in usbtv_image_chunk()
438 int size = vb2_plane_size(&buf->vb.vb2_buf, 0); in usbtv_image_chunk()
439 enum vb2_buffer_state state = usbtv->chunks_done == in usbtv_image_chunk()
440 usbtv->n_chunks ? in usbtv_image_chunk()
444 buf->vb.field = V4L2_FIELD_INTERLACED; in usbtv_image_chunk()
445 buf->vb.sequence = usbtv->sequence++; in usbtv_image_chunk()
446 buf->vb.vb2_buf.timestamp = ktime_get_ns(); in usbtv_image_chunk()
447 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size); in usbtv_image_chunk()
448 vb2_buffer_done(&buf->vb.vb2_buf, state); in usbtv_image_chunk()
449 list_del(&buf->list); in usbtv_image_chunk()
451 usbtv->last_odd = odd; in usbtv_image_chunk()
454 spin_unlock_irqrestore(&usbtv->buflock, flags); in usbtv_image_chunk()
457 /* Got image data. Each packet contains a number of 256-word chunks we
463 struct usbtv *usbtv = (struct usbtv *)ip->context; in usbtv_iso_cb()
465 switch (ip->status) { in usbtv_iso_cb()
470 case -ENODEV: in usbtv_iso_cb()
471 case -ENOENT: in usbtv_iso_cb()
472 case -ECONNRESET: in usbtv_iso_cb()
473 case -ESHUTDOWN: in usbtv_iso_cb()
477 dev_warn(usbtv->dev, "Bad response for ISO request.\n"); in usbtv_iso_cb()
481 for (i = 0; i < ip->number_of_packets; i++) { in usbtv_iso_cb()
482 int size = ip->iso_frame_desc[i].actual_length; in usbtv_iso_cb()
483 unsigned char *data = ip->transfer_buffer + in usbtv_iso_cb()
484 ip->iso_frame_desc[i].offset; in usbtv_iso_cb()
495 dev_warn(usbtv->dev, "Could not resubmit ISO URB\n"); in usbtv_iso_cb()
501 int size = usbtv->iso_size; in usbtv_setup_iso_transfer()
508 ip->dev = usbtv->udev; in usbtv_setup_iso_transfer()
509 ip->context = usbtv; in usbtv_setup_iso_transfer()
510 ip->pipe = usb_rcvisocpipe(usbtv->udev, USBTV_VIDEO_ENDP); in usbtv_setup_iso_transfer()
511 ip->interval = 1; in usbtv_setup_iso_transfer()
512 ip->transfer_flags = URB_ISO_ASAP; in usbtv_setup_iso_transfer()
513 ip->transfer_buffer = kcalloc(USBTV_ISOC_PACKETS, size, in usbtv_setup_iso_transfer()
515 if (!ip->transfer_buffer) { in usbtv_setup_iso_transfer()
519 ip->complete = usbtv_iso_cb; in usbtv_setup_iso_transfer()
520 ip->number_of_packets = USBTV_ISOC_PACKETS; in usbtv_setup_iso_transfer()
521 ip->transfer_buffer_length = size * USBTV_ISOC_PACKETS; in usbtv_setup_iso_transfer()
523 ip->iso_frame_desc[i].offset = size * i; in usbtv_setup_iso_transfer()
524 ip->iso_frame_desc[i].length = size; in usbtv_setup_iso_transfer()
537 struct urb *ip = usbtv->isoc_urbs[i]; in usbtv_stop()
542 kfree(ip->transfer_buffer); in usbtv_stop()
544 usbtv->isoc_urbs[i] = NULL; in usbtv_stop()
548 spin_lock_irqsave(&usbtv->buflock, flags); in usbtv_stop()
549 while (!list_empty(&usbtv->bufs)) { in usbtv_stop()
550 struct usbtv_buf *buf = list_first_entry(&usbtv->bufs, in usbtv_stop()
552 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in usbtv_stop()
553 list_del(&buf->list); in usbtv_stop()
555 spin_unlock_irqrestore(&usbtv->buflock, flags); in usbtv_stop()
565 ret = usb_set_interface(usbtv->udev, 0, 0); in usbtv_start()
573 ret = usb_set_interface(usbtv->udev, 0, 1); in usbtv_start()
584 ret = -ENOMEM; in usbtv_start()
587 usbtv->isoc_urbs[i] = ip; in usbtv_start()
606 strscpy(cap->driver, "usbtv", sizeof(cap->driver)); in usbtv_querycap()
607 strscpy(cap->card, "usbtv", sizeof(cap->card)); in usbtv_querycap()
608 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); in usbtv_querycap()
617 switch (i->index) { in usbtv_enum_input()
619 strscpy(i->name, "Composite", sizeof(i->name)); in usbtv_enum_input()
622 strscpy(i->name, "S-Video", sizeof(i->name)); in usbtv_enum_input()
625 return -EINVAL; in usbtv_enum_input()
628 i->type = V4L2_INPUT_TYPE_CAMERA; in usbtv_enum_input()
629 i->std = dev->vdev.tvnorms; in usbtv_enum_input()
636 if (f->index > 0) in usbtv_enum_fmt_vid_cap()
637 return -EINVAL; in usbtv_enum_fmt_vid_cap()
639 f->pixelformat = V4L2_PIX_FMT_YUYV; in usbtv_enum_fmt_vid_cap()
648 f->fmt.pix.width = usbtv->width; in usbtv_fmt_vid_cap()
649 f->fmt.pix.height = usbtv->height; in usbtv_fmt_vid_cap()
650 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; in usbtv_fmt_vid_cap()
651 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in usbtv_fmt_vid_cap()
652 f->fmt.pix.bytesperline = usbtv->width * 2; in usbtv_fmt_vid_cap()
653 f->fmt.pix.sizeimage = (f->fmt.pix.bytesperline * f->fmt.pix.height); in usbtv_fmt_vid_cap()
654 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in usbtv_fmt_vid_cap()
662 *norm = usbtv->norm; in usbtv_g_std()
668 int ret = -EINVAL; in usbtv_s_std()
680 *i = usbtv->input; in usbtv_g_input()
728 unsigned size = USBTV_CHUNK * usbtv->n_chunks * 2 * sizeof(u32); in usbtv_queue_setup()
732 *nbuffers = 2 - q_num_bufs; in usbtv_queue_setup()
734 return sizes[0] < size ? -EINVAL : 0; in usbtv_queue_setup()
744 struct usbtv *usbtv = vb2_get_drv_priv(vb->vb2_queue); in usbtv_buf_queue()
748 if (usbtv->udev == NULL) { in usbtv_buf_queue()
753 spin_lock_irqsave(&usbtv->buflock, flags); in usbtv_buf_queue()
754 list_add_tail(&buf->list, &usbtv->bufs); in usbtv_buf_queue()
755 spin_unlock_irqrestore(&usbtv->buflock, flags); in usbtv_buf_queue()
762 if (usbtv->udev == NULL) in usbtv_start_streaming()
763 return -ENODEV; in usbtv_start_streaming()
765 usbtv->last_odd = 1; in usbtv_start_streaming()
766 usbtv->sequence = 0; in usbtv_start_streaming()
774 if (usbtv->udev) in usbtv_stop_streaming()
789 struct usbtv *usbtv = container_of(ctrl->handler, struct usbtv, in usbtv_s_ctrl()
797 return -ENOMEM; in usbtv_s_ctrl()
803 if (ctrl->id == V4L2_CID_BRIGHTNESS || ctrl->id == V4L2_CID_CONTRAST) { in usbtv_s_ctrl()
804 ret = usb_control_msg(usbtv->udev, in usbtv_s_ctrl()
805 usb_rcvctrlpipe(usbtv->udev, 0), USBTV_CONTROL_REG, in usbtv_s_ctrl()
813 switch (ctrl->id) { in usbtv_s_ctrl()
818 data[0] |= (ctrl->val >> 8) & 0xf; in usbtv_s_ctrl()
819 data[2] = ctrl->val & 0xff; in usbtv_s_ctrl()
825 data[0] |= (ctrl->val >> 4) & 0xf0; in usbtv_s_ctrl()
826 data[1] = ctrl->val & 0xff; in usbtv_s_ctrl()
830 data[0] = ctrl->val >> 8; in usbtv_s_ctrl()
831 data[1] = ctrl->val & 0xff; in usbtv_s_ctrl()
837 if (ctrl->val > 0) { in usbtv_s_ctrl()
838 data[0] = 0x92 + (ctrl->val >> 8); in usbtv_s_ctrl()
839 data[1] = ctrl->val & 0xff; in usbtv_s_ctrl()
841 data[0] = 0x82 + (-ctrl->val >> 8); in usbtv_s_ctrl()
842 data[1] = -ctrl->val & 0xff; in usbtv_s_ctrl()
848 data[1] = ctrl->val; in usbtv_s_ctrl()
853 return -EINVAL; in usbtv_s_ctrl()
856 ret = usb_control_msg(usbtv->udev, usb_sndctrlpipe(usbtv->udev, 0), in usbtv_s_ctrl()
863 dev_warn(usbtv->dev, "Failed to submit a control request.\n"); in usbtv_s_ctrl()
877 v4l2_device_unregister(&usbtv->v4l2_dev); in usbtv_release()
878 v4l2_ctrl_handler_free(&usbtv->ctrl); in usbtv_release()
888 spin_lock_init(&usbtv->buflock); in usbtv_video_init()
889 mutex_init(&usbtv->v4l2_lock); in usbtv_video_init()
890 mutex_init(&usbtv->vb2q_lock); in usbtv_video_init()
891 INIT_LIST_HEAD(&usbtv->bufs); in usbtv_video_init()
894 usbtv->vb2q.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in usbtv_video_init()
895 usbtv->vb2q.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; in usbtv_video_init()
896 usbtv->vb2q.drv_priv = usbtv; in usbtv_video_init()
897 usbtv->vb2q.buf_struct_size = sizeof(struct usbtv_buf); in usbtv_video_init()
898 usbtv->vb2q.ops = &usbtv_vb2_ops; in usbtv_video_init()
899 usbtv->vb2q.mem_ops = &vb2_vmalloc_memops; in usbtv_video_init()
900 usbtv->vb2q.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in usbtv_video_init()
901 usbtv->vb2q.lock = &usbtv->vb2q_lock; in usbtv_video_init()
902 ret = vb2_queue_init(&usbtv->vb2q); in usbtv_video_init()
904 dev_warn(usbtv->dev, "Could not initialize videobuf2 queue\n"); in usbtv_video_init()
909 v4l2_ctrl_handler_init(&usbtv->ctrl, 4); in usbtv_video_init()
910 v4l2_ctrl_new_std(&usbtv->ctrl, &usbtv_ctrl_ops, in usbtv_video_init()
912 v4l2_ctrl_new_std(&usbtv->ctrl, &usbtv_ctrl_ops, in usbtv_video_init()
914 v4l2_ctrl_new_std(&usbtv->ctrl, &usbtv_ctrl_ops, in usbtv_video_init()
916 v4l2_ctrl_new_std(&usbtv->ctrl, &usbtv_ctrl_ops, in usbtv_video_init()
917 V4L2_CID_HUE, -0xdff, 0xdff, 1, 0x000); in usbtv_video_init()
918 v4l2_ctrl_new_std(&usbtv->ctrl, &usbtv_ctrl_ops, in usbtv_video_init()
920 ret = usbtv->ctrl.error; in usbtv_video_init()
922 dev_warn(usbtv->dev, "Could not initialize controls\n"); in usbtv_video_init()
927 usbtv->v4l2_dev.ctrl_handler = &usbtv->ctrl; in usbtv_video_init()
928 usbtv->v4l2_dev.release = usbtv_release; in usbtv_video_init()
929 ret = v4l2_device_register(usbtv->dev, &usbtv->v4l2_dev); in usbtv_video_init()
931 dev_warn(usbtv->dev, "Could not register v4l2 device\n"); in usbtv_video_init()
936 strscpy(usbtv->vdev.name, "usbtv", sizeof(usbtv->vdev.name)); in usbtv_video_init()
937 usbtv->vdev.v4l2_dev = &usbtv->v4l2_dev; in usbtv_video_init()
938 usbtv->vdev.release = video_device_release_empty; in usbtv_video_init()
939 usbtv->vdev.fops = &usbtv_fops; in usbtv_video_init()
940 usbtv->vdev.ioctl_ops = &usbtv_ioctl_ops; in usbtv_video_init()
941 usbtv->vdev.tvnorms = USBTV_TV_STD; in usbtv_video_init()
942 usbtv->vdev.queue = &usbtv->vb2q; in usbtv_video_init()
943 usbtv->vdev.lock = &usbtv->v4l2_lock; in usbtv_video_init()
944 usbtv->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in usbtv_video_init()
946 video_set_drvdata(&usbtv->vdev, usbtv); in usbtv_video_init()
947 ret = video_register_device(&usbtv->vdev, VFL_TYPE_VIDEO, -1); in usbtv_video_init()
949 dev_warn(usbtv->dev, "Could not register video device\n"); in usbtv_video_init()
956 v4l2_device_unregister(&usbtv->v4l2_dev); in usbtv_video_init()
959 v4l2_ctrl_handler_free(&usbtv->ctrl); in usbtv_video_init()
966 vb2_video_unregister_device(&usbtv->vdev); in usbtv_video_free()
967 v4l2_device_disconnect(&usbtv->v4l2_dev); in usbtv_video_free()
969 v4l2_device_put(&usbtv->v4l2_dev); in usbtv_video_free()