Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] doc-rst: move v4l2-dev doc to a separate file

Move the documentation for video device node creation to
a separate file.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

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