[media] saa7146: support control events and priority handling
authorHans Verkuil <hans.verkuil@cisco.com>
Tue, 1 May 2012 15:04:52 +0000 (12:04 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 14 May 2012 18:00:03 +0000 (15:00 -0300)
Use v4l2_fh which gives you control events and priority handling for free.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/common/saa7146_fops.c
drivers/media/common/saa7146_video.c
include/media/saa7146_vv.h

index 66f6e79dd97bc3cc508c1fd6ad72a1faa518d897..dfb396568ab691a325bac003bad516fa03b02e5b 100644 (file)
@@ -198,7 +198,6 @@ static int fops_open(struct file *file)
        struct saa7146_dev *dev = video_drvdata(file);
        struct saa7146_fh *fh = NULL;
        int result = 0;
-
        enum v4l2_buf_type type;
 
        DEB_EE("file:%p, dev:%s\n", file, video_device_node_name(vdev));
@@ -227,7 +226,9 @@ static int fops_open(struct file *file)
                goto out;
        }
 
-       file->private_data = fh;
+       v4l2_fh_init(&fh->fh, vdev);
+
+       file->private_data = &fh->fh;
        fh->dev = dev;
 
        if (vdev->vfl_type == VFL_TYPE_VBI) {
@@ -251,6 +252,7 @@ static int fops_open(struct file *file)
        }
 
        result = 0;
+       v4l2_fh_add(&fh->fh);
 out:
        if (fh && result != 0) {
                kfree(fh);
@@ -280,6 +282,8 @@ static int fops_release(struct file *file)
                saa7146_video_uops.release(dev,file);
        }
 
+       v4l2_fh_del(&fh->fh);
+       v4l2_fh_exit(&fh->fh);
        module_put(dev->ext->module);
        file->private_data = NULL;
        kfree(fh);
@@ -322,12 +326,13 @@ static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
        struct saa7146_fh *fh = file->private_data;
        struct videobuf_buffer *buf = NULL;
        struct videobuf_queue *q;
+       unsigned int res = v4l2_ctrl_poll(file, wait);
 
        DEB_EE("file:%p, poll:%p\n", file, wait);
 
        if (vdev->vfl_type == VFL_TYPE_VBI) {
                if( 0 == fh->vbi_q.streaming )
-                       return videobuf_poll_stream(file, &fh->vbi_q, wait);
+                       return res | videobuf_poll_stream(file, &fh->vbi_q, wait);
                q = &fh->vbi_q;
        } else {
                DEB_D("using video queue\n");
@@ -339,17 +344,17 @@ static unsigned int fops_poll(struct file *file, struct poll_table_struct *wait)
 
        if (!buf) {
                DEB_D("buf == NULL!\n");
-               return POLLERR;
+               return res | POLLERR;
        }
 
        poll_wait(file, &buf->done, wait);
        if (buf->state == VIDEOBUF_DONE || buf->state == VIDEOBUF_ERROR) {
                DEB_D("poll succeeded!\n");
-               return POLLIN|POLLRDNORM;
+               return res | POLLIN | POLLRDNORM;
        }
 
        DEB_D("nothing to poll for, buf->state:%d\n", buf->state);
-       return 0;
+       return res;
 }
 
 static ssize_t fops_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
@@ -583,6 +588,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
        vfd->lock = &dev->v4l2_lock;
        vfd->v4l2_dev = &dev->v4l2_dev;
        vfd->tvnorms = 0;
+       set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
        for (i = 0; i < dev->ext_vv_data->num_stds; i++)
                vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
        strlcpy(vfd->name, name, sizeof(vfd->name));
index 850799051bef7bf41cef5c749d6bf2a4120cc1fc..4ca9a2561513878d2c9e6a5d7d27b031be57ffd6 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <media/saa7146_vv.h>
 #include <media/v4l2-chip-ident.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-ctrls.h>
 #include <linux/module.h>
 
 static int max_memory = 32;
@@ -1021,6 +1023,8 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
        .vidioc_streamon             = vidioc_streamon,
        .vidioc_streamoff            = vidioc_streamoff,
        .vidioc_g_parm               = vidioc_g_parm,
+       .vidioc_subscribe_event      = v4l2_ctrl_subscribe_event,
+       .vidioc_unsubscribe_event    = v4l2_event_unsubscribe,
 };
 
 /*********************************************************************************/
index 2cc32c51417342e732e5124a6aa4dc0977007d52..2bbdf3046be63bf7156818a357927b9b1d36aa94 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
+#include <media/v4l2-fh.h>
 #include <media/saa7146.h>
 #include <media/videobuf-dma-sg.h>
 
@@ -84,6 +85,8 @@ struct saa7146_overlay {
 
 /* per open data */
 struct saa7146_fh {
+       /* Must be the first field! */
+       struct v4l2_fh          fh;
        struct saa7146_dev      *dev;
 
        /* video capture */