1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef _IA_CSS_SDIS_COMMON_HOST_H
17 #define _IA_CSS_SDIS_COMMON_HOST_H
18 
19 #define ISP_MAX_SDIS_HOR_PROJ_NUM_ISP \
20 	__ISP_SDIS_HOR_PROJ_NUM_ISP(ISP_MAX_INTERNAL_WIDTH, ISP_MAX_INTERNAL_HEIGHT, \
21 		SH_CSS_DIS_DECI_FACTOR_LOG2, ISP_PIPE_VERSION)
22 #define ISP_MAX_SDIS_VER_PROJ_NUM_ISP \
23 	__ISP_SDIS_VER_PROJ_NUM_ISP(ISP_MAX_INTERNAL_WIDTH, \
24 		SH_CSS_DIS_DECI_FACTOR_LOG2)
25 
26 #define _ISP_SDIS_HOR_COEF_NUM_VECS \
27 	__ISP_SDIS_HOR_COEF_NUM_VECS(ISP_INTERNAL_WIDTH)
28 #define ISP_MAX_SDIS_HOR_COEF_NUM_VECS \
29 	__ISP_SDIS_HOR_COEF_NUM_VECS(ISP_MAX_INTERNAL_WIDTH)
30 #define ISP_MAX_SDIS_VER_COEF_NUM_VECS \
31 	__ISP_SDIS_VER_COEF_NUM_VECS(ISP_MAX_INTERNAL_HEIGHT)
32 
33 /* SDIS Coefficients: */
34 /* The ISP uses vectors to store the coefficients, so we round
35    the number of coefficients up to vectors. */
36 #define __ISP_SDIS_HOR_COEF_NUM_VECS(in_width)  _ISP_VECS(_ISP_BQS(in_width))
37 #define __ISP_SDIS_VER_COEF_NUM_VECS(in_height) _ISP_VECS(_ISP_BQS(in_height))
38 
39 /* SDIS Projections:
40  * SDIS1: Horizontal projections are calculated for each line.
41  * Vertical projections are calculated for each column.
42  * SDIS2: Projections are calculated for each grid cell.
43  * Grid cells that do not fall completely within the image are not
44  * valid. The host needs to use the bigger one for the stride but
45  * should only return the valid ones to the 3A. */
46 #define __ISP_SDIS_HOR_PROJ_NUM_ISP(in_width, in_height, deci_factor_log2, \
47 	isp_pipe_version) \
48 	((isp_pipe_version == 1) ? \
49 		CEIL_SHIFT(_ISP_BQS(in_height), deci_factor_log2) : \
50 		CEIL_SHIFT(_ISP_BQS(in_width), deci_factor_log2))
51 
52 #define __ISP_SDIS_VER_PROJ_NUM_ISP(in_width, deci_factor_log2) \
53 	CEIL_SHIFT(_ISP_BQS(in_width), deci_factor_log2)
54 
55 #define SH_CSS_DIS_VER_NUM_COEF_TYPES(b) \
56   (((b)->info->sp.pipeline.isp_pipe_version == 2) ? \
57 	IA_CSS_DVS2_NUM_COEF_TYPES : \
58 	IA_CSS_DVS_NUM_COEF_TYPES)
59 
60 #ifndef PIPE_GENERATION
61 #if defined(__ISP) || defined(MK_FIRMWARE)
62 
63 /* Array cannot be 2-dimensional, since driver ddr allocation does not know stride */
64 struct sh_css_isp_sdis_hori_proj_tbl {
65 	s32 tbl[ISP_DVS_NUM_COEF_TYPES * ISP_MAX_SDIS_HOR_PROJ_NUM_ISP];
66 #if DVS2_PROJ_MARGIN > 0
67 	s32 margin[DVS2_PROJ_MARGIN];
68 #endif
69 };
70 
71 struct sh_css_isp_sdis_vert_proj_tbl {
72 	s32 tbl[ISP_DVS_NUM_COEF_TYPES * ISP_MAX_SDIS_VER_PROJ_NUM_ISP];
73 #if DVS2_PROJ_MARGIN > 0
74 	s32 margin[DVS2_PROJ_MARGIN];
75 #endif
76 };
77 
78 struct sh_css_isp_sdis_hori_coef_tbl {
79 	VMEM_ARRAY(tbl[ISP_DVS_NUM_COEF_TYPES],
80 		   ISP_MAX_SDIS_HOR_COEF_NUM_VECS * ISP_NWAY);
81 };
82 
83 struct sh_css_isp_sdis_vert_coef_tbl {
84 	VMEM_ARRAY(tbl[ISP_DVS_NUM_COEF_TYPES],
85 		   ISP_MAX_SDIS_VER_COEF_NUM_VECS * ISP_NWAY);
86 };
87 
88 #endif /* defined(__ISP) || defined (MK_FIRMWARE) */
89 #endif /* PIPE_GENERATION */
90 
91 #ifndef PIPE_GENERATION
92 struct s_sdis_config {
93 	unsigned int horicoef_vectors;
94 	unsigned int vertcoef_vectors;
95 	unsigned int horiproj_num;
96 	unsigned int vertproj_num;
97 };
98 
99 extern struct s_sdis_config sdis_config;
100 #endif
101 
102 #endif /* _IA_CSS_SDIS_COMMON_HOST_H */
103