1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2010 Nokia Corporation
7 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 * Sakari Ailus <sakari.ailus@iki.fi>
11 #include <linux/ioctl.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/types.h>
16 #include <linux/videodev2.h>
17 #include <linux/export.h>
18 #include <linux/version.h>
20 #include <media/v4l2-ctrls.h>
21 #include <media/v4l2-device.h>
22 #include <media/v4l2-ioctl.h>
23 #include <media/v4l2-fh.h>
24 #include <media/v4l2-event.h>
26 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
27 static int subdev_fh_init(struct v4l2_subdev_fh *fh, struct v4l2_subdev *sd)
29 if (sd->entity.num_pads) {
30 fh->pad = v4l2_subdev_alloc_pad_config(sd);
38 static void subdev_fh_free(struct v4l2_subdev_fh *fh)
40 v4l2_subdev_free_pad_config(fh->pad);
44 static int subdev_open(struct file *file)
46 struct video_device *vdev = video_devdata(file);
47 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
48 struct v4l2_subdev_fh *subdev_fh;
51 subdev_fh = kzalloc(sizeof(*subdev_fh), GFP_KERNEL);
52 if (subdev_fh == NULL)
55 ret = subdev_fh_init(subdev_fh, sd);
61 v4l2_fh_init(&subdev_fh->vfh, vdev);
62 v4l2_fh_add(&subdev_fh->vfh);
63 file->private_data = &subdev_fh->vfh;
64 #if defined(CONFIG_MEDIA_CONTROLLER)
65 if (sd->v4l2_dev->mdev && sd->entity.graph_obj.mdev->dev) {
68 owner = sd->entity.graph_obj.mdev->dev->driver->owner;
69 if (!try_module_get(owner)) {
73 subdev_fh->owner = owner;
77 if (sd->internal_ops && sd->internal_ops->open) {
78 ret = sd->internal_ops->open(sd, subdev_fh);
86 module_put(subdev_fh->owner);
87 v4l2_fh_del(&subdev_fh->vfh);
88 v4l2_fh_exit(&subdev_fh->vfh);
89 subdev_fh_free(subdev_fh);
95 static int subdev_close(struct file *file)
97 struct video_device *vdev = video_devdata(file);
98 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
99 struct v4l2_fh *vfh = file->private_data;
100 struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);
102 if (sd->internal_ops && sd->internal_ops->close)
103 sd->internal_ops->close(sd, subdev_fh);
104 module_put(subdev_fh->owner);
107 subdev_fh_free(subdev_fh);
109 file->private_data = NULL;
113 #else /* CONFIG_VIDEO_V4L2_SUBDEV_API */
114 static int subdev_open(struct file *file)
119 static int subdev_close(struct file *file)
123 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
125 static inline int check_which(u32 which)
127 if (which != V4L2_SUBDEV_FORMAT_TRY &&
128 which != V4L2_SUBDEV_FORMAT_ACTIVE)
134 static inline int check_pad(struct v4l2_subdev *sd, u32 pad)
136 #if defined(CONFIG_MEDIA_CONTROLLER)
137 if (sd->entity.num_pads) {
138 if (pad >= sd->entity.num_pads)
143 /* allow pad 0 on subdevices not registered as media entities */
149 static int check_cfg(u32 which, struct v4l2_subdev_pad_config *cfg)
151 if (which == V4L2_SUBDEV_FORMAT_TRY && !cfg)
157 static inline int check_format(struct v4l2_subdev *sd,
158 struct v4l2_subdev_pad_config *cfg,
159 struct v4l2_subdev_format *format)
164 return check_which(format->which) ? : check_pad(sd, format->pad) ? :
165 check_cfg(format->which, cfg);
168 static int call_get_fmt(struct v4l2_subdev *sd,
169 struct v4l2_subdev_pad_config *cfg,
170 struct v4l2_subdev_format *format)
172 return check_format(sd, cfg, format) ? :
173 sd->ops->pad->get_fmt(sd, cfg, format);
176 static int call_set_fmt(struct v4l2_subdev *sd,
177 struct v4l2_subdev_pad_config *cfg,
178 struct v4l2_subdev_format *format)
180 return check_format(sd, cfg, format) ? :
181 sd->ops->pad->set_fmt(sd, cfg, format);
184 static int call_enum_mbus_code(struct v4l2_subdev *sd,
185 struct v4l2_subdev_pad_config *cfg,
186 struct v4l2_subdev_mbus_code_enum *code)
191 return check_which(code->which) ? : check_pad(sd, code->pad) ? :
192 check_cfg(code->which, cfg) ? :
193 sd->ops->pad->enum_mbus_code(sd, cfg, code);
196 static int call_enum_frame_size(struct v4l2_subdev *sd,
197 struct v4l2_subdev_pad_config *cfg,
198 struct v4l2_subdev_frame_size_enum *fse)
203 return check_which(fse->which) ? : check_pad(sd, fse->pad) ? :
204 check_cfg(fse->which, cfg) ? :
205 sd->ops->pad->enum_frame_size(sd, cfg, fse);
208 static inline int check_frame_interval(struct v4l2_subdev *sd,
209 struct v4l2_subdev_frame_interval *fi)
214 return check_pad(sd, fi->pad);
217 static int call_g_frame_interval(struct v4l2_subdev *sd,
218 struct v4l2_subdev_frame_interval *fi)
220 return check_frame_interval(sd, fi) ? :
221 sd->ops->video->g_frame_interval(sd, fi);
224 static int call_s_frame_interval(struct v4l2_subdev *sd,
225 struct v4l2_subdev_frame_interval *fi)
227 return check_frame_interval(sd, fi) ? :
228 sd->ops->video->s_frame_interval(sd, fi);
231 static int call_enum_frame_interval(struct v4l2_subdev *sd,
232 struct v4l2_subdev_pad_config *cfg,
233 struct v4l2_subdev_frame_interval_enum *fie)
238 return check_which(fie->which) ? : check_pad(sd, fie->pad) ? :
239 check_cfg(fie->which, cfg) ? :
240 sd->ops->pad->enum_frame_interval(sd, cfg, fie);
243 static inline int check_selection(struct v4l2_subdev *sd,
244 struct v4l2_subdev_pad_config *cfg,
245 struct v4l2_subdev_selection *sel)
250 return check_which(sel->which) ? : check_pad(sd, sel->pad) ? :
251 check_cfg(sel->which, cfg);
254 static int call_get_selection(struct v4l2_subdev *sd,
255 struct v4l2_subdev_pad_config *cfg,
256 struct v4l2_subdev_selection *sel)
258 return check_selection(sd, cfg, sel) ? :
259 sd->ops->pad->get_selection(sd, cfg, sel);
262 static int call_set_selection(struct v4l2_subdev *sd,
263 struct v4l2_subdev_pad_config *cfg,
264 struct v4l2_subdev_selection *sel)
266 return check_selection(sd, cfg, sel) ? :
267 sd->ops->pad->set_selection(sd, cfg, sel);
270 static inline int check_edid(struct v4l2_subdev *sd,
271 struct v4l2_subdev_edid *edid)
276 if (edid->blocks && edid->edid == NULL)
279 return check_pad(sd, edid->pad);
282 static int call_get_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid)
284 return check_edid(sd, edid) ? : sd->ops->pad->get_edid(sd, edid);
287 static int call_set_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid)
289 return check_edid(sd, edid) ? : sd->ops->pad->set_edid(sd, edid);
292 static int call_dv_timings_cap(struct v4l2_subdev *sd,
293 struct v4l2_dv_timings_cap *cap)
298 return check_pad(sd, cap->pad) ? :
299 sd->ops->pad->dv_timings_cap(sd, cap);
302 static int call_enum_dv_timings(struct v4l2_subdev *sd,
303 struct v4l2_enum_dv_timings *dvt)
308 return check_pad(sd, dvt->pad) ? :
309 sd->ops->pad->enum_dv_timings(sd, dvt);
312 static int call_get_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
313 struct v4l2_mbus_config *config)
315 return check_pad(sd, pad) ? :
316 sd->ops->pad->get_mbus_config(sd, pad, config);
319 static int call_set_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
320 struct v4l2_mbus_config *config)
322 return check_pad(sd, pad) ? :
323 sd->ops->pad->get_mbus_config(sd, pad, config);
326 static const struct v4l2_subdev_pad_ops v4l2_subdev_call_pad_wrappers = {
327 .get_fmt = call_get_fmt,
328 .set_fmt = call_set_fmt,
329 .enum_mbus_code = call_enum_mbus_code,
330 .enum_frame_size = call_enum_frame_size,
331 .enum_frame_interval = call_enum_frame_interval,
332 .get_selection = call_get_selection,
333 .set_selection = call_set_selection,
334 .get_edid = call_get_edid,
335 .set_edid = call_set_edid,
336 .dv_timings_cap = call_dv_timings_cap,
337 .enum_dv_timings = call_enum_dv_timings,
338 .get_mbus_config = call_get_mbus_config,
339 .set_mbus_config = call_set_mbus_config,
342 static const struct v4l2_subdev_video_ops v4l2_subdev_call_video_wrappers = {
343 .g_frame_interval = call_g_frame_interval,
344 .s_frame_interval = call_s_frame_interval,
347 const struct v4l2_subdev_ops v4l2_subdev_call_wrappers = {
348 .pad = &v4l2_subdev_call_pad_wrappers,
349 .video = &v4l2_subdev_call_video_wrappers,
351 EXPORT_SYMBOL(v4l2_subdev_call_wrappers);
353 #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
354 static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
356 struct video_device *vdev = video_devdata(file);
357 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
358 struct v4l2_fh *vfh = file->private_data;
359 struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);
360 bool ro_subdev = test_bit(V4L2_FL_SUBDEV_RO_DEVNODE, &vdev->flags);
364 case VIDIOC_SUBDEV_QUERYCAP: {
365 struct v4l2_subdev_capability *cap = arg;
367 memset(cap->reserved, 0, sizeof(cap->reserved));
368 cap->version = LINUX_VERSION_CODE;
369 cap->capabilities = ro_subdev ? V4L2_SUBDEV_CAP_RO_SUBDEV : 0;
374 case VIDIOC_QUERYCTRL:
376 * TODO: this really should be folded into v4l2_queryctrl (this
377 * currently returns -EINVAL for NULL control handlers).
378 * However, v4l2_queryctrl() is still called directly by
379 * drivers as well and until that has been addressed I believe
380 * it is safer to do the check here. The same is true for the
381 * other control ioctls below.
383 if (!vfh->ctrl_handler)
385 return v4l2_queryctrl(vfh->ctrl_handler, arg);
387 case VIDIOC_QUERY_EXT_CTRL:
388 if (!vfh->ctrl_handler)
390 return v4l2_query_ext_ctrl(vfh->ctrl_handler, arg);
392 case VIDIOC_QUERYMENU:
393 if (!vfh->ctrl_handler)
395 return v4l2_querymenu(vfh->ctrl_handler, arg);
398 if (!vfh->ctrl_handler)
400 return v4l2_g_ctrl(vfh->ctrl_handler, arg);
403 if (!vfh->ctrl_handler)
405 return v4l2_s_ctrl(vfh, vfh->ctrl_handler, arg);
407 case VIDIOC_G_EXT_CTRLS:
408 if (!vfh->ctrl_handler)
410 return v4l2_g_ext_ctrls(vfh->ctrl_handler,
411 vdev, sd->v4l2_dev->mdev, arg);
413 case VIDIOC_S_EXT_CTRLS:
414 if (!vfh->ctrl_handler)
416 return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler,
417 vdev, sd->v4l2_dev->mdev, arg);
419 case VIDIOC_TRY_EXT_CTRLS:
420 if (!vfh->ctrl_handler)
422 return v4l2_try_ext_ctrls(vfh->ctrl_handler,
423 vdev, sd->v4l2_dev->mdev, arg);
426 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
429 return v4l2_event_dequeue(vfh, arg, file->f_flags & O_NONBLOCK);
431 case VIDIOC_SUBSCRIBE_EVENT:
432 return v4l2_subdev_call(sd, core, subscribe_event, vfh, arg);
434 case VIDIOC_UNSUBSCRIBE_EVENT:
435 return v4l2_subdev_call(sd, core, unsubscribe_event, vfh, arg);
437 #ifdef CONFIG_VIDEO_ADV_DEBUG
438 case VIDIOC_DBG_G_REGISTER:
440 struct v4l2_dbg_register *p = arg;
442 if (!capable(CAP_SYS_ADMIN))
444 return v4l2_subdev_call(sd, core, g_register, p);
446 case VIDIOC_DBG_S_REGISTER:
448 struct v4l2_dbg_register *p = arg;
450 if (!capable(CAP_SYS_ADMIN))
452 return v4l2_subdev_call(sd, core, s_register, p);
454 case VIDIOC_DBG_G_CHIP_INFO:
456 struct v4l2_dbg_chip_info *p = arg;
458 if (p->match.type != V4L2_CHIP_MATCH_SUBDEV || p->match.addr)
460 if (sd->ops->core && sd->ops->core->s_register)
461 p->flags |= V4L2_CHIP_FL_WRITABLE;
462 if (sd->ops->core && sd->ops->core->g_register)
463 p->flags |= V4L2_CHIP_FL_READABLE;
464 strscpy(p->name, sd->name, sizeof(p->name));
469 case VIDIOC_LOG_STATUS: {
472 pr_info("%s: ================= START STATUS =================\n",
474 ret = v4l2_subdev_call(sd, core, log_status);
475 pr_info("%s: ================== END STATUS ==================\n",
480 case VIDIOC_SUBDEV_G_FMT: {
481 struct v4l2_subdev_format *format = arg;
483 memset(format->reserved, 0, sizeof(format->reserved));
484 memset(format->format.reserved, 0, sizeof(format->format.reserved));
485 return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh->pad, format);
488 case VIDIOC_SUBDEV_S_FMT: {
489 struct v4l2_subdev_format *format = arg;
491 if (format->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)
494 memset(format->reserved, 0, sizeof(format->reserved));
495 memset(format->format.reserved, 0, sizeof(format->format.reserved));
496 return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh->pad, format);
499 case VIDIOC_SUBDEV_G_CROP: {
500 struct v4l2_subdev_crop *crop = arg;
501 struct v4l2_subdev_selection sel;
503 memset(crop->reserved, 0, sizeof(crop->reserved));
504 memset(&sel, 0, sizeof(sel));
505 sel.which = crop->which;
507 sel.target = V4L2_SEL_TGT_CROP;
509 rval = v4l2_subdev_call(
510 sd, pad, get_selection, subdev_fh->pad, &sel);
517 case VIDIOC_SUBDEV_S_CROP: {
518 struct v4l2_subdev_crop *crop = arg;
519 struct v4l2_subdev_selection sel;
521 if (crop->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)
524 memset(crop->reserved, 0, sizeof(crop->reserved));
525 memset(&sel, 0, sizeof(sel));
526 sel.which = crop->which;
528 sel.target = V4L2_SEL_TGT_CROP;
531 rval = v4l2_subdev_call(
532 sd, pad, set_selection, subdev_fh->pad, &sel);
539 case VIDIOC_SUBDEV_ENUM_MBUS_CODE: {
540 struct v4l2_subdev_mbus_code_enum *code = arg;
542 memset(code->reserved, 0, sizeof(code->reserved));
543 return v4l2_subdev_call(sd, pad, enum_mbus_code, subdev_fh->pad,
547 case VIDIOC_SUBDEV_ENUM_FRAME_SIZE: {
548 struct v4l2_subdev_frame_size_enum *fse = arg;
550 memset(fse->reserved, 0, sizeof(fse->reserved));
551 return v4l2_subdev_call(sd, pad, enum_frame_size, subdev_fh->pad,
555 case VIDIOC_SUBDEV_G_FRAME_INTERVAL: {
556 struct v4l2_subdev_frame_interval *fi = arg;
558 memset(fi->reserved, 0, sizeof(fi->reserved));
559 return v4l2_subdev_call(sd, video, g_frame_interval, arg);
562 case VIDIOC_SUBDEV_S_FRAME_INTERVAL: {
563 struct v4l2_subdev_frame_interval *fi = arg;
568 memset(fi->reserved, 0, sizeof(fi->reserved));
569 return v4l2_subdev_call(sd, video, s_frame_interval, arg);
572 case VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: {
573 struct v4l2_subdev_frame_interval_enum *fie = arg;
575 memset(fie->reserved, 0, sizeof(fie->reserved));
576 return v4l2_subdev_call(sd, pad, enum_frame_interval, subdev_fh->pad,
580 case VIDIOC_SUBDEV_G_SELECTION: {
581 struct v4l2_subdev_selection *sel = arg;
583 memset(sel->reserved, 0, sizeof(sel->reserved));
584 return v4l2_subdev_call(
585 sd, pad, get_selection, subdev_fh->pad, sel);
588 case VIDIOC_SUBDEV_S_SELECTION: {
589 struct v4l2_subdev_selection *sel = arg;
591 if (sel->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)
594 memset(sel->reserved, 0, sizeof(sel->reserved));
595 return v4l2_subdev_call(
596 sd, pad, set_selection, subdev_fh->pad, sel);
599 case VIDIOC_G_EDID: {
600 struct v4l2_subdev_edid *edid = arg;
602 return v4l2_subdev_call(sd, pad, get_edid, edid);
605 case VIDIOC_S_EDID: {
606 struct v4l2_subdev_edid *edid = arg;
608 return v4l2_subdev_call(sd, pad, set_edid, edid);
611 case VIDIOC_SUBDEV_DV_TIMINGS_CAP: {
612 struct v4l2_dv_timings_cap *cap = arg;
614 return v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
617 case VIDIOC_SUBDEV_ENUM_DV_TIMINGS: {
618 struct v4l2_enum_dv_timings *dvt = arg;
620 return v4l2_subdev_call(sd, pad, enum_dv_timings, dvt);
623 case VIDIOC_SUBDEV_QUERY_DV_TIMINGS:
624 return v4l2_subdev_call(sd, video, query_dv_timings, arg);
626 case VIDIOC_SUBDEV_G_DV_TIMINGS:
627 return v4l2_subdev_call(sd, video, g_dv_timings, arg);
629 case VIDIOC_SUBDEV_S_DV_TIMINGS:
633 return v4l2_subdev_call(sd, video, s_dv_timings, arg);
635 case VIDIOC_SUBDEV_G_STD:
636 return v4l2_subdev_call(sd, video, g_std, arg);
638 case VIDIOC_SUBDEV_S_STD: {
639 v4l2_std_id *std = arg;
644 return v4l2_subdev_call(sd, video, s_std, *std);
647 case VIDIOC_SUBDEV_ENUMSTD: {
648 struct v4l2_standard *p = arg;
651 if (v4l2_subdev_call(sd, video, g_tvnorms, &id))
654 return v4l_video_std_enumstd(p, id);
657 case VIDIOC_SUBDEV_QUERYSTD:
658 return v4l2_subdev_call(sd, video, querystd, arg);
661 return v4l2_subdev_call(sd, core, ioctl, cmd, arg);
667 static long subdev_do_ioctl_lock(struct file *file, unsigned int cmd, void *arg)
669 struct video_device *vdev = video_devdata(file);
670 struct mutex *lock = vdev->lock;
673 if (lock && mutex_lock_interruptible(lock))
675 if (video_is_registered(vdev))
676 ret = subdev_do_ioctl(file, cmd, arg);
682 static long subdev_ioctl(struct file *file, unsigned int cmd,
685 return video_usercopy(file, cmd, arg, subdev_do_ioctl_lock);
689 static long subdev_compat_ioctl32(struct file *file, unsigned int cmd,
692 struct video_device *vdev = video_devdata(file);
693 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
695 return v4l2_subdev_call(sd, core, compat_ioctl32, cmd, arg);
699 #else /* CONFIG_VIDEO_V4L2_SUBDEV_API */
700 static long subdev_ioctl(struct file *file, unsigned int cmd,
707 static long subdev_compat_ioctl32(struct file *file, unsigned int cmd,
713 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
715 static __poll_t subdev_poll(struct file *file, poll_table *wait)
717 struct video_device *vdev = video_devdata(file);
718 struct v4l2_subdev *sd = vdev_to_v4l2_subdev(vdev);
719 struct v4l2_fh *fh = file->private_data;
721 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_EVENTS))
724 poll_wait(file, &fh->wait, wait);
726 if (v4l2_event_pending(fh))
732 const struct v4l2_file_operations v4l2_subdev_fops = {
733 .owner = THIS_MODULE,
735 .unlocked_ioctl = subdev_ioctl,
737 .compat_ioctl32 = subdev_compat_ioctl32,
739 .release = subdev_close,
743 #ifdef CONFIG_MEDIA_CONTROLLER
745 int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
746 struct fwnode_endpoint *endpoint)
748 struct fwnode_handle *fwnode;
749 struct v4l2_subdev *sd;
751 if (!is_media_entity_v4l2_subdev(entity))
754 sd = media_entity_to_v4l2_subdev(entity);
756 fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode);
757 fwnode_handle_put(fwnode);
759 if (dev_fwnode(sd->dev) == fwnode)
760 return endpoint->port;
764 EXPORT_SYMBOL_GPL(v4l2_subdev_get_fwnode_pad_1_to_1);
766 int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
767 struct media_link *link,
768 struct v4l2_subdev_format *source_fmt,
769 struct v4l2_subdev_format *sink_fmt)
771 /* The width, height and code must match. */
772 if (source_fmt->format.width != sink_fmt->format.width
773 || source_fmt->format.height != sink_fmt->format.height
774 || source_fmt->format.code != sink_fmt->format.code)
777 /* The field order must match, or the sink field order must be NONE
778 * to support interlaced hardware connected to bridges that support
779 * progressive formats only.
781 if (source_fmt->format.field != sink_fmt->format.field &&
782 sink_fmt->format.field != V4L2_FIELD_NONE)
787 EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate_default);
790 v4l2_subdev_link_validate_get_format(struct media_pad *pad,
791 struct v4l2_subdev_format *fmt)
793 if (is_media_entity_v4l2_subdev(pad->entity)) {
794 struct v4l2_subdev *sd =
795 media_entity_to_v4l2_subdev(pad->entity);
797 fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE;
798 fmt->pad = pad->index;
799 return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt);
802 WARN(pad->entity->function != MEDIA_ENT_F_IO_V4L,
803 "Driver bug! Wrong media entity type 0x%08x, entity %s\n",
804 pad->entity->function, pad->entity->name);
809 int v4l2_subdev_link_validate(struct media_link *link)
811 struct v4l2_subdev *sink;
812 struct v4l2_subdev_format sink_fmt, source_fmt;
815 rval = v4l2_subdev_link_validate_get_format(
816 link->source, &source_fmt);
820 rval = v4l2_subdev_link_validate_get_format(
821 link->sink, &sink_fmt);
825 sink = media_entity_to_v4l2_subdev(link->sink->entity);
827 rval = v4l2_subdev_call(sink, pad, link_validate, link,
828 &source_fmt, &sink_fmt);
829 if (rval != -ENOIOCTLCMD)
832 return v4l2_subdev_link_validate_default(
833 sink, link, &source_fmt, &sink_fmt);
835 EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate);
837 struct v4l2_subdev_pad_config *
838 v4l2_subdev_alloc_pad_config(struct v4l2_subdev *sd)
840 struct v4l2_subdev_pad_config *cfg;
843 if (!sd->entity.num_pads)
846 cfg = kvmalloc_array(sd->entity.num_pads, sizeof(*cfg),
847 GFP_KERNEL | __GFP_ZERO);
851 ret = v4l2_subdev_call(sd, pad, init_cfg, cfg);
852 if (ret < 0 && ret != -ENOIOCTLCMD) {
859 EXPORT_SYMBOL_GPL(v4l2_subdev_alloc_pad_config);
861 void v4l2_subdev_free_pad_config(struct v4l2_subdev_pad_config *cfg)
865 EXPORT_SYMBOL_GPL(v4l2_subdev_free_pad_config);
866 #endif /* CONFIG_MEDIA_CONTROLLER */
868 void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
870 INIT_LIST_HEAD(&sd->list);
878 sd->host_priv = NULL;
879 #if defined(CONFIG_MEDIA_CONTROLLER)
880 sd->entity.name = sd->name;
881 sd->entity.obj_type = MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
882 sd->entity.function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
885 EXPORT_SYMBOL(v4l2_subdev_init);
887 void v4l2_subdev_notify_event(struct v4l2_subdev *sd,
888 const struct v4l2_event *ev)
890 v4l2_event_queue(sd->devnode, ev);
891 v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, (void *)ev);
893 EXPORT_SYMBOL_GPL(v4l2_subdev_notify_event);