4 * Copyright (C) 2010 Nokia Corporation
6 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/ioctl.h>
24 #include <linux/slab.h>
25 #include <linux/types.h>
26 #include <linux/videodev2.h>
28 #include <media/v4l2-ctrls.h>
29 #include <media/v4l2-device.h>
30 #include <media/v4l2-ioctl.h>
31 #include <media/v4l2-fh.h>
32 #include <media/v4l2-event.h>
34 static int subdev_open(struct file *file)
36 struct video_device *vdev = video_devdata(file);
37 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
41 if (sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS) {
42 vfh = kzalloc(sizeof(*vfh), GFP_KERNEL);
46 ret = v4l2_fh_init(vfh, vdev);
50 ret = v4l2_event_init(vfh);
54 ret = v4l2_event_alloc(vfh, sd->nevents);
59 file->private_data = vfh;
73 static int subdev_close(struct file *file)
75 struct v4l2_fh *vfh = file->private_data;
86 static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
88 struct video_device *vdev = video_devdata(file);
89 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
90 struct v4l2_fh *fh = file->private_data;
93 case VIDIOC_QUERYCTRL:
94 return v4l2_subdev_queryctrl(sd, arg);
96 case VIDIOC_QUERYMENU:
97 return v4l2_subdev_querymenu(sd, arg);
100 return v4l2_subdev_g_ctrl(sd, arg);
103 return v4l2_subdev_s_ctrl(sd, arg);
105 case VIDIOC_G_EXT_CTRLS:
106 return v4l2_subdev_g_ext_ctrls(sd, arg);
108 case VIDIOC_S_EXT_CTRLS:
109 return v4l2_subdev_s_ext_ctrls(sd, arg);
111 case VIDIOC_TRY_EXT_CTRLS:
112 return v4l2_subdev_try_ext_ctrls(sd, arg);
115 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
118 return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK);
120 case VIDIOC_SUBSCRIBE_EVENT:
121 return v4l2_subdev_call(sd, core, subscribe_event, fh, arg);
123 case VIDIOC_UNSUBSCRIBE_EVENT:
124 return v4l2_subdev_call(sd, core, unsubscribe_event, fh, arg);
133 static long subdev_ioctl(struct file *file, unsigned int cmd,
136 return video_usercopy(file, cmd, arg, subdev_do_ioctl);
139 static unsigned int subdev_poll(struct file *file, poll_table *wait)
141 struct video_device *vdev = video_devdata(file);
142 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
143 struct v4l2_fh *fh = file->private_data;
145 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
148 poll_wait(file, &fh->events->wait, wait);
150 if (v4l2_event_pending(fh))
156 const struct v4l2_file_operations v4l2_subdev_fops = {
157 .owner = THIS_MODULE,
159 .unlocked_ioctl = subdev_ioctl,
160 .release = subdev_close,
164 void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
166 INIT_LIST_HEAD(&sd->list);
174 sd->host_priv = NULL;
176 EXPORT_SYMBOL(v4l2_subdev_init);