diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2009-12-09 06:40:10 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 03:53:19 -0400 |
commit | 2c0ab67be1b4197a4effac89bb0604832e38be8d (patch) | |
tree | 033b1d2c6ae25e05f1f46f3c2e7bdb504c359ad3 /Documentation/video4linux | |
parent | 95db3a60e0652a52df145aacade1a88c5acef659 (diff) |
[media] v4l: Make video_device inherit from media_entity
V4L2 devices are media entities. As such they need to inherit from
(include) the media_entity structure.
When registering/unregistering the device, the media entity is
automatically registered/unregistered. The entity is acquired on device
open and released on device close.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'Documentation/video4linux')
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index 7de55cfae04e..062708169def 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt | |||
@@ -71,6 +71,10 @@ sub-device instances, the video_device struct stores V4L2 device node data | |||
71 | and in the future a v4l2_fh struct will keep track of filehandle instances | 71 | and in the future a v4l2_fh struct will keep track of filehandle instances |
72 | (this is not yet implemented). | 72 | (this is not yet implemented). |
73 | 73 | ||
74 | The V4L2 framework also optionally integrates with the media framework. If a | ||
75 | driver sets the struct v4l2_device mdev field, sub-devices and video nodes | ||
76 | will automatically appear in the media framework as entities. | ||
77 | |||
74 | 78 | ||
75 | struct v4l2_device | 79 | struct v4l2_device |
76 | ------------------ | 80 | ------------------ |
@@ -84,11 +88,14 @@ You must register the device instance: | |||
84 | v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); | 88 | v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); |
85 | 89 | ||
86 | Registration will initialize the v4l2_device struct. If the dev->driver_data | 90 | Registration will initialize the v4l2_device struct. If the dev->driver_data |
87 | field is NULL, it will be linked to v4l2_dev. Drivers that use the media | 91 | field is NULL, it will be linked to v4l2_dev. |
88 | device framework in addition to the V4L2 framework need to set | 92 | |
93 | Drivers that want integration with the media device framework need to set | ||
89 | dev->driver_data manually to point to the driver-specific device structure | 94 | dev->driver_data manually to point to the driver-specific device structure |
90 | that embed the struct v4l2_device instance. This is achieved by a | 95 | that embed the struct v4l2_device instance. This is achieved by a |
91 | dev_set_drvdata() call before registering the V4L2 device instance. | 96 | dev_set_drvdata() call before registering the V4L2 device instance. They must |
97 | also set the struct v4l2_device mdev field to point to a properly initialized | ||
98 | and registered media_device instance. | ||
92 | 99 | ||
93 | If v4l2_dev->name is empty then it will be set to a value derived from dev | 100 | If v4l2_dev->name is empty then it will be set to a value derived from dev |
94 | (driver name followed by the bus_id, to be precise). If you set it up before | 101 | (driver name followed by the bus_id, to be precise). If you set it up before |
@@ -530,6 +537,21 @@ If you use v4l2_ioctl_ops, then you should set either .unlocked_ioctl or | |||
530 | The v4l2_file_operations struct is a subset of file_operations. The main | 537 | The v4l2_file_operations struct is a subset of file_operations. The main |
531 | difference is that the inode argument is omitted since it is never used. | 538 | difference is that the inode argument is omitted since it is never used. |
532 | 539 | ||
540 | If integration with the media framework is needed, you must initialize the | ||
541 | media_entity struct embedded in the video_device struct (entity field) by | ||
542 | calling media_entity_init(): | ||
543 | |||
544 | struct media_pad *pad = &my_vdev->pad; | ||
545 | int err; | ||
546 | |||
547 | err = media_entity_init(&vdev->entity, 1, pad, 0); | ||
548 | |||
549 | The pads array must have been previously initialized. There is no need to | ||
550 | manually set the struct media_entity type and name fields. | ||
551 | |||
552 | A reference to the entity will be automatically acquired/released when the | ||
553 | video device is opened/closed. | ||
554 | |||
533 | v4l2_file_operations and locking | 555 | v4l2_file_operations and locking |
534 | -------------------------------- | 556 | -------------------------------- |
535 | 557 | ||
@@ -559,6 +581,9 @@ for you. | |||
559 | return err; | 581 | return err; |
560 | } | 582 | } |
561 | 583 | ||
584 | If the v4l2_device parent device has a non-NULL mdev field, the video device | ||
585 | entity will be automatically registered with the media device. | ||
586 | |||
562 | Which device is registered depends on the type argument. The following | 587 | Which device is registered depends on the type argument. The following |
563 | types exist: | 588 | types exist: |
564 | 589 | ||
@@ -634,6 +659,13 @@ release, of course) will return an error as well. | |||
634 | When the last user of the video device node exits, then the vdev->release() | 659 | When the last user of the video device node exits, then the vdev->release() |
635 | callback is called and you can do the final cleanup there. | 660 | callback is called and you can do the final cleanup there. |
636 | 661 | ||
662 | Don't forget to cleanup the media entity associated with the video device if | ||
663 | it has been initialized: | ||
664 | |||
665 | media_entity_cleanup(&vdev->entity); | ||
666 | |||
667 | This can be done from the release callback. | ||
668 | |||
637 | 669 | ||
638 | video_device helper functions | 670 | video_device helper functions |
639 | ----------------------------- | 671 | ----------------------------- |