• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __ANALOG_H__
16 #define __ANALOG_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 #include "stdbool.h"
22 #include "hal_analogif.h"
23 #include "hal_cmu.h"
24 #include "hal_aud.h"
25 #include "plat_addr_map.h"
26 #include CHIP_SPECIFIC_HDR(analog)
27 #ifdef DONGLE_SUPPORT
28 #include CHIP_SPECIFIC_HDR(dongle)
29 #endif
30 
31 #define ANALOG_DEBUG_TRACE(n, s, ...)       TR_DUMMY(n, s, ##__VA_ARGS__)
32 #define ANALOG_INFO_TRACE_IMM(n, s, ...)    TR_INFO((n) | TR_ATTR_IMM, s, ##__VA_ARGS__)
33 #define ANALOG_INFO_TRACE(n, s, ...)        TR_INFO(n, s, ##__VA_ARGS__)
34 
35 #ifndef ISPI_ANA_REG
36 #define ISPI_ANA_REG(reg)                   (reg)
37 #endif
38 #define analog_read(reg, val)               hal_analogif_reg_read(ISPI_ANA_REG(reg), val)
39 #define analog_write(reg, val)              hal_analogif_reg_write(ISPI_ANA_REG(reg), val)
40 
41 #define FLOAT_TO_PPB_INT(f)                 ((int)(f * 1000 * 1000 * 1000))
42 
43 #ifndef ANA_AUD_PLL_USER_T
44 enum ANA_AUD_PLL_USER_T {
45     ANA_AUD_PLL_USER_CODEC      = (1 << 0),
46     ANA_AUD_PLL_USER_I2S        = (1 << 1),
47     ANA_AUD_PLL_USER_SPDIF      = (1 << 2),
48     ANA_AUD_PLL_USER_PCM        = (1 << 3),
49 
50     ANA_AUD_PLL_USER_END        = (1 << 4),
51 };
52 #endif
53 
54 enum ANA_DAC_DC_CALIB_MODE_T {
55     ANA_DAC_DC_CALIB_MODE_ADC_ONLY,
56     ANA_DAC_DC_CALIB_MODE_DAC_TO_ADC,
57     ANA_DAC_DC_CALIB_MODE_NORMAL,
58 };
59 
60 void analog_aud_freq_pll_config(uint32_t freq, uint32_t div);
61 
62 void analog_aud_get_dc_calib_value(int16_t *dc_l, int16_t *dc_r);
63 
64 void analog_open(void);
65 
66 void analog_aud_xtal_tune(float ratio);
67 
68 void analog_aud_pll_tune(float ratio);
69 
70 void analog_aud_pll_open(enum ANA_AUD_PLL_USER_T user);
71 
72 void analog_aud_pll_close(enum ANA_AUD_PLL_USER_T user);
73 
74 void analog_aud_set_dac_gain(int32_t v);
75 
76 uint32_t analog_codec_get_dac_gain(void);
77 
78 uint32_t analog_codec_dac_gain_to_db(int32_t gain);
79 
80 int32_t analog_codec_dac_max_attn_db(void);
81 
82 void analog_aud_apply_anc_adc_gain_offset(enum ANC_TYPE_T type, int16_t offset_l, int16_t offset_r);
83 
84 void analog_aud_restore_anc_dyn_adc_gain(enum ANC_TYPE_T type);
85 
86 void analog_aud_apply_adc_gain_offset(enum AUD_CHANNEL_MAP_T ch_map, int16_t offset);
87 
88 void analog_aud_apply_dyn_adc_gain(enum AUD_CHANNEL_MAP_T ch_map, int16_t gain);
89 
90 void analog_aud_codec_open(void);
91 
92 void analog_aud_codec_close(void);
93 
94 void analog_aud_codec_mute(void);
95 
96 void analog_aud_codec_nomute(void);
97 
98 void analog_aud_codec_adc_enable(enum AUD_IO_PATH_T input_path, enum AUD_CHANNEL_MAP_T ch_map, bool en);
99 
100 void analog_aud_codec_dac_enable(bool en);
101 
102 void analog_aud_codec_speaker_enable(bool en);
103 
104 void analog_aud_codec_anc_enable(enum ANC_TYPE_T type, bool en);
105 
106 void analog_aud_mickey_enable(bool en);
107 
108 void analog_sleep(void);
109 
110 void analog_wakeup(void);
111 
112 int analog_debug_config_audio_output(bool diff);
113 
114 int analog_debug_config_codec(uint16_t mv);
115 
116 int analog_debug_config_low_power_adc(bool enable);
117 
118 void analog_debug_config_anc_calib_mode(bool enable);
119 
120 bool analog_debug_get_anc_calib_mode(void);
121 
122 void analog_productiontest_settings_checker(void);
123 
124 bool analog_aud_dc_calib_valid(void);
125 
126 uint16_t analog_aud_dac_dc_diff_to_val(int32_t diff);
127 
128 uint16_t analog_aud_dc_calib_val_to_efuse(uint16_t val);
129 
130 int16_t analog_aud_dac_dc_get_step(void);
131 
132 void analog_aud_save_dc_calib(uint16_t val);
133 
134 void analog_aud_dc_calib_set_value(uint16_t dc_l, uint16_t dc_r);
135 
136 void analog_aud_dc_calib_get_cur_value(uint16_t *dc_l, uint16_t *dc_r);
137 
138 bool analog_aud_dc_calib_get_large_ana_dc_value(uint16_t *ana_dc, int cur_dig_dc, int tgt_dig_dc,
139     int chan, bool init);
140 
141 void analog_aud_dc_calib_enable(bool en);
142 
143 void analog_aud_dac_dc_auto_calib_enable(void);
144 
145 void analog_aud_dac_dc_auto_calib_disable(void);
146 
147 void analog_aud_dac_dc_auto_calib_set_mode(enum ANA_DAC_DC_CALIB_MODE_T mode);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
154 
155