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