• 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 #if !defined( __ACAMERA_FW_H__ )
21 #define __ACAMERA_FW_H__
22 
23 #include "acamera_types.h"
24 #include "acamera_logger.h"
25 #include "acamera_calibrations.h"
26 #include "system_interrupts.h"
27 #include "system_semaphore.h"
28 #include "acamera_firmware_api.h"
29 #include "acamera_isp_core_nomem_settings.h"
30 #include "acamera_firmware_config.h"
31 #include "acamera_isp_config.h"
32 
33 
34 #define FW_PAUSE 0
35 #define FW_RUN 1
36 
37 
38 struct _acamera_fsm_mgr_t;
39 struct _acamera_context_t;
40 struct _dma_raw_capture_t;
41 struct _acamera_firmware_t;
42 struct _isp_info_t;
43 typedef struct _acamera_fsm_mgr_t acamera_fsm_mgr_t;
44 typedef struct _acamera_context_t acamera_context_t;
45 typedef struct _acamera_context_t *acamera_context_ptr_t;
46 typedef struct _dma_raw_capture_t dma_raw_capture_t;
47 typedef struct _acamera_firmware_t acamera_firmware_t;
48 typedef struct _isp_info_t isp_info_t;
49 
50 struct _isp_info_t {
51     uint8_t state;
52 };
53 
54 #include "acamera_fsm_mgr.h"
55 #include "fsm_util.h"
56 #include "fsm_param.h"
57 #include "sensor_init.h"
58 #include "acamera_isp_config.h"
59 
60 
61 #if ISP_DMA_RAW_CAPTURE
62 #include "dma_raw_capture.h"
63 #endif
64 
65 typedef struct _sytem_tab {
66     uint8_t global_freeze_firmware;
67     uint8_t global_manual_exposure;
68     uint8_t global_manual_exposure_ratio;
69 
70     uint8_t global_manual_iridix;
71     uint8_t global_manual_sinter;
72     uint8_t global_manual_temper;
73     uint8_t global_manual_awb;
74     uint8_t global_manual_saturation;
75     uint8_t global_manual_auto_level;
76     uint8_t global_manual_frame_stitch;
77     uint8_t global_manual_raw_frontend;
78     uint8_t global_manual_black_level;
79     uint8_t global_manual_shading;
80     uint8_t global_manual_demosaic;
81     uint8_t global_manual_cnr;
82     uint8_t global_manual_sharpen;
83 
84     uint32_t global_exposure;
85     uint32_t global_long_integration_time;
86     uint32_t global_short_integration_time;
87     uint8_t global_exposure_ratio;
88 
89 
90     uint8_t global_iridix_strength_target;
91     uint8_t global_maximum_iridix_strength;
92     uint8_t global_minimum_iridix_strength;
93     uint8_t global_sinter_threshold_target;
94     uint8_t global_temper_threshold_target;
95     uint16_t global_awb_red_gain;
96     uint16_t global_awb_blue_gain;
97     uint8_t global_saturation_target;
98 
99     uint8_t global_ae_compensation;
100     uint8_t global_calibrate_bad_pixels;
101     uint32_t global_info_preset_num;
102 } system_tab;
103 
104 typedef struct _acamera_isp_sw_regs_map {
105     volatile uint8_t *isp_sw_config_map;
106 } acamera_isp_sw_regs_map;
107 
108 
109 
110 struct _acamera_context_t {
111     uint32_t irq_flag;
112 
113     // profiling routines
114     uint32_t binit_profiler;
115     uint32_t breport_profiler;
116     uint32_t start_profiling;
117     uint32_t stop_profiling;
118     uint32_t frame;
119 
120     uint8_t system_state;
121     uint8_t initialized;
122     uint8_t hflip;
123     uint8_t vflip;
124 
125     acamera_fsm_mgr_t fsm_mgr;
126     acamera_firmware_t *p_gfw;
127 
128     // current calibration set
129     ACameraCalibrations acameraCalibrations;
130 
131     // global settings which can be shared through fsms
132     system_tab stab;
133 
134     uint32_t context_id;
135     uint32_t *context_ref;
136 
137     // context settings
138     acamera_settings settings;
139 
140     const acam_reg_t **isp_sequence;
141     isp_context_seq isp_context_seq;
142 
143     int32_t isp_sequence_default;
144 
145     /* frame counters */
146     uint32_t isp_frame_counter_raw; // frame counter for raw callback
147     uint32_t isp_frame_counter;     // frame counter for frame / metadata callbacks
148 
149     acamera_isp_sw_regs_map sw_reg_map;
150 };
151 
152 
153 struct _acamera_firmware_t {
154 #if ISP_DMA_RAW_CAPTURE
155     // dma_capture
156     dma_raw_capture_t dma_raw_capture;
157 #endif
158 
159     uint32_t api_context; // the active context for API and to display
160     // context instances
161     uint32_t context_number;
162     acamera_context_t fw_ctx[FIRMWARE_CONTEXT_NUMBER];
163 
164     void *dma_chan_isp_config;
165     uint32_t dma_flag_isp_config_completed;
166     void *dma_chan_isp_metering;
167     uint32_t dma_flag_isp_metering_completed;
168 
169     uint32_t initialized;
170 
171     semaphore_t sem_evt_avail;
172 };
173 
174 void acamera_load_isp_sequence( uintptr_t isp_base, const acam_reg_t **sequence, uint8_t num );
175 void acamera_load_sw_sequence( uintptr_t isp_base, const acam_reg_t **sequence, uint8_t num );
176 void load_sensor_sequence( uint8_t num );
177 void acamera_load_array_sequence( acamera_sbus_ptr_t p_sbus, uintptr_t isp_offset, char size, const acam_reg_t **sequence, int group );
178 
179 
acamera_fw_interrupts_enable(acamera_context_ptr_t p_ctx)180 static __inline void acamera_fw_interrupts_enable( acamera_context_ptr_t p_ctx )
181 {
182     if ( p_ctx != NULL ) {
183         if ( !( p_ctx->irq_flag ) ) {
184             system_interrupts_enable();
185         }
186     }
187 }
188 
acamera_fw_interrupts_disable(acamera_context_ptr_t p_ctx)189 static __inline void acamera_fw_interrupts_disable( acamera_context_ptr_t p_ctx )
190 {
191     if ( p_ctx != NULL ) {
192         if ( !( p_ctx->irq_flag ) ) {
193             system_interrupts_disable();
194         }
195     }
196 }
197 
acamera_isp_interrupts_enable(acamera_fsm_mgr_t * p_fsm_mgr)198 static __inline void acamera_isp_interrupts_enable( acamera_fsm_mgr_t *p_fsm_mgr )
199 {
200     if ( p_fsm_mgr != NULL ) {
201         acamera_fw_interrupts_enable( p_fsm_mgr->p_ctx );
202     }
203 }
204 
acamera_isp_interrupts_disable(acamera_fsm_mgr_t * p_fsm_mgr)205 static __inline void acamera_isp_interrupts_disable( acamera_fsm_mgr_t *p_fsm_mgr )
206 {
207     if ( p_fsm_mgr != NULL ) {
208         acamera_fw_interrupts_disable( p_fsm_mgr->p_ctx );
209     }
210 }
211 
212 void acamera_fw_raise_event( acamera_context_ptr_t p_ctx, event_id_t event_id );
213 
214 void acamera_fw_process( acamera_context_t *p_ctx );
215 
216 void acamera_fw_init( acamera_context_t *p_ctx );
217 void acamera_fw_deinit( acamera_context_t *p_ctx );
218 int32_t acamera_init_context( acamera_context_t *p_ctx, acamera_settings *settings, acamera_firmware_t *g_fw );
219 void acamera_deinit_context( acamera_context_t *p_ctx );
220 void acamera_general_interrupt_hanlder( acamera_context_ptr_t p_ctx, uint8_t event );
221 
222 int32_t acamera_init_calibrations( acamera_context_ptr_t p_ctx, char* s_name );
223 void acamera_change_resolution( acamera_context_ptr_t p_ctx, uint32_t exposure_correction );
224 void configure_buffers( acamera_context_ptr_t p_ctx, uint32_t start_addr, uint16_t width, uint16_t height );
225 void acamera_fw_error_routine( acamera_context_t *p_ctx, uint32_t irq_mask );
226 
227 int acamera_3aalg_enable(void);
228 int32_t acamera_extern_param_calculate(void *param);
229 
230 #define ACAMERA_MGR2CTX_PTR( p_fsm_mgr ) \
231     ( ( p_fsm_mgr )->p_ctx )
232 
233 #define ACAMERA_MGR2FIRMWARE_PTR( p_fsm_mgr ) \
234     ( ( p_fsm_mgr )->p_ctx->p_gfw )
235 
236 #define ACAMERA_FSM2MGR_PTR( p_fsm ) \
237     ( ( p_fsm )->p_fsm_mgr )
238 
239 #define ACAMERA_FSM2CTX_PTR( p_fsm ) \
240     ( ( p_fsm )->p_fsm_mgr->p_ctx )
241 
242 #endif /* __ACAMERA_FW_H__ */
243