Merge tag 'next-media-rkisp1-20240814' of git://git.kernel.org/pub/scm/linux/kernel/git/pinchartl/linux.git

Extensible parameters support for the rkisp1 driver.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
Hans Verkuil
2024-08-14 17:18:47 +02:00
14 changed files with 1689 additions and 166 deletions

View File

@@ -114,11 +114,18 @@ to be applied to the hardware during a video stream, allowing userspace
to dynamically modify values such as black level, cross talk corrections
and others.
The buffer format is defined by struct :c:type:`rkisp1_params_cfg`, and
userspace should set
The ISP driver supports two different parameters configuration methods, the
`fixed parameters format` or the `extensible parameters format`.
When using the `fixed parameters` method the buffer format is defined by struct
:c:type:`rkisp1_params_cfg`, and userspace should set
:ref:`V4L2_META_FMT_RK_ISP1_PARAMS <v4l2-meta-fmt-rk-isp1-params>` as the
dataformat.
When using the `extensible parameters` method the buffer format is defined by
struct :c:type:`rkisp1_ext_params_cfg`, and userspace should set
:ref:`V4L2_META_FMT_RK_ISP1_EXT_PARAMS <v4l2-meta-fmt-rk-isp1-ext-params>` as
the dataformat.
Capturing Video Frames Example
==============================

View File

@@ -1,28 +1,67 @@
.. SPDX-License-Identifier: GPL-2.0
.. _v4l2-meta-fmt-rk-isp1-params:
.. _v4l2-meta-fmt-rk-isp1-stat-3a:
*****************************************************************************
V4L2_META_FMT_RK_ISP1_PARAMS ('rk1p'), V4L2_META_FMT_RK_ISP1_STAT_3A ('rk1s')
*****************************************************************************
************************************************************************************************************************
V4L2_META_FMT_RK_ISP1_PARAMS ('rk1p'), V4L2_META_FMT_RK_ISP1_STAT_3A ('rk1s'), V4L2_META_FMT_RK_ISP1_EXT_PARAMS ('rk1e')
************************************************************************************************************************
========================
Configuration parameters
========================
The configuration parameters are passed to the
The configuration of the RkISP1 ISP is performed by userspace by providing
parameters for the ISP to the driver using the :c:type:`v4l2_meta_format`
interface.
There are two methods that allow to configure the ISP, the `fixed parameters`
configuration format and the `extensible parameters` configuration
format.
.. _v4l2-meta-fmt-rk-isp1-params:
Fixed parameters configuration format
=====================================
When using the fixed configuration format, parameters are passed to the
:ref:`rkisp1_params <rkisp1_params>` metadata output video node, using
the :c:type:`v4l2_meta_format` interface. The buffer contains
a single instance of the C structure :c:type:`rkisp1_params_cfg` defined in
``rkisp1-config.h``. So the structure can be obtained from the buffer by:
the `V4L2_META_FMT_RK_ISP1_PARAMS` meta format.
The buffer contains a single instance of the C structure
:c:type:`rkisp1_params_cfg` defined in ``rkisp1-config.h``. So the structure can
be obtained from the buffer by:
.. code-block:: c
struct rkisp1_params_cfg *params = (struct rkisp1_params_cfg*) buffer;
This method supports a subset of the ISP features only, new applications should
use the extensible parameters method.
.. _v4l2-meta-fmt-rk-isp1-ext-params:
Extensible parameters configuration format
==========================================
When using the extensible configuration format, parameters are passed to the
:ref:`rkisp1_params <rkisp1_params>` metadata output video node, using
the `V4L2_META_FMT_RK_ISP1_EXT_PARAMS` meta format.
The buffer contains a single instance of the C structure
:c:type:`rkisp1_ext_params_cfg` defined in ``rkisp1-config.h``. The
:c:type:`rkisp1_ext_params_cfg` structure is designed to allow userspace to
populate the data buffer with only the configuration data for the ISP blocks it
intends to configure. The extensible parameters format design allows developers
to define new block types to support new configuration parameters, and defines a
versioning scheme so that it can be extended and versioned without breaking
compatibility with existing applications.
For these reasons, this configuration method is preferred over the `fixed
parameters` format alternative.
.. rkisp1_stat_buffer
===========================
3A and histogram statistics
===========================

View File

@@ -178,3 +178,17 @@ void rkisp1_sd_adjust_crop(struct v4l2_rect *crop,
rkisp1_sd_adjust_crop_rect(crop, &crop_bounds);
}
void rkisp1_bls_swap_regs(enum rkisp1_fmt_raw_pat_type pattern,
const u32 input[4], u32 output[4])
{
static const unsigned int swap[4][4] = {
[RKISP1_RAW_RGGB] = { 0, 1, 2, 3 },
[RKISP1_RAW_GRBG] = { 1, 0, 3, 2 },
[RKISP1_RAW_GBRG] = { 2, 3, 0, 1 },
[RKISP1_RAW_BGGR] = { 3, 2, 1, 0 },
};
for (unsigned int i = 0; i < 4; ++i)
output[i] = input[swap[pattern][i]];
}

View File

@@ -33,9 +33,10 @@ struct regmap;
#define RKISP1_ISP_SD_SRC BIT(0)
#define RKISP1_ISP_SD_SINK BIT(1)
/* min and max values for the widths and heights of the entities */
#define RKISP1_ISP_MAX_WIDTH 4032
#define RKISP1_ISP_MAX_HEIGHT 3024
/*
* Minimum values for the width and height of entities. The maximum values are
* model-specific and stored in the rkisp1_info structure.
*/
#define RKISP1_ISP_MIN_WIDTH 32
#define RKISP1_ISP_MIN_HEIGHT 32
@@ -115,6 +116,8 @@ enum rkisp1_isp_pad {
* @RKISP1_FEATURE_SELF_PATH: The ISP has a self path
* @RKISP1_FEATURE_DUAL_CROP: The ISP has the dual crop block at the resizer input
* @RKISP1_FEATURE_DMA_34BIT: The ISP uses 34-bit DMA addresses
* @RKISP1_FEATURE_BLS: The ISP has a dedicated BLS block
* @RKISP1_FEATURE_COMPAND: The ISP has a companding block
*
* The ISP features are stored in a bitmask in &rkisp1_info.features and allow
* the driver to implement support for features present in some ISP versions
@@ -126,6 +129,8 @@ enum rkisp1_feature {
RKISP1_FEATURE_SELF_PATH = BIT(2),
RKISP1_FEATURE_DUAL_CROP = BIT(3),
RKISP1_FEATURE_DMA_34BIT = BIT(4),
RKISP1_FEATURE_BLS = BIT(5),
RKISP1_FEATURE_COMPAND = BIT(6),
};
#define rkisp1_has_feature(rkisp1, feature) \
@@ -140,6 +145,8 @@ enum rkisp1_feature {
* @isr_size: number of entries in the @isrs array
* @isp_ver: ISP version
* @features: bitmask of rkisp1_feature features implemented by the ISP
* @max_width: maximum input frame width
* @max_height: maximum input frame height
*
* This structure contains information about the ISP specific to a particular
* ISP model, version, or integration in a particular SoC.
@@ -151,6 +158,8 @@ struct rkisp1_info {
unsigned int isr_size;
enum rkisp1_cif_isp_version isp_ver;
unsigned int features;
unsigned int max_width;
unsigned int max_height;
};
/*
@@ -232,7 +241,7 @@ struct rkisp1_vdev_node {
/*
* struct rkisp1_buffer - A container for the vb2 buffers used by the video devices:
* params, stats, mainpath, selfpath
* stats, mainpath, selfpath
*
* @vb: vb2 buffer
* @queue: entry of the buffer in the queue
@@ -244,6 +253,26 @@ struct rkisp1_buffer {
dma_addr_t buff_addr[VIDEO_MAX_PLANES];
};
/*
* struct rkisp1_params_buffer - A container for the vb2 buffers used by the
* params video device
*
* @vb: vb2 buffer
* @queue: entry of the buffer in the queue
* @cfg: scratch buffer used for caching the ISP configuration parameters
*/
struct rkisp1_params_buffer {
struct vb2_v4l2_buffer vb;
struct list_head queue;
void *cfg;
};
static inline struct rkisp1_params_buffer *
to_rkisp1_params_buffer(struct vb2_v4l2_buffer *vbuf)
{
return container_of(vbuf, struct rkisp1_params_buffer, vb);
}
/*
* struct rkisp1_dummy_buffer - A buffer to write the next frame to in case
* there are no vb2 buffers available.
@@ -372,9 +401,11 @@ struct rkisp1_params_ops {
* @ops: pointer to the variant-specific operations
* @config_lock: locks the buffer list 'params'
* @params: queue of rkisp1_buffer
* @vdev_fmt: v4l2_format of the metadata format
* @metafmt the currently enabled metadata format
* @quantization: the quantization configured on the isp's src pad
* @ycbcr_encoding the YCbCr encoding
* @raw_type: the bayer pattern on the isp video sink pad
* @enabled_blocks: bitmask of enabled ISP blocks
*/
struct rkisp1_params {
struct rkisp1_vdev_node vnode;
@@ -383,11 +414,14 @@ struct rkisp1_params {
spinlock_t config_lock; /* locks the buffers list 'params' */
struct list_head params;
struct v4l2_format vdev_fmt;
const struct v4l2_meta_format *metafmt;
enum v4l2_quantization quantization;
enum v4l2_ycbcr_encoding ycbcr_encoding;
enum rkisp1_fmt_raw_pat_type raw_type;
u32 enabled_blocks;
};
/*
@@ -573,6 +607,9 @@ void rkisp1_sd_adjust_crop_rect(struct v4l2_rect *crop,
void rkisp1_sd_adjust_crop(struct v4l2_rect *crop,
const struct v4l2_mbus_framefmt *bounds);
void rkisp1_bls_swap_regs(enum rkisp1_fmt_raw_pat_type pattern,
const u32 input[4], u32 output[4]);
/*
* rkisp1_mbus_info_get_by_code - get the isp info of the media bus code
*

View File

@@ -307,6 +307,7 @@ static int rkisp1_csi_set_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_format *fmt)
{
struct rkisp1_csi *csi = to_rkisp1_csi(sd);
const struct rkisp1_mbus_info *mbus_info;
struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
@@ -326,10 +327,10 @@ static int rkisp1_csi_set_fmt(struct v4l2_subdev *sd,
sink_fmt->width = clamp_t(u32, fmt->format.width,
RKISP1_ISP_MIN_WIDTH,
RKISP1_ISP_MAX_WIDTH);
csi->rkisp1->info->max_width);
sink_fmt->height = clamp_t(u32, fmt->format.height,
RKISP1_ISP_MIN_HEIGHT,
RKISP1_ISP_MAX_HEIGHT);
csi->rkisp1->info->max_height);
fmt->format = *sink_fmt;

View File

@@ -509,7 +509,10 @@ static const struct rkisp1_info px30_isp_info = {
.isp_ver = RKISP1_V12,
.features = RKISP1_FEATURE_MIPI_CSI2
| RKISP1_FEATURE_SELF_PATH
| RKISP1_FEATURE_DUAL_CROP,
| RKISP1_FEATURE_DUAL_CROP
| RKISP1_FEATURE_BLS,
.max_width = 3264,
.max_height = 2448,
};
static const char * const rk3399_isp_clks[] = {
@@ -530,7 +533,10 @@ static const struct rkisp1_info rk3399_isp_info = {
.isp_ver = RKISP1_V10,
.features = RKISP1_FEATURE_MIPI_CSI2
| RKISP1_FEATURE_SELF_PATH
| RKISP1_FEATURE_DUAL_CROP,
| RKISP1_FEATURE_DUAL_CROP
| RKISP1_FEATURE_BLS,
.max_width = 4416,
.max_height = 3312,
};
static const char * const imx8mp_isp_clks[] = {
@@ -550,7 +556,10 @@ static const struct rkisp1_info imx8mp_isp_info = {
.isr_size = ARRAY_SIZE(imx8mp_isp_isrs),
.isp_ver = RKISP1_V_IMX8MP,
.features = RKISP1_FEATURE_MAIN_STRIDE
| RKISP1_FEATURE_DMA_34BIT,
| RKISP1_FEATURE_DMA_34BIT
| RKISP1_FEATURE_COMPAND,
.max_width = 4096,
.max_height = 3072,
};
static const struct of_device_id rkisp1_of_match[] = {

View File

@@ -517,6 +517,7 @@ static int rkisp1_isp_enum_frame_size(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_size_enum *fse)
{
struct rkisp1_isp *isp = to_rkisp1_isp(sd);
const struct rkisp1_mbus_info *mbus_info;
if (fse->pad == RKISP1_ISP_PAD_SINK_PARAMS ||
@@ -539,9 +540,9 @@ static int rkisp1_isp_enum_frame_size(struct v4l2_subdev *sd,
return -EINVAL;
fse->min_width = RKISP1_ISP_MIN_WIDTH;
fse->max_width = RKISP1_ISP_MAX_WIDTH;
fse->max_width = isp->rkisp1->info->max_width;
fse->min_height = RKISP1_ISP_MIN_HEIGHT;
fse->max_height = RKISP1_ISP_MAX_HEIGHT;
fse->max_height = isp->rkisp1->info->max_height;
return 0;
}
@@ -772,10 +773,10 @@ static void rkisp1_isp_set_sink_fmt(struct rkisp1_isp *isp,
sink_fmt->width = clamp_t(u32, format->width,
RKISP1_ISP_MIN_WIDTH,
RKISP1_ISP_MAX_WIDTH);
isp->rkisp1->info->max_width);
sink_fmt->height = clamp_t(u32, format->height,
RKISP1_ISP_MIN_HEIGHT,
RKISP1_ISP_MAX_HEIGHT);
isp->rkisp1->info->max_height);
/*
* Adjust the color space fields. Accept any color primaries and

File diff suppressed because it is too large Load Diff

View File

@@ -704,6 +704,12 @@
#define RKISP1_CIF_ISP_DPF_SPATIAL_COEFF_MAX 0x1f
#define RKISP1_CIF_ISP_DPF_NLL_COEFF_N_MAX 0x3ff
/* COMPAND */
#define RKISP1_CIF_ISP_COMPAND_CTRL_EXPAND_ENABLE BIT(0)
#define RKISP1_CIF_ISP_COMPAND_CTRL_COMPRESS_ENABLE BIT(1)
#define RKISP1_CIF_ISP_COMPAND_CTRL_SOFT_RESET_FLAG BIT(2)
#define RKISP1_CIF_ISP_COMPAND_CTRL_BLS_ENABLE BIT(3)
/* =================================================================== */
/* CIF Registers */
/* =================================================================== */
@@ -1394,6 +1400,23 @@
#define RKISP1_CIF_ISP_VSM_DELTA_H (RKISP1_CIF_ISP_VSM_BASE + 0x0000001c)
#define RKISP1_CIF_ISP_VSM_DELTA_V (RKISP1_CIF_ISP_VSM_BASE + 0x00000020)
#define RKISP1_CIF_ISP_COMPAND_BASE 0x00003200
#define RKISP1_CIF_ISP_COMPAND_CTRL (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000000)
#define RKISP1_CIF_ISP_COMPAND_BLS_A_FIXED (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000004)
#define RKISP1_CIF_ISP_COMPAND_BLS_B_FIXED (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000008)
#define RKISP1_CIF_ISP_COMPAND_BLS_C_FIXED (RKISP1_CIF_ISP_COMPAND_BASE + 0x0000000c)
#define RKISP1_CIF_ISP_COMPAND_BLS_D_FIXED (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000010)
#define RKISP1_CIF_ISP_COMPAND_EXPAND_PX_N(n) (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000014 + (n) * 4)
#define RKISP1_CIF_ISP_COMPAND_COMPRESS_PX_N(n) (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000040 + (n) * 4)
#define RKISP1_CIF_ISP_COMPAND_EXPAND_Y_ADDR (RKISP1_CIF_ISP_COMPAND_BASE + 0x0000006c)
#define RKISP1_CIF_ISP_COMPAND_EXPAND_Y_WRITE_DATA (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000070)
#define RKISP1_CIF_ISP_COMPAND_COMPRESS_Y_ADDR (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000074)
#define RKISP1_CIF_ISP_COMPAND_COMPRESS_Y_WRITE_DATA (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000078)
#define RKISP1_CIF_ISP_COMPAND_EXPAND_X_ADDR (RKISP1_CIF_ISP_COMPAND_BASE + 0x0000007c)
#define RKISP1_CIF_ISP_COMPAND_EXPAND_X_WRITE_DATA (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000080)
#define RKISP1_CIF_ISP_COMPAND_COMPRESS_X_ADDR (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000084)
#define RKISP1_CIF_ISP_COMPAND_COMPRESS_X_WRITE_DATA (RKISP1_CIF_ISP_COMPAND_BASE + 0x00000088)
#define RKISP1_CIF_ISP_CSI0_BASE 0x00007000
#define RKISP1_CIF_ISP_CSI0_CTRL0 (RKISP1_CIF_ISP_CSI0_BASE + 0x00000000)

View File

@@ -494,10 +494,10 @@ static void rkisp1_rsz_set_sink_fmt(struct rkisp1_resizer *rsz,
sink_fmt->width = clamp_t(u32, format->width,
RKISP1_ISP_MIN_WIDTH,
RKISP1_ISP_MAX_WIDTH);
rsz->rkisp1->info->max_width);
sink_fmt->height = clamp_t(u32, format->height,
RKISP1_ISP_MIN_HEIGHT,
RKISP1_ISP_MAX_HEIGHT);
rsz->rkisp1->info->max_height);
/*
* Adjust the color space fields. Accept any color primaries and

View File

@@ -304,48 +304,25 @@ static void rkisp1_stats_get_hst_meas_v12(struct rkisp1_stats *stats,
static void rkisp1_stats_get_bls_meas(struct rkisp1_stats *stats,
struct rkisp1_stat_buffer *pbuf)
{
static const u32 regs[] = {
RKISP1_CIF_ISP_BLS_A_MEASURED,
RKISP1_CIF_ISP_BLS_B_MEASURED,
RKISP1_CIF_ISP_BLS_C_MEASURED,
RKISP1_CIF_ISP_BLS_D_MEASURED,
};
struct rkisp1_device *rkisp1 = stats->rkisp1;
const struct rkisp1_mbus_info *in_fmt = rkisp1->isp.sink_fmt;
struct rkisp1_cif_isp_bls_meas_val *bls_val;
u32 swapped[4];
rkisp1_bls_swap_regs(in_fmt->bayer_pat, regs, swapped);
bls_val = &pbuf->params.ae.bls_val;
if (in_fmt->bayer_pat == RKISP1_RAW_BGGR) {
bls_val->meas_b =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_A_MEASURED);
bls_val->meas_gb =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_B_MEASURED);
bls_val->meas_gr =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_C_MEASURED);
bls_val->meas_r =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_D_MEASURED);
} else if (in_fmt->bayer_pat == RKISP1_RAW_GBRG) {
bls_val->meas_gb =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_A_MEASURED);
bls_val->meas_b =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_B_MEASURED);
bls_val->meas_r =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_C_MEASURED);
bls_val->meas_gr =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_D_MEASURED);
} else if (in_fmt->bayer_pat == RKISP1_RAW_GRBG) {
bls_val->meas_gr =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_A_MEASURED);
bls_val->meas_r =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_B_MEASURED);
bls_val->meas_b =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_C_MEASURED);
bls_val->meas_gb =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_D_MEASURED);
} else if (in_fmt->bayer_pat == RKISP1_RAW_RGGB) {
bls_val->meas_r =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_A_MEASURED);
bls_val->meas_gr =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_B_MEASURED);
bls_val->meas_gb =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_C_MEASURED);
bls_val->meas_b =
rkisp1_read(rkisp1, RKISP1_CIF_ISP_BLS_D_MEASURED);
}
bls_val->meas_r = rkisp1_read(rkisp1, swapped[0]);
bls_val->meas_gr = rkisp1_read(rkisp1, swapped[1]);
bls_val->meas_gb = rkisp1_read(rkisp1, swapped[2]);
bls_val->meas_b = rkisp1_read(rkisp1, swapped[3]);
}
static const struct rkisp1_stats_ops rkisp1_v10_stats_ops = {

View File

@@ -1458,6 +1458,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break;
case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break;
case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A Statistics"; break;
case V4L2_META_FMT_RK_ISP1_EXT_PARAMS: descr = "Rockchip ISP1 Ext 3A Params"; break;
case V4L2_PIX_FMT_NV12_8L128: descr = "NV12 (8x128 Linear)"; break;
case V4L2_PIX_FMT_NV12M_8L128: descr = "NV12M (8x128 Linear)"; break;
case V4L2_PIX_FMT_NV12_10BE_8L128: descr = "10-bit NV12 (8x128 Linear, BE)"; break;

File diff suppressed because it is too large Load Diff

View File

@@ -854,6 +854,7 @@ struct v4l2_pix_format {
/* Vendor specific - used for RK_ISP1 camera sub-system */
#define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P') /* Rockchip ISP1 3A Parameters */
#define V4L2_META_FMT_RK_ISP1_STAT_3A v4l2_fourcc('R', 'K', '1', 'S') /* Rockchip ISP1 3A Statistics */
#define V4L2_META_FMT_RK_ISP1_EXT_PARAMS v4l2_fourcc('R', 'K', '1', 'E') /* Rockchip ISP1 3a Extensible Parameters */
/* Vendor specific - used for RaspberryPi PiSP */
#define V4L2_META_FMT_RPI_BE_CFG v4l2_fourcc('R', 'P', 'B', 'C') /* PiSP BE configuration */