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