• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19 
20 #ifndef __DMA_WRITER_API__
21 #define __DMA_WRITER_API__
22 
23 #include "acamera_types.h"
24 #include "acamera_firmware_config.h"
25 #include "acamera.h"
26 /**
27  *   return codes
28  */
29 typedef enum dma_error {
30     edma_ok = 0,
31     edma_fail,
32     edma_invalid_pipe,
33     edma_wrong_parameters,
34     edma_invalid_api,
35     edma_invalid_settings
36 } dma_error;
37 
38 
39 /**
40  *   pipe api
41  *   all functions must be initialized properly
42  */
43 typedef struct dma_api {
44     uint8_t ( *p_acamera_isp_dma_writer_format_read )( uintptr_t );
45     void ( *p_acamera_isp_dma_writer_format_write )( uintptr_t, uint8_t );
46     void ( *p_acamera_isp_dma_writer_bank0_base_write )( uintptr_t, uint32_t );
47 #if ISP_HAS_FPGA_WRAPPER
48     void ( *p_acamera_fpga_frame_reader_rbase_write )( uintptr_t, uint32_t );
49     void ( *p_acamera_fpga_frame_reader_line_offset_write )( uintptr_t, uint32_t );
50     void (*p_acamera_fpga_frame_reader_format_write) (uintptr_t base, uint8_t data);
51     void (*p_acamera_fpga_frame_reader_rbase_load_write) (uintptr_t base, uint8_t data);
52 #endif
53     void ( *p_acamera_isp_dma_writer_line_offset_write )( uintptr_t, uint32_t );
54     void ( *p_acamera_isp_dma_writer_frame_write_on_write )( uintptr_t, uint8_t );
55     void ( *p_acamera_isp_dma_writer_active_width_write )( uintptr_t, uint16_t );
56     void ( *p_acamera_isp_dma_writer_active_height_write )( uintptr_t, uint16_t );
57 
58     uint16_t ( *p_acamera_isp_dma_writer_active_width_read )( uintptr_t );
59     uint16_t ( *p_acamera_isp_dma_writer_active_height_read )( uintptr_t );
60 
61     void ( *p_acamera_isp_dma_writer_max_bank_write )( uintptr_t, uint8_t );
62 
63     uint8_t ( *p_acamera_isp_dma_writer_format_read_uv )( uintptr_t );
64     void ( *p_acamera_isp_dma_writer_format_write_uv )( uintptr_t, uint8_t );
65     void ( *p_acamera_isp_dma_writer_bank0_base_write_uv )( uintptr_t, uint32_t );
66     void ( *p_acamera_isp_dma_writer_max_bank_write_uv )( uintptr_t, uint8_t );
67     void ( *p_acamera_isp_dma_writer_line_offset_write_uv )( uintptr_t, uint32_t );
68     void ( *p_acamera_isp_dma_writer_frame_write_on_write_uv )( uintptr_t, uint8_t );
69     void ( *p_acamera_isp_dma_writer_active_width_write_uv )( uintptr_t, uint16_t );
70     void ( *p_acamera_isp_dma_writer_active_height_write_uv )( uintptr_t, uint16_t );
71     uint16_t ( *p_acamera_isp_dma_writer_active_width_read_uv )( uintptr_t );
72     uint16_t ( *p_acamera_isp_dma_writer_active_height_read_uv )( uintptr_t );
73 #if ISP_HAS_FPGA_WRAPPER
74     void ( *p_acamera_fpga_frame_reader_rbase_write_uv )( uintptr_t, uint32_t );
75     void ( *p_acamera_fpga_frame_reader_line_offset_write_uv )( uintptr_t, uint32_t );
76     void (*p_acamera_fpga_frame_reader_format_write_uv) (uintptr_t base, uint8_t data);
77     void (*p_acamera_fpga_frame_reader_rbase_load_write_uv) (uintptr_t base, uint8_t data);
78 #endif
79 
80 } dma_api;
81 
82 
83 /**
84  *   pipe settings
85  */
86 typedef struct dma_pipe_settings {
87     uint32_t width;  // dma output width
88     uint32_t height; // dma output height
89 
90     tframe_t frame_buf_queue[MAX_DMA_QUEUE_FRAMES];
91 
92     metadata_t curr_metadata;
93 
94     uint32_t vflip; // vertical flip
95 
96     int32_t read_offset;  // offset for frame reader
97     int32_t write_offset; // offset for frame writer
98     uint32_t active;      // frame reader gets data from active pipe
99     uint32_t enabled;     // enable or disable any pipe activity
100 
101     uint32_t banks_number; // number of used banks
102     uint32_t clear_memory; // clear memory befor writing
103     uint32_t clear_color;  // clear color
104     uint32_t last_address; // last address which was used to write a frame
105     uintptr_t isp_base;
106     uint32_t ctx_id;
107     buffer_callback_t callback; // callback
108     tframe_t *last_tframe;
109     uint8_t pause;
110     struct _acamera_context_t *p_ctx;
111     tframe_t *back_tframe; //used to backup last tframe
112     uint32_t c_fps; //current sensor setting fps
113     uint32_t t_fps; //pipe target fps
114     uint32_t inter_val; //interval frames
115     uint32_t init_delay;
116     tframe_t *inqueue_tframe[2];
117 } dma_pipe_settings;
118 
119 
120 /**
121  *   Create a dma writer instance
122  *
123  *   This routine creates a dma writer instance.
124  *   The output pointer to dma writer structure will be saved in *handle
125  *
126  *   @param handle - pointer to the instance
127  *
128  *   @return edma_ok - success
129  *           edma_fail - fail
130  */
131 dma_error dma_writer_create( void **handle );
132 void dma_writer_exit( void *handle );
133 
134 /**
135  *   Check if the pipe correctly initialized
136  *
137  *
138  *   @param handle - pointer to the instance
139  *
140  *   @return edma_ok - initialized properly
141  *           edma_fail - fail
142  */
143 dma_error dma_writer_pipe_initialized( void **handle, dma_type type );
144 
145 
146 /**
147  *   Get default settings for one dma pipe.
148  *
149  *   To be sure that all settings are correct you have to call this function before changing any parameters.
150  *   It sets all settings in their default value. After that it can be changed by caller.
151  *
152  *   @param handle - pointer to the instance
153  *   @param settings - pointer to the settings structure.
154  *   @param type - a type of a dma output
155  *
156  *   @return edma_ok - success
157  *           edma_fail - fail
158  */
159 dma_error dma_writer_get_default_settings( void *handle, dma_type type, dma_pipe_settings *settings );
160 
161 
162 /**
163  *   Initialize a pipe
164  *
165  *   This routine will initialize a pipe with specified settings and given api
166  *   Be sure that all api functions have been initialized properly
167  *
168  *   @param handle - pointer to the instance
169  *   @param settings - pointer to the settings structure.
170  *   @param api - pointer to the api structure.
171  *   @param type - a type of a dma output
172  *
173  *   @return edma_ok - success
174  *           edma_fail - fail
175  */
176 dma_error dma_writer_init( void *handle, dma_type type, dma_pipe_settings *settings, dma_api *api );
177 
178 
179 /**
180  *   Return current settings
181  *
182  *   The routine will copy all settings to your memory
183  *   for specified pipe. It's better to use this function when you're
184  *   planning to call set_settings after it.
185  *
186  *   @param handle - pointer to the instance
187  *   @param settings - pointer to the settings structure.
188  *   @param type - a type of a dma output
189  *
190  *   @return edma_ok - success
191  *           edma_fail - fail
192  */
193 dma_error dma_writer_get_settings( void *handle, dma_type type, dma_pipe_settings *settings );
194 
195 
196 /**
197  *   Return current settings
198  *
199  *   The routine will return a pointer on a settings structure
200  *   for a given pipe. It can be used if you need just a fast access
201  *   to the settings without modifying it
202  *
203  *   @param handle - pointer to the instance
204  *   @param settings - pointer to the settings structure.
205  *   @param type - a type of a dma output
206  *
207  *   @return edma_ok - success
208  *           edma_fail - fail
209  */
210 dma_error dma_writer_get_ptr_settings( void *handle, dma_type type, dma_pipe_settings **settings );
211 
212 /**
213  *   Apply new settings for specified pipe
214  *
215  *   This routine should be used to change the settings of a pipe.
216  *
217  *   @param handle - pointer to the instance
218  *   @param settings - pointer to the settings structure.
219  *   @param type - a type of a dma output
220  *
221  *   @return edma_ok - success
222  *           edma_fail - fail
223  */
224 dma_error dma_writer_set_settings( void *handle, dma_type type, dma_pipe_settings *settings );
225 
226 
227 /**
228  *   Reset a pipe to the initial state
229  *
230  *   The routine will reset a specified pipe to its initial state
231  *
232  *   @param handle - pointer to the instance
233  *   @param type - a type of a dma output
234  *
235  *   @return edma_ok - success
236  *           edma_fail - fail
237  */
238 dma_error dma_writer_reset( void *handle, dma_type type );
239 
240 
241 /**
242  *   Process an interrupt
243  *
244  *   The routine will handle an interrupt to update
245  *   a state of all pipes
246  *
247  *   @param handle - pointer to the instance
248  *   @param irq_event - input interrupt number
249  *
250  *   @return edma_ok - success
251  *           edma_fail - fail
252  */
253 dma_error dma_writer_process_interrupt( void *handle, uint32_t irq_event );
254 
255 dma_error dma_writer_set_pipe_fps(void *handle, dma_type type, uint32_t c_fps, uint32_t t_fps);
256 
257 uint16_t dma_writer_write_frame_queue( void *handle, dma_type type, tframe_t *frame_buf_array, uint16_t frame_buf_len );
258 metadata_t *dma_writer_return_metadata( void *handle, dma_type type );
259 tframe_t *dma_writer_api_return_next_ready_frame( void *handle, dma_type type );
260 int dma_set_frame_ready_handle( void *handle, dma_type type, uint32_t addr, dma_buf_state set_dma_state );
261 void dma_writer_set_initialized( void *handle, dma_type type, uint8_t initialized );
262 dma_error dma_writer_pipe_get_next_empty_buffer( void *handle, dma_type type );
263 
264 #endif /* __DMA_WRITER_API__ */
265