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