| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * V4L2 sub-device |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
|---|
| 7 | 8 | * Sakari Ailus <sakari.ailus@iki.fi> |
|---|
| 8 | | - * |
|---|
| 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. |
|---|
| 12 | | - * |
|---|
| 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. |
|---|
| 17 | 9 | */ |
|---|
| 18 | 10 | |
|---|
| 19 | 11 | #include <linux/ioctl.h> |
|---|
| 20 | 12 | #include <linux/mm.h> |
|---|
| 13 | +#include <linux/module.h> |
|---|
| 21 | 14 | #include <linux/slab.h> |
|---|
| 22 | 15 | #include <linux/types.h> |
|---|
| 23 | 16 | #include <linux/videodev2.h> |
|---|
| 24 | 17 | #include <linux/export.h> |
|---|
| 18 | +#include <linux/version.h> |
|---|
| 25 | 19 | |
|---|
| 26 | 20 | #include <media/v4l2-ctrls.h> |
|---|
| 27 | 21 | #include <media/v4l2-device.h> |
|---|
| 28 | 22 | #include <media/v4l2-ioctl.h> |
|---|
| 29 | 23 | #include <media/v4l2-fh.h> |
|---|
| 30 | 24 | #include <media/v4l2-event.h> |
|---|
| 25 | +#ifndef __GENKSYMS__ |
|---|
| 26 | +#include <trace/hooks/v4l2core.h> |
|---|
| 27 | +#endif |
|---|
| 31 | 28 | |
|---|
| 29 | +#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 32 | 30 | static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd) |
|---|
| 33 | 31 | { |
|---|
| 34 | | -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 35 | 32 | if (sd->entity.num_pads) { |
|---|
| 36 | 33 | fh->pad = v4l2_subdev_alloc_pad_config(sd); |
|---|
| 37 | 34 | if (fh->pad == NULL) |
|---|
| 38 | 35 | return -ENOMEM; |
|---|
| 39 | 36 | } |
|---|
| 40 | | -#endif |
|---|
| 37 | + |
|---|
| 41 | 38 | return 0; |
|---|
| 42 | 39 | } |
|---|
| 43 | 40 | |
|---|
| 44 | 41 | static void subdev_fh_free(struct v4l2_subdev_fh *fh) |
|---|
| 45 | 42 | { |
|---|
| 46 | | -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 47 | 43 | v4l2_subdev_free_pad_config(fh->pad); |
|---|
| 48 | 44 | fh->pad = NULL; |
|---|
| 49 | | -#endif |
|---|
| 50 | 45 | } |
|---|
| 51 | 46 | |
|---|
| 52 | 47 | static int subdev_open(struct file *file) |
|---|
| .. | .. |
|---|
| 54 | 49 | struct video_device *vdev = video_devdata(file); |
|---|
| 55 | 50 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
|---|
| 56 | 51 | struct v4l2_subdev_fh *subdev_fh; |
|---|
| 57 | | -#if defined(CONFIG_MEDIA_CONTROLLER) |
|---|
| 58 | | - struct media_entity *entity = NULL; |
|---|
| 59 | | -#endif |
|---|
| 60 | 52 | int ret; |
|---|
| 61 | 53 | |
|---|
| 62 | 54 | subdev_fh = kzalloc(sizeof(*subdev_fh), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 73 | 65 | v4l2_fh_add(&subdev_fh->vfh); |
|---|
| 74 | 66 | file->private_data = &subdev_fh->vfh; |
|---|
| 75 | 67 | #if defined(CONFIG_MEDIA_CONTROLLER) |
|---|
| 76 | | - if (sd->v4l2_dev->mdev) { |
|---|
| 77 | | - entity = media_entity_get(&sd->entity); |
|---|
| 78 | | - if (!entity) { |
|---|
| 68 | + if (sd->v4l2_dev->mdev && sd->entity.graph_obj.mdev->dev) { |
|---|
| 69 | + struct module *owner; |
|---|
| 70 | + |
|---|
| 71 | + owner = sd->entity.graph_obj.mdev->dev->driver->owner; |
|---|
| 72 | + if (!try_module_get(owner)) { |
|---|
| 79 | 73 | ret = -EBUSY; |
|---|
| 80 | 74 | goto err; |
|---|
| 81 | 75 | } |
|---|
| 76 | + subdev_fh->owner = owner; |
|---|
| 82 | 77 | } |
|---|
| 83 | 78 | #endif |
|---|
| 84 | 79 | |
|---|
| .. | .. |
|---|
| 91 | 86 | return 0; |
|---|
| 92 | 87 | |
|---|
| 93 | 88 | err: |
|---|
| 94 | | -#if defined(CONFIG_MEDIA_CONTROLLER) |
|---|
| 95 | | - media_entity_put(entity); |
|---|
| 96 | | -#endif |
|---|
| 89 | + module_put(subdev_fh->owner); |
|---|
| 97 | 90 | v4l2_fh_del(&subdev_fh->vfh); |
|---|
| 98 | 91 | v4l2_fh_exit(&subdev_fh->vfh); |
|---|
| 99 | 92 | subdev_fh_free(subdev_fh); |
|---|
| .. | .. |
|---|
| 111 | 104 | |
|---|
| 112 | 105 | if (sd->internal_ops && sd->internal_ops->close) |
|---|
| 113 | 106 | sd->internal_ops->close(sd, subdev_fh); |
|---|
| 114 | | -#if defined(CONFIG_MEDIA_CONTROLLER) |
|---|
| 115 | | - if (sd->v4l2_dev->mdev) |
|---|
| 116 | | - media_entity_put(&sd->entity); |
|---|
| 117 | | -#endif |
|---|
| 107 | + module_put(subdev_fh->owner); |
|---|
| 118 | 108 | v4l2_fh_del(vfh); |
|---|
| 119 | 109 | v4l2_fh_exit(vfh); |
|---|
| 120 | 110 | subdev_fh_free(subdev_fh); |
|---|
| .. | .. |
|---|
| 123 | 113 | |
|---|
| 124 | 114 | return 0; |
|---|
| 125 | 115 | } |
|---|
| 116 | +#else /* CONFIG_VIDEO_V4L2_SUBDEV_API */ |
|---|
| 117 | +static int subdev_open(struct file *file) |
|---|
| 118 | +{ |
|---|
| 119 | + return -ENODEV; |
|---|
| 120 | +} |
|---|
| 126 | 121 | |
|---|
| 127 | | -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 128 | | -static int check_format(struct v4l2_subdev *sd, |
|---|
| 122 | +static int subdev_close(struct file *file) |
|---|
| 123 | +{ |
|---|
| 124 | + return -ENODEV; |
|---|
| 125 | +} |
|---|
| 126 | +#endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */ |
|---|
| 127 | + |
|---|
| 128 | +static inline int check_which(u32 which) |
|---|
| 129 | +{ |
|---|
| 130 | + if (which != V4L2_SUBDEV_FORMAT_TRY && |
|---|
| 131 | + which != V4L2_SUBDEV_FORMAT_ACTIVE) |
|---|
| 132 | + return -EINVAL; |
|---|
| 133 | + |
|---|
| 134 | + return 0; |
|---|
| 135 | +} |
|---|
| 136 | + |
|---|
| 137 | +static inline int check_pad(struct v4l2_subdev *sd, u32 pad) |
|---|
| 138 | +{ |
|---|
| 139 | +#if defined(CONFIG_MEDIA_CONTROLLER) |
|---|
| 140 | + if (sd->entity.num_pads) { |
|---|
| 141 | + if (pad >= sd->entity.num_pads) |
|---|
| 142 | + return -EINVAL; |
|---|
| 143 | + return 0; |
|---|
| 144 | + } |
|---|
| 145 | +#endif |
|---|
| 146 | + /* allow pad 0 on subdevices not registered as media entities */ |
|---|
| 147 | + if (pad > 0) |
|---|
| 148 | + return -EINVAL; |
|---|
| 149 | + return 0; |
|---|
| 150 | +} |
|---|
| 151 | + |
|---|
| 152 | +static int check_cfg(u32 which, struct v4l2_subdev_pad_config *cfg) |
|---|
| 153 | +{ |
|---|
| 154 | + if (which == V4L2_SUBDEV_FORMAT_TRY && !cfg) |
|---|
| 155 | + return -EINVAL; |
|---|
| 156 | + |
|---|
| 157 | + return 0; |
|---|
| 158 | +} |
|---|
| 159 | + |
|---|
| 160 | +static inline int check_format(struct v4l2_subdev *sd, |
|---|
| 161 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 162 | + struct v4l2_subdev_format *format) |
|---|
| 163 | +{ |
|---|
| 164 | + if (!format) |
|---|
| 165 | + return -EINVAL; |
|---|
| 166 | + |
|---|
| 167 | + return check_which(format->which) ? : check_pad(sd, format->pad) ? : |
|---|
| 168 | + check_cfg(format->which, cfg); |
|---|
| 169 | +} |
|---|
| 170 | + |
|---|
| 171 | +static int call_get_fmt(struct v4l2_subdev *sd, |
|---|
| 172 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 129 | 173 | struct v4l2_subdev_format *format) |
|---|
| 130 | 174 | { |
|---|
| 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; |
|---|
| 175 | + return check_format(sd, cfg, format) ? : |
|---|
| 176 | + sd->ops->pad->get_fmt(sd, cfg, format); |
|---|
| 139 | 177 | } |
|---|
| 140 | 178 | |
|---|
| 141 | | -static int check_crop(struct v4l2_subdev *sd, struct v4l2_subdev_crop *crop) |
|---|
| 179 | +static int call_set_fmt(struct v4l2_subdev *sd, |
|---|
| 180 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 181 | + struct v4l2_subdev_format *format) |
|---|
| 142 | 182 | { |
|---|
| 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; |
|---|
| 183 | + return check_format(sd, cfg, format) ? : |
|---|
| 184 | + sd->ops->pad->set_fmt(sd, cfg, format); |
|---|
| 151 | 185 | } |
|---|
| 152 | 186 | |
|---|
| 153 | | -static int check_selection(struct v4l2_subdev *sd, |
|---|
| 154 | | - struct v4l2_subdev_selection *sel) |
|---|
| 187 | +static int call_enum_mbus_code(struct v4l2_subdev *sd, |
|---|
| 188 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 189 | + struct v4l2_subdev_mbus_code_enum *code) |
|---|
| 155 | 190 | { |
|---|
| 156 | | - if (sel->which != V4L2_SUBDEV_FORMAT_TRY && |
|---|
| 157 | | - sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
|---|
| 191 | + if (!code) |
|---|
| 158 | 192 | return -EINVAL; |
|---|
| 159 | 193 | |
|---|
| 160 | | - if (sel->pad >= sd->entity.num_pads) |
|---|
| 161 | | - return -EINVAL; |
|---|
| 162 | | - |
|---|
| 163 | | - return 0; |
|---|
| 194 | + return check_which(code->which) ? : check_pad(sd, code->pad) ? : |
|---|
| 195 | + check_cfg(code->which, cfg) ? : |
|---|
| 196 | + sd->ops->pad->enum_mbus_code(sd, cfg, code); |
|---|
| 164 | 197 | } |
|---|
| 165 | 198 | |
|---|
| 166 | | -static int check_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) |
|---|
| 199 | +static int call_enum_frame_size(struct v4l2_subdev *sd, |
|---|
| 200 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 201 | + struct v4l2_subdev_frame_size_enum *fse) |
|---|
| 167 | 202 | { |
|---|
| 168 | | - if (edid->pad >= sd->entity.num_pads) |
|---|
| 203 | + if (!fse) |
|---|
| 204 | + return -EINVAL; |
|---|
| 205 | + |
|---|
| 206 | + return check_which(fse->which) ? : check_pad(sd, fse->pad) ? : |
|---|
| 207 | + check_cfg(fse->which, cfg) ? : |
|---|
| 208 | + sd->ops->pad->enum_frame_size(sd, cfg, fse); |
|---|
| 209 | +} |
|---|
| 210 | + |
|---|
| 211 | +static inline int check_frame_interval(struct v4l2_subdev *sd, |
|---|
| 212 | + struct v4l2_subdev_frame_interval *fi) |
|---|
| 213 | +{ |
|---|
| 214 | + if (!fi) |
|---|
| 215 | + return -EINVAL; |
|---|
| 216 | + |
|---|
| 217 | + return check_pad(sd, fi->pad); |
|---|
| 218 | +} |
|---|
| 219 | + |
|---|
| 220 | +static int call_g_frame_interval(struct v4l2_subdev *sd, |
|---|
| 221 | + struct v4l2_subdev_frame_interval *fi) |
|---|
| 222 | +{ |
|---|
| 223 | + return check_frame_interval(sd, fi) ? : |
|---|
| 224 | + sd->ops->video->g_frame_interval(sd, fi); |
|---|
| 225 | +} |
|---|
| 226 | + |
|---|
| 227 | +static int call_s_frame_interval(struct v4l2_subdev *sd, |
|---|
| 228 | + struct v4l2_subdev_frame_interval *fi) |
|---|
| 229 | +{ |
|---|
| 230 | + return check_frame_interval(sd, fi) ? : |
|---|
| 231 | + sd->ops->video->s_frame_interval(sd, fi); |
|---|
| 232 | +} |
|---|
| 233 | + |
|---|
| 234 | +static int call_enum_frame_interval(struct v4l2_subdev *sd, |
|---|
| 235 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 236 | + struct v4l2_subdev_frame_interval_enum *fie) |
|---|
| 237 | +{ |
|---|
| 238 | + if (!fie) |
|---|
| 239 | + return -EINVAL; |
|---|
| 240 | + |
|---|
| 241 | + return check_which(fie->which) ? : check_pad(sd, fie->pad) ? : |
|---|
| 242 | + check_cfg(fie->which, cfg) ? : |
|---|
| 243 | + sd->ops->pad->enum_frame_interval(sd, cfg, fie); |
|---|
| 244 | +} |
|---|
| 245 | + |
|---|
| 246 | +static inline int check_selection(struct v4l2_subdev *sd, |
|---|
| 247 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 248 | + struct v4l2_subdev_selection *sel) |
|---|
| 249 | +{ |
|---|
| 250 | + if (!sel) |
|---|
| 251 | + return -EINVAL; |
|---|
| 252 | + |
|---|
| 253 | + return check_which(sel->which) ? : check_pad(sd, sel->pad) ? : |
|---|
| 254 | + check_cfg(sel->which, cfg); |
|---|
| 255 | +} |
|---|
| 256 | + |
|---|
| 257 | +static int call_get_selection(struct v4l2_subdev *sd, |
|---|
| 258 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 259 | + struct v4l2_subdev_selection *sel) |
|---|
| 260 | +{ |
|---|
| 261 | + return check_selection(sd, cfg, sel) ? : |
|---|
| 262 | + sd->ops->pad->get_selection(sd, cfg, sel); |
|---|
| 263 | +} |
|---|
| 264 | + |
|---|
| 265 | +static int call_set_selection(struct v4l2_subdev *sd, |
|---|
| 266 | + struct v4l2_subdev_pad_config *cfg, |
|---|
| 267 | + struct v4l2_subdev_selection *sel) |
|---|
| 268 | +{ |
|---|
| 269 | + return check_selection(sd, cfg, sel) ? : |
|---|
| 270 | + sd->ops->pad->set_selection(sd, cfg, sel); |
|---|
| 271 | +} |
|---|
| 272 | + |
|---|
| 273 | +static inline int check_edid(struct v4l2_subdev *sd, |
|---|
| 274 | + struct v4l2_subdev_edid *edid) |
|---|
| 275 | +{ |
|---|
| 276 | + if (!edid) |
|---|
| 169 | 277 | return -EINVAL; |
|---|
| 170 | 278 | |
|---|
| 171 | 279 | if (edid->blocks && edid->edid == NULL) |
|---|
| 172 | 280 | return -EINVAL; |
|---|
| 173 | 281 | |
|---|
| 174 | | - return 0; |
|---|
| 282 | + return check_pad(sd, edid->pad); |
|---|
| 175 | 283 | } |
|---|
| 176 | | -#endif |
|---|
| 177 | 284 | |
|---|
| 285 | +static int call_get_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) |
|---|
| 286 | +{ |
|---|
| 287 | + return check_edid(sd, edid) ? : sd->ops->pad->get_edid(sd, edid); |
|---|
| 288 | +} |
|---|
| 289 | + |
|---|
| 290 | +static int call_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid) |
|---|
| 291 | +{ |
|---|
| 292 | + return check_edid(sd, edid) ? : sd->ops->pad->set_edid(sd, edid); |
|---|
| 293 | +} |
|---|
| 294 | + |
|---|
| 295 | +static int call_dv_timings_cap(struct v4l2_subdev *sd, |
|---|
| 296 | + struct v4l2_dv_timings_cap *cap) |
|---|
| 297 | +{ |
|---|
| 298 | + if (!cap) |
|---|
| 299 | + return -EINVAL; |
|---|
| 300 | + |
|---|
| 301 | + return check_pad(sd, cap->pad) ? : |
|---|
| 302 | + sd->ops->pad->dv_timings_cap(sd, cap); |
|---|
| 303 | +} |
|---|
| 304 | + |
|---|
| 305 | +static int call_enum_dv_timings(struct v4l2_subdev *sd, |
|---|
| 306 | + struct v4l2_enum_dv_timings *dvt) |
|---|
| 307 | +{ |
|---|
| 308 | + if (!dvt) |
|---|
| 309 | + return -EINVAL; |
|---|
| 310 | + |
|---|
| 311 | + return check_pad(sd, dvt->pad) ? : |
|---|
| 312 | + sd->ops->pad->enum_dv_timings(sd, dvt); |
|---|
| 313 | +} |
|---|
| 314 | + |
|---|
| 315 | +static int call_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad, |
|---|
| 316 | + struct v4l2_mbus_config *config) |
|---|
| 317 | +{ |
|---|
| 318 | + return check_pad(sd, pad) ? : |
|---|
| 319 | + sd->ops->pad->get_mbus_config(sd, pad, config); |
|---|
| 320 | +} |
|---|
| 321 | + |
|---|
| 322 | +static int call_set_mbus_config(struct v4l2_subdev *sd, unsigned int pad, |
|---|
| 323 | + struct v4l2_mbus_config *config) |
|---|
| 324 | +{ |
|---|
| 325 | + return check_pad(sd, pad) ? : |
|---|
| 326 | + sd->ops->pad->get_mbus_config(sd, pad, config); |
|---|
| 327 | +} |
|---|
| 328 | + |
|---|
| 329 | +static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = { |
|---|
| 330 | + .get_fmt = call_get_fmt, |
|---|
| 331 | + .set_fmt = call_set_fmt, |
|---|
| 332 | + .enum_mbus_code = call_enum_mbus_code, |
|---|
| 333 | + .enum_frame_size = call_enum_frame_size, |
|---|
| 334 | + .enum_frame_interval = call_enum_frame_interval, |
|---|
| 335 | + .get_selection = call_get_selection, |
|---|
| 336 | + .set_selection = call_set_selection, |
|---|
| 337 | + .get_edid = call_get_edid, |
|---|
| 338 | + .set_edid = call_set_edid, |
|---|
| 339 | + .dv_timings_cap = call_dv_timings_cap, |
|---|
| 340 | + .enum_dv_timings = call_enum_dv_timings, |
|---|
| 341 | + .get_mbus_config = call_get_mbus_config, |
|---|
| 342 | + .set_mbus_config = call_set_mbus_config, |
|---|
| 343 | +}; |
|---|
| 344 | + |
|---|
| 345 | +static const struct v4l2_subdev_video_ops v4l2_subdev_call_video_wrappers = { |
|---|
| 346 | + .g_frame_interval = call_g_frame_interval, |
|---|
| 347 | + .s_frame_interval = call_s_frame_interval, |
|---|
| 348 | +}; |
|---|
| 349 | + |
|---|
| 350 | +const struct v4l2_subdev_ops v4l2_subdev_call_wrappers = { |
|---|
| 351 | + .pad = &v4l2_subdev_call_pad_wrappers, |
|---|
| 352 | + .video = &v4l2_subdev_call_video_wrappers, |
|---|
| 353 | +}; |
|---|
| 354 | +EXPORT_SYMBOL(v4l2_subdev_call_wrappers); |
|---|
| 355 | + |
|---|
| 356 | +#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 178 | 357 | static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
|---|
| 179 | 358 | { |
|---|
| 180 | 359 | struct video_device *vdev = video_devdata(file); |
|---|
| 181 | 360 | struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev); |
|---|
| 182 | 361 | struct v4l2_fh *vfh = file->private_data; |
|---|
| 183 | | -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 184 | 362 | struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); |
|---|
| 363 | + bool ro_subdev = test_bit(V4L2_FL_SUBDEV_RO_DEVNODE, &vdev->flags); |
|---|
| 185 | 364 | int rval; |
|---|
| 186 | | -#endif |
|---|
| 187 | 365 | |
|---|
| 188 | 366 | switch (cmd) { |
|---|
| 367 | + case VIDIOC_SUBDEV_QUERYCAP: { |
|---|
| 368 | + struct v4l2_subdev_capability *cap = arg; |
|---|
| 369 | + |
|---|
| 370 | + memset(cap->reserved, 0, sizeof(cap->reserved)); |
|---|
| 371 | + cap->version = LINUX_VERSION_CODE; |
|---|
| 372 | + cap->capabilities = ro_subdev ? V4L2_SUBDEV_CAP_RO_SUBDEV : 0; |
|---|
| 373 | + |
|---|
| 374 | + return 0; |
|---|
| 375 | + } |
|---|
| 376 | + |
|---|
| 189 | 377 | case VIDIOC_QUERYCTRL: |
|---|
| 190 | 378 | /* |
|---|
| 191 | 379 | * TODO: this really should be folded into v4l2_queryctrl (this |
|---|
| .. | .. |
|---|
| 222 | 410 | case VIDIOC_G_EXT_CTRLS: |
|---|
| 223 | 411 | if (!vfh->ctrl_handler) |
|---|
| 224 | 412 | return -ENOTTY; |
|---|
| 225 | | - return v4l2_g_ext_ctrls(vfh->ctrl_handler, arg); |
|---|
| 413 | + return v4l2_g_ext_ctrls(vfh->ctrl_handler, |
|---|
| 414 | + vdev, sd->v4l2_dev->mdev, arg); |
|---|
| 226 | 415 | |
|---|
| 227 | 416 | case VIDIOC_S_EXT_CTRLS: |
|---|
| 228 | 417 | if (!vfh->ctrl_handler) |
|---|
| 229 | 418 | return -ENOTTY; |
|---|
| 230 | | - return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, arg); |
|---|
| 419 | + return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, |
|---|
| 420 | + vdev, sd->v4l2_dev->mdev, arg); |
|---|
| 231 | 421 | |
|---|
| 232 | 422 | case VIDIOC_TRY_EXT_CTRLS: |
|---|
| 233 | 423 | if (!vfh->ctrl_handler) |
|---|
| 234 | 424 | return -ENOTTY; |
|---|
| 235 | | - return v4l2_try_ext_ctrls(vfh->ctrl_handler, arg); |
|---|
| 425 | + return v4l2_try_ext_ctrls(vfh->ctrl_handler, |
|---|
| 426 | + vdev, sd->v4l2_dev->mdev, arg); |
|---|
| 236 | 427 | |
|---|
| 237 | 428 | case VIDIOC_DQEVENT: |
|---|
| 238 | 429 | if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS)) |
|---|
| .. | .. |
|---|
| 273 | 464 | p->flags |= V4L2_CHIP_FL_WRITABLE; |
|---|
| 274 | 465 | if (sd->ops->core && sd->ops->core->g_register) |
|---|
| 275 | 466 | p->flags |= V4L2_CHIP_FL_READABLE; |
|---|
| 276 | | - strlcpy(p->name, sd->name, sizeof(p->name)); |
|---|
| 467 | + strscpy(p->name, sd->name, sizeof(p->name)); |
|---|
| 277 | 468 | return 0; |
|---|
| 278 | 469 | } |
|---|
| 279 | 470 | #endif |
|---|
| .. | .. |
|---|
| 289 | 480 | return ret; |
|---|
| 290 | 481 | } |
|---|
| 291 | 482 | |
|---|
| 292 | | -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) |
|---|
| 293 | 483 | case VIDIOC_SUBDEV_G_FMT: { |
|---|
| 294 | 484 | struct v4l2_subdev_format *format = arg; |
|---|
| 295 | | - |
|---|
| 296 | | - rval = check_format(sd, format); |
|---|
| 297 | | - if (rval) |
|---|
| 298 | | - return rval; |
|---|
| 299 | 485 | |
|---|
| 300 | 486 | memset(format->reserved, 0, sizeof(format->reserved)); |
|---|
| 301 | 487 | memset(format->format.reserved, 0, sizeof(format->format.reserved)); |
|---|
| .. | .. |
|---|
| 304 | 490 | |
|---|
| 305 | 491 | case VIDIOC_SUBDEV_S_FMT: { |
|---|
| 306 | 492 | struct v4l2_subdev_format *format = arg; |
|---|
| 493 | + int ret = 0; |
|---|
| 307 | 494 | |
|---|
| 308 | | - rval = check_format(sd, format); |
|---|
| 309 | | - if (rval) |
|---|
| 310 | | - return rval; |
|---|
| 495 | + if (format->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev) |
|---|
| 496 | + return -EPERM; |
|---|
| 497 | + |
|---|
| 498 | + trace_android_vh_v4l2subdev_set_fmt(sd, subdev_fh->pad, |
|---|
| 499 | + format, &ret); |
|---|
| 500 | + trace_android_rvh_v4l2subdev_set_fmt(sd, subdev_fh->pad, |
|---|
| 501 | + format, &ret); |
|---|
| 502 | + if (ret) |
|---|
| 503 | + return ret; |
|---|
| 311 | 504 | |
|---|
| 312 | 505 | memset(format->reserved, 0, sizeof(format->reserved)); |
|---|
| 313 | 506 | memset(format->format.reserved, 0, sizeof(format->format.reserved)); |
|---|
| .. | .. |
|---|
| 317 | 510 | case VIDIOC_SUBDEV_G_CROP: { |
|---|
| 318 | 511 | struct v4l2_subdev_crop *crop = arg; |
|---|
| 319 | 512 | struct v4l2_subdev_selection sel; |
|---|
| 320 | | - |
|---|
| 321 | | - rval = check_crop(sd, crop); |
|---|
| 322 | | - if (rval) |
|---|
| 323 | | - return rval; |
|---|
| 324 | 513 | |
|---|
| 325 | 514 | memset(crop->reserved, 0, sizeof(crop->reserved)); |
|---|
| 326 | 515 | memset(&sel, 0, sizeof(sel)); |
|---|
| .. | .. |
|---|
| 340 | 529 | struct v4l2_subdev_crop *crop = arg; |
|---|
| 341 | 530 | struct v4l2_subdev_selection sel; |
|---|
| 342 | 531 | |
|---|
| 343 | | - memset(crop->reserved, 0, sizeof(crop->reserved)); |
|---|
| 344 | | - rval = check_crop(sd, crop); |
|---|
| 345 | | - if (rval) |
|---|
| 346 | | - return rval; |
|---|
| 532 | + if (crop->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev) |
|---|
| 533 | + return -EPERM; |
|---|
| 347 | 534 | |
|---|
| 535 | + memset(crop->reserved, 0, sizeof(crop->reserved)); |
|---|
| 348 | 536 | memset(&sel, 0, sizeof(sel)); |
|---|
| 349 | 537 | sel.which = crop->which; |
|---|
| 350 | 538 | sel.pad = crop->pad; |
|---|
| .. | .. |
|---|
| 362 | 550 | case VIDIOC_SUBDEV_ENUM_MBUS_CODE: { |
|---|
| 363 | 551 | struct v4l2_subdev_mbus_code_enum *code = arg; |
|---|
| 364 | 552 | |
|---|
| 365 | | - if (code->which != V4L2_SUBDEV_FORMAT_TRY && |
|---|
| 366 | | - code->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
|---|
| 367 | | - return -EINVAL; |
|---|
| 368 | | - |
|---|
| 369 | | - if (code->pad >= sd->entity.num_pads) |
|---|
| 370 | | - return -EINVAL; |
|---|
| 371 | | - |
|---|
| 372 | 553 | memset(code->reserved, 0, sizeof(code->reserved)); |
|---|
| 373 | 554 | return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh->pad, |
|---|
| 374 | 555 | code); |
|---|
| .. | .. |
|---|
| 376 | 557 | |
|---|
| 377 | 558 | case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: { |
|---|
| 378 | 559 | struct v4l2_subdev_frame_size_enum *fse = arg; |
|---|
| 379 | | - |
|---|
| 380 | | - if (fse->which != V4L2_SUBDEV_FORMAT_TRY && |
|---|
| 381 | | - fse->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
|---|
| 382 | | - return -EINVAL; |
|---|
| 383 | | - |
|---|
| 384 | | - if (fse->pad >= sd->entity.num_pads) |
|---|
| 385 | | - return -EINVAL; |
|---|
| 386 | 560 | |
|---|
| 387 | 561 | memset(fse->reserved, 0, sizeof(fse->reserved)); |
|---|
| 388 | 562 | return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh->pad, |
|---|
| .. | .. |
|---|
| 392 | 566 | case VIDIOC_SUBDEV_G_FRAME_INTERVAL: { |
|---|
| 393 | 567 | struct v4l2_subdev_frame_interval *fi = arg; |
|---|
| 394 | 568 | |
|---|
| 395 | | - if (fi->pad >= sd->entity.num_pads) |
|---|
| 396 | | - return -EINVAL; |
|---|
| 397 | | - |
|---|
| 398 | 569 | memset(fi->reserved, 0, sizeof(fi->reserved)); |
|---|
| 399 | 570 | return v4l2_subdev_call(sd, video, g_frame_interval, arg); |
|---|
| 400 | 571 | } |
|---|
| 401 | 572 | |
|---|
| 402 | 573 | case VIDIOC_SUBDEV_S_FRAME_INTERVAL: { |
|---|
| 403 | 574 | struct v4l2_subdev_frame_interval *fi = arg; |
|---|
| 575 | + int ret = 0; |
|---|
| 404 | 576 | |
|---|
| 405 | | - if (fi->pad >= sd->entity.num_pads) |
|---|
| 406 | | - return -EINVAL; |
|---|
| 577 | + if (ro_subdev) |
|---|
| 578 | + return -EPERM; |
|---|
| 579 | + |
|---|
| 580 | + trace_android_vh_v4l2subdev_set_frame_interval(sd, fi, &ret); |
|---|
| 581 | + trace_android_rvh_v4l2subdev_set_frame_interval(sd, fi, &ret); |
|---|
| 582 | + if (ret) |
|---|
| 583 | + return ret; |
|---|
| 407 | 584 | |
|---|
| 408 | 585 | memset(fi->reserved, 0, sizeof(fi->reserved)); |
|---|
| 409 | 586 | return v4l2_subdev_call(sd, video, s_frame_interval, arg); |
|---|
| .. | .. |
|---|
| 411 | 588 | |
|---|
| 412 | 589 | case VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: { |
|---|
| 413 | 590 | struct v4l2_subdev_frame_interval_enum *fie = arg; |
|---|
| 414 | | - |
|---|
| 415 | | - if (fie->which != V4L2_SUBDEV_FORMAT_TRY && |
|---|
| 416 | | - fie->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
|---|
| 417 | | - return -EINVAL; |
|---|
| 418 | | - |
|---|
| 419 | | - if (fie->pad >= sd->entity.num_pads) |
|---|
| 420 | | - return -EINVAL; |
|---|
| 421 | 591 | |
|---|
| 422 | 592 | memset(fie->reserved, 0, sizeof(fie->reserved)); |
|---|
| 423 | 593 | return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh->pad, |
|---|
| .. | .. |
|---|
| 427 | 597 | case VIDIOC_SUBDEV_G_SELECTION: { |
|---|
| 428 | 598 | struct v4l2_subdev_selection *sel = arg; |
|---|
| 429 | 599 | |
|---|
| 430 | | - rval = check_selection(sd, sel); |
|---|
| 431 | | - if (rval) |
|---|
| 432 | | - return rval; |
|---|
| 433 | | - |
|---|
| 434 | 600 | memset(sel->reserved, 0, sizeof(sel->reserved)); |
|---|
| 435 | 601 | return v4l2_subdev_call( |
|---|
| 436 | 602 | sd, pad, get_selection, subdev_fh->pad, sel); |
|---|
| .. | .. |
|---|
| 438 | 604 | |
|---|
| 439 | 605 | case VIDIOC_SUBDEV_S_SELECTION: { |
|---|
| 440 | 606 | struct v4l2_subdev_selection *sel = arg; |
|---|
| 607 | + int ret = 0; |
|---|
| 441 | 608 | |
|---|
| 442 | | - rval = check_selection(sd, sel); |
|---|
| 443 | | - if (rval) |
|---|
| 444 | | - return rval; |
|---|
| 609 | + if (sel->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev) |
|---|
| 610 | + return -EPERM; |
|---|
| 611 | + |
|---|
| 612 | + trace_android_vh_v4l2subdev_set_selection(sd, subdev_fh->pad, |
|---|
| 613 | + sel, &ret); |
|---|
| 614 | + trace_android_rvh_v4l2subdev_set_selection(sd, subdev_fh->pad, |
|---|
| 615 | + sel, &ret); |
|---|
| 616 | + if (ret) |
|---|
| 617 | + return ret; |
|---|
| 445 | 618 | |
|---|
| 446 | 619 | memset(sel->reserved, 0, sizeof(sel->reserved)); |
|---|
| 447 | 620 | return v4l2_subdev_call( |
|---|
| .. | .. |
|---|
| 451 | 624 | case VIDIOC_G_EDID: { |
|---|
| 452 | 625 | struct v4l2_subdev_edid *edid = arg; |
|---|
| 453 | 626 | |
|---|
| 454 | | - rval = check_edid(sd, edid); |
|---|
| 455 | | - if (rval) |
|---|
| 456 | | - return rval; |
|---|
| 457 | | - |
|---|
| 458 | 627 | return v4l2_subdev_call(sd, pad, get_edid, edid); |
|---|
| 459 | 628 | } |
|---|
| 460 | 629 | |
|---|
| 461 | 630 | case VIDIOC_S_EDID: { |
|---|
| 462 | 631 | struct v4l2_subdev_edid *edid = arg; |
|---|
| 463 | | - |
|---|
| 464 | | - rval = check_edid(sd, edid); |
|---|
| 465 | | - if (rval) |
|---|
| 466 | | - return rval; |
|---|
| 467 | 632 | |
|---|
| 468 | 633 | return v4l2_subdev_call(sd, pad, set_edid, edid); |
|---|
| 469 | 634 | } |
|---|
| .. | .. |
|---|
| 471 | 636 | case VIDIOC_SUBDEV_DV_TIMINGS_CAP: { |
|---|
| 472 | 637 | struct v4l2_dv_timings_cap *cap = arg; |
|---|
| 473 | 638 | |
|---|
| 474 | | - if (cap->pad >= sd->entity.num_pads) |
|---|
| 475 | | - return -EINVAL; |
|---|
| 476 | | - |
|---|
| 477 | 639 | return v4l2_subdev_call(sd, pad, dv_timings_cap, cap); |
|---|
| 478 | 640 | } |
|---|
| 479 | 641 | |
|---|
| 480 | 642 | case VIDIOC_SUBDEV_ENUM_DV_TIMINGS: { |
|---|
| 481 | 643 | struct v4l2_enum_dv_timings *dvt = arg; |
|---|
| 482 | | - |
|---|
| 483 | | - if (dvt->pad >= sd->entity.num_pads) |
|---|
| 484 | | - return -EINVAL; |
|---|
| 485 | 644 | |
|---|
| 486 | 645 | return v4l2_subdev_call(sd, pad, enum_dv_timings, dvt); |
|---|
| 487 | 646 | } |
|---|
| .. | .. |
|---|
| 493 | 652 | return v4l2_subdev_call(sd, video, g_dv_timings, arg); |
|---|
| 494 | 653 | |
|---|
| 495 | 654 | case VIDIOC_SUBDEV_S_DV_TIMINGS: |
|---|
| 496 | | - return v4l2_subdev_call(sd, video, s_dv_timings, arg); |
|---|
| 655 | + if (ro_subdev) |
|---|
| 656 | + return -EPERM; |
|---|
| 497 | 657 | |
|---|
| 498 | | - case VIDIOC_G_INPUT: |
|---|
| 499 | | - return v4l2_subdev_call(sd, video, g_input_status, arg); |
|---|
| 658 | + return v4l2_subdev_call(sd, video, s_dv_timings, arg); |
|---|
| 500 | 659 | |
|---|
| 501 | 660 | case VIDIOC_SUBDEV_G_STD: |
|---|
| 502 | 661 | return v4l2_subdev_call(sd, video, g_std, arg); |
|---|
| 503 | 662 | |
|---|
| 504 | 663 | case VIDIOC_SUBDEV_S_STD: { |
|---|
| 505 | 664 | v4l2_std_id *std = arg; |
|---|
| 665 | + |
|---|
| 666 | + if (ro_subdev) |
|---|
| 667 | + return -EPERM; |
|---|
| 506 | 668 | |
|---|
| 507 | 669 | return v4l2_subdev_call(sd, video, s_std, *std); |
|---|
| 508 | 670 | } |
|---|
| .. | .. |
|---|
| 519 | 681 | |
|---|
| 520 | 682 | case VIDIOC_SUBDEV_QUERYSTD: |
|---|
| 521 | 683 | return v4l2_subdev_call(sd, video, querystd, arg); |
|---|
| 522 | | -#endif |
|---|
| 684 | + |
|---|
| 523 | 685 | default: |
|---|
| 524 | 686 | return v4l2_subdev_call(sd, core, ioctl, cmd, arg); |
|---|
| 525 | 687 | } |
|---|
| .. | .. |
|---|
| 559 | 721 | } |
|---|
| 560 | 722 | #endif |
|---|
| 561 | 723 | |
|---|
| 724 | +#else /* CONFIG_VIDEO_V4L2_SUBDEV_API */ |
|---|
| 725 | +static long subdev_ioctl(struct file *file, unsigned int cmd, |
|---|
| 726 | + unsigned long arg) |
|---|
| 727 | +{ |
|---|
| 728 | + return -ENODEV; |
|---|
| 729 | +} |
|---|
| 730 | + |
|---|
| 731 | +#ifdef CONFIG_COMPAT |
|---|
| 732 | +static long subdev_compat_ioctl32(struct file *file, unsigned int cmd, |
|---|
| 733 | + unsigned long arg) |
|---|
| 734 | +{ |
|---|
| 735 | + return -ENODEV; |
|---|
| 736 | +} |
|---|
| 737 | +#endif |
|---|
| 738 | +#endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */ |
|---|
| 739 | + |
|---|
| 562 | 740 | static __poll_t subdev_poll(struct file *file, poll_table *wait) |
|---|
| 563 | 741 | { |
|---|
| 564 | 742 | struct video_device *vdev = video_devdata(file); |
|---|
| .. | .. |
|---|
| 586 | 764 | .release = subdev_close, |
|---|
| 587 | 765 | .poll = subdev_poll, |
|---|
| 588 | 766 | }; |
|---|
| 589 | | -EXPORT_SYMBOL_GPL(v4l2_subdev_fops); |
|---|
| 590 | 767 | |
|---|
| 591 | 768 | #ifdef CONFIG_MEDIA_CONTROLLER |
|---|
| 769 | + |
|---|
| 770 | +int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity, |
|---|
| 771 | + struct fwnode_endpoint *endpoint) |
|---|
| 772 | +{ |
|---|
| 773 | + struct fwnode_handle *fwnode; |
|---|
| 774 | + struct v4l2_subdev *sd; |
|---|
| 775 | + |
|---|
| 776 | + if (!is_media_entity_v4l2_subdev(entity)) |
|---|
| 777 | + return -EINVAL; |
|---|
| 778 | + |
|---|
| 779 | + sd = media_entity_to_v4l2_subdev(entity); |
|---|
| 780 | + |
|---|
| 781 | + fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode); |
|---|
| 782 | + fwnode_handle_put(fwnode); |
|---|
| 783 | + |
|---|
| 784 | + if (dev_fwnode(sd->dev) == fwnode) |
|---|
| 785 | + return endpoint->port; |
|---|
| 786 | + |
|---|
| 787 | + return -ENXIO; |
|---|
| 788 | +} |
|---|
| 789 | +EXPORT_SYMBOL_GPL(v4l2_subdev_get_fwnode_pad_1_to_1); |
|---|
| 790 | + |
|---|
| 592 | 791 | int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd, |
|---|
| 593 | 792 | struct media_link *link, |
|---|
| 594 | 793 | struct v4l2_subdev_format *source_fmt, |
|---|