xref: /linux/drivers/staging/media/atomisp/include/linux/atomisp.h (revision 42b16d3ac371a2fac9b6f08fd75f23f34ba3955a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Medifield PNW Camera Imaging ISP subsystem.
4  *
5  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version
9  * 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  *
17  */
18 
19 #ifndef _ATOM_ISP_H
20 #define _ATOM_ISP_H
21 
22 #include <linux/types.h>
23 
24 /* struct media_device_info.hw_revision */
25 #define ATOMISP_HW_REVISION_MASK	0x0000ff00
26 #define ATOMISP_HW_REVISION_SHIFT	8
27 #define ATOMISP_HW_REVISION_ISP2300	0x00
28 #define ATOMISP_HW_REVISION_ISP2400	0x10
29 #define ATOMISP_HW_REVISION_ISP2401_LEGACY 0x11
30 #define ATOMISP_HW_REVISION_ISP2401	0x20
31 
32 #define ATOMISP_HW_STEPPING_MASK	0x000000ff
33 #define ATOMISP_HW_STEPPING_A0		0x00
34 #define ATOMISP_HW_STEPPING_B0		0x10
35 
36 /*ISP binary running mode*/
37 #define CI_MODE_PREVIEW		0x8000
38 #define CI_MODE_VIDEO		0x4000
39 #define CI_MODE_STILL_CAPTURE	0x2000
40 #define CI_MODE_NONE		0x0000
41 
42 #define OUTPUT_MODE_FILE 0x0100
43 #define OUTPUT_MODE_TEXT 0x0200
44 
45 /*
46  * Camera HAL sets this flag in v4l2_buffer reserved2 to indicate this
47  * buffer has a per-frame parameter.
48  */
49 #define ATOMISP_BUFFER_HAS_PER_FRAME_SETTING	0x80000000
50 
51 /* Custom format for RAW capture from M10MO 0x3130314d */
52 #define V4L2_PIX_FMT_CUSTOM_M10MO_RAW	v4l2_fourcc('M', '1', '0', '1')
53 
54 /* Custom media bus formats being used in atomisp */
55 #define V4L2_MBUS_FMT_CUSTOM_YUV420	0x8001
56 #define V4L2_MBUS_FMT_CUSTOM_YVU420	0x8002
57 #define V4L2_MBUS_FMT_CUSTOM_YUV422P	0x8003
58 #define V4L2_MBUS_FMT_CUSTOM_YUV444	0x8004
59 #define V4L2_MBUS_FMT_CUSTOM_NV12	0x8005
60 #define V4L2_MBUS_FMT_CUSTOM_NV21	0x8006
61 #define V4L2_MBUS_FMT_CUSTOM_NV16	0x8007
62 #define V4L2_MBUS_FMT_CUSTOM_YUYV	0x8008
63 #define V4L2_MBUS_FMT_CUSTOM_SBGGR16	0x8009
64 #define V4L2_MBUS_FMT_CUSTOM_RGB32	0x800a
65 
66 /* Custom media bus format for M10MO RAW capture */
67 #if 0
68 #define V4L2_MBUS_FMT_CUSTOM_M10MO_RAW	0x800b
69 #endif
70 
71 /* Configuration used by Bayer noise reduction and YCC noise reduction */
72 struct atomisp_nr_config {
73 	/* [gain] Strength of noise reduction for Bayer NR (Used by Bayer NR) */
74 	unsigned int bnr_gain;
75 	/* [gain] Strength of noise reduction for YCC NR (Used by YCC NR) */
76 	unsigned int ynr_gain;
77 	/* [intensity] Sensitivity of Edge (Used by Bayer NR) */
78 	unsigned int direction;
79 	/* [intensity] coring threshold for Cb (Used by YCC NR) */
80 	unsigned int threshold_cb;
81 	/* [intensity] coring threshold for Cr (Used by YCC NR) */
82 	unsigned int threshold_cr;
83 };
84 
85 /* Temporal noise reduction configuration */
86 struct atomisp_tnr_config {
87 	unsigned int gain;	 /* [gain] Strength of NR */
88 	unsigned int threshold_y;/* [intensity] Motion sensitivity for Y */
89 	unsigned int threshold_uv;/* [intensity] Motion sensitivity for U/V */
90 };
91 
92 /* Histogram. This contains num_elements values of type unsigned int.
93  * The data pointer is a DDR pointer (virtual address).
94  */
95 struct atomisp_histogram {
96 	unsigned int num_elements;
97 	void __user *data;
98 };
99 
100 enum atomisp_ob_mode {
101 	atomisp_ob_mode_none,
102 	atomisp_ob_mode_fixed,
103 	atomisp_ob_mode_raster
104 };
105 
106 /* Optical black level configuration */
107 struct atomisp_ob_config {
108 	/* Obtical black level mode (Fixed / Raster) */
109 	enum atomisp_ob_mode mode;
110 	/* [intensity] optical black level for GR (relevant for fixed mode) */
111 	unsigned int level_gr;
112 	/* [intensity] optical black level for R (relevant for fixed mode) */
113 	unsigned int level_r;
114 	/* [intensity] optical black level for B (relevant for fixed mode) */
115 	unsigned int level_b;
116 	/* [intensity] optical black level for GB (relevant for fixed mode) */
117 	unsigned int level_gb;
118 	/* [BQ] 0..63 start position of OB area (relevant for raster mode) */
119 	unsigned short start_position;
120 	/* [BQ] start..63 end position of OB area (relevant for raster mode) */
121 	unsigned short end_position;
122 };
123 
124 /* Edge enhancement (sharpen) configuration */
125 struct atomisp_ee_config {
126 	/* [gain] The strength of sharpness. u5_11 */
127 	unsigned int gain;
128 	/* [intensity] The threshold that divides noises from edge. u8_8 */
129 	unsigned int threshold;
130 	/* [gain] The strength of sharpness in pell-mell area. u5_11 */
131 	unsigned int detail_gain;
132 };
133 
134 struct atomisp_3a_output {
135 	int ae_y;
136 	int awb_cnt;
137 	int awb_gr;
138 	int awb_r;
139 	int awb_b;
140 	int awb_gb;
141 	int af_hpf1;
142 	int af_hpf2;
143 };
144 
145 enum atomisp_calibration_type {
146 	calibration_type1,
147 	calibration_type2,
148 	calibration_type3
149 };
150 
151 struct atomisp_gc_config {
152 	__u16 gain_k1;
153 	__u16 gain_k2;
154 };
155 
156 struct atomisp_3a_config {
157 	unsigned int ae_y_coef_r;	/* [gain] Weight of R for Y */
158 	unsigned int ae_y_coef_g;	/* [gain] Weight of G for Y */
159 	unsigned int ae_y_coef_b;	/* [gain] Weight of B for Y */
160 	unsigned int awb_lg_high_raw;	/* [intensity]
161 					   AWB level gate high for raw */
162 	unsigned int awb_lg_low;	/* [intensity] AWB level gate low */
163 	unsigned int awb_lg_high;	/* [intensity] AWB level gate high */
164 	int af_fir1_coef[7];	/* [factor] AF FIR coefficients of fir1 */
165 	int af_fir2_coef[7];	/* [factor] AF FIR coefficients of fir2 */
166 };
167 
168 struct atomisp_dvs_grid_info {
169 	u32 enable;
170 	u32 width;
171 	u32 aligned_width;
172 	u32 height;
173 	u32 aligned_height;
174 	u32 bqs_per_grid_cell;
175 	u32 num_hor_coefs;
176 	u32 num_ver_coefs;
177 };
178 
179 struct atomisp_dvs_envelop {
180 	unsigned int width;
181 	unsigned int height;
182 };
183 
184 struct atomisp_grid_info {
185 	u32 enable;
186 	u32 use_dmem;
187 	u32 has_histogram;
188 	u32 s3a_width;
189 	u32 s3a_height;
190 	u32 aligned_width;
191 	u32 aligned_height;
192 	u32 s3a_bqs_per_grid_cell;
193 	u32 deci_factor_log2;
194 	u32 elem_bit_depth;
195 };
196 
197 struct atomisp_dis_vector {
198 	int x;
199 	int y;
200 };
201 
202 /* DVS 2.0 Coefficient types. This structure contains 4 pointers to
203  *  arrays that contain the coefficients for each type.
204  */
205 struct atomisp_dvs2_coef_types {
206 	short __user *odd_real; /** real part of the odd coefficients*/
207 	short __user *odd_imag; /** imaginary part of the odd coefficients*/
208 	short __user *even_real;/** real part of the even coefficients*/
209 	short __user *even_imag;/** imaginary part of the even coefficients*/
210 };
211 
212 /*
213  * DVS 2.0 Statistic types. This structure contains 4 pointers to
214  * arrays that contain the statistics for each type.
215  */
216 struct atomisp_dvs2_stat_types {
217 	int __user *odd_real; /** real part of the odd statistics*/
218 	int __user *odd_imag; /** imaginary part of the odd statistics*/
219 	int __user *even_real;/** real part of the even statistics*/
220 	int __user *even_imag;/** imaginary part of the even statistics*/
221 };
222 
223 struct atomisp_dis_coefficients {
224 	struct atomisp_dvs_grid_info grid_info;
225 	struct atomisp_dvs2_coef_types hor_coefs;
226 	struct atomisp_dvs2_coef_types ver_coefs;
227 };
228 
229 struct atomisp_dvs2_statistics {
230 	struct atomisp_dvs_grid_info grid_info;
231 	struct atomisp_dvs2_stat_types hor_prod;
232 	struct atomisp_dvs2_stat_types ver_prod;
233 };
234 
235 struct atomisp_dis_statistics {
236 	struct atomisp_dvs2_statistics dvs2_stat;
237 	u32 exp_id;
238 };
239 
240 struct atomisp_3a_rgby_output {
241 	u32 r;
242 	u32 g;
243 	u32 b;
244 	u32 y;
245 };
246 
247 /*
248  * Because we have 2 pipes at max to output metadata, therefore driver will use
249  * ATOMISP_MAIN_METADATA to specify the metadata from the pipe which keeps
250  * streaming always and use ATOMISP_SEC_METADATA to specify the metadata from
251  * the pipe which is streaming by request like capture pipe of ZSL or SDV mode
252  * as secondary metadata. And for the use case which has only one pipe
253  * streaming like online capture, ATOMISP_MAIN_METADATA will be used.
254  */
255 enum atomisp_metadata_type {
256 	ATOMISP_MAIN_METADATA = 0,
257 	ATOMISP_SEC_METADATA,
258 	ATOMISP_METADATA_TYPE_NUM,
259 };
260 
261 struct atomisp_ext_isp_ctrl {
262 	u32 id;
263 	u32 data;
264 };
265 
266 struct atomisp_3a_statistics {
267 	struct atomisp_grid_info  grid_info;
268 	struct atomisp_3a_output __user *data;
269 	struct atomisp_3a_rgby_output __user *rgby_data;
270 	u32 exp_id; /* exposure ID */
271 	u32 isp_config_id; /* isp config ID */
272 };
273 
274 /* White Balance (Gain Adjust) */
275 struct atomisp_wb_config {
276 	unsigned int integer_bits;
277 	unsigned int gr;	/* unsigned <integer_bits>.<16-integer_bits> */
278 	unsigned int r;		/* unsigned <integer_bits>.<16-integer_bits> */
279 	unsigned int b;		/* unsigned <integer_bits>.<16-integer_bits> */
280 	unsigned int gb;	/* unsigned <integer_bits>.<16-integer_bits> */
281 };
282 
283 /* Color Space Conversion settings */
284 struct atomisp_cc_config {
285 	unsigned int fraction_bits;
286 	int matrix[3 * 3];	/* RGB2YUV Color matrix, signed
287 				   <13-fraction_bits>.<fraction_bits> */
288 };
289 
290 /* De pixel noise configuration */
291 struct atomisp_de_config {
292 	unsigned int pixelnoise;
293 	unsigned int c1_coring_threshold;
294 	unsigned int c2_coring_threshold;
295 };
296 
297 /* Chroma enhancement */
298 struct atomisp_ce_config {
299 	unsigned char uv_level_min;
300 	unsigned char uv_level_max;
301 };
302 
303 /* Defect pixel correction configuration */
304 struct atomisp_dp_config {
305 	/* [intensity] The threshold of defect Pixel Correction, representing
306 	 * the permissible difference of intensity between one pixel and its
307 	 * surrounding pixels. Smaller values result in more frequent pixel
308 	 * corrections. u0_16
309 	 */
310 	unsigned int threshold;
311 	/* [gain] The sensitivity of mis-correction. ISP will miss a lot of
312 	 * defects if the value is set too large. u8_8
313 	 */
314 	unsigned int gain;
315 	unsigned int gr;
316 	unsigned int r;
317 	unsigned int b;
318 	unsigned int gb;
319 };
320 
321 /* XNR threshold */
322 struct atomisp_xnr_config {
323 	__u16 threshold;
324 };
325 
326 /* metadata config */
327 struct atomisp_metadata_config {
328 	u32 metadata_height;
329 	u32 metadata_stride;
330 };
331 
332 /*
333  * Generic resolution structure.
334  */
335 struct atomisp_resolution {
336 	u32 width;  /** Width */
337 	u32 height; /** Height */
338 };
339 
340 /*
341  * This specifies the coordinates (x,y)
342  */
343 struct atomisp_zoom_point {
344 	s32 x; /** x coordinate */
345 	s32 y; /** y coordinate */
346 };
347 
348 /*
349  * This specifies the region
350  */
351 struct atomisp_zoom_region {
352 	struct atomisp_zoom_point
353 		origin; /* Starting point coordinates for the region */
354 	struct atomisp_resolution resolution; /* Region resolution */
355 };
356 
357 struct atomisp_dz_config {
358 	u32 dx; /** Horizontal zoom factor */
359 	u32 dy; /** Vertical zoom factor */
360 	struct atomisp_zoom_region zoom_region; /** region for zoom */
361 };
362 
363 struct atomisp_parm {
364 	struct atomisp_grid_info info;
365 	struct atomisp_dvs_grid_info dvs_grid;
366 	struct atomisp_dvs_envelop dvs_envelop;
367 	struct atomisp_wb_config wb_config;
368 	struct atomisp_cc_config cc_config;
369 	struct atomisp_ob_config ob_config;
370 	struct atomisp_de_config de_config;
371 	struct atomisp_dz_config dz_config;
372 	struct atomisp_ce_config ce_config;
373 	struct atomisp_dp_config dp_config;
374 	struct atomisp_nr_config nr_config;
375 	struct atomisp_ee_config ee_config;
376 	struct atomisp_tnr_config tnr_config;
377 	struct atomisp_metadata_config metadata_config;
378 };
379 
380 struct dvs2_bq_resolution {
381 	int width_bq;         /* width [BQ] */
382 	int height_bq;        /* height [BQ] */
383 };
384 
385 struct atomisp_dvs2_bq_resolutions {
386 	/* GDC source image size [BQ] */
387 	struct dvs2_bq_resolution source_bq;
388 	/* GDC output image size [BQ] */
389 	struct dvs2_bq_resolution output_bq;
390 	/* GDC effective envelope size [BQ] */
391 	struct dvs2_bq_resolution envelope_bq;
392 	/* isp pipe filter size [BQ] */
393 	struct dvs2_bq_resolution ispfilter_bq;
394 	/* GDC shit size [BQ] */
395 	struct dvs2_bq_resolution gdc_shift_bq;
396 };
397 
398 struct atomisp_dvs_6axis_config {
399 	u32 exp_id;
400 	u32 width_y;
401 	u32 height_y;
402 	u32 width_uv;
403 	u32 height_uv;
404 	u32 *xcoords_y;
405 	u32 *ycoords_y;
406 	u32 *xcoords_uv;
407 	u32 *ycoords_uv;
408 };
409 
410 struct atomisp_formats_config {
411 	u32 video_full_range_flag;
412 };
413 
414 struct atomisp_parameters {
415 	struct atomisp_wb_config   *wb_config;  /* White Balance config */
416 	struct atomisp_cc_config   *cc_config;  /* Color Correction config */
417 	struct atomisp_tnr_config  *tnr_config; /* Temporal Noise Reduction */
418 	struct atomisp_ecd_config  *ecd_config; /* Eigen Color Demosaicing */
419 	struct atomisp_ynr_config  *ynr_config; /* Y(Luma) Noise Reduction */
420 	struct atomisp_fc_config   *fc_config;  /* Fringe Control */
421 	struct atomisp_formats_config *formats_config; /* Formats Control */
422 	struct atomisp_cnr_config  *cnr_config; /* Chroma Noise Reduction */
423 	struct atomisp_macc_config *macc_config;  /* MACC */
424 	struct atomisp_ctc_config  *ctc_config; /* Chroma Tone Control */
425 	struct atomisp_aa_config   *aa_config;  /* Anti-Aliasing */
426 	struct atomisp_aa_config   *baa_config;  /* Anti-Aliasing */
427 	struct atomisp_ce_config   *ce_config;
428 	struct atomisp_dvs_6axis_config *dvs_6axis_config;
429 	struct atomisp_ob_config   *ob_config;  /* Objective Black config */
430 	struct atomisp_dp_config   *dp_config;  /* Dead Pixel config */
431 	struct atomisp_nr_config   *nr_config;  /* Noise Reduction config */
432 	struct atomisp_ee_config   *ee_config;  /* Edge Enhancement config */
433 	struct atomisp_de_config   *de_config;  /* Demosaic config */
434 	struct atomisp_gc_config   *gc_config;  /* Gamma Correction config */
435 	struct atomisp_anr_config  *anr_config; /* Advanced Noise Reduction */
436 	struct atomisp_3a_config   *a3a_config; /* 3A Statistics config */
437 	struct atomisp_xnr_config  *xnr_config; /* eXtra Noise Reduction */
438 	struct atomisp_dz_config   *dz_config;  /* Digital Zoom */
439 	struct atomisp_cc_config *yuv2rgb_cc_config; /* Color
440 							Correction config */
441 	struct atomisp_cc_config *rgb2yuv_cc_config; /* Color
442 							Correction config */
443 	struct atomisp_macc_table  *macc_table;
444 	struct atomisp_gamma_table *gamma_table;
445 	struct atomisp_ctc_table   *ctc_table;
446 	struct atomisp_xnr_table   *xnr_table;
447 	struct atomisp_rgb_gamma_table *r_gamma_table;
448 	struct atomisp_rgb_gamma_table *g_gamma_table;
449 	struct atomisp_rgb_gamma_table *b_gamma_table;
450 	struct atomisp_vector      *motion_vector; /* For 2-axis DVS */
451 	struct atomisp_shading_table *shading_table;
452 	struct atomisp_morph_table   *morph_table;
453 	struct atomisp_dvs_coefficients *dvs_coefs; /* DVS 1.0 coefficients */
454 	struct atomisp_dis_coefficients *dvs2_coefs; /* DVS 2.0 coefficients */
455 	struct atomisp_capture_config   *capture_config;
456 	struct atomisp_anr_thres   *anr_thres;
457 
458 	void	*lin_2500_config;       /* Skylake: Linearization config */
459 	void	*obgrid_2500_config;    /* Skylake: OBGRID config */
460 	void	*bnr_2500_config;       /* Skylake: bayer denoise config */
461 	void	*shd_2500_config;       /* Skylake: shading config */
462 	void	*dm_2500_config;        /* Skylake: demosaic config */
463 	void	*rgbpp_2500_config;     /* Skylake: RGBPP config */
464 	void	*dvs_stat_2500_config;  /* Skylake: DVS STAT config */
465 	void	*lace_stat_2500_config; /* Skylake: LACE STAT config */
466 	void	*yuvp1_2500_config;     /* Skylake: yuvp1 config */
467 	void	*yuvp2_2500_config;     /* Skylake: yuvp2 config */
468 	void	*tnr_2500_config;       /* Skylake: TNR config */
469 	void	*dpc_2500_config;       /* Skylake: DPC config */
470 	void	*awb_2500_config;       /* Skylake: auto white balance config */
471 	void	*awb_fr_2500_config;    /* Skylake: auto white balance filter response config */
472 	void	*anr_2500_config;       /* Skylake: ANR config */
473 	void	*af_2500_config;        /* Skylake: auto focus config */
474 	void	*ae_2500_config;        /* Skylake: auto exposure config */
475 	void	*bds_2500_config;       /* Skylake: bayer downscaler config */
476 	void	*dvs_2500_config;       /* Skylake: digital video stabilization config */
477 	void	*res_mgr_2500_config;
478 
479 	/*
480 	 * Output frame pointer the config is to be applied to (optional),
481 	 * set to NULL to make this config is applied as global.
482 	 */
483 	void	*output_frame;
484 	/*
485 	 * Unique ID to track which config was actually applied to a particular
486 	 * frame, driver will send this id back with output frame together.
487 	 */
488 	u32	isp_config_id;
489 
490 	/*
491 	 * Switch to control per_frame setting:
492 	 * 0: this is a global setting
493 	 * 1: this is a per_frame setting
494 	 * PLEASE KEEP THIS AT THE END OF THE STRUCTURE!!
495 	 */
496 	u32	per_frame_setting;
497 };
498 
499 #define ATOMISP_GAMMA_TABLE_SIZE        1024
500 struct atomisp_gamma_table {
501 	unsigned short data[ATOMISP_GAMMA_TABLE_SIZE];
502 };
503 
504 /* Morphing table for advanced ISP.
505  * Each line of width elements takes up COORD_TABLE_EXT_WIDTH elements
506  * in memory.
507  */
508 #define ATOMISP_MORPH_TABLE_NUM_PLANES  6
509 struct atomisp_morph_table {
510 	unsigned int enabled;
511 
512 	unsigned int height;
513 	unsigned int width;	/* number of valid elements per line */
514 	unsigned short __user *coordinates_x[ATOMISP_MORPH_TABLE_NUM_PLANES];
515 	unsigned short __user *coordinates_y[ATOMISP_MORPH_TABLE_NUM_PLANES];
516 };
517 
518 #define ATOMISP_NUM_SC_COLORS	4
519 #define ATOMISP_SC_FLAG_QUERY	BIT(0)
520 
521 struct atomisp_shading_table {
522 	__u32 enable;
523 
524 	__u32 sensor_width;
525 	__u32 sensor_height;
526 	__u32 width;
527 	__u32 height;
528 	__u32 fraction_bits;
529 
530 	__u16 *data[ATOMISP_NUM_SC_COLORS];
531 };
532 
533 /* parameter for MACC */
534 #define ATOMISP_NUM_MACC_AXES           16
535 struct atomisp_macc_table {
536 	short data[4 * ATOMISP_NUM_MACC_AXES];
537 };
538 
539 struct atomisp_macc_config {
540 	int color_effect;
541 	struct atomisp_macc_table table;
542 };
543 
544 /* Parameter for ctc parameter control */
545 #define ATOMISP_CTC_TABLE_SIZE          1024
546 struct atomisp_ctc_table {
547 	unsigned short data[ATOMISP_CTC_TABLE_SIZE];
548 };
549 
550 /* Parameter for overlay image loading */
551 struct atomisp_overlay {
552 	/* the frame containing the overlay data The overlay frame width should
553 	 * be the multiples of 2*ISP_VEC_NELEMS. The overlay frame height
554 	 * should be the multiples of 2.
555 	 */
556 	struct v4l2_framebuffer *frame;
557 	/* Y value of overlay background */
558 	unsigned char bg_y;
559 	/* U value of overlay background */
560 	char bg_u;
561 	/* V value of overlay background */
562 	char bg_v;
563 	/* the blending percent of input data for Y subpixels */
564 	unsigned char blend_input_perc_y;
565 	/* the blending percent of input data for U subpixels */
566 	unsigned char blend_input_perc_u;
567 	/* the blending percent of input data for V subpixels */
568 	unsigned char blend_input_perc_v;
569 	/* the blending percent of overlay data for Y subpixels */
570 	unsigned char blend_overlay_perc_y;
571 	/* the blending percent of overlay data for U subpixels */
572 	unsigned char blend_overlay_perc_u;
573 	/* the blending percent of overlay data for V subpixels */
574 	unsigned char blend_overlay_perc_v;
575 	/* the overlay start x pixel position on output frame It should be the
576 	   multiples of 2*ISP_VEC_NELEMS. */
577 	unsigned int overlay_start_x;
578 	/* the overlay start y pixel position on output frame It should be the
579 	   multiples of 2. */
580 	unsigned int overlay_start_y;
581 };
582 
583 struct atomisp_exposure {
584 	unsigned int integration_time[8];
585 	unsigned int shutter_speed[8];
586 	unsigned int gain[4];
587 	unsigned int aperture;
588 };
589 
590 /* For texture streaming. */
591 struct atomisp_bc_video_package {
592 	int ioctl_cmd;
593 	int device_id;
594 	int inputparam;
595 	int outputparam;
596 };
597 
598 enum atomisp_focus_hp {
599 	ATOMISP_FOCUS_HP_IN_PROGRESS = (1U << 2),
600 	ATOMISP_FOCUS_HP_COMPLETE    = (2U << 2),
601 	ATOMISP_FOCUS_HP_FAILED      = (3U << 2)
602 };
603 
604 /* Masks */
605 #define ATOMISP_FOCUS_STATUS_MOVING           BIT(0)
606 #define ATOMISP_FOCUS_STATUS_ACCEPTS_NEW_MOVE BIT(1)
607 #define ATOMISP_FOCUS_STATUS_HOME_POSITION    (3U << 2)
608 
609 enum atomisp_camera_port {
610 	ATOMISP_CAMERA_PORT_SECONDARY,
611 	ATOMISP_CAMERA_PORT_PRIMARY,
612 	ATOMISP_CAMERA_PORT_TERTIARY,
613 	ATOMISP_CAMERA_NR_PORTS
614 };
615 
616 enum atomisp_ext_isp_id {
617 	EXT_ISP_CID_ISO = 0,
618 	EXT_ISP_CID_CAPTURE_HDR,
619 	EXT_ISP_CID_CAPTURE_LLS,
620 	EXT_ISP_CID_FOCUS_MODE,
621 	EXT_ISP_CID_FOCUS_EXECUTION,
622 	EXT_ISP_CID_TOUCH_POSX,
623 	EXT_ISP_CID_TOUCH_POSY,
624 	EXT_ISP_CID_CAF_STATUS,
625 	EXT_ISP_CID_AF_STATUS,
626 	EXT_ISP_CID_GET_AF_MODE,
627 	EXT_ISP_CID_CAPTURE_BURST,
628 	EXT_ISP_CID_ZOOM,
629 	EXT_ISP_CID_SHOT_MODE
630 };
631 
632 #define EXT_ISP_FOCUS_MODE_NORMAL	0
633 #define EXT_ISP_FOCUS_MODE_MACRO	1
634 #define EXT_ISP_FOCUS_MODE_TOUCH_AF	2
635 #define EXT_ISP_FOCUS_MODE_PREVIEW_CAF	3
636 #define EXT_ISP_FOCUS_MODE_MOVIE_CAF	4
637 #define EXT_ISP_FOCUS_MODE_FACE_CAF	5
638 #define EXT_ISP_FOCUS_MODE_TOUCH_MACRO	6
639 #define EXT_ISP_FOCUS_MODE_TOUCH_CAF	7
640 
641 #define EXT_ISP_FOCUS_STOP		0
642 #define EXT_ISP_FOCUS_SEARCH		1
643 #define EXT_ISP_PAN_FOCUSING		2
644 
645 #define EXT_ISP_CAF_RESTART_CHECK	1
646 #define EXT_ISP_CAF_STATUS_FOCUSING	2
647 #define EXT_ISP_CAF_STATUS_SUCCESS	3
648 #define EXT_ISP_CAF_STATUS_FAIL         4
649 
650 #define EXT_ISP_AF_STATUS_INVALID	1
651 #define EXT_ISP_AF_STATUS_FOCUSING	2
652 #define EXT_ISP_AF_STATUS_SUCCESS	3
653 #define EXT_ISP_AF_STATUS_FAIL		4
654 
655 enum atomisp_burst_capture_options {
656 	EXT_ISP_BURST_CAPTURE_CTRL_START = 0,
657 	EXT_ISP_BURST_CAPTURE_CTRL_STOP
658 };
659 
660 #define EXT_ISP_SHOT_MODE_AUTO		0
661 #define EXT_ISP_SHOT_MODE_BEAUTY_FACE	1
662 #define EXT_ISP_SHOT_MODE_BEST_PHOTO	2
663 #define EXT_ISP_SHOT_MODE_DRAMA		3
664 #define EXT_ISP_SHOT_MODE_BEST_FACE	4
665 #define EXT_ISP_SHOT_MODE_ERASER	5
666 #define EXT_ISP_SHOT_MODE_PANORAMA	6
667 #define EXT_ISP_SHOT_MODE_RICH_TONE_HDR	7
668 #define EXT_ISP_SHOT_MODE_NIGHT		8
669 #define EXT_ISP_SHOT_MODE_SOUND_SHOT	9
670 #define EXT_ISP_SHOT_MODE_ANIMATED_PHOTO	10
671 #define EXT_ISP_SHOT_MODE_SPORTS	11
672 
673 /*Private IOCTLs for ISP */
674 #define ATOMISP_IOC_G_XNR \
675 	_IOR('v', BASE_VIDIOC_PRIVATE + 0, int)
676 #define ATOMISP_IOC_S_XNR \
677 	_IOW('v', BASE_VIDIOC_PRIVATE + 0, int)
678 #define ATOMISP_IOC_G_NR \
679 	_IOR('v', BASE_VIDIOC_PRIVATE + 1, struct atomisp_nr_config)
680 #define ATOMISP_IOC_S_NR \
681 	_IOW('v', BASE_VIDIOC_PRIVATE + 1, struct atomisp_nr_config)
682 #define ATOMISP_IOC_G_TNR \
683 	_IOR('v', BASE_VIDIOC_PRIVATE + 2, struct atomisp_tnr_config)
684 #define ATOMISP_IOC_S_TNR \
685 	_IOW('v', BASE_VIDIOC_PRIVATE + 2, struct atomisp_tnr_config)
686 #define ATOMISP_IOC_G_HISTOGRAM \
687 	_IOWR('v', BASE_VIDIOC_PRIVATE + 3, struct atomisp_histogram)
688 #define ATOMISP_IOC_S_HISTOGRAM \
689 	_IOW('v', BASE_VIDIOC_PRIVATE + 3, struct atomisp_histogram)
690 #define ATOMISP_IOC_G_BLACK_LEVEL_COMP \
691 	_IOR('v', BASE_VIDIOC_PRIVATE + 4, struct atomisp_ob_config)
692 #define ATOMISP_IOC_S_BLACK_LEVEL_COMP \
693 	_IOW('v', BASE_VIDIOC_PRIVATE + 4, struct atomisp_ob_config)
694 #define ATOMISP_IOC_G_EE \
695 	_IOR('v', BASE_VIDIOC_PRIVATE + 5, struct atomisp_ee_config)
696 #define ATOMISP_IOC_S_EE \
697 	_IOW('v', BASE_VIDIOC_PRIVATE + 5, struct atomisp_ee_config)
698 /* Digital Image Stabilization:
699  * 1. get dis statistics: reads DIS statistics from ISP (every frame)
700  * 2. set dis coefficients: set DIS filter coefficients (one time)
701  * 3. set dis motion vector: set motion vector (result of DIS, every frame)
702  */
703 #define ATOMISP_IOC_G_DIS_STAT \
704 	_IOWR('v', BASE_VIDIOC_PRIVATE + 6, struct atomisp_dis_statistics)
705 
706 #define ATOMISP_IOC_G_DVS2_BQ_RESOLUTIONS \
707 	_IOR('v', BASE_VIDIOC_PRIVATE + 6, struct atomisp_dvs2_bq_resolutions)
708 
709 #define ATOMISP_IOC_S_DIS_COEFS \
710 	_IOW('v', BASE_VIDIOC_PRIVATE + 6, struct atomisp_dis_coefficients)
711 
712 #define ATOMISP_IOC_S_DIS_VECTOR \
713 	_IOW('v', BASE_VIDIOC_PRIVATE + 6, struct atomisp_dvs_6axis_config)
714 
715 #define ATOMISP_IOC_G_3A_STAT \
716 	_IOWR('v', BASE_VIDIOC_PRIVATE + 7, struct atomisp_3a_statistics)
717 #define ATOMISP_IOC_G_ISP_PARM \
718 	_IOR('v', BASE_VIDIOC_PRIVATE + 8, struct atomisp_parm)
719 #define ATOMISP_IOC_S_ISP_PARM \
720 	_IOW('v', BASE_VIDIOC_PRIVATE + 8, struct atomisp_parm)
721 #define ATOMISP_IOC_G_ISP_GAMMA \
722 	_IOR('v', BASE_VIDIOC_PRIVATE + 9, struct atomisp_gamma_table)
723 #define ATOMISP_IOC_S_ISP_GAMMA \
724 	_IOW('v', BASE_VIDIOC_PRIVATE + 9, struct atomisp_gamma_table)
725 #define ATOMISP_IOC_G_ISP_GDC_TAB \
726 	_IOR('v', BASE_VIDIOC_PRIVATE + 10, struct atomisp_morph_table)
727 #define ATOMISP_IOC_S_ISP_GDC_TAB \
728 	_IOW('v', BASE_VIDIOC_PRIVATE + 10, struct atomisp_morph_table)
729 
730 /* macc parameter control*/
731 #define ATOMISP_IOC_G_ISP_MACC \
732 	_IOR('v', BASE_VIDIOC_PRIVATE + 12, struct atomisp_macc_config)
733 #define ATOMISP_IOC_S_ISP_MACC \
734 	_IOW('v', BASE_VIDIOC_PRIVATE + 12, struct atomisp_macc_config)
735 
736 /* Defect pixel detection & Correction */
737 #define ATOMISP_IOC_G_ISP_BAD_PIXEL_DETECTION \
738 	_IOR('v', BASE_VIDIOC_PRIVATE + 13, struct atomisp_dp_config)
739 #define ATOMISP_IOC_S_ISP_BAD_PIXEL_DETECTION \
740 	_IOW('v', BASE_VIDIOC_PRIVATE + 13, struct atomisp_dp_config)
741 
742 /* False Color Correction */
743 #define ATOMISP_IOC_G_ISP_FALSE_COLOR_CORRECTION \
744 	_IOR('v', BASE_VIDIOC_PRIVATE + 14, struct atomisp_de_config)
745 #define ATOMISP_IOC_S_ISP_FALSE_COLOR_CORRECTION \
746 	_IOW('v', BASE_VIDIOC_PRIVATE + 14, struct atomisp_de_config)
747 
748 /* ctc parameter control */
749 #define ATOMISP_IOC_G_ISP_CTC \
750 	_IOR('v', BASE_VIDIOC_PRIVATE + 15, struct atomisp_ctc_table)
751 #define ATOMISP_IOC_S_ISP_CTC \
752 	_IOW('v', BASE_VIDIOC_PRIVATE + 15, struct atomisp_ctc_table)
753 
754 /* white balance Correction */
755 #define ATOMISP_IOC_G_ISP_WHITE_BALANCE \
756 	_IOR('v', BASE_VIDIOC_PRIVATE + 16, struct atomisp_wb_config)
757 #define ATOMISP_IOC_S_ISP_WHITE_BALANCE \
758 	_IOW('v', BASE_VIDIOC_PRIVATE + 16, struct atomisp_wb_config)
759 
760 /* fpn table loading */
761 #define ATOMISP_IOC_S_ISP_FPN_TABLE \
762 	_IOW('v', BASE_VIDIOC_PRIVATE + 17, struct v4l2_framebuffer)
763 
764 /* overlay image loading */
765 #define ATOMISP_IOC_G_ISP_OVERLAY \
766 	_IOWR('v', BASE_VIDIOC_PRIVATE + 18, struct atomisp_overlay)
767 #define ATOMISP_IOC_S_ISP_OVERLAY \
768 	_IOW('v', BASE_VIDIOC_PRIVATE + 18, struct atomisp_overlay)
769 
770 /* bcd driver bridge */
771 #define ATOMISP_IOC_CAMERA_BRIDGE \
772 	_IOWR('v', BASE_VIDIOC_PRIVATE + 19, struct atomisp_bc_video_package)
773 
774 #define ATOMISP_IOC_S_EXPOSURE \
775 	_IOW('v', BASE_VIDIOC_PRIVATE + 21, struct atomisp_exposure)
776 
777 /* white balance Correction */
778 #define ATOMISP_IOC_G_3A_CONFIG \
779 	_IOR('v', BASE_VIDIOC_PRIVATE + 23, struct atomisp_3a_config)
780 #define ATOMISP_IOC_S_3A_CONFIG \
781 	_IOW('v', BASE_VIDIOC_PRIVATE + 23, struct atomisp_3a_config)
782 
783 /* LCS (shading) table write */
784 #define ATOMISP_IOC_S_ISP_SHD_TAB \
785 	_IOWR('v', BASE_VIDIOC_PRIVATE + 27, struct atomisp_shading_table)
786 
787 /* Gamma Correction */
788 #define ATOMISP_IOC_G_ISP_GAMMA_CORRECTION \
789 	_IOR('v', BASE_VIDIOC_PRIVATE + 28, struct atomisp_gc_config)
790 
791 #define ATOMISP_IOC_S_ISP_GAMMA_CORRECTION \
792 	_IOW('v', BASE_VIDIOC_PRIVATE + 28, struct atomisp_gc_config)
793 
794 #define ATOMISP_IOC_S_PARAMETERS \
795 	_IOW('v', BASE_VIDIOC_PRIVATE + 32, struct atomisp_parameters)
796 
797 #define ATOMISP_IOC_EXP_ID_UNLOCK \
798 	_IOW('v', BASE_VIDIOC_PRIVATE + 36, int)
799 
800 #define ATOMISP_IOC_EXP_ID_CAPTURE \
801 	_IOW('v', BASE_VIDIOC_PRIVATE + 37, int)
802 
803 #define ATOMISP_IOC_S_ENABLE_DZ_CAPT_PIPE \
804 	_IOWR('v', BASE_VIDIOC_PRIVATE + 38, unsigned int)
805 
806 #define ATOMISP_IOC_G_FORMATS_CONFIG \
807 	_IOR('v', BASE_VIDIOC_PRIVATE + 39, struct atomisp_formats_config)
808 
809 #define ATOMISP_IOC_S_FORMATS_CONFIG \
810 	_IOW('v', BASE_VIDIOC_PRIVATE + 39, struct atomisp_formats_config)
811 
812 #define ATOMISP_IOC_INJECT_A_FAKE_EVENT \
813 	_IOW('v', BASE_VIDIOC_PRIVATE + 42, int)
814 
815 #define ATOMISP_IOC_S_ARRAY_RESOLUTION \
816 	_IOW('v', BASE_VIDIOC_PRIVATE + 45, struct atomisp_resolution)
817 
818 /* for depth mode sensor frame sync compensation */
819 #define ATOMISP_IOC_G_DEPTH_SYNC_COMP \
820 	_IOR('v', BASE_VIDIOC_PRIVATE + 46, unsigned int)
821 
822 #define ATOMISP_IOC_S_SENSOR_EE_CONFIG \
823 	_IOW('v', BASE_VIDIOC_PRIVATE + 47, unsigned int)
824 
825 /*
826  * Reserved ioctls. We have customer implementing it internally.
827  * We can't use both numbers to not cause ABI conflict.
828  * Anyway, those ioctls are hacks and not implemented by us:
829  *
830  * #define ATOMISP_IOC_G_SENSOR_REG \
831  *	_IOW('v', BASE_VIDIOC_PRIVATE + 55, struct atomisp_sensor_regs)
832  * #define ATOMISP_IOC_S_SENSOR_REG \
833  *	_IOW('v', BASE_VIDIOC_PRIVATE + 56, struct atomisp_sensor_regs)
834  */
835 
836 /*  ISP Private control IDs */
837 #define V4L2_CID_ATOMISP_BAD_PIXEL_DETECTION \
838 	(V4L2_CID_PRIVATE_BASE + 0)
839 #define V4L2_CID_ATOMISP_POSTPROCESS_GDC_CAC \
840 	(V4L2_CID_PRIVATE_BASE + 1)
841 #define V4L2_CID_ATOMISP_VIDEO_STABLIZATION \
842 	(V4L2_CID_PRIVATE_BASE + 2)
843 #define V4L2_CID_ATOMISP_FIXED_PATTERN_NR \
844 	(V4L2_CID_PRIVATE_BASE + 3)
845 #define V4L2_CID_ATOMISP_FALSE_COLOR_CORRECTION \
846 	(V4L2_CID_PRIVATE_BASE + 4)
847 #define V4L2_CID_ATOMISP_LOW_LIGHT \
848 	(V4L2_CID_PRIVATE_BASE + 5)
849 
850 /* Camera class:
851  * Exposure, Flash and privacy (indicator) light controls, to be upstreamed */
852 #define V4L2_CID_CAMERA_LASTP1             (V4L2_CID_CAMERA_CLASS_BASE + 1024)
853 
854 #define V4L2_CID_RUN_MODE			(V4L2_CID_CAMERA_LASTP1 + 20)
855 #define ATOMISP_RUN_MODE_VIDEO			1
856 #define ATOMISP_RUN_MODE_STILL_CAPTURE		2
857 #define ATOMISP_RUN_MODE_PREVIEW		3
858 #define ATOMISP_RUN_MODE_MIN			1
859 #define ATOMISP_RUN_MODE_MAX			3
860 
861 #define V4L2_CID_ENABLE_VFPP			(V4L2_CID_CAMERA_LASTP1 + 21)
862 #define V4L2_CID_ATOMISP_CONTINUOUS_MODE	(V4L2_CID_CAMERA_LASTP1 + 22)
863 #define V4L2_CID_ATOMISP_CONTINUOUS_RAW_BUFFER_SIZE \
864 						(V4L2_CID_CAMERA_LASTP1 + 23)
865 #define V4L2_CID_ATOMISP_CONTINUOUS_VIEWFINDER \
866 						(V4L2_CID_CAMERA_LASTP1 + 24)
867 
868 #define V4L2_CID_VFPP				(V4L2_CID_CAMERA_LASTP1 + 25)
869 #define ATOMISP_VFPP_ENABLE			0
870 #define ATOMISP_VFPP_DISABLE_SCALER		1
871 #define ATOMISP_VFPP_DISABLE_LOWLAT		2
872 
873 #define V4L2_CID_START_ZSL_CAPTURE	(V4L2_CID_CAMERA_LASTP1 + 28)
874 /* Lock and unlock raw buffer */
875 #define V4L2_CID_ENABLE_RAW_BUFFER_LOCK (V4L2_CID_CAMERA_LASTP1 + 29)
876 
877 #define V4L2_CID_EXPOSURE_ZONE_NUM	(V4L2_CID_CAMERA_LASTP1 + 31)
878 /* Disable digital zoom */
879 #define V4L2_CID_DISABLE_DZ		(V4L2_CID_CAMERA_LASTP1 + 32)
880 
881 #define V4L2_CID_ATOMISP_SELECT_ISP_VERSION	(V4L2_CID_CAMERA_LASTP1 + 38)
882 
883 #define V4L2_BUF_FLAG_BUFFER_INVALID       0x0400
884 #define V4L2_BUF_FLAG_BUFFER_VALID         0x0800
885 
886 #define V4L2_BUF_TYPE_VIDEO_CAPTURE_ION  (V4L2_BUF_TYPE_PRIVATE + 1024)
887 
888 #define V4L2_EVENT_ATOMISP_3A_STATS_READY   (V4L2_EVENT_PRIVATE_START + 1)
889 #define V4L2_EVENT_ATOMISP_METADATA_READY   (V4L2_EVENT_PRIVATE_START + 2)
890 #define V4L2_EVENT_ATOMISP_ACC_COMPLETE     (V4L2_EVENT_PRIVATE_START + 4)
891 #define V4L2_EVENT_ATOMISP_PAUSE_BUFFER	    (V4L2_EVENT_PRIVATE_START + 5)
892 #define V4L2_EVENT_ATOMISP_CSS_RESET	    (V4L2_EVENT_PRIVATE_START + 6)
893 /* Nonstandard color effects for V4L2_CID_COLORFX */
894 enum {
895 	V4L2_COLORFX_SKIN_WHITEN_LOW = 1001,
896 	V4L2_COLORFX_SKIN_WHITEN_HIGH = 1002,
897 	V4L2_COLORFX_WARM = 1003,
898 	V4L2_COLORFX_COLD = 1004,
899 	V4L2_COLORFX_WASHED = 1005,
900 	V4L2_COLORFX_RED = 1006,
901 	V4L2_COLORFX_GREEN = 1007,
902 	V4L2_COLORFX_BLUE = 1008,
903 	V4L2_COLORFX_PINK = 1009,
904 	V4L2_COLORFX_YELLOW = 1010,
905 	V4L2_COLORFX_PURPLE = 1011,
906 };
907 
908 #endif /* _ATOM_ISP_H */
909