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)
36 * All structs below are directly mapped onto the equivalent structs in
37 * drivers/staging/vc04_services/vchiq-mmal/mmal-parameters.h
42 * struct bcm2835_isp_rational - Rational value type.
47 struct bcm2835_isp_rational {
53 * struct bcm2835_isp_ccm - Colour correction matrix.
55 * @ccm: 3x3 correction matrix coefficients.
56 * @offsets: 1x3 correction offsets.
58 struct bcm2835_isp_ccm {
59 struct bcm2835_isp_rational ccm[3][3];
64 * struct bcm2835_isp_custom_ccm - Custom CCM applied with the
65 * V4L2_CID_USER_BCM2835_ISP_CC_MATRIX ctrl.
67 * @enabled: Enable custom CCM.
68 * @ccm: Custom CCM coefficients and offsets.
70 struct bcm2835_isp_custom_ccm {
72 struct bcm2835_isp_ccm ccm;
76 * enum bcm2835_isp_gain_format - format of the gains in the lens shading
77 * tables used with the
78 * V4L2_CID_USER_BCM2835_ISP_LENS_SHADING ctrl.
80 * @GAIN_FORMAT_U0P8_1: Gains are u0.8 format, starting at 1.0
81 * @GAIN_FORMAT_U1P7_0: Gains are u1.7 format, starting at 0.0
82 * @GAIN_FORMAT_U1P7_1: Gains are u1.7 format, starting at 1.0
83 * @GAIN_FORMAT_U2P6_0: Gains are u2.6 format, starting at 0.0
84 * @GAIN_FORMAT_U2P6_1: Gains are u2.6 format, starting at 1.0
85 * @GAIN_FORMAT_U3P5_0: Gains are u3.5 format, starting at 0.0
86 * @GAIN_FORMAT_U3P5_1: Gains are u3.5 format, starting at 1.0
87 * @GAIN_FORMAT_U4P10: Gains are u4.10 format, starting at 0.0
89 enum bcm2835_isp_gain_format {
90 GAIN_FORMAT_U0P8_1 = 0,
91 GAIN_FORMAT_U1P7_0 = 1,
92 GAIN_FORMAT_U1P7_1 = 2,
93 GAIN_FORMAT_U2P6_0 = 3,
94 GAIN_FORMAT_U2P6_1 = 4,
95 GAIN_FORMAT_U3P5_0 = 5,
96 GAIN_FORMAT_U3P5_1 = 6,
97 GAIN_FORMAT_U4P10 = 7,
101 * struct bcm2835_isp_lens_shading - Lens shading tables supplied with the
102 * V4L2_CID_USER_BCM2835_ISP_LENS_SHADING
105 * @enabled: Enable lens shading.
106 * @grid_cell_size: Size of grid cells in samples (16, 32, 64, 128 or 256).
107 * @grid_width: Width of lens shading tables in grid cells.
108 * @grid_stride: Row to row distance (in grid cells) between grid cells
109 * in the same horizontal location.
110 * @grid_height: Height of lens shading tables in grid cells.
111 * @mem_handle_table: Memory handle to the tables.
112 * @ref_transform: Reference transform - unsupported, please pass zero.
113 * @corner_sampled: Whether the gains are sampled at the corner points
114 * of the grid cells or in the cell centres.
115 * @gain_format: Format of the gains (see enum &bcm2835_isp_gain_format).
117 struct bcm2835_isp_lens_shading {
119 __u32 grid_cell_size;
123 __u32 mem_handle_table;
125 __u32 corner_sampled;
130 * struct bcm2835_isp_black_level - Sensor black level set with the
131 * V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL ctrl.
133 * @enabled: Enable black level.
134 * @black_level_r: Black level for red channel.
135 * @black_level_g: Black level for green channels.
136 * @black_level_b: Black level for blue channel.
138 struct bcm2835_isp_black_level {
143 __u8 padding[2]; /* Unused */
147 * struct bcm2835_isp_geq - Green equalisation parameters set with the
148 * V4L2_CID_USER_BCM2835_ISP_GEQ ctrl.
150 * @enabled: Enable green equalisation.
151 * @offset: Fixed offset of the green equalisation threshold.
152 * @slope: Slope of the green equalisation threshold.
154 struct bcm2835_isp_geq {
157 struct bcm2835_isp_rational slope;
160 #define BCM2835_NUM_GAMMA_PTS 33
163 * struct bcm2835_isp_gamma - Gamma parameters set with the
164 * V4L2_CID_USER_BCM2835_ISP_GAMMA ctrl.
166 * @enabled: Enable gamma adjustment.
167 * @X: X values of the points defining the gamma curve.
168 * Values should be scaled to 16 bits.
169 * @Y: Y values of the points defining the gamma curve.
170 * Values should be scaled to 16 bits.
172 struct bcm2835_isp_gamma {
174 __u16 x[BCM2835_NUM_GAMMA_PTS];
175 __u16 y[BCM2835_NUM_GAMMA_PTS];
179 * struct bcm2835_isp_denoise - Denoise parameters set with the
180 * V4L2_CID_USER_BCM2835_ISP_DENOISE ctrl.
182 * @enabled: Enable denoise.
183 * @constant: Fixed offset of the noise threshold.
184 * @slope: Slope of the noise threshold.
185 * @strength: Denoise strength between 0.0 (off) and 1.0 (maximum).
187 struct bcm2835_isp_denoise {
190 struct bcm2835_isp_rational slope;
191 struct bcm2835_isp_rational strength;
195 * struct bcm2835_isp_sharpen - Sharpen parameters set with the
196 * V4L2_CID_USER_BCM2835_ISP_SHARPEN ctrl.
198 * @enabled: Enable sharpening.
199 * @threshold: Threshold at which to start sharpening pixels.
200 * @strength: Strength with which pixel sharpening increases.
201 * @limit: Limit to the amount of sharpening applied.
203 struct bcm2835_isp_sharpen {
205 struct bcm2835_isp_rational threshold;
206 struct bcm2835_isp_rational strength;
207 struct bcm2835_isp_rational limit;
211 * enum bcm2835_isp_dpc_mode - defective pixel correction (DPC) strength.
213 * @DPC_MODE_OFF: No DPC.
214 * @DPC_MODE_NORMAL: Normal DPC.
215 * @DPC_MODE_STRONG: Strong DPC.
217 enum bcm2835_isp_dpc_mode {
224 * struct bcm2835_isp_dpc - Defective pixel correction (DPC) parameters set
225 * with the V4L2_CID_USER_BCM2835_ISP_DPC ctrl.
227 * @enabled: Enable DPC.
228 * @strength: DPC strength (see enum &bcm2835_isp_dpc_mode).
230 struct bcm2835_isp_dpc {
236 * ISP statistics structures.
238 * The bcm2835_isp_stats structure is generated at the output of the
239 * statistics node. Note that this does not directly map onto the statistics
240 * output of the ISP HW. Instead, the MMAL firmware code maps the HW statistics
241 * to the bcm2835_isp_stats structure.
243 #define DEFAULT_AWB_REGIONS_X 16
244 #define DEFAULT_AWB_REGIONS_Y 12
246 #define NUM_HISTOGRAMS 2
247 #define NUM_HISTOGRAM_BINS 128
248 #define AWB_REGIONS (DEFAULT_AWB_REGIONS_X * DEFAULT_AWB_REGIONS_Y)
249 #define FLOATING_REGIONS 16
250 #define AGC_REGIONS 16
251 #define FOCUS_REGIONS 12
254 * struct bcm2835_isp_stats_hist - Histogram statistics
256 * @r_hist: Red channel histogram.
257 * @g_hist: Combined green channel histogram.
258 * @b_hist: Blue channel histogram.
260 struct bcm2835_isp_stats_hist {
261 __u32 r_hist[NUM_HISTOGRAM_BINS];
262 __u32 g_hist[NUM_HISTOGRAM_BINS];
263 __u32 b_hist[NUM_HISTOGRAM_BINS];
267 * struct bcm2835_isp_stats_region - Region sums.
269 * @counted: The number of 2x2 bayer tiles accumulated.
270 * @notcounted: The number of 2x2 bayer tiles not accumulated.
271 * @r_sum: Total sum of counted pixels in the red channel for a region.
272 * @g_sum: Total sum of counted pixels in the green channel for a region.
273 * @b_sum: Total sum of counted pixels in the blue channel for a region.
275 struct bcm2835_isp_stats_region {
284 * struct bcm2835_isp_stats_focus - Focus statistics.
286 * @contrast_val: Focus measure - accumulated output of the focus filter.
287 * In the first dimension, index [0] counts pixels below a
288 * preset threshold, and index [1] counts pixels above the
289 * threshold. In the second dimension, index [0] uses the
290 * first predefined filter, and index [1] uses the second
292 * @contrast_val_num: The number of counted pixels in the above accumulation.
294 struct bcm2835_isp_stats_focus {
295 __u64 contrast_val[2][2];
296 __u32 contrast_val_num[2][2];
300 * struct bcm2835_isp_stats - ISP statistics.
302 * @version: Version of the bcm2835_isp_stats structure.
303 * @size: Size of the bcm2835_isp_stats structure.
304 * @hist: Histogram statistics for the entire image.
305 * @awb_stats: Statistics for the regions defined for AWB calculations.
306 * @floating_stats: Statistics for arbitrarily placed (floating) regions.
307 * @agc_stats: Statistics for the regions defined for AGC calculations.
308 * @focus_stats: Focus filter statistics for the focus regions.
310 struct bcm2835_isp_stats {
313 struct bcm2835_isp_stats_hist hist[NUM_HISTOGRAMS];
314 struct bcm2835_isp_stats_region awb_stats[AWB_REGIONS];
315 struct bcm2835_isp_stats_region floating_stats[FLOATING_REGIONS];
316 struct bcm2835_isp_stats_region agc_stats[AGC_REGIONS];
317 struct bcm2835_isp_stats_focus focus_stats[FOCUS_REGIONS];
320 #endif /* __BCM2835_ISP_H_ */