Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / include / uapi / linux / bcm2835-isp.h
1 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */
2 /*
3  * bcm2835-isp.h
4  *
5  * BCM2835 ISP driver - user space header file.
6  *
7  * Copyright © 2019-2020 Raspberry Pi (Trading) Ltd.
8  *
9  * Author: Naushir Patuck (naush@raspberrypi.com)
10  *
11  */
12
13 #ifndef __BCM2835_ISP_H_
14 #define __BCM2835_ISP_H_
15
16 #include <linux/v4l2-controls.h>
17
18 #define V4L2_CID_USER_BCM2835_ISP_CC_MATRIX     \
19                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0001)
20 #define V4L2_CID_USER_BCM2835_ISP_LENS_SHADING  \
21                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0002)
22 #define V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL   \
23                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0003)
24 #define V4L2_CID_USER_BCM2835_ISP_GEQ           \
25                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0004)
26 #define V4L2_CID_USER_BCM2835_ISP_GAMMA         \
27                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0005)
28 #define V4L2_CID_USER_BCM2835_ISP_DENOISE       \
29                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0006)
30 #define V4L2_CID_USER_BCM2835_ISP_SHARPEN       \
31                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0007)
32 #define V4L2_CID_USER_BCM2835_ISP_DPC           \
33                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0008)
34 #define V4L2_CID_USER_BCM2835_ISP_CDN \
35                                 (V4L2_CID_USER_BCM2835_ISP_BASE + 0x0009)
36
37 /*
38  * All structs below are directly mapped onto the equivalent structs in
39  * drivers/staging/vc04_services/vchiq-mmal/mmal-parameters.h
40  * for convenience.
41  */
42
43 /**
44  * struct bcm2835_isp_rational - Rational value type.
45  *
46  * @num:        Numerator.
47  * @den:        Denominator.
48  */
49 struct bcm2835_isp_rational {
50         __s32 num;
51         __u32 den;
52 };
53
54 /**
55  * struct bcm2835_isp_ccm - Colour correction matrix.
56  *
57  * @ccm:        3x3 correction matrix coefficients.
58  * @offsets:    1x3 correction offsets.
59  */
60 struct bcm2835_isp_ccm {
61         struct bcm2835_isp_rational ccm[3][3];
62         __s32 offsets[3];
63 };
64
65 /**
66  * struct bcm2835_isp_custom_ccm - Custom CCM applied with the
67  *                                 V4L2_CID_USER_BCM2835_ISP_CC_MATRIX ctrl.
68  *
69  * @enabled:    Enable custom CCM.
70  * @ccm:        Custom CCM coefficients and offsets.
71  */
72 struct bcm2835_isp_custom_ccm {
73         __u32 enabled;
74         struct bcm2835_isp_ccm ccm;
75 };
76
77 /**
78  * enum bcm2835_isp_gain_format - format of the gains in the lens shading
79  *                                tables used with the
80  *                                V4L2_CID_USER_BCM2835_ISP_LENS_SHADING ctrl.
81  *
82  * @GAIN_FORMAT_U0P8_1:         Gains are u0.8 format, starting at 1.0
83  * @GAIN_FORMAT_U1P7_0:         Gains are u1.7 format, starting at 0.0
84  * @GAIN_FORMAT_U1P7_1:         Gains are u1.7 format, starting at 1.0
85  * @GAIN_FORMAT_U2P6_0:         Gains are u2.6 format, starting at 0.0
86  * @GAIN_FORMAT_U2P6_1:         Gains are u2.6 format, starting at 1.0
87  * @GAIN_FORMAT_U3P5_0:         Gains are u3.5 format, starting at 0.0
88  * @GAIN_FORMAT_U3P5_1:         Gains are u3.5 format, starting at 1.0
89  * @GAIN_FORMAT_U4P10:          Gains are u4.10 format, starting at 0.0
90  */
91 enum bcm2835_isp_gain_format {
92         GAIN_FORMAT_U0P8_1 = 0,
93         GAIN_FORMAT_U1P7_0 = 1,
94         GAIN_FORMAT_U1P7_1 = 2,
95         GAIN_FORMAT_U2P6_0 = 3,
96         GAIN_FORMAT_U2P6_1 = 4,
97         GAIN_FORMAT_U3P5_0 = 5,
98         GAIN_FORMAT_U3P5_1 = 6,
99         GAIN_FORMAT_U4P10  = 7,
100 };
101
102 /**
103  * struct bcm2835_isp_lens_shading - Lens shading tables supplied with the
104  *                                   V4L2_CID_USER_BCM2835_ISP_LENS_SHADING
105  *                                   ctrl.
106  *
107  * @enabled:            Enable lens shading.
108  * @grid_cell_size:     Size of grid cells in samples (16, 32, 64, 128 or 256).
109  * @grid_width:         Width of lens shading tables in grid cells.
110  * @grid_stride:        Row to row distance (in grid cells) between grid cells
111  *                      in the same horizontal location.
112  * @grid_height:        Height of lens shading tables in grid cells.
113  * @dmabuf:             dmabuf file handle containing the table.
114  * @ref_transform:      Reference transform - unsupported, please pass zero.
115  * @corner_sampled:     Whether the gains are sampled at the corner points
116  *                      of the grid cells or in the cell centres.
117  * @gain_format:        Format of the gains (see enum &bcm2835_isp_gain_format).
118  */
119 struct bcm2835_isp_lens_shading {
120         __u32 enabled;
121         __u32 grid_cell_size;
122         __u32 grid_width;
123         __u32 grid_stride;
124         __u32 grid_height;
125         __s32 dmabuf;
126         __u32 ref_transform;
127         __u32 corner_sampled;
128         __u32 gain_format;
129 };
130
131 /**
132  * struct bcm2835_isp_black_level - Sensor black level set with the
133  *                                  V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL ctrl.
134  *
135  * @enabled:            Enable black level.
136  * @black_level_r:      Black level for red channel.
137  * @black_level_g:      Black level for green channels.
138  * @black_level_b:      Black level for blue channel.
139  */
140 struct bcm2835_isp_black_level {
141         __u32 enabled;
142         __u16 black_level_r;
143         __u16 black_level_g;
144         __u16 black_level_b;
145         __u8 padding[2]; /* Unused */
146 };
147
148 /**
149  * struct bcm2835_isp_geq - Green equalisation parameters set with the
150  *                          V4L2_CID_USER_BCM2835_ISP_GEQ ctrl.
151  *
152  * @enabled:    Enable green equalisation.
153  * @offset:     Fixed offset of the green equalisation threshold.
154  * @slope:      Slope of the green equalisation threshold.
155  */
156 struct bcm2835_isp_geq {
157         __u32 enabled;
158         __u32 offset;
159         struct bcm2835_isp_rational slope;
160 };
161
162 #define BCM2835_NUM_GAMMA_PTS 33
163
164 /**
165  * struct bcm2835_isp_gamma - Gamma parameters set with the
166  *                            V4L2_CID_USER_BCM2835_ISP_GAMMA ctrl.
167  *
168  * @enabled:    Enable gamma adjustment.
169  * @X:          X values of the points defining the gamma curve.
170  *              Values should be scaled to 16 bits.
171  * @Y:          Y values of the points defining the gamma curve.
172  *              Values should be scaled to 16 bits.
173  */
174 struct bcm2835_isp_gamma {
175         __u32 enabled;
176         __u16 x[BCM2835_NUM_GAMMA_PTS];
177         __u16 y[BCM2835_NUM_GAMMA_PTS];
178 };
179
180 /**
181  * enum bcm2835_isp_cdn_mode - Mode of operation for colour denoise.
182  *
183  * @CDN_MODE_FAST:              Fast (but lower quality) colour denoise
184  *                              algorithm, typically used for video recording.
185  * @CDN_HIGH_QUALITY:           High quality (but slower) colour denoise
186  *                              algorithm, typically used for stills capture.
187  */
188 enum bcm2835_isp_cdn_mode {
189         CDN_MODE_FAST = 0,
190         CDN_MODE_HIGH_QUALITY = 1,
191 };
192
193 /**
194  * struct bcm2835_isp_cdn - Colour denoise parameters set with the
195  *                          V4L2_CID_USER_BCM2835_ISP_CDN ctrl.
196  *
197  * @enabled:    Enable colour denoise.
198  * @mode:       Colour denoise operating mode (see enum &bcm2835_isp_cdn_mode)
199  */
200 struct bcm2835_isp_cdn {
201         __u32 enabled;
202         __u32 mode;
203 };
204
205 /**
206  * struct bcm2835_isp_denoise - Denoise parameters set with the
207  *                              V4L2_CID_USER_BCM2835_ISP_DENOISE ctrl.
208  *
209  * @enabled:    Enable denoise.
210  * @constant:   Fixed offset of the noise threshold.
211  * @slope:      Slope of the noise threshold.
212  * @strength:   Denoise strength between 0.0 (off) and 1.0 (maximum).
213  */
214 struct bcm2835_isp_denoise {
215         __u32 enabled;
216         __u32 constant;
217         struct bcm2835_isp_rational slope;
218         struct bcm2835_isp_rational strength;
219 };
220
221 /**
222  * struct bcm2835_isp_sharpen - Sharpen parameters set with the
223  *                              V4L2_CID_USER_BCM2835_ISP_SHARPEN ctrl.
224  *
225  * @enabled:    Enable sharpening.
226  * @threshold:  Threshold at which to start sharpening pixels.
227  * @strength:   Strength with which pixel sharpening increases.
228  * @limit:      Limit to the amount of sharpening applied.
229  */
230 struct bcm2835_isp_sharpen {
231         __u32 enabled;
232         struct bcm2835_isp_rational threshold;
233         struct bcm2835_isp_rational strength;
234         struct bcm2835_isp_rational limit;
235 };
236
237 /**
238  * enum bcm2835_isp_dpc_mode - defective pixel correction (DPC) strength.
239  *
240  * @DPC_MODE_OFF:               No DPC.
241  * @DPC_MODE_NORMAL:            Normal DPC.
242  * @DPC_MODE_STRONG:            Strong DPC.
243  */
244 enum bcm2835_isp_dpc_mode {
245         DPC_MODE_OFF = 0,
246         DPC_MODE_NORMAL = 1,
247         DPC_MODE_STRONG = 2,
248 };
249
250 /**
251  * struct bcm2835_isp_dpc - Defective pixel correction (DPC) parameters set
252  *                          with the V4L2_CID_USER_BCM2835_ISP_DPC ctrl.
253  *
254  * @enabled:    Enable DPC.
255  * @strength:   DPC strength (see enum &bcm2835_isp_dpc_mode).
256  */
257 struct bcm2835_isp_dpc {
258         __u32 enabled;
259         __u32 strength;
260 };
261
262 /*
263  * ISP statistics structures.
264  *
265  * The bcm2835_isp_stats structure is generated at the output of the
266  * statistics node.  Note that this does not directly map onto the statistics
267  * output of the ISP HW.  Instead, the MMAL firmware code maps the HW statistics
268  * to the bcm2835_isp_stats structure.
269  */
270 #define DEFAULT_AWB_REGIONS_X 16
271 #define DEFAULT_AWB_REGIONS_Y 12
272
273 #define NUM_HISTOGRAMS 2
274 #define NUM_HISTOGRAM_BINS 128
275 #define AWB_REGIONS (DEFAULT_AWB_REGIONS_X * DEFAULT_AWB_REGIONS_Y)
276 #define FLOATING_REGIONS 16
277 #define AGC_REGIONS 16
278 #define FOCUS_REGIONS 12
279
280 /**
281  * struct bcm2835_isp_stats_hist - Histogram statistics
282  *
283  * @r_hist:     Red channel histogram.
284  * @g_hist:     Combined green channel histogram.
285  * @b_hist:     Blue channel histogram.
286  */
287 struct bcm2835_isp_stats_hist {
288         __u32 r_hist[NUM_HISTOGRAM_BINS];
289         __u32 g_hist[NUM_HISTOGRAM_BINS];
290         __u32 b_hist[NUM_HISTOGRAM_BINS];
291 };
292
293 /**
294  * struct bcm2835_isp_stats_region - Region sums.
295  *
296  * @counted:    The number of 2x2 bayer tiles accumulated.
297  * @notcounted: The number of 2x2 bayer tiles not accumulated.
298  * @r_sum:      Total sum of counted pixels in the red channel for a region.
299  * @g_sum:      Total sum of counted pixels in the green channel for a region.
300  * @b_sum:      Total sum of counted pixels in the blue channel for a region.
301  */
302 struct bcm2835_isp_stats_region {
303         __u32 counted;
304         __u32 notcounted;
305         __u64 r_sum;
306         __u64 g_sum;
307         __u64 b_sum;
308 };
309
310 /**
311  * struct bcm2835_isp_stats_focus - Focus statistics.
312  *
313  * @contrast_val:       Focus measure - accumulated output of the focus filter.
314  *                      In the first dimension, index [0] counts pixels below a
315  *                      preset threshold, and index [1] counts pixels above the
316  *                      threshold.  In the second dimension, index [0] uses the
317  *                      first predefined filter, and index [1] uses the second
318  *                      predefined filter.
319  * @contrast_val_num:   The number of counted pixels in the above accumulation.
320  */
321 struct bcm2835_isp_stats_focus {
322         __u64 contrast_val[2][2];
323         __u32 contrast_val_num[2][2];
324 };
325
326 /**
327  * struct bcm2835_isp_stats - ISP statistics.
328  *
329  * @version:            Version of the bcm2835_isp_stats structure.
330  * @size:               Size of the bcm2835_isp_stats structure.
331  * @hist:               Histogram statistics for the entire image.
332  * @awb_stats:          Statistics for the regions defined for AWB calculations.
333  * @floating_stats:     Statistics for arbitrarily placed (floating) regions.
334  * @agc_stats:          Statistics for the regions defined for AGC calculations.
335  * @focus_stats:        Focus filter statistics for the focus regions.
336  */
337 struct bcm2835_isp_stats {
338         __u32 version;
339         __u32 size;
340         struct bcm2835_isp_stats_hist hist[NUM_HISTOGRAMS];
341         struct bcm2835_isp_stats_region awb_stats[AWB_REGIONS];
342         struct bcm2835_isp_stats_region floating_stats[FLOATING_REGIONS];
343         struct bcm2835_isp_stats_region agc_stats[AGC_REGIONS];
344         struct bcm2835_isp_stats_focus focus_stats[FOCUS_REGIONS];
345 };
346
347 #endif /* __BCM2835_ISP_H_ */