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( __CMOS_FSM_H__ ) 21 #define __CMOS_FSM_H__ 22 23 24 25 typedef struct _cmos_fsm_t cmos_fsm_t; 26 typedef struct _cmos_fsm_t *cmos_fsm_ptr_t; 27 typedef const struct _cmos_fsm_t *cmos_fsm_const_ptr_t; 28 29 #include "acamera_sensor_api.h" 30 #include "acamera_math.h" 31 #include "acamera_isp_config.h" 32 #include "system_spinlock.h" 33 34 #define API_OTAE_ITERATION_COUNT ( 15 ) 35 36 typedef enum _cmos_partition_lut_index_ { 37 PARTITION_LUT_BALANED_INDEX = 0, 38 PARTITION_LUT_INTEGRATION_PRIORITY_INDEX = 1, 39 PARTITION_LUT_INDEX_MAX, 40 } cmos_partition_lut_index_t; 41 42 #if FILTER_LONG_INT_TIME 43 typedef struct _it_long_hist_t { 44 uint32_t v[FILTER_LONG_INT_TIME]; 45 uint64_t sum; 46 uint32_t *p; 47 } it_long_hist_t; 48 #endif 49 50 #if FILTER_SHORT_INT_TIME 51 typedef struct _it_short_hist_t { 52 uint32_t v[FILTER_SHORT_INT_TIME]; 53 uint64_t sum; 54 uint32_t *p; 55 } it_short_hist_t; 56 #endif 57 58 typedef struct _cmos_control_param_t { 59 uint32_t global_antiflicker_enable; 60 uint32_t global_anti_flicker_frequency; 61 uint32_t global_manual_integration_time; 62 uint32_t global_manual_sensor_analog_gain; 63 uint32_t global_manual_sensor_digital_gain; 64 uint32_t global_manual_isp_digital_gain; 65 uint32_t global_manual_max_integration_time; 66 uint32_t global_max_integration_time; 67 uint32_t global_max_sensor_analog_gain; 68 uint32_t global_max_sensor_digital_gain; 69 uint32_t global_max_isp_digital_gain; 70 uint32_t global_max_exposure_ratio; 71 uint32_t global_integration_time; 72 uint32_t global_sensor_analog_gain; 73 uint32_t global_sensor_digital_gain; 74 uint32_t global_isp_digital_gain; 75 uint32_t global_analog_gain_last_priority; 76 uint32_t global_analog_gain_reserve; 77 } cmos_control_param_t; 78 79 /* 80 typedef struct _exposure_data_set_t 81 { 82 uint32_t integration_time; 83 int32_t isp_dgain_log2; 84 uint32_t exposure_ratio; 85 uint32_t actual_integration_time; 86 uint32_t integration_time_long; 87 uint32_t exposure_ratio_short; 88 uint32_t exposure_ratio_medium; 89 uint32_t integration_time_medium; 90 } exposure_data_set_t; 91 typedef struct _exposure_info_set_t 92 { 93 int32_t exposure_log2; 94 int32_t again_log2; 95 int32_t dgain_log2; 96 int32_t isp_dgain_log2; 97 } exposure_info_set_t; 98 typedef struct _exposure_set_t 99 { 100 exposure_info_set_t info; 101 exposure_data_set_t data; 102 } exposure_set_t; 103 */ 104 105 typedef struct _fps_counter_t { 106 uint32_t last_tick; 107 uint32_t avg_frame_ticks; 108 } fps_counter_t; 109 110 void cmos_update_exposure_partitioning_lut( cmos_fsm_ptr_t p_fsm ); 111 void cmos_init( cmos_fsm_ptr_t p_fsm ); 112 void cmos_deinit( cmos_fsm_ptr_t p_fsm ); 113 void cmos_inttime_write( cmos_fsm_const_ptr_t p_fsm ); 114 void cmos_gains_write( cmos_fsm_const_ptr_t p_fsm ); 115 void cmos_inttime_update( cmos_fsm_ptr_t p_fsm ); 116 void cmos_alloc_integration_time( cmos_fsm_ptr_t p_fsm, int32_t int_time ); 117 int cmos_convert_integration_time_ms2lines( cmos_fsm_ptr_t p_fsm, int int_time_ms ); 118 void cmos_analog_gain_update( cmos_fsm_ptr_t p_fsm ); 119 void cmos_digital_gain_update( cmos_fsm_ptr_t p_fsm ); 120 void cmos_antiflicker_update( cmos_fsm_ptr_t p_fsm ); 121 void cmos_long_exposure_update( cmos_fsm_ptr_t p_fsm ); 122 void cmos_calc_target_gain( cmos_fsm_ptr_t p_fsm ); 123 void cmos_update_exposure( cmos_fsm_ptr_t p_fsm ); 124 void cmos_update_exposure_history( cmos_fsm_ptr_t p_fsm ); 125 void cmos_set_exposure_target( cmos_fsm_ptr_t p_fsm, int32_t exposure_log2, uint32_t exposure_ratio ); 126 exposure_set_t *cmos_get_frame_exposure_set( cmos_fsm_ptr_t p_fsm, int i_frame ); 127 uint16_t cmos_get_fps( cmos_fsm_ptr_t p_fsm ); 128 129 struct _cmos_fsm_t { 130 fsm_common_t cmn; 131 132 acamera_fsm_mgr_t *p_fsm_mgr; 133 fsm_irq_mask_t mask; 134 int16_t wb[4]; 135 uint8_t manual_gain_mode; 136 uint32_t manual_gain; 137 uint32_t exposure; 138 int32_t exposure_log2; 139 sys_spinlock exp_lock; 140 exposure_set_t exp_next_set; 141 exposure_data_set_t exp_write_set; 142 int32_t max_exposure_log2; 143 #if FILTER_LONG_INT_TIME 144 it_long_hist_t long_it_hist; 145 #endif 146 #if FILTER_SHORT_INT_TIME 147 it_short_hist_t short_it_hist; 148 #endif 149 exposure_set_t exposure_hist[8]; 150 int exposure_hist_pos; 151 fps_counter_t fps_cnt; 152 uint16_t flicker_freq; 153 uint32_t lines_per_500ms; 154 uint32_t exposure_ratio_in; 155 uint32_t prev_integration_time_short; 156 uint16_t integration_time_short; 157 uint16_t integration_time_medium; 158 uint16_t integration_time_medium2; 159 uint16_t integration_time_long; 160 uint16_t exposure_ratio; 161 int32_t again_val_log2; 162 int32_t dgain_val_log2; 163 int32_t log2_gain_avg; 164 int32_t isp_dgain_log2; 165 int32_t target_gain_log2; 166 int32_t target_gain_step_log2; 167 uint8_t flash_state; 168 uint8_t flash_skip_charge; 169 uint8_t strategy; 170 int32_t maximum_isp_digital_gain; 171 172 uint32_t frame_id_tracking; 173 uint32_t prev_ae_frame_id_tracking; 174 uint32_t prev_awb_frame_id_tracking; 175 176 /* previous FrameStart FrameID */ 177 uint32_t prev_fs_frame_id; 178 uint32_t prev_dgain_frame_id; 179 180 uint32_t exp_lut[SYSTEM_EXPOSURE_PARTITION_VALUE_COUNT]; 181 }; 182 183 184 void cmos_fsm_clear( cmos_fsm_ptr_t p_fsm ); 185 void cmos_fsm_init( void *fsm, fsm_init_param_t *init_param ); 186 187 int cmos_fsm_set_param( void *fsm, uint32_t param_id, void *input, uint32_t input_size ); 188 int cmos_fsm_get_param( void *fsm, uint32_t param_id, void *input, uint32_t input_size, void *output, uint32_t output_size ); 189 uint8_t cmos_fsm_process_event( cmos_fsm_ptr_t p_fsm, event_id_t event_id ); 190 191 void cmos_fsm_process_interrupt( cmos_fsm_const_ptr_t p_fsm, uint8_t irq_event ); 192 193 void cmos_request_interrupt( cmos_fsm_ptr_t p_fsm, system_fw_interrupt_mask_t mask ); 194 195 #endif /* __CMOS_FSM_H__ */ 196