162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ciVideo device' s internal representation
462306a36Sopenharmony_ci=======================================
562306a36Sopenharmony_ci
662306a36Sopenharmony_ciThe actual device nodes in the ``/dev`` directory are created using the
762306a36Sopenharmony_ci:c:type:`video_device` struct (``v4l2-dev.h``). This struct can either be
862306a36Sopenharmony_ciallocated dynamically or embedded in a larger struct.
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciTo allocate it dynamically use :c:func:`video_device_alloc`:
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci.. code-block:: c
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci	struct video_device *vdev = video_device_alloc();
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci	if (vdev == NULL)
1762306a36Sopenharmony_ci		return -ENOMEM;
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci	vdev->release = video_device_release;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciIf you embed it in a larger struct, then you must set the ``release()``
2262306a36Sopenharmony_cicallback to your own function:
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci.. code-block:: c
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	struct video_device *vdev = &my_vdev->vdev;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	vdev->release = my_vdev_release;
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciThe ``release()`` callback must be set and it is called when the last user
3162306a36Sopenharmony_ciof the video device exits.
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciThe default :c:func:`video_device_release` callback currently
3462306a36Sopenharmony_cijust calls ``kfree`` to free the allocated memory.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciThere is also a :c:func:`video_device_release_empty` function that does
3762306a36Sopenharmony_cinothing (is empty) and should be used if the struct is embedded and there
3862306a36Sopenharmony_ciis nothing to do when it is released.
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ciYou should also set these fields of :c:type:`video_device`:
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci- :c:type:`video_device`->v4l2_dev: must be set to the :c:type:`v4l2_device`
4362306a36Sopenharmony_ci  parent device.
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci- :c:type:`video_device`->name: set to something descriptive and unique.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci- :c:type:`video_device`->vfl_dir: set this to ``VFL_DIR_RX`` for capture
4862306a36Sopenharmony_ci  devices (``VFL_DIR_RX`` has value 0, so this is normally already the
4962306a36Sopenharmony_ci  default), set to ``VFL_DIR_TX`` for output devices and ``VFL_DIR_M2M`` for mem2mem (codec) devices.
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci- :c:type:`video_device`->fops: set to the :c:type:`v4l2_file_operations`
5262306a36Sopenharmony_ci  struct.
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci- :c:type:`video_device`->ioctl_ops: if you use the :c:type:`v4l2_ioctl_ops`
5562306a36Sopenharmony_ci  to simplify ioctl maintenance (highly recommended to use this and it might
5662306a36Sopenharmony_ci  become compulsory in the future!), then set this to your
5762306a36Sopenharmony_ci  :c:type:`v4l2_ioctl_ops` struct. The :c:type:`video_device`->vfl_type and
5862306a36Sopenharmony_ci  :c:type:`video_device`->vfl_dir fields are used to disable ops that do not
5962306a36Sopenharmony_ci  match the type/dir combination. E.g. VBI ops are disabled for non-VBI nodes,
6062306a36Sopenharmony_ci  and output ops  are disabled for a capture device. This makes it possible to
6162306a36Sopenharmony_ci  provide just one :c:type:`v4l2_ioctl_ops` struct for both vbi and
6262306a36Sopenharmony_ci  video nodes.
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci- :c:type:`video_device`->lock: leave to ``NULL`` if you want to do all the
6562306a36Sopenharmony_ci  locking  in the driver. Otherwise you give it a pointer to a struct
6662306a36Sopenharmony_ci  ``mutex_lock`` and before the :c:type:`video_device`->unlocked_ioctl
6762306a36Sopenharmony_ci  file operation is called this lock will be taken by the core and released
6862306a36Sopenharmony_ci  afterwards. See the next section for more details.
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci- :c:type:`video_device`->queue: a pointer to the struct vb2_queue
7162306a36Sopenharmony_ci  associated with this device node.
7262306a36Sopenharmony_ci  If queue is not ``NULL``, and queue->lock is not ``NULL``, then queue->lock
7362306a36Sopenharmony_ci  is used for the queuing ioctls (``VIDIOC_REQBUFS``, ``CREATE_BUFS``,
7462306a36Sopenharmony_ci  ``QBUF``, ``DQBUF``,  ``QUERYBUF``, ``PREPARE_BUF``, ``STREAMON`` and
7562306a36Sopenharmony_ci  ``STREAMOFF``) instead of the lock above.
7662306a36Sopenharmony_ci  That way the :ref:`vb2 <vb2_framework>` queuing framework does not have
7762306a36Sopenharmony_ci  to wait for other ioctls.   This queue pointer is also used by the
7862306a36Sopenharmony_ci  :ref:`vb2 <vb2_framework>` helper functions to check for
7962306a36Sopenharmony_ci  queuing ownership (i.e. is the filehandle calling it allowed to do the
8062306a36Sopenharmony_ci  operation).
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci- :c:type:`video_device`->prio: keeps track of the priorities. Used to
8362306a36Sopenharmony_ci  implement ``VIDIOC_G_PRIORITY`` and ``VIDIOC_S_PRIORITY``.
8462306a36Sopenharmony_ci  If left to ``NULL``, then it will use the struct v4l2_prio_state
8562306a36Sopenharmony_ci  in :c:type:`v4l2_device`. If you want to have a separate priority state per
8662306a36Sopenharmony_ci  (group of) device node(s),   then you can point it to your own struct
8762306a36Sopenharmony_ci  :c:type:`v4l2_prio_state`.
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci- :c:type:`video_device`->dev_parent: you only set this if v4l2_device was
9062306a36Sopenharmony_ci  registered with ``NULL`` as the parent ``device`` struct. This only happens
9162306a36Sopenharmony_ci  in cases where one hardware device has multiple PCI devices that all share
9262306a36Sopenharmony_ci  the same :c:type:`v4l2_device` core.
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci  The cx88 driver is an example of this: one core :c:type:`v4l2_device` struct,
9562306a36Sopenharmony_ci  but   it is used by both a raw video PCI device (cx8800) and a MPEG PCI device
9662306a36Sopenharmony_ci  (cx8802). Since the :c:type:`v4l2_device` cannot be associated with two PCI
9762306a36Sopenharmony_ci  devices at the same time it is setup without a parent device. But when the
9862306a36Sopenharmony_ci  struct video_device is initialized you **do** know which parent
9962306a36Sopenharmony_ci  PCI device to use and so you set ``dev_device`` to the correct PCI device.
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciIf you use :c:type:`v4l2_ioctl_ops`, then you should set
10262306a36Sopenharmony_ci:c:type:`video_device`->unlocked_ioctl to :c:func:`video_ioctl2` in your
10362306a36Sopenharmony_ci:c:type:`v4l2_file_operations` struct.
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ciIn some cases you want to tell the core that a function you had specified in
10662306a36Sopenharmony_ciyour :c:type:`v4l2_ioctl_ops` should be ignored. You can mark such ioctls by
10762306a36Sopenharmony_cicalling this function before :c:func:`video_register_device` is called:
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	:c:func:`v4l2_disable_ioctl <v4l2_disable_ioctl>`
11062306a36Sopenharmony_ci	(:c:type:`vdev <video_device>`, cmd).
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciThis tends to be needed if based on external factors (e.g. which card is
11362306a36Sopenharmony_cibeing used) you want to turns off certain features in :c:type:`v4l2_ioctl_ops`
11462306a36Sopenharmony_ciwithout having to make a new struct.
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ciThe :c:type:`v4l2_file_operations` struct is a subset of file_operations.
11762306a36Sopenharmony_ciThe main difference is that the inode argument is omitted since it is never
11862306a36Sopenharmony_ciused.
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ciIf integration with the media framework is needed, you must initialize the
12162306a36Sopenharmony_ci:c:type:`media_entity` struct embedded in the :c:type:`video_device` struct
12262306a36Sopenharmony_ci(entity field) by calling :c:func:`media_entity_pads_init`:
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci.. code-block:: c
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci	struct media_pad *pad = &my_vdev->pad;
12762306a36Sopenharmony_ci	int err;
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	err = media_entity_pads_init(&vdev->entity, 1, pad);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ciThe pads array must have been previously initialized. There is no need to
13262306a36Sopenharmony_cimanually set the struct media_entity type and name fields.
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ciA reference to the entity will be automatically acquired/released when the
13562306a36Sopenharmony_civideo device is opened/closed.
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ciioctls and locking
13862306a36Sopenharmony_ci------------------
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ciThe V4L core provides optional locking services. The main service is the
14162306a36Sopenharmony_cilock field in struct video_device, which is a pointer to a mutex.
14262306a36Sopenharmony_ciIf you set this pointer, then that will be used by unlocked_ioctl to
14362306a36Sopenharmony_ciserialize all ioctls.
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciIf you are using the :ref:`videobuf2 framework <vb2_framework>`, then there
14662306a36Sopenharmony_ciis a second lock that you can set: :c:type:`video_device`->queue->lock. If
14762306a36Sopenharmony_ciset, then this lock will be used instead of :c:type:`video_device`->lock
14862306a36Sopenharmony_cito serialize all queuing ioctls (see the previous section
14962306a36Sopenharmony_cifor the full list of those ioctls).
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ciThe advantage of using a different lock for the queuing ioctls is that for some
15262306a36Sopenharmony_cidrivers (particularly USB drivers) certain commands such as setting controls
15362306a36Sopenharmony_cican take a long time, so you want to use a separate lock for the buffer queuing
15462306a36Sopenharmony_ciioctls. That way your ``VIDIOC_DQBUF`` doesn't stall because the driver is busy
15562306a36Sopenharmony_cichanging the e.g. exposure of the webcam.
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ciOf course, you can always do all the locking yourself by leaving both lock
15862306a36Sopenharmony_cipointers at ``NULL``.
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ciIf you use the old :ref:`videobuf framework <vb_framework>` then you must
16162306a36Sopenharmony_cipass the :c:type:`video_device`->lock to the videobuf queue initialize
16262306a36Sopenharmony_cifunction: if videobuf has to wait for a frame to arrive, then it will
16362306a36Sopenharmony_citemporarily unlock the lock and relock it afterwards. If your driver also
16462306a36Sopenharmony_ciwaits in the code, then you should do the same to allow other
16562306a36Sopenharmony_ciprocesses to access the device node while the first process is waiting for
16662306a36Sopenharmony_cisomething.
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ciIn the case of :ref:`videobuf2 <vb2_framework>` you will need to implement the
16962306a36Sopenharmony_ci``wait_prepare()`` and ``wait_finish()`` callbacks to unlock/lock if applicable.
17062306a36Sopenharmony_ciIf you use the ``queue->lock`` pointer, then you can use the helper functions
17162306a36Sopenharmony_ci:c:func:`vb2_ops_wait_prepare` and :c:func:`vb2_ops_wait_finish`.
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ciThe implementation of a hotplug disconnect should also take the lock from
17462306a36Sopenharmony_ci:c:type:`video_device` before calling v4l2_device_disconnect. If you are also
17562306a36Sopenharmony_ciusing :c:type:`video_device`->queue->lock, then you have to first lock
17662306a36Sopenharmony_ci:c:type:`video_device`->queue->lock followed by :c:type:`video_device`->lock.
17762306a36Sopenharmony_ciThat way you can be sure no ioctl is running when you call
17862306a36Sopenharmony_ci:c:func:`v4l2_device_disconnect`.
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ciVideo device registration
18162306a36Sopenharmony_ci-------------------------
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ciNext you register the video device with :c:func:`video_register_device`.
18462306a36Sopenharmony_ciThis will create the character device for you.
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci.. code-block:: c
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	err = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
18962306a36Sopenharmony_ci	if (err) {
19062306a36Sopenharmony_ci		video_device_release(vdev); /* or kfree(my_vdev); */
19162306a36Sopenharmony_ci		return err;
19262306a36Sopenharmony_ci	}
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ciIf the :c:type:`v4l2_device` parent device has a not ``NULL`` mdev field,
19562306a36Sopenharmony_cithe video device entity will be automatically registered with the media
19662306a36Sopenharmony_cidevice.
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ciWhich device is registered depends on the type argument. The following
19962306a36Sopenharmony_citypes exist:
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci========================== ====================	 ==============================
20262306a36Sopenharmony_ci:c:type:`vfl_devnode_type` Device name		 Usage
20362306a36Sopenharmony_ci========================== ====================	 ==============================
20462306a36Sopenharmony_ci``VFL_TYPE_VIDEO``         ``/dev/videoX``       for video input/output devices
20562306a36Sopenharmony_ci``VFL_TYPE_VBI``           ``/dev/vbiX``         for vertical blank data (i.e.
20662306a36Sopenharmony_ci						 closed captions, teletext)
20762306a36Sopenharmony_ci``VFL_TYPE_RADIO``         ``/dev/radioX``       for radio tuners
20862306a36Sopenharmony_ci``VFL_TYPE_SUBDEV``        ``/dev/v4l-subdevX``  for V4L2 subdevices
20962306a36Sopenharmony_ci``VFL_TYPE_SDR``           ``/dev/swradioX``     for Software Defined Radio
21062306a36Sopenharmony_ci						 (SDR) tuners
21162306a36Sopenharmony_ci``VFL_TYPE_TOUCH``         ``/dev/v4l-touchX``   for touch sensors
21262306a36Sopenharmony_ci========================== ====================	 ==============================
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ciThe last argument gives you a certain amount of control over the device
21562306a36Sopenharmony_cinode number used (i.e. the X in ``videoX``). Normally you will pass -1
21662306a36Sopenharmony_cito let the v4l2 framework pick the first free number. But sometimes users
21762306a36Sopenharmony_ciwant to select a specific node number. It is common that drivers allow
21862306a36Sopenharmony_cithe user to select a specific device node number through a driver module
21962306a36Sopenharmony_cioption. That number is then passed to this function and video_register_device
22062306a36Sopenharmony_ciwill attempt to select that device node number. If that number was already
22162306a36Sopenharmony_ciin use, then the next free device node number will be selected and it
22262306a36Sopenharmony_ciwill send a warning to the kernel log.
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ciAnother use-case is if a driver creates many devices. In that case it can
22562306a36Sopenharmony_cibe useful to place different video devices in separate ranges. For example,
22662306a36Sopenharmony_civideo capture devices start at 0, video output devices start at 16.
22762306a36Sopenharmony_ciSo you can use the last argument to specify a minimum device node number
22862306a36Sopenharmony_ciand the v4l2 framework will try to pick the first free number that is equal
22962306a36Sopenharmony_cior higher to what you passed. If that fails, then it will just pick the
23062306a36Sopenharmony_cifirst free number.
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ciSince in this case you do not care about a warning about not being able
23362306a36Sopenharmony_cito select the specified device node number, you can call the function
23462306a36Sopenharmony_ci:c:func:`video_register_device_no_warn` instead.
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ciWhenever a device node is created some attributes are also created for you.
23762306a36Sopenharmony_ciIf you look in ``/sys/class/video4linux`` you see the devices. Go into e.g.
23862306a36Sopenharmony_ci``video0`` and you will see 'name', 'dev_debug' and 'index' attributes. The
23962306a36Sopenharmony_ci'name' attribute is the 'name' field of the video_device struct. The
24062306a36Sopenharmony_ci'dev_debug' attribute can be used to enable core debugging. See the next
24162306a36Sopenharmony_cisection for more detailed information on this.
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ciThe 'index' attribute is the index of the device node: for each call to
24462306a36Sopenharmony_ci:c:func:`video_register_device()` the index is just increased by 1. The
24562306a36Sopenharmony_cifirst video device node you register always starts with index 0.
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ciUsers can setup udev rules that utilize the index attribute to make fancy
24862306a36Sopenharmony_cidevice names (e.g. '``mpegX``' for MPEG video capture device nodes).
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ciAfter the device was successfully registered, then you can use these fields:
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci- :c:type:`video_device`->vfl_type: the device type passed to
25362306a36Sopenharmony_ci  :c:func:`video_register_device`.
25462306a36Sopenharmony_ci- :c:type:`video_device`->minor: the assigned device minor number.
25562306a36Sopenharmony_ci- :c:type:`video_device`->num: the device node number (i.e. the X in
25662306a36Sopenharmony_ci  ``videoX``).
25762306a36Sopenharmony_ci- :c:type:`video_device`->index: the device index number.
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ciIf the registration failed, then you need to call
26062306a36Sopenharmony_ci:c:func:`video_device_release` to free the allocated :c:type:`video_device`
26162306a36Sopenharmony_cistruct, or free your own struct if the :c:type:`video_device` was embedded in
26262306a36Sopenharmony_ciit. The ``vdev->release()`` callback will never be called if the registration
26362306a36Sopenharmony_cifailed, nor should you ever attempt to unregister the device if the
26462306a36Sopenharmony_ciregistration failed.
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_civideo device debugging
26762306a36Sopenharmony_ci----------------------
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ciThe 'dev_debug' attribute that is created for each video, vbi, radio or swradio
27062306a36Sopenharmony_cidevice in ``/sys/class/video4linux/<devX>/`` allows you to enable logging of
27162306a36Sopenharmony_cifile operations.
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ciIt is a bitmask and the following bits can be set:
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci.. tabularcolumns:: |p{5ex}|L|
27662306a36Sopenharmony_ci
27762306a36Sopenharmony_ci===== ================================================================
27862306a36Sopenharmony_ciMask  Description
27962306a36Sopenharmony_ci===== ================================================================
28062306a36Sopenharmony_ci0x01  Log the ioctl name and error code. VIDIOC_(D)QBUF ioctls are
28162306a36Sopenharmony_ci      only logged if bit 0x08 is also set.
28262306a36Sopenharmony_ci0x02  Log the ioctl name arguments and error code. VIDIOC_(D)QBUF
28362306a36Sopenharmony_ci      ioctls are
28462306a36Sopenharmony_ci      only logged if bit 0x08 is also set.
28562306a36Sopenharmony_ci0x04  Log the file operations open, release, read, write, mmap and
28662306a36Sopenharmony_ci      get_unmapped_area. The read and write operations are only
28762306a36Sopenharmony_ci      logged if bit 0x08 is also set.
28862306a36Sopenharmony_ci0x08  Log the read and write file operations and the VIDIOC_QBUF and
28962306a36Sopenharmony_ci      VIDIOC_DQBUF ioctls.
29062306a36Sopenharmony_ci0x10  Log the poll file operation.
29162306a36Sopenharmony_ci0x20  Log error and messages in the control operations.
29262306a36Sopenharmony_ci===== ================================================================
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ciVideo device cleanup
29562306a36Sopenharmony_ci--------------------
29662306a36Sopenharmony_ci
29762306a36Sopenharmony_ciWhen the video device nodes have to be removed, either during the unload
29862306a36Sopenharmony_ciof the driver or because the USB device was disconnected, then you should
29962306a36Sopenharmony_ciunregister them with:
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci	:c:func:`video_unregister_device`
30262306a36Sopenharmony_ci	(:c:type:`vdev <video_device>`);
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ciThis will remove the device nodes from sysfs (causing udev to remove them
30562306a36Sopenharmony_cifrom ``/dev``).
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ciAfter :c:func:`video_unregister_device` returns no new opens can be done.
30862306a36Sopenharmony_ciHowever, in the case of USB devices some application might still have one of
30962306a36Sopenharmony_cithese device nodes open. So after the unregister all file operations (except
31062306a36Sopenharmony_cirelease, of course) will return an error as well.
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ciWhen the last user of the video device node exits, then the ``vdev->release()``
31362306a36Sopenharmony_cicallback is called and you can do the final cleanup there.
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ciDon't forget to cleanup the media entity associated with the video device if
31662306a36Sopenharmony_ciit has been initialized:
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci	:c:func:`media_entity_cleanup <media_entity_cleanup>`
31962306a36Sopenharmony_ci	(&vdev->entity);
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ciThis can be done from the release callback.
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_cihelper functions
32562306a36Sopenharmony_ci----------------
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ciThere are a few useful helper functions:
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ci- file and :c:type:`video_device` private data
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ciYou can set/get driver private data in the video_device struct using:
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci	:c:func:`video_get_drvdata <video_get_drvdata>`
33462306a36Sopenharmony_ci	(:c:type:`vdev <video_device>`);
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	:c:func:`video_set_drvdata <video_set_drvdata>`
33762306a36Sopenharmony_ci	(:c:type:`vdev <video_device>`);
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ciNote that you can safely call :c:func:`video_set_drvdata` before calling
34062306a36Sopenharmony_ci:c:func:`video_register_device`.
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ciAnd this function:
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci	:c:func:`video_devdata <video_devdata>`
34562306a36Sopenharmony_ci	(struct file \*file);
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_cireturns the video_device belonging to the file struct.
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ciThe :c:func:`video_devdata` function combines :c:func:`video_get_drvdata`
35062306a36Sopenharmony_ciwith :c:func:`video_devdata`:
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci	:c:func:`video_drvdata <video_drvdata>`
35362306a36Sopenharmony_ci	(struct file \*file);
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ciYou can go from a :c:type:`video_device` struct to the v4l2_device struct using:
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci.. code-block:: c
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci	struct v4l2_device *v4l2_dev = vdev->v4l2_dev;
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci- Device node name
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ciThe :c:type:`video_device` node kernel name can be retrieved using:
36462306a36Sopenharmony_ci
36562306a36Sopenharmony_ci	:c:func:`video_device_node_name <video_device_node_name>`
36662306a36Sopenharmony_ci	(:c:type:`vdev <video_device>`);
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ciThe name is used as a hint by userspace tools such as udev. The function
36962306a36Sopenharmony_cishould be used where possible instead of accessing the video_device::num and
37062306a36Sopenharmony_civideo_device::minor fields.
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_civideo_device functions and data structures
37362306a36Sopenharmony_ci------------------------------------------
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci.. kernel-doc:: include/media/v4l2-dev.h
376