/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/* Copyright (C) 2017 - 2018 Intel Corporation */
#ifndef __IPU3_UAPI_H
#define __IPU3_UAPI_H
#include <linux/types.h>
/* from /drivers/staging/media/ipu3/include/videodev2.h */
/* Vendor specific - used for IPU3 camera sub-system */
/* IPU3 processing parameters */
#define V4L2_META_FMT_IPU3_PARAMS v4l2_fourcc('i', 'p', '3', 'p')
/* IPU3 3A statistics */
#define V4L2_META_FMT_IPU3_STAT_3A v4l2_fourcc('i', 'p', '3', 's')
/* from include/uapi/linux/v4l2-controls.h */
#define V4L2_CID_INTEL_IPU3_BASE (V4L2_CID_USER_BASE + 0x10c0)
#define V4L2_CID_INTEL_IPU3_MODE (V4L2_CID_INTEL_IPU3_BASE + 1)
/******************* ipu3_uapi_stats_3a *******************/
#define IPU3_UAPI_MAX_STRIPES 2
#define IPU3_UAPI_MAX_BUBBLE_SIZE 10
#define IPU3_UAPI_GRID_START_MASK ((1 << 12) - 1)
#define IPU3_UAPI_GRID_Y_START_EN (1 << 15)
/* controls generation of meta_data (like FF enable/disable) */
#define IPU3_UAPI_AWB_RGBS_THR_B_EN (1 << 14)
#define IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT (1 << 15)
/**
* struct ipu3_uapi_grid_config - Grid plane config
*
* @width: Grid horizontal dimensions, in number of grid blocks(cells).
* For AWB, the range is (16, 80).
* For AF/AE, the range is (16, 32).
* @height: Grid vertical dimensions, in number of grid cells.
* For AWB, the range is (16, 60).
* For AF/AE, the range is (16, 24).
* @block_width_log2: Log2 of the width of each cell in pixels.
* For AWB, the range is [3, 6].
* For AF/AE, the range is [3, 7].
* @block_height_log2: Log2 of the height of each cell in pixels.
* For AWB, the range is [3, 6].
* For AF/AE, the range is [3, 7].
* @height_per_slice: The number of blocks in vertical axis per slice.
* Default 2.
* @x_start: X value of top left corner of Region of Interest(ROI).
* @y_start: Y value of top left corner of ROI
* @x_end: X value of bottom right corner of ROI
* @y_end: Y value of bottom right corner of ROI
*
* Due to the size of total amount of collected data, most statistics
* create a grid-based output, and the data is then divided into "slices".
*/
struct ipu3_uapi_grid_config {
__u8 width;
__u8 height;
__u16 block_width_log2:3;
__u16 block_height_log2:3;
__u16 height_per_slice:8;
__u16 x_start;
__u16 y_start;
__u16 x_end;
__u16 y_end;
} __attribute__((packed));
/**
* struct ipu3_uapi_awb_set_item - Memory layout for each cell in AWB
*
* @Gr_avg: Green average for red lines in the cell.
* @R_avg: Red average in the cell.
* @B_avg: Blue average in the cell.
* @Gb_avg: Green average for blue lines in the cell.
* @sat_ratio: Percentage of pixels over the thresholds specified in
* ipu3_uapi_awb_config_s, coded from 0 to 255.
* @padding0: Unused byte for padding.
* @padding1: Unused byte for padding.
* @padding2: Unused byte for padding.
*/
struct ipu3_uapi_awb_set_item {
__u8 Gr_avg;
__u8 R_avg;
__u8 B_avg;
__u8 Gb_avg;
__u8 sat_ratio;
__u8 padding0;
__u8 padding1;
__u8 padding2;
} __attribute__((packed));
/*
* The grid based data is divided into "slices" called set, each slice of setX
* refers to ipu3_uapi_grid_config width * height_per_slice.
*/
#define IPU3_UAPI_AWB_MAX_SETS 60
/* Based on grid size 80 * 60 and cell size 16 x 16 */
#define IPU3_UAPI_AWB_SET_SIZE 160
#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \
(IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES)
#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \
(IPU3_UAPI_AWB_MAX_SETS * \
(IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES))
/**
* struct ipu3_uapi_awb_raw_buffer - AWB raw buffer
*
* @meta_data: buffer to hold auto white balance meta data which is
* the average values for each color channel.
*/
struct ipu3_uapi_awb_raw_buffer {
struct ipu3_uapi_awb_set_item meta_data[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]
__attribute__((aligned(32)));
} __attribute__((packed));
/**
* struct ipu3_uapi_awb_config_s - AWB config
*
* @rgbs_thr_gr: gr threshold value.
* @rgbs_thr_r: Red threshold value.
* @rgbs_thr_gb: gb threshold value.
* @rgbs_thr_b: Blue threshold value.
* @grid: &ipu3_uapi_grid_config, the default grid resolution is 16x16 cells.
*
* The threshold is a saturation measure range [0, 8191], 8191 is default.
* Values over threshold may be optionally rejected for averaging.
*/
struct ipu3_uapi_awb_config_s {
__u16 rgbs_thr_gr;
__u16 rgbs_thr_r;
__u16 rgbs_thr_gb;
__u16 rgbs_thr_b;
struct ipu3_uapi_grid_config grid;
} __attribute__((aligned(32))) __attribute__((packed));
/**
* struct ipu3_uapi_awb_config - AWB config wrapper
*
* @config: config for auto white balance as defined by &ipu3_uapi_awb_config_s
*/
struct ipu3_uapi_awb_config {
struct ipu3_uapi_awb_config_s config __attribute__((aligned(32)));
} __attribute__((packed));
#define IPU3_UAPI_AE_COLORS 4 /* R, G, B, Y */
#define IPU3_UAPI_AE_BINS 256
#define IPU3_UAPI_AE_WEIGHTS 96
/**
* struct ipu3_uapi_ae_raw_buffer - AE global weighted histogram
*
* @vals: Sum of IPU3_UAPI_AE_COLORS in cell
*
* Each histogram contains IPU3_UAPI_AE_BINS bins. Each bin has 24 bit unsigned
* for counting the number of the pixel.
*/
struct ipu3_uapi_ae_raw_buffer {
__u32 vals[IPU3_UAPI_AE_BINS * IPU3_UAPI_AE_COLORS];
} __attribute__((packed));
/**
* struct ipu3_uapi_ae_raw_buffer_aligned - AE raw buffer
*
* @buff: &ipu3_uapi_ae_raw_buffer to hold full frame meta data.
*/
struct ipu3_uapi_ae_raw_buffer_aligned {
struct ipu3_uapi_ae_raw_buffer buff __attribute__((aligned(32)));
} __attribute__((packed));
/**
* struct ipu3_uapi_ae_grid_config - AE weight grid
*
* @width: Grid horizontal dimensions. Value: [16, 32], default 16.
* @height: Grid vertical dimensions. Value: [16, 24], default 16.
* @block_width_log2: Log2 of the width of the grid cell, value: [3, 7].
* @block_height_log2: Log2 of the height of the grid cell, value: [3, 7].
* default is 3 (cell size 8x8), 4 cell per grid.
* @reserved0: reserved
* @ae_en: 0: does not write to &ipu3_uapi_ae_raw_buffer_aligned array,
* 1: write normally.
* @rst_hist_array: write 1 to trigger histogram array reset.
* @done_rst_hist_array: flag for histogram array reset done.
* @x_start: X value of top left corner of ROI, default 0.
* @y_start: Y value of top left corner of ROI, default 0.
* @x_end: X value of bottom right corner of ROI
* @y_end: Y value of bottom right corner of ROI
*
* The AE block accumulates 4 global weighted histograms(R, G, B, Y) over
* a defined ROI within the frame. The contribution of each pixel into the
* histogram, defined by &ipu3_uapi_ae_weight_elem LUT, is indexed by a grid.
*/
struct ipu3_uapi_ae_grid_config {
__u8 width;
__u8 height;
__u8 block_width_log2:4;
__u8 block_height_log2:4;
__u8 reserved0:5;
__u8 ae_en:1;
__u8 rst_hist_array:1;
__u8 done_rst_hist_array:1;
__u16 x_start;
__u16 y_start;
__u16 x_end;
__u16 y_end;
} __attribute__((packed));
/**
* struct ipu3_uapi_ae_weight_elem - AE weights LUT
*
* @cell0: weighted histogram grid value.
* @cell1: weighted histogram grid value.
* @cell2: weighted histogram grid value.
* @cell3: weighted histogram grid value.
* @cell4: weighted histogram grid value.
* @cell5: weighted histogram grid value.
* @cell6: weighted histogram grid value.
* @cell7: weighted histogram grid value.
*
* Use weighted grid value to give a different contribution factor to each cell.
* Precision u4, range [0, 15].
*/
struct ipu3_uapi_ae_weight_elem {
__u32 cell0:4;
__u32 cell1:4;
__u32 cell2:4;
__u32 cell3:4;
__u32 cell4:4;
__u32 cell5:4;
__u32 cell6:4;
__u32 cell7:4;
} __attribute__((packed));
/**
* struct ipu3_uapi_ae_ccm - AE coefficients for WB and CCM
*
* @gain_gr: WB gain factor for the gr channels. Default 256.
* @gain_r: WB gain factor for the r channel. Default 256.
* @gain_b: WB gain factor for the b channel. Default 256.
* @gain_gb: WB gain factor for the gb channels. Default 256.
* @mat: 4x4 matrix that transforms Bayer quad output from WB to RGB+Y.
*
* Default:
* 128, 0, 0, 0,
* 0, 128, 0, 0,
* 0, 0, 128, 0,
* 0, 0, 0, 128,
*
* As part of the raw frame pre-process stage, the WB and color conversion need
* to be applied to expose the impact of these gain operations.
*/
struct ipu3_uapi_ae_ccm {
__u16 gain_gr;
__u16 gain_r;
__u16 gain_b;
__u16 gain_gb;
__s16 mat[16];
} __attribute__((packed));
/**
* struct ipu3_uapi_ae_config - AE config
*
* @grid_cfg: config for auto exposure statistics grid. See struct
* &ipu3_uapi_ae_grid_config, as Imgu did not support output
* auto exposure statistics, so user can ignore this configuration
* and use the RGB table in auto-whitebalance statistics instead.
* @weights: &IPU3_UAPI_AE_WEIGHTS is based on 32x24 blocks in the grid.
* Each grid cell has a corresponding value in weights LUT called
* grid value, global histogram is updated based on grid value and
* pixel value.
* @ae_ccm: Color convert matrix pre-processing block.
*
* Calculate AE grid from image resolution, resample ae weights.
*/
struct ipu3_uapi_ae_config {
struct ipu3_uapi_ae_grid_config grid_cfg __attribute__((aligned(32)));
struct ipu3_uapi_ae_weight_elem weights[IPU3_UAPI_AE_WEIGHTS]
__attribute__((aligned(32)));
struct ipu3_uapi_ae_ccm ae_ccm __attribute__((aligned(32)));
} __attribute__((packed));
/**
* struct ipu3_uapi_af_filter_config - AF 2D filter for contrast measurements
*
* @y1_coeff_0: filter Y1, structure: 3x11, support both symmetry and
* anti-symmetry type. A12 is center, A1-A11 are neighbours.
* for analyzing low frequency content, used to calculate sum
* of gradients in x direction.
* @y1_coeff_0.a1: filter1 coefficients A1, u8, default 0.
* @y1_coeff_0.a2: filter1 coefficients A2, u8, default 0.
* @y1_coeff_0.a3: filter1 coefficients A3, u8, default 0.
* @y1_coeff_0.a4: filter1 coefficients A4, u8, default 0.
* @y1_coeff_1: Struct
* @y1_coeff_1.a5: filter1 coefficients A5, u8, default 0.
* @y1_coeff_1.a6: filter1 coefficients A6, u8, default 0.
* @y1_coeff_1.a7: filter1 coefficients A7, u8, default 0.
* @y1_coeff_1.a8: filter1 coefficients A8, u8, default 0.
* @y1_coeff_2: Struct
* @y1_coeff_2.a9: filter1 coefficients A9, u8, default 0.
* @y1_coeff_2.a10: filter1 coefficients A10, u8, default 0.
* @y1_coeff_2.a11: filter1 coefficients A11, u8, default 0.
* @y1_coeff_2.a12: filter1 coefficients A12, u8, default 128.
* @y1_sign_vec: Each bit corresponds to one coefficient sign bit,
* 0: positive, 1: negative, default 0.
* @y2_coeff_0: Y2, same structure as Y1. For analyzing high frequency content.
* @y2_coeff_0.a1: filter2 coefficients A1, u8, default 0.
* @y2_coeff_0.a2: filter2 coefficients A2, u8, default 0.
* @y2_coeff_0.a3: filter2 coefficients A3, u8, default 0.
* @y2_coeff_0.a4: filter2 coefficients A4, u8, default 0.
* @y2_coeff_1: Struct
* @y2_coeff_1.a5: filter2 coefficients A5, u8, default 0.
* @y2_coeff_1.a6: filter2 coefficients A6, u8, default 0.
* @y2_coeff_1.a7: filter2 coefficients A7, u8, default 0.
* @y2_coeff_1.a8: filter2 coefficients A8, u8, default 0.
* @y2_coeff_2: Struct
* @y2_coeff_2.a9: filter1 coefficients A9, u8, default 0.
* @y2_coeff_2.a10: filter1 coefficients A10, u8, default 0.
* @y2_coeff_2.a11: filter1 coefficients A11, u8, default 0.
* @y2_coeff_2.a12: filter1 coefficients A12, u8, default 128.
* @y2_sign_vec: Each bit corresponds to one coefficient sign bit,
* 0: positive, 1: negative, default 0.
* @y_calc: Pre-processing that converts Bayer quad to RGB+Y values to be
* used for building histogram. Range [0, 32], default 8.
* Rule:
* y_gen_rate_gr + y_gen_rate_r + y_gen_rate_b + y_gen_rate_gb = 32
* A single Y is calculated based on sum of Gr/R/B/Gb based on
* their contribution ratio.
* @y_calc.y_gen_rate_gr: Contribution ratio Gr for Y
* @y_calc.y_gen_rate_r: Contribution ratio R for Y
* @y_calc.y_gen_rate_b: Contribution ratio B for Y
* @y_calc.y_gen_rate_gb: Contribution ratio Gb for Y
* @nf: The shift right value that should be applied during the Y1/Y2 filter to
* make sure the total memory needed is 2 bytes per grid cell.
* @nf.reserved0: reserved
* @nf.y1_nf: Normalization factor for the convolution coeffs of y1,
* should be log2 of the sum of the abs values of the filter
|