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