1 // SPDX-License-Identifier: GPL-2.0
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #include "sh_css_param_dvs.h"
17 #include <assert_support.h>
18 #include <type_support.h>
19 #include <ia_css_err.h>
20 #include <ia_css_types.h>
21 #include "ia_css_debug.h"
23 static struct ia_css_dvs_6axis_config *
24 alloc_dvs_6axis_table(const struct ia_css_resolution *frame_res,
25 struct ia_css_dvs_6axis_config *dvs_config_src)
27 unsigned int width_y = 0;
28 unsigned int height_y = 0;
29 unsigned int width_uv = 0;
30 unsigned int height_uv = 0;
32 struct ia_css_dvs_6axis_config *dvs_config = NULL;
34 dvs_config = kvmalloc(sizeof(struct ia_css_dvs_6axis_config),
37 IA_CSS_ERROR("out of memory");
40 /*Initialize new struct with latest config settings*/
42 dvs_config->width_y = width_y = dvs_config_src->width_y;
43 dvs_config->height_y = height_y = dvs_config_src->height_y;
44 dvs_config->width_uv = width_uv = dvs_config_src->width_uv;
45 dvs_config->height_uv = height_uv = dvs_config_src->height_uv;
46 IA_CSS_LOG("alloc_dvs_6axis_table Y: W %d H %d", width_y, height_y);
47 } else if (frame_res) {
48 dvs_config->width_y = width_y = DVS_TABLE_IN_BLOCKDIM_X_LUMA(frame_res->width);
49 dvs_config->height_y = height_y = DVS_TABLE_IN_BLOCKDIM_Y_LUMA(
51 dvs_config->width_uv = width_uv = DVS_TABLE_IN_BLOCKDIM_X_CHROMA(
53 2); /* UV = Y/2, depens on colour format YUV 4.2.0*/
54 dvs_config->height_uv = height_uv = DVS_TABLE_IN_BLOCKDIM_Y_CHROMA(
56 2);/* UV = Y/2, depens on colour format YUV 4.2.0*/
57 IA_CSS_LOG("alloc_dvs_6axis_table Y: W %d H %d", width_y, height_y);
60 /* Generate Y buffers */
61 dvs_config->xcoords_y = kvmalloc(width_y * height_y * sizeof(uint32_t),
63 if (!dvs_config->xcoords_y) {
64 IA_CSS_ERROR("out of memory");
69 dvs_config->ycoords_y = kvmalloc(width_y * height_y * sizeof(uint32_t),
71 if (!dvs_config->ycoords_y) {
72 IA_CSS_ERROR("out of memory");
77 /* Generate UV buffers */
78 IA_CSS_LOG("UV W %d H %d", width_uv, height_uv);
80 dvs_config->xcoords_uv = kvmalloc(width_uv * height_uv * sizeof(uint32_t),
82 if (!dvs_config->xcoords_uv) {
83 IA_CSS_ERROR("out of memory");
88 dvs_config->ycoords_uv = kvmalloc(width_uv * height_uv * sizeof(uint32_t),
90 if (!dvs_config->ycoords_uv) {
91 IA_CSS_ERROR("out of memory");
97 &dvs_config); /* we might have allocated some memory, release this */
102 IA_CSS_LEAVE("dvs_config=%p", dvs_config);
107 init_dvs_6axis_table_from_default(struct ia_css_dvs_6axis_config *dvs_config,
108 const struct ia_css_resolution *dvs_offset)
111 unsigned int width_y = dvs_config->width_y;
112 unsigned int height_y = dvs_config->height_y;
113 unsigned int width_uv = dvs_config->width_uv;
114 unsigned int height_uv = dvs_config->height_uv;
116 IA_CSS_LOG("Env_X=%d, Env_Y=%d, width_y=%d, height_y=%d",
117 dvs_offset->width, dvs_offset->height, width_y, height_y);
118 for (y = 0; y < height_y; y++) {
119 for (x = 0; x < width_y; x++) {
120 dvs_config->xcoords_y[y * width_y + x] = (dvs_offset->width + x *
121 DVS_BLOCKDIM_X) << DVS_COORD_FRAC_BITS;
125 for (y = 0; y < height_y; y++) {
126 for (x = 0; x < width_y; x++) {
127 dvs_config->ycoords_y[y * width_y + x] = (dvs_offset->height + y *
128 DVS_BLOCKDIM_Y_LUMA) << DVS_COORD_FRAC_BITS;
132 for (y = 0; y < height_uv; y++) {
133 for (x = 0; x < width_uv;
134 x++) { /* Envelope dimensions set in Ypixels hence offset UV = offset Y/2 */
135 dvs_config->xcoords_uv[y * width_uv + x] = ((dvs_offset->width / 2) + x *
136 DVS_BLOCKDIM_X) << DVS_COORD_FRAC_BITS;
140 for (y = 0; y < height_uv; y++) {
141 for (x = 0; x < width_uv;
142 x++) { /* Envelope dimensions set in Ypixels hence offset UV = offset Y/2 */
143 dvs_config->ycoords_uv[y * width_uv + x] = ((dvs_offset->height / 2) + y *
144 DVS_BLOCKDIM_Y_CHROMA) <<
151 init_dvs_6axis_table_from_config(struct ia_css_dvs_6axis_config *dvs_config,
152 struct ia_css_dvs_6axis_config *dvs_config_src)
154 unsigned int width_y = dvs_config->width_y;
155 unsigned int height_y = dvs_config->height_y;
156 unsigned int width_uv = dvs_config->width_uv;
157 unsigned int height_uv = dvs_config->height_uv;
159 memcpy(dvs_config->xcoords_y, dvs_config_src->xcoords_y,
160 (width_y * height_y * sizeof(uint32_t)));
161 memcpy(dvs_config->ycoords_y, dvs_config_src->ycoords_y,
162 (width_y * height_y * sizeof(uint32_t)));
163 memcpy(dvs_config->xcoords_uv, dvs_config_src->xcoords_uv,
164 (width_uv * height_uv * sizeof(uint32_t)));
165 memcpy(dvs_config->ycoords_uv, dvs_config_src->ycoords_uv,
166 (width_uv * height_uv * sizeof(uint32_t)));
169 struct ia_css_dvs_6axis_config *
170 generate_dvs_6axis_table(const struct ia_css_resolution *frame_res,
171 const struct ia_css_resolution *dvs_offset)
173 struct ia_css_dvs_6axis_config *dvs_6axis_table;
178 dvs_6axis_table = alloc_dvs_6axis_table(frame_res, NULL);
179 if (dvs_6axis_table) {
180 init_dvs_6axis_table_from_default(dvs_6axis_table, dvs_offset);
181 return dvs_6axis_table;
186 struct ia_css_dvs_6axis_config *
187 generate_dvs_6axis_table_from_config(struct ia_css_dvs_6axis_config
190 struct ia_css_dvs_6axis_config *dvs_6axis_table;
192 assert(dvs_config_src);
194 dvs_6axis_table = alloc_dvs_6axis_table(NULL, dvs_config_src);
195 if (dvs_6axis_table) {
196 init_dvs_6axis_table_from_config(dvs_6axis_table, dvs_config_src);
197 return dvs_6axis_table;
203 free_dvs_6axis_table(struct ia_css_dvs_6axis_config **dvs_6axis_config)
205 assert(dvs_6axis_config);
206 assert(*dvs_6axis_config);
208 if ((dvs_6axis_config) && (*dvs_6axis_config)) {
209 IA_CSS_ENTER_PRIVATE("dvs_6axis_config %p", (*dvs_6axis_config));
210 if ((*dvs_6axis_config)->xcoords_y) {
211 kvfree((*dvs_6axis_config)->xcoords_y);
212 (*dvs_6axis_config)->xcoords_y = NULL;
215 if ((*dvs_6axis_config)->ycoords_y) {
216 kvfree((*dvs_6axis_config)->ycoords_y);
217 (*dvs_6axis_config)->ycoords_y = NULL;
220 /* Free up UV buffers */
221 if ((*dvs_6axis_config)->xcoords_uv) {
222 kvfree((*dvs_6axis_config)->xcoords_uv);
223 (*dvs_6axis_config)->xcoords_uv = NULL;
226 if ((*dvs_6axis_config)->ycoords_uv) {
227 kvfree((*dvs_6axis_config)->ycoords_uv);
228 (*dvs_6axis_config)->ycoords_uv = NULL;
231 IA_CSS_LEAVE_PRIVATE("dvs_6axis_config %p", (*dvs_6axis_config));
232 kvfree(*dvs_6axis_config);
233 *dvs_6axis_config = NULL;
237 void copy_dvs_6axis_table(struct ia_css_dvs_6axis_config *dvs_config_dst,
238 const struct ia_css_dvs_6axis_config *dvs_config_src)
240 unsigned int width_y;
241 unsigned int height_y;
242 unsigned int width_uv;
243 unsigned int height_uv;
245 assert(dvs_config_src);
246 assert(dvs_config_dst);
247 assert(dvs_config_src->xcoords_y);
248 assert(dvs_config_src->xcoords_uv);
249 assert(dvs_config_src->ycoords_y);
250 assert(dvs_config_src->ycoords_uv);
251 assert(dvs_config_src->width_y == dvs_config_dst->width_y);
252 assert(dvs_config_src->width_uv == dvs_config_dst->width_uv);
253 assert(dvs_config_src->height_y == dvs_config_dst->height_y);
254 assert(dvs_config_src->height_uv == dvs_config_dst->height_uv);
256 width_y = dvs_config_src->width_y;
257 height_y = dvs_config_src->height_y;
259 dvs_config_src->width_uv; /* = Y/2, depens on colour format YUV 4.2.0*/
260 height_uv = dvs_config_src->height_uv;
262 memcpy(dvs_config_dst->xcoords_y, dvs_config_src->xcoords_y,
263 (width_y * height_y * sizeof(uint32_t)));
264 memcpy(dvs_config_dst->ycoords_y, dvs_config_src->ycoords_y,
265 (width_y * height_y * sizeof(uint32_t)));
267 memcpy(dvs_config_dst->xcoords_uv, dvs_config_src->xcoords_uv,
268 (width_uv * height_uv * sizeof(uint32_t)));
269 memcpy(dvs_config_dst->ycoords_uv, dvs_config_src->ycoords_uv,
270 (width_uv * height_uv * sizeof(uint32_t)));
274 ia_css_dvs_statistics_get(enum dvs_statistics_type type,
275 union ia_css_dvs_statistics_host *host_stats,
276 const union ia_css_dvs_statistics_isp *isp_stats)
278 if (type == DVS_STATISTICS) {
279 ia_css_get_dvs_statistics(host_stats->p_dvs_statistics_host,
280 isp_stats->p_dvs_statistics_isp);
281 } else if (type == DVS2_STATISTICS) {
282 ia_css_get_dvs2_statistics(host_stats->p_dvs2_statistics_host,
283 isp_stats->p_dvs_statistics_isp);