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