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 /*
123  * Denoising pre filter
124  */
125 #define RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS      17
126 #define RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS  6
127 
128 /*
129  * Measurement types
130  */
131 #define RKISP1_CIF_ISP_STAT_AWB           (1U << 0)
132 #define RKISP1_CIF_ISP_STAT_AUTOEXP       (1U << 1)
133 #define RKISP1_CIF_ISP_STAT_AFM           (1U << 2)
134 #define RKISP1_CIF_ISP_STAT_HIST          (1U << 3)
135 
136 /**
137  * enum rkisp1_cif_isp_version - ISP variants
138  *
139  * @RKISP1_V10: used at least in rk3288 and rk3399
140  * @RKISP1_V11: declared in the original vendor code, but not used
141  * @RKISP1_V12: used at least in rk3326 and px30
142  * @RKISP1_V13: used at least in rk1808
143  */
144 enum rkisp1_cif_isp_version {
145 	RKISP1_V10 = 10,
146 	RKISP1_V11,
147 	RKISP1_V12,
148 	RKISP1_V13,
149 };
150 
151 enum rkisp1_cif_isp_histogram_mode {
152 	RKISP1_CIF_ISP_HISTOGRAM_MODE_DISABLE,
153 	RKISP1_CIF_ISP_HISTOGRAM_MODE_RGB_COMBINED,
154 	RKISP1_CIF_ISP_HISTOGRAM_MODE_R_HISTOGRAM,
155 	RKISP1_CIF_ISP_HISTOGRAM_MODE_G_HISTOGRAM,
156 	RKISP1_CIF_ISP_HISTOGRAM_MODE_B_HISTOGRAM,
157 	RKISP1_CIF_ISP_HISTOGRAM_MODE_Y_HISTOGRAM
158 };
159 
160 enum rkisp1_cif_isp_awb_mode_type {
161 	RKISP1_CIF_ISP_AWB_MODE_MANUAL,
162 	RKISP1_CIF_ISP_AWB_MODE_RGB,
163 	RKISP1_CIF_ISP_AWB_MODE_YCBCR
164 };
165 
166 enum rkisp1_cif_isp_flt_mode {
167 	RKISP1_CIF_ISP_FLT_STATIC_MODE,
168 	RKISP1_CIF_ISP_FLT_DYNAMIC_MODE
169 };
170 
171 /**
172  * enum rkisp1_cif_isp_exp_ctrl_autostop - stop modes
173  * @RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_0: continuous measurement
174  * @RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_1: stop measuring after a complete frame
175  */
176 enum rkisp1_cif_isp_exp_ctrl_autostop {
177 	RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_0 = 0,
178 	RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_1 = 1,
179 };
180 
181 /**
182  * enum rkisp1_cif_isp_exp_meas_mode - Exposure measure mode
183  * @RKISP1_CIF_ISP_EXP_MEASURING_MODE_0: Y = 16 + 0.25R + 0.5G + 0.1094B
184  * @RKISP1_CIF_ISP_EXP_MEASURING_MODE_1: Y = (R + G + B) x (85/256)
185  */
186 enum rkisp1_cif_isp_exp_meas_mode {
187 	RKISP1_CIF_ISP_EXP_MEASURING_MODE_0,
188 	RKISP1_CIF_ISP_EXP_MEASURING_MODE_1,
189 };
190 
191 /*---------- PART1: Input Parameters ------------*/
192 
193 /**
194  * struct rkisp1_cif_isp_window -  measurement window.
195  *
196  * Measurements are calculated per window inside the frame.
197  * This struct represents a window for a measurement.
198  *
199  * @h_offs: the horizontal offset of the window from the left of the frame in pixels.
200  * @v_offs: the vertical offset of the window from the top of the frame in pixels.
201  * @h_size: the horizontal size of the window in pixels
202  * @v_size: the vertical size of the window in pixels.
203  */
204 struct rkisp1_cif_isp_window {
205 	__u16 h_offs;
206 	__u16 v_offs;
207 	__u16 h_size;
208 	__u16 v_size;
209 };
210 
211 /**
212  * struct rkisp1_cif_isp_bls_fixed_val - BLS fixed subtraction values
213  *
214  * The values will be subtracted from the sensor
215  * values. Therefore a negative value means addition instead of subtraction!
216  *
217  * @r: Fixed (signed!) subtraction value for Bayer pattern R
218  * @gr: Fixed (signed!) subtraction value for Bayer pattern Gr
219  * @gb: Fixed (signed!) subtraction value for Bayer pattern Gb
220  * @b: Fixed (signed!) subtraction value for Bayer pattern B
221  */
222 struct rkisp1_cif_isp_bls_fixed_val {
223 	__s16 r;
224 	__s16 gr;
225 	__s16 gb;
226 	__s16 b;
227 };
228 
229 /**
230  * struct rkisp1_cif_isp_bls_config - Configuration used by black level subtraction
231  *
232  * @enable_auto: Automatic mode activated means that the measured values
233  *		 are subtracted. Otherwise the fixed subtraction
234  *		 values will be subtracted.
235  * @en_windows: enabled window
236  * @bls_window1: Measurement window 1 size
237  * @bls_window2: Measurement window 2 size
238  * @bls_samples: Set amount of measured pixels for each Bayer position
239  *		 (A, B,C and D) to 2^bls_samples.
240  * @fixed_val: Fixed subtraction values
241  */
242 struct rkisp1_cif_isp_bls_config {
243 	__u8 enable_auto;
244 	__u8 en_windows;
245 	struct rkisp1_cif_isp_window bls_window1;
246 	struct rkisp1_cif_isp_window bls_window2;
247 	__u8 bls_samples;
248 	struct rkisp1_cif_isp_bls_fixed_val fixed_val;
249 };
250 
251 /**
252  * struct rkisp1_cif_isp_dpcc_methods_config - Methods Configuration used by DPCC
253  *
254  * Methods Configuration used by Defect Pixel Cluster Correction
255  *
256  * @method: Method enable bits
257  * @line_thresh: Line threshold
258  * @line_mad_fac: Line MAD factor
259  * @pg_fac: Peak gradient factor
260  * @rnd_thresh: Rank Neighbor Difference threshold
261  * @rg_fac: Rank gradient factor
262  */
263 struct rkisp1_cif_isp_dpcc_methods_config {
264 	__u32 method;
265 	__u32 line_thresh;
266 	__u32 line_mad_fac;
267 	__u32 pg_fac;
268 	__u32 rnd_thresh;
269 	__u32 rg_fac;
270 };
271 
272 /**
273  * struct rkisp1_cif_isp_dpcc_config - Configuration used by DPCC
274  *
275  * Configuration used by Defect Pixel Cluster Correction
276  *
277  * @mode: dpcc output mode
278  * @output_mode: whether use hard coded methods
279  * @set_use: stage1 methods set
280  * @methods: methods config
281  * @ro_limits: rank order limits
282  * @rnd_offs: differential rank offsets for rank neighbor difference
283  */
284 struct rkisp1_cif_isp_dpcc_config {
285 	__u32 mode;
286 	__u32 output_mode;
287 	__u32 set_use;
288 	struct rkisp1_cif_isp_dpcc_methods_config methods[RKISP1_CIF_ISP_DPCC_METHODS_MAX];
289 	__u32 ro_limits;
290 	__u32 rnd_offs;
291 };
292 
293 /**
294  * struct rkisp1_cif_isp_gamma_corr_curve - gamma curve point definition y-axis (output).
295  *
296  * The reset values define a linear curve which has the same effect as bypass. Reset values are:
297  * gamma_y[0] = 0x0000, gamma_y[1] = 0x0100, ... gamma_y[15] = 0x0f00, gamma_y[16] = 0xfff
298  *
299  * @gamma_y: the values for the y-axis of gamma curve points. Each value is 12 bit.
300  */
301 struct rkisp1_cif_isp_gamma_corr_curve {
302 	__u16 gamma_y[RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE];
303 };
304 
305 /**
306  * struct rkisp1_cif_isp_gamma_curve_x_axis_pnts - De-Gamma Curve definition x increments
307  *		(sampling points). gamma_dx0 is for the lower samples (1-8), gamma_dx1 is for the
308  *		higher samples (9-16). The reset values for both fields is 0x44444444. This means
309  *		that each sample is 4 units away from the previous one on the x-axis.
310  *
311  * @gamma_dx0: gamma curve sample points definitions. Bits 0:2 for sample 1. Bit 3 unused.
312  *		Bits 4:6 for sample 2. bit 7 unused ... Bits 28:30 for sample 8. Bit 31 unused
313  * @gamma_dx1: gamma curve sample points definitions. Bits 0:2 for sample 9. Bit 3 unused.
314  *		Bits 4:6 for sample 10. bit 7 unused ... Bits 28:30 for sample 16. Bit 31 unused
315  */
316 struct rkisp1_cif_isp_gamma_curve_x_axis_pnts {
317 	__u32 gamma_dx0;
318 	__u32 gamma_dx1;
319 };
320 
321 /**
322  * struct rkisp1_cif_isp_sdg_config - Configuration used by sensor degamma
323  *
324  * @curve_r: gamma curve point definition axis for red
325  * @curve_g: gamma curve point definition axis for green
326  * @curve_b: gamma curve point definition axis for blue
327  * @xa_pnts: x axis increments
328  */
329 struct rkisp1_cif_isp_sdg_config {
330 	struct rkisp1_cif_isp_gamma_corr_curve curve_r;
331 	struct rkisp1_cif_isp_gamma_corr_curve curve_g;
332 	struct rkisp1_cif_isp_gamma_corr_curve curve_b;
333 	struct rkisp1_cif_isp_gamma_curve_x_axis_pnts xa_pnts;
334 };
335 
336 /**
337  * struct rkisp1_cif_isp_lsc_config - Configuration used by Lens shading correction
338  *
339  * @r_data_tbl: sample table red
340  * @gr_data_tbl: sample table green (red)
341  * @gb_data_tbl: sample table green (blue)
342  * @b_data_tbl: sample table blue
343  * @x_grad_tbl: gradient table x
344  * @y_grad_tbl: gradient table y
345  * @x_size_tbl: size table x
346  * @y_size_tbl: size table y
347  * @config_width: not used at the moment
348  * @config_height: not used at the moment
349  */
350 struct rkisp1_cif_isp_lsc_config {
351 	__u16 r_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
352 	__u16 gr_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
353 	__u16 gb_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
354 	__u16 b_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
355 
356 	__u16 x_grad_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
357 	__u16 y_grad_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
358 
359 	__u16 x_size_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
360 	__u16 y_size_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
361 	__u16 config_width;
362 	__u16 config_height;
363 };
364 
365 /**
366  * struct rkisp1_cif_isp_ie_config - Configuration used by image effects
367  *
368  * @effect: values from 'enum v4l2_colorfx'. Possible values are: V4L2_COLORFX_SEPIA,
369  *		V4L2_COLORFX_SET_CBCR, V4L2_COLORFX_AQUA, V4L2_COLORFX_EMBOSS,
370  *		V4L2_COLORFX_SKETCH,   V4L2_COLORFX_BW,   V4L2_COLORFX_NEGATIVE
371  * @color_sel: bits 0:2 - colors bitmask (001 - blue, 010 - green, 100 - red).
372  *		bits 8:15 - Threshold value of the RGB colors for the color selection effect.
373  * @eff_mat_1: 3x3 Matrix Coefficients for Emboss Effect 1
374  * @eff_mat_2: 3x3 Matrix Coefficients for Emboss Effect 2
375  * @eff_mat_3: 3x3 Matrix Coefficients for Emboss 3/Sketch 1
376  * @eff_mat_4: 3x3 Matrix Coefficients for Sketch Effect 2
377  * @eff_mat_5: 3x3 Matrix Coefficients for Sketch Effect 3
378  * @eff_tint: Chrominance increment values of tint (used for sepia effect)
379  */
380 struct rkisp1_cif_isp_ie_config {
381 	__u16 effect;
382 	__u16 color_sel;
383 	__u16 eff_mat_1;
384 	__u16 eff_mat_2;
385 	__u16 eff_mat_3;
386 	__u16 eff_mat_4;
387 	__u16 eff_mat_5;
388 	__u16 eff_tint;
389 };
390 
391 /**
392  * struct rkisp1_cif_isp_cproc_config - Configuration used by Color Processing
393  *
394  * @c_out_range: Chrominance pixel clipping range at output.
395  *		 (0 for limit, 1 for full)
396  * @y_in_range: Luminance pixel clipping range at output.
397  * @y_out_range: Luminance pixel clipping range at output.
398  * @contrast: 00~ff, 0.0~1.992
399  * @brightness: 80~7F, -128~+127
400  * @sat: saturation, 00~FF, 0.0~1.992
401  * @hue: 80~7F, -90~+87.188
402  */
403 struct rkisp1_cif_isp_cproc_config {
404 	__u8 c_out_range;
405 	__u8 y_in_range;
406 	__u8 y_out_range;
407 	__u8 contrast;
408 	__u8 brightness;
409 	__u8 sat;
410 	__u8 hue;
411 };
412 
413 /**
414  * struct rkisp1_cif_isp_awb_meas_config - Configuration for the AWB statistics
415  *
416  * @awb_mode: the awb meas mode. From enum rkisp1_cif_isp_awb_mode_type.
417  * @awb_wnd: white balance measurement window (in pixels)
418  * @max_y: only pixels values < max_y contribute to awb measurement, set to 0
419  *	   to disable this feature
420  * @min_y: only pixels values > min_y contribute to awb measurement
421  * @max_csum: Chrominance sum maximum value, only consider pixels with Cb+Cr,
422  *	      smaller than threshold for awb measurements
423  * @min_c: Chrominance minimum value, only consider pixels with Cb/Cr
424  *	   each greater than threshold value for awb measurements
425  * @frames: number of frames - 1 used for mean value calculation
426  *	    (ucFrames=0 means 1 Frame)
427  * @awb_ref_cr: reference Cr value for AWB regulation, target for AWB
428  * @awb_ref_cb: reference Cb value for AWB regulation, target for AWB
429  * @enable_ymax_cmp: enable Y_MAX compare (Not valid in RGB measurement mode.)
430  */
431 struct rkisp1_cif_isp_awb_meas_config {
432 	/*
433 	 * Note: currently the h and v offsets are mapped to grid offsets
434 	 */
435 	struct rkisp1_cif_isp_window awb_wnd;
436 	__u32 awb_mode;
437 	__u8 max_y;
438 	__u8 min_y;
439 	__u8 max_csum;
440 	__u8 min_c;
441 	__u8 frames;
442 	__u8 awb_ref_cr;
443 	__u8 awb_ref_cb;
444 	__u8 enable_ymax_cmp;
445 };
446 
447 /**
448  * struct rkisp1_cif_isp_awb_gain_config - Configuration used by auto white balance gain
449  *
450  * All fields in this struct are 10 bit, where:
451  * 0x100h = 1, unsigned integer value, range 0 to 4 with 8 bit fractional part.
452  *
453  * out_data_x = ( AWB_GAIN_X * in_data + 128) >> 8
454  *
455  * @gain_red: gain value for red component.
456  * @gain_green_r: gain value for green component in red line.
457  * @gain_blue: gain value for blue component.
458  * @gain_green_b: gain value for green component in blue line.
459  */
460 struct rkisp1_cif_isp_awb_gain_config {
461 	__u16 gain_red;
462 	__u16 gain_green_r;
463 	__u16 gain_blue;
464 	__u16 gain_green_b;
465 };
466 
467 /**
468  * struct rkisp1_cif_isp_flt_config - Configuration used by ISP filtering
469  *
470  * All 4 threshold fields (thresh_*) are 10 bits.
471  * All 6 factor fields (fac_*) are 6 bits.
472  *
473  * @mode: ISP_FILT_MODE register fields (from enum rkisp1_cif_isp_flt_mode)
474  * @grn_stage1: Green filter stage 1 select (range 0x0...0x8)
475  * @chr_h_mode: Chroma filter horizontal mode
476  * @chr_v_mode: Chroma filter vertical mode
477  * @thresh_bl0: If thresh_bl1 < sum_grad < thresh_bl0 then fac_bl0 is selected (blurring th)
478  * @thresh_bl1: If sum_grad < thresh_bl1 then fac_bl1 is selected (blurring th)
479  * @thresh_sh0: If thresh_sh0 < sum_grad < thresh_sh1 then thresh_sh0 is selected (sharpening th)
480  * @thresh_sh1: If thresh_sh1 < sum_grad then thresh_sh1 is selected (sharpening th)
481  * @lum_weight: Parameters for luminance weight function.
482  * @fac_sh1: filter factor for sharp1 level
483  * @fac_sh0: filter factor for sharp0 level
484  * @fac_mid: filter factor for mid level and for static filter mode
485  * @fac_bl0: filter factor for blur 0 level
486  * @fac_bl1: filter factor for blur 1 level (max blur)
487  */
488 struct rkisp1_cif_isp_flt_config {
489 	__u32 mode;
490 	__u8 grn_stage1;
491 	__u8 chr_h_mode;
492 	__u8 chr_v_mode;
493 	__u32 thresh_bl0;
494 	__u32 thresh_bl1;
495 	__u32 thresh_sh0;
496 	__u32 thresh_sh1;
497 	__u32 lum_weight;
498 	__u32 fac_sh1;
499 	__u32 fac_sh0;
500 	__u32 fac_mid;
501 	__u32 fac_bl0;
502 	__u32 fac_bl1;
503 };
504 
505 /**
506  * struct rkisp1_cif_isp_bdm_config - Configuration used by Bayer DeMosaic
507  *
508  * @demosaic_th: threshold for bayer demosaicing texture detection
509  */
510 struct rkisp1_cif_isp_bdm_config {
511 	__u8 demosaic_th;
512 };
513 
514 /**
515  * struct rkisp1_cif_isp_ctk_config - Configuration used by Cross Talk correction
516  *
517  * @coeff: color correction matrix. Values are 11-bit signed fixed-point numbers with 4 bit integer
518  *		and 7 bit fractional part, ranging from -8 (0x400) to +7.992 (0x3FF). 0 is
519  *		represented by 0x000 and a coefficient value of 1 as 0x080.
520  * @ct_offset: Red, Green, Blue offsets for the crosstalk correction matrix
521  */
522 struct rkisp1_cif_isp_ctk_config {
523 	__u16 coeff[3][3];
524 	__u16 ct_offset[3];
525 };
526 
527 enum rkisp1_cif_isp_goc_mode {
528 	RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC,
529 	RKISP1_CIF_ISP_GOC_MODE_EQUIDISTANT
530 };
531 
532 /**
533  * struct rkisp1_cif_isp_goc_config - Configuration used by Gamma Out correction
534  *
535  * @mode: goc mode (from enum rkisp1_cif_isp_goc_mode)
536  * @gamma_y: gamma out curve y-axis for all color components
537  *
538  * The number of entries of @gamma_y depends on the hardware revision
539  * as is reported by the hw_revision field of the struct media_device_info
540  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
541  *
542  * Versions <= V11 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10
543  * entries, versions >= V12 have RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12
544  * entries. RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum
545  * of the two.
546  */
547 struct rkisp1_cif_isp_goc_config {
548 	__u32 mode;
549 	__u16 gamma_y[RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES];
550 };
551 
552 /**
553  * struct rkisp1_cif_isp_hst_config - Configuration for Histogram statistics
554  *
555  * @mode: histogram mode (from enum rkisp1_cif_isp_histogram_mode)
556  * @histogram_predivider: process every stepsize pixel, all other pixels are
557  *			  skipped
558  * @meas_window: coordinates of the measure window
559  * @hist_weight: weighting factor for sub-windows
560  *
561  * The number of entries of @hist_weight depends on the hardware revision
562  * as is reported by the hw_revision field of the struct media_device_info
563  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
564  *
565  * Versions <= V11 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10
566  * entries, versions >= V12 have RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12
567  * entries. RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum
568  * of the two.
569  */
570 struct rkisp1_cif_isp_hst_config {
571 	__u32 mode;
572 	__u8 histogram_predivider;
573 	struct rkisp1_cif_isp_window meas_window;
574 	__u8 hist_weight[RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE];
575 };
576 
577 /**
578  * struct rkisp1_cif_isp_aec_config - Configuration for Auto Exposure statistics
579  *
580  * @mode: Exposure measure mode (from enum rkisp1_cif_isp_exp_meas_mode)
581  * @autostop: stop mode (from enum rkisp1_cif_isp_exp_ctrl_autostop)
582  * @meas_window: coordinates of the measure window
583  */
584 struct rkisp1_cif_isp_aec_config {
585 	__u32 mode;
586 	__u32 autostop;
587 	struct rkisp1_cif_isp_window meas_window;
588 };
589 
590 /**
591  * struct rkisp1_cif_isp_afc_config - Configuration for the Auto Focus statistics
592  *
593  * @num_afm_win: max RKISP1_CIF_ISP_AFM_MAX_WINDOWS
594  * @afm_win: coordinates of the meas window
595  * @thres: threshold used for minimizing the influence of noise
596  * @var_shift: the number of bits for the shift operation at the end of the
597  *	       calculation chain.
598  */
599 struct rkisp1_cif_isp_afc_config {
600 	__u8 num_afm_win;
601 	struct rkisp1_cif_isp_window afm_win[RKISP1_CIF_ISP_AFM_MAX_WINDOWS];
602 	__u32 thres;
603 	__u32 var_shift;
604 };
605 
606 /**
607  * enum rkisp1_cif_isp_dpf_gain_usage - dpf gain usage
608  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED: don't use any gains in preprocessing stage
609  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS: use only the noise function gains from
610  *				    registers DPF_NF_GAIN_R, ...
611  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS:  use only the gains from LSC module
612  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS: use the noise function gains and the
613  *					gains from LSC module
614  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS: use only the gains from AWB module
615  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS: use the gains from AWB and LSC module
616  * @RKISP1_CIF_ISP_DPF_GAIN_USAGE_MAX: upper border (only for an internal evaluation)
617  */
618 enum rkisp1_cif_isp_dpf_gain_usage {
619 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED,
620 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS,
621 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS,
622 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS,
623 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS,
624 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS,
625 	RKISP1_CIF_ISP_DPF_GAIN_USAGE_MAX
626 };
627 
628 /**
629  * enum rkisp1_cif_isp_dpf_rb_filtersize - Red and blue filter sizes
630  * @RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9: red and blue filter kernel size 13x9
631  *				   (means 7x5 active pixel)
632  * @RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9: red and blue filter kernel size 9x9
633  *				   (means 5x5 active pixel)
634  */
635 enum rkisp1_cif_isp_dpf_rb_filtersize {
636 	RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9,
637 	RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9,
638 };
639 
640 /**
641  * enum rkisp1_cif_isp_dpf_nll_scale_mode - dpf noise level scale mode
642  * @RKISP1_CIF_ISP_NLL_SCALE_LINEAR: use a linear scaling
643  * @RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC: use a logarithmic scaling
644  */
645 enum rkisp1_cif_isp_dpf_nll_scale_mode {
646 	RKISP1_CIF_ISP_NLL_SCALE_LINEAR,
647 	RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC,
648 };
649 
650 /**
651  * struct rkisp1_cif_isp_dpf_nll - Noise level lookup
652  *
653  * @coeff: Noise level Lookup coefficient
654  * @scale_mode: dpf noise level scale mode (from enum rkisp1_cif_isp_dpf_nll_scale_mode)
655  */
656 struct rkisp1_cif_isp_dpf_nll {
657 	__u16 coeff[RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS];
658 	__u32 scale_mode;
659 };
660 
661 /**
662  * struct rkisp1_cif_isp_dpf_rb_flt - Red blue filter config
663  *
664  * @fltsize: The filter size for the red and blue pixels
665  *	     (from enum rkisp1_cif_isp_dpf_rb_filtersize)
666  * @spatial_coeff: Spatial weights
667  * @r_enable: enable filter processing for red pixels
668  * @b_enable: enable filter processing for blue pixels
669  */
670 struct rkisp1_cif_isp_dpf_rb_flt {
671 	__u32 fltsize;
672 	__u8 spatial_coeff[RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS];
673 	__u8 r_enable;
674 	__u8 b_enable;
675 };
676 
677 /**
678  * struct rkisp1_cif_isp_dpf_g_flt - Green filter Configuration
679  *
680  * @spatial_coeff: Spatial weights
681  * @gr_enable: enable filter processing for green pixels in green/red lines
682  * @gb_enable: enable filter processing for green pixels in green/blue lines
683  */
684 struct rkisp1_cif_isp_dpf_g_flt {
685 	__u8 spatial_coeff[RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS];
686 	__u8 gr_enable;
687 	__u8 gb_enable;
688 };
689 
690 /**
691  * struct rkisp1_cif_isp_dpf_gain - Noise function Configuration
692  *
693  * @mode: dpf gain usage  (from enum rkisp1_cif_isp_dpf_gain_usage)
694  * @nf_r_gain: Noise function Gain that replaces the AWB gain for red pixels
695  * @nf_b_gain: Noise function Gain that replaces the AWB gain for blue pixels
696  * @nf_gr_gain: Noise function Gain that replaces the AWB gain
697  *		for green pixels in a red line
698  * @nf_gb_gain: Noise function Gain that replaces the AWB gain
699  *		for green pixels in a blue line
700  */
701 struct rkisp1_cif_isp_dpf_gain {
702 	__u32 mode;
703 	__u16 nf_r_gain;
704 	__u16 nf_b_gain;
705 	__u16 nf_gr_gain;
706 	__u16 nf_gb_gain;
707 };
708 
709 /**
710  * struct rkisp1_cif_isp_dpf_config - Configuration used by De-noising pre-filter
711  *
712  * @gain: noise function gain
713  * @g_flt: green filter config
714  * @rb_flt: red blue filter config
715  * @nll: noise level lookup
716  */
717 struct rkisp1_cif_isp_dpf_config {
718 	struct rkisp1_cif_isp_dpf_gain gain;
719 	struct rkisp1_cif_isp_dpf_g_flt g_flt;
720 	struct rkisp1_cif_isp_dpf_rb_flt rb_flt;
721 	struct rkisp1_cif_isp_dpf_nll nll;
722 };
723 
724 /**
725  * struct rkisp1_cif_isp_dpf_strength_config - strength of the filter
726  *
727  * @r: filter strength of the RED filter
728  * @g: filter strength of the GREEN filter
729  * @b: filter strength of the BLUE filter
730  */
731 struct rkisp1_cif_isp_dpf_strength_config {
732 	__u8 r;
733 	__u8 g;
734 	__u8 b;
735 };
736 
737 /**
738  * struct rkisp1_cif_isp_isp_other_cfg - Parameters for some blocks in rockchip isp1
739  *
740  * @dpcc_config: Defect Pixel Cluster Correction config
741  * @bls_config: Black Level Subtraction config
742  * @sdg_config: sensor degamma config
743  * @lsc_config: Lens Shade config
744  * @awb_gain_config: Auto White balance gain config
745  * @flt_config: filter config
746  * @bdm_config: demosaic config
747  * @ctk_config: cross talk config
748  * @goc_config: gamma out config
749  * @bls_config: black level subtraction config
750  * @dpf_config: De-noising pre-filter config
751  * @dpf_strength_config: dpf strength config
752  * @cproc_config: color process config
753  * @ie_config: image effects config
754  */
755 struct rkisp1_cif_isp_isp_other_cfg {
756 	struct rkisp1_cif_isp_dpcc_config dpcc_config;
757 	struct rkisp1_cif_isp_bls_config bls_config;
758 	struct rkisp1_cif_isp_sdg_config sdg_config;
759 	struct rkisp1_cif_isp_lsc_config lsc_config;
760 	struct rkisp1_cif_isp_awb_gain_config awb_gain_config;
761 	struct rkisp1_cif_isp_flt_config flt_config;
762 	struct rkisp1_cif_isp_bdm_config bdm_config;
763 	struct rkisp1_cif_isp_ctk_config ctk_config;
764 	struct rkisp1_cif_isp_goc_config goc_config;
765 	struct rkisp1_cif_isp_dpf_config dpf_config;
766 	struct rkisp1_cif_isp_dpf_strength_config dpf_strength_config;
767 	struct rkisp1_cif_isp_cproc_config cproc_config;
768 	struct rkisp1_cif_isp_ie_config ie_config;
769 };
770 
771 /**
772  * struct rkisp1_cif_isp_isp_meas_cfg - Rockchip ISP1 Measure Parameters
773  *
774  * @awb_meas_config: auto white balance config
775  * @hst_config: histogram config
776  * @aec_config: auto exposure config
777  * @afc_config: auto focus config
778  */
779 struct rkisp1_cif_isp_isp_meas_cfg {
780 	struct rkisp1_cif_isp_awb_meas_config awb_meas_config;
781 	struct rkisp1_cif_isp_hst_config hst_config;
782 	struct rkisp1_cif_isp_aec_config aec_config;
783 	struct rkisp1_cif_isp_afc_config afc_config;
784 };
785 
786 /**
787  * struct rkisp1_params_cfg - Rockchip ISP1 Input Parameters Meta Data
788  *
789  * @module_en_update: mask the enable bits of which module should be updated
790  * @module_ens: mask the enable value of each module, only update the module
791  *		which correspond bit was set in module_en_update
792  * @module_cfg_update: mask the config bits of which module should be updated
793  * @meas: measurement config
794  * @others: other config
795  */
796 struct rkisp1_params_cfg {
797 	__u32 module_en_update;
798 	__u32 module_ens;
799 	__u32 module_cfg_update;
800 
801 	struct rkisp1_cif_isp_isp_meas_cfg meas;
802 	struct rkisp1_cif_isp_isp_other_cfg others;
803 };
804 
805 /*---------- PART2: Measurement Statistics ------------*/
806 
807 /**
808  * struct rkisp1_cif_isp_awb_meas - AWB measured values
809  *
810  * @cnt: White pixel count, number of "white pixels" found during last
811  *	 measurement
812  * @mean_y_or_g: Mean value of Y within window and frames,
813  *		 Green if RGB is selected.
814  * @mean_cb_or_b: Mean value of Cb within window and frames,
815  *		  Blue if RGB is selected.
816  * @mean_cr_or_r: Mean value of Cr within window and frames,
817  *		  Red if RGB is selected.
818  */
819 struct rkisp1_cif_isp_awb_meas {
820 	__u32 cnt;
821 	__u8 mean_y_or_g;
822 	__u8 mean_cb_or_b;
823 	__u8 mean_cr_or_r;
824 };
825 
826 /**
827  * struct rkisp1_cif_isp_awb_stat - statistics automatic white balance data
828  *
829  * @awb_mean: Mean measured data
830  */
831 struct rkisp1_cif_isp_awb_stat {
832 	struct rkisp1_cif_isp_awb_meas awb_mean[RKISP1_CIF_ISP_AWB_MAX_GRID];
833 };
834 
835 /**
836  * struct rkisp1_cif_isp_bls_meas_val - BLS measured values
837  *
838  * @meas_r: Mean measured value for Bayer pattern R
839  * @meas_gr: Mean measured value for Bayer pattern Gr
840  * @meas_gb: Mean measured value for Bayer pattern Gb
841  * @meas_b: Mean measured value for Bayer pattern B
842  */
843 struct rkisp1_cif_isp_bls_meas_val {
844 	__u16 meas_r;
845 	__u16 meas_gr;
846 	__u16 meas_gb;
847 	__u16 meas_b;
848 };
849 
850 /**
851  * struct rkisp1_cif_isp_ae_stat - statistics auto exposure data
852  *
853  * @exp_mean: Mean luminance value of block xx
854  * @bls_val:  BLS measured values
855  *
856  * The number of entries of @exp_mean depends on the hardware revision
857  * as is reported by the hw_revision field of the struct media_device_info
858  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
859  *
860  * Versions <= V11 have RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries,
861  * versions >= V12 have RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries.
862  * RKISP1_CIF_ISP_AE_MEAN_MAX is equal to the maximum of the two.
863  *
864  * Image is divided into 5x5 blocks on V10 and 9x9 blocks on V12.
865  */
866 struct rkisp1_cif_isp_ae_stat {
867 	__u8 exp_mean[RKISP1_CIF_ISP_AE_MEAN_MAX];
868 	struct rkisp1_cif_isp_bls_meas_val bls_val;
869 };
870 
871 /**
872  * struct rkisp1_cif_isp_af_meas_val - AF measured values
873  *
874  * @sum: sharpness value
875  * @lum: luminance value
876  */
877 struct rkisp1_cif_isp_af_meas_val {
878 	__u32 sum;
879 	__u32 lum;
880 };
881 
882 /**
883  * struct rkisp1_cif_isp_af_stat - statistics auto focus data
884  *
885  * @window: AF measured value of window x
886  *
887  * The module measures the sharpness in 3 windows of selectable size via
888  * register settings(ISP_AFM_*_A/B/C)
889  */
890 struct rkisp1_cif_isp_af_stat {
891 	struct rkisp1_cif_isp_af_meas_val window[RKISP1_CIF_ISP_AFM_MAX_WINDOWS];
892 };
893 
894 /**
895  * struct rkisp1_cif_isp_hist_stat - statistics histogram data
896  *
897  * @hist_bins: measured bin counters. Each bin is a 20 bits unsigned fixed point
898  *	       type. Bits 0-4 are the fractional part and bits 5-19 are the
899  *	       integer part.
900  *
901  * The window of the measurements area is divided to 5x5 sub-windows for
902  * V10/V11 and to 9x9 sub-windows for V12. The histogram is then computed for
903  * each sub-window independently and the final result is a weighted average of
904  * the histogram measurements on all sub-windows. The window of the
905  * measurements area and the weight of each sub-window are configurable using
906  * struct @rkisp1_cif_isp_hst_config.
907  *
908  * The histogram contains 16 bins in V10/V11 and 32 bins in V12/V13.
909  *
910  * The number of entries of @hist_bins depends on the hardware revision
911  * as is reported by the hw_revision field of the struct media_device_info
912  * that is returned by ioctl MEDIA_IOC_DEVICE_INFO.
913  *
914  * Versions <= V11 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries,
915  * versions >= V12 have RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries.
916  * RKISP1_CIF_ISP_HIST_BIN_N_MAX is equal to the maximum of the two.
917  */
918 struct rkisp1_cif_isp_hist_stat {
919 	__u32 hist_bins[RKISP1_CIF_ISP_HIST_BIN_N_MAX];
920 };
921 
922 /**
923  * struct rkisp1_cif_isp_stat - Rockchip ISP1 Statistics Data
924  *
925  * @awb: statistics data for automatic white balance
926  * @ae: statistics data for auto exposure
927  * @af: statistics data for auto focus
928  * @hist: statistics histogram data
929  */
930 struct rkisp1_cif_isp_stat {
931 	struct rkisp1_cif_isp_awb_stat awb;
932 	struct rkisp1_cif_isp_ae_stat ae;
933 	struct rkisp1_cif_isp_af_stat af;
934 	struct rkisp1_cif_isp_hist_stat hist;
935 };
936 
937 /**
938  * struct rkisp1_stat_buffer - Rockchip ISP1 Statistics Meta Data
939  *
940  * @meas_type: measurement types (RKISP1_CIF_ISP_STAT_* definitions)
941  * @frame_id: frame ID for sync
942  * @params: statistics data
943  */
944 struct rkisp1_stat_buffer {
945 	__u32 meas_type;
946 	__u32 frame_id;
947 	struct rkisp1_cif_isp_stat params;
948 };
949 
950 #endif /* _UAPI_RKISP1_CONFIG_H */
951