diff options
author | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-21 16:05:35 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-23 07:04:21 -0400 |
commit | 243b6935aeeccc4e4e07ded08d2e743f21af3664 (patch) | |
tree | 591f791cf6de7bfba0139ede51883baee85b911d | |
parent | 81d866fdcda8888970dc1812da927e509f429ea9 (diff) |
[media] v4l2-dev: add cross-references and improve markup
Add cross-references for the functions/structs and add
the markup tags to improve its display.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r-- | Documentation/media/kapi/v4l2-dev.rst | 362 | ||||
-rw-r--r-- | Documentation/media/kapi/v4l2-videobuf.rst | 2 | ||||
-rw-r--r-- | Documentation/media/kapi/v4l2-videobuf2.rst | 2 |
3 files changed, 195 insertions, 171 deletions
diff --git a/Documentation/media/kapi/v4l2-dev.rst b/Documentation/media/kapi/v4l2-dev.rst index f9b75d211ca0..306306d8a43d 100644 --- a/Documentation/media/kapi/v4l2-dev.rst +++ b/Documentation/media/kapi/v4l2-dev.rst | |||
@@ -1,13 +1,13 @@ | |||
1 | Video device creation | 1 | Video device creation |
2 | ===================== | 2 | ===================== |
3 | 3 | ||
4 | The actual device nodes in the /dev directory are created using the | 4 | The actual device nodes in the ``/dev`` directory are created using the |
5 | video_device struct (v4l2-dev.h). This struct can either be allocated | 5 | :c:type:`video_device` struct (``v4l2-dev.h``). This struct can either be |
6 | dynamically or embedded in a larger struct. | 6 | allocated dynamically or embedded in a larger struct. |
7 | 7 | ||
8 | To allocate it dynamically use: | 8 | To allocate it dynamically use :cpp:func:`video_device_alloc`: |
9 | 9 | ||
10 | .. code-block:: none | 10 | .. code-block:: c |
11 | 11 | ||
12 | struct video_device *vdev = video_device_alloc(); | 12 | struct video_device *vdev = video_device_alloc(); |
13 | 13 | ||
@@ -16,100 +16,110 @@ To allocate it dynamically use: | |||
16 | 16 | ||
17 | vdev->release = video_device_release; | 17 | vdev->release = video_device_release; |
18 | 18 | ||
19 | If you embed it in a larger struct, then you must set the release() | 19 | If you embed it in a larger struct, then you must set the ``release()`` |
20 | callback to your own function: | 20 | callback to your own function: |
21 | 21 | ||
22 | .. code-block:: none | 22 | .. code-block:: c |
23 | 23 | ||
24 | struct video_device *vdev = &my_vdev->vdev; | 24 | struct video_device *vdev = &my_vdev->vdev; |
25 | 25 | ||
26 | vdev->release = my_vdev_release; | 26 | vdev->release = my_vdev_release; |
27 | 27 | ||
28 | The release callback must be set and it is called when the last user | 28 | The ``release()`` callback must be set and it is called when the last user |
29 | of the video device exits. | 29 | of the video device exits. |
30 | 30 | ||
31 | The default video_device_release() callback just calls kfree to free the | 31 | The default :cpp:func:`video_device_release` callback currently |
32 | allocated memory. | 32 | just calls ``kfree`` to free the allocated memory. |
33 | 33 | ||
34 | There is also a video_device_release_empty() function that does nothing | 34 | There is also a ::cpp:func:`video_device_release_empty` function that does |
35 | (is empty) and can be used if the struct is embedded and there is nothing | 35 | nothing (is empty) and should be used if the struct is embedded and there |
36 | to do when it is released. | 36 | is nothing to do when it is released. |
37 | 37 | ||
38 | You should also set these fields: | 38 | You should also set these fields of :c:type:`video_device`: |
39 | 39 | ||
40 | - v4l2_dev: must be set to the v4l2_device parent device. | 40 | - :c:type:`video_device`->v4l2_dev: must be set to the :c:type:`v4l2_device` |
41 | 41 | parent device. | |
42 | - name: set to something descriptive and unique. | 42 | |
43 | 43 | - :c:type:`video_device`->name: set to something descriptive and unique. | |
44 | - vfl_dir: set this to VFL_DIR_RX for capture devices (VFL_DIR_RX has value 0, | 44 | |
45 | so this is normally already the default), set to VFL_DIR_TX for output | 45 | - :c:type:`video_device`->vfl_dir: set this to ``VFL_DIR_RX`` for capture |
46 | devices and VFL_DIR_M2M for mem2mem (codec) devices. | 46 | devices (``VFL_DIR_RX`` has value 0, so this is normally already the |
47 | 47 | default), set to ``VFL_DIR_TX`` for output devices and ``VFL_DIR_M2M`` for mem2mem (codec) devices. | |
48 | - fops: set to the v4l2_file_operations struct. | 48 | |
49 | 49 | - :c:type:`video_device`->fops: set to the :c:type:`v4l2_file_operations` | |
50 | - ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance | 50 | struct. |
51 | (highly recommended to use this and it might become compulsory in the | 51 | |
52 | future!), then set this to your v4l2_ioctl_ops struct. The vfl_type and | 52 | - :c:type:`video_device`->ioctl_ops: if you use the :c:type:`v4l2_ioctl_ops` |
53 | vfl_dir fields are used to disable ops that do not match the type/dir | 53 | to simplify ioctl maintenance (highly recommended to use this and it might |
54 | combination. E.g. VBI ops are disabled for non-VBI nodes, and output ops | 54 | become compulsory in the future!), then set this to your |
55 | are disabled for a capture device. This makes it possible to provide | 55 | :c:type:`v4l2_ioctl_ops` struct. The :c:type:`video_device`->vfl_type and |
56 | just one v4l2_ioctl_ops struct for both vbi and video nodes. | 56 | :c:type:`video_device`->vfl_dir fields are used to disable ops that do not |
57 | 57 | match the type/dir combination. E.g. VBI ops are disabled for non-VBI nodes, | |
58 | - lock: leave to NULL if you want to do all the locking in the driver. | 58 | and output ops are disabled for a capture device. This makes it possible to |
59 | Otherwise you give it a pointer to a struct mutex_lock and before the | 59 | provide just one :c:type:`v4l2_ioctl_ops struct` for both vbi and |
60 | unlocked_ioctl file operation is called this lock will be taken by the | 60 | video nodes. |
61 | core and released afterwards. See the next section for more details. | 61 | |
62 | 62 | - :c:type:`video_device`->lock: leave to ``NULL`` if you want to do all the | |
63 | - queue: a pointer to the struct vb2_queue associated with this device node. | 63 | locking in the driver. Otherwise you give it a pointer to a struct |
64 | If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is | 64 | ``mutex_lock`` and before the :c:type:`video_device`->unlocked_ioctl |
65 | used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF, | 65 | file operation is called this lock will be taken by the core and released |
66 | QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above. | 66 | afterwards. See the next section for more details. |
67 | That way the vb2 queuing framework does not have to wait for other ioctls. | 67 | |
68 | This queue pointer is also used by the vb2 helper functions to check for | 68 | - :c:type:`video_device`->queue: a pointer to the struct :c:type:`vb2_queue` |
69 | associated with this device node. | ||
70 | If queue is not ``NULL``, and queue->lock is not ``NULL``, then queue->lock | ||
71 | is used for the queuing ioctls (``VIDIOC_REQBUFS``, ``CREATE_BUFS``, | ||
72 | ``QBUF``, ``DQBUF``, ``QUERYBUF``, ``PREPARE_BUF``, ``STREAMON`` and | ||
73 | ``STREAMOFF``) instead of the lock above. | ||
74 | That way the :ref:`vb2 <vb2_framework>` queuing framework does not have | ||
75 | to wait for other ioctls. This queue pointer is also used by the | ||
76 | :ref:`vb2 <vb2_framework>` helper functions to check for | ||
69 | queuing ownership (i.e. is the filehandle calling it allowed to do the | 77 | queuing ownership (i.e. is the filehandle calling it allowed to do the |
70 | operation). | 78 | operation). |
71 | 79 | ||
72 | - prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY. | 80 | - :c:type:`video_device`->prio: keeps track of the priorities. Used to |
73 | If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device. | 81 | implement ``VIDIOC_G_PRIORITY`` and ``VIDIOC_S_PRIORITY``. |
74 | If you want to have a separate priority state per (group of) device node(s), | 82 | If left to ``NULL``, then it will use the struct :c:type:`v4l2_prio_state` |
75 | then you can point it to your own struct v4l2_prio_state. | 83 | in :c:type:`v4l2_device`. If you want to have a separate priority state per |
76 | 84 | (group of) device node(s), then you can point it to your own struct | |
77 | - dev_parent: you only set this if v4l2_device was registered with NULL as | 85 | :c:type:`v4l2_prio_state`. |
78 | the parent device struct. This only happens in cases where one hardware | 86 | |
79 | device has multiple PCI devices that all share the same v4l2_device core. | 87 | - :c:type:`video_device`->dev_parent: you only set this if v4l2_device was |
80 | 88 | registered with ``NULL`` as the parent ``device`` struct. This only happens | |
81 | The cx88 driver is an example of this: one core v4l2_device struct, but | 89 | in cases where one hardware device has multiple PCI devices that all share |
82 | it is used by both a raw video PCI device (cx8800) and a MPEG PCI device | 90 | the same :c:type:`v4l2_device` core. |
83 | (cx8802). Since the v4l2_device cannot be associated with two PCI devices | 91 | |
84 | at the same time it is setup without a parent device. But when the struct | 92 | The cx88 driver is an example of this: one core :c:type:`v4l2_device` struct, |
85 | video_device is initialized you *do* know which parent PCI device to use and | 93 | but it is used by both a raw video PCI device (cx8800) and a MPEG PCI device |
86 | so you set dev_device to the correct PCI device. | 94 | (cx8802). Since the :c:type:`v4l2_device` cannot be associated with two PCI |
87 | 95 | devices at the same time it is setup without a parent device. But when the | |
88 | If you use v4l2_ioctl_ops, then you should set .unlocked_ioctl to video_ioctl2 | 96 | struct :c:type:`video_device` is initialized you **do** know which parent |
89 | in your v4l2_file_operations struct. | 97 | PCI device to use and so you set ``dev_device`` to the correct PCI device. |
90 | 98 | ||
91 | Do not use .ioctl! This is deprecated and will go away in the future. | 99 | If you use :c:type:`v4l2_ioctl_ops`, then you should set |
100 | :c:type:`video_device`->unlocked_ioctl to :cpp:func:`video_ioctl2` in your | ||
101 | :c:type:`v4l2_file_operations` struct. | ||
92 | 102 | ||
93 | In some cases you want to tell the core that a function you had specified in | 103 | In some cases you want to tell the core that a function you had specified in |
94 | your v4l2_ioctl_ops should be ignored. You can mark such ioctls by calling this | 104 | your :c:type:`v4l2_ioctl_ops` should be ignored. You can mark such ioctls by |
95 | function before video_device_register is called: | 105 | calling this function before :cpp:func:`video_register_device` is called: |
96 | |||
97 | .. code-block:: none | ||
98 | 106 | ||
99 | void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd); | 107 | :cpp:func:`v4l2_disable_ioctl <v4l2_disable_ioctl>` |
108 | (:c:type:`vdev <video_device>`, cmd). | ||
100 | 109 | ||
101 | This tends to be needed if based on external factors (e.g. which card is | 110 | This tends to be needed if based on external factors (e.g. which card is |
102 | being used) you want to turns off certain features in v4l2_ioctl_ops without | 111 | being used) you want to turns off certain features in :c:type:`v4l2_ioctl_ops` |
103 | having to make a new struct. | 112 | without having to make a new struct. |
104 | 113 | ||
105 | The v4l2_file_operations struct is a subset of file_operations. The main | 114 | The :c:type:`v4l2_file_operations` struct is a subset of file_operations. |
106 | difference is that the inode argument is omitted since it is never used. | 115 | The main difference is that the inode argument is omitted since it is never |
116 | used. | ||
107 | 117 | ||
108 | If integration with the media framework is needed, you must initialize the | 118 | If integration with the media framework is needed, you must initialize the |
109 | media_entity struct embedded in the video_device struct (entity field) by | 119 | :c:type:`media_entity` struct embedded in the :c:type:`video_device` struct |
110 | calling media_entity_pads_init(): | 120 | (entity field) by calling :cpp:func:`media_entity_pads_init`: |
111 | 121 | ||
112 | .. code-block:: none | 122 | .. code-block:: c |
113 | 123 | ||
114 | struct media_pad *pad = &my_vdev->pad; | 124 | struct media_pad *pad = &my_vdev->pad; |
115 | int err; | 125 | int err; |
@@ -126,47 +136,52 @@ ioctls and locking | |||
126 | ------------------ | 136 | ------------------ |
127 | 137 | ||
128 | The V4L core provides optional locking services. The main service is the | 138 | The V4L core provides optional locking services. The main service is the |
129 | lock field in struct video_device, which is a pointer to a mutex. If you set | 139 | lock field in struct :c:type:`video_device`, which is a pointer to a mutex. |
130 | this pointer, then that will be used by unlocked_ioctl to serialize all ioctls. | 140 | If you set this pointer, then that will be used by unlocked_ioctl to |
131 | 141 | serialize all ioctls. | |
132 | If you are using the videobuf2 framework, then there is a second lock that you | 142 | |
133 | can set: video_device->queue->lock. If set, then this lock will be used instead | 143 | If you are using the :ref:`videobuf2 framework <vb2_framework>`, then there |
134 | of video_device->lock to serialize all queuing ioctls (see the previous section | 144 | is a second lock that you can set: :c:type:`video_device`->queue->lock. If |
145 | set, then this lock will be used instead of :c:type:`video_device`->lock | ||
146 | to serialize all queuing ioctls (see the previous section | ||
135 | for the full list of those ioctls). | 147 | for the full list of those ioctls). |
136 | 148 | ||
137 | The advantage of using a different lock for the queuing ioctls is that for some | 149 | The advantage of using a different lock for the queuing ioctls is that for some |
138 | drivers (particularly USB drivers) certain commands such as setting controls | 150 | drivers (particularly USB drivers) certain commands such as setting controls |
139 | can take a long time, so you want to use a separate lock for the buffer queuing | 151 | can take a long time, so you want to use a separate lock for the buffer queuing |
140 | ioctls. That way your VIDIOC_DQBUF doesn't stall because the driver is busy | 152 | ioctls. That way your ``VIDIOC_DQBUF`` doesn't stall because the driver is busy |
141 | changing the e.g. exposure of the webcam. | 153 | changing the e.g. exposure of the webcam. |
142 | 154 | ||
143 | Of course, you can always do all the locking yourself by leaving both lock | 155 | Of course, you can always do all the locking yourself by leaving both lock |
144 | pointers at NULL. | 156 | pointers at ``NULL``. |
145 | 157 | ||
146 | If you use the old videobuf then you must pass the video_device lock to the | 158 | If you use the old :ref:`videobuf framework <vb_framework>` then you must |
147 | videobuf queue initialize function: if videobuf has to wait for a frame to | 159 | pass the :c:type:`video_device`->lock to the videobuf queue initialize |
148 | arrive, then it will temporarily unlock the lock and relock it afterwards. If | 160 | function: if videobuf has to wait for a frame to arrive, then it will |
149 | your driver also waits in the code, then you should do the same to allow other | 161 | temporarily unlock the lock and relock it afterwards. If your driver also |
162 | waits in the code, then you should do the same to allow other | ||
150 | processes to access the device node while the first process is waiting for | 163 | processes to access the device node while the first process is waiting for |
151 | something. | 164 | something. |
152 | 165 | ||
153 | In the case of videobuf2 you will need to implement the wait_prepare and | 166 | In the case of :ref:`videobuf2 <vb2_framework>` you will need to implement the |
154 | wait_finish callbacks to unlock/lock if applicable. If you use the queue->lock | 167 | ``wait_prepare()`` and ``wait_finish()`` callbacks to unlock/lock if applicable. |
155 | pointer, then you can use the helper functions vb2_ops_wait_prepare/finish. | 168 | If you use the ``queue->lock`` pointer, then you can use the helper functions |
169 | :cpp:func:`vb2_ops_wait_prepare` and :cpp:func:`vb2_ops_wait_finish`. | ||
156 | 170 | ||
157 | The implementation of a hotplug disconnect should also take the lock from | 171 | The implementation of a hotplug disconnect should also take the lock from |
158 | video_device before calling v4l2_device_disconnect. If you are also using | 172 | :c:type:`video_device` before calling v4l2_device_disconnect. If you are also |
159 | video_device->queue->lock, then you have to first lock video_device->queue->lock | 173 | using :c:type:`video_device`->queue->lock, then you have to first lock |
160 | followed by video_device->lock. That way you can be sure no ioctl is running | 174 | :c:type:`video_device`->queue->lock followed by :c:type:`video_device`->lock. |
161 | when you call v4l2_device_disconnect. | 175 | That way you can be sure no ioctl is running when you call |
176 | :c:type:`v4l2_device_disconnect`. | ||
162 | 177 | ||
163 | video_device registration | 178 | Video device registration |
164 | ------------------------- | 179 | ------------------------- |
165 | 180 | ||
166 | Next you register the video device: this will create the character device | 181 | Next you register the video device with :cpp:func:`video_register_device`. |
167 | for you. | 182 | This will create the character device for you. |
168 | 183 | ||
169 | .. code-block:: none | 184 | .. code-block:: c |
170 | 185 | ||
171 | err = video_register_device(vdev, VFL_TYPE_GRABBER, -1); | 186 | err = video_register_device(vdev, VFL_TYPE_GRABBER, -1); |
172 | if (err) { | 187 | if (err) { |
@@ -174,19 +189,20 @@ for you. | |||
174 | return err; | 189 | return err; |
175 | } | 190 | } |
176 | 191 | ||
177 | If the v4l2_device parent device has a non-NULL mdev field, the video device | 192 | If the :c:type:`v4l2_device` parent device has a not ``NULL`` mdev field, |
178 | entity will be automatically registered with the media device. | 193 | the video device entity will be automatically registered with the media |
194 | device. | ||
179 | 195 | ||
180 | Which device is registered depends on the type argument. The following | 196 | Which device is registered depends on the type argument. The following |
181 | types exist: | 197 | types exist: |
182 | 198 | ||
183 | VFL_TYPE_GRABBER: videoX for video input/output devices | 199 | - ``VFL_TYPE_GRABBER``: ``/dev/videoX`` for video input/output devices |
184 | VFL_TYPE_VBI: vbiX for vertical blank data (i.e. closed captions, teletext) | 200 | - ``VFL_TYPE_VBI``: ``/dev/vbiX`` for vertical blank data (i.e. closed captions, teletext) |
185 | VFL_TYPE_RADIO: radioX for radio tuners | 201 | - ``VFL_TYPE_RADIO``: ``/dev/radioX`` for radio tuners |
186 | VFL_TYPE_SDR: swradioX for Software Defined Radio tuners | 202 | - ``VFL_TYPE_SDR``: ``/dev/swradioX`` for Software Defined Radio tuners |
187 | 203 | ||
188 | The last argument gives you a certain amount of control over the device | 204 | The last argument gives you a certain amount of control over the device |
189 | device node number used (i.e. the X in videoX). Normally you will pass -1 | 205 | device node number used (i.e. the X in ``videoX``). Normally you will pass -1 |
190 | to let the v4l2 framework pick the first free number. But sometimes users | 206 | to let the v4l2 framework pick the first free number. But sometimes users |
191 | want to select a specific node number. It is common that drivers allow | 207 | want to select a specific node number. It is common that drivers allow |
192 | the user to select a specific device node number through a driver module | 208 | the user to select a specific device node number through a driver module |
@@ -205,85 +221,90 @@ first free number. | |||
205 | 221 | ||
206 | Since in this case you do not care about a warning about not being able | 222 | Since in this case you do not care about a warning about not being able |
207 | to select the specified device node number, you can call the function | 223 | to select the specified device node number, you can call the function |
208 | video_register_device_no_warn() instead. | 224 | :cpp:func:`video_register_device_no_warn` instead. |
209 | 225 | ||
210 | Whenever a device node is created some attributes are also created for you. | 226 | Whenever a device node is created some attributes are also created for you. |
211 | If you look in /sys/class/video4linux you see the devices. Go into e.g. | 227 | If you look in ``/sys/class/video4linux`` you see the devices. Go into e.g. |
212 | video0 and you will see 'name', 'dev_debug' and 'index' attributes. The 'name' | 228 | ``video0`` and you will see 'name', 'dev_debug' and 'index' attributes. The |
213 | attribute is the 'name' field of the video_device struct. The 'dev_debug' attribute | 229 | 'name' attribute is the 'name' field of the video_device struct. The |
214 | can be used to enable core debugging. See the next section for more detailed | 230 | 'dev_debug' attribute can be used to enable core debugging. See the next |
215 | information on this. | 231 | section for more detailed information on this. |
216 | 232 | ||
217 | The 'index' attribute is the index of the device node: for each call to | 233 | The 'index' attribute is the index of the device node: for each call to |
218 | video_register_device() the index is just increased by 1. The first video | 234 | :cpp:func:`video_register_device()` the index is just increased by 1. The |
219 | device node you register always starts with index 0. | 235 | first video device node you register always starts with index 0. |
220 | 236 | ||
221 | Users can setup udev rules that utilize the index attribute to make fancy | 237 | Users can setup udev rules that utilize the index attribute to make fancy |
222 | device names (e.g. 'mpegX' for MPEG video capture device nodes). | 238 | device names (e.g. '``mpegX``' for MPEG video capture device nodes). |
223 | 239 | ||
224 | After the device was successfully registered, then you can use these fields: | 240 | After the device was successfully registered, then you can use these fields: |
225 | 241 | ||
226 | - vfl_type: the device type passed to video_register_device. | 242 | - :c:type:`video_device`->vfl_type: the device type passed to |
227 | - minor: the assigned device minor number. | 243 | :cpp:func:`video_register_device`. |
228 | - num: the device node number (i.e. the X in videoX). | 244 | - :c:type:`video_device`->minor: the assigned device minor number. |
229 | - index: the device index number. | 245 | - :c:type:`video_device`->num: the device node number (i.e. the X in |
246 | ``videoX``). | ||
247 | - :c:type:`video_device`->index: the device index number. | ||
230 | 248 | ||
231 | If the registration failed, then you need to call video_device_release() | 249 | If the registration failed, then you need to call |
232 | to free the allocated video_device struct, or free your own struct if the | 250 | :cpp:func:`video_device_release` to free the allocated :c:type:`video_device` |
233 | video_device was embedded in it. The vdev->release() callback will never | 251 | struct, or free your own struct if the :c:type:`video_device` was embedded in |
234 | be called if the registration failed, nor should you ever attempt to | 252 | it. The ``vdev->release()`` callback will never be called if the registration |
235 | unregister the device if the registration failed. | 253 | failed, nor should you ever attempt to unregister the device if the |
254 | registration failed. | ||
236 | 255 | ||
237 | video device debugging | 256 | video device debugging |
238 | ---------------------- | 257 | ---------------------- |
239 | 258 | ||
240 | The 'dev_debug' attribute that is created for each video, vbi, radio or swradio | 259 | The 'dev_debug' attribute that is created for each video, vbi, radio or swradio |
241 | device in /sys/class/video4linux/<devX>/ allows you to enable logging of | 260 | device in ``/sys/class/video4linux/<devX>/`` allows you to enable logging of |
242 | file operations. | 261 | file operations. |
243 | 262 | ||
244 | It is a bitmask and the following bits can be set: | 263 | It is a bitmask and the following bits can be set: |
245 | 264 | ||
246 | .. code-block:: none | ||
247 | |||
248 | 0x01: Log the ioctl name and error code. VIDIOC_(D)QBUF ioctls are only logged | ||
249 | if bit 0x08 is also set. | ||
250 | 0x02: Log the ioctl name arguments and error code. VIDIOC_(D)QBUF ioctls are | ||
251 | only logged if bit 0x08 is also set. | ||
252 | 0x04: Log the file operations open, release, read, write, mmap and | ||
253 | get_unmapped_area. The read and write operations are only logged if | ||
254 | bit 0x08 is also set. | ||
255 | 0x08: Log the read and write file operations and the VIDIOC_QBUF and | ||
256 | VIDIOC_DQBUF ioctls. | ||
257 | 0x10: Log the poll file operation. | ||
258 | 265 | ||
259 | video_device cleanup | 266 | ===== ================================================================ |
267 | Mask Description | ||
268 | ===== ================================================================ | ||
269 | 0x01 Log the ioctl name and error code. VIDIOC_(D)QBUF ioctls are | ||
270 | only logged if bit 0x08 is also set. | ||
271 | 0x02 Log the ioctl name arguments and error code. VIDIOC_(D)QBUF | ||
272 | ioctls are | ||
273 | only logged if bit 0x08 is also set. | ||
274 | 0x04 Log the file operations open, release, read, write, mmap and | ||
275 | get_unmapped_area. The read and write operations are only | ||
276 | logged if bit 0x08 is also set. | ||
277 | 0x08 Log the read and write file operations and the VIDIOC_QBUF and | ||
278 | VIDIOC_DQBUF ioctls. | ||
279 | 0x10 Log the poll file operation. | ||
280 | ===== ================================================================ | ||
281 | |||
282 | Video device cleanup | ||
260 | -------------------- | 283 | -------------------- |
261 | 284 | ||
262 | When the video device nodes have to be removed, either during the unload | 285 | When the video device nodes have to be removed, either during the unload |
263 | of the driver or because the USB device was disconnected, then you should | 286 | of the driver or because the USB device was disconnected, then you should |
264 | unregister them: | 287 | unregister them with: |
265 | 288 | ||
266 | .. code-block:: none | 289 | :cpp:func:`video_unregister_device` |
267 | 290 | (:c:type:`vdev <video_device>`); | |
268 | video_unregister_device(vdev); | ||
269 | 291 | ||
270 | This will remove the device nodes from sysfs (causing udev to remove them | 292 | This will remove the device nodes from sysfs (causing udev to remove them |
271 | from /dev). | 293 | from ``/dev``). |
272 | 294 | ||
273 | After video_unregister_device() returns no new opens can be done. However, | 295 | After :cpp:func:`video_unregister_device` returns no new opens can be done. |
274 | in the case of USB devices some application might still have one of these | 296 | However, in the case of USB devices some application might still have one of |
275 | device nodes open. So after the unregister all file operations (except | 297 | these device nodes open. So after the unregister all file operations (except |
276 | release, of course) will return an error as well. | 298 | release, of course) will return an error as well. |
277 | 299 | ||
278 | When the last user of the video device node exits, then the vdev->release() | 300 | When the last user of the video device node exits, then the ``vdev->release()`` |
279 | callback is called and you can do the final cleanup there. | 301 | callback is called and you can do the final cleanup there. |
280 | 302 | ||
281 | Don't forget to cleanup the media entity associated with the video device if | 303 | Don't forget to cleanup the media entity associated with the video device if |
282 | it has been initialized: | 304 | it has been initialized: |
283 | 305 | ||
284 | .. code-block:: none | 306 | :cpp:func:`media_entity_cleanup <media_entity_cleanup>` |
285 | 307 | (&vdev->entity); | |
286 | media_entity_cleanup(&vdev->entity); | ||
287 | 308 | ||
288 | This can be done from the release callback. | 309 | This can be done from the release callback. |
289 | 310 | ||
@@ -293,45 +314,44 @@ video_device helper functions | |||
293 | 314 | ||
294 | There are a few useful helper functions: | 315 | There are a few useful helper functions: |
295 | 316 | ||
296 | - file/video_device private data | 317 | - file and :c:type:`video_device` private data |
297 | 318 | ||
298 | You can set/get driver private data in the video_device struct using: | 319 | You can set/get driver private data in the video_device struct using: |
299 | 320 | ||
300 | .. code-block:: none | 321 | :cpp:func:`video_get_drvdata <video_get_drvdata>` |
322 | (:c:type:`vdev <video_device>`); | ||
301 | 323 | ||
302 | void *video_get_drvdata(struct video_device *vdev); | 324 | :cpp:func:`video_set_drvdata <video_set_drvdata>` |
303 | void video_set_drvdata(struct video_device *vdev, void *data); | 325 | (:c:type:`vdev <video_device>`); |
304 | 326 | ||
305 | Note that you can safely call video_set_drvdata() before calling | 327 | Note that you can safely call :cpp:func:`video_set_drvdata` before calling |
306 | video_register_device(). | 328 | :cpp:func:`video_register_device`. |
307 | 329 | ||
308 | And this function: | 330 | And this function: |
309 | 331 | ||
310 | .. code-block:: none | 332 | :cpp:func:`video_devdata <video_devdata>` |
311 | 333 | (struct file \*file); | |
312 | struct video_device *video_devdata(struct file *file); | ||
313 | 334 | ||
314 | returns the video_device belonging to the file struct. | 335 | returns the video_device belonging to the file struct. |
315 | 336 | ||
316 | The video_drvdata function combines video_get_drvdata with video_devdata: | 337 | The :cpp:func:`video_devdata` function combines :cpp:func:`video_get_drvdata` |
338 | with :cpp:func:`video_devdata`: | ||
317 | 339 | ||
318 | .. code-block:: none | 340 | :cpp:func:`video_drvdata <video_drvdata>` |
341 | (struct file \*file); | ||
319 | 342 | ||
320 | void *video_drvdata(struct file *file); | 343 | You can go from a :c:type:`video_device` struct to the v4l2_device struct using: |
321 | 344 | ||
322 | You can go from a video_device struct to the v4l2_device struct using: | 345 | .. code-block:: c |
323 | |||
324 | .. code-block:: none | ||
325 | 346 | ||
326 | struct v4l2_device *v4l2_dev = vdev->v4l2_dev; | 347 | struct v4l2_device *v4l2_dev = vdev->v4l2_dev; |
327 | 348 | ||
328 | - Device node name | 349 | - Device node name |
329 | 350 | ||
330 | The video_device node kernel name can be retrieved using | 351 | The :c:type:`video_device` node kernel name can be retrieved using: |
331 | |||
332 | .. code-block:: none | ||
333 | 352 | ||
334 | const char *video_device_node_name(struct video_device *vdev); | 353 | :cpp:func:`video_device_node_name <video_device_node_name>` |
354 | (:c:type:`vdev <video_device>`); | ||
335 | 355 | ||
336 | The name is used as a hint by userspace tools such as udev. The function | 356 | The name is used as a hint by userspace tools such as udev. The function |
337 | should be used where possible instead of accessing the video_device::num and | 357 | should be used where possible instead of accessing the video_device::num and |
diff --git a/Documentation/media/kapi/v4l2-videobuf.rst b/Documentation/media/kapi/v4l2-videobuf.rst index 01156728203c..54adfd772d28 100644 --- a/Documentation/media/kapi/v4l2-videobuf.rst +++ b/Documentation/media/kapi/v4l2-videobuf.rst | |||
@@ -1,3 +1,5 @@ | |||
1 | .. _vb_framework: | ||
2 | |||
1 | Videobuf Framework | 3 | Videobuf Framework |
2 | ================== | 4 | ================== |
3 | 5 | ||
diff --git a/Documentation/media/kapi/v4l2-videobuf2.rst b/Documentation/media/kapi/v4l2-videobuf2.rst index b4f2d6983ef3..bdb8b83f1ea0 100644 --- a/Documentation/media/kapi/v4l2-videobuf2.rst +++ b/Documentation/media/kapi/v4l2-videobuf2.rst | |||
@@ -1,3 +1,5 @@ | |||
1 | .. _vb2_framework: | ||
2 | |||
1 | V4L2 videobuf2 kAPI | 3 | V4L2 videobuf2 kAPI |
2 | ^^^^^^^^^^^^^^^^^^^ | 4 | ^^^^^^^^^^^^^^^^^^^ |
3 | 5 | ||