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