xref: /linux/include/uapi/linux/media/raspberrypi/pisp_be_config.h (revision 0cdee263bc5e7b20f657ea09f9272f50c568f35b)
1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2 /*
3  * PiSP Back End configuration definitions.
4  *
5  * Copyright (C) 2021 - Raspberry Pi Ltd
6  *
7  */
8 #ifndef _UAPI_PISP_BE_CONFIG_H_
9 #define _UAPI_PISP_BE_CONFIG_H_
10 
11 #include <linux/types.h>
12 
13 #include "pisp_common.h"
14 
15 /* byte alignment for inputs */
16 #define PISP_BACK_END_INPUT_ALIGN 4u
17 /* alignment for compressed inputs */
18 #define PISP_BACK_END_COMPRESSED_ALIGN 8u
19 /* minimum required byte alignment for outputs */
20 #define PISP_BACK_END_OUTPUT_MIN_ALIGN 16u
21 /* preferred byte alignment for outputs */
22 #define PISP_BACK_END_OUTPUT_MAX_ALIGN 64u
23 
24 /* minimum allowed tile sizes anywhere in the pipeline */
25 #define PISP_BACK_END_MIN_TILE_WIDTH	16u
26 #define PISP_BACK_END_MIN_TILE_HEIGHT	16u
27 #define PISP_BACK_END_MAX_TILE_WIDTH	65536u
28 #define PISP_BACK_END_MAX_TILE_HEIGHT	65536u
29 
30 #define PISP_BACK_END_NUM_OUTPUTS 2
31 #define PISP_BACK_END_HOG_OUTPUT 1
32 
33 #define PISP_BACK_END_NUM_TILES 64
34 
35 enum pisp_be_bayer_enable {
36 	PISP_BE_BAYER_ENABLE_INPUT = 0x000001,
37 	PISP_BE_BAYER_ENABLE_DECOMPRESS = 0x000002,
38 	PISP_BE_BAYER_ENABLE_DPC = 0x000004,
39 	PISP_BE_BAYER_ENABLE_GEQ = 0x000008,
40 	PISP_BE_BAYER_ENABLE_TDN_INPUT = 0x000010,
41 	PISP_BE_BAYER_ENABLE_TDN_DECOMPRESS = 0x000020,
42 	PISP_BE_BAYER_ENABLE_TDN = 0x000040,
43 	PISP_BE_BAYER_ENABLE_TDN_COMPRESS = 0x000080,
44 	PISP_BE_BAYER_ENABLE_TDN_OUTPUT = 0x000100,
45 	PISP_BE_BAYER_ENABLE_SDN = 0x000200,
46 	PISP_BE_BAYER_ENABLE_BLC = 0x000400,
47 	PISP_BE_BAYER_ENABLE_STITCH_INPUT = 0x000800,
48 	PISP_BE_BAYER_ENABLE_STITCH_DECOMPRESS = 0x001000,
49 	PISP_BE_BAYER_ENABLE_STITCH = 0x002000,
50 	PISP_BE_BAYER_ENABLE_STITCH_COMPRESS = 0x004000,
51 	PISP_BE_BAYER_ENABLE_STITCH_OUTPUT = 0x008000,
52 	PISP_BE_BAYER_ENABLE_WBG = 0x010000,
53 	PISP_BE_BAYER_ENABLE_CDN = 0x020000,
54 	PISP_BE_BAYER_ENABLE_LSC = 0x040000,
55 	PISP_BE_BAYER_ENABLE_TONEMAP = 0x080000,
56 	PISP_BE_BAYER_ENABLE_CAC = 0x100000,
57 	PISP_BE_BAYER_ENABLE_DEBIN = 0x200000,
58 	PISP_BE_BAYER_ENABLE_DEMOSAIC = 0x400000,
59 };
60 
61 enum pisp_be_rgb_enable {
62 	PISP_BE_RGB_ENABLE_INPUT = 0x000001,
63 	PISP_BE_RGB_ENABLE_CCM = 0x000002,
64 	PISP_BE_RGB_ENABLE_SAT_CONTROL = 0x000004,
65 	PISP_BE_RGB_ENABLE_YCBCR = 0x000008,
66 	PISP_BE_RGB_ENABLE_FALSE_COLOUR = 0x000010,
67 	PISP_BE_RGB_ENABLE_SHARPEN = 0x000020,
68 	/* Preferred colours would occupy 0x000040 */
69 	PISP_BE_RGB_ENABLE_YCBCR_INVERSE = 0x000080,
70 	PISP_BE_RGB_ENABLE_GAMMA = 0x000100,
71 	PISP_BE_RGB_ENABLE_CSC0 = 0x000200,
72 	PISP_BE_RGB_ENABLE_CSC1 = 0x000400,
73 	PISP_BE_RGB_ENABLE_DOWNSCALE0 = 0x001000,
74 	PISP_BE_RGB_ENABLE_DOWNSCALE1 = 0x002000,
75 	PISP_BE_RGB_ENABLE_RESAMPLE0 = 0x008000,
76 	PISP_BE_RGB_ENABLE_RESAMPLE1 = 0x010000,
77 	PISP_BE_RGB_ENABLE_OUTPUT0 = 0x040000,
78 	PISP_BE_RGB_ENABLE_OUTPUT1 = 0x080000,
79 	PISP_BE_RGB_ENABLE_HOG = 0x200000
80 };
81 
82 #define PISP_BE_RGB_ENABLE_CSC(i) (PISP_BE_RGB_ENABLE_CSC0 << (i))
83 #define PISP_BE_RGB_ENABLE_DOWNSCALE(i) (PISP_BE_RGB_ENABLE_DOWNSCALE0 << (i))
84 #define PISP_BE_RGB_ENABLE_RESAMPLE(i) (PISP_BE_RGB_ENABLE_RESAMPLE0 << (i))
85 #define PISP_BE_RGB_ENABLE_OUTPUT(i) (PISP_BE_RGB_ENABLE_OUTPUT0 << (i))
86 
87 /*
88  * We use the enable flags to show when blocks are "dirty", but we need some
89  * extra ones too.
90  */
91 enum pisp_be_dirty {
92 	PISP_BE_DIRTY_GLOBAL = 0x0001,
93 	PISP_BE_DIRTY_SH_FC_COMBINE = 0x0002,
94 	PISP_BE_DIRTY_CROP = 0x0004
95 };
96 
97 /**
98  * struct pisp_be_global_config - PiSP global enable bitmaps
99  * @bayer_enables:	Bayer input enable flags
100  * @rgb_enables:	RGB output enable flags
101  * @bayer_order:	Bayer input format ordering
102  * @pad:		Padding bytes
103  */
104 struct pisp_be_global_config {
105 	__u32 bayer_enables;
106 	__u32 rgb_enables;
107 	__u8 bayer_order;
108 	__u8 pad[3];
109 } __attribute__((packed));
110 
111 /**
112  * struct pisp_be_input_buffer_config - PiSP Back End input buffer
113  * @addr:		Input buffer address
114  */
115 struct pisp_be_input_buffer_config {
116 	/* low 32 bits followed by high 32 bits (for each of up to 3 planes) */
117 	__u32 addr[3][2];
118 } __attribute__((packed));
119 
120 /**
121  * struct pisp_be_dpc_config - PiSP Back End DPC config
122  *
123  * Defective Pixel Correction configuration
124  *
125  * @coeff_level:	Coefficient for the darkest neighbouring pixel value
126  * @coeff_range:	Coefficient for the range of pixels for this Bayer channel
127  * @pad:		Padding byte
128  * @flags:		DPC configuration flags
129  */
130 struct pisp_be_dpc_config {
131 	__u8 coeff_level;
132 	__u8 coeff_range;
133 	__u8 pad;
134 #define PISP_BE_DPC_FLAG_FOLDBACK 1
135 	__u8 flags;
136 } __attribute__((packed));
137 
138 /**
139  * struct pisp_be_geq_config - PiSP Back End GEQ config
140  *
141  * Green Equalisation configuration
142  *
143  * @offset:		Offset value for threshold calculation
144  * @slope_sharper:	Slope/Sharper configuration
145  * @min:		Minimum value the threshold may have
146  * @max:		Maximum value the threshold may have
147  */
148 struct pisp_be_geq_config {
149 	__u16 offset;
150 #define PISP_BE_GEQ_SHARPER (1U << 15)
151 #define PISP_BE_GEQ_SLOPE ((1 << 10) - 1)
152 	/* top bit is the "sharper" flag, slope value is bottom 10 bits */
153 	__u16 slope_sharper;
154 	__u16 min;
155 	__u16 max;
156 } __attribute__((packed));
157 
158 /**
159  * struct pisp_be_tdn_input_buffer_config - PiSP Back End TDN input buffer
160  * @addr:		TDN input buffer address
161  */
162 struct pisp_be_tdn_input_buffer_config {
163 	/* low 32 bits followed by high 32 bits */
164 	__u32 addr[2];
165 } __attribute__((packed));
166 
167 /**
168  * struct pisp_be_tdn_config - PiSP Back End TDN config
169  *
170  * Temporal Denoise configuration
171  *
172  * @black_level:	Black level value subtracted from pixels
173  * @ratio:		Multiplier for the LTA input frame
174  * @noise_constant:	Constant offset value used in noise estimation
175  * @noise_slope:	Noise estimation multiplier
176  * @threshold:		Threshold for TDN operations
177  * @reset:		Disable TDN operations
178  * @pad:		Padding byte
179  */
180 struct pisp_be_tdn_config {
181 	__u16 black_level;
182 	__u16 ratio;
183 	__u16 noise_constant;
184 	__u16 noise_slope;
185 	__u16 threshold;
186 	__u8 reset;
187 	__u8 pad;
188 } __attribute__((packed));
189 
190 /**
191  * struct pisp_be_tdn_output_buffer_config - PiSP Back End TDN output buffer
192  * @addr:		TDN output buffer address
193  */
194 struct pisp_be_tdn_output_buffer_config {
195 	/* low 32 bits followed by high 32 bits */
196 	__u32 addr[2];
197 } __attribute__((packed));
198 
199 /**
200  * struct pisp_be_sdn_config - PiSP Back End SDN config
201  *
202  * Spatial Denoise configuration
203  *
204  * @black_level:	Black level subtracted from pixel for noise estimation
205  * @leakage:		Proportion of the original undenoised value to mix in
206  *			denoised output
207  * @pad:		Padding byte
208  * @noise_constant:	Noise constant used for noise estimation
209  * @noise_slope:	Noise slope value used for noise estimation
210  * @noise_constant2:	Second noise constant used for noise estimation
211  * @noise_slope2:	Second slope value used for noise estimation
212  */
213 struct pisp_be_sdn_config {
214 	__u16 black_level;
215 	__u8 leakage;
216 	__u8 pad;
217 	__u16 noise_constant;
218 	__u16 noise_slope;
219 	__u16 noise_constant2;
220 	__u16 noise_slope2;
221 } __attribute__((packed));
222 
223 /**
224  * struct pisp_be_stitch_input_buffer_config - PiSP Back End Stitch input
225  * @addr:		Stitch input buffer address
226  */
227 struct pisp_be_stitch_input_buffer_config {
228 	/* low 32 bits followed by high 32 bits */
229 	__u32 addr[2];
230 } __attribute__((packed));
231 
232 #define PISP_BE_STITCH_STREAMING_LONG 0x8000
233 #define PISP_BE_STITCH_EXPOSURE_RATIO_MASK 0x7fff
234 
235 /**
236  * struct pisp_be_stitch_config - PiSP Back End Stitch config
237  *
238  * Stitch block configuration
239  *
240  * @threshold_lo:		Low threshold value
241  * @threshold_diff_power:	Low and high threshold difference
242  * @pad:			Padding bytes
243  * @exposure_ratio:		Multiplier to convert long exposure pixels into
244  *				short exposure pixels
245  * @motion_threshold_256:	Motion threshold above which short exposure
246  *				pixels are used
247  * @motion_threshold_recip:	Reciprocal of motion_threshold_256 value
248  */
249 struct pisp_be_stitch_config {
250 	__u16 threshold_lo;
251 	__u8 threshold_diff_power;
252 	__u8 pad;
253 
254 	/* top bit indicates whether streaming input is the long exposure */
255 	__u16 exposure_ratio;
256 
257 	__u8 motion_threshold_256;
258 	__u8 motion_threshold_recip;
259 } __attribute__((packed));
260 
261 /**
262  * struct pisp_be_stitch_output_buffer_config - PiSP Back End Stitch output
263  * @addr:		Stitch input buffer address
264  */
265 struct pisp_be_stitch_output_buffer_config {
266 	/* low 32 bits followed by high 32 bits */
267 	__u32 addr[2];
268 } __attribute__((packed));
269 
270 /**
271  * struct pisp_be_cdn_config - PiSP Back End CDN config
272  *
273  * Colour Denoise configuration
274  *
275  * @thresh:		Constant for noise estimation
276  * @iir_strength:	Relative strength of the IIR part of the filter
277  * @g_adjust:		Proportion of the change assigned to the G channel
278  */
279 struct pisp_be_cdn_config {
280 	__u16 thresh;
281 	__u8 iir_strength;
282 	__u8 g_adjust;
283 } __attribute__((packed));
284 
285 #define PISP_BE_LSC_LOG_GRID_SIZE 5
286 #define PISP_BE_LSC_GRID_SIZE (1 << PISP_BE_LSC_LOG_GRID_SIZE)
287 #define PISP_BE_LSC_STEP_PRECISION 18
288 
289 /**
290  * struct pisp_be_lsc_config - PiSP Back End LSC config
291  *
292  * Lens Shading Correction configuration
293  *
294  * @grid_step_x:	Reciprocal of cell size width
295  * @grid_step_y:	Reciprocal of cell size height
296  * @lut_packed:		Jointly-coded RGB gains for each LSC grid
297  */
298 struct pisp_be_lsc_config {
299 	/* (1<<18) / grid_cell_width */
300 	__u16 grid_step_x;
301 	/* (1<<18) / grid_cell_height */
302 	__u16 grid_step_y;
303 	/* RGB gains jointly encoded in 32 bits */
304 #define PISP_BE_LSC_LUT_SIZE	(PISP_BE_LSC_GRID_SIZE + 1)
305 	__u32 lut_packed[PISP_BE_LSC_LUT_SIZE][PISP_BE_LSC_LUT_SIZE];
306 } __attribute__((packed));
307 
308 /**
309  * struct pisp_be_lsc_extra - PiSP Back End LSC Extra config
310  * @offset_x:		Horizontal offset into the LSC table of this tile
311  * @offset_y:		Vertical offset into the LSC table of this tile
312  */
313 struct pisp_be_lsc_extra {
314 	__u16 offset_x;
315 	__u16 offset_y;
316 } __attribute__((packed));
317 
318 #define PISP_BE_CAC_LOG_GRID_SIZE 3
319 #define PISP_BE_CAC_GRID_SIZE (1 << PISP_BE_CAC_LOG_GRID_SIZE)
320 #define PISP_BE_CAC_STEP_PRECISION 20
321 
322 /**
323  * struct pisp_be_cac_config - PiSP Back End CAC config
324  *
325  * Chromatic Aberration Correction config
326  *
327  * @grid_step_x:	Reciprocal of cell size width
328  * @grid_step_y:	Reciprocal of cell size height
329  * @lut:		Pixel shift for the CAC grid
330  */
331 struct pisp_be_cac_config {
332 	/* (1<<20) / grid_cell_width */
333 	__u16 grid_step_x;
334 	/* (1<<20) / grid_cell_height */
335 	__u16 grid_step_y;
336 	/* [gridy][gridx][rb][xy] */
337 #define PISP_BE_CAC_LUT_SIZE		(PISP_BE_CAC_GRID_SIZE + 1)
338 	__s8 lut[PISP_BE_CAC_LUT_SIZE][PISP_BE_CAC_LUT_SIZE][2][2];
339 } __attribute__((packed));
340 
341 /**
342  * struct pisp_be_cac_extra - PiSP Back End CAC extra config
343  * @offset_x:		Horizontal offset into the CAC table of this tile
344  * @offset_y:		Horizontal offset into the CAC table of this tile
345  */
346 struct pisp_be_cac_extra {
347 	__u16 offset_x;
348 	__u16 offset_y;
349 } __attribute__((packed));
350 
351 #define PISP_BE_DEBIN_NUM_COEFFS 4
352 
353 /**
354  * struct pisp_be_debin_config - PiSP Back End Debin config
355  *
356  * Debinning configuration
357  *
358  * @coeffs:		Filter coefficients for debinning
359  * @h_enable:		Horizontal debinning enable
360  * @v_enable:		Vertical debinning enable
361  * @pad:		Padding bytes
362  */
363 struct pisp_be_debin_config {
364 	__s8 coeffs[PISP_BE_DEBIN_NUM_COEFFS];
365 	__s8 h_enable;
366 	__s8 v_enable;
367 	__s8 pad[2];
368 } __attribute__((packed));
369 
370 #define PISP_BE_TONEMAP_LUT_SIZE 64
371 
372 /**
373  * struct pisp_be_tonemap_config - PiSP Back End Tonemap config
374  *
375  * Tonemapping configuration
376  *
377  * @detail_constant:	Constant value for threshold calculation
378  * @detail_slope:	Slope value for threshold calculation
379  * @iir_strength:	Relative strength of the IIR fiter
380  * @strength:		Strength factor
381  * @lut:		Look-up table for tonemap curve
382  */
383 struct pisp_be_tonemap_config {
384 	__u16 detail_constant;
385 	__u16 detail_slope;
386 	__u16 iir_strength;
387 	__u16 strength;
388 	__u32 lut[PISP_BE_TONEMAP_LUT_SIZE];
389 } __attribute__((packed));
390 
391 /**
392  * struct pisp_be_demosaic_config - PiSP Back End Demosaic config
393  *
394  * Demosaic configuration
395  *
396  * @sharper:		Use other Bayer channels to increase sharpness
397  * @fc_mode:		Built-in false colour suppression mode
398  * @pad:		Padding bytes
399  */
400 struct pisp_be_demosaic_config {
401 	__u8 sharper;
402 	__u8 fc_mode;
403 	__u8 pad[2];
404 } __attribute__((packed));
405 
406 /**
407  * struct pisp_be_ccm_config - PiSP Back End CCM config
408  *
409  * Colour Correction Matrix configuration
410  *
411  * @coeffs:		Matrix coefficients
412  * @pad:		Padding bytes
413  * @offsets:		Offsets triplet
414  */
415 struct pisp_be_ccm_config {
416 	__s16 coeffs[9];
417 	__u8 pad[2];
418 	__s32 offsets[3];
419 } __attribute__((packed));
420 
421 /**
422  * struct pisp_be_sat_control_config - PiSP Back End SAT config
423  *
424  * Saturation Control configuration
425  *
426  * @shift_r:		Left shift for Red colour channel
427  * @shift_g:		Left shift for Green colour channel
428  * @shift_b:		Left shift for Blue colour channel
429  * @pad:		Padding byte
430  */
431 struct pisp_be_sat_control_config {
432 	__u8 shift_r;
433 	__u8 shift_g;
434 	__u8 shift_b;
435 	__u8 pad;
436 } __attribute__((packed));
437 
438 /**
439  * struct pisp_be_false_colour_config - PiSP Back End False Colour config
440  *
441  * False Colour configuration
442  *
443  * @distance:		Distance of neighbouring pixels, either 1 or 2
444  * @pad:		Padding bytes
445  */
446 struct pisp_be_false_colour_config {
447 	__u8 distance;
448 	__u8 pad[3];
449 } __attribute__((packed));
450 
451 #define PISP_BE_SHARPEN_SIZE 5
452 #define PISP_BE_SHARPEN_FUNC_NUM_POINTS 9
453 
454 /**
455  * struct pisp_be_sharpen_config - PiSP Back End Sharpening config
456  *
457  * Sharpening configuration
458  *
459  * @kernel0:		Coefficient for filter 0
460  * @pad0:		Padding byte
461  * @kernel1:		Coefficient for filter 1
462  * @pad1:		Padding byte
463  * @kernel2:		Coefficient for filter 2
464  * @pad2:		Padding byte
465  * @kernel3:		Coefficient for filter 3
466  * @pad3:		Padding byte
467  * @kernel4:		Coefficient for filter 4
468  * @pad4:		Padding byte
469  * @threshold_offset0:	Offset for filter 0 response calculation
470  * @threshold_slope0:	Slope multiplier for the filter 0 response calculation
471  * @scale0:		Scale factor for filter 0 response calculation
472  * @pad5:		Padding byte
473  * @threshold_offset1:	Offset for filter 0 response calculation
474  * @threshold_slope1:	Slope multiplier for the filter 0 response calculation
475  * @scale1:		Scale factor for filter 0 response calculation
476  * @pad6:		Padding byte
477  * @threshold_offset2:	Offset for filter 0 response calculation
478  * @threshold_slope2:	Slope multiplier for the filter 0 response calculation
479  * @scale2:		Scale factor for filter 0 response calculation
480  * @pad7:		Padding byte
481  * @threshold_offset3:	Offset for filter 0 response calculation
482  * @threshold_slope3:	Slope multiplier for the filter 0 response calculation
483  * @scale3:		Scale factor for filter 0 response calculation
484  * @pad8:		Padding byte
485  * @threshold_offset4:	Offset for filter 0 response calculation
486  * @threshold_slope4:	Slope multiplier for the filter 0 response calculation
487  * @scale4:		Scale factor for filter 0 response calculation
488  * @pad9:		Padding byte
489  * @positive_strength:	Factor to scale the positive sharpening strength
490  * @positive_pre_limit:	Maximum allowed possible positive sharpening value
491  * @positive_func:	Gain factor applied to positive sharpening response
492  * @positive_limit:	Final gain factor applied to positive sharpening
493  * @negative_strength:	Factor to scale the negative sharpening strength
494  * @negative_pre_limit:	Maximum allowed possible negative sharpening value
495  * @negative_func:	Gain factor applied to negative sharpening response
496  * @negative_limit:	Final gain factor applied to negative sharpening
497  * @enables:		Filter enable mask
498  * @white:		White output pixel filter mask
499  * @black:		Black output pixel filter mask
500  * @grey:		Grey output pixel filter mask
501  */
502 struct pisp_be_sharpen_config {
503 	__s8 kernel0[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
504 	__s8 pad0[3];
505 	__s8 kernel1[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
506 	__s8 pad1[3];
507 	__s8 kernel2[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
508 	__s8 pad2[3];
509 	__s8 kernel3[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
510 	__s8 pad3[3];
511 	__s8 kernel4[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
512 	__s8 pad4[3];
513 	__u16 threshold_offset0;
514 	__u16 threshold_slope0;
515 	__u16 scale0;
516 	__u16 pad5;
517 	__u16 threshold_offset1;
518 	__u16 threshold_slope1;
519 	__u16 scale1;
520 	__u16 pad6;
521 	__u16 threshold_offset2;
522 	__u16 threshold_slope2;
523 	__u16 scale2;
524 	__u16 pad7;
525 	__u16 threshold_offset3;
526 	__u16 threshold_slope3;
527 	__u16 scale3;
528 	__u16 pad8;
529 	__u16 threshold_offset4;
530 	__u16 threshold_slope4;
531 	__u16 scale4;
532 	__u16 pad9;
533 	__u16 positive_strength;
534 	__u16 positive_pre_limit;
535 	__u16 positive_func[PISP_BE_SHARPEN_FUNC_NUM_POINTS];
536 	__u16 positive_limit;
537 	__u16 negative_strength;
538 	__u16 negative_pre_limit;
539 	__u16 negative_func[PISP_BE_SHARPEN_FUNC_NUM_POINTS];
540 	__u16 negative_limit;
541 	__u8 enables;
542 	__u8 white;
543 	__u8 black;
544 	__u8 grey;
545 } __attribute__((packed));
546 
547 /**
548  * struct pisp_be_sh_fc_combine_config - PiSP Back End Sharpening and
549  *					 False Colour config
550  *
551  * Sharpening and False Colour configuration
552  *
553  * @y_factor:		Control amount of desaturation of pixels being darkened
554  * @c1_factor:		Control amount of brightening of a pixel for the Cb
555  *			channel
556  * @c2_factor:		Control amount of brightening of a pixel for the Cr
557  *			channel
558  * @pad:		Padding byte
559  */
560 struct pisp_be_sh_fc_combine_config {
561 	__u8 y_factor;
562 	__u8 c1_factor;
563 	__u8 c2_factor;
564 	__u8 pad;
565 } __attribute__((packed));
566 
567 #define PISP_BE_GAMMA_LUT_SIZE 64
568 
569 /**
570  * struct pisp_be_gamma_config - PiSP Back End Gamma configuration
571  * @lut:		Gamma curve look-up table
572  */
573 struct pisp_be_gamma_config {
574 	__u32 lut[PISP_BE_GAMMA_LUT_SIZE];
575 } __attribute__((packed));
576 
577 /**
578  * struct pisp_be_crop_config - PiSP Back End Crop config
579  *
580  * Crop configuration
581  *
582  * @offset_x:		Number of pixels cropped from the left of the tile
583  * @offset_y:		Number of pixels cropped from the top of the tile
584  * @width:		Width of the cropped tile output
585  * @height:		Height of the cropped tile output
586  */
587 struct pisp_be_crop_config {
588 	__u16 offset_x, offset_y;
589 	__u16 width, height;
590 } __attribute__((packed));
591 
592 #define PISP_BE_RESAMPLE_FILTER_SIZE 96
593 
594 /**
595  * struct pisp_be_resample_config - PiSP Back End Resampling config
596  *
597  * Resample configuration
598  *
599  * @scale_factor_h:	Horizontal scale factor
600  * @scale_factor_v:	Vertical scale factor
601  * @coef:		Resample coefficients
602  */
603 struct pisp_be_resample_config {
604 	__u16 scale_factor_h, scale_factor_v;
605 	__s16 coef[PISP_BE_RESAMPLE_FILTER_SIZE];
606 } __attribute__((packed));
607 
608 /**
609  * struct pisp_be_resample_extra - PiSP Back End Resample config
610  *
611  * Resample configuration
612  *
613  * @scaled_width:	Width in pixels of the scaled output
614  * @scaled_height:	Height in pixels of the scaled output
615  * @initial_phase_h:	Initial horizontal phase
616  * @initial_phase_v:	Initial vertical phase
617  */
618 struct pisp_be_resample_extra {
619 	__u16 scaled_width;
620 	__u16 scaled_height;
621 	__s16 initial_phase_h[3];
622 	__s16 initial_phase_v[3];
623 } __attribute__((packed));
624 
625 /**
626  * struct pisp_be_downscale_config - PiSP Back End Downscale config
627  *
628  * Downscale configuration
629  *
630  * @scale_factor_h:	Horizontal scale factor
631  * @scale_factor_v:	Vertical scale factor
632  * @scale_recip_h:	Horizontal reciprocal factor
633  * @scale_recip_v:	Vertical reciprocal factor
634  */
635 struct pisp_be_downscale_config {
636 	__u16 scale_factor_h;
637 	__u16 scale_factor_v;
638 	__u16 scale_recip_h;
639 	__u16 scale_recip_v;
640 } __attribute__((packed));
641 
642 /**
643  * struct pisp_be_downscale_extra - PiSP Back End Downscale Extra config
644  * @scaled_width:	Scaled image width
645  * @scaled_height:	Scaled image height
646  */
647 struct pisp_be_downscale_extra {
648 	__u16 scaled_width;
649 	__u16 scaled_height;
650 } __attribute__((packed));
651 
652 /**
653  * struct pisp_be_hog_config - PiSP Back End HOG config
654  *
655  * Histogram of Oriented Gradients configuration
656  *
657  * @compute_signed:	Set 0 for unsigned gradients, 1 for signed
658  * @channel_mix:	Channels proportions to use
659  * @stride:		Stride in bytes between blocks directly below
660  */
661 struct pisp_be_hog_config {
662 	__u8 compute_signed;
663 	__u8 channel_mix[3];
664 	__u32 stride;
665 } __attribute__((packed));
666 
667 struct pisp_be_axi_config {
668 	__u8 r_qos; /* Read QoS */
669 	__u8 r_cache_prot; /* Read { prot[2:0], cache[3:0] } */
670 	__u8 w_qos; /* Write QoS */
671 	__u8 w_cache_prot; /* Write { prot[2:0], cache[3:0] } */
672 } __attribute__((packed));
673 
674 /**
675  * enum pisp_be_transform - PiSP Back End Transform flags
676  * @PISP_BE_TRANSFORM_NONE:	No transform
677  * @PISP_BE_TRANSFORM_HFLIP:	Horizontal flip
678  * @PISP_BE_TRANSFORM_VFLIP:	Vertical flip
679  * @PISP_BE_TRANSFORM_ROT180:	180 degress rotation
680  */
681 enum pisp_be_transform {
682 	PISP_BE_TRANSFORM_NONE = 0x0,
683 	PISP_BE_TRANSFORM_HFLIP = 0x1,
684 	PISP_BE_TRANSFORM_VFLIP = 0x2,
685 	PISP_BE_TRANSFORM_ROT180 =
686 		(PISP_BE_TRANSFORM_HFLIP | PISP_BE_TRANSFORM_VFLIP)
687 };
688 
689 struct pisp_be_output_format_config {
690 	struct pisp_image_format_config image;
691 	__u8 transform;
692 	__u8 pad[3];
693 	__u16 lo;
694 	__u16 hi;
695 	__u16 lo2;
696 	__u16 hi2;
697 } __attribute__((packed));
698 
699 /**
700  * struct pisp_be_output_buffer_config - PiSP Back End Output buffer
701  * @addr:		Output buffer address
702  */
703 struct pisp_be_output_buffer_config {
704 	/* low 32 bits followed by high 32 bits (for each of 3 planes) */
705 	__u32 addr[3][2];
706 } __attribute__((packed));
707 
708 /**
709  * struct pisp_be_hog_buffer_config - PiSP Back End HOG buffer
710  * @addr:		HOG buffer address
711  */
712 struct pisp_be_hog_buffer_config {
713 	/* low 32 bits followed by high 32 bits */
714 	__u32 addr[2];
715 } __attribute__((packed));
716 
717 /**
718  * struct pisp_be_config - RaspberryPi PiSP Back End Processing configuration
719  *
720  * @input_buffer:		Input buffer addresses
721  * @tdn_input_buffer:		TDN input buffer addresses
722  * @stitch_input_buffer:	Stitch input buffer addresses
723  * @tdn_output_buffer:		TDN output buffer addresses
724  * @stitch_output_buffer:	Stitch output buffer addresses
725  * @output_buffer:		Output buffers addresses
726  * @hog_buffer:			HOG buffer addresses
727  * @global:			Global PiSP configuration
728  * @input_format:		Input image format
729  * @decompress:			Decompress configuration
730  * @dpc:			Defective Pixel Correction configuration
731  * @geq:			Green Equalisation configuration
732  * @tdn_input_format:		Temporal Denoise input format
733  * @tdn_decompress:		Temporal Denoise decompress configuration
734  * @tdn:			Temporal Denoise configuration
735  * @tdn_compress:		Temporal Denoise compress configuration
736  * @tdn_output_format:		Temporal Denoise output format
737  * @sdn:			Spatial Denoise configuration
738  * @blc:			Black Level Correction configuration
739  * @stitch_compress:		Stitch compress configuration
740  * @stitch_output_format:	Stitch output format
741  * @stitch_input_format:	Stitch input format
742  * @stitch_decompress:		Stitch decompress configuration
743  * @stitch:			Stitch configuration
744  * @lsc:			Lens Shading Correction configuration
745  * @wbg:			White Balance Gain configuration
746  * @cdn:			Colour Denoise configuration
747  * @cac:			Colour Aberration Correction configuration
748  * @debin:			Debinning configuration
749  * @tonemap:			Tonemapping configuration
750  * @demosaic:			Demosaicing configuration
751  * @ccm:			Colour Correction Matrix configuration
752  * @sat_control:		Saturation Control configuration
753  * @ycbcr:			YCbCr colour correction configuration
754  * @sharpen:			Sharpening configuration
755  * @false_colour:		False colour correction
756  * @sh_fc_combine:		Sharpening and False Colour correction
757  * @ycbcr_inverse:		Inverse YCbCr colour correction
758  * @gamma:			Gamma curve configuration
759  * @csc:			Color Space Conversion configuration
760  * @downscale:			Downscale configuration
761  * @resample:			Resampling configuration
762  * @output_format:		Output format configuration
763  * @hog:			HOG configuration
764  * @axi:			AXI bus configuration
765  * @lsc_extra:			LSC extra info
766  * @cac_extra:			CAC extra info
767  * @downscale_extra:		Downscaler extra info
768  * @resample_extra:		Resample extra info
769  * @crop:			Crop configuration
770  * @hog_format:			HOG format info
771  * @dirty_flags_bayer:		Bayer enable dirty flags
772  *				(:c:type:`pisp_be_bayer_enable`)
773  * @dirty_flags_rgb:		RGB enable dirty flags
774  *				(:c:type:`pisp_be_rgb_enable`)
775  * @dirty_flags_extra:		Extra dirty flags
776  */
777 struct pisp_be_config {
778 	/* I/O configuration: */
779 	struct pisp_be_input_buffer_config input_buffer;
780 	struct pisp_be_tdn_input_buffer_config tdn_input_buffer;
781 	struct pisp_be_stitch_input_buffer_config stitch_input_buffer;
782 	struct pisp_be_tdn_output_buffer_config tdn_output_buffer;
783 	struct pisp_be_stitch_output_buffer_config stitch_output_buffer;
784 	struct pisp_be_output_buffer_config
785 				output_buffer[PISP_BACK_END_NUM_OUTPUTS];
786 	struct pisp_be_hog_buffer_config hog_buffer;
787 	/* Processing configuration: */
788 	struct pisp_be_global_config global;
789 	struct pisp_image_format_config input_format;
790 	struct pisp_decompress_config decompress;
791 	struct pisp_be_dpc_config dpc;
792 	struct pisp_be_geq_config geq;
793 	struct pisp_image_format_config tdn_input_format;
794 	struct pisp_decompress_config tdn_decompress;
795 	struct pisp_be_tdn_config tdn;
796 	struct pisp_compress_config tdn_compress;
797 	struct pisp_image_format_config tdn_output_format;
798 	struct pisp_be_sdn_config sdn;
799 	struct pisp_bla_config blc;
800 	struct pisp_compress_config stitch_compress;
801 	struct pisp_image_format_config stitch_output_format;
802 	struct pisp_image_format_config stitch_input_format;
803 	struct pisp_decompress_config stitch_decompress;
804 	struct pisp_be_stitch_config stitch;
805 	struct pisp_be_lsc_config lsc;
806 	struct pisp_wbg_config wbg;
807 	struct pisp_be_cdn_config cdn;
808 	struct pisp_be_cac_config cac;
809 	struct pisp_be_debin_config debin;
810 	struct pisp_be_tonemap_config tonemap;
811 	struct pisp_be_demosaic_config demosaic;
812 	struct pisp_be_ccm_config ccm;
813 	struct pisp_be_sat_control_config sat_control;
814 	struct pisp_be_ccm_config ycbcr;
815 	struct pisp_be_sharpen_config sharpen;
816 	struct pisp_be_false_colour_config false_colour;
817 	struct pisp_be_sh_fc_combine_config sh_fc_combine;
818 	struct pisp_be_ccm_config ycbcr_inverse;
819 	struct pisp_be_gamma_config gamma;
820 	struct pisp_be_ccm_config csc[PISP_BACK_END_NUM_OUTPUTS];
821 	struct pisp_be_downscale_config downscale[PISP_BACK_END_NUM_OUTPUTS];
822 	struct pisp_be_resample_config resample[PISP_BACK_END_NUM_OUTPUTS];
823 	struct pisp_be_output_format_config
824 				output_format[PISP_BACK_END_NUM_OUTPUTS];
825 	struct pisp_be_hog_config hog;
826 	struct pisp_be_axi_config axi;
827 	/* Non-register fields: */
828 	struct pisp_be_lsc_extra lsc_extra;
829 	struct pisp_be_cac_extra cac_extra;
830 	struct pisp_be_downscale_extra
831 				downscale_extra[PISP_BACK_END_NUM_OUTPUTS];
832 	struct pisp_be_resample_extra resample_extra[PISP_BACK_END_NUM_OUTPUTS];
833 	struct pisp_be_crop_config crop;
834 	struct pisp_image_format_config hog_format;
835 	__u32 dirty_flags_bayer; /* these use pisp_be_bayer_enable */
836 	__u32 dirty_flags_rgb; /* use pisp_be_rgb_enable */
837 	__u32 dirty_flags_extra; /* these use pisp_be_dirty_t */
838 } __attribute__((packed));
839 
840 /**
841  * enum pisp_tile_edge - PiSP Back End Tile position
842  * @PISP_LEFT_EDGE:		Left edge tile
843  * @PISP_RIGHT_EDGE:		Right edge tile
844  * @PISP_TOP_EDGE:		Top edge tile
845  * @PISP_BOTTOM_EDGE:		Bottom edge tile
846  */
847 enum pisp_tile_edge {
848 	PISP_LEFT_EDGE = (1 << 0),
849 	PISP_RIGHT_EDGE = (1 << 1),
850 	PISP_TOP_EDGE = (1 << 2),
851 	PISP_BOTTOM_EDGE = (1 << 3)
852 };
853 
854 /**
855  * struct pisp_tile - Raspberry Pi PiSP Back End tile configuration
856  *
857  * Tile parameters: each set of tile parameters is a 160-bytes block of data
858  * which contains the tile processing parameters.
859  *
860  * @edge:			Edge tile flag
861  * @pad0:			Padding bytes
862  * @input_addr_offset:		Top-left pixel offset, in bytes
863  * @input_addr_offset2:		Top-left pixel offset, in bytes for the second/
864  *				third image planes
865  * @input_offset_x:		Horizontal offset in pixels of this tile in the
866  *				input image
867  * @input_offset_y:		Vertical offset in pixels of this tile in the
868  *				input image
869  * @input_width:		Width in pixels of this tile
870  * @input_height:		Height in pixels of the this tile
871  * @tdn_input_addr_offset:	TDN input image offset, in bytes
872  * @tdn_output_addr_offset:	TDN output image offset, in bytes
873  * @stitch_input_addr_offset:	Stitch input image offset, in bytes
874  * @stitch_output_addr_offset:	Stitch output image offset, in bytes
875  * @lsc_grid_offset_x:		Horizontal offset in the LSC table for this tile
876  * @lsc_grid_offset_y:		Vertical offset in the LSC table for this tile
877  * @cac_grid_offset_x:		Horizontal offset in the CAC table for this tile
878  * @cac_grid_offset_y:		Horizontal offset in the CAC table for this tile
879  * @crop_x_start:		Number of pixels cropped from the left of the
880  *				tile
881  * @crop_x_end:			Number of pixels cropped from the right of the
882  *				tile
883  * @crop_y_start:		Number of pixels cropped from the top of the
884  *				tile
885  * @crop_y_end:			Number of pixels cropped from the bottom of the
886  *				tile
887  * @downscale_phase_x:		Initial horizontal phase in pixels
888  * @downscale_phase_y:		Initial vertical phase in pixels
889  * @resample_in_width:		Width in pixels of the tile entering the
890  *				Resample block
891  * @resample_in_height:		Height in pixels of the tile entering the
892  *				Resample block
893  * @resample_phase_x:		Initial horizontal phase for the Resample block
894  * @resample_phase_y:		Initial vertical phase for the Resample block
895  * @output_offset_x:		Horizontal offset in pixels where the tile will
896  *				be written into the output image
897  * @output_offset_y:		Vertical offset in pixels where the tile will be
898  *				written into the output image
899  * @output_width:		Width in pixels in the output image of this tile
900  * @output_height:		Height in pixels in the output image of this tile
901  * @output_addr_offset:		Offset in bytes into the output buffer
902  * @output_addr_offset2:	Offset in bytes into the output buffer for the
903  *				second and third plane
904  * @output_hog_addr_offset:	Offset in bytes into the HOG buffer where
905  *				results of this tile are to be written
906  */
907 struct pisp_tile {
908 	__u8 edge; /* enum pisp_tile_edge */
909 	__u8 pad0[3];
910 	/* 4 bytes */
911 	__u32 input_addr_offset;
912 	__u32 input_addr_offset2;
913 	__u16 input_offset_x;
914 	__u16 input_offset_y;
915 	__u16 input_width;
916 	__u16 input_height;
917 	/* 20 bytes */
918 	__u32 tdn_input_addr_offset;
919 	__u32 tdn_output_addr_offset;
920 	__u32 stitch_input_addr_offset;
921 	__u32 stitch_output_addr_offset;
922 	/* 36 bytes */
923 	__u32 lsc_grid_offset_x;
924 	__u32 lsc_grid_offset_y;
925 	/* 44 bytes */
926 	__u32 cac_grid_offset_x;
927 	__u32 cac_grid_offset_y;
928 	/* 52 bytes */
929 	__u16 crop_x_start[PISP_BACK_END_NUM_OUTPUTS];
930 	__u16 crop_x_end[PISP_BACK_END_NUM_OUTPUTS];
931 	__u16 crop_y_start[PISP_BACK_END_NUM_OUTPUTS];
932 	__u16 crop_y_end[PISP_BACK_END_NUM_OUTPUTS];
933 	/* 68 bytes */
934 	/* Ordering is planes then branches */
935 	__u16 downscale_phase_x[3 * PISP_BACK_END_NUM_OUTPUTS];
936 	__u16 downscale_phase_y[3 * PISP_BACK_END_NUM_OUTPUTS];
937 	/* 92 bytes */
938 	__u16 resample_in_width[PISP_BACK_END_NUM_OUTPUTS];
939 	__u16 resample_in_height[PISP_BACK_END_NUM_OUTPUTS];
940 	/* 100 bytes */
941 	/* Ordering is planes then branches */
942 	__u16 resample_phase_x[3 * PISP_BACK_END_NUM_OUTPUTS];
943 	__u16 resample_phase_y[3 * PISP_BACK_END_NUM_OUTPUTS];
944 	/* 124 bytes */
945 	__u16 output_offset_x[PISP_BACK_END_NUM_OUTPUTS];
946 	__u16 output_offset_y[PISP_BACK_END_NUM_OUTPUTS];
947 	__u16 output_width[PISP_BACK_END_NUM_OUTPUTS];
948 	__u16 output_height[PISP_BACK_END_NUM_OUTPUTS];
949 	/* 140 bytes */
950 	__u32 output_addr_offset[PISP_BACK_END_NUM_OUTPUTS];
951 	__u32 output_addr_offset2[PISP_BACK_END_NUM_OUTPUTS];
952 	/* 156 bytes */
953 	__u32 output_hog_addr_offset;
954 	/* 160 bytes */
955 } __attribute__((packed));
956 
957 /**
958  * struct pisp_be_tiles_config - Raspberry Pi PiSP Back End configuration
959  * @tiles:	Tile descriptors
960  * @num_tiles:	Number of tiles
961  * @config:	PiSP Back End configuration
962  */
963 struct pisp_be_tiles_config {
964 	struct pisp_be_config config;
965 	struct pisp_tile tiles[PISP_BACK_END_NUM_TILES];
966 	__u32 num_tiles;
967 } __attribute__((packed));
968 
969 #endif /* _UAPI_PISP_BE_CONFIG_H_ */
970