aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/video4linux/v4l2-framework.txt8
-rw-r--r--drivers/media/video/v4l2-dev.c38
2 files changed, 24 insertions, 22 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index cb6c7eb51472..38b3716d8643 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -486,14 +486,14 @@ VFL_TYPE_RADIO: radioX for radio tuners
486VFL_TYPE_VTX: vtxX for teletext devices (deprecated, don't use) 486VFL_TYPE_VTX: vtxX for teletext devices (deprecated, don't use)
487 487
488The last argument gives you a certain amount of control over the device 488The last argument gives you a certain amount of control over the device
489kernel number used (i.e. the X in videoX). Normally you will pass -1 to 489device node number used (i.e. the X in videoX). Normally you will pass -1 to
490let the v4l2 framework pick the first free number. But if a driver creates 490let the v4l2 framework pick the first free number. But if a driver creates
491many devices, then it can be useful to have different video devices in 491many devices, then it can be useful to have different video devices in
492separate ranges. For example, video capture devices start at 0, video 492separate ranges. For example, video capture devices start at 0, video
493output devices start at 16. 493output devices start at 16.
494 494
495So you can use the last argument to specify a minimum kernel number and 495So you can use the last argument to specify a minimum device node number
496the v4l2 framework will try to pick the first free number that is equal 496and the v4l2 framework will try to pick the first free number that is equal
497or higher to what you passed. If that fails, then it will just pick the 497or higher to what you passed. If that fails, then it will just pick the
498first free number. 498first free number.
499 499
@@ -513,7 +513,7 @@ After the device was successfully registered, then you can use these fields:
513 513
514- vfl_type: the device type passed to video_register_device. 514- vfl_type: the device type passed to video_register_device.
515- minor: the assigned device minor number. 515- minor: the assigned device minor number.
516- num: the device kernel number (i.e. the X in videoX). 516- num: the device node number (i.e. the X in videoX).
517- index: the device index number. 517- index: the device index number.
518 518
519If the registration failed, then you need to call video_device_release() 519If the registration failed, then you need to call video_device_release()
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 1219721894a1..4e61c77b7634 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -66,7 +66,7 @@ static struct device_attribute video_device_attrs[] = {
66 */ 66 */
67static struct video_device *video_device[VIDEO_NUM_DEVICES]; 67static struct video_device *video_device[VIDEO_NUM_DEVICES];
68static DEFINE_MUTEX(videodev_lock); 68static DEFINE_MUTEX(videodev_lock);
69static DECLARE_BITMAP(video_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES); 69static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
70 70
71struct video_device *video_device_alloc(void) 71struct video_device *video_device_alloc(void)
72{ 72{
@@ -119,8 +119,8 @@ static void v4l2_device_release(struct device *cd)
119 the release() callback. */ 119 the release() callback. */
120 vdev->cdev = NULL; 120 vdev->cdev = NULL;
121 121
122 /* Mark minor as free */ 122 /* Mark device node number as free */
123 clear_bit(vdev->num, video_nums[vdev->vfl_type]); 123 clear_bit(vdev->num, devnode_nums[vdev->vfl_type]);
124 124
125 mutex_unlock(&videodev_lock); 125 mutex_unlock(&videodev_lock);
126 126
@@ -338,13 +338,14 @@ static int get_index(struct video_device *vdev)
338 * video_register_device - register video4linux devices 338 * video_register_device - register video4linux devices
339 * @vdev: video device structure we want to register 339 * @vdev: video device structure we want to register
340 * @type: type of device to register 340 * @type: type of device to register
341 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ... 341 * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...
342 * -1 == first free) 342 * -1 == first free)
343 * 343 *
344 * The registration code assigns minor numbers based on the type 344 * The registration code assigns minor numbers and device node numbers
345 * requested. -ENFILE is returned in all the device slots for this 345 * based on the requested type and registers the new device node with
346 * category are full. If not then the minor field is set and the 346 * the kernel.
347 * driver initialize function is called (if non %NULL). 347 * An error is returned if no free minor or device node number could be
348 * found, or if the registration of the device node failed.
348 * 349 *
349 * Zero is returned on success. 350 * Zero is returned on success.
350 * 351 *
@@ -401,7 +402,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
401 if (vdev->v4l2_dev && vdev->v4l2_dev->dev) 402 if (vdev->v4l2_dev && vdev->v4l2_dev->dev)
402 vdev->parent = vdev->v4l2_dev->dev; 403 vdev->parent = vdev->v4l2_dev->dev;
403 404
404 /* Part 2: find a free minor, kernel number and device index. */ 405 /* Part 2: find a free minor, device node number and device index. */
405#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES 406#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
406 /* Keep the ranges for the first four types for historical 407 /* Keep the ranges for the first four types for historical
407 * reasons. 408 * reasons.
@@ -432,21 +433,22 @@ int video_register_device(struct video_device *vdev, int type, int nr)
432 } 433 }
433#endif 434#endif
434 435
435 /* Pick a minor number */ 436 /* Pick a device node number */
436 mutex_lock(&videodev_lock); 437 mutex_lock(&videodev_lock);
437 nr = find_next_zero_bit(video_nums[type], minor_cnt, nr == -1 ? 0 : nr); 438 nr = find_next_zero_bit(devnode_nums[type], minor_cnt, nr == -1 ? 0 : nr);
438 if (nr == minor_cnt) 439 if (nr == minor_cnt)
439 nr = find_first_zero_bit(video_nums[type], minor_cnt); 440 nr = find_first_zero_bit(devnode_nums[type], minor_cnt);
440 if (nr == minor_cnt) { 441 if (nr == minor_cnt) {
441 printk(KERN_ERR "could not get a free kernel number\n"); 442 printk(KERN_ERR "could not get a free device node number\n");
442 mutex_unlock(&videodev_lock); 443 mutex_unlock(&videodev_lock);
443 return -ENFILE; 444 return -ENFILE;
444 } 445 }
445#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES 446#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
446 /* 1-on-1 mapping of kernel number to minor number */ 447 /* 1-on-1 mapping of device node number to minor number */
447 i = nr; 448 i = nr;
448#else 449#else
449 /* The kernel number and minor numbers are independent */ 450 /* The device node number and minor numbers are independent, so
451 we just find the first free minor number. */
450 for (i = 0; i < VIDEO_NUM_DEVICES; i++) 452 for (i = 0; i < VIDEO_NUM_DEVICES; i++)
451 if (video_device[i] == NULL) 453 if (video_device[i] == NULL)
452 break; 454 break;
@@ -458,7 +460,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
458#endif 460#endif
459 vdev->minor = i + minor_offset; 461 vdev->minor = i + minor_offset;
460 vdev->num = nr; 462 vdev->num = nr;
461 set_bit(nr, video_nums[type]); 463 set_bit(nr, devnode_nums[type]);
462 /* Should not happen since we thought this minor was free */ 464 /* Should not happen since we thought this minor was free */
463 WARN_ON(video_device[vdev->minor] != NULL); 465 WARN_ON(video_device[vdev->minor] != NULL);
464 vdev->index = get_index(vdev); 466 vdev->index = get_index(vdev);
@@ -492,7 +494,7 @@ int video_register_device(struct video_device *vdev, int type, int nr)
492 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); 494 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
493 if (vdev->parent) 495 if (vdev->parent)
494 vdev->dev.parent = vdev->parent; 496 vdev->dev.parent = vdev->parent;
495 dev_set_name(&vdev->dev, "%s%d", name_base, nr); 497 dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
496 ret = device_register(&vdev->dev); 498 ret = device_register(&vdev->dev);
497 if (ret < 0) { 499 if (ret < 0) {
498 printk(KERN_ERR "%s: device_register failed\n", __func__); 500 printk(KERN_ERR "%s: device_register failed\n", __func__);
@@ -512,7 +514,7 @@ cleanup:
512 mutex_lock(&videodev_lock); 514 mutex_lock(&videodev_lock);
513 if (vdev->cdev) 515 if (vdev->cdev)
514 cdev_del(vdev->cdev); 516 cdev_del(vdev->cdev);
515 clear_bit(vdev->num, video_nums[type]); 517 clear_bit(vdev->num, devnode_nums[type]);
516 mutex_unlock(&videodev_lock); 518 mutex_unlock(&videodev_lock);
517 /* Mark this video device as never having been registered. */ 519 /* Mark this video device as never having been registered. */
518 vdev->minor = -1; 520 vdev->minor = -1;