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_frame.h"
17#include "ia_css_debug.h"
18#define IA_CSS_INCLUDE_CONFIGURATIONS
19#include "ia_css_isp_configs.h"
20#include "ia_css_output.host.h"
21#include "isp.h"
22
23#include "assert_support.h"
24
25const struct ia_css_output_config default_output_config = {
26	0,
27	0
28};
29
30static const struct ia_css_output_configuration default_output_configuration = {
31	.info = (struct ia_css_frame_info *)NULL,
32};
33
34static const struct ia_css_output0_configuration default_output0_configuration
35	= {
36	.info = (struct ia_css_frame_info *)NULL,
37};
38
39static const struct ia_css_output1_configuration default_output1_configuration
40	= {
41	.info = (struct ia_css_frame_info *)NULL,
42};
43
44void
45ia_css_output_encode(
46    struct sh_css_isp_output_params *to,
47    const struct ia_css_output_config *from,
48    unsigned int size)
49{
50	(void)size;
51	to->enable_hflip = from->enable_hflip;
52	to->enable_vflip = from->enable_vflip;
53}
54
55int ia_css_output_config(struct sh_css_isp_output_isp_config *to,
56			 const struct ia_css_output_configuration  *from,
57			 unsigned int size)
58{
59	unsigned int elems_a = ISP_VEC_NELEMS;
60	int ret;
61
62	ret = ia_css_dma_configure_from_info(&to->port_b, from->info);
63	if (ret)
64		return ret;
65
66	to->width_a_over_b = elems_a / to->port_b.elems;
67	to->height = from->info ? from->info->res.height : 0;
68	to->enable = from->info != NULL;
69	ia_css_frame_info_to_frame_sp_info(&to->info, from->info);
70
71	/* Assume divisiblity here, may need to generalize to fixed point. */
72	if (elems_a % to->port_b.elems != 0)
73		return -EINVAL;
74
75	return 0;
76}
77
78int ia_css_output0_config(struct sh_css_isp_output_isp_config       *to,
79			  const struct ia_css_output0_configuration *from,
80			  unsigned int size)
81{
82	return ia_css_output_config(to, (const struct ia_css_output_configuration *)from, size);
83}
84
85int ia_css_output1_config(struct sh_css_isp_output_isp_config       *to,
86		          const struct ia_css_output1_configuration *from,
87			  unsigned int size)
88{
89	return ia_css_output_config(to, (const struct ia_css_output_configuration *)from, size);
90}
91
92int ia_css_output_configure(const struct ia_css_binary     *binary,
93			    const struct ia_css_frame_info *info)
94{
95	if (info) {
96		struct ia_css_output_configuration config =
97			    default_output_configuration;
98
99		config.info = info;
100
101		return ia_css_configure_output(binary, &config);
102	}
103	return 0;
104}
105
106int ia_css_output0_configure(const struct ia_css_binary    *binary,
107			    const struct ia_css_frame_info *info)
108{
109	if (info) {
110		struct ia_css_output0_configuration config =
111			    default_output0_configuration;
112
113		config.info = info;
114
115		return ia_css_configure_output0(binary, &config);
116	}
117	return 0;
118}
119
120int ia_css_output1_configure(const struct ia_css_binary     *binary,
121			     const struct ia_css_frame_info *info)
122{
123	if (info) {
124		struct ia_css_output1_configuration config =
125			    default_output1_configuration;
126
127		config.info = info;
128
129		return ia_css_configure_output1(binary, &config);
130	}
131	return 0;
132}
133
134void
135ia_css_output_dump(
136    const struct sh_css_isp_output_params *output,
137    unsigned int level)
138{
139	if (!output) return;
140	ia_css_debug_dtrace(level, "Horizontal Output Flip:\n");
141	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
142			    "enable", output->enable_hflip);
143	ia_css_debug_dtrace(level, "Vertical Output Flip:\n");
144	ia_css_debug_dtrace(level, "\t%-32s = %d\n",
145			    "enable", output->enable_vflip);
146}
147
148void
149ia_css_output_debug_dtrace(
150    const struct ia_css_output_config *config,
151    unsigned int level)
152{
153	ia_css_debug_dtrace(level,
154			    "config.enable_hflip=%d",
155			    config->enable_hflip);
156	ia_css_debug_dtrace(level,
157			    "config.enable_vflip=%d",
158			    config->enable_vflip);
159}
160