···11+Video device creation22+=====================33+44+The actual device nodes in the /dev directory are created using the55+video_device struct (v4l2-dev.h). This struct can either be allocated66+dynamically or embedded in a larger struct.77+88+To allocate it dynamically use:99+1010+.. code-block:: none1111+1212+ struct video_device *vdev = video_device_alloc();1313+1414+ if (vdev == NULL)1515+ return -ENOMEM;1616+1717+ vdev->release = video_device_release;1818+1919+If you embed it in a larger struct, then you must set the release()2020+callback to your own function:2121+2222+.. code-block:: none2323+2424+ struct video_device *vdev = &my_vdev->vdev;2525+2626+ vdev->release = my_vdev_release;2727+2828+The release callback must be set and it is called when the last user2929+of the video device exits.3030+3131+The default video_device_release() callback just calls kfree to free the3232+allocated memory.3333+3434+There is also a video_device_release_empty() function that does nothing3535+(is empty) and can be used if the struct is embedded and there is nothing3636+to do when it is released.3737+3838+You should also set these fields:3939+4040+- v4l2_dev: must be set to the v4l2_device parent device.4141+4242+- name: set to something descriptive and unique.4343+4444+- vfl_dir: set this to VFL_DIR_RX for capture devices (VFL_DIR_RX has value 0,4545+ so this is normally already the default), set to VFL_DIR_TX for output4646+ devices and VFL_DIR_M2M for mem2mem (codec) devices.4747+4848+- fops: set to the v4l2_file_operations struct.4949+5050+- ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance5151+ (highly recommended to use this and it might become compulsory in the5252+ future!), then set this to your v4l2_ioctl_ops struct. The vfl_type and5353+ vfl_dir fields are used to disable ops that do not match the type/dir5454+ combination. E.g. VBI ops are disabled for non-VBI nodes, and output ops5555+ are disabled for a capture device. This makes it possible to provide5656+ just one v4l2_ioctl_ops struct for both vbi and video nodes.5757+5858+- lock: leave to NULL if you want to do all the locking in the driver.5959+ Otherwise you give it a pointer to a struct mutex_lock and before the6060+ unlocked_ioctl file operation is called this lock will be taken by the6161+ core and released afterwards. See the next section for more details.6262+6363+- queue: a pointer to the struct vb2_queue associated with this device node.6464+ If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is6565+ used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF,6666+ QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above.6767+ That way the vb2 queuing framework does not have to wait for other ioctls.6868+ This queue pointer is also used by the vb2 helper functions to check for6969+ queuing ownership (i.e. is the filehandle calling it allowed to do the7070+ operation).7171+7272+- prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY.7373+ If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device.7474+ If you want to have a separate priority state per (group of) device node(s),7575+ then you can point it to your own struct v4l2_prio_state.7676+7777+- dev_parent: you only set this if v4l2_device was registered with NULL as7878+ the parent device struct. This only happens in cases where one hardware7979+ device has multiple PCI devices that all share the same v4l2_device core.8080+8181+ The cx88 driver is an example of this: one core v4l2_device struct, but8282+ it is used by both a raw video PCI device (cx8800) and a MPEG PCI device8383+ (cx8802). Since the v4l2_device cannot be associated with two PCI devices8484+ at the same time it is setup without a parent device. But when the struct8585+ video_device is initialized you *do* know which parent PCI device to use and8686+ so you set dev_device to the correct PCI device.8787+8888+If you use v4l2_ioctl_ops, then you should set .unlocked_ioctl to video_ioctl28989+in your v4l2_file_operations struct.9090+9191+Do not use .ioctl! This is deprecated and will go away in the future.9292+9393+In some cases you want to tell the core that a function you had specified in9494+your v4l2_ioctl_ops should be ignored. You can mark such ioctls by calling this9595+function before video_device_register is called:9696+9797+.. code-block:: none9898+9999+ void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd);100100+101101+This tends to be needed if based on external factors (e.g. which card is102102+being used) you want to turns off certain features in v4l2_ioctl_ops without103103+having to make a new struct.104104+105105+The v4l2_file_operations struct is a subset of file_operations. The main106106+difference is that the inode argument is omitted since it is never used.107107+108108+If integration with the media framework is needed, you must initialize the109109+media_entity struct embedded in the video_device struct (entity field) by110110+calling media_entity_pads_init():111111+112112+.. code-block:: none113113+114114+ struct media_pad *pad = &my_vdev->pad;115115+ int err;116116+117117+ err = media_entity_pads_init(&vdev->entity, 1, pad);118118+119119+The pads array must have been previously initialized. There is no need to120120+manually set the struct media_entity type and name fields.121121+122122+A reference to the entity will be automatically acquired/released when the123123+video device is opened/closed.124124+125125+ioctls and locking126126+------------------127127+128128+The V4L core provides optional locking services. The main service is the129129+lock field in struct video_device, which is a pointer to a mutex. If you set130130+this pointer, then that will be used by unlocked_ioctl to serialize all ioctls.131131+132132+If you are using the videobuf2 framework, then there is a second lock that you133133+can set: video_device->queue->lock. If set, then this lock will be used instead134134+of video_device->lock to serialize all queuing ioctls (see the previous section135135+for the full list of those ioctls).136136+137137+The advantage of using a different lock for the queuing ioctls is that for some138138+drivers (particularly USB drivers) certain commands such as setting controls139139+can take a long time, so you want to use a separate lock for the buffer queuing140140+ioctls. That way your VIDIOC_DQBUF doesn't stall because the driver is busy141141+changing the e.g. exposure of the webcam.142142+143143+Of course, you can always do all the locking yourself by leaving both lock144144+pointers at NULL.145145+146146+If you use the old videobuf then you must pass the video_device lock to the147147+videobuf queue initialize function: if videobuf has to wait for a frame to148148+arrive, then it will temporarily unlock the lock and relock it afterwards. If149149+your driver also waits in the code, then you should do the same to allow other150150+processes to access the device node while the first process is waiting for151151+something.152152+153153+In the case of videobuf2 you will need to implement the wait_prepare and154154+wait_finish callbacks to unlock/lock if applicable. If you use the queue->lock155155+pointer, then you can use the helper functions vb2_ops_wait_prepare/finish.156156+157157+The implementation of a hotplug disconnect should also take the lock from158158+video_device before calling v4l2_device_disconnect. If you are also using159159+video_device->queue->lock, then you have to first lock video_device->queue->lock160160+followed by video_device->lock. That way you can be sure no ioctl is running161161+when you call v4l2_device_disconnect.162162+163163+video_device registration164164+-------------------------165165+166166+Next you register the video device: this will create the character device167167+for you.168168+169169+.. code-block:: none170170+171171+ err = video_register_device(vdev, VFL_TYPE_GRABBER, -1);172172+ if (err) {173173+ video_device_release(vdev); /* or kfree(my_vdev); */174174+ return err;175175+ }176176+177177+If the v4l2_device parent device has a non-NULL mdev field, the video device178178+entity will be automatically registered with the media device.179179+180180+Which device is registered depends on the type argument. The following181181+types exist:182182+183183+VFL_TYPE_GRABBER: videoX for video input/output devices184184+VFL_TYPE_VBI: vbiX for vertical blank data (i.e. closed captions, teletext)185185+VFL_TYPE_RADIO: radioX for radio tuners186186+VFL_TYPE_SDR: swradioX for Software Defined Radio tuners187187+188188+The last argument gives you a certain amount of control over the device189189+device node number used (i.e. the X in videoX). Normally you will pass -1190190+to let the v4l2 framework pick the first free number. But sometimes users191191+want to select a specific node number. It is common that drivers allow192192+the user to select a specific device node number through a driver module193193+option. That number is then passed to this function and video_register_device194194+will attempt to select that device node number. If that number was already195195+in use, then the next free device node number will be selected and it196196+will send a warning to the kernel log.197197+198198+Another use-case is if a driver creates many devices. In that case it can199199+be useful to place different video devices in separate ranges. For example,200200+video capture devices start at 0, video output devices start at 16.201201+So you can use the last argument to specify a minimum device node number202202+and the v4l2 framework will try to pick the first free number that is equal203203+or higher to what you passed. If that fails, then it will just pick the204204+first free number.205205+206206+Since in this case you do not care about a warning about not being able207207+to select the specified device node number, you can call the function208208+video_register_device_no_warn() instead.209209+210210+Whenever a device node is created some attributes are also created for you.211211+If you look in /sys/class/video4linux you see the devices. Go into e.g.212212+video0 and you will see 'name', 'dev_debug' and 'index' attributes. The 'name'213213+attribute is the 'name' field of the video_device struct. The 'dev_debug' attribute214214+can be used to enable core debugging. See the next section for more detailed215215+information on this.216216+217217+The 'index' attribute is the index of the device node: for each call to218218+video_register_device() the index is just increased by 1. The first video219219+device node you register always starts with index 0.220220+221221+Users can setup udev rules that utilize the index attribute to make fancy222222+device names (e.g. 'mpegX' for MPEG video capture device nodes).223223+224224+After the device was successfully registered, then you can use these fields:225225+226226+- vfl_type: the device type passed to video_register_device.227227+- minor: the assigned device minor number.228228+- num: the device node number (i.e. the X in videoX).229229+- index: the device index number.230230+231231+If the registration failed, then you need to call video_device_release()232232+to free the allocated video_device struct, or free your own struct if the233233+video_device was embedded in it. The vdev->release() callback will never234234+be called if the registration failed, nor should you ever attempt to235235+unregister the device if the registration failed.236236+237237+video device debugging238238+----------------------239239+240240+The 'dev_debug' attribute that is created for each video, vbi, radio or swradio241241+device in /sys/class/video4linux/<devX>/ allows you to enable logging of242242+file operations.243243+244244+It is a bitmask and the following bits can be set:245245+246246+.. code-block:: none247247+248248+ 0x01: Log the ioctl name and error code. VIDIOC_(D)QBUF ioctls are only logged249249+ if bit 0x08 is also set.250250+ 0x02: Log the ioctl name arguments and error code. VIDIOC_(D)QBUF ioctls are251251+ only logged if bit 0x08 is also set.252252+ 0x04: Log the file operations open, release, read, write, mmap and253253+ get_unmapped_area. The read and write operations are only logged if254254+ bit 0x08 is also set.255255+ 0x08: Log the read and write file operations and the VIDIOC_QBUF and256256+ VIDIOC_DQBUF ioctls.257257+ 0x10: Log the poll file operation.258258+259259+video_device cleanup260260+--------------------261261+262262+When the video device nodes have to be removed, either during the unload263263+of the driver or because the USB device was disconnected, then you should264264+unregister them:265265+266266+.. code-block:: none267267+268268+ video_unregister_device(vdev);269269+270270+This will remove the device nodes from sysfs (causing udev to remove them271271+from /dev).272272+273273+After video_unregister_device() returns no new opens can be done. However,274274+in the case of USB devices some application might still have one of these275275+device nodes open. So after the unregister all file operations (except276276+release, of course) will return an error as well.277277+278278+When the last user of the video device node exits, then the vdev->release()279279+callback is called and you can do the final cleanup there.280280+281281+Don't forget to cleanup the media entity associated with the video device if282282+it has been initialized:283283+284284+.. code-block:: none285285+286286+ media_entity_cleanup(&vdev->entity);287287+288288+This can be done from the release callback.289289+290290+291291+video_device helper functions292292+-----------------------------293293+294294+There are a few useful helper functions:295295+296296+- file/video_device private data297297+298298+You can set/get driver private data in the video_device struct using:299299+300300+.. code-block:: none301301+302302+ void *video_get_drvdata(struct video_device *vdev);303303+ void video_set_drvdata(struct video_device *vdev, void *data);304304+305305+Note that you can safely call video_set_drvdata() before calling306306+video_register_device().307307+308308+And this function:309309+310310+.. code-block:: none311311+312312+ struct video_device *video_devdata(struct file *file);313313+314314+returns the video_device belonging to the file struct.315315+316316+The video_drvdata function combines video_get_drvdata with video_devdata:317317+318318+.. code-block:: none319319+320320+ void *video_drvdata(struct file *file);321321+322322+You can go from a video_device struct to the v4l2_device struct using:323323+324324+.. code-block:: none325325+326326+ struct v4l2_device *v4l2_dev = vdev->v4l2_dev;327327+328328+- Device node name329329+330330+The video_device node kernel name can be retrieved using331331+332332+.. code-block:: none333333+334334+ const char *video_device_node_name(struct video_device *vdev);335335+336336+The name is used as a hint by userspace tools such as udev. The function337337+should be used where possible instead of accessing the video_device::num and338338+video_device::minor fields.339339+340340+video_device kAPI341341+-----------------342342+343343+.. kernel-doc:: include/media/v4l2-dev.h
-344
Documentation/media/kapi/v4l2-framework.rst
···8181will automatically appear in the media framework as entities.828283838484-struct video_device8585--------------------8686-8787-The actual device nodes in the /dev directory are created using the8888-video_device struct (v4l2-dev.h). This struct can either be allocated8989-dynamically or embedded in a larger struct.9090-9191-To allocate it dynamically use:9292-9393-.. code-block:: none9494-9595- struct video_device *vdev = video_device_alloc();9696-9797- if (vdev == NULL)9898- return -ENOMEM;9999-100100- vdev->release = video_device_release;101101-102102-If you embed it in a larger struct, then you must set the release()103103-callback to your own function:104104-105105-.. code-block:: none106106-107107- struct video_device *vdev = &my_vdev->vdev;108108-109109- vdev->release = my_vdev_release;110110-111111-The release callback must be set and it is called when the last user112112-of the video device exits.113113-114114-The default video_device_release() callback just calls kfree to free the115115-allocated memory.116116-117117-There is also a video_device_release_empty() function that does nothing118118-(is empty) and can be used if the struct is embedded and there is nothing119119-to do when it is released.120120-121121-You should also set these fields:122122-123123-- v4l2_dev: must be set to the v4l2_device parent device.124124-125125-- name: set to something descriptive and unique.126126-127127-- vfl_dir: set this to VFL_DIR_RX for capture devices (VFL_DIR_RX has value 0,128128- so this is normally already the default), set to VFL_DIR_TX for output129129- devices and VFL_DIR_M2M for mem2mem (codec) devices.130130-131131-- fops: set to the v4l2_file_operations struct.132132-133133-- ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance134134- (highly recommended to use this and it might become compulsory in the135135- future!), then set this to your v4l2_ioctl_ops struct. The vfl_type and136136- vfl_dir fields are used to disable ops that do not match the type/dir137137- combination. E.g. VBI ops are disabled for non-VBI nodes, and output ops138138- are disabled for a capture device. This makes it possible to provide139139- just one v4l2_ioctl_ops struct for both vbi and video nodes.140140-141141-- lock: leave to NULL if you want to do all the locking in the driver.142142- Otherwise you give it a pointer to a struct mutex_lock and before the143143- unlocked_ioctl file operation is called this lock will be taken by the144144- core and released afterwards. See the next section for more details.145145-146146-- queue: a pointer to the struct vb2_queue associated with this device node.147147- If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is148148- used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF,149149- QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above.150150- That way the vb2 queuing framework does not have to wait for other ioctls.151151- This queue pointer is also used by the vb2 helper functions to check for152152- queuing ownership (i.e. is the filehandle calling it allowed to do the153153- operation).154154-155155-- prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY.156156- If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device.157157- If you want to have a separate priority state per (group of) device node(s),158158- then you can point it to your own struct v4l2_prio_state.159159-160160-- dev_parent: you only set this if v4l2_device was registered with NULL as161161- the parent device struct. This only happens in cases where one hardware162162- device has multiple PCI devices that all share the same v4l2_device core.163163-164164- The cx88 driver is an example of this: one core v4l2_device struct, but165165- it is used by both a raw video PCI device (cx8800) and a MPEG PCI device166166- (cx8802). Since the v4l2_device cannot be associated with two PCI devices167167- at the same time it is setup without a parent device. But when the struct168168- video_device is initialized you *do* know which parent PCI device to use and169169- so you set dev_device to the correct PCI device.170170-171171-If you use v4l2_ioctl_ops, then you should set .unlocked_ioctl to video_ioctl2172172-in your v4l2_file_operations struct.173173-174174-Do not use .ioctl! This is deprecated and will go away in the future.175175-176176-In some cases you want to tell the core that a function you had specified in177177-your v4l2_ioctl_ops should be ignored. You can mark such ioctls by calling this178178-function before video_device_register is called:179179-180180-.. code-block:: none181181-182182- void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd);183183-184184-This tends to be needed if based on external factors (e.g. which card is185185-being used) you want to turns off certain features in v4l2_ioctl_ops without186186-having to make a new struct.187187-188188-The v4l2_file_operations struct is a subset of file_operations. The main189189-difference is that the inode argument is omitted since it is never used.190190-191191-If integration with the media framework is needed, you must initialize the192192-media_entity struct embedded in the video_device struct (entity field) by193193-calling media_entity_pads_init():194194-195195-.. code-block:: none196196-197197- struct media_pad *pad = &my_vdev->pad;198198- int err;199199-200200- err = media_entity_pads_init(&vdev->entity, 1, pad);201201-202202-The pads array must have been previously initialized. There is no need to203203-manually set the struct media_entity type and name fields.204204-205205-A reference to the entity will be automatically acquired/released when the206206-video device is opened/closed.207207-208208-ioctls and locking209209-------------------210210-211211-The V4L core provides optional locking services. The main service is the212212-lock field in struct video_device, which is a pointer to a mutex. If you set213213-this pointer, then that will be used by unlocked_ioctl to serialize all ioctls.214214-215215-If you are using the videobuf2 framework, then there is a second lock that you216216-can set: video_device->queue->lock. If set, then this lock will be used instead217217-of video_device->lock to serialize all queuing ioctls (see the previous section218218-for the full list of those ioctls).219219-220220-The advantage of using a different lock for the queuing ioctls is that for some221221-drivers (particularly USB drivers) certain commands such as setting controls222222-can take a long time, so you want to use a separate lock for the buffer queuing223223-ioctls. That way your VIDIOC_DQBUF doesn't stall because the driver is busy224224-changing the e.g. exposure of the webcam.225225-226226-Of course, you can always do all the locking yourself by leaving both lock227227-pointers at NULL.228228-229229-If you use the old videobuf then you must pass the video_device lock to the230230-videobuf queue initialize function: if videobuf has to wait for a frame to231231-arrive, then it will temporarily unlock the lock and relock it afterwards. If232232-your driver also waits in the code, then you should do the same to allow other233233-processes to access the device node while the first process is waiting for234234-something.235235-236236-In the case of videobuf2 you will need to implement the wait_prepare and237237-wait_finish callbacks to unlock/lock if applicable. If you use the queue->lock238238-pointer, then you can use the helper functions vb2_ops_wait_prepare/finish.239239-240240-The implementation of a hotplug disconnect should also take the lock from241241-video_device before calling v4l2_device_disconnect. If you are also using242242-video_device->queue->lock, then you have to first lock video_device->queue->lock243243-followed by video_device->lock. That way you can be sure no ioctl is running244244-when you call v4l2_device_disconnect.245245-246246-video_device registration247247--------------------------248248-249249-Next you register the video device: this will create the character device250250-for you.251251-252252-.. code-block:: none253253-254254- err = video_register_device(vdev, VFL_TYPE_GRABBER, -1);255255- if (err) {256256- video_device_release(vdev); /* or kfree(my_vdev); */257257- return err;258258- }259259-260260-If the v4l2_device parent device has a non-NULL mdev field, the video device261261-entity will be automatically registered with the media device.262262-263263-Which device is registered depends on the type argument. The following264264-types exist:265265-266266-VFL_TYPE_GRABBER: videoX for video input/output devices267267-VFL_TYPE_VBI: vbiX for vertical blank data (i.e. closed captions, teletext)268268-VFL_TYPE_RADIO: radioX for radio tuners269269-VFL_TYPE_SDR: swradioX for Software Defined Radio tuners270270-271271-The last argument gives you a certain amount of control over the device272272-device node number used (i.e. the X in videoX). Normally you will pass -1273273-to let the v4l2 framework pick the first free number. But sometimes users274274-want to select a specific node number. It is common that drivers allow275275-the user to select a specific device node number through a driver module276276-option. That number is then passed to this function and video_register_device277277-will attempt to select that device node number. If that number was already278278-in use, then the next free device node number will be selected and it279279-will send a warning to the kernel log.280280-281281-Another use-case is if a driver creates many devices. In that case it can282282-be useful to place different video devices in separate ranges. For example,283283-video capture devices start at 0, video output devices start at 16.284284-So you can use the last argument to specify a minimum device node number285285-and the v4l2 framework will try to pick the first free number that is equal286286-or higher to what you passed. If that fails, then it will just pick the287287-first free number.288288-289289-Since in this case you do not care about a warning about not being able290290-to select the specified device node number, you can call the function291291-video_register_device_no_warn() instead.292292-293293-Whenever a device node is created some attributes are also created for you.294294-If you look in /sys/class/video4linux you see the devices. Go into e.g.295295-video0 and you will see 'name', 'dev_debug' and 'index' attributes. The 'name'296296-attribute is the 'name' field of the video_device struct. The 'dev_debug' attribute297297-can be used to enable core debugging. See the next section for more detailed298298-information on this.299299-300300-The 'index' attribute is the index of the device node: for each call to301301-video_register_device() the index is just increased by 1. The first video302302-device node you register always starts with index 0.303303-304304-Users can setup udev rules that utilize the index attribute to make fancy305305-device names (e.g. 'mpegX' for MPEG video capture device nodes).306306-307307-After the device was successfully registered, then you can use these fields:308308-309309-- vfl_type: the device type passed to video_register_device.310310-- minor: the assigned device minor number.311311-- num: the device node number (i.e. the X in videoX).312312-- index: the device index number.313313-314314-If the registration failed, then you need to call video_device_release()315315-to free the allocated video_device struct, or free your own struct if the316316-video_device was embedded in it. The vdev->release() callback will never317317-be called if the registration failed, nor should you ever attempt to318318-unregister the device if the registration failed.319319-320320-video device debugging321321-----------------------322322-323323-The 'dev_debug' attribute that is created for each video, vbi, radio or swradio324324-device in /sys/class/video4linux/<devX>/ allows you to enable logging of325325-file operations.326326-327327-It is a bitmask and the following bits can be set:328328-329329-.. code-block:: none330330-331331- 0x01: Log the ioctl name and error code. VIDIOC_(D)QBUF ioctls are only logged332332- if bit 0x08 is also set.333333- 0x02: Log the ioctl name arguments and error code. VIDIOC_(D)QBUF ioctls are334334- only logged if bit 0x08 is also set.335335- 0x04: Log the file operations open, release, read, write, mmap and336336- get_unmapped_area. The read and write operations are only logged if337337- bit 0x08 is also set.338338- 0x08: Log the read and write file operations and the VIDIOC_QBUF and339339- VIDIOC_DQBUF ioctls.340340- 0x10: Log the poll file operation.341341-342342-video_device cleanup343343---------------------344344-345345-When the video device nodes have to be removed, either during the unload346346-of the driver or because the USB device was disconnected, then you should347347-unregister them:348348-349349-.. code-block:: none350350-351351- video_unregister_device(vdev);352352-353353-This will remove the device nodes from sysfs (causing udev to remove them354354-from /dev).355355-356356-After video_unregister_device() returns no new opens can be done. However,357357-in the case of USB devices some application might still have one of these358358-device nodes open. So after the unregister all file operations (except359359-release, of course) will return an error as well.360360-361361-When the last user of the video device node exits, then the vdev->release()362362-callback is called and you can do the final cleanup there.363363-364364-Don't forget to cleanup the media entity associated with the video device if365365-it has been initialized:366366-367367-.. code-block:: none368368-369369- media_entity_cleanup(&vdev->entity);370370-371371-This can be done from the release callback.372372-373373-374374-video_device helper functions375375------------------------------376376-377377-There are a few useful helper functions:378378-379379-- file/video_device private data380380-381381-You can set/get driver private data in the video_device struct using:382382-383383-.. code-block:: none384384-385385- void *video_get_drvdata(struct video_device *vdev);386386- void video_set_drvdata(struct video_device *vdev, void *data);387387-388388-Note that you can safely call video_set_drvdata() before calling389389-video_register_device().390390-391391-And this function:392392-393393-.. code-block:: none394394-395395- struct video_device *video_devdata(struct file *file);396396-397397-returns the video_device belonging to the file struct.398398-399399-The video_drvdata function combines video_get_drvdata with video_devdata:400400-401401-.. code-block:: none402402-403403- void *video_drvdata(struct file *file);404404-405405-You can go from a video_device struct to the v4l2_device struct using:406406-407407-.. code-block:: none408408-409409- struct v4l2_device *v4l2_dev = vdev->v4l2_dev;410410-411411-- Device node name412412-413413-The video_device node kernel name can be retrieved using414414-415415-.. code-block:: none416416-417417- const char *video_device_node_name(struct video_device *vdev);418418-419419-The name is used as a hint by userspace tools such as udev. The function420420-should be used where possible instead of accessing the video_device::num and421421-video_device::minor fields.422422-4238442485video buffer helper functions42586-----------------------------···360699361700It is expected that once the CCF becomes available on all relevant362701architectures this API will be removed.363363-364364-video_device kAPI365365-^^^^^^^^^^^^^^^^^366366-367367-.. kernel-doc:: include/media/v4l2-dev.h