GNU Linux-libre 4.14.295-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / isp / kernels / ynr / ynr_1.0 / ia_css_ynr.host.c
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #include "ia_css_types.h"
16 #include "sh_css_defs.h"
17 #include "ia_css_debug.h"
18 #include "sh_css_frac.h"
19
20 #include "bnr/bnr_1.0/ia_css_bnr.host.h"
21 #include "ia_css_ynr.host.h"
22
23 const struct ia_css_nr_config default_nr_config = {
24         16384,
25         8192,
26         1280,
27         0,
28         0
29 };
30
31 const struct ia_css_ee_config default_ee_config = {
32         8192,
33         128,
34         2048
35 };
36
37 void
38 ia_css_nr_encode(
39         struct sh_css_isp_ynr_params *to,
40         const struct ia_css_nr_config *from,
41         unsigned size)
42 {
43         (void)size;
44         /* YNR (Y Noise Reduction) */
45         to->threshold =
46                 uDIGIT_FITTING((unsigned)8192, 16, SH_CSS_BAYER_BITS);
47         to->gain_all =
48             uDIGIT_FITTING(from->ynr_gain, 16, SH_CSS_YNR_GAIN_SHIFT);
49         to->gain_dir =
50             uDIGIT_FITTING(from->ynr_gain, 16, SH_CSS_YNR_GAIN_SHIFT);
51         to->threshold_cb =
52             uDIGIT_FITTING(from->threshold_cb, 16, SH_CSS_BAYER_BITS);
53         to->threshold_cr =
54             uDIGIT_FITTING(from->threshold_cr, 16, SH_CSS_BAYER_BITS);
55 }
56
57 void
58 ia_css_yee_encode(
59         struct sh_css_isp_yee_params *to,
60         const struct ia_css_yee_config *from,
61         unsigned size)
62 {
63         int asiWk1 = (int) from->ee.gain;
64         int asiWk2 = asiWk1 / 8;
65         int asiWk3 = asiWk1 / 4;
66
67         (void)size;
68         /* YEE (Y Edge Enhancement) */
69         to->dirthreshold_s =
70             min((uDIGIT_FITTING(from->nr.direction, 16, SH_CSS_BAYER_BITS)
71                                     << 1),
72                 SH_CSS_BAYER_MAXVAL);
73         to->dirthreshold_g =
74             min((uDIGIT_FITTING(from->nr.direction, 16, SH_CSS_BAYER_BITS)
75                                     << 4),
76                 SH_CSS_BAYER_MAXVAL);
77         to->dirthreshold_width_log2 =
78             uFRACTION_BITS_FITTING(8);
79         to->dirthreshold_width =
80             1 << to->dirthreshold_width_log2;
81         to->detailgain =
82             uDIGIT_FITTING(from->ee.detail_gain, 11,
83                            SH_CSS_YEE_DETAIL_GAIN_SHIFT);
84         to->coring_s =
85             (uDIGIT_FITTING((unsigned)56, 16, SH_CSS_BAYER_BITS) *
86              from->ee.threshold) >> 8;
87         to->coring_g =
88             (uDIGIT_FITTING((unsigned)224, 16, SH_CSS_BAYER_BITS) *
89              from->ee.threshold) >> 8;
90         /* 8; // *1.125 ->[s4.8] */
91         to->scale_plus_s =
92             (asiWk1 + asiWk2) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
93         /* 8; // ( * -.25)->[s4.8] */
94         to->scale_plus_g =
95             (0 - asiWk3) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
96         /* 8; // *0.875 ->[s4.8] */
97         to->scale_minus_s =
98             (asiWk1 - asiWk2) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
99         /* 8; // ( *.25 ) ->[s4.8] */
100         to->scale_minus_g =
101             (asiWk3) >> (11 - SH_CSS_YEE_SCALE_SHIFT);
102         to->clip_plus_s =
103             uDIGIT_FITTING((unsigned)32760, 16, SH_CSS_BAYER_BITS);
104         to->clip_plus_g = 0;
105         to->clip_minus_s =
106             uDIGIT_FITTING((unsigned)504, 16, SH_CSS_BAYER_BITS);
107         to->clip_minus_g =
108             uDIGIT_FITTING((unsigned)32256, 16, SH_CSS_BAYER_BITS);
109         to->Yclip = SH_CSS_BAYER_MAXVAL;
110 }
111
112 void
113 ia_css_nr_dump(
114         const struct sh_css_isp_ynr_params *ynr,
115         unsigned level)
116 {
117         if (!ynr) return;
118         ia_css_debug_dtrace(level,
119                 "Y Noise Reduction:\n");
120         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
121                         "ynr_threshold", ynr->threshold);
122         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
123                         "ynr_gain_all", ynr->gain_all);
124         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
125                         "ynr_gain_dir", ynr->gain_dir);
126         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
127                         "ynr_threshold_cb", ynr->threshold_cb);
128         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
129                         "ynr_threshold_cr", ynr->threshold_cr);
130 }
131
132 void
133 ia_css_yee_dump(
134         const struct sh_css_isp_yee_params *yee,
135         unsigned level)
136 {
137         ia_css_debug_dtrace(level,
138                 "Y Edge Enhancement:\n");
139         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
140                         "ynryee_dirthreshold_s",
141                         yee->dirthreshold_s);
142         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
143                         "ynryee_dirthreshold_g",
144                         yee->dirthreshold_g);
145         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
146                         "ynryee_dirthreshold_width_log2",
147                         yee->dirthreshold_width_log2);
148         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
149                         "ynryee_dirthreshold_width",
150                         yee->dirthreshold_width);
151         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
152                         "yee_detailgain",
153                         yee->detailgain);
154         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
155                         "yee_coring_s",
156                         yee->coring_s);
157         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
158                         "yee_coring_g",
159                         yee->coring_g);
160         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
161                         "yee_scale_plus_s",
162                         yee->scale_plus_s);
163         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
164                         "yee_scale_plus_g",
165                         yee->scale_plus_g);
166         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
167                         "yee_scale_minus_s",
168                         yee->scale_minus_s);
169         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
170                         "yee_scale_minus_g",
171                         yee->scale_minus_g);
172         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
173                         "yee_clip_plus_s",
174                         yee->clip_plus_s);
175         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
176                         "yee_clip_plus_g",
177                         yee->clip_plus_g);
178         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
179                         "yee_clip_minus_s",
180                         yee->clip_minus_s);
181         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
182                         "yee_clip_minus_g",
183                         yee->clip_minus_g);
184         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
185                         "ynryee_Yclip",
186                         yee->Yclip);
187 }
188
189 void
190 ia_css_nr_debug_dtrace(
191         const struct ia_css_nr_config *config,
192         unsigned level)
193 {
194         ia_css_debug_dtrace(level,
195                 "config.direction=%d, "
196                 "config.bnr_gain=%d, config.ynr_gain=%d, "
197                 "config.threshold_cb=%d, config.threshold_cr=%d\n",
198                 config->direction,
199                 config->bnr_gain, config->ynr_gain,
200                 config->threshold_cb, config->threshold_cr);
201 }
202
203 void
204 ia_css_ee_debug_dtrace(
205         const struct ia_css_ee_config *config,
206         unsigned level)
207 {
208         ia_css_debug_dtrace(level,
209                 "config.threshold=%d, config.gain=%d, config.detail_gain=%d\n",
210                 config->threshold, config->gain, config->detail_gain);
211 }
212
213 void
214 ia_css_init_ynr_state(
215         void/*struct sh_css_isp_ynr_vmem_state*/ *state,
216         size_t size)
217 {
218         memset(state, 0, size);
219 }