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 "sh_css_param_dvs.h"
16 #include <assert_support.h>
17 #include <type_support.h>
18 #include <ia_css_err.h>
19 #include <ia_css_types.h>
20 #include "ia_css_debug.h"
21 #include "memory_access.h"
23 static struct ia_css_dvs_6axis_config *
24 alloc_dvs_6axis_table(const struct ia_css_resolution *frame_res, struct ia_css_dvs_6axis_config *dvs_config_src)
26 unsigned int width_y = 0;
27 unsigned int height_y = 0;
28 unsigned int width_uv = 0;
29 unsigned int height_uv = 0;
30 enum ia_css_err err = IA_CSS_SUCCESS;
31 struct ia_css_dvs_6axis_config *dvs_config = NULL;
33 dvs_config = (struct ia_css_dvs_6axis_config *)sh_css_malloc(sizeof(struct ia_css_dvs_6axis_config));
34 if (dvs_config == NULL) {
35 IA_CSS_ERROR("out of memory");
36 err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
39 { /*Initialize new struct with latest config settings*/
40 if (NULL != dvs_config_src) {
41 dvs_config->width_y = width_y = dvs_config_src->width_y;
42 dvs_config->height_y = height_y = dvs_config_src->height_y;
43 dvs_config->width_uv = width_uv = dvs_config_src->width_uv;
44 dvs_config->height_uv = height_uv = dvs_config_src->height_uv;
45 IA_CSS_LOG("alloc_dvs_6axis_table Y: W %d H %d", width_y, height_y);
47 else if (NULL != 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(frame_res->height);
50 dvs_config->width_uv = width_uv = DVS_TABLE_IN_BLOCKDIM_X_CHROMA(frame_res->width / 2); /* UV = Y/2, depens on colour format YUV 4.2.0*/
51 dvs_config->height_uv = height_uv = DVS_TABLE_IN_BLOCKDIM_Y_CHROMA(frame_res->height / 2);/* UV = Y/2, depens on colour format YUV 4.2.0*/
52 IA_CSS_LOG("alloc_dvs_6axis_table Y: W %d H %d", width_y, height_y);
55 /* Generate Y buffers */
56 dvs_config->xcoords_y = (uint32_t *)sh_css_malloc(width_y * height_y * sizeof(uint32_t));
57 if (dvs_config->xcoords_y == NULL) {
58 IA_CSS_ERROR("out of memory");
59 err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
63 dvs_config->ycoords_y = (uint32_t *)sh_css_malloc(width_y * height_y * sizeof(uint32_t));
64 if (dvs_config->ycoords_y == NULL) {
65 IA_CSS_ERROR("out of memory");
66 err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
70 /* Generate UV buffers */
71 IA_CSS_LOG("UV W %d H %d", width_uv, height_uv);
73 dvs_config->xcoords_uv = (uint32_t *)sh_css_malloc(width_uv * height_uv * sizeof(uint32_t));
74 if (dvs_config->xcoords_uv == NULL) {
75 IA_CSS_ERROR("out of memory");
76 err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
80 dvs_config->ycoords_uv = (uint32_t *)sh_css_malloc(width_uv * height_uv * sizeof(uint32_t));
81 if (dvs_config->ycoords_uv == NULL) {
82 IA_CSS_ERROR("out of memory");
83 err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
86 if (err != IA_CSS_SUCCESS) {
87 free_dvs_6axis_table(&dvs_config); /* we might have allocated some memory, release this */
92 IA_CSS_LEAVE("dvs_config=%p", dvs_config);
97 init_dvs_6axis_table_from_default(struct ia_css_dvs_6axis_config *dvs_config, const struct ia_css_resolution *dvs_offset)
100 unsigned int width_y = dvs_config->width_y;
101 unsigned int height_y = dvs_config->height_y;
102 unsigned int width_uv = dvs_config->width_uv;
103 unsigned int height_uv = dvs_config->height_uv;
105 IA_CSS_LOG("Env_X=%d, Env_Y=%d, width_y=%d, height_y=%d",
106 dvs_offset->width, dvs_offset->height, width_y, height_y);
107 for (y = 0; y < height_y; y++) {
108 for (x = 0; x < width_y; x++) {
109 dvs_config->xcoords_y[y*width_y + x] = (dvs_offset->width + x*DVS_BLOCKDIM_X) << DVS_COORD_FRAC_BITS;
113 for (y = 0; y < height_y; y++) {
114 for (x = 0; x < width_y; x++) {
115 dvs_config->ycoords_y[y*width_y + x] = (dvs_offset->height + y*DVS_BLOCKDIM_Y_LUMA) << DVS_COORD_FRAC_BITS;
119 for (y = 0; y < height_uv; y++) {
120 for (x = 0; x < width_uv; x++) { /* Envelope dimensions set in Ypixels hence offset UV = offset Y/2 */
121 dvs_config->xcoords_uv[y*width_uv + x] = ((dvs_offset->width / 2) + x*DVS_BLOCKDIM_X) << DVS_COORD_FRAC_BITS;
125 for (y = 0; y < height_uv; y++) {
126 for (x = 0; x < width_uv; x++) { /* Envelope dimensions set in Ypixels hence offset UV = offset Y/2 */
127 dvs_config->ycoords_uv[y*width_uv + x] = ((dvs_offset->height / 2) + y*DVS_BLOCKDIM_Y_CHROMA) << DVS_COORD_FRAC_BITS;
134 init_dvs_6axis_table_from_config(struct ia_css_dvs_6axis_config *dvs_config, struct ia_css_dvs_6axis_config *dvs_config_src)
136 unsigned int width_y = dvs_config->width_y;
137 unsigned int height_y = dvs_config->height_y;
138 unsigned int width_uv = dvs_config->width_uv;
139 unsigned int height_uv = dvs_config->height_uv;
141 memcpy(dvs_config->xcoords_y, dvs_config_src->xcoords_y, (width_y * height_y * sizeof(uint32_t)));
142 memcpy(dvs_config->ycoords_y, dvs_config_src->ycoords_y, (width_y * height_y * sizeof(uint32_t)));
143 memcpy(dvs_config->xcoords_uv, dvs_config_src->xcoords_uv, (width_uv * height_uv * sizeof(uint32_t)));
144 memcpy(dvs_config->ycoords_uv, dvs_config_src->ycoords_uv, (width_uv * height_uv * sizeof(uint32_t)));
147 struct ia_css_dvs_6axis_config *
148 generate_dvs_6axis_table(const struct ia_css_resolution *frame_res, const struct ia_css_resolution *dvs_offset)
150 struct ia_css_dvs_6axis_config *dvs_6axis_table;
152 assert(frame_res != NULL);
153 assert(dvs_offset != NULL);
155 dvs_6axis_table = alloc_dvs_6axis_table(frame_res, NULL);
156 if (dvs_6axis_table) {
157 init_dvs_6axis_table_from_default(dvs_6axis_table, dvs_offset);
158 return dvs_6axis_table;
163 struct ia_css_dvs_6axis_config *
164 generate_dvs_6axis_table_from_config(struct ia_css_dvs_6axis_config *dvs_config_src)
166 struct ia_css_dvs_6axis_config *dvs_6axis_table;
168 assert(NULL != dvs_config_src);
170 dvs_6axis_table = alloc_dvs_6axis_table(NULL, dvs_config_src);
171 if (dvs_6axis_table) {
172 init_dvs_6axis_table_from_config(dvs_6axis_table, dvs_config_src);
173 return dvs_6axis_table;
179 free_dvs_6axis_table(struct ia_css_dvs_6axis_config **dvs_6axis_config)
181 assert(dvs_6axis_config != NULL);
182 assert(*dvs_6axis_config != NULL);
184 if ((dvs_6axis_config != NULL) && (*dvs_6axis_config != NULL))
186 IA_CSS_ENTER_PRIVATE("dvs_6axis_config %p", (*dvs_6axis_config));
187 if ((*dvs_6axis_config)->xcoords_y != NULL)
189 sh_css_free((*dvs_6axis_config)->xcoords_y);
190 (*dvs_6axis_config)->xcoords_y = NULL;
193 if ((*dvs_6axis_config)->ycoords_y != NULL)
195 sh_css_free((*dvs_6axis_config)->ycoords_y);
196 (*dvs_6axis_config)->ycoords_y = NULL;
199 /* Free up UV buffers */
200 if ((*dvs_6axis_config)->xcoords_uv != NULL)
202 sh_css_free((*dvs_6axis_config)->xcoords_uv);
203 (*dvs_6axis_config)->xcoords_uv = NULL;
206 if ((*dvs_6axis_config)->ycoords_uv != NULL)
208 sh_css_free((*dvs_6axis_config)->ycoords_uv);
209 (*dvs_6axis_config)->ycoords_uv = NULL;
212 IA_CSS_LEAVE_PRIVATE("dvs_6axis_config %p", (*dvs_6axis_config));
213 sh_css_free(*dvs_6axis_config);
214 *dvs_6axis_config = NULL;
218 void copy_dvs_6axis_table(struct ia_css_dvs_6axis_config *dvs_config_dst,
219 const struct ia_css_dvs_6axis_config *dvs_config_src)
221 unsigned int width_y;
222 unsigned int height_y;
223 unsigned int width_uv;
224 unsigned int height_uv;
226 assert(dvs_config_src != NULL);
227 assert(dvs_config_dst != NULL);
228 assert(dvs_config_src->xcoords_y != NULL);
229 assert(dvs_config_src->xcoords_uv != NULL);
230 assert(dvs_config_src->ycoords_y != NULL);
231 assert(dvs_config_src->ycoords_uv != NULL);
232 assert(dvs_config_src->width_y == dvs_config_dst->width_y);
233 assert(dvs_config_src->width_uv == dvs_config_dst->width_uv);
234 assert(dvs_config_src->height_y == dvs_config_dst->height_y);
235 assert(dvs_config_src->height_uv == dvs_config_dst->height_uv);
237 width_y = dvs_config_src->width_y;
238 height_y = dvs_config_src->height_y;
239 width_uv = dvs_config_src->width_uv; /* = Y/2, depens on colour format YUV 4.2.0*/
240 height_uv = dvs_config_src->height_uv;
242 memcpy(dvs_config_dst->xcoords_y, dvs_config_src->xcoords_y, (width_y * height_y * sizeof(uint32_t)));
243 memcpy(dvs_config_dst->ycoords_y, dvs_config_src->ycoords_y, (width_y * height_y * sizeof(uint32_t)));
245 memcpy(dvs_config_dst->xcoords_uv, dvs_config_src->xcoords_uv, (width_uv * height_uv * sizeof(uint32_t)));
246 memcpy(dvs_config_dst->ycoords_uv, dvs_config_src->ycoords_uv, (width_uv * height_uv * sizeof(uint32_t)));
251 ia_css_dvs_statistics_get(enum dvs_statistics_type type,
252 union ia_css_dvs_statistics_host *host_stats,
253 const union ia_css_dvs_statistics_isp *isp_stats)
256 if (DVS_STATISTICS == type)
258 ia_css_get_dvs_statistics(host_stats->p_dvs_statistics_host,
259 isp_stats->p_dvs_statistics_isp);
260 } else if (DVS2_STATISTICS == type)
262 ia_css_get_dvs2_statistics(host_stats->p_dvs2_statistics_host,
263 isp_stats->p_dvs_statistics_isp);