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) |
Laurent Pinchart | 9b02cbb | 2015-04-24 20:06:31 -0300 | [diff] [blame^] | 38 | if (sd->entity.num_pads) { |
| 39 | fh->pad = v4l2_subdev_alloc_pad_config(sd); |
| 40 | if (fh->pad == NULL) |
| 41 | return -ENOMEM; |
| 42 | } |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 43 | #endif |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static void subdev_fh_free(struct v4l2_subdev_fh *fh) |
| 48 | { |
| 49 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
Laurent Pinchart | 9b02cbb | 2015-04-24 20:06:31 -0300 | [diff] [blame^] | 50 | v4l2_subdev_free_pad_config(fh->pad); |
Sakari Ailus | ae184cd | 2011-10-14 14:14:26 -0300 | [diff] [blame] | 51 | fh->pad = NULL; |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 52 | #endif |
| 53 | } |
| 54 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 55 | static int subdev_open(struct file *file) |
| 56 | { |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 57 | struct video_device *vdev = video_devdata(file); |
| 58 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 59 | struct v4l2_subdev_fh *subdev_fh; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 60 | #if defined(CONFIG_MEDIA_CONTROLLER) |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 61 | struct media_entity *entity = NULL; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 62 | #endif |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 63 | int ret; |
| 64 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 65 | subdev_fh = kzalloc(sizeof(*subdev_fh), GFP_KERNEL); |
| 66 | if (subdev_fh == NULL) |
| 67 | return -ENOMEM; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 68 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 69 | ret = subdev_fh_init(subdev_fh, sd); |
| 70 | if (ret) { |
| 71 | kfree(subdev_fh); |
| 72 | return ret; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 73 | } |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 74 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 75 | v4l2_fh_init(&subdev_fh->vfh, vdev); |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 76 | v4l2_fh_add(&subdev_fh->vfh); |
| 77 | file->private_data = &subdev_fh->vfh; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 78 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 79 | if (sd->v4l2_dev->mdev) { |
| 80 | entity = media_entity_get(&sd->entity); |
| 81 | if (!entity) { |
| 82 | ret = -EBUSY; |
| 83 | goto err; |
| 84 | } |
| 85 | } |
| 86 | #endif |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 87 | |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 88 | if (sd->internal_ops && sd->internal_ops->open) { |
| 89 | ret = sd->internal_ops->open(sd, subdev_fh); |
| 90 | if (ret < 0) |
| 91 | goto err; |
| 92 | } |
| 93 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 94 | return 0; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 95 | |
| 96 | err: |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 97 | #if defined(CONFIG_MEDIA_CONTROLLER) |
Markus Elfring | 5164d6a | 2015-02-03 11:27:38 -0300 | [diff] [blame] | 98 | media_entity_put(entity); |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 99 | #endif |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 100 | v4l2_fh_del(&subdev_fh->vfh); |
| 101 | v4l2_fh_exit(&subdev_fh->vfh); |
| 102 | subdev_fh_free(subdev_fh); |
| 103 | kfree(subdev_fh); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 104 | |
| 105 | return ret; |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static int subdev_close(struct file *file) |
| 109 | { |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 110 | struct video_device *vdev = video_devdata(file); |
| 111 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 112 | struct v4l2_fh *vfh = file->private_data; |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 113 | struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 114 | |
Laurent Pinchart | f0beea8 | 2010-08-01 19:05:09 -0300 | [diff] [blame] | 115 | if (sd->internal_ops && sd->internal_ops->close) |
| 116 | sd->internal_ops->close(sd, subdev_fh); |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 117 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 118 | if (sd->v4l2_dev->mdev) |
| 119 | media_entity_put(&sd->entity); |
| 120 | #endif |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 121 | v4l2_fh_del(vfh); |
| 122 | v4l2_fh_exit(vfh); |
| 123 | subdev_fh_free(subdev_fh); |
| 124 | kfree(subdev_fh); |
| 125 | file->private_data = NULL; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 126 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Mauro Carvalho Chehab | d352bcc9 | 2014-07-22 01:40:00 -0300 | [diff] [blame] | 130 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 131 | static int check_format(struct v4l2_subdev *sd, |
| 132 | struct v4l2_subdev_format *format) |
| 133 | { |
| 134 | if (format->which != V4L2_SUBDEV_FORMAT_TRY && |
| 135 | format->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | if (format->pad >= sd->entity.num_pads) |
| 139 | return -EINVAL; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static int check_crop(struct v4l2_subdev *sd, struct v4l2_subdev_crop *crop) |
| 145 | { |
| 146 | if (crop->which != V4L2_SUBDEV_FORMAT_TRY && |
| 147 | crop->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 148 | return -EINVAL; |
| 149 | |
| 150 | if (crop->pad >= sd->entity.num_pads) |
| 151 | return -EINVAL; |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int check_selection(struct v4l2_subdev *sd, |
| 157 | struct v4l2_subdev_selection *sel) |
| 158 | { |
| 159 | if (sel->which != V4L2_SUBDEV_FORMAT_TRY && |
| 160 | sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 161 | return -EINVAL; |
| 162 | |
| 163 | if (sel->pad >= sd->entity.num_pads) |
| 164 | return -EINVAL; |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int check_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) |
| 170 | { |
| 171 | if (edid->pad >= sd->entity.num_pads) |
| 172 | return -EINVAL; |
| 173 | |
| 174 | if (edid->blocks && edid->edid == NULL) |
| 175 | return -EINVAL; |
| 176 | |
| 177 | return 0; |
| 178 | } |
Mauro Carvalho Chehab | d352bcc9 | 2014-07-22 01:40:00 -0300 | [diff] [blame] | 179 | #endif |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 180 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 181 | static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
| 182 | { |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 183 | struct video_device *vdev = video_devdata(file); |
| 184 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 185 | struct v4l2_fh *vfh = file->private_data; |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 186 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
| 187 | struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 188 | int rval; |
Mauro Carvalho Chehab | d352bcc9 | 2014-07-22 01:40:00 -0300 | [diff] [blame] | 189 | #endif |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 190 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 191 | switch (cmd) { |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 192 | case VIDIOC_QUERYCTRL: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 193 | return v4l2_queryctrl(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 194 | |
Hans Verkuil | e6bee36 | 2014-06-10 04:22:06 -0300 | [diff] [blame] | 195 | case VIDIOC_QUERY_EXT_CTRL: |
| 196 | return v4l2_query_ext_ctrl(vfh->ctrl_handler, arg); |
| 197 | |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 198 | case VIDIOC_QUERYMENU: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 199 | return v4l2_querymenu(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 200 | |
| 201 | case VIDIOC_G_CTRL: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 202 | return v4l2_g_ctrl(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 203 | |
| 204 | case VIDIOC_S_CTRL: |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 205 | return v4l2_s_ctrl(vfh, vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 206 | |
| 207 | case VIDIOC_G_EXT_CTRLS: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 208 | return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 209 | |
| 210 | case VIDIOC_S_EXT_CTRLS: |
Hans Verkuil | ab892ba | 2011-06-07 06:47:18 -0300 | [diff] [blame] | 211 | return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 212 | |
| 213 | case VIDIOC_TRY_EXT_CTRLS: |
Hans Verkuil | 18d171b | 2011-05-25 08:52:13 -0300 | [diff] [blame] | 214 | return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg); |
Laurent Pinchart | ea8aa43 | 2009-12-09 08:39:54 -0300 | [diff] [blame] | 215 | |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 216 | case VIDIOC_DQEVENT: |
| 217 | if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) |
| 218 | return -ENOIOCTLCMD; |
| 219 | |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 220 | return v4l2_event_dequeue(vfh, arg, file->f_flags & O_NONBLOCK); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 221 | |
| 222 | case VIDIOC_SUBSCRIBE_EVENT: |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 223 | return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 224 | |
| 225 | case VIDIOC_UNSUBSCRIBE_EVENT: |
Stanimir Varbanov | 7cd5a16 | 2010-05-21 06:04:24 -0300 | [diff] [blame] | 226 | return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg); |
Martin Hostettler | 69967a7 | 2011-09-19 02:04:56 -0300 | [diff] [blame] | 227 | |
| 228 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 229 | case VIDIOC_DBG_G_REGISTER: |
| 230 | { |
| 231 | struct v4l2_dbg_register *p = arg; |
| 232 | |
| 233 | if (!capable(CAP_SYS_ADMIN)) |
| 234 | return -EPERM; |
| 235 | return v4l2_subdev_call(sd, core, g_register, p); |
| 236 | } |
| 237 | case VIDIOC_DBG_S_REGISTER: |
| 238 | { |
| 239 | struct v4l2_dbg_register *p = arg; |
| 240 | |
| 241 | if (!capable(CAP_SYS_ADMIN)) |
| 242 | return -EPERM; |
| 243 | return v4l2_subdev_call(sd, core, s_register, p); |
| 244 | } |
| 245 | #endif |
Sylwester Nawrocki | bcd158d | 2011-10-01 11:13:59 -0300 | [diff] [blame] | 246 | |
Hans Verkuil | 42194e7 | 2012-02-02 08:26:20 -0300 | [diff] [blame] | 247 | case VIDIOC_LOG_STATUS: { |
| 248 | int ret; |
| 249 | |
| 250 | pr_info("%s: ================= START STATUS =================\n", |
| 251 | sd->name); |
| 252 | ret = v4l2_subdev_call(sd, core, log_status); |
| 253 | pr_info("%s: ================== END STATUS ==================\n", |
| 254 | sd->name); |
| 255 | return ret; |
| 256 | } |
Sylwester Nawrocki | bcd158d | 2011-10-01 11:13:59 -0300 | [diff] [blame] | 257 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 258 | #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
| 259 | case VIDIOC_SUBDEV_G_FMT: { |
| 260 | struct v4l2_subdev_format *format = arg; |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 261 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 262 | rval = check_format(sd, format); |
| 263 | if (rval) |
| 264 | return rval; |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 265 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 266 | return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh->pad, format); |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | case VIDIOC_SUBDEV_S_FMT: { |
| 270 | struct v4l2_subdev_format *format = arg; |
| 271 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 272 | rval = check_format(sd, format); |
| 273 | if (rval) |
| 274 | return rval; |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 275 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 276 | return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh->pad, format); |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 277 | } |
| 278 | |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 279 | case VIDIOC_SUBDEV_G_CROP: { |
| 280 | struct v4l2_subdev_crop *crop = arg; |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 281 | struct v4l2_subdev_selection sel; |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 282 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 283 | rval = check_crop(sd, crop); |
| 284 | if (rval) |
| 285 | return rval; |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 286 | |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 287 | memset(&sel, 0, sizeof(sel)); |
| 288 | sel.which = crop->which; |
| 289 | sel.pad = crop->pad; |
Sakari Ailus | 5689b28 | 2012-05-18 09:31:18 -0300 | [diff] [blame] | 290 | sel.target = V4L2_SEL_TGT_CROP; |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 291 | |
| 292 | rval = v4l2_subdev_call( |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 293 | sd, pad, get_selection, subdev_fh->pad, &sel); |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 294 | |
| 295 | crop->rect = sel.r; |
| 296 | |
| 297 | return rval; |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | case VIDIOC_SUBDEV_S_CROP: { |
| 301 | struct v4l2_subdev_crop *crop = arg; |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 302 | struct v4l2_subdev_selection sel; |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 303 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 304 | rval = check_crop(sd, crop); |
| 305 | if (rval) |
| 306 | return rval; |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 307 | |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 308 | memset(&sel, 0, sizeof(sel)); |
| 309 | sel.which = crop->which; |
| 310 | sel.pad = crop->pad; |
Sakari Ailus | 5689b28 | 2012-05-18 09:31:18 -0300 | [diff] [blame] | 311 | sel.target = V4L2_SEL_TGT_CROP; |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 312 | sel.r = crop->rect; |
| 313 | |
| 314 | rval = v4l2_subdev_call( |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 315 | sd, pad, set_selection, subdev_fh->pad, &sel); |
Sakari Ailus | 5b9d770 | 2011-11-14 15:30:24 -0300 | [diff] [blame] | 316 | |
| 317 | crop->rect = sel.r; |
| 318 | |
| 319 | return rval; |
Antti Koskipaa | f6a5cb1 | 2010-06-23 05:03:42 -0300 | [diff] [blame] | 320 | } |
| 321 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 322 | case VIDIOC_SUBDEV_ENUM_MBUS_CODE: { |
| 323 | struct v4l2_subdev_mbus_code_enum *code = arg; |
| 324 | |
Hans Verkuil | 20058f9 | 2015-03-04 01:47:56 -0800 | [diff] [blame] | 325 | if (code->which != V4L2_SUBDEV_FORMAT_TRY && |
| 326 | code->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 327 | return -EINVAL; |
| 328 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 329 | if (code->pad >= sd->entity.num_pads) |
| 330 | return -EINVAL; |
| 331 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 332 | return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh->pad, |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 333 | code); |
| 334 | } |
| 335 | |
| 336 | case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: { |
| 337 | struct v4l2_subdev_frame_size_enum *fse = arg; |
| 338 | |
Hans Verkuil | 20058f9 | 2015-03-04 01:47:56 -0800 | [diff] [blame] | 339 | if (fse->which != V4L2_SUBDEV_FORMAT_TRY && |
| 340 | fse->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 341 | return -EINVAL; |
| 342 | |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 343 | if (fse->pad >= sd->entity.num_pads) |
| 344 | return -EINVAL; |
| 345 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 346 | return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh->pad, |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 347 | fse); |
| 348 | } |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 349 | |
Sakari Ailus | 743e183 | 2013-04-22 10:24:51 -0300 | [diff] [blame] | 350 | case VIDIOC_SUBDEV_G_FRAME_INTERVAL: { |
| 351 | struct v4l2_subdev_frame_interval *fi = arg; |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 352 | |
Sakari Ailus | 743e183 | 2013-04-22 10:24:51 -0300 | [diff] [blame] | 353 | if (fi->pad >= sd->entity.num_pads) |
| 354 | return -EINVAL; |
| 355 | |
| 356 | return v4l2_subdev_call(sd, video, g_frame_interval, arg); |
| 357 | } |
| 358 | |
| 359 | case VIDIOC_SUBDEV_S_FRAME_INTERVAL: { |
| 360 | struct v4l2_subdev_frame_interval *fi = arg; |
| 361 | |
| 362 | if (fi->pad >= sd->entity.num_pads) |
| 363 | return -EINVAL; |
| 364 | |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 365 | return v4l2_subdev_call(sd, video, s_frame_interval, arg); |
Sakari Ailus | 743e183 | 2013-04-22 10:24:51 -0300 | [diff] [blame] | 366 | } |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 367 | |
| 368 | case VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: { |
| 369 | struct v4l2_subdev_frame_interval_enum *fie = arg; |
| 370 | |
Hans Verkuil | 20058f9 | 2015-03-04 01:47:56 -0800 | [diff] [blame] | 371 | if (fie->which != V4L2_SUBDEV_FORMAT_TRY && |
| 372 | fie->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
| 373 | return -EINVAL; |
| 374 | |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 375 | if (fie->pad >= sd->entity.num_pads) |
| 376 | return -EINVAL; |
| 377 | |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 378 | return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh->pad, |
Laurent Pinchart | 35c3017 | 2010-05-05 11:38:35 -0300 | [diff] [blame] | 379 | fie); |
| 380 | } |
Sakari Ailus | ae184cd | 2011-10-14 14:14:26 -0300 | [diff] [blame] | 381 | |
| 382 | case VIDIOC_SUBDEV_G_SELECTION: { |
| 383 | struct v4l2_subdev_selection *sel = arg; |
| 384 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 385 | rval = check_selection(sd, sel); |
| 386 | if (rval) |
| 387 | return rval; |
Sakari Ailus | ae184cd | 2011-10-14 14:14:26 -0300 | [diff] [blame] | 388 | |
| 389 | return v4l2_subdev_call( |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 390 | sd, pad, get_selection, subdev_fh->pad, sel); |
Sakari Ailus | ae184cd | 2011-10-14 14:14:26 -0300 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | case VIDIOC_SUBDEV_S_SELECTION: { |
| 394 | struct v4l2_subdev_selection *sel = arg; |
| 395 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 396 | rval = check_selection(sd, sel); |
| 397 | if (rval) |
| 398 | return rval; |
Sakari Ailus | ae184cd | 2011-10-14 14:14:26 -0300 | [diff] [blame] | 399 | |
| 400 | return v4l2_subdev_call( |
Hans Verkuil | f723413 | 2015-03-04 01:47:54 -0800 | [diff] [blame] | 401 | sd, pad, set_selection, subdev_fh->pad, sel); |
Sakari Ailus | ae184cd | 2011-10-14 14:14:26 -0300 | [diff] [blame] | 402 | } |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 403 | |
Laurent Pinchart | f2e9084 | 2014-01-29 10:07:13 -0300 | [diff] [blame] | 404 | case VIDIOC_G_EDID: { |
| 405 | struct v4l2_subdev_edid *edid = arg; |
Hans Verkuil | ed45ce2 | 2012-08-10 06:07:12 -0300 | [diff] [blame] | 406 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 407 | rval = check_edid(sd, edid); |
| 408 | if (rval) |
| 409 | return rval; |
Laurent Pinchart | f2e9084 | 2014-01-29 10:07:13 -0300 | [diff] [blame] | 410 | |
| 411 | return v4l2_subdev_call(sd, pad, get_edid, edid); |
| 412 | } |
| 413 | |
| 414 | case VIDIOC_S_EDID: { |
| 415 | struct v4l2_subdev_edid *edid = arg; |
| 416 | |
Sakari Ailus | b225e39 | 2014-06-04 08:22:03 -0300 | [diff] [blame] | 417 | rval = check_edid(sd, edid); |
| 418 | if (rval) |
| 419 | return rval; |
Laurent Pinchart | f2e9084 | 2014-01-29 10:07:13 -0300 | [diff] [blame] | 420 | |
| 421 | return v4l2_subdev_call(sd, pad, set_edid, edid); |
| 422 | } |
Laurent Pinchart | 9cfd65e | 2014-01-29 10:07:13 -0300 | [diff] [blame] | 423 | |
| 424 | case VIDIOC_SUBDEV_DV_TIMINGS_CAP: { |
| 425 | struct v4l2_dv_timings_cap *cap = arg; |
| 426 | |
| 427 | if (cap->pad >= sd->entity.num_pads) |
| 428 | return -EINVAL; |
| 429 | |
| 430 | return v4l2_subdev_call(sd, pad, dv_timings_cap, cap); |
| 431 | } |
| 432 | |
| 433 | case VIDIOC_SUBDEV_ENUM_DV_TIMINGS: { |
| 434 | struct v4l2_enum_dv_timings *dvt = arg; |
| 435 | |
| 436 | if (dvt->pad >= sd->entity.num_pads) |
| 437 | return -EINVAL; |
| 438 | |
| 439 | return v4l2_subdev_call(sd, pad, enum_dv_timings, dvt); |
| 440 | } |
| 441 | |
| 442 | case VIDIOC_SUBDEV_QUERY_DV_TIMINGS: |
| 443 | return v4l2_subdev_call(sd, video, query_dv_timings, arg); |
| 444 | |
| 445 | case VIDIOC_SUBDEV_G_DV_TIMINGS: |
| 446 | return v4l2_subdev_call(sd, video, g_dv_timings, arg); |
| 447 | |
| 448 | case VIDIOC_SUBDEV_S_DV_TIMINGS: |
| 449 | return v4l2_subdev_call(sd, video, s_dv_timings, arg); |
Laurent Pinchart | 333c8b9 | 2010-03-15 20:26:04 -0300 | [diff] [blame] | 450 | #endif |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 451 | default: |
Laurent Pinchart | c30b46e | 2010-02-26 12:23:10 -0300 | [diff] [blame] | 452 | return v4l2_subdev_call(sd, core, ioctl, cmd, arg); |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static long subdev_ioctl(struct file *file, unsigned int cmd, |
| 459 | unsigned long arg) |
| 460 | { |
| 461 | return video_usercopy(file, cmd, arg, subdev_do_ioctl); |
| 462 | } |
| 463 | |
Hans Verkuil | ab58a30 | 2014-02-10 08:08:44 -0300 | [diff] [blame] | 464 | #ifdef CONFIG_COMPAT |
| 465 | static long subdev_compat_ioctl32(struct file *file, unsigned int cmd, |
| 466 | unsigned long arg) |
| 467 | { |
| 468 | struct video_device *vdev = video_devdata(file); |
| 469 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
| 470 | |
| 471 | return v4l2_subdev_call(sd, core, compat_ioctl32, cmd, arg); |
| 472 | } |
| 473 | #endif |
| 474 | |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 475 | static unsigned int subdev_poll(struct file *file, poll_table *wait) |
| 476 | { |
| 477 | struct video_device *vdev = video_devdata(file); |
| 478 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
| 479 | struct v4l2_fh *fh = file->private_data; |
| 480 | |
| 481 | if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) |
| 482 | return POLLERR; |
| 483 | |
Hans Verkuil | 523f46d | 2011-06-13 17:44:42 -0300 | [diff] [blame] | 484 | poll_wait(file, &fh->wait, wait); |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 485 | |
| 486 | if (v4l2_event_pending(fh)) |
| 487 | return POLLPRI; |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 492 | const struct v4l2_file_operations v4l2_subdev_fops = { |
| 493 | .owner = THIS_MODULE, |
| 494 | .open = subdev_open, |
| 495 | .unlocked_ioctl = subdev_ioctl, |
Hans Verkuil | ab58a30 | 2014-02-10 08:08:44 -0300 | [diff] [blame] | 496 | #ifdef CONFIG_COMPAT |
| 497 | .compat_ioctl32 = subdev_compat_ioctl32, |
| 498 | #endif |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 499 | .release = subdev_close, |
Sakari Ailus | 02adb1c | 2010-03-03 12:49:38 -0300 | [diff] [blame] | 500 | .poll = subdev_poll, |
Laurent Pinchart | 2096a5d | 2009-12-09 08:38:49 -0300 | [diff] [blame] | 501 | }; |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 502 | |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 503 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 504 | int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd, |
| 505 | struct media_link *link, |
| 506 | struct v4l2_subdev_format *source_fmt, |
| 507 | struct v4l2_subdev_format *sink_fmt) |
| 508 | { |
Laurent Pinchart | 24acf8b | 2014-05-19 11:36:23 -0300 | [diff] [blame] | 509 | /* The width, height and code must match. */ |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 510 | if (source_fmt->format.width != sink_fmt->format.width |
| 511 | || source_fmt->format.height != sink_fmt->format.height |
| 512 | || source_fmt->format.code != sink_fmt->format.code) |
| 513 | return -EINVAL; |
| 514 | |
Laurent Pinchart | 24acf8b | 2014-05-19 11:36:23 -0300 | [diff] [blame] | 515 | /* The field order must match, or the sink field order must be NONE |
| 516 | * to support interlaced hardware connected to bridges that support |
| 517 | * progressive formats only. |
| 518 | */ |
| 519 | if (source_fmt->format.field != sink_fmt->format.field && |
| 520 | sink_fmt->format.field != V4L2_FIELD_NONE) |
| 521 | return -EINVAL; |
| 522 | |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 523 | return 0; |
| 524 | } |
| 525 | EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_default); |
| 526 | |
| 527 | static int |
| 528 | v4l2_subdev_link_validate_get_format(struct media_pad *pad, |
| 529 | struct v4l2_subdev_format *fmt) |
| 530 | { |
Mauro Carvalho Chehab | 3efdf62 | 2015-05-07 22:12:32 -0300 | [diff] [blame] | 531 | if (is_media_entity_v4l2_subdev(pad->entity)) { |
Laurent Pinchart | 864a121 | 2012-10-20 17:47:22 -0300 | [diff] [blame] | 532 | struct v4l2_subdev *sd = |
| 533 | media_entity_to_v4l2_subdev(pad->entity); |
| 534 | |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 535 | fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE; |
| 536 | fmt->pad = pad->index; |
Laurent Pinchart | 864a121 | 2012-10-20 17:47:22 -0300 | [diff] [blame] | 537 | return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt); |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 538 | } |
Laurent Pinchart | 864a121 | 2012-10-20 17:47:22 -0300 | [diff] [blame] | 539 | |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 540 | WARN(pad->entity->function != MEDIA_ENT_F_IO_V4L, |
Laurent Pinchart | 864a121 | 2012-10-20 17:47:22 -0300 | [diff] [blame] | 541 | "Driver bug! Wrong media entity type 0x%08x, entity %s\n", |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame] | 542 | pad->entity->function, pad->entity->name); |
Laurent Pinchart | 864a121 | 2012-10-20 17:47:22 -0300 | [diff] [blame] | 543 | |
| 544 | return -EINVAL; |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | int v4l2_subdev_link_validate(struct media_link *link) |
| 548 | { |
| 549 | struct v4l2_subdev *sink; |
| 550 | struct v4l2_subdev_format sink_fmt, source_fmt; |
| 551 | int rval; |
| 552 | |
| 553 | rval = v4l2_subdev_link_validate_get_format( |
| 554 | link->source, &source_fmt); |
| 555 | if (rval < 0) |
| 556 | return 0; |
| 557 | |
| 558 | rval = v4l2_subdev_link_validate_get_format( |
| 559 | link->sink, &sink_fmt); |
| 560 | if (rval < 0) |
| 561 | return 0; |
| 562 | |
| 563 | sink = media_entity_to_v4l2_subdev(link->sink->entity); |
| 564 | |
| 565 | rval = v4l2_subdev_call(sink, pad, link_validate, link, |
| 566 | &source_fmt, &sink_fmt); |
| 567 | if (rval != -ENOIOCTLCMD) |
| 568 | return rval; |
| 569 | |
| 570 | return v4l2_subdev_link_validate_default( |
| 571 | sink, link, &source_fmt, &sink_fmt); |
| 572 | } |
| 573 | EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate); |
Laurent Pinchart | 9b02cbb | 2015-04-24 20:06:31 -0300 | [diff] [blame^] | 574 | |
| 575 | struct v4l2_subdev_pad_config * |
| 576 | v4l2_subdev_alloc_pad_config(struct v4l2_subdev *sd) |
| 577 | { |
| 578 | struct v4l2_subdev_pad_config *cfg; |
| 579 | int ret; |
| 580 | |
| 581 | if (!sd->entity.num_pads) |
| 582 | return NULL; |
| 583 | |
| 584 | cfg = kcalloc(sd->entity.num_pads, sizeof(*cfg), GFP_KERNEL); |
| 585 | if (!cfg) |
| 586 | return NULL; |
| 587 | |
| 588 | ret = v4l2_subdev_call(sd, pad, init_cfg, cfg); |
| 589 | if (ret < 0 && ret != -ENOIOCTLCMD) { |
| 590 | kfree(cfg); |
| 591 | return NULL; |
| 592 | } |
| 593 | |
| 594 | return cfg; |
| 595 | } |
| 596 | EXPORT_SYMBOL_GPL(v4l2_subdev_alloc_pad_config); |
| 597 | |
| 598 | void v4l2_subdev_free_pad_config(struct v4l2_subdev_pad_config *cfg) |
| 599 | { |
| 600 | kfree(cfg); |
| 601 | } |
| 602 | EXPORT_SYMBOL_GPL(v4l2_subdev_free_pad_config); |
Sakari Ailus | 8227c92 | 2011-10-10 17:01:25 -0300 | [diff] [blame] | 603 | #endif /* CONFIG_MEDIA_CONTROLLER */ |
| 604 | |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 605 | void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops) |
| 606 | { |
| 607 | INIT_LIST_HEAD(&sd->list); |
| 608 | BUG_ON(!ops); |
| 609 | sd->ops = ops; |
| 610 | sd->v4l2_dev = NULL; |
| 611 | sd->flags = 0; |
| 612 | sd->name[0] = '\0'; |
| 613 | sd->grp_id = 0; |
| 614 | sd->dev_priv = NULL; |
| 615 | sd->host_priv = NULL; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 616 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 617 | sd->entity.name = sd->name; |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 618 | sd->entity.obj_type = MEDIA_ENTITY_TYPE_V4L2_SUBDEV; |
Mauro Carvalho Chehab | 4ca72ef | 2015-12-10 17:25:41 -0200 | [diff] [blame] | 619 | sd->entity.function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN; |
Laurent Pinchart | 61f5db5 | 2009-12-09 08:40:08 -0300 | [diff] [blame] | 620 | #endif |
Laurent Pinchart | 3dd5ee0 | 2009-12-09 08:38:52 -0300 | [diff] [blame] | 621 | } |
| 622 | EXPORT_SYMBOL(v4l2_subdev_init); |
Lars-Peter Clausen | 8ae5640 | 2015-06-24 13:50:29 -0300 | [diff] [blame] | 623 | |
| 624 | /** |
| 625 | * v4l2_subdev_notify_event() - Delivers event notification for subdevice |
| 626 | * @sd: The subdev for which to deliver the event |
| 627 | * @ev: The event to deliver |
| 628 | * |
| 629 | * Will deliver the specified event to all userspace event listeners which are |
| 630 | * subscribed to the v42l subdev event queue as well as to the bridge driver |
| 631 | * using the notify callback. The notification type for the notify callback |
| 632 | * will be V4L2_DEVICE_NOTIFY_EVENT. |
| 633 | */ |
| 634 | void v4l2_subdev_notify_event(struct v4l2_subdev *sd, |
| 635 | const struct v4l2_event *ev) |
| 636 | { |
| 637 | v4l2_event_queue(sd->devnode, ev); |
| 638 | v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, (void *)ev); |
| 639 | } |
| 640 | EXPORT_SYMBOL_GPL(v4l2_subdev_notify_event); |