1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunVideo device' s internal representation 4*4882a593Smuzhiyun======================================= 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunThe actual device nodes in the ``/dev`` directory are created using the 7*4882a593Smuzhiyun:c:type:`video_device` struct (``v4l2-dev.h``). This struct can either be 8*4882a593Smuzhiyunallocated dynamically or embedded in a larger struct. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunTo allocate it dynamically use :c:func:`video_device_alloc`: 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun.. code-block:: c 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun struct video_device *vdev = video_device_alloc(); 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun if (vdev == NULL) 17*4882a593Smuzhiyun return -ENOMEM; 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun vdev->release = video_device_release; 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunIf you embed it in a larger struct, then you must set the ``release()`` 22*4882a593Smuzhiyuncallback to your own function: 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun.. code-block:: c 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun struct video_device *vdev = &my_vdev->vdev; 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun vdev->release = my_vdev_release; 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunThe ``release()`` callback must be set and it is called when the last user 31*4882a593Smuzhiyunof the video device exits. 32*4882a593Smuzhiyun 33*4882a593SmuzhiyunThe default :c:func:`video_device_release` callback currently 34*4882a593Smuzhiyunjust calls ``kfree`` to free the allocated memory. 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunThere is also a :c:func:`video_device_release_empty` function that does 37*4882a593Smuzhiyunnothing (is empty) and should be used if the struct is embedded and there 38*4882a593Smuzhiyunis nothing to do when it is released. 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunYou should also set these fields of :c:type:`video_device`: 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun- :c:type:`video_device`->v4l2_dev: must be set to the :c:type:`v4l2_device` 43*4882a593Smuzhiyun parent device. 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun- :c:type:`video_device`->name: set to something descriptive and unique. 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun- :c:type:`video_device`->vfl_dir: set this to ``VFL_DIR_RX`` for capture 48*4882a593Smuzhiyun devices (``VFL_DIR_RX`` has value 0, so this is normally already the 49*4882a593Smuzhiyun default), set to ``VFL_DIR_TX`` for output devices and ``VFL_DIR_M2M`` for mem2mem (codec) devices. 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun- :c:type:`video_device`->fops: set to the :c:type:`v4l2_file_operations` 52*4882a593Smuzhiyun struct. 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun- :c:type:`video_device`->ioctl_ops: if you use the :c:type:`v4l2_ioctl_ops` 55*4882a593Smuzhiyun to simplify ioctl maintenance (highly recommended to use this and it might 56*4882a593Smuzhiyun become compulsory in the future!), then set this to your 57*4882a593Smuzhiyun :c:type:`v4l2_ioctl_ops` struct. The :c:type:`video_device`->vfl_type and 58*4882a593Smuzhiyun :c:type:`video_device`->vfl_dir fields are used to disable ops that do not 59*4882a593Smuzhiyun match the type/dir combination. E.g. VBI ops are disabled for non-VBI nodes, 60*4882a593Smuzhiyun and output ops are disabled for a capture device. This makes it possible to 61*4882a593Smuzhiyun provide just one :c:type:`v4l2_ioctl_ops` struct for both vbi and 62*4882a593Smuzhiyun video nodes. 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun- :c:type:`video_device`->lock: leave to ``NULL`` if you want to do all the 65*4882a593Smuzhiyun locking in the driver. Otherwise you give it a pointer to a struct 66*4882a593Smuzhiyun ``mutex_lock`` and before the :c:type:`video_device`->unlocked_ioctl 67*4882a593Smuzhiyun file operation is called this lock will be taken by the core and released 68*4882a593Smuzhiyun afterwards. See the next section for more details. 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun- :c:type:`video_device`->queue: a pointer to the struct vb2_queue 71*4882a593Smuzhiyun associated with this device node. 72*4882a593Smuzhiyun If queue is not ``NULL``, and queue->lock is not ``NULL``, then queue->lock 73*4882a593Smuzhiyun is used for the queuing ioctls (``VIDIOC_REQBUFS``, ``CREATE_BUFS``, 74*4882a593Smuzhiyun ``QBUF``, ``DQBUF``, ``QUERYBUF``, ``PREPARE_BUF``, ``STREAMON`` and 75*4882a593Smuzhiyun ``STREAMOFF``) instead of the lock above. 76*4882a593Smuzhiyun That way the :ref:`vb2 <vb2_framework>` queuing framework does not have 77*4882a593Smuzhiyun to wait for other ioctls. This queue pointer is also used by the 78*4882a593Smuzhiyun :ref:`vb2 <vb2_framework>` helper functions to check for 79*4882a593Smuzhiyun queuing ownership (i.e. is the filehandle calling it allowed to do the 80*4882a593Smuzhiyun operation). 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun- :c:type:`video_device`->prio: keeps track of the priorities. Used to 83*4882a593Smuzhiyun implement ``VIDIOC_G_PRIORITY`` and ``VIDIOC_S_PRIORITY``. 84*4882a593Smuzhiyun If left to ``NULL``, then it will use the struct v4l2_prio_state 85*4882a593Smuzhiyun in :c:type:`v4l2_device`. If you want to have a separate priority state per 86*4882a593Smuzhiyun (group of) device node(s), then you can point it to your own struct 87*4882a593Smuzhiyun :c:type:`v4l2_prio_state`. 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun- :c:type:`video_device`->dev_parent: you only set this if v4l2_device was 90*4882a593Smuzhiyun registered with ``NULL`` as the parent ``device`` struct. This only happens 91*4882a593Smuzhiyun in cases where one hardware device has multiple PCI devices that all share 92*4882a593Smuzhiyun the same :c:type:`v4l2_device` core. 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun The cx88 driver is an example of this: one core :c:type:`v4l2_device` struct, 95*4882a593Smuzhiyun but it is used by both a raw video PCI device (cx8800) and a MPEG PCI device 96*4882a593Smuzhiyun (cx8802). Since the :c:type:`v4l2_device` cannot be associated with two PCI 97*4882a593Smuzhiyun devices at the same time it is setup without a parent device. But when the 98*4882a593Smuzhiyun struct video_device is initialized you **do** know which parent 99*4882a593Smuzhiyun PCI device to use and so you set ``dev_device`` to the correct PCI device. 100*4882a593Smuzhiyun 101*4882a593SmuzhiyunIf you use :c:type:`v4l2_ioctl_ops`, then you should set 102*4882a593Smuzhiyun:c:type:`video_device`->unlocked_ioctl to :c:func:`video_ioctl2` in your 103*4882a593Smuzhiyun:c:type:`v4l2_file_operations` struct. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunIn some cases you want to tell the core that a function you had specified in 106*4882a593Smuzhiyunyour :c:type:`v4l2_ioctl_ops` should be ignored. You can mark such ioctls by 107*4882a593Smuzhiyuncalling this function before :c:func:`video_register_device` is called: 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun :c:func:`v4l2_disable_ioctl <v4l2_disable_ioctl>` 110*4882a593Smuzhiyun (:c:type:`vdev <video_device>`, cmd). 111*4882a593Smuzhiyun 112*4882a593SmuzhiyunThis tends to be needed if based on external factors (e.g. which card is 113*4882a593Smuzhiyunbeing used) you want to turns off certain features in :c:type:`v4l2_ioctl_ops` 114*4882a593Smuzhiyunwithout having to make a new struct. 115*4882a593Smuzhiyun 116*4882a593SmuzhiyunThe :c:type:`v4l2_file_operations` struct is a subset of file_operations. 117*4882a593SmuzhiyunThe main difference is that the inode argument is omitted since it is never 118*4882a593Smuzhiyunused. 119*4882a593Smuzhiyun 120*4882a593SmuzhiyunIf integration with the media framework is needed, you must initialize the 121*4882a593Smuzhiyun:c:type:`media_entity` struct embedded in the :c:type:`video_device` struct 122*4882a593Smuzhiyun(entity field) by calling :c:func:`media_entity_pads_init`: 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun.. code-block:: c 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun struct media_pad *pad = &my_vdev->pad; 127*4882a593Smuzhiyun int err; 128*4882a593Smuzhiyun 129*4882a593Smuzhiyun err = media_entity_pads_init(&vdev->entity, 1, pad); 130*4882a593Smuzhiyun 131*4882a593SmuzhiyunThe pads array must have been previously initialized. There is no need to 132*4882a593Smuzhiyunmanually set the struct media_entity type and name fields. 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunA reference to the entity will be automatically acquired/released when the 135*4882a593Smuzhiyunvideo device is opened/closed. 136*4882a593Smuzhiyun 137*4882a593Smuzhiyunioctls and locking 138*4882a593Smuzhiyun------------------ 139*4882a593Smuzhiyun 140*4882a593SmuzhiyunThe V4L core provides optional locking services. The main service is the 141*4882a593Smuzhiyunlock field in struct video_device, which is a pointer to a mutex. 142*4882a593SmuzhiyunIf you set this pointer, then that will be used by unlocked_ioctl to 143*4882a593Smuzhiyunserialize all ioctls. 144*4882a593Smuzhiyun 145*4882a593SmuzhiyunIf you are using the :ref:`videobuf2 framework <vb2_framework>`, then there 146*4882a593Smuzhiyunis a second lock that you can set: :c:type:`video_device`->queue->lock. If 147*4882a593Smuzhiyunset, then this lock will be used instead of :c:type:`video_device`->lock 148*4882a593Smuzhiyunto serialize all queuing ioctls (see the previous section 149*4882a593Smuzhiyunfor the full list of those ioctls). 150*4882a593Smuzhiyun 151*4882a593SmuzhiyunThe advantage of using a different lock for the queuing ioctls is that for some 152*4882a593Smuzhiyundrivers (particularly USB drivers) certain commands such as setting controls 153*4882a593Smuzhiyuncan take a long time, so you want to use a separate lock for the buffer queuing 154*4882a593Smuzhiyunioctls. That way your ``VIDIOC_DQBUF`` doesn't stall because the driver is busy 155*4882a593Smuzhiyunchanging the e.g. exposure of the webcam. 156*4882a593Smuzhiyun 157*4882a593SmuzhiyunOf course, you can always do all the locking yourself by leaving both lock 158*4882a593Smuzhiyunpointers at ``NULL``. 159*4882a593Smuzhiyun 160*4882a593SmuzhiyunIf you use the old :ref:`videobuf framework <vb_framework>` then you must 161*4882a593Smuzhiyunpass the :c:type:`video_device`->lock to the videobuf queue initialize 162*4882a593Smuzhiyunfunction: if videobuf has to wait for a frame to arrive, then it will 163*4882a593Smuzhiyuntemporarily unlock the lock and relock it afterwards. If your driver also 164*4882a593Smuzhiyunwaits in the code, then you should do the same to allow other 165*4882a593Smuzhiyunprocesses to access the device node while the first process is waiting for 166*4882a593Smuzhiyunsomething. 167*4882a593Smuzhiyun 168*4882a593SmuzhiyunIn the case of :ref:`videobuf2 <vb2_framework>` you will need to implement the 169*4882a593Smuzhiyun``wait_prepare()`` and ``wait_finish()`` callbacks to unlock/lock if applicable. 170*4882a593SmuzhiyunIf you use the ``queue->lock`` pointer, then you can use the helper functions 171*4882a593Smuzhiyun:c:func:`vb2_ops_wait_prepare` and :c:func:`vb2_ops_wait_finish`. 172*4882a593Smuzhiyun 173*4882a593SmuzhiyunThe implementation of a hotplug disconnect should also take the lock from 174*4882a593Smuzhiyun:c:type:`video_device` before calling v4l2_device_disconnect. If you are also 175*4882a593Smuzhiyunusing :c:type:`video_device`->queue->lock, then you have to first lock 176*4882a593Smuzhiyun:c:type:`video_device`->queue->lock followed by :c:type:`video_device`->lock. 177*4882a593SmuzhiyunThat way you can be sure no ioctl is running when you call 178*4882a593Smuzhiyun:c:func:`v4l2_device_disconnect`. 179*4882a593Smuzhiyun 180*4882a593SmuzhiyunVideo device registration 181*4882a593Smuzhiyun------------------------- 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunNext you register the video device with :c:func:`video_register_device`. 184*4882a593SmuzhiyunThis will create the character device for you. 185*4882a593Smuzhiyun 186*4882a593Smuzhiyun.. code-block:: c 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun err = video_register_device(vdev, VFL_TYPE_VIDEO, -1); 189*4882a593Smuzhiyun if (err) { 190*4882a593Smuzhiyun video_device_release(vdev); /* or kfree(my_vdev); */ 191*4882a593Smuzhiyun return err; 192*4882a593Smuzhiyun } 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunIf the :c:type:`v4l2_device` parent device has a not ``NULL`` mdev field, 195*4882a593Smuzhiyunthe video device entity will be automatically registered with the media 196*4882a593Smuzhiyundevice. 197*4882a593Smuzhiyun 198*4882a593SmuzhiyunWhich device is registered depends on the type argument. The following 199*4882a593Smuzhiyuntypes exist: 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun========================== ==================== ============================== 202*4882a593Smuzhiyun:c:type:`vfl_devnode_type` Device name Usage 203*4882a593Smuzhiyun========================== ==================== ============================== 204*4882a593Smuzhiyun``VFL_TYPE_VIDEO`` ``/dev/videoX`` for video input/output devices 205*4882a593Smuzhiyun``VFL_TYPE_VBI`` ``/dev/vbiX`` for vertical blank data (i.e. 206*4882a593Smuzhiyun closed captions, teletext) 207*4882a593Smuzhiyun``VFL_TYPE_RADIO`` ``/dev/radioX`` for radio tuners 208*4882a593Smuzhiyun``VFL_TYPE_SUBDEV`` ``/dev/v4l-subdevX`` for V4L2 subdevices 209*4882a593Smuzhiyun``VFL_TYPE_SDR`` ``/dev/swradioX`` for Software Defined Radio 210*4882a593Smuzhiyun (SDR) tuners 211*4882a593Smuzhiyun``VFL_TYPE_TOUCH`` ``/dev/v4l-touchX`` for touch sensors 212*4882a593Smuzhiyun========================== ==================== ============================== 213*4882a593Smuzhiyun 214*4882a593SmuzhiyunThe last argument gives you a certain amount of control over the device 215*4882a593Smuzhiyundevice node number used (i.e. the X in ``videoX``). Normally you will pass -1 216*4882a593Smuzhiyunto let the v4l2 framework pick the first free number. But sometimes users 217*4882a593Smuzhiyunwant to select a specific node number. It is common that drivers allow 218*4882a593Smuzhiyunthe user to select a specific device node number through a driver module 219*4882a593Smuzhiyunoption. That number is then passed to this function and video_register_device 220*4882a593Smuzhiyunwill attempt to select that device node number. If that number was already 221*4882a593Smuzhiyunin use, then the next free device node number will be selected and it 222*4882a593Smuzhiyunwill send a warning to the kernel log. 223*4882a593Smuzhiyun 224*4882a593SmuzhiyunAnother use-case is if a driver creates many devices. In that case it can 225*4882a593Smuzhiyunbe useful to place different video devices in separate ranges. For example, 226*4882a593Smuzhiyunvideo capture devices start at 0, video output devices start at 16. 227*4882a593SmuzhiyunSo you can use the last argument to specify a minimum device node number 228*4882a593Smuzhiyunand the v4l2 framework will try to pick the first free number that is equal 229*4882a593Smuzhiyunor higher to what you passed. If that fails, then it will just pick the 230*4882a593Smuzhiyunfirst free number. 231*4882a593Smuzhiyun 232*4882a593SmuzhiyunSince in this case you do not care about a warning about not being able 233*4882a593Smuzhiyunto select the specified device node number, you can call the function 234*4882a593Smuzhiyun:c:func:`video_register_device_no_warn` instead. 235*4882a593Smuzhiyun 236*4882a593SmuzhiyunWhenever a device node is created some attributes are also created for you. 237*4882a593SmuzhiyunIf you look in ``/sys/class/video4linux`` you see the devices. Go into e.g. 238*4882a593Smuzhiyun``video0`` and you will see 'name', 'dev_debug' and 'index' attributes. The 239*4882a593Smuzhiyun'name' attribute is the 'name' field of the video_device struct. The 240*4882a593Smuzhiyun'dev_debug' attribute can be used to enable core debugging. See the next 241*4882a593Smuzhiyunsection for more detailed information on this. 242*4882a593Smuzhiyun 243*4882a593SmuzhiyunThe 'index' attribute is the index of the device node: for each call to 244*4882a593Smuzhiyun:c:func:`video_register_device()` the index is just increased by 1. The 245*4882a593Smuzhiyunfirst video device node you register always starts with index 0. 246*4882a593Smuzhiyun 247*4882a593SmuzhiyunUsers can setup udev rules that utilize the index attribute to make fancy 248*4882a593Smuzhiyundevice names (e.g. '``mpegX``' for MPEG video capture device nodes). 249*4882a593Smuzhiyun 250*4882a593SmuzhiyunAfter the device was successfully registered, then you can use these fields: 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun- :c:type:`video_device`->vfl_type: the device type passed to 253*4882a593Smuzhiyun :c:func:`video_register_device`. 254*4882a593Smuzhiyun- :c:type:`video_device`->minor: the assigned device minor number. 255*4882a593Smuzhiyun- :c:type:`video_device`->num: the device node number (i.e. the X in 256*4882a593Smuzhiyun ``videoX``). 257*4882a593Smuzhiyun- :c:type:`video_device`->index: the device index number. 258*4882a593Smuzhiyun 259*4882a593SmuzhiyunIf the registration failed, then you need to call 260*4882a593Smuzhiyun:c:func:`video_device_release` to free the allocated :c:type:`video_device` 261*4882a593Smuzhiyunstruct, or free your own struct if the :c:type:`video_device` was embedded in 262*4882a593Smuzhiyunit. The ``vdev->release()`` callback will never be called if the registration 263*4882a593Smuzhiyunfailed, nor should you ever attempt to unregister the device if the 264*4882a593Smuzhiyunregistration failed. 265*4882a593Smuzhiyun 266*4882a593Smuzhiyunvideo device debugging 267*4882a593Smuzhiyun---------------------- 268*4882a593Smuzhiyun 269*4882a593SmuzhiyunThe 'dev_debug' attribute that is created for each video, vbi, radio or swradio 270*4882a593Smuzhiyundevice in ``/sys/class/video4linux/<devX>/`` allows you to enable logging of 271*4882a593Smuzhiyunfile operations. 272*4882a593Smuzhiyun 273*4882a593SmuzhiyunIt is a bitmask and the following bits can be set: 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun.. tabularcolumns:: |p{5ex}|L| 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun===== ================================================================ 278*4882a593SmuzhiyunMask Description 279*4882a593Smuzhiyun===== ================================================================ 280*4882a593Smuzhiyun0x01 Log the ioctl name and error code. VIDIOC_(D)QBUF ioctls are 281*4882a593Smuzhiyun only logged if bit 0x08 is also set. 282*4882a593Smuzhiyun0x02 Log the ioctl name arguments and error code. VIDIOC_(D)QBUF 283*4882a593Smuzhiyun ioctls are 284*4882a593Smuzhiyun only logged if bit 0x08 is also set. 285*4882a593Smuzhiyun0x04 Log the file operations open, release, read, write, mmap and 286*4882a593Smuzhiyun get_unmapped_area. The read and write operations are only 287*4882a593Smuzhiyun logged if bit 0x08 is also set. 288*4882a593Smuzhiyun0x08 Log the read and write file operations and the VIDIOC_QBUF and 289*4882a593Smuzhiyun VIDIOC_DQBUF ioctls. 290*4882a593Smuzhiyun0x10 Log the poll file operation. 291*4882a593Smuzhiyun0x20 Log error and messages in the control operations. 292*4882a593Smuzhiyun===== ================================================================ 293*4882a593Smuzhiyun 294*4882a593SmuzhiyunVideo device cleanup 295*4882a593Smuzhiyun-------------------- 296*4882a593Smuzhiyun 297*4882a593SmuzhiyunWhen the video device nodes have to be removed, either during the unload 298*4882a593Smuzhiyunof the driver or because the USB device was disconnected, then you should 299*4882a593Smuzhiyununregister them with: 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun :c:func:`video_unregister_device` 302*4882a593Smuzhiyun (:c:type:`vdev <video_device>`); 303*4882a593Smuzhiyun 304*4882a593SmuzhiyunThis will remove the device nodes from sysfs (causing udev to remove them 305*4882a593Smuzhiyunfrom ``/dev``). 306*4882a593Smuzhiyun 307*4882a593SmuzhiyunAfter :c:func:`video_unregister_device` returns no new opens can be done. 308*4882a593SmuzhiyunHowever, in the case of USB devices some application might still have one of 309*4882a593Smuzhiyunthese device nodes open. So after the unregister all file operations (except 310*4882a593Smuzhiyunrelease, of course) will return an error as well. 311*4882a593Smuzhiyun 312*4882a593SmuzhiyunWhen the last user of the video device node exits, then the ``vdev->release()`` 313*4882a593Smuzhiyuncallback is called and you can do the final cleanup there. 314*4882a593Smuzhiyun 315*4882a593SmuzhiyunDon't forget to cleanup the media entity associated with the video device if 316*4882a593Smuzhiyunit has been initialized: 317*4882a593Smuzhiyun 318*4882a593Smuzhiyun :c:func:`media_entity_cleanup <media_entity_cleanup>` 319*4882a593Smuzhiyun (&vdev->entity); 320*4882a593Smuzhiyun 321*4882a593SmuzhiyunThis can be done from the release callback. 322*4882a593Smuzhiyun 323*4882a593Smuzhiyun 324*4882a593Smuzhiyunhelper functions 325*4882a593Smuzhiyun---------------- 326*4882a593Smuzhiyun 327*4882a593SmuzhiyunThere are a few useful helper functions: 328*4882a593Smuzhiyun 329*4882a593Smuzhiyun- file and :c:type:`video_device` private data 330*4882a593Smuzhiyun 331*4882a593SmuzhiyunYou can set/get driver private data in the video_device struct using: 332*4882a593Smuzhiyun 333*4882a593Smuzhiyun :c:func:`video_get_drvdata <video_get_drvdata>` 334*4882a593Smuzhiyun (:c:type:`vdev <video_device>`); 335*4882a593Smuzhiyun 336*4882a593Smuzhiyun :c:func:`video_set_drvdata <video_set_drvdata>` 337*4882a593Smuzhiyun (:c:type:`vdev <video_device>`); 338*4882a593Smuzhiyun 339*4882a593SmuzhiyunNote that you can safely call :c:func:`video_set_drvdata` before calling 340*4882a593Smuzhiyun:c:func:`video_register_device`. 341*4882a593Smuzhiyun 342*4882a593SmuzhiyunAnd this function: 343*4882a593Smuzhiyun 344*4882a593Smuzhiyun :c:func:`video_devdata <video_devdata>` 345*4882a593Smuzhiyun (struct file \*file); 346*4882a593Smuzhiyun 347*4882a593Smuzhiyunreturns the video_device belonging to the file struct. 348*4882a593Smuzhiyun 349*4882a593SmuzhiyunThe :c:func:`video_devdata` function combines :c:func:`video_get_drvdata` 350*4882a593Smuzhiyunwith :c:func:`video_devdata`: 351*4882a593Smuzhiyun 352*4882a593Smuzhiyun :c:func:`video_drvdata <video_drvdata>` 353*4882a593Smuzhiyun (struct file \*file); 354*4882a593Smuzhiyun 355*4882a593SmuzhiyunYou can go from a :c:type:`video_device` struct to the v4l2_device struct using: 356*4882a593Smuzhiyun 357*4882a593Smuzhiyun.. code-block:: c 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun struct v4l2_device *v4l2_dev = vdev->v4l2_dev; 360*4882a593Smuzhiyun 361*4882a593Smuzhiyun- Device node name 362*4882a593Smuzhiyun 363*4882a593SmuzhiyunThe :c:type:`video_device` node kernel name can be retrieved using: 364*4882a593Smuzhiyun 365*4882a593Smuzhiyun :c:func:`video_device_node_name <video_device_node_name>` 366*4882a593Smuzhiyun (:c:type:`vdev <video_device>`); 367*4882a593Smuzhiyun 368*4882a593SmuzhiyunThe name is used as a hint by userspace tools such as udev. The function 369*4882a593Smuzhiyunshould be used where possible instead of accessing the video_device::num and 370*4882a593Smuzhiyunvideo_device::minor fields. 371*4882a593Smuzhiyun 372*4882a593Smuzhiyunvideo_device functions and data structures 373*4882a593Smuzhiyun------------------------------------------ 374*4882a593Smuzhiyun 375*4882a593Smuzhiyun.. kernel-doc:: include/media/v4l2-dev.h 376