GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / isp / kernels / raw / raw_1.0 / ia_css_raw.host.c
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #include "ia_css_frame.h"
16 #include "ia_css_types.h"
17 #include "sh_css_defs.h"
18 #include "ia_css_debug.h"
19 #include "assert_support.h"
20 #define IA_CSS_INCLUDE_CONFIGURATIONS
21 #include "ia_css_isp_configs.h"
22 #include "isp.h"
23 #include "isp/modes/interface/isp_types.h"
24
25 #include "ia_css_raw.host.h"
26
27
28 static const struct ia_css_raw_configuration default_config = {
29         .pipe = (struct sh_css_sp_pipeline *)NULL,
30 };
31
32 static inline unsigned
33 sh_css_elems_bytes_from_info (unsigned raw_bit_depth)
34 {
35         return CEIL_DIV(raw_bit_depth,8);
36 }
37
38 /* MW: These areMIPI / ISYS properties, not camera function properties */
39 static enum sh_stream_format
40 css2isp_stream_format(enum ia_css_stream_format from)
41 {
42         switch (from) {
43         case IA_CSS_STREAM_FORMAT_YUV420_8_LEGACY:
44                 return sh_stream_format_yuv420_legacy;
45         case IA_CSS_STREAM_FORMAT_YUV420_8:
46         case IA_CSS_STREAM_FORMAT_YUV420_10:
47         case IA_CSS_STREAM_FORMAT_YUV420_16:
48                 return sh_stream_format_yuv420;
49         case IA_CSS_STREAM_FORMAT_YUV422_8:
50         case IA_CSS_STREAM_FORMAT_YUV422_10:
51         case IA_CSS_STREAM_FORMAT_YUV422_16:
52                 return sh_stream_format_yuv422;
53         case IA_CSS_STREAM_FORMAT_RGB_444:
54         case IA_CSS_STREAM_FORMAT_RGB_555:
55         case IA_CSS_STREAM_FORMAT_RGB_565:
56         case IA_CSS_STREAM_FORMAT_RGB_666:
57         case IA_CSS_STREAM_FORMAT_RGB_888:
58                 return sh_stream_format_rgb;
59         case IA_CSS_STREAM_FORMAT_RAW_6:
60         case IA_CSS_STREAM_FORMAT_RAW_7:
61         case IA_CSS_STREAM_FORMAT_RAW_8:
62         case IA_CSS_STREAM_FORMAT_RAW_10:
63         case IA_CSS_STREAM_FORMAT_RAW_12:
64         case IA_CSS_STREAM_FORMAT_RAW_14:
65         case IA_CSS_STREAM_FORMAT_RAW_16:
66                 return sh_stream_format_raw;
67         case IA_CSS_STREAM_FORMAT_BINARY_8:
68         default:
69                 return sh_stream_format_raw;
70         }
71 }
72
73 void
74 ia_css_raw_config(
75         struct sh_css_isp_raw_isp_config *to,
76         const struct ia_css_raw_configuration  *from,
77         unsigned size)
78 {
79         unsigned elems_a = ISP_VEC_NELEMS;
80         const struct ia_css_frame_info *in_info = from->in_info;
81         const struct ia_css_frame_info *internal_info = from->internal_info;
82
83         (void)size;
84 #if !defined(USE_INPUT_SYSTEM_VERSION_2401)
85         /* 2401 input system uses input width width */
86         in_info = internal_info;
87 #else
88         /*in some cases, in_info is NULL*/
89         if (in_info)
90                 (void)internal_info;
91         else
92                 in_info = internal_info;
93
94 #endif
95         ia_css_dma_configure_from_info(&to->port_b, in_info);
96
97         /* Assume divisiblity here, may need to generalize to fixed point. */
98         assert((in_info->format == IA_CSS_FRAME_FORMAT_RAW_PACKED) ||
99                    (elems_a % to->port_b.elems == 0));
100
101         to->width_a_over_b      = elems_a / to->port_b.elems;
102         to->inout_port_config   = from->pipe->inout_port_config;
103         to->format              = in_info->format;
104         to->required_bds_factor = from->pipe->required_bds_factor;
105         to->two_ppc             = from->two_ppc;
106         to->stream_format       = css2isp_stream_format(from->stream_format);
107         to->deinterleaved       = from->deinterleaved;
108 #if (defined(USE_INPUT_SYSTEM_VERSION_2401) || defined(CONFIG_CSI2_PLUS))
109         to->start_column        = in_info->crop_info.start_column;
110         to->start_line          = in_info->crop_info.start_line;
111         to->enable_left_padding = from->enable_left_padding;
112 #endif
113 }
114
115 void
116 ia_css_raw_configure(
117         const struct sh_css_sp_pipeline *pipe,
118         const struct ia_css_binary      *binary,
119         const struct ia_css_frame_info  *in_info,
120         const struct ia_css_frame_info  *internal_info,
121         bool two_ppc,
122         bool deinterleaved)
123 {
124         uint8_t enable_left_padding = (uint8_t)((binary->left_padding) ? 1 : 0);
125         struct ia_css_raw_configuration config = default_config;
126
127         config.pipe                = pipe;
128         config.in_info             = in_info;
129         config.internal_info       = internal_info;
130         config.two_ppc             = two_ppc;
131         config.stream_format       = binary->input_format;
132         config.deinterleaved       = deinterleaved;
133         config.enable_left_padding = enable_left_padding;
134
135         ia_css_configure_raw(binary, &config);
136 }