7.Pixel data transmitter and receiver drivers

V4L2 supports various devices that transmit and receive pixel data. Examples ofthese devices include a camera sensor, a TV tuner and a parallel, a BT.656 or aCSI-2 receiver in an SoC.

7.1.Bus types

The following buses are the most common. This section discusses these two only.

7.1.1.MIPI CSI-2

CSI-2 is a data bus intended for transferring images from cameras tothe host SoC. It is defined by theMIPI alliance.

7.1.2.Parallel and BT.656

The parallel andBT.656 buses transport one bit of data on each clock cycleper data line. The parallel bus uses synchronisation and other additionalsignals whereas BT.656 embeds synchronisation.

7.2.Transmitter drivers

Transmitter drivers generally need to provide the receiver drivers with theconfiguration of the transmitter. What is required depends on the type of thebus. These are common for both buses.

7.2.1.Media bus pixel code

SeeMedia Bus Pixel Codes.

7.2.2.Link frequency

TheV4L2_CID_LINK_FREQ control is used to tell thereceiver the frequency of the bus (i.e. it is not the same as the symbol rate).

Drivers that do not have user-configurable link frequency should report itthrough the.get_mbus_config() subdev pad operation, in thelink_freqfield ofstructv4l2_mbus_config, instead of through controls.

Receiver drivers should usev4l2_get_link_freq() helper to obtain thelink frequency from the transmitter sub-device.

7.2.3..enable_streams() and.disable_streams() callbacks

Thestructv4l2_subdev_pad_ops->enable_streams() andstructv4l2_subdev_pad_ops->disable_streams() callbacks are used by the receiver driverto control the transmitter driver’s streaming state. These callbacks may not becalled directly, but by usingv4l2_subdev_enable_streams() andv4l2_subdev_disable_streams().

7.2.4.Stopping the transmitter

A transmitter stops sending the stream of images as a result ofcalling the.disable_streams() callback. Some transmitters may stop thestream at a frame boundary whereas others stop immediately,effectively leaving the current frame unfinished. The receiver drivershould not make assumptions either way, but function properly in bothcases.

7.3.CSI-2 transmitter drivers

7.3.1.Pixel rate

The pixel rate on the bus is calculated as follows:

pixel_rate = link_freq * 2 * nr_of_lanes * 16 / k / bits_per_sample

where

variables in pixel rate calculation

variable or constant

description

link_freq

The value of theV4L2_CID_LINK_FREQ integer64 menu item.

nr_of_lanes

Number of data lanes used on the CSI-2 link.

2

Data is transferred on both rising and falling edge of the signal.

bits_per_sample

Number of bits per sample.

k

16 for D-PHY and 7 for C-PHY.

Information on whether D-PHY or C-PHY is used, and the value ofnr_of_lanes, can be obtained from the OF endpoint configuration.

Note

The pixel rate calculated this way isnot the same thing as thepixel rate on the camera sensor’s pixel array which is indicated by theV4L2_CID_PIXEL_RATE control.

7.3.2.LP-11 and LP-111 states

As part of transitioning to high speed mode, a CSI-2 transmitter typicallybriefly sets the bus to LP-11 or LP-111 state, depending on the PHY. This periodmay be as short as 100 µs, during which the receiver observes this state andproceeds its own part of high speed mode transition.

Most receivers are capable of autonomously handling this once the software hasconfigured them to do so, but there are receivers which require softwareinvolvement in observing LP-11 or LP-111 state. 100 µs is a brief period to hitin software, especially when there is no interrupt telling something ishappening.

One way to address this is to configure the transmitter side explicitly to LP-11or LP-111 state, which requires support from the transmitter hardware. This isnot universally available. Many devices return to this state once streaming isstopped while the state after power-on is LP-00 or LP-000.

The.pre_streamon() callback may be used to prepare a transmitter fortransitioning to streaming state, but not yet start streaming. Similarly, the.post_streamoff() callback is used to undo what was done by the.pre_streamon() callback. The caller of.pre_streamon() is thus requiredto call.post_streamoff() for each successful call of.pre_streamon().

In the context of CSI-2, the.pre_streamon() callback is used to transitionthe transmitter to the LP-11 or LP-111 state. This also requires powering on thedevice, so this should be only done when it is needed.

Receiver drivers that do not need explicit LP-11 or LP-111 state setup arewaived from calling the two callbacks.