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