xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/media/rkisp1.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun.. include:: <isonum.txt>
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun=========================================
6*4882a593SmuzhiyunRockchip Image Signal Processor (rkisp1)
7*4882a593Smuzhiyun=========================================
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunIntroduction
10*4882a593Smuzhiyun============
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunThis file documents the driver for the Rockchip ISP1 that is part of RK3288
13*4882a593Smuzhiyunand RK3399 SoCs. The driver is located under drivers/staging/media/rkisp1
14*4882a593Smuzhiyunand uses the Media-Controller API.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunTopology
17*4882a593Smuzhiyun========
18*4882a593Smuzhiyun.. _rkisp1_topology_graph:
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun.. kernel-figure:: rkisp1.dot
21*4882a593Smuzhiyun    :alt:   Diagram of the default media pipeline topology
22*4882a593Smuzhiyun    :align: center
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunThe driver has 4 video devices:
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun- rkisp1_mainpath: capture device for retrieving images, usually in higher
28*4882a593Smuzhiyun  resolution.
29*4882a593Smuzhiyun- rkisp1_selfpath: capture device for retrieving images.
30*4882a593Smuzhiyun- rkisp1_stats: a metadata capture device that sends statistics.
31*4882a593Smuzhiyun- rkisp1_params: a metadata output device that receives parameters
32*4882a593Smuzhiyun  configurations from userspace.
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunThe driver has 3 subdevices:
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun- rkisp1_resizer_mainpath: used to resize and downsample frames for the
37*4882a593Smuzhiyun  mainpath capture device.
38*4882a593Smuzhiyun- rkisp1_resizer_selfpath: used to resize and downsample frames for the
39*4882a593Smuzhiyun  selfpath capture device.
40*4882a593Smuzhiyun- rkisp1_isp: is connected to the sensor and is responsible for all the isp
41*4882a593Smuzhiyun  operations.
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunrkisp1_mainpath, rkisp1_selfpath - Frames Capture Video Nodes
45*4882a593Smuzhiyun-------------------------------------------------------------
46*4882a593SmuzhiyunThose are the `mainpath` and `selfpath` capture devices to capture frames.
47*4882a593SmuzhiyunThose entities are the DMA engines that write the frames to memory.
48*4882a593SmuzhiyunThe selfpath video device can capture YUV/RGB formats. Its input is YUV encoded
49*4882a593Smuzhiyunstream and it is able to convert it to RGB. The selfpath is not able to
50*4882a593Smuzhiyuncapture bayer formats.
51*4882a593SmuzhiyunThe mainpath can capture both bayer and YUV formats but it is not able to
52*4882a593Smuzhiyuncapture RGB formats.
53*4882a593SmuzhiyunBoth capture videos support
54*4882a593Smuzhiyunthe ``V4L2_CAP_IO_MC`` :ref:`capability <device-capabilities>`.
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun
57*4882a593Smuzhiyunrkisp1_resizer_mainpath, rkisp1_resizer_selfpath - Resizers Subdevices Nodes
58*4882a593Smuzhiyun----------------------------------------------------------------------------
59*4882a593SmuzhiyunThose are resizer entities for the mainpath and the selfpath. Those entities
60*4882a593Smuzhiyuncan scale the frames up and down and also change the YUV sampling (for example
61*4882a593SmuzhiyunYUV4:2:2 -> YUV4:2:0). They also have cropping capability on the sink pad.
62*4882a593SmuzhiyunThe resizers entities can only operate on YUV:4:2:2 format
63*4882a593Smuzhiyun(MEDIA_BUS_FMT_YUYV8_2X8).
64*4882a593SmuzhiyunThe mainpath capture device supports capturing video in bayer formats. In that
65*4882a593Smuzhiyuncase the resizer of the mainpath is set to 'bypass' mode - it just forward the
66*4882a593Smuzhiyunframe without operating on it.
67*4882a593Smuzhiyun
68*4882a593Smuzhiyunrkisp1_isp - Image Signal Processing Subdevice Node
69*4882a593Smuzhiyun---------------------------------------------------
70*4882a593SmuzhiyunThis is the isp entity. It is connected to the sensor on sink pad 0 and
71*4882a593Smuzhiyunreceives the frames using the CSI-2 protocol. It is responsible of configuring
72*4882a593Smuzhiyunthe CSI-2 protocol. It has a cropping capability on sink pad 0 that is
73*4882a593Smuzhiyunconnected to the sensor and on source pad 2 connected to the resizer entities.
74*4882a593SmuzhiyunCropping on sink pad 0 defines the image region from the sensor.
75*4882a593SmuzhiyunCropping on source pad 2 defines the region for the Image Stabilizer (IS).
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun.. _rkisp1_stats:
78*4882a593Smuzhiyun
79*4882a593Smuzhiyunrkisp1_stats - Statistics Video Node
80*4882a593Smuzhiyun------------------------------------
81*4882a593SmuzhiyunThe statistics video node outputs the 3A (auto focus, auto exposure and auto
82*4882a593Smuzhiyunwhite balance) statistics, and also histogram statistics for the frames that
83*4882a593Smuzhiyunare being processed by the rkisp1 to userspace applications.
84*4882a593SmuzhiyunUsing these data, applications can implement algorithms and re-parameterize
85*4882a593Smuzhiyunthe driver through the rkisp_params node to improve image quality during a
86*4882a593Smuzhiyunvideo stream.
87*4882a593SmuzhiyunThe buffer format is defined by struct :c:type:`rkisp1_stat_buffer`, and
88*4882a593Smuzhiyunuserspace should set
89*4882a593Smuzhiyun:ref:`V4L2_META_FMT_RK_ISP1_STAT_3A <v4l2-meta-fmt-stat-rkisp1>` as the
90*4882a593Smuzhiyundataformat.
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun.. _rkisp1_params:
93*4882a593Smuzhiyun
94*4882a593Smuzhiyunrkisp1_params - Parameters Video Node
95*4882a593Smuzhiyun-------------------------------------
96*4882a593SmuzhiyunThe rkisp1_params video node receives a set of parameters from userspace
97*4882a593Smuzhiyunto be applied to the hardware during a video stream, allowing userspace
98*4882a593Smuzhiyunto dynamically modify values such as black level, cross talk corrections
99*4882a593Smuzhiyunand others.
100*4882a593Smuzhiyun
101*4882a593SmuzhiyunThe buffer format is defined by struct :c:type:`rkisp1_params_cfg`, and
102*4882a593Smuzhiyunuserspace should set
103*4882a593Smuzhiyun:ref:`V4L2_META_FMT_RK_ISP1_PARAMS <v4l2-meta-fmt-params-rkisp1>` as the
104*4882a593Smuzhiyundataformat.
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun
107*4882a593SmuzhiyunCapturing Video Frames Example
108*4882a593Smuzhiyun==============================
109*4882a593Smuzhiyun
110*4882a593SmuzhiyunIn the following example, the sensor connected to pad 0 of 'rkisp1_isp' is
111*4882a593Smuzhiyunimx219.
112*4882a593Smuzhiyun
113*4882a593SmuzhiyunThe following commands can be used to capture video from the selfpath video
114*4882a593Smuzhiyunnode with dimension 900x800 planar format YUV 4:2:2. It uses all cropping
115*4882a593Smuzhiyuncapabilities possible, (see explanation right below)
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun.. code-block:: bash
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun	# set the links
120*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "-r"
121*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "-l" "'imx219 4-0010':0 -> 'rkisp1_isp':0 [1]"
122*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "-l" "'rkisp1_isp':2 -> 'rkisp1_resizer_selfpath':0 [1]"
123*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "-l" "'rkisp1_isp':2 -> 'rkisp1_resizer_mainpath':0 [0]"
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun	# set format for imx219 4-0010:0
126*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"imx219 4-0010":0 [fmt:SRGGB10_1X10/1640x1232]'
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun	# set format for rkisp1_isp pads:
129*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_isp":0 [fmt:SRGGB10_1X10/1640x1232 crop: (0,0)/1600x1200]'
130*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_isp":2 [fmt:YUYV8_2X8/1600x1200 crop: (0,0)/1500x1100]'
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun	# set format for rkisp1_resizer_selfpath pads:
133*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_resizer_selfpath":0 [fmt:YUYV8_2X8/1500x1100 crop: (300,400)/1400x1000]'
134*4882a593Smuzhiyun	"media-ctl" "-d" "platform:rkisp1" "--set-v4l2" '"rkisp1_resizer_selfpath":1 [fmt:YUYV8_2X8/900x800]'
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun	# set format for rkisp1_selfpath:
137*4882a593Smuzhiyun	"v4l2-ctl" "-z" "platform:rkisp1" "-d" "rkisp1_selfpath" "-v" "width=900,height=800,"
138*4882a593Smuzhiyun	"v4l2-ctl" "-z" "platform:rkisp1" "-d" "rkisp1_selfpath" "-v" "pixelformat=422P"
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun	# start streaming:
141*4882a593Smuzhiyun	v4l2-ctl "-z" "platform:rkisp1" "-d" "rkisp1_selfpath" "--stream-mmap" "--stream-count" "10"
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun
144*4882a593SmuzhiyunIn the above example the sensor is configured to bayer format:
145*4882a593Smuzhiyun`SRGGB10_1X10/1640x1232`. The rkisp1_isp:0 pad should be configured to the
146*4882a593Smuzhiyunsame mbus format and dimensions as the sensor, otherwise streaming will fail
147*4882a593Smuzhiyunwith 'EPIPE' error. So it is also configured to `SRGGB10_1X10/1640x1232`.
148*4882a593SmuzhiyunIn addition, the rkisp1_isp:0 pad is configured to cropping `(0,0)/1600x1200`.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunThe cropping dimensions are automatically propagated to be the format of the
151*4882a593Smuzhiyunisp source pad `rkisp1_isp:2`. Another cropping operation is configured on
152*4882a593Smuzhiyunthe isp source pad: `(0,0)/1500x1100`.
153*4882a593Smuzhiyun
154*4882a593SmuzhiyunThe resizer's sink pad `rkisp1_resizer_selfpath` should be configured to format
155*4882a593Smuzhiyun`YUYV8_2X8/1500x1100` in order to match the format on the other side of the
156*4882a593Smuzhiyunlink. In addition a cropping `(300,400)/1400x1000` is configured on it.
157*4882a593Smuzhiyun
158*4882a593SmuzhiyunThe source pad of the resizer, `rkisp1_resizer_selfpath:1` is configured to
159*4882a593Smuzhiyunformat `YUYV8_2X8/900x800`. That means that the resizer first crop a window
160*4882a593Smuzhiyunof `(300,400)/1400x100` from the received frame and then scales this window
161*4882a593Smuzhiyunto dimension `900x800`.
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunNote that the above example does not uses the stats-params control loop.
164*4882a593SmuzhiyunTherefore the capture frames will not go through the 3A algorithms and
165*4882a593Smuzhiyunprobably won't have a good quality, and can even look dark and greenish.
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunConfiguring Quantization
168*4882a593Smuzhiyun========================
169*4882a593Smuzhiyun
170*4882a593SmuzhiyunThe driver supports limited and full range quantization on YUV formats,
171*4882a593Smuzhiyunwhere limited is the default.
172*4882a593SmuzhiyunTo switch between one or the other, userspace should use the Colorspace
173*4882a593SmuzhiyunConversion API (CSC) for subdevices on source pad 2 of the
174*4882a593Smuzhiyunisp (`rkisp1_isp:2`). The quantization configured on this pad is the
175*4882a593Smuzhiyunquantization of the captured video frames on the mainpath and selfpath
176*4882a593Smuzhiyunvideo nodes.
177*4882a593SmuzhiyunNote that the resizer and capture entities will always report
178*4882a593Smuzhiyun``V4L2_QUANTIZATION_DEFAULT`` even if the quantization is configured to full
179*4882a593Smuzhiyunrange on `rkisp1_isp:2`. So in order to get the configured quantization,
180*4882a593Smuzhiyunapplication should get it from pad `rkisp1_isp:2`.
181*4882a593Smuzhiyun
182