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 "ia_css_dp.host.h"
13
14 /* We use a different set of DPC configuration parameters when
15 * DPC is used before OBC and NORM. Currently these parameters
16 * are used in usecases which selects both BDS and DPC.
17 **/
18 const struct ia_css_dp_config default_dp_10bpp_config = {
19 1024,
20 2048,
21 32768,
22 32768,
23 32768,
24 32768
25 };
26
27 const struct ia_css_dp_config default_dp_config = {
28 8192,
29 2048,
30 32768,
31 32768,
32 32768,
33 32768
34 };
35
36 void
ia_css_dp_encode(struct sh_css_isp_dp_params * to,const struct ia_css_dp_config * from,unsigned int size)37 ia_css_dp_encode(
38 struct sh_css_isp_dp_params *to,
39 const struct ia_css_dp_config *from,
40 unsigned int size)
41 {
42 int gain = from->gain;
43 int gr = from->gr;
44 int r = from->r;
45 int b = from->b;
46 int gb = from->gb;
47
48 (void)size;
49 to->threshold_single =
50 SH_CSS_BAYER_MAXVAL;
51 to->threshold_2adjacent =
52 uDIGIT_FITTING(from->threshold, 16, SH_CSS_BAYER_BITS);
53 to->gain =
54 uDIGIT_FITTING(from->gain, 8, SH_CSS_DP_GAIN_SHIFT);
55
56 to->coef_rr_gr =
57 uDIGIT_FITTING(gain * gr / r, 8, SH_CSS_DP_GAIN_SHIFT);
58 to->coef_rr_gb =
59 uDIGIT_FITTING(gain * gb / r, 8, SH_CSS_DP_GAIN_SHIFT);
60 to->coef_bb_gb =
61 uDIGIT_FITTING(gain * gb / b, 8, SH_CSS_DP_GAIN_SHIFT);
62 to->coef_bb_gr =
63 uDIGIT_FITTING(gain * gr / b, 8, SH_CSS_DP_GAIN_SHIFT);
64 to->coef_gr_rr =
65 uDIGIT_FITTING(gain * r / gr, 8, SH_CSS_DP_GAIN_SHIFT);
66 to->coef_gr_bb =
67 uDIGIT_FITTING(gain * b / gr, 8, SH_CSS_DP_GAIN_SHIFT);
68 to->coef_gb_bb =
69 uDIGIT_FITTING(gain * b / gb, 8, SH_CSS_DP_GAIN_SHIFT);
70 to->coef_gb_rr =
71 uDIGIT_FITTING(gain * r / gb, 8, SH_CSS_DP_GAIN_SHIFT);
72 }
73
74 void
ia_css_dp_dump(const struct sh_css_isp_dp_params * dp,unsigned int level)75 ia_css_dp_dump(
76 const struct sh_css_isp_dp_params *dp,
77 unsigned int level)
78 {
79 if (!dp) return;
80 ia_css_debug_dtrace(level, "Defect Pixel Correction:\n");
81 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
82 "dp_threshold_single_w_2adj_on",
83 dp->threshold_single);
84 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
85 "dp_threshold_2adj_w_2adj_on",
86 dp->threshold_2adjacent);
87 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
88 "dp_gain", dp->gain);
89 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
90 "dpc_coef_rr_gr", dp->coef_rr_gr);
91 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
92 "dpc_coef_rr_gb", dp->coef_rr_gb);
93 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
94 "dpc_coef_bb_gb", dp->coef_bb_gb);
95 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
96 "dpc_coef_bb_gr", dp->coef_bb_gr);
97 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
98 "dpc_coef_gr_rr", dp->coef_gr_rr);
99 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
100 "dpc_coef_gr_bb", dp->coef_gr_bb);
101 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
102 "dpc_coef_gb_bb", dp->coef_gb_bb);
103 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
104 "dpc_coef_gb_rr", dp->coef_gb_rr);
105 }
106
107 void
ia_css_dp_debug_dtrace(const struct ia_css_dp_config * config,unsigned int level)108 ia_css_dp_debug_dtrace(
109 const struct ia_css_dp_config *config,
110 unsigned int level)
111 {
112 ia_css_debug_dtrace(level,
113 "config.threshold=%d, config.gain=%d\n",
114 config->threshold, config->gain);
115 }
116
117 void
ia_css_init_dp_state(void * state,size_t size)118 ia_css_init_dp_state(
119 void/*struct sh_css_isp_dp_vmem_state*/ * state,
120 size_t size)
121 {
122 memset(state, 0, size);
123 }
124