Commit 1c1d86a1 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[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: default avatarHans Verkuil <hans.verkuil@cisco.com>
Acked-by: default avatarSakari Ailus <sakari.ailus@iki.fi>
Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent d481c581
...@@ -495,8 +495,8 @@ static const struct file_operations v4l2_fops = { ...@@ -495,8 +495,8 @@ static const struct file_operations v4l2_fops = {
}; };
/** /**
* get_index - assign stream index number based on parent device * get_index - assign stream index number based on v4l2_dev
* @vdev: video_device to assign index number to, vdev->parent should be assigned * @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
* *
* Note that when this is called the new device has not yet been registered * Note that when this is called the new device has not yet been registered
* in the video_device array, but it was able to obtain a minor number. * 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,15 +514,11 @@ static int get_index(struct video_device *vdev)
static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES); static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
int i; int i;
/* Some drivers do not set the parent. In that case always return 0. */
if (vdev->parent == NULL)
return 0;
bitmap_zero(used, VIDEO_NUM_DEVICES); bitmap_zero(used, VIDEO_NUM_DEVICES);
for (i = 0; i < VIDEO_NUM_DEVICES; i++) { for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
if (video_device[i] != NULL && if (video_device[i] != NULL &&
video_device[i]->parent == vdev->parent) { video_device[i]->v4l2_dev == vdev->v4l2_dev) {
set_bit(video_device[i]->index, used); set_bit(video_device[i]->index, used);
} }
} }
...@@ -775,6 +771,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr, ...@@ -775,6 +771,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
/* the release callback MUST be present */ /* the release callback MUST be present */
if (WARN_ON(!vdev->release)) if (WARN_ON(!vdev->release))
return -EINVAL; return -EINVAL;
/* the v4l2_dev pointer MUST be present */
if (WARN_ON(!vdev->v4l2_dev))
return -EINVAL;
/* v4l2_fh support */ /* v4l2_fh support */
spin_lock_init(&vdev->fh_lock); spin_lock_init(&vdev->fh_lock);
...@@ -802,16 +801,14 @@ int __video_register_device(struct video_device *vdev, int type, int nr, ...@@ -802,16 +801,14 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
vdev->vfl_type = type; vdev->vfl_type = type;
vdev->cdev = NULL; vdev->cdev = NULL;
if (vdev->v4l2_dev) { if (vdev->dev_parent == NULL)
if (vdev->v4l2_dev->dev) vdev->dev_parent = vdev->v4l2_dev->dev;
vdev->parent = vdev->v4l2_dev->dev; if (vdev->ctrl_handler == NULL)
if (vdev->ctrl_handler == NULL) vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler; /* If the prio state pointer is NULL, then use the v4l2_device
/* If the prio state pointer is NULL, then use the v4l2_device prio state. */
prio state. */ if (vdev->prio == NULL)
if (vdev->prio == NULL) vdev->prio = &vdev->v4l2_dev->prio;
vdev->prio = &vdev->v4l2_dev->prio;
}
/* Part 2: find a free minor, device node number and device index. */ /* Part 2: find a free minor, device node number and device index. */
#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
...@@ -896,8 +893,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr, ...@@ -896,8 +893,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
/* Part 4: register the device with sysfs */ /* Part 4: register the device with sysfs */
vdev->dev.class = &video_class; vdev->dev.class = &video_class;
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
if (vdev->parent) vdev->dev.parent = vdev->dev_parent;
vdev->dev.parent = vdev->parent;
dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num); dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
ret = device_register(&vdev->dev); ret = device_register(&vdev->dev);
if (ret < 0) { if (ret < 0) {
......
...@@ -1813,12 +1813,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops, ...@@ -1813,12 +1813,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
p->flags |= V4L2_CHIP_FL_WRITABLE; p->flags |= V4L2_CHIP_FL_WRITABLE;
if (ops->vidioc_g_register) if (ops->vidioc_g_register)
p->flags |= V4L2_CHIP_FL_READABLE; p->flags |= V4L2_CHIP_FL_READABLE;
if (vfd->v4l2_dev) strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
else if (vfd->parent)
strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name));
else
strlcpy(p->name, "bridge", sizeof(p->name));
if (ops->vidioc_g_chip_info) if (ops->vidioc_g_chip_info)
return ops->vidioc_g_chip_info(file, fh, arg); return ops->vidioc_g_chip_info(file, fh, arg);
if (p->match.addr) if (p->match.addr)
......
...@@ -96,9 +96,9 @@ struct video_device ...@@ -96,9 +96,9 @@ struct video_device
struct device dev; /* v4l device */ struct device dev; /* v4l device */
struct cdev *cdev; /* character device */ struct cdev *cdev; /* character device */
/* Set either parent or v4l2_dev if your driver uses v4l2_device */
struct device *parent; /* device parent */
struct v4l2_device *v4l2_dev; /* v4l2_device parent */ struct v4l2_device *v4l2_dev; /* v4l2_device parent */
/* Only set parent if that can't be deduced from v4l2_dev */
struct device *dev_parent; /* device parent */
/* Control handler associated with this device node. May be NULL. */ /* Control handler associated with this device node. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler; struct v4l2_ctrl_handler *ctrl_handler;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment