2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
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.
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
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"
22 * XNR 3.0.11 division look-up table
24 #define XNR3_0_11_LOOK_UP_TABLE_POINTS 16
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};
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};
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};
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};
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.
47 const struct ia_css_xnr3_0_11_config default_xnr3_0_11_config = {
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
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,
62 const unsigned total_blocks = 4;
63 const unsigned shuffle_block = 16;
69 for (i = 0; i < ISP_VEC_NELEMS; i++) {
77 /* Constraints on "x":
78 * - values should be greater or equal to 0.
79 * - values should be ascending.
83 for (j = 1; j < XNR3_0_11_LOOK_UP_TABLE_POINTS; j++) {
85 assert(x[j] > x[j-1]);
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.
96 /* TODO: guard this code with above assumptions */
97 for(i = 0; i < total_blocks; i++) {
98 base = shuffle_block * i;
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];
112 /* (void) = ia_css_xnr3_0_11_encode(*to, *from)
113 * -----------------------------------------------
114 * DMEM Encode Function to translate UV parameters from userspace into ISP space
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,
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);
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;
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;
144 /* (void) = ia_css_xnr3_0_11_debug_dtrace(*config, level)
145 * -----------------------------------------------
146 * Dummy Function added as the tool expects it
149 ia_css_xnr3_0_11_debug_dtrace(
150 const struct ia_css_xnr3_0_11_config *config,