tx-rx.rst 4.4 KB

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