7e86bc8be0542b33645226ac17ca722a0aad16f3
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] /
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 "type_support.h"
16 #include "math_support.h"
17 #include "sh_css_defs.h"
18 #include "assert_support.h"
19 #include "ia_css_xnr3_0_11.host.h"
20
21 /*
22 * XNR 3.0.11 division look-up table
23 */
24 #define XNR3_0_11_LOOK_UP_TABLE_POINTS 16
25
26 static const int16_t x[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
27 512, 637, 782, 952, 1147, 1372, 1627, 1917, 2242,
28 2597, 2992, 3427, 3907, 4432, 5007, 5632};
29
30 static const int16_t a[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
31 -6587, -4309, -2886, -1970, -1362, -7710, -5508,
32 -4008, -2931, -2219, -1676, -1280, -999, -769, -616, 0};
33
34 static const int16_t b[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
35 4096, 3292, 2682, 2203, 1828, 1529, 1289, 1094,
36 935, 808, 701, 612, 537, 473, 419, 372};
37
38 static const int16_t c[XNR3_0_11_LOOK_UP_TABLE_POINTS] = {
39 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
40
41
42 /*
43 * Default kernel parameters (weights). In general, default is bypass mode or as close
44 * to the ineffective values as possible. Due to the chroma down+upsampling,
45 * perfect bypass mode is not possible for xnr3.
46 */
47 const struct ia_css_xnr3_0_11_config default_xnr3_0_11_config = {
48 7, 7, 7, 7, 7, 2 };
49
50
51 /* (void) = ia_css_xnr3_0_11_vmem_encode(*to, *from)
52 * -----------------------------------------------
53 * VMEM Encode Function to translate UV parameters from userspace into ISP space
54 */
55 void
56 ia_css_xnr3_0_11_vmem_encode(
57 struct sh_css_isp_xnr3_0_11_vmem_params *to,
58 const struct ia_css_xnr3_0_11_config *from,
59 unsigned size)
60 {
61 unsigned i, j, base;
62 const unsigned total_blocks = 4;
63 const unsigned shuffle_block = 16;
64
65 (void)from;
66 (void)size;
67
68 /* Init */
69 for (i = 0; i < ISP_VEC_NELEMS; i++) {
70 to->x[0][i] = 0;
71 to->a[0][i] = 0;
72 to->b[0][i] = 0;
73 to->c[0][i] = 0;
74 }
75
76
77 /* Constraints on "x":
78 * - values should be greater or equal to 0.
79 * - values should be ascending.
80 */
81 assert(x[0] >= 0);
82
83 for (j = 1; j < XNR3_0_11_LOOK_UP_TABLE_POINTS; j++) {
84 assert(x[j] >= 0);
85 assert(x[j] > x[j-1]);
86
87 }
88
89
90 /* The implementation of the calulating 1/x is based on the availability
91 * of the OP_vec_shuffle16 operation.
92 * A 64 element vector is split up in 4 blocks of 16 element. Each array is copied to
93 * a vector 4 times, (starting at 0, 16, 32 and 48). All array elements are copied or
94 * initialised as described in the KFS. The remaining elements of a vector are set to 0.
95 */
96 /* TODO: guard this code with above assumptions */
97 for(i = 0; i < total_blocks; i++) {
98 base = shuffle_block * i;
99
100 for (j = 0; j < XNR3_0_11_LOOK_UP_TABLE_POINTS; j++) {
101 to->x[0][base + j] = x[j];
102 to->a[0][base + j] = a[j];
103 to->b[0][base + j] = b[j];
104 to->c[0][base + j] = c[j];
105 }
106 }
107
108 }
109
110
111
112 /* (void) = ia_css_xnr3_0_11_encode(*to, *from)
113 * -----------------------------------------------
114 * DMEM Encode Function to translate UV parameters from userspace into ISP space
115 */
116 void
117 ia_css_xnr3_0_11_encode(
118 struct sh_css_isp_xnr3_0_11_params *to,
119 const struct ia_css_xnr3_0_11_config *from,
120 unsigned size)
121 {
122 int kernel_size = XNR_FILTER_SIZE;
123 /* The adjust factor is the next power of 2
124 w.r.t. the kernel size*/
125 int adjust_factor = ceil_pow2(kernel_size);
126
127 int32_t weight_y0 = from->weight_y0;
128 int32_t weight_y1 = from->weight_y1;
129 int32_t weight_u0 = from->weight_u0;
130 int32_t weight_u1 = from->weight_u1;
131 int32_t weight_v0 = from->weight_v0;
132 int32_t weight_v1 = from->weight_v1;
133
134 (void)size;
135
136 to->weight_y0 = weight_y0;
137 to->weight_u0 = weight_u0;
138 to->weight_v0 = weight_v0;
139 to->weight_ydiff = (weight_y1 - weight_y0) * adjust_factor / kernel_size;
140 to->weight_udiff = (weight_u1 - weight_u0) * adjust_factor / kernel_size;
141 to->weight_vdiff = (weight_v1 - weight_v0) * adjust_factor / kernel_size;
142 }
143
144 /* (void) = ia_css_xnr3_0_11_debug_dtrace(*config, level)
145 * -----------------------------------------------
146 * Dummy Function added as the tool expects it
147 */
148 void
149 ia_css_xnr3_0_11_debug_dtrace(
150 const struct ia_css_xnr3_0_11_config *config,
151 unsigned level)
152 {
153 (void)config;
154 (void)level;
155 }