aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-06-12 10:15:12 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-06-21 10:07:12 -0400
commit1c1d86a1ea07506c070cfb217a009d53990bdeb0 (patch)
tree49396011dd6c6eedaf2b1d3f009f63ca5aed78a0
parentd481c581dfe43be11a17728b5c84c2d4b5beecb2 (diff)
[media] v4l2: always require v4l2_dev, rename parent to dev_parent
The last set of drivers still using the parent field of video_device instead of the v4l2_dev field have been converted, so v4l2_dev is now always set. A proper pointer to v4l2_dev is necessary these days otherwise the advanced debugging ioctls will not work when addressing sub-devices. It also ensures that the core can always go from a video_device struct to the top-level v4l2_device struct. There is still one single use case for the parent pointer: if there are multiple busses, each being the parent of one or more video nodes, and if they all share the same v4l2_device struct. In that case one still needs a parent pointer since the v4l2_device struct can only refer to a single parent device. The cx88 driver is one such case. Unfortunately, the cx88 failed to set the parent pointer since 3.6. The next patch will correct this. In order to support this use-case the parent pointer is only renamed to dev_parent, not removed altogether. It has been renamed to ensure that the compiler will catch any (possibly out-of-tree) drivers that were missed during the conversion. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Sakari Ailus <sakari.ailus@iki.fi> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/v4l2-core/v4l2-dev.c34
-rw-r--r--drivers/media/v4l2-core/v4l2-ioctl.c7
-rw-r--r--include/media/v4l2-dev.h4
3 files changed, 18 insertions, 27 deletions
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 0c061e16502e..c8859d6ff6ad 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -495,8 +495,8 @@ static const struct file_operations v4l2_fops = {
495}; 495};
496 496
497/** 497/**
498 * get_index - assign stream index number based on parent device 498 * get_index - assign stream index number based on v4l2_dev
499 * @vdev: video_device to assign index number to, vdev->parent should be assigned 499 * @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
500 * 500 *
501 * Note that when this is called the new device has not yet been registered 501 * Note that when this is called the new device has not yet been registered
502 * in the video_device array, but it was able to obtain a minor number. 502 * in the video_device array, but it was able to obtain a minor number.
@@ -514,15 +514,11 @@ static int get_index(struct video_device *vdev)
514 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES); 514 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
515 int i; 515 int i;
516 516
517 /* Some drivers do not set the parent. In that case always return 0. */
518 if (vdev->parent == NULL)
519 return 0;
520
521 bitmap_zero(used, VIDEO_NUM_DEVICES); 517 bitmap_zero(used, VIDEO_NUM_DEVICES);
522 518
523 for (i = 0; i < VIDEO_NUM_DEVICES; i++) { 519 for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
524 if (video_device[i] != NULL && 520 if (video_device[i] != NULL &&
525 video_device[i]->parent == vdev->parent) { 521 video_device[i]->v4l2_dev == vdev->v4l2_dev) {
526 set_bit(video_device[i]->index, used); 522 set_bit(video_device[i]->index, used);
527 } 523 }
528 } 524 }
@@ -775,6 +771,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
775 /* the release callback MUST be present */ 771 /* the release callback MUST be present */
776 if (WARN_ON(!vdev->release)) 772 if (WARN_ON(!vdev->release))
777 return -EINVAL; 773 return -EINVAL;
774 /* the v4l2_dev pointer MUST be present */
775 if (WARN_ON(!vdev->v4l2_dev))
776 return -EINVAL;
778 777
779 /* v4l2_fh support */ 778 /* v4l2_fh support */
780 spin_lock_init(&vdev->fh_lock); 779 spin_lock_init(&vdev->fh_lock);
@@ -802,16 +801,14 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
802 801
803 vdev->vfl_type = type; 802 vdev->vfl_type = type;
804 vdev->cdev = NULL; 803 vdev->cdev = NULL;
805 if (vdev->v4l2_dev) { 804 if (vdev->dev_parent == NULL)
806 if (vdev->v4l2_dev->dev) 805 vdev->dev_parent = vdev->v4l2_dev->dev;
807 vdev->parent = vdev->v4l2_dev->dev; 806 if (vdev->ctrl_handler == NULL)
808 if (vdev->ctrl_handler == NULL) 807 vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
809 vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler; 808 /* If the prio state pointer is NULL, then use the v4l2_device
810 /* If the prio state pointer is NULL, then use the v4l2_device 809 prio state. */
811 prio state. */ 810 if (vdev->prio == NULL)
812 if (vdev->prio == NULL) 811 vdev->prio = &vdev->v4l2_dev->prio;
813 vdev->prio = &vdev->v4l2_dev->prio;
814 }
815 812
816 /* Part 2: find a free minor, device node number and device index. */ 813 /* Part 2: find a free minor, device node number and device index. */
817#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES 814#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
@@ -896,8 +893,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
896 /* Part 4: register the device with sysfs */ 893 /* Part 4: register the device with sysfs */
897 vdev->dev.class = &video_class; 894 vdev->dev.class = &video_class;
898 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); 895 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
899 if (vdev->parent) 896 vdev->dev.parent = vdev->dev_parent;
900 vdev->dev.parent = vdev->parent;
901 dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num); 897 dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
902 ret = device_register(&vdev->dev); 898 ret = device_register(&vdev->dev);
903 if (ret < 0) { 899 if (ret < 0) {
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index c9d9f01d21bc..68e6b5e912ff 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1813,12 +1813,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
1813 p->flags |= V4L2_CHIP_FL_WRITABLE; 1813 p->flags |= V4L2_CHIP_FL_WRITABLE;
1814 if (ops->vidioc_g_register) 1814 if (ops->vidioc_g_register)
1815 p->flags |= V4L2_CHIP_FL_READABLE; 1815 p->flags |= V4L2_CHIP_FL_READABLE;
1816 if (vfd->v4l2_dev) 1816 strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1817 strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1818 else if (vfd->parent)
1819 strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name));
1820 else
1821 strlcpy(p->name, "bridge", sizeof(p->name));
1822 if (ops->vidioc_g_chip_info) 1817 if (ops->vidioc_g_chip_info)
1823 return ops->vidioc_g_chip_info(file, fh, arg); 1818 return ops->vidioc_g_chip_info(file, fh, arg);
1824 if (p->match.addr) 1819 if (p->match.addr)
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index b2c3776a1cff..c768c9f8abc2 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -96,9 +96,9 @@ struct video_device
96 struct device dev; /* v4l device */ 96 struct device dev; /* v4l device */
97 struct cdev *cdev; /* character device */ 97 struct cdev *cdev; /* character device */
98 98
99 /* Set either parent or v4l2_dev if your driver uses v4l2_device */
100 struct device *parent; /* device parent */
101 struct v4l2_device *v4l2_dev; /* v4l2_device parent */ 99 struct v4l2_device *v4l2_dev; /* v4l2_device parent */
100 /* Only set parent if that can't be deduced from v4l2_dev */
101 struct device *dev_parent; /* device parent */
102 102
103 /* Control handler associated with this device node. May be NULL. */ 103 /* Control handler associated with this device node. May be NULL. */
104 struct v4l2_ctrl_handler *ctrl_handler; 104 struct v4l2_ctrl_handler *ctrl_handler;