0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 .. _transmitter-receiver:
0004
0005 Pixel data transmitter and receiver drivers
0006 ===========================================
0007
0008 V4L2 supports various devices that transmit and receive pixel data. Examples of
0009 these devices include a camera sensor, a TV tuner and a parallel or a CSI-2
0010 receiver in an SoC.
0011
0012 Bus types
0013 ---------
0014
0015 The following busses are the most common. This section discusses these two only.
0016
0017 MIPI CSI-2
0018 ^^^^^^^^^^
0019
0020 CSI-2 is a data bus intended for transferring images from cameras to
0021 the host SoC. It is defined by the `MIPI alliance`_.
0022
0023 .. _`MIPI alliance`: https://www.mipi.org/
0024
0025 Parallel
0026 ^^^^^^^^
0027
0028 `BT.601`_ and `BT.656`_ are the most common parallel busses.
0029
0030 .. _`BT.601`: https://en.wikipedia.org/wiki/Rec._601
0031 .. _`BT.656`: https://en.wikipedia.org/wiki/ITU-R_BT.656
0032
0033 Transmitter drivers
0034 -------------------
0035
0036 Transmitter drivers generally need to provide the receiver drivers with the
0037 configuration of the transmitter. What is required depends on the type of the
0038 bus. These are common for both busses.
0039
0040 Media bus pixel code
0041 ^^^^^^^^^^^^^^^^^^^^
0042
0043 See :ref:`v4l2-mbus-pixelcode`.
0044
0045 Link frequency
0046 ^^^^^^^^^^^^^^
0047
0048 The :ref:`V4L2_CID_LINK_FREQ <v4l2-cid-link-freq>` control is used to tell the
0049 receiver the frequency of the bus (i.e. it is not the same as the symbol rate).
0050
0051 ``.s_stream()`` callback
0052 ^^^^^^^^^^^^^^^^^^^^^^^^
0053
0054 The struct struct v4l2_subdev_video_ops->s_stream() callback is used by the
0055 receiver driver to control the transmitter driver's streaming state.
0056
0057
0058 CSI-2 transmitter drivers
0059 -------------------------
0060
0061 Pixel rate
0062 ^^^^^^^^^^
0063
0064 The pixel rate on the bus is calculated as follows::
0065
0066 pixel_rate = link_freq * 2 * nr_of_lanes * 16 / k / bits_per_sample
0067
0068 where
0069
0070 .. list-table:: variables in pixel rate calculation
0071 :header-rows: 1
0072
0073 * - variable or constant
0074 - description
0075 * - link_freq
0076 - The value of the ``V4L2_CID_LINK_FREQ`` integer64 menu item.
0077 * - nr_of_lanes
0078 - Number of data lanes used on the CSI-2 link. This can
0079 be obtained from the OF endpoint configuration.
0080 * - 2
0081 - Data is transferred on both rising and falling edge of the signal.
0082 * - bits_per_sample
0083 - Number of bits per sample.
0084 * - k
0085 - 16 for D-PHY and 7 for C-PHY
0086
0087 .. note::
0088
0089 The pixel rate calculated this way is **not** the same thing as the
0090 pixel rate on the camera sensor's pixel array which is indicated by the
0091 :ref:`V4L2_CID_PIXEL_RATE <v4l2-cid-pixel-rate>` control.
0092
0093 LP-11 and LP-111 modes
0094 ^^^^^^^^^^^^^^^^^^^^^^
0095
0096 As part of transitioning to high speed mode, a CSI-2 transmitter typically
0097 briefly sets the bus to LP-11 or LP-111 state, depending on the PHY. This period
0098 may be as short as 100 µs, during which the receiver observes this state and
0099 proceeds its own part of high speed mode transition.
0100
0101 Most receivers are capable of autonomously handling this once the software has
0102 configured them to do so, but there are receivers which require software
0103 involvement in observing LP-11 or LP-111 state. 100 µs is a brief period to hit
0104 in software, especially when there is no interrupt telling something is
0105 happening.
0106
0107 One way to address this is to configure the transmitter side explicitly to LP-11
0108 or LP-111 mode, which requires support from the transmitter hardware. This is
0109 not universally available. Many devices return to this state once streaming is
0110 stopped while the state after power-on is LP-00 or LP-000.
0111
0112 The ``.pre_streamon()`` callback may be used to prepare a transmitter for
0113 transitioning to streaming state, but not yet start streaming. Similarly, the
0114 ``.post_streamoff()`` callback is used to undo what was done by the
0115 ``.pre_streamon()`` callback. The caller of ``.pre_streamon()`` is thus required
0116 to call ``.post_streamoff()`` for each successful call of ``.pre_streamon()``.
0117
0118 In the context of CSI-2, the ``.pre_streamon()`` callback is used to transition
0119 the transmitter to the LP-11 or LP-111 mode. This also requires powering on the
0120 device, so this should be only done when it is needed.
0121
0122 Receiver drivers that do not need explicit LP-11 or LP-111 mode setup are waived
0123 from calling the two callbacks.
0124
0125 Stopping the transmitter
0126 ^^^^^^^^^^^^^^^^^^^^^^^^
0127
0128 A transmitter stops sending the stream of images as a result of
0129 calling the ``.s_stream()`` callback. Some transmitters may stop the
0130 stream at a frame boundary whereas others stop immediately,
0131 effectively leaving the current frame unfinished. The receiver driver
0132 should not make assumptions either way, but function properly in both
0133 cases.