linux/drivers/staging/media/atomisp/pci/sh_css_defs.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#ifndef _SH_CSS_DEFS_H_
#define _SH_CSS_DEFS_H_

#include "isp.h"

/*#include "vamem.h"*/ /* Cannot include for VAMEM properties this file is visible on ISP -> pipeline generator */

#include "math_support.h"	/* max(), min, etc etc */

/* ID's for refcount */
#define IA_CSS_REFCOUNT_PARAM_SET_POOL
#define IA_CSS_REFCOUNT_PARAM_BUFFER

/* Digital Image Stabilization */
#define SH_CSS_DIS_DECI_FACTOR_LOG2

/* UV offset: 1:uv=-128...127, 0:uv=0...255 */
#define SH_CSS_UV_OFFSET_IS_0

/* Bits of bayer is adjusted as 13 in ISP */
#define SH_CSS_BAYER_BITS

/* Max value of bayer data (unsigned 13bit in ISP) */
#define SH_CSS_BAYER_MAXVAL

/* Bits of yuv in ISP */
#define SH_CSS_ISP_YUV_BITS

#define SH_CSS_DP_GAIN_SHIFT
#define SH_CSS_BNR_GAIN_SHIFT
#define SH_CSS_YNR_GAIN_SHIFT
#define SH_CSS_AE_YCOEF_SHIFT
#define SH_CSS_AF_FIR_SHIFT
#define SH_CSS_YEE_DETAIL_GAIN_SHIFT
#define SH_CSS_YEE_SCALE_SHIFT
#define SH_CSS_TNR_COEF_SHIFT
#define SH_CSS_MACC_COEF_SHIFT
#define SH_CSS_MACC2_COEF_SHIFT
#define SH_CSS_DIS_COEF_SHIFT

/* enumeration of the bayer downscale factors. When a binary supports multiple
 * factors, the OR of these defines is used to build the mask of supported
 * factors. The BDS factor is used in pre-processor expressions so we cannot
 * use an enum here. */
#define SH_CSS_BDS_FACTOR_1_00
#define SH_CSS_BDS_FACTOR_1_25
#define SH_CSS_BDS_FACTOR_1_50
#define SH_CSS_BDS_FACTOR_2_00
#define SH_CSS_BDS_FACTOR_2_25
#define SH_CSS_BDS_FACTOR_2_50
#define SH_CSS_BDS_FACTOR_3_00
#define SH_CSS_BDS_FACTOR_4_00
#define SH_CSS_BDS_FACTOR_4_50
#define SH_CSS_BDS_FACTOR_5_00
#define SH_CSS_BDS_FACTOR_6_00
#define SH_CSS_BDS_FACTOR_8_00
#define NUM_BDS_FACTORS

#define PACK_BDS_FACTOR(factor)

/* Following macros should match with the type enum ia_css_pipe_version in
 * ia_css_pipe_public.h. The reason to add these macros is that enum type
 * will be evaluted to 0 in preprocessing time. */
#define SH_CSS_ISP_PIPE_VERSION_1
#define SH_CSS_ISP_PIPE_VERSION_2_2
#define SH_CSS_ISP_PIPE_VERSION_2_6_1
#define SH_CSS_ISP_PIPE_VERSION_2_7

/*--------------- sRGB Gamma -----------------
CCM        : YCgCo[0,8191] -> RGB[0,4095]
sRGB Gamma : RGB  [0,4095] -> RGB[0,8191]
CSC        : RGB  [0,8191] -> YUV[0,8191]

CCM:
Y[0,8191],CgCo[-4096,4095],coef[-8192,8191] -> RGB[0,4095]

sRGB Gamma:
RGB[0,4095] -(interpolation step16)-> RGB[0,255] -(LUT 12bit)-> RGB[0,4095] -> RGB[0,8191]

CSC:
RGB[0,8191],coef[-8192,8191] -> RGB[0,8191]
--------------------------------------------*/
/* Bits of input/output of sRGB Gamma */
#define SH_CSS_RGB_GAMMA_INPUT_BITS
#define SH_CSS_RGB_GAMMA_OUTPUT_BITS

/* Bits of fractional part of interpolation in vamem, [0,4095]->[0,255] */
#define SH_CSS_RGB_GAMMA_FRAC_BITS
#define SH_CSS_RGB_GAMMA_ONE

/* Bits of input of CCM,  = 13, Y[0,8191],CgCo[-4096,4095] */
#define SH_CSS_YUV2RGB_CCM_INPUT_BITS

/* Bits of output of CCM,  = 12, RGB[0,4095] */
#define SH_CSS_YUV2RGB_CCM_OUTPUT_BITS

/* Maximum value of output of CCM */
#define SH_CSS_YUV2RGB_CCM_MAX_OUTPUT

#define SH_CSS_NUM_INPUT_BUF_LINES

/* Left cropping only applicable for sufficiently large nway */
#define SH_CSS_MAX_LEFT_CROPPING
#define SH_CSS_MAX_TOP_CROPPING

#define SH_CSS_SP_MAX_WIDTH

/* This is the maximum grid we can handle in the ISP binaries.
 * The host code makes sure no bigger grid is ever selected. */
#define SH_CSS_MAX_BQ_GRID_WIDTH
#define SH_CSS_MAX_BQ_GRID_HEIGHT

/* The minimum dvs envelope is 12x12(for IPU2) to make sure the
 * invalid rows/columns that result from filter initialization are skipped. */
#define SH_CSS_MIN_DVS_ENVELOPE

/* The FPGA system (vec_nelems == 16) only supports up to 5MP */
#define SH_CSS_MAX_SENSOR_WIDTH
#define SH_CSS_MAX_SENSOR_HEIGHT

/* Limited to reduce vmem pressure */
#if ISP_VMEM_DEPTH >= 3072
#define SH_CSS_MAX_CONTINUOUS_SENSOR_WIDTH
#define SH_CSS_MAX_CONTINUOUS_SENSOR_HEIGHT
#else
#define SH_CSS_MAX_CONTINUOUS_SENSOR_WIDTH
#define SH_CSS_MAX_CONTINUOUS_SENSOR_HEIGHT
#endif
/* When using bayer decimation */
/*
#define SH_CSS_MAX_CONTINUOUS_SENSOR_WIDTH_DEC  4224
#define SH_CSS_MAX_CONTINUOUS_SENSOR_HEIGHT_DEC 3168
*/
#define SH_CSS_MAX_CONTINUOUS_SENSOR_WIDTH_DEC
#define SH_CSS_MAX_CONTINUOUS_SENSOR_HEIGHT_DEC

#define SH_CSS_MIN_SENSOR_WIDTH
#define SH_CSS_MIN_SENSOR_HEIGHT

/*
#define SH_CSS_MAX_VF_WIDTH_DEC               1920
#define SH_CSS_MAX_VF_HEIGHT_DEC              1080
*/
#define SH_CSS_MAX_VF_WIDTH_DEC
#define SH_CSS_MAX_VF_HEIGHT_DEC

/* We use 16 bits per coordinate component, including integer
   and fractional bits */
#define SH_CSS_MORPH_TABLE_GRID
#define SH_CSS_MORPH_TABLE_ELEM_BYTES
#define SH_CSS_MORPH_TABLE_ELEMS_PER_DDR_WORD

#define SH_CSS_MAX_SCTBL_WIDTH_PER_COLOR
#define SH_CSS_MAX_SCTBL_HEIGHT_PER_COLOR

#define SH_CSS_MAX_SCTBL_ALIGNED_WIDTH_PER_COLOR

/* Each line of this table is aligned to the maximum line width. */
#define SH_CSS_MAX_S3ATBL_WIDTH

/* Video mode specific DVS define */
/* The video binary supports a delay of 1 or 2 frames */
#define MAX_DVS_FRAME_DELAY
/* +1 because DVS reads the previous and writes the current frame concurrently */
#define MAX_NUM_VIDEO_DELAY_FRAMES

#define NUM_VIDEO_TNR_FRAMES

/* Note that this is the define used to configure all data structures common for all modes */
/* It should be equal or bigger to the max number of DVS frames for all possible modes */
/* Rules: these implement logic shared between the host code and ISP firmware.
   The ISP firmware needs these rules to be applied at pre-processor time,
   that's why these are macros, not functions. */
#define _ISP_BQS(num)
#define _ISP_VECS(width)

#define ISP_BQ_GRID_WIDTH(elements_per_line, deci_factor_log2)
#define ISP_BQ_GRID_HEIGHT(lines_per_frame, deci_factor_log2)
#define ISP_C_VECTORS_PER_LINE(elements_per_line)

/* The morphing table is similar to the shading table in the sense that we
   have 1 more value than we have cells in the grid. */
#define _ISP_MORPH_TABLE_WIDTH(int_width)
#define _ISP_MORPH_TABLE_HEIGHT(int_height)
#define _ISP_MORPH_TABLE_ALIGNED_WIDTH(width)

#define _ISP_SCTBL_WIDTH_PER_COLOR(input_width, deci_factor_log2)
#define _ISP_SCTBL_HEIGHT(input_height, deci_factor_log2)
#define _ISP_SCTBL_ALIGNED_WIDTH_PER_COLOR(input_width, deci_factor_log2)

/* To position the shading center grid point on the center of output image,
 * one more grid cell is needed as margin. */
#define SH_CSS_SCTBL_CENTERING_MARGIN

/* The shading table width and height are the number of grids, not cells. The last grid should be counted. */
#define SH_CSS_SCTBL_LAST_GRID_COUNT

/* Number of horizontal grids per color in the shading table. */
#define _ISP2401_SCTBL_WIDTH_PER_COLOR(input_width, deci_factor_log2)

/* Number of vertical grids per color in the shading table. */
#define _ISP2401_SCTBL_HEIGHT(input_height, deci_factor_log2)

/* ISP2401: Legacy API: Number of horizontal grids per color in the shading table. */
#define _ISP_SCTBL_LEGACY_WIDTH_PER_COLOR(input_width, deci_factor_log2)

/* ISP2401: Legacy API: Number of vertical grids per color in the shading table. */
#define _ISP_SCTBL_LEGACY_HEIGHT(input_height, deci_factor_log2)

/* *****************************************************************
 * Statistics for 3A (Auto Focus, Auto White Balance, Auto Exposure)
 * *****************************************************************/
/* if left cropping is used, 3A statistics are also cropped by 2 vectors. */
#define _ISP_S3ATBL_WIDTH(in_width, deci_factor_log2)
#define _ISP_S3ATBL_HEIGHT(in_height, deci_factor_log2)
#define _ISP_S3A_ELEMS_ISP_WIDTH(width, left_crop)

#define _ISP_S3ATBL_ISP_WIDTH(in_width, deci_factor_log2)
#define _ISP_S3ATBL_ISP_HEIGHT(in_height, deci_factor_log2)
#define ISP_S3ATBL_VECTORS
#define ISP_S3ATBL_HI_LO_STRIDE
#define ISP_S3ATBL_HI_LO_STRIDE_BYTES

/* Viewfinder support */
#define __ISP_MAX_VF_OUTPUT_WIDTH(width, left_crop)

#define __ISP_VF_OUTPUT_WIDTH_VECS(out_width, vf_log_downscale)

#define _ISP_VF_OUTPUT_WIDTH(vf_out_vecs)
#define _ISP_VF_OUTPUT_HEIGHT(out_height, vf_log_ds)

#define _ISP_LOG_VECTOR_STEP(mode)

/* It is preferred to have not more than 2x scaling at one step
 * in GDC (assumption is for capture_pp and yuv_scale stages) */
#define MAX_PREFERRED_YUV_DS_PER_STEP

/* Rules for computing the internal width. This is extremely complicated
 * and definitely needs to be commented and explained. */
#define _ISP_LEFT_CROP_EXTRA(left_crop)

#define __ISP_MIN_INTERNAL_WIDTH(num_chunks, pipelining, mode)

#define __ISP_PADDED_OUTPUT_WIDTH(out_width, dvs_env_width, left_crop)

#define __ISP_CHUNK_STRIDE_ISP(mode)

#define __ISP_CHUNK_STRIDE_DDR(c_subsampling, num_chunks)
#define __ISP_INTERNAL_WIDTH(out_width, \
			     dvs_env_width, \
			     left_crop, \
			     mode, \
			     c_subsampling, \
			     num_chunks, \
			     pipelining)

#define __ISP_INTERNAL_HEIGHT(out_height, dvs_env_height, top_crop)

/* @GC: Input can be up to sensor resolution when either bayer downscaling
 *	or raw binning is enabled.
 *	Also, during continuous mode, we need to align to 4*NWAY since input
 *	should support binning */
#define _ISP_MAX_INPUT_WIDTH(max_internal_width, enable_ds, enable_fixed_bayer_ds, enable_raw_bin, \
				enable_continuous)

#define _ISP_INPUT_WIDTH(internal_width, ds_input_width, enable_ds)

#define _ISP_MAX_INPUT_HEIGHT(max_internal_height, enable_ds, enable_fixed_bayer_ds, enable_raw_bin, \
				enable_continuous)

#define _ISP_INPUT_HEIGHT(internal_height, ds_input_height, enable_ds)

#define SH_CSS_MAX_STAGES

/* For CSI2+ input system, it requires extra paddinga from vmem */
#define _ISP_EXTRA_PADDING_VECS

#endif /* _SH_CSS_DEFS_H_ */