aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/video4linux/v4l2-framework.txt22
-rw-r--r--drivers/media/video/cx18/cx18-streams.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c2
-rw-r--r--drivers/media/video/v4l2-dev.c20
-rw-r--r--include/media/v4l2-dev.h4
5 files changed, 41 insertions, 9 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index 38b3716d8643..b806edaf3e75 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -486,17 +486,27 @@ 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
489device node 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
490let the v4l2 framework pick the first free number. But if a driver creates 490to let the v4l2 framework pick the first free number. But sometimes users
491many devices, then it can be useful to have different video devices in 491want to select a specific node number. It is common that drivers allow
492separate ranges. For example, video capture devices start at 0, video 492the user to select a specific device node number through a driver module
493output devices start at 16. 493option. That number is then passed to this function and video_register_device
494 494will attempt to select that device node number. If that number was already
495in use, then the next free device node number will be selected and it
496will send a warning to the kernel log.
497
498Another use-case is if a driver creates many devices. In that case it can
499be useful to place different video devices in separate ranges. For example,
500video capture devices start at 0, video output devices start at 16.
495So you can use the last argument to specify a minimum device node number 501So you can use the last argument to specify a minimum device node number
496and the v4l2 framework will try to pick the first free number that is equal 502and 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 503or higher to what you passed. If that fails, then it will just pick the
498first free number. 504first free number.
499 505
506Since in this case you do not care about a warning about not being able
507to select the specified device node number, you can call the function
508video_register_device_no_warn() instead.
509
500Whenever a device node is created some attributes are also created for you. 510Whenever 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. 511If 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 512video0 and you will see 'name' and 'index' attributes. The 'name' attribute
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 6c988b95adc6..7df513a2dba8 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -245,7 +245,7 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
245 video_set_drvdata(s->video_dev, s); 245 video_set_drvdata(s->video_dev, s);
246 246
247 /* Register device. First try the desired minor, then any free one. */ 247 /* Register device. First try the desired minor, then any free one. */
248 ret = video_register_device(s->video_dev, vfl_type, num); 248 ret = video_register_device_no_warn(s->video_dev, vfl_type, num);
249 if (ret < 0) { 249 if (ret < 0) {
250 CX18_ERR("Couldn't register v4l2 device for %s (device node number %d)\n", 250 CX18_ERR("Couldn't register v4l2 device for %s (device node number %d)\n",
251 s->name, num); 251 s->name, num);
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 23400035240a..67699e3f2aaa 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -261,7 +261,7 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
261 video_set_drvdata(s->vdev, s); 261 video_set_drvdata(s->vdev, s);
262 262
263 /* Register device. First try the desired minor, then any free one. */ 263 /* Register device. First try the desired minor, then any free one. */
264 if (video_register_device(s->vdev, vfl_type, num)) { 264 if (video_register_device_no_warn(s->vdev, vfl_type, num)) {
265 IVTV_ERR("Couldn't register v4l2 device for %s (device node number %d)\n", 265 IVTV_ERR("Couldn't register v4l2 device for %s (device node number %d)\n",
266 s->name, num); 266 s->name, num);
267 video_device_release(s->vdev); 267 video_device_release(s->vdev);
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 4715f08157bc..500cbe9891ac 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -382,6 +382,8 @@ static int get_index(struct video_device *vdev)
382 * @type: type of device to register 382 * @type: type of device to register
383 * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ... 383 * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...
384 * -1 == first free) 384 * -1 == first free)
385 * @warn_if_nr_in_use: warn if the desired device node number
386 * was already in use and another number was chosen instead.
385 * 387 *
386 * The registration code assigns minor numbers and device node numbers 388 * The registration code assigns minor numbers and device node numbers
387 * based on the requested type and registers the new device node with 389 * based on the requested type and registers the new device node with
@@ -401,7 +403,8 @@ static int get_index(struct video_device *vdev)
401 * 403 *
402 * %VFL_TYPE_RADIO - A radio card 404 * %VFL_TYPE_RADIO - A radio card
403 */ 405 */
404int video_register_device(struct video_device *vdev, int type, int nr) 406static int __video_register_device(struct video_device *vdev, int type, int nr,
407 int warn_if_nr_in_use)
405{ 408{
406 int i = 0; 409 int i = 0;
407 int ret; 410 int ret;
@@ -547,6 +550,10 @@ int video_register_device(struct video_device *vdev, int type, int nr)
547 reference to the device goes away. */ 550 reference to the device goes away. */
548 vdev->dev.release = v4l2_device_release; 551 vdev->dev.release = v4l2_device_release;
549 552
553 if (nr != -1 && nr != vdev->num && warn_if_nr_in_use)
554 printk(KERN_WARNING "%s: requested %s%d, got %s%d\n",
555 __func__, name_base, nr, name_base, vdev->num);
556
550 /* Part 5: Activate this minor. The char device can now be used. */ 557 /* Part 5: Activate this minor. The char device can now be used. */
551 mutex_lock(&videodev_lock); 558 mutex_lock(&videodev_lock);
552 video_device[vdev->minor] = vdev; 559 video_device[vdev->minor] = vdev;
@@ -563,8 +570,19 @@ cleanup:
563 vdev->minor = -1; 570 vdev->minor = -1;
564 return ret; 571 return ret;
565} 572}
573
574int video_register_device(struct video_device *vdev, int type, int nr)
575{
576 return __video_register_device(vdev, type, nr, 1);
577}
566EXPORT_SYMBOL(video_register_device); 578EXPORT_SYMBOL(video_register_device);
567 579
580int video_register_device_no_warn(struct video_device *vdev, int type, int nr)
581{
582 return __video_register_device(vdev, type, nr, 0);
583}
584EXPORT_SYMBOL(video_register_device_no_warn);
585
568/** 586/**
569 * video_unregister_device - unregister a video4linux device 587 * video_unregister_device - unregister a video4linux device
570 * @vdev: the device to unregister 588 * @vdev: the device to unregister
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 255f6442b635..73c9867d744c 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -101,6 +101,10 @@ struct video_device
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);
103 103
104/* Same as video_register_device, but no warning is issued if the desired
105 device node number was already in use. */
106int __must_check video_register_device_no_warn(struct video_device *vdev, int type, int nr);
107
104/* Unregister video devices. Will do nothing if vdev == NULL or 108/* Unregister video devices. Will do nothing if vdev == NULL or
105 vdev->minor < 0. */ 109 vdev->minor < 0. */
106void video_unregister_device(struct video_device *vdev); 110void video_unregister_device(struct video_device *vdev);