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