tx-rx.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. _transmitter-receiver:
  3. Pixel data transmitter and receiver drivers
  4. ===========================================
  5. V4L2 supports various devices that transmit and receive pixel data. Examples of
  6. these devices include a camera sensor, a TV tuner and a parallel, a BT.656 or a
  7. CSI-2 receiver in an SoC.
  8. Bus types
  9. ---------
  10. The following buses are the most common. This section discusses these two only.
  11. MIPI CSI-2
  12. ^^^^^^^^^^
  13. CSI-2 is a data bus intended for transferring images from cameras to
  14. the host SoC. It is defined by the `MIPI alliance`_.
  15. .. _`MIPI alliance`: https://www.mipi.org/
  16. Parallel and BT.656
  17. ^^^^^^^^^^^^^^^^^^^
  18. The parallel and `BT.656`_ buses transport one bit of data on each clock cycle
  19. per data line. The parallel bus uses synchronisation and other additional
  20. signals whereas BT.656 embeds synchronisation.
  21. .. _`BT.656`: https://en.wikipedia.org/wiki/ITU-R_BT.656
  22. Transmitter drivers
  23. -------------------
  24. Transmitter drivers generally need to provide the receiver drivers with the
  25. configuration of the transmitter. What is required depends on the type of the
  26. bus. These are common for both buses.
  27. Media bus pixel code
  28. ^^^^^^^^^^^^^^^^^^^^
  29. See :ref:`v4l2-mbus-pixelcode`.
  30. Link frequency
  31. ^^^^^^^^^^^^^^
  32. The :ref:`V4L2_CID_LINK_FREQ <v4l2-cid-link-freq>` control is used to tell the
  33. receiver the frequency of the bus (i.e. it is not the same as the symbol rate).
  34. Drivers that do not have user-configurable link frequency should report it
  35. through the ``.get_mbus_config()`` subdev pad operation, in the ``link_freq``
  36. field of struct v4l2_mbus_config, instead of through controls.
  37. Receiver drivers should use :c:func:`v4l2_get_link_freq` helper to obtain the
  38. link frequency from the transmitter sub-device.
  39. ``.enable_streams()`` and ``.disable_streams()`` callbacks
  40. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  41. The struct v4l2_subdev_pad_ops->enable_streams() and struct
  42. v4l2_subdev_pad_ops->disable_streams() callbacks are used by the receiver driver
  43. to control the transmitter driver's streaming state. These callbacks may not be
  44. called directly, but by using ``v4l2_subdev_enable_streams()`` and
  45. ``v4l2_subdev_disable_streams()``.
  46. Stopping the transmitter
  47. ^^^^^^^^^^^^^^^^^^^^^^^^
  48. A transmitter stops sending the stream of images as a result of
  49. calling the ``.disable_streams()`` callback. Some transmitters may stop the
  50. stream at a frame boundary whereas others stop immediately,
  51. effectively leaving the current frame unfinished. The receiver driver
  52. should not make assumptions either way, but function properly in both
  53. cases.
  54. CSI-2 transmitter drivers
  55. -------------------------
  56. Pixel rate
  57. ^^^^^^^^^^
  58. The pixel rate on the bus is calculated as follows::
  59. pixel_rate = link_freq * 2 * nr_of_lanes * 16 / k / bits_per_sample
  60. where
  61. .. list-table:: variables in pixel rate calculation
  62. :header-rows: 1
  63. * - variable or constant
  64. - description
  65. * - link_freq
  66. - The value of the ``V4L2_CID_LINK_FREQ`` integer64 menu item.
  67. * - nr_of_lanes
  68. - Number of data lanes used on the CSI-2 link.
  69. * - 2
  70. - Data is transferred on both rising and falling edge of the signal.
  71. * - bits_per_sample
  72. - Number of bits per sample.
  73. * - k
  74. - 16 for D-PHY and 7 for C-PHY.
  75. Information on whether D-PHY or C-PHY is used, and the value of ``nr_of_lanes``, can be obtained from the OF endpoint configuration.
  76. .. note::
  77. The pixel rate calculated this way is **not** the same thing as the
  78. pixel rate on the camera sensor's pixel array which is indicated by the
  79. :ref:`V4L2_CID_PIXEL_RATE <v4l2-cid-pixel-rate>` control.
  80. LP-11 and LP-111 states
  81. ^^^^^^^^^^^^^^^^^^^^^^^
  82. As part of transitioning to high speed mode, a CSI-2 transmitter typically
  83. briefly sets the bus to LP-11 or LP-111 state, depending on the PHY. This period
  84. may be as short as 100 µs, during which the receiver observes this state and
  85. proceeds its own part of high speed mode transition.
  86. Most receivers are capable of autonomously handling this once the software has
  87. configured them to do so, but there are receivers which require software
  88. involvement in observing LP-11 or LP-111 state. 100 µs is a brief period to hit
  89. in software, especially when there is no interrupt telling something is
  90. happening.
  91. One way to address this is to configure the transmitter side explicitly to LP-11
  92. or LP-111 state, which requires support from the transmitter hardware. This is
  93. not universally available. Many devices return to this state once streaming is
  94. stopped while the state after power-on is LP-00 or LP-000.
  95. The ``.pre_streamon()`` callback may be used to prepare a transmitter for
  96. transitioning to streaming state, but not yet start streaming. Similarly, the
  97. ``.post_streamoff()`` callback is used to undo what was done by the
  98. ``.pre_streamon()`` callback. The caller of ``.pre_streamon()`` is thus required
  99. to call ``.post_streamoff()`` for each successful call of ``.pre_streamon()``.
  100. In the context of CSI-2, the ``.pre_streamon()`` callback is used to transition
  101. the transmitter to the LP-11 or LP-111 state. This also requires powering on the
  102. device, so this should be only done when it is needed.
  103. Receiver drivers that do not need explicit LP-11 or LP-111 state setup are
  104. waived from calling the two callbacks.