Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: Documentation: media: Improve camera sensor documentation

Modernise the documentation to make it more precise and update the use of
pixel rate control and various other changes. In particular:

- Use non-proportional font for file names, properties as well as
controls.

- The unit of the HBLANK control is pixels, not lines.

- The unit of PIXEL_RATE control is pixels per second, not Hz.

- Merge common requirements for CSI-2 and parallel busses.

- Include all DT properties needed for assigned clocks.

- Fix referencing the link rate control.

- SMIA driver's new name is CCS driver.

- The PIXEL_RATE control denotes pixel rate on the pixel array on camera
sensors. Do not suggest it is used to tell the maximum pixel rate on the
bus anymore.

- Improve ReST syntax (plain struct and function names).

- Remove the suggestion to use s_power() in receiver drivers.

- Make MIPI website URL use HTTPS, add Wikipedia links to BT.601 and
BT.656.

Fixes: e4cf8c58af75 ("media: Documentation: media: Document how to write camera sensor drivers")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Sakari Ailus and committed by
Mauro Carvalho Chehab
b9a54336 0368e7d2

+137 -123
+17 -28
Documentation/driver-api/media/camera-sensor.rst
··· 3 3 Writing camera sensor drivers 4 4 ============================= 5 5 6 - CSI-2 7 - ----- 6 + CSI-2 and parallel (BT.601 and BT.656) busses 7 + --------------------------------------------- 8 8 9 - Please see what is written on :ref:`MIPI_CSI_2`. 9 + Please see :ref:`transmitter-receiver`. 10 10 11 11 Handling clocks 12 12 --------------- ··· 26 26 ACPI 27 27 ~~~~ 28 28 29 - Read the "clock-frequency" _DSD property to denote the frequency. The driver can 30 - rely on this frequency being used. 29 + Read the ``clock-frequency`` _DSD property to denote the frequency. The driver 30 + can rely on this frequency being used. 31 31 32 32 Devicetree 33 33 ~~~~~~~~~~ 34 34 35 - The currently preferred way to achieve this is using "assigned-clock-rates" 36 - property. See Documentation/devicetree/bindings/clock/clock-bindings.txt for 37 - more information. The driver then gets the frequency using clk_get_rate(). 35 + The currently preferred way to achieve this is using ``assigned-clocks``, 36 + ``assigned-clock-parents`` and ``assigned-clock-rates`` properties. See 37 + ``Documentation/devicetree/bindings/clock/clock-bindings.txt`` for more 38 + information. The driver then gets the frequency using ``clk_get_rate()``. 38 39 39 40 This approach has the drawback that there's no guarantee that the frequency 40 41 hasn't been modified directly or indirectly by another driver, or supported by ··· 56 55 scaling configurations. The output size of the device is the result of a series 57 56 of cropping and scaling operations from the device's pixel array's size. 58 57 59 - An example of such a driver is the smiapp driver (see drivers/media/i2c/smiapp). 58 + An example of such a driver is the CCS driver (see ``drivers/media/i2c/ccs``). 60 59 61 60 Register list based drivers 62 61 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ··· 68 67 format set on a source pad at the end of the device's internal pipeline. 69 68 70 69 Most sensor drivers are implemented this way, see e.g. 71 - drivers/media/i2c/imx319.c for an example. 70 + ``drivers/media/i2c/imx319.c`` for an example. 72 71 73 72 Frame interval configuration 74 73 ---------------------------- ··· 95 94 crop, use the full source image size, i.e. pixel array size. 96 95 97 96 Horizontal and vertical blanking are specified by ``V4L2_CID_HBLANK`` and 98 - ``V4L2_CID_VBLANK``, respectively. The unit of these controls are lines. The 99 - pixel rate is specified by ``V4L2_CID_PIXEL_RATE`` in the same sub-device. The 100 - unit of that control is Hz. 97 + ``V4L2_CID_VBLANK``, respectively. The unit of the ``V4L2_CID_HBLANK`` control 98 + is pixels and the unit of the ``V4L2_CID_VBLANK`` is lines. The pixel rate in 99 + the sensor's **pixel array** is specified by ``V4L2_CID_PIXEL_RATE`` in the same 100 + sub-device. The unit of that control is pixels per second. 101 101 102 102 Register list based drivers need to implement read-only sub-device nodes for the 103 103 purpose. Devices that are not register list based need these to configure the ··· 127 125 accessed and when it is streaming. 128 126 129 127 Existing camera sensor drivers may rely on the old 130 - :c:type:`v4l2_subdev_core_ops`->s_power() callback for bridge or ISP drivers to 128 + struct v4l2_subdev_core_ops->s_power() callback for bridge or ISP drivers to 131 129 manage their power state. This is however **deprecated**. If you feel you need 132 130 to begin calling an s_power from an ISP or a bridge driver, instead please add 133 131 runtime PM support to the sensor driver you are using. Likewise, new drivers 134 132 should not use s_power. 135 133 136 134 Please see examples in e.g. ``drivers/media/i2c/ov8856.c`` and 137 - ``drivers/media/i2c/smiapp/smiapp-core.c``. The two drivers work in both ACPI 135 + ``drivers/media/i2c/ccs/ccs-core.c``. The two drivers work in both ACPI 138 136 and DT based systems. 139 137 140 138 Control framework ··· 151 149 The function returns a non-zero value if it succeeded getting the power count or 152 150 runtime PM was disabled, in either of which cases the driver may proceed to 153 151 access the device. 154 - 155 - Controls 156 - -------- 157 - 158 - For camera sensors that are connected to a bus where transmitter and receiver 159 - require common configuration set by drivers, such as CSI-2 or parallel (BT.601 160 - or BT.656) bus, the ``V4L2_CID_LINK_FREQ`` control is mandatory on transmitter 161 - drivers. Receiver drivers can use the ``V4L2_CID_LINK_FREQ`` to query the 162 - frequency used on the bus. 163 - 164 - The transmitter drivers should also implement ``V4L2_CID_PIXEL_RATE`` control in 165 - order to tell the maximum pixel rate to the receiver. This is required on raw 166 - camera sensors.
-94
Documentation/driver-api/media/csi2.rst
··· 1 - .. SPDX-License-Identifier: GPL-2.0 2 - 3 - .. _MIPI_CSI_2: 4 - 5 - MIPI CSI-2 6 - ========== 7 - 8 - CSI-2 is a data bus intended for transferring images from cameras to 9 - the host SoC. It is defined by the `MIPI alliance`_. 10 - 11 - .. _`MIPI alliance`: http://www.mipi.org/ 12 - 13 - Media bus formats 14 - ----------------- 15 - 16 - See :ref:`v4l2-mbus-pixelcode` for details on which media bus formats should 17 - be used for CSI-2 interfaces. 18 - 19 - Transmitter drivers 20 - ------------------- 21 - 22 - CSI-2 transmitter, such as a sensor or a TV tuner, drivers need to 23 - provide the CSI-2 receiver with information on the CSI-2 bus 24 - configuration. These include the V4L2_CID_LINK_FREQ and 25 - V4L2_CID_PIXEL_RATE controls and 26 - (:c:type:`v4l2_subdev_video_ops`->s_stream() callback). These 27 - interface elements must be present on the sub-device represents the 28 - CSI-2 transmitter. 29 - 30 - The V4L2_CID_LINK_FREQ control is used to tell the receiver driver the 31 - frequency (and not the symbol rate) of the link. The V4L2_CID_PIXEL_RATE 32 - control may be used by the receiver to obtain the pixel rate the transmitter 33 - uses. The :c:type:`v4l2_subdev_video_ops`->s_stream() callback provides an 34 - ability to start and stop the stream. 35 - 36 - The 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 - 40 - where 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 - 59 - The transmitter drivers must, if possible, configure the CSI-2 60 - transmitter to *LP-11 mode* whenever the transmitter is powered on but 61 - not active, and maintain *LP-11 mode* until stream on. Only at stream 62 - on should the transmitter activate the clock on the clock lane and 63 - transition to *HS mode*. 64 - 65 - Some transmitters do this automatically but some have to be explicitly 66 - programmed to do so, and some are unable to do so altogether due to 67 - hardware constraints. 68 - 69 - Stopping the transmitter 70 - ^^^^^^^^^^^^^^^^^^^^^^^^ 71 - 72 - A transmitter stops sending the stream of images as a result of 73 - calling the ``.s_stream()`` callback. Some transmitters may stop the 74 - stream at a frame boundary whereas others stop immediately, 75 - effectively leaving the current frame unfinished. The receiver driver 76 - should not make assumptions either way, but function properly in both 77 - cases. 78 - 79 - Receiver drivers 80 - ---------------- 81 - 82 - Before the receiver driver may enable the CSI-2 transmitter by using 83 - the :c:type:`v4l2_subdev_video_ops`->s_stream(), it must have powered 84 - the transmitter up by using the 85 - :c:type:`v4l2_subdev_core_ops`->s_power() callback. This may take 86 - place either indirectly by using :c:func:`v4l2_pipeline_pm_get` or 87 - directly. 88 - 89 - Formats 90 - ------- 91 - 92 - The media bus pixel codes document parallel formats. Should the pixel data be 93 - transported over a serial bus, the media bus pixel code that describes a 94 - parallel format that transfers a sample on a single clock cycle is used.
+1 -1
Documentation/driver-api/media/index.rst
··· 37 37 rc-core 38 38 mc-core 39 39 cec-core 40 - csi2 40 + tx-rx 41 41 camera-sensor 42 42 43 43 drivers/index
+117
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 receiver 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 + The transmitter drivers must, if possible, configure the CSI-2 transmitter to 97 + *LP-11 or LP-111 mode* whenever the transmitter is powered on but not active, 98 + and maintain *LP-11 or LP-111 mode* until stream on. Only at stream on should 99 + the transmitter activate the clock on the clock lane and transition to *HS 100 + mode*. 101 + 102 + Some transmitters do this automatically but some have to be explicitly 103 + programmed to do so, and some are unable to do so altogether due to 104 + hardware constraints. 105 + 106 + The receiver thus need to be configured to expect LP-11 or LP-111 mode from the 107 + transmitter before the transmitter driver's ``.s_stream()`` op is called. 108 + 109 + Stopping the transmitter 110 + ^^^^^^^^^^^^^^^^^^^^^^^^ 111 + 112 + A transmitter stops sending the stream of images as a result of 113 + calling the ``.s_stream()`` callback. Some transmitters may stop the 114 + stream at a frame boundary whereas others stop immediately, 115 + effectively leaving the current frame unfinished. The receiver driver 116 + should not make assumptions either way, but function properly in both 117 + cases.
+2
Documentation/userspace-api/media/v4l/ext-ctrls-image-process.rst
··· 20 20 ``V4L2_CID_IMAGE_PROC_CLASS (class)`` 21 21 The IMAGE_PROC class descriptor. 22 22 23 + .. _v4l2-cid-link-freq: 24 + 23 25 ``V4L2_CID_LINK_FREQ (integer menu)`` 24 26 Data bus frequency. Together with the media bus pixel code, bus type 25 27 (clock cycles per sample), the data bus frequency defines the pixel