1// SPDX-License-Identifier: GPL-2.0
2/*
3Support for Intel Camera Imaging ISP subsystem.
4Copyright (c) 2010 - 2015, Intel Corporation.
5
6This program is free software; you can redistribute it and/or modify it
7under the terms and conditions of the GNU General Public License,
8version 2, as published by the Free Software Foundation.
9
10This program is distributed in the hope it will be useful, but WITHOUT
11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13more details.
14*/
15
16#include "ia_css_yuv444_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
25int ia_css_yuv444_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 = ia_css_frame_get_info(in_frame);
32	const unsigned int ddr_bits_per_element = sizeof(short) * 8;
33	const unsigned int ddr_elems_per_word = ceil_div(HIVE_ISP_DDR_WORD_BITS,
34						ddr_bits_per_element);
35	unsigned int size_get = 0, size_put = 0;
36	unsigned int offset = 0;
37	int ret;
38
39	if (binary->info->mem_offsets.offsets.param) {
40		size_get = binary->info->mem_offsets.offsets.param->dmem.get.size;
41		offset = binary->info->mem_offsets.offsets.param->dmem.get.offset;
42	}
43
44	if (size_get) {
45		struct ia_css_common_io_config *to = (struct ia_css_common_io_config *)
46						     &binary->mem_params.params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM].address[offset];
47		struct dma_port_config config;
48#ifndef IA_CSS_NO_DEBUG
49		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
50				    "ia_css_yuv444_io_config() get part enter:\n");
51#endif
52
53		ret = ia_css_dma_configure_from_info(&config, in_frame_info);
54		if (ret)
55			return ret;
56
57		// The base_address of the input frame will be set in the ISP
58		to->width = in_frame_info->res.width;
59		to->height = in_frame_info->res.height;
60		to->stride = config.stride;
61		to->ddr_elems_per_word = ddr_elems_per_word;
62#ifndef IA_CSS_NO_DEBUG
63		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
64				    "ia_css_yuv444_io_config() get part leave:\n");
65#endif
66	}
67
68	if (binary->info->mem_offsets.offsets.param) {
69		size_put = binary->info->mem_offsets.offsets.param->dmem.put.size;
70		offset = binary->info->mem_offsets.offsets.param->dmem.put.offset;
71	}
72
73	if (size_put) {
74		struct ia_css_common_io_config *to = (struct ia_css_common_io_config *)
75						     &binary->mem_params.params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM].address[offset];
76		struct dma_port_config config;
77#ifndef IA_CSS_NO_DEBUG
78		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
79				    "ia_css_yuv444_io_config() put part enter:\n");
80#endif
81
82		ret = ia_css_dma_configure_from_info(&config, &out_frames[0]->frame_info);
83		if (ret)
84			return ret;
85
86		to->base_address = out_frames[0]->data;
87		to->width = out_frames[0]->frame_info.res.width;
88		to->height = out_frames[0]->frame_info.res.height;
89		to->stride = config.stride;
90		to->ddr_elems_per_word = ddr_elems_per_word;
91
92#ifndef IA_CSS_NO_DEBUG
93		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
94				    "ia_css_yuv444_io_config() put part leave:\n");
95#endif
96	}
97	return 0;
98}
99