GNU Linux-libre 4.14.313-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / isp / kernels / tnr / tnr_1.0 / ia_css_tnr.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 "ia_css_frame.h"
17 #include "sh_css_defs.h"
18 #include "ia_css_debug.h"
19 #include "sh_css_frac.h"
20 #include "assert_support.h"
21 #define IA_CSS_INCLUDE_CONFIGURATIONS
22 #include "ia_css_isp_configs.h"
23 #include "isp.h"
24
25 #include "ia_css_tnr.host.h"
26 const struct ia_css_tnr_config default_tnr_config = {
27         32768,
28         32,
29         32,
30 };
31
32 void
33 ia_css_tnr_encode(
34         struct sh_css_isp_tnr_params *to,
35         const struct ia_css_tnr_config *from,
36         unsigned size)
37 {
38         (void)size;
39         to->coef =
40             uDIGIT_FITTING(from->gain, 16, SH_CSS_TNR_COEF_SHIFT);
41         to->threshold_Y =
42             uDIGIT_FITTING(from->threshold_y, 16, SH_CSS_ISP_YUV_BITS);
43         to->threshold_C =
44             uDIGIT_FITTING(from->threshold_uv, 16, SH_CSS_ISP_YUV_BITS);
45 }
46
47 void
48 ia_css_tnr_dump(
49         const struct sh_css_isp_tnr_params *tnr,
50         unsigned level)
51 {
52         if (!tnr) return;
53         ia_css_debug_dtrace(level, "Temporal Noise Reduction:\n");
54         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
55                         "tnr_coef", tnr->coef);
56         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
57                         "tnr_threshold_Y", tnr->threshold_Y);
58         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
59                         "tnr_threshold_C", tnr->threshold_C);
60 }
61
62 void
63 ia_css_tnr_debug_dtrace(
64         const struct ia_css_tnr_config *config,
65         unsigned level)
66 {
67         ia_css_debug_dtrace(level,
68                 "config.gain=%d, "
69                 "config.threshold_y=%d, config.threshold_uv=%d\n",
70                 config->gain,
71                 config->threshold_y, config->threshold_uv);
72 }
73
74 void
75 ia_css_tnr_config(
76         struct sh_css_isp_tnr_isp_config *to,
77         const struct ia_css_tnr_configuration *from,
78         unsigned size)
79 {
80         unsigned elems_a = ISP_VEC_NELEMS;
81         unsigned i;
82
83         (void)size;
84         ia_css_dma_configure_from_info(&to->port_b, &from->tnr_frames[0]->info);
85         to->width_a_over_b = elems_a / to->port_b.elems;
86         to->frame_height = from->tnr_frames[0]->info.res.height;
87 #ifndef ISP2401
88         for (i = 0; i < NUM_VIDEO_TNR_FRAMES; i++) {
89 #else
90         for (i = 0; i < NUM_TNR_FRAMES; i++) {
91 #endif
92                 to->tnr_frame_addr[i] = from->tnr_frames[i]->data + from->tnr_frames[i]->planes.yuyv.offset;
93         }
94
95         /* Assume divisiblity here, may need to generalize to fixed point. */
96         assert (elems_a % to->port_b.elems == 0);
97 }
98
99 void
100 ia_css_tnr_configure(
101         const struct ia_css_binary     *binary,
102         const struct ia_css_frame **frames)
103 {
104         struct ia_css_tnr_configuration config;
105         unsigned i;
106
107 #ifndef ISP2401
108         for (i = 0; i < NUM_VIDEO_TNR_FRAMES; i++)
109 #else
110         for (i = 0; i < NUM_TNR_FRAMES; i++)
111 #endif
112                 config.tnr_frames[i] = frames[i];
113
114         ia_css_configure_tnr(binary, &config);
115 }
116
117 void
118 ia_css_init_tnr_state(
119         struct sh_css_isp_tnr_dmem_state *state,
120         size_t size)
121 {
122         (void)size;
123
124 #ifndef ISP2401
125         assert(NUM_VIDEO_TNR_FRAMES >= 2);
126 #endif
127         assert(sizeof(*state) == size);
128         state->tnr_in_buf_idx = 0;
129         state->tnr_out_buf_idx = 1;
130 }