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 "type_support.h"
17 #include "ia_css_bnr2_2.host.h"
18 
19 #ifndef IA_CSS_NO_DEBUG
20 #include "ia_css_debug.h" /* ia_css_debug_dtrace() */
21 #endif
22 
23 /* Default kernel parameters. */
24 const struct ia_css_bnr2_2_config default_bnr2_2_config = {
25 	200,
26 	200,
27 	200,
28 	0,
29 	0,
30 	0,
31 	200,
32 	200,
33 	200,
34 	0,
35 	0,
36 	0,
37 	0,
38 	4096,
39 	8191,
40 	128,
41 	1,
42 	0,
43 	0,
44 	0,
45 	8191,
46 	0,
47 	8191
48 };
49 
50 void
ia_css_bnr2_2_encode(struct sh_css_isp_bnr2_2_params * to,const struct ia_css_bnr2_2_config * from,size_t size)51 ia_css_bnr2_2_encode(
52     struct sh_css_isp_bnr2_2_params *to,
53     const struct ia_css_bnr2_2_config *from,
54     size_t size)
55 {
56 	(void)size;
57 	to->d_var_gain_r = from->d_var_gain_r;
58 	to->d_var_gain_g = from->d_var_gain_g;
59 	to->d_var_gain_b = from->d_var_gain_b;
60 	to->d_var_gain_slope_r = from->d_var_gain_slope_r;
61 	to->d_var_gain_slope_g = from->d_var_gain_slope_g;
62 	to->d_var_gain_slope_b = from->d_var_gain_slope_b;
63 
64 	to->n_var_gain_r = from->n_var_gain_r;
65 	to->n_var_gain_g = from->n_var_gain_g;
66 	to->n_var_gain_b = from->n_var_gain_b;
67 	to->n_var_gain_slope_r = from->n_var_gain_slope_r;
68 	to->n_var_gain_slope_g = from->n_var_gain_slope_g;
69 	to->n_var_gain_slope_b = from->n_var_gain_slope_b;
70 
71 	to->dir_thres = from->dir_thres;
72 	to->dir_thres_w = from->dir_thres_w;
73 	to->var_offset_coef = from->var_offset_coef;
74 
75 	to->dir_gain = from->dir_gain;
76 	to->detail_gain	= from->detail_gain;
77 	to->detail_gain_divisor = from->detail_gain_divisor;
78 	to->detail_level_offset = from->detail_level_offset;
79 
80 	to->d_var_th_min = from->d_var_th_min;
81 	to->d_var_th_max = from->d_var_th_max;
82 	to->n_var_th_min = from->n_var_th_min;
83 	to->n_var_th_max = from->n_var_th_max;
84 }
85 
86 #ifndef IA_CSS_NO_DEBUG
87 void
ia_css_bnr2_2_debug_dtrace(const struct ia_css_bnr2_2_config * bnr,unsigned int level)88 ia_css_bnr2_2_debug_dtrace(
89     const struct ia_css_bnr2_2_config *bnr,
90     unsigned int level)
91 {
92 	if (!bnr)
93 		return;
94 
95 	ia_css_debug_dtrace(level, "Bayer Noise Reduction 2.2:\n");
96 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_gain_r", bnr->d_var_gain_r);
97 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_gain_g", bnr->d_var_gain_g);
98 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_gain_b", bnr->d_var_gain_b);
99 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_gain_slope_r",
100 			    bnr->d_var_gain_slope_r);
101 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_gain_slope_g",
102 			    bnr->d_var_gain_slope_g);
103 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_gain_slope_b",
104 			    bnr->d_var_gain_slope_b);
105 
106 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_gain_r", bnr->n_var_gain_r);
107 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_gain_g", bnr->n_var_gain_g);
108 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_gain_b", bnr->n_var_gain_b);
109 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_gain_slope_r",
110 			    bnr->n_var_gain_slope_r);
111 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_gain_slope_g",
112 			    bnr->n_var_gain_slope_g);
113 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_gain_slope_b",
114 			    bnr->n_var_gain_slope_b);
115 
116 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "dir_thres", bnr->dir_thres);
117 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "dir_thres_w", bnr->dir_thres_w);
118 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "var_offset_coef",
119 			    bnr->var_offset_coef);
120 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "dir_gain", bnr->dir_gain);
121 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "detail_gain", bnr->detail_gain);
122 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "detail_gain_divisor",
123 			    bnr->detail_gain_divisor);
124 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "detail_level_offset",
125 			    bnr->detail_level_offset);
126 
127 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_th_min", bnr->d_var_th_min);
128 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "d_var_th_max", bnr->d_var_th_max);
129 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_th_min", bnr->n_var_th_min);
130 	ia_css_debug_dtrace(level, "\t%-32s = %d\n", "n_var_th_max", bnr->n_var_th_max);
131 }
132 #endif /* IA_CSS_NO_DEBUG */
133