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 #include "ia_css_types.h"
8 #include "sh_css_defs.h"
9 #include "ia_css_debug.h"
10 #include "sh_css_frac.h"
11
12 #include "bnr/bnr_1.0/ia_css_bnr.host.h"
13 #include "ia_css_ynr.host.h"
14
15 const struct ia_css_nr_config default_nr_config = {
16 16384,
17 8192,
18 1280,
19 0,
20 0
21 };
22
23 const struct ia_css_ee_config default_ee_config = {
24 8192,
25 128,
26 2048
27 };
28
29 void
ia_css_nr_encode(struct sh_css_isp_ynr_params * to,const struct ia_css_nr_config * from,unsigned int size)30 ia_css_nr_encode(
31 struct sh_css_isp_ynr_params *to,
32 const struct ia_css_nr_config *from,
33 unsigned int size)
34 {
35 (void)size;
36 /* YNR (Y Noise Reduction) */
37 to->threshold =
38 uDIGIT_FITTING(8192U, 16, SH_CSS_BAYER_BITS);
39 to->gain_all =
40 uDIGIT_FITTING(from->ynr_gain, 16, SH_CSS_YNR_GAIN_SHIFT);
41 to->gain_dir =
42 uDIGIT_FITTING(from->ynr_gain, 16, SH_CSS_YNR_GAIN_SHIFT);
43 to->threshold_cb =
44 uDIGIT_FITTING(from->threshold_cb, 16, SH_CSS_BAYER_BITS);
45 to->threshold_cr =
46 uDIGIT_FITTING(from->threshold_cr, 16, SH_CSS_BAYER_BITS);
47 }
48
49 void
ia_css_yee_encode(struct sh_css_isp_yee_params * to,const struct ia_css_yee_config * from,unsigned int size)50 ia_css_yee_encode(
51 struct sh_css_isp_yee_params *to,
52 const struct ia_css_yee_config *from,
53 unsigned int size)
54 {
55 int asiWk1 = (int)from->ee.gain;
56 int asiWk2 = asiWk1 / 8;
57 int asiWk3 = asiWk1 / 4;
58
59 (void)size;
60 /* YEE (Y Edge Enhancement) */
61 to->dirthreshold_s =
62 min((uDIGIT_FITTING(from->nr.direction, 16, SH_CSS_BAYER_BITS)
63 << 1),
64 SH_CSS_BAYER_MAXVAL);
65 to->dirthreshold_g =
66 min((uDIGIT_FITTING(from->nr.direction, 16, SH_CSS_BAYER_BITS)
67 << 4),
68 SH_CSS_BAYER_MAXVAL);
69 to->dirthreshold_width_log2 =
70 uFRACTION_BITS_FITTING(8);
71 to->dirthreshold_width =
72 1 << to->dirthreshold_width_log2;
73 to->detailgain =
74 uDIGIT_FITTING(from->ee.detail_gain, 11,
75 SH_CSS_YEE_DETAIL_GAIN_SHIFT);
76 to->coring_s =
77 (uDIGIT_FITTING(56U, 16, SH_CSS_BAYER_BITS) *
78 from->ee.threshold) >> 8;
79 to->coring_g =
80 (uDIGIT_FITTING(224U, 16, SH_CSS_BAYER_BITS) *
81 from->ee.threshold) >> 8;
82 /* 8; // *1.125 ->[s4.8] */
83 to->scale_plus_s =
84 (asiWk1 + asiWk2) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
85 /* 8; // ( * -.25)->[s4.8] */
86 to->scale_plus_g =
87 (0 - asiWk3) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
88 /* 8; // *0.875 ->[s4.8] */
89 to->scale_minus_s =
90 (asiWk1 - asiWk2) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
91 /* 8; // ( *.25 ) ->[s4.8] */
92 to->scale_minus_g =
93 (asiWk3) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
94 to->clip_plus_s =
95 uDIGIT_FITTING(32760U, 16, SH_CSS_BAYER_BITS);
96 to->clip_plus_g = 0;
97 to->clip_minus_s =
98 uDIGIT_FITTING(504U, 16, SH_CSS_BAYER_BITS);
99 to->clip_minus_g =
100 uDIGIT_FITTING(32256U, 16, SH_CSS_BAYER_BITS);
101 to->Yclip = SH_CSS_BAYER_MAXVAL;
102 }
103
104 void
ia_css_nr_dump(const struct sh_css_isp_ynr_params * ynr,unsigned int level)105 ia_css_nr_dump(
106 const struct sh_css_isp_ynr_params *ynr,
107 unsigned int level)
108 {
109 if (!ynr) return;
110 ia_css_debug_dtrace(level,
111 "Y Noise Reduction:\n");
112 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
113 "ynr_threshold", ynr->threshold);
114 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
115 "ynr_gain_all", ynr->gain_all);
116 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
117 "ynr_gain_dir", ynr->gain_dir);
118 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
119 "ynr_threshold_cb", ynr->threshold_cb);
120 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
121 "ynr_threshold_cr", ynr->threshold_cr);
122 }
123
124 void
ia_css_yee_dump(const struct sh_css_isp_yee_params * yee,unsigned int level)125 ia_css_yee_dump(
126 const struct sh_css_isp_yee_params *yee,
127 unsigned int level)
128 {
129 ia_css_debug_dtrace(level,
130 "Y Edge Enhancement:\n");
131 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
132 "ynryee_dirthreshold_s",
133 yee->dirthreshold_s);
134 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
135 "ynryee_dirthreshold_g",
136 yee->dirthreshold_g);
137 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
138 "ynryee_dirthreshold_width_log2",
139 yee->dirthreshold_width_log2);
140 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
141 "ynryee_dirthreshold_width",
142 yee->dirthreshold_width);
143 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
144 "yee_detailgain",
145 yee->detailgain);
146 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
147 "yee_coring_s",
148 yee->coring_s);
149 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
150 "yee_coring_g",
151 yee->coring_g);
152 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
153 "yee_scale_plus_s",
154 yee->scale_plus_s);
155 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
156 "yee_scale_plus_g",
157 yee->scale_plus_g);
158 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
159 "yee_scale_minus_s",
160 yee->scale_minus_s);
161 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
162 "yee_scale_minus_g",
163 yee->scale_minus_g);
164 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
165 "yee_clip_plus_s",
166 yee->clip_plus_s);
167 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
168 "yee_clip_plus_g",
169 yee->clip_plus_g);
170 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
171 "yee_clip_minus_s",
172 yee->clip_minus_s);
173 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
174 "yee_clip_minus_g",
175 yee->clip_minus_g);
176 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
177 "ynryee_Yclip",
178 yee->Yclip);
179 }
180
181 void
ia_css_nr_debug_dtrace(const struct ia_css_nr_config * config,unsigned int level)182 ia_css_nr_debug_dtrace(
183 const struct ia_css_nr_config *config,
184 unsigned int level)
185 {
186 ia_css_debug_dtrace(level,
187 "config.direction=%d, config.bnr_gain=%d, config.ynr_gain=%d, config.threshold_cb=%d, config.threshold_cr=%d\n",
188 config->direction,
189 config->bnr_gain, config->ynr_gain,
190 config->threshold_cb, config->threshold_cr);
191 }
192
193 void
ia_css_ee_debug_dtrace(const struct ia_css_ee_config * config,unsigned int level)194 ia_css_ee_debug_dtrace(
195 const struct ia_css_ee_config *config,
196 unsigned int level)
197 {
198 ia_css_debug_dtrace(level,
199 "config.threshold=%d, config.gain=%d, config.detail_gain=%d\n",
200 config->threshold, config->gain, config->detail_gain);
201 }
202
203 void
ia_css_init_ynr_state(void * state,size_t size)204 ia_css_init_ynr_state(
205 void/*struct sh_css_isp_ynr_vmem_state*/ * state,
206 size_t size)
207 {
208 memset(state, 0, size);
209 }
210