tx-rx.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 busses 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 busses.
  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. ``.s_stream()`` callback
  35. ^^^^^^^^^^^^^^^^^^^^^^^^
  36. The struct struct v4l2_subdev_video_ops->s_stream() callback is used by the
  37. receiver driver to control the transmitter driver's streaming state.
  38. CSI-2 transmitter drivers
  39. -------------------------
  40. Pixel rate
  41. ^^^^^^^^^^
  42. The pixel rate on the bus is calculated as follows::
  43. pixel_rate = link_freq * 2 * nr_of_lanes * 16 / k / bits_per_sample
  44. where
  45. .. list-table:: variables in pixel rate calculation
  46. :header-rows: 1
  47. * - variable or constant
  48. - description
  49. * - link_freq
  50. - The value of the ``V4L2_CID_LINK_FREQ`` integer64 menu item.
  51. * - nr_of_lanes
  52. - Number of data lanes used on the CSI-2 link. This can
  53. be obtained from the OF endpoint configuration.
  54. * - 2
  55. - Data is transferred on both rising and falling edge of the signal.
  56. * - bits_per_sample
  57. - Number of bits per sample.
  58. * - k
  59. - 16 for D-PHY and 7 for C-PHY
  60. .. note::
  61. The pixel rate calculated this way is **not** the same thing as the
  62. pixel rate on the camera sensor's pixel array which is indicated by the
  63. :ref:`V4L2_CID_PIXEL_RATE <v4l2-cid-pixel-rate>` control.
  64. LP-11 and LP-111 states
  65. ^^^^^^^^^^^^^^^^^^^^^^^
  66. As part of transitioning to high speed mode, a CSI-2 transmitter typically
  67. briefly sets the bus to LP-11 or LP-111 state, depending on the PHY. This period
  68. may be as short as 100 µs, during which the receiver observes this state and
  69. proceeds its own part of high speed mode transition.
  70. Most receivers are capable of autonomously handling this once the software has
  71. configured them to do so, but there are receivers which require software
  72. involvement in observing LP-11 or LP-111 state. 100 µs is a brief period to hit
  73. in software, especially when there is no interrupt telling something is
  74. happening.
  75. One way to address this is to configure the transmitter side explicitly to LP-11
  76. or LP-111 state, which requires support from the transmitter hardware. This is
  77. not universally available. Many devices return to this state once streaming is
  78. stopped while the state after power-on is LP-00 or LP-000.
  79. The ``.pre_streamon()`` callback may be used to prepare a transmitter for
  80. transitioning to streaming state, but not yet start streaming. Similarly, the
  81. ``.post_streamoff()`` callback is used to undo what was done by the
  82. ``.pre_streamon()`` callback. The caller of ``.pre_streamon()`` is thus required
  83. to call ``.post_streamoff()`` for each successful call of ``.pre_streamon()``.
  84. In the context of CSI-2, the ``.pre_streamon()`` callback is used to transition
  85. the transmitter to the LP-11 or LP-111 state. This also requires powering on the
  86. device, so this should be only done when it is needed.
  87. Receiver drivers that do not need explicit LP-11 or LP-111 state setup are
  88. waived from calling the two callbacks.
  89. Stopping the transmitter
  90. ^^^^^^^^^^^^^^^^^^^^^^^^
  91. A transmitter stops sending the stream of images as a result of
  92. calling the ``.s_stream()`` callback. Some transmitters may stop the
  93. stream at a frame boundary whereas others stop immediately,
  94. effectively leaving the current frame unfinished. The receiver driver
  95. should not make assumptions either way, but function properly in both
  96. cases.