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