1 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */
5 * BCM2835 ISP driver - user space header file.
7 * Copyright © 2019-2020 Raspberry Pi (Trading) Ltd.
9 * Author: Naushir Patuck (naush@raspberrypi.com)
13 #ifndef __BCM2835_ISP_H_
14 #define __BCM2835_ISP_H_
16 #include <linux/v4l2-controls.h>
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)
38 * All structs below are directly mapped onto the equivalent structs in
39 * drivers/staging/vc04_services/vchiq-mmal/mmal-parameters.h
44 * struct bcm2835_isp_rational - Rational value type.
49 struct bcm2835_isp_rational {
55 * struct bcm2835_isp_ccm - Colour correction matrix.
57 * @ccm: 3x3 correction matrix coefficients.
58 * @offsets: 1x3 correction offsets.
60 struct bcm2835_isp_ccm {
61 struct bcm2835_isp_rational ccm[3][3];
66 * struct bcm2835_isp_custom_ccm - Custom CCM applied with the
67 * V4L2_CID_USER_BCM2835_ISP_CC_MATRIX ctrl.
69 * @enabled: Enable custom CCM.
70 * @ccm: Custom CCM coefficients and offsets.
72 struct bcm2835_isp_custom_ccm {
74 struct bcm2835_isp_ccm ccm;
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.
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
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,
103 * struct bcm2835_isp_lens_shading - Lens shading tables supplied with the
104 * V4L2_CID_USER_BCM2835_ISP_LENS_SHADING
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).
119 struct bcm2835_isp_lens_shading {
121 __u32 grid_cell_size;
127 __u32 corner_sampled;
132 * struct bcm2835_isp_black_level - Sensor black level set with the
133 * V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL ctrl.
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.
140 struct bcm2835_isp_black_level {
145 __u8 padding[2]; /* Unused */
149 * struct bcm2835_isp_geq - Green equalisation parameters set with the
150 * V4L2_CID_USER_BCM2835_ISP_GEQ ctrl.
152 * @enabled: Enable green equalisation.
153 * @offset: Fixed offset of the green equalisation threshold.
154 * @slope: Slope of the green equalisation threshold.
156 struct bcm2835_isp_geq {
159 struct bcm2835_isp_rational slope;
162 #define BCM2835_NUM_GAMMA_PTS 33
165 * struct bcm2835_isp_gamma - Gamma parameters set with the
166 * V4L2_CID_USER_BCM2835_ISP_GAMMA ctrl.
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.
174 struct bcm2835_isp_gamma {
176 __u16 x[BCM2835_NUM_GAMMA_PTS];
177 __u16 y[BCM2835_NUM_GAMMA_PTS];
181 * enum bcm2835_isp_cdn_mode - Mode of operation for colour denoise.
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.
188 enum bcm2835_isp_cdn_mode {
190 CDN_MODE_HIGH_QUALITY = 1,
194 * struct bcm2835_isp_cdn - Colour denoise parameters set with the
195 * V4L2_CID_USER_BCM2835_ISP_CDN ctrl.
197 * @enabled: Enable colour denoise.
198 * @mode: Colour denoise operating mode (see enum &bcm2835_isp_cdn_mode)
200 struct bcm2835_isp_cdn {
206 * struct bcm2835_isp_denoise - Denoise parameters set with the
207 * V4L2_CID_USER_BCM2835_ISP_DENOISE ctrl.
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).
214 struct bcm2835_isp_denoise {
217 struct bcm2835_isp_rational slope;
218 struct bcm2835_isp_rational strength;
222 * struct bcm2835_isp_sharpen - Sharpen parameters set with the
223 * V4L2_CID_USER_BCM2835_ISP_SHARPEN ctrl.
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.
230 struct bcm2835_isp_sharpen {
232 struct bcm2835_isp_rational threshold;
233 struct bcm2835_isp_rational strength;
234 struct bcm2835_isp_rational limit;
238 * enum bcm2835_isp_dpc_mode - defective pixel correction (DPC) strength.
240 * @DPC_MODE_OFF: No DPC.
241 * @DPC_MODE_NORMAL: Normal DPC.
242 * @DPC_MODE_STRONG: Strong DPC.
244 enum bcm2835_isp_dpc_mode {
251 * struct bcm2835_isp_dpc - Defective pixel correction (DPC) parameters set
252 * with the V4L2_CID_USER_BCM2835_ISP_DPC ctrl.
254 * @enabled: Enable DPC.
255 * @strength: DPC strength (see enum &bcm2835_isp_dpc_mode).
257 struct bcm2835_isp_dpc {
263 * ISP statistics structures.
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.
270 #define DEFAULT_AWB_REGIONS_X 16
271 #define DEFAULT_AWB_REGIONS_Y 12
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
281 * struct bcm2835_isp_stats_hist - Histogram statistics
283 * @r_hist: Red channel histogram.
284 * @g_hist: Combined green channel histogram.
285 * @b_hist: Blue channel histogram.
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];
294 * struct bcm2835_isp_stats_region - Region sums.
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.
302 struct bcm2835_isp_stats_region {
311 * struct bcm2835_isp_stats_focus - Focus statistics.
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
319 * @contrast_val_num: The number of counted pixels in the above accumulation.
321 struct bcm2835_isp_stats_focus {
322 __u64 contrast_val[2][2];
323 __u32 contrast_val_num[2][2];
327 * struct bcm2835_isp_stats - ISP statistics.
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.
337 struct bcm2835_isp_stats {
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];
347 #endif /* __BCM2835_ISP_H_ */