aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/video4linux/v4l2-framework.txt17
-rw-r--r--drivers/media/video/v4l2-dev.c55
-rw-r--r--include/media/v4l2-dev.h2
3 files changed, 20 insertions, 54 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index e395a9cdc533..cb6c7eb51472 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -500,17 +500,11 @@ first free number.
500Whenever a device node is created some attributes are also created for you. 500Whenever a device node is created some attributes are also created for you.
501If you look in /sys/class/video4linux you see the devices. Go into e.g. 501If you look in /sys/class/video4linux you see the devices. Go into e.g.
502video0 and you will see 'name' and 'index' attributes. The 'name' attribute 502video0 and you will see 'name' and 'index' attributes. The 'name' attribute
503is the 'name' field of the video_device struct. The 'index' attribute is 503is the 'name' field of the video_device struct.
504a device node index that can be assigned by the driver, or that is calculated
505for you.
506
507If you call video_register_device(), then the index is just increased by
5081 for each device node you register. The first video device node you register
509always starts off with 0.
510 504
511Alternatively you can call video_register_device_index() which is identical 505The 'index' attribute is the index of the device node: for each call to
512to video_register_device(), but with an extra index argument. Here you can 506video_register_device() the index is just increased by 1. The first video
513pass a specific index value (between 0 and 31) that should be used. 507device node you register always starts with index 0.
514 508
515Users can setup udev rules that utilize the index attribute to make fancy 509Users can setup udev rules that utilize the index attribute to make fancy
516device names (e.g. 'mpegX' for MPEG video capture device nodes). 510device names (e.g. 'mpegX' for MPEG video capture device nodes).
@@ -520,8 +514,7 @@ After the device was successfully registered, then you can use these fields:
520- vfl_type: the device type passed to video_register_device. 514- vfl_type: the device type passed to video_register_device.
521- minor: the assigned device minor number. 515- minor: the assigned device minor number.
522- num: the device kernel number (i.e. the X in videoX). 516- num: the device kernel number (i.e. the X in videoX).
523- index: the device index number (calculated or set explicitly using 517- index: the device index number.
524 video_register_device_index).
525 518
526If the registration failed, then you need to call video_device_release() 519If the registration failed, then you need to call video_device_release()
527to free the allocated video_device struct, or free your own struct if the 520to free the allocated video_device struct, or free your own struct if the
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index a7f1b69a7dab..1219721894a1 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -299,32 +299,28 @@ static const struct file_operations v4l2_fops = {
299}; 299};
300 300
301/** 301/**
302 * get_index - assign stream number based on parent device 302 * get_index - assign stream index number based on parent device
303 * @vdev: video_device to assign index number to, vdev->parent should be assigned 303 * @vdev: video_device to assign index number to, vdev->parent should be assigned
304 * @num: -1 if auto assign, requested number otherwise
305 * 304 *
306 * Note that when this is called the new device has not yet been registered 305 * Note that when this is called the new device has not yet been registered
307 * in the video_device array. 306 * in the video_device array, but it was able to obtain a minor number.
308 * 307 *
309 * Returns -ENFILE if num is already in use, a free index number if 308 * This means that we can always obtain a free stream index number since
310 * successful. 309 * the worst case scenario is that there are VIDEO_NUM_DEVICES - 1 slots in
310 * use of the video_device array.
311 *
312 * Returns a free index number.
311 */ 313 */
312static int get_index(struct video_device *vdev, int num) 314static int get_index(struct video_device *vdev)
313{ 315{
314 /* This can be static since this function is called with the global 316 /* This can be static since this function is called with the global
315 videodev_lock held. */ 317 videodev_lock held. */
316 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES); 318 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
317 int i; 319 int i;
318 320
319 if (num >= VIDEO_NUM_DEVICES) { 321 /* Some drivers do not set the parent. In that case always return 0. */
320 printk(KERN_ERR "videodev: %s num is too large\n", __func__);
321 return -EINVAL;
322 }
323
324 /* Some drivers do not set the parent. In that case always return
325 num or 0. */
326 if (vdev->parent == NULL) 322 if (vdev->parent == NULL)
327 return num >= 0 ? num : 0; 323 return 0;
328 324
329 bitmap_zero(used, VIDEO_NUM_DEVICES); 325 bitmap_zero(used, VIDEO_NUM_DEVICES);
330 326
@@ -335,30 +331,15 @@ static int get_index(struct video_device *vdev, int num)
335 } 331 }
336 } 332 }
337 333
338 if (num >= 0) { 334 return find_first_zero_bit(used, VIDEO_NUM_DEVICES);
339 if (test_bit(num, used))
340 return -ENFILE;
341 return num;
342 }
343
344 i = find_first_zero_bit(used, VIDEO_NUM_DEVICES);
345 return i == VIDEO_NUM_DEVICES ? -ENFILE : i;
346} 335}
347 336
348int video_register_device(struct video_device *vdev, int type, int nr)
349{
350 return video_register_device_index(vdev, type, nr, -1);
351}
352EXPORT_SYMBOL(video_register_device);
353
354/** 337/**
355 * video_register_device_index - register video4linux devices 338 * video_register_device - register video4linux devices
356 * @vdev: video device structure we want to register 339 * @vdev: video device structure we want to register
357 * @type: type of device to register 340 * @type: type of device to register
358 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ... 341 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
359 * -1 == first free) 342 * -1 == first free)
360 * @index: stream number based on parent device;
361 * -1 if auto assign, requested number otherwise
362 * 343 *
363 * The registration code assigns minor numbers based on the type 344 * The registration code assigns minor numbers based on the type
364 * requested. -ENFILE is returned in all the device slots for this 345 * requested. -ENFILE is returned in all the device slots for this
@@ -377,8 +358,7 @@ EXPORT_SYMBOL(video_register_device);
377 * 358 *
378 * %VFL_TYPE_RADIO - A radio card 359 * %VFL_TYPE_RADIO - A radio card
379 */ 360 */
380int video_register_device_index(struct video_device *vdev, int type, int nr, 361int video_register_device(struct video_device *vdev, int type, int nr)
381 int index)
382{ 362{
383 int i = 0; 363 int i = 0;
384 int ret; 364 int ret;
@@ -481,14 +461,9 @@ int video_register_device_index(struct video_device *vdev, int type, int nr,
481 set_bit(nr, video_nums[type]); 461 set_bit(nr, video_nums[type]);
482 /* Should not happen since we thought this minor was free */ 462 /* Should not happen since we thought this minor was free */
483 WARN_ON(video_device[vdev->minor] != NULL); 463 WARN_ON(video_device[vdev->minor] != NULL);
484 ret = vdev->index = get_index(vdev, index); 464 vdev->index = get_index(vdev);
485 mutex_unlock(&videodev_lock); 465 mutex_unlock(&videodev_lock);
486 466
487 if (ret < 0) {
488 printk(KERN_ERR "%s: get_index failed\n", __func__);
489 goto cleanup;
490 }
491
492 /* Part 3: Initialize the character device */ 467 /* Part 3: Initialize the character device */
493 vdev->cdev = cdev_alloc(); 468 vdev->cdev = cdev_alloc();
494 if (vdev->cdev == NULL) { 469 if (vdev->cdev == NULL) {
@@ -543,7 +518,7 @@ cleanup:
543 vdev->minor = -1; 518 vdev->minor = -1;
544 return ret; 519 return ret;
545} 520}
546EXPORT_SYMBOL(video_register_device_index); 521EXPORT_SYMBOL(video_register_device);
547 522
548/** 523/**
549 * video_unregister_device - unregister a video4linux device 524 * video_unregister_device - unregister a video4linux device
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 2058dd45e915..255f6442b635 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -100,8 +100,6 @@ struct video_device
100 100
101 Also note that vdev->minor is set to -1 if the registration failed. */ 101 Also note that vdev->minor is set to -1 if the registration failed. */
102int __must_check video_register_device(struct video_device *vdev, int type, int nr); 102int __must_check video_register_device(struct video_device *vdev, int type, int nr);
103int __must_check video_register_device_index(struct video_device *vdev,
104 int type, int nr, int index);
105 103
106/* Unregister video devices. Will do nothing if vdev == NULL or 104/* Unregister video devices. Will do nothing if vdev == NULL or
107 vdev->minor < 0. */ 105 vdev->minor < 0. */