Signed-off-by: Hans Verkuil <[email protected]>
---
 drivers/media/video/vivi.c |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 21d8f6a..8790e03 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -32,6 +32,7 @@
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
+#include <media/v4l2-event.h>
 #include <media/v4l2-common.h>
 
 #define VIVI_MODULE_NAME "vivi"
@@ -983,6 +984,14 @@ static int vidioc_s_input(struct file *file, void *priv, 
unsigned int i)
        return 0;
 }
 
+static int vidioc_subscribe_event(struct v4l2_fh *fh,
+                               struct v4l2_event_subscription *sub)
+{
+       if (sub->type != V4L2_EVENT_CTRL_CH_VALUE)
+               return -EINVAL;
+       return v4l2_event_subscribe(fh, sub);
+}
+
 /* --- controls ---------------------------------------------- */
 
 static int vivi_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -998,6 +1007,25 @@ static int vivi_s_ctrl(struct v4l2_ctrl *ctrl)
        File operations for the device
    ------------------------------------------------------------------*/
 
+static int vivi_open(struct file *filp)
+{
+       int ret = v4l2_fh_open(filp);
+       struct v4l2_fh *fh;
+
+       if (ret)
+               return ret;
+       fh = filp->private_data;
+       ret = v4l2_event_init(fh);
+       if (ret)
+               goto rel_fh;
+       ret = v4l2_event_alloc(fh, 10);
+       if (!ret)
+               return ret;
+rel_fh:
+       v4l2_fh_release(filp);
+       return ret;
+}
+
 static ssize_t
 vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
 {
@@ -1012,10 +1040,17 @@ static unsigned int
 vivi_poll(struct file *file, struct poll_table_struct *wait)
 {
        struct vivi_dev *dev = video_drvdata(file);
+       struct v4l2_fh *fh = file->private_data;
        struct vb2_queue *q = &dev->vb_vidq;
+       unsigned int res;
 
        dprintk(dev, 1, "%s\n", __func__);
-       return vb2_poll(q, file, wait);
+       res = vb2_poll(q, file, wait);
+       if (v4l2_event_pending(fh))
+               res |= POLLPRI;
+       else
+               poll_wait(file, &fh->events->wait, wait);
+       return res;
 }
 
 static int vivi_close(struct file *file)
@@ -1132,7 +1167,7 @@ static const struct v4l2_ctrl_config vivi_ctrl_bitmask = {
 
 static const struct v4l2_file_operations vivi_fops = {
        .owner          = THIS_MODULE,
-       .open           = v4l2_fh_open,
+       .open           = vivi_open,
        .release        = vivi_close,
        .read           = vivi_read,
        .poll           = vivi_poll,
@@ -1156,6 +1191,8 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
        .vidioc_s_input       = vidioc_s_input,
        .vidioc_streamon      = vidioc_streamon,
        .vidioc_streamoff     = vidioc_streamoff,
+       .vidioc_subscribe_event = vidioc_subscribe_event,
+       .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
 
 static struct video_device vivi_template = {
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to