Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1.. SPDX-License-Identifier: GPL-2.0
2
3.. _MIPI_CSI_2:
4
5MIPI CSI-2
6==========
7
8CSI-2 is a data bus intended for transferring images from cameras to
9the host SoC. It is defined by the `MIPI alliance`_.
10
11.. _`MIPI alliance`: http://www.mipi.org/
12
13Media bus formats
14-----------------
15
16See :ref:`v4l2-mbus-pixelcode` for details on which media bus formats should
17be used for CSI-2 interfaces.
18
19Transmitter drivers
20-------------------
21
22CSI-2 transmitter, such as a sensor or a TV tuner, drivers need to
23provide the CSI-2 receiver with information on the CSI-2 bus
24configuration. These include the V4L2_CID_LINK_FREQ and
25V4L2_CID_PIXEL_RATE controls and
26(:c:type:`v4l2_subdev_video_ops`->s_stream() callback). These
27interface elements must be present on the sub-device represents the
28CSI-2 transmitter.
29
30The V4L2_CID_LINK_FREQ control is used to tell the receiver driver the
31frequency (and not the symbol rate) of the link. The V4L2_CID_PIXEL_RATE
32control may be used by the receiver to obtain the pixel rate the transmitter
33uses. The :c:type:`v4l2_subdev_video_ops`->s_stream() callback provides an
34ability to start and stop the stream.
35
36The value of the V4L2_CID_PIXEL_RATE is calculated as follows::
37
38 pixel_rate = link_freq * 2 * nr_of_lanes * 16 / k / bits_per_sample
39
40where
41
42.. list-table:: variables in pixel rate calculation
43 :header-rows: 1
44
45 * - variable or constant
46 - description
47 * - link_freq
48 - The value of the V4L2_CID_LINK_FREQ integer64 menu item.
49 * - nr_of_lanes
50 - Number of data lanes used on the CSI-2 link. This can
51 be obtained from the OF endpoint configuration.
52 * - 2
53 - Two bits are transferred per clock cycle per lane.
54 * - bits_per_sample
55 - Number of bits per sample.
56 * - k
57 - 16 for D-PHY and 7 for C-PHY
58
59The transmitter drivers must, if possible, configure the CSI-2
60transmitter to *LP-11 mode* whenever the transmitter is powered on but
61not active, and maintain *LP-11 mode* until stream on. Only at stream
62on should the transmitter activate the clock on the clock lane and
63transition to *HS mode*.
64
65Some transmitters do this automatically but some have to be explicitly
66programmed to do so, and some are unable to do so altogether due to
67hardware constraints.
68
69Stopping the transmitter
70^^^^^^^^^^^^^^^^^^^^^^^^
71
72A transmitter stops sending the stream of images as a result of
73calling the ``.s_stream()`` callback. Some transmitters may stop the
74stream at a frame boundary whereas others stop immediately,
75effectively leaving the current frame unfinished. The receiver driver
76should not make assumptions either way, but function properly in both
77cases.
78
79Receiver drivers
80----------------
81
82Before the receiver driver may enable the CSI-2 transmitter by using
83the :c:type:`v4l2_subdev_video_ops`->s_stream(), it must have powered
84the transmitter up by using the
85:c:type:`v4l2_subdev_core_ops`->s_power() callback. This may take
86place either indirectly by using :c:func:`v4l2_pipeline_pm_get` or
87directly.
88
89Formats
90-------
91
92The media bus pixel codes document parallel formats. Should the pixel data be
93transported over a serial bus, the media bus pixel code that describes a
94parallel format that transfers a sample on a single clock cycle is used.