Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: via-camera: convert to the vb2 framework

Convert the via-camera to the vb2 framework. With this change this
driver passes all 'v4l2-compliance -s' tests on my OLPC 1.5.

Also tested with the Sugar 'Record' application.

All tests were done under the OLPC official 5.0.8 kernel.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
4590c074 4e4f3b99

+158 -334
+1 -1
drivers/media/platform/Kconfig
··· 16 16 config VIDEO_VIA_CAMERA 17 17 tristate "VIAFB camera controller support" 18 18 depends on FB_VIA 19 - select VIDEOBUF_DMA_SG 19 + select VIDEOBUF2_DMA_SG 20 20 select VIDEO_OV7670 21 21 help 22 22 Driver support for the integrated camera controller in VIA
+157 -333
drivers/media/platform/via-camera.c
··· 21 21 #include <media/v4l2-event.h> 22 22 #include <media/v4l2-image-sizes.h> 23 23 #include <media/i2c/ov7670.h> 24 - #include <media/videobuf-dma-sg.h> 24 + #include <media/videobuf2-dma-sg.h> 25 25 #include <linux/delay.h> 26 26 #include <linux/dma-mapping.h> 27 27 #include <linux/pm_qos.h> ··· 85 85 * live in frame buffer memory, so we don't call them "DMA". 86 86 */ 87 87 unsigned int cb_offsets[3]; /* offsets into fb mem */ 88 - u8 __iomem *cb_addrs[3]; /* Kernel-space addresses */ 88 + u8 __iomem *cb_addrs[3]; /* Kernel-space addresses */ 89 89 int n_cap_bufs; /* How many are we using? */ 90 - int next_buf; 91 - struct videobuf_queue vb_queue; 92 - struct list_head buffer_queue; /* prot. by reg_lock */ 93 - /* 94 - * User tracking. 95 - */ 96 - int users; 97 - struct file *owner; 90 + struct vb2_queue vq; 91 + struct list_head buffer_queue; 92 + u32 sequence; 98 93 /* 99 94 * Video format information. sensor_format is kept in a form 100 95 * that we can use to pass to the sensor. We always run the ··· 100 105 struct v4l2_pix_format sensor_format; 101 106 struct v4l2_pix_format user_format; 102 107 u32 mbus_code; 108 + }; 109 + 110 + /* buffer for one video frame */ 111 + struct via_buffer { 112 + /* common v4l buffer stuff -- must be first */ 113 + struct vb2_v4l2_buffer vbuf; 114 + struct list_head queue; 103 115 }; 104 116 105 117 /* ··· 325 323 } 326 324 327 325 /* 328 - * Find the next videobuf buffer which has somebody waiting on it. 326 + * Find the next buffer which has somebody waiting on it. 329 327 */ 330 - static struct videobuf_buffer *viacam_next_buffer(struct via_camera *cam) 328 + static struct via_buffer *viacam_next_buffer(struct via_camera *cam) 331 329 { 332 - unsigned long flags; 333 - struct videobuf_buffer *buf = NULL; 334 - 335 - spin_lock_irqsave(&cam->viadev->reg_lock, flags); 336 330 if (cam->opstate != S_RUNNING) 337 - goto out; 331 + return NULL; 338 332 if (list_empty(&cam->buffer_queue)) 339 - goto out; 340 - buf = list_entry(cam->buffer_queue.next, struct videobuf_buffer, queue); 341 - if (!waitqueue_active(&buf->done)) {/* Nobody waiting */ 342 - buf = NULL; 343 - goto out; 344 - } 345 - list_del(&buf->queue); 346 - buf->state = VIDEOBUF_ACTIVE; 347 - out: 348 - spin_unlock_irqrestore(&cam->viadev->reg_lock, flags); 349 - return buf; 333 + return NULL; 334 + return list_entry(cam->buffer_queue.next, struct via_buffer, queue); 350 335 } 351 336 352 337 /* ··· 341 352 */ 342 353 static irqreturn_t viacam_irq(int irq, void *data) 343 354 { 344 - int bufn; 345 - struct videobuf_buffer *vb; 346 355 struct via_camera *cam = data; 347 - struct videobuf_dmabuf *vdma; 356 + struct via_buffer *vb; 357 + int bufn; 358 + struct sg_table *sgt; 348 359 360 + mutex_lock(&cam->lock); 349 361 /* 350 362 * If there is no place to put the data frame, don't bother 351 363 * with anything else. ··· 364 374 /* 365 375 * Copy over the data and let any waiters know. 366 376 */ 367 - vdma = videobuf_to_dma(vb); 368 - viafb_dma_copy_out_sg(cam->cb_offsets[bufn], vdma->sglist, vdma->sglen); 369 - vb->state = VIDEOBUF_DONE; 370 - vb->size = cam->user_format.sizeimage; 371 - wake_up(&vb->done); 377 + sgt = vb2_dma_sg_plane_desc(&vb->vbuf.vb2_buf, 0); 378 + vb->vbuf.vb2_buf.timestamp = ktime_get_ns(); 379 + viafb_dma_copy_out_sg(cam->cb_offsets[bufn], sgt->sgl, sgt->nents); 380 + vb->vbuf.sequence = cam->sequence++; 381 + vb->vbuf.field = V4L2_FIELD_NONE; 382 + list_del(&vb->queue); 383 + vb2_buffer_done(&vb->vbuf.vb2_buf, VB2_BUF_STATE_DONE); 372 384 done: 385 + mutex_unlock(&cam->lock); 373 386 return IRQ_HANDLED; 374 387 } 375 388 ··· 548 555 static void viacam_start_engine(struct via_camera *cam) 549 556 { 550 557 spin_lock_irq(&cam->viadev->reg_lock); 551 - cam->next_buf = 0; 552 558 viacam_write_reg_mask(cam, VCR_CAPINTC, VCR_CI_ENABLE, VCR_CI_ENABLE); 553 559 viacam_int_enable(cam); 554 560 (void) viacam_read_reg(cam, VCR_CAPINTC); /* Force post */ ··· 568 576 569 577 570 578 /* --------------------------------------------------------------------------*/ 571 - /* Videobuf callback ops */ 579 + /* vb2 callback ops */ 572 580 573 - /* 574 - * buffer_setup. The purpose of this one would appear to be to tell 575 - * videobuf how big a single image is. It's also evidently up to us 576 - * to put some sort of limit on the maximum number of buffers allowed. 577 - */ 578 - static int viacam_vb_buf_setup(struct videobuf_queue *q, 579 - unsigned int *count, unsigned int *size) 581 + static struct via_buffer *vb2_to_via_buffer(struct vb2_buffer *vb) 580 582 { 581 - struct via_camera *cam = q->priv_data; 583 + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 582 584 583 - *size = cam->user_format.sizeimage; 584 - if (*count == 0 || *count > 6) /* Arbitrary number */ 585 - *count = 6; 586 - return 0; 585 + return container_of(vbuf, struct via_buffer, vbuf); 587 586 } 588 587 589 - /* 590 - * Prepare a buffer. 591 - */ 592 - static int viacam_vb_buf_prepare(struct videobuf_queue *q, 593 - struct videobuf_buffer *vb, enum v4l2_field field) 588 + static void viacam_vb2_queue(struct vb2_buffer *vb) 594 589 { 595 - struct via_camera *cam = q->priv_data; 590 + struct via_camera *cam = vb2_get_drv_priv(vb->vb2_queue); 591 + struct via_buffer *via = vb2_to_via_buffer(vb); 596 592 597 - vb->size = cam->user_format.sizeimage; 598 - vb->width = cam->user_format.width; /* bytesperline???? */ 599 - vb->height = cam->user_format.height; 600 - vb->field = field; 601 - if (vb->state == VIDEOBUF_NEEDS_INIT) { 602 - int ret = videobuf_iolock(q, vb, NULL); 603 - if (ret) 604 - return ret; 593 + list_add_tail(&via->queue, &cam->buffer_queue); 594 + } 595 + 596 + static int viacam_vb2_prepare(struct vb2_buffer *vb) 597 + { 598 + struct via_camera *cam = vb2_get_drv_priv(vb->vb2_queue); 599 + 600 + if (vb2_plane_size(vb, 0) < cam->user_format.sizeimage) { 601 + cam_dbg(cam, 602 + "Plane size too small (%lu < %u)\n", 603 + vb2_plane_size(vb, 0), 604 + cam->user_format.sizeimage); 605 + return -EINVAL; 605 606 } 606 - vb->state = VIDEOBUF_PREPARED; 607 + 608 + vb2_set_plane_payload(vb, 0, cam->user_format.sizeimage); 609 + 607 610 return 0; 608 611 } 609 612 610 - /* 611 - * We've got a buffer to put data into. 612 - * 613 - * FIXME: check for a running engine and valid buffers? 614 - */ 615 - static void viacam_vb_buf_queue(struct videobuf_queue *q, 616 - struct videobuf_buffer *vb) 613 + static int viacam_vb2_queue_setup(struct vb2_queue *vq, 614 + unsigned int *nbufs, 615 + unsigned int *num_planes, unsigned int sizes[], 616 + struct device *alloc_devs[]) 617 617 { 618 - struct via_camera *cam = q->priv_data; 618 + struct via_camera *cam = vb2_get_drv_priv(vq); 619 + int size = cam->user_format.sizeimage; 619 620 621 + if (*num_planes) 622 + return sizes[0] < size ? -EINVAL : 0; 623 + 624 + *num_planes = 1; 625 + sizes[0] = size; 626 + return 0; 627 + } 628 + 629 + static int viacam_vb2_start_streaming(struct vb2_queue *vq, unsigned int count) 630 + { 631 + struct via_camera *cam = vb2_get_drv_priv(vq); 632 + struct via_buffer *buf, *tmp; 633 + int ret = 0; 634 + 635 + if (cam->opstate != S_IDLE) { 636 + ret = -EBUSY; 637 + goto out; 638 + } 620 639 /* 621 - * Note that videobuf holds the lock when it calls 622 - * us, so we need not (indeed, cannot) take it here. 640 + * Configure things if need be. 623 641 */ 624 - vb->state = VIDEOBUF_QUEUED; 625 - list_add_tail(&vb->queue, &cam->buffer_queue); 642 + if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { 643 + ret = viacam_configure_sensor(cam); 644 + if (ret) 645 + goto out; 646 + ret = viacam_config_controller(cam); 647 + if (ret) 648 + goto out; 649 + } 650 + cam->sequence = 0; 651 + /* 652 + * If the CPU goes into C3, the DMA transfer gets corrupted and 653 + * users start filing unsightly bug reports. Put in a "latency" 654 + * requirement which will keep the CPU out of the deeper sleep 655 + * states. 656 + */ 657 + pm_qos_add_request(&cam->qos_request, PM_QOS_CPU_DMA_LATENCY, 50); 658 + viacam_start_engine(cam); 659 + return 0; 660 + out: 661 + list_for_each_entry_safe(buf, tmp, &cam->buffer_queue, queue) { 662 + list_del(&buf->queue); 663 + vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED); 664 + } 665 + return ret; 626 666 } 627 667 628 - /* 629 - * Free a buffer. 630 - */ 631 - static void viacam_vb_buf_release(struct videobuf_queue *q, 632 - struct videobuf_buffer *vb) 668 + static void viacam_vb2_stop_streaming(struct vb2_queue *vq) 633 669 { 634 - struct via_camera *cam = q->priv_data; 670 + struct via_camera *cam = vb2_get_drv_priv(vq); 671 + struct via_buffer *buf, *tmp; 635 672 636 - videobuf_dma_unmap(&cam->platdev->dev, videobuf_to_dma(vb)); 637 - videobuf_dma_free(videobuf_to_dma(vb)); 638 - vb->state = VIDEOBUF_NEEDS_INIT; 673 + pm_qos_remove_request(&cam->qos_request); 674 + viacam_stop_engine(cam); 675 + 676 + list_for_each_entry_safe(buf, tmp, &cam->buffer_queue, queue) { 677 + list_del(&buf->queue); 678 + vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_ERROR); 679 + } 639 680 } 640 681 641 - static const struct videobuf_queue_ops viacam_vb_ops = { 642 - .buf_setup = viacam_vb_buf_setup, 643 - .buf_prepare = viacam_vb_buf_prepare, 644 - .buf_queue = viacam_vb_buf_queue, 645 - .buf_release = viacam_vb_buf_release, 682 + static const struct vb2_ops viacam_vb2_ops = { 683 + .queue_setup = viacam_vb2_queue_setup, 684 + .buf_queue = viacam_vb2_queue, 685 + .buf_prepare = viacam_vb2_prepare, 686 + .start_streaming = viacam_vb2_start_streaming, 687 + .stop_streaming = viacam_vb2_stop_streaming, 688 + .wait_prepare = vb2_ops_wait_prepare, 689 + .wait_finish = vb2_ops_wait_finish, 646 690 }; 647 691 648 692 /* --------------------------------------------------------------------------*/ ··· 706 678 } 707 679 via_sensor_power_up(cam); 708 680 set_bit(CF_CONFIG_NEEDED, &cam->flags); 709 - /* 710 - * Hook into videobuf. Evidently this cannot fail. 711 - */ 712 - videobuf_queue_sg_init(&cam->vb_queue, &viacam_vb_ops, 713 - &cam->platdev->dev, &cam->viadev->reg_lock, 714 - V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 715 - sizeof(struct videobuf_buffer), cam, NULL); 716 681 } 717 - (cam->users)++; 718 682 out: 719 683 mutex_unlock(&cam->lock); 720 684 return ret; ··· 718 698 bool last_open; 719 699 720 700 mutex_lock(&cam->lock); 721 - (cam->users)--; 722 701 last_open = v4l2_fh_is_singular_file(filp); 723 - /* 724 - * If the "owner" is closing, shut down any ongoing 725 - * operations. 726 - */ 727 - if (filp == cam->owner) { 728 - videobuf_stop(&cam->vb_queue); 729 - /* 730 - * We don't hold the spinlock here, but, if release() 731 - * is being called by the owner, nobody else will 732 - * be changing the state. And an extra stop would 733 - * not hurt anyway. 734 - */ 735 - if (cam->opstate != S_IDLE) 736 - viacam_stop_engine(cam); 737 - cam->owner = NULL; 738 - } 702 + _vb2_fop_release(filp, NULL); 739 703 /* 740 704 * Last one out needs to turn out the lights. 741 705 */ 742 706 if (last_open) { 743 - videobuf_mmap_free(&cam->vb_queue); 744 707 via_sensor_power_down(cam); 745 708 viafb_release_dma(); 746 709 } 747 - v4l2_fh_release(filp); 748 710 mutex_unlock(&cam->lock); 749 711 return 0; 750 712 } 751 - 752 - /* 753 - * Read a frame from the device. 754 - */ 755 - static ssize_t viacam_read(struct file *filp, char __user *buffer, 756 - size_t len, loff_t *pos) 757 - { 758 - struct via_camera *cam = video_drvdata(filp); 759 - int ret; 760 - 761 - mutex_lock(&cam->lock); 762 - /* 763 - * Enforce the V4l2 "only one owner gets to read data" rule. 764 - */ 765 - if (cam->owner && cam->owner != filp) { 766 - ret = -EBUSY; 767 - goto out_unlock; 768 - } 769 - cam->owner = filp; 770 - /* 771 - * Do we need to configure the hardware? 772 - */ 773 - if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { 774 - ret = viacam_configure_sensor(cam); 775 - if (!ret) 776 - ret = viacam_config_controller(cam); 777 - if (ret) 778 - goto out_unlock; 779 - } 780 - /* 781 - * Fire up the capture engine, then have videobuf do 782 - * the heavy lifting. Someday it would be good to avoid 783 - * stopping and restarting the engine each time. 784 - */ 785 - INIT_LIST_HEAD(&cam->buffer_queue); 786 - viacam_start_engine(cam); 787 - ret = videobuf_read_stream(&cam->vb_queue, buffer, len, pos, 0, 788 - filp->f_flags & O_NONBLOCK); 789 - viacam_stop_engine(cam); 790 - /* videobuf_stop() ?? */ 791 - 792 - out_unlock: 793 - mutex_unlock(&cam->lock); 794 - return ret; 795 - } 796 - 797 - 798 - static __poll_t viacam_poll(struct file *filp, struct poll_table_struct *pt) 799 - { 800 - struct via_camera *cam = video_drvdata(filp); 801 - 802 - return v4l2_ctrl_poll(filp, pt) | videobuf_poll_stream(filp, &cam->vb_queue, pt); 803 - } 804 - 805 - 806 - static int viacam_mmap(struct file *filp, struct vm_area_struct *vma) 807 - { 808 - struct via_camera *cam = video_drvdata(filp); 809 - 810 - return videobuf_mmap_mapper(&cam->vb_queue, vma); 811 - } 812 - 813 - 814 713 815 714 static const struct v4l2_file_operations viacam_fops = { 816 715 .owner = THIS_MODULE, 817 716 .open = viacam_open, 818 717 .release = viacam_release, 819 - .read = viacam_read, 820 - .poll = viacam_poll, 821 - .mmap = viacam_mmap, 822 - .unlocked_ioctl = video_ioctl2, 718 + .read = vb2_fop_read, 719 + .poll = vb2_fop_poll, 720 + .mmap = vb2_fop_mmap, 721 + .unlocked_ioctl = video_ioctl2, 823 722 }; 824 723 825 724 /*----------------------------------------------------------------------------*/ ··· 865 926 { 866 927 struct via_camera *cam = video_drvdata(filp); 867 928 struct v4l2_format sfmt; 868 - int ret; 869 929 870 - mutex_lock(&cam->lock); 871 - ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); 872 - mutex_unlock(&cam->lock); 873 - return ret; 930 + return viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); 874 931 } 875 932 876 933 ··· 875 940 { 876 941 struct via_camera *cam = video_drvdata(filp); 877 942 878 - mutex_lock(&cam->lock); 879 943 fmt->fmt.pix = cam->user_format; 880 - mutex_unlock(&cam->lock); 881 944 return 0; 882 945 } 883 946 ··· 891 958 * Camera must be idle or we can't mess with the 892 959 * video setup. 893 960 */ 894 - mutex_lock(&cam->lock); 895 - if (cam->opstate != S_IDLE) { 896 - ret = -EBUSY; 897 - goto out; 898 - } 961 + if (cam->opstate != S_IDLE) 962 + return -EBUSY; 899 963 /* 900 964 * Let the sensor code look over and tweak the 901 965 * requested formatting. 902 966 */ 903 967 ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); 904 968 if (ret) 905 - goto out; 969 + return ret; 906 970 /* 907 971 * OK, let's commit to the new format. 908 972 */ ··· 909 979 ret = viacam_configure_sensor(cam); 910 980 if (!ret) 911 981 ret = viacam_config_controller(cam); 912 - out: 913 - mutex_unlock(&cam->lock); 914 982 return ret; 915 983 } 916 984 ··· 921 993 return 0; 922 994 } 923 995 924 - /* 925 - * Streaming operations - pure videobuf stuff. 926 - */ 927 - static int viacam_reqbufs(struct file *filp, void *priv, 928 - struct v4l2_requestbuffers *rb) 929 - { 930 - struct via_camera *cam = video_drvdata(filp); 931 - 932 - return videobuf_reqbufs(&cam->vb_queue, rb); 933 - } 934 - 935 - static int viacam_querybuf(struct file *filp, void *priv, 936 - struct v4l2_buffer *buf) 937 - { 938 - struct via_camera *cam = video_drvdata(filp); 939 - 940 - return videobuf_querybuf(&cam->vb_queue, buf); 941 - } 942 - 943 - static int viacam_qbuf(struct file *filp, void *priv, struct v4l2_buffer *buf) 944 - { 945 - struct via_camera *cam = video_drvdata(filp); 946 - 947 - return videobuf_qbuf(&cam->vb_queue, buf); 948 - } 949 - 950 - static int viacam_dqbuf(struct file *filp, void *priv, struct v4l2_buffer *buf) 951 - { 952 - struct via_camera *cam = video_drvdata(filp); 953 - 954 - return videobuf_dqbuf(&cam->vb_queue, buf, filp->f_flags & O_NONBLOCK); 955 - } 956 - 957 - static int viacam_streamon(struct file *filp, void *priv, enum v4l2_buf_type t) 958 - { 959 - struct via_camera *cam = video_drvdata(filp); 960 - int ret = 0; 961 - 962 - if (t != V4L2_BUF_TYPE_VIDEO_CAPTURE) 963 - return -EINVAL; 964 - 965 - mutex_lock(&cam->lock); 966 - if (cam->opstate != S_IDLE) { 967 - ret = -EBUSY; 968 - goto out; 969 - } 970 - /* 971 - * Enforce the V4l2 "only one owner gets to read data" rule. 972 - */ 973 - if (cam->owner && cam->owner != filp) { 974 - ret = -EBUSY; 975 - goto out; 976 - } 977 - cam->owner = filp; 978 - /* 979 - * Configure things if need be. 980 - */ 981 - if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { 982 - ret = viacam_configure_sensor(cam); 983 - if (ret) 984 - goto out; 985 - ret = viacam_config_controller(cam); 986 - if (ret) 987 - goto out; 988 - } 989 - /* 990 - * If the CPU goes into C3, the DMA transfer gets corrupted and 991 - * users start filing unsightly bug reports. Put in a "latency" 992 - * requirement which will keep the CPU out of the deeper sleep 993 - * states. 994 - */ 995 - pm_qos_add_request(&cam->qos_request, PM_QOS_CPU_DMA_LATENCY, 50); 996 - /* 997 - * Fire things up. 998 - */ 999 - INIT_LIST_HEAD(&cam->buffer_queue); 1000 - ret = videobuf_streamon(&cam->vb_queue); 1001 - if (!ret) 1002 - viacam_start_engine(cam); 1003 - out: 1004 - mutex_unlock(&cam->lock); 1005 - return ret; 1006 - } 1007 - 1008 - static int viacam_streamoff(struct file *filp, void *priv, enum v4l2_buf_type t) 1009 - { 1010 - struct via_camera *cam = video_drvdata(filp); 1011 - int ret; 1012 - 1013 - if (t != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1014 - return -EINVAL; 1015 - mutex_lock(&cam->lock); 1016 - if (cam->opstate != S_RUNNING) { 1017 - ret = -EINVAL; 1018 - goto out; 1019 - } 1020 - pm_qos_remove_request(&cam->qos_request); 1021 - viacam_stop_engine(cam); 1022 - /* 1023 - * Videobuf will recycle all of the outstanding buffers, but 1024 - * we should be sure we don't retain any references to 1025 - * any of them. 1026 - */ 1027 - ret = videobuf_streamoff(&cam->vb_queue); 1028 - INIT_LIST_HEAD(&cam->buffer_queue); 1029 - out: 1030 - mutex_unlock(&cam->lock); 1031 - return ret; 1032 - } 1033 - 1034 996 /* G/S_PARM */ 1035 997 1036 998 static int viacam_g_parm(struct file *filp, void *priv, 1037 999 struct v4l2_streamparm *parm) 1038 1000 { 1039 1001 struct via_camera *cam = video_drvdata(filp); 1040 - int ret; 1041 1002 1042 - mutex_lock(&cam->lock); 1043 - ret = v4l2_g_parm_cap(video_devdata(filp), cam->sensor, parm); 1044 - mutex_unlock(&cam->lock); 1045 - return ret; 1003 + return v4l2_g_parm_cap(video_devdata(filp), cam->sensor, parm); 1046 1004 } 1047 1005 1048 1006 static int viacam_s_parm(struct file *filp, void *priv, 1049 1007 struct v4l2_streamparm *parm) 1050 1008 { 1051 1009 struct via_camera *cam = video_drvdata(filp); 1052 - int ret; 1053 1010 1054 - mutex_lock(&cam->lock); 1055 - ret = v4l2_s_parm_cap(video_devdata(filp), cam->sensor, parm); 1056 - mutex_unlock(&cam->lock); 1057 - return ret; 1011 + return v4l2_s_parm_cap(video_devdata(filp), cam->sensor, parm); 1058 1012 } 1059 1013 1060 1014 static int viacam_enum_framesizes(struct file *filp, void *priv, ··· 982 1172 if (interval->width < QCIF_WIDTH || interval->width > VGA_WIDTH || 983 1173 interval->height < QCIF_HEIGHT || interval->height > VGA_HEIGHT) 984 1174 return -EINVAL; 985 - mutex_lock(&cam->lock); 986 1175 ret = sensor_call(cam, pad, enum_frame_interval, NULL, &fie); 987 - mutex_unlock(&cam->lock); 988 1176 if (ret) 989 1177 return ret; 990 1178 interval->type = V4L2_FRMIVAL_TYPE_DISCRETE; 991 1179 interval->discrete = fie.interval; 992 1180 return 0; 993 1181 } 994 - 995 - 996 1182 997 1183 static const struct v4l2_ioctl_ops viacam_ioctl_ops = { 998 1184 .vidioc_enum_input = viacam_enum_input, ··· 999 1193 .vidioc_g_fmt_vid_cap = viacam_g_fmt_vid_cap, 1000 1194 .vidioc_s_fmt_vid_cap = viacam_s_fmt_vid_cap, 1001 1195 .vidioc_querycap = viacam_querycap, 1002 - .vidioc_reqbufs = viacam_reqbufs, 1003 - .vidioc_querybuf = viacam_querybuf, 1004 - .vidioc_qbuf = viacam_qbuf, 1005 - .vidioc_dqbuf = viacam_dqbuf, 1006 - .vidioc_streamon = viacam_streamon, 1007 - .vidioc_streamoff = viacam_streamoff, 1196 + .vidioc_reqbufs = vb2_ioctl_reqbufs, 1197 + .vidioc_create_bufs = vb2_ioctl_create_bufs, 1198 + .vidioc_querybuf = vb2_ioctl_querybuf, 1199 + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, 1200 + .vidioc_qbuf = vb2_ioctl_qbuf, 1201 + .vidioc_dqbuf = vb2_ioctl_dqbuf, 1202 + .vidioc_expbuf = vb2_ioctl_expbuf, 1203 + .vidioc_streamon = vb2_ioctl_streamon, 1204 + .vidioc_streamoff = vb2_ioctl_streamoff, 1008 1205 .vidioc_g_parm = viacam_g_parm, 1009 1206 .vidioc_s_parm = viacam_s_parm, 1010 1207 .vidioc_enum_framesizes = viacam_enum_framesizes, ··· 1051 1242 /* 1052 1243 * Make sure the sensor's power state is correct 1053 1244 */ 1054 - if (cam->users > 0) 1245 + if (!list_empty(&cam->vdev.fh_list)) 1055 1246 via_sensor_power_up(cam); 1056 1247 else 1057 1248 via_sensor_power_down(cam); ··· 1136 1327 int ret; 1137 1328 struct i2c_adapter *sensor_adapter; 1138 1329 struct viafb_dev *viadev = pdev->dev.platform_data; 1330 + struct vb2_queue *vq; 1139 1331 struct i2c_board_info ov7670_info = { 1140 1332 .type = "ov7670", 1141 1333 .addr = 0x42 >> 1, ··· 1180 1370 via_cam_info = cam; 1181 1371 cam->platdev = pdev; 1182 1372 cam->viadev = viadev; 1183 - cam->users = 0; 1184 - cam->owner = NULL; 1185 1373 cam->opstate = S_IDLE; 1186 1374 cam->user_format = cam->sensor_format = viacam_def_pix_format; 1187 1375 mutex_init(&cam->lock); ··· 1240 1432 viacam_irq, IRQF_SHARED, "via-camera", cam); 1241 1433 if (ret) 1242 1434 goto out_power_down; 1435 + 1436 + vq = &cam->vq; 1437 + vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1438 + vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; 1439 + vq->drv_priv = cam; 1440 + vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1441 + vq->buf_struct_size = sizeof(struct via_buffer); 1442 + vq->dev = cam->v4l2_dev.dev; 1443 + 1444 + vq->ops = &viacam_vb2_ops; 1445 + vq->mem_ops = &vb2_dma_sg_memops; 1446 + vq->lock = &cam->lock; 1447 + 1448 + ret = vb2_queue_init(vq); 1243 1449 /* 1244 1450 * Tell V4l2 that we exist. 1245 1451 */ 1246 1452 cam->vdev = viacam_v4l_template; 1247 1453 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1454 + cam->vdev.lock = &cam->lock; 1455 + cam->vdev.queue = vq; 1248 1456 video_set_drvdata(&cam->vdev, cam); 1249 1457 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); 1250 1458 if (ret)