xref: /linux/drivers/staging/media/atomisp/pci/isp/kernels/s3a/s3a_1.0/ia_css_s3a_types.h (revision c771600c6af14749609b49565ffb4cac2959710d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  */
6 
7 #ifndef __IA_CSS_S3A_TYPES_H
8 #define __IA_CSS_S3A_TYPES_H
9 
10 /* @file
11 * CSS-API header file for 3A statistics parameters.
12 */
13 
14 #include <ia_css_frac.h>
15 
16 #if (defined(SYSTEM_css_skycam_c0_system)) && (!defined(PIPE_GENERATION))
17 #include "../../../../components/stats_3a/src/stats_3a_public.h"
18 #endif
19 
20 /* 3A configuration. This configures the 3A statistics collection
21  *  module.
22  */
23 
24 /* 3A statistics grid
25  *
26  *  ISP block: S3A1 (3A Support for 3A ver.1 (Histogram is not used for AE))
27  *             S3A2 (3A Support for 3A ver.2 (Histogram is used for AE))
28  *  ISP1: S3A1 is used.
29  *  ISP2: S3A2 is used.
30  */
31 struct ia_css_3a_grid_info {
32 #if defined(SYSTEM_css_skycam_c0_system)
33 	u32 ae_enable;					/** ae enabled in binary,
34 								   0:disabled, 1:enabled */
35 	struct ae_public_config_grid_config
36 		ae_grd_info;	/** see description in ae_public.h*/
37 
38 	u32 awb_enable;					/** awb enabled in binary,
39 								   0:disabled, 1:enabled */
40 	struct awb_public_config_grid_config
41 		awb_grd_info;	/** see description in awb_public.h*/
42 
43 	u32 af_enable;					/** af enabled in binary,
44 								   0:disabled, 1:enabled */
45 	struct af_public_grid_config		af_grd_info;	/** see description in af_public.h*/
46 
47 	u32 awb_fr_enable;					/** awb_fr enabled in binary,
48 								   0:disabled, 1:enabled */
49 	struct awb_fr_public_grid_config
50 		awb_fr_grd_info;/** see description in awb_fr_public.h*/
51 
52 	u32 elem_bit_depth;    /** TODO:Taken from BYT  - need input from AIQ
53 					if needed for SKC
54 					Bit depth of element used
55 					to calculate 3A statistics.
56 					This is 13, which is the normalized
57 					bayer bit depth in DSP. */
58 
59 #else
60 	u32 enable;            /** 3A statistics enabled.
61 					0:disabled, 1:enabled */
62 	u32 use_dmem;          /** DMEM or VMEM determines layout.
63 					0:3A statistics are stored to VMEM,
64 					1:3A statistics are stored to DMEM */
65 	u32 has_histogram;     /** Statistics include histogram.
66 					0:no histogram, 1:has histogram */
67 	u32 width;		    /** Width of 3A grid table.
68 					(= Horizontal number of grid cells
69 					in table, which cells have effective
70 					statistics.) */
71 	u32 height;	    /** Height of 3A grid table.
72 					(= Vertical number of grid cells
73 					in table, which cells have effective
74 					statistics.) */
75 	u32 aligned_width;     /** Horizontal stride (for alloc).
76 					(= Horizontal number of grid cells
77 					in table, which means
78 					the allocated width.) */
79 	u32 aligned_height;    /** Vertical stride (for alloc).
80 					(= Vertical number of grid cells
81 					in table, which means
82 					the allocated height.) */
83 	u32 bqs_per_grid_cell; /** Grid cell size in BQ(Bayer Quad) unit.
84 					(1BQ means {Gr,R,B,Gb}(2x2 pixels).)
85 					Valid values are 8,16,32,64. */
86 	u32 deci_factor_log2;  /** log2 of bqs_per_grid_cell. */
87 	u32 elem_bit_depth;    /** Bit depth of element used
88 					to calculate 3A statistics.
89 					This is 13, which is the normalized
90 					bayer bit depth in DSP. */
91 #endif
92 };
93 
94 /* This struct should be split into 3, for AE, AWB and AF.
95  * However, that will require driver/ 3A lib modifications.
96  */
97 
98 /* 3A configuration. This configures the 3A statistics collection
99  *  module.
100  *
101  *  ae_y_*: Coefficients to calculate luminance from bayer.
102  *  awb_lg_*: Thresholds to check the saturated bayer pixels for AWB.
103  *    Condition of effective pixel for AWB level gate check:
104  *      bayer(sensor) <= awb_lg_high_raw &&
105  *      bayer(when AWB statisitcs is calculated) >= awb_lg_low &&
106  *      bayer(when AWB statisitcs is calculated) <= awb_lg_high
107  *  af_fir*: Coefficients of high pass filter to calculate AF statistics.
108  *
109  *  ISP block: S3A1(ae_y_* for AE/AF, awb_lg_* for AWB)
110  *             S3A2(ae_y_* for AF, awb_lg_* for AWB)
111  *             SDVS1(ae_y_*)
112  *             SDVS2(ae_y_*)
113  *  ISP1: S3A1 and SDVS1 are used.
114  *  ISP2: S3A2 and SDVS2 are used.
115  */
116 struct ia_css_3a_config {
117 	ia_css_u0_16 ae_y_coef_r;	/** Weight of R for Y.
118 						u0.16, [0,65535],
119 						default/ineffective 25559 */
120 	ia_css_u0_16 ae_y_coef_g;	/** Weight of G for Y.
121 						u0.16, [0,65535],
122 						default/ineffective 32768 */
123 	ia_css_u0_16 ae_y_coef_b;	/** Weight of B for Y.
124 						u0.16, [0,65535],
125 						default/ineffective 7209 */
126 	ia_css_u0_16 awb_lg_high_raw;	/** AWB level gate high for raw.
127 						u0.16, [0,65535],
128 						default 65472(=1023*64),
129 						ineffective 65535 */
130 	ia_css_u0_16 awb_lg_low;	/** AWB level gate low.
131 						u0.16, [0,65535],
132 						default 64(=1*64),
133 						ineffective 0 */
134 	ia_css_u0_16 awb_lg_high;	/** AWB level gate high.
135 						u0.16, [0,65535],
136 						default 65535,
137 						ineffective 65535 */
138 	ia_css_s0_15 af_fir1_coef[7];	/** AF FIR coefficients of fir1.
139 						s0.15, [-32768,32767],
140 				default/ineffective
141 				-6689,-12207,-32768,32767,12207,6689,0 */
142 	ia_css_s0_15 af_fir2_coef[7];	/** AF FIR coefficients of fir2.
143 						s0.15, [-32768,32767],
144 				default/ineffective
145 				2053,0,-18437,32767,-18437,2053,0 */
146 };
147 
148 /* 3A statistics. This structure describes the data stored
149  *  in each 3A grid point.
150  *
151  *  ISP block: S3A1 (3A Support for 3A ver.1) (Histogram is not used for AE)
152  *             S3A2 (3A Support for 3A ver.2) (Histogram is used for AE)
153  *             - ae_y is used only for S3A1.
154  *             - awb_* and af_* are used both for S3A1 and S3A2.
155  *  ISP1: S3A1 is used.
156  *  ISP2: S3A2 is used.
157  */
158 struct ia_css_3a_output {
159 	s32 ae_y;    /** Sum of Y in a statistics window, for AE.
160 				(u19.13) */
161 	s32 awb_cnt; /** Number of effective pixels
162 				in a statistics window.
163 				Pixels passed by the AWB level gate check are
164 				judged as "effective". (u32) */
165 	s32 awb_gr;  /** Sum of Gr in a statistics window, for AWB.
166 				All Gr pixels (not only for effective pixels)
167 				are summed. (u19.13) */
168 	s32 awb_r;   /** Sum of R in a statistics window, for AWB.
169 				All R pixels (not only for effective pixels)
170 				are summed. (u19.13) */
171 	s32 awb_b;   /** Sum of B in a statistics window, for AWB.
172 				All B pixels (not only for effective pixels)
173 				are summed. (u19.13) */
174 	s32 awb_gb;  /** Sum of Gb in a statistics window, for AWB.
175 				All Gb pixels (not only for effective pixels)
176 				are summed. (u19.13) */
177 	s32 af_hpf1; /** Sum of |Y| following high pass filter af_fir1
178 				within a statistics window, for AF. (u19.13) */
179 	s32 af_hpf2; /** Sum of |Y| following high pass filter af_fir2
180 				within a statistics window, for AF. (u19.13) */
181 };
182 
183 /* 3A Statistics. This structure describes the statistics that are generated
184  *  using the provided configuration (ia_css_3a_config).
185  */
186 struct ia_css_3a_statistics {
187 	struct ia_css_3a_grid_info
188 		grid;	/** grid info contains the dimensions of the 3A grid */
189 	struct ia_css_3a_output
190 		*data;	/** the pointer to 3a_output[grid.width * grid.height]
191 						     containing the 3A statistics */
192 	struct ia_css_3a_rgby_output *rgby_data;/** the pointer to 3a_rgby_output[256]
193 						     containing the histogram */
194 };
195 
196 /* Histogram (Statistics for AE).
197  *
198  *  4 histograms(r,g,b,y),
199  *  256 bins for each histogram, unsigned 24bit value for each bin.
200  *    struct ia_css_3a_rgby_output data[256];
201 
202  *  ISP block: HIST2
203  * (ISP1: HIST2 is not used.)
204  *  ISP2: HIST2 is used.
205  */
206 struct ia_css_3a_rgby_output {
207 	u32 r;	/** Number of R of one bin of the histogram R. (u24) */
208 	u32 g;	/** Number of G of one bin of the histogram G. (u24) */
209 	u32 b;	/** Number of B of one bin of the histogram B. (u24) */
210 	u32 y;	/** Number of Y of one bin of the histogram Y. (u24) */
211 };
212 
213 #endif /* __IA_CSS_S3A_TYPES_H */
214