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