1 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR MIT) */
2 /*
3  * Rockchip ISP1 userspace API
4  * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
5  */
6 
7 #ifndef _UAPI_RKISP1_CONFIG_H
8 #define _UAPI_RKISP1_CONFIG_H
9 
10 #include <linux/types.h>
11 
12 /* Defect Pixel Cluster Detection */
13 #define RKISP1_CIF_ISP_MODULE_DPCC		(1U << 0)
14 /* Black Level Subtraction */
15 #define RKISP1_CIF_ISP_MODULE_BLS		(1U << 1)
16 /* Sensor De-gamma */
17 #define RKISP1_CIF_ISP_MODULE_SDG		(1U << 2)
18 /* Histogram statistics configuration */
19 #define RKISP1_CIF_ISP_MODULE_HST		(1U << 3)
20 /* Lens Shade Control */
21 #define RKISP1_CIF_ISP_MODULE_LSC		(1U << 4)
22 /* Auto White Balance Gain */
23 #define RKISP1_CIF_ISP_MODULE_AWB_GAIN		(1U << 5)
24 /* Filter */
25 #define RKISP1_CIF_ISP_MODULE_FLT		(1U << 6)
26 /* Bayer Demosaic */
27 #define RKISP1_CIF_ISP_MODULE_BDM		(1U << 7)
28 /* Cross Talk */
29 #define RKISP1_CIF_ISP_MODULE_CTK		(1U << 8)
30 /* Gamma Out Curve */
31 #define RKISP1_CIF_ISP_MODULE_GOC		(1U << 9)
32 /* Color Processing */
33 #define RKISP1_CIF_ISP_MODULE_CPROC		(1U << 10)
34 /* Auto Focus Control statistics configuration */
35 #define RKISP1_CIF_ISP_MODULE_AFC		(1U << 11)
36 /* Auto White Balancing statistics configuration */
37 #define RKISP1_CIF_ISP_MODULE_AWB		(1U << 12)
38 /* Image Effect */
39 #define RKISP1_CIF_ISP_MODULE_IE		(1U << 13)
40 /* Auto Exposure Control statistics configuration */
41 #define RKISP1_CIF_ISP_MODULE_AEC		(1U << 14)
42 /* Wide Dynamic Range */
43 #define RKISP1_CIF_ISP_MODULE_WDR		(1U << 15)
44 /* Denoise Pre-Filter */
45 #define RKISP1_CIF_ISP_MODULE_DPF		(1U << 16)
46 /* Denoise Pre-Filter Strength */
47 #define RKISP1_CIF_ISP_MODULE_DPF_STRENGTH	(1U << 17)
48 
49 #define RKISP1_CIF_ISP_CTK_COEFF_MAX            0x100
50 #define RKISP1_CIF_ISP_CTK_OFFSET_MAX           0x800
51 
52 #define RKISP1_CIF_ISP_AE_MEAN_MAX_V10		25
53 #define RKISP1_CIF_ISP_AE_MEAN_MAX_V12		81
54 #define RKISP1_CIF_ISP_AE_MEAN_MAX		RKISP1_CIF_ISP_AE_MEAN_MAX_V12
55 
56 #define RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10	16
57 #define RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12	32
58 #define RKISP1_CIF_ISP_HIST_BIN_N_MAX		RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12
59 
60 #define RKISP1_CIF_ISP_AFM_MAX_WINDOWS          3
61 #define RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE       17
62 
63 #define RKISP1_CIF_ISP_BDM_MAX_TH               0xff
64 
65 /*
66  * Black level compensation
67  */
68 /* maximum value for horizontal start address */
69 #define RKISP1_CIF_ISP_BLS_START_H_MAX             0x00000fff
70 /* maximum value for horizontal stop address */
71 #define RKISP1_CIF_ISP_BLS_STOP_H_MAX              0x00000fff
72 /* maximum value for vertical start address */
73 #define RKISP1_CIF_ISP_BLS_START_V_MAX             0x00000fff
74 /* maximum value for vertical stop address */
75 #define RKISP1_CIF_ISP_BLS_STOP_V_MAX              0x00000fff
76 /* maximum is 2^18 = 262144*/
77 #define RKISP1_CIF_ISP_BLS_SAMPLES_MAX             0x00000012
78 /* maximum value for fixed black level */
79 #define RKISP1_CIF_ISP_BLS_FIX_SUB_MAX             0x00000fff
80 /* minimum value for fixed black level */
81 #define RKISP1_CIF_ISP_BLS_FIX_SUB_MIN             0xfffff000
82 /* 13 bit range (signed)*/
83 #define RKISP1_CIF_ISP_BLS_FIX_MASK                0x00001fff
84 
85 /*
86  * Automatic white balance measurements
87  */
88 #define RKISP1_CIF_ISP_AWB_MAX_GRID                1
89 #define RKISP1_CIF_ISP_AWB_MAX_FRAMES              7
90 
91 /*
92  * Gamma out
93  */
94 /* Maximum number of color samples supported */
95 #define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10   17
96 #define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12   34
97 #define RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES       RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12
98 
99 /*
100  * Lens shade correction
101  */
102 #define RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE        8
103 
104 /*
105  * The following matches the tuning process,
106  * not the max capabilities of the chip.
107  */
108 #define RKISP1_CIF_ISP_LSC_SAMPLES_MAX             17
109 
110 /*
111  * Histogram calculation
112  */
113 #define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 25
114 #define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 81
115 #define RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE     RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
116 
117 /*
118  * Defect Pixel Cluster Correction
119  */
120 #define RKISP1_CIF_ISP_DPCC_METHODS_MAX				3
121 
122 #define RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE			(1U << 2)
123 
124 #define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER	(1U << 0)
125 #define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_RB_CENTER	(1U << 1)
126 #define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_G_3X3		(1U << 2)
127 #define RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_RB_3X3		(1U << 3)
128 
129 /* 0-2 for sets 1-3 */
130 #define RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_SET(n)		((n) << 0)
131 #define RKISP1_CIF_ISP_DPCC_SET_USE_STAGE1_USE_FIX_SET		(1U << 3)
132 
133 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_GREEN_ENABLE		(1U << 0)
134 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_GREEN_ENABLE		(1U << 1)
135 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_GREEN_ENABLE		(1U << 2)
136 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_GREEN_ENABLE	(1U << 3)
137 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_GREEN_ENABLE		(1U << 4)
138 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_PG_RED_BLUE_ENABLE	(1U << 8)
139 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_LC_RED_BLUE_ENABLE	(1U << 9)
140 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_RO_RED_BLUE_ENABLE	(1U << 10)
141 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_RND_RED_BLUE_ENABLE	(1U << 11)
142 #define RKISP1_CIF_ISP_DPCC_METHODS_SET_RG_RED_BLUE_ENABLE	(1U << 12)
143 
144 #define RKISP1_CIF_ISP_DPCC_LINE_THRESH_G(v)			((v) << 0)
145 #define RKISP1_CIF_ISP_DPCC_LINE_THRESH_RB(v)			((v) << 8)
146 #define RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_G(v)			((v) << 0)
147 #define RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_RB(v)			((v) << 8)
148 #define RKISP1_CIF_ISP_DPCC_PG_FAC_G(v)				((v) << 0)
149 #define RKISP1_CIF_ISP_DPCC_PG_FAC_RB(v)			((v) << 8)
150 #define RKISP1_CIF_ISP_DPCC_RND_THRESH_G(v)			((v) << 0)
151 #define RKISP1_CIF_ISP_DPCC_RND_THRESH_RB(v)			((v) << 8)
152 #define RKISP1_CIF_ISP_DPCC_RG_FAC_G(v)				((v) << 0)
153 #define RKISP1_CIF_ISP_DPCC_RG_FAC_RB(v)			((v) << 8)
154 
155 #define RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_G(n, v)			((v) << ((n) * 4))
156 #define RKISP1_CIF_ISP_DPCC_RO_LIMITS_n_RB(n, v)		((v) << ((n) * 4 + 2))
157 
158 #define RKISP1_CIF_ISP_DPCC_RND_OFFS_n_G(n, v)			((v) << ((n) * 4))
159 #define RKISP1_CIF_ISP_DPCC_RND_OFFS_n_RB(n, v)			((v) << ((n) * 4 + 2))
160 
161 /*
162  * Denoising pre filter
163  */
164 #define RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS      17
165 #define RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS  6
166 
167 /*
168  * Compand
169  */
170 #define RKISP1_CIF_ISP_COMPAND_NUM_POINTS	64
171 
172 /*
173  * Measurement types
174  */
175 #define RKISP1_CIF_ISP_STAT_AWB           (1U << 0)
176 #define RKISP1_CIF_ISP_STAT_AUTOEXP       (1U << 1)
177 #define RKISP1_CIF_ISP_STAT_AFM           (1U << 2)
178 #define RKISP1_CIF_ISP_STAT_HIST          (1U << 3)
179 
180 /**
181  * enum rkisp1_cif_isp_version - ISP variants
182  *
183  * @RKISP1_V10: Used at least in RK3288 and RK3399.
184  * @RKISP1_V11: Declared in the original vendor code, but not used. Same number
185  *	of entries in grids and histogram as v10.
186  * @RKISP1_V12: Used at least in RK3326 and PX30.
187  * @RKISP1_V13: Used at least in RK1808. Same number of entries in grids and
188  *	histogram as v12.
189  * @RKISP1_V_IMX8MP: Used in at least i.MX8MP. Same number of entries in grids
190  *	and histogram as v10.
191  */
192 enum rkisp1_cif_isp_version {
193 	RKISP1_V10 = 10,
194 	RKISP1_V11,
195 	RKISP1_V12,
196 	RKISP1_V13,
197 	RKISP1_V_IMX8MP,
198 };
199 
200 enum rkisp1_cif_isp_histogram_mode {
201 	RKISP1_CIF_ISP_HISTOGRAM_MODE_DISABLE,
202 	RKISP1_CIF_ISP_HISTOGRAM_MODE_RGB_COMBINED,
203 	RKISP1_CIF_ISP_HISTOGRAM_MODE_R_HISTOGRAM,
204 	RKISP1_CIF_ISP_HISTOGRAM_MODE_G_HISTOGRAM,
205 	RKISP1_CIF_ISP_HISTOGRAM_MODE_B_HISTOGRAM,
206 	RKISP1_CIF_ISP_HISTOGRAM_MODE_Y_HISTOGRAM
207 };
208 
209 enum rkisp1_cif_isp_awb_mode_type {
210 	RKISP1_CIF_ISP_AWB_MODE_MANUAL,
211 	RKISP1_CIF_ISP_AWB_MODE_RGB,
212 	RKISP1_CIF_ISP_AWB_MODE_YCBCR
213 };
214 
215 enum rkisp1_cif_isp_flt_mode {
216 	RKISP1_CIF_ISP_FLT_STATIC_MODE,
217 	RKISP1_CIF_ISP_FLT_DYNAMIC_MODE
218 };
219 
220 /**
221  * enum rkisp1_cif_isp_exp_ctrl_autostop - stop modes
222  * @RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_0: continuous measurement
223  * @RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
224  */
225 enum rkisp1_cif_isp_exp_ctrl_autostop {
226 	RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_0 = 0,
227 	RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_1 = 1,
228 };
229 
230 /**
231  * enum rkisp1_cif_isp_exp_meas_mode - Exposure measure mode
232  * @RKISP1_CIF_ISP_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B
233  * @RKISP1_CIF_ISP_EXP_MEASURING_MODE_1: Y = (R + G + B) x (85/256)
234  */
235 enum rkisp1_cif_isp_exp_meas_mode {
236 	RKISP1_CIF_ISP_EXP_MEASURING_MODE_0,
237 	RKISP1_CIF_ISP_EXP_MEASURING_MODE_1,
238 };
239 
240 /*---------- PART1: Input Parameters ------------*/
241 
242 /**
243  * struct rkisp1_cif_isp_window -  measurement window.
244  *
245  * Measurements are calculated per window inside the frame.
246  * This struct represents a window for a measurement.
247  *
248  * @h_offs: the horizontal offset of the window from the left of the frame in pixels.
249  * @v_offs: the vertical offset of the window from the top of the frame in pixels.
250  * @h_size: the horizontal size of the window in pixels
251  * @v_size: the vertical size of the window in pixels.
252  */
253 struct rkisp1_cif_isp_window {
254 	__u16 h_offs;
255 	__u16 v_offs;
256 	__u16 h_size;
257 	__u16 v_size;
258 };
259 
260 /**
261  * struct rkisp1_cif_isp_bls_fixed_val - BLS fixed subtraction values
262  *
263  * The values will be subtracted from the sensor
264  * values. Therefore a negative value means addition instead of subtraction!
265  *
266  * @r: Fixed (signed!) subtraction value for Bayer pattern R
267  * @gr: Fixed (signed!) subtraction value for Bayer pattern Gr
268  * @gb: Fixed (signed!) subtraction value for Bayer pattern Gb
269  * @b: Fixed (signed!) subtraction value for Bayer pattern B
270  */
271 struct rkisp1_cif_isp_bls_fixed_val {
272 	__s16 r;
273 	__s16 gr;
274 	__s16 gb;
275 	__s16 b;
276 };
277 
278 /**
279  * struct rkisp1_cif_isp_bls_config - Configuration used by black level subtraction
280  *
281  * @enable_auto: Automatic mode activated means that the measured values
282  *		 are subtracted. Otherwise the fixed subtraction
283  *		 values will be subtracted.
284  * @en_windows: enabled window
285  * @bls_window1: Measurement window 1 size
286  * @bls_window2: Measurement window 2 size
287  * @bls_samples: Set amount of measured pixels for each Bayer position
288  *		 (A, B,C and D) to 2^bls_samples.
289  * @fixed_val: Fixed subtraction values
290  */
291 struct rkisp1_cif_isp_bls_config {
292 	__u8 enable_auto;
293 	__u8 en_windows;
294 	struct rkisp1_cif_isp_window bls_window1;
295 	struct rkisp1_cif_isp_window bls_window2;
296 	__u8 bls_samples;
297 	struct rkisp1_cif_isp_bls_fixed_val fixed_val;
298 };
299 
300 /**
301  * struct rkisp1_cif_isp_dpcc_methods_config - DPCC methods set configuration
302  *
303  * This structure stores the configuration of one set of methods for the DPCC
304  * algorithm. Multiple methods can be selected in each set (independently for
305  * the Green and Red/Blue components) through the @method field, the result is
306  * the logical AND of all enabled methods. The remaining fields set thresholds
307  * and factors for each method.
308  *
309  * @method: Method enable bits (RKISP1_CIF_ISP_DPCC_METHODS_SET_*)
310  * @line_thresh: Line threshold (RKISP1_CIF_ISP_DPCC_LINE_THRESH_*)
311  * @line_mad_fac: Line Mean Absolute Difference factor (RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_*)
312  * @pg_fac: Peak gradient factor (RKISP1_CIF_ISP_DPCC_PG_FAC_*)
313  * @rnd_thresh: Rank Neighbor Difference threshold (RKISP1_CIF_ISP_DPCC_RND_THRESH_*)
314  * @rg_fac: Rank gradient factor (RKISP1_CIF_ISP_DPCC_RG_FAC_*)
315  */
316 struct rkisp1_cif_isp_dpcc_methods_config {
317 	__u32 method;
318 	__u32 line_thresh;
319 	__u32 line_mad_fac;
320 	__u32 pg_fac;
321 	__u32 rnd_thresh;
322 	__u32 rg_fac;
323 };
324 
325 /**
326  * struct rkisp1_cif_isp_dpcc_config - Configuration used by DPCC
327  *
328  * Configuration used by Defect Pixel Cluster Correction. Three sets of methods
329  * can be configured and selected through the @set_use field. The result is the
330  * logical OR of all enabled sets.
331  *
332  * @mode: DPCC mode (RKISP1_CIF_ISP_DPCC_MODE_*)
333  * @output_mode: Interpolation output mode (RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_*)
334  * @set_use: Methods sets selection (RKISP1_CIF_ISP_DPCC_SET_USE_*)
335  * @methods: Methods sets configuration
336  * @ro_limits: Rank order limits (RKISP1_CIF_ISP_DPCC_RO_LIMITS_*)
337  * @rnd_offs: Differential rank offsets for rank neighbor difference (RKISP1_CIF_ISP_DPCC_RND_OFFS_*)
338  */
339 struct rkisp1_cif_isp_dpcc_config {
340 	__u32 mode;
341 	__u32 output_mode;
342 	__u32 set_use;
343 	struct rkisp1_cif_isp_dpcc_methods_config methods[RKISP1_CIF_ISP_DPCC_METHODS_MAX];
344 	__u32 ro_limits;
345 	__u32 rnd_offs;
346 };
347 
348 /**
349  * struct rkisp1_cif_isp_gamma_corr_curve - gamma curve point definition y-axis (output).
350  *
351  * The reset values define a linear curve which has the same effect as bypass. Reset values are:
352  * gamma_y[0] = 0x0000, gamma_y[1] = 0x0100, ... gamma_y[15] = 0x0f00, gamma_y[16] = 0xfff
353  *
354  * @gamma_y: the values for the y-axis of gamma curve points. Each value is 12 bit.
355  */
356 struct rkisp1_cif_isp_gamma_corr_curve {
357 	__u16 gamma_y[RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE];
358 };
359 
360 /**
361  * struct rkisp1_cif_isp_gamma_curve_x_axis_pnts - De-Gamma Curve definition x increments
362  *		(sampling points). gamma_dx0 is for the lower samples (1-8), gamma_dx1 is for the
363  *		higher samples (9-16). The reset values for both fields is 0x44444444. This means
364  *		that each sample is 4 units away from the previous one on the x-axis.
365  *
366  * @gamma_dx0: gamma curve sample points definitions. Bits 0:2 for sample 1. Bit 3 unused.
367  *		Bits 4:6 for sample 2. bit 7 unused ... Bits 28:30 for sample 8. Bit 31 unused
368  * @gamma_dx1: gamma curve sample points definitions. Bits 0:2 for sample 9. Bit 3 unused.
369  *		Bits 4:6 for sample 10. bit 7 unused ... Bits 28:30 for sample 16. Bit 31 unused
370  */
371 struct rkisp1_cif_isp_gamma_curve_x_axis_pnts {
372 	__u32 gamma_dx0;
373 	__u32 gamma_dx1;
374 };
375 
376 /**
377  * struct rkisp1_cif_isp_sdg_config - Configuration used by sensor degamma
378  *
379  * @curve_r: gamma curve point definition axis for red
380  * @curve_g: gamma curve point definition axis for green
381  * @curve_b: gamma curve point definition axis for blue
382  * @xa_pnts: x axis increments
383  */
384 struct rkisp1_cif_isp_sdg_config {
385 	struct rkisp1_cif_isp_gamma_corr_curve curve_r;
386 	struct rkisp1_cif_isp_gamma_corr_curve curve_g;
387 	struct rkisp1_cif_isp_gamma_corr_curve curve_b;
388 	struct rkisp1_cif_isp_gamma_curve_x_axis_pnts xa_pnts;
389 };
390 
391 /**
392  * struct rkisp1_cif_isp_lsc_config - Configuration used by Lens shading correction
393  *
394  * @r_data_tbl: sample table red
395  * @gr_data_tbl: sample table green (red)
396  * @gb_data_tbl: sample table green (blue)
397  * @b_data_tbl: sample table blue
398  * @x_grad_tbl: gradient table x
399  * @y_grad_tbl: gradient table y
400  * @x_size_tbl: size table x
401  * @y_size_tbl: size table y
402  * @config_width: not used at the moment
403  * @config_height: not used at the moment
404  */
405 struct rkisp1_cif_isp_lsc_config {
406 	__u16 r_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
407 	__u16 gr_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
408 	__u16 gb_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
409 	__u16 b_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
410 
411 	__u16 x_grad_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
412 	__u16 y_grad_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
413 
414 	__u16 x_size_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
415 	__u16 y_size_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
416 	__u16 config_width;
417 	__u16 config_height;
418 };
419 
420 /**
421  * struct rkisp1_cif_isp_ie_config - Configuration used by image effects
422  *
423  * @effect: values from 'enum v4l2_colorfx'. Possible values are: V4L2_COLORFX_SEPIA,
424  *		V4L2_COLORFX_SET_CBCR, V4L2_COLORFX_AQUA, V4L2_COLORFX_EMBOSS,
425  *		V4L2_COLORFX_SKETCH,   V4L2_COLORFX_BW,   V4L2_COLORFX_NEGATIVE
426  * @color_sel: bits 0:2 - colors bitmask (001 - blue, 010 - green, 100 - red).
427  *		bits 8:15 - Threshold value of the RGB colors for the color selection effect.
428  * @eff_mat_1: 3x3 Matrix Coefficients for Emboss Effect 1
429  * @eff_mat_2: 3x3 Matrix Coefficients for Emboss Effect 2
430  * @eff_mat_3: 3x3 Matrix Coefficients for Emboss 3/Sketch 1
431  * @eff_mat_4: 3x3 Matrix Coefficients for Sketch Effect 2
432  * @eff_mat_5: 3x3 Matrix Coefficients for Sketch Effect 3
433  * @eff_tint: Chrominance increment values of tint (used for sepia effect)
434  */
435 struct rkisp1_cif_isp_ie_config {
436 	__u16 effect;
437 	__u16 color_sel;
438 	__u16 eff_mat_1;
439 	__u16 eff_mat_2;
440 	__u16 eff_mat_3;
441 	__u16 eff_mat_4;
442 	__u16 eff_mat_5;
443 	__u16 eff_tint;
444 };
445 
446 /**
447  * struct rkisp1_cif_isp_cproc_config - Configuration used by Color Processing
448  *
449  * @c_out_range: Chrominance pixel clipping range at output.
450  *		 (0 for limit, 1 for full)
451  * @y_in_range: Luminance pixel clipping range at output.
452  * @y_out_range: Luminance pixel clipping range at output.
453  * @contrast: 00~ff, 0.0~1.992
454  * @brightness: 80~7F, -128~+127
455  * @sat: saturation, 00~FF, 0.0~1.992
456  * @hue: 80~7F, -90~+87.188
457  */
458 struct rkisp1_cif_isp_cproc_config {
459 	__u8 c_out_range;
460 	__u8 y_in_range;
461 	__u8 y_out_range;
462 	__u8 contrast;
463 	__u8 brightness;
464 	__u8 sat;
465 	__u8 hue;
466 };
467 
468 /**
469  * struct rkisp1_cif_isp_awb_meas_config - Configuration for the AWB statistics
470  *
471  * @awb_mode: the awb meas mode. From enum rkisp1_cif_isp_awb_mode_type.
472  * @awb_wnd: white balance measurement window (in pixels)
473  * @max_y: only pixels values < max_y contribute to awb measurement, set to 0
474  *	   to disable this feature
475  * @min_y: only pixels values > min_y contribute to awb measurement
476  * @max_csum: Chrominance sum maximum value, only consider pixels with Cb+Cr,
477  *	      smaller than threshold for awb measurements
478  * @min_c: Chrominance minimum value, only consider pixels with Cb/Cr
479  *	   each greater than threshold value for awb measurements
480  * @frames: number of frames - 1 used for mean value calculation
481  *	    (ucFrames=0 means 1 Frame)
482  * @awb_ref_cr: reference Cr value for AWB regulation, target for AWB
483  * @awb_ref_cb: reference Cb value for AWB regulation, target for AWB
484  * @enable_ymax_cmp: enable Y_MAX compare (Not valid in RGB measurement mode.)
485  */
486 struct rkisp1_cif_isp_awb_meas_config {
487 	/*
488 	 * Note: currently the h and v offsets are mapped to grid offsets
489 	 */
490 	struct rkisp1_cif_isp_window awb_wnd;
491 	__u32 awb_mode;
492 	__u8 max_y;
493 	__u8 min_y;
494 	__u8 max_csum;
495 	__u8 min_c;
496 	__u8 frames;
497 	__u8 awb_ref_cr;
498 	__u8 awb_ref_cb;
499 	__u8 enable_ymax_cmp;
500 };
501 
502 /**
503  * struct rkisp1_cif_isp_awb_gain_config - Configuration used by auto white balance gain
504  *
505  * All fields in this struct are 10 bit, where:
506  * 0x100h = 1, unsigned integer value, range 0 to 4 with 8 bit fractional part.
507  *
508  * out_data_x = ( AWB_GAIN_X * in_data + 128) >> 8
509  *
510  * @gain_red: gain value for red component.
511  * @gain_green_r: gain value for green component in red line.
512  * @gain_blue: gain value for blue component.
513  * @gain_green_b: gain value for green component in blue line.
514  */
515 struct rkisp1_cif_isp_awb_gain_config {
516 	__u16 gain_red;
517 	__u16 gain_green_r;
518 	__u16 gain_blue;
519 	__u16 gain_green_b;
520 };
521 
522 /**
523  * struct rkisp1_cif_isp_flt_config - Configuration used by ISP filtering
524  *
525  * All 4 threshold fields (thresh_*) are 10 bits.
526  * All 6 factor fields (fac_*) are 6 bits.
527  *
528  * @mode: ISP_FILT_MODE register fields (from enum rkisp1_cif_isp_flt_mode)
529  * @grn_stage1: Green filter stage 1 select (range 0x0...0x8)
530  * @chr_h_mode: Chroma filter horizontal mode
531  * @chr_v_mode: Chroma filter vertical mode
532  * @thresh_bl0: If thresh_bl1 < sum_grad < thresh_bl0 then fac_bl0 is selected (blurring th)
533  * @thresh_bl1: If sum_grad < thresh_bl1 then fac_bl1 is selected (blurring th)
534  * @thresh_sh0: If thresh_sh0 < sum_grad < thresh_sh1 then thresh_sh0 is selected (sharpening th)
535  * @thresh_sh1: If thresh_sh1 < sum_grad then thresh_sh1 is selected (sharpening th)
536  * @lum_weight: Parameters for luminance weight function.
537  * @fac_sh1: filter factor for sharp1 level
538  * @fac_sh0: filter factor for sharp0 level
539  * @fac_mid: filter factor for mid level and for static filter mode
540  * @fac_bl0: filter factor for blur 0 level
541  * @fac_bl1: filter factor for blur 1 level (max blur)
542  */
543 struct rkisp1_cif_isp_flt_config {
544 	__u32 mode;
545 	__u8 grn_stage1;
546 	__u8 chr_h_mode;
547 	__u8 chr_v_mode;
548 	__u32 thresh_bl0;
549 	__u32 thresh_bl1;
550 	__u32 thresh_sh0;
551 	__u32 thresh_sh1;
552 	__u32 lum_weight;
553 	__u32 fac_sh1;
554 	__u32 fac_sh0;
555 	__u32 fac_mid;
556 	__u32 fac_bl0;
557 	__u32 fac_bl1;
558 };
559 
560 /**
561  * struct rkisp1_cif_isp_bdm_config - Configuration used by Bayer DeMosaic
562  *
563  * @demosaic_th: threshold for bayer demosaicing texture detection
564  */
565 struct rkisp1_cif_isp_bdm_config {
566 	__u8 demosaic_th;
567 };
568 
569 /**
570  * struct rkisp1_cif_isp_ctk_config - Configuration used by Cross Talk correction
571  *
572  * @coeff: color correction matrix. Values are 11-bit signed fixed-point numbers with 4 bit integer
573  *		and 7 bit fractional part, ranging from -8 (0x400) to +7.992 (0x3FF). 0 is
574  *		represented by 0x000 and a coefficient value of 1 as 0x080.
575  * @ct_offset: Red, Green, Blue offsets for the crosstalk correction matrix
576  */
577 struct rkisp1_cif_isp_ctk_config {
578 	__u16 coeff[3][3];
579 	__u16 ct_offset[3];
580 };
581 
582 enum rkisp1_cif_isp_goc_mode {
583 	RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC,
584 	RKISP1_CIF_ISP_GOC_MODE_EQUIDISTANT
585 };
586 
587 /**
588  * struct rkisp1_cif_isp_goc_config - Configuration used by Gamma Out correction
589  *
590  * @mode: goc mode (from enum rkisp1_cif_isp_goc_mode)
591  * @gamma_y: gamma out curve y-axis for all color components
592  *
593  * The number of entries of @gamma_y depends on the hardware revision
594  * as is reported by the hw_revision field of the struct media_device_info
595  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
596  *
597  * V10 has RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 entries, V12 has
598  * RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12 entries.
599  * RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum of the two.
600  */
601 struct rkisp1_cif_isp_goc_config {
602 	__u32 mode;
603 	__u16 gamma_y[RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES];
604 };
605 
606 /**
607  * struct rkisp1_cif_isp_hst_config - Configuration for Histogram statistics
608  *
609  * @mode: histogram mode (from enum rkisp1_cif_isp_histogram_mode)
610  * @histogram_predivider: process every stepsize pixel, all other pixels are
611  *			  skipped
612  * @meas_window: coordinates of the measure window
613  * @hist_weight: weighting factor for sub-windows
614  *
615  * The number of entries of @hist_weight depends on the hardware revision
616  * as is reported by the hw_revision field of the struct media_device_info
617  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
618  *
619  * V10 has RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 entries, V12 has
620  * RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 entries.
621  * RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum of the
622  * two.
623  */
624 struct rkisp1_cif_isp_hst_config {
625 	__u32 mode;
626 	__u8 histogram_predivider;
627 	struct rkisp1_cif_isp_window meas_window;
628 	__u8 hist_weight[RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE];
629 };
630 
631 /**
632  * struct rkisp1_cif_isp_aec_config - Configuration for Auto Exposure statistics
633  *
634  * @mode: Exposure measure mode (from enum rkisp1_cif_isp_exp_meas_mode)
635  * @autostop: stop mode (from enum rkisp1_cif_isp_exp_ctrl_autostop)
636  * @meas_window: coordinates of the measure window
637  */
638 struct rkisp1_cif_isp_aec_config {
639 	__u32 mode;
640 	__u32 autostop;
641 	struct rkisp1_cif_isp_window meas_window;
642 };
643 
644 /**
645  * struct rkisp1_cif_isp_afc_config - Configuration for the Auto Focus statistics
646  *
647  * @num_afm_win: max RKISP1_CIF_ISP_AFM_MAX_WINDOWS
648  * @afm_win: coordinates of the meas window
649  * @thres: threshold used for minimizing the influence of noise
650  * @var_shift: the number of bits for the shift operation at the end of the
651  *	       calculation chain.
652  */
653 struct rkisp1_cif_isp_afc_config {
654 	__u8 num_afm_win;
655 	struct rkisp1_cif_isp_window afm_win[RKISP1_CIF_ISP_AFM_MAX_WINDOWS];
656 	__u32 thres;
657 	__u32 var_shift;
658 };
659 
660 /**
661  * enum rkisp1_cif_isp_dpf_gain_usage - dpf gain usage
662  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED: don't use any gains in preprocessing stage
663  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS: use only the noise function gains from
664  *				    registers DPF_NF_GAIN_R, ...
665  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS:  use only the gains from LSC module
666  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS: use the noise function gains and the
667  *					gains from LSC module
668  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS: use only the gains from AWB module
669  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS: use the gains from AWB and LSC module
670  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_MAX: upper border (only for an internal evaluation)
671  */
672 enum rkisp1_cif_isp_dpf_gain_usage {
673 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED,
674 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS,
675 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS,
676 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS,
677 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS,
678 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS,
679 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_MAX
680 };
681 
682 /**
683  * enum rkisp1_cif_isp_dpf_rb_filtersize - Red and blue filter sizes
684  * @RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9: red and blue filter kernel size 13x9
685  *				   (means 7x5 active pixel)
686  * @RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9: red and blue filter kernel size 9x9
687  *				   (means 5x5 active pixel)
688  */
689 enum rkisp1_cif_isp_dpf_rb_filtersize {
690 	RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9,
691 	RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9,
692 };
693 
694 /**
695  * enum rkisp1_cif_isp_dpf_nll_scale_mode - dpf noise level scale mode
696  * @RKISP1_CIF_ISP_NLL_SCALE_LINEAR: use a linear scaling
697  * @RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC: use a logarithmic scaling
698  */
699 enum rkisp1_cif_isp_dpf_nll_scale_mode {
700 	RKISP1_CIF_ISP_NLL_SCALE_LINEAR,
701 	RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC,
702 };
703 
704 /**
705  * struct rkisp1_cif_isp_dpf_nll - Noise level lookup
706  *
707  * @coeff: Noise level Lookup coefficient
708  * @scale_mode: dpf noise level scale mode (from enum rkisp1_cif_isp_dpf_nll_scale_mode)
709  */
710 struct rkisp1_cif_isp_dpf_nll {
711 	__u16 coeff[RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS];
712 	__u32 scale_mode;
713 };
714 
715 /**
716  * struct rkisp1_cif_isp_dpf_rb_flt - Red blue filter config
717  *
718  * @fltsize: The filter size for the red and blue pixels
719  *	     (from enum rkisp1_cif_isp_dpf_rb_filtersize)
720  * @spatial_coeff: Spatial weights
721  * @r_enable: enable filter processing for red pixels
722  * @b_enable: enable filter processing for blue pixels
723  */
724 struct rkisp1_cif_isp_dpf_rb_flt {
725 	__u32 fltsize;
726 	__u8 spatial_coeff[RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS];
727 	__u8 r_enable;
728 	__u8 b_enable;
729 };
730 
731 /**
732  * struct rkisp1_cif_isp_dpf_g_flt - Green filter Configuration
733  *
734  * @spatial_coeff: Spatial weights
735  * @gr_enable: enable filter processing for green pixels in green/red lines
736  * @gb_enable: enable filter processing for green pixels in green/blue lines
737  */
738 struct rkisp1_cif_isp_dpf_g_flt {
739 	__u8 spatial_coeff[RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS];
740 	__u8 gr_enable;
741 	__u8 gb_enable;
742 };
743 
744 /**
745  * struct rkisp1_cif_isp_dpf_gain - Noise function Configuration
746  *
747  * @mode: dpf gain usage  (from enum rkisp1_cif_isp_dpf_gain_usage)
748  * @nf_r_gain: Noise function Gain that replaces the AWB gain for red pixels
749  * @nf_b_gain: Noise function Gain that replaces the AWB gain for blue pixels
750  * @nf_gr_gain: Noise function Gain that replaces the AWB gain
751  *		for green pixels in a red line
752  * @nf_gb_gain: Noise function Gain that replaces the AWB gain
753  *		for green pixels in a blue line
754  */
755 struct rkisp1_cif_isp_dpf_gain {
756 	__u32 mode;
757 	__u16 nf_r_gain;
758 	__u16 nf_b_gain;
759 	__u16 nf_gr_gain;
760 	__u16 nf_gb_gain;
761 };
762 
763 /**
764  * struct rkisp1_cif_isp_dpf_config - Configuration used by De-noising pre-filter
765  *
766  * @gain: noise function gain
767  * @g_flt: green filter config
768  * @rb_flt: red blue filter config
769  * @nll: noise level lookup
770  */
771 struct rkisp1_cif_isp_dpf_config {
772 	struct rkisp1_cif_isp_dpf_gain gain;
773 	struct rkisp1_cif_isp_dpf_g_flt g_flt;
774 	struct rkisp1_cif_isp_dpf_rb_flt rb_flt;
775 	struct rkisp1_cif_isp_dpf_nll nll;
776 };
777 
778 /**
779  * struct rkisp1_cif_isp_dpf_strength_config - strength of the filter
780  *
781  * @r: filter strength of the RED filter
782  * @g: filter strength of the GREEN filter
783  * @b: filter strength of the BLUE filter
784  */
785 struct rkisp1_cif_isp_dpf_strength_config {
786 	__u8 r;
787 	__u8 g;
788 	__u8 b;
789 };
790 
791 /**
792  * struct rkisp1_cif_isp_isp_other_cfg - Parameters for some blocks in rockchip isp1
793  *
794  * @dpcc_config: Defect Pixel Cluster Correction config
795  * @bls_config: Black Level Subtraction config
796  * @sdg_config: sensor degamma config
797  * @lsc_config: Lens Shade config
798  * @awb_gain_config: Auto White balance gain config
799  * @flt_config: filter config
800  * @bdm_config: demosaic config
801  * @ctk_config: cross talk config
802  * @goc_config: gamma out config
803  * @bls_config: black level subtraction config
804  * @dpf_config: De-noising pre-filter config
805  * @dpf_strength_config: dpf strength config
806  * @cproc_config: color process config
807  * @ie_config: image effects config
808  */
809 struct rkisp1_cif_isp_isp_other_cfg {
810 	struct rkisp1_cif_isp_dpcc_config dpcc_config;
811 	struct rkisp1_cif_isp_bls_config bls_config;
812 	struct rkisp1_cif_isp_sdg_config sdg_config;
813 	struct rkisp1_cif_isp_lsc_config lsc_config;
814 	struct rkisp1_cif_isp_awb_gain_config awb_gain_config;
815 	struct rkisp1_cif_isp_flt_config flt_config;
816 	struct rkisp1_cif_isp_bdm_config bdm_config;
817 	struct rkisp1_cif_isp_ctk_config ctk_config;
818 	struct rkisp1_cif_isp_goc_config goc_config;
819 	struct rkisp1_cif_isp_dpf_config dpf_config;
820 	struct rkisp1_cif_isp_dpf_strength_config dpf_strength_config;
821 	struct rkisp1_cif_isp_cproc_config cproc_config;
822 	struct rkisp1_cif_isp_ie_config ie_config;
823 };
824 
825 /**
826  * struct rkisp1_cif_isp_isp_meas_cfg - Rockchip ISP1 Measure Parameters
827  *
828  * @awb_meas_config: auto white balance config
829  * @hst_config: histogram config
830  * @aec_config: auto exposure config
831  * @afc_config: auto focus config
832  */
833 struct rkisp1_cif_isp_isp_meas_cfg {
834 	struct rkisp1_cif_isp_awb_meas_config awb_meas_config;
835 	struct rkisp1_cif_isp_hst_config hst_config;
836 	struct rkisp1_cif_isp_aec_config aec_config;
837 	struct rkisp1_cif_isp_afc_config afc_config;
838 };
839 
840 /**
841  * struct rkisp1_params_cfg - Rockchip ISP1 Input Parameters Meta Data
842  *
843  * @module_en_update: mask the enable bits of which module should be updated
844  * @module_ens: mask the enable value of each module, only update the module
845  *		which correspond bit was set in module_en_update
846  * @module_cfg_update: mask the config bits of which module should be updated
847  * @meas: measurement config
848  * @others: other config
849  */
850 struct rkisp1_params_cfg {
851 	__u32 module_en_update;
852 	__u32 module_ens;
853 	__u32 module_cfg_update;
854 
855 	struct rkisp1_cif_isp_isp_meas_cfg meas;
856 	struct rkisp1_cif_isp_isp_other_cfg others;
857 };
858 
859 /**
860  * struct rkisp1_cif_isp_compand_bls_config - Rockchip ISP1 Companding parameters (BLS)
861  * @r: Fixed subtraction value for Bayer pattern R
862  * @gr: Fixed subtraction value for Bayer pattern Gr
863  * @gb: Fixed subtraction value for Bayer pattern Gb
864  * @b: Fixed subtraction value for Bayer pattern B
865  *
866  * The values will be subtracted from the sensor values. Note that unlike the
867  * dedicated BLS block, the BLS values in the compander are 20-bit unsigned.
868  */
869 struct rkisp1_cif_isp_compand_bls_config {
870 	__u32 r;
871 	__u32 gr;
872 	__u32 gb;
873 	__u32 b;
874 };
875 
876 /**
877  * struct rkisp1_cif_isp_compand_curve_config - Rockchip ISP1 Companding
878  * parameters (expand and compression curves)
879  * @px: Compand curve x-values. Each value stores the distance from the
880  *      previous x-value, expressed as log2 of the distance on 5 bits.
881  * @x: Compand curve x-values. The functionality of these parameters are
882  *     unknown due to do a lack of hardware documentation, but these are left
883  *     here for future compatibility purposes.
884  * @y: Compand curve y-values
885  */
886 struct rkisp1_cif_isp_compand_curve_config {
887 	__u8 px[RKISP1_CIF_ISP_COMPAND_NUM_POINTS];
888 	__u32 x[RKISP1_CIF_ISP_COMPAND_NUM_POINTS];
889 	__u32 y[RKISP1_CIF_ISP_COMPAND_NUM_POINTS];
890 };
891 
892 /*---------- PART2: Measurement Statistics ------------*/
893 
894 /**
895  * struct rkisp1_cif_isp_awb_meas - AWB measured values
896  *
897  * @cnt: White pixel count, number of "white pixels" found during last
898  *	 measurement
899  * @mean_y_or_g: Mean value of Y within window and frames,
900  *		 Green if RGB is selected.
901  * @mean_cb_or_b: Mean value of Cb within window and frames,
902  *		  Blue if RGB is selected.
903  * @mean_cr_or_r: Mean value of Cr within window and frames,
904  *		  Red if RGB is selected.
905  */
906 struct rkisp1_cif_isp_awb_meas {
907 	__u32 cnt;
908 	__u8 mean_y_or_g;
909 	__u8 mean_cb_or_b;
910 	__u8 mean_cr_or_r;
911 };
912 
913 /**
914  * struct rkisp1_cif_isp_awb_stat - statistics automatic white balance data
915  *
916  * @awb_mean: Mean measured data
917  */
918 struct rkisp1_cif_isp_awb_stat {
919 	struct rkisp1_cif_isp_awb_meas awb_mean[RKISP1_CIF_ISP_AWB_MAX_GRID];
920 };
921 
922 /**
923  * struct rkisp1_cif_isp_bls_meas_val - BLS measured values
924  *
925  * @meas_r: Mean measured value for Bayer pattern R
926  * @meas_gr: Mean measured value for Bayer pattern Gr
927  * @meas_gb: Mean measured value for Bayer pattern Gb
928  * @meas_b: Mean measured value for Bayer pattern B
929  */
930 struct rkisp1_cif_isp_bls_meas_val {
931 	__u16 meas_r;
932 	__u16 meas_gr;
933 	__u16 meas_gb;
934 	__u16 meas_b;
935 };
936 
937 /**
938  * struct rkisp1_cif_isp_ae_stat - statistics auto exposure data
939  *
940  * @exp_mean: Mean luminance value of block xx
941  * @bls_val:  BLS measured values
942  *
943  * The number of entries of @exp_mean depends on the hardware revision
944  * as is reported by the hw_revision field of the struct media_device_info
945  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
946  *
947  * V10 has RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries, V12 has
948  * RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries. RKISP1_CIF_ISP_AE_MEAN_MAX is equal
949  * to the maximum of the two.
950  *
951  * Image is divided into 5x5 blocks on V10 and 9x9 blocks on V12.
952  */
953 struct rkisp1_cif_isp_ae_stat {
954 	__u8 exp_mean[RKISP1_CIF_ISP_AE_MEAN_MAX];
955 	struct rkisp1_cif_isp_bls_meas_val bls_val;
956 };
957 
958 /**
959  * struct rkisp1_cif_isp_af_meas_val - AF measured values
960  *
961  * @sum: sharpness value
962  * @lum: luminance value
963  */
964 struct rkisp1_cif_isp_af_meas_val {
965 	__u32 sum;
966 	__u32 lum;
967 };
968 
969 /**
970  * struct rkisp1_cif_isp_af_stat - statistics auto focus data
971  *
972  * @window: AF measured value of window x
973  *
974  * The module measures the sharpness in 3 windows of selectable size via
975  * register settings(ISP_AFM_*_A/B/C)
976  */
977 struct rkisp1_cif_isp_af_stat {
978 	struct rkisp1_cif_isp_af_meas_val window[RKISP1_CIF_ISP_AFM_MAX_WINDOWS];
979 };
980 
981 /**
982  * struct rkisp1_cif_isp_hist_stat - statistics histogram data
983  *
984  * @hist_bins: measured bin counters. Each bin is a 20 bits unsigned fixed point
985  *	       type. Bits 0-4 are the fractional part and bits 5-19 are the
986  *	       integer part.
987  *
988  * The window of the measurements area is divided to 5x5 sub-windows for
989  * V10 and to 9x9 sub-windows for V12. The histogram is then computed for each
990  * sub-window independently and the final result is a weighted average of the
991  * histogram measurements on all sub-windows. The window of the measurements
992  * area and the weight of each sub-window are configurable using
993  * struct @rkisp1_cif_isp_hst_config.
994  *
995  * The histogram contains 16 bins in V10 and 32 bins in V12.
996  *
997  * The number of entries of @hist_bins depends on the hardware revision
998  * as is reported by the hw_revision field of the struct media_device_info
999  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
1000  *
1001  * V10 has RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries, V12 has
1002  * RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries. RKISP1_CIF_ISP_HIST_BIN_N_MAX is
1003  * equal to the maximum of the two.
1004  */
1005 struct rkisp1_cif_isp_hist_stat {
1006 	__u32 hist_bins[RKISP1_CIF_ISP_HIST_BIN_N_MAX];
1007 };
1008 
1009 /**
1010  * struct rkisp1_cif_isp_stat - Rockchip ISP1 Statistics Data
1011  *
1012  * @awb: statistics data for automatic white balance
1013  * @ae: statistics data for auto exposure
1014  * @af: statistics data for auto focus
1015  * @hist: statistics histogram data
1016  */
1017 struct rkisp1_cif_isp_stat {
1018 	struct rkisp1_cif_isp_awb_stat awb;
1019 	struct rkisp1_cif_isp_ae_stat ae;
1020 	struct rkisp1_cif_isp_af_stat af;
1021 	struct rkisp1_cif_isp_hist_stat hist;
1022 };
1023 
1024 /**
1025  * struct rkisp1_stat_buffer - Rockchip ISP1 Statistics Meta Data
1026  *
1027  * @meas_type: measurement types (RKISP1_CIF_ISP_STAT_* definitions)
1028  * @frame_id: frame ID for sync
1029  * @params: statistics data
1030  */
1031 struct rkisp1_stat_buffer {
1032 	__u32 meas_type;
1033 	__u32 frame_id;
1034 	struct rkisp1_cif_isp_stat params;
1035 };
1036 
1037 /*---------- PART3: Extensible Configuration Parameters  ------------*/
1038 
1039 /**
1040  * enum rkisp1_ext_params_block_type - RkISP1 extensible params block type
1041  *
1042  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS: Black level subtraction
1043  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC: Defect pixel cluster correction
1044  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG: Sensor de-gamma
1045  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN: Auto white balance gains
1046  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT: ISP filtering
1047  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM: Bayer de-mosaic
1048  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK: Cross-talk correction
1049  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC: Gamma out correction
1050  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF: De-noise pre-filter
1051  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH: De-noise pre-filter strength
1052  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC: Color processing
1053  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_IE: Image effects
1054  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC: Lens shading correction
1055  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS: Auto white balance statistics
1056  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS: Histogram statistics
1057  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS: Auto exposure statistics
1058  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS: Auto-focus statistics
1059  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS: BLS in the compand block
1060  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND: Companding expand curve
1061  * @RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS: Companding compress curve
1062  */
1063 enum rkisp1_ext_params_block_type {
1064 	RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS,
1065 	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC,
1066 	RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG,
1067 	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN,
1068 	RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT,
1069 	RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM,
1070 	RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK,
1071 	RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC,
1072 	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF,
1073 	RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH,
1074 	RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC,
1075 	RKISP1_EXT_PARAMS_BLOCK_TYPE_IE,
1076 	RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC,
1077 	RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS,
1078 	RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS,
1079 	RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS,
1080 	RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS,
1081 	RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS,
1082 	RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND,
1083 	RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS,
1084 };
1085 
1086 #define RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE	(1U << 0)
1087 #define RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE	(1U << 1)
1088 
1089 /**
1090  * struct rkisp1_ext_params_block_header - RkISP1 extensible parameters block
1091  *					   header
1092  *
1093  * This structure represents the common part of all the ISP configuration
1094  * blocks. Each parameters block shall embed an instance of this structure type
1095  * as its first member, followed by the block-specific configuration data. The
1096  * driver inspects this common header to discern the block type and its size and
1097  * properly handle the block content by casting it to the correct block-specific
1098  * type.
1099  *
1100  * The @type field is one of the values enumerated by
1101  * :c:type:`rkisp1_ext_params_block_type` and specifies how the data should be
1102  * interpreted by the driver. The @size field specifies the size of the
1103  * parameters block and is used by the driver for validation purposes.
1104  *
1105  * The @flags field is a bitmask of per-block flags RKISP1_EXT_PARAMS_FL_*.
1106  *
1107  * When userspace wants to configure and enable an ISP block it shall fully
1108  * populate the block configuration and set the
1109  * RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE bit in the @flags field.
1110  *
1111  * When userspace simply wants to disable an ISP block the
1112  * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bit should be set in @flags field. The
1113  * driver ignores the rest of the block configuration structure in this case.
1114  *
1115  * If a new configuration of an ISP block has to be applied userspace shall
1116  * fully populate the ISP block configuration and omit setting the
1117  * RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE and RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bits
1118  * in the @flags field.
1119  *
1120  * Setting both the RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE and
1121  * RKISP1_EXT_PARAMS_FL_BLOCK_DISABLE bits in the @flags field is not allowed
1122  * and not accepted by the driver.
1123  *
1124  * Userspace is responsible for correctly populating the parameters block header
1125  * fields (@type, @flags and @size) and the block-specific parameters.
1126  *
1127  * For example:
1128  *
1129  * .. code-block:: c
1130  *
1131  *	void populate_bls(struct rkisp1_ext_params_block_header *block) {
1132  *		struct rkisp1_ext_params_bls_config *bls =
1133  *			(struct rkisp1_ext_params_bls_config *)block;
1134  *
1135  *		bls->header.type = RKISP1_EXT_PARAMS_BLOCK_ID_BLS;
1136  *		bls->header.flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;
1137  *		bls->header.size = sizeof(*bls);
1138  *
1139  *		bls->config.enable_auto = 0;
1140  *		bls->config.fixed_val.r = blackLevelRed_;
1141  *		bls->config.fixed_val.gr = blackLevelGreenR_;
1142  *		bls->config.fixed_val.gb = blackLevelGreenB_;
1143  *		bls->config.fixed_val.b = blackLevelBlue_;
1144  *	}
1145  *
1146  * @type: The parameters block type, see
1147  *	  :c:type:`rkisp1_ext_params_block_type`
1148  * @flags: A bitmask of block flags
1149  * @size: Size (in bytes) of the parameters block, including this header
1150  */
1151 struct rkisp1_ext_params_block_header {
1152 	__u16 type;
1153 	__u16 flags;
1154 	__u32 size;
1155 };
1156 
1157 /**
1158  * struct rkisp1_ext_params_bls_config - RkISP1 extensible params BLS config
1159  *
1160  * RkISP1 extensible parameters Black Level Subtraction configuration block.
1161  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.
1162  *
1163  * @header: The RkISP1 extensible parameters header, see
1164  *	    :c:type:`rkisp1_ext_params_block_header`
1165  * @config: Black Level Subtraction configuration, see
1166  *	    :c:type:`rkisp1_cif_isp_bls_config`
1167  */
1168 struct rkisp1_ext_params_bls_config {
1169 	struct rkisp1_ext_params_block_header header;
1170 	struct rkisp1_cif_isp_bls_config config;
1171 } __attribute__((aligned(8)));
1172 
1173 /**
1174  * struct rkisp1_ext_params_dpcc_config - RkISP1 extensible params DPCC config
1175  *
1176  * RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
1177  * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.
1178  *
1179  * @header: The RkISP1 extensible parameters header, see
1180  *	    :c:type:`rkisp1_ext_params_block_header`
1181  * @config: Defective Pixel Cluster Correction configuration, see
1182  *	    :c:type:`rkisp1_cif_isp_dpcc_config`
1183  */
1184 struct rkisp1_ext_params_dpcc_config {
1185 	struct rkisp1_ext_params_block_header header;
1186 	struct rkisp1_cif_isp_dpcc_config config;
1187 } __attribute__((aligned(8)));
1188 
1189 /**
1190  * struct rkisp1_ext_params_sdg_config - RkISP1 extensible params SDG config
1191  *
1192  * RkISP1 extensible parameters Sensor Degamma configuration block. Identified
1193  * by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.
1194  *
1195  * @header: The RkISP1 extensible parameters header, see
1196  *	    :c:type:`rkisp1_ext_params_block_header`
1197  * @config: Sensor Degamma configuration, see
1198  *	    :c:type:`rkisp1_cif_isp_sdg_config`
1199  */
1200 struct rkisp1_ext_params_sdg_config {
1201 	struct rkisp1_ext_params_block_header header;
1202 	struct rkisp1_cif_isp_sdg_config config;
1203 } __attribute__((aligned(8)));
1204 
1205 /**
1206  * struct rkisp1_ext_params_lsc_config - RkISP1 extensible params LSC config
1207  *
1208  * RkISP1 extensible parameters Lens Shading Correction configuration block.
1209  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.
1210  *
1211  * @header: The RkISP1 extensible parameters header, see
1212  *	    :c:type:`rkisp1_ext_params_block_header`
1213  * @config: Lens Shading Correction configuration, see
1214  *	    :c:type:`rkisp1_cif_isp_lsc_config`
1215  */
1216 struct rkisp1_ext_params_lsc_config {
1217 	struct rkisp1_ext_params_block_header header;
1218 	struct rkisp1_cif_isp_lsc_config config;
1219 } __attribute__((aligned(8)));
1220 
1221 /**
1222  * struct rkisp1_ext_params_awb_gain_config - RkISP1 extensible params AWB
1223  *					      gain config
1224  *
1225  * RkISP1 extensible parameters Auto-White Balance Gains configuration block.
1226  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.
1227  *
1228  * @header: The RkISP1 extensible parameters header, see
1229  *	    :c:type:`rkisp1_ext_params_block_header`
1230  * @config: Auto-White Balance Gains configuration, see
1231  *	    :c:type:`rkisp1_cif_isp_awb_gain_config`
1232  */
1233 struct rkisp1_ext_params_awb_gain_config {
1234 	struct rkisp1_ext_params_block_header header;
1235 	struct rkisp1_cif_isp_awb_gain_config config;
1236 } __attribute__((aligned(8)));
1237 
1238 /**
1239  * struct rkisp1_ext_params_flt_config - RkISP1 extensible params FLT config
1240  *
1241  * RkISP1 extensible parameters Filter configuration block. Identified by
1242  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.
1243  *
1244  * @header: The RkISP1 extensible parameters header, see
1245  *	    :c:type:`rkisp1_ext_params_block_header`
1246  * @config: Filter configuration, see :c:type:`rkisp1_cif_isp_flt_config`
1247  */
1248 struct rkisp1_ext_params_flt_config {
1249 	struct rkisp1_ext_params_block_header header;
1250 	struct rkisp1_cif_isp_flt_config config;
1251 } __attribute__((aligned(8)));
1252 
1253 /**
1254  * struct rkisp1_ext_params_bdm_config - RkISP1 extensible params BDM config
1255  *
1256  * RkISP1 extensible parameters Demosaicing configuration block. Identified by
1257  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.
1258  *
1259  * @header: The RkISP1 extensible parameters header, see
1260  *	    :c:type:`rkisp1_ext_params_block_header`
1261  * @config: Demosaicing configuration, see :c:type:`rkisp1_cif_isp_bdm_config`
1262  */
1263 struct rkisp1_ext_params_bdm_config {
1264 	struct rkisp1_ext_params_block_header header;
1265 	struct rkisp1_cif_isp_bdm_config config;
1266 } __attribute__((aligned(8)));
1267 
1268 /**
1269  * struct rkisp1_ext_params_ctk_config - RkISP1 extensible params CTK config
1270  *
1271  * RkISP1 extensible parameters Cross-Talk configuration block. Identified by
1272  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.
1273  *
1274  * @header: The RkISP1 extensible parameters header, see
1275  *	    :c:type:`rkisp1_ext_params_block_header`
1276  * @config: Cross-Talk configuration, see :c:type:`rkisp1_cif_isp_ctk_config`
1277  */
1278 struct rkisp1_ext_params_ctk_config {
1279 	struct rkisp1_ext_params_block_header header;
1280 	struct rkisp1_cif_isp_ctk_config config;
1281 } __attribute__((aligned(8)));
1282 
1283 /**
1284  * struct rkisp1_ext_params_goc_config - RkISP1 extensible params GOC config
1285  *
1286  * RkISP1 extensible parameters Gamma-Out configuration block. Identified by
1287  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.
1288  *
1289  * @header: The RkISP1 extensible parameters header, see
1290  *	    :c:type:`rkisp1_ext_params_block_header`
1291  * @config: Gamma-Out configuration, see :c:type:`rkisp1_cif_isp_goc_config`
1292  */
1293 struct rkisp1_ext_params_goc_config {
1294 	struct rkisp1_ext_params_block_header header;
1295 	struct rkisp1_cif_isp_goc_config config;
1296 } __attribute__((aligned(8)));
1297 
1298 /**
1299  * struct rkisp1_ext_params_dpf_config - RkISP1 extensible params DPF config
1300  *
1301  * RkISP1 extensible parameters De-noise Pre-Filter configuration block.
1302  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.
1303  *
1304  * @header: The RkISP1 extensible parameters header, see
1305  *	    :c:type:`rkisp1_ext_params_block_header`
1306  * @config: De-noise Pre-Filter configuration, see
1307  *	    :c:type:`rkisp1_cif_isp_dpf_config`
1308  */
1309 struct rkisp1_ext_params_dpf_config {
1310 	struct rkisp1_ext_params_block_header header;
1311 	struct rkisp1_cif_isp_dpf_config config;
1312 } __attribute__((aligned(8)));
1313 
1314 /**
1315  * struct rkisp1_ext_params_dpf_strength_config - RkISP1 extensible params DPF
1316  *						  strength config
1317  *
1318  * RkISP1 extensible parameters De-noise Pre-Filter strength configuration
1319  * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.
1320  *
1321  * @header: The RkISP1 extensible parameters header, see
1322  *	    :c:type:`rkisp1_ext_params_block_header`
1323  * @config: De-noise Pre-Filter strength configuration, see
1324  *	    :c:type:`rkisp1_cif_isp_dpf_strength_config`
1325  */
1326 struct rkisp1_ext_params_dpf_strength_config {
1327 	struct rkisp1_ext_params_block_header header;
1328 	struct rkisp1_cif_isp_dpf_strength_config config;
1329 } __attribute__((aligned(8)));
1330 
1331 /**
1332  * struct rkisp1_ext_params_cproc_config - RkISP1 extensible params CPROC config
1333  *
1334  * RkISP1 extensible parameters Color Processing configuration block.
1335  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.
1336  *
1337  * @header: The RkISP1 extensible parameters header, see
1338  *	    :c:type:`rkisp1_ext_params_block_header`
1339  * @config: Color processing configuration, see
1340  *	    :c:type:`rkisp1_cif_isp_cproc_config`
1341  */
1342 struct rkisp1_ext_params_cproc_config {
1343 	struct rkisp1_ext_params_block_header header;
1344 	struct rkisp1_cif_isp_cproc_config config;
1345 } __attribute__((aligned(8)));
1346 
1347 /**
1348  * struct rkisp1_ext_params_ie_config - RkISP1 extensible params IE config
1349  *
1350  * RkISP1 extensible parameters Image Effect configuration block. Identified by
1351  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.
1352  *
1353  * @header: The RkISP1 extensible parameters header, see
1354  *	    :c:type:`rkisp1_ext_params_block_header`
1355  * @config: Image Effect configuration, see :c:type:`rkisp1_cif_isp_ie_config`
1356  */
1357 struct rkisp1_ext_params_ie_config {
1358 	struct rkisp1_ext_params_block_header header;
1359 	struct rkisp1_cif_isp_ie_config config;
1360 } __attribute__((aligned(8)));
1361 
1362 /**
1363  * struct rkisp1_ext_params_awb_meas_config - RkISP1 extensible params AWB
1364  *					      Meas config
1365  *
1366  * RkISP1 extensible parameters Auto-White Balance Measurement configuration
1367  * block. Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.
1368  *
1369  * @header: The RkISP1 extensible parameters header, see
1370  *	    :c:type:`rkisp1_ext_params_block_header`
1371  * @config: Auto-White Balance measure configuration, see
1372  *	    :c:type:`rkisp1_cif_isp_awb_meas_config`
1373  */
1374 struct rkisp1_ext_params_awb_meas_config {
1375 	struct rkisp1_ext_params_block_header header;
1376 	struct rkisp1_cif_isp_awb_meas_config config;
1377 } __attribute__((aligned(8)));
1378 
1379 /**
1380  * struct rkisp1_ext_params_hst_config - RkISP1 extensible params Histogram config
1381  *
1382  * RkISP1 extensible parameters Histogram statistics configuration block.
1383  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.
1384  *
1385  * @header: The RkISP1 extensible parameters header, see
1386  *	    :c:type:`rkisp1_ext_params_block_header`
1387  * @config: Histogram statistics configuration, see
1388  *	    :c:type:`rkisp1_cif_isp_hst_config`
1389  */
1390 struct rkisp1_ext_params_hst_config {
1391 	struct rkisp1_ext_params_block_header header;
1392 	struct rkisp1_cif_isp_hst_config config;
1393 } __attribute__((aligned(8)));
1394 
1395 /**
1396  * struct rkisp1_ext_params_aec_config - RkISP1 extensible params AEC config
1397  *
1398  * RkISP1 extensible parameters Auto-Exposure statistics configuration block.
1399  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.
1400  *
1401  * @header: The RkISP1 extensible parameters header, see
1402  *	    :c:type:`rkisp1_ext_params_block_header`
1403  * @config: Auto-Exposure statistics configuration, see
1404  *	    :c:type:`rkisp1_cif_isp_aec_config`
1405  */
1406 struct rkisp1_ext_params_aec_config {
1407 	struct rkisp1_ext_params_block_header header;
1408 	struct rkisp1_cif_isp_aec_config config;
1409 } __attribute__((aligned(8)));
1410 
1411 /**
1412  * struct rkisp1_ext_params_afc_config - RkISP1 extensible params AFC config
1413  *
1414  * RkISP1 extensible parameters Auto-Focus statistics configuration block.
1415  * Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.
1416  *
1417  * @header: The RkISP1 extensible parameters header, see
1418  *	    :c:type:`rkisp1_ext_params_block_header`
1419  * @config: Auto-Focus statistics configuration, see
1420  *	    :c:type:`rkisp1_cif_isp_afc_config`
1421  */
1422 struct rkisp1_ext_params_afc_config {
1423 	struct rkisp1_ext_params_block_header header;
1424 	struct rkisp1_cif_isp_afc_config config;
1425 } __attribute__((aligned(8)));
1426 
1427 /**
1428  * struct rkisp1_ext_params_compand_bls_config - RkISP1 extensible params
1429  * Compand BLS config
1430  *
1431  * RkISP1 extensible parameters Companding configuration block (black level
1432  * subtraction). Identified by :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS`.
1433  *
1434  * @header: The RkISP1 extensible parameters header, see
1435  *	    :c:type:`rkisp1_ext_params_block_header`
1436  * @config: Companding BLS configuration, see
1437  *	    :c:type:`rkisp1_cif_isp_compand_bls_config`
1438  */
1439 struct rkisp1_ext_params_compand_bls_config {
1440 	struct rkisp1_ext_params_block_header header;
1441 	struct rkisp1_cif_isp_compand_bls_config config;
1442 } __attribute__((aligned(8)));
1443 
1444 /**
1445  * struct rkisp1_ext_params_compand_curve_config - RkISP1 extensible params
1446  * Compand curve config
1447  *
1448  * RkISP1 extensible parameters Companding configuration block (expand and
1449  * compression curves). Identified by
1450  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND` or
1451  * :c:type:`RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS`.
1452  *
1453  * @header: The RkISP1 extensible parameters header, see
1454  *	    :c:type:`rkisp1_ext_params_block_header`
1455  * @config: Companding curve configuration, see
1456  *	    :c:type:`rkisp1_cif_isp_compand_curve_config`
1457  */
1458 struct rkisp1_ext_params_compand_curve_config {
1459 	struct rkisp1_ext_params_block_header header;
1460 	struct rkisp1_cif_isp_compand_curve_config config;
1461 } __attribute__((aligned(8)));
1462 
1463 /*
1464  * The rkisp1_ext_params_compand_curve_config structure is counted twice as it
1465  * is used for both the COMPAND_EXPAND and COMPAND_COMPRESS block types.
1466  */
1467 #define RKISP1_EXT_PARAMS_MAX_SIZE					\
1468 	(sizeof(struct rkisp1_ext_params_bls_config)			+\
1469 	sizeof(struct rkisp1_ext_params_dpcc_config)			+\
1470 	sizeof(struct rkisp1_ext_params_sdg_config)			+\
1471 	sizeof(struct rkisp1_ext_params_lsc_config)			+\
1472 	sizeof(struct rkisp1_ext_params_awb_gain_config)		+\
1473 	sizeof(struct rkisp1_ext_params_flt_config)			+\
1474 	sizeof(struct rkisp1_ext_params_bdm_config)			+\
1475 	sizeof(struct rkisp1_ext_params_ctk_config)			+\
1476 	sizeof(struct rkisp1_ext_params_goc_config)			+\
1477 	sizeof(struct rkisp1_ext_params_dpf_config)			+\
1478 	sizeof(struct rkisp1_ext_params_dpf_strength_config)		+\
1479 	sizeof(struct rkisp1_ext_params_cproc_config)			+\
1480 	sizeof(struct rkisp1_ext_params_ie_config)			+\
1481 	sizeof(struct rkisp1_ext_params_awb_meas_config)		+\
1482 	sizeof(struct rkisp1_ext_params_hst_config)			+\
1483 	sizeof(struct rkisp1_ext_params_aec_config)			+\
1484 	sizeof(struct rkisp1_ext_params_afc_config)			+\
1485 	sizeof(struct rkisp1_ext_params_compand_bls_config)		+\
1486 	sizeof(struct rkisp1_ext_params_compand_curve_config)		+\
1487 	sizeof(struct rkisp1_ext_params_compand_curve_config))
1488 
1489 /**
1490  * enum rksip1_ext_param_buffer_version - RkISP1 extensible parameters version
1491  *
1492  * @RKISP1_EXT_PARAM_BUFFER_V1: First version of RkISP1 extensible parameters
1493  */
1494 enum rksip1_ext_param_buffer_version {
1495 	RKISP1_EXT_PARAM_BUFFER_V1 = 1,
1496 };
1497 
1498 /**
1499  * struct rkisp1_ext_params_cfg - RkISP1 extensible parameters configuration
1500  *
1501  * This struct contains the configuration parameters of the RkISP1 ISP
1502  * algorithms, serialized by userspace into a data buffer. Each configuration
1503  * parameter block is represented by a block-specific structure which contains a
1504  * :c:type:`rkisp1_ext_params_block_header` entry as first member. Userspace
1505  * populates the @data buffer with configuration parameters for the blocks that
1506  * it intends to configure. As a consequence, the data buffer effective size
1507  * changes according to the number of ISP blocks that userspace intends to
1508  * configure and is set by userspace in the @data_size field.
1509  *
1510  * The parameters buffer is versioned by the @version field to allow modifying
1511  * and extending its definition. Userspace shall populate the @version field to
1512  * inform the driver about the version it intends to use. The driver will parse
1513  * and handle the @data buffer according to the data layout specific to the
1514  * indicated version and return an error if the desired version is not
1515  * supported.
1516  *
1517  * Currently the single RKISP1_EXT_PARAM_BUFFER_V1 version is supported.
1518  * When a new format version will be added, a mechanism for userspace to query
1519  * the supported format versions will be implemented in the form of a read-only
1520  * V4L2 control. If such control is not available, userspace should assume only
1521  * RKISP1_EXT_PARAM_BUFFER_V1 is supported by the driver.
1522  *
1523  * For each ISP block that userspace wants to configure, a block-specific
1524  * structure is appended to the @data buffer, one after the other without gaps
1525  * in between nor overlaps. Userspace shall populate the @data_size field with
1526  * the effective size, in bytes, of the @data buffer.
1527  *
1528  * The expected memory layout of the parameters buffer is::
1529  *
1530  *	+-------------------- struct rkisp1_ext_params_cfg -------------------+
1531  *	| version = RKISP_EXT_PARAMS_BUFFER_V1;                               |
1532  *	| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
1533  *	|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
1534  *	| +------------------------- data  ---------------------------------+ |
1535  *	| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
1536  *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
1537  *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
1538  *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
1539  *	| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
1540  *	| | | +---------------------------------------------------------+ | | |
1541  *	| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
1542  *	| | | | enable_auto = 0;                                        | | | |
1543  *	| | | | fixed_val.r = 256;                                      | | | |
1544  *	| | | | fixed_val.gr = 256;                                     | | | |
1545  *	| | | | fixed_val.gb = 256;                                     | | | |
1546  *	| | | | fixed_val.b = 256;                                      | | | |
1547  *	| | | +---------------------------------------------------------+ | | |
1548  *	| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
1549  *	| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
1550  *	| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
1551  *	| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
1552  *	| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
1553  *	| | | +---------------------------------------------------------+ | | |
1554  *	| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
1555  *	| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
1556  *	| | | | output_mode =                                           | | | |
1557  *	| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
1558  *	| | | | set_use = ... ;                                         | | | |
1559  *	| | | | ...  = ... ;                                            | | | |
1560  *	| | | +---------------------------------------------------------+ | | |
1561  *	| | +-------------------------------------------------------------+ | |
1562  *	| +-----------------------------------------------------------------+ |
1563  *	+---------------------------------------------------------------------+
1564  *
1565  * @version: The RkISP1 extensible parameters buffer version, see
1566  *	     :c:type:`rksip1_ext_param_buffer_version`
1567  * @data_size: The RkISP1 configuration data effective size, excluding this
1568  *	       header
1569  * @data: The RkISP1 extensible configuration data blocks
1570  */
1571 struct rkisp1_ext_params_cfg {
1572 	__u32 version;
1573 	__u32 data_size;
1574 	__u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
1575 };
1576 
1577 #endif /* _UAPI_RKISP1_CONFIG_H */
1578