xref: /linux/drivers/staging/media/atomisp/pci/isp/kernels/raw/raw_1.0/ia_css_raw.host.c (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
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_types.h"
18 #include "sh_css_defs.h"
19 #include "ia_css_debug.h"
20 #include "assert_support.h"
21 #define IA_CSS_INCLUDE_CONFIGURATIONS
22 #include "ia_css_isp_configs.h"
23 #include "isp.h"
24 #include "isp/modes/interface/isp_types.h"
25 
26 #include "ia_css_raw.host.h"
27 
28 static const struct ia_css_raw_configuration default_config = {
29 	.pipe = (struct sh_css_sp_pipeline *)NULL,
30 };
31 
32 /* MW: These areMIPI / ISYS properties, not camera function properties */
33 static enum sh_stream_format
css2isp_stream_format(enum atomisp_input_format from)34 css2isp_stream_format(enum atomisp_input_format from) {
35 	switch (from)
36 	{
37 	case ATOMISP_INPUT_FORMAT_YUV420_8_LEGACY:
38 				return sh_stream_format_yuv420_legacy;
39 	case ATOMISP_INPUT_FORMAT_YUV420_8:
40 	case ATOMISP_INPUT_FORMAT_YUV420_10:
41 	case ATOMISP_INPUT_FORMAT_YUV420_16:
42 		return sh_stream_format_yuv420;
43 	case ATOMISP_INPUT_FORMAT_YUV422_8:
44 	case ATOMISP_INPUT_FORMAT_YUV422_10:
45 	case ATOMISP_INPUT_FORMAT_YUV422_16:
46 		return sh_stream_format_yuv422;
47 	case ATOMISP_INPUT_FORMAT_RGB_444:
48 	case ATOMISP_INPUT_FORMAT_RGB_555:
49 	case ATOMISP_INPUT_FORMAT_RGB_565:
50 	case ATOMISP_INPUT_FORMAT_RGB_666:
51 	case ATOMISP_INPUT_FORMAT_RGB_888:
52 		return sh_stream_format_rgb;
53 	case ATOMISP_INPUT_FORMAT_RAW_6:
54 	case ATOMISP_INPUT_FORMAT_RAW_7:
55 	case ATOMISP_INPUT_FORMAT_RAW_8:
56 	case ATOMISP_INPUT_FORMAT_RAW_10:
57 	case ATOMISP_INPUT_FORMAT_RAW_12:
58 	case ATOMISP_INPUT_FORMAT_RAW_14:
59 	case ATOMISP_INPUT_FORMAT_RAW_16:
60 		return sh_stream_format_raw;
61 	case ATOMISP_INPUT_FORMAT_BINARY_8:
62 	default:
63 		return sh_stream_format_raw;
64 	}
65 }
66 
ia_css_raw_config(struct sh_css_isp_raw_isp_config * to,const struct ia_css_raw_configuration * from,unsigned int size)67 int ia_css_raw_config(struct sh_css_isp_raw_isp_config *to,
68 		      const struct ia_css_raw_configuration  *from,
69 		      unsigned int size)
70 {
71 	unsigned int elems_a = ISP_VEC_NELEMS;
72 	const struct ia_css_frame_info *in_info = from->in_info;
73 	const struct ia_css_frame_info *internal_info = from->internal_info;
74 	int ret;
75 
76 	if (!IS_ISP2401 || !in_info)
77 		in_info = internal_info;
78 
79 	ret = ia_css_dma_configure_from_info(&to->port_b, in_info);
80 	if (ret)
81 		return ret;
82 
83 	/* Assume divisiblity here, may need to generalize to fixed point. */
84 	assert((in_info->format == IA_CSS_FRAME_FORMAT_RAW_PACKED) ||
85 	       (elems_a % to->port_b.elems == 0));
86 
87 	to->width_a_over_b      = elems_a / to->port_b.elems;
88 	to->inout_port_config   = from->pipe->inout_port_config;
89 	to->format              = in_info->format;
90 	to->required_bds_factor = from->pipe->required_bds_factor;
91 	to->two_ppc             = from->two_ppc;
92 	to->stream_format       = css2isp_stream_format(from->stream_format);
93 	to->deinterleaved       = from->deinterleaved;
94 
95 	if (IS_ISP2401) {
96 		to->start_column        = in_info->crop_info.start_column;
97 		to->start_line          = in_info->crop_info.start_line;
98 		to->enable_left_padding = from->enable_left_padding;
99 	}
100 
101 	return 0;
102 }
103 
ia_css_raw_configure(const struct sh_css_sp_pipeline * pipe,const struct ia_css_binary * binary,const struct ia_css_frame_info * in_info,const struct ia_css_frame_info * internal_info,bool two_ppc,bool deinterleaved)104 int ia_css_raw_configure(const struct sh_css_sp_pipeline *pipe,
105 			 const struct ia_css_binary      *binary,
106 			 const struct ia_css_frame_info  *in_info,
107 			 const struct ia_css_frame_info  *internal_info,
108 			 bool two_ppc,
109 			 bool deinterleaved)
110 {
111 	u8 enable_left_padding = (uint8_t)((binary->left_padding) ? 1 : 0);
112 	struct ia_css_raw_configuration config = default_config;
113 
114 	config.pipe                = pipe;
115 	config.in_info             = in_info;
116 	config.internal_info       = internal_info;
117 	config.two_ppc             = two_ppc;
118 	config.stream_format       = binary->input_format;
119 	config.deinterleaved       = deinterleaved;
120 	config.enable_left_padding = enable_left_padding;
121 
122 	return ia_css_configure_raw(binary, &config);
123 }
124