diff options
Diffstat (limited to 'Documentation/video4linux/v4l2-framework.txt')
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 143 |
1 files changed, 137 insertions, 6 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index 5155700c206b..e831aaca66f8 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt | |||
@@ -545,12 +545,11 @@ unregister them: | |||
545 | This will remove the device nodes from sysfs (causing udev to remove them | 545 | This will remove the device nodes from sysfs (causing udev to remove them |
546 | from /dev). | 546 | from /dev). |
547 | 547 | ||
548 | After video_unregister_device() returns no new opens can be done. | 548 | After video_unregister_device() returns no new opens can be done. However, |
549 | 549 | in the case of USB devices some application might still have one of these | |
550 | However, in the case of USB devices some application might still have one | 550 | device nodes open. So after the unregister all file operations will return |
551 | of these device nodes open. You should block all new accesses to read, | 551 | an error as well, except for the ioctl and unlocked_ioctl file operations: |
552 | write, poll, etc. except possibly for certain ioctl operations like | 552 | those will still be passed on since some buffer ioctls may still be needed. |
553 | queueing buffers. | ||
554 | 553 | ||
555 | When the last user of the video device node exits, then the vdev->release() | 554 | When the last user of the video device node exits, then the vdev->release() |
556 | callback is called and you can do the final cleanup there. | 555 | callback is called and you can do the final cleanup there. |
@@ -609,3 +608,135 @@ scatter/gather method (videobuf-dma-sg), DMA with linear access | |||
609 | 608 | ||
610 | Please see Documentation/video4linux/videobuf for more information on how | 609 | Please see Documentation/video4linux/videobuf for more information on how |
611 | to use the videobuf layer. | 610 | to use the videobuf layer. |
611 | |||
612 | struct v4l2_fh | ||
613 | -------------- | ||
614 | |||
615 | struct v4l2_fh provides a way to easily keep file handle specific data | ||
616 | that is used by the V4L2 framework. Using v4l2_fh is optional for | ||
617 | drivers. | ||
618 | |||
619 | The users of v4l2_fh (in the V4L2 framework, not the driver) know | ||
620 | whether a driver uses v4l2_fh as its file->private_data pointer by | ||
621 | testing the V4L2_FL_USES_V4L2_FH bit in video_device->flags. | ||
622 | |||
623 | Useful functions: | ||
624 | |||
625 | - v4l2_fh_init() | ||
626 | |||
627 | Initialise the file handle. This *MUST* be performed in the driver's | ||
628 | v4l2_file_operations->open() handler. | ||
629 | |||
630 | - v4l2_fh_add() | ||
631 | |||
632 | Add a v4l2_fh to video_device file handle list. May be called after | ||
633 | initialising the file handle. | ||
634 | |||
635 | - v4l2_fh_del() | ||
636 | |||
637 | Unassociate the file handle from video_device(). The file handle | ||
638 | exit function may now be called. | ||
639 | |||
640 | - v4l2_fh_exit() | ||
641 | |||
642 | Uninitialise the file handle. After uninitialisation the v4l2_fh | ||
643 | memory can be freed. | ||
644 | |||
645 | struct v4l2_fh is allocated as a part of the driver's own file handle | ||
646 | structure and is set to file->private_data in the driver's open | ||
647 | function by the driver. Drivers can extract their own file handle | ||
648 | structure by using the container_of macro. Example: | ||
649 | |||
650 | struct my_fh { | ||
651 | int blah; | ||
652 | struct v4l2_fh fh; | ||
653 | }; | ||
654 | |||
655 | ... | ||
656 | |||
657 | int my_open(struct file *file) | ||
658 | { | ||
659 | struct my_fh *my_fh; | ||
660 | struct video_device *vfd; | ||
661 | int ret; | ||
662 | |||
663 | ... | ||
664 | |||
665 | ret = v4l2_fh_init(&my_fh->fh, vfd); | ||
666 | if (ret) | ||
667 | return ret; | ||
668 | |||
669 | v4l2_fh_add(&my_fh->fh); | ||
670 | |||
671 | file->private_data = &my_fh->fh; | ||
672 | |||
673 | ... | ||
674 | } | ||
675 | |||
676 | int my_release(struct file *file) | ||
677 | { | ||
678 | struct v4l2_fh *fh = file->private_data; | ||
679 | struct my_fh *my_fh = container_of(fh, struct my_fh, fh); | ||
680 | |||
681 | ... | ||
682 | } | ||
683 | |||
684 | V4L2 events | ||
685 | ----------- | ||
686 | |||
687 | The V4L2 events provide a generic way to pass events to user space. | ||
688 | The driver must use v4l2_fh to be able to support V4L2 events. | ||
689 | |||
690 | Useful functions: | ||
691 | |||
692 | - v4l2_event_alloc() | ||
693 | |||
694 | To use events, the driver must allocate events for the file handle. By | ||
695 | calling the function more than once, the driver may assure that at least n | ||
696 | events in total have been allocated. The function may not be called in | ||
697 | atomic context. | ||
698 | |||
699 | - v4l2_event_queue() | ||
700 | |||
701 | Queue events to video device. The driver's only responsibility is to fill | ||
702 | in the type and the data fields. The other fields will be filled in by | ||
703 | V4L2. | ||
704 | |||
705 | - v4l2_event_subscribe() | ||
706 | |||
707 | The video_device->ioctl_ops->vidioc_subscribe_event must check the driver | ||
708 | is able to produce events with specified event id. Then it calls | ||
709 | v4l2_event_subscribe() to subscribe the event. | ||
710 | |||
711 | - v4l2_event_unsubscribe() | ||
712 | |||
713 | vidioc_unsubscribe_event in struct v4l2_ioctl_ops. A driver may use | ||
714 | v4l2_event_unsubscribe() directly unless it wants to be involved in | ||
715 | unsubscription process. | ||
716 | |||
717 | The special type V4L2_EVENT_ALL may be used to unsubscribe all events. The | ||
718 | drivers may want to handle this in a special way. | ||
719 | |||
720 | - v4l2_event_pending() | ||
721 | |||
722 | Returns the number of pending events. Useful when implementing poll. | ||
723 | |||
724 | Drivers do not initialise events directly. The events are initialised | ||
725 | through v4l2_fh_init() if video_device->ioctl_ops->vidioc_subscribe_event is | ||
726 | non-NULL. This *MUST* be performed in the driver's | ||
727 | v4l2_file_operations->open() handler. | ||
728 | |||
729 | Events are delivered to user space through the poll system call. The driver | ||
730 | can use v4l2_fh->events->wait wait_queue_head_t as the argument for | ||
731 | poll_wait(). | ||
732 | |||
733 | There are standard and private events. New standard events must use the | ||
734 | smallest available event type. The drivers must allocate their events from | ||
735 | their own class starting from class base. Class base is | ||
736 | V4L2_EVENT_PRIVATE_START + n * 1000 where n is the lowest available number. | ||
737 | The first event type in the class is reserved for future use, so the first | ||
738 | available event type is 'class base + 1'. | ||
739 | |||
740 | An example on how the V4L2 events may be used can be found in the OMAP | ||
741 | 3 ISP driver available at <URL:http://gitorious.org/omap3camera> as of | ||
742 | writing this. | ||