1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2010 - 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_bayer_io.host.h"
17 #include "dma.h"
18 #include "math_support.h"
19 #ifndef IA_CSS_NO_DEBUG
20 #include "ia_css_debug.h"
21 #endif
22 #include "ia_css_isp_params.h"
23 #include "ia_css_frame.h"
24 
25 int ia_css_bayer_io_config(const struct ia_css_binary      *binary,
26 			   const struct sh_css_binary_args *args)
27 {
28 	const struct ia_css_frame *in_frame = args->in_frame;
29 	const struct ia_css_frame **out_frames = (const struct ia_css_frame **)
30 		&args->out_frame;
31 	const struct ia_css_frame_info *in_frame_info = (in_frame) ? &in_frame->info :
32 		&binary->in_frame_info;
33 
34 	const unsigned int ddr_bits_per_element = sizeof(short) * 8;
35 	const unsigned int ddr_elems_per_word = ceil_div(HIVE_ISP_DDR_WORD_BITS,
36 						ddr_bits_per_element);
37 	unsigned int size_get = 0, size_put = 0;
38 	unsigned int offset = 0;
39 
40 	if (binary->info->mem_offsets.offsets.param) {
41 		size_get = binary->info->mem_offsets.offsets.param->dmem.get.size;
42 		offset = binary->info->mem_offsets.offsets.param->dmem.get.offset;
43 	}
44 
45 	if (size_get) {
46 		struct ia_css_common_io_config *to = (struct ia_css_common_io_config *)
47 						     &binary->mem_params.params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM].address[offset];
48 		struct dma_port_config config;
49 #ifndef IA_CSS_NO_DEBUG
50 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
51 				    "ia_css_bayer_io_config() get part enter:\n");
52 #endif
53 
54 		ia_css_dma_configure_from_info(&config, in_frame_info);
55 		// The base_address of the input frame will be set in the ISP
56 		to->width = in_frame_info->res.width;
57 		to->height = in_frame_info->res.height;
58 		to->stride = config.stride;
59 		to->ddr_elems_per_word = ddr_elems_per_word;
60 #ifndef IA_CSS_NO_DEBUG
61 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
62 				    "ia_css_bayer_io_config() get part leave:\n");
63 #endif
64 	}
65 
66 	if (binary->info->mem_offsets.offsets.param) {
67 		size_put = binary->info->mem_offsets.offsets.param->dmem.put.size;
68 		offset = binary->info->mem_offsets.offsets.param->dmem.put.offset;
69 	}
70 
71 	if (size_put) {
72 		struct ia_css_common_io_config *to = (struct ia_css_common_io_config *)
73 						     &binary->mem_params.params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM].address[offset];
74 		struct dma_port_config config;
75 #ifndef IA_CSS_NO_DEBUG
76 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
77 				    "ia_css_bayer_io_config() put part enter:\n");
78 #endif
79 
80 		ia_css_dma_configure_from_info(&config, &out_frames[0]->info);
81 		to->base_address = out_frames[0]->data;
82 		to->width = out_frames[0]->info.res.width;
83 		to->height = out_frames[0]->info.res.height;
84 		to->stride = config.stride;
85 		to->ddr_elems_per_word = ddr_elems_per_word;
86 
87 #ifndef IA_CSS_NO_DEBUG
88 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
89 				    "ia_css_bayer_io_config() put part leave:\n");
90 #endif
91 	}
92 	return 0;
93 }
94