GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / isp / kernels / sc / sc_1.0 / ia_css_sc.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 "assert_support.h"
19 #ifdef ISP2401
20 #include "math_support.h"       /* min() */
21
22 #define IA_CSS_INCLUDE_CONFIGURATIONS
23 #include "ia_css_isp_configs.h"
24 #endif
25
26 #include "ia_css_sc.host.h"
27
28 void
29 ia_css_sc_encode(
30         struct sh_css_isp_sc_params *to,
31         struct ia_css_shading_table **from,
32         unsigned size)
33 {
34         (void)size;
35         to->gain_shift = (*from)->fraction_bits;
36 }
37
38 void
39 ia_css_sc_dump(
40         const struct sh_css_isp_sc_params *sc,
41         unsigned level)
42 {
43         if (!sc) return;
44         ia_css_debug_dtrace(level, "Shading Correction:\n");
45         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
46                         "sc_gain_shift", sc->gain_shift);
47 }
48
49 #ifdef ISP2401
50 void
51 ia_css_sc_config(
52         struct sh_css_isp_sc_isp_config *to,
53         const struct ia_css_sc_configuration *from,
54         unsigned size)
55 {
56         uint32_t internal_org_x_bqs = from->internal_frame_origin_x_bqs_on_sctbl;
57         uint32_t internal_org_y_bqs = from->internal_frame_origin_y_bqs_on_sctbl;
58         uint32_t slice, rest, i;
59
60         (void)size;
61
62         /* The internal_frame_origin_x_bqs_on_sctbl is separated to 8 times of slice_vec. */
63         rest = internal_org_x_bqs;
64         for (i = 0; i < SH_CSS_SC_INTERPED_GAIN_HOR_SLICE_TIMES; i++) {
65                 slice = min(rest, ((uint32_t)ISP_SLICE_NELEMS));
66                 rest = rest - slice;
67                 to->interped_gain_hor_slice_bqs[i] = slice;
68         }
69
70         to->internal_frame_origin_y_bqs_on_sctbl = internal_org_y_bqs;
71 }
72
73 void
74 ia_css_sc_configure(
75         const struct ia_css_binary *binary,
76         uint32_t internal_frame_origin_x_bqs_on_sctbl,
77         uint32_t internal_frame_origin_y_bqs_on_sctbl)
78 {
79         const struct ia_css_sc_configuration config = {
80                 internal_frame_origin_x_bqs_on_sctbl,
81                 internal_frame_origin_y_bqs_on_sctbl };
82
83         ia_css_configure_sc(binary, &config);
84 }
85
86 #endif
87 /* ------ deprecated(bz675) : from ------ */
88 /* It looks like @parameter{} (in *.pipe) is used to generate the process/get/set functions,
89    for parameters which should be used in the isp kernels.
90    However, the ia_css_shading_settings structure has a parameter which is used only in the css,
91    and does not have a parameter which is used in the isp kernels.
92    Then, I did not use @parameter{} to generate the get/set function
93    for the ia_css_shading_settings structure. (michie) */
94 void
95 sh_css_get_shading_settings(const struct ia_css_isp_parameters *params,
96                         struct ia_css_shading_settings *settings)
97 {
98         if (settings == NULL)
99                 return;
100         assert(params != NULL);
101
102         ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
103                 "ia_css_get_shading_settings() enter: settings=%p\n", settings);
104
105         *settings = params->shading_settings;
106
107         ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
108                 "ia_css_get_shading_settings() leave: settings.enable_shading_table_conversion=%d\n",
109                 settings->enable_shading_table_conversion);
110 }
111
112 void
113 sh_css_set_shading_settings(struct ia_css_isp_parameters *params,
114                         const struct ia_css_shading_settings *settings)
115 {
116         if (settings == NULL)
117                 return;
118         assert(params != NULL);
119
120         ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
121                 "ia_css_set_shading_settings() enter: settings.enable_shading_table_conversion=%d\n",
122                 settings->enable_shading_table_conversion);
123
124         params->shading_settings = *settings;
125         params->shading_settings_changed = true;
126
127         ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
128                 "ia_css_set_shading_settings() leave: return_void\n");
129 }
130 /* ------ deprecated(bz675) : to ------ */