Merge tag 'mac80211-for-davem-2015-09-22' of git://git.kernel.org/pub/scm/linux/kerne...
[firefly-linux-kernel-4.4.55.git] / drivers / media / platform / fsl-viu.c
index ab8012c7635ee94d1ee27d9650ea8799a18ac3a3..ae8c6b35a3571114b55f9fd3bb47bd33affed4d1 100644 (file)
@@ -29,6 +29,8 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-ctrls.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-event.h>
 #include <media/videobuf-dma-contig.h>
 
 #define DRV_NAME               "fsl_viu"
@@ -53,7 +55,6 @@ static int info_level;
  * Basic structures
  */
 struct viu_fmt {
-       char  name[32];
        u32   fourcc;           /* v4l2 format id */
        u32   pixelformat;
        int   depth;
@@ -61,12 +62,10 @@ struct viu_fmt {
 
 static struct viu_fmt formats[] = {
        {
-               .name           = "RGB-16 (5/B-6/G-5/R)",
                .fourcc         = V4L2_PIX_FMT_RGB565,
                .pixelformat    = V4L2_PIX_FMT_RGB565,
                .depth          = 16,
        }, {
-               .name           = "RGB-32 (A-R-G-B)",
                .fourcc         = V4L2_PIX_FMT_RGB32,
                .pixelformat    = V4L2_PIX_FMT_RGB32,
                .depth          = 32,
@@ -154,6 +153,8 @@ struct viu_dev {
 };
 
 struct viu_fh {
+       /* must remain the first field of this struct */
+       struct v4l2_fh          fh;
        struct viu_dev          *dev;
 
        /* video capture */
@@ -577,10 +578,9 @@ static int vidioc_enum_fmt(struct file *file, void  *priv,
 {
        int index = f->index;
 
-       if (f->index > NUM_FORMATS)
+       if (f->index >= NUM_FORMATS)
                return -EINVAL;
 
-       strlcpy(f->description, formats[index].name, sizeof(f->description));
        f->pixelformat = formats[index].fourcc;
        return 0;
 }
@@ -597,6 +597,7 @@ static int vidioc_g_fmt_cap(struct file *file, void *priv,
        f->fmt.pix.bytesperline =
                        (f->fmt.pix.width * fh->fmt->depth) >> 3;
        f->fmt.pix.sizeimage    = fh->sizeimage;
+       f->fmt.pix.colorspace   = V4L2_COLORSPACE_SMPTE170M;
        return 0;
 }
 
@@ -604,7 +605,6 @@ static int vidioc_try_fmt_cap(struct file *file, void *priv,
                                        struct v4l2_format *f)
 {
        struct viu_fmt *fmt;
-       enum v4l2_field field;
        unsigned int maxw, maxh;
 
        fmt = format_by_fourcc(f->fmt.pix.pixelformat);
@@ -614,19 +614,10 @@ static int vidioc_try_fmt_cap(struct file *file, void *priv,
                return -EINVAL;
        }
 
-       field = f->fmt.pix.field;
-
-       if (field == V4L2_FIELD_ANY) {
-               field = V4L2_FIELD_INTERLACED;
-       } else if (field != V4L2_FIELD_INTERLACED) {
-               dprintk(1, "Field type invalid.\n");
-               return -EINVAL;
-       }
-
        maxw  = norm_maxw();
        maxh  = norm_maxh();
 
-       f->fmt.pix.field = field;
+       f->fmt.pix.field = V4L2_FIELD_INTERLACED;
        if (f->fmt.pix.height < 32)
                f->fmt.pix.height = 32;
        if (f->fmt.pix.height > maxh)
@@ -638,6 +629,8 @@ static int vidioc_try_fmt_cap(struct file *file, void *priv,
        f->fmt.pix.width &= ~0x03;
        f->fmt.pix.bytesperline =
                (f->fmt.pix.width * fmt->depth) >> 3;
+       f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
+       f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
 
        return 0;
 }
@@ -658,7 +651,6 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
        fh->sizeimage     = f->fmt.pix.sizeimage;
        fh->vb_vidq.field = f->fmt.pix.field;
        fh->type          = f->type;
-       dprintk(1, "set to pixelformat '%4.6s'\n", (char *)&fh->fmt->name);
        return 0;
 }
 
@@ -724,8 +716,8 @@ static int viu_setup_preview(struct viu_dev *dev, struct viu_fh *fh)
 {
        int bpp;
 
-       dprintk(1, "%s %dx%d %s\n", __func__,
-               fh->win.w.width, fh->win.w.height, dev->ovfmt->name);
+       dprintk(1, "%s %dx%d\n", __func__,
+               fh->win.w.width, fh->win.w.height);
 
        reg_val.status_cfg = 0;
 
@@ -962,7 +954,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 {
        struct viu_fh *fh = priv;
 
-       if (i > 1)
+       if (i)
                return -EINVAL;
 
        decoder_call(fh->dev, video, s_routing, i, 0, 0);
@@ -1207,6 +1199,7 @@ static int viu_open(struct file *file)
                return -ENOMEM;
        }
 
+       v4l2_fh_init(&fh->fh, vdev);
        file->private_data = fh;
        fh->dev = dev;
 
@@ -1242,6 +1235,7 @@ static int viu_open(struct file *file)
                                       fh->type, V4L2_FIELD_INTERLACED,
                                       sizeof(struct viu_buf), fh,
                                       &fh->dev->lock);
+       v4l2_fh_add(&fh->fh);
        mutex_unlock(&dev->lock);
        return 0;
 }
@@ -1274,13 +1268,17 @@ static unsigned int viu_poll(struct file *file, struct poll_table_struct *wait)
        struct viu_fh *fh = file->private_data;
        struct videobuf_queue *q = &fh->vb_vidq;
        struct viu_dev *dev = fh->dev;
-       unsigned int res;
+       unsigned long req_events = poll_requested_events(wait);
+       unsigned int res = v4l2_ctrl_poll(file, wait);
 
        if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
                return POLLERR;
 
+       if (!(req_events & (POLLIN | POLLRDNORM)))
+               return res;
+
        mutex_lock(&dev->lock);
-       res = videobuf_poll_stream(file, q, wait);
+       res |= videobuf_poll_stream(file, q, wait);
        mutex_unlock(&dev->lock);
        return res;
 }
@@ -1295,6 +1293,8 @@ static int viu_release(struct file *file)
        viu_stop_dma(dev);
        videobuf_stop(&fh->vb_vidq);
        videobuf_mmap_free(&fh->vb_vidq);
+       v4l2_fh_del(&fh->fh);
+       v4l2_fh_exit(&fh->fh);
        mutex_unlock(&dev->lock);
 
        kfree(fh);
@@ -1375,6 +1375,9 @@ static const struct v4l2_ioctl_ops viu_ioctl_ops = {
        .vidioc_s_input       = vidioc_s_input,
        .vidioc_streamon      = vidioc_streamon,
        .vidioc_streamoff     = vidioc_streamoff,
+       .vidioc_log_status    = v4l2_ctrl_log_status,
+       .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+       .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
 
 static struct video_device viu_template = {
@@ -1476,7 +1479,7 @@ static int viu_of_probe(struct platform_device *op)
                goto err_vdev;
        }
 
-       memcpy(vdev, &viu_template, sizeof(viu_template));
+       *vdev = viu_template;
 
        vdev->v4l2_dev = &viu_dev->v4l2_dev;