162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci.. include:: <isonum.txt> 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci========================================= 662306a36Sopenharmony_ciRockchip Image Signal Processor (rkisp1) 762306a36Sopenharmony_ci========================================= 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciIntroduction 1062306a36Sopenharmony_ci============ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciThis file documents the driver for the Rockchip ISP1 that is part of RK3288 1362306a36Sopenharmony_ciand RK3399 SoCs. The driver is located under drivers/media/platform/rockchip/ 1462306a36Sopenharmony_cirkisp1 and uses the Media-Controller API. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciRevisions 1762306a36Sopenharmony_ci========= 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciThere exist multiple smaller revisions to this ISP that got introduced in 2062306a36Sopenharmony_cilater SoCs. Revisions can be found in the enum :c:type:`rkisp1_cif_isp_version` 2162306a36Sopenharmony_ciin the UAPI and the revision of the ISP inside the running SoC can be read 2262306a36Sopenharmony_ciin the field hw_revision of struct media_device_info as returned by 2362306a36Sopenharmony_ciioctl MEDIA_IOC_DEVICE_INFO. 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciVersions in use are: 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci- RKISP1_V10: used at least in rk3288 and rk3399 2862306a36Sopenharmony_ci- RKISP1_V11: declared in the original vendor code, but not used 2962306a36Sopenharmony_ci- RKISP1_V12: used at least in rk3326 and px30 3062306a36Sopenharmony_ci- RKISP1_V13: used at least in rk1808 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ciTopology 3362306a36Sopenharmony_ci======== 3462306a36Sopenharmony_ci.. _rkisp1_topology_graph: 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci.. kernel-figure:: rkisp1.dot 3762306a36Sopenharmony_ci :alt: Diagram of the default media pipeline topology 3862306a36Sopenharmony_ci :align: center 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciThe driver has 4 video devices: 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci- rkisp1_mainpath: capture device for retrieving images, usually in higher 4462306a36Sopenharmony_ci resolution. 4562306a36Sopenharmony_ci- rkisp1_selfpath: capture device for retrieving images. 4662306a36Sopenharmony_ci- rkisp1_stats: a metadata capture device that sends statistics. 4762306a36Sopenharmony_ci- rkisp1_params: a metadata output device that receives parameters 4862306a36Sopenharmony_ci configurations from userspace. 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciThe driver has 3 subdevices: 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci- rkisp1_resizer_mainpath: used to resize and downsample frames for the 5362306a36Sopenharmony_ci mainpath capture device. 5462306a36Sopenharmony_ci- rkisp1_resizer_selfpath: used to resize and downsample frames for the 5562306a36Sopenharmony_ci selfpath capture device. 5662306a36Sopenharmony_ci- rkisp1_isp: is connected to the sensor and is responsible for all the isp 5762306a36Sopenharmony_ci operations. 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cirkisp1_mainpath, rkisp1_selfpath - Frames Capture Video Nodes 6162306a36Sopenharmony_ci------------------------------------------------------------- 6262306a36Sopenharmony_ciThose are the `mainpath` and `selfpath` capture devices to capture frames. 6362306a36Sopenharmony_ciThose entities are the DMA engines that write the frames to memory. 6462306a36Sopenharmony_ciThe selfpath video device can capture YUV/RGB formats. Its input is YUV encoded 6562306a36Sopenharmony_cistream and it is able to convert it to RGB. The selfpath is not able to 6662306a36Sopenharmony_cicapture bayer formats. 6762306a36Sopenharmony_ciThe mainpath can capture both bayer and YUV formats but it is not able to 6862306a36Sopenharmony_cicapture RGB formats. 6962306a36Sopenharmony_ciBoth capture videos support 7062306a36Sopenharmony_cithe ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`. 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cirkisp1_resizer_mainpath, rkisp1_resizer_selfpath - Resizers Subdevices Nodes 7462306a36Sopenharmony_ci---------------------------------------------------------------------------- 7562306a36Sopenharmony_ciThose are resizer entities for the mainpath and the selfpath. Those entities 7662306a36Sopenharmony_cican scale the frames up and down and also change the YUV sampling (for example 7762306a36Sopenharmony_ciYUV4:2:2 -> YUV4:2:0). They also have cropping capability on the sink pad. 7862306a36Sopenharmony_ciThe resizers entities can only operate on YUV:4:2:2 format 7962306a36Sopenharmony_ci(MEDIA_BUS_FMT_YUYV8_2X8). 8062306a36Sopenharmony_ciThe mainpath capture device supports capturing video in bayer formats. In that 8162306a36Sopenharmony_cicase the resizer of the mainpath is set to 'bypass' mode - it just forward the 8262306a36Sopenharmony_ciframe without operating on it. 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_cirkisp1_isp - Image Signal Processing Subdevice Node 8562306a36Sopenharmony_ci--------------------------------------------------- 8662306a36Sopenharmony_ciThis is the isp entity. It is connected to the sensor on sink pad 0 and 8762306a36Sopenharmony_cireceives the frames using the CSI-2 protocol. It is responsible of configuring 8862306a36Sopenharmony_cithe CSI-2 protocol. It has a cropping capability on sink pad 0 that is 8962306a36Sopenharmony_ciconnected to the sensor and on source pad 2 connected to the resizer entities. 9062306a36Sopenharmony_ciCropping on sink pad 0 defines the image region from the sensor. 9162306a36Sopenharmony_ciCropping on source pad 2 defines the region for the Image Stabilizer (IS). 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci.. _rkisp1_stats: 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cirkisp1_stats - Statistics Video Node 9662306a36Sopenharmony_ci------------------------------------ 9762306a36Sopenharmony_ciThe statistics video node outputs the 3A (auto focus, auto exposure and auto 9862306a36Sopenharmony_ciwhite balance) statistics, and also histogram statistics for the frames that 9962306a36Sopenharmony_ciare being processed by the rkisp1 to userspace applications. 10062306a36Sopenharmony_ciUsing these data, applications can implement algorithms and re-parameterize 10162306a36Sopenharmony_cithe driver through the rkisp_params node to improve image quality during a 10262306a36Sopenharmony_civideo stream. 10362306a36Sopenharmony_ciThe buffer format is defined by struct :c:type:`rkisp1_stat_buffer`, and 10462306a36Sopenharmony_ciuserspace should set 10562306a36Sopenharmony_ci:ref:`V4L2_META_FMT_RK_ISP1_STAT_3A <v4l2-meta-fmt-rk-isp1-stat-3a>` as the 10662306a36Sopenharmony_cidataformat. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci.. _rkisp1_params: 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cirkisp1_params - Parameters Video Node 11162306a36Sopenharmony_ci------------------------------------- 11262306a36Sopenharmony_ciThe rkisp1_params video node receives a set of parameters from userspace 11362306a36Sopenharmony_cito be applied to the hardware during a video stream, allowing userspace 11462306a36Sopenharmony_cito dynamically modify values such as black level, cross talk corrections 11562306a36Sopenharmony_ciand others. 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ciThe buffer format is defined by struct :c:type:`rkisp1_params_cfg`, and 11862306a36Sopenharmony_ciuserspace should set 11962306a36Sopenharmony_ci:ref:`V4L2_META_FMT_RK_ISP1_PARAMS <v4l2-meta-fmt-rk-isp1-params>` as the 12062306a36Sopenharmony_cidataformat. 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciCapturing Video Frames Example 12462306a36Sopenharmony_ci============================== 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ciIn the following example, the sensor connected to pad 0 of 'rkisp1_isp' is 12762306a36Sopenharmony_ciimx219. 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ciThe following commands can be used to capture video from the selfpath video 13062306a36Sopenharmony_cinode with dimension 900x800 planar format YUV 4:2:2. It uses all cropping 13162306a36Sopenharmony_cicapabilities possible, (see explanation right below) 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci.. code-block:: bash 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci # set the links 13662306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "-r" 13762306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "-l" "'imx219 4-0010':0 -> 'rkisp1_isp':0 [1]" 13862306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "-l" "'rkisp1_isp':2 -> 'rkisp1_resizer_selfpath':0 [1]" 13962306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "-l" "'rkisp1_isp':2 -> 'rkisp1_resizer_mainpath':0 [0]" 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci # set format for imx219 4-0010:0 14262306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"imx219 4-0010":0 [fmt:SRGGB10_1X10/1640x1232]' 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci # set format for rkisp1_isp pads: 14562306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_isp":0 [fmt:SRGGB10_1X10/1640x1232 crop: (0,0)/1600x1200]' 14662306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_isp":2 [fmt:YUYV8_2X8/1600x1200 crop: (0,0)/1500x1100]' 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci # set format for rkisp1_resizer_selfpath pads: 14962306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_resizer_selfpath":0 [fmt:YUYV8_2X8/1500x1100 crop: (300,400)/1400x1000]' 15062306a36Sopenharmony_ci "media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_resizer_selfpath":1 [fmt:YUYV8_2X8/900x800]' 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci # set format for rkisp1_selfpath: 15362306a36Sopenharmony_ci "v4l2-ctl" "-z" "platform:rkisp1" "-d" "rkisp1_selfpath" "-v" "width=900,height=800," 15462306a36Sopenharmony_ci "v4l2-ctl" "-z" "platform:rkisp1" "-d" "rkisp1_selfpath" "-v" "pixelformat=422P" 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci # start streaming: 15762306a36Sopenharmony_ci v4l2-ctl "-z" "platform:rkisp1" "-d" "rkisp1_selfpath" "--stream-mmap" "--stream-count" "10" 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ciIn the above example the sensor is configured to bayer format: 16162306a36Sopenharmony_ci`SRGGB10_1X10/1640x1232`. The rkisp1_isp:0 pad should be configured to the 16262306a36Sopenharmony_cisame mbus format and dimensions as the sensor, otherwise streaming will fail 16362306a36Sopenharmony_ciwith 'EPIPE' error. So it is also configured to `SRGGB10_1X10/1640x1232`. 16462306a36Sopenharmony_ciIn addition, the rkisp1_isp:0 pad is configured to cropping `(0,0)/1600x1200`. 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ciThe cropping dimensions are automatically propagated to be the format of the 16762306a36Sopenharmony_ciisp source pad `rkisp1_isp:2`. Another cropping operation is configured on 16862306a36Sopenharmony_cithe isp source pad: `(0,0)/1500x1100`. 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ciThe resizer's sink pad `rkisp1_resizer_selfpath` should be configured to format 17162306a36Sopenharmony_ci`YUYV8_2X8/1500x1100` in order to match the format on the other side of the 17262306a36Sopenharmony_cilink. In addition a cropping `(300,400)/1400x1000` is configured on it. 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ciThe source pad of the resizer, `rkisp1_resizer_selfpath:1` is configured to 17562306a36Sopenharmony_ciformat `YUYV8_2X8/900x800`. That means that the resizer first crop a window 17662306a36Sopenharmony_ciof `(300,400)/1400x100` from the received frame and then scales this window 17762306a36Sopenharmony_cito dimension `900x800`. 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciNote that the above example does not uses the stats-params control loop. 18062306a36Sopenharmony_ciTherefore the capture frames will not go through the 3A algorithms and 18162306a36Sopenharmony_ciprobably won't have a good quality, and can even look dark and greenish. 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ciConfiguring Quantization 18462306a36Sopenharmony_ci======================== 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ciThe driver supports limited and full range quantization on YUV formats, 18762306a36Sopenharmony_ciwhere limited is the default. 18862306a36Sopenharmony_ciTo switch between one or the other, userspace should use the Colorspace 18962306a36Sopenharmony_ciConversion API (CSC) for subdevices on source pad 2 of the 19062306a36Sopenharmony_ciisp (`rkisp1_isp:2`). The quantization configured on this pad is the 19162306a36Sopenharmony_ciquantization of the captured video frames on the mainpath and selfpath 19262306a36Sopenharmony_civideo nodes. 19362306a36Sopenharmony_ciNote that the resizer and capture entities will always report 19462306a36Sopenharmony_ci``V4L2_QUANTIZATION_DEFAULT`` even if the quantization is configured to full 19562306a36Sopenharmony_cirange on `rkisp1_isp:2`. So in order to get the configured quantization, 19662306a36Sopenharmony_ciapplication should get it from pad `rkisp1_isp:2`. 19762306a36Sopenharmony_ci 198