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