Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164243
b: refs/heads/master
c: 22e2212
h: refs/heads/master
i:
  164241: 533c1d2
  164239: 5a9a3da
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Sep 19, 2009
1 parent c7241fd commit 768c187
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7ae0cd9bc793e16d8d68df3c17c601732cc1d3c7
refs/heads/master: 22e221258b56cc1a4dc5a9fb2c26f4d6ed9dde81
8 changes: 4 additions & 4 deletions trunk/Documentation/video4linux/v4l2-framework.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ VFL_TYPE_RADIO: radioX for radio tuners
VFL_TYPE_VTX: vtxX for teletext devices (deprecated, don't use)

The last argument gives you a certain amount of control over the device
kernel number used (i.e. the X in videoX). Normally you will pass -1 to
device node number used (i.e. the X in videoX). Normally you will pass -1 to
let the v4l2 framework pick the first free number. But if a driver creates
many devices, then it can be useful to have different video devices in
separate ranges. For example, video capture devices start at 0, video
output devices start at 16.

So you can use the last argument to specify a minimum kernel number and
the v4l2 framework will try to pick the first free number that is equal
So you can use the last argument to specify a minimum device node number
and the v4l2 framework will try to pick the first free number that is equal
or higher to what you passed. If that fails, then it will just pick the
first free number.

Expand All @@ -513,7 +513,7 @@ After the device was successfully registered, then you can use these fields:

- vfl_type: the device type passed to video_register_device.
- minor: the assigned device minor number.
- num: the device kernel number (i.e. the X in videoX).
- num: the device node number (i.e. the X in videoX).
- index: the device index number.

If the registration failed, then you need to call video_device_release()
Expand Down
38 changes: 20 additions & 18 deletions trunk/drivers/media/video/v4l2-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static struct device_attribute video_device_attrs[] = {
*/
static struct video_device *video_device[VIDEO_NUM_DEVICES];
static DEFINE_MUTEX(videodev_lock);
static DECLARE_BITMAP(video_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);

struct video_device *video_device_alloc(void)
{
Expand Down Expand Up @@ -119,8 +119,8 @@ static void v4l2_device_release(struct device *cd)
the release() callback. */
vdev->cdev = NULL;

/* Mark minor as free */
clear_bit(vdev->num, video_nums[vdev->vfl_type]);
/* Mark device node number as free */
clear_bit(vdev->num, devnode_nums[vdev->vfl_type]);

mutex_unlock(&videodev_lock);

Expand Down Expand Up @@ -338,13 +338,14 @@ static int get_index(struct video_device *vdev)
* video_register_device - register video4linux devices
* @vdev: video device structure we want to register
* @type: type of device to register
* @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
* @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...
* -1 == first free)
*
* The registration code assigns minor numbers based on the type
* requested. -ENFILE is returned in all the device slots for this
* category are full. If not then the minor field is set and the
* driver initialize function is called (if non %NULL).
* The registration code assigns minor numbers and device node numbers
* based on the requested type and registers the new device node with
* the kernel.
* An error is returned if no free minor or device node number could be
* found, or if the registration of the device node failed.
*
* Zero is returned on success.
*
Expand Down Expand Up @@ -401,7 +402,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
if (vdev->v4l2_dev && vdev->v4l2_dev->dev)
vdev->parent = vdev->v4l2_dev->dev;

/* Part 2: find a free minor, kernel number and device index. */
/* Part 2: find a free minor, device node number and device index. */
#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
/* Keep the ranges for the first four types for historical
* reasons.
Expand Down Expand Up @@ -432,21 +433,22 @@ int video_register_device(struct video_device *vdev, int type, int nr)
}
#endif

/* Pick a minor number */
/* Pick a device node number */
mutex_lock(&videodev_lock);
nr = find_next_zero_bit(video_nums[type], minor_cnt, nr == -1 ? 0 : nr);
nr = find_next_zero_bit(devnode_nums[type], minor_cnt, nr == -1 ? 0 : nr);
if (nr == minor_cnt)
nr = find_first_zero_bit(video_nums[type], minor_cnt);
nr = find_first_zero_bit(devnode_nums[type], minor_cnt);
if (nr == minor_cnt) {
printk(KERN_ERR "could not get a free kernel number\n");
printk(KERN_ERR "could not get a free device node number\n");
mutex_unlock(&videodev_lock);
return -ENFILE;
}
#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
/* 1-on-1 mapping of kernel number to minor number */
/* 1-on-1 mapping of device node number to minor number */
i = nr;
#else
/* The kernel number and minor numbers are independent */
/* The device node number and minor numbers are independent, so
we just find the first free minor number. */
for (i = 0; i < VIDEO_NUM_DEVICES; i++)
if (video_device[i] == NULL)
break;
Expand All @@ -458,7 +460,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
#endif
vdev->minor = i + minor_offset;
vdev->num = nr;
set_bit(nr, video_nums[type]);
set_bit(nr, devnode_nums[type]);
/* Should not happen since we thought this minor was free */
WARN_ON(video_device[vdev->minor] != NULL);
vdev->index = get_index(vdev);
Expand Down Expand Up @@ -492,7 +494,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
if (vdev->parent)
vdev->dev.parent = vdev->parent;
dev_set_name(&vdev->dev, "%s%d", name_base, nr);
dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
ret = device_register(&vdev->dev);
if (ret < 0) {
printk(KERN_ERR "%s: device_register failed\n", __func__);
Expand All @@ -512,7 +514,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
mutex_lock(&videodev_lock);
if (vdev->cdev)
cdev_del(vdev->cdev);
clear_bit(vdev->num, video_nums[type]);
clear_bit(vdev->num, devnode_nums[type]);
mutex_unlock(&videodev_lock);
/* Mark this video device as never having been registered. */
vdev->minor = -1;
Expand Down

0 comments on commit 768c187

Please sign in to comment.