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