camera-sensor.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. _media_using_camera_sensor_drivers:
  3. Using camera sensor drivers
  4. ===========================
  5. This section describes common practices for how the V4L2 sub-device interface is
  6. used to control the camera sensor drivers.
  7. You may also find :ref:`media_writing_camera_sensor_drivers` useful.
  8. Sensor internal pipeline configuration
  9. --------------------------------------
  10. Camera sensors have an internal processing pipeline including cropping and
  11. binning functionality. The sensor drivers belong to two distinct classes, freely
  12. configurable and register list-based drivers, depending on how the driver
  13. configures this functionality.
  14. Freely configurable camera sensor drivers
  15. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. Freely configurable camera sensor drivers expose the device's internal
  17. processing pipeline as one or more sub-devices with different cropping and
  18. scaling configurations. The output size of the device is the result of a series
  19. of cropping and scaling operations from the device's pixel array's size.
  20. An example of such a driver is the CCS driver.
  21. Register list-based drivers
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. Register list-based drivers generally, instead of able to configure the device
  24. they control based on user requests, are limited to a number of preset
  25. configurations that combine a number of different parameters that on hardware
  26. level are independent. How a driver picks such configuration is based on the
  27. format set on a source pad at the end of the device's internal pipeline.
  28. Most sensor drivers are implemented this way.
  29. Frame interval configuration
  30. ----------------------------
  31. There are two different methods for obtaining possibilities for different frame
  32. intervals as well as configuring the frame interval. Which one to implement
  33. depends on the type of the device.
  34. Raw camera sensors
  35. ~~~~~~~~~~~~~~~~~~
  36. Instead of a high level parameter such as frame interval, the frame interval is
  37. a result of the configuration of a number of camera sensor implementation
  38. specific parameters. Luckily, these parameters tend to be the same for more or
  39. less all modern raw camera sensors.
  40. The frame interval is calculated using the following equation::
  41. frame interval = (analogue crop width + horizontal blanking) *
  42. (analogue crop height + vertical blanking) / pixel rate
  43. The formula is bus independent and is applicable for raw timing parameters on
  44. large variety of devices beyond camera sensors. Devices that have no analogue
  45. crop, use the full source image size, i.e. pixel array size.
  46. Horizontal and vertical blanking are specified by ``V4L2_CID_HBLANK`` and
  47. ``V4L2_CID_VBLANK``, respectively. The unit of the ``V4L2_CID_HBLANK`` control
  48. is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in
  49. the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same
  50. sub-device. The unit of that control is pixels per second.
  51. Register list-based drivers need to implement read-only sub-device nodes for the
  52. purpose. Devices that are not register list based need these to configure the
  53. device's internal processing pipeline.
  54. The first entity in the linear pipeline is the pixel array. The pixel array may
  55. be followed by other entities that are there to allow configuring binning,
  56. skipping, scaling or digital crop, see :ref:`VIDIOC_SUBDEV_G_SELECTION
  57. <VIDIOC_SUBDEV_G_SELECTION>`.
  58. USB cameras etc. devices
  59. ~~~~~~~~~~~~~~~~~~~~~~~~
  60. USB video class hardware, as well as many cameras offering a similar higher
  61. level interface natively, generally use the concept of frame interval (or frame
  62. rate) on device level in firmware or hardware. This means lower level controls
  63. implemented by raw cameras may not be used on uAPI (or even kAPI) to control the
  64. frame interval on these devices.
  65. Rotation, orientation and flipping
  66. ----------------------------------
  67. Some systems have the camera sensor mounted upside down compared to its natural
  68. mounting rotation. In such cases, drivers shall expose the information to
  69. userspace with the :ref:`V4L2_CID_CAMERA_SENSOR_ROTATION
  70. <v4l2-camera-sensor-rotation>` control.
  71. Sensor drivers shall also report the sensor's mounting orientation with the
  72. :ref:`V4L2_CID_CAMERA_SENSOR_ORIENTATION <v4l2-camera-sensor-orientation>`.
  73. Sensor drivers that have any vertical or horizontal flips embedded in the
  74. register programming sequences shall initialize the :ref:`V4L2_CID_HFLIP
  75. <v4l2-cid-hflip>` and :ref:`V4L2_CID_VFLIP <v4l2-cid-vflip>` controls with the
  76. values programmed by the register sequences. The default values of these
  77. controls shall be 0 (disabled). Especially these controls shall not be inverted,
  78. independently of the sensor's mounting rotation.