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 "ia_css_vf.host.h"
16 #include <assert_support.h>
17 #include <ia_css_err.h>
18 #include <ia_css_frame.h>
19 #include <ia_css_frame_public.h>
20 #include <ia_css_pipeline.h>
21 #define IA_CSS_INCLUDE_CONFIGURATIONS
22 #include "ia_css_isp_configs.h"
28 struct sh_css_isp_vf_isp_config *to,
29 const struct ia_css_vf_configuration *from,
32 unsigned elems_a = ISP_VEC_NELEMS;
35 to->vf_downscale_bits = from->vf_downscale_bits;
36 to->enable = from->info != NULL;
39 ia_css_frame_info_to_frame_sp_info(&to->info, from->info);
40 ia_css_dma_configure_from_info(&to->dma.port_b, from->info);
41 to->dma.width_a_over_b = elems_a / to->dma.port_b.elems;
43 /* Assume divisiblity here, may need to generalize to fixed point. */
44 assert (elems_a % to->dma.port_b.elems == 0);
48 /* compute the log2 of the downscale factor needed to get closest
49 * to the requested viewfinder resolution on the upper side. The output cannot
50 * be smaller than the requested viewfinder resolution.
53 sh_css_vf_downscale_log2(
54 const struct ia_css_frame_info *out_info,
55 const struct ia_css_frame_info *vf_info,
56 unsigned int *downscale_log2)
58 unsigned int ds_log2 = 0;
59 unsigned int out_width;
61 if ((out_info == NULL) | (vf_info == NULL))
62 return IA_CSS_ERR_INVALID_ARGUMENTS;
64 out_width = out_info->res.width;
67 return IA_CSS_ERR_INVALID_ARGUMENTS;
69 /* downscale until width smaller than the viewfinder width. We don't
70 * test for the height since the vmem buffers only put restrictions on
71 * the width of a line, not on the number of lines in a frame.
73 while (out_width >= vf_info->res.width) {
77 /* now width is smaller, so we go up one step */
78 if ((ds_log2 > 0) && (out_width < ia_css_binary_max_vf_width()))
80 /* TODO: use actual max input resolution of vf_pp binary */
81 if ((out_info->res.width >> ds_log2) >= 2 * ia_css_binary_max_vf_width())
82 return IA_CSS_ERR_INVALID_ARGUMENTS;
83 *downscale_log2 = ds_log2;
84 return IA_CSS_SUCCESS;
87 static enum ia_css_err
89 const struct ia_css_binary_info *info,
90 const struct ia_css_frame_info *out_info,
91 const struct ia_css_frame_info *vf_info,
92 unsigned int *downscale_log2,
93 struct ia_css_vf_configuration *config)
96 unsigned vf_log_ds = 0;
98 /* First compute value */
100 err = sh_css_vf_downscale_log2(out_info, vf_info, &vf_log_ds);
101 if (err != IA_CSS_SUCCESS)
104 vf_log_ds = min(vf_log_ds, info->vf_dec.max_log_downscale);
105 *downscale_log2 = vf_log_ds;
107 /* Then store it in isp config section */
108 config->vf_downscale_bits = vf_log_ds;
109 return IA_CSS_SUCCESS;
114 struct ia_css_vf_configuration *config,
115 const struct ia_css_frame_info *vf_info)
117 config->info = vf_info;
122 const struct ia_css_binary *binary,
123 const struct ia_css_frame_info *out_info,
124 struct ia_css_frame_info *vf_info,
125 unsigned int *downscale_log2)
128 struct ia_css_vf_configuration config;
129 const struct ia_css_binary_info *info = &binary->info->sp;
131 err = configure_kernel(info, out_info, vf_info, downscale_log2, &config);
132 configure_dma(&config, vf_info);
135 vf_info->raw_bit_depth = info->dma.vfdec_bits_per_pixel;
136 ia_css_configure_vf (binary, &config);
138 return IA_CSS_SUCCESS;