GNU Linux-libre 4.14.265-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / isp / kernels / wb / wb_1.0 / ia_css_wb.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 #ifndef IA_CSS_NO_DEBUG
18 #include "ia_css_debug.h"
19 #endif
20 #include "sh_css_frac.h"
21
22 #include "ia_css_wb.host.h"
23
24 const struct ia_css_wb_config default_wb_config = {
25         1,
26         32768,
27         32768,
28         32768,
29         32768
30 };
31
32 void
33 ia_css_wb_encode(
34         struct sh_css_isp_wb_params *to,
35         const struct ia_css_wb_config *from,
36         unsigned size)
37 {
38         (void)size;
39         to->gain_shift =
40             uISP_REG_BIT - from->integer_bits;
41         to->gain_gr =
42             uDIGIT_FITTING(from->gr, 16 - from->integer_bits,
43                            to->gain_shift);
44         to->gain_r =
45             uDIGIT_FITTING(from->r, 16 - from->integer_bits,
46                            to->gain_shift);
47         to->gain_b =
48             uDIGIT_FITTING(from->b, 16 - from->integer_bits,
49                            to->gain_shift);
50         to->gain_gb =
51             uDIGIT_FITTING(from->gb, 16 - from->integer_bits,
52                            to->gain_shift);
53 }
54
55 #ifndef IA_CSS_NO_DEBUG
56 void
57 ia_css_wb_dump(
58         const struct sh_css_isp_wb_params *wb,
59         unsigned level)
60 {
61         if (!wb) return;
62         ia_css_debug_dtrace(level, "White Balance:\n");
63         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
64                         "wb_gain_shift", wb->gain_shift);
65         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
66                         "wb_gain_gr", wb->gain_gr);
67         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
68                         "wb_gain_r", wb->gain_r);
69         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
70                         "wb_gain_b", wb->gain_b);
71         ia_css_debug_dtrace(level, "\t%-32s = %d\n",
72                         "wb_gain_gb", wb->gain_gb);
73 }
74
75 void
76 ia_css_wb_debug_dtrace(
77         const struct ia_css_wb_config *config,
78         unsigned level)
79 {
80         ia_css_debug_dtrace(level,
81                 "config.integer_bits=%d, "
82                 "config.gr=%d, config.r=%d, "
83                 "config.b=%d, config.gb=%d\n",
84                 config->integer_bits,
85                 config->gr, config->r,
86                 config->b, config->gb);
87 }
88 #endif
89