| @@ -0,0 +1,794 @@ |
| 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 | +/** |
| 40 | + * struct mali_c55_ae_1024bin_hist - Auto Exposure 1024-bin histogram statistics |
| 41 | + * |
| 42 | + * @bins: 1024 element array of 16-bit pixel counts. |
| 43 | + * |
| 44 | + * The 1024-bin histogram module collects image-global but zone-weighted |
| 45 | + * intensity distributions of pixels in fixed-width bins. The modules can be |
| 46 | + * configured into different "plane modes" which affect the contents of the |
| 47 | + * collected statistics. In plane mode 0, pixel intensities are taken regardless |
| 48 | + * of colour plane into a single 1024-bin histogram with a bin width of 4. In |
| 49 | + * plane mode 1, four 256-bin histograms with a bin width of 16 are collected - |
| 50 | + * one for each CFA colour plane. In plane modes 4, 5, 6 and 7 two 512-bin |
| 51 | + * histograms with a bin width of 8 are collected - in each mode one of the |
| 52 | + * colour planes is collected into the first histogram and all the others are |
| 53 | + * combined into the second. The histograms are stored consecutively in the bins |
| 54 | + * array. |
| 55 | + * |
| 56 | + * The 16-bit pixel counts are stored as a 4-bit exponent in the most |
| 57 | + * significant bits followed by a 12-bit mantissa. Conversion to a usable |
| 58 | + * format can be done according to the following pseudo-code:: |
| 59 | + * |
| 60 | + * if (e == 0) { |
| 61 | + * bin = m * 2; |
| 62 | + * } else { |
| 63 | + * bin = (m + 4096) * 2^e |
| 64 | + * } |
| 65 | + * |
| 66 | + * where |
| 67 | + * e is the exponent value in range 0..15 |
| 68 | + * m is the mantissa value in range 0..4095 |
| 69 | + * |
| 70 | + * The pixels used in calculating the statistics can be masked using three |
| 71 | + * methods: |
| 72 | + * |
| 73 | + * 1. Pixels can be skipped in X and Y directions independently. |
| 74 | + * 2. Minimum/Maximum intensities can be configured |
| 75 | + * 3. Zones can be differentially weighted, including 0 weighted to mask them |
| 76 | + * |
| 77 | + * The data for this histogram can be collected from different tap points in the |
| 78 | + * ISP depending on configuration - after the white balance or digital gain |
| 79 | + * blocks, or immediately after the input crossbar. |
| 80 | + */ |
| 81 | +struct mali_c55_ae_1024bin_hist { |
| 82 | + __u16 bins[1024]; |
| 83 | +} __attribute__((packed)); |
| 84 | + |
| 85 | +/** |
| 86 | + * struct mali_c55_ae_5bin_hist - Auto Exposure 5-bin histogram statistics |
| 87 | + * |
| 88 | + * @hist0: 16-bit normalised pixel count for the 0th intensity bin |
| 89 | + * @hist1: 16-bit normalised pixel count for the 1st intensity bin |
| 90 | + * @hist3: 16-bit normalised pixel count for the 3rd intensity bin |
| 91 | + * @hist4: 16-bit normalised pixel count for the 4th intensity bin |
| 92 | + * |
| 93 | + * The ISP generates a 5-bin histogram of normalised pixel counts within bins of |
| 94 | + * pixel intensity for each of 225 possible zones within a frame. The centre bin |
| 95 | + * of the histogram for each zone is not available from the hardware and must be |
| 96 | + * calculated by subtracting the values of hist0, hist1, hist3 and hist4 from |
| 97 | + * 0xffff as in the following equation: |
| 98 | + * |
| 99 | + * hist2 = 0xffff - (hist0 + hist1 + hist3 + hist4) |
| 100 | + */ |
| 101 | +struct mali_c55_ae_5bin_hist { |
| 102 | + __u16 hist0; |
| 103 | + __u16 hist1; |
| 104 | + __u16 hist3; |
| 105 | + __u16 hist4; |
| 106 | +} __attribute__((packed)); |
| 107 | + |
| 108 | +/** |
| 109 | + * struct mali_c55_awb_average_ratios - Auto White Balance colour ratios |
| 110 | + * |
| 111 | + * @avg_rg_gr: Average R/G or G/R ratio in Q4.8 format. |
| 112 | + * @avg_bg_br: Average B/G or B/R ratio in Q4.8 format. |
| 113 | + * @num_pixels: The number of pixels used in the AWB calculation |
| 114 | + * |
| 115 | + * The ISP calculates and collects average colour ratios for each zone in an |
| 116 | + * image and stores them in Q4.8 format (the lowest 8 bits are fractional, with |
| 117 | + * bits [11:8] representing the integer). The exact ratios collected (either |
| 118 | + * R/G, B/G or G/R, B/R) are configurable through the parameters buffer. The |
| 119 | + * value of the 4 high bits is undefined. |
| 120 | + */ |
| 121 | +struct mali_c55_awb_average_ratios { |
| 122 | + __u16 avg_rg_gr; |
| 123 | + __u16 avg_bg_br; |
| 124 | + __u32 num_pixels; |
| 125 | +} __attribute__((packed)); |
| 126 | + |
| 127 | +/** |
| 128 | + * struct mali_c55_af_statistics - Auto Focus edge and intensity statistics |
| 129 | + * |
| 130 | + * @intensity_stats: Packed mantissa and exponent value for pixel intensity |
| 131 | + * @edge_stats: Packed mantissa and exponent values for edge intensity |
| 132 | + * |
| 133 | + * The ISP collects the squared sum of pixel intensities for each zone within a |
| 134 | + * configurable Region of Interest on the frame. Additionally, the same data are |
| 135 | + * collected after being passed through a bandpass filter which removes high and |
| 136 | + * low frequency components - these are referred to as the edge statistics. |
| 137 | + * |
| 138 | + * The intensity and edge statistics for a zone can be used to calculate the |
| 139 | + * contrast information for a zone |
| 140 | + * |
| 141 | + * C = E2 / I2 |
| 142 | + * |
| 143 | + * Where I2 is the intensity statistic for a zone and E2 is the edge statistic |
| 144 | + * for that zone. Optimum focus is reached when C is at its maximum. |
| 145 | + * |
| 146 | + * The intensity and edge statistics are stored packed into a non-standard 16 |
| 147 | + * bit floating point format, where the 7 most significant bits represent the |
| 148 | + * exponent and the 9 least significant bits the mantissa. This format can be |
| 149 | + * unpacked with the following pseudocode:: |
| 150 | + * |
| 151 | + * if (e == 0) { |
| 152 | + * x = m; |
| 153 | + * } else { |
| 154 | + * x = 2^e-1 * (m + 2^9) |
| 155 | + * } |
| 156 | + * |
| 157 | + * where |
| 158 | + * e is the exponent value in range 0..127 |
| 159 | + * m is the mantissa value in range 0..511 |
| 160 | + */ |
| 161 | +struct mali_c55_af_statistics { |
| 162 | + __u16 intensity_stats; |
| 163 | + __u16 edge_stats; |
| 164 | +} __attribute__((packed)); |
| 165 | + |
| 166 | +/** |
| 167 | + * struct mali_c55_stats_buffer - 3A statistics for the mali-c55 ISP |
| 168 | + * |
| 169 | + * @ae_1024bin_hist: 1024-bin frame-global pixel intensity histogram |
| 170 | + * @iridix_1024bin_hist: Post-Iridix block 1024-bin histogram |
| 171 | + * @ae_5bin_hists: 5-bin pixel intensity histograms for AEC |
| 172 | + * @reserved1: Undefined buffer space |
| 173 | + * @awb_ratios: Color balance ratios for Auto White Balance |
| 174 | + * @reserved2: Undefined buffer space |
| 175 | + * @af_statistics: Pixel intensity statistics for Auto Focus |
| 176 | + * @reserved3: Undefined buffer space |
| 177 | + * |
| 178 | + * This struct describes the metering statistics space in the Mali-C55 ISP's |
| 179 | + * hardware in its entirety. The space between each defined area is marked as |
| 180 | + * "unknown" and may not be 0, but should not be used. The @ae_5bin_hists, |
| 181 | + * @awb_ratios and @af_statistics members are arrays of statistics per-zone. |
| 182 | + * The zones are arranged in the array in raster order starting from the top |
| 183 | + * left corner of the image. |
| 184 | + */ |
| 185 | + |
| 186 | +struct mali_c55_stats_buffer { |
| 187 | + struct mali_c55_ae_1024bin_hist ae_1024bin_hist; |
| 188 | + struct mali_c55_ae_1024bin_hist iridix_1024bin_hist; |
| 189 | + struct mali_c55_ae_5bin_hist ae_5bin_hists[MALI_C55_MAX_ZONES]; |
| 190 | + __u32 reserved1[14]; |
| 191 | + struct mali_c55_awb_average_ratios awb_ratios[MALI_C55_MAX_ZONES]; |
| 192 | + __u32 reserved2[14]; |
| 193 | + struct mali_c55_af_statistics af_statistics[MALI_C55_MAX_ZONES]; |
| 194 | + __u32 reserved3[15]; |
| 195 | +} __attribute__((packed)); |
| 196 | + |
| 197 | +/** |
| 198 | + * enum mali_c55_param_buffer_version - Mali-C55 parameters block versioning |
| 199 | + * |
| 200 | + * @MALI_C55_PARAM_BUFFER_V1: First version of Mali-C55 parameters block |
| 201 | + */ |
| 202 | +enum mali_c55_param_buffer_version { |
| 203 | + MALI_C55_PARAM_BUFFER_V1, |
| 204 | +}; |
| 205 | + |
| 206 | +/** |
| 207 | + * enum mali_c55_param_block_type - Enumeration of Mali-C55 parameter blocks |
| 208 | + * |
| 209 | + * This enumeration defines the types of Mali-C55 parameters block. Each block |
| 210 | + * configures a specific processing block of the Mali-C55 ISP. The block |
| 211 | + * type allows the driver to correctly interpret the parameters block data. |
| 212 | + * |
| 213 | + * It is the responsibility of userspace to correctly set the type of each |
| 214 | + * parameters block. |
| 215 | + * |
| 216 | + * @MALI_C55_PARAM_BLOCK_SENSOR_OFFS: Sensor pre-shading black level offset |
| 217 | + * @MALI_C55_PARAM_BLOCK_AEXP_HIST: Auto-exposure 1024-bin histogram |
| 218 | + * configuration |
| 219 | + * @MALI_C55_PARAM_BLOCK_AEXP_IHIST: Post-Iridix auto-exposure 1024-bin |
| 220 | + * histogram configuration |
| 221 | + * @MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS: Auto-exposure 1024-bin histogram |
| 222 | + * weighting |
| 223 | + * @MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS: Post-Iridix auto-exposure 1024-bin |
| 224 | + * histogram weighting |
| 225 | + * @MALI_C55_PARAM_BLOCK_DIGITAL_GAIN: Digital gain |
| 226 | + * @MALI_C55_PARAM_BLOCK_AWB_GAINS: Auto-white balance gains |
| 227 | + * @MALI_C55_PARAM_BLOCK_AWB_CONFIG: Auto-white balance statistics config |
| 228 | + * @MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP: Auto-white balance gains for AEXP-0 tap |
| 229 | + * @MALI_C55_PARAM_MESH_SHADING_CONFIG : Mesh shading tables configuration |
| 230 | + * @MALI_C55_PARAM_MESH_SHADING_SELECTION: Mesh shading table selection |
| 231 | + */ |
| 232 | +enum mali_c55_param_block_type { |
| 233 | + MALI_C55_PARAM_BLOCK_SENSOR_OFFS, |
| 234 | + MALI_C55_PARAM_BLOCK_AEXP_HIST, |
| 235 | + MALI_C55_PARAM_BLOCK_AEXP_IHIST, |
| 236 | + MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS, |
| 237 | + MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS, |
| 238 | + MALI_C55_PARAM_BLOCK_DIGITAL_GAIN, |
| 239 | + MALI_C55_PARAM_BLOCK_AWB_GAINS, |
| 240 | + MALI_C55_PARAM_BLOCK_AWB_CONFIG, |
| 241 | + MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP, |
| 242 | + MALI_C55_PARAM_MESH_SHADING_CONFIG, |
| 243 | + MALI_C55_PARAM_MESH_SHADING_SELECTION, |
| 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 | + * define MALI_C55_PARAMS_MAX_SIZE - Maximum size of all Mali C55 Parameters |
| 771 | + * |
| 772 | + * Though the parameters for the Mali-C55 are passed as optional blocks, the |
| 773 | + * driver still needs to know the absolute maximum size so that it can allocate |
| 774 | + * a buffer sized appropriately to accommodate userspace attempting to set all |
| 775 | + * possible parameters in a single frame. |
| 776 | + * |
| 777 | + * Some structs are in this list multiple times. Where that's the case, it just |
| 778 | + * reflects the fact that the same struct can be used with multiple different |
| 779 | + * header types from :c:type:`mali_c55_param_block_type`. |
| 780 | + */ |
| 781 | +#define MALI_C55_PARAMS_MAX_SIZE \ |
| 782 | + (sizeof(struct mali_c55_params_sensor_off_preshading) + \ |
| 783 | + sizeof(struct mali_c55_params_aexp_hist) + \ |
| 784 | + sizeof(struct mali_c55_params_aexp_weights) + \ |
| 785 | + sizeof(struct mali_c55_params_aexp_hist) + \ |
| 786 | + sizeof(struct mali_c55_params_aexp_weights) + \ |
| 787 | + sizeof(struct mali_c55_params_digital_gain) + \ |
| 788 | + sizeof(struct mali_c55_params_awb_gains) + \ |
| 789 | + sizeof(struct mali_c55_params_awb_config) + \ |
| 790 | + sizeof(struct mali_c55_params_awb_gains) + \ |
| 791 | + sizeof(struct mali_c55_params_mesh_shading_config) + \ |
| 792 | + sizeof(struct mali_c55_params_mesh_shading_selection)) |
| 793 | + |
| 794 | +#endif /* __UAPI_MALI_C55_CONFIG_H */ |