Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 1 | /* |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 2 | * V4L2 sub-device |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 3 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 4 | * Copyright (C) 2010 Nokia Corporation |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 5 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 6 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
| 7 | * Sakari Ailus <sakari.ailus@iki.fi> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 8 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 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. |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 12 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 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. |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 17 | * |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 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 |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 21 | */ |
| 22 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 23 | #include <linux/ioctl.h> |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 24 | #include <linux/slab.h> |
| 25 | #include <linux/types.h> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 26 | #include <linux/videodev2.h> |
Paul Gortmaker | 35a2463 | 2011-08-01 15:26:38 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 28 | |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 29 | #include <media/v4l2-ctrls.h> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 30 | #include <media/v4l2-device.h> |
| 31 | #include <media/v4l2-ioctl.h> |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 32 | #include <media/v4l2-fh.h> |
| 33 | #include <media/v4l2-event.h> |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 34 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 35 | static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd) |
| 36 | { |
| 37 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
| 38 | /* Allocate try format and crop in the same memory block */ |
| 39 | fh->try_fmt = kzalloc((sizeof(*fh->try_fmt) + sizeof(*fh->try_crop)) |
| 40 | * sd->entity.num_pads, GFP_KERNEL); |
| 41 | if (fh->try_fmt == NULL) |
| 42 | return -ENOMEM; |
| 43 | |
| 44 | fh->try_crop = (struct v4l2_rect *) |
| 45 | (fh->try_fmt + sd->entity.num_pads); |
| 46 | #endif |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static void subdev_fh_free(struct v4l2_subdev_fh *fh) |
| 51 | { |
| 52 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
| 53 | kfree(fh->try_fmt); |
| 54 | fh->try_fmt = NULL; |
| 55 | fh->try_crop = NULL; |
| 56 | #endif |
| 57 | } |
| 58 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 59 | static int subdev_open(struct file *file) |
| 60 | { |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 61 | struct video_device *vdev = video_devdata(file); |
| 62 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 63 | struct v4l2_subdev_fh *subdev_fh; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 64 | #if defined(CONFIG_MEDIA_CONTROLLER) |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 65 | struct media_entity *entity = NULL; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 66 | #endif |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 67 | int ret; |
| 68 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 69 | subdev_fh = kzalloc(sizeof(*subdev_fh), GFP_KERNEL); |
| 70 | if (subdev_fh == NULL) |
| 71 | return -ENOMEM; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 72 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 73 | ret = subdev_fh_init(subdev_fh, sd); |
| 74 | if (ret) { |
| 75 | kfree(subdev_fh); |
| 76 | return ret; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 77 | } |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 78 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 79 | v4l2_fh_init(&subdev_fh->vfh, vdev); |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 80 | v4l2_fh_add(&subdev_fh->vfh); |
| 81 | file->private_data = &subdev_fh->vfh; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 82 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 83 | if (sd->v4l2_dev->mdev) { |
| 84 | entity = media_entity_get(&sd->entity); |
| 85 | if (!entity) { |
| 86 | ret = -EBUSY; |
| 87 | goto err; |
| 88 | } |
| 89 | } |
| 90 | #endif |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 91 | |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 92 | if (sd->internal_ops && sd->internal_ops->open) { |
| 93 | ret = sd->internal_ops->open(sd, subdev_fh); |
| 94 | if (ret < 0) |
| 95 | goto err; |
| 96 | } |
| 97 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 98 | return 0; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 99 | |
| 100 | err: |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 101 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 102 | if (entity) |
| 103 | media_entity_put(entity); |
| 104 | #endif |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 105 | v4l2_fh_del(&subdev_fh->vfh); |
| 106 | v4l2_fh_exit(&subdev_fh->vfh); |
| 107 | subdev_fh_free(subdev_fh); |
| 108 | kfree(subdev_fh); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 109 | |
| 110 | return ret; |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static int subdev_close(struct file *file) |
| 114 | { |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 115 | struct video_device *vdev = video_devdata(file); |
| 116 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 117 | struct v4l2_fh *vfh = file->private_data; |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 118 | struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 119 | |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 120 | if (sd->internal_ops && sd->internal_ops->close) |
| 121 | sd->internal_ops->close(sd, subdev_fh); |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 122 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 123 | if (sd->v4l2_dev->mdev) |
| 124 | media_entity_put(&sd->entity); |
| 125 | #endif |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 126 | v4l2_fh_del(vfh); |
| 127 | v4l2_fh_exit(vfh); |
| 128 | subdev_fh_free(subdev_fh); |
| 129 | kfree(subdev_fh); |
| 130 | file->private_data = NULL; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 131 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
| 136 | { |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 137 | struct video_device *vdev = video_devdata(file); |
| 138 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 139 | struct v4l2_fh *vfh = file->private_data; |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 140 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
| 141 | struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); |
| 142 | #endif |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 143 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 144 | switch (cmd) { |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 145 | case VIDIOC_QUERYCTRL: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 146 | return v4l2_queryctrl(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 147 | |
| 148 | case VIDIOC_QUERYMENU: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 149 | return v4l2_querymenu(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 150 | |
| 151 | case VIDIOC_G_CTRL: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 152 | return v4l2_g_ctrl(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 153 | |
| 154 | case VIDIOC_S_CTRL: |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 155 | return v4l2_s_ctrl(vfh, vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 156 | |
| 157 | case VIDIOC_G_EXT_CTRLS: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 158 | return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 159 | |
| 160 | case VIDIOC_S_EXT_CTRLS: |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 161 | return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 162 | |
| 163 | case VIDIOC_TRY_EXT_CTRLS: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 164 | return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 165 | |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 166 | case VIDIOC_DQEVENT: |
| 167 | if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) |
| 168 | return -ENOIOCTLCMD; |
| 169 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 170 | return v4l2_event_dequeue(vfh, arg, file->f_flags & O_NONBLOCK); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 171 | |
| 172 | case VIDIOC_SUBSCRIBE_EVENT: |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 173 | return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 174 | |
| 175 | case VIDIOC_UNSUBSCRIBE_EVENT: |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 176 | return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg); |
Martin Hostettler | 69967a7 | 2011-09-19 02:04:56 -0300 | [diff] [blame] | 177 | |
| 178 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 179 | case VIDIOC_DBG_G_REGISTER: |
| 180 | { |
| 181 | struct v4l2_dbg_register *p = arg; |
| 182 | |
| 183 | if (!capable(CAP_SYS_ADMIN)) |
| 184 | return -EPERM; |
| 185 | return v4l2_subdev_call(sd, core, g_register, p); |
| 186 | } |
| 187 | case VIDIOC_DBG_S_REGISTER: |
| 188 | { |
| 189 | struct v4l2_dbg_register *p = arg; |
| 190 | |
| 191 | if (!capable(CAP_SYS_ADMIN)) |
| 192 | return -EPERM; |
| 193 | return v4l2_subdev_call(sd, core, s_register, p); |
| 194 | } |
| 195 | #endif |
Sylwester Nawrocki | bcd158d | 2011-10-01 11:13:59 -0300 | [diff] [blame] | 196 | |
Hans Verkuil | 42194e7 | 2012-02-02 08:26:20 -0300 | [diff] [blame^] | 197 | case VIDIOC_LOG_STATUS: { |
| 198 | int ret; |
| 199 | |
| 200 | pr_info("%s: ================= START STATUS =================\n", |
| 201 | sd->name); |
| 202 | ret = v4l2_subdev_call(sd, core, log_status); |
| 203 | pr_info("%s: ================== END STATUS ==================\n", |
| 204 | sd->name); |
| 205 | return ret; |
| 206 | } |
Sylwester Nawrocki | bcd158d | 2011-10-01 11:13:59 -0300 | [diff] [blame] | 207 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 208 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
| 209 | case VIDIOC_SUBDEV_G_FMT: { |
| 210 | struct v4l2_subdev_format *format = arg; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 211 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 212 | if (format->which != V4L2_SUBDEV_FORMAT_TRY && |
| 213 | format->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 214 | return -EINVAL; |
| 215 | |
| 216 | if (format->pad >= sd->entity.num_pads) |
| 217 | return -EINVAL; |
| 218 | |
| 219 | return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh, format); |
| 220 | } |
| 221 | |
| 222 | case VIDIOC_SUBDEV_S_FMT: { |
| 223 | struct v4l2_subdev_format *format = arg; |
| 224 | |
| 225 | if (format->which != V4L2_SUBDEV_FORMAT_TRY && |
| 226 | format->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 227 | return -EINVAL; |
| 228 | |
| 229 | if (format->pad >= sd->entity.num_pads) |
| 230 | return -EINVAL; |
| 231 | |
| 232 | return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh, format); |
| 233 | } |
| 234 | |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 235 | case VIDIOC_SUBDEV_G_CROP: { |
| 236 | struct v4l2_subdev_crop *crop = arg; |
| 237 | |
| 238 | if (crop->which != V4L2_SUBDEV_FORMAT_TRY && |
| 239 | crop->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 240 | return -EINVAL; |
| 241 | |
| 242 | if (crop->pad >= sd->entity.num_pads) |
| 243 | return -EINVAL; |
| 244 | |
| 245 | return v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop); |
| 246 | } |
| 247 | |
| 248 | case VIDIOC_SUBDEV_S_CROP: { |
| 249 | struct v4l2_subdev_crop *crop = arg; |
| 250 | |
| 251 | if (crop->which != V4L2_SUBDEV_FORMAT_TRY && |
| 252 | crop->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 253 | return -EINVAL; |
| 254 | |
| 255 | if (crop->pad >= sd->entity.num_pads) |
| 256 | return -EINVAL; |
| 257 | |
| 258 | return v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop); |
| 259 | } |
| 260 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 261 | case VIDIOC_SUBDEV_ENUM_MBUS_CODE: { |
| 262 | struct v4l2_subdev_mbus_code_enum *code = arg; |
| 263 | |
| 264 | if (code->pad >= sd->entity.num_pads) |
| 265 | return -EINVAL; |
| 266 | |
| 267 | return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh, |
| 268 | code); |
| 269 | } |
| 270 | |
| 271 | case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: { |
| 272 | struct v4l2_subdev_frame_size_enum *fse = arg; |
| 273 | |
| 274 | if (fse->pad >= sd->entity.num_pads) |
| 275 | return -EINVAL; |
| 276 | |
| 277 | return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh, |
| 278 | fse); |
| 279 | } |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 280 | |
| 281 | case VIDIOC_SUBDEV_G_FRAME_INTERVAL: |
| 282 | return v4l2_subdev_call(sd, video, g_frame_interval, arg); |
| 283 | |
| 284 | case VIDIOC_SUBDEV_S_FRAME_INTERVAL: |
| 285 | return v4l2_subdev_call(sd, video, s_frame_interval, arg); |
| 286 | |
| 287 | case VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: { |
| 288 | struct v4l2_subdev_frame_interval_enum *fie = arg; |
| 289 | |
| 290 | if (fie->pad >= sd->entity.num_pads) |
| 291 | return -EINVAL; |
| 292 | |
| 293 | return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh, |
| 294 | fie); |
| 295 | } |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 296 | #endif |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 297 | default: |
Laurent Pinchart | c30b46e | 2010-02-26 12:23:10 -0300 | [diff] [blame] | 298 | return v4l2_subdev_call(sd, core, ioctl, cmd, arg); |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static long subdev_ioctl(struct file *file, unsigned int cmd, |
| 305 | unsigned long arg) |
| 306 | { |
| 307 | return video_usercopy(file, cmd, arg, subdev_do_ioctl); |
| 308 | } |
| 309 | |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 310 | static unsigned int subdev_poll(struct file *file, poll_table *wait) |
| 311 | { |
| 312 | struct video_device *vdev = video_devdata(file); |
| 313 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
| 314 | struct v4l2_fh *fh = file->private_data; |
| 315 | |
| 316 | if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) |
| 317 | return POLLERR; |
| 318 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 319 | poll_wait(file, &fh->wait, wait); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 320 | |
| 321 | if (v4l2_event_pending(fh)) |
| 322 | return POLLPRI; |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 327 | const struct v4l2_file_operations v4l2_subdev_fops = { |
| 328 | .owner = THIS_MODULE, |
| 329 | .open = subdev_open, |
| 330 | .unlocked_ioctl = subdev_ioctl, |
| 331 | .release = subdev_close, |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 332 | .poll = subdev_poll, |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 333 | }; |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 334 | |
| 335 | void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops) |
| 336 | { |
| 337 | INIT_LIST_HEAD(&sd->list); |
| 338 | BUG_ON(!ops); |
| 339 | sd->ops = ops; |
| 340 | sd->v4l2_dev = NULL; |
| 341 | sd->flags = 0; |
| 342 | sd->name[0] = '\0'; |
| 343 | sd->grp_id = 0; |
| 344 | sd->dev_priv = NULL; |
| 345 | sd->host_priv = NULL; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 346 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 347 | sd->entity.name = sd->name; |
| 348 | sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV; |
| 349 | #endif |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 350 | } |
| 351 | EXPORT_SYMBOL(v4l2_subdev_init); |