media: tegra: Tegra V4L2 camera
[linux-2.6.git] / drivers / media / video / v4l2-subdev.c
index bc763db..b7967c9 100644 (file)
@@ -75,20 +75,7 @@ static int subdev_open(struct file *file)
                return ret;
        }
 
-       ret = v4l2_fh_init(&subdev_fh->vfh, vdev);
-       if (ret)
-               goto err;
-
-       if (sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) {
-               ret = v4l2_event_init(&subdev_fh->vfh);
-               if (ret)
-                       goto err;
-
-               ret = v4l2_event_alloc(&subdev_fh->vfh, sd->nevents);
-               if (ret)
-                       goto err;
-       }
-
+       v4l2_fh_init(&subdev_fh->vfh, vdev);
        v4l2_fh_add(&subdev_fh->vfh);
        file->private_data = &subdev_fh->vfh;
 #if defined(CONFIG_MEDIA_CONTROLLER)
@@ -149,28 +136,31 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
        struct video_device *vdev = video_devdata(file);
        struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
        struct v4l2_fh *vfh = file->private_data;
+#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
+       struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);
+#endif
 
        switch (cmd) {
        case VIDIOC_QUERYCTRL:
-               return v4l2_subdev_queryctrl(sd, arg);
+               return v4l2_queryctrl(vfh->ctrl_handler, arg);
 
        case VIDIOC_QUERYMENU:
-               return v4l2_subdev_querymenu(sd, arg);
+               return v4l2_querymenu(vfh->ctrl_handler, arg);
 
        case VIDIOC_G_CTRL:
-               return v4l2_subdev_g_ctrl(sd, arg);
+               return v4l2_g_ctrl(vfh->ctrl_handler, arg);
 
        case VIDIOC_S_CTRL:
-               return v4l2_subdev_s_ctrl(sd, arg);
+               return v4l2_s_ctrl(vfh, vfh->ctrl_handler, arg);
 
        case VIDIOC_G_EXT_CTRLS:
-               return v4l2_subdev_g_ext_ctrls(sd, arg);
+               return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg);
 
        case VIDIOC_S_EXT_CTRLS:
-               return v4l2_subdev_s_ext_ctrls(sd, arg);
+               return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg);
 
        case VIDIOC_TRY_EXT_CTRLS:
-               return v4l2_subdev_try_ext_ctrls(sd, arg);
+               return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg);
 
        case VIDIOC_DQEVENT:
                if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
@@ -183,9 +173,97 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
        case VIDIOC_UNSUBSCRIBE_EVENT:
                return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
+#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
+       case VIDIOC_SUBDEV_G_FMT: {
+               struct v4l2_subdev_format *format = arg;
+
+               if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
+                   format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+                       return -EINVAL;
+
+               if (format->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh, format);
+       }
+
+       case VIDIOC_SUBDEV_S_FMT: {
+               struct v4l2_subdev_format *format = arg;
+
+               if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
+                   format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+                       return -EINVAL;
+
+               if (format->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh, format);
+       }
+
+       case VIDIOC_SUBDEV_G_CROP: {
+               struct v4l2_subdev_crop *crop = arg;
+
+               if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
+                   crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+                       return -EINVAL;
+
+               if (crop->pad >= sd->entity.num_pads)
+                       return -EINVAL;
 
+               return v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
+       }
+
+       case VIDIOC_SUBDEV_S_CROP: {
+               struct v4l2_subdev_crop *crop = arg;
+
+               if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
+                   crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+                       return -EINVAL;
+
+               if (crop->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
+       }
+
+       case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {
+               struct v4l2_subdev_mbus_code_enum *code = arg;
+
+               if (code->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh,
+                                       code);
+       }
+
+       case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: {
+               struct v4l2_subdev_frame_size_enum *fse = arg;
+
+               if (fse->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh,
+                                       fse);
+       }
+
+       case VIDIOC_SUBDEV_G_FRAME_INTERVAL:
+               return v4l2_subdev_call(sd, video, g_frame_interval, arg);
+
+       case VIDIOC_SUBDEV_S_FRAME_INTERVAL:
+               return v4l2_subdev_call(sd, video, s_frame_interval, arg);
+
+       case VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: {
+               struct v4l2_subdev_frame_interval_enum *fie = arg;
+
+               if (fie->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh,
+                                       fie);
+       }
+#endif
        default:
-               return -ENOIOCTLCMD;
+               return v4l2_subdev_call(sd, core, ioctl, cmd, arg);
        }
 
        return 0;
@@ -206,7 +284,7 @@ static unsigned int subdev_poll(struct file *file, poll_table *wait)
        if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
                return POLLERR;
 
-       poll_wait(file, &fh->events->wait, wait);
+       poll_wait(file, &fh->wait, wait);
 
        if (v4l2_event_pending(fh))
                return POLLPRI;