xref: /linux/include/uapi/linux/media/arm/mali-c55-config.h (revision f4cdf7ca9a1fdcca413157df19753f388a5a224e)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * ARM Mali-C55 ISP Driver - Userspace API
4  *
5  * Copyright (C) 2023 Ideas on Board Oy
6  */
7 
8 #ifndef __UAPI_MALI_C55_CONFIG_H
9 #define __UAPI_MALI_C55_CONFIG_H
10 
11 #include <linux/types.h>
12 #include <linux/v4l2-controls.h>
13 #include <linux/media/v4l2-isp.h>
14 
15 #define V4L2_CID_MALI_C55_CAPABILITIES	(V4L2_CID_USER_MALI_C55_BASE + 0x0)
16 #define MALI_C55_GPS_PONG		(1U << 0)
17 #define MALI_C55_GPS_WDR		(1U << 1)
18 #define MALI_C55_GPS_COMPRESSION	(1U << 2)
19 #define MALI_C55_GPS_TEMPER		(1U << 3)
20 #define MALI_C55_GPS_SINTER_LITE	(1U << 4)
21 #define MALI_C55_GPS_SINTER		(1U << 5)
22 #define MALI_C55_GPS_IRIDIX_LTM		(1U << 6)
23 #define MALI_C55_GPS_IRIDIX_GTM		(1U << 7)
24 #define MALI_C55_GPS_CNR		(1U << 8)
25 #define MALI_C55_GPS_FRSCALER		(1U << 9)
26 #define MALI_C55_GPS_DS_PIPE		(1U << 10)
27 
28 /*
29  * Frames are split into zones of almost equal width and height - a zone is a
30  * rectangular tile of a frame. The metering blocks within the ISP collect
31  * aggregated statistics per zone. A maximum of 15x15 zones can be configured,
32  * and so the statistics buffer within the hardware is sized to accommodate
33  * that.
34  *
35  * The utilised number of zones is runtime configurable.
36  */
37 #define MALI_C55_MAX_ZONES	(15 * 15)
38 
39 /* Number of RGB gamma LUT entries. */
40 #define MALI_C55_NUM_GAMMA_LUT_ELEMENTS 129
41 
42 /**
43  * struct mali_c55_ae_1024bin_hist - Auto Exposure 1024-bin histogram statistics
44  *
45  * @bins:	1024 element array of 16-bit pixel counts.
46  *
47  * The 1024-bin histogram module collects image-global but zone-weighted
48  * intensity distributions of pixels in fixed-width bins. The modules can be
49  * configured into different "plane modes" which affect the contents of the
50  * collected statistics. In plane mode 0, pixel intensities are taken regardless
51  * of colour plane into a single 1024-bin histogram with a bin width of 4. In
52  * plane mode 1, four 256-bin histograms with a bin width of 16 are collected -
53  * one for each CFA colour plane. In plane modes 4, 5, 6 and 7 two 512-bin
54  * histograms with a bin width of 8 are collected - in each mode one of the
55  * colour planes is collected into the first histogram and all the others are
56  * combined into the second. The histograms are stored consecutively in the bins
57  * array.
58  *
59  * The 16-bit pixel counts are stored as a 4-bit exponent in the most
60  * significant bits followed by a 12-bit mantissa. Conversion to a usable
61  * format can be done according to the following pseudo-code::
62  *
63  *	if (e == 0) {
64  *		bin = m * 2;
65  *	} else {
66  *		bin = (m + 4096) * 2^e
67  *	}
68  *
69  * where
70  *	e is the exponent value in range 0..15
71  *	m is the mantissa value in range 0..4095
72  *
73  * The pixels used in calculating the statistics can be masked using three
74  * methods:
75  *
76  * 1. Pixels can be skipped in X and Y directions independently.
77  * 2. Minimum/Maximum intensities can be configured
78  * 3. Zones can be differentially weighted, including 0 weighted to mask them
79  *
80  * The data for this histogram can be collected from different tap points in the
81  * ISP depending on configuration - after the white balance or digital gain
82  * blocks, or immediately after the input crossbar.
83  */
84 struct mali_c55_ae_1024bin_hist {
85 	__u16 bins[1024];
86 } __attribute__((packed));
87 
88 /**
89  * struct mali_c55_ae_5bin_hist - Auto Exposure 5-bin histogram statistics
90  *
91  * @hist0:	16-bit normalised pixel count for the 0th intensity bin
92  * @hist1:	16-bit normalised pixel count for the 1st intensity bin
93  * @hist3:	16-bit normalised pixel count for the 3rd intensity bin
94  * @hist4:	16-bit normalised pixel count for the 4th intensity bin
95  *
96  * The ISP generates a 5-bin histogram of normalised pixel counts within bins of
97  * pixel intensity for each of 225 possible zones within a frame. The centre bin
98  * of the histogram for each zone is not available from the hardware and must be
99  * calculated by subtracting the values of hist0, hist1, hist3 and hist4 from
100  * 0xffff as in the following equation:
101  *
102  *	hist2 = 0xffff - (hist0 + hist1 + hist3 + hist4)
103  */
104 struct mali_c55_ae_5bin_hist {
105 	__u16 hist0;
106 	__u16 hist1;
107 	__u16 hist3;
108 	__u16 hist4;
109 } __attribute__((packed));
110 
111 /**
112  * struct mali_c55_awb_average_ratios - Auto White Balance colour ratios
113  *
114  * @avg_rg_gr:	Average R/G or G/R ratio in Q4.8 format.
115  * @avg_bg_br:	Average B/G or B/R ratio in Q4.8 format.
116  * @num_pixels:	The number of pixels used in the AWB calculation
117  *
118  * The ISP calculates and collects average colour ratios for each zone in an
119  * image and stores them in Q4.8 format (the lowest 8 bits are fractional, with
120  * bits [11:8] representing the integer). The exact ratios collected (either
121  * R/G, B/G or G/R, B/R) are configurable through the parameters buffer. The
122  * value of the 4 high bits is undefined.
123  */
124 struct mali_c55_awb_average_ratios {
125 	__u16 avg_rg_gr;
126 	__u16 avg_bg_br;
127 	__u32 num_pixels;
128 } __attribute__((packed));
129 
130 /**
131  * struct mali_c55_af_statistics - Auto Focus edge and intensity statistics
132  *
133  * @intensity_stats:	Packed mantissa and exponent value for pixel intensity
134  * @edge_stats:		Packed mantissa and exponent values for edge intensity
135  *
136  * The ISP collects the squared sum of pixel intensities for each zone within a
137  * configurable Region of Interest on the frame. Additionally, the same data are
138  * collected after being passed through a bandpass filter which removes high and
139  * low frequency components - these are referred to as the edge statistics.
140  *
141  * The intensity and edge statistics for a zone can be used to calculate the
142  * contrast information for a zone
143  *
144  *	C = E2 / I2
145  *
146  * Where I2 is the intensity statistic for a zone and E2 is the edge statistic
147  * for that zone. Optimum focus is reached when C is at its maximum.
148  *
149  * The intensity and edge statistics are stored packed into a non-standard 16
150  * bit floating point format, where the 7 most significant bits represent the
151  * exponent and the 9 least significant bits the mantissa. This format can be
152  * unpacked with the following pseudocode::
153  *
154  *	if (e == 0) {
155  *		x = m;
156  *	} else {
157  *		x = 2^e-1 * (m + 2^9)
158  *	}
159  *
160  * where
161  *	e is the exponent value in range 0..127
162  *	m is the mantissa value in range 0..511
163  */
164 struct mali_c55_af_statistics {
165 	__u16 intensity_stats;
166 	__u16 edge_stats;
167 } __attribute__((packed));
168 
169 /**
170  * struct mali_c55_stats_buffer - 3A statistics for the mali-c55 ISP
171  *
172  * @ae_1024bin_hist:		1024-bin frame-global pixel intensity histogram
173  * @iridix_1024bin_hist:	Post-Iridix block 1024-bin histogram
174  * @ae_5bin_hists:		5-bin pixel intensity histograms for AEC
175  * @reserved1:			Undefined buffer space
176  * @awb_ratios:			Color balance ratios for Auto White Balance
177  * @reserved2:			Undefined buffer space
178  * @af_statistics:		Pixel intensity statistics for Auto Focus
179  * @reserved3:			Undefined buffer space
180  *
181  * This struct describes the metering statistics space in the Mali-C55 ISP's
182  * hardware in its entirety. The space between each defined area is marked as
183  * "unknown" and may not be 0, but should not be used. The @ae_5bin_hists,
184  * @awb_ratios and @af_statistics members are arrays of statistics per-zone.
185  * The zones are arranged in the array in raster order starting from the top
186  * left corner of the image.
187  */
188 
189 struct mali_c55_stats_buffer {
190 	struct mali_c55_ae_1024bin_hist ae_1024bin_hist;
191 	struct mali_c55_ae_1024bin_hist iridix_1024bin_hist;
192 	struct mali_c55_ae_5bin_hist ae_5bin_hists[MALI_C55_MAX_ZONES];
193 	__u32 reserved1[14];
194 	struct mali_c55_awb_average_ratios awb_ratios[MALI_C55_MAX_ZONES];
195 	__u32 reserved2[14];
196 	struct mali_c55_af_statistics af_statistics[MALI_C55_MAX_ZONES];
197 	__u32 reserved3[15];
198 } __attribute__((packed));
199 
200 /**
201  * enum mali_c55_param_block_type - Enumeration of Mali-C55 parameter blocks
202  *
203  * This enumeration defines the types of Mali-C55 parameters block. Each block
204  * configures a specific processing block of the Mali-C55 ISP. The block
205  * type allows the driver to correctly interpret the parameters block data.
206  *
207  * It is the responsibility of userspace to correctly set the type of each
208  * parameters block.
209  *
210  * @MALI_C55_PARAM_BLOCK_SENSOR_OFFS: Sensor pre-shading black level offset
211  * @MALI_C55_PARAM_BLOCK_AEXP_HIST: Auto-exposure 1024-bin histogram
212  *				    configuration
213  * @MALI_C55_PARAM_BLOCK_AEXP_IHIST: Post-Iridix auto-exposure 1024-bin
214  *				     histogram configuration
215  * @MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS: Auto-exposure 1024-bin histogram
216  *					    weighting
217  * @MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS: Post-Iridix auto-exposure 1024-bin
218  *					     histogram weighting
219  * @MALI_C55_PARAM_BLOCK_DIGITAL_GAIN: Digital gain
220  * @MALI_C55_PARAM_BLOCK_AWB_GAINS: Auto-white balance gains
221  * @MALI_C55_PARAM_BLOCK_AWB_CONFIG: Auto-white balance statistics config
222  * @MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP: Auto-white balance gains for AEXP-0 tap
223  * @MALI_C55_PARAM_MESH_SHADING_CONFIG : Mesh shading tables configuration
224  * @MALI_C55_PARAM_MESH_SHADING_SELECTION: Mesh shading table selection
225  * @MALI_C55_PARAM_BLOCK_CCM: Colour correction matrix
226  * @MALI_C55_PARAM_BLOCK_GAMMA_FR: Gamma gain and offset for FR pipe
227  * @MALI_C55_PARAM_BLOCK_GAMMA_DS: Gamma gain and offset for DS pipe
228  */
229 enum mali_c55_param_block_type {
230 	MALI_C55_PARAM_BLOCK_SENSOR_OFFS,
231 	MALI_C55_PARAM_BLOCK_AEXP_HIST,
232 	MALI_C55_PARAM_BLOCK_AEXP_IHIST,
233 	MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS,
234 	MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS,
235 	MALI_C55_PARAM_BLOCK_DIGITAL_GAIN,
236 	MALI_C55_PARAM_BLOCK_AWB_GAINS,
237 	MALI_C55_PARAM_BLOCK_AWB_CONFIG,
238 	MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP,
239 	MALI_C55_PARAM_MESH_SHADING_CONFIG,
240 	MALI_C55_PARAM_MESH_SHADING_SELECTION,
241 	MALI_C55_PARAM_BLOCK_CCM,
242 	MALI_C55_PARAM_BLOCK_GAMMA_FR,
243 	MALI_C55_PARAM_BLOCK_GAMMA_DS,
244 };
245 
246 /**
247  * struct mali_c55_params_sensor_off_preshading - offset subtraction for each
248  *						  color channel
249  *
250  * Provides removal of the sensor black level from the sensor data. Separate
251  * offsets are provided for each of the four Bayer component color channels
252  * which are defaulted to R, Gr, Gb, B.
253  *
254  * header.type should be set to MALI_C55_PARAM_BLOCK_SENSOR_OFFS from
255  * :c:type:`mali_c55_param_block_type` for this block.
256  *
257  * @header: The Mali-C55 parameters block header
258  * @chan00: Offset for color channel 00 (default: R)
259  * @chan01: Offset for color channel 01 (default: Gr)
260  * @chan10: Offset for color channel 10 (default: Gb)
261  * @chan11: Offset for color channel 11 (default: B)
262  */
263 struct mali_c55_params_sensor_off_preshading {
264 	struct v4l2_isp_params_block_header header;
265 	__u32 chan00;
266 	__u32 chan01;
267 	__u32 chan10;
268 	__u32 chan11;
269 };
270 
271 /**
272  * enum mali_c55_aexp_hist_tap_points - Tap points for the AEXP histogram
273  * @MALI_C55_AEXP_HIST_TAP_WB: After static white balance
274  * @MALI_C55_AEXP_HIST_TAP_FS: After WDR Frame Stitch
275  * @MALI_C55_AEXP_HIST_TAP_TPG: After the test pattern generator
276  */
277 enum mali_c55_aexp_hist_tap_points {
278 	MALI_C55_AEXP_HIST_TAP_WB = 0,
279 	MALI_C55_AEXP_HIST_TAP_FS,
280 	MALI_C55_AEXP_HIST_TAP_TPG,
281 };
282 
283 /**
284  * enum mali_c55_aexp_skip_x - Horizontal pixel skipping
285  * @MALI_C55_AEXP_SKIP_X_EVERY_2ND: Collect every 2nd pixel horizontally
286  * @MALI_C55_AEXP_SKIP_X_EVERY_3RD: Collect every 3rd pixel horizontally
287  * @MALI_C55_AEXP_SKIP_X_EVERY_4TH: Collect every 4th pixel horizontally
288  * @MALI_C55_AEXP_SKIP_X_EVERY_5TH: Collect every 5th pixel horizontally
289  * @MALI_C55_AEXP_SKIP_X_EVERY_8TH: Collect every 8th pixel horizontally
290  * @MALI_C55_AEXP_SKIP_X_EVERY_9TH: Collect every 9th pixel horizontally
291  */
292 enum mali_c55_aexp_skip_x {
293 	MALI_C55_AEXP_SKIP_X_EVERY_2ND,
294 	MALI_C55_AEXP_SKIP_X_EVERY_3RD,
295 	MALI_C55_AEXP_SKIP_X_EVERY_4TH,
296 	MALI_C55_AEXP_SKIP_X_EVERY_5TH,
297 	MALI_C55_AEXP_SKIP_X_EVERY_8TH,
298 	MALI_C55_AEXP_SKIP_X_EVERY_9TH
299 };
300 
301 /**
302  * enum mali_c55_aexp_skip_y - Vertical pixel skipping
303  * @MALI_C55_AEXP_SKIP_Y_ALL: Collect every single pixel vertically
304  * @MALI_C55_AEXP_SKIP_Y_EVERY_2ND: Collect every 2nd pixel vertically
305  * @MALI_C55_AEXP_SKIP_Y_EVERY_3RD: Collect every 3rd pixel vertically
306  * @MALI_C55_AEXP_SKIP_Y_EVERY_4TH: Collect every 4th pixel vertically
307  * @MALI_C55_AEXP_SKIP_Y_EVERY_5TH: Collect every 5th pixel vertically
308  * @MALI_C55_AEXP_SKIP_Y_EVERY_8TH: Collect every 8th pixel vertically
309  * @MALI_C55_AEXP_SKIP_Y_EVERY_9TH: Collect every 9th pixel vertically
310  */
311 enum mali_c55_aexp_skip_y {
312 	MALI_C55_AEXP_SKIP_Y_ALL,
313 	MALI_C55_AEXP_SKIP_Y_EVERY_2ND,
314 	MALI_C55_AEXP_SKIP_Y_EVERY_3RD,
315 	MALI_C55_AEXP_SKIP_Y_EVERY_4TH,
316 	MALI_C55_AEXP_SKIP_Y_EVERY_5TH,
317 	MALI_C55_AEXP_SKIP_Y_EVERY_8TH,
318 	MALI_C55_AEXP_SKIP_Y_EVERY_9TH
319 };
320 
321 /**
322  * enum mali_c55_aexp_row_column_offset - Start from the first or second row or
323  *					  column
324  * @MALI_C55_AEXP_FIRST_ROW_OR_COL:	Start from the first row / column
325  * @MALI_C55_AEXP_SECOND_ROW_OR_COL:	Start from the second row / column
326  */
327 enum mali_c55_aexp_row_column_offset {
328 	MALI_C55_AEXP_FIRST_ROW_OR_COL = 1,
329 	MALI_C55_AEXP_SECOND_ROW_OR_COL = 2,
330 };
331 
332 /**
333  * enum mali_c55_aexp_hist_plane_mode - Mode for the AEXP Histograms
334  * @MALI_C55_AEXP_HIST_COMBINED: All color planes in one 1024-bin histogram
335  * @MALI_C55_AEXP_HIST_SEPARATE: Each color plane in one 256-bin histogram with a bin width of 16
336  * @MALI_C55_AEXP_HIST_FOCUS_00: Top left plane in the first bank, rest in second bank
337  * @MALI_C55_AEXP_HIST_FOCUS_01: Top right plane in the first bank, rest in second bank
338  * @MALI_C55_AEXP_HIST_FOCUS_10: Bottom left plane in the first bank, rest in second bank
339  * @MALI_C55_AEXP_HIST_FOCUS_11: Bottom right plane in the first bank, rest in second bank
340  *
341  * In the "focus" modes statistics are collected into two 512-bin histograms
342  * with a bin width of 8. One colour plane is in the first histogram with the
343  * remainder combined into the second. The four options represent which of the
344  * four positions in a bayer pattern are the focused plane.
345  */
346 enum mali_c55_aexp_hist_plane_mode {
347 	MALI_C55_AEXP_HIST_COMBINED = 0,
348 	MALI_C55_AEXP_HIST_SEPARATE = 1,
349 	MALI_C55_AEXP_HIST_FOCUS_00 = 4,
350 	MALI_C55_AEXP_HIST_FOCUS_01 = 5,
351 	MALI_C55_AEXP_HIST_FOCUS_10 = 6,
352 	MALI_C55_AEXP_HIST_FOCUS_11 = 7,
353 };
354 
355 /**
356  * struct mali_c55_params_aexp_hist - configuration for AEXP metering hists
357  *
358  * This struct allows users to configure the 1024-bin AEXP histograms. Broadly
359  * speaking the parameters allow you to mask particular regions of the image and
360  * to select different kinds of histogram.
361  *
362  * The skip_x, offset_x, skip_y and offset_y fields allow users to ignore or
363  * mask pixels in the frame by their position relative to the top left pixel.
364  * First, the skip_y, offset_x and offset_y fields define which of the pixels
365  * within each 2x2 region will be counted in the statistics.
366  *
367  * If skip_y == 0 then two pixels from each covered region will be counted. If
368  * both offset_x and offset_y are zero, then the two left-most pixels in each
369  * 2x2 pixel region will be counted. Setting offset_x = 1 will discount the top
370  * left pixel and count the top right pixel. Setting offset_y = 1 will discount
371  * the bottom left pixel and count the bottom right pixel.
372  *
373  * If skip_y != 0 then only a single pixel from each region covered by the
374  * pattern will be counted. In this case offset_x controls whether the pixel
375  * that's counted is in the left (if offset_x == 0) or right (if offset_x == 1)
376  * column and offset_y controls whether the pixel that's counted is in the top
377  * (if offset_y == 0) or bottom (if offset_y == 1) row.
378  *
379  * The skip_x and skip_y fields control how the 2x2 pixel region is repeated
380  * across the image data. The first instance of the region is always in the top
381  * left of the image data. The skip_x field controls how many pixels are ignored
382  * in the x direction before the pixel masking region is repeated. The skip_y
383  * field controls how many pixels are ignored in the y direction before the
384  * pixel masking region is repeated.
385  *
386  * These fields can be used to reduce the number of pixels counted for the
387  * statistics, but it's important to be careful to configure them correctly.
388  * Some combinations of values will result in colour components from the input
389  * data being ignored entirely, for example in the following configuration:
390  *
391  * skip_x = 0
392  * offset_x = 0
393  * skip_y = 0
394  * offset_y = 0
395  *
396  * Only the R and Gb components of RGGB data that was input would be collected.
397  * Similarly in the following configuration:
398  *
399  * skip_x = 0
400  * offset_x = 0
401  * skip_y = 1
402  * offset_y = 1
403  *
404  * Only the Gb component of RGGB data that was input would be collected. To
405  * correct things such that all 4 colour components were included it would be
406  * necessary to set the skip_x and skip_y fields in a way that resulted in all
407  * four colour components being collected:
408  *
409  * skip_x = 1
410  * offset_x = 0
411  * skip_y = 1
412  * offset_y = 1
413  *
414  * header.type should be set to one of either MALI_C55_PARAM_BLOCK_AEXP_HIST or
415  * MALI_C55_PARAM_BLOCK_AEXP_IHIST from :c:type:`mali_c55_param_block_type`.
416  *
417  * @header:		The Mali-C55 parameters block header
418  * @skip_x:		Horizontal decimation. See enum mali_c55_aexp_skip_x
419  * @offset_x:		Skip the first column, or not. See enum mali_c55_aexp_row_column_offset
420  * @skip_y:		Vertical decimation. See enum mali_c55_aexp_skip_y
421  * @offset_y:		Skip the first row, or not. See enum mali_c55_aexp_row_column_offset
422  * @scale_bottom:	Scale pixels in bottom half of intensity range: 0=1x ,1=2x, 2=4x, 4=8x, 4=16x
423  * @scale_top:		scale pixels in top half of intensity range: 0=1x ,1=2x, 2=4x, 4=8x, 4=16x
424  * @plane_mode:		Plane separation mode. See enum mali_c55_aexp_hist_plane_mode
425  * @tap_point:		Tap point for histogram from enum mali_c55_aexp_hist_tap_points.
426  *			This parameter is unused for the post-Iridix Histogram
427  */
428 struct mali_c55_params_aexp_hist {
429 	struct v4l2_isp_params_block_header header;
430 	__u8 skip_x;
431 	__u8 offset_x;
432 	__u8 skip_y;
433 	__u8 offset_y;
434 	__u8 scale_bottom;
435 	__u8 scale_top;
436 	__u8 plane_mode;
437 	__u8 tap_point;
438 };
439 
440 /**
441  * struct mali_c55_params_aexp_weights - Array of weights for AEXP metering
442  *
443  * This struct allows users to configure the weighting for both of the 1024-bin
444  * AEXP histograms. The pixel data collected for each zone is multiplied by the
445  * corresponding weight from this array, which may be zero if the intention is
446  * to mask off the zone entirely.
447  *
448  * header.type should be set to one of either MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS
449  * or MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS from :c:type:`mali_c55_param_block_type`.
450  *
451  * @header:		The Mali-C55 parameters block header
452  * @nodes_used_horiz:	Number of active zones horizontally [0..15]
453  * @nodes_used_vert:	Number of active zones vertically [0..15]
454  * @zone_weights:	Zone weighting. Index is row*col where 0,0 is the top
455  *			left zone continuing in raster order. Each zone can be
456  *			weighted in the range [0..15]. The number of rows and
457  *			columns is defined by @nodes_used_vert and
458  *			@nodes_used_horiz
459  */
460 struct mali_c55_params_aexp_weights {
461 	struct v4l2_isp_params_block_header header;
462 	__u8 nodes_used_horiz;
463 	__u8 nodes_used_vert;
464 	__u8 zone_weights[MALI_C55_MAX_ZONES];
465 };
466 
467 /**
468  * struct mali_c55_params_digital_gain - Digital gain value
469  *
470  * This struct carries a digital gain value to set in the ISP.
471  *
472  * header.type should be set to MALI_C55_PARAM_BLOCK_DIGITAL_GAIN from
473  * :c:type:`mali_c55_param_block_type` for this block.
474  *
475  * @header:	The Mali-C55 parameters block header
476  * @gain:	The digital gain value to apply, in Q5.8 format.
477  */
478 struct mali_c55_params_digital_gain {
479 	struct v4l2_isp_params_block_header header;
480 	__u16 gain;
481 };
482 
483 /**
484  * enum mali_c55_awb_stats_mode - Statistics mode for AWB
485  * @MALI_C55_AWB_MODE_GRBR: Statistics collected as Green/Red and Blue/Red ratios
486  * @MALI_C55_AWB_MODE_RGBG: Statistics collected as Red/Green and Blue/Green ratios
487  */
488 enum mali_c55_awb_stats_mode {
489 	MALI_C55_AWB_MODE_GRBR = 0,
490 	MALI_C55_AWB_MODE_RGBG,
491 };
492 
493 /**
494  * struct mali_c55_params_awb_gains - Gain settings for auto white balance
495  *
496  * This struct allows users to configure the gains for auto-white balance. There
497  * are four gain settings corresponding to each colour channel in the bayer
498  * domain. Although named generically, the association between the gain applied
499  * and the colour channel is done automatically within the ISP depending on the
500  * input format, and so the following mapping always holds true::
501  *
502  *	gain00 = R
503  *	gain01 = Gr
504  *	gain10 = Gb
505  *	gain11 = B
506  *
507  * All of the gains are stored in Q4.8 format.
508  *
509  * header.type should be set to one of either MALI_C55_PARAM_BLOCK_AWB_GAINS or
510  * MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP from :c:type:`mali_c55_param_block_type`.
511  *
512  * @header:	The Mali-C55 parameters block header
513  * @gain00:	Multiplier for colour channel 00
514  * @gain01:	Multiplier for colour channel 01
515  * @gain10:	Multiplier for colour channel 10
516  * @gain11:	Multiplier for colour channel 11
517  */
518 struct mali_c55_params_awb_gains {
519 	struct v4l2_isp_params_block_header header;
520 	__u16 gain00;
521 	__u16 gain01;
522 	__u16 gain10;
523 	__u16 gain11;
524 };
525 
526 /**
527  * enum mali_c55_params_awb_tap_points - Tap points for the AWB statistics
528  * @MALI_C55_AWB_STATS_TAP_PF: Immediately after the Purple Fringe block
529  * @MALI_C55_AWB_STATS_TAP_CNR: Immediately after the CNR block
530  */
531 enum mali_c55_params_awb_tap_points {
532 	MALI_C55_AWB_STATS_TAP_PF = 0,
533 	MALI_C55_AWB_STATS_TAP_CNR,
534 };
535 
536 /**
537  * struct mali_c55_params_awb_config - Stats settings for auto-white balance
538  *
539  * This struct allows the configuration of the statistics generated for auto
540  * white balance. Pixel intensity limits can be set to exclude overly bright or
541  * dark regions of an image from the statistics entirely. Colour ratio minima
542  * and maxima can be set to discount pixels who's ratios fall outside the
543  * defined boundaries; there are two sets of registers to do this - the
544  * "min/max" ratios which bound a region and the "high/low" ratios which further
545  * trim the upper and lower ratios. For example with the boundaries configured
546  * as follows, only pixels whos colour ratios falls into the region marked "A"
547  * would be counted::
548  *
549  *	                                                          cr_high
550  *	    2.0 |                                                   |
551  *	        |               cb_max --> _________________________v_____
552  *	    1.8 |                         |                         \    |
553  *	        |                         |                          \   |
554  *	    1.6 |                         |                           \  |
555  *	        |                         |                            \ |
556  *	 c  1.4 |               cb_low -->|\              A             \|<--  cb_high
557  *	 b      |                         | \                            |
558  *	    1.2 |                         |  \                           |
559  *	 r      |                         |   \                          |
560  *	 a  1.0 |              cb_min --> |____\_________________________|
561  *	 t      |                         ^    ^                         ^
562  *	 i  0.8 |                         |    |                         |
563  *	 o      |                      cr_min  |                       cr_max
564  *	 s  0.6 |                              |
565  *	        |                             cr_low
566  *	    0.4 |
567  *	        |
568  *	    0.2 |
569  *	        |
570  *	    0.0 |_______________________________________________________________
571  *	        0.0   0.2   0.4   0.6   0.8   1.0   1.2   1.4   1.6   1.8   2.0
572  *	                                   cr ratios
573  *
574  * header.type should be set to MALI_C55_PARAM_BLOCK_AWB_CONFIG from
575  * :c:type:`mali_c55_param_block_type` for this block.
576  *
577  * @header:		The Mali-C55 parameters block header
578  * @tap_point:		The tap point from enum mali_c55_params_awb_tap_points
579  * @stats_mode:		AWB statistics collection mode, see :c:type:`mali_c55_awb_stats_mode`
580  * @white_level:	Upper pixel intensity (I.E. raw pixel values) limit
581  * @black_level:	Lower pixel intensity (I.E. raw pixel values) limit
582  * @cr_max:		Maximum R/G ratio (Q4.8 format)
583  * @cr_min:		Minimum R/G ratio (Q4.8 format)
584  * @cb_max:		Maximum B/G ratio (Q4.8 format)
585  * @cb_min:		Minimum B/G ratio (Q4.8 format)
586  * @nodes_used_horiz:	Number of active zones horizontally [0..15]
587  * @nodes_used_vert:	Number of active zones vertically [0..15]
588  * @cr_high:		R/G ratio trim high (Q4.8 format)
589  * @cr_low:		R/G ratio trim low (Q4.8 format)
590  * @cb_high:		B/G ratio trim high (Q4.8 format)
591  * @cb_low:		B/G ratio trim low (Q4.8 format)
592  */
593 struct mali_c55_params_awb_config {
594 	struct v4l2_isp_params_block_header header;
595 	__u8 tap_point;
596 	__u8 stats_mode;
597 	__u16 white_level;
598 	__u16 black_level;
599 	__u16 cr_max;
600 	__u16 cr_min;
601 	__u16 cb_max;
602 	__u16 cb_min;
603 	__u8 nodes_used_horiz;
604 	__u8 nodes_used_vert;
605 	__u16 cr_high;
606 	__u16 cr_low;
607 	__u16 cb_high;
608 	__u16 cb_low;
609 };
610 
611 #define MALI_C55_NUM_MESH_SHADING_ELEMENTS 3072
612 
613 /**
614  * struct mali_c55_params_mesh_shading_config - Mesh shading configuration
615  *
616  * The mesh shading correction module allows programming a separate table of
617  * either 16x16 or 32x32 node coefficients for 3 different light sources. The
618  * final correction coefficients applied are computed by blending the
619  * coefficients from two tables together.
620  *
621  * A page of 1024 32-bit integers is associated to each colour channel, with
622  * pages stored consecutively in memory. Each 32-bit integer packs 3 8-bit
623  * correction coefficients for a single node, one for each of the three light
624  * sources. The 8 most significant bits are unused. The following table
625  * describes the layout::
626  *
627  *	+----------- Page (Colour Plane) 0 -------------+
628  *	| @mesh[i]  | Mesh Point | Bits  | Light Source |
629  *	+-----------+------------+-------+--------------+
630  *	|         0 |        0,0 | 16,23 | LS2          |
631  *	|           |            | 08-15 | LS1          |
632  *	|           |            | 00-07 | LS0          |
633  *	+-----------+------------+-------+--------------+
634  *	|         1 |        0,1 | 16,23 | LS2          |
635  *	|           |            | 08-15 | LS1          |
636  *	|           |            | 00-07 | LS0          |
637  *	+-----------+------------+-------+--------------+
638  *	|       ... |        ... | ...   | ...          |
639  *	+-----------+------------+-------+--------------+
640  *	|      1023 |      31,31 | 16,23 | LS2          |
641  *	|           |            | 08-15 | LS1          |
642  *	|           |            | 00-07 | LS0          |
643  *	+----------- Page (Colour Plane) 1 -------------+
644  *	| @mesh[i]  | Mesh Point | Bits  | Light Source |
645  *	+-----------+------------+-------+--------------+
646  *	|      1024 |        0,0 | 16,23 | LS2          |
647  *	|           |            | 08-15 | LS1          |
648  *	|           |            | 00-07 | LS0          |
649  *	+-----------+------------+-------+--------------+
650  *	|      1025 |        0,1 | 16,23 | LS2          |
651  *	|           |            | 08-15 | LS1          |
652  *	|           |            | 00-07 | LS0          |
653  *	+-----------+------------+-------+--------------+
654  *	|       ... |        ... | ...   | ...          |
655  *	+-----------+------------+-------+--------------+
656  *	|      2047 |      31,31 | 16,23 | LS2          |
657  *	|           |            | 08-15 | LS1          |
658  *	|           |            | 00-07 | LS0          |
659  *	+----------- Page (Colour Plane) 2 -------------+
660  *	| @mesh[i]  | Mesh Point | Bits  | Light Source |
661  *	+-----------+------------+-------+--------------+
662  *	|      2048 |        0,0 | 16,23 | LS2          |
663  *	|           |            | 08-15 | LS1          |
664  *	|           |            | 00-07 | LS0          |
665  *	+-----------+------------+-------+--------------+
666  *	|      2049 |        0,1 | 16,23 | LS2          |
667  *	|           |            | 08-15 | LS1          |
668  *	|           |            | 00-07 | LS0          |
669  *	+-----------+------------+-------+--------------+
670  *	|       ... |        ... | ...   | ...          |
671  *	+-----------+------------+-------+--------------+
672  *	|      3071 |      31,31 | 16,23 | LS2          |
673  *	|           |            | 08-15 | LS1          |
674  *	|           |            | 00-07 | LS0          |
675  *	+-----------+------------+-------+--------------+
676  *
677  * The @mesh_scale member determines the precision and minimum and maximum gain.
678  * For example if @mesh_scale is 0 and therefore selects 0 - 2x gain, a value of
679  * 0 in a coefficient means 0.0 gain, a value of 128 means 1.0 gain and 255
680  * means 2.0 gain.
681  *
682  * header.type should be set to MALI_C55_PARAM_MESH_SHADING_CONFIG from
683  * :c:type:`mali_c55_param_block_type` for this block.
684  *
685  * @header:		The Mali-C55 parameters block header
686  * @mesh_show:		Output the mesh data rather than image data
687  * @mesh_scale:		Set the precision and maximum gain range of mesh shading
688  *				- 0 = 0-2x gain
689  *				- 1 = 0-4x gain
690  *				- 2 = 0-8x gain
691  *				- 3 = 0-16x gain
692  *				- 4 = 1-2x gain
693  *				- 5 = 1-3x gain
694  *				- 6 = 1-5x gain
695  *				- 7 = 1-9x gain
696  * @mesh_page_r:	Mesh page select for red colour plane [0..2]
697  * @mesh_page_g:	Mesh page select for green colour plane [0..2]
698  * @mesh_page_b:	Mesh page select for blue colour plane [0..2]
699  * @mesh_width:		Number of horizontal nodes minus 1 [15,31]
700  * @mesh_height:	Number of vertical nodes minus 1 [15,31]
701  * @mesh:		Mesh shading correction tables
702  */
703 struct mali_c55_params_mesh_shading_config {
704 	struct v4l2_isp_params_block_header header;
705 	__u8 mesh_show;
706 	__u8 mesh_scale;
707 	__u8 mesh_page_r;
708 	__u8 mesh_page_g;
709 	__u8 mesh_page_b;
710 	__u8 mesh_width;
711 	__u8 mesh_height;
712 	__u32 mesh[MALI_C55_NUM_MESH_SHADING_ELEMENTS];
713 };
714 
715 /** enum mali_c55_params_mesh_alpha_bank - Mesh shading table bank selection
716  * @MALI_C55_MESH_ALPHA_BANK_LS0_AND_LS1 - Select Light Sources 0 and 1
717  * @MALI_C55_MESH_ALPHA_BANK_LS1_AND_LS2 - Select Light Sources 1 and 2
718  * @MALI_C55_MESH_ALPHA_BANK_LS0_AND_LS2 - Select Light Sources 0 and 2
719  */
720 enum mali_c55_params_mesh_alpha_bank {
721 	MALI_C55_MESH_ALPHA_BANK_LS0_AND_LS1 = 0,
722 	MALI_C55_MESH_ALPHA_BANK_LS1_AND_LS2 = 1,
723 	MALI_C55_MESH_ALPHA_BANK_LS0_AND_LS2 = 4
724 };
725 
726 /**
727  * struct mali_c55_params_mesh_shading_selection - Mesh table selection
728  *
729  * The module computes the final correction coefficients by blending the ones
730  * from two light source tables, which are selected (independently for each
731  * colour channel) by the @mesh_alpha_bank_r/g/b fields.
732  *
733  * The final blended coefficients for each node are calculated using the
734  * following equation:
735  *
736  *     Final coefficient = (a * LS\ :sub:`b`\ + (256 - a) * LS\ :sub:`a`\) / 256
737  *
738  * Where a is the @mesh_alpha_r/g/b value, and LS\ :sub:`a`\ and LS\ :sub:`b`\
739  * are the node cofficients for the two tables selected by the
740  * @mesh_alpha_bank_r/g/b value.
741  *
742  * The scale of the applied correction may also be controlled by tuning the
743  * @mesh_strength member. This is a modifier to the final coefficients which can
744  * be used to globally reduce the gains applied.
745  *
746  * header.type should be set to MALI_C55_PARAM_MESH_SHADING_SELECTION from
747  * :c:type:`mali_c55_param_block_type` for this block.
748  *
749  * @header:		The Mali-C55 parameters block header
750  * @mesh_alpha_bank_r:	Red mesh table select (c:type:`enum mali_c55_params_mesh_alpha_bank`)
751  * @mesh_alpha_bank_g:	Green mesh table select (c:type:`enum mali_c55_params_mesh_alpha_bank`)
752  * @mesh_alpha_bank_b:	Blue mesh table select (c:type:`enum mali_c55_params_mesh_alpha_bank`)
753  * @mesh_alpha_r:	Blend coefficient for R [0..255]
754  * @mesh_alpha_g:	Blend coefficient for G [0..255]
755  * @mesh_alpha_b:	Blend coefficient for B [0..255]
756  * @mesh_strength:	Mesh strength in Q4.12 format [0..4096]
757  */
758 struct mali_c55_params_mesh_shading_selection {
759 	struct v4l2_isp_params_block_header header;
760 	__u8 mesh_alpha_bank_r;
761 	__u8 mesh_alpha_bank_g;
762 	__u8 mesh_alpha_bank_b;
763 	__u8 mesh_alpha_r;
764 	__u8 mesh_alpha_g;
765 	__u8 mesh_alpha_b;
766 	__u16 mesh_strength;
767 };
768 
769 /**
770  * struct mali_c55_params_ccm - Coefficients, offsets and gains for the colour
771  *				correction matrix
772  *
773  * The colour correction module converts images data from a sensor-specific
774  * colour space to known one.
775  *
776  * Colour correction is applied after demosaicing and each pixel is represented
777  * as a column vector of the three RGB colour channels on which the following
778  * operations take place:
779  * 1) An offset is subtracted from each colour channel
780  * 2) Each colour channel is multiplied by a gain
781  * 3) The pixel column vector is multiplied by the colour correction matrix
782  *
783  * This struct allows users to configure the coefficients for CCM and the
784  * per-channel offsets and gains. The nine matrix coefficients are expressed as
785  * 13 bits signed Q4.8 Sign/Magnitude fixed-point numbers, the three gain
786  * multipliers are expressed as 12 bits unsigned Q4.8 fixed-point numbers and
787  * the three offsets are expressed as a 12 bits unsigned integers.
788  *
789  * header.type should be set to MALI_C55_PARAM_BLOCK_CCM from
790  * :c:type:`mali_c55_param_block_type`.
791  *
792  * @header:	The Mali-C55 parameters block header
793  * @coeffs:	3x3 color conversion matrix coefficients in sign/magnitude
794  *		Q4.8 format
795  * @gains:	Gains for red, green and blue channels in unsigned Q4.8 format
796  * @offs:	Offsets for red, green and blue channels
797  */
798 struct mali_c55_params_ccm {
799 	struct v4l2_isp_params_block_header header;
800 	__u16 coeffs[3][3];
801 	__u16 gains[3];
802 	__u16 offs[3];
803 };
804 
805 /**
806  * struct mali_c55_params_gamma - RGB Gamma correction
807  *
808  * Gamma correction is used to program a standard gamma curve such as the sRGB
809  * one. It provides gains and offsets to implement contrast adjustments.
810  *
811  * Gamma correction is applied on both the FR and DS pipes separately in the RGB
812  * colour domain where the following operations take place:
813  * 1) An offset is subtracted from each colour channel
814  * 2) Each colour channel is multiplied by a gain
815  * 3) The Gamma LUT is applied to each colour channel
816  *
817  * The Gamma LUT has 129 entries where each node is an unsigned 12 bit number.
818  * It is expected that LUT[0]=0 and LUT[128]=0xfff, with the other 127 values
819  * defining the Gamma correction curve. The three gain multipliers are expressed
820  * as 12-bits unsigned Q4.8 fixed-point numbers and the three offsets are
821  * expressed as a 12-bits unsigned integers.
822  *
823  * As one Gamma correction block is available on both the FR and DS pipes, the
824  * header.type field should be set to one of either
825  * MALI_C55_PARAM_BLOCK_GAMMA_FR or MALI_C55_PARAM_BLOCK_GAMMA_DS from
826  * :c:type:`mali_c55_param_block_type`.
827  *
828  * @header:	The Mali-C55 parameters block header
829  * @gains:	Gains for the red, green and blue channel in unsigned Q4.8 format
830  * @offs:	Offsets subtracted from the red, green and blue channels
831  *		in unsigned 12 bits format
832  * @lut:	129-node Gamma LUT in unsigned 12 bits format
833  */
834 struct mali_c55_params_gamma {
835 	struct v4l2_isp_params_block_header header;
836 	__u16 gains[3];
837 	__u16 offs[3];
838 	__u32 lut[MALI_C55_NUM_GAMMA_LUT_ELEMENTS];
839 };
840 
841 /**
842  * define MALI_C55_PARAMS_MAX_SIZE - Maximum size of all Mali C55 Parameters
843  *
844  * Though the parameters for the Mali-C55 are passed as optional blocks, the
845  * driver still needs to know the absolute maximum size so that it can allocate
846  * a buffer sized appropriately to accommodate userspace attempting to set all
847  * possible parameters in a single frame.
848  *
849  * Some structs are in this list multiple times. Where that's the case, it just
850  * reflects the fact that the same struct can be used with multiple different
851  * header types from :c:type:`mali_c55_param_block_type`.
852  */
853 #define MALI_C55_PARAMS_MAX_SIZE				\
854 	(sizeof(struct mali_c55_params_sensor_off_preshading) +	\
855 	sizeof(struct mali_c55_params_aexp_hist) +		\
856 	sizeof(struct mali_c55_params_aexp_weights) +		\
857 	sizeof(struct mali_c55_params_aexp_hist) +		\
858 	sizeof(struct mali_c55_params_aexp_weights) +		\
859 	sizeof(struct mali_c55_params_digital_gain) +		\
860 	sizeof(struct mali_c55_params_awb_gains) +		\
861 	sizeof(struct mali_c55_params_awb_config) +		\
862 	sizeof(struct mali_c55_params_awb_gains) +		\
863 	sizeof(struct mali_c55_params_mesh_shading_config) +	\
864 	sizeof(struct mali_c55_params_mesh_shading_selection) +	\
865 	sizeof(struct mali_c55_params_ccm) +			\
866 	sizeof(struct mali_c55_params_gamma) +			\
867 	sizeof(struct mali_c55_params_gamma))
868 
869 #endif /* __UAPI_MALI_C55_CONFIG_H */
870