1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
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.
9  *
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
13  * more details.
14  */
15 
16 #include "ia_css_iterator.host.h"
17 #include "ia_css_frame_public.h"
18 #include "ia_css_binary.h"
19 #include "ia_css_err.h"
20 #define IA_CSS_INCLUDE_CONFIGURATIONS
21 #include "ia_css_isp_configs.h"
22 
23 static const struct ia_css_iterator_configuration default_config = {
24 	.input_info = (struct ia_css_frame_info *)NULL,
25 };
26 
27 void
ia_css_iterator_config(struct sh_css_isp_iterator_isp_config * to,const struct ia_css_iterator_configuration * from,unsigned int size)28 ia_css_iterator_config(
29     struct sh_css_isp_iterator_isp_config *to,
30     const struct ia_css_iterator_configuration *from,
31     unsigned int size)
32 {
33 	(void)size;
34 	ia_css_frame_info_to_frame_sp_info(&to->input_info,    from->input_info);
35 	ia_css_frame_info_to_frame_sp_info(&to->internal_info, from->internal_info);
36 	ia_css_frame_info_to_frame_sp_info(&to->output_info,   from->output_info);
37 	ia_css_frame_info_to_frame_sp_info(&to->vf_info,       from->vf_info);
38 	ia_css_resolution_to_sp_resolution(&to->dvs_envelope,  from->dvs_envelope);
39 }
40 
ia_css_iterator_configure(const struct ia_css_binary * binary,const struct ia_css_frame_info * in_info)41 int ia_css_iterator_configure(const struct ia_css_binary *binary,
42 			      const struct ia_css_frame_info *in_info)
43 {
44 	struct ia_css_frame_info my_info = IA_CSS_BINARY_DEFAULT_FRAME_INFO;
45 	struct ia_css_iterator_configuration config = default_config;
46 
47 	config.input_info    = &binary->in_frame_info;
48 	config.internal_info = &binary->internal_frame_info;
49 	config.output_info   = &binary->out_frame_info[0];
50 	config.vf_info       = &binary->vf_frame_info;
51 	config.dvs_envelope  = &binary->dvs_envelope;
52 
53 	/* Use in_info iso binary->in_frame_info.
54 	 * They can differ in padded width in case of scaling, e.g. for capture_pp.
55 	 * Find out why.
56 	*/
57 	if (in_info)
58 		config.input_info = in_info;
59 	if (binary->out_frame_info[0].res.width == 0)
60 		config.output_info = &binary->out_frame_info[1];
61 	my_info = *config.output_info;
62 	config.output_info = &my_info;
63 	/* we do this only for preview pipe because in fill_binary_info function
64 	 * we assign vf_out res to out res, but for ISP internal processing, we need
65 	 * the original out res. for video pipe, it has two output pins --- out and
66 	 * vf_out, so it can keep these two resolutions already. */
67 	if (binary->info->sp.pipeline.mode == IA_CSS_BINARY_MODE_PREVIEW &&
68 	    binary->vf_downscale_log2 > 0)
69 	{
70 		/* TODO: Remove this after preview output decimation is fixed
71 		 * by configuring out&vf info files properly */
72 		my_info.padded_width <<= binary->vf_downscale_log2;
73 		my_info.res.width    <<= binary->vf_downscale_log2;
74 		my_info.res.height   <<= binary->vf_downscale_log2;
75 	}
76 
77 	return ia_css_configure_iterator(binary, &config);
78 }
79