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 "system_global.h"
17
18
19 #include "input_formatter.h"
20 #include <type_support.h>
21 #include "gp_device.h"
22
23 #include "assert_support.h"
24
25 #ifndef __INLINE_INPUT_FORMATTER__
26 #include "input_formatter_private.h"
27 #endif /* __INLINE_INPUT_FORMATTER__ */
28
29 static const unsigned int input_formatter_alignment[N_INPUT_FORMATTER_ID] = {
30 ISP_VEC_ALIGN, ISP_VEC_ALIGN, HIVE_ISP_CTRL_DATA_BYTES
31 };
32
33 const hrt_address HIVE_IF_SRST_ADDRESS[N_INPUT_FORMATTER_ID] = {
34 INPUT_FORMATTER0_SRST_OFFSET,
35 INPUT_FORMATTER1_SRST_OFFSET,
36 INPUT_FORMATTER2_SRST_OFFSET,
37 INPUT_FORMATTER3_SRST_OFFSET
38 };
39
40 const hrt_data HIVE_IF_SRST_MASK[N_INPUT_FORMATTER_ID] = {
41 INPUT_FORMATTER0_SRST_MASK,
42 INPUT_FORMATTER1_SRST_MASK,
43 INPUT_FORMATTER2_SRST_MASK,
44 INPUT_FORMATTER3_SRST_MASK
45 };
46
47 const u8 HIVE_IF_SWITCH_CODE[N_INPUT_FORMATTER_ID] = {
48 HIVE_INPUT_SWITCH_SELECT_IF_PRIM,
49 HIVE_INPUT_SWITCH_SELECT_IF_PRIM,
50 HIVE_INPUT_SWITCH_SELECT_IF_SEC,
51 HIVE_INPUT_SWITCH_SELECT_STR_TO_MEM
52 };
53
54 /* MW Should be part of system_global.h, where we have the main enumeration */
55 static const bool HIVE_IF_BIN_COPY[N_INPUT_FORMATTER_ID] = {
56 false, false, false, true
57 };
58
input_formatter_rst(const input_formatter_ID_t ID)59 void input_formatter_rst(
60 const input_formatter_ID_t ID)
61 {
62 hrt_address addr;
63 hrt_data rst;
64
65 assert(ID < N_INPUT_FORMATTER_ID);
66
67 addr = HIVE_IF_SRST_ADDRESS[ID];
68 rst = HIVE_IF_SRST_MASK[ID];
69
70 /* TEMPORARY HACK: THIS RESET BREAKS THE METADATA FEATURE
71 * WICH USES THE STREAM2MEMRY BLOCK.
72 * MUST BE FIXED PROPERLY
73 */
74 if (!HIVE_IF_BIN_COPY[ID]) {
75 input_formatter_reg_store(ID, addr, rst);
76 }
77
78 return;
79 }
80
input_formatter_get_alignment(const input_formatter_ID_t ID)81 unsigned int input_formatter_get_alignment(
82 const input_formatter_ID_t ID)
83 {
84 assert(ID < N_INPUT_FORMATTER_ID);
85
86 return input_formatter_alignment[ID];
87 }
88
input_formatter_set_fifo_blocking_mode(const input_formatter_ID_t ID,const bool enable)89 void input_formatter_set_fifo_blocking_mode(
90 const input_formatter_ID_t ID,
91 const bool enable)
92 {
93 assert(ID < N_INPUT_FORMATTER_ID);
94
95 /* cnd_input_formatter_reg_store() */
96 if (!HIVE_IF_BIN_COPY[ID]) {
97 input_formatter_reg_store(ID,
98 HIVE_IF_BLOCK_FIFO_NO_REQ_ADDRESS, enable);
99 }
100 return;
101 }
102
input_formatter_get_switch_state(const input_formatter_ID_t ID,input_formatter_switch_state_t * state)103 void input_formatter_get_switch_state(
104 const input_formatter_ID_t ID,
105 input_formatter_switch_state_t *state)
106 {
107 assert(ID < N_INPUT_FORMATTER_ID);
108 assert(state);
109
110 /* We'll change this into an intelligent function to get switch info per IF */
111 (void)ID;
112
113 state->if_input_switch_lut_reg[0] = gp_device_reg_load(GP_DEVICE0_ID,
114 _REG_GP_IFMT_input_switch_lut_reg0);
115 state->if_input_switch_lut_reg[1] = gp_device_reg_load(GP_DEVICE0_ID,
116 _REG_GP_IFMT_input_switch_lut_reg1);
117 state->if_input_switch_lut_reg[2] = gp_device_reg_load(GP_DEVICE0_ID,
118 _REG_GP_IFMT_input_switch_lut_reg2);
119 state->if_input_switch_lut_reg[3] = gp_device_reg_load(GP_DEVICE0_ID,
120 _REG_GP_IFMT_input_switch_lut_reg3);
121 state->if_input_switch_lut_reg[4] = gp_device_reg_load(GP_DEVICE0_ID,
122 _REG_GP_IFMT_input_switch_lut_reg4);
123 state->if_input_switch_lut_reg[5] = gp_device_reg_load(GP_DEVICE0_ID,
124 _REG_GP_IFMT_input_switch_lut_reg5);
125 state->if_input_switch_lut_reg[6] = gp_device_reg_load(GP_DEVICE0_ID,
126 _REG_GP_IFMT_input_switch_lut_reg6);
127 state->if_input_switch_lut_reg[7] = gp_device_reg_load(GP_DEVICE0_ID,
128 _REG_GP_IFMT_input_switch_lut_reg7);
129 state->if_input_switch_fsync_lut = gp_device_reg_load(GP_DEVICE0_ID,
130 _REG_GP_IFMT_input_switch_fsync_lut);
131 state->if_input_switch_ch_id_fmt_type = gp_device_reg_load(GP_DEVICE0_ID,
132 _REG_GP_IFMT_input_switch_ch_id_fmt_type);
133
134 return;
135 }
136
input_formatter_get_state(const input_formatter_ID_t ID,input_formatter_state_t * state)137 void input_formatter_get_state(
138 const input_formatter_ID_t ID,
139 input_formatter_state_t *state)
140 {
141 assert(ID < N_INPUT_FORMATTER_ID);
142 assert(state);
143 /*
144 state->reset = input_formatter_reg_load(ID,
145 HIVE_IF_RESET_ADDRESS);
146 */
147 state->start_line = input_formatter_reg_load(ID,
148 HIVE_IF_START_LINE_ADDRESS);
149 state->start_column = input_formatter_reg_load(ID,
150 HIVE_IF_START_COLUMN_ADDRESS);
151 state->cropped_height = input_formatter_reg_load(ID,
152 HIVE_IF_CROPPED_HEIGHT_ADDRESS);
153 state->cropped_width = input_formatter_reg_load(ID,
154 HIVE_IF_CROPPED_WIDTH_ADDRESS);
155 state->ver_decimation = input_formatter_reg_load(ID,
156 HIVE_IF_VERTICAL_DECIMATION_ADDRESS);
157 state->hor_decimation = input_formatter_reg_load(ID,
158 HIVE_IF_HORIZONTAL_DECIMATION_ADDRESS);
159 state->hor_deinterleaving = input_formatter_reg_load(ID,
160 HIVE_IF_H_DEINTERLEAVING_ADDRESS);
161 state->left_padding = input_formatter_reg_load(ID,
162 HIVE_IF_LEFTPADDING_WIDTH_ADDRESS);
163 state->eol_offset = input_formatter_reg_load(ID,
164 HIVE_IF_END_OF_LINE_OFFSET_ADDRESS);
165 state->vmem_start_address = input_formatter_reg_load(ID,
166 HIVE_IF_VMEM_START_ADDRESS_ADDRESS);
167 state->vmem_end_address = input_formatter_reg_load(ID,
168 HIVE_IF_VMEM_END_ADDRESS_ADDRESS);
169 state->vmem_increment = input_formatter_reg_load(ID,
170 HIVE_IF_VMEM_INCREMENT_ADDRESS);
171 state->is_yuv420 = input_formatter_reg_load(ID,
172 HIVE_IF_YUV_420_FORMAT_ADDRESS);
173 state->vsync_active_low = input_formatter_reg_load(ID,
174 HIVE_IF_VSYNCK_ACTIVE_LOW_ADDRESS);
175 state->hsync_active_low = input_formatter_reg_load(ID,
176 HIVE_IF_HSYNCK_ACTIVE_LOW_ADDRESS);
177 state->allow_fifo_overflow = input_formatter_reg_load(ID,
178 HIVE_IF_ALLOW_FIFO_OVERFLOW_ADDRESS);
179 state->block_fifo_when_no_req = input_formatter_reg_load(ID,
180 HIVE_IF_BLOCK_FIFO_NO_REQ_ADDRESS);
181 state->ver_deinterleaving = input_formatter_reg_load(ID,
182 HIVE_IF_V_DEINTERLEAVING_ADDRESS);
183 /* FSM */
184 state->fsm_sync_status = input_formatter_reg_load(ID,
185 HIVE_IF_FSM_SYNC_STATUS);
186 state->fsm_sync_counter = input_formatter_reg_load(ID,
187 HIVE_IF_FSM_SYNC_COUNTER);
188 state->fsm_crop_status = input_formatter_reg_load(ID,
189 HIVE_IF_FSM_CROP_STATUS);
190 state->fsm_crop_line_counter = input_formatter_reg_load(ID,
191 HIVE_IF_FSM_CROP_LINE_COUNTER);
192 state->fsm_crop_pixel_counter = input_formatter_reg_load(ID,
193 HIVE_IF_FSM_CROP_PIXEL_COUNTER);
194 state->fsm_deinterleaving_index = input_formatter_reg_load(ID,
195 HIVE_IF_FSM_DEINTERLEAVING_IDX);
196 state->fsm_dec_h_counter = input_formatter_reg_load(ID,
197 HIVE_IF_FSM_DECIMATION_H_COUNTER);
198 state->fsm_dec_v_counter = input_formatter_reg_load(ID,
199 HIVE_IF_FSM_DECIMATION_V_COUNTER);
200 state->fsm_dec_block_v_counter = input_formatter_reg_load(ID,
201 HIVE_IF_FSM_DECIMATION_BLOCK_V_COUNTER);
202 state->fsm_padding_status = input_formatter_reg_load(ID,
203 HIVE_IF_FSM_PADDING_STATUS);
204 state->fsm_padding_elem_counter = input_formatter_reg_load(ID,
205 HIVE_IF_FSM_PADDING_ELEMENT_COUNTER);
206 state->fsm_vector_support_error = input_formatter_reg_load(ID,
207 HIVE_IF_FSM_VECTOR_SUPPORT_ERROR);
208 state->fsm_vector_buffer_full = input_formatter_reg_load(ID,
209 HIVE_IF_FSM_VECTOR_SUPPORT_BUFF_FULL);
210 state->vector_support = input_formatter_reg_load(ID,
211 HIVE_IF_FSM_VECTOR_SUPPORT);
212 state->sensor_data_lost = input_formatter_reg_load(ID,
213 HIVE_IF_FIFO_SENSOR_STATUS);
214
215 return;
216 }
217
input_formatter_bin_get_state(const input_formatter_ID_t ID,input_formatter_bin_state_t * state)218 void input_formatter_bin_get_state(
219 const input_formatter_ID_t ID,
220 input_formatter_bin_state_t *state)
221 {
222 assert(ID < N_INPUT_FORMATTER_ID);
223 assert(state);
224
225 state->reset = input_formatter_reg_load(ID,
226 HIVE_STR2MEM_SOFT_RESET_REG_ADDRESS);
227 state->input_endianness = input_formatter_reg_load(ID,
228 HIVE_STR2MEM_INPUT_ENDIANNESS_REG_ADDRESS);
229 state->output_endianness = input_formatter_reg_load(ID,
230 HIVE_STR2MEM_OUTPUT_ENDIANNESS_REG_ADDRESS);
231 state->bitswap = input_formatter_reg_load(ID,
232 HIVE_STR2MEM_BIT_SWAPPING_REG_ADDRESS);
233 state->block_synch = input_formatter_reg_load(ID,
234 HIVE_STR2MEM_BLOCK_SYNC_LEVEL_REG_ADDRESS);
235 state->packet_synch = input_formatter_reg_load(ID,
236 HIVE_STR2MEM_PACKET_SYNC_LEVEL_REG_ADDRESS);
237 state->readpostwrite_synch = input_formatter_reg_load(ID,
238 HIVE_STR2MEM_READ_POST_WRITE_SYNC_ENABLE_REG_ADDRESS);
239 state->is_2ppc = input_formatter_reg_load(ID,
240 HIVE_STR2MEM_DUAL_BYTE_INPUTS_ENABLED_REG_ADDRESS);
241 state->en_status_update = input_formatter_reg_load(ID,
242 HIVE_STR2MEM_EN_STAT_UPDATE_ADDRESS);
243 return;
244 }
245