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 "isp.h"
11
12 #include "ia_css_ob.host.h"
13
14 const struct ia_css_ob_config default_ob_config = {
15 IA_CSS_OB_MODE_NONE,
16 0,
17 0,
18 0,
19 0,
20 0,
21 0
22 };
23
24 /* TODO: include ob.isp.h to get isp knowledge and
25 add assert on platform restrictions */
26
27 void
ia_css_ob_configure(struct sh_css_isp_ob_stream_config * config,unsigned int isp_pipe_version,unsigned int raw_bit_depth)28 ia_css_ob_configure(
29 struct sh_css_isp_ob_stream_config *config,
30 unsigned int isp_pipe_version,
31 unsigned int raw_bit_depth)
32 {
33 config->isp_pipe_version = isp_pipe_version;
34 config->raw_bit_depth = raw_bit_depth;
35 }
36
37 void
ia_css_ob_encode(struct sh_css_isp_ob_params * to,const struct ia_css_ob_config * from,const struct sh_css_isp_ob_stream_config * config,unsigned int size)38 ia_css_ob_encode(
39 struct sh_css_isp_ob_params *to,
40 const struct ia_css_ob_config *from,
41 const struct sh_css_isp_ob_stream_config *config,
42 unsigned int size)
43 {
44 unsigned int ob_bit_depth
45 = config->isp_pipe_version == 2 ? SH_CSS_BAYER_BITS : config->raw_bit_depth;
46 unsigned int scale = 16 - ob_bit_depth;
47
48 (void)size;
49 switch (from->mode) {
50 case IA_CSS_OB_MODE_FIXED:
51 to->blacklevel_gr = from->level_gr >> scale;
52 to->blacklevel_r = from->level_r >> scale;
53 to->blacklevel_b = from->level_b >> scale;
54 to->blacklevel_gb = from->level_gb >> scale;
55 to->area_start_bq = 0;
56 to->area_length_bq = 0;
57 to->area_length_bq_inverse = 0;
58 break;
59 case IA_CSS_OB_MODE_RASTER:
60 to->blacklevel_gr = 0;
61 to->blacklevel_r = 0;
62 to->blacklevel_b = 0;
63 to->blacklevel_gb = 0;
64 to->area_start_bq = from->start_position;
65 to->area_length_bq =
66 (from->end_position - from->start_position) + 1;
67 to->area_length_bq_inverse = AREA_LENGTH_UNIT / to->area_length_bq;
68 break;
69 default:
70 to->blacklevel_gr = 0;
71 to->blacklevel_r = 0;
72 to->blacklevel_b = 0;
73 to->blacklevel_gb = 0;
74 to->area_start_bq = 0;
75 to->area_length_bq = 0;
76 to->area_length_bq_inverse = 0;
77 break;
78 }
79 }
80
81 void
ia_css_ob_vmem_encode(struct sh_css_isp_ob_vmem_params * to,const struct ia_css_ob_config * from,const struct sh_css_isp_ob_stream_config * config,unsigned int size)82 ia_css_ob_vmem_encode(
83 struct sh_css_isp_ob_vmem_params *to,
84 const struct ia_css_ob_config *from,
85 const struct sh_css_isp_ob_stream_config *config,
86 unsigned int size)
87 {
88 struct sh_css_isp_ob_params tmp;
89 struct sh_css_isp_ob_params *ob = &tmp;
90
91 (void)size;
92 ia_css_ob_encode(&tmp, from, config, sizeof(tmp));
93
94 {
95 unsigned int i;
96 unsigned int sp_obarea_start_bq = ob->area_start_bq;
97 unsigned int sp_obarea_length_bq = ob->area_length_bq;
98 unsigned int low = sp_obarea_start_bq;
99 unsigned int high = low + sp_obarea_length_bq;
100 u16 all_ones = ~0;
101
102 for (i = 0; i < OBAREA_MASK_SIZE; i++) {
103 if (i >= low && i < high)
104 to->vmask[i / ISP_VEC_NELEMS][i % ISP_VEC_NELEMS] = all_ones;
105 else
106 to->vmask[i / ISP_VEC_NELEMS][i % ISP_VEC_NELEMS] = 0;
107 }
108 }
109 }
110
111 void
ia_css_ob_dump(const struct sh_css_isp_ob_params * ob,unsigned int level)112 ia_css_ob_dump(
113 const struct sh_css_isp_ob_params *ob,
114 unsigned int level)
115 {
116 if (!ob) return;
117 ia_css_debug_dtrace(level, "Optical Black:\n");
118 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
119 "ob_blacklevel_gr", ob->blacklevel_gr);
120 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
121 "ob_blacklevel_r", ob->blacklevel_r);
122 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
123 "ob_blacklevel_b", ob->blacklevel_b);
124 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
125 "ob_blacklevel_gb", ob->blacklevel_gb);
126 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
127 "obarea_start_bq", ob->area_start_bq);
128 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
129 "obarea_length_bq", ob->area_length_bq);
130 ia_css_debug_dtrace(level, "\t%-32s = %d\n",
131 "obarea_length_bq_inverse",
132 ob->area_length_bq_inverse);
133 }
134
135 void
ia_css_ob_debug_dtrace(const struct ia_css_ob_config * config,unsigned int level)136 ia_css_ob_debug_dtrace(
137 const struct ia_css_ob_config *config,
138 unsigned int level)
139 {
140 ia_css_debug_dtrace(level,
141 "config.mode=%d, config.level_gr=%d, config.level_r=%d, config.level_b=%d, config.level_gb=%d, config.start_position=%d, config.end_position=%d\n",
142 config->mode,
143 config->level_gr, config->level_r,
144 config->level_b, config->level_gb,
145 config->start_position, config->end_position);
146 }
147